1 14 package org.compiere.apps.form; 15 16 import java.awt.*; 17 import java.sql.*; 18 import java.util.*; 19 import javax.swing.*; 20 21 import org.compiere.apps.*; 22 import org.compiere.plaf.*; 23 import org.compiere.util.*; 24 import java.awt.event.*; 25 26 32 public class FormFrame extends JFrame implements ActionListener 33 { 34 38 public FormFrame () 39 { 40 super(); 41 m_WindowNo = Env.createWindowNo (this); 42 try 43 { 44 jbInit(); 45 createMenu(); 46 } 47 catch(Exception e) 48 { 49 Log.error("FormFrame", e); 50 } 51 } 53 54 private int m_WindowNo; 55 private String m_Description = null; 56 private String m_Help = null; 57 58 private JMenuBar menuBar = new JMenuBar(); 59 60 64 private void jbInit() throws Exception 65 { 66 CompiereColor.setBackground(this); 67 this.setIconImage(org.compiere.Compiere.getImage16()); 69 this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); 70 this.setJMenuBar(menuBar); 71 73 } 75 78 private void createMenu() 79 { 80 JMenu mFile = AEnv.getMenu("File"); 82 menuBar.add(mFile); 83 AEnv.addMenuItem("PrintScreen", null, KeyStroke.getKeyStroke(KeyEvent.VK_PRINTSCREEN, 0), mFile, this); 84 AEnv.addMenuItem("ScreenShot", null, KeyStroke.getKeyStroke(KeyEvent.VK_PRINTSCREEN, Event.SHIFT_MASK), mFile, this); 85 AEnv.addMenuItem("Report", null, KeyStroke.getKeyStroke(KeyEvent.VK_P, Event.ALT_MASK), mFile, this); 86 mFile.addSeparator(); 87 AEnv.addMenuItem("End", null, KeyStroke.getKeyStroke(KeyEvent.VK_X, Event.ALT_MASK), mFile, this); 88 AEnv.addMenuItem("Exit", null, KeyStroke.getKeyStroke(KeyEvent.VK_X, Event.SHIFT_MASK+Event.ALT_MASK), mFile, this); 89 90 JMenu mView = AEnv.getMenu("View"); 92 menuBar.add(mView); 93 AEnv.addMenuItem("InfoProduct", null, KeyStroke.getKeyStroke(KeyEvent.VK_I, Event.CTRL_MASK), mView, this); 94 AEnv.addMenuItem("InfoBPartner", null, KeyStroke.getKeyStroke(KeyEvent.VK_I, Event.SHIFT_MASK+Event.CTRL_MASK), mView, this); 95 AEnv.addMenuItem("InfoAccount", null, KeyStroke.getKeyStroke(KeyEvent.VK_I, Event.ALT_MASK+Event.CTRL_MASK), mView, this); 96 mView.addSeparator(); 97 AEnv.addMenuItem("InfoOrder", "Info", null, mView, this); 98 AEnv.addMenuItem("InfoInvoice", "Info", null, mView, this); 99 AEnv.addMenuItem("InfoInOut", "Info", null, mView, this); 100 AEnv.addMenuItem("InfoPayment", "Info", null, mView, this); 101 AEnv.addMenuItem("InfoSchedule", "Info", null, mView, this); 102 103 JMenu mTools = AEnv.getMenu("Tools"); 105 menuBar.add(mTools); 106 AEnv.addMenuItem("Calculator", null, null, mTools, this); 107 AEnv.addMenuItem("Calendar", null, null, mTools, this); 108 AEnv.addMenuItem("Editor", null, null, mTools, this); 109 AEnv.addMenuItem("Script", null, null, mTools, this); 110 mTools.addSeparator(); 111 AEnv.addMenuItem("Preference", null, null, mTools, this); 112 113 JMenu mHelp = AEnv.getMenu("Help"); 115 menuBar.add(mHelp); 116 AEnv.addMenuItem("Help", "Help", KeyStroke.getKeyStroke(KeyEvent.VK_F1, 0), mHelp, this); 117 AEnv.addMenuItem("Online", null, null, mHelp, this); 118 AEnv.addMenuItem("SendMail", null, null, mHelp, this); 119 AEnv.addMenuItem("About", null, null, mHelp, this); 120 } 122 125 public void dispose() 126 { 127 Log.trace(Log.l3_Util, "FormFrame.dispose"); 128 Env.clearWinContext(m_WindowNo); 129 super.dispose(); 130 } 132 137 public boolean openForm (int AD_Form_ID) 138 { 139 Properties ctx = Env.getCtx(); 140 String name = null; 142 String className = null; 143 String sql = "SELECT Name, Description, ClassName, Help FROM AD_Form WHERE AD_Form_ID=?"; 144 boolean trl = !Env.isBaseLanguage(ctx, "AD_Form"); 145 if (trl) 146 sql = "SELECT t.Name, t.Description, f.ClassName, t.Help " 147 + "FROM AD_Form f INNER JOIN AD_Form_Trl t" 148 + " ON (f.AD_Form_ID=t.AD_Form_ID AND AD_Language=?)" 149 + "WHERE f.AD_Form_ID=?"; 150 151 try 152 { 153 PreparedStatement pstmt = DB.prepareStatement (sql); 154 if (trl) 155 { 156 pstmt.setString(1, Env.getAD_Language(ctx)); 157 pstmt.setInt(2, AD_Form_ID); 158 } 159 else 160 pstmt.setInt(1, AD_Form_ID); 161 ResultSet rs = pstmt.executeQuery(); 162 if (rs.next()) 163 { 164 name = rs.getString(1); 165 m_Description = rs.getString(2); 166 className = rs.getString(3); 167 m_Help = rs.getString(4); 168 } 169 rs.close(); 170 pstmt.close(); 171 } 172 catch (SQLException e) 173 { 174 Log.error ("FormFrame.openForm", e); 175 } 176 if (className == null) 177 return false; 178 Log.trace(Log.l1_User, "FormFrame.openForm - AD_Form_ID=" + AD_Form_ID, "Class=" + className); 180 Env.setContext(ctx, m_WindowNo, "WindowName", name); 181 setTitle(Env.getHeader(ctx, m_WindowNo)); 182 183 FormPanel panel = null; 184 try 185 { 186 panel = (FormPanel)Class.forName(className).newInstance(); 188 } 190 catch (Exception e) 191 { 192 Log.error("FormFrame.openForm - class=" + className + ", AD_Form_ID=" + AD_Form_ID, e); 193 return false; 194 } 195 panel.init(m_WindowNo, this); 197 return true; 198 } 200 204 public void actionPerformed(ActionEvent e) 205 { 206 String cmd = e.getActionCommand(); 207 if (cmd.equals("End")) 208 dispose(); 209 else if (cmd.equals("Help")) 210 actionHelp(); 211 else if (!AEnv.actionPerformed(cmd, m_WindowNo, this)) 212 Log.error("FormFrame.actionPerformed - Not handeled=" + cmd); 213 } 215 218 private void actionHelp() 219 { 220 StringBuffer sb = new StringBuffer (); 221 sb.append("<h2>").append(m_Description).append("</h2><p>") 222 .append(m_Help); 223 Help hlp = new Help (Env.getFrame(this), this.getTitle(), sb.toString()); 224 hlp.show(); 225 } 227 } | Popular Tags |