Logo Search packages:      
Sourcecode: josm version File versions  Download package

org::openstreetmap::josm::gui::dialogs::PropertiesDialog::PropertiesDialog ( MapFrame  mapFrame  )  [inline]

Create a new PropertiesDialog

Definition at line 325 of file PropertiesDialog.java.

References org::openstreetmap::josm::gui::tagging::TaggingPreset::actionPerformed(), membershipData, org::openstreetmap::josm::data::osm::visitor::NameVisitor::name, nameVisitor, propertyData, propertyEdit(), propertyTable, and org::openstreetmap::josm::data::osm::visitor::NameVisitor::visit().

                                                 {
            super(tr("Properties/Memberships"), "propertiesdialog", tr("Properties for selected objects."), KeyEvent.VK_P, 150);

            // ---------------------------------------
            // This drop-down is really deprecated but we offer people a chance to 
            // activate it if they really want. Presets should be used from the 
            // menu.
            if (TaggingPresetPreference.taggingPresets.size() > 0 && 
                        Main.pref.getBoolean("taggingpresets.in-properties-dialog", false)) {
                  Vector<ActionListener> allPresets = new Vector<ActionListener>();
                  for (final TaggingPreset p : TaggingPresetPreference.taggingPresets)
                        allPresets.add(new ForwardActionListener(this, p));

                  TaggingPreset empty = new TaggingPreset();
                  // empty.setName("this drop-down will be removed soon");
                  allPresets.add(0, new ForwardActionListener(this, empty));
                  taggingPresets.setModel(new DefaultComboBoxModel(allPresets));
                  JPanel north = new JPanel(new GridBagLayout());
                  north.add(getComponent(0),GBC.eol().fill(GBC.HORIZONTAL));
                  north.add(taggingPresets,GBC.eol().fill(GBC.HORIZONTAL));
                  add(north, BorderLayout.NORTH);
            }
            taggingPresets.addActionListener(new ActionListener(){
                  public void actionPerformed(ActionEvent e) {
                        TaggingPreset preset = ((ForwardActionListener)taggingPresets.getSelectedItem()).preset;
                        preset.actionPerformed(e);
                        taggingPresets.setSelectedItem(null);
                  }
            });
            taggingPresets.setRenderer(new TaggingCellRenderer());

            // setting up the properties table
            
            propertyData.setColumnIdentifiers(new String[]{tr("Key"),tr("Value")});
            propertyTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
      
            propertyTable.getColumnModel().getColumn(1).setCellRenderer(new DefaultTableCellRenderer(){
                  @Override public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
                        Component c = super.getTableCellRendererComponent(table, value, isSelected, false, row, column);
                        if (c instanceof JLabel) {
                              String str = ((JComboBox) value).getEditor().getItem().toString();
                              ((JLabel)c).setText(str);
                              if (str.equals(tr("<different>")))
                                    c.setFont(c.getFont().deriveFont(Font.ITALIC));
                        }
                        return c;
                  }
            });
            
            // setting up the membership table
            
            membershipData.setColumnIdentifiers(new String[]{tr("Member Of"),tr("Role")});
            membershipTable.setRowSelectionAllowed(false);
            
            membershipTable.getColumnModel().getColumn(0).setCellRenderer(new DefaultTableCellRenderer() {
                  @Override public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
                        Component c = super.getTableCellRendererComponent(table, value, isSelected, false, row, column);
                        if (c instanceof JLabel) {
                              nameVisitor.visit((Relation)value);
                              ((JLabel)c).setText(nameVisitor.name);
                        }
                        return c;
                  }
            });
            
            // combine both tables and wrap them in a scrollPane
            JPanel bothTables = new JPanel();
            bothTables.setLayout(new GridBagLayout());
            bothTables.add(propertyTable.getTableHeader(), GBC.eol().fill(GBC.HORIZONTAL));
            bothTables.add(propertyTable, GBC.eol().fill(GBC.BOTH));
            bothTables.add(membershipTable.getTableHeader(), GBC.eol().fill(GBC.HORIZONTAL));
            bothTables.add(membershipTable, GBC.eol().fill(GBC.BOTH));
            
            DblClickWatch dblClickWatch = new DblClickWatch();
            propertyTable.addMouseListener(dblClickWatch);
            membershipTable.addMouseListener(dblClickWatch);
            JScrollPane scrollPane = new JScrollPane(bothTables);
            scrollPane.addMouseListener(dblClickWatch);
            add(scrollPane, BorderLayout.CENTER);

            JPanel buttonPanel = new JPanel(new GridLayout(1,3));
            ActionListener buttonAction = new ActionListener(){
                  public void actionPerformed(ActionEvent e) {
                        int sel = propertyTable.getSelectedRow();
                        if (e.getActionCommand().equals("Add"))
                              add();
                        else if (e.getActionCommand().equals("Edit")) {
                              if (sel == -1)
                                    JOptionPane.showMessageDialog(Main.parent, tr("Please select the row to edit."));
                              else
                                    propertyEdit(sel);
                        } else if (e.getActionCommand().equals("Delete")) {
                              if (sel == -1)
                                    JOptionPane.showMessageDialog(Main.parent, tr("Please select the row to delete."));
                              else
                                    delete(sel);
                        }
                  }
            };
            
            buttonPanel.add(createButton(marktr("Add"),tr("Add a new key/value pair to all objects"), KeyEvent.VK_A, buttonAction));
            buttonPanel.add(createButton(marktr("Edit"),tr( "Edit the value of the selected key for all objects"), KeyEvent.VK_E, buttonAction));
            buttonPanel.add(createButton(marktr("Delete"),tr("Delete the selected key in all objects"), KeyEvent.VK_D, buttonAction));
            add(buttonPanel, BorderLayout.SOUTH);

            DataSet.selListeners.add(this);
      }


Generated by  Doxygen 1.6.0   Back to index