1 19 package org.openharmonise.him.window; 20 21 import java.awt.*; 22 23 import javax.swing.*; 24 import javax.swing.border.*; 25 26 import org.openharmonise.him.context.StateHandler; 27 import org.openharmonise.vfs.context.*; 28 29 30 39 public class StatusBar extends JPanel implements ContextListener, Runnable { 40 41 44 private static StatusBar m_instance = null; 45 46 49 private JProgressBar m_progressBar = null; 50 51 54 private boolean m_bProgressMoving = false; 55 56 59 private boolean m_bFullPrint = false; 60 61 64 private JLabel m_infoText = null; 65 66 70 private StatusBar() { 71 super(); 72 this.setup(); 73 } 74 75 78 private StatusBar(boolean arg0) { 79 super(arg0); 80 } 81 82 85 private StatusBar(LayoutManager arg0) { 86 super(arg0); 87 } 88 89 93 private StatusBar(LayoutManager arg0, boolean arg1) { 94 super(arg0, arg1); 95 } 96 97 102 public static StatusBar getInstance() { 103 if(m_instance==null) { 104 m_instance = new StatusBar(); 105 } 106 107 return m_instance; 108 } 109 110 114 private void setup() { 115 new Thread (this).start(); 116 ContextHandler.getInstance().addListener(ContextType.CONTEXT_WAIT, this); 117 118 this.setPreferredSize( new Dimension(200,20)); 119 this.setBorder( BorderFactory.createBevelBorder(BevelBorder.LOWERED) ); 120 this.setLayout(new BorderLayout()); 121 122 this.m_infoText = new JLabel("Logging in to services..."); 123 String fontName = "Dialog"; 124 int fontSize = 10; 125 Font font = new Font(fontName, Font.PLAIN, fontSize); 126 this.m_infoText.setFont(font); 127 this.m_infoText.setPreferredSize( new Dimension(300,20)); 128 this.add( this.m_infoText, BorderLayout.WEST ); 129 130 this.m_progressBar = new JProgressBar(0,200); 131 this.m_progressBar.setIndeterminate(false); 132 this.add(this.m_progressBar, BorderLayout.EAST); 133 } 134 135 138 public void contextMessage(ContextEvent ce) { 139 if(ce.CONTEXT_TYPE==ContextType.CONTEXT_WAIT) { 140 if(ce.getMessage().equals("ON")) { 141 if(StateHandler.getInstance().getBarText()!=null) { 142 this.m_infoText.setText(StateHandler.getInstance().getBarText()); 143 } 144 this.revalidate(); 145 this.validate(); 146 this.paint(this.getGraphics()); 147 this.m_bProgressMoving = true; 148 this.m_bFullPrint = true; 149 } else { 150 this.m_infoText.setText(""); 151 this.m_bProgressMoving = false; 152 this.m_progressBar.setValue(0); 153 this.revalidate(); 154 this.validate(); 155 this.paint(this.getGraphics()); 156 } 157 } 158 } 159 160 163 public void run() { 164 try { 165 while(true) { 166 if(this.m_bProgressMoving) { 167 if(this.m_bFullPrint) { 168 this.print(this.getGraphics()); 169 this.m_bFullPrint=false; 170 } else { 171 if(this.m_progressBar.getValue()>=this.m_progressBar.getMaximum()) { 172 this.m_progressBar.setValue(10); 173 } else { 174 this.m_progressBar.setValue(this.m_progressBar.getValue()+1); 175 } 176 this.m_progressBar.print(this.m_progressBar.getGraphics()); 177 } 178 } else { 179 } 180 Thread.sleep(100); 181 } 182 } catch (InterruptedException e) { 183 e.printStackTrace(System.err); 184 } 185 } 186 } 187
| Popular Tags
|