001: /*
002: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
003: */
004: package com.tc.admin;
005:
006: import com.tc.admin.common.XFrame;
007: import com.tc.admin.common.XMenuBar;
008: import com.tc.admin.common.XTreeNode;
009:
010: import java.awt.BorderLayout;
011: import java.awt.Dimension;
012: import java.awt.GraphicsConfiguration;
013: import java.awt.GraphicsDevice;
014: import java.awt.GraphicsEnvironment;
015: import java.awt.Insets;
016: import java.awt.Rectangle;
017: import java.awt.Toolkit;
018: import java.awt.event.WindowEvent;
019: import java.util.prefs.Preferences;
020:
021: public class AdminClientFrame extends XFrame implements
022: AdminClientController {
023: private AdminClientPanel m_mainPanel;
024:
025: public AdminClientFrame() {
026: super ();
027:
028: getContentPane().setLayout(new BorderLayout());
029: getContentPane().add(m_mainPanel = new AdminClientPanel());
030:
031: XMenuBar menuBar;
032: m_mainPanel.initMenubar(menuBar = new XMenuBar());
033: setMenubar(menuBar);
034:
035: setTitle(AdminClient.getContext().getMessage("title"));
036: setDefaultCloseOperation(EXIT_ON_CLOSE);
037: }
038:
039: public boolean isExpanded(XTreeNode node) {
040: return m_mainPanel.isExpanded(node);
041: }
042:
043: public void expand(XTreeNode node) {
044: m_mainPanel.expand(node);
045: }
046:
047: public boolean isSelected(XTreeNode node) {
048: return m_mainPanel.isSelected(node);
049: }
050:
051: public void select(XTreeNode node) {
052: m_mainPanel.select(node);
053: }
054:
055: public void remove(XTreeNode node) {
056: m_mainPanel.remove(node);
057: }
058:
059: public void nodeStructureChanged(XTreeNode node) {
060: m_mainPanel.nodeStructureChanged(node);
061: }
062:
063: public void nodeChanged(XTreeNode node) {
064: m_mainPanel.nodeChanged(node);
065: }
066:
067: public boolean testServerMatch(ServerNode node) {
068: return m_mainPanel.testServerMatch(node);
069: }
070:
071: private Preferences getPreferences() {
072: AdminClientContext acc = AdminClient.getContext();
073: return acc.prefs.node("AdminClientFrame");
074: }
075:
076: private void storePreferences() {
077: AdminClientContext acc = AdminClient.getContext();
078: acc.client.storePrefs();
079: }
080:
081: public void updateServerPrefs() {
082: m_mainPanel.updateServerPrefs();
083: }
084:
085: protected void processWindowEvent(final WindowEvent e) {
086: if (e.getID() == WindowEvent.WINDOW_CLOSING) {
087: System.exit(0);
088: }
089: super .processWindowEvent(e);
090: }
091:
092: public void log(String s) {
093: m_mainPanel.log(s);
094: }
095:
096: public void log(Exception e) {
097: m_mainPanel.log(e);
098: }
099:
100: public void setStatus(String msg) {
101: m_mainPanel.setStatus(msg);
102: }
103:
104: public void clearStatus() {
105: m_mainPanel.clearStatus();
106: }
107:
108: public Rectangle getDefaultBounds() {
109: Toolkit tk = Toolkit.getDefaultToolkit();
110: Dimension size = tk.getScreenSize();
111: GraphicsEnvironment env = GraphicsEnvironment
112: .getLocalGraphicsEnvironment();
113: GraphicsDevice device = env.getDefaultScreenDevice();
114: GraphicsConfiguration config = device.getDefaultConfiguration();
115: Insets insets = tk.getScreenInsets(config);
116:
117: size.width -= (insets.left + insets.right);
118: size.height -= (insets.top + insets.bottom);
119:
120: int width = (int) (size.width * 0.75f);
121: int height = (int) (size.height * 0.66f);
122:
123: // center
124: int x = size.width / 2 - width / 2;
125: int y = size.height / 2 - height / 2;
126:
127: return new Rectangle(x, y, width, height);
128: }
129:
130: private String getBoundsString() {
131: Rectangle b = getBounds();
132: return b.x + "," + b.y + "," + b.width + "," + b.height;
133: }
134:
135: private int parseInt(String s) {
136: try {
137: return Integer.parseInt(s);
138: } catch (Exception e) {
139: return 0;
140: }
141: }
142:
143: private Rectangle parseBoundsString(String s) {
144: String[] split = s.split(",");
145: int x = parseInt(split[0]);
146: int y = parseInt(split[1]);
147: int width = parseInt(split[2]);
148: int height = parseInt(split[3]);
149:
150: return new Rectangle(x, y, width, height);
151: }
152:
153: public void storeBounds() {
154: String name = getName();
155:
156: if (name == null) {
157: return;
158: }
159:
160: int state = getExtendedState();
161: if ((state & NORMAL) != NORMAL) {
162: return;
163: }
164:
165: Preferences prefs = getPreferences();
166:
167: prefs.put("Bounds", getBoundsString());
168: storePreferences();
169: }
170:
171: protected Rectangle getPreferredBounds() {
172: Preferences prefs = getPreferences();
173: String s = prefs.get("Bounds", null);
174:
175: return s != null ? parseBoundsString(s) : getDefaultBounds();
176: }
177:
178: public void addServerLog(ConnectionContext cc) {
179: m_mainPanel.addServerLog(cc);
180: }
181:
182: public void removeServerLog(ConnectionContext cc) {
183: m_mainPanel.removeServerLog(cc);
184: }
185: }
|