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