1 package rero.gui.sdi; 2 3 import javax.swing.*; 4 import javax.swing.event.*; 5 6 import java.awt.*; 7 import java.awt.event.*; 8 9 import java.util.*; 10 11 import java.beans.*; 12 13 import rero.gui.windows.*; 14 import rero.gui.background.*; 15 16 import rero.util.*; 17 18 import rero.config.*; 19 20 import rero.gui.toolkit.OrientedToolBar; 21 22 23 public class ClientPanel extends WindowManager implements ActionListener, ClientStateListener 24 { 25 protected StatusWindow active = null; 26 27 protected JPanel desktop, top; 28 protected JLabel button; 29 30 public void propertyChanged(String key, String value) 31 { 32 if (key.equals("switchbar.position")) 33 { 34 int orientation = ClientState.getClientState().getInteger("switchbar.position", ClientDefaults.switchbar_position); 35 36 top.remove(button); 37 if (orientation == 2 || orientation == 3) 38 { 39 top.add(button, BorderLayout.SOUTH); 40 } 41 else 42 { 43 top.add(button, BorderLayout.EAST); 44 } 45 } 46 else 47 { 48 super.propertyChanged(key, value); 49 } 50 } 51 52 public void init() 53 { 54 switchbar = new OrientedToolBar(); 55 56 top = new JPanel(); 57 top.setLayout(new BorderLayout(5, 0)); 58 59 button = new JLabel("<html><b>X</b></html>", SwingConstants.CENTER); 60 button.setToolTipText("Close active window"); 61 62 button.addMouseListener(new MouseAdapter() 63 { 64 protected Color original; 65 66 public void mousePressed(MouseEvent e) 67 { 68 original = button.getForeground(); 69 button.setForeground(UIManager.getColor("TextArea.selectionBackground")); 70 } 71 72 public void mouseClicked(MouseEvent e) 73 { 74 processClose(); 75 } 76 77 public void mouseReleased(MouseEvent e) 78 { 79 button.setForeground(original); 80 } 81 82 public void mouseEntered(MouseEvent e) 83 { 84 button.setText("<html><b><u>X</u></b></html>"); 85 } 86 87 public void mouseExited(MouseEvent e) 88 { 89 button.setText("<html><b>X</b></html>"); 90 } 91 92 }); 93 94 top.add(switchbar, BorderLayout.CENTER); 95 96 propertyChanged("switchbar.position", null); 97 99 setLayout(new BorderLayout()); 100 101 switchOptions = new SwitchBarOptions(this, top); 102 103 105 windowMap = new HashMap(); 106 windows = new LinkedList(); 107 108 desktop = new JPanel(); 109 desktop.setLayout(new BorderLayout()); 110 111 add(desktop, BorderLayout.CENTER); 112 113 new MantainActiveFocus(this); 114 115 ClientState.getClientState().addClientStateListener("switchbar.position", this); 116 } 117 118 public void addWindow(StatusWindow window, boolean selected) 119 { 120 ClientSingleWindow temp = new ClientSingleWindow(this); 121 window.init(temp); 122 123 windowMap.put(window.getWindow(), window); 124 windowMap.put(window.getButton(), window); 125 126 window.getButton().addActionListener(this); 127 128 addToSwitchbar(window); 130 131 if (selected) 133 { 134 if (active != null) 135 { 136 doDeactivate(active); 137 } 138 139 desktop.add(temp, BorderLayout.CENTER); 140 141 active = window; 142 } 143 144 temp.processOpen(); 145 146 if (selected) 147 { 148 if (!window.getButton().isSelected()) 149 { 150 window.getButton().setSelected(true); 151 } 152 } 153 154 revalidate(); 155 156 refreshFocus(); 157 } 158 159 public void killWindow(ClientWindow cwindow) 160 { 161 StatusWindow window = getWindowFor(cwindow); 162 163 if (window == null) 164 return; 166 ((ClientSingleWindow)window.getWindow()).processClose(); 167 168 int idx = windows.indexOf(window); 169 170 switchbar.remove(window.getButton()); 171 windowMap.remove(window.getButton()); 172 windowMap.remove(window.getWindow()); 173 windows.remove(window); 174 175 desktop.remove(window); 176 177 if (window == active && active.getName().equals(StatusWindow.STATUS_NAME)) 178 { 179 active = null; } 181 else if (window == active) 182 { 183 newActive(idx, true); refreshFocus(); 185 } 186 187 switchbar.validate(); 188 switchbar.repaint(); 189 } 190 191 public void processClose() 192 { 193 if (active != null) 194 { 195 killWindow(active.getWindow()); 196 } 197 } 198 199 public StatusWindow getActiveWindow() 200 { 201 return active; 202 } 203 204 protected void doActivate(StatusWindow window) 205 { 206 if (active != null && active != window.getWindow()) 207 { 208 doDeactivate(active); 209 } 210 211 desktop.add((ClientSingleWindow)window.getWindow(), BorderLayout.CENTER); 212 213 active = window; 214 ((ClientSingleWindow)active.getWindow()).processActive(); 215 216 if (!window.getButton().isSelected()) 217 { 218 window.getButton().setSelected(true); 219 } 220 221 revalidate(); 222 repaint(); 223 224 refreshFocus(); 225 } 226 227 public void refreshFocus() 228 { 229 SwingUtilities.invokeLater(new Runnable () 230 { 231 public void run() 232 { 233 if (getActiveWindow() != null && isShowing() && getActiveWindow().isLegalWindow() && !rero.gui.KeyBindings.is_dialog_active) 234 { 235 getActiveWindow().getInput().requestFocus(); 236 } 237 } 238 }); 239 } 240 241 protected void doDeactivate(StatusWindow window) 242 { 243 desktop.remove((ClientSingleWindow)window.getWindow()); 244 ((ClientSingleWindow)window.getWindow()).processInactive(); 245 window.getButton().setSelected(false); 246 } 247 248 private class MantainActiveFocus extends ComponentAdapter 249 { 250 public MantainActiveFocus(JComponent component) 251 { 252 component.addComponentListener(this); 253 } 254 255 public void componentMoved(ComponentEvent e) 256 { 257 } 258 259 public void componentShown(ComponentEvent e) 260 { 261 refreshFocus(); 262 } 263 } 264 } 265 | Popular Tags |