PageRenderTime 26ms CodeModel.GetById 11ms app.highlight 12ms RepoModel.GetById 1ms app.codeStats 0ms

/jEdit/tags/jedit-4-2-pre14/org/gjt/sp/jedit/options/PluginManagerOptionPane.java

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