PageRenderTime 43ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/jEdit/tags/jedit-4-3-pre5/org/gjt/sp/jedit/pluginmgr/PluginManagerProgress.java

#
Java | 234 lines | 145 code | 30 blank | 59 comment | 6 complexity | da4761b03c66fa45426b758b50438bf9 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. * PluginManagerProgress.java - Plugin download progress meter
  3. * :tabSize=8:indentSize=8:noTabs=false:
  4. * :folding=explicit:collapseFolds=1:
  5. *
  6. * Copyright (C) 2000, 2001 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.jedit.pluginmgr;
  23. //{{{ Imports
  24. import javax.swing.border.*;
  25. import javax.swing.*;
  26. import java.awt.event.*;
  27. import java.awt.*;
  28. import org.gjt.sp.jedit.*;
  29. import org.gjt.sp.util.ProgressObserver;
  30. //}}}
  31. class PluginManagerProgress extends JDialog implements ProgressObserver
  32. {
  33. //{{{ PluginManagerProgress constructor
  34. public PluginManagerProgress(PluginManager dialog, Roster roster)
  35. {
  36. super(dialog,jEdit.getProperty("plugin-manager.progress"),true);
  37. this.roster = roster;
  38. JPanel content = new JPanel(new BorderLayout(12,12));
  39. content.setBorder(new EmptyBorder(12,12,12,12));
  40. setContentPane(content);
  41. progress = new JProgressBar();
  42. progress.setStringPainted(true);
  43. progress.setString(jEdit.getProperty("plugin-manager.progress"));
  44. int maximum = 0;
  45. count = roster.getOperationCount();
  46. for(int i = 0; i < count; i++)
  47. {
  48. maximum += roster.getOperation(i).getMaximum();
  49. }
  50. progress.setMaximum(maximum);
  51. content.add(BorderLayout.NORTH,progress);
  52. stop = new JButton(jEdit.getProperty("plugin-manager.progress.stop"));
  53. stop.addActionListener(new ActionHandler());
  54. JPanel panel = new JPanel(new FlowLayout(
  55. FlowLayout.CENTER,0,0));
  56. panel.add(stop);
  57. content.add(BorderLayout.CENTER,panel);
  58. addWindowListener(new WindowHandler());
  59. pack();
  60. setLocationRelativeTo(dialog);
  61. setVisible(true);
  62. } //}}}
  63. //{{{ setValue() method
  64. /**
  65. * @param value the new value
  66. * @deprecated Use {@link #setValue(long)}
  67. */
  68. public void setValue(final int value)
  69. {
  70. SwingUtilities.invokeLater(new Runnable()
  71. {
  72. public void run()
  73. {
  74. progress.setValue(valueSoFar + value);
  75. }
  76. });
  77. } //}}}
  78. //{{{ setValue() method
  79. /**
  80. * Update the progress value.
  81. *
  82. * @param value the new value
  83. * @since jEdit 4.3pre3
  84. */
  85. public void setValue(final long value)
  86. {
  87. SwingUtilities.invokeLater(new Runnable()
  88. {
  89. public void run()
  90. {
  91. progress.setValue(valueSoFar + (int) value);
  92. }
  93. });
  94. } //}}}
  95. //{{{ setMaximum() method
  96. /**
  97. * This method is unused with the plugin manager.
  98. *
  99. * @param value the new max value (it will be ignored)
  100. * @since jEdit 4.3pre3
  101. */
  102. public void setMaximum(long value)
  103. {
  104. } //}}}
  105. //{{{ setStatus() method
  106. /**
  107. * This method is unused with the plugin manager.
  108. *
  109. * @param status the new status (it will be ignored)
  110. * @since jEdit 4.3pre3
  111. */
  112. public void setStatus(String status)
  113. {
  114. setTitle(status);
  115. progress.setString(status);
  116. } //}}}
  117. //{{{ done() method
  118. public void done()
  119. {
  120. try
  121. {
  122. if(done == count)
  123. {
  124. SwingUtilities.invokeAndWait(new Runnable()
  125. {
  126. public void run()
  127. {
  128. dispose();
  129. }
  130. });
  131. }
  132. else
  133. {
  134. SwingUtilities.invokeAndWait(new Runnable()
  135. {
  136. public void run()
  137. {
  138. valueSoFar += roster.getOperation(done - 1)
  139. .getMaximum();
  140. progress.setValue(valueSoFar);
  141. done++;
  142. }
  143. });
  144. }
  145. }
  146. catch(Exception e)
  147. {
  148. }
  149. } //}}}
  150. //{{{ Private members
  151. //{{{ Instance variables
  152. private Thread thread;
  153. private JProgressBar progress;
  154. private JButton stop;
  155. private int count;
  156. private int done = 1;
  157. // progress value as of start of current task
  158. private int valueSoFar;
  159. private Roster roster;
  160. //}}}
  161. //{{{ ActionHandler class
  162. class ActionHandler implements ActionListener
  163. {
  164. public void actionPerformed(ActionEvent evt)
  165. {
  166. if(evt.getSource() == stop)
  167. {
  168. thread.stop();
  169. dispose();
  170. }
  171. }
  172. } //}}}
  173. //{{{ WindowHandler class
  174. class WindowHandler extends WindowAdapter
  175. {
  176. boolean done;
  177. public void windowOpened(WindowEvent evt)
  178. {
  179. if(done)
  180. return;
  181. done = true;
  182. thread = new RosterThread();
  183. thread.start();
  184. }
  185. public void windowClosing(WindowEvent evt)
  186. {
  187. thread.stop();
  188. dispose();
  189. }
  190. } //}}}
  191. //{{{ RosterThread class
  192. class RosterThread extends Thread
  193. {
  194. RosterThread()
  195. {
  196. super("Plugin manager thread");
  197. }
  198. public void run()
  199. {
  200. roster.performOperationsInWorkThread(PluginManagerProgress.this);
  201. }
  202. } //}}}
  203. //}}}
  204. }