PageRenderTime 48ms CodeModel.GetById 38ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 0ms

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