KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > compiere > apps > Preference


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.apps;
15
16 import java.awt.*;
17 import java.awt.event.*;
18 import javax.swing.*;
19 import javax.swing.event.*;
20 import javax.swing.table.*;
21 import java.util.*;
22
23 import org.compiere.util.*;
24 import org.compiere.grid.ed.*;
25 import org.compiere.plaf.*;
26 import org.compiere.swing.*;
27 import org.compiere.print.*;
28 import org.compiere.minigrid.*;
29 import org.compiere.model.*;
30
31 /**
32  * Customize settings like L&F, AutoCommit, etc. & Diagnostics
33  *
34  * @author Jorg Janke
35  * @version $Id: Preference.java,v 1.25 2003/11/06 07:08:28 jjanke Exp $
36  */

37 public final class Preference extends JDialog
38     implements ActionListener, ListSelectionListener
39 {
40     /**
41      * Standard Constructor
42      * @param frame frame
43      * @param WindowNo window
44      * @param modal modal
45      */

46     public Preference(Frame frame, int WindowNo, boolean modal)
47     {
48         super(frame, Msg.getMsg(Env.getCtx(), "Preference"), modal);
49         Log.trace(Log.l2_Sub, "Preference");
50         setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
51         try
52         {
53             jbInit();
54         }
55         catch(Exception JavaDoc ex)
56         {
57             Log.error("Preference - " + ex.getMessage());
58         }
59         load();
60         //
61
StringBuffer JavaDoc sta = new StringBuffer JavaDoc("#");
62         sta.append(Env.getCtx().size()).append(" - ")
63             .append(Msg.translate(Env.getCtx(), "AD_Window_ID"))
64             .append("=").append(WindowNo);
65         statusBar.setStatusLine(sta.toString());
66         statusBar.setStatusDB("");
67         AEnv.positionCenterWindow(frame, this);
68     } // Preference
69

70     /**
71      * Minimum Constructor
72      */

73     public Preference()
74     {
75         this(null, 0, false);
76     } // Preference
77

78     private CPanel panel = new CPanel();
79     private BorderLayout panelLayout = new BorderLayout();
80     private CTabbedPane tabPane = new CTabbedPane();
81     private CPanel customizePane = new CPanel();
82     private CPanel contextPane = new CPanel();
83     private GridBagLayout customizeLayout = new GridBagLayout();
84     private CCheckBox autoCommit = new CCheckBox();
85     private CCheckBox printPreview = new CCheckBox();
86     private CPanel southPanel = new CPanel();
87     private BorderLayout southLayout = new BorderLayout();
88     private BorderLayout icontextLayout = new BorderLayout();
89     private JList infoList = new JList();
90     private JScrollPane contextListScrollPane = new JScrollPane(infoList);
91     private CPanel contextSouthPanel = new CPanel();
92     private CText contextHeader = new CText(4,15);
93     private CText contextDetail = new CText(4,35);
94     private CText infoArea = new CText(5, 30);
95     private BorderLayout contextSouthLayout = new BorderLayout();
96     private StatusBar statusBar = new StatusBar();
97     private ConfirmPanel confirm = new ConfirmPanel(true);
98     private JSlider debugLevel = new JSlider();
99     private CLabel traceLabel = new CLabel();
100     private CCheckBox autoLogin = new CCheckBox();
101     private CCheckBox compiereSys = new CCheckBox();
102     private CCheckBox storePassword = new CCheckBox();
103     private CCheckBox showTrl = new CCheckBox();
104     private CCheckBox showAcct = new CCheckBox();
105     private CButton uiTheme = new CButton();
106     private CLabel lPrinter = new CLabel();
107     private CPrinter fPrinter = new CPrinter();
108     private CLabel lDate = new CLabel();
109     private VDate fDate = new VDate();
110     private CCheckBox serverObjects = new CCheckBox();
111     private CPanel errorPane = new CPanel();
112     private BorderLayout errorLayout = new BorderLayout();
113     private JScrollPane errorScrollPane = new JScrollPane();
114     private MiniTable errorTable = new MiniTable();
115     private CButton bErrorReset = new CButton(Msg.getMsg(Env.getCtx(), "Reset"));
116     private CButton bRoleInfo = new CButton(Msg.translate(Env.getCtx(), "AD_Role_ID"));
117
118     /**
119      * Static Init.
120      * <pre>
121      * - panel
122      * - tabPane
123      * - customizePane
124      * - infoArea
125      * - fields ...
126      * - contextPane
127      * - contextList
128      * - contextSouthPanel
129      * - contextHeader
130      * - contextDetail
131      * - errorPane
132      * - errorScollPane
133      * - errorTable
134      * - southPanel
135      * </pre>
136      * @throws Exception
137      */

138     void jbInit() throws Exception JavaDoc
139     {
140         CompiereColor.setBackground(this);
141         traceLabel.setRequestFocusEnabled(false);
142         traceLabel.setText("TraceLevel");
143         debugLevel.setMinorTickSpacing(1);
144         debugLevel.setMajorTickSpacing(2);
145         debugLevel.setPaintLabels(true);
146         debugLevel.setValue(5);
147         debugLevel.setPaintTicks(true);
148         debugLevel.setMaximum(10);
149         debugLevel.setSnapToTicks(true);
150         debugLevel.setOpaque(false);
151
152         uiTheme.setText(Msg.getMsg(Env.getCtx(), "UITheme", true));
153         uiTheme.setToolTipText(Msg.getMsg(Env.getCtx(), "UITheme", false));
154         autoCommit.setText(Msg.getMsg(Env.getCtx(), "AutoCommit", true));
155         autoCommit.setToolTipText(Msg.getMsg(Env.getCtx(), "AutoCommit", false));
156         compiereSys.setText(Msg.getMsg(Env.getCtx(), "CompiereSys", true));
157         compiereSys.setToolTipText(Msg.getMsg(Env.getCtx(), "CompiereSys", false));
158         printPreview.setText(Msg.getMsg(Env.getCtx(), "AlwaysPrintPreview", true));
159         printPreview.setToolTipText(Msg.getMsg(Env.getCtx(), "AlwaysPrintPreview", false));
160         autoLogin.setText(Msg.getMsg(Env.getCtx(), "AutoLogin", true));
161         autoLogin.setToolTipText(Msg.getMsg(Env.getCtx(), "AutoLogin", false));
162         storePassword.setText(Msg.getMsg(Env.getCtx(), "StorePassword", true));
163         storePassword.setToolTipText(Msg.getMsg(Env.getCtx(), "StorePassword", false));
164         showTrl.setText(Msg.getMsg(Env.getCtx(), "ShowTrlTab", true));
165         showTrl.setToolTipText(Msg.getMsg(Env.getCtx(), "ShowTrlTab", false));
166         showAcct.setText(Msg.getMsg(Env.getCtx(), "ShowAcctTab", true));
167         showAcct.setToolTipText(Msg.getMsg(Env.getCtx(), "ShowAcctTab", false));
168         serverObjects.setText(Msg.getMsg(Env.getCtx(), "ServerObjects", true));
169         serverObjects.setToolTipText(Msg.getMsg(Env.getCtx(), "ServerObjects", false));
170         lPrinter.setText(Msg.getMsg(Env.getCtx(), "Printer"));
171         lDate.setText(Msg.getMsg(Env.getCtx(), "Date"));
172         infoArea.setReadWrite(false);
173         getContentPane().add(panel);
174         panel.setLayout(panelLayout);
175         panel.add(tabPane, BorderLayout.CENTER);
176         // Customize
177
// tabPane.add(customizePane, Msg.getMsg(Env.getCtx(), "Preference"));
178
tabPane.add(customizePane, Msg.getMsg(Env.getCtx(), "Preference"));
179         customizePane.setLayout(customizeLayout);
180         customizePane.add(infoArea, new GridBagConstraints(0, 0, 3, 1, 0.0, 0.0
181             ,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(5, 5, 5, 5), 0, 0));
182         customizePane.add(uiTheme, new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0
183             ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
184         customizePane.add(bRoleInfo, new GridBagConstraints(2, 1, 1, 1, 0.0, 0.0
185             ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
186
187         customizePane.add(autoCommit, new GridBagConstraints(1, 2, 1, 1, 0.0, 0.0
188             ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
189         customizePane.add(compiereSys, new GridBagConstraints(2, 2, 1, 1, 0.0, 0.0
190             ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
191         customizePane.add(autoLogin, new GridBagConstraints(1, 3, 1, 1, 0.0, 0.0
192             ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
193         customizePane.add(storePassword, new GridBagConstraints(2, 3, 1, 1, 0.0, 0.0
194             ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
195         customizePane.add(showAcct, new GridBagConstraints(1, 4, 1, 1, 0.0, 0.0
196             ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
197         customizePane.add(showTrl, new GridBagConstraints(2, 4, 1, 1, 0.0, 0.0
198             ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
199         customizePane.add(serverObjects, new GridBagConstraints(1, 5, 1, 1, 0.0, 0.0
200             ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
201         customizePane.add(printPreview, new GridBagConstraints(2, 5, 1, 1, 0.0, 0.0
202             ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
203
204         customizePane.add(debugLevel, new GridBagConstraints(1, 6, 2, 1, 0.0, 0.0
205             ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0));
206         customizePane.add(traceLabel, new GridBagConstraints(0, 6, 1, 1, 0.0, 0.0
207             ,GridBagConstraints.NORTHEAST, GridBagConstraints.NONE, new Insets(0, 0, 5, 5), 0, 0));
208         customizePane.add(lPrinter, new GridBagConstraints(0, 7, 1, 1, 0.0, 0.0
209             ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
210         customizePane.add(fPrinter, new GridBagConstraints(1, 7, 2, 1, 0.0, 0.0
211             ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
212         customizePane.add(lDate, new GridBagConstraints(0, 8, 1, 1, 0.0, 0.0
213             ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
214         customizePane.add(fDate, new GridBagConstraints(1, 8, 2, 1, 0.0, 0.0
215             ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
216         // Info
217
// tabPane.add(contextPane, Msg.getMsg(Env.getCtx(), "Context"));
218
tabPane.add(contextPane, Msg.getMsg(Env.getCtx(), "Context"));
219         contextPane.setLayout(icontextLayout);
220         contextPane.add(contextListScrollPane, BorderLayout.CENTER);
221         contextListScrollPane.setPreferredSize(new Dimension(200, 300));
222         infoList.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
223         infoList.setBackground(CompierePLAF.getFieldBackground_Inactive());
224         infoList.addListSelectionListener(this);
225         infoList.setFixedCellWidth(30);
226         contextPane.add(contextSouthPanel, BorderLayout.SOUTH);
227         contextSouthPanel.setLayout(contextSouthLayout);
228         contextSouthPanel.add(contextHeader, BorderLayout.WEST);
229         contextHeader.setBackground(SystemColor.info);
230         contextHeader.setReadWrite(false);
231         contextHeader.setLineWrap(true);
232         contextHeader.setWrapStyleWord(true);
233         contextHeader.setBorder(BorderFactory.createLoweredBevelBorder());
234         contextSouthPanel.add(contextDetail, BorderLayout.CENTER);
235         contextDetail.setBackground(SystemColor.info);
236         contextDetail.setReadWrite(false);
237         contextDetail.setLineWrap(true);
238         contextDetail.setWrapStyleWord(true);
239         contextDetail.setBorder(BorderFactory.createLoweredBevelBorder());
240         // Error Pane
241
errorPane.setLayout(errorLayout);
242 // tabPane.add(errorPane, Msg.getMsg(Env.getCtx(), "Errors"));
243
tabPane.add(errorPane, "Errors");
244         errorPane.add(errorScrollPane, BorderLayout.CENTER);
245         errorScrollPane.getViewport().add(errorTable, null);
246         errorPane.add(bErrorReset, BorderLayout.SOUTH);
247         // South
248
panel.add(southPanel, BorderLayout.SOUTH);
249         southPanel.setLayout(southLayout);
250         southPanel.add(statusBar, BorderLayout.SOUTH);
251         southPanel.add(confirm, BorderLayout.CENTER);
252         //
253
bRoleInfo.addActionListener(this);
254         confirm.addActionListener(this);
255     } // jbInit
256

257
258     /**
259      * List Selection Listener - show info in header/detail fields
260      * @param e evant
261      */

262     public void valueChanged(ListSelectionEvent e)
263     {
264         if (e.getValueIsAdjusting())
265             return;
266
267         String JavaDoc value = (String JavaDoc)infoList.getSelectedValue();
268         if (value == null)
269             return;
270         int pos = value.indexOf("==");
271         if (pos == -1)
272         {
273             contextHeader.setText("");
274             contextDetail.setText(value);
275         }
276         else
277         {
278             contextHeader.setText(value.substring(0, pos).replace('|','\n'));
279             contextDetail.setText(value.substring(pos+3));
280         }
281     } // valueChanged
282

283
284     /**
285      * ActionListener
286      * @param e event
287      */

288     public void actionPerformed(ActionEvent e)
289     {
290         // UI Change
291
if (e.getSource() == uiTheme)
292             new CompierePLAFEditor(this, false);
293         else if (e.getActionCommand().equals(ConfirmPanel.A_CANCEL))
294             dispose();
295         else if (e.getActionCommand().equals(ConfirmPanel.A_OK))
296             cmd_save();
297         else if (e.getSource() == bErrorReset)
298             cmd_resetErrors();
299         else if (e.getSource() == bRoleInfo)
300             ADialog.info(0, this, "RoleInfo", MRole.getDefault().toStringX(Env.getCtx()));
301     } // actionPerformed
302

303
304     /**
305      * Load Settings - and Context
306      */

307     private void load()
308     {
309         Log.trace(Log.l3_Util, "Preference.load");
310         infoArea.setText(AboutBox.getInfo());
311         infoArea.setCaretPosition(0);
312
313         // -- Load Settings --
314
// UI
315
uiTheme.addActionListener(this);
316         // AutoCommit
317
autoCommit.setSelected(Env.isAutoCommit(Env.getCtx()));
318         // CompiereSys
319
compiereSys.setSelected(Ini.getPropertyBool(Ini.P_COMPIERESYS));
320         if (Env.getAD_Client_ID(Env.getCtx()) > 20)
321         {
322             compiereSys.setSelected(false);
323             compiereSys.setEnabled(false);
324         }
325         // AutoLogin
326
autoLogin.setSelected(Ini.getPropertyBool(Ini.P_A_LOGIN));
327         // Save Password
328
storePassword.setSelected(Ini.getPropertyBool(Ini.P_STORE_PWD));
329         // Show Acct Tab
330
if (MRole.getDefault().isShowAcct())
331             showAcct.setSelected(Ini.getPropertyBool(Ini.P_SHOW_ACCT));
332         else
333         {
334             showAcct.setSelected(false);
335             showAcct.setReadWrite(false);
336         }
337         // Show Trl Tab
338
showTrl.setSelected(Ini.getPropertyBool(Ini.P_SHOW_TRL));
339         // Server Objects
340
serverObjects.setSelected(Ini.getPropertyBool(Ini.P_OBJECTS));
341         // Print Preview
342
printPreview.setSelected(Ini.getPropertyBool(Ini.P_PRINTPREVIEW));
343
344         // DebugLevel
345
debugLevel.setValue(Log.getTraceLevel());
346         // Printer
347
fPrinter.setValue(Env.getContext(Env.getCtx(), "#Printer"));
348         // Date
349
fDate.setValue(Env.getContextAsDate(Env.getCtx(), "#Date"));
350
351         // -- Load and sort Context --
352
String JavaDoc[] context = Env.getEntireContext(Env.getCtx());
353         Arrays.sort(context);
354         infoList.setListData(context);
355
356         // Load Errors
357
Vector data = LogBuffer.get().getLogData();
358         Vector columnNames = LogBuffer.get().getColumnNames(Env.getCtx());
359         DefaultTableModel model = new DefaultTableModel(data, columnNames);
360         errorTable.setModel(model);
361         errorTable.setCellSelectionEnabled(true);
362         tabPane.setTitleAt(2, Msg.getMsg(Env.getCtx(), "Errors") + " (" + data.size() + ")");
363         for (int i = 2; i < 6; i++)
364             errorTable.setColumnReadOnly(i, false);
365         errorTable.autoSize();
366         bErrorReset.addActionListener(this);
367     } // load
368

369     /**
370      * Save Settings
371      */

372     private void cmd_save()
373     {
374         Log.trace(Log.l3_Util, "Preference.cmd_save");
375         // UI
376
// AutoCommit
377
Ini.setProperty(Ini.P_A_COMMIT, (autoCommit.isSelected()));
378         Env.setAutoCommit(Env.getCtx(), autoCommit.isSelected());
379         // CompiereSys
380
Ini.setProperty(Ini.P_COMPIERESYS, compiereSys.isSelected());
381         // AutoLogin
382
Ini.setProperty(Ini.P_A_LOGIN, (autoLogin.isSelected()));
383         // Save Password
384
Ini.setProperty(Ini.P_STORE_PWD, (storePassword.isSelected()));
385         // Show Acct Tab
386
Ini.setProperty(Ini.P_SHOW_ACCT, (showAcct.isSelected()));
387         Env.setContext(Env.getCtx(), "#ShowAcct", (showAcct.isSelected()));
388         // Show Trl Tab
389
Ini.setProperty(Ini.P_SHOW_TRL, (showTrl.isSelected()));
390         Env.setContext(Env.getCtx(), "#ShowTrl", (showTrl.isSelected()));
391         // Server Objects
392
Ini.setProperty(Ini.P_OBJECTS, (serverObjects.isSelected()));
393         // Print Preview
394
Ini.setProperty(Ini.P_PRINTPREVIEW, (printPreview.isSelected()));
395         // DebugLevel
396
Log.setTraceLevel(debugLevel.getValue());
397         Ini.setProperty(Ini.P_DEBUGLEVEL, String.valueOf(debugLevel.getValue()));
398         // Printer
399
String JavaDoc printer = (String JavaDoc)fPrinter.getSelectedItem();
400         Env.setContext(Env.getCtx(), "#Printer", printer);
401         Ini.setProperty(Ini.P_PRINTER, printer);
402         // Date (remove seconds)
403
java.sql.Timestamp JavaDoc ts = (java.sql.Timestamp JavaDoc)fDate.getValue();
404         if (ts != null)
405         {
406             java.sql.Date JavaDoc sd = new java.sql.Date JavaDoc(ts.getTime());
407             Env.setContext(Env.getCtx(), "#Date", sd.toString()); // YYYY-MM-DD
408
}
409
410         Ini.saveProperties(true);
411         if (!Ini.isClient())
412             Ini.saveProperties(false);
413
414         dispose();
415     } // cmd_save
416

417     /**
418      * Reset Errors
419      */

420     private void cmd_resetErrors()
421     {
422         LogBuffer.get().resetBuffer();
423         Vector data = LogBuffer.get().getLogData();
424         Vector columnNames = LogBuffer.get().getColumnNames(Env.getCtx());
425         DefaultTableModel model = new DefaultTableModel(data, columnNames);
426         errorTable.setModel(model);
427         //
428
tabPane.setTitleAt(2, Msg.getMsg(Env.getCtx(), "Errors") + " (" + data.size() + ")");
429         errorTable.autoSize();
430     } // cmd_resetErrors
431

432 } // Preference
433
Popular Tags