1 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 ; 11 import java.awt.Dimension ; 12 import java.awt.GraphicsConfiguration ; 13 import java.awt.GraphicsDevice ; 14 import java.awt.GraphicsEnvironment ; 15 import java.awt.Insets ; 16 import java.awt.Rectangle ; 17 import java.awt.Toolkit ; 18 import java.awt.event.WindowEvent ; 19 import java.util.prefs.Preferences ; 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 ()); 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 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 e) { 83 if(e.getID() == WindowEvent.WINDOW_CLOSING) { 84 System.exit(0); 85 } 86 super.processWindowEvent(e); 87 } 88 89 public void log(String s) { 90 m_mainPanel.log(s); 91 } 92 93 public void log(Exception e) { 94 m_mainPanel.log(e); 95 } 96 97 public void setStatus(String msg) { 98 m_mainPanel.setStatus(msg); 99 } 100 101 public void clearStatus() { 102 m_mainPanel.clearStatus(); 103 } 104 105 public Rectangle getDefaultBounds() { 106 Toolkit tk = Toolkit.getDefaultToolkit(); 107 Dimension size = tk.getScreenSize(); 108 GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment(); 109 GraphicsDevice device = env.getDefaultScreenDevice(); 110 GraphicsConfiguration config = device.getDefaultConfiguration(); 111 Insets 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 int x = size.width/2 - width/2; 121 int y = size.height/2 - height/2; 122 123 return new Rectangle (x, y, width, height); 124 } 125 126 private String getBoundsString() { 127 Rectangle b = getBounds(); 128 return b.x+","+b.y+","+b.width+","+b.height; 129 } 130 131 private int parseInt(String s) { 132 try { 133 return Integer.parseInt(s); 134 } 135 catch(Exception e) { 136 return 0; 137 } 138 } 139 140 private Rectangle parseBoundsString(String s) { 141 String [] 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 (x,y,width,height); 148 } 149 150 public void storeBounds() { 151 String 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 prefs = getPreferences(); 163 164 prefs.put("Bounds", getBoundsString()); 165 storePreferences(); 166 } 167 168 protected Rectangle getPreferredBounds() { 169 Preferences prefs = getPreferences(); 170 String 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 |