PageRenderTime 178ms CodeModel.GetById 170ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/jEdit/tags/jedit-4-0-pre3/jars/LatestVersion/LatestVersionPlugin.java

#
Java | 90 lines | 61 code | 11 blank | 18 comment | 11 complexity | 82b3936a9f0aa73597a7fcfe7c29b9f3 MD5 | raw file
 1/*
 2 * LatestVersionPlugin.java - Latest Version Check Plugin
 3 * Copyright (C) 1999, 2000 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
20import javax.swing.JOptionPane;
21import java.awt.event.ActionEvent;
22import java.io.*;
23import java.net.URL;
24import java.util.Vector;
25import org.gjt.sp.jedit.*;
26
27public class LatestVersionPlugin extends EditPlugin
28{
29	public void createMenuItems(Vector menuItems)
30	{
31		menuItems.addElement(GUIUtilities.loadMenuItem("version-check"));
32	}
33
34	public static void doVersionCheck(View view)
35	{
36		view.showWaitCursor();
37
38		try
39		{
40			URL url = new URL(jEdit.getProperty(
41				"version-check.url"));
42			InputStream in = url.openStream();
43			BufferedReader bin = new BufferedReader(
44				new InputStreamReader(in));
45
46			String line;
47			String version = null;
48			String build = null;
49			while((line = bin.readLine()) != null)
50			{
51				if(line.startsWith(".version"))
52					version = line.substring(8).trim();
53				else if(line.startsWith(".build"))
54					build = line.substring(6).trim();
55			}
56
57			bin.close();
58
59			if(version != null && build != null)
60			{
61				if(jEdit.getBuild().compareTo(build) < 0)
62					newVersionAvailable(view,version,url);
63				else
64				{
65					GUIUtilities.message(view,"version-check"
66						+ ".up-to-date",new String[0]);
67				}
68			}
69		}
70		catch(IOException e)
71		{
72			String[] args = { jEdit.getProperty("version-check.url"),
73				e.toString() };
74			GUIUtilities.error(view,"read-error",args);
75		}
76
77		view.hideWaitCursor();
78	}
79
80	public static void newVersionAvailable(View view, String version, URL url)
81	{
82		String[] args = { version };
83
84		int result = GUIUtilities.confirm(view,"version-check.new-version",
85			args,JOptionPane.YES_NO_OPTION,JOptionPane.INFORMATION_MESSAGE);
86
87		if(result == JOptionPane.YES_OPTION)
88			jEdit.openFile(view,url.toString());
89	}
90}