PageRenderTime 108ms CodeModel.GetById 82ms app.highlight 22ms RepoModel.GetById 1ms app.codeStats 0ms

/jEdit/tags/jedit-4-3-pre5/org/gjt/sp/jedit/options/PluginManagerOptionPane.java

#
Java | 291 lines | 206 code | 43 blank | 42 comment | 22 complexity | 4e0bfe87dff5caf4ed7ab324955dee3d MD5 | raw file
  1/*
  2 * PluginManagerOptionPane.java - Plugin options panel
  3 * :tabSize=8:indentSize=8:noTabs=false:
  4 * :folding=explicit:collapseFolds=1:
  5 *
  6 * Copyright (C) 2003 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.options;
 24
 25import javax.swing.*;
 26import javax.swing.border.*;
 27import java.awt.*;
 28import java.awt.event.*;
 29import java.util.*;
 30import org.gjt.sp.jedit.*;
 31import org.gjt.sp.jedit.io.VFSManager;
 32import org.gjt.sp.jedit.pluginmgr.*;
 33import org.gjt.sp.util.*;
 34
 35/**
 36 * @version $Id: PluginManagerOptionPane.java 5236 2005-07-27 21:54:36Z kpouer $
 37 */
 38public class PluginManagerOptionPane extends AbstractOptionPane
 39{
 40	//{{{ Constructor
 41	public PluginManagerOptionPane()
 42	{
 43		super("plugin-manager");
 44	} //}}}
 45
 46	//{{{ _init() method
 47	protected void _init()
 48	{
 49		setLayout(new BorderLayout());
 50
 51		locationLabel = new JLabel(jEdit.getProperty(
 52			"options.plugin-manager.location"));
 53
 54		mirrorLabel = new JLabel();
 55		updateMirrorLabel();
 56
 57		if(jEdit.getSettingsDirectory() != null)
 58		{
 59			settingsDir = new JRadioButton(jEdit.getProperty(
 60				"options.plugin-manager.settings-dir"));
 61			settingsDir.setToolTipText(MiscUtilities.constructPath(
 62				jEdit.getSettingsDirectory(),"jars"));
 63		}
 64		appDir = new JRadioButton(jEdit.getProperty(
 65			"options.plugin-manager.app-dir"));
 66		appDir.setToolTipText(MiscUtilities.constructPath(
 67			jEdit.getJEditHome(),"jars"));
 68
 69		miraList = new JList(miraModel = new MirrorModel());
 70		miraList.setSelectionModel(new SingleSelectionModel());
 71
 72		/* Download mirror */
 73		add(BorderLayout.NORTH,mirrorLabel);
 74		add(BorderLayout.CENTER,new JScrollPane(miraList));
 75
 76		JPanel buttonPanel = new JPanel();
 77		buttonPanel.setLayout(new BoxLayout(buttonPanel,BoxLayout.Y_AXIS));
 78
 79		buttonPanel.add(Box.createVerticalStrut(6));
 80
 81		/* Update mirror list */
 82		JButton updateMirrors = new JButton(jEdit.getProperty(
 83			"options.plugin-manager.updateMirrors"));
 84		updateMirrors.addActionListener(new ActionHandler());
 85		buttonPanel.add(updateMirrors);
 86
 87		buttonPanel.add(Box.createVerticalStrut(6));
 88
 89		/* Download source */
 90		downloadSource = new JCheckBox(jEdit.getProperty(
 91			"options.plugin-manager.downloadSource"));
 92		downloadSource.setSelected(jEdit.getBooleanProperty("plugin-manager.downloadSource"));
 93		buttonPanel.add(downloadSource);
 94
 95		buttonPanel.add(Box.createVerticalStrut(6));
 96
 97		/* Delete downloaded files */
 98		deleteDownloads = new JCheckBox(jEdit.getProperty(
 99			"options.plugin-manager.deleteDownloads"));
100		deleteDownloads.setSelected(jEdit.getBooleanProperty("plugin-manager.deleteDownloads"));
101		buttonPanel.add(deleteDownloads);
102
103		buttonPanel.add(Box.createVerticalStrut(6));
104
105		/* Install location */
106		locGrp = new ButtonGroup();
107		if(jEdit.getSettingsDirectory() != null)
108			locGrp.add(settingsDir);
109		locGrp.add(appDir);
110		JPanel locPanel = new JPanel();
111		locPanel.setBorder(new EmptyBorder(3,12,0,0));
112		locPanel.setLayout(new BoxLayout(locPanel,BoxLayout.Y_AXIS));
113		if(jEdit.getSettingsDirectory() != null)
114		{
115			locPanel.add(settingsDir);
116			locPanel.add(Box.createVerticalStrut(3));
117		}
118		locPanel.add(appDir);
119		buttonPanel.add(locationLabel);
120		buttonPanel.add(locPanel);
121
122		buttonPanel.add(Box.createGlue());
123		add(BorderLayout.SOUTH,buttonPanel);
124
125		if (jEdit.getBooleanProperty("plugin-manager.installUser")
126			&& jEdit.getSettingsDirectory() != null)
127			settingsDir.setSelected(true);
128		else
129			appDir.setSelected(true);
130	} //}}}
131
132	//{{{ _save() method
133	protected void _save()
134	{
135		jEdit.setBooleanProperty("plugin-manager.installUser",
136			settingsDir != null && settingsDir.isSelected());
137		jEdit.setBooleanProperty("plugin-manager.downloadSource",downloadSource.isSelected());
138		jEdit.setBooleanProperty("plugin-manager.deleteDownloads",deleteDownloads.isSelected());
139
140		if(miraList.getSelectedIndex() != -1)
141		{
142			String currentMirror = miraModel.getID(miraList.getSelectedIndex());
143			String previousMirror = jEdit.getProperty("plugin-manager.mirror.id");
144
145			if (!previousMirror.equals(currentMirror))
146			{
147				jEdit.setProperty("plugin-manager.mirror.id",currentMirror);
148				jEdit.setProperty("plugin-manager.mirror.name",(String) miraModel.getElementAt(miraList.getSelectedIndex()));
149				updateMirrorLabel();
150				// Insert code to update the plugin managers list here later
151			}
152		}
153	} //}}}
154
155	//{{{ Private members
156
157	//{{{ Instance variables
158	private JLabel locationLabel;
159	private JLabel mirrorLabel;
160
161	private ButtonGroup locGrp;
162	private JRadioButton settingsDir;
163	private JRadioButton appDir;
164	private JCheckBox downloadSource;
165	private JCheckBox deleteDownloads;
166
167	private MirrorModel miraModel;
168	private JList miraList;
169	//}}}
170
171	//{{{ updateMirrorLabel method
172	private void updateMirrorLabel()
173	{
174		String currentMirror = jEdit.getProperty("plugin-manager.mirror.id");
175		String mirrorName;
176		if (currentMirror.equals(MirrorList.Mirror.NONE))
177		{
178			mirrorName = "Plugin Central default";
179		}
180		else
181		{
182			mirrorName = jEdit.getProperty("plugin-manager.mirror.name");
183			if (mirrorName == null) mirrorName = currentMirror;
184		}
185		mirrorLabel.setText(jEdit.getProperty(
186			"options.plugin-manager.mirror") + ' ' + mirrorName);
187	} //}}}
188
189	//}}}
190
191	//{{{ MirrorModel class
192	class MirrorModel extends AbstractListModel
193	{
194		private ArrayList mirrors;
195
196		public MirrorModel()
197		{
198			mirrors = new ArrayList();
199		}
200
201		public String getID(int index)
202		{
203			return ((MirrorList.Mirror)mirrors.get(index)).id;
204		}
205
206		public int getSize()
207		{
208			return mirrors.size();
209		}
210
211		public Object getElementAt(int index)
212		{
213			MirrorList.Mirror mirror = (MirrorList.Mirror)mirrors.get(index);
214			if(mirror.id.equals(MirrorList.Mirror.NONE))
215				return jEdit.getProperty("options.plugin-manager.none");
216			else
217				return mirror.continent+": "+mirror.description+" ("+mirror.location+")";
218		}
219
220		public void setList(ArrayList mirrors)
221		{
222			this.mirrors = mirrors;
223			fireContentsChanged(this,0,mirrors.size() - 1);
224		}
225	} //}}}
226
227	//{{{ SingleSelectionModel class
228	class SingleSelectionModel extends DefaultListSelectionModel
229	{
230		public SingleSelectionModel()
231		{
232			super();
233			setSelectionMode(SINGLE_SELECTION);
234		}
235
236		public void removeSelectionInterval(int index0, int index1) {}
237	} //}}}
238
239	//{{{ ActionHandler class
240	class ActionHandler implements ActionListener
241	{
242		public void actionPerformed(ActionEvent evt)
243		{
244			VFSManager.runInWorkThread(new DownloadMirrorsThread());
245		}
246	} //}}}
247
248	//{{{ DownloadMirrorsThread class
249	class DownloadMirrorsThread extends WorkRequest
250	{
251		public void run()
252		{
253			setStatus(jEdit.getProperty("options.plugin-manager.workthread"));
254			setMaximum(1);
255			setValue(0);
256
257			final ArrayList mirrors = new ArrayList();
258			try
259			{
260				mirrors.addAll(new MirrorList().mirrors);
261			}
262			catch (Exception ex)
263			{
264				Log.log(Log.ERROR,this,ex);
265				GUIUtilities.error(PluginManagerOptionPane.this,
266					"ioerror",new String[] { ex.toString() });
267			}
268
269			SwingUtilities.invokeLater(new Runnable()
270			{
271				public void run()
272				{
273					miraModel.setList(mirrors);
274
275					String id = jEdit.getProperty("plugin-manager.mirror.id");
276					int size = miraModel.getSize();
277					for (int i=0; i < size; i++)
278					{
279						if (size == 1 || miraModel.getID(i).equals(id))
280						{
281							miraList.setSelectedIndex(i);
282							break;
283						}
284					}
285				}
286			});
287
288			setValue(1);
289		}
290	} //}}}
291}