1 22 23 package org.gjt.sp.jedit.gui; 24 25 import javax.swing.border.*; 27 import javax.swing.*; 28 import java.awt.event.*; 29 import java.awt.*; 30 import org.gjt.sp.jedit.io.VFSManager; 31 import org.gjt.sp.jedit.*; 32 import org.gjt.sp.util.*; 33 35 41 public class IOProgressMonitor extends JPanel 42 { 43 public IOProgressMonitor() 45 { 46 super(new BorderLayout()); 47 caption = new JLabel(); 48 updateCaption(); 49 add(BorderLayout.NORTH,caption); 50 51 threads = new ThreadProgress[VFSManager.getIOThreadPool() 52 .getThreadCount()]; 53 54 Box box = new Box(BoxLayout.Y_AXIS); 55 for(int i = 0; i < threads.length; i++) 56 { 57 if(i != 0) 58 box.add(Box.createVerticalStrut(6)); 59 60 threads[i] = new ThreadProgress(i); 61 box.add(threads[i]); 62 } 63 64 JPanel threadPanel = new JPanel(new BorderLayout()); 65 threadPanel.setBorder(new EmptyBorder(6,6,6,6)); 66 threadPanel.add(BorderLayout.NORTH,box); 67 68 add(BorderLayout.CENTER,new JScrollPane(threadPanel)); 69 70 workThreadHandler = new WorkThreadHandler(); 71 } 73 public void addNotify() 75 { 76 VFSManager.getIOThreadPool().addProgressListener(workThreadHandler); 77 super.addNotify(); 78 } 80 public void removeNotify() 82 { 83 VFSManager.getIOThreadPool().removeProgressListener(workThreadHandler); 84 super.removeNotify(); 85 } 87 89 private JLabel caption; 91 private ThreadProgress[] threads; 92 private WorkThreadHandler workThreadHandler; 93 95 private void updateCaption() 97 { 98 String [] args = { String.valueOf(VFSManager.getIOThreadPool() 99 .getRequestCount()) }; 100 caption.setText(jEdit.getProperty("io-progress-monitor.caption",args)); 101 } 103 105 class WorkThreadHandler implements WorkThreadProgressListener 107 { 108 public void statusUpdate(final WorkThreadPool threadPool, final int threadIndex) 109 { 110 SwingUtilities.invokeLater(new Runnable () 111 { 112 public void run() 113 { 114 updateCaption(); 115 threads[threadIndex].update(); 116 } 117 }); 118 } 119 120 public void progressUpdate(final WorkThreadPool threadPool, final int threadIndex) 121 { 122 SwingUtilities.invokeLater(new Runnable () 123 { 124 public void run() 125 { 126 updateCaption(); 127 threads[threadIndex].update(); 128 } 129 }); 130 } 131 } 133 class ThreadProgress extends JPanel 135 { 136 public ThreadProgress(int index) 138 { 139 super(new BorderLayout(12,12)); 140 141 this.index = index; 142 143 Box box = new Box(BoxLayout.Y_AXIS); 144 box.add(Box.createGlue()); 145 box.add(progress = new JProgressBar()); 146 progress.setStringPainted(true); 147 box.add(Box.createGlue()); 148 ThreadProgress.this.add(BorderLayout.CENTER,box); 149 150 abort = new JButton(jEdit.getProperty("io-progress-monitor.abort")); 151 abort.addActionListener(new ActionHandler()); 152 ThreadProgress.this.add(BorderLayout.EAST,abort); 153 154 update(); 155 } 157 public void update() 159 { 160 WorkThread thread = VFSManager.getIOThreadPool().getThread(index); 161 if(thread.isRequestRunning()) 162 { 163 if (progress.isIndeterminate()) 164 { 165 if (thread.getProgressMaximum() != 0) 166 progress.setIndeterminate(false); 167 } 168 else if (thread.getProgressMaximum() == 0) 169 progress.setIndeterminate(true); 170 171 abort.setEnabled(true); 172 String status = thread.getStatus(); 173 if(status == null) 174 status = ""; 175 progress.setString(status); 176 progress.setMaximum(thread.getProgressMaximum()); 177 progress.setValue(thread.getProgressValue()); 179 } 180 else 181 { 182 abort.setEnabled(false); 183 progress.setString(jEdit.getProperty("io-progress-monitor" 184 + ".idle")); 185 progress.setIndeterminate(false); 186 progress.setValue(0); 187 } 188 } 190 private int index; 192 private JProgressBar progress; 193 private JButton abort; 194 196 class ActionHandler implements ActionListener 198 { 199 public void actionPerformed(ActionEvent evt) 200 { 201 if(evt.getSource() == abort) 202 { 203 int result = GUIUtilities.confirm( 204 IOProgressMonitor.this,"abort",null, 205 JOptionPane.YES_NO_OPTION, 206 JOptionPane.QUESTION_MESSAGE); 207 if(result == JOptionPane.YES_OPTION) 208 { 209 VFSManager.getIOThreadPool().getThread(index) 210 .abortCurrentRequest(); 211 } 212 } 213 } 214 } } } 217 | Popular Tags |