PageRenderTime 41ms CodeModel.GetById 7ms RepoModel.GetById 1ms app.codeStats 0ms

/jEdit/tags/jedit-4-2-pre4/org/gjt/sp/jedit/pluginmgr/PluginListDownloadProgress.java

#
Java | 152 lines | 113 code | 20 blank | 19 comment | 3 complexity | 53fdbe670f3ea62b525cdb6d973174d6 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, 2002 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 org.gjt.sp.jedit.options.GlobalOptions;
  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(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.export-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. String ok = jEdit.getProperty("common.ok");
  90. String proxyButton = jEdit.getProperty(
  91. "plugin-list.ioerror.proxy-servers");
  92. int retVal = JOptionPane.showOptionDialog(window,
  93. jEdit.getProperty("plugin-list.ioerror.message",pp),
  94. jEdit.getProperty("plugin-list.ioerror.title"),
  95. JOptionPane.YES_NO_OPTION,
  96. JOptionPane.ERROR_MESSAGE,
  97. null,
  98. new Object[] {
  99. proxyButton,
  100. ok
  101. },
  102. ok);
  103. if(retVal == 0)
  104. new GlobalOptions(window,"firewall");
  105. }
  106. }
  107. }
  108. class ActionHandler implements ActionListener
  109. {
  110. public void actionPerformed(ActionEvent evt)
  111. {
  112. thread.stop();
  113. dispose();
  114. }
  115. }
  116. class WindowHandler extends WindowAdapter
  117. {
  118. boolean done;
  119. public void windowOpened(WindowEvent evt)
  120. {
  121. if(done)
  122. return;
  123. done = true;
  124. thread = new DownloadThread();
  125. thread.start();
  126. }
  127. public void windowClosing(WindowEvent evt)
  128. {
  129. thread.stop();
  130. }
  131. }
  132. }