PageRenderTime 43ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 1ms

/jEdit/tags/jedit-4-2-pre4/org/gjt/sp/jedit/pluginmgr/PluginManager.java

#
Java | 253 lines | 174 code | 31 blank | 48 comment | 30 complexity | f522bf4ff35e5bd4b1a9e2c877e53d8c 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. * PluginManager.java - Plugin manager window
  3. * :tabSize=8:indentSize=8:noTabs=false:
  4. * :folding=explicit:collapseFolds=1:
  5. *
  6. * Copyright (C) 2002 Kris Kopicki
  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.event.*;
  26. import javax.swing.table.*;
  27. import javax.swing.*;
  28. import java.awt.event.*;
  29. import java.awt.*;
  30. import java.util.*;
  31. import org.gjt.sp.jedit.gui.*;
  32. import org.gjt.sp.jedit.msg.*;
  33. import org.gjt.sp.jedit.options.GlobalOptions;
  34. import org.gjt.sp.jedit.*;
  35. //}}}
  36. public class PluginManager extends JFrame implements EBComponent
  37. {
  38. //{{{ getInstance() method
  39. /**
  40. * Returns the currently visible plugin manager window, or null.
  41. * @since jEdit 4.2pre2
  42. */
  43. public static PluginManager getInstance()
  44. {
  45. return instance;
  46. } //}}}
  47. //{{{ dispose() method
  48. public void dispose()
  49. {
  50. GUIUtilities.saveGeometry(this,"plugin-manager");
  51. instance = null;
  52. EditBus.removeFromBus(this);
  53. super.dispose();
  54. } //}}}
  55. //{{{ handleMessage() method
  56. public void handleMessage(EBMessage message)
  57. {
  58. // Force the install tab to refresh for possible
  59. // change of mirror
  60. if (message instanceof PropertiesChanged)
  61. {
  62. pluginList = null;
  63. if(tabPane.getSelectedIndex() != 0)
  64. {
  65. SwingUtilities.invokeLater(new Runnable()
  66. {
  67. public void run()
  68. {
  69. updatePluginList();
  70. installer.updateModel();
  71. updater.updateModel();
  72. }
  73. });
  74. }
  75. }
  76. else if (message instanceof PluginUpdate)
  77. {
  78. if(!queuedUpdate)
  79. {
  80. SwingUtilities.invokeLater(new Runnable()
  81. {
  82. public void run()
  83. {
  84. queuedUpdate = false;
  85. manager.update();
  86. }
  87. });
  88. queuedUpdate = true;
  89. }
  90. }
  91. } //}}}
  92. //{{{ showPluginManager() method
  93. public static void showPluginManager(Frame frame)
  94. {
  95. if (instance == null)
  96. instance = new PluginManager(frame);
  97. else
  98. {
  99. instance.toFront();
  100. return;
  101. }
  102. } //}}}
  103. //{{{ ok() method
  104. public void ok()
  105. {
  106. dispose();
  107. } //}}}
  108. //{{{ cancel() method
  109. public void cancel()
  110. {
  111. dispose();
  112. } //}}}
  113. //{{{ getPluginList() method
  114. public PluginList getPluginList()
  115. {
  116. return pluginList;
  117. } //}}}
  118. //{{{ Private members
  119. private static PluginManager instance;
  120. //{{{ Instance variables
  121. private JTabbedPane tabPane;
  122. private JButton done;
  123. private JButton cancel;
  124. private JButton options;
  125. private InstallPanel installer;
  126. private InstallPanel updater;
  127. private ManagePanel manager;
  128. private PluginList pluginList;
  129. private boolean queuedUpdate;
  130. //}}}
  131. //{{{ PluginManager constructor
  132. private PluginManager(Frame frame)
  133. {
  134. super(jEdit.getProperty("plugin-manager.title"));
  135. EditBus.addToBus(this);
  136. /* Setup panes */
  137. JPanel content = new JPanel(new BorderLayout(12,12));
  138. content.setBorder(new EmptyBorder(12,12,12,12));
  139. setContentPane(content);
  140. tabPane = new JTabbedPane();
  141. tabPane.addTab(jEdit.getProperty("manage-plugins.title"),
  142. manager = new ManagePanel(this));
  143. tabPane.addTab(jEdit.getProperty("update-plugins.title"),
  144. updater = new InstallPanel(this,true));
  145. tabPane.addTab(jEdit.getProperty("install-plugins.title"),
  146. installer = new InstallPanel(this,false));
  147. content.add(BorderLayout.CENTER,tabPane);
  148. tabPane.addChangeListener(new ListUpdater());
  149. /* Create the buttons */
  150. Box buttons = new Box(BoxLayout.X_AXIS);
  151. ActionListener al = new ActionHandler();
  152. options = new JButton(jEdit.getProperty("plugin-manager.options"));
  153. options.addActionListener(al);
  154. done = new JButton(jEdit.getProperty("plugin-manager.done"));
  155. done.addActionListener(al);
  156. buttons.add(Box.createGlue());
  157. buttons.add(options);
  158. buttons.add(Box.createHorizontalStrut(6));
  159. buttons.add(done);
  160. buttons.add(Box.createGlue());
  161. getRootPane().setDefaultButton(done);
  162. content.add(BorderLayout.SOUTH,buttons);
  163. setDefaultCloseOperation(DISPOSE_ON_CLOSE);
  164. setIconImage(GUIUtilities.getPluginIcon());
  165. pack();
  166. GUIUtilities.loadGeometry(this,"plugin-manager");
  167. show();
  168. } //}}}
  169. //{{{ updatePluginList() method
  170. private void updatePluginList()
  171. {
  172. if(jEdit.getSettingsDirectory() == null
  173. && jEdit.getJEditHome() == null)
  174. {
  175. GUIUtilities.error(this,"no-settings",null);
  176. }
  177. else if(pluginList == null)
  178. {
  179. pluginList = new PluginListDownloadProgress(this)
  180. .getPluginList();
  181. }
  182. } //}}}
  183. //}}}
  184. //{{{ Inner classes
  185. //{{{ ActionHandler class
  186. class ActionHandler implements ActionListener
  187. {
  188. public void actionPerformed(ActionEvent evt)
  189. {
  190. Object source = evt.getSource();
  191. if(source == done)
  192. ok();
  193. else if (source == cancel)
  194. cancel();
  195. else if (source == options)
  196. new GlobalOptions(PluginManager.this,"plugin-manager");
  197. }
  198. } //}}}
  199. //{{{ ListUpdater class
  200. class ListUpdater implements ChangeListener
  201. {
  202. public void stateChanged(ChangeEvent e)
  203. {
  204. final Component selected = tabPane.getSelectedComponent();
  205. if(selected == installer || selected == updater)
  206. {
  207. SwingUtilities.invokeLater(new Runnable()
  208. {
  209. public void run()
  210. {
  211. updatePluginList();
  212. installer.updateModel();
  213. updater.updateModel();
  214. }
  215. });
  216. }
  217. else if(selected == manager)
  218. manager.update();
  219. }
  220. } //}}}
  221. //}}}
  222. }