1 14 package org.compiere.apps; 15 16 import javax.swing.*; 17 import java.awt.*; 18 import java.awt.event.*; 19 20 import org.compiere.plaf.*; 21 import org.compiere.swing.*; 22 23 import org.compiere.util.*; 24 25 31 public class Waiting extends JDialog implements ActionListener 32 { 33 40 public Waiting (Frame owner, String text, boolean canNotWait, int timer) 41 { 42 super(owner, Msg.getMsg(Env.getCtx(), "Processing")); 43 init (text, canNotWait, timer); 44 } 46 53 public Waiting (Dialog owner, String text, boolean canNotWait, int timer) 54 { 55 super(owner, Msg.getMsg(Env.getCtx(), "Processing")); 56 init (text, canNotWait, timer); 57 } 59 65 private void init (String text, boolean canNotWait, int timer) 66 { 67 Log.trace(Log.l6_Database, "Waiting.init", text + " - Sec=" + timer); 68 if (timer == 1) 70 return; 71 72 try 73 { 74 jbInit(); 75 setText (text); 76 if (!canNotWait) 77 bDoNotWait.setVisible(false); 78 } 79 catch(Exception e) 80 { 81 Log.error ("Waiting", e); 82 } 83 progressBar.setMinimum(0); 85 progressBar.setMaximum(timer < 5 ? 10 : timer); 87 m_timer = new Timer (1000, this); m_timer.start(); 90 AEnv.showCenterWindow(getOwner(), this); 91 } 93 private int m_timervalue = 0; 94 private Timer m_timer; 95 96 private CPanel southPanel = new CPanel(); 97 private CButton bDoNotWait = new CButton(); 98 private CLabel infoLabel = new CLabel(); 99 private FlowLayout southLayout = new FlowLayout(); 100 private CPanel mainPanel = new CPanel(); 101 private JProgressBar progressBar = new JProgressBar(); 102 103 107 private void jbInit() throws Exception 108 { 109 CompiereColor.setBackground(this); 110 this.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); 111 this.setResizable(false); 112 this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); 113 114 this.getContentPane().add(Box.createVerticalStrut(8), BorderLayout.NORTH); 115 this.getContentPane().add(Box.createHorizontalStrut(8), BorderLayout.WEST); 116 this.getContentPane().add(Box.createVerticalStrut(8), BorderLayout.SOUTH); 117 this.getContentPane().add(Box.createHorizontalStrut(8), BorderLayout.EAST); 118 mainPanel.setLayout(new BorderLayout(5,5)); 119 this.getContentPane().add(mainPanel, BorderLayout.CENTER); 120 infoLabel.setFont(new java.awt.Font ("Dialog", 3, 14)); 122 infoLabel.setHorizontalAlignment(SwingConstants.CENTER); 123 infoLabel.setHorizontalTextPosition(SwingConstants.RIGHT); 124 infoLabel.setIcon(Env.getImageIcon("C10030.gif")); 125 infoLabel.setIconTextGap(10); 126 mainPanel.add(infoLabel, BorderLayout.NORTH); 127 mainPanel.add(progressBar, BorderLayout.CENTER); 128 } 137 141 public void setText (String text) 142 { 143 infoLabel.setText(text); 144 } 146 150 public void actionPerformed (ActionEvent e) 151 { 152 if (e.getSource() == bDoNotWait) 153 doNotWait(); 154 progressBar.setValue(m_timervalue++); 156 if (m_timervalue > progressBar.getMaximum()) 157 m_timervalue = progressBar.getMinimum(); 158 } 161 165 public void setTimerEstimate (int max) 166 { 167 progressBar.setMaximum(max); 168 } 170 174 public void doNotWait() 175 { 176 177 dispose(); 178 } 180 183 public void dispose() 184 { 185 if (m_timer != null) 186 m_timer.stop(); 187 m_timer = null; 188 super.dispose(); 189 } 191 } | Popular Tags |