Ignore:
Timestamp:
2011-03-23T17:23:31+01:00 (14 years ago)
Author:
zverik
Message:

role list -> table; download parents action; more type and role presets (relcontext plugin)

Location:
applications/editors/josm/plugins/relcontext/src/relcontext
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/relcontext/src/relcontext/ChosenRelation.java

    r25673 r25679  
    4747   
    4848    private final static String[] MULTIPOLYGON_TYPES = new String[] {
    49         "multipolygon", "boundary", "natural_reserve"
     49        "multipolygon", "boundary"
    5050    };
    5151
  • applications/editors/josm/plugins/relcontext/src/relcontext/RelContextDialog.java

    r25678 r25679  
    11package relcontext;
    22
    3 import java.awt.event.ActionEvent;
    4 import java.awt.event.ComponentEvent;
    5 import java.awt.event.FocusEvent;
    6 import java.beans.PropertyChangeEvent;
    7 import static org.openstreetmap.josm.tools.I18n.tr;
     3import org.openstreetmap.josm.gui.DefaultNameFormatter;
     4import org.openstreetmap.josm.data.osm.NameFormatter;
     5import java.awt.Component;
     6import javax.swing.event.ListSelectionEvent;
     7import javax.swing.table.DefaultTableCellRenderer;
     8import javax.swing.table.TableColumnModel;
     9import javax.swing.table.DefaultTableModel;
     10import java.awt.event.*;
     11import java.util.*;
     12import javax.swing.*;
     13import relcontext.actions.*;
    814
    915import java.awt.BorderLayout;
    1016import java.awt.Dialog.ModalityType;
    11 import java.awt.Dimension;
    1217import java.awt.FlowLayout;
    1318import java.awt.GridBagLayout;
    14 import java.awt.event.ActionListener;
    15 import java.awt.event.ComponentAdapter;
    16 import java.awt.event.FocusAdapter;
    17 import java.awt.event.KeyEvent;
    18 import java.awt.event.MouseEvent;
    19 import java.awt.event.MouseAdapter;
     19import java.beans.PropertyChangeEvent;
    2020import java.beans.PropertyChangeListener;
     21import javax.swing.event.ListSelectionListener;
    2122
    2223import org.openstreetmap.josm.Main;
     
    2627import org.openstreetmap.josm.data.osm.event.SelectionEventManager;
    2728import org.openstreetmap.josm.data.osm.OsmPrimitive;
     29import org.openstreetmap.josm.data.osm.RelationMember;
     30import org.openstreetmap.josm.data.osm.event.DatasetEventManager;
    2831import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    2932import org.openstreetmap.josm.gui.MapView;
     
    3235import org.openstreetmap.josm.gui.dialogs.ToggleDialog;
    3336import org.openstreetmap.josm.tools.Shortcut;
    34 
    35 import java.util.*;
    36 import javax.swing.*;
     37import org.openstreetmap.josm.tools.GBC;
    3738import org.openstreetmap.josm.command.ChangeCommand;
    38 import org.openstreetmap.josm.data.osm.RelationMember;
    39 import org.openstreetmap.josm.data.osm.event.DatasetEventManager;
    4039import org.openstreetmap.josm.gui.tagging.ac.AutoCompletingComboBox;
    4140import org.openstreetmap.josm.gui.tagging.ac.AutoCompletionListItem;
    42 import org.openstreetmap.josm.gui.tagging.ac.AutoCompletionManager;
    43 import org.openstreetmap.josm.tools.GBC;
    44 import relcontext.actions.*;
     41import static org.openstreetmap.josm.tools.I18n.tr;
    4542
    4643/**
     
    5047 */
    5148public class RelContextDialog extends ToggleDialog implements EditLayerChangeListener, ChosenRelationListener, SelectionChangedListener {
    52     private JList relationsList;
    53     private final DefaultListModel relationsData;
     49
     50    private final DefaultTableModel relationsData;
    5451    private ChosenRelation chosenRelation;
    5552    private JPanel chosenRelationPanel;
     
    7168        MapView.addEditLayerChangeListener(chosenRelation);
    7269
    73         relationsData = new DefaultListModel();
    74         relationsList = new JList(relationsData);
    75         relationsList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    76         relationsList.setCellRenderer(new OsmPrimitivRenderer() {
    77             @Override
    78             protected String getComponentToolTipText( OsmPrimitive value ) {
    79                 return null;
    80             }
    81         });
    82         relationsList.addMouseListener(new MouseAdapter() {
    83             @Override
    84             public void mouseClicked( MouseEvent e ) {
    85                 if( Main.main.getEditLayer() == null ) {
    86                     return;
    87                 }
    88                 chosenRelation.set((Relation)relationsList.getSelectedValue());
    89                 relationsList.clearSelection();
    90             }
    91         });
    92         rcPanel.add(new JScrollPane(relationsList), BorderLayout.CENTER);
     70        relationsData = new RelationTableModel();
     71        relationsData.setColumnIdentifiers(new String[] {tr("Member Of"), tr("Role")});
     72        final JTable relationsTable = new JTable(relationsData);
     73        configureRelationsTable(relationsTable);
     74        rcPanel.add(new JScrollPane(relationsTable, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER), BorderLayout.CENTER);
    9375
    9476        chosenRelationPanel = new JPanel(new BorderLayout());
     
    173155    }
    174156
     157    private void configureRelationList( final JList relationsList ) {
     158        relationsList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
     159        relationsList.setCellRenderer(new OsmPrimitivRenderer() {
     160            @Override
     161            protected String getComponentToolTipText( OsmPrimitive value ) {
     162                return null;
     163            }
     164        });
     165        relationsList.addMouseListener(new MouseAdapter() {
     166            @Override
     167            public void mouseClicked( MouseEvent e ) {
     168                if( Main.main.getEditLayer() == null ) {
     169                    return;
     170                }
     171                chosenRelation.set((Relation)relationsList.getSelectedValue());
     172                relationsList.clearSelection();
     173            }
     174        });
     175    }
     176
     177    private void configureRelationsTable( final JTable relationsTable ) {
     178        relationsTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
     179        relationsTable.setTableHeader(null);
     180        TableColumnModel columns = relationsTable.getColumnModel();
     181        columns.getColumn(0).setCellRenderer(new OsmPrimitivRenderer() {
     182            @Override
     183            protected String getComponentToolTipText( OsmPrimitive value ) {
     184                return null;
     185            }
     186        });
     187        columns.getColumn(1).setPreferredWidth(40);
     188        columns.getColumn(0).setPreferredWidth(220);
     189        relationsTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
     190            public void valueChanged( ListSelectionEvent e ) {
     191                int selectedRow = relationsTable.getSelectedRow();
     192                if( selectedRow >= 0 ) {
     193                    chosenRelation.set((Relation)relationsData.getValueAt(selectedRow, 0));
     194                    relationsTable.clearSelection();
     195                }
     196            }
     197        });
     198    }
     199
    175200    @Override
    176201    public void hideNotify() {
     
    226251        updateRoleIndicator();
    227252        // repopulate relations table
    228         relationsData.clear();
     253        relationsData.setRowCount(0);
    229254        if( newSelection == null )
    230255            return;
    231         Set<Relation> rels = new HashSet<Relation>();
     256
     257        final NameFormatter formatter = DefaultNameFormatter.getInstance();
     258        Set<Relation> relations = new TreeSet<Relation>(new Comparator<Relation>() {
     259            public int compare( Relation r1, Relation r2 ) {
     260                return r1.getDisplayName(formatter).compareTo(r2.getDisplayName(formatter));
     261            }
     262        });
    232263        for( OsmPrimitive element : newSelection ) {
    233264            for( OsmPrimitive ref : element.getReferrers() ) {
    234265                if( ref instanceof Relation && !ref.isIncomplete() && !ref.isDeleted() ) {
    235                     rels.add((Relation) ref);
    236                 }
    237             }
    238         }
    239         for( Relation rel : rels )
    240             relationsData.addElement(rel);
     266                    relations.add((Relation) ref);
     267                }
     268            }
     269        }
     270
     271        for( Relation rel : relations ) {
     272            String role = null;
     273            for( RelationMember m : rel.getMembers() ) {
     274                for( OsmPrimitive element : newSelection ) {
     275                    if( m.getMember().equals(element) ) {
     276                        if( role == null )
     277                            role = m.getRole();
     278                        else if( !role.equals(m.getRole()) ) {
     279                            role = tr("<different>");
     280                            break;
     281                        }
     282                    }
     283                }
     284            }
     285            relationsData.addRow(new Object[] {rel, role == null ? "" : role});
     286        }
    241287    }
    242288
     
    257303        possibleRoles.put("boundary", new String[] {"admin_centre", "label", "subarea"});
    258304        possibleRoles.put("route", new String[] {"forward", "backward", "stop", "platform"});
     305        possibleRoles.put("restriction", new String[] {"from", "to", "via", "location_hint"});
     306        possibleRoles.put("enforcement", new String[] {"device", "from", "to", "force"});
     307        possibleRoles.put("destination_sign", new String[] {"to", "from", "intersection", "sign"});
     308        possibleRoles.put("site", new String[] {"perimeter", "entrance", "label"});
     309        possibleRoles.put("bridge", new String[] {"across", "under", "outline", "edge"});
     310        possibleRoles.put("tunnel", new String[] {"through", "outline", "edge"});
     311        possibleRoles.put("surveillance", new String[] {"camera", "extent", "visible", "hidden"});
    259312    }
    260313
     
    262315        String currentRole = roleBox.getSelectedItem() == null ? null : ((AutoCompletionListItem)roleBox.getSelectedItem()).getValue();
    263316        List<String> items = new ArrayList<String>();
    264         items.add("");
     317        items.add(" ");
    265318        if( chosenRelation != null && chosenRelation.get() != null ) {
    266319            if( chosenRelation.isMultipolygon() ) {
     
    271324                String[] values = possibleRoles.get(chosenRelation.get().get("type"));
    272325                if( values != null )
    273                     for( String value : values )
    274                         items.add(value);
     326                    items.addAll(Arrays.asList(values));
    275327            }
    276328            for( RelationMember m : chosenRelation.get().getMembers() )
    277329                if( !items.contains(m.getRole()) )
    278330                    items.add(m.getRole());
     331        }
     332        if( currentRole != null && currentRole.length() > 1 ) {
    279333            lastSelectedRole = currentRole;
    280         } else if( currentRole != null && currentRole.length() > 0 ) {
    281             lastSelectedRole = currentRole;
    282334        }
    283335        roleBox.setPossibleItems(items);
    284         // todo: store last non-empty role and try to select it if present, but do not store if empty role was chosen
    285 //        if( lastSelectedRole != null && items.contains(lastSelectedRole) )
    286 //            roleBox.setSelectedItem(lastSelectedRole);
    287 //        else if( lastSelectedRole == null && items.contains("outer") )
    288 //            roleBox.setSelectedItem("outer");
     336        if( lastSelectedRole != null && items.contains(lastSelectedRole) )
     337            roleBox.setSelectedItem(lastSelectedRole);
     338        // todo: do we really want empty role as default one? Maybe, store last selected role in preferences
    289339    }
    290340
     
    351401        private void checkPopup( MouseEvent e ) {
    352402            if( e.isPopupTrigger() && chosenRelation.get() != null ) {
    353                 popupMenu.show(e.getComponent(), e.getX(), e.getY());
     403                popupMenu.show(e.getComponent(), e.getX(), e.getY() - 5);
    354404            }
    355405        }
     
    360410            add(new SelectMembersAction(chosenRelation));
    361411            add(new DeleteChosenRelationAction(chosenRelation));
     412            add(new DownloadParentsAction(chosenRelation));
    362413        }
    363414    }
     
    421472        }
    422473    }
     474
     475    private static class RelationTableModel extends DefaultTableModel {
     476        @Override
     477        public boolean isCellEditable(int row, int column) {
     478            return false;
     479        }
     480
     481        @Override
     482        public Class<?> getColumnClass(int columnIndex) {
     483            return columnIndex == 0 ? Relation.class : String.class;
     484        }
     485    }
    423486}
  • applications/editors/josm/plugins/relcontext/src/relcontext/actions/CreateRelationAction.java

    r25677 r25679  
    7676    }
    7777
     78    // Thanks to TagInfo for the list
    7879    private static final List<String> RELATION_TYPES = Arrays.asList(new String[] {
    79         "multipolygon", "boundary", "route"
     80        "multipolygon", "boundary", "route", "site", "restriction", "associatedStreet", "public_transport",
     81        "street", "collection", "address", "enforcement", "destination_sign", "route_master", "junction", "site",
     82        "waterway", "bridge", "tunnel", "surveillance"
    8083    });
    8184
Note: See TracChangeset for help on using the changeset viewer.