Changeset 1606 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2009-05-20T15:59:44+02:00 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/dialogs/PropertiesDialog.java
r1599 r1606 9 9 import java.awt.BorderLayout; 10 10 import java.awt.Component; 11 import java.awt.Cursor; 12 import java.awt.Dimension; 11 13 import java.awt.Font; 12 14 import java.awt.GridBagLayout; … … 19 21 import java.awt.event.MouseAdapter; 20 22 import java.awt.event.MouseEvent; 21 import java. lang.String;23 import java.awt.event.MouseListener; 22 24 import java.util.Collection; 23 25 import java.util.Collections; … … 60 62 import org.openstreetmap.josm.data.osm.visitor.NameVisitor; 61 63 import org.openstreetmap.josm.gui.ExtendedDialog; 62 import org.openstreetmap.josm.gui.JMultilineLabel;63 64 import org.openstreetmap.josm.gui.MapFrame; 64 65 import org.openstreetmap.josm.gui.SideButton; … … 138 139 objKey=key; 139 140 140 String msg = "<html>"+trn("This will change up to {0} object.", "This will change up to {0} objects.", sel.size(), sel.size())+"<br><br>("+tr("An empty value deletes the key.", key)+")</html>"; 141 String msg = "<html>"+trn("This will change up to {0} object.", 142 "This will change up to {0} objects.", sel.size(), sel.size()) 143 +"<br><br>("+tr("An empty value deletes the key.", key)+")</html>"; 141 144 142 145 JPanel panel = new JPanel(new BorderLayout()); … … 159 162 final AutoCompleteComboBox values = new AutoCompleteComboBox(); 160 163 values.setRenderer(new DefaultListCellRenderer() { 161 @Override public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { 162 Component c = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); 164 @Override public Component getListCellRendererComponent(JList list, 165 Object value, int index, boolean isSelected, boolean cellHasFocus){ 166 Component c = super.getListCellRendererComponent(list, value, 167 index, isSelected, cellHasFocus); 163 168 if (c instanceof JLabel) { 164 169 String str = null; … … 257 262 commands.add(new ChangePropertyCommand(sel, newkey, value)); 258 263 } 259 Main.main.undoRedo.add(new SequenceCommand(trn("Change properties of up to {0} object", "Change properties of up to {0} objects", sel.size(), sel.size()), commands)); 264 Main.main.undoRedo.add(new SequenceCommand( 265 trn("Change properties of up to {0} object", 266 "Change properties of up to {0} objects", sel.size(), sel.size()), 267 commands)); 260 268 } 261 269 … … 279 287 * @param values 280 288 */ 281 private void updateListData(String key, final TreeMap<String, TreeSet<String>> allData, final AutoCompleteComboBox values) { 289 private void updateListData(String key, final TreeMap<String, TreeSet<String>> allData, 290 final AutoCompleteComboBox values) { 282 291 Collection<String> newItems; 283 292 if (allData.containsKey(key)) { … … 309 318 310 319 JPanel p = new JPanel(new BorderLayout()); 311 p.add(new JLabel("<html>"+trn("This will change up to {0} object.","This will change up to {0} objects.", sel.size(),sel.size())+"<br><br>"+tr("Please select a key")), 312 BorderLayout.NORTH); 320 p.add(new JLabel("<html>"+trn("This will change up to {0} object.", 321 "This will change up to {0} objects.", sel.size(),sel.size()) 322 +"<br><br>"+tr("Please select a key")), BorderLayout.NORTH); 313 323 final TreeMap<String, TreeSet<String>> allData = createAutoCompletionInfo(false); 314 324 final AutoCompleteComboBox keys = new AutoCompleteComboBox(); … … 352 362 * @param values 353 363 */ 354 private void addFocusAdapter(final int row, final TreeMap<String, TreeSet<String>> allData,final AutoCompleteComboBox keys, final AutoCompleteComboBox values) { 364 private void addFocusAdapter(final int row, final TreeMap<String, TreeSet<String>> allData, 365 final AutoCompleteComboBox keys, final AutoCompleteComboBox values) { 355 366 // get the combo box' editor component 356 367 JTextComponent editor = (JTextComponent)values.getEditor() … … 442 453 private final SideButton btnEdit; 443 454 private final SideButton btnDel; 444 private final JMultilineLabel presets = new JMultilineLabel(""); 445 446 private final JLabel selectSth = new JLabel("<html><p>" + tr("Please select the objects you want to change properties for.") + "</p></html>"); 455 private final JPanel presets = new JPanel(new GridBagLayout()); 456 457 private final JLabel selectSth = new JLabel("<html><p>" 458 + tr("Please select the objects you want to change properties for.") + "</p></html>"); 447 459 448 460 /** … … 459 471 460 472 propertyTable.getColumnModel().getColumn(1).setCellRenderer(new DefaultTableCellRenderer(){ 461 @Override public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { 473 @Override public Component getTableCellRendererComponent(JTable table, Object value, 474 boolean isSelected, boolean hasFocus, int row, int column) { 462 475 Component c = super.getTableCellRendererComponent(table, value, isSelected, false, row, column); 463 476 if (c instanceof JLabel) { … … 489 502 490 503 membershipTable.getColumnModel().getColumn(0).setCellRenderer(new DefaultTableCellRenderer() { 491 @Override public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { 504 @Override public Component getTableCellRendererComponent(JTable table, Object value, 505 boolean isSelected, boolean hasFocus, int row, int column) { 492 506 Component c = super.getTableCellRendererComponent(table, value, isSelected, false, row, column); 493 507 if (c instanceof JLabel) { … … 500 514 501 515 membershipTable.getColumnModel().getColumn(1).setCellRenderer(new DefaultTableCellRenderer() { 502 @Override public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { 516 @Override public Component getTableCellRendererComponent(JTable table, Object value, 517 boolean isSelected, boolean hasFocus, int row, int column) { 503 518 Component c = super.getTableCellRendererComponent(table, value, isSelected, false, row, column); 504 519 if (c instanceof JLabel) { … … 525 540 JPanel bothTables = new JPanel(); 526 541 bothTables.setLayout(new GridBagLayout()); 542 bothTables.add(presets, GBC.eol().fill(GBC.HORIZONTAL).insets(5, 2, 5, 2)); 527 543 bothTables.add(selectSth, GBC.eol().fill().insets(10, 10, 10, 10)); 528 544 bothTables.add(propertyTable.getTableHeader(), GBC.eol().fill(GBC.HORIZONTAL)); … … 530 546 bothTables.add(membershipTable.getTableHeader(), GBC.eol().fill(GBC.HORIZONTAL)); 531 547 bothTables.add(membershipTable, GBC.eol().fill(GBC.BOTH)); 532 bothTables.add(presets, GBC.eol().fill().insets(5, 2, 5, 2));533 548 534 549 DblClickWatch dblClickWatch = new DblClickWatch(); … … 540 555 541 556 selectSth.setPreferredSize(scrollPane.getSize()); 542 presets.set PreferredSize(scrollPane.getSize());557 presets.setSize(scrollPane.getSize()); 543 558 544 559 JPanel buttonPanel = new JPanel(new GridLayout(1,3)); … … 629 644 private void checkPresets(int nodes, int ways, int relations, int closedways) 630 645 { 646 /** 647 * Small helper class that manages the highlighting of the label on hover as well as opening 648 * the corresponding preset when clicked 649 */ 650 class PresetLabelML implements MouseListener { 651 JLabel label; 652 Font bold; 653 Font normal; 654 TaggingPreset tag; 655 PresetLabelML(JLabel lbl, TaggingPreset t) { 656 super(); 657 label = lbl; 658 lbl.setCursor(new Cursor(Cursor.HAND_CURSOR)); 659 normal = label.getFont(); 660 bold = normal.deriveFont(normal.getStyle() ^ Font.BOLD); 661 tag = t; 662 } 663 public void mouseClicked(MouseEvent arg0) { 664 tag.actionPerformed(null); 665 } 666 public void mouseEntered(MouseEvent arg0) { 667 label.setFont(bold); 668 } 669 public void mouseExited(MouseEvent arg0) { 670 label.setFont(normal); 671 } 672 public void mousePressed(MouseEvent arg0) {} 673 public void mouseReleased(MouseEvent arg0) {} 674 } 675 631 676 LinkedList<TaggingPreset> p = new LinkedList<TaggingPreset>(); 677 presets.removeAll(); 632 678 int total = nodes+ways+relations+closedways; 633 if(total != 0) 634 { 635 for(TaggingPreset t : TaggingPresetPreference.taggingPresets) 679 if(total == 0) { 680 presets.setVisible(false); 681 return; 682 } 683 684 for(TaggingPreset t : TaggingPresetPreference.taggingPresets) { 685 if(t.types == null || !((relations > 0 && !t.types.contains("relation")) && 686 (nodes > 0 && !t.types.contains("node")) && 687 (ways+closedways > 0 && !t.types.contains("way")) && 688 (closedways > 0 && !t.types.contains("closedway")))) 636 689 { 637 if(t.types == null || !((relations > 0 && !t.types.contains("relation")) && 638 (nodes > 0 && !t.types.contains("node")) && 639 (ways+closedways > 0 && !t.types.contains("way")) && 640 (closedways > 0 && !t.types.contains("closedway")))) 641 { 642 int found = 0; 643 for(TaggingPreset.Item i : t.data) 644 { 645 if(i instanceof TaggingPreset.Key) 646 { 647 String val = ((TaggingPreset.Key)i).value; 648 String key = ((TaggingPreset.Key)i).key; 649 // we subtract 100 if not found and add 1 if found 650 found -= 100; 651 if(valueCount.containsKey(key)) 652 { 653 Map<String, Integer> v = valueCount.get(key); 654 if(v.size() == 1 && v.containsKey(val) && v.get(val) == total) 655 { 656 found += 101; 657 } 658 } 659 } 660 } 661 if(found > 0) 662 p.add(t); 663 } 664 } 665 } 666 String t = ""; 667 for(TaggingPreset tp : p) 668 { 669 if(t.length() > 0) 670 t += "\n"; 671 t += tp.getName(); 672 } 673 presets.setText(t); 674 presets.setVisible(t.length() > 0); 690 int found = 0; 691 for(TaggingPreset.Item i : t.data) { 692 if(!(i instanceof TaggingPreset.Key)) 693 continue; 694 String val = ((TaggingPreset.Key)i).value; 695 String key = ((TaggingPreset.Key)i).key; 696 // we subtract 100 if not found and add 1 if found 697 found -= 100; 698 if(!valueCount.containsKey(key)) 699 continue; 700 701 Map<String, Integer> v = valueCount.get(key); 702 if(v.size() == 1 && v.containsKey(val) && v.get(val) == total) 703 found += 101; 704 } 705 706 if(found <= 0) 707 continue; 708 709 JLabel lbl = new JLabel(t.getName()); 710 lbl.addMouseListener(new PresetLabelML(lbl, t)); 711 presets.add(lbl, GBC.eol().fill(GBC.HORIZONTAL)); 712 } 713 } 714 715 if(presets.getComponentCount() > 0) { 716 presets.setVisible(true); 717 // This ensures the presets are exactly as high as needed. 718 int height = presets.getComponentCount() * presets.getComponent(0).getHeight(); 719 Dimension size = new Dimension(presets.getWidth(), height); 720 presets.setMaximumSize(size); 721 presets.setMinimumSize(size); 722 } else 723 presets.setVisible(false); 675 724 } 676 725 … … 746 795 } 747 796 797 checkPresets(nodes, ways, relations, closedways); 798 748 799 membershipTable.getTableHeader().setVisible(membershipData.getRowCount() > 0); 749 800 membershipTable.setVisible(membershipData.getRowCount() > 0); … … 761 812 else if(hasMemberships) membershipTable.changeSelection(0, 0, false, false); 762 813 763 checkPresets(nodes, ways, relations, closedways);764 765 814 if(propertyData.getRowCount() != 0 || membershipData.getRowCount() != 0) { 766 815 setTitle(tr("Properties: {0} / Memberships: {1}",
Note:
See TracChangeset
for help on using the changeset viewer.