PageRenderTime 54ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 0ms

/jEdit/tags/jedit-4-5-pre1/org/gjt/sp/jedit/pluginmgr/PluginManagerProgress.java

#
Java | 220 lines | 138 code | 28 blank | 54 comment | 6 complexity | abe73ed90881a783678ceffa85aafd48 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. 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. count = roster.getOperationCount();
  45. int maximum = 0;
  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. * Update the progress value.
  66. *
  67. * @param value the new value
  68. * @since jEdit 4.3pre3
  69. */
  70. public void setValue(final long value)
  71. {
  72. SwingUtilities.invokeLater(new Runnable()
  73. {
  74. public void run()
  75. {
  76. progress.setValue(valueSoFar + (int) value);
  77. }
  78. });
  79. } //}}}
  80. //{{{ setMaximum() method
  81. /**
  82. * This method is unused with the plugin manager.
  83. *
  84. * @param value the new max value (it will be ignored)
  85. * @since jEdit 4.3pre3
  86. */
  87. public void setMaximum(long value)
  88. {
  89. } //}}}
  90. //{{{ setStatus() method
  91. /**
  92. * This method is unused with the plugin manager.
  93. *
  94. * @param status the new status (it will be ignored)
  95. * @since jEdit 4.3pre3
  96. */
  97. public void setStatus(String status)
  98. {
  99. setTitle(status);
  100. progress.setString(status);
  101. } //}}}
  102. //{{{ done() method
  103. public void done()
  104. {
  105. try
  106. {
  107. if(done == count)
  108. {
  109. SwingUtilities.invokeAndWait(new Runnable()
  110. {
  111. public void run()
  112. {
  113. dispose();
  114. }
  115. });
  116. }
  117. else
  118. {
  119. SwingUtilities.invokeAndWait(new Runnable()
  120. {
  121. public void run()
  122. {
  123. valueSoFar += roster.getOperation(done - 1)
  124. .getMaximum();
  125. progress.setValue(valueSoFar);
  126. done++;
  127. }
  128. });
  129. }
  130. }
  131. catch(Exception e)
  132. {
  133. }
  134. } //}}}
  135. //{{{ Private members
  136. //{{{ Instance variables
  137. private Thread thread;
  138. private final JProgressBar progress;
  139. private final JButton stop;
  140. private final int count;
  141. private int done = 1;
  142. // progress value as of start of current task
  143. private int valueSoFar;
  144. private final Roster roster;
  145. //}}}
  146. //{{{ ActionHandler class
  147. class ActionHandler implements ActionListener
  148. {
  149. public void actionPerformed(ActionEvent evt)
  150. {
  151. if(evt.getSource() == stop)
  152. {
  153. thread.stop();
  154. dispose();
  155. }
  156. }
  157. } //}}}
  158. //{{{ WindowHandler class
  159. class WindowHandler extends WindowAdapter
  160. {
  161. boolean done;
  162. @Override
  163. public void windowOpened(WindowEvent evt)
  164. {
  165. if(done)
  166. return;
  167. done = true;
  168. thread = new RosterThread();
  169. thread.start();
  170. }
  171. @Override
  172. public void windowClosing(WindowEvent evt)
  173. {
  174. thread.stop();
  175. dispose();
  176. }
  177. } //}}}
  178. //{{{ RosterThread class
  179. class RosterThread extends Thread
  180. {
  181. RosterThread()
  182. {
  183. super("Plugin manager thread");
  184. }
  185. @Override
  186. public void run()
  187. {
  188. roster.performOperationsInWorkThread(PluginManagerProgress.this);
  189. }
  190. } //}}}
  191. //}}}
  192. }