KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > admin > AdminClientFrame


1 /*
2  * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
3  */

4 package com.tc.admin;
5
6 import com.tc.admin.common.XFrame;
7 import com.tc.admin.common.XMenuBar;
8 import com.tc.admin.common.XTreeNode;
9
10 import java.awt.BorderLayout JavaDoc;
11 import java.awt.Dimension JavaDoc;
12 import java.awt.GraphicsConfiguration JavaDoc;
13 import java.awt.GraphicsDevice JavaDoc;
14 import java.awt.GraphicsEnvironment JavaDoc;
15 import java.awt.Insets JavaDoc;
16 import java.awt.Rectangle JavaDoc;
17 import java.awt.Toolkit JavaDoc;
18 import java.awt.event.WindowEvent JavaDoc;
19 import java.util.prefs.Preferences JavaDoc;
20
21 public class AdminClientFrame extends XFrame
22   implements AdminClientController
23 {
24   private AdminClientPanel m_mainPanel;
25
26   public AdminClientFrame() {
27     super();
28
29     getContentPane().setLayout(new BorderLayout JavaDoc());
30     getContentPane().add(m_mainPanel = new AdminClientPanel());
31     
32     XMenuBar menuBar;
33     m_mainPanel.initMenubar(menuBar = new XMenuBar());
34     setMenubar(menuBar);
35
36     setTitle(AdminClient.getContext().getMessage("title"));
37     setDefaultCloseOperation(EXIT_ON_CLOSE);
38   }
39
40   public boolean isExpanded(XTreeNode node) {
41     return m_mainPanel.isExpanded(node);
42   }
43
44   public void expand(XTreeNode node) {
45     m_mainPanel.expand(node);
46   }
47
48   public boolean isSelected(XTreeNode node) {
49     return m_mainPanel.isSelected(node);
50   }
51
52   public void select(XTreeNode node) {
53     m_mainPanel.select(node);
54   }
55
56   public void remove(XTreeNode node) {
57     m_mainPanel.remove(node);
58   }
59
60   public void nodeStructureChanged(XTreeNode node) {
61     m_mainPanel.nodeStructureChanged(node);
62   }
63
64   public void nodeChanged(XTreeNode node) {
65     m_mainPanel.nodeChanged(node);
66   }
67
68   private Preferences JavaDoc getPreferences() {
69     AdminClientContext acc = AdminClient.getContext();
70     return acc.prefs.node("AdminClientFrame");
71   }
72
73   private void storePreferences() {
74     AdminClientContext acc = AdminClient.getContext();
75     acc.client.storePrefs();
76   }
77
78  public void updateServerPrefs() {
79     m_mainPanel.updateServerPrefs();
80   }
81
82   protected void processWindowEvent(final WindowEvent JavaDoc e) {
83     if(e.getID() == WindowEvent.WINDOW_CLOSING) {
84       System.exit(0);
85     }
86     super.processWindowEvent(e);
87   }
88
89   public void log(String JavaDoc s) {
90     m_mainPanel.log(s);
91   }
92
93   public void log(Exception JavaDoc e) {
94     m_mainPanel.log(e);
95   }
96
97   public void setStatus(String JavaDoc msg) {
98     m_mainPanel.setStatus(msg);
99   }
100
101   public void clearStatus() {
102     m_mainPanel.clearStatus();
103   }
104
105   public Rectangle JavaDoc getDefaultBounds() {
106     Toolkit JavaDoc tk = Toolkit.getDefaultToolkit();
107     Dimension JavaDoc size = tk.getScreenSize();
108     GraphicsEnvironment JavaDoc env = GraphicsEnvironment.getLocalGraphicsEnvironment();
109     GraphicsDevice JavaDoc device = env.getDefaultScreenDevice();
110     GraphicsConfiguration JavaDoc config = device.getDefaultConfiguration();
111     Insets JavaDoc insets = tk.getScreenInsets(config);
112
113     size.width -= (insets.left+insets.right);
114     size.height -= (insets.top+insets.bottom);
115
116     int width = (int)(size.width * 0.75f);
117     int height = (int)(size.height * 0.66f);
118
119     // center
120
int x = size.width/2 - width/2;
121     int y = size.height/2 - height/2;
122
123     return new Rectangle JavaDoc(x, y, width, height);
124   }
125
126   private String JavaDoc getBoundsString() {
127     Rectangle JavaDoc b = getBounds();
128     return b.x+","+b.y+","+b.width+","+b.height;
129   }
130
131   private int parseInt(String JavaDoc s) {
132     try {
133       return Integer.parseInt(s);
134     }
135     catch(Exception JavaDoc e) {
136       return 0;
137     }
138   }
139
140   private Rectangle JavaDoc parseBoundsString(String JavaDoc s) {
141     String JavaDoc[] split = s.split(",");
142     int x = parseInt(split[0]);
143     int y = parseInt(split[1]);
144     int width = parseInt(split[2]);
145     int height = parseInt(split[3]);
146
147     return new Rectangle JavaDoc(x,y,width,height);
148   }
149
150   public void storeBounds() {
151     String JavaDoc name = getName();
152
153     if(name == null) {
154       return;
155     }
156
157     int state = getExtendedState();
158     if((state & NORMAL) != NORMAL) {
159       return;
160     }
161     
162     Preferences JavaDoc prefs = getPreferences();
163
164     prefs.put("Bounds", getBoundsString());
165     storePreferences();
166   }
167
168   protected Rectangle JavaDoc getPreferredBounds() {
169     Preferences JavaDoc prefs = getPreferences();
170     String JavaDoc s = prefs.get("Bounds", null);
171
172     return s != null ? parseBoundsString(s) : getDefaultBounds();
173   }
174
175   public void addServerLog(ConnectionContext cc) {
176     m_mainPanel.addServerLog(cc);
177   }
178
179   public void removeServerLog(ConnectionContext cc) {
180     m_mainPanel.removeServerLog(cc);
181   }
182 }
183
Popular Tags