001 /* steelme theme manager for Java
002 * Copyright (C) 2000 - 2004 T.J. Willis
003 *
004 * This program is free software; you can redistribute it and/or
005 * modify it under the terms of the GNU General Public License
006 * as published by the Free Software Foundation; either version 2
007 * of the License, or (at your option) any later version.
008 *
009 * This program is distributed in the hope that it will be useful,
010 * but WITHOUT ANY WARRANTY; without even the implied warranty of
011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
012 * GNU General Public License for more details.
013 *
014 * You should have received a copy of the GNU General Public License
015 * along with this program; if not, write to the Free Software
016 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
017 *
018 * $Header: /cvsroot/steelme/steelme/src/net/sourceforge/steelme/ThemeEditor.java,v 1.4 2004/05/27 23:11:09 tj_willis Exp $
019 */
020 package net.sourceforge.steelme;
021
022 import java.awt.*;
023 import javax.swing.*;
024 import javax.swing.plaf.metal.*;
025 import javax.swing.plaf.*;
026 import org.apache.log4j.*;
027
028 /**
029 * Describe class <code>ThemeEditor</code> here.
030 *
031 * @author <a href="mailto:tj_willis@users.sourceforge.net">T.J. Willis</a>
032 * @version 1.0
033 * @has 1 Has - net.sourceforge.steelme.SteelmeTheme
034 * @has 1 Has - net.sourceforge.steelme.SteelmeThemeManager
035 * @has 1..n Has - net.sourceforge.steelme.ThemeResistantJButton
036 * @has 1 Has - net.sourceforge.steelme.FontChooserPanel
037 * @has 1 Has - net.sourceforge.steelme.ThemeFileFilter
038
039
040 */
041 public class ThemeEditor
042 extends javax.swing.JFrame
043 implements ThemeChangedListener
044 {
045 Category cat = Category.getInstance(ThemeEditor.class.getName());
046
047 // FIXED: minimize access
048 private Color cp1;
049 private Color cp2;
050 private Color cp3;
051 private Color cs1;
052 private Color cs2;
053 private Color cs3;
054 private Font font;
055 private Color ct1;
056 private Color ct2;
057 private Color cw,cb;
058 private SteelmeTheme def;
059 private JRootPane target;
060
061 /** Creates new ThemeEditor */
062 public ThemeEditor() {
063 super("steelme Theme Editor");
064 init();
065 }
066
067 public ThemeEditor(JComponent target) {
068 this();
069 this.target = target.getRootPane();
070 }
071
072
073 private final void init(){
074 def = SteelmeThemeManager.getCurrentTheme();
075 // if(def==null) {
076 // MetalTheme m = MetalLookAndFeel.getCurrentTheme();
077 // def = new SteelmeTheme(m);
078 // }
079 if(def==null) {
080 def = new SteelmeTheme();
081 }
082 SteelmeThemeManager.addListener(this);
083 initComponents();
084 if(def!=null) {
085 setColors(def);
086 setButtons(def);
087 }
088 }
089
090 /**
091 * Describe <code>setTheme</code> method here.
092 *
093 * @param p a <code>SteelmeTheme</code> value
094 */
095 public void setTheme(SteelmeTheme p) {
096 //PavlovMetalThemeManager.setCurrentTheme(def);
097 setColors(p);
098 setButtons(p);
099 }
100
101 /**
102 * Describe <code>setButtons</code> method here.
103 *
104 * @param p a <code>SteelmeTheme</code> value
105 */
106 protected void setButtons(SteelmeTheme p) {
107 p1.setMyBackground(cp1);
108 p2.setMyBackground(cp2);
109 p3.setMyBackground(cp3);
110 s1.setMyBackground(cs1);
111 s2.setMyBackground(cs2);
112 s3.setMyBackground(cs3);
113 t1.setMyBackground(ct1);
114 t2.setMyBackground(ct2);
115 w.setMyBackground(cw);
116 b.setMyBackground(cb);
117 fontChooser.setThemeFont(font);
118 }
119 /**
120 * Describe <code>setColors</code> method here.
121 *
122 * @param p a <code>SteelmeTheme</code> value
123 */
124 protected void setColors(SteelmeTheme p) {
125 cp1 = (Color)p.getP1();
126 cp2 = (Color)p.getP2();
127 cp3 = (Color)p.getP3();
128 cs1 = (Color)p.getS1();
129 cs2 = (Color)p.getS2();
130 cs3 = (Color)p.getS3();
131 font = (Font)p.getUserTextFont();
132 ct1 = (Color)p.getT1();
133 ct2 = (Color)p.getT2();
134 cw = (Color)p.getW();
135 cb = (Color)p.getB();
136 }
137
138
139
140 private void initComponents() {
141 jLabel1 = new JLabel();
142 jPanel1 = new JPanel();
143 jLabel6 = new JLabel();
144 p1 = new ThemeResistantJButton();
145 jLabel7 = new JLabel();
146 s1 = new ThemeResistantJButton();
147 jLabel9 = new JLabel();
148 p2 = new ThemeResistantJButton();
149 jLabel8 = new JLabel();
150 s2 = new ThemeResistantJButton();
151 jLabel10 = new JLabel();
152 p3 = new ThemeResistantJButton();
153 jLabel11 = new JLabel();
154 s3 = new ThemeResistantJButton();
155 jLabel12 = new JLabel();
156 t1 = new ThemeResistantJButton();
157 jLabel13 = new JLabel();
158 t2 = new ThemeResistantJButton();
159
160 jLabel14 = new JLabel();
161 w = new ThemeResistantJButton();
162 jLabel15 = new JLabel();
163 b = new ThemeResistantJButton();
164
165 jLabel18 = new JLabel();
166 jTextField1 = new JTextField();
167 jLabel19 = new JLabel();
168 //jButton13 = new JButton();
169 fontChooser = new FontChooserPanel(font);
170 jPanel3 = new JPanel();
171 save = new JButton();
172 apply = new JButton();
173 done = new JButton();
174
175 getContentPane().setLayout(new java.awt.GridBagLayout());
176 java.awt.GridBagConstraints gridBagConstraints1;
177
178 jLabel1.setHorizontalAlignment(SwingConstants.CENTER);
179 jLabel1.setText("");
180 gridBagConstraints1 = new java.awt.GridBagConstraints();
181 gridBagConstraints1.gridwidth = 4;
182 gridBagConstraints1.fill = java.awt.GridBagConstraints.HORIZONTAL;
183 getContentPane().add(jLabel1, gridBagConstraints1);
184
185 jPanel1.setLayout(new java.awt.GridLayout(5, 4));
186
187 jLabel6.setText("Active Window Border:");
188 jPanel1.add(jLabel6);
189
190 p1.setText("Choose...");
191 p1.addActionListener(new java.awt.event.ActionListener() {
192 public void actionPerformed(java.awt.event.ActionEvent evt) {
193 p1ActionPerformed(evt);
194 }
195 }
196 );
197
198 jPanel1.add(p1);
199
200 jLabel7.setText("Inactive Window Border:");
201 jPanel1.add(jLabel7);
202
203 s1.setText("Choose...");
204 s1.addActionListener(new java.awt.event.ActionListener() {
205 public void actionPerformed(java.awt.event.ActionEvent evt) {
206 s1ActionPerformed(evt);
207 }
208 }
209 );
210
211 jPanel1.add(s1);
212
213 jLabel9.setText("Desktop Background:"); //desktop ref OK
214 jPanel1.add(jLabel9);
215
216 p2.setText("Choose...");
217 p2.addActionListener(new java.awt.event.ActionListener() {
218 public void actionPerformed(java.awt.event.ActionEvent evt) {
219 p2ActionPerformed(evt);
220 }
221 }
222 );
223
224 jPanel1.add(p2);
225
226 jLabel8.setText("Borders:");
227 jPanel1.add(jLabel8);
228
229 s2.setText("Choose...");
230 s2.addActionListener(new java.awt.event.ActionListener() {
231 public void actionPerformed(java.awt.event.ActionEvent evt) {
232 s2ActionPerformed(evt);
233 }
234 }
235 );
236
237 jPanel1.add(s2);
238
239 jLabel10.setText("Active Window Title Bkgd:");
240 jPanel1.add(jLabel10);
241
242 p3.setText("Choose...");
243 p3.addActionListener(new java.awt.event.ActionListener() {
244 public void actionPerformed(java.awt.event.ActionEvent evt) {
245 p3ActionPerformed(evt);
246 }
247 }
248 );
249
250 jPanel1.add(p3);
251
252 jLabel11.setText("Frame and Menu Background:");
253 jPanel1.add(jLabel11);
254
255 s3.setText("Choose...");
256 s3.addActionListener(new java.awt.event.ActionListener() {
257 public void actionPerformed(java.awt.event.ActionEvent evt) {
258 s3ActionPerformed(evt);
259 }
260 }
261 );
262
263 jPanel1.add(s3);
264
265 jLabel12.setText("Active Text Color:");
266 jPanel1.add(jLabel12);
267
268 t1.setText("Choose...");
269 t1.addActionListener(new java.awt.event.ActionListener() {
270 public void actionPerformed(java.awt.event.ActionEvent evt) {
271 t1ActionPerformed(evt);
272 }
273 }
274 );
275
276 jPanel1.add(t1);
277
278 jLabel13.setText("Inactive Text Color:");
279 jPanel1.add(jLabel13);
280
281 t2.setText("Choose...");
282 t2.addActionListener(new java.awt.event.ActionListener() {
283 public void actionPerformed(java.awt.event.ActionEvent evt) {
284 t2ActionPerformed(evt);
285 }
286 }
287 );
288
289 jPanel1.add(t2);
290
291
292 jLabel14.setText("Widget Background Color:");
293 jPanel1.add(jLabel14);
294
295 w.setText("Choose...");
296 w.addActionListener(new java.awt.event.ActionListener() {
297 public void actionPerformed(java.awt.event.ActionEvent evt) {
298 wActionPerformed(evt);
299 }
300 }
301 );
302
303 jPanel1.add(w);
304
305 jLabel15.setText("System Text Color:");
306 jPanel1.add(jLabel15);
307
308 b.setText("Choose...");
309 b.addActionListener(new java.awt.event.ActionListener() {
310 public void actionPerformed(java.awt.event.ActionEvent evt) {
311 bActionPerformed(evt);
312 }
313 }
314 );
315
316 jPanel1.add(b);
317
318
319
320
321 gridBagConstraints1 = new java.awt.GridBagConstraints();
322 gridBagConstraints1.gridx = 0;
323 gridBagConstraints1.gridy = 2;
324 gridBagConstraints1.gridwidth = 4;
325 gridBagConstraints1.gridheight = 3;
326 gridBagConstraints1.weightx = 1.0;
327 getContentPane().add(jPanel1, gridBagConstraints1);
328
329 jLabel18.setHorizontalAlignment(SwingConstants.RIGHT);
330 jLabel18.setText("Theme Name:");
331 jLabel18.setVerticalAlignment(SwingConstants.BOTTOM);
332 gridBagConstraints1 = new java.awt.GridBagConstraints();
333 gridBagConstraints1.gridx = 2;
334 gridBagConstraints1.gridy = 5;
335 gridBagConstraints1.fill = java.awt.GridBagConstraints.HORIZONTAL;
336 gridBagConstraints1.anchor = java.awt.GridBagConstraints.EAST;
337 getContentPane().add(jLabel18, gridBagConstraints1);
338
339 jTextField1.setColumns(20);
340 jTextField1.setText("Unnamed Theme");
341 gridBagConstraints1 = new java.awt.GridBagConstraints();
342 gridBagConstraints1.gridx = 3;
343 gridBagConstraints1.gridy = 5;
344 gridBagConstraints1.fill = java.awt.GridBagConstraints.BOTH;
345 getContentPane().add(jTextField1, gridBagConstraints1);
346
347 jLabel19.setText("Font:");
348 gridBagConstraints1 = new java.awt.GridBagConstraints();
349 gridBagConstraints1.gridx = 2;
350 gridBagConstraints1.gridy = 6;
351 getContentPane().add(jLabel19, gridBagConstraints1);
352
353 //jButton13.setText("Choose...");
354 fontChooser.setMaximumSize(new java.awt.Dimension(235, 235));
355 fontChooser.setMinimumSize(new java.awt.Dimension(235, 235));
356 gridBagConstraints1 = new java.awt.GridBagConstraints();
357 gridBagConstraints1.gridx = 3;
358 gridBagConstraints1.gridy = 6;
359 gridBagConstraints1.gridheight = 3;
360 gridBagConstraints1.fill = java.awt.GridBagConstraints.BOTH;
361 gridBagConstraints1.weightx = 1.0;
362 gridBagConstraints1.weighty = 1.0;
363 getContentPane().add(fontChooser, gridBagConstraints1);
364
365 save.setText("Save");
366 //save.setEnabled(false);
367 save.addActionListener(new java.awt.event.ActionListener() {
368 public void actionPerformed(java.awt.event.ActionEvent evt) {
369 saveActionPerformed(evt);
370 }
371 }
372 );
373 jPanel3.add(save);
374
375 apply.setText("Apply");
376 apply.addActionListener(new java.awt.event.ActionListener() {
377 public void actionPerformed(java.awt.event.ActionEvent evt) {
378 applyActionPerformed(evt);
379 }
380 }
381 );
382
383 jPanel3.add(apply);
384
385 done.setText("Done");
386 done.addActionListener(new java.awt.event.ActionListener() {
387 public void actionPerformed(java.awt.event.ActionEvent evt) {
388 doneActionPerformed(evt);
389 }
390 }
391 );
392
393 jPanel3.add(done);
394
395 gridBagConstraints1 = new java.awt.GridBagConstraints();
396 gridBagConstraints1.gridx = 3;
397 gridBagConstraints1.gridy = 9;
398 gridBagConstraints1.gridwidth = 2;
399 gridBagConstraints1.fill = java.awt.GridBagConstraints.HORIZONTAL;
400 getContentPane().add(jPanel3, gridBagConstraints1);
401
402 this.pack();
403 }
404
405 private void doneActionPerformed(java.awt.event.ActionEvent evt) {
406 this.setVisible(false);
407 // Add your handling code here:
408 }
409
410 private void saveActionPerformed(java.awt.event.ActionEvent evt) {
411 font = fontChooser.getSelectedFont(); // NPE's
412 SteelmeTheme p = new SteelmeTheme(cp1,cp2,cp3,cs1,cs2,cs3,font,ct1,ct2,cw,cb);
413 p.setName(jTextField1.getText());
414 p.applyTheme(target);
415 SteelmeThemeManager.setCurrentTheme(p);
416 p.save();
417 }
418
419 private void applyActionPerformed(java.awt.event.ActionEvent evt) {
420 font = fontChooser.getSelectedFont(); // NPE's
421 SteelmeTheme p = new SteelmeTheme(cp1,cp2,cp3,cs1,cs2,cs3,font,ct1,ct2,cw,cb);
422 p.applyTheme(target);
423 SteelmeThemeManager.setCurrentTheme(p);
424 }
425
426 private void s3ActionPerformed(java.awt.event.ActionEvent evt) {
427 cs3 = JColorChooser.showDialog(this,"Choose Color",cs3);
428 s3.setMyBackground(cs3);
429 }
430
431 private void s2ActionPerformed(java.awt.event.ActionEvent evt) {
432 cs2 = JColorChooser.showDialog(this,"Choose Color",cs2);
433 // Add your handling code here:
434 s2.setMyBackground(cs2);
435 }
436
437 private void t1ActionPerformed(java.awt.event.ActionEvent evt) {
438 ct1 = JColorChooser.showDialog(this,"Choose Color",ct1);
439 t1.setMyBackground(ct1);
440 }
441
442 private void t2ActionPerformed(java.awt.event.ActionEvent evt) {
443 ct2 = JColorChooser.showDialog(this,"Choose Color",ct2);
444 // Add your handling code here:
445 t2.setMyBackground(ct2);
446 }
447
448 private void s1ActionPerformed(java.awt.event.ActionEvent evt) {
449 // Add your handling code here:
450 cs1 = JColorChooser.showDialog(this,"Choose Color",cs1);
451 s1.setMyBackground(cs1);
452 }
453
454 private void p3ActionPerformed(java.awt.event.ActionEvent evt) {
455 cp3 = JColorChooser.showDialog(this,"Choose Color",cp3);
456 // Add your handling code here:
457 p3.setMyBackground(cp3);
458 }
459
460 private void p1ActionPerformed(java.awt.event.ActionEvent evt) {
461 cp1 = JColorChooser.showDialog(this,"Choose Color",cp1);
462 // Add your handling code here:
463 p1.setMyBackground(cp1);
464 }
465
466 private void p2ActionPerformed(java.awt.event.ActionEvent evt) {
467 cp2 = JColorChooser.showDialog(this,"Choose Color",cp2);
468 // Add your handling code here:
469 p2.setMyBackground(cp2);
470 }
471
472 private void wActionPerformed(java.awt.event.ActionEvent evt) {
473 cw = JColorChooser.showDialog(this,"Choose Color",cw);
474 // Add your handling code here:
475 w.setMyBackground(cw);
476 }
477
478 private void bActionPerformed(java.awt.event.ActionEvent evt) {
479 cb = JColorChooser.showDialog(this,"Choose Color",cb);
480 // Add your handling code here:
481 b.setMyBackground(cb);
482 }
483
484 // Variables declaration - do not modify
485 private JLabel jLabel1;
486 private JPanel jPanel1;
487 private JLabel jLabel6;
488 private ThemeResistantJButton p1;
489 private JLabel jLabel7;
490 private ThemeResistantJButton s1;
491 private JLabel jLabel9;
492 private ThemeResistantJButton p2;
493 private JLabel jLabel8;
494 private ThemeResistantJButton s2;
495 private JLabel jLabel10;
496 private ThemeResistantJButton p3;
497 private JLabel jLabel11;
498 private ThemeResistantJButton s3;
499 private JLabel jLabel12;
500 private ThemeResistantJButton t1;
501 private JLabel jLabel13;
502 private ThemeResistantJButton t2;
503 private JLabel jLabel14;
504 private ThemeResistantJButton w;
505 private JLabel jLabel15;
506 private ThemeResistantJButton b;
507 private JLabel jLabel18;
508 private JTextField jTextField1;
509 private JLabel jLabel19;
510 //private JButton jButton13;
511 private FontChooserPanel fontChooser;
512 private JPanel jPanel3;
513 private JButton save;
514 private JButton apply;
515 private JButton done;
516 // End of variables declaration
517
518
519
520 /**
521 * Describe <code>themeChanged</code> method here.
522 *
523 * @param newTheme a <code>SteelmeTheme</code> value
524 */
525 public void themeChanged(SteelmeTheme newTheme) {
526 setTheme(newTheme);
527 }
528
529 }