- Timestamp:
- 2010-09-17T17:03:17+02:00 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/preferences/AdvancedPreference.java
r3531 r3536 11 11 import java.awt.event.MouseAdapter; 12 12 import java.awt.event.MouseEvent; 13 import java.util.Arrays; 14 import java.util.ArrayList; 13 15 import java.util.Map; 14 16 import java.util.TreeMap; … … 30 32 31 33 import org.openstreetmap.josm.Main; 34 import org.openstreetmap.josm.gui.ExtendedDialog; 32 35 import org.openstreetmap.josm.tools.GBC; 33 36 … … 234 237 private void addPreference(final PreferenceTabbedPane gui) { 235 238 String s[] = showEditDialog(gui, tr("Enter a new key/value pair"), 236 null, null);239 "", ""); 237 240 if(s != null && !s[0].isEmpty() && !s[1].isEmpty()) { 238 241 data.put(s[0], s[1]); … … 272 275 JTextField tvalue = new JTextField(value, 50); 273 276 p.add(tkey, GBC.eop().insets(5,0,0,0).fill(GBC.HORIZONTAL)); 274 p.add(new JLabel(tr("Value")), GBC.std().insets(0,0,5,0)); 275 /* TODO: Split value at "\u001e" and present a table with automatic added lines */ 276 p.add(tvalue, GBC.eol().insets(5,0,0,0).fill(GBC.HORIZONTAL)); 277 int answer = JOptionPane.showConfirmDialog( 278 gui, p, 279 title, 280 JOptionPane.OK_CANCEL_OPTION, 281 JOptionPane.PLAIN_MESSAGE 282 ); 283 if(answer == JOptionPane.OK_OPTION) { 284 return new String[]{tkey.getText(), tvalue.getText()}; 277 PrefValueTableModel model = new PrefValueTableModel(value); 278 p.add(new JLabel(tr("Values")), GBC.std().insets(0,0,5,0)); 279 JTable table = new JTable(model); 280 table.putClientProperty("terminateEditOnFocusLost", true); 281 table.getTableHeader().setVisible(false); 282 JScrollPane pane = new JScrollPane(table); 283 Dimension d = pane.getPreferredSize(); 284 d.height = (d.height/20)*(model.getRowCount()+4); 285 pane.setPreferredSize(d); 286 p.add(pane, GBC.eol().insets(5,10,0,0).fill(GBC.HORIZONTAL)); 287 ExtendedDialog ed = new ExtendedDialog(gui, title, 288 new String[] {tr("OK"), tr("Cancel")}); 289 ed.setButtonIcons(new String[] {"ok.png", "cancel.png"}); 290 ed.setContent(p); 291 ed.showDialog(); 292 if(ed.getValue() == 1) { 293 return new String[]{tkey.getText(), model.getText()}; 285 294 } 286 295 return null; 287 296 } 297 class PrefValueTableModel extends DefaultTableModel { 298 private final ArrayList<String> data = new ArrayList<String>(); 299 public PrefValueTableModel(String val) { 300 data.addAll(Arrays.asList(val.split("\u001e"))); 301 setColumnIdentifiers(new String[]{""}); 302 } 303 304 public String getText() { 305 String s = null; 306 for(String a : data) 307 { 308 if(s == null) { 309 s = a; 310 } else { 311 s += "\u001e" + a; 312 } 313 } 314 return s == null ? "" : s; 315 } 316 317 @Override 318 public int getRowCount() { 319 return data == null ? 1 : data.size()+1; 320 } 321 322 @Override 323 public Object getValueAt(int row, int column) { 324 return data.size() == row ? "" : data.get(row); 325 } 326 327 @Override 328 public void setValueAt(Object o, int row, int column) { 329 String s = (String)o; 330 if(row == data.size()) { 331 data.add(s); 332 fireTableRowsInserted(row+1, row+1); 333 } else { 334 data.set(row, s); 335 } 336 fireTableCellUpdated(row, column); 337 } 338 339 @Override 340 public boolean isCellEditable(int row, int column) { 341 return true; 342 } 343 } 288 344 }
Note:
See TracChangeset
for help on using the changeset viewer.