Changeset 32398 in osm


Ignore:
Timestamp:
2016-06-25T11:56:57+02:00 (8 years ago)
Author:
donvip
Message:

checkstyle

Location:
applications/editors/josm/plugins/reltoolbox/src/relcontext
Files:
23 edited

Legend:

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

    r32395 r32398  
    6969
    7070    public boolean isSame(Object r) {
    71         if (r == null )
     71        if (r == null)
    7272            return chosenRelation == null;
    73         else if (!(r instanceof Relation) )
     73        else if (!(r instanceof Relation))
    7474            return false;
    7575        else
     
    8989
    9090    public static boolean isMultipolygon(Relation r) {
    91         if (r == null )
     91        if (r == null)
    9292            return false;
    9393        String type = r.get("type");
    94         if (type == null )
     94        if (type == null)
    9595            return false;
    96         for (String t : MULTIPOLYGON_TYPES )
    97             if (t.equals(type) )
     96        for (String t : MULTIPOLYGON_TYPES) {
     97            if (t.equals(type))
    9898                return true;
     99        }
    99100        return false;
    100101    }
     
    138139            return;
    139140
    140         OsmDataLayer dataLayer = mv.getEditLayer();
    141         float opacity = dataLayer == null ? 0.0f : !dataLayer.isVisible() ? 0.0f : (float)dataLayer.getOpacity();
    142         if (opacity < 0.01 )
     141        OsmDataLayer dataLayer = mv.getLayerManager().getEditLayer();
     142        float opacity = dataLayer == null ? 0.0f : !dataLayer.isVisible() ? 0.0f : (float) dataLayer.getOpacity();
     143        if (opacity < 0.01)
    143144            return;
    144145
     
    153154        g.setComposite(oldComposite);
    154155        g.setStroke(oldStroke);
    155 
    156156    }
    157157
     
    159159        for (OsmPrimitive element : rel.getMemberPrimitives()) {
    160160            if (element.getType() == OsmPrimitiveType.NODE) {
    161                 Node node = (Node)element;
     161                Node node = (Node) element;
    162162                Point center = mv.getPoint(node);
    163163                g.drawOval(center.x - 4, center.y - 4, 9, 9);
    164164            } else if (element.getType() == OsmPrimitiveType.WAY) {
    165                 Way way = (Way)element;
     165                Way way = (Way) element;
    166166                if (way.getNodesCount() >= 2) {
    167167                    GeneralPath b = new GeneralPath();
     
    177177                Color oldColor = g.getColor();
    178178                g.setColor(Color.magenta);
    179                 drawRelations(g, mv, bbox, (Relation)element);
     179                drawRelations(g, mv, bbox, (Relation) element);
    180180                g.setColor(oldColor);
    181181            }
     
    186186    @Override
    187187    public void relationMembersChanged(RelationMembersChangedEvent event) {
    188         if (chosenRelation != null && event.getRelation().equals(chosenRelation) ) {
     188        if (chosenRelation != null && event.getRelation().equals(chosenRelation)) {
    189189            fireRelationChanged(chosenRelation);
    190190        }
     
    193193    @Override
    194194    public void tagsChanged(TagsChangedEvent event) {
    195         if (chosenRelation != null && event.getPrimitive().equals(chosenRelation) ) {
     195        if (chosenRelation != null && event.getPrimitive().equals(chosenRelation)) {
    196196            fireRelationChanged(chosenRelation);
    197197        }
     
    200200    @Override
    201201    public void dataChanged(DataChangedEvent event) {
    202         if (chosenRelation != null ) {
     202        if (chosenRelation != null) {
    203203            fireRelationChanged(chosenRelation);
    204204        }
     
    207207    @Override
    208208    public void primitivesRemoved(PrimitivesRemovedEvent event) {
    209         if (chosenRelation != null && event.getPrimitives().contains(chosenRelation) ) {
     209        if (chosenRelation != null && event.getPrimitives().contains(chosenRelation)) {
    210210            clear();
    211211        }
     
    214214    @Override
    215215    public void wayNodesChanged(WayNodesChangedEvent event) {
    216         if (chosenRelation != null )
    217         {
     216        if (chosenRelation != null) {
    218217            fireRelationChanged(chosenRelation); // download incomplete primitives doesn't cause dataChanged event
    219218        }
     
    222221    @Override
    223222    public void primitivesAdded(PrimitivesAddedEvent event) {}
     223
    224224    @Override
    225225    public void nodeMoved(NodeMovedEvent event) {}
     226
    226227    @Override
    227228    public void otherDatasetChange(AbstractDatasetChangedEvent event) {}
  • applications/editors/josm/plugins/reltoolbox/src/relcontext/ChosenRelationComponent.java

    r32395 r32398  
    1515public class ChosenRelationComponent extends JLabel implements ChosenRelationListener {
    1616
    17     //private ChosenRelation chRel;
    18 
    1917    public ChosenRelationComponent(ChosenRelation rel) {
    2018        super("");
    21         /*        setBackground(Color.white);
    22         setOpaque(true);
    23         setBorder(new LineBorder(Color.black, 1, true));*/
    24         //this.chRel = rel;
    2519        rel.addChosenRelationListener(this);
    2620    }
     
    3226    }
    3327
    34     private final static String[] TYPE_KEYS = new String[] {
     28    private static final String[] TYPE_KEYS = new String[] {
    3529            "natural", "landuse", "place", "waterway", "leisure", "amenity", "restriction", "public_transport", "route", "enforcement"
    3630    };
    3731
    38     private final static String[] NAMING_TAGS = new String[] {
     32    private static final String[] NAMING_TAGS = new String[] {
    3933            "name", "place_name", "ref", "destination", "note"
    4034    };
    4135
    4236    protected String prepareText(Relation rel) {
    43         if (rel == null )
     37        if (rel == null)
    4438            return "";
    4539
    4640        String type = rel.get("type");
    47         if (type == null || type.length() == 0 ) {
     41        if (type == null || type.length() == 0) {
    4842            type = "-";
    4943        }
    5044
    5145        String tag = null;
    52         for (int i = 0; i < TYPE_KEYS.length && tag == null; i++ )
     46        for (int i = 0; i < TYPE_KEYS.length && tag == null; i++) {
    5347            if (rel.hasKey(TYPE_KEYS[i])) {
    5448                tag = TYPE_KEYS[i];
    5549            }
    56         if (tag != null ) {
     50        }
     51        if (tag != null) {
    5752            tag = tag.substring(0, 2) + "=" + rel.get(tag);
    5853        }
    5954
    6055        String name = null;
    61         for (int i = 0; i < NAMING_TAGS.length && name == null; i++ )
    62             if (rel.hasKey(NAMING_TAGS[i]) ) {
     56        for (int i = 0; i < NAMING_TAGS.length && name == null; i++) {
     57            if (rel.hasKey(NAMING_TAGS[i])) {
    6358                name = rel.get(NAMING_TAGS[i]);
    6459            }
     60        }
    6561
    6662        StringBuilder sb = new StringBuilder();
    6763        sb.append(type.substring(0, 1));
    68         if (type.equals("boundary") && rel.hasKey("admin_level") ) {
     64        if (type.equals("boundary") && rel.hasKey("admin_level")) {
    6965            sb.append(rel.get("admin_level"));
    7066        }
    71         if (name != null ) {
     67        if (name != null) {
    7268            sb.append(" \"").append(name).append('"');
    7369        }
    74         if (tag != null ) {
     70        if (tag != null) {
    7571            sb.append("; ").append(tag);
    7672        }
  • applications/editors/josm/plugins/reltoolbox/src/relcontext/ExtraNameFormatHook.java

    r32395 r32398  
    2626    @Override
    2727    public String checkFormat(IWay way, String defaultName) {
    28         if (way.get("place") != null && way.get("name") == null && way.get("place_name") != null )
     28        if (way.get("place") != null && way.get("name") == null && way.get("place_name") != null)
    2929            return way.get("place_name") + " " + defaultName;
    3030        return null;
     
    3737            String name = relation.get("destination");
    3838            if (type.equals("destination_sign") && name != null) {
    39                 if (relation.get("distance") != null ) {
     39                if (relation.get("distance") != null) {
    4040                    name += " " + relation.get("distance");
    4141                }
    42                 if (defaultName.indexOf('"') < 0 )
     42                if (defaultName.indexOf('"') < 0)
    4343                    return '"' + name + "\" " + defaultName;
    4444                else
  • applications/editors/josm/plugins/reltoolbox/src/relcontext/RelContextDialog.java

    r32395 r32398  
    7070import org.openstreetmap.josm.data.osm.event.SelectionEventManager;
    7171import org.openstreetmap.josm.gui.DefaultNameFormatter;
    72 import org.openstreetmap.josm.gui.MapView;
    73 import org.openstreetmap.josm.gui.MapView.EditLayerChangeListener;
    7472import org.openstreetmap.josm.gui.OsmPrimitivRenderer;
    7573import org.openstreetmap.josm.gui.dialogs.ToggleDialog;
    76 import org.openstreetmap.josm.gui.layer.OsmDataLayer;
     74import org.openstreetmap.josm.gui.layer.MainLayerManager.ActiveLayerChangeEvent;
     75import org.openstreetmap.josm.gui.layer.MainLayerManager.ActiveLayerChangeListener;
    7776import org.openstreetmap.josm.gui.tagging.ac.AutoCompletingComboBox;
    7877import org.openstreetmap.josm.tools.GBC;
     
    102101 * @author Zverik
    103102 */
    104 public class RelContextDialog extends ToggleDialog implements EditLayerChangeListener, ChosenRelationListener, SelectionChangedListener {
     103public class RelContextDialog extends ToggleDialog implements ActiveLayerChangeListener, ChosenRelationListener, SelectionChangedListener {
    105104
    106105    public static final String PREF_PREFIX = "reltoolbox";
     
    136135        final JTable relationsTable = new JTable(relationsData);
    137136        configureRelationsTable(relationsTable);
    138         rcPanel.add(new JScrollPane(relationsTable, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER), BorderLayout.CENTER);
     137        rcPanel.add(new JScrollPane(relationsTable,
     138                JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER), BorderLayout.CENTER);
    139139
    140140        final MouseListener relationMouseAdapter = new ChosenRelationMouseAdapter();
     
    146146            @Override
    147147            public void itemStateChanged(ItemEvent e) {
    148                 if (e.getStateChange() == ItemEvent.DESELECTED ) return;
     148                if (e.getStateChange() == ItemEvent.DESELECTED) return;
    149149                String memberRole = roleBoxModel.getSelectedMembersRole();
    150150                String selectedRole = roleBoxModel.isAnotherRoleSelected() ? askForRoleName() : roleBoxModel.getSelectedRole();
     
    200200        });
    201201        downloadButton.setVisible(false);
    202         if (Main.pref.getBoolean(PREF_PREFIX + ".hidetopline", false) ) {
     202        if (Main.pref.getBoolean(PREF_PREFIX + ".hidetopline", false)) {
    203203            chosenRelationPanel.setVisible(false);
    204204        }
     
    229229
    230230            private void checkPopup(MouseEvent e) {
    231                 if (e.isPopupTrigger() ) {
     231                if (e.isPopupTrigger()) {
    232232                    multiPopupMenu.show(e.getComponent(), e.getX(), e.getY());
    233233                }
     
    249249                int row = relationsTable.rowAtPoint(p);
    250250                if (SwingUtilities.isLeftMouseButton(e) && row >= 0) {
    251                     Relation relation = (Relation)relationsData.getValueAt(row, 0);
     251                    Relation relation = (Relation) relationsData.getValueAt(row, 0);
    252252                    if (e.getClickCount() > 1) {
    253                         Main.main.getEditLayer().data.setSelected(relation);
     253                        Main.getLayerManager().getEditLayer().data.setSelected(relation);
    254254                    }
    255255                }
     
    271271                    int row = relationsTable.rowAtPoint(p);
    272272                    if (row > -1) {
    273                         Relation relation = (Relation)relationsData.getValueAt(row, 0);
     273                        Relation relation = (Relation) relationsData.getValueAt(row, 0);
    274274                        JPopupMenu menu = chosenRelation.isSame(relation) ? popupMenu
    275275                                : new ChosenRelationPopupMenu(new StaticChosenRelation(relation));
     
    288288
    289289            @Override
    290             public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
     290            public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus,
     291                    int row, int column) {
    291292                Component c = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
    292                 if (!isSelected && value instanceof Relation && chosenRelation.isSame(value) ) {
     293                if (!isSelected && value instanceof Relation && chosenRelation.isSame(value)) {
    293294                    c.setBackground(CHOSEN_RELATION_COLOR);
    294295                } else {
     
    301302        columns.getColumn(1).setCellRenderer(new DefaultTableCellRenderer() {
    302303            @Override
    303             public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
     304            public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus,
     305                    int row, int column) {
    304306                Component c = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
    305                 if (!isSelected && chosenRelation.isSame(table.getValueAt(row, 0)) ) {
     307                if (!isSelected && chosenRelation.isSame(table.getValueAt(row, 0))) {
    306308                    c.setBackground(CHOSEN_RELATION_COLOR);
    307309                } else {
     
    318320                int selectedRow = relationsTable.getSelectedRow();
    319321                if (selectedRow >= 0) {
    320                     chosenRelation.set((Relation)relationsData.getValueAt(selectedRow, 0));
     322                    chosenRelation.set((Relation) relationsData.getValueAt(selectedRow, 0));
    321323                    relationsTable.clearSelection();
    322324                }
     
    334336    public void hideNotify() {
    335337        SelectionEventManager.getInstance().removeSelectionListener(this);
    336         MapView.removeEditLayerChangeListener(this);
     338        Main.getLayerManager().removeActiveLayerChangeListener(this);
    337339        DatasetEventManager.getInstance().removeDatasetListener(chosenRelation);
    338340        chosenRelation.clear();
     
    342344    public void showNotify() {
    343345        SelectionEventManager.getInstance().addSelectionListener(this, FireMode.IN_EDT_CONSOLIDATED);
    344         MapView.addEditLayerChangeListener(this);
     346        Main.getLayerManager().addActiveLayerChangeListener(this);
    345347        DatasetEventManager.getInstance().addDatasetListener(chosenRelation, FireMode.IN_EDT);
    346348    }
     
    352354    @Override
    353355    public void chosenRelationChanged(Relation oldRelation, Relation newRelation) {
    354         if (chosenRelationPanel != null && Main.pref.getBoolean(PREF_PREFIX + ".hidetopline", false) ) {
     356        if (chosenRelationPanel != null && Main.pref.getBoolean(PREF_PREFIX + ".hidetopline", false)) {
    355357            chosenRelationPanel.setVisible(newRelation != null);
    356358        }
    357         if (Main.main.getCurrentDataSet() != null ) {
    358             selectionChanged(Main.main.getCurrentDataSet().getSelected());
     359        if (Main.getLayerManager().getEditDataSet() != null) {
     360            selectionChanged(Main.getLayerManager().getEditDataSet().getSelected());
    359361        }
    360362        roleBoxModel.update();
    361         // ?
    362363    }
    363364
    364365    @Override
    365366    public void selectionChanged(Collection<? extends OsmPrimitive> newSelection) {
    366         if (!isVisible() || relationsData == null )
     367        if (!isVisible() || relationsData == null)
    367368            return;
    368369        roleBoxModel.update();
     
    370371        relationsData.setRowCount(0);
    371372        sortAndFixAction.chosenRelationChanged(chosenRelation.get(), chosenRelation.get());
    372         if (newSelection == null )
     373        if (newSelection == null)
    373374            return;
    374375
     
    388389                for (OsmPrimitive element : newSelection) {
    389390                    if (m.getMember().equals(element)) {
    390                         if (role == null ) {
     391                        if (role == null) {
    391392                            role = m.getRole();
    392393                        } else if (!role.equals(m.getRole())) {
     
    399400            relationsData.addRow(new Object[] {rel, role == null ? "" : role});
    400401        }
    401         for (OsmPrimitive element : newSelection )
    402             if (element instanceof Relation && !chosenRelation.isSame(element) ) {
     402        for (OsmPrimitive element : newSelection) {
     403            if (element instanceof Relation && !chosenRelation.isSame(element)) {
    403404                relationsData.addRow(new Object[] {element, ""});
    404405            }
     406        }
    405407    }
    406408
    407409    private void updateSelection() {
    408         if (Main.main.getCurrentDataSet() == null) {
     410        if (Main.getLayerManager().getEditDataSet() == null) {
    409411            selectionChanged(Collections.<OsmPrimitive>emptyList());
    410412        } else {
    411             selectionChanged(Main.main.getCurrentDataSet().getSelected());
     413            selectionChanged(Main.getLayerManager().getEditDataSet().getSelected());
    412414        }
    413415    }
    414416
    415417    @Override
    416     public void editLayerChanged(OsmDataLayer oldLayer, OsmDataLayer newLayer) {
     418    public void activeOrEditLayerChanged(ActiveLayerChangeEvent e) {
    417419        updateSelection();
    418420    }
     
    435437
    436438        ClassLoader classLoader = RelContextDialog.class.getClassLoader();
    437         try (
    438                 InputStream possibleRolesStream = classLoader.getResourceAsStream(POSSIBLE_ROLES_FILE);
     439        try (InputStream possibleRolesStream = classLoader.getResourceAsStream(POSSIBLE_ROLES_FILE);
    439440                BufferedReader r = new BufferedReader(new InputStreamReader(possibleRolesStream));
    440441                ) {
    441             while(r.ready()) {
     442            while (r.ready()) {
    442443                String line = r.readLine();
    443444                StringTokenizer t = new StringTokenizer(line, " ,;:\"");
     
    445446                    String type = t.nextToken();
    446447                    List<String> roles = new ArrayList<>();
    447                     while(t.hasMoreTokens() ) {
     448                    while (t.hasMoreTokens()) {
    448449                        roles.add(t.nextToken());
    449450                    }
     
    451452                }
    452453            }
    453         } catch(Exception e) {
     454        } catch (Exception e) {
    454455            Main.error("[RelToolbox] Error reading possible roles file.");
    455456            Main.error(e);
     
    463464        List<String> items = new ArrayList<>();
    464465        for (String role : roleBoxModel.getRoles()) {
    465             if (role.length() > 1 ) {
     466            if (role.length() > 1) {
    466467                items.add(role);
    467468            }
     
    497498        Object answer = optionPane.getValue();
    498499        if (answer == null || answer == JOptionPane.UNINITIALIZED_VALUE
    499                 || (answer instanceof Integer && (Integer)answer != JOptionPane.OK_OPTION))
     500                || (answer instanceof Integer && (Integer) answer != JOptionPane.OK_OPTION))
    500501            return null;
    501502
     
    506507        @Override
    507508        public void mouseClicked(MouseEvent e) {
    508             if (e.isControlDown() || !(e.getComponent() instanceof JComboBox ) ) // do not use left click handler on combo box
    509                 if (SwingUtilities.isLeftMouseButton(e) && chosenRelation.get() != null && Main.main.getEditLayer() != null) {
    510                     Main.main.getEditLayer().data.setSelected(chosenRelation.get());
     509            if (e.isControlDown() || !(e.getComponent() instanceof JComboBox)) // do not use left click handler on combo box
     510                if (SwingUtilities.isLeftMouseButton(e) && chosenRelation.get() != null && Main.getLayerManager().getEditLayer() != null) {
     511                    Main.getLayerManager().getEditLayer().data.setSelected(chosenRelation.get());
    511512                }
    512513        }
     
    530531
    531532    private class ChosenRelationPopupMenu extends JPopupMenu {
    532         public ChosenRelationPopupMenu(ChosenRelation chosenRelation) {
     533        ChosenRelationPopupMenu(ChosenRelation chosenRelation) {
    533534            add(new SelectMembersAction(chosenRelation));
    534535            add(new SelectRelationAction(chosenRelation));
     
    545546
    546547    protected void applyRoleToSelection(String role) {
    547         if (chosenRelation != null && chosenRelation.get() != null && Main.main.getCurrentDataSet() != null && !Main.main.getCurrentDataSet().selectionEmpty()) {
    548             Collection<OsmPrimitive> selected = Main.main.getCurrentDataSet().getSelected();
     548        if (chosenRelation != null && chosenRelation.get() != null
     549                && Main.getLayerManager().getEditDataSet() != null && !Main.getLayerManager().getEditDataSet().selectionEmpty()) {
     550            Collection<OsmPrimitive> selected = Main.getLayerManager().getEditDataSet().getSelected();
    549551            Relation r = chosenRelation.get();
    550552            List<Command> commands = new ArrayList<>();
     
    553555                if (selected.contains(m.getMember())) {
    554556                    if (!role.equals(m.getRole())) {
    555                         //                        r.setMember(i, new RelationMember(role, m.getMember()));
    556557                        commands.add(new ChangeRelationMemberRoleCommand(r, i, role));
    557558                    }
     
    576577        }
    577578    }
    578     /*
    579     private class MultipolygonSettingsAction extends AbstractAction {
    580         public MultipolygonSettingsAction() {
    581             super();
    582             putValue(SMALL_ICON, ImageProvider.get("svpRight"));
    583             putValue(SHORT_DESCRIPTION, tr("Change multipolygon creation settings"));
    584         }
    585 
    586         public void actionPerformed(ActionEvent e) {
    587             Component c = e.getSource() instanceof Component ? (Component)e.getSource() : Main.parent;
    588             multiPopupMenu.show(c, 0, 0);
    589         }
    590     }*/
    591579
    592580    private class MultipolygonSettingsPopup extends JPopupMenu implements ActionListener {
    593         public MultipolygonSettingsPopup() {
    594             super();
     581        MultipolygonSettingsPopup() {
    595582            addMenuItem("boundary", tr("Create administrative boundary relations"));
    596583            addMenuItem("boundaryways", tr("Add tags boundary and admin_level to boundary relation ways"));
     
    614601            String property = e.getActionCommand();
    615602            if (property != null && property.length() > 0 && e.getSource() instanceof JCheckBoxMenuItem) {
    616                 boolean value = ((JCheckBoxMenuItem)e.getSource()).isSelected();
     603                boolean value = ((JCheckBoxMenuItem) e.getSource()).isSelected();
    617604                Main.pref.put(property, value);
    618605                show(getInvoker(), getX(), getY());
     
    623610    private class EnterRoleAction extends JosmAction implements ChosenRelationListener {
    624611
    625         public EnterRoleAction() {
    626             super(tr("Change role"), (String)null, tr("Enter role for selected members"),
     612        EnterRoleAction() {
     613            super(tr("Change role"), (String) null, tr("Enter role for selected members"),
    627614                    Shortcut.registerShortcut("reltoolbox:changerole", tr("Relation Toolbox: {0}", tr("Enter role for selected members")),
    628615                            KeyEvent.VK_R, Shortcut.ALT_CTRL), false, "relcontext/enterrole", true);
     
    635622            if (roleBoxModel.membersRole != null) {
    636623                String role = askForRoleName();
    637                 if (role != null ) {
     624                if (role != null) {
    638625                    applyRoleToSelection(role);
    639626                }
     
    655642        private final String ANOTHER_ROLE = tr("another...");
    656643
    657         public RoleComboBoxModel(JComboBox<String> combobox) {
     644        RoleComboBoxModel(JComboBox<String> combobox) {
    658645            super();
    659646            this.combobox = combobox;
     
    664651            membersRole = getSelectedMembersRoleIntl();
    665652            if (membersRole == null) {
    666                 if (combobox.isEnabled() ) {
     653                if (combobox.isEnabled()) {
    667654                    combobox.setEnabled(false);
    668655                }
    669656                return;
    670657            }
    671             if (!combobox.isEnabled() ) {
     658            if (!combobox.isEnabled()) {
    672659                combobox.setEnabled(true);
    673660            }
     
    681668                if (chosenRelation.get().get("type") != null) {
    682669                    List<String> values = possibleRoles.get(chosenRelation.get().get("type"));
    683                     if (values != null ) {
     670                    if (values != null) {
    684671                        items.addAll(values);
    685672                    }
    686673                }
    687                 for (RelationMember m : chosenRelation.get().getMembers() )
    688                     if (m.getRole().length() > 0 && !items.contains(m.getRole()) ) {
     674                for (RelationMember m : chosenRelation.get().getMembers()) {
     675                    if (m.getRole().length() > 0 && !items.contains(m.getRole())) {
    689676                        items.add(m.getRole());
    690677                    }
     678                }
    691679            }
    692680            items.add(EMPTY_ROLE);
    693             if (!items.contains(membersRole) ) {
     681            if (!items.contains(membersRole)) {
    694682                items.add(0, membersRole);
    695683            }
     
    697685            roles = Collections.unmodifiableList(items);
    698686
    699             if (membersRole != null ) {
     687            if (membersRole != null) {
    700688                setSelectedItem(membersRole);
    701689            } else {
     
    715703        private String getSelectedMembersRoleIntl() {
    716704            String role = null;
    717             if (chosenRelation != null && chosenRelation.get() != null && Main.main.getCurrentDataSet() != null && !Main.main.getCurrentDataSet().selectionEmpty()) {
    718                 Collection<OsmPrimitive> selected = Main.main.getCurrentDataSet().getSelected();
     705            if (chosenRelation != null && chosenRelation.get() != null
     706                    && Main.getLayerManager().getEditDataSet() != null && !Main.getLayerManager().getEditDataSet().selectionEmpty()) {
     707                Collection<OsmPrimitive> selected = Main.getLayerManager().getEditDataSet().getSelected();
    719708                for (RelationMember m : chosenRelation.get().getMembers()) {
    720709                    if (selected.contains(m.getMember())) {
    721                         if (role == null ) {
     710                        if (role == null) {
    722711                            role = m.getRole();
    723712                        } else if (m.getRole() != null && !role.equals(m.getRole())) {
  • applications/editors/josm/plugins/reltoolbox/src/relcontext/actions/AddRemoveMemberAction.java

    r32395 r32398  
    1313import org.openstreetmap.josm.command.ChangeCommand;
    1414import org.openstreetmap.josm.command.Command;
     15import org.openstreetmap.josm.data.osm.DataSet;
    1516import org.openstreetmap.josm.data.osm.Node;
    1617import org.openstreetmap.josm.data.osm.OsmPrimitive;
     
    4950    @Override
    5051    public void actionPerformed(ActionEvent e) {
    51         if (rel.get() == null )
     52        if (rel.get() == null)
    5253            return;
    5354
    5455        Relation r = new Relation(rel.get());
    5556
    56         Collection<OsmPrimitive> toAdd = new ArrayList<>(getCurrentDataSet().getSelected());
     57        Collection<OsmPrimitive> toAdd = new ArrayList<>(getLayerManager().getEditDataSet().getSelected());
    5758        toAdd.remove(rel.get());
    5859        toAdd.removeAll(r.getMemberPrimitives());
     
    6263
    6364        // 1. remove all present members
    64         r.removeMembersFor(getCurrentDataSet().getSelected());
     65        r.removeMembersFor(getLayerManager().getEditDataSet().getSelected());
    6566
    6667        // 2. add all new members
    6768        for (OsmPrimitive p : toAdd) {
    6869            int pos = -1; //p instanceof Way ? findAdjacentMember(p, r) : -1;
    69             if (pos < 0 ) {
     70            if (pos < 0) {
    7071                r.addMember(new RelationMember("", p));
    7172            } else {
     
    7677        // 3. check for roles again (temporary)
    7778        Command roleFix = !isBroken && sortAndFix.needsFixing(r) ? sortAndFix.fixRelation(r) : null;
    78         if (roleFix != null ) {
     79        if (roleFix != null) {
    7980            roleFix.executeCommand();
    8081        }
    8182
    82         if (!r.getMemberPrimitives().equals(rel.get().getMemberPrimitives()) ) {
     83        if (!r.getMemberPrimitives().equals(rel.get().getMemberPrimitives())) {
    8384            Main.main.undoRedo.add(new ChangeCommand(rel.get(), r));
    8485        }
     
    9697            for (int i = 0; i < r.getMembersCount(); i++) {
    9798                if (r.getMember(i).getType().equals(OsmPrimitiveType.WAY)) {
    98                     Way rw = (Way)r.getMember(i).getMember();
     99                    Way rw = (Way) r.getMember(i).getMember();
    99100                    Node firstNodeR = rw.firstNode();
    100101                    Node lastNodeR = rw.lastNode();
    101                     if (firstNode.equals(firstNodeR) || firstNode.equals(lastNodeR) || lastNode.equals(firstNodeR) || lastNode.equals(lastNodeR) )
     102                    if (firstNode.equals(firstNodeR) || firstNode.equals(lastNodeR) || lastNode.equals(firstNodeR) || lastNode.equals(lastNodeR))
    102103                        return i + 1;
    103104                }
     
    114115    @Override
    115116    protected void updateEnabledState() {
    116         updateEnabledState(getCurrentDataSet() == null ? null : getCurrentDataSet().getSelected());
     117        updateEnabledState(getLayerManager().getEditDataSet() == null ? null : getLayerManager().getEditDataSet().getSelected());
    117118    }
    118119
     
    134135        // todo: change icon based on selection
    135136        final int state; // 0=unknown, 1=add, 2=remove, 3=both
    136         if (getCurrentDataSet() == null || getCurrentDataSet().getSelected() == null
    137                 || getCurrentDataSet().getSelected().isEmpty() || rel == null || rel.get() == null ) {
     137        DataSet ds = getLayerManager().getEditDataSet();
     138        if (ds == null || ds.getSelected() == null
     139                || ds.getSelected().isEmpty() || rel == null || rel.get() == null) {
    138140            state = 0;
    139141        } else {
    140             Collection<OsmPrimitive> toAdd = new ArrayList<>(getCurrentDataSet().getSelected());
     142            Collection<OsmPrimitive> toAdd = new ArrayList<>(ds.getSelected());
    141143            toAdd.remove(rel.get());
    142144            int selectedSize = toAdd.size();
    143             if (selectedSize == 0 ) {
     145            if (selectedSize == 0) {
    144146                state = 0;
    145147            } else {
    146148                toAdd.removeAll(rel.get().getMemberPrimitives());
    147                 if (toAdd.isEmpty() ) {
     149                if (toAdd.isEmpty()) {
    148150                    state = 2;
    149                 } else if (toAdd.size() < selectedSize ) {
     151                } else if (toAdd.size() < selectedSize) {
    150152                    state = 3;
    151153                } else {
     
    157159            @Override
    158160            public void run() {
    159                 //        String name = state == 0 ? "?" : state == 1 ? "+" : state == 2 ? "-" : "±";
    160                 //        putValue(Action.NAME, name);
    161161                if (state == 0) {
    162                     //            putValue(NAME, "?");
    163162                    putValue(LARGE_ICON_KEY, ImageProvider.get("relcontext", "addremove"));
    164163                } else {
  • applications/editors/josm/plugins/reltoolbox/src/relcontext/actions/CreateMultipolygonAction.java

    r32395 r32398  
    3333import org.openstreetmap.josm.command.Command;
    3434import org.openstreetmap.josm.command.SequenceCommand;
     35import org.openstreetmap.josm.data.osm.DataSet;
    3536import org.openstreetmap.josm.data.osm.MultipolygonBuilder;
    3637import org.openstreetmap.josm.data.osm.Node;
     
    6869
    6970    public static boolean getDefaultPropertyValue(String property) {
    70         if (property.equals("boundary") )
     71        if (property.equals("boundary"))
    7172            return false;
    72         else if (property.equals("boundaryways") )
     73        else if (property.equals("boundaryways"))
    7374            return true;
    74         else if (property.equals("tags") )
     75        else if (property.equals("tags"))
    7576            return true;
    76         else if (property.equals("alltags") )
     77        else if (property.equals("alltags"))
    7778            return false;
    78         else if (property.equals("single") )
     79        else if (property.equals("single"))
    7980            return true;
    80         else if (property.equals("allowsplit") )
     81        else if (property.equals("allowsplit"))
    8182            return false;
    8283        throw new IllegalArgumentException(property);
     
    9091    public void actionPerformed(ActionEvent e) {
    9192        boolean isBoundary = getPref("boundary");
    92         Collection<Way> selectedWays = getCurrentDataSet().getSelectedWays();
     93        DataSet ds = getLayerManager().getEditDataSet();
     94        Collection<Way> selectedWays = ds.getSelectedWays();
    9395        if (!isBoundary && getPref("tags")) {
    9496            List<Relation> rels = null;
    9597            if (getPref("allowsplit") || selectedWays.size() == 1) {
    96                 if (SplittingMultipolygons.canProcess(selectedWays) ) {
    97                     rels = SplittingMultipolygons.process(getCurrentDataSet().getSelectedWays());
     98                if (SplittingMultipolygons.canProcess(selectedWays)) {
     99                    rels = SplittingMultipolygons.process(ds.getSelectedWays());
    98100                }
    99101            } else {
    100102                if (TheRing.areAllOfThoseRings(selectedWays)) {
    101103                    List<Command> commands = new ArrayList<>();
    102                     rels = TheRing.makeManySimpleMultipolygons(getCurrentDataSet().getSelectedWays(), commands);
    103                     if (!commands.isEmpty() ) {
     104                    rels = TheRing.makeManySimpleMultipolygons(ds.getSelectedWays(), commands);
     105                    if (!commands.isEmpty()) {
    104106                        Main.main.undoRedo.add(new SequenceCommand(tr("Create multipolygons from rings"), commands));
    105107                    }
     
    107109            }
    108110            if (rels != null && !rels.isEmpty()) {
    109                 if (chRel != null ) {
     111                if (chRel != null) {
    110112                    chRel.set(rels.size() == 1 ? rels.get(0) : null);
    111113                }
    112                 if (rels.size() == 1 ) {
    113                     getCurrentDataSet().setSelected(rels);
     114                if (rels.size() == 1) {
     115                    ds.setSelected(rels);
    114116                } else {
    115                     getCurrentDataSet().clearSelection();
     117                    ds.clearSelection();
    116118                }
    117119                return;
     
    121123        // for now, just copying standard action
    122124        MultipolygonBuilder mpc = new MultipolygonBuilder();
    123         String error = mpc.makeFromWays(getCurrentDataSet().getSelectedWays());
     125        String error = mpc.makeFromWays(getLayerManager().getEditDataSet().getSelectedWays());
    124126        if (error != null) {
    125127            JOptionPane.showMessageDialog(Main.parent, error);
     
    133135            rel.put("type", "multipolygon");
    134136        }
    135         for (MultipolygonBuilder.JoinedPolygon poly : mpc.outerWays ) {
    136             for (Way w : poly.ways ) {
     137        for (MultipolygonBuilder.JoinedPolygon poly : mpc.outerWays) {
     138            for (Way w : poly.ways) {
    137139                rel.addMember(new RelationMember("outer", w));
    138140            }
    139141        }
    140         for (MultipolygonBuilder.JoinedPolygon poly : mpc.innerWays ) {
    141             for (Way w : poly.ways ) {
     142        for (MultipolygonBuilder.JoinedPolygon poly : mpc.innerWays) {
     143            for (Way w : poly.ways) {
    142144                rel.addMember(new RelationMember("inner", w));
    143145            }
     
    149151        }
    150152        if (isBoundary) {
    151             if (!askForAdminLevelAndName(rel) )
     153            if (!askForAdminLevelAndName(rel))
    152154                return;
    153155            addBoundaryMembers(rel);
    154             if (getPref("boundaryways") ) {
     156            if (getPref("boundaryways")) {
    155157                list.addAll(fixWayTagsForBoundary(rel));
    156158            }
     
    159161        Main.main.undoRedo.add(new SequenceCommand(tr("Create multipolygon"), list));
    160162
    161         if (chRel != null ) {
     163        if (chRel != null) {
    162164            chRel.set(rel);
    163165        }
    164166
    165         getCurrentDataSet().setSelected(rel);
     167        getLayerManager().getEditDataSet().setSelected(rel);
    166168    }
    167169
    168170    @Override
    169171    protected void updateEnabledState() {
    170         if (getCurrentDataSet() == null) {
     172        if (getLayerManager().getEditDataSet() == null) {
    171173            setEnabled(false);
    172174        } else {
    173             updateEnabledState(getCurrentDataSet().getSelected());
     175            updateEnabledState(getLayerManager().getEditDataSet().getSelected());
    174176        }
    175177    }
     
    178180    protected void updateEnabledState(Collection<? extends OsmPrimitive> selection) {
    179181        boolean isEnabled = true;
    180         if (selection == null || selection.isEmpty() ) {
     182        if (selection == null || selection.isEmpty()) {
    181183            isEnabled = false;
    182184        } else {
     
    197199     */
    198200    private void addBoundaryMembers(Relation rel) {
    199         for (OsmPrimitive p : getCurrentDataSet().getSelected()) {
     201        for (OsmPrimitive p : getLayerManager().getEditDataSet().getSelected()) {
    200202            String role = null;
    201203            if (p.getType().equals(OsmPrimitiveType.RELATION)) {
    202204                role = "subarea";
    203205            } else if (p.getType().equals(OsmPrimitiveType.NODE)) {
    204                 Node n = (Node)p;
     206                Node n = (Node) p;
    205207                if (!n.isIncomplete()) {
    206                     if (n.hasKey("place") ) {
     208                    if (n.hasKey("place")) {
    207209                        role = "admin_centre";
    208210                    } else {
     
    211213                }
    212214            }
    213             if (role != null ) {
     215            if (role != null) {
    214216                rel.addMember(new RelationMember(role, p));
    215217            }
     
    222224    private List<Command> fixWayTagsForBoundary(Relation rel) {
    223225        List<Command> commands = new ArrayList<>();
    224         if (!rel.hasKey("boundary") || !rel.hasKey("admin_level") )
     226        if (!rel.hasKey("boundary") || !rel.hasKey("admin_level"))
    225227            return commands;
    226228        String adminLevelStr = rel.get("admin_level");
     
    228230        try {
    229231            adminLevel = Integer.parseInt(adminLevelStr);
    230         } catch(NumberFormatException e) {
     232        } catch (NumberFormatException e) {
    231233            return commands;
    232234        }
     
    236238            if (p instanceof Way) {
    237239                int count = 0;
    238                 if (p.hasKey("boundary") && p.get("boundary").equals("administrative") ) {
     240                if (p.hasKey("boundary") && p.get("boundary").equals("administrative")) {
    239241                    count++;
    240242                }
    241                 if (p.hasKey("admin_level") ) {
     243                if (p.hasKey("admin_level")) {
    242244                    count++;
    243245                }
    244246                if (p.keySet().size() - count == 0) {
    245                     if (!p.hasKey("boundary") ) {
     247                    if (!p.hasKey("boundary")) {
    246248                        waysBoundary.add(p);
    247249                    }
     
    251253                        try {
    252254                            int oldAdminLevel = Integer.parseInt(p.get("admin_level"));
    253                             if (oldAdminLevel > adminLevel ) {
     255                            if (oldAdminLevel > adminLevel) {
    254256                                waysAdminLevel.add(p);
    255257                            }
    256                         } catch(NumberFormatException e) {
     258                        } catch (NumberFormatException e) {
    257259                            waysAdminLevel.add(p); // some garbage, replace it
    258260                        }
     
    261263            }
    262264        }
    263         if (!waysBoundary.isEmpty() ) {
     265        if (!waysBoundary.isEmpty()) {
    264266            commands.add(new ChangePropertyCommand(waysBoundary, "boundary", "administrative"));
    265267        }
    266         if (!waysAdminLevel.isEmpty() ) {
     268        if (!waysAdminLevel.isEmpty()) {
    267269            commands.add(new ChangePropertyCommand(waysAdminLevel, "admin_level", adminLevelStr));
    268270        }
    269271        return commands;
    270272    }
    271     static public final List<String> DEFAULT_LINEAR_TAGS = Arrays.asList(new String[] {"barrier", "source"});
     273
     274    public static final List<String> DEFAULT_LINEAR_TAGS = Arrays.asList(new String[] {"barrier", "source"});
     275
    272276    private static final Set<String> REMOVE_FROM_BOUNDARY_TAGS = new TreeSet<>(Arrays.asList(new String[] {
    273277            "boundary", "boundary_type", "type", "admin_level"
     
    314318        // filter out empty key conflicts - we need second iteration
    315319        boolean isBoundary = getPref("boundary");
    316         if (isBoundary || !getPref("alltags") ) {
    317             for (RelationMember m : relation.getMembers() )
    318                 if (m.hasRole() && m.getRole().equals("outer") && m.isWay() ) {
    319                     for (String key : values.keySet() )
    320                         if (!m.getWay().hasKey(key) && !relation.hasKey(key) ) {
     320        if (isBoundary || !getPref("alltags")) {
     321            for (RelationMember m : relation.getMembers()) {
     322                if (m.hasRole() && m.getRole().equals("outer") && m.isWay()) {
     323                    for (String key : values.keySet()) {
     324                        if (!m.getWay().hasKey(key) && !relation.hasKey(key)) {
    321325                            conflictingKeys.add(key);
    322326                        }
    323                 }
    324         }
    325 
    326         for (String key : conflictingKeys ) {
     327                    }
     328                }
     329            }
     330        }
     331
     332        for (String key : conflictingKeys) {
    327333            values.remove(key);
    328334        }
    329335
    330         for (String linearTag : Main.pref.getCollection(PREF_MULTIPOLY + "lineartags", DEFAULT_LINEAR_TAGS) ) {
     336        for (String linearTag : Main.pref.getCollection(PREF_MULTIPOLY + "lineartags", DEFAULT_LINEAR_TAGS)) {
    331337            values.remove(linearTag);
    332338        }
    333339
    334         if (values.containsKey("natural") && values.get("natural").equals("coastline") ) {
     340        if (values.containsKey("natural") && values.get("natural").equals("coastline")) {
    335341            values.remove("natural");
    336342        }
     
    339345        if (isBoundary) {
    340346            Set<String> keySet = new TreeSet<>(values.keySet());
    341             for (String key : keySet )
    342                 if (!REMOVE_FROM_BOUNDARY_TAGS.contains(key) ) {
     347            for (String key : keySet) {
     348                if (!REMOVE_FROM_BOUNDARY_TAGS.contains(key)) {
    343349                    values.remove(key);
    344350                }
     351            }
    345352        }
    346353
     
    376383        if (moveTags) {
    377384            // add those tag values to the relation
    378             if (isBoundary ) {
     385            if (isBoundary) {
    379386                values.put("name", name);
    380387            }
     
    384391                if (!r2.hasKey(key) && !key.equals("area")
    385392                        && (!isBoundary || key.equals("admin_level") || key.equals("name"))) {
    386                     if (relation.isNew() ) {
     393                    if (relation.isNew()) {
    387394                        relation.put(key, values.get(key));
    388395                    } else {
     
    392399                }
    393400            }
    394             if (fixed && !relation.isNew() ) {
     401            if (fixed && !relation.isNew()) {
    395402                commands.add(new ChangeCommand(relation, r2));
    396403            }
     
    402409    /**
    403410     *
    404      * @param rel
     411     * @param rel relation
    405412     * @return false if user pressed "cancel".
    406413     */
     
    408415        String relAL = rel.get("admin_level");
    409416        String relName = rel.get("name");
    410         if (relAL != null && relName != null )
     417        if (relAL != null && relName != null)
    411418            return true;
    412419
     
    421428
    422429        final JTextField name = new JTextField();
    423         if (relName != null ) {
     430        if (relName != null) {
    424431            name.setText(relName);
    425432        }
     
    450457        Object answer = optionPane.getValue();
    451458        if (answer == null || answer == JOptionPane.UNINITIALIZED_VALUE
    452                 || (answer instanceof Integer && (Integer)answer != JOptionPane.OK_OPTION))
     459                || (answer instanceof Integer && (Integer) answer != JOptionPane.OK_OPTION))
    453460            return false;
    454461
     
    459466            Main.pref.put(PREF_MULTIPOLY + "lastadmin", admin_level);
    460467        }
    461         if (new_name.length() > 0 ) {
     468        if (new_name.length() > 0) {
    462469            rel.put("name", new_name);
    463470        }
  • applications/editors/josm/plugins/reltoolbox/src/relcontext/actions/CreateRelationAction.java

    r32395 r32398  
    5656    public void actionPerformed(ActionEvent e) {
    5757        String type = askForType();
    58         if (type == null )
     58        if (type == null)
    5959            return;
    6060
    6161        Relation rel = new Relation();
    62         if (type.length() > 0 ) {
     62        if (type.length() > 0) {
    6363            rel.put("type", type);
    6464        }
    65         for (OsmPrimitive selected : getCurrentDataSet().getSelected() ) {
     65        for (OsmPrimitive selected : getLayerManager().getEditDataSet().getSelected()) {
    6666            rel.addMember(new RelationMember("", selected));
    6767        }
     
    7676    @Override
    7777    protected void updateEnabledState() {
    78         if (getCurrentDataSet() == null) {
     78        if (getLayerManager().getEditDataSet() == null) {
    7979            setEnabled(false);
    8080        } else {
    81             updateEnabledState(getCurrentDataSet().getSelected());
     81            updateEnabledState(getLayerManager().getEditDataSet().getSelected());
    8282        }
    8383    }
     
    130130        Object answer = optionPane.getValue();
    131131        if (answer == null || answer == JOptionPane.UNINITIALIZED_VALUE
    132                 || (answer instanceof Integer && (Integer)answer != JOptionPane.OK_OPTION))
     132                || (answer instanceof Integer && (Integer) answer != JOptionPane.OK_OPTION))
    133133            return null;
    134134
  • applications/editors/josm/plugins/reltoolbox/src/relcontext/actions/DeleteChosenRelationAction.java

    r32395 r32398  
    3333        Relation r = rel.get();
    3434        rel.clear();
    35         Command c = DeleteCommand.delete(Main.main.getEditLayer(), Collections.singleton(r), true, true);
    36         if (c != null ) {
     35        Command c = DeleteCommand.delete(Main.getLayerManager().getEditLayer(), Collections.singleton(r), true, true);
     36        if (c != null) {
    3737            Main.main.undoRedo.add(c);
    3838        }
  • applications/editors/josm/plugins/reltoolbox/src/relcontext/actions/DownloadChosenRelationAction.java

    r32395 r32398  
    3131
    3232    public DownloadChosenRelationAction(ChosenRelation rel) {
    33         super();
    34         //        putValue(NAME, "D");
    3533        putValue(SMALL_ICON, ImageProvider.get("relcontext", "download"));
    3634        putValue(SHORT_DESCRIPTION, tr("Download incomplete members for the chosen relation"));
     
    4341    public void actionPerformed(ActionEvent e) {
    4442        Relation relation = rel.get();
    45         if (relation == null || relation.isNew() ) return;
     43        if (relation == null || relation.isNew()) return;
    4644        int total = relation.getMembersCount();
    4745        int incomplete = relation.getIncompleteMembers().size();
    48         //        if (incomplete <= 5 || (incomplete <= 10 && incomplete * 3 < total) )
    49         if (incomplete <= 10 && incomplete * 3 < total ) {
     46        if (incomplete <= 10 && incomplete * 3 < total) {
    5047            downloadIncomplete(relation);
    5148        } else {
     
    7067    protected void downloadMembers(Relation rel) {
    7168        if (!rel.isNew()) {
    72             Main.worker.submit(new DownloadRelationTask(Collections.singletonList(rel), Main.main.getEditLayer()));
     69            Main.worker.submit(new DownloadRelationTask(Collections.singletonList(rel), Main.getLayerManager().getEditLayer()));
    7370        }
    7471    }
    7572
    7673    protected void downloadIncomplete(Relation rel) {
    77         if (rel.isNew() ) return;
     74        if (rel.isNew()) return;
    7875        Set<OsmPrimitive> ret = new HashSet<>();
    7976        ret.addAll(rel.getIncompleteMembers());
    80         if (ret.isEmpty() ) return;
    81         Main.worker.submit(new DownloadRelationMemberTask(Collections.singletonList(rel), ret, Main.main.getEditLayer()));
     77        if (ret.isEmpty()) return;
     78        Main.worker.submit(new DownloadRelationMemberTask(Collections.singletonList(rel), ret, Main.getLayerManager().getEditLayer()));
    8279    }
    8380}
  • applications/editors/josm/plugins/reltoolbox/src/relcontext/actions/DownloadParentsAction.java

    r32395 r32398  
    3838        this.rel = rel;
    3939        rel.addChosenRelationListener(this);
    40         setEnabled(rel.get() != null && Main.main.getEditLayer() != null);
     40        setEnabled(rel.get() != null && Main.getLayerManager().getEditLayer() != null);
    4141    }
    4242
     
    4444    public void actionPerformed(ActionEvent e) {
    4545        Relation relation = rel.get();
    46         if (relation == null ) return;
     46        if (relation == null) return;
    4747        List<OsmPrimitive> objects = new ArrayList<>();
    4848        objects.add(relation);
    4949        objects.addAll(relation.getMemberPrimitives());
    50         Main.worker.submit(new DownloadReferrersTask(Main.main.getEditLayer(), objects));
     50        Main.worker.submit(new DownloadReferrersTask(Main.getLayerManager().getEditLayer(), objects));
    5151    }
    5252
    5353    @Override
    5454    public void chosenRelationChanged(Relation oldRelation, Relation newRelation) {
    55         setEnabled(newRelation != null && Main.main.getEditLayer() != null);
     55        setEnabled(newRelation != null && Main.getLayerManager().getEditLayer() != null);
    5656    }
    5757
    5858    protected void downloadMembers(Relation rel) {
    5959        if (!rel.isNew()) {
    60             Main.worker.submit(new DownloadRelationTask(Collections.singletonList(rel), Main.main.getEditLayer()));
     60            Main.worker.submit(new DownloadRelationTask(Collections.singletonList(rel), Main.getLayerManager().getEditLayer()));
    6161        }
    6262    }
    6363
    6464    protected void downloadIncomplete(Relation rel) {
    65         if (rel.isNew() ) return;
     65        if (rel.isNew()) return;
    6666        Set<OsmPrimitive> ret = new HashSet<>();
    6767        ret.addAll(rel.getIncompleteMembers());
    68         if (ret.isEmpty() ) return;
    69         Main.worker.submit(new DownloadRelationMemberTask(Collections.singletonList(rel), ret, Main.main.getEditLayer()));
     68        if (ret.isEmpty()) return;
     69        Main.worker.submit(new DownloadRelationMemberTask(Collections.singletonList(rel), ret, Main.getLayerManager().getEditLayer()));
    7070    }
    7171}
  • applications/editors/josm/plugins/reltoolbox/src/relcontext/actions/DuplicateChosenRelationAction.java

    r32395 r32398  
    3434        Main.main.undoRedo.add(new AddCommand(copy));
    3535        rel.set(copy);
    36         if (Main.main.getCurrentDataSet() != null ) {
    37             Main.main.getCurrentDataSet().setSelected(copy);
     36        if (Main.getLayerManager().getEditDataSet() != null) {
     37            Main.getLayerManager().getEditDataSet().setSelected(copy);
    3838        }
    3939    }
  • applications/editors/josm/plugins/reltoolbox/src/relcontext/actions/EditChosenRelationAction.java

    r32395 r32398  
    2525
    2626    public EditChosenRelationAction(ChosenRelation rel) {
    27         super();
    28         //        putValue(NAME, "E");
    2927        putValue(SMALL_ICON, ImageProvider.get("dialogs/mappaint", "pencil"));
    3028        putValue(SHORT_DESCRIPTION, tr("Open relation editor for the chosen relation"));
     
    3735    public void actionPerformed(ActionEvent e) {
    3836        Relation relation = rel.get();
    39         if (relation == null ) return;
    40         RelationEditor.getEditor(Main.main.getEditLayer(), relation, null).setVisible(true);
     37        if (relation == null) return;
     38        RelationEditor.getEditor(Main.getLayerManager().getEditLayer(), relation, null).setVisible(true);
    4139    }
    4240
  • applications/editors/josm/plugins/reltoolbox/src/relcontext/actions/FindRelationAction.java

    r32395 r32398  
    6363        relationsList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    6464        relationsList.setCellRenderer(new OsmPrimitivRenderer());
    65         panel.add(new JScrollPane(relationsList, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER), BorderLayout.CENTER);
     65        panel.add(new JScrollPane(relationsList,
     66                JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER), BorderLayout.CENTER);
    6667        panel.setPreferredSize(new Dimension(400, 400));
    6768
     
    108109            @Override
    109110            public void keyPressed(KeyEvent e) {
    110                 if (shouldForward(e) ) {
     111                if (shouldForward(e)) {
    111112                    relationsList.dispatchEvent(e);
    112113                }
     
    115116            @Override
    116117            public void keyReleased(KeyEvent e) {
    117                 if (shouldForward(e) ) {
     118                if (shouldForward(e)) {
    118119                    relationsList.dispatchEvent(e);
    119120                }
     
    132133        Object answer = optionPane.getValue();
    133134        if (answer == null || answer == JOptionPane.UNINITIALIZED_VALUE
    134                 || (answer instanceof Integer && (Integer)answer != JOptionPane.OK_OPTION))
     135                || (answer instanceof Integer && (Integer) answer != JOptionPane.OK_OPTION))
    135136            return;
    136137
    137138        Relation r = relationsList.getSelectedValue();
    138         if (r != null ) {
     139        if (r != null) {
    139140            chRel.set(r);
    140141        }
     
    143144    @Override
    144145    protected void updateEnabledState() {
    145         setEnabled(getCurrentDataSet() != null);
     146        setEnabled(getLayerManager().getEditDataSet() != null);
    146147    }
    147148
     
    150151        if (keywords.length > 0) {
    151152            List<String> filteredKeywords = new ArrayList<>(keywords.length);
    152             for (String s : keywords )
    153                 if (s.length() > 0 ) {
     153            for (String s : keywords) {
     154                if (s.length() > 0) {
    154155                    filteredKeywords.add(s.trim().toLowerCase());
    155156                }
     157            }
    156158            keywords = filteredKeywords.toArray(new String[0]);
    157159        }
    158160
    159         System.out.println("keywords.length = " + keywords.length);
    160         for (int i = 0; i < keywords.length; i++ ) {
    161             System.out.println("keyword["+i+"] = " + keywords[i]);
     161        if (Main.isDebugEnabled()) {
     162            Main.debug("keywords.length = " + keywords.length);
     163            for (int i = 0; i < keywords.length; i++) {
     164                Main.debug("keyword["+i+"] = " + keywords[i]);
     165            }
    162166        }
    163167
    164168        List<Relation> relations = new ArrayList<>();
    165         if (getEditLayer() != null) {
    166             for (Relation r : getEditLayer().data.getRelations()) {
     169        if (getLayerManager().getEditLayer() != null) {
     170            for (Relation r : getLayerManager().getEditLayer().data.getRelations()) {
    167171                if (!r.isDeleted() && r.isVisible() && !r.isIncomplete()) {
    168172                    boolean add = true;
    169173                    for (int i = 0; i < keywords.length && add; i++) {
    170174                        boolean ok = false;
    171                         if (String.valueOf(r.getPrimitiveId().getUniqueId()).contains(keywords[i]) ) {
     175                        if (String.valueOf(r.getPrimitiveId().getUniqueId()).contains(keywords[i])) {
    172176                            ok = true;
    173177                        } else {
     
    180184                            }
    181185                        }
    182                         if (!ok ) {
     186                        if (!ok) {
    183187                            add = false;
    184188                        }
    185189                    }
    186                     if (add ) {
     190                    if (add) {
    187191                        relations.add(r);
    188192                    }
     
    227231        public void setRelations(Collection<Relation> relations) {
    228232            int selectedIndex = selectionModel.getMinSelectionIndex();
    229             Relation sel =  selectedIndex < 0 ? null : getElementAt(selectedIndex);
     233            Relation sel = selectedIndex < 0 ? null : getElementAt(selectedIndex);
    230234
    231235            this.relations.clear();
    232236            selectionModel.clearSelection();
    233             if (relations != null ) {
     237            if (relations != null) {
    234238                this.relations.addAll(relations);
    235239            }
     
    238242            if (sel != null) {
    239243                selectedIndex = this.relations.indexOf(sel);
    240                 if (selectedIndex >= 0 ) {
     244                if (selectedIndex >= 0) {
    241245                    selectionModel.addSelectionInterval(selectedIndex, selectedIndex);
    242246                }
    243247            }
    244             if (selectionModel.isSelectionEmpty() && !this.relations.isEmpty() ) {
     248            if (selectionModel.isSelectionEmpty() && !this.relations.isEmpty()) {
    245249                selectionModel.addSelectionInterval(0, 0);
    246250            }
  • applications/editors/josm/plugins/reltoolbox/src/relcontext/actions/PublicTransportHelper.java

    r32395 r32398  
    77
    88/**
     9 * @author freeExec
    910 * @see http://wiki.openstreetmap.org/wiki/Key:public_transport
    10  */
    11 
    12 /**
    13  *
    14  * @author freeExec
    1511 */
    1612public final class PublicTransportHelper {
    1713
    18     public final static String PUBLIC_TRANSPORT = "public_transport";
    19     public final static String STOP_POSITION = "stop_position";
    20     public final static String STOP = "stop";
    21     public final static String STOP_AREA = "stop_area";
    22     public final static String PLATFORM = "platform";
    23     public final static String HIGHWAY = "highway";
    24     public final static String RAILWAY = "railway";
    25     public final static String BUS_STOP = "bus_stop";
    26     public final static String RAILWAY_HALT = "halt";
    27     public final static String RAILWAY_STATION = "station";
     14    public static final String PUBLIC_TRANSPORT = "public_transport";
     15    public static final String STOP_POSITION = "stop_position";
     16    public static final String STOP = "stop";
     17    public static final String STOP_AREA = "stop_area";
     18    public static final String PLATFORM = "platform";
     19    public static final String HIGHWAY = "highway";
     20    public static final String RAILWAY = "railway";
     21    public static final String BUS_STOP = "bus_stop";
     22    public static final String RAILWAY_HALT = "halt";
     23    public static final String RAILWAY_STATION = "station";
    2824
    2925    private PublicTransportHelper() {
     
    5450                String pt = p.get(PUBLIC_TRANSPORT);
    5551                if (STOP_POSITION.equals(pt)) return true;
    56             }
    57             else if (p.hasKey(RAILWAY)) {
     52            } else if (p.hasKey(RAILWAY)) {
    5853                String rw = p.get(RAILWAY);
    5954                if (RAILWAY_HALT.equals(rw) || RAILWAY_STATION.equals(rw)) return true;
     
    8378        return false;
    8479    }
     80
    8581    public static boolean isWayPlatform(RelationMember m) {
    8682        return isWayPlatform(m.getMember());
     
    121117        if (result != null) return result;
    122118        // try to get name by stop_area
    123         for (OsmPrimitive refOp : prim.getReferrers())
     119        for (OsmPrimitive refOp : prim.getReferrers()) {
    124120            if (refOp.getType() == OsmPrimitiveType.RELATION
    125             && refOp.hasTag(PUBLIC_TRANSPORT, STOP_AREA)) {
     121                    && refOp.hasTag(PUBLIC_TRANSPORT, STOP_AREA)) {
    126122                result = refOp.getName();
    127123                if (result != null) return result;
    128124            }
     125        }
    129126        return result;
    130127    }
  • applications/editors/josm/plugins/reltoolbox/src/relcontext/actions/ReconstructPolygonAction.java

    r32395 r32398  
    6060        boolean wont = false;
    6161        for (RelationMember m : r.getMembers()) {
    62             if (m.isWay() ) {
     62            if (m.isWay()) {
    6363                ways.add(m.getWay());
    6464            } else {
     
    6767        }
    6868        if (wont) {
    69             JOptionPane.showMessageDialog(Main.parent, tr("Multipolygon must consist only of ways"), tr("Reconstruct polygon"), JOptionPane.ERROR_MESSAGE);
     69            JOptionPane.showMessageDialog(Main.parent,
     70                    tr("Multipolygon must consist only of ways"), tr("Reconstruct polygon"), JOptionPane.ERROR_MESSAGE);
    7071            return;
    7172        }
     
    7980
    8081        if (!mpc.innerWays.isEmpty()) {
    81             JOptionPane.showMessageDialog(Main.parent, tr("Reconstruction of polygons can be done only from outer ways"), tr("Reconstruct polygon"), JOptionPane.ERROR_MESSAGE);
     82            JOptionPane.showMessageDialog(Main.parent,
     83                    tr("Reconstruction of polygons can be done only from outer ways"), tr("Reconstruct polygon"), JOptionPane.ERROR_MESSAGE);
    8284            return;
    8385        }
     
    8688        List<Way> newSelection = new ArrayList<>();
    8789        List<Command> commands = new ArrayList<>();
    88         Command c = DeleteCommand.delete(Main.main.getEditLayer(), Collections.singleton(r), true, true);
    89         if (c == null )
     90        Command c = DeleteCommand.delete(Main.getLayerManager().getEditLayer(), Collections.singleton(r), true, true);
     91        if (c == null)
    9092            return;
    9193        commands.add(c);
     
    106108                }
    107109                List<OsmPrimitive> referrers = w.getReferrers();
    108                 for (Iterator<OsmPrimitive> ref1 = relations.iterator(); ref1.hasNext(); )
    109                     if (!referrers.contains(ref1.next()) ) {
     110                for (Iterator<OsmPrimitive> ref1 = relations.iterator(); ref1.hasNext();) {
     111                    if (!referrers.contains(ref1.next())) {
    110112                        ref1.remove();
    111113                    }
     114                }
    112115            }
    113116            tags.putAll(r.getKeys());
     
    123126                    keys.removeAll(IRRELEVANT_KEYS);
    124127                    if (keys.isEmpty()) {
    125                         if (candidateWay == null ) {
     128                        if (candidateWay == null) {
    126129                            candidateWay = w;
    127130                        } else {
     
    149152        Main.main.undoRedo.add(new SequenceCommand(tr("Reconstruct polygons from relation {0}",
    150153                r.getDisplayName(DefaultNameFormatter.getInstance())), commands));
    151         Main.main.getCurrentDataSet().setSelected(newSelection);
     154        Main.getLayerManager().getEditDataSet().setSelected(newSelection);
    152155    }
    153156
     
    158161
    159162    private boolean isSuitableRelation(Relation newRelation) {
    160         if (newRelation == null || !"multipolygon".equals(newRelation.get("type")) || newRelation.getMembersCount() == 0 )
     163        if (newRelation == null || !"multipolygon".equals(newRelation.get("type")) || newRelation.getMembersCount() == 0)
    161164            return false;
    162165        else {
    163             for (RelationMember m : newRelation.getMembers() )
    164                 if ("inner".equals(m.getRole()) )
     166            for (RelationMember m : newRelation.getMembers()) {
     167                if ("inner".equals(m.getRole()))
    165168                    return false;
     169            }
    166170            return true;
    167171        }
  • applications/editors/josm/plugins/reltoolbox/src/relcontext/actions/ReconstructRouteAction.java

    r32395 r32398  
    3333 * @author freeExec
    3434 */
    35 public class ReconstructRouteAction  extends AbstractAction implements ChosenRelationListener {
     35public class ReconstructRouteAction extends AbstractAction implements ChosenRelationListener {
    3636    private final ChosenRelation rel;
    3737
    38     public ReconstructRouteAction (ChosenRelation rel) {
     38    public ReconstructRouteAction(ChosenRelation rel) {
    3939        super(tr("Reconstruct route"));
    4040        putValue(SMALL_ICON, ImageProvider.get("dialogs", "filter"));
     
    6565                                m.getMember());
    6666                stopMembers.put(rm.getMember(), rm);
    67             }
    68             else if (PublicTransportHelper.isMemberPlatform(m)) {
     67            } else if (PublicTransportHelper.isMemberPlatform(m)) {
    6968                RelationMember rm = new RelationMember(
    7069                        m.hasRole() ? m.getRole() : PublicTransportHelper.PLATFORM,
     
    8180                    platformMembers.put(platformName, nList);
    8281                }
    83             }
    84             else if (PublicTransportHelper.isMemberRouteway(m)) {
     82            } else if (PublicTransportHelper.isMemberRouteway(m)) {
    8583                routeMembers.add(new RelationMember(m));
    8684            } else {
     
    9391        Node lastNode = null;
    9492        for (int rIndex = 0; rIndex < routeMembers.size(); rIndex++) {
    95             Way w = (Way)routeMembers.get(rIndex).getMember();
     93            Way w = (Way) routeMembers.get(rIndex).getMember();
    9694            boolean dirForward = false;
    9795            if (lastNode == null) { // first segment
    9896                if (routeMembers.size() > 2) {
    99                     Way nextWay = (Way)routeMembers.get(rIndex + 1).getMember();
     97                    Way nextWay = (Way) routeMembers.get(rIndex + 1).getMember();
    10098                    if (w.lastNode().equals(nextWay.lastNode()) || w.lastNode().equals(nextWay.firstNode())) {
    10199                        dirForward = true;
     
    106104                } // else one segment - direction unknown
    107105            } else {
    108                 if (lastNode.equals(w.firstNode())) { dirForward = true; lastNode = w.lastNode(); } else {
     106                if (lastNode.equals(w.firstNode())) {
     107                    dirForward = true; lastNode = w.lastNode();
     108                } else {
    109109                    lastNode = w.firstNode();
    110110                }
     
    126126                        }
    127127                        boolean existsPlatform = platformMembers.containsKey(stopName);
    128                         if (!existsPlatform) { stopName = ""; } // find of the nameless
     128                        if (!existsPlatform) {
     129                            stopName = ""; // find of the nameless
     130                        }
    129131                        if (existsPlatform || platformMembers.containsKey(stopName)) {
    130132                            List<RelationMember> lMember = platformMembers.get(stopName);
     
    153155            String stopName = PublicTransportHelper.getNameViaStoparea(stop);
    154156            boolean existsPlatform = platformMembers.containsKey(stopName);
    155             if (!existsPlatform) { stopName = ""; } // find of the nameless
     157            if (!existsPlatform) {
     158                stopName = ""; // find of the nameless
     159            }
    156160            if (existsPlatform || platformMembers.containsKey(stopName)) {
    157161                List<RelationMember> lMember = platformMembers.get(stopName);
     
    224228    }
    225229
    226     private boolean isSuitableRelation (Relation newRelation) {
     230    private boolean isSuitableRelation(Relation newRelation) {
    227231        return !(newRelation == null || !"route".equals(newRelation.get("type")) || newRelation.getMembersCount() == 0);
    228232    }
  • applications/editors/josm/plugins/reltoolbox/src/relcontext/actions/RelationHelpAction.java

    r32395 r32398  
    4545    @Override
    4646    public void actionPerformed(ActionEvent e) {
    47         if (rel.get() == null )
     47        if (rel.get() == null)
    4848            return;
    4949        try {
     
    6161            uris.add(new URI(String.format("%sRelations", base)));
    6262
    63             Main.worker.execute(new Runnable(){
     63            Main.worker.execute(new Runnable() {
    6464                @Override
    6565                public void run() {
  • applications/editors/josm/plugins/reltoolbox/src/relcontext/actions/SelectMembersAction.java

    r32395 r32398  
    2828    @Override
    2929    public void actionPerformed(ActionEvent e) {
    30         Main.main.getEditLayer().data.setSelected(rel.get() == null ? null : rel.get().getMemberPrimitives());
     30        Main.getLayerManager().getEditLayer().data.setSelected(rel.get() == null ? null : rel.get().getMemberPrimitives());
    3131    }
    3232
  • applications/editors/josm/plugins/reltoolbox/src/relcontext/actions/SelectRelationAction.java

    r32395 r32398  
    2929    @Override
    3030    public void actionPerformed(ActionEvent e) {
    31         Main.main.getEditLayer().data.setSelected(rel.get() == null ? null : rel.get());
     31        Main.getLayerManager().getEditLayer().data.setSelected(rel.get() == null ? null : rel.get());
    3232    }
    3333
  • applications/editors/josm/plugins/reltoolbox/src/relcontext/actions/SortAndFixAction.java

    r32395 r32398  
    5656    public void actionPerformed(ActionEvent e) {
    5757        Command c = fixRelation(rel.get());
    58         if (c != null ) {
     58        if (c != null) {
    5959            Main.main.undoRedo.add(c);
    6060        }
     
    7171
    7272    private RelationFixer getFixer(Relation rel) {
    73         for (RelationFixer fixer : fixers)
     73        for (RelationFixer fixer : fixers) {
    7474            if (fixer.isFixerApplicable(rel))
    7575                return fixer;
     76        }
    7677        return new NothingFixer();
    7778    }
     
    8283
    8384    protected static boolean isIncomplete(Relation r) {
    84         if (r == null || r.isIncomplete() || r.isDeleted() )
     85        if (r == null || r.isIncomplete() || r.isDeleted())
    8586            return true;
    86         for (RelationMember m : r.getMembers())
    87             if (m.getMember().isIncomplete() )
     87        for (RelationMember m : r.getMembers()) {
     88            if (m.getMember().isIncomplete())
    8889                return true;
     90        }
    8991        return false;
    9092    }
    91 
    9293}
  • applications/editors/josm/plugins/reltoolbox/src/relcontext/actions/SplittingMultipolygons.java

    r32395 r32398  
    3333 * @author Zverik
    3434 */
    35 public class SplittingMultipolygons {
     35public final class SplittingMultipolygons {
    3636    private static final String PREF_MULTIPOLY = "reltoolbox.multipolygon.";
     37
     38    private SplittingMultipolygons() {
     39        // Hide default constructor for utilities classes
     40    }
    3741
    3842    public static boolean canProcess(Collection<Way> ways) {
    3943        List<Way> rings = new ArrayList<>();
    4044        List<Way> arcs = new ArrayList<>();
    41         Area a = Main.main.getCurrentDataSet().getDataSourceArea();
     45        Area a = Main.getLayerManager().getEditDataSet().getDataSourceArea();
    4246        for (Way way : ways) {
    43             if (way.isDeleted() )
     47            if (way.isDeleted())
    4448                return false;
    4549            for (Node n : way.getNodes()) {
    4650                LatLon ll = n.getCoor();
    47                 if (n.isIncomplete() || (a != null && !a.contains(ll.getX(), ll.getY())) )
     51                if (n.isIncomplete() || (a != null && !a.contains(ll.getX(), ll.getY())))
    4852                    return false;
    4953            }
    50             if (way.isClosed() ) {
     54            if (way.isClosed()) {
    5155                rings.add(way);
    5256            } else {
     
    5963            for (Way segment : arcs) {
    6064                boolean found = false;
    61                 for (Way ring : rings )
    62                     if (ring.containsNode(segment.firstNode()) && ring.containsNode(segment.lastNode()) ) {
     65                for (Way ring : rings) {
     66                    if (ring.containsNode(segment.firstNode()) && ring.containsNode(segment.lastNode())) {
    6367                        found = true;
    6468                    }
    65                 if (!found )
     69                }
     70                if (!found)
    6671                    return false;
    6772            }
    6873        }
    6974
    70         if (rings.isEmpty() && arcs.isEmpty() )
     75        if (rings.isEmpty() && arcs.isEmpty())
    7176            return false;
    7277
     
    7580            for (int j = i + 1; j < rings.size(); j++) {
    7681                PolygonIntersection intersection = Geometry.polygonIntersection(rings.get(i).getNodes(), rings.get(j).getNodes());
    77                 if (intersection == PolygonIntersection.FIRST_INSIDE_SECOND || intersection == PolygonIntersection.SECOND_INSIDE_FIRST )
     82                if (intersection == PolygonIntersection.FIRST_INSIDE_SECOND || intersection == PolygonIntersection.SECOND_INSIDE_FIRST)
    7883                    return false;
    7984            }
     
    8489
    8590    public static List<Relation> process(Collection<Way> selectedWays) {
    86         //    System.out.println("---------------------------------------");
    8791        List<Relation> result = new ArrayList<>();
    8892        List<Way> rings = new ArrayList<>();
    8993        List<Way> arcs = new ArrayList<>();
    9094        for (Way way : selectedWays) {
    91             if (way.isClosed() ) {
     95            if (way.isClosed()) {
    9296                rings.add(way);
    9397            } else {
     
    148152    public static List<Way> splitWay(Way w, Node n1, Node n2, List<Command> commands) {
    149153        List<Node> nodes = new ArrayList<>(w.getNodes());
    150         if (w.isClosed() ) {
     154        if (w.isClosed()) {
    151155            nodes.remove(nodes.size() - 1);
    152156        }
     
    159163        }
    160164        // right now index2 >= index1
    161         if (index2 < 1 || index1 >= w.getNodesCount() - 1 || index2 >= w.getNodesCount() )
     165        if (index2 < 1 || index1 >= w.getNodesCount() - 1 || index2 >= w.getNodesCount())
    162166            return Collections.emptyList();
    163         if (w.isClosed() && (index1 < 0 || index1 == index2 || index1 + w.getNodesCount() == index2) )
     167        if (w.isClosed() && (index1 < 0 || index1 == index2 || index1 + w.getNodesCount() == index2))
    164168            return Collections.emptyList();
    165169
     
    183187            chunks.get(chunks.size() - 1).addAll(chunks.get(0));
    184188            chunks.remove(0);
    185         } else if (chunks.get(chunks.size() - 1).size() < 2 ) {
     189        } else if (chunks.get(chunks.size() - 1).size() < 2) {
    186190            chunks.remove(chunks.size() - 1);
    187191        }
    188 
    189         // todo remove debug: show chunks array contents
    190         /*for (List<Node> c1 : chunks) {
    191     for (Node cn1 : c1 )
    192     System.out.print(cn1.getId() + ",");
    193     System.out.println();
    194     }*/
    195192
    196193        // build a map of referencing relations
     
    199196        for (OsmPrimitive p : w.getReferrers()) {
    200197            if (p instanceof Relation) {
    201                 Relation rel = commands == null ? (Relation)p : new Relation((Relation)p);
    202                 if (commands != null ) {
     198                Relation rel = commands == null ? (Relation) p : new Relation((Relation) p);
     199                if (commands != null) {
    203200                    relationCommands.add(new ChangeCommand(p, rel));
    204201                }
    205                 for (int i = 0; i < rel.getMembersCount(); i++ )
    206                     if (rel.getMember(i).getMember().equals(w) ) {
     202                for (int i = 0; i < rel.getMembersCount(); i++) {
     203                    if (rel.getMember(i).getMember().equals(w)) {
    207204                        references.put(rel, Integer.valueOf(i));
    208205                    }
     206                }
    209207            }
    210208        }
     
    229227            }
    230228            newWay.setNodes(achunk);
    231             if (commands != null ) {
     229            if (commands != null) {
    232230                commands.add(new AddCommand(newWay));
    233231            }
    234232        }
    235         if (commands != null ) {
     233        if (commands != null) {
    236234            commands.addAll(relationCommands);
    237235        }
     
    247245     */
    248246    public static Relation tryToCloseOneWay(Way segment, List<Command> resultingCommands) {
    249         if (segment.isClosed() || segment.isIncomplete() )
     247        if (segment.isClosed() || segment.isIncomplete())
    250248            return null;
    251249
     
    256254        for (Iterator<Way> iter = ways.iterator(); iter.hasNext();) {
    257255            boolean save = false;
    258             for (OsmPrimitive ref : iter.next().getReferrers() )
    259                 if (ref instanceof Relation && ((Relation)ref).isMultipolygon() && !ref.isDeleted() ) {
     256            for (OsmPrimitive ref : iter.next().getReferrers()) {
     257                if (ref instanceof Relation && ((Relation) ref).isMultipolygon() && !ref.isDeleted()) {
    260258                    save = true;
    261259                }
    262             if (!save ) {
     260            }
     261            if (!save) {
    263262                iter.remove();
    264263            }
    265264        }
    266         if (ways.isEmpty() )
     265        if (ways.isEmpty())
    267266            return null; // well...
    268267        Way target = ways.get(0);
     
    283282            }
    284283        }
    285         if (changed ) {
     284        if (changed) {
    286285            commands.add(new ChangeCommand(segment, segmentCopy));
    287286        }
     
    318317    private static <T> List<T> intersection(Collection<T> list1, Collection<T> list2) {
    319318        List<T> result = new ArrayList<>();
    320         for (T item : list1 )
    321             if (list2.contains(item) ) {
     319        for (T item : list1) {
     320            if (list2.contains(item)) {
    322321                result.add(item);
    323322            }
     323        }
    324324        return result;
    325325    }
     
    329329     */
    330330    public static Relation attachRingToNeighbours(Way ring, List<Command> resultingCommands) {
    331         if (!ring.isClosed() || ring.isIncomplete() )
     331        if (!ring.isClosed() || ring.isIncomplete())
    332332            return null;
    333333        Map<Way, Boolean> touchingWays = new HashMap<>();
     
    336336                if (p instanceof Way && !p.equals(ring)) {
    337337                    for (OsmPrimitive r : p.getReferrers()) {
    338                         if (r instanceof Relation && ((Relation)r).hasKey("type") && ((Relation)r).get("type").equals("multipolygon")) {
    339                             if (touchingWays.containsKey(p) ) {
    340                                 touchingWays.put((Way)p, Boolean.TRUE);
     338                        if (r instanceof Relation && ((Relation) r).hasKey("type") && ((Relation) r).get("type").equals("multipolygon")) {
     339                            if (touchingWays.containsKey(p)) {
     340                                touchingWays.put((Way) p, Boolean.TRUE);
    341341                            } else {
    342                                 touchingWays.put((Way)p, Boolean.FALSE);
     342                                touchingWays.put((Way) p, Boolean.FALSE);
    343343                            }
    344344                            break;
     
    350350
    351351        List<TheRing> otherWays = new ArrayList<>();
    352         for (Way w : touchingWays.keySet() )
     352        for (Way w : touchingWays.keySet()) {
    353353            if (touchingWays.get(w)) {
    354354                otherWays.add(new TheRing(w));
    355                 //        System.out.println("Touching ring: " + otherWays.get(otherWays.size()-1));
    356             }
    357 
    358         //    for (Iterator<Way> keys = touchingWays.keySet().iterator(); keys.hasNext();) {
    359         //        if (!touchingWays.get(keys.next()) )
    360         //        keys.remove();
    361         //    }
     355            }
     356        }
    362357
    363358        // now touchingWays has only ways that touch the ring twice
     
    365360        TheRing theRing = new TheRing(ring); // this is actually useful
    366361
    367         for (TheRing otherRing : otherWays ) {
     362        for (TheRing otherRing : otherWays) {
    368363            theRing.collide(otherRing);
    369364        }
    370365
    371366        theRing.putSourceWayFirst();
    372         for (TheRing otherRing : otherWays ) {
     367        for (TheRing otherRing : otherWays) {
    373368            otherRing.putSourceWayFirst();
    374369        }
    375370
    376371        Map<Relation, Relation> relationCache = new HashMap<>();
    377         for (TheRing otherRing : otherWays ) {
     372        for (TheRing otherRing : otherWays) {
    378373            commands.addAll(otherRing.getCommands(false, relationCache));
    379374        }
  • applications/editors/josm/plugins/reltoolbox/src/relcontext/actions/TheRing.java

    r32395 r32398  
    11// License: GPL. For details, see LICENSE file.
    22package relcontext.actions;
     3
     4import static org.openstreetmap.josm.tools.I18n.tr;
    35
    46import java.util.ArrayList;
     
    4547        List<Way> rings = new ArrayList<>();
    4648        for (Way way : ways) {
    47             if (way.isClosed() ) {
     49            if (way.isClosed()) {
    4850                rings.add(way);
    4951            } else
    5052                return false;
    5153        }
    52         if (rings.isEmpty() || ways.size() == 1 )
     54        if (rings.isEmpty() || ways.size() == 1)
    5355            return false;
    5456
     
    5759            for (int j = i + 1; j < rings.size(); j++) {
    5860                PolygonIntersection intersection = Geometry.polygonIntersection(rings.get(i).getNodes(), rings.get(j).getNodes());
    59                 if (intersection == PolygonIntersection.FIRST_INSIDE_SECOND || intersection == PolygonIntersection.SECOND_INSIDE_FIRST )
     61                if (intersection == PolygonIntersection.FIRST_INSIDE_SECOND || intersection == PolygonIntersection.SECOND_INSIDE_FIRST)
    6062                    return false;
    6163            }
     
    7274        log("---------------------------------------");
    7375        List<TheRing> rings = new ArrayList<>(selection.size());
    74         for (Way w : selection ) {
     76        for (Way w : selection) {
    7577            rings.add(new TheRing(w));
    7678        }
    77         for (int i = 0; i < rings.size() - 1; i++ ) {
    78             for (int j = i + 1; j < rings.size(); j++ ) {
     79        for (int i = 0; i < rings.size() - 1; i++) {
     80            for (int j = i + 1; j < rings.size(); j++) {
    7981                rings.get(i).collide(rings.get(j));
    8082            }
     
    108110                            RingSegment segment = splitRingAt(i, split[0], split[1]);
    109111                            RingSegment otherSegment = other.splitRingAt(j, split[2], split[3]);
    110                             if (!areSegmentsEqual(segment, otherSegment) )
    111                                 throw new IllegalArgumentException("Error: algorithm gave incorrect segments: " + segment + " and " + otherSegment);
     112                            if (!areSegmentsEqual(segment, otherSegment))
     113                                throw new IllegalArgumentException(
     114                                        "Error: algorithm gave incorrect segments: " + segment + " and " + otherSegment);
    112115                            segment.makeReference(otherSegment);
    113116                        }
    114117                    }
    115                     if (segment1.isReference() ) {
     118                    if (segment1.isReference()) {
    116119                        break;
    117120                    }
     
    126129    public static Node[] getSplitNodes(List<Node> nodes1, List<Node> nodes2, boolean isRing1, boolean isRing2) {
    127130        int pos = 0;
    128         while(pos < nodes1.size() && !nodes2.contains(nodes1.get(pos)) ) {
     131        while (pos < nodes1.size() && !nodes2.contains(nodes1.get(pos))) {
    129132            pos++;
    130133        }
     
    133136            // rewind a bit
    134137            pos = nodes1.size() - 1;
    135             while(pos > 0 && nodes2.contains(nodes1.get(pos)) ) {
     138            while (pos > 0 && nodes2.contains(nodes1.get(pos))) {
    136139                pos--;
    137140            }
    138141            if (pos == 0 && nodes1.size() == nodes2.size()) {
    139                 JOptionPane.showMessageDialog(Main.parent, "Two rings are equal, and this must not be.", "Multipolygon from rings", JOptionPane.ERROR_MESSAGE);
     142                JOptionPane.showMessageDialog(Main.parent,
     143                        tr("Two rings are equal, and this must not be."), tr("Multipolygon from rings"), JOptionPane.ERROR_MESSAGE);
    140144                return null;
    141145            }
     
    143147        }
    144148        int firstPos = isRing1 ? pos : nodes1.size();
    145         while(!collideFound) {
     149        while (!collideFound) {
    146150            log("pos=" + pos);
    147151            int start1 = pos;
     
    152156            if (last1 >= 0) {
    153157                last2 = incrementBy(start2, -1, nodes2.size(), isRing2);
    154                 if (last2 >= 0 && nodes1.get(last1).equals(nodes2.get(last2)) ) {
     158                if (last2 >= 0 && nodes1.get(last1).equals(nodes2.get(last2))) {
    155159                    increment2 = -1;
    156160                } else {
    157161                    last2 = incrementBy(start2, 1, nodes2.size(), isRing2);
    158                     if (last2 >= 0 && nodes1.get(last1).equals(nodes2.get(last2)) ) {
     162                    if (last2 >= 0 && nodes1.get(last1).equals(nodes2.get(last2))) {
    159163                        increment2 = 1;
    160164                    }
     
    165169                // find the first nodes
    166170                boolean reachedEnd = false;
    167                 while(!reachedEnd) {
     171                while (!reachedEnd) {
    168172                    int newLast1 = incrementBy(last1, 1, nodes1.size(), isRing1);
    169173                    int newLast2 = incrementBy(last2, increment2, nodes2.size(), isRing2);
    170                     if (newLast1 < 0 || newLast2 < 0 || !nodes1.get(newLast1).equals(nodes2.get(newLast2)) ) {
     174                    if (newLast1 < 0 || newLast2 < 0 || !nodes1.get(newLast1).equals(nodes2.get(newLast2))) {
    171175                        reachedEnd = true;
    172176                    } else {
     
    184188            } else {
    185189                pos = last1;
    186                 while(pos != firstPos && pos >= 0 && !nodes2.contains(nodes1.get(pos)) ) {
     190                while (pos != firstPos && pos >= 0 && !nodes2.contains(nodes1.get(pos))) {
    187191                    pos = incrementBy(pos, 1, nodes1.size(), isRing1);
    188192                }
    189                 if (pos < 0 || pos == firstPos || !nodes2.contains(nodes1.get(pos)) ) {
     193                if (pos < 0 || pos == firstPos || !nodes2.contains(nodes1.get(pos))) {
    190194                    collideFound = true;
    191195                }
     
    197201    private static int incrementBy(int value, int increment, int limit1, boolean isRing) {
    198202        int result = value + increment;
    199         if (result < 0 )
     203        if (result < 0)
    200204            return isRing ? result + limit1 : -1;
    201         else if (result >= limit1 )
     205        else if (result >= limit1)
    202206            return isRing ? result - limit1 : -1;
    203207        else
     
    209213        List<Node> nodes2 = seg2.getNodes();
    210214        int size = nodes1.size();
    211         if (size != nodes2.size() )
     215        if (size != nodes2.size())
    212216            return false;
    213217        boolean reverse = size > 1 && !nodes1.get(0).equals(nodes2.get(0));
    214         for (int i = 0; i < size; i++ )
    215             if (!nodes1.get(i).equals(nodes2.get(reverse ? size-1-i : i)) )
     218        for (int i = 0; i < size; i++) {
     219            if (!nodes1.get(i).equals(nodes2.get(reverse ? size-1-i : i)))
    216220                return false;
     221        }
    217222        return true;
    218223    }
     
    223228     */
    224229    private RingSegment splitRingAt(int segmentIndex, Node n1, Node n2) {
    225         if (n1.equals(n2) )
     230        if (n1.equals(n2))
    226231            throw new IllegalArgumentException("Both nodes are equal, id=" + n1.getUniqueId());
    227232        RingSegment segment = segments.get(segmentIndex);
     
    242247        // if thirdPart == null, then n2 == lastNode
    243248        int pos = segmentIndex + 1;
    244         if (secondPart != null ) {
     249        if (secondPart != null) {
    245250            segments.add(pos++, secondPart);
    246251        }
    247         if (thirdPart != null ) {
     252        if (thirdPart != null) {
    248253            segments.add(pos++, thirdPart);
    249254        }
     
    260265        // build segments map
    261266        Map<RingSegment, TheRing> segmentMap = new HashMap<>();
    262         for (TheRing ring : rings ) {
    263             for (RingSegment seg : ring.segments )
    264                 if (!seg.isReference() ) {
     267        for (TheRing ring : rings) {
     268            for (RingSegment seg : ring.segments) {
     269                if (!seg.isReference()) {
    265270                    segmentMap.put(seg, ring);
    266271                }
     272            }
    267273        }
    268274
     
    283289
    284290        // initializing source way for each ring
    285         for (TheRing ring : rings ) {
     291        for (TheRing ring : rings) {
    286292            ring.putSourceWayFirst();
    287293        }
     
    290296    private int countNonReferenceSegments() {
    291297        int count = 0;
    292         for (RingSegment seg : segments )
    293             if (!seg.isReference() ) {
     298        for (RingSegment seg : segments) {
     299            if (!seg.isReference()) {
    294300                count++;
    295301            }
     302        }
    296303        return count;
    297304    }
     
    325332            relation.put("type", "multipolygon");
    326333            for (String key : sourceCopy.keySet()) {
    327                 if (linearTags.contains(key) ) {
     334                if (linearTags.contains(key)) {
    328335                    continue;
    329336                }
    330                 if (key.equals("natural") && sourceCopy.get("natural").equals("coastline") ) {
     337                if (key.equals("natural") && sourceCopy.get("natural").equals("coastline")) {
    331338                    continue;
    332339                }
     
    343350                Relation rel = null;
    344351                if (relationChangeMap != null) {
    345                     if (relationChangeMap.containsKey(p) ) {
     352                    if (relationChangeMap.containsKey(p)) {
    346353                        rel = relationChangeMap.get(p);
    347354                    } else {
    348                         rel = new Relation((Relation)p);
    349                         relationChangeMap.put((Relation)p, rel);
     355                        rel = new Relation((Relation) p);
     356                        relationChangeMap.put((Relation) p, rel);
    350357                    }
    351358                } else {
    352                     rel = new Relation((Relation)p);
     359                    rel = new Relation((Relation) p);
    353360                    relationCommands.add(new ChangeCommand(p, rel));
    354361                }
    355                 for (int i = 0; i < rel.getMembersCount(); i++ )
    356                     if (rel.getMember(i).getMember().equals(source) ) {
     362                for (int i = 0; i < rel.getMembersCount(); i++) {
     363                    if (rel.getMember(i).getMember().equals(source)) {
    357364                        referencingRelations.put(rel, Integer.valueOf(i));
    358365                    }
    359             }
    360         }
    361         // todo: когда два кольца менÑ�ÑŽÑ‚ одно и то же отношение, в Ñ�пиÑ�ок команд добавлÑ�етÑ�Ñ�
    362         // изменение базового отношениÑ� на новое, а не предыдущего
    363         // поÑ�тому Ñ�охранÑ�етÑ�Ñ� только первое изменение
     366                }
     367            }
     368        }
    364369
    365370        List<Command> commands = new ArrayList<>();
     
    368373            boolean needAdding = !seg.isWayConstructed();
    369374            Way w = seg.constructWay(seg.isReference() ? null : sourceCopy);
    370             if (needAdding ) {
     375            if (needAdding) {
    371376                commands.add(new AddCommand(w));
    372377            }
     
    383388                }
    384389            }
    385             if (createMultipolygon ) {
     390            if (createMultipolygon) {
    386391                relation.addMember(new RelationMember("outer", w));
    387392            }
    388393        }
    389         if (!foundOwnWay ) {
     394        if (!foundOwnWay) {
    390395            commands.add(new DeleteCommand(source));
    391396        }
    392397        commands.addAll(relationCommands);
    393         if (createMultipolygon ) {
     398        if (createMultipolygon) {
    394399            commands.add(new AddCommand(relation));
    395400        }
     
    398403
    399404    public static void updateCommandsWithRelations(List<Command> commands, Map<Relation, Relation> relationCache) {
    400         for (Relation src : relationCache.keySet() ) {
     405        for (Relation src : relationCache.keySet()) {
    401406            commands.add(new ChangeCommand(src, relationCache.get(src)));
    402407        }
     
    414419        StringBuilder sb = new StringBuilder("TheRing@");
    415420        sb.append(this.hashCode()).append('[').append("wayId: ").append(source == null ? "null" : source.getUniqueId()).append("; segments: ");
    416         if (segments.isEmpty() ) {
     421        if (segments.isEmpty()) {
    417422            sb.append("empty");
    418423        } else {
    419424            sb.append(segments.get(0));
    420             for (int i = 1; i < segments.size(); i++ ) {
     425            for (int i = 1; i < segments.size(); i++) {
    421426                sb.append(", ").append(segments.get(i));
    422427            }
     
    425430    }
    426431
    427     /**
    428      * Appends "append" to "base" so the closed polygon forms.
    429      */
    430     /*private static void closePolygon(List<Node> base, List<Node> append) {
    431     if (append.get(0).equals(base.get(0)) && append.get(append.size() - 1).equals(base.get(base.size() - 1))) {
    432         List<Node> ap2 = new ArrayList<Node>(append);
    433         Collections.reverse(ap2);
    434         append = ap2;
    435     }
    436     base.remove(base.size() - 1);
    437     base.addAll(append);
    438     }*/
    439 
    440     /**
    441      * Checks if a middle point between two nodes is inside a polygon. Useful to check if the way is inside.
    442      */
    443     /*private static boolean segmentInsidePolygon(Node n1, Node n2, List<Node> polygon) {
    444     EastNorth en1 = n1.getEastNorth();
    445     EastNorth en2 = n2.getEastNorth();
    446     Node testNode = new Node(new EastNorth((en1.east() + en2.east()) / 2.0, (en1.north() + en2.north()) / 2.0));
    447     return Geometry.nodeInsidePolygon(testNode, polygon);
    448     }*/
    449 
    450432    private static void log(String s) {
    451         //    System.out.println(s);
     433        Main.debug(s);
    452434    }
    453435
     
    459441        private boolean isRing;
    460442
    461         /*private RingSegment() {
    462     }*/
    463 
    464         public RingSegment(Way w) {
     443        RingSegment(Way w) {
    465444            this(w.getNodes());
    466445        }
    467446
    468         public RingSegment(List<Node> nodes) {
     447        RingSegment(List<Node> nodes) {
    469448            this.nodes = nodes;
    470449            isRing = nodes.size() > 1 && nodes.get(0).equals(nodes.get(nodes.size() - 1));
    471             if (isRing ) {
     450            if (isRing) {
    472451                nodes.remove(nodes.size() - 1);
    473452            }
    474453            references = null;
    475454        }
    476 
    477         /*public RingSegment(RingSegment ref) {
    478         this.nodes = null;
    479         this.references = ref;
    480     }*/
    481455
    482456        /**
     
    487461         */
    488462        public RingSegment split(Node n) {
    489             if (nodes == null )
     463            if (nodes == null)
    490464                throw new IllegalArgumentException("Cannot split segment: it is a reference");
    491465            int pos = nodes.indexOf(n);
    492             if (pos <= 0 || pos >= nodes.size() - 1 )
     466            if (pos <= 0 || pos >= nodes.size() - 1)
    493467                return null;
    494468            List<Node> newNodes = new ArrayList<>(nodes.subList(pos, nodes.size()));
     
    503477         */
    504478        public RingSegment split(Node n1, Node n2) {
    505             if (nodes == null )
     479            if (nodes == null)
    506480                throw new IllegalArgumentException("Cannot split segment: it is a reference");
    507481            if (!isRing) {
    508                 if (n1 == null || nodes.get(0).equals(n1) || nodes.get(nodes.size() - 1).equals(n1) )
     482                if (n1 == null || nodes.get(0).equals(n1) || nodes.get(nodes.size() - 1).equals(n1))
    509483                    return split(n2);
    510                 if (n2 == null || nodes.get(0).equals(n2) || nodes.get(nodes.size() - 1).equals(n2) )
     484                if (n2 == null || nodes.get(0).equals(n2) || nodes.get(nodes.size() - 1).equals(n2))
    511485                    return split(n1);
    512486                throw new IllegalArgumentException("Split for two nodes is called for not-ring: " + this);
     
    514488            int pos1 = nodes.indexOf(n1);
    515489            int pos2 = nodes.indexOf(n2);
    516             if (pos1 == pos2 )
     490            if (pos1 == pos2)
    517491                return null;
    518492
     
    521495                newNodes.addAll(nodes.subList(pos2, nodes.size()));
    522496                newNodes.addAll(nodes.subList(0, pos1 + 1));
    523                 if (pos2 + 1 < nodes.size() ) {
     497                if (pos2 + 1 < nodes.size()) {
    524498                    nodes.subList(pos2 + 1, nodes.size()).clear();
    525499                }
    526                 if (pos1 > 0 ) {
     500                if (pos1 > 0) {
    527501                    nodes.subList(0, pos1).clear();
    528502                }
     
    541515
    542516        public List<Node> getWayNodes() {
    543             if (nodes == null )
     517            if (nodes == null)
    544518                throw new IllegalArgumentException("Won't give you wayNodes: it is a reference");
    545519            List<Node> wayNodes = new ArrayList<>(nodes);
    546             if (isRing ) {
     520            if (isRing) {
    547521                wayNodes.add(wayNodes.get(0));
    548522            }
     
    576550
    577551        public Way constructWay(Way template) {
    578             if (isReference() )
     552            if (isReference())
    579553                return references.constructWay(template);
    580554            if (resultingWay == null) {
     
    590564
    591565        public void overrideWay(Way source) {
    592             if (isReference() ) {
     566            if (isReference()) {
    593567                references.overrideWay(source);
    594568            } else {
     
    598572        }
    599573
    600         /**
    601          * Compares two segments with respect to referencing.
    602          * @return true if ways are equals, or one references another.
    603          */
    604         /*public boolean isReferencingEqual(RingSegment other) {
    605         return this.equals(other) || (other.isReference() && other.references == this) || (isReference() && references == other);
    606     }*/
    607 
    608574        @Override
    609575        public String toString() {
    610576            StringBuilder sb = new StringBuilder("RingSegment@");
    611577            sb.append(this.hashCode()).append('[');
    612             if (isReference() ) {
     578            if (isReference()) {
    613579                sb.append("references ").append(references.hashCode());
    614             } else if (nodes.isEmpty() ) {
     580            } else if (nodes.isEmpty()) {
    615581                sb.append("empty");
    616582            } else {
    617                 if (isRing ) {
     583                if (isRing) {
    618584                    sb.append("ring:");
    619585                }
    620586                sb.append(nodes.get(0).getUniqueId());
    621                 for (int i = 1; i < nodes.size(); i++ ) {
     587                for (int i = 1; i < nodes.size(); i++) {
    622588                    sb.append(',').append(nodes.get(i).getUniqueId());
    623589                }
  • applications/editors/josm/plugins/reltoolbox/src/relcontext/relationfix/AssociatedStreetFixer.java

    r32395 r32398  
    9090                        (way.hasKey("building") || way.hasKey("addr:housenumber"))) {
    9191                    fixed = true;
    92                     rel.setMember(i,  new RelationMember("house", way));
     92                    rel.setMember(i, new RelationMember("house", way));
    9393                }
    9494            } else if (m.isRelation()) {
Note: See TracChangeset for help on using the changeset viewer.