1 19 package org.openharmonise.him.configuration; 20 21 import java.awt.*; 22 import java.awt.event.*; 23 import java.util.*; 24 25 import javax.swing.*; 26 27 import org.openharmonise.him.configuration.lnf.*; 28 import org.openharmonise.him.configuration.reporting.*; 29 import org.openharmonise.him.configuration.searchin.*; 30 import org.openharmonise.him.configuration.sync.*; 31 import org.openharmonise.vfs.context.*; 32 import org.openharmonise.vfs.gui.*; 33 34 35 42 public class ConfigDialog extends JDialog implements LayoutManager, ActionListener, ContextListener { 43 44 47 private ArrayList m_listeners = new ArrayList(); 48 49 52 private JTabbedPane m_tabs = null; 53 54 57 private JButton m_buttonOK = null; 58 59 62 private JButton m_buttonCancel = null; 63 64 67 private JButton m_buttonApply = null; 68 69 72 private String m_sSelectTab = null; 73 74 81 public ConfigDialog(Frame frame, String sTitle) throws HeadlessException { 82 super(frame, sTitle, true); 83 this.setup(); 84 } 85 86 90 private void setup() { 91 92 ContextHandler.getInstance().addListener(ContextType.CONTEXT_APP_FOCUS, this); 93 94 this.setResizable(false); 95 96 this.getContentPane().setLayout(this); 97 98 this.setSize(400,400); 99 int x = this.getGraphicsConfiguration().getBounds().width/2-this.getSize().width/2; 100 int y = this.getGraphicsConfiguration().getBounds().height/2-this.getSize().height/2; 101 102 this.setLocation(x, y); 103 104 String fontName = "Dialog"; 105 int fontSize = 11; 106 Font font = new Font(fontName, Font.PLAIN, fontSize); 107 this.getContentPane().setBackground(new Color(224,224,224)); 108 109 this.m_buttonOK = new JButton("OK"); 110 this.m_buttonOK.setActionCommand("OK"); 111 this.m_buttonOK.addActionListener(this); 112 this.m_buttonOK.setFont(font); 113 this.getContentPane().add(this.m_buttonOK); 114 115 this.m_buttonCancel = new JButton("Cancel"); 116 this.m_buttonCancel.setActionCommand("CANCEL"); 117 this.m_buttonCancel.addActionListener(this); 118 this.m_buttonCancel.setFont(font); 119 this.getContentPane().add(this.m_buttonCancel); 120 121 this.m_buttonApply = new JButton("Apply"); 122 this.m_buttonApply.setEnabled(false); 123 this.m_buttonApply.setActionCommand("APPLY"); 124 this.m_buttonApply.addActionListener(this); 125 this.m_buttonApply.setFont(font); 126 this.getContentPane().add(this.m_buttonApply); 127 128 this.m_tabs = new JTabbedPane(); 129 this.m_tabs.setFont(font); 130 131 JPanel panel = new JPanel(); 132 panel.setLayout(new FlowLayout(FlowLayout.CENTER)); 133 134 ReportingConfigOptions reportingOptions = new ReportingConfigOptions(this); 135 panel.add(reportingOptions); 136 137 LookAndFeelConfigOptions options = new LookAndFeelConfigOptions(this); 138 panel.add(options); 139 140 SyncConfigOptions syncOptions = new SyncConfigOptions(this); 141 panel.add(syncOptions); 142 143 this.m_tabs.addTab("Options", panel); 144 145 panel = new SearchInOptions(this); 146 147 this.m_tabs.addTab("Search in", panel); 148 149 this.getContentPane().add(this.m_tabs); 150 151 } 152 153 159 public void setSelectedTab(String sTabName) { 160 this.m_sSelectTab = sTabName; 161 } 162 163 166 public void actionPerformed(ActionEvent ae) { 167 if(ae.getActionCommand().equals("OK")) { 168 this.fireApplyChanges(); 169 ContextHandler.getInstance().removeListener(ContextType.CONTEXT_APP_FOCUS, this); 170 this.hide(); 171 } else if(ae.getActionCommand().equals("CANCEL")) { 172 ContextHandler.getInstance().removeListener(ContextType.CONTEXT_APP_FOCUS, this); 173 this.hide(); 174 } else if(ae.getActionCommand().equals("APPLY")) { 175 this.m_buttonApply.setEnabled(false); 176 this.fireApplyChanges(); 177 178 } 179 } 180 181 184 public void layoutContainer(Container arg0) { 185 this.m_tabs.setSize(this.getSize().width-10, 430); 186 this.m_tabs.setLocation(0, 0); 187 188 this.m_buttonOK.setSize(70, 20); 189 this.m_buttonOK.setLocation(150, 340); 190 191 this.m_buttonCancel.setSize(70, 20); 192 this.m_buttonCancel.setLocation(230, 340); 193 194 this.m_buttonApply.setSize(70, 20); 195 this.m_buttonApply.setLocation(310, 340); 196 } 197 198 203 public void addApplyChangesListener(ApplyChangesListener listener) { 204 this.m_listeners.add(listener); 205 } 206 207 212 public void removeApplyChangesListener(ApplyChangesListener listener) { 213 this.m_listeners.remove(listener); 214 } 215 216 220 private void fireApplyChanges() { 221 Iterator itor = this.m_listeners.iterator(); 222 while (itor.hasNext()) { 223 ApplyChangesListener listener = (ApplyChangesListener) itor.next(); 224 listener.applyChanges(); 225 } 226 } 227 228 234 public void changesMade() { 235 this.m_buttonApply.setEnabled(true); 236 } 237 238 public static void main(String [] args) { 239 JFrame frame = new JFrame(); 240 frame.setIconImage( ((ImageIcon)IconManager.getInstance().getIcon("32-sim-logo.gif")).getImage() ); 241 242 ConfigDialog dialog = new ConfigDialog(frame, "Customise"); 243 dialog.show(); 244 System.exit(0); 245 } 246 247 251 private ConfigDialog(Dialog arg0) throws HeadlessException { 252 super(arg0); 253 } 254 255 260 private ConfigDialog(Dialog arg0, boolean arg1) throws HeadlessException { 261 super(arg0, arg1); 262 } 263 264 268 private ConfigDialog(Frame arg0) throws HeadlessException { 269 super(arg0); 270 } 271 272 277 private ConfigDialog(Frame arg0, boolean arg1) throws HeadlessException { 278 super(arg0, arg1); 279 } 280 281 286 private ConfigDialog() throws HeadlessException { 287 super(); 288 } 289 290 296 private ConfigDialog(Dialog arg0, String arg1, boolean arg2) 297 throws HeadlessException { 298 super(arg0, arg1, arg2); 299 } 300 301 306 private ConfigDialog(Dialog arg0, String arg1) throws HeadlessException { 307 super(arg0, arg1); 308 } 309 310 316 private ConfigDialog(Frame arg0, String arg1, boolean arg2) 317 throws HeadlessException { 318 super(arg0, arg1, arg2); 319 } 320 321 328 private ConfigDialog( 329 Dialog arg0, 330 String arg1, 331 boolean arg2, 332 GraphicsConfiguration arg3) 333 throws HeadlessException { 334 super(arg0, arg1, arg2, arg3); 335 } 336 337 343 private ConfigDialog( 344 Frame arg0, 345 String arg1, 346 boolean arg2, 347 GraphicsConfiguration arg3) { 348 super(arg0, arg1, arg2, arg3); 349 } 350 351 354 public void removeLayoutComponent(Component arg0) { 355 } 356 357 360 public void addLayoutComponent(String arg0, Component arg1) { 361 } 362 363 366 public Dimension minimumLayoutSize(Container arg0) { 367 return this.getSize(); 368 } 369 370 373 public Dimension preferredLayoutSize(Container arg0) { 374 return this.getSize(); 375 } 376 377 380 public void show() { 381 if(this.m_sSelectTab!=null) { 382 int nIndex = 0; 383 for(int i=0; i<this.m_tabs.getTabCount(); i++) { 384 if(this.m_tabs.getTitleAt(i).equals(this.m_sSelectTab)) { 385 nIndex = i; 386 } 387 } 388 this.m_tabs.setSelectedIndex(nIndex); 389 } 390 super.show(); 391 } 392 393 396 public void contextMessage(ContextEvent ce) { 397 if(ce.CONTEXT_TYPE==ContextType.CONTEXT_APP_FOCUS) { 398 this.toFront(); 399 } 400 } 401 402 } 403 | Popular Tags |