PageRenderTime 102ms CodeModel.GetById 88ms app.highlight 11ms RepoModel.GetById 1ms app.codeStats 0ms

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

#
Java | 152 lines | 113 code | 20 blank | 19 comment | 3 complexity | 53fdbe670f3ea62b525cdb6d973174d6 MD5 | raw file
  1/*
  2 * PluginListDownloadProgress.java - Plugin list download progress dialog
  3 * Copyright (C) 2001, 2002 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 com.microstar.xml.XmlException;
 23import javax.swing.border.*;
 24import javax.swing.*;
 25import java.awt.event.*;
 26import java.awt.*;
 27import org.gjt.sp.jedit.options.GlobalOptions;
 28import org.gjt.sp.jedit.*;
 29import org.gjt.sp.util.Log;
 30
 31class PluginListDownloadProgress extends JDialog
 32{
 33	PluginListDownloadProgress(PluginManager window)
 34	{
 35		super(window,
 36			jEdit.getProperty("plugin-list.progress.title"),true);
 37
 38		this.window = window;
 39
 40		JPanel content = new JPanel(new BorderLayout());
 41		content.setBorder(new EmptyBorder(12,12,12,12));
 42		setContentPane(content);
 43
 44		JLabel caption = new JLabel(jEdit.getProperty("plugin-list.progress.caption"));
 45		caption.setBorder(new EmptyBorder(0,0,12,0));
 46		content.add(BorderLayout.NORTH,caption);
 47
 48		Box box = new Box(BoxLayout.X_AXIS);
 49		box.add(Box.createGlue());
 50		JButton stop = new JButton(jEdit.getProperty("plugin-list.progress.stop"));
 51		stop.addActionListener(new ActionHandler());
 52		stop.setMaximumSize(stop.getPreferredSize());
 53		box.add(stop);
 54		box.add(Box.createGlue());
 55		content.add(BorderLayout.CENTER,box);
 56
 57		addWindowListener(new WindowHandler());
 58		setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
 59		pack();
 60		setLocationRelativeTo(window);
 61		setResizable(false);
 62		show();
 63	}
 64
 65	PluginList getPluginList()
 66	{
 67		return list;
 68	}
 69
 70	// private members
 71	private PluginManager window;
 72	private PluginList list;
 73	private DownloadThread thread;
 74
 75	class DownloadThread extends Thread
 76	{
 77		public void run()
 78		{
 79			try
 80			{
 81				list = new PluginList();
 82				dispose();
 83			}
 84			catch(XmlException xe)
 85			{
 86				dispose();
 87
 88				int line = xe.getLine();
 89				String path = jEdit.getProperty("plugin-manager.export-url");
 90				String message = xe.getMessage();
 91				Log.log(Log.ERROR,this,path + ":" + line
 92					+ ": " + message);
 93				String[] pp = { path, String.valueOf(line), message };
 94				GUIUtilities.error(window,"plugin-list.xmlerror",pp);
 95			}
 96			catch(Exception e)
 97			{
 98				dispose();
 99
100				Log.log(Log.ERROR,this,e);
101				String[] pp = { e.toString() };
102
103				String ok = jEdit.getProperty("common.ok");
104				String proxyButton = jEdit.getProperty(
105					"plugin-list.ioerror.proxy-servers");
106				int retVal = JOptionPane.showOptionDialog(window,
107					jEdit.getProperty("plugin-list.ioerror.message",pp),
108					jEdit.getProperty("plugin-list.ioerror.title"),
109					JOptionPane.YES_NO_OPTION,
110					JOptionPane.ERROR_MESSAGE,
111					null,
112					new Object[] {
113						proxyButton,
114						ok
115					},
116					ok);
117
118				if(retVal == 0)
119					new GlobalOptions(window,"firewall");
120			}
121		}
122	}
123
124	class ActionHandler implements ActionListener
125	{
126		public void actionPerformed(ActionEvent evt)
127		{
128			thread.stop();
129			dispose();
130		}
131	}
132
133	class WindowHandler extends WindowAdapter
134	{
135		boolean done;
136
137		public void windowOpened(WindowEvent evt)
138		{
139			if(done)
140				return;
141
142			done = true;
143			thread = new DownloadThread();
144			thread.start();
145		}
146
147		public void windowClosing(WindowEvent evt)
148		{
149			thread.stop();
150		}
151	}
152}