PageRenderTime 51ms CodeModel.GetById 23ms RepoModel.GetById 0ms 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
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. * 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. package org.gjt.sp.jedit.pluginmgr;
  20. import com.microstar.xml.XmlException;
  21. import javax.swing.border.*;
  22. import javax.swing.*;
  23. import java.awt.event.*;
  24. import java.awt.*;
  25. import java.io.InterruptedIOException;
  26. import org.gjt.sp.jedit.*;
  27. import org.gjt.sp.util.Log;
  28. class PluginListDownloadProgress extends JDialog
  29. {
  30. PluginListDownloadProgress(PluginManager window)
  31. {
  32. super(JOptionPane.getFrameForComponent(window),
  33. jEdit.getProperty("plugin-list.progress.title"),true);
  34. this.window = window;
  35. JPanel content = new JPanel(new BorderLayout());
  36. content.setBorder(new EmptyBorder(12,12,12,12));
  37. setContentPane(content);
  38. JLabel caption = new JLabel(jEdit.getProperty("plugin-list.progress.caption"));
  39. caption.setBorder(new EmptyBorder(0,0,12,0));
  40. content.add(BorderLayout.NORTH,caption);
  41. Box box = new Box(BoxLayout.X_AXIS);
  42. box.add(Box.createGlue());
  43. JButton stop = new JButton(jEdit.getProperty("plugin-list.progress.stop"));
  44. stop.addActionListener(new ActionHandler());
  45. stop.setMaximumSize(stop.getPreferredSize());
  46. box.add(stop);
  47. box.add(Box.createGlue());
  48. content.add(BorderLayout.CENTER,box);
  49. addWindowListener(new WindowHandler());
  50. setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
  51. pack();
  52. setLocationRelativeTo(window);
  53. setResizable(false);
  54. show();
  55. }
  56. PluginList getPluginList()
  57. {
  58. return list;
  59. }
  60. // private members
  61. private PluginManager window;
  62. private PluginList list;
  63. private DownloadThread thread;
  64. class DownloadThread extends Thread
  65. {
  66. public void run()
  67. {
  68. try
  69. {
  70. list = new PluginList();
  71. dispose();
  72. }
  73. catch(XmlException xe)
  74. {
  75. dispose();
  76. int line = xe.getLine();
  77. String path = jEdit.getProperty("plugin-manager.url");
  78. String message = xe.getMessage();
  79. Log.log(Log.ERROR,this,path + ":" + line
  80. + ": " + message);
  81. String[] pp = { path, String.valueOf(line), message };
  82. GUIUtilities.error(window,"plugin-list.xmlerror",pp);
  83. }
  84. catch(Exception e)
  85. {
  86. dispose();
  87. Log.log(Log.ERROR,this,e);
  88. String[] pp = { e.toString() };
  89. GUIUtilities.error(window,"plugin-list.ioerror",pp);
  90. }
  91. }
  92. }
  93. class ActionHandler implements ActionListener
  94. {
  95. public void actionPerformed(ActionEvent evt)
  96. {
  97. thread.stop();
  98. dispose();
  99. }
  100. }
  101. class WindowHandler extends WindowAdapter
  102. {
  103. boolean done;
  104. public void windowActivated(WindowEvent evt)
  105. {
  106. if(done)
  107. return;
  108. done = true;
  109. thread = new DownloadThread();
  110. thread.start();
  111. }
  112. public void windowClosing(WindowEvent evt)
  113. {
  114. thread.stop();
  115. }
  116. }
  117. }