Ignore:
Timestamp:
2010-09-15T18:53:09+02:00 (14 years ago)
Author:
stoecker
Message:

remove tabs

Location:
applications/editors/josm/plugins/multipoly-convert/src/converttomultipoly
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/multipoly-convert/src/converttomultipoly/MultipolyAction.java

    r20416 r23189  
    2727/**
    2828 * Convert an area into an advance multipolygon.
    29  * 
     29 *
    3030 * New relation with type=multipolygon is created for each ways.
    31  * 
     31 *
    3232 * All the tags (except the source tag) will be moved into the relation.
    3333 */
     
    3535public class MultipolyAction extends JosmAction {
    3636
    37         public MultipolyAction() {
    38                 super(tr("Convert to multipolygon"), "multipoly_convert",
    39                                 tr("Convert to multipolygon."), Shortcut.registerShortcut(
    40                                                 "tools:multipolyconv", tr("Tool: {0}",
    41                                                                 tr("Convert to multipolygon")), KeyEvent.VK_M,
    42                                                 Shortcut.GROUP_EDIT, Shortcut.SHIFT_DEFAULT), true);
    43         }
     37    public MultipolyAction() {
     38        super(tr("Convert to multipolygon"), "multipoly_convert",
     39                tr("Convert to multipolygon."), Shortcut.registerShortcut(
     40                        "tools:multipolyconv", tr("Tool: {0}",
     41                                tr("Convert to multipolygon")), KeyEvent.VK_M,
     42                        Shortcut.GROUP_EDIT, Shortcut.SHIFT_DEFAULT), true);
     43    }
    4444
    45         /**
    46         * The action button has been clicked
    47          *
    48         * @param e
    49         *            Action Event
    50         */
    51         public void actionPerformed(ActionEvent e) {
     45    /**
     46    * The action button has been clicked
     47     *
     48    * @param e
     49    *            Action Event
     50    */
     51    public void actionPerformed(ActionEvent e) {
    5252
    53                 // Get all ways in some type=multipolygon relation
    54                 HashSet<OsmPrimitive> relationsInMulti = new HashSet<OsmPrimitive>();
    55                 for (Relation r : Main.main.getCurrentDataSet().getRelations()) {
    56                         if (!r.isUsable())
    57                                 continue;
    58                         if (r.get("type") != "multipolygon")
    59                                 continue;
    60                         for (RelationMember rm : r.getMembers()) {
    61                                 OsmPrimitive m = rm.getMember();
    62                                 if (m instanceof Way) {
    63                                         relationsInMulti.add(m);
    64                                 }
    65                         }
    66                 }
     53        // Get all ways in some type=multipolygon relation
     54        HashSet<OsmPrimitive> relationsInMulti = new HashSet<OsmPrimitive>();
     55        for (Relation r : Main.main.getCurrentDataSet().getRelations()) {
     56            if (!r.isUsable())
     57                continue;
     58            if (r.get("type") != "multipolygon")
     59                continue;
     60            for (RelationMember rm : r.getMembers()) {
     61                OsmPrimitive m = rm.getMember();
     62                if (m instanceof Way) {
     63                    relationsInMulti.add(m);
     64                }
     65            }
     66        }
    6767
    68                 // List of selected ways
    69                 ArrayList<Way> selectedWays = new ArrayList<Way>();
    70                
     68        // List of selected ways
     69        ArrayList<Way> selectedWays = new ArrayList<Way>();
    7170
    72                 // For every selected way
    73                 for (OsmPrimitive osm : Main.main.getCurrentDataSet().getSelected()) {
    74                         if (osm instanceof Way) {
    75                                 Way way = (Way) osm;
    76                                 // Check if way is already in another multipolygon
    77                                 if (relationsInMulti.contains(osm)) {
    78                                         JOptionPane
    79                                                         .showMessageDialog(
    80                                                                         Main.parent,
    81                                                                         tr("One of the selected ways is already part of another multipolygon."));
    82                                         return;
    83                                 }
    8471
    85                                 selectedWays.add(way);
    86                         }
    87                 }
     72        // For every selected way
     73        for (OsmPrimitive osm : Main.main.getCurrentDataSet().getSelected()) {
     74            if (osm instanceof Way) {
     75                Way way = (Way) osm;
     76                // Check if way is already in another multipolygon
     77                if (relationsInMulti.contains(osm)) {
     78                    JOptionPane
     79                            .showMessageDialog(
     80                                    Main.parent,
     81                                    tr("One of the selected ways is already part of another multipolygon."));
     82                    return;
     83                }
    8884
    89                 if (Main.map == null) {
    90                         JOptionPane.showMessageDialog(Main.parent, tr("No data loaded."));
    91                         return;
    92                 }
     85                selectedWays.add(way);
     86            }
     87        }
    9388
    94                 Collection<Command> cmds = new LinkedList<Command>();
    95                 // Add ways to it
    96                 for (int i = 0; i < selectedWays.size(); i++) {
    97                         Way way = selectedWays.get(i);
     89        if (Main.map == null) {
     90            JOptionPane.showMessageDialog(Main.parent, tr("No data loaded."));
     91            return;
     92        }
    9893
    99                         // Create new relation
    100                         Relation rel = new Relation();
    101                         rel.put("type", "multipolygon");
     94        Collection<Command> cmds = new LinkedList<Command>();
     95        // Add ways to it
     96        for (int i = 0; i < selectedWays.size(); i++) {
     97                Way way = selectedWays.get(i);
    10298
    103                         RelationMember rm = new RelationMember("outer", way);
    104                         rel.addMember(rm);
    105                        
    106                         for (Iterator<String> keyi = way.getKeys().keySet().iterator() ; keyi.hasNext() ; ) {
    107                                 String key = keyi.next();
    108                                 rel.put(key, way.get(key));
    109                                 System.out.println(key);
    110                                 if (key.compareTo("source") != 0) {
    111                                         way.remove(key);
    112                                 }
    113                         }
    114                         // Add relation
    115                         cmds.add(new AddCommand(rel));
    116                 }
    117                 // Commit
    118                 Main.main.undoRedo.add(new SequenceCommand(tr("Create multipolygon"), cmds));
    119                 Main.map.repaint();
    120         }
     99                // Create new relation
     100                    Relation rel = new Relation();
     101                    rel.put("type", "multipolygon");
    121102
    122         /** Enable this action only if something is selected */
    123         @Override
    124         protected void updateEnabledState() {
    125                 if (getCurrentDataSet() == null) {
    126                         setEnabled(false);
    127                 } else {
    128                         updateEnabledState(getCurrentDataSet().getSelected());
    129                 }
    130         }
     103            RelationMember rm = new RelationMember("outer", way);
     104            rel.addMember(rm);
    131105
    132         /** Enable this action only if something is selected */
    133         @Override
    134         protected void updateEnabledState(
    135                         Collection<? extends OsmPrimitive> selection) {
    136                 setEnabled(selection != null && !selection.isEmpty());
    137         }
     106            for (Iterator<String> keyi = way.getKeys().keySet().iterator() ; keyi.hasNext() ; ) {
     107                    String key = keyi.next();
     108                    rel.put(key, way.get(key));
     109                    System.out.println(key);
     110                    if (key.compareTo("source") != 0) {
     111                            way.remove(key);
     112                    }
     113            }
     114                    // Add relation
     115                    cmds.add(new AddCommand(rel));
     116        }
     117        // Commit
     118        Main.main.undoRedo.add(new SequenceCommand(tr("Create multipolygon"), cmds));
     119        Main.map.repaint();
     120    }
     121
     122    /** Enable this action only if something is selected */
     123    @Override
     124    protected void updateEnabledState() {
     125        if (getCurrentDataSet() == null) {
     126            setEnabled(false);
     127        } else {
     128            updateEnabledState(getCurrentDataSet().getSelected());
     129        }
     130    }
     131
     132    /** Enable this action only if something is selected */
     133    @Override
     134    protected void updateEnabledState(
     135            Collection<? extends OsmPrimitive> selection) {
     136        setEnabled(selection != null && !selection.isEmpty());
     137    }
    138138}
  • applications/editors/josm/plugins/multipoly-convert/src/converttomultipoly/MultipolyPlugin.java

    r20416 r23189  
    1515public class MultipolyPlugin extends Plugin {
    1616
    17         protected String name;
     17    protected String name;
    1818
    1919//        public MultipolyPlugin(PluginInformation info) {
    2020        public MultipolyPlugin(PluginInformation info) {
    21                 super(info);
    22                 name = tr("Convert to multipolygon");
    23                 JMenu toolsMenu = null;
    24                 for (int i = 0; i < Main.main.menu.getMenuCount() && toolsMenu == null; i++) {
    25                         JMenu menu = Main.main.menu.getMenu(i);
    26                         String name = menu.getText();
    27                         if (name != null && name.equals(tr("Tools"))) {
    28                                 toolsMenu = menu;
    29                         }
    30                 }
     21        super(info);
     22        name = tr("Convert to multipolygon");
     23        JMenu toolsMenu = null;
     24        for (int i = 0; i < Main.main.menu.getMenuCount() && toolsMenu == null; i++) {
     25            JMenu menu = Main.main.menu.getMenu(i);
     26            String name = menu.getText();
     27            if (name != null && name.equals(tr("Tools"))) {
     28                toolsMenu = menu;
     29            }
     30        }
    3131
    32                 if (toolsMenu == null) {
    33                         toolsMenu = new JMenu(name);
    34                         toolsMenu.add(new JMenuItem(new MultipolyAction()));
    35                         Main.main.menu.add(toolsMenu, 2);
    36                 } else {
    37                         toolsMenu.addSeparator();
    38                         toolsMenu.add(new JMenuItem(new MultipolyAction()));
    39                 }
    40         }
     32        if (toolsMenu == null) {
     33            toolsMenu = new JMenu(name);
     34            toolsMenu.add(new JMenuItem(new MultipolyAction()));
     35            Main.main.menu.add(toolsMenu, 2);
     36        } else {
     37            toolsMenu.addSeparator();
     38            toolsMenu.add(new JMenuItem(new MultipolyAction()));
     39        }
     40    }
    4141}
Note: See TracChangeset for help on using the changeset viewer.