1 package com.ca.directory.jxplorer.editor; 2 3 import com.ca.commons.cbutil.*; 4 import com.ca.directory.jxplorer.viewer.tableviewer.*; 5 import com.ca.directory.jxplorer.HelpIDs; 6 7 import javax.swing.*; 8 import java.awt.*; 9 import java.awt.event.*; 10 11 15 public class booleaneditor extends JDialog 16 implements abstractstringeditor 17 { 18 public static final String TRUE = "TRUE"; 19 public static final String FALSE = "FALSE"; 20 21 protected CBButton btnOk = null, btnCancel = null, btnHelp = null; 22 protected JComboBox combo = null; 23 protected CBPanel panel = null; 24 protected editablestring newEditableString = null; 25 26 32 public booleaneditor(Frame owner, AttributeValue att) 33 { 34 super(owner); 35 setModal(true); 36 37 String attID = att.getID(); 38 39 setTitle(CBIntText.get(attID)); 40 41 panel = new CBPanel(); 42 43 btnOk = new CBButton(CBIntText.get("Ok"), CBIntText.get("Click here to make the changes (remember to click Submit in the table editor).")); 44 btnOk.addActionListener(new ActionListener() { 45 public void actionPerformed(ActionEvent e) { 46 save(); 47 }}); 48 49 btnCancel = new CBButton(CBIntText.get("Cancel"), CBIntText.get("Click here to exit.")); 50 btnCancel.addActionListener(new ActionListener() { 51 public void actionPerformed(ActionEvent e) { 52 quit(); 53 }}); 54 55 btnHelp = new CBButton(CBIntText.get("Help"), CBIntText.get("Click here for Help.")); CBHelpSystem.useDefaultHelp(btnHelp, HelpIDs.ATTR_BOOLEAN); 57 58 combo = new JComboBox(); 59 combo.addItem(TRUE); 60 combo.addItem(FALSE); 61 combo.setSize(20, 40); 62 63 panel.makeLight(); 64 panel.add(combo); 65 panel.addln(new JLabel(" ")); 66 67 JPanel buttonPanel = new JPanel(); 68 69 buttonPanel.add(btnOk); 70 buttonPanel.add(btnCancel); 71 buttonPanel.add(btnHelp); panel.add(buttonPanel); 73 74 panel.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke("ENTER"), "enter"); 76 panel.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke("ESCAPE"), "escape"); 77 panel.getActionMap().put("enter", new MyAction(CBAction.ENTER)); 78 panel.getActionMap().put("escape", new MyAction(CBAction.ESCAPE)); 79 80 getContentPane().add(panel); 81 setSize(210,100); 82 } 83 84 95 private class MyAction extends CBAction 96 { 97 101 public MyAction(int key) 102 { 103 super(key); 104 } 105 106 111 public void actionPerformed(ActionEvent e) 112 { 113 if (getKey() == ESCAPE) 114 quit(); 115 else if (getKey() == ENTER) 116 save(); 117 } 118 } 119 120 124 public void setStringValue(editablestring oldEditableString) 125 { 126 String attString = oldEditableString.getStringValue(); 127 128 if(attString == null || attString.equalsIgnoreCase(FALSE)) 129 combo.setSelectedItem(FALSE); 130 else 131 combo.setSelectedItem(TRUE); 132 133 newEditableString = oldEditableString; 134 } 135 136 139 public void save() 140 { 141 Object obj = combo.getSelectedItem(); 142 143 if(obj != null && ((String )obj).equalsIgnoreCase(TRUE)) 144 newEditableString.setStringValue(TRUE); 145 else if(obj != null && ((String )obj).equalsIgnoreCase(FALSE)) 146 newEditableString.setStringValue(FALSE); 147 148 quit(); 149 } 150 151 154 public void quit() 155 { 156 setVisible(false); 157 dispose(); 158 } 159 } | Popular Tags |