01: /*
02: * Copyright (C) 2007 Jared Alexander Spigner
03: *
04: * This library is free software; you can redistribute it and/or
05: * modify it under the terms of the GNU Lesser General Public
06: * License as published by the Free Software Foundation; either
07: * version 2.1 of the License, or any later version.
08: *
09: * This library is distributed in the hope that it will be useful,
10: * but WITHOUT ANY WARRANTY; without even the implied warranty of
11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12: * Lesser General Public License for more details.
13: *
14: * You should have received a copy of the GNU Lesser General Public
15: * License along with this library; if not, write to the Free Software
16: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17: *
18: * jspigner@openjx.org
19: *
20: * JXWindow.java
21: *
22: * Created on June 8, 2007, 12:00 AM
23: *
24: */
25:
26: package org.openjx.display;
27:
28: import java.awt.Dimension;
29: import java.awt.Point;
30: import java.awt.Toolkit;
31:
32: import javax.swing.JFrame;
33:
34: /**
35: * This class contains the JXViewer when OpenJX is run in application mode.
36: *
37: * @author Jared Spigner
38: */
39: public class JXWindow extends JFrame {
40:
41: /**
42: * This is the constructor for the JXWindow class. It creates a new
43: * instance of JXWindow.
44: *
45: * @param jxViewer points to an instance of the JXViewer class.
46: */
47: public JXWindow(JXViewer jxViewer) {
48: this .setSize(800, 600);
49: this .add(jxViewer);
50:
51: this .setDefaultCloseOperation(DISPOSE_ON_CLOSE);
52: this .setTitle("OpenJX Viewer v1.13");
53: this .centerScreen();
54:
55: this .setVisible(true);
56: }
57:
58: /**
59: * This method simply centers the window on the computer's screen.
60: */
61: public void centerScreen() {
62: Point p = null;
63: Dimension d = null;
64:
65: d = Toolkit.getDefaultToolkit().getScreenSize();
66: p = new Point();
67:
68: double centerX = p.getX() + d.getWidth() / 2;
69: double centerY = p.getY() + d.getHeight() / 2;
70:
71: this .getSize(d);
72:
73: p.setLocation(centerX - d.getWidth() / 2, centerY
74: - d.getHeight() / 2);
75:
76: if (p.getX() < 0)
77: p.setLocation(0, p.getY());
78:
79: if (p.getY() < 0)
80: p.setLocation(p.getX(), 0);
81:
82: this.setLocation(p);
83: }
84:
85: }
|