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 16 public class postaladdresseditor extends JDialog 17 implements abstractstringeditor 18 { 19 protected CBButton btnOk, btnReset, btnCancel, btnHelp; 20 protected JTextArea area; 21 protected CBPanel display; 22 protected editablestring edStringNew; 23 24 27 private final AttributeValue attBackup; 28 29 35 public postaladdresseditor(Frame owner, AttributeValue att) 36 { 37 super(owner); 38 setModal(true); 39 40 attBackup = att; 41 42 String attID = att.getID(); 43 44 setTitle(CBIntText.get(attID)); 45 46 display = new CBPanel(); 47 48 btnOk = new CBButton(CBIntText.get("Ok"), CBIntText.get("Click here to make the changes (remember to click Submit in the table editor).")); 49 btnOk.addActionListener(new ActionListener() { 50 public void actionPerformed(ActionEvent e) { 51 save(); 52 }}); 53 54 btnReset = new CBButton(CBIntText.get("Reset"), CBIntText.get("Click here to reset your changes.")); 55 btnReset.addActionListener(new ActionListener() { 56 public void actionPerformed(ActionEvent e) { 57 setStringValue(attBackup); 58 }}); 59 60 btnCancel = new CBButton(CBIntText.get("Cancel"), CBIntText.get("Click here to exit.")); 61 btnCancel.addActionListener(new ActionListener() { 62 public void actionPerformed(ActionEvent e) { 63 quit(); 64 }}); 65 66 btnHelp = new CBButton(CBIntText.get("Help"), CBIntText.get("Click here for Help.")); CBHelpSystem.useDefaultHelp(btnHelp, HelpIDs.ATTR_POSTAL); 68 69 area = new JTextArea(); 70 71 JScrollPane scrollPane = new JScrollPane(area); 72 scrollPane.setPreferredSize(new Dimension(310,60)); 73 74 display.makeHeavy(); 75 display.addln(scrollPane); 76 display.makeLight(); 77 78 JPanel buttonPanel = new JPanel(); 79 80 buttonPanel.add(btnOk); 81 buttonPanel.add(btnReset); 82 buttonPanel.add(btnCancel); 83 buttonPanel.add(btnHelp); 84 display.add(buttonPanel); 85 86 display.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke("ENTER"), "enter"); 88 display.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke("ESCAPE"), "escape"); 89 display.getActionMap().put("enter", new MyAction(CBAction.ENTER)); 90 display.getActionMap().put("escape", new MyAction(CBAction.ESCAPE)); 91 92 getContentPane().add(display); 93 setSize(300,175); 94 } 95 96 107 private class MyAction extends CBAction 108 { 109 113 public MyAction(int key) 114 { 115 super(key); 116 } 117 118 123 public void actionPerformed(ActionEvent e) 124 { 125 if (getKey() == ESCAPE) 126 quit(); 127 else if (getKey() == ENTER) 128 save(); 129 } 130 } 131 132 137 public void setStringValue(editablestring edStringOld) 138 { 139 String attString = edStringOld.getStringValue(); 140 String attRemoveDollar = attString.replace('$', '\n'); 141 attRemoveDollar = CBParse.replaceAllString(new StringBuffer (attRemoveDollar), "\\24", "$"); area.setText(attRemoveDollar); 144 edStringNew = edStringOld; 145 } 146 147 150 public void save() 151 { 152 String newAttribute = area.getText(); 153 154 String temp = CBParse.replaceAllString(new StringBuffer (newAttribute), "$", "\\24"); 156 157 String editedAttribute = temp.replace('\n', '$'); 159 160 boolean check = true; 161 162 165 if(check) 166 { 167 edStringNew.setStringValue(editedAttribute); 169 quit(); 170 } 171 } 172 173 176 public void quit() 177 { 178 setVisible(false); 179 dispose(); 180 } 181 } | Popular Tags |