PageRenderTime 36ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/jEdit/tags/jedit-4-2-pre4/org/gjt/sp/jedit/gui/IOProgressMonitor.java

#
Java | 201 lines | 137 code | 25 blank | 39 comment | 10 complexity | 3270d20f1530df3b729785cab3528a9c 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. * IOProgressMonitor.java - I/O progress monitor
  3. * :tabSize=8:indentSize=8:noTabs=false:
  4. * :folding=explicit:collapseFolds=1:
  5. *
  6. * Copyright (C) 2000, 2002 Slava Pestov
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License
  10. * as published by the Free Software Foundation; either version 2
  11. * of the License, or any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  21. */
  22. package org.gjt.sp.jedit.gui;
  23. //{{{ Imports
  24. import javax.swing.border.*;
  25. import javax.swing.*;
  26. import java.awt.event.*;
  27. import java.awt.*;
  28. import org.gjt.sp.jedit.io.VFSManager;
  29. import org.gjt.sp.jedit.*;
  30. import org.gjt.sp.util.*;
  31. //}}}
  32. public class IOProgressMonitor extends JPanel
  33. {
  34. //{{{ IOProgressMonitor constructor
  35. public IOProgressMonitor()
  36. {
  37. super(new BorderLayout());
  38. caption = new JLabel();
  39. updateCaption();
  40. add(BorderLayout.NORTH,caption);
  41. threads = new ThreadProgress[VFSManager.getIOThreadPool()
  42. .getThreadCount()];
  43. Box box = new Box(BoxLayout.Y_AXIS);
  44. for(int i = 0; i < threads.length; i++)
  45. {
  46. if(i != 0)
  47. box.add(Box.createVerticalStrut(6));
  48. threads[i] = new ThreadProgress(i);
  49. box.add(threads[i]);
  50. }
  51. JPanel threadPanel = new JPanel(new BorderLayout());
  52. threadPanel.setBorder(new EmptyBorder(6,6,6,6));
  53. threadPanel.add(BorderLayout.NORTH,box);
  54. add(BorderLayout.CENTER,new JScrollPane(threadPanel));
  55. workThreadHandler = new WorkThreadHandler();
  56. } //}}}
  57. //{{{ addNotify() method
  58. public void addNotify()
  59. {
  60. VFSManager.getIOThreadPool().addProgressListener(workThreadHandler);
  61. super.addNotify();
  62. } //}}}
  63. //{{{ removeNotify() method
  64. public void removeNotify()
  65. {
  66. VFSManager.getIOThreadPool().removeProgressListener(workThreadHandler);
  67. super.removeNotify();
  68. } //}}}
  69. //{{{ Private members
  70. //{{{ Instance variables
  71. private JLabel caption;
  72. private ThreadProgress[] threads;
  73. private WorkThreadHandler workThreadHandler;
  74. //}}}
  75. //{{{ updateCaption() method
  76. private void updateCaption()
  77. {
  78. String[] args = { String.valueOf(VFSManager.getIOThreadPool()
  79. .getRequestCount()) };
  80. caption.setText(jEdit.getProperty("io-progress-monitor.caption",args));
  81. } //}}}
  82. //}}}
  83. //{{{ WorkThreadHandler class
  84. class WorkThreadHandler implements WorkThreadProgressListener
  85. {
  86. public void statusUpdate(final WorkThreadPool pool, final int index)
  87. {
  88. SwingUtilities.invokeLater(new Runnable()
  89. {
  90. public void run()
  91. {
  92. updateCaption();
  93. threads[index].update();
  94. }
  95. });
  96. }
  97. public void progressUpdate(final WorkThreadPool pool, final int index)
  98. {
  99. SwingUtilities.invokeLater(new Runnable()
  100. {
  101. public void run()
  102. {
  103. updateCaption();
  104. threads[index].update();
  105. }
  106. });
  107. }
  108. } //}}}
  109. //{{{ ThreadProgress class
  110. class ThreadProgress extends JPanel
  111. {
  112. //{{{ ThreadProgress constructor
  113. public ThreadProgress(int index)
  114. {
  115. super(new BorderLayout(12,12));
  116. this.index = index;
  117. Box box = new Box(BoxLayout.Y_AXIS);
  118. box.add(Box.createGlue());
  119. box.add(progress = new JProgressBar());
  120. progress.setStringPainted(true);
  121. box.add(Box.createGlue());
  122. ThreadProgress.this.add(BorderLayout.CENTER,box);
  123. abort = new JButton(jEdit.getProperty("io-progress-monitor.abort"));
  124. abort.addActionListener(new ActionHandler());
  125. ThreadProgress.this.add(BorderLayout.EAST,abort);
  126. update();
  127. } //}}}
  128. //{{{ update() method
  129. public void update()
  130. {
  131. WorkThread thread = VFSManager.getIOThreadPool().getThread(index);
  132. if(thread.isRequestRunning())
  133. {
  134. abort.setEnabled(true);
  135. String status = thread.getStatus();
  136. if(status == null)
  137. status = "";
  138. progress.setString(status);
  139. progress.setMaximum(thread.getProgressMaximum());
  140. //System.err.println("value: " + thread.getProgressValue());
  141. progress.setValue(thread.getProgressValue());
  142. }
  143. else
  144. {
  145. abort.setEnabled(false);
  146. progress.setString(jEdit.getProperty("io-progress-monitor"
  147. + ".idle"));
  148. progress.setValue(0);
  149. }
  150. } //}}}
  151. //{{{ Private members
  152. private int index;
  153. private JProgressBar progress;
  154. private JButton abort;
  155. //}}}
  156. //{{{ ActionHandler class
  157. class ActionHandler implements ActionListener
  158. {
  159. public void actionPerformed(ActionEvent evt)
  160. {
  161. if(evt.getSource() == abort)
  162. {
  163. int result = GUIUtilities.confirm(
  164. IOProgressMonitor.this,"abort",null,
  165. JOptionPane.YES_NO_OPTION,
  166. JOptionPane.QUESTION_MESSAGE);
  167. if(result == JOptionPane.YES_OPTION)
  168. {
  169. VFSManager.getIOThreadPool().getThread(index)
  170. .abortCurrentRequest();
  171. }
  172. }
  173. }
  174. } //}}}
  175. } //}}}
  176. }