KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > compiere > apps > form > FormFrame


1 /******************************************************************************
2  * The contents of this file are subject to the Compiere License Version 1.1
3  * ("License"); You may not use this file except in compliance with the License
4  * You may obtain a copy of the License at http://www.compiere.org/license.html
5  * Software distributed under the License is distributed on an "AS IS" basis,
6  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
7  * the specific language governing rights and limitations under the License.
8  * The Original Code is Compiere ERP & CRM Business Solution
9  * The Initial Developer of the Original Code is Jorg Janke and ComPiere, Inc.
10  * Portions created by Jorg Janke are Copyright (C) 1999-2002 Jorg Janke, parts
11  * created by ComPiere are Copyright (C) ComPiere, Inc.; All Rights Reserved.
12  * Contributor(s): ______________________________________.
13  *****************************************************************************/

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 /**
27  * Form Framework
28  *
29  * @author Jorg Janke
30  * @version $Id: FormFrame.java,v 1.9 2003/08/10 05:31:15 jjanke Exp $
31  */

32 public class FormFrame extends JFrame implements ActionListener
33 {
34     /**
35      * Create Form.
36      * Need to call openForm
37      */

38     public FormFrame ()
39     {
40         super();
41         m_WindowNo = Env.createWindowNo (this);
42         try
43         {
44             jbInit();
45             createMenu();
46         }
47         catch(Exception JavaDoc e)
48         {
49             Log.error("FormFrame", e);
50         }
51     } // FormFrame
52

53     /** WindowNo */
54     private int m_WindowNo;
55     private String JavaDoc m_Description = null;
56     private String JavaDoc m_Help = null;
57
58     private JMenuBar menuBar = new JMenuBar();
59
60     /**
61      * Static Init
62      * @throws Exception
63      */

64     private void jbInit() throws Exception JavaDoc
65     {
66         CompiereColor.setBackground(this);
67         //
68
this.setIconImage(org.compiere.Compiere.getImage16());
69         this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
70         this.setJMenuBar(menuBar);
71         //
72

73     } // jbInit
74

75     /**
76      * Create Menu
77      */

78     private void createMenu()
79     {
80         // File
81
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         // View
91
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         // Tools
104
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         // Help
114
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     } // createMenu
121

122     /**
123      * Dispose
124      */

125     public void dispose()
126     {
127         Log.trace(Log.l3_Util, "FormFrame.dispose");
128         Env.clearWinContext(m_WindowNo);
129         super.dispose();
130     } // dispose
131

132     /**
133      * Open Form
134      * @param AD_Form_ID form
135      * @return true if form opened
136      */

137     public boolean openForm (int AD_Form_ID)
138     {
139         Properties ctx = Env.getCtx();
140         //
141
String JavaDoc name = null;
142         String JavaDoc className = null;
143         String JavaDoc 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         //
179
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             // Create instance w/o parameters
187
panel = (FormPanel)Class.forName(className).newInstance();
188             //
189
}
190         catch (Exception JavaDoc e)
191         {
192             Log.error("FormFrame.openForm - class=" + className + ", AD_Form_ID=" + AD_Form_ID, e);
193             return false;
194         }
195         //
196
panel.init(m_WindowNo, this);
197         return true;
198     } // openForm
199

200     /**
201      * Action Listener
202      * @param e event
203      */

204     public void actionPerformed(ActionEvent e)
205     {
206         String JavaDoc 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     } // actionPerformed
214

215     /**
216      * Show Help
217      */

218     private void actionHelp()
219     {
220         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
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     } // actionHelp
226

227 } // FormFrame
228
Popular Tags