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

org::openstreetmap::josm::gui::dialogs::RelationEditor::RelationEditor ( Relation  relation  )  [inline]

Creates a new relation editor for the given relation. The relation will be saved if the user selects "ok" in the editor.

If no relation is given, will create an editor for a new relation.

Parameters:
relation relation to edit, or null to create a new one.

Definition at line 99 of file RelationEditor.java.

References org::openstreetmap::josm::data::osm::OsmPrimitive::entrySet(), org::openstreetmap::josm::data::osm::OsmPrimitive::id, org::openstreetmap::josm::data::osm::RelationMember::member, memberData, org::openstreetmap::josm::data::osm::Relation::members, propertyData, propertyTable, org::openstreetmap::josm::data::osm::OsmPrimitive::put(), and org::openstreetmap::josm::data::osm::RelationMember::role.

      {
            super(relation == null ? tr("Create new relation") : 
                  relation.id == 0 ? tr ("Edit new relation") :
                  tr("Edit relation #{0}", relation.id));
            this.relation = relation;
            
            if (relation == null) {
                  // create a new relation
                  this.clone = new Relation();
            } else {
                  // edit an existing relation
                  this.clone = new Relation(relation);      
            }
            
            getContentPane().setLayout(new BorderLayout());
            JTabbedPane tabPane = new JTabbedPane();
            getContentPane().add(tabPane, BorderLayout.CENTER);
            
            // (ab)use JOptionPane to make this look familiar;
            // hook up with JOptionPane's property change event
            // to detect button click
            final JOptionPane okcancel = new JOptionPane("", 
                  JOptionPane.PLAIN_MESSAGE, JOptionPane.OK_CANCEL_OPTION, null);
            getContentPane().add(okcancel, BorderLayout.SOUTH);
            
            okcancel.addPropertyChangeListener(new PropertyChangeListener() {
                  public void propertyChange(PropertyChangeEvent event) {
                        if (event.getPropertyName().equals(JOptionPane.VALUE_PROPERTY) && event.getNewValue() != null) {
                              if ((Integer)event.getNewValue() == JOptionPane.OK_OPTION) {
                                    // clicked ok!
                                    if (RelationEditor.this.relation == null) {
                                          Main.main.undoRedo.add(new AddCommand(clone));
                                    } else if (!RelationEditor.this.relation.realEqual(clone, true)) {
                                          Main.main.undoRedo.add(new ChangeCommand(RelationEditor.this.relation, clone));
                                    }
                              }
                              setVisible(false);
                        }
                  }
            });

            JLabel help = new JLabel("<html><em>"+
                  "This is the basic relation editor which allows you to change the relation's tags " +
                  "as well as the members. In addition to this we should have a smart editor that " +
                  "detects the type of relationship and limits your choices in a sensible way.</em></html>");
            
            getContentPane().add(help, BorderLayout.NORTH);       
            try { setAlwaysOnTop(true); } catch (SecurityException sx) {}
            
            // Basic Editor panel has two blocks; 
            // a tag table at the top and a membership list below.

            // setting up the properties table
            
            propertyData.setColumnIdentifiers(new String[]{tr("Key"),tr("Value")});
            propertyTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
            propertyData.addTableModelListener(new TableModelListener() {
                  public void tableChanged(TableModelEvent tme) {
                        if (tme.getType() == TableModelEvent.UPDATE) {
                              int row = tme.getFirstRow();
                  
                              if (!(tme.getColumn() == 0 && row == propertyData.getRowCount() -1)) {
                                    clone.entrySet().clear();
                                    for (int i = 0; i < propertyData.getRowCount(); i++) {
                                          String key = propertyData.getValueAt(i, 0).toString();
                                          String value = propertyData.getValueAt(i, 1).toString();
                                          if (key.length() > 0 && value.length() > 0) clone.put(key, value);
                                    }
                                    refreshTables();
                              }
                        }
                  }
            });
            propertyTable.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE);
            
            // setting up the member table
            
          memberData.setColumnIdentifiers(new String[]{tr("Role"),tr("Occupied By")});
            memberTable.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
            memberTable.getColumnModel().getColumn(1).setCellRenderer(new OsmPrimitivRenderer());
            /*
            memberTable.getColumnModel().getColumn(1).setCellRenderer(new DefaultTableCellRenderer() {
                  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) {
                              ((OsmPrimitive)value).visit(nameVisitor);
                              ((JLabel)c).setText(nameVisitor.name);
                        }
                        return c;
                  }
            });   
            */
            memberData.addTableModelListener(new TableModelListener() {
                  public void tableChanged(TableModelEvent tme) {
                        if (tme.getType() == TableModelEvent.UPDATE && tme.getColumn() == 0) {
                              int row = tme.getFirstRow();
                              clone.members.get(row).role = memberData.getValueAt(row, 0).toString();
                        }
                  }
            });
            memberTable.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE);

            
            // combine both tables and wrap them in a scrollPane
            JPanel bothTables = new JPanel();
            bothTables.setLayout(new GridBagLayout());
            bothTables.add(new JLabel(tr("Tags (empty value deletes tag)")), GBC.eol().fill(GBC.HORIZONTAL));
            bothTables.add(new JScrollPane(propertyTable), GBC.eop().fill(GBC.BOTH));
            bothTables.add(new JLabel(tr("Members")), GBC.eol().fill(GBC.HORIZONTAL));
            bothTables.add(new JScrollPane(memberTable), GBC.eol().fill(GBC.BOTH));
            
            JPanel buttonPanel = new JPanel(new GridLayout(1,3));
            
            buttonPanel.add(createButton(marktr("Add Selected"),"addselected", tr("Add all currently selected objects as members"), KeyEvent.VK_A, new ActionListener() {
                  public void actionPerformed(ActionEvent e) {
                        addSelected();
                  }
            }));

            buttonPanel.add(createButton(marktr("Delete"),"delete", tr("Remove the member in the current table row from this relation"), KeyEvent.VK_D, new ActionListener() {
                  public void actionPerformed(ActionEvent e) {
                        int[] rows = memberTable.getSelectedRows();
                        RelationMember mem = new RelationMember();
                        for (int row : rows) {
                              mem.role = memberTable.getValueAt(row, 0).toString();
                              mem.member = (OsmPrimitive) memberTable.getValueAt(row, 1);
                              clone.members.remove(mem);
                        }
                        refreshTables();
                  }
            }));

            buttonPanel.add(createButton(marktr("Select"),"select", tr("Highlight the member from the current table row as JOSM's selection"), KeyEvent.VK_S, new ActionListener() {
                  public void actionPerformed(ActionEvent e) {
                        int[] rows = memberTable.getSelectedRows();
                        ArrayList<OsmPrimitive> sel = new ArrayList<OsmPrimitive>(rows.length);
                        for (int i : rows) { sel.add((OsmPrimitive)memberTable.getValueAt(i, 1)); }
                        Main.ds.setSelected(sel);
                  }
            }));
            bothTables.add(buttonPanel, GBC.eop().fill(GBC.HORIZONTAL));

            tabPane.add(bothTables, "Basic");
            
            refreshTables();
            
            setSize(new Dimension(400, 500));
            setLocationRelativeTo(Main.parent);
      }


Generated by  Doxygen 1.6.0   Back to index