/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
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
- /*
- * LatestVersionPlugin.java - Latest Version Check Plugin
- * Copyright (C) 1999, 2000 Slava Pestov
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- */
- import javax.swing.JOptionPane;
- import java.awt.event.ActionEvent;
- import java.io.*;
- import java.net.URL;
- import java.util.Vector;
- import org.gjt.sp.jedit.*;
- public class LatestVersionPlugin extends EditPlugin
- {
- public void createMenuItems(Vector menuItems)
- {
- menuItems.addElement(GUIUtilities.loadMenuItem("version-check"));
- }
- public static void doVersionCheck(View view)
- {
- view.showWaitCursor();
- try
- {
- URL url = new URL(jEdit.getProperty(
- "version-check.url"));
- InputStream in = url.openStream();
- BufferedReader bin = new BufferedReader(
- new InputStreamReader(in));
- String line;
- String version = null;
- String build = null;
- while((line = bin.readLine()) != null)
- {
- if(line.startsWith(".version"))
- version = line.substring(8).trim();
- else if(line.startsWith(".build"))
- build = line.substring(6).trim();
- }
- bin.close();
- if(version != null && build != null)
- {
- if(jEdit.getBuild().compareTo(build) < 0)
- newVersionAvailable(view,version,url);
- else
- {
- GUIUtilities.message(view,"version-check"
- + ".up-to-date",new String[0]);
- }
- }
- }
- catch(IOException e)
- {
- String[] args = { jEdit.getProperty("version-check.url"),
- e.toString() };
- GUIUtilities.error(view,"read-error",args);
- }
- view.hideWaitCursor();
- }
- public static void newVersionAvailable(View view, String version, URL url)
- {
- String[] args = { version };
- int result = GUIUtilities.confirm(view,"version-check.new-version",
- args,JOptionPane.YES_NO_OPTION,JOptionPane.INFORMATION_MESSAGE);
- if(result == JOptionPane.YES_OPTION)
- jEdit.openFile(view,url.toString());
- }
- }