PageRenderTime 42ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

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

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