1 22 23 package org.gjt.sp.jedit.pluginmgr; 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.*; 31 import org.gjt.sp.util.ProgressObserver; 32 34 class PluginManagerProgress extends JDialog implements ProgressObserver 35 { 36 public PluginManagerProgress(PluginManager dialog, Roster roster) 38 { 39 super(dialog,jEdit.getProperty("plugin-manager.progress"),true); 40 41 this.roster = roster; 42 43 JPanel content = new JPanel(new BorderLayout(12,12)); 44 content.setBorder(new EmptyBorder(12,12,12,12)); 45 setContentPane(content); 46 47 progress = new JProgressBar(); 48 progress.setStringPainted(true); 49 progress.setString(jEdit.getProperty("plugin-manager.progress")); 50 51 int maximum = 0; 52 count = roster.getOperationCount(); 53 for(int i = 0; i < count; i++) 54 { 55 maximum += roster.getOperation(i).getMaximum(); 56 } 57 58 progress.setMaximum(maximum); 59 content.add(BorderLayout.NORTH,progress); 60 61 stop = new JButton(jEdit.getProperty("plugin-manager.progress.stop")); 62 stop.addActionListener(new ActionHandler()); 63 JPanel panel = new JPanel(new FlowLayout( 64 FlowLayout.CENTER,0,0)); 65 panel.add(stop); 66 content.add(BorderLayout.CENTER,panel); 67 68 addWindowListener(new WindowHandler()); 69 70 pack(); 71 setLocationRelativeTo(dialog); 72 setVisible(true); 73 } 75 77 81 public void setValue(final int value) 82 { 83 SwingUtilities.invokeLater(new Runnable () 84 { 85 public void run() 86 { 87 progress.setValue(valueSoFar + value); 88 } 89 }); 90 } 92 99 public void setValue(final long value) 100 { 101 SwingUtilities.invokeLater(new Runnable () 102 { 103 public void run() 104 { 105 progress.setValue(valueSoFar + (int) value); 106 } 107 }); 108 } 110 117 public void setMaximum(long value) 118 { 119 } 121 128 public void setStatus(String status) 129 { 130 setTitle(status); 131 progress.setString(status); 132 } 134 public void done() 136 { 137 try 138 { 139 if(done == count) 140 { 141 SwingUtilities.invokeAndWait(new Runnable () 142 { 143 public void run() 144 { 145 dispose(); 146 } 147 }); 148 } 149 else 150 { 151 SwingUtilities.invokeAndWait(new Runnable () 152 { 153 public void run() 154 { 155 valueSoFar += roster.getOperation(done - 1) 156 .getMaximum(); 157 progress.setValue(valueSoFar); 158 done++; 159 } 160 }); 161 } 162 } 163 catch(Exception e) 164 { 165 } 166 } 168 170 private Thread thread; 172 173 private JProgressBar progress; 174 private JButton stop; 175 private int count; 176 private int done = 1; 177 178 private int valueSoFar; 180 181 private Roster roster; 182 184 class ActionHandler implements ActionListener 186 { 187 public void actionPerformed(ActionEvent evt) 188 { 189 if(evt.getSource() == stop) 190 { 191 thread.stop(); 192 dispose(); 193 } 194 } 195 } 197 class WindowHandler extends WindowAdapter 199 { 200 boolean done; 201 202 public void windowOpened(WindowEvent evt) 203 { 204 if(done) 205 return; 206 207 done = true; 208 thread = new RosterThread(); 209 thread.start(); 210 } 211 212 public void windowClosing(WindowEvent evt) 213 { 214 thread.stop(); 215 dispose(); 216 } 217 } 219 class RosterThread extends Thread 221 { 222 RosterThread() 223 { 224 super("Plugin manager thread"); 225 } 226 227 public void run() 228 { 229 roster.performOperationsInWorkThread(PluginManagerProgress.this); 230 } 231 } 233 } 235 | Popular Tags |