KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > compiere > plaf > CompiereThemeEditor


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.plaf;
15
16 import java.awt.BorderLayout JavaDoc;
17 import java.awt.FlowLayout JavaDoc;
18 import java.awt.GridLayout JavaDoc;
19 import java.awt.event.ActionEvent JavaDoc;
20 import java.awt.event.ActionListener JavaDoc;
21 import java.util.ResourceBundle JavaDoc;
22
23 import javax.swing.JColorChooser JavaDoc;
24 import javax.swing.JDialog JavaDoc;
25 import javax.swing.UIManager JavaDoc;
26 import javax.swing.border.TitledBorder JavaDoc;
27 import javax.swing.plaf.ColorUIResource JavaDoc;
28 import javax.swing.plaf.FontUIResource JavaDoc;
29 import javax.swing.plaf.metal.MetalLookAndFeel JavaDoc;
30
31 import org.compiere.swing.CButton;
32 import org.compiere.swing.CPanel;
33 import org.compiere.util.Ini;
34
35 /**
36  * Java Theme Editor.
37  * Edit the attributes and save them in Ini.properties.
38  * Does not set background of CompiereColorUI.
39  *
40  * @author Jorg Janke
41  * @version $Id: CompiereThemeEditor.java,v 1.9 2003/10/30 15:12:03 acarstoiu Exp $
42  */

43 public class CompiereThemeEditor extends JDialog JavaDoc implements ActionListener JavaDoc
44 {
45     /**
46      * Constructor
47      * @param owner Frame owner
48      */

49     public CompiereThemeEditor (JDialog JavaDoc owner)
50     {
51         super(owner, s_res.getString("CompiereThemeEditor"), true);
52         try
53         {
54             jbInit();
55             loadTheme();
56             dynInit();
57             CompierePLAF.showCenterScreen(this);
58         }
59         catch(Exception JavaDoc e)
60         {
61             System.err.println("CompiereThemeEditor");
62             e.printStackTrace();
63         }
64     } // CompiereThemeEditor
65

66     static ResourceBundle JavaDoc s_res = ResourceBundle.getBundle("org.compiere.plaf.PlafRes");
67
68     private CButton primary1 = new CButton();
69     private CButton primary2 = new CButton();
70     private CButton primary3 = new CButton();
71     private CButton secondary1 = new CButton();
72     private CButton secondary2 = new CButton();
73     private CButton secondary3 = new CButton();
74     private CButton controlFont = new CButton();
75     private CButton systemFont = new CButton();
76     private CButton userFont = new CButton();
77     private CButton smallFont = new CButton();
78     private CButton mandatory = new CButton();
79     private CButton error = new CButton();
80     private CButton windowFont = new CButton();
81     private CButton menuFont = new CButton();
82     private CButton white = new CButton();
83     private CButton black = new CButton();
84     private CPanel confirmPanel = new CPanel();
85
86     private CButton inactive = new CButton();
87     private CButton txt_ok = new CButton();
88     private CButton txt_error = new CButton();
89     private CButton bCancel = CompierePLAF.getCancelButton();
90     private CButton bOK = CompierePLAF.getOKButton();
91     private FlowLayout JavaDoc confirmLayout = new FlowLayout JavaDoc();
92     private CPanel centerPanel = new CPanel();
93     private CPanel metalColorPanel = new CPanel();
94     private BorderLayout JavaDoc centerLayout = new BorderLayout JavaDoc();
95     private CPanel compiereColorPanel = new CPanel();
96     private TitledBorder JavaDoc metalColorBorder;
97     private TitledBorder JavaDoc compiereColorBorder;
98     private GridLayout JavaDoc metalColorLayout = new GridLayout JavaDoc();
99     private GridLayout JavaDoc compiereColorLayout = new GridLayout JavaDoc();
100     private CPanel fontPanel = new CPanel();
101     private GridLayout JavaDoc fontLayout = new GridLayout JavaDoc();
102     private TitledBorder JavaDoc fontBorder;
103     private CButton info = new CButton();
104
105     /**
106      * Static Init
107      * @throws Exception
108      */

109     private void jbInit() throws Exception JavaDoc
110     {
111         CompiereColor.setBackground(this);
112         metalColorBorder = new TitledBorder JavaDoc(s_res.getString("MetalColors"));
113         compiereColorBorder = new TitledBorder JavaDoc(s_res.getString("CompiereColors"));
114         fontBorder = new TitledBorder JavaDoc(s_res.getString("CompiereFonts"));
115         fontPanel.setBorder(fontBorder);
116         fontPanel.setOpaque(false);
117
118         this.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
119         //
120
primary1.setToolTipText(s_res.getString("Primary1Info"));
121         primary1.setText(s_res.getString("Primary1"));
122         primary1.addActionListener(this);
123         primary2.setToolTipText(s_res.getString("Primary2Info"));
124         primary2.setText(s_res.getString("Primary2"));
125         primary2.addActionListener(this);
126         primary3.setToolTipText(s_res.getString("Primary3Info"));
127         primary3.setText(s_res.getString("Primary3"));
128         primary3.addActionListener(this);
129         secondary1.setToolTipText(s_res.getString("Secondary1Info"));
130         secondary1.setText(s_res.getString("Secondary1"));
131         secondary1.addActionListener(this);
132         secondary2.setToolTipText(s_res.getString("Secondary2Info"));
133         secondary2.setText(s_res.getString("Secondary2"));
134         secondary2.addActionListener(this);
135         secondary3.setToolTipText(s_res.getString("Secondary3Info"));
136         secondary3.setText(s_res.getString("Secondary3"));
137         secondary3.addActionListener(this);
138         controlFont.setToolTipText(s_res.getString("ControlFontInfo"));
139         controlFont.setText(s_res.getString("ControlFont"));
140         controlFont.addActionListener(this);
141         systemFont.setToolTipText(s_res.getString("SystemFontInfo"));
142         systemFont.setText(s_res.getString("SystemFont"));
143         systemFont.addActionListener(this);
144         userFont.setToolTipText(s_res.getString("UserFontInfo"));
145         userFont.setText(s_res.getString("UserFont"));
146         userFont.addActionListener(this);
147         smallFont.setText(s_res.getString("SmallFont"));
148         smallFont.addActionListener(this);
149         mandatory.setToolTipText(s_res.getString("MandatoryInfo"));
150         mandatory.setText(s_res.getString("Mandatory"));
151         mandatory.addActionListener(this);
152         error.setToolTipText(s_res.getString("ErrorInfo"));
153         error.setText(s_res.getString("Error"));
154         error.addActionListener(this);
155         info.setToolTipText(s_res.getString("InfoInfo"));
156         info.setText(s_res.getString("Info"));
157         info.addActionListener(this);
158         windowFont.setText(s_res.getString("WindowTitleFont"));
159         windowFont.addActionListener(this);
160         menuFont.setText(s_res.getString("MenuFont"));
161         menuFont.addActionListener(this);
162         white.setToolTipText(s_res.getString("WhiteInfo"));
163         white.setText(s_res.getString("White"));
164         white.addActionListener(this);
165         black.setToolTipText(s_res.getString("BlackInfo"));
166         black.setText(s_res.getString("Black"));
167         black.addActionListener(this);
168         inactive.setToolTipText(s_res.getString("InactiveInfo"));
169         inactive.setText(s_res.getString("Inactive"));
170         inactive.addActionListener(this);
171         txt_ok.setToolTipText(s_res.getString("TextOKInfo"));
172         txt_ok.setText(s_res.getString("TextOK"));
173         txt_ok.addActionListener(this);
174         txt_error.setToolTipText(s_res.getString("TextIssueInfo"));
175         txt_error.setText(s_res.getString("TextIssue"));
176         txt_error.addActionListener(this);
177         //
178
confirmPanel.setLayout(confirmLayout);
179         confirmLayout.setAlignment(FlowLayout.RIGHT);
180         centerPanel.setLayout(centerLayout);
181         metalColorPanel.setBorder(metalColorBorder);
182         metalColorPanel.setOpaque(false);
183         metalColorPanel.setLayout(metalColorLayout);
184         compiereColorPanel.setLayout(compiereColorLayout);
185         compiereColorPanel.setBorder(compiereColorBorder);
186         compiereColorPanel.setOpaque(false);
187         metalColorLayout.setColumns(3);
188         metalColorLayout.setHgap(5);
189         metalColorLayout.setRows(3);
190         metalColorLayout.setVgap(5);
191         compiereColorLayout.setColumns(4);
192         compiereColorLayout.setHgap(5);
193         compiereColorLayout.setRows(2);
194         compiereColorLayout.setVgap(5);
195         fontPanel.setLayout(fontLayout);
196         fontLayout.setColumns(3);
197         fontLayout.setHgap(5);
198         fontLayout.setRows(2);
199         fontLayout.setVgap(5);
200         centerLayout.setVgap(5);
201         fontBorder.setTitle(s_res.getString("Fonts"));
202         confirmPanel.setOpaque(false);
203         this.getContentPane().add(confirmPanel, BorderLayout.SOUTH);
204         confirmPanel.add(bCancel, null);
205         confirmPanel.add(bOK, null);
206         this.getContentPane().add(centerPanel, BorderLayout.CENTER);
207         centerPanel.add(metalColorPanel, BorderLayout.NORTH);
208         metalColorPanel.add(primary1, null);
209         metalColorPanel.add(primary2, null);
210         metalColorPanel.add(primary3, null);
211         metalColorPanel.add(secondary1, null);
212         metalColorPanel.add(secondary2, null);
213         metalColorPanel.add(secondary3, null);
214         metalColorPanel.add(white, null);
215         metalColorPanel.add(black, null);
216         centerPanel.add(compiereColorPanel, BorderLayout.CENTER);
217         compiereColorPanel.add(txt_error, null);
218         centerPanel.add(fontPanel, BorderLayout.SOUTH);
219         fontPanel.add(controlFont, null);
220         fontPanel.add(systemFont, null);
221         fontPanel.add(menuFont, null);
222         fontPanel.add(userFont, null);
223         fontPanel.add(windowFont, null);
224         fontPanel.add(smallFont, null);
225         compiereColorPanel.add(error, null);
226         compiereColorPanel.add(inactive, null);
227         compiereColorPanel.add(txt_ok, null);
228         compiereColorPanel.add(mandatory, null);
229         compiereColorPanel.add(info, null);
230         bCancel.addActionListener(this);
231         bOK.addActionListener(this);
232     } // jbInit
233

234     /**
235      * Load Theme from current Setting (if MetalLookAndFeel)
236      */

237     private void loadTheme()
238     {
239         if (UIManager.getLookAndFeel() instanceof MetalLookAndFeel JavaDoc)
240         {
241             CompiereTheme.setTheme();
242         }
243         else // Not a Metal Theme
244
{
245             primary1.setEnabled(false);
246             primary2.setEnabled(false);
247             primary3.setEnabled(false);
248             secondary1.setEnabled(false);
249             secondary2.setEnabled(false);
250             secondary3.setEnabled(false);
251         }
252     } // loadTheme
253

254     /**
255      * Dynamic Init
256      */

257     private void dynInit()
258     {
259     // System.out.println("CompiereThemeEditor.dynInit");
260
CompiereTheme ct = CompiereLookAndFeel.getCompiereTheme();
261         // Colors
262
primary1.setBackground(ct.getPrimary1());
263         primary2.setBackground(ct.getPrimary2());
264         primary3.setBackground(ct.getPrimary3());
265         secondary1.setBackground(ct.getSecondary1());
266         secondary2.setBackground(ct.getSecondary2());
267         secondary3.setBackground(ct.getSecondary3());
268         //
269
white.setBackground(ct.getWhite());
270         black.setBackground(ct.getSecondary3());
271         black.setForeground(ct.getBlack());
272         //
273
error.setBackground(CompierePLAF.getFieldBackground_Error());
274         mandatory.setBackground(CompierePLAF.getFieldBackground_Mandatory());
275         inactive.setBackground(CompierePLAF.getFieldBackground_Inactive());
276         info.setBackground(CompierePLAF.getInfoBackground());
277         //
278
txt_ok.setBackground(CompierePLAF.getFieldBackground_Normal());
279         txt_ok.setForeground(CompierePLAF.getTextColor_OK());
280         txt_error.setBackground(CompierePLAF.getFieldBackground_Normal());
281         txt_error.setForeground(CompierePLAF.getTextColor_Issue());
282
283         // Fonts
284
controlFont.setFont(ct.getControlTextFont());
285         systemFont.setFont(ct.getSystemTextFont());
286         userFont.setFont(ct.getUserTextFont());
287         smallFont.setFont(ct.getSubTextFont());
288         menuFont.setFont(ct.getMenuTextFont());
289         windowFont.setFont(ct.getWindowTitleFont());
290     } // dynInit
291

292     /**
293      * Action Listener
294      * @param e
295      */

296     public void actionPerformed(ActionEvent JavaDoc e)
297     {
298     // System.out.println("CompiereThemeEditor.actionPerformed " + e);
299
// Confirm
300
if (e.getSource() == bOK)
301         {
302             CompiereTheme.save(Ini.getProperties());
303             dispose();
304             return;
305         }
306         // Cancel
307
else if (e.getSource() == bCancel)
308         {
309             dispose();
310             return;
311         }
312         CompiereTheme vt = new CompiereTheme();
313
314         try { // to capture errors when Cancel in JColorChooser
315

316         if (e.getSource() == primary1)
317         {
318             CompiereTheme.primary1 = new ColorUIResource JavaDoc(JColorChooser.showDialog
319                 (this, s_res.getString("Primary1"), CompiereTheme.primary1));
320         }
321         else if (e.getSource() == primary2)
322         {
323             CompiereTheme.primary2 = new ColorUIResource JavaDoc(JColorChooser.showDialog
324                 (this, s_res.getString("Primary2"), CompiereTheme.primary2));
325         }
326         else if (e.getSource() == primary3)
327         {
328             CompiereTheme.primary3 = new ColorUIResource JavaDoc(JColorChooser.showDialog
329                 (this, s_res.getString("Primary3"), CompiereTheme.primary3));
330         }
331         else if (e.getSource() == secondary1)
332         {
333             CompiereTheme.secondary1 = new ColorUIResource JavaDoc(JColorChooser.showDialog
334                 (this, s_res.getString("Secondary1"), CompiereTheme.secondary1));
335         }
336         else if (e.getSource() == secondary2)
337         {
338             CompiereTheme.secondary2 = new ColorUIResource JavaDoc(JColorChooser.showDialog
339                 (this, s_res.getString("Secondary2"), CompiereTheme.secondary2));
340         }
341         else if (e.getSource() == secondary3)
342         {
343             CompiereTheme.secondary3 = new ColorUIResource JavaDoc(JColorChooser.showDialog
344                 (this, s_res.getString("Secondary3"), CompiereTheme.secondary3));
345         }
346
347         else if (e.getSource() == error)
348         {
349             CompiereTheme.error = new ColorUIResource JavaDoc(JColorChooser.showDialog
350                 (this, s_res.getString("Error"), CompiereTheme.error));
351         }
352         else if (e.getSource() == mandatory)
353         {
354             CompiereTheme.mandatory = new ColorUIResource JavaDoc(JColorChooser.showDialog
355                 (this, s_res.getString("Mandatory"), CompiereTheme.mandatory));
356         }
357         else if (e.getSource() == inactive)
358         {
359             CompiereTheme.inactive = new ColorUIResource JavaDoc(JColorChooser.showDialog
360                 (this, s_res.getString("Inactive"), CompiereTheme.inactive));
361         }
362         else if (e.getSource() == info)
363         {
364             CompiereTheme.info = new ColorUIResource JavaDoc(JColorChooser.showDialog
365                 (this, s_res.getString("Info"), CompiereTheme.info));
366         }
367
368         else if (e.getSource() == black)
369         {
370             CompiereTheme.black = new ColorUIResource JavaDoc(JColorChooser.showDialog
371                 (this, s_res.getString("Black"), CompiereTheme.black));
372         }
373         else if (e.getSource() == white)
374         {
375             CompiereTheme.white = new ColorUIResource JavaDoc(JColorChooser.showDialog
376                 (this, s_res.getString("White"), CompiereTheme.white));
377         }
378         else if (e.getSource() == txt_ok)
379         {
380             CompiereTheme.txt_ok = new ColorUIResource JavaDoc(JColorChooser.showDialog
381                 (this, s_res.getString("TextOK"), CompiereTheme.txt_ok));
382         }
383         else if (e.getSource() == txt_error)
384         {
385             CompiereTheme.txt_error = new ColorUIResource JavaDoc(JColorChooser.showDialog
386                 (this, s_res.getString("TextIssue"), CompiereTheme.txt_error));
387         }
388
389         else if (e.getSource() == controlFont)
390         {
391             CompiereTheme.controlFont = new FontUIResource JavaDoc(FontChooser.showDialog
392                 (this, s_res.getString("ControlFont"), vt.getControlTextFont()));
393         }
394         else if (e.getSource() == systemFont)
395         {
396             CompiereTheme.systemFont = new FontUIResource JavaDoc(FontChooser.showDialog
397                 (this, s_res.getString("SystemFont"), vt.getSystemTextFont()));
398         }
399         else if (e.getSource() == userFont)
400         {
401             CompiereTheme.userFont = new FontUIResource JavaDoc(FontChooser.showDialog
402                 (this, s_res.getString("UserFont"), vt.getUserTextFont()));
403         }
404         else if (e.getSource() == smallFont)
405         {
406             CompiereTheme.smallFont = new FontUIResource JavaDoc(FontChooser.showDialog
407                 (this, s_res.getString("SmallFont"), vt.getSubTextFont()));
408         }
409         else if (e.getSource() == menuFont)
410         {
411             CompiereTheme.menuFont = new FontUIResource JavaDoc(FontChooser.showDialog
412                 (this, s_res.getString("MenuFont"), vt.getMenuTextFont()));
413         }
414         else if (e.getSource() == windowFont)
415         {
416             CompiereTheme.windowFont = new FontUIResource JavaDoc(FontChooser.showDialog
417                 (this, s_res.getString("WindowTitleFont"), vt.getWindowTitleFont()));
418         }
419
420         } catch (Exception JavaDoc ee) {} // to capture errors when Cancel in JColorChooser
421

422         dynInit();
423     } // actionPerformed
424

425 } // CompiereThemeEditor
426
Popular Tags