Source code: junk/gui/JXLookAndFeel.java
1 /*
2 * @(#)JXLookAndFeel.java
3 * Copyright (C) 2002 Tay Hock Keong <tay_ivan@hotmail.com>
4 * This file is part of JD4X.
5 * JD4X is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2, or (at your option)
8 * any later version.
9 * JD4X is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with JD4X; see the file COPYING. If not, write to the Free
15 * Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
16 */
17
18 package junk.gui;
19
20 import java.awt.*;
21 import java.awt.event.*;
22 import java.awt.event.MouseEvent.*;
23 import javax.swing.*;
24
25 /**
26 * JXLookAndFeel provides the Java cross platform metal look and feel support on
27 * the JD4X system as a default. However, once the JD4X windowing module can
28 * support its own look and feel, this class may be deprecated. The advantage of
29 * keeping this implementation is that it depends on the J2SDK AWT and therefore
30 * it will be more portable than the JD4X windowing module. The disadvantage is
31 * that it is undependable and may result in inconsistant heavy weight component
32 * behaviour because the AWT depends on an existing desktop windowing manager
33 * that do not exist in the JD4X system without the windowing module. The reason
34 * that it is being introduced at this stage is because it can stand in as a
35 * temporary replacement for the windowing module. Clients should not depend on
36 * this implementation for proper desktop GUI support because it leaves the
37 * client with very limited customizing options.
38 * <BR>IMPORTANT: This class is deprecated as of 08/06/2003. Moth should be used
39 * instead for dependable windowing behavior. This class remains in the JD4X
40 * distribution only for porting purposes. Do not use this class togather with
41 * Moth as it duplicates the work done by Moth.
42 * @version 0.1, 08/05/2002
43 * @since JD4X 1.0
44 * @author Tay Hock Keong
45 */
46
47 public class JXLookAndFeel implements AWTEventListener{
48
49 /**
50 * Disallow an instance of this class to be created. It is only
51 * meant to be a static utility tool.
52 */
53 private JXLookAndFeel(){
54 }
55
56 /**
57 * Invoked when an event is dispatched in the AWT. It uses some very simple
58 * windowing techiques to provide a cheap hack on the heavy weight desktop
59 * components. This method has been depricated!
60 * @param event
61 * the event that occured.
62 */
63 public void eventDispatched(AWTEvent event){
64 /*Object obj = event.getSource();
65 long eid = (long) event.getID();
66 long we = eid & AWTEvent.WINDOW_EVENT_MASK;*/
67 /* only detected within a Jvm. */
68 /*if(we == AWTEvent.WINDOW_EVENT_MASK){
69 if(obj instanceof javax.swing.JFrame){
70 JFrame jf = (JFrame)obj;
71 jf.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
72 }
73 else if(obj instanceof javax.swing.JDialog){
74 JDialog jd = (JDialog)obj;
75 jd.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
76 }
77 else if(obj instanceof java.awt.Window){
78 System.out.println("Window event detected -> Window");
79 }
80 }*/
81 /*if(eid == (long)java.awt.event.MouseEvent.MOUSE_CLICKED){
82 if(obj instanceof Window){
83 Window win = (Window)obj;
84 win.toFront();
85 }
86 }*/
87 }
88
89 /**
90 * Provide support for the Java Metal Look & Feel in the JD4X system.
91 * @return
92 * true=Look & Feel is supportable, else it cannot support the Java
93 * metal Look & Feel.
94 * @throws ClassNotFoundException
95 * thrown if the LookAndFeel class could not be found.
96 * @throws InstantiationException
97 * thrown if a new instance of the class couldn't be created.
98 * @throws IllegalAccessException
99 * thrown if the class or initializer isn't accessible.
100 * @throws UnsupportedLookAndFeelException
101 * thrown if lnf.isSupportedLookAndFeel() is false.
102 */
103 public static void supportJavaLookNFeel() throws ClassNotFoundException,
104 InstantiationException, IllegalAccessException, UnsupportedLookAndFeelException{
105 //for future might be used drawing support.
106 Toolkit tk = Toolkit.getDefaultToolkit();
107 tk.setDynamicLayout(true);
108 tk.sync();
109 //setup windowing support hack. Cheap trick!
110 /*long eventMask = AWTEvent.MOUSE_EVENT_MASK; // | AWTEvent.WINDOW_EVENT_MASK;
111 tk.addAWTEventListener(new JXLookAndFeel(), eventMask);*/
112 //setup Java Metal theme Swing support.
113 System.setProperty("sun.awt.noerasebackground","true");
114 JDialog.setDefaultLookAndFeelDecorated(true);
115 JFrame.setDefaultLookAndFeelDecorated(true);
116 javax.swing.plaf.metal.MetalLookAndFeel.setCurrentTheme(new javax.swing.plaf.metal.DefaultMetalTheme());
117 UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
118 }
119 }