KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > rero > test > WindowTest


1 package rero.test;
2
3 import java.awt.*;
4 import java.awt.event.*;
5
6 import javax.swing.*;
7 import javax.swing.event.*;
8
9 import rero.gui.*;
10 import rero.gui.windows.*;
11
12 import rero.config.*;
13 import rero.ident.*;
14
15 import java.net.URI JavaDoc;
16
17 import java.lang.reflect.*;
18
19 public class WindowTest
20 {
21    private static void checkEnvironment()
22    {
23       boolean invalidenv = false;
24
25       try
26       {
27          String JavaDoc envs = System.getProperty("java.specification.version");
28          double ver = Double.parseDouble(envs);
29
30          if (ver == 1.4)
31          {
32             invalidenv = System.getProperty("java.vm.version").indexOf("1.4.1") > -1 || System.getProperty("java.vm.version").indexOf("1.4.0") > -1;
33          }
34          else
35          {
36             invalidenv = ver < 1.4;
37          }
38       }
39       catch (Exception JavaDoc ex) { invalidenv = true; }
40
41       if (invalidenv)
42       {
43          String JavaDoc outdated = "Outdated Java Error:\njIRC Requires a java virtual machine compatible \nwith Java 1.4.2 or greater. Download the latest \nversion of "+System.getProperty("java.vendor")+"'s Java at\n"+System.getProperty("java.vendor.url")+"\nYou are running: Java "+System.getProperty("java.version");
44
45          System.err.println(outdated);
46
47          Frame temp = new Frame();
48          JOptionPane.showMessageDialog(temp, outdated, "Outdated Java Error", JOptionPane.ERROR_MESSAGE);
49          System.exit(-1);
50       }
51    }
52
53    public static void main(String JavaDoc args[])
54    {
55       checkEnvironment(); // check if user is using an old java or not, if they are kill jIRC and notify them of the truth.
56

57       int ARGNO = 0;
58
59       //
60
// Handle Mac OS X specific stuff (iff we are on Mac OS X... won't affect anything otherwise)
61
//
62
if (System.getProperty("mrj.version") != null)
63       {
64          System.setProperty("apple.laf.useScreenMenuBar", "true");
65          System.setProperty("com.apple.macos.smallTabs", "true");
66          System.setProperty("com.apple.mrj.application.apple.menu.about.name", "jIRCii");
67
68          try
69          {
70             Class JavaDoc osxAdapter = Class.forName("apple.OSXAdapter");
71             Class JavaDoc[] defArgs = new Class JavaDoc[0]; // no arguments
72
Method registerMethod = osxAdapter.getDeclaredMethod("registerMacOSXApplication", defArgs);
73
74             if (registerMethod != null)
75             {
76                registerMethod.invoke(osxAdapter, new Object JavaDoc[0]);
77             }
78          }
79          catch (Exception JavaDoc ex)
80          {
81             System.err.println("Exception while loading the OSXAdapter:");
82             ex.printStackTrace();
83          }
84       }
85
86       //
87
// base directory stuff
88
//
89
if ((ARGNO + 1) < args.length && args[ARGNO].equals("-settings"))
90       {
91          ClientState.setBaseDirectory(args[ARGNO + 1]);
92
93          ARGNO += 2;
94       }
95
96       //
97
// Setup the appropriate look and feel based on user preferences and other such excitement
98
//
99
try
100       {
101          if ((ARGNO + 1) < args.length && args[ARGNO].equals("-lnf"))
102          {
103              UIManager.setLookAndFeel(args[ARGNO + 1]);
104              ARGNO += 2;
105          }
106          // do a blacklisting on Sun's GTK Look And Feel for the native look and feel option...
107
// heres why:
108
// 1. editbox fires a exception every time enter is pressed in it
109
// 2. some components decide to ignore properties like setOpaque()
110
// 3. it looks like crap
111
// 4. it is in my oppinion pretty broken and NOT ready for prime time yet.
112
//
113
else if (ClientState.getClientState().isOption("ui.native", ClientDefaults.ui_native) && !"com.sun.java.swing.plaf.gtk.GTKLookAndFeel".equals(UIManager.getSystemLookAndFeelClassName()))
114          {
115              UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
116          }
117          else
118          {
119              UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
120          }
121       }
122       catch (Exception JavaDoc e)
123       {
124          System.err.println("Could not load specified look and feel, using system default");
125          e.printStackTrace();
126       }
127
128       //
129
// Tell jIRCii to Watch for Proxy Server changes
130
//
131
ProxySettings.initialize();
132
133       //
134
// Initialize and launch the ident daemon
135
//
136
IdentDaemon.initialize();
137
138       //
139
// check for an irc:// specified on the command line...
140
//
141
if (ARGNO < args.length && (args[ARGNO].indexOf("irc://") > -1 || args[ARGNO].indexOf("ircs://") > -1))
142       {
143          try
144          {
145             new QuickConnect(new URI JavaDoc(args[ARGNO])); // sets up a data structure that jIRCii uses to setup auto connect for this..
146
}
147          catch (Exception JavaDoc urlex) { urlex.printStackTrace(); }
148
149          ARGNO++;
150       }
151
152       //
153
// Open the window and launch this bad boy irc client
154
//
155
new WindowTest();
156    }
157
158    protected JFrame frame;
159
160    public WindowTest()
161    {
162       frame = new JFrame("jIRCii");
163
164       GlobalCapabilities.frame = frame;
165   
166       frame.getContentPane().setLayout(new BorderLayout());
167
168       frame.getContentPane().add(new SessionManager(frame), BorderLayout.CENTER);
169
170       frame.setIconImage(ClientState.getClientState().getIcon("jirc.icon", "jicon.jpg").getImage());
171
172       int inset = (int)Toolkit.getDefaultToolkit().getScreenSize().getWidth() / 2;
173
174       frame.setBounds(ClientState.getClientState().getBounds("desktop.bounds", Toolkit.getDefaultToolkit().getScreenSize(), new Dimension(640, 480)));
175
176       frame.addWindowListener(new WindowAdapter()
177       {
178          public void windowClosing(WindowEvent ev)
179          {
180             SessionManager.getGlobalCapabilities().QuitClient();
181          }
182       });
183
184       frame.addComponentListener(new ComponentAdapter()
185       {
186          public void componentMoved(ComponentEvent ev)
187          {
188             if (ClientState.getClientState().isOption("desktop.relative", false) ||
189                 ClientState.getClientState().isOption("window.relative", false) ||
190                 ClientState.getClientState().isOption("statusbar.relative", false)
191                )
192             {
193                frame.validate();
194                ClientState.getClientState().fireChange("desktop");
195                ClientState.getClientState().fireChange("window");
196                ClientState.getClientState().fireChange("statusbar");
197                frame.repaint();
198             }
199          }
200       });
201
202       frame.show();
203    }
204 }
205
Popular Tags