source: trunk/src/org/expeditee/gui/Browser.java@ 71

Last change on this file since 71 was 71, checked in by ra33, 16 years ago

Removed last remnants of adjusting position of items to account for the titleBar and the edge of the browser window.

Also fixed stuff with conversion of color and points so that they can handle additive mode correctly

File size: 5.9 KB
Line 
1package org.expeditee.gui;
2
3import java.awt.Color;
4import java.awt.Dimension;
5import java.awt.Graphics;
6import java.awt.Graphics2D;
7import java.awt.RenderingHints;
8import java.awt.Toolkit;
9import java.awt.event.ComponentEvent;
10import java.awt.event.ComponentListener;
11import java.awt.event.WindowEvent;
12import java.awt.event.WindowListener;
13import java.awt.event.WindowStateListener;
14
15import javax.swing.JFrame;
16
17import org.expeditee.AbsoluteLayout;
18import org.expeditee.actions.Actions;
19import org.expeditee.actions.Misc;
20import org.expeditee.io.Logger;
21
22/**
23 * The Main GUI class, comprises what people will see on the screen.<br>
24 * Note: Each Object (Item) is responsible for drawing itself on the screen.<br>
25 * Note2: The Frame is registered as a MouseListener and KeyListener, and
26 * processes any Events.
27 *
28 * @author jdm18
29 *
30 */
31public class Browser extends JFrame implements ComponentListener,
32 WindowListener, WindowStateListener {
33
34 /**
35 * Default version - just to stop eclipse from complaining about it.
36 */
37 private static final long serialVersionUID = 1L;
38
39 // private static final JScrollPane scrollPane = new JScrollPane();
40
41 public static Browser _theBrowser;
42
43 /**
44 * Constructs a new Browser object, then launches it
45 *
46 * @param args
47 */
48 public static void main(String[] args) {
49 _theBrowser = new Browser();
50 // Why do we want to ignore repaint?
51 //_theBrowser.setIgnoreRepaint(true);
52 _theBrowser.requestFocus();
53 // FrameGraphics.ForceRepaint();
54 }
55
56 public void setSizes(Dimension size) {
57 setSize(size);
58 setPreferredSize(size);
59
60 FrameGraphics.setMaxSize(this.getContentPane().getSize());
61 }
62
63 public Browser() {
64 // Use the default values initially so we can load the profile frame
65 setSizes(new Dimension(UserSettings.InitialWidth,
66 UserSettings.InitialHeight));
67 // center the frame on the screen
68 Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
69 double xpos = screen.getWidth() / 2;
70 double ypos = screen.getHeight() / 2;
71 setLocation((int) (xpos - (UserSettings.InitialWidth / 2)),
72 (int) (ypos - (UserSettings.InitialHeight / 2)));
73
74 addWindowListener(this);
75 addWindowStateListener(this);
76
77 UserSettings.Init();
78 UserSettings.Username = FrameIO.ConvertToValidFramesetName(System
79 .getProperty("user.name"));
80 String userName = UserSettings.Username;
81 Frame profile = FrameIO.LoadProfile(userName);
82 if (profile == null) {
83 try {
84 profile = FrameIO.CreateNewProfile(userName);
85 } catch (Exception e) {
86 // TODO tell the user that there was a problem creating the
87 // profile frame and close nicely
88 e.printStackTrace();
89 assert (false);
90 }
91 }
92 FrameUtils.ParseProfile(profile);
93
94 // Now reset the size of the windows to the size specified in the users
95 // profile
96 setSizes(new Dimension(UserSettings.InitialWidth,
97 UserSettings.InitialHeight));
98
99 // set the layout to absolute layout for widgets
100 this.getContentPane().setLayout(new AbsoluteLayout());
101 // enable the glasspane-for capturing all mouse events
102 this
103 .setGlassPane(new MouseEventRouter(getJMenuBar(),
104 getContentPane()));
105 this.getGlassPane().setVisible(true);
106 this.getContentPane().setBackground(Color.white);
107 this.getContentPane().setFocusTraversalKeysEnabled(false);
108
109 setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
110
111 addComponentListener(this);
112 pack();
113 try {
114 go();
115 } catch (Exception e) {
116 e.printStackTrace();
117 Logger.Log(e);
118 }
119 // FrameGraphics.ForceRepaint();
120 }
121
122 Graphics2D g;
123
124 /**
125 * Loads in the Menus and the first Frame.
126 */
127 public void go() {
128
129 Actions.Init();
130 DisplayIO.Init(this);
131 // Set visible must be just after DisplayIO.Init for the message box to
132 // be the right size
133 setVisible(true);
134
135 setupGraphics();
136
137 // required to accept TAB key
138 setFocusTraversalKeysEnabled(false);
139
140 assert (UserSettings.FirstFrame != null);
141 Frame firstFrame = FrameIO.LoadFrame(UserSettings.FirstFrame);
142
143 DisplayIO.setCurrentFrame(firstFrame);
144 DisplayIO.UpdateTitle();
145
146 FrameKeyboardActions keyboardListner = new FrameKeyboardActions();
147 this.getContentPane().addKeyListener(keyboardListner);
148 this.addKeyListener(keyboardListner);
149 }
150
151 private void setupGraphics() {
152 if (g != null)
153 g.dispose();
154 g = (Graphics2D) this.getContentPane().getGraphics();
155 assert (g != null);
156 g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
157 RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
158 g.setFont(g.getFont().deriveFont(40f));
159 FrameGraphics.setDisplayGraphics(g);
160 }
161
162 // private int count = 0;
163 @Override
164 public void paint(Graphics g) {
165 // All this does is make sure the screen is repainted when the browser
166 // is moved so that some of the window is off the edge of the display
167 // then moved back into view
168 super.paint(g);
169 FrameGraphics.Repaint();
170 //System.out.println("Paint " + count++);
171 }
172
173 /**
174 * @inheritDoc
175 */
176 public void componentResized(ComponentEvent e) {
177 setSizes(this.getSize());
178 setupGraphics();
179 FrameIO.RefreshCasheImages();
180 FrameGraphics.Repaint();
181 }
182
183 /**
184 * @inheritDoc
185 */
186 public void componentMoved(ComponentEvent e) {
187 // FrameGraphics.setMaxSize(this.getSize());
188 }
189
190 /**
191 * @inheritDoc
192 */
193 public void componentShown(ComponentEvent e) {
194 }
195
196 /**
197 * @inheritDoc
198 */
199 public void componentHidden(ComponentEvent e) {
200 }
201
202 public void windowClosing(WindowEvent e) {
203 Misc.Exit();
204 }
205
206 public void windowClosed(WindowEvent e) {
207 }
208
209 public void windowOpened(WindowEvent e) {
210 }
211
212 public void windowIconified(WindowEvent e) {
213 }
214
215 public void windowDeiconified(WindowEvent e) {
216 }
217
218 public void windowActivated(WindowEvent e) {
219 // System.out.println("Activated");
220 }
221
222 public void windowDeactivated(WindowEvent e) {
223 }
224
225 public void windowStateChanged(WindowEvent e) {
226 // FrameGraphics.Repaint();
227 // System.out.println('C');
228 }
229
230 public int getDrawingAreaX() {
231 // return scrollPane.getLocationOnScreen().x;
232 return this.getLocationOnScreen().x;
233 }
234
235 public int getDrawingAreaY() {
236 // return scrollPane.getLocationOnScreen().y;
237 return this.getLocationOnScreen().y;
238 }
239}
Note: See TracBrowser for help on using the repository browser.