PageRenderTime 45ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/jEdit/tags/jedit-4-3-pre5/org/gjt/sp/util/WorkRequest.java

#
Java | 131 lines | 61 code | 8 blank | 62 comment | 8 complexity | 3c7182159a1e717a6faf3a2be72b4295 MD5 | raw file
Possible License(s): BSD-3-Clause, AGPL-1.0, Apache-2.0, LGPL-2.0, LGPL-3.0, GPL-2.0, CC-BY-SA-3.0, LGPL-2.1, GPL-3.0, MPL-2.0-no-copyleft-exception, IPL-1.0
  1. /*
  2. * WorkRequest.java - Runnable subclass
  3. * :tabSize=8:indentSize=8:noTabs=false:
  4. * :folding=explicit:collapseFolds=1:
  5. *
  6. * Copyright (C) 2000 Slava Pestov
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License
  10. * as published by the Free Software Foundation; either version 2
  11. * of the License, or any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  21. */
  22. package org.gjt.sp.util;
  23. /**
  24. * A subclass of the Runnable interface.
  25. * @since jEdit 2.6pre1
  26. * @version $Id: WorkRequest.java 5234 2005-07-27 21:44:10Z kpouer $
  27. */
  28. public abstract class WorkRequest implements Runnable, ProgressObserver
  29. {
  30. /**
  31. * If the max value is greater that <code>Integer.MAX_VALUE</code> this
  32. * will be true and all values will be divided by 1024.
  33. * @since jEdit 4.3pre3
  34. */
  35. private boolean largeValues;
  36. /**
  37. * Sets if the request can be aborted.
  38. */
  39. public void setAbortable(boolean abortable)
  40. {
  41. Thread thread = Thread.currentThread();
  42. if(thread instanceof WorkThread)
  43. ((WorkThread)thread).setAbortable(abortable);
  44. }
  45. /**
  46. * Sets the status text.
  47. * @param status The status text
  48. */
  49. public void setStatus(String status)
  50. {
  51. Thread thread = Thread.currentThread();
  52. if(thread instanceof WorkThread)
  53. ((WorkThread)thread).setStatus(status);
  54. }
  55. /**
  56. * Sets the progress value.
  57. * @param value The progress value.
  58. * @deprecated use {@link #setValue(long)}
  59. */
  60. public void setProgressValue(int value)
  61. {
  62. Thread thread = Thread.currentThread();
  63. if(thread instanceof WorkThread)
  64. ((WorkThread)thread).setProgressValue(value);
  65. }
  66. /**
  67. * Sets the maximum progress value.
  68. * @param value The progress value.
  69. * @deprecated use {@link #setMaximum(long)}
  70. */
  71. public void setProgressMaximum(int value)
  72. {
  73. Thread thread = Thread.currentThread();
  74. if(thread instanceof WorkThread)
  75. ((WorkThread)thread).setProgressMaximum(value);
  76. }
  77. //{{{ setValue() method
  78. /**
  79. * Update the progress value.
  80. *
  81. * @param value the new value
  82. * @since jEdit 4.3pre3
  83. */
  84. public void setValue(long value)
  85. {
  86. Thread thread = Thread.currentThread();
  87. if(thread instanceof WorkThread)
  88. {
  89. if (largeValues)
  90. {
  91. ((WorkThread)thread).setProgressValue((int) (value >> 10));
  92. }
  93. else
  94. {
  95. ((WorkThread)thread).setProgressValue((int) value);
  96. }
  97. }
  98. } //}}}
  99. //{{{ setValue() method
  100. /**
  101. * Update the maximum value.
  102. *
  103. * @param value the new maximum value
  104. * @since jEdit 4.3pre3
  105. */
  106. public void setMaximum(long value)
  107. {
  108. Thread thread = Thread.currentThread();
  109. if(thread instanceof WorkThread)
  110. {
  111. if (value > Integer.MAX_VALUE)
  112. {
  113. largeValues = true;
  114. ((WorkThread)thread).setProgressMaximum((int) (value >> 10));
  115. }
  116. else
  117. {
  118. largeValues = false;
  119. ((WorkThread)thread).setProgressMaximum((int) value);
  120. }
  121. }
  122. } //}}}
  123. }