Changeset 100 in josm for src/org/openstreetmap/josm/gui/dialogs/PropertiesDialog.java
- Timestamp:
- 2006-04-28T01:32:03+02:00 (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/org/openstreetmap/josm/gui/dialogs/PropertiesDialog.java
r98 r100 11 11 import java.awt.event.MouseAdapter; 12 12 import java.awt.event.MouseEvent; 13 import java.awt.event.WindowEvent;14 import java.awt.event.WindowFocusListener;15 13 import java.util.Collection; 16 14 import java.util.HashMap; 17 import java.util.Iterator;18 15 import java.util.Map; 19 16 import java.util.TreeMap; … … 93 90 p.add(combo, BorderLayout.CENTER); 94 91 95 final JOptionPane optionPane = new JOptionPane(p, JOptionPane.QUESTION_MESSAGE, JOptionPane.OK_CANCEL_OPTION); 92 final JOptionPane optionPane = new JOptionPane(p, JOptionPane.QUESTION_MESSAGE, JOptionPane.OK_CANCEL_OPTION){ 93 @Override public void selectInitialValue() { 94 combo.requestFocusInWindow(); 95 combo.getEditor().selectAll(); 96 } 97 }; 96 98 final JDialog dlg = optionPane.createDialog(Main.parent, "Change values?"); 97 dlg.addWindowFocusListener(new WindowFocusListener(){98 public void windowGainedFocus(WindowEvent e) {99 combo.requestFocusInWindow();100 }101 public void windowLostFocus(WindowEvent e) {102 }103 });104 99 combo.getEditor().addActionListener(new ActionListener(){ 105 100 public void actionPerformed(ActionEvent e) { … … 130 125 PropertiesDialog.this.repaint(); // repaint is enough 131 126 } 132 127 133 128 /** 134 129 * Open the add selection dialog and add a new key/value to the table (and to the … … 137 132 void add() { 138 133 Collection<OsmPrimitive> sel = Main.ds.getSelected(); 139 134 140 135 JPanel p = new JPanel(new BorderLayout()); 141 136 p.add(new JLabel("<html>This will change "+sel.size()+" object"+(sel.size()==1?"":"s")+".<br><br>"+ 142 137 "Please select a key"), BorderLayout.NORTH); 143 Vector<String> allKeys = newVector<String>();138 TreeSet<String> allKeys = new TreeSet<String>(); 144 139 for (OsmPrimitive osm : Main.ds.allNonDeletedPrimitives()) 145 140 allKeys.addAll(osm.keySet()); 146 for (Iterator<String> it = allKeys.iterator(); it.hasNext();) { 147 String s = it.next(); 148 for (int i = 0; i < data.getRowCount(); ++i) { 149 if (s.equals(data.getValueAt(i, 0))) { 150 it.remove(); 151 break; 152 } 153 } 154 } 155 JComboBox keys = new JComboBox(allKeys); 141 for (int i = 0; i < data.getRowCount(); ++i) 142 allKeys.remove(data.getValueAt(i, 0)); 143 final JComboBox keys = new JComboBox(new Vector<String>(allKeys)); 156 144 keys.setEditable(true); 157 145 p.add(keys, BorderLayout.CENTER); 158 146 159 147 JPanel p2 = new JPanel(new BorderLayout()); 160 148 p.add(p2, BorderLayout.SOUTH); 161 149 p2.add(new JLabel("Please select a value"), BorderLayout.NORTH); 162 JTextField values = new JTextField(); 150 final JTextField values = new JTextField(); 163 151 p2.add(values, BorderLayout.CENTER); 164 int answer = JOptionPane.showConfirmDialog(Main.parent, p, 165 "Change values?", JOptionPane.OK_CANCEL_OPTION); 166 if (answer != JOptionPane.OK_OPTION) 152 JOptionPane pane = new JOptionPane(p, JOptionPane.PLAIN_MESSAGE, JOptionPane.OK_CANCEL_OPTION){ 153 @Override public void selectInitialValue() { 154 keys.requestFocusInWindow(); 155 keys.getEditor().selectAll(); 156 } 157 }; 158 pane.createDialog(Main.parent, "Change values?").setVisible(true); 159 if (!Integer.valueOf(JOptionPane.OK_OPTION).equals(pane.getValue())) 167 160 return; 168 161 String key = keys.getEditor().getItem().toString(); … … 184 177 selectionChanged(sel); // update table 185 178 } 186 179 187 180 /** 188 181 * The property data. … … 200 193 */ 201 194 private final JTable propertyTable = new JTable(data); 202 195 203 196 /** 204 197 * Create a new PropertiesDialog … … 208 201 209 202 setPreferredSize(new Dimension(320,150)); 210 203 211 204 data.setColumnIdentifiers(new String[]{"Key", "Value"}); 212 205 propertyTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); … … 228 221 } 229 222 }); 230 //propertyTable.addMouseListener(new DblClickWatch());231 223 DblClickWatch dblClickWatch = new DblClickWatch(); 224 propertyTable.addMouseListener(dblClickWatch); 232 225 JScrollPane scrollPane = new JScrollPane(propertyTable); 233 scrollPane.addMouseListener( new DblClickWatch());226 scrollPane.addMouseListener(dblClickWatch); 234 227 add(scrollPane, BorderLayout.CENTER); 235 228 236 229 JPanel buttonPanel = new JPanel(new GridLayout(1,3)); 237 230 ActionListener buttonAction = new ActionListener(){ … … 258 251 add(buttonPanel, BorderLayout.SOUTH); 259 252 } 260 253 261 254 private JButton createButton(String name, String tooltip, int mnemonic, ActionListener actionListener) { 262 255 JButton b = new JButton(name, ImageProvider.get("dialogs", name.toLowerCase())); … … 284 277 propertyTable.getCellEditor().cancelCellEditing(); 285 278 data.setRowCount(0); 286 279 287 280 Map<String, Integer> valueCount = new HashMap<String, Integer>(); 288 281 TreeMap<String, Collection<String>> props = new TreeMap<String, Collection<String>>();
Note:
See TracChangeset
for help on using the changeset viewer.
