PageRenderTime 51ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/jEdit/tags/jedit-4-1-pre5/org/gjt/sp/jedit/gui/IOProgressMonitor.java

#
Java | 199 lines | 135 code | 25 blank | 39 comment | 8 complexity | 103f135804a33231e11070a9d4907bd5 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.event.*;
  26. import javax.swing.*;
  27. import java.awt.event.*;
  28. import java.awt.*;
  29. import org.gjt.sp.jedit.io.VFSManager;
  30. import org.gjt.sp.jedit.*;
  31. import org.gjt.sp.util.*;
  32. //}}}
  33. public class IOProgressMonitor extends JPanel
  34. {
  35. //{{{ IOProgressMonitor constructor
  36. public IOProgressMonitor()
  37. {
  38. super(new BorderLayout());
  39. caption = new JLabel();
  40. updateCaption();
  41. add(BorderLayout.NORTH,caption);
  42. threads = new ThreadProgress[VFSManager.getIOThreadPool()
  43. .getThreadCount()];
  44. Box box = new Box(BoxLayout.Y_AXIS);
  45. for(int i = 0; i < threads.length; i++)
  46. {
  47. if(i != 0)
  48. box.add(Box.createVerticalStrut(6));
  49. threads[i] = new ThreadProgress(i);
  50. box.add(threads[i]);
  51. }
  52. JPanel threadPanel = new JPanel(new BorderLayout());
  53. threadPanel.setBorder(new EmptyBorder(6,6,6,6));
  54. threadPanel.add(BorderLayout.NORTH,box);
  55. add(BorderLayout.CENTER,new JScrollPane(threadPanel));
  56. workThreadHandler = new WorkThreadHandler();
  57. } //}}}
  58. //{{{ addNotify() method
  59. public void addNotify()
  60. {
  61. VFSManager.getIOThreadPool().addProgressListener(workThreadHandler);
  62. super.addNotify();
  63. } //}}}
  64. //{{{ removeNotify() method
  65. public void removeNotify()
  66. {
  67. VFSManager.getIOThreadPool().removeProgressListener(workThreadHandler);
  68. super.removeNotify();
  69. } //}}}
  70. //{{{ Private members
  71. //{{{ Instance variables
  72. private JLabel caption;
  73. private ThreadProgress[] threads;
  74. private WorkThreadHandler workThreadHandler;
  75. //}}}
  76. //{{{ updateCaption() method
  77. private void updateCaption()
  78. {
  79. String[] args = { String.valueOf(VFSManager.getIOThreadPool()
  80. .getRequestCount()) };
  81. caption.setText(jEdit.getProperty("io-progress-monitor.caption",args));
  82. } //}}}
  83. //}}}
  84. //{{{ WorkThreadHandler class
  85. class WorkThreadHandler implements WorkThreadProgressListener
  86. {
  87. public void statusUpdate(final WorkThreadPool pool, final int index)
  88. {
  89. SwingUtilities.invokeLater(new Runnable()
  90. {
  91. public void run()
  92. {
  93. updateCaption();
  94. threads[index].update();
  95. }
  96. });
  97. }
  98. public void progressUpdate(final WorkThreadPool pool, final int index)
  99. {
  100. SwingUtilities.invokeLater(new Runnable()
  101. {
  102. public void run()
  103. {
  104. updateCaption();
  105. threads[index].update();
  106. }
  107. });
  108. }
  109. } //}}}
  110. //{{{ ThreadProgress class
  111. class ThreadProgress extends JPanel
  112. {
  113. //{{{ ThreadProgress constructor
  114. public ThreadProgress(int index)
  115. {
  116. super(new BorderLayout(12,12));
  117. this.index = index;
  118. Box box = new Box(BoxLayout.Y_AXIS);
  119. box.add(Box.createGlue());
  120. box.add(progress = new JProgressBar());
  121. progress.setStringPainted(true);
  122. box.add(Box.createGlue());
  123. ThreadProgress.this.add(BorderLayout.CENTER,box);
  124. abort = new JButton(jEdit.getProperty("io-progress-monitor.abort"));
  125. abort.addActionListener(new ActionHandler());
  126. ThreadProgress.this.add(BorderLayout.EAST,abort);
  127. update();
  128. } //}}}
  129. //{{{ update() method
  130. public void update()
  131. {
  132. WorkThread thread = VFSManager.getIOThreadPool().getThread(index);
  133. if(thread.isRequestRunning())
  134. {
  135. abort.setEnabled(true);
  136. progress.setString(thread.getStatus());
  137. progress.setMaximum(thread.getProgressMaximum());
  138. //System.err.println("value: " + thread.getProgressValue());
  139. progress.setValue(thread.getProgressValue());
  140. }
  141. else
  142. {
  143. abort.setEnabled(false);
  144. progress.setString(jEdit.getProperty("io-progress-monitor"
  145. + ".idle"));
  146. progress.setValue(0);
  147. }
  148. } //}}}
  149. //{{{ Private members
  150. private int index;
  151. private JProgressBar progress;
  152. private JButton abort;
  153. //}}}
  154. //{{{ ActionHandler class
  155. class ActionHandler implements ActionListener
  156. {
  157. public void actionPerformed(ActionEvent evt)
  158. {
  159. if(evt.getSource() == abort)
  160. {
  161. int result = GUIUtilities.confirm(
  162. IOProgressMonitor.this,"abort",null,
  163. JOptionPane.YES_NO_OPTION,
  164. JOptionPane.QUESTION_MESSAGE);
  165. if(result == JOptionPane.YES_OPTION)
  166. {
  167. VFSManager.getIOThreadPool().getThread(index)
  168. .abortCurrentRequest();
  169. }
  170. }
  171. }
  172. } //}}}
  173. } //}}}
  174. }