1 14 package org.compiere.apps; 15 16 import java.awt.event.*; 17 import javax.swing.*; 18 import java.awt.*; 19 20 import org.compiere.util.*; 21 import org.compiere.plaf.*; 22 23 29 public class AGlassPane extends JPanel implements MouseListener, ActionListener 30 { 31 34 public AGlassPane() 35 { 36 this.setOpaque(false); 37 this.setVisible(false); 38 this.addMouseListener(this); 39 } 41 42 public static Image s_image = Env.getImage("C10030.gif"); 43 44 public static Font s_font = new Font("Dialog", 3, 14); 45 46 public static Color s_color = CompierePLAF.getTextColor_OK(); 47 48 49 private static final int GAP = 4; 50 51 52 private String m_message = Msg.getMsg(Env.getCtx(), "Processing"); 53 54 55 private Timer m_timer; 56 57 private int m_timervalue = 0; 58 private int m_timermax = 0; 59 60 64 public void setMessage(String AD_Message) 65 { 66 if (AD_Message == null) 67 m_message = Msg.getMsg(Env.getCtx(), "Processing"); 68 else if (AD_Message.length() == 0) 69 m_message = AD_Message; 70 else 71 m_message = Msg.getMsg(Env.getCtx(), AD_Message); 72 if (isVisible()) 73 repaint(); 74 } 76 80 public String getMessage() 81 { 82 return m_message; 83 } 85 86 87 91 public void setBusyTimer (int time) 92 { 93 Log.trace(Log.l4_Data, "AGlassPane.setBusyTimer - " + time); 94 if (time < 2) 96 { 97 m_timermax = 0; 98 if (isVisible()) 99 repaint(); 100 return; 101 } 102 103 m_timermax = time; 104 m_timervalue = 0; 105 106 m_timer = new Timer (1000, this); m_timer.start(); 109 110 if (!isVisible()) 111 setVisible(true); 112 repaint(); 113 } 115 119 public void actionPerformed (ActionEvent e) 120 { 121 if (m_timermax > 0) 122 { 123 m_timervalue++; 124 if (m_timervalue > m_timermax) 125 m_timervalue = 0; 126 repaint(); 127 } 128 } 130 131 132 141 public void paintComponent (Graphics g) 142 { 143 Dimension panelSize = getSize(); 144 g.setColor(new Color(1f,1f,1f, 0.4f)); g.fillRect(0,0, panelSize.width, panelSize.height); 146 g.setFont(s_font); 148 g.setColor(s_color); 149 FontMetrics fm = g.getFontMetrics(); 150 Dimension messageSize = new Dimension (fm.stringWidth(m_message), fm.getAscent() + fm.getDescent()); 151 Dimension imageSize = new Dimension (s_image.getWidth(this), s_image.getHeight(this)); 152 Dimension progressSize = new Dimension(150, 15); 153 155 int height = imageSize.height + GAP + messageSize.height + GAP + progressSize.height; 157 if (height > panelSize.height) 158 { 159 Log.error("AGlassPane.paintComponent - Panel too small - height=" + panelSize.height); 160 return; 161 } 162 int yImage = (panelSize.height/2) - (height/2); 163 int yMessage = yImage + imageSize.height + GAP + fm.getAscent(); 164 int yProgress = yMessage + fm.getDescent() + GAP; 165 167 if (imageSize.width > panelSize.width || messageSize.width > panelSize.width) 169 { 170 Log.error("AGlassPane.paintComponent - Panel too small - width=" + panelSize.width); 171 return; 172 } 173 int xImage = (panelSize.width/2) - (imageSize.width/2); 174 int xMessage = (panelSize.width/2) - (messageSize.width/2); 175 int xProgress = (panelSize.width/2) - (progressSize.width/2); 176 177 g.drawImage(s_image, xImage, yImage, this); 178 g.drawString(m_message, xMessage, yMessage); 179 if (m_timermax > 0) 180 { 181 int pWidth = progressSize.width / m_timermax * m_timervalue; 182 g.setColor(CompierePLAF.getPrimary3()); 183 g.fill3DRect(xProgress, yProgress, pWidth, progressSize.height, true); 184 g.setColor(CompierePLAF.getPrimary2()); 185 g.draw3DRect(xProgress, yProgress, progressSize.width, progressSize.height, true); 186 } 187 } 189 190 191 192 196 public void mouseClicked(MouseEvent e) 197 { 198 if (isVisible()) 199 e.consume(); 200 } 201 205 public void mousePressed(MouseEvent e) 206 { 207 if (isVisible()) 208 e.consume(); 209 } 210 214 public void mouseReleased(MouseEvent e) 215 { 216 if (isVisible()) 217 e.consume(); 218 } 219 223 public void mouseEntered(MouseEvent e) 224 { 225 if (isVisible()) 226 e.consume(); 227 } 228 232 public void mouseExited(MouseEvent e) 233 { 234 if (isVisible()) 235 e.consume(); 236 } 237 238 } | Popular Tags |