KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > compiere > util > IniDialog


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-2001 Jorg Janke, parts
11  * created by ComPiere are Copyright (C) ComPiere, Inc.; All Rights Reserved.
12  * Contributor(s): ______________________________________.
13  *****************************************************************************/

14 package org.compiere.util;
15
16 import java.awt.BorderLayout JavaDoc;
17 import java.awt.Color JavaDoc;
18 import java.awt.Dimension JavaDoc;
19 import java.awt.FlowLayout JavaDoc;
20 import java.awt.event.ActionEvent JavaDoc;
21 import java.awt.event.ActionListener JavaDoc;
22 import java.net.URL JavaDoc;
23 import java.util.ResourceBundle JavaDoc;
24
25 import javax.swing.JButton JavaDoc;
26 import javax.swing.JDialog JavaDoc;
27 import javax.swing.JEditorPane JavaDoc;
28 import javax.swing.JLabel JavaDoc;
29 import javax.swing.JPanel JavaDoc;
30 import javax.swing.JScrollPane JavaDoc;
31
32 import org.compiere.plaf.CompierePLAF;
33
34 /**
35  * Init Dialog (License)
36  *
37  * @author Jorg Janke
38  * @version $Id: IniDialog.java,v 1.5 2003/09/27 11:08:54 jjanke Exp $
39  */

40 public final class IniDialog extends JDialog JavaDoc implements ActionListener JavaDoc
41 {
42     /**
43      * Constructor
44      */

45     public IniDialog()
46     {
47         super();
48         try
49         {
50             jbInit();
51             // get License file
52
String JavaDoc where = s_res.getString("license_htm");
53             if (where == null || where.length() == 0)
54             {
55                 System.err.println("IniDialog - no license pointer in resource");
56                 where = "org/compiere/license.htm";
57             }
58             URL JavaDoc url = getClass().getClassLoader().getResource(where);
59             if (url == null)
60             {
61                 System.err.println("IniDialog - no license in resource ");
62                 url = new URL JavaDoc("http://www.compiere.org/license.htm");
63             }
64             if (url == null)
65                 cmd_reject();
66             //
67
licensePane.setPage(url);
68             CompierePLAF.showCenterScreen(this);
69         }
70         catch (Exception JavaDoc ex)
71         {
72             System.err.println("IniDialog error: " + ex.toString());
73             ex.printStackTrace();
74             cmd_reject();
75         }
76     } // IniDialog
77

78     /** Translation */
79     static ResourceBundle JavaDoc s_res = ResourceBundle.getBundle("org.compiere.util.IniRes");
80     private boolean m_accept = false;
81
82     private JPanel JavaDoc mainPanel = new JPanel JavaDoc();
83     private BorderLayout JavaDoc mainLayout = new BorderLayout JavaDoc();
84     private JScrollPane JavaDoc scrollPane = new JScrollPane JavaDoc();
85     private JPanel JavaDoc southPanel = new JPanel JavaDoc();
86     private JButton JavaDoc bReject = CompierePLAF.getCancelButton();
87     private JButton JavaDoc bAccept = CompierePLAF.getOKButton();
88     private FlowLayout JavaDoc southLayout = new FlowLayout JavaDoc();
89     private JLabel JavaDoc southLabel = new JLabel JavaDoc();
90     private JEditorPane JavaDoc licensePane = new JEditorPane JavaDoc();
91
92     /**
93      * Static Layout
94      * @throws Exception
95      */

96     private void jbInit() throws Exception JavaDoc
97     {
98         setTitle("Compiere - " + s_res.getString("Compiere_License"));
99         southLabel.setText(s_res.getString("Do_you_accept"));
100         bReject.setText(s_res.getString("No"));
101         bAccept.setText(s_res.getString("Yes_I_Understand"));
102         //
103
setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
104         setModal(true);
105         //
106
mainPanel.setLayout(mainLayout);
107         bReject.setForeground(Color.red);
108         bReject.addActionListener(this);
109         bAccept.addActionListener(this);
110         southPanel.setLayout(southLayout);
111         southLayout.setAlignment(FlowLayout.RIGHT);
112         licensePane.setEditable(false);
113         licensePane.setContentType("text/html");
114         scrollPane.setPreferredSize(new Dimension JavaDoc(700, 400));
115         southPanel.add(southLabel, null);
116         getContentPane().add(mainPanel);
117         mainPanel.add(scrollPane, BorderLayout.CENTER);
118         scrollPane.getViewport().add(licensePane, null);
119         mainPanel.add(southPanel, BorderLayout.SOUTH);
120         southPanel.add(bReject, null);
121         southPanel.add(bAccept, null);
122     } // jbInit
123

124     /**
125      * ActionListener
126      * @param e event
127      */

128     public final void actionPerformed(ActionEvent JavaDoc e)
129     {
130         if (e.getSource() == bAccept)
131             m_accept = true;
132         dispose();
133     } // actionPerformed
134

135     /**
136      * Dispose
137      */

138     public final void dispose()
139     {
140         super.dispose();
141         if (!m_accept)
142             cmd_reject();
143     } // dispose
144

145     /**
146      * Is Accepted
147      * @return true if accepted
148      */

149     public final boolean isAccepted()
150     {
151         return m_accept;
152     } // isAccepted
153

154     /**
155      * Reject License
156      */

157     public final void cmd_reject()
158     {
159         String JavaDoc info = "License rejected or expired";
160         try
161         {
162             info = s_res.getString("License_rejected");
163         }
164         catch (Exception JavaDoc e)
165         {
166         }
167         System.err.println(info);
168         System.exit(10);
169     } // cmd_reject
170

171     /**
172      * Display License and exit if rejected
173      * @return true if acceptes
174      */

175     public static final boolean accept()
176     {
177         IniDialog id = new IniDialog();
178         if (id.isAccepted())
179             return true;
180         System.exit(10);
181         return false; // never executed.
182
} // accpept
183

184 } // IniDialog
185
Popular Tags