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

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

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