PageRenderTime 425ms CodeModel.GetById 419ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

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

#
Java | 135 lines | 98 code | 18 blank | 19 comment | 1 complexity | 1d6f1aad0cd67beef47d37bac54240c5 MD5 | raw file
  1/*
  2 * PluginListDownloadProgress.java - Plugin list download progress dialog
  3 * Copyright (C) 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 com.microstar.xml.XmlException;
 23import javax.swing.border.*;
 24import javax.swing.*;
 25import java.awt.event.*;
 26import java.awt.*;
 27import java.io.InterruptedIOException;
 28import org.gjt.sp.jedit.*;
 29import org.gjt.sp.util.Log;
 30
 31class PluginListDownloadProgress extends JDialog
 32{
 33	PluginListDownloadProgress(PluginManager window)
 34	{
 35		super(JOptionPane.getFrameForComponent(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.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				GUIUtilities.error(window,"plugin-list.ioerror",pp);
103			}
104		}
105	}
106
107	class ActionHandler implements ActionListener
108	{
109		public void actionPerformed(ActionEvent evt)
110		{
111			thread.stop();
112			dispose();
113		}
114	}
115
116	class WindowHandler extends WindowAdapter
117	{
118		boolean done;
119
120		public void windowActivated(WindowEvent evt)
121		{
122			if(done)
123				return;
124
125			done = true;
126			thread = new DownloadThread();
127			thread.start();
128		}
129
130		public void windowClosing(WindowEvent evt)
131		{
132			thread.stop();
133		}
134	}
135}