PageRenderTime 38ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 0ms

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

#
Java | 271 lines | 192 code | 38 blank | 41 comment | 7 complexity | 246f2c2633988ab1c21f694880ad384c 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. //}}}
  30. public class PluginManagerProgress extends JDialog
  31. {
  32. //{{{ PluginManagerProgress constructor
  33. public PluginManagerProgress(JDialog dialog, String type, Roster roster)
  34. {
  35. super(JOptionPane.getFrameForComponent(dialog),
  36. jEdit.getProperty("plugin-manager.progress."
  37. + type + "-task"),true);
  38. this.roster = roster;
  39. this.type = type;
  40. JPanel content = new JPanel(new BorderLayout(12,12));
  41. content.setBorder(new EmptyBorder(12,12,12,12));
  42. setContentPane(content);
  43. globalProgress = new JProgressBar();
  44. globalProgress.setStringPainted(true);
  45. globalProgress.setString(jEdit.getProperty("plugin-manager.progress."
  46. + type + "-task"));
  47. count = roster.getOperationCount();
  48. globalProgress.setMaximum(count);
  49. content.add(BorderLayout.NORTH,globalProgress);
  50. localProgress = new JProgressBar();
  51. localProgress.setStringPainted(true);
  52. content.add(BorderLayout.CENTER,localProgress);
  53. stop = new JButton(jEdit.getProperty("plugin-manager.progress.stop"));
  54. stop.addActionListener(new ActionHandler());
  55. JPanel panel = new JPanel();
  56. panel.setLayout(new BoxLayout(panel,BoxLayout.X_AXIS));
  57. panel.add(Box.createGlue());
  58. panel.add(stop);
  59. panel.add(Box.createGlue());
  60. content.add(BorderLayout.SOUTH,panel);
  61. addWindowListener(new WindowHandler());
  62. pack();
  63. Dimension screen = getToolkit().getScreenSize();
  64. Dimension size = getSize();
  65. size.width = Math.max(size.width,500);
  66. setSize(size);
  67. setLocationRelativeTo(dialog);
  68. show();
  69. } //}}}
  70. //{{{ removing() method
  71. public void removing(String plugin)
  72. {
  73. String[] args = { plugin };
  74. showMessage(jEdit.getProperty("plugin-manager.progress.removing",args));
  75. stop.setEnabled(true);
  76. } //}}}
  77. //{{{ downloading() method
  78. public void downloading(String plugin)
  79. {
  80. String[] args = { plugin };
  81. showMessage(jEdit.getProperty("plugin-manager.progress.downloading",args));
  82. stop.setEnabled(true);
  83. } //}}}
  84. //{{{ installing() method
  85. public void installing(String plugin)
  86. {
  87. String[] args = { plugin };
  88. showMessage(jEdit.getProperty("plugin-manager.progress.installing",args));
  89. stop.setEnabled(false);
  90. } //}}}
  91. //{{{ setMaximum() method
  92. public void setMaximum(final int total)
  93. {
  94. SwingUtilities.invokeLater(new Runnable()
  95. {
  96. public void run()
  97. {
  98. localProgress.setMaximum(total);
  99. }
  100. });
  101. } //}}}
  102. //{{{ setValue() method
  103. public void setValue(final int value)
  104. {
  105. SwingUtilities.invokeLater(new Runnable()
  106. {
  107. public void run()
  108. {
  109. localProgress.setValue(value);
  110. }
  111. });
  112. } //}}}
  113. //{{{ done() method
  114. public void done(final boolean ok)
  115. {
  116. this.ok |= ok;
  117. try
  118. {
  119. if(!ok || done == count)
  120. {
  121. SwingUtilities.invokeAndWait(new Runnable()
  122. {
  123. public void run()
  124. {
  125. dispose();
  126. if(ok)
  127. {
  128. GUIUtilities.message(PluginManagerProgress.this,
  129. "plugin-manager." + type
  130. + "-done",null);
  131. }
  132. else
  133. {
  134. // user will see an error in any case
  135. //GUIUtilities.message(PluginManagerProgress.this,
  136. // "plugin-manager.failed",null);
  137. }
  138. }
  139. });
  140. }
  141. else
  142. {
  143. SwingUtilities.invokeAndWait(new Runnable()
  144. {
  145. public void run()
  146. {
  147. globalProgress.setValue(done++);
  148. localProgress.setValue(0);
  149. }
  150. });
  151. }
  152. }
  153. catch(Exception e)
  154. {
  155. }
  156. } //}}}
  157. //{{{ isOK() method
  158. public boolean isOK()
  159. {
  160. return ok;
  161. } //}}}
  162. //{{{ Private members
  163. //{{{ Instance variables
  164. private Thread thread;
  165. private String type;
  166. private JProgressBar globalProgress, localProgress;
  167. private JButton stop;
  168. private int count;
  169. private int done = 1;
  170. private boolean ok;
  171. private Roster roster;
  172. //}}}
  173. //{{{ showMessage() method
  174. private void showMessage(final String msg)
  175. {
  176. try
  177. {
  178. SwingUtilities.invokeAndWait(new Runnable()
  179. {
  180. public void run()
  181. {
  182. localProgress.setString(msg);
  183. }
  184. });
  185. }
  186. catch(Exception e)
  187. {
  188. }
  189. Thread.yield();
  190. } //}}}
  191. //{{{ ActionHandler class
  192. class ActionHandler implements ActionListener
  193. {
  194. public void actionPerformed(ActionEvent evt)
  195. {
  196. if(evt.getSource() == stop)
  197. {
  198. thread.stop();
  199. dispose();
  200. }
  201. }
  202. } //}}}
  203. //{{{ WindowHandler class
  204. class WindowHandler extends WindowAdapter
  205. {
  206. boolean done;
  207. public void windowOpened(WindowEvent evt)
  208. {
  209. if(done)
  210. return;
  211. done = true;
  212. thread = new RosterThread();
  213. thread.start();
  214. }
  215. public void windowClosing(WindowEvent evt)
  216. {
  217. thread.stop();
  218. dispose();
  219. }
  220. } //}}}
  221. //{{{ RosterThread class
  222. class RosterThread extends Thread
  223. {
  224. RosterThread()
  225. {
  226. super("Plugin manager thread");
  227. }
  228. public void run()
  229. {
  230. roster.performOperations(PluginManagerProgress.this);
  231. }
  232. } //}}}
  233. }