PageRenderTime 170ms CodeModel.GetById 138ms app.highlight 28ms RepoModel.GetById 1ms app.codeStats 0ms

/jEdit/tags/jedit-4-0-pre3/org/gjt/sp/jedit/pluginmgr/InstallPluginsDialog.java

#
Java | 311 lines | 252 code | 40 blank | 19 comment | 33 complexity | f9ff9fa922e711e7d770f3cbdbf74855 MD5 | raw file
  1/*
  2 * InstallPluginsDialog.java - Plugin install dialog box
  3 * Copyright (C) 2000, 2001 Slava Pestov
  4 *
  5 * This program is free software; you can redistribute it and/or
  6 * modify it under the terms of the GNU General Public License
  7 * as published by the Free Software Foundation; either version 2
  8 * of the License, or any later version.
  9 *
 10 * This program is distributed in the hope that it will be useful,
 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 13 * GNU General Public License for more details.
 14 *
 15 * You should have received a copy of the GNU General Public License
 16 * along with this program; if not, write to the Free Software
 17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 18 */
 19
 20package org.gjt.sp.jedit.pluginmgr;
 21
 22import javax.swing.border.EmptyBorder;
 23import javax.swing.event.*;
 24import javax.swing.*;
 25import java.awt.event.*;
 26import java.awt.*;
 27import java.util.Vector;
 28import org.gjt.sp.jedit.gui.*;
 29import org.gjt.sp.jedit.*;
 30
 31class InstallPluginsDialog extends EnhancedDialog
 32{
 33	static final int INSTALL = 0;
 34	static final int UPDATE = 1;
 35
 36	InstallPluginsDialog(JDialog dialog, Vector model, int mode)
 37	{
 38		super(JOptionPane.getFrameForComponent(dialog),
 39			(mode == INSTALL
 40			? jEdit.getProperty("install-plugins.title")
 41			: jEdit.getProperty("update-plugins.title")),true);
 42
 43		JPanel content = new JPanel(new BorderLayout());
 44		content.setBorder(new EmptyBorder(12,12,12,12));
 45		setContentPane(content);
 46
 47		JLabel label = new JLabel(jEdit.getProperty("install-plugins.caption"));
 48		label.setBorder(new EmptyBorder(0,0,6,0));
 49		content.add(BorderLayout.NORTH,label);
 50
 51		JPanel panel = new JPanel(new BorderLayout());
 52		panel.setBorder(new EmptyBorder(0,0,12,0));
 53
 54		plugins = new JCheckBoxList(model);
 55		plugins.getSelectionModel().addListSelectionListener(new ListHandler());
 56		JScrollPane scroller = new JScrollPane(plugins);
 57		Dimension dim = scroller.getPreferredSize();
 58		dim.height = 120;
 59		scroller.setPreferredSize(dim);
 60		panel.add(BorderLayout.CENTER,scroller);
 61
 62		JPanel panel2 = new JPanel(new BorderLayout());
 63		panel2.setBorder(new EmptyBorder(6,0,0,0));
 64		JPanel labelBox = new JPanel(new GridLayout(
 65			(mode == UPDATE ? 6 : 5),1,0,3));
 66		labelBox.setBorder(new EmptyBorder(0,0,3,12));
 67		labelBox.add(new JLabel(jEdit.getProperty("install-plugins"
 68			+ ".info.name"),SwingConstants.RIGHT));
 69		labelBox.add(new JLabel(jEdit.getProperty("install-plugins"
 70			+ ".info.author"),SwingConstants.RIGHT));
 71		labelBox.add(new JLabel(jEdit.getProperty("install-plugins"
 72			+ ".info.latest-version"),SwingConstants.RIGHT));
 73		if(mode == UPDATE)
 74		{
 75			labelBox.add(new JLabel(jEdit.getProperty("install-plugins"
 76				+ ".info.installed-version"),SwingConstants.RIGHT));
 77		}
 78		labelBox.add(new JLabel(jEdit.getProperty("install-plugins"
 79			+ ".info.updated"),SwingConstants.RIGHT));
 80		labelBox.add(new JLabel(jEdit.getProperty("install-plugins"
 81			+ ".info.description"),SwingConstants.RIGHT));
 82		panel2.add(BorderLayout.WEST,labelBox);
 83
 84		JPanel valueBox = new JPanel(new GridLayout(
 85			(mode == UPDATE ? 6 : 5),1,0,3));
 86		valueBox.setBorder(new EmptyBorder(0,0,3,0));
 87		valueBox.add(name = new JLabel());
 88		valueBox.add(author = new JLabel());
 89		valueBox.add(latestVersion = new JLabel());
 90		if(mode == UPDATE)
 91		{
 92			valueBox.add(installedVersion = new JLabel());
 93		}
 94		valueBox.add(updated = new JLabel());
 95		valueBox.add(Box.createGlue());
 96		panel2.add(BorderLayout.CENTER,valueBox);
 97
 98		JPanel panel3 = new JPanel(new BorderLayout(0,3));
 99		description = new JTextArea(6,30);
100		description.setEditable(false);
101		description.setLineWrap(true);
102		description.setWrapStyleWord(true);
103		panel3.add(BorderLayout.NORTH,new JScrollPane(description));
104		if(mode == INSTALL)
105		{
106			JPanel panel4 = new JPanel(new BorderLayout(0,3));
107
108			ButtonGroup grp = new ButtonGroup();
109			installUser = new JRadioButton();
110			String settings = jEdit.getSettingsDirectory();
111			if(settings == null)
112			{
113				settings = jEdit.getProperty("install-plugins.none");
114				installUser.setEnabled(false);
115			}
116			else
117			{
118				settings = MiscUtilities.constructPath(settings,"jars");
119				installUser.setEnabled(true);
120			}
121			String[] args = { settings };
122			installUser.setText(jEdit.getProperty("install-plugins.user",args));
123			grp.add(installUser);
124			panel4.add(BorderLayout.CENTER,installUser);
125
126			installSystem = new JRadioButton();
127			String jEditHome = jEdit.getJEditHome();
128			if(jEditHome == null)
129			{
130				jEditHome = jEdit.getProperty("install-plugins.none");
131				installSystem.setEnabled(false);
132			}
133			else
134			{
135				jEditHome = MiscUtilities.constructPath(jEditHome,"jars");
136				installSystem.setEnabled(true);
137			}
138			args[0] = jEditHome;
139			installSystem.setText(jEdit.getProperty("install-plugins.system",args));
140			grp.add(installSystem);
141			panel4.add(BorderLayout.SOUTH,installSystem);
142
143			if(installUser.isEnabled())
144				installUser.setSelected(true);
145			else
146				installSystem.setSelected(true);
147
148			panel3.add(BorderLayout.CENTER,panel4);
149		}
150
151		panel3.add(BorderLayout.SOUTH,downloadSource = new JCheckBox(
152			jEdit.getProperty("install-plugins.downloadSource")));
153		downloadSource.setSelected(jEdit.getBooleanProperty("install-plugins"
154			+ ".downloadSource.value"));
155
156		panel2.add(BorderLayout.SOUTH,panel3);
157
158		panel.add(BorderLayout.SOUTH,panel2);
159
160		content.add(BorderLayout.CENTER,panel);
161
162		Box box = new Box(BoxLayout.X_AXIS);
163
164		box.add(Box.createGlue());
165		install = new JButton(jEdit.getProperty("install-plugins.install"));
166		install.setEnabled(false);
167		getRootPane().setDefaultButton(install);
168		install.addActionListener(new ActionHandler());
169		box.add(install);
170		box.add(Box.createHorizontalStrut(6));
171
172		cancel = new JButton(jEdit.getProperty("common.cancel"));
173		cancel.addActionListener(new ActionHandler());
174		box.add(cancel);
175		box.add(Box.createHorizontalStrut(6));
176		box.add(Box.createGlue());
177
178		content.add(BorderLayout.SOUTH,box);
179
180		pack();
181		setLocationRelativeTo(dialog);
182		show();
183	}
184
185	public void ok()
186	{
187		jEdit.setBooleanProperty("install-plugins.downloadSource.value",
188			downloadSource.isSelected());
189		dispose();
190	}
191
192	public void cancel()
193	{
194		cancelled = true;
195
196		dispose();
197	}
198
199	void installPlugins(Roster roster)
200	{
201		if(cancelled)
202			return;
203
204		String installDirectory;
205		if(installUser == null || installUser.isSelected())
206		{
207			installDirectory = MiscUtilities.constructPath(
208				jEdit.getSettingsDirectory(),"jars");
209		}
210		else
211		{
212			installDirectory = MiscUtilities.constructPath(
213				jEdit.getJEditHome(),"jars");
214		}
215
216		Object[] selected = plugins.getCheckedValues();
217		for(int i = 0; i < selected.length; i++)
218		{
219			PluginList.Plugin plugin = (PluginList.Plugin)selected[i];
220			plugin.install(roster,installDirectory,downloadSource.isSelected());
221		}
222	}
223
224	// private members
225	private JCheckBoxList plugins;
226	private JLabel name;
227	private JLabel author;
228	private JLabel latestVersion;
229	private JLabel installedVersion;
230	private JLabel updated;
231	private JTextArea description;
232	private JRadioButton installUser;
233	private JRadioButton installSystem;
234	private JCheckBox downloadSource;
235
236	private JButton install;
237	private JButton cancel;
238
239	private boolean cancelled;
240	private Thread thread;
241
242	class ActionHandler implements ActionListener
243	{
244		public void actionPerformed(ActionEvent evt)
245		{
246			if(evt.getSource() == install)
247				ok();
248			else
249				cancel();
250		}
251	}
252
253	class ListHandler implements ListSelectionListener
254	{
255		public void valueChanged(ListSelectionEvent evt)
256		{
257			Object selected = plugins.getSelectedValue();
258			if(selected instanceof PluginList.Plugin)
259			{
260				install.setEnabled(true);
261
262				PluginList.Plugin plugin = (PluginList.Plugin)selected;
263				PluginList.Branch branch = plugin.getCompatibleBranch();
264				name.setText(plugin.name);
265				author.setText(plugin.author);
266				if(branch.obsolete)
267					latestVersion.setText(jEdit.getProperty(
268						"install-plugins.info.obsolete"));
269				else
270					latestVersion.setText(branch.version);
271				if(installedVersion != null)
272					installedVersion.setText(plugin.installedVersion);
273				updated.setText(branch.date);
274
275				StringBuffer buf = new StringBuffer();
276				for(int i = 0; i < branch.deps.size(); i++)
277				{
278					PluginList.Dependency dep = (PluginList.Dependency)
279						branch.deps.elementAt(i);
280					if(dep.what.equals("plugin")
281						&& !dep.isSatisfied())
282					{
283						if(buf.length() != 0)
284							buf.append(", ");
285
286						buf.append(dep.plugin);
287					}
288				}
289
290				description.setText(plugin.description
291					+ (buf.length() == 0 ? ""
292					: jEdit.getProperty("install-plugins.info"
293					+ ".also-install") + buf.toString()
294					+ (branch.obsolete ? jEdit.getProperty(
295					"install-plugins.info.obsolete-text") : "")));
296			}
297			else
298			{
299				install.setEnabled(false);
300
301				name.setText(null);
302				author.setText(null);
303				latestVersion.setText(null);
304				if(installedVersion != null)
305					installedVersion.setText(null);
306				updated.setText(null);
307				description.setText(null);
308			}
309		}
310	}
311}