1 14 package org.compiere.apps; 15 16 import java.awt.*; 17 import java.awt.event.*; 18 import java.awt.print.*; 19 import javax.swing.*; 20 import java.util.*; 21 22 import org.compiere.*; 23 import org.compiere.util.*; 24 import org.compiere.plaf.*; 25 import org.compiere.swing.*; 26 import org.compiere.db.*; 27 28 34 public final class ADialogDialog extends CDialog implements ActionListener 35 { 36 44 public ADialogDialog(Frame frame, String title, String message, int messageType) 45 { 46 super (frame, title, frame != null); 47 common (message, messageType); 48 AEnv.showCenterWindow(frame, this); 49 } 51 59 public ADialogDialog(Dialog dialog, String title, String message, int messageType) 60 { 61 super (dialog, title, dialog != null); 62 common (message, messageType); 63 AEnv.showCenterWindow(dialog, this); 64 } 66 71 private void common (String message, int messageType) 72 { 73 CompiereColor.setBackground(this); 75 try 76 { 77 setInfoMessage (message); 78 jbInit(); 79 setInfoIcon (messageType); 80 } 81 catch(Exception ex) 82 { 83 Log.error("ADialogDialog.common - " + ex.getMessage()); 84 } 85 this.getRootPane().setDefaultButton(confirmPanel.getOKButton()); 87 } 89 93 protected void processWindowEvent(WindowEvent e) 94 { 95 super.processWindowEvent(e); 96 if (e.getID() == WindowEvent.WINDOW_OPENED) 97 confirmPanel.getOKButton().requestFocusInWindow(); 98 } 100 101 public static int A_OK = 0; 102 103 public static int A_CANCEL = 1; 104 105 private int m_returnCode = A_CANCEL; 106 107 private static Icon i_inform = Env.getImageIcon("Inform32.gif"); 108 private static Icon i_warn = Env.getImageIcon("Warn32.gif"); 109 private static Icon i_question = Env.getImageIcon("Question32.gif"); 110 private static Icon i_error = Env.getImageIcon("Error32.gif"); 111 112 private JMenuBar menuBar = new JMenuBar(); 113 private JMenu mFile = AEnv.getMenu("File"); 114 private JMenuItem mEMail = new JMenuItem(); 115 private JMenuItem mPrintScreen = new JMenuItem(); 116 private JMenuItem mScreenShot = new JMenuItem(); 117 private JMenuItem mEnd = new JMenuItem(); 118 private JMenuItem mPreference = new JMenuItem(); 119 private ConfirmPanel confirmPanel = new ConfirmPanel(true); 120 private CPanel westPanel = new CPanel(); 121 private CLabel iconLabel = new CLabel(); 122 private GridBagLayout westLayout = new GridBagLayout(); 123 private CText info = new CText (3, 40); 124 private GridBagLayout infoLayout = new GridBagLayout(); 125 private CPanel infoPanel = new CPanel(); 126 127 131 private void jbInit() throws Exception 132 { 133 this.setJMenuBar(menuBar); 134 mEMail.setIcon(Env.getImageIcon("SendMail16.gif")); 136 mEMail.setText(Msg.getMsg(Env.getCtx(), "EMail")); 137 mEMail.addActionListener(this); 138 mPrintScreen.setIcon(Env.getImageIcon("PrintScreen16.gif")); 139 mPrintScreen.setText(Msg.getMsg(Env.getCtx(), "PrintScreen")); 140 mPrintScreen.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_PRINTSCREEN, 0)); 141 mPrintScreen.addActionListener(this); 142 mScreenShot.setIcon(Env.getImageIcon("ScreenShot16.gif")); 143 mScreenShot.setText(Msg.getMsg(Env.getCtx(), "ScreenShot")); 144 mScreenShot.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_PRINTSCREEN, Event.SHIFT_MASK)); 145 mScreenShot.addActionListener(this); 146 mPreference.setIcon(Env.getImageIcon("Preference16.gif")); 147 mPreference.setText(Msg.getMsg(Env.getCtx(), "Preference")); 148 mPreference.addActionListener(this); 149 mEnd.setIcon(Env.getImageIcon("End16.gif")); 150 mEnd.setText(Msg.getMsg(Env.getCtx(), "End")); 151 mEnd.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X, Event.ALT_MASK)); 152 mEnd.addActionListener(this); 153 westPanel.setLayout(westLayout); 155 westPanel.setName("westPanel"); 156 westPanel.setRequestFocusEnabled(false); 157 infoPanel.setLayout(infoLayout); 158 infoPanel.setName("infoPanel"); 159 infoPanel.setRequestFocusEnabled(false); 160 this.getContentPane().add(confirmPanel, BorderLayout.SOUTH); 161 this.getContentPane().add(westPanel, BorderLayout.WEST); 162 westPanel.add(iconLabel, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0 163 ,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(10, 10, 10, 10), 0, 0)); 164 this.getContentPane().add(infoPanel, BorderLayout.CENTER); 165 infoPanel.add(info, new GridBagConstraints(0, 1, 1, 1, 1.0, 1.0 166 ,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(10, 10, 10, 10), 0, 0)); 167 menuBar.add(mFile); 169 mFile.add(mPrintScreen); 170 mFile.add(mScreenShot); 171 mFile.addSeparator(); 172 mFile.add(mEMail); 173 mFile.add(mPreference); 174 mFile.addSeparator(); 175 mFile.add(mEnd); 176 confirmPanel.addActionListener(this); 178 } 180 184 private void setInfoMessage(String message) 185 { 186 int rows = 0; 187 int cols = 0; 188 189 StringTokenizer st = new StringTokenizer(message, "\n", false); 190 while (st.hasMoreTokens()) 191 { 192 rows++; 193 int length = st.nextToken().length(); 194 cols = Math.max(cols, length); 195 while (length > 35) 196 { 197 rows++; 198 length -= 35; 199 } 200 } 201 202 rows = Math.max(2, rows); 203 rows = Math.min(10, rows); 204 cols = Math.max(30, cols); 205 cols = Math.min(40, cols); 206 207 info.setText(message); 208 info.setRows(rows); 209 info.setColumns(cols); 210 info.setRequestFocusEnabled(false); 211 info.setReadWrite(false); 212 info.setOpaque(false); 213 info.setLineWrap(true); 214 info.setWrapStyleWord(true); 215 info.setBorder(null); 216 info.setCaretPosition(0); 218 } 221 222 223 227 private void setInfoIcon (int messageType) 228 { 229 confirmPanel.getCancelButton().setVisible(false); 230 switch (messageType) 232 { 233 case JOptionPane.ERROR_MESSAGE: 234 iconLabel.setIcon(i_error); 235 break; 236 case JOptionPane.INFORMATION_MESSAGE: 237 iconLabel.setIcon(i_inform); 238 break; 239 case JOptionPane.QUESTION_MESSAGE: 240 confirmPanel.getCancelButton().setVisible(true); 241 iconLabel.setIcon(i_question); 242 break; 243 case JOptionPane.WARNING_MESSAGE: 244 iconLabel.setIcon(i_warn); 245 break; 246 247 case JOptionPane.PLAIN_MESSAGE: 248 default: 249 break; 250 } } 253 254 255 259 public void actionPerformed (ActionEvent e) 260 { 261 if (e.getActionCommand().equals(ConfirmPanel.A_OK)) 262 { 263 m_returnCode = A_OK; 264 dispose(); 265 } 266 else if (e.getActionCommand().equals(ConfirmPanel.A_CANCEL) || e.getSource() == mEnd) 267 { 268 m_returnCode = A_CANCEL; 269 dispose(); 270 } 271 else if (e.getSource() == mPrintScreen) 272 printScreen(); 273 else if (e.getSource() == mEMail) 274 { 275 String title = getTitle(); 276 String text = info.getText(); 277 dispose(); ADialog.createSupportEMail(this, title, text); 279 } 280 else if (e.getSource() == mPreference) 281 { 282 Preference p = new Preference(null, 0, true); 283 p.show(); 284 } 285 } 287 291 public int getReturnCode() 292 { 293 return m_returnCode; 294 } 296 299 private void printScreen() 300 { 301 PrintScreenPainter.printScreen(this); 302 } 304 } | Popular Tags |