Changeset 33030 in osm


Ignore:
Timestamp:
2016-10-09T04:25:33+02:00 (8 years ago)
Author:
donvip
Message:

checkstyle

Location:
applications/editors/josm/plugins/seachartedit
Files:
2 added
7 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/seachartedit/.project

    r32680 r33030  
    1616                        </arguments>
    1717                </buildCommand>
     18                <buildCommand>
     19                        <name>net.sf.eclipsecs.core.CheckstyleBuilder</name>
     20                        <arguments>
     21                        </arguments>
     22                </buildCommand>
    1823        </buildSpec>
    1924        <natures>
    2025                <nature>org.eclipse.jdt.core.javanature</nature>
     26                <nature>net.sf.eclipsecs.core.CheckstyleNature</nature>
    2127        </natures>
    2228</projectDescription>
  • applications/editors/josm/plugins/seachartedit/src/messages/Messages.java

    r30895 r33030  
    1313import java.util.ResourceBundle;
    1414
    15 public class Messages {
    16         private static final String BUNDLE_NAME = "resources/msg.messages";
     15public final class Messages {
     16    private static final String BUNDLE_NAME = "resources/msg.messages";
    1717
    18         private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle.getBundle(BUNDLE_NAME);
     18    private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle.getBundle(BUNDLE_NAME);
    1919
    20         private Messages() {
    21         }
     20    private Messages() {
     21    }
    2222
    23         public static String getString(String key) {
    24                 try {
    25                         return RESOURCE_BUNDLE.getString(key);
    26                 } catch (MissingResourceException e) {
    27                         return '!' + key + '!';
    28                 }
    29         }
     23    public static String getString(String key) {
     24        try {
     25            return RESOURCE_BUNDLE.getString(key);
     26        } catch (MissingResourceException e) {
     27            return '!' + key + '!';
     28        }
     29    }
    3030}
  • applications/editors/josm/plugins/seachartedit/src/panels/PanelMain.java

    r31060 r33030  
    1818import java.awt.event.ActionListener;
    1919import java.awt.image.BufferedImage;
    20 import java.io.*;
     20import java.io.IOException;
    2121import java.util.ArrayList;
    2222
    23 import javax.swing.*;
     23import javax.swing.ImageIcon;
     24import javax.swing.JButton;
     25import javax.swing.JFileChooser;
     26import javax.swing.JPanel;
     27import javax.swing.JTextArea;
     28import javax.swing.JTextField;
     29
     30import org.openstreetmap.josm.Main;
    2431
    2532import messages.Messages;
    26 
    27 import org.openstreetmap.josm.Main;
    28 
     33import s57.S57att.Att;
     34import s57.S57map.AttMap;
     35import s57.S57map.Feature;
     36import s57.S57obj.Obj;
    2937import s57.S57val.AttVal;
    30 import s57.S57att.*;
    31 import s57.S57obj.*;
    32 import s57.S57map.*;
    3338import scedit.SCeditAction;
    3439
    3540public class PanelMain extends JPanel {
    3641
    37         BufferedImage img;
    38         int w, h, z, f;
    39         JTextField wt, ht, zt, ft;
    40         public static JTextArea decode = null;
    41         public static JTextField messageBar = null;
    42         public JButton saveButton = null;
    43         private ActionListener alSave = new ActionListener() {
    44                 public void actionPerformed(java.awt.event.ActionEvent e) {
    45                 }
    46         };
    47         private JButton importButton = null;
    48         JFileChooser ifc = new JFileChooser(Main.pref.get("nceditplugin.encinpfile"));
    49         private ActionListener alImport = new ActionListener() {
    50                 public void actionPerformed(java.awt.event.ActionEvent e) {
    51                         if (e.getSource() == importButton) {
    52                                 SCeditAction.panelS57.setVisible(true);
     42    BufferedImage img;
     43    int w, h, z, f;
     44    JTextField wt, ht, zt, ft;
     45    public static JTextArea decode = null;
     46    public static JTextField messageBar = null;
     47    public JButton saveButton = null;
     48    private ActionListener alSave = new ActionListener() {
     49        @Override
     50        public void actionPerformed(java.awt.event.ActionEvent e) {
     51        }
     52    };
     53    private JButton importButton = null;
     54    JFileChooser ifc = new JFileChooser(Main.pref.get("nceditplugin.encinpfile"));
     55    private ActionListener alImport = new ActionListener() {
     56        @Override
     57        public void actionPerformed(java.awt.event.ActionEvent e) {
     58            if (e.getSource() == importButton) {
     59                SCeditAction.panelS57.setVisible(true);
    5360        setStatus("Select S-57 ENC file for import", Color.yellow);
    54                                 int returnVal = ifc.showOpenDialog(Main.parent);
    55                                 if (returnVal == JFileChooser.APPROVE_OPTION) {
    56                                         try {
    57                                                 Main.pref.put("smed2plugin.encinpfile", ifc.getSelectedFile().getPath());
    58                                                 SCeditAction.panelS57.startImport(ifc.getSelectedFile());
    59                                         } catch (IOException e1) {
    60                                                 SCeditAction.panelS57.setVisible(false);
    61                                                 setStatus("IO Exception", Color.red);
    62                                         }
    63                                 } else {
    64                                         SCeditAction.panelS57.setVisible(false);
    65                                         clrStatus();
    66                                 }
    67                         }
    68                 }
    69         };
    70 
    71         private JButton exportButton = null;
    72         final JFileChooser efc = new JFileChooser();
    73         private ActionListener alExport = new ActionListener() {
    74                 public void actionPerformed(java.awt.event.ActionEvent e) {
    75                         if (e.getSource() == exportButton) {
    76                                 SCeditAction.panelS57.setVisible(true);
     61                int returnVal = ifc.showOpenDialog(Main.parent);
     62                if (returnVal == JFileChooser.APPROVE_OPTION) {
     63                    try {
     64                        Main.pref.put("smed2plugin.encinpfile", ifc.getSelectedFile().getPath());
     65                        SCeditAction.panelS57.startImport(ifc.getSelectedFile());
     66                    } catch (IOException e1) {
     67                        SCeditAction.panelS57.setVisible(false);
     68                        setStatus("IO Exception", Color.red);
     69                    }
     70                } else {
     71                    SCeditAction.panelS57.setVisible(false);
     72                    clrStatus();
     73                }
     74            }
     75        }
     76    };
     77
     78    private JButton exportButton = null;
     79    final JFileChooser efc = new JFileChooser();
     80    private ActionListener alExport = new ActionListener() {
     81        @Override
     82        public void actionPerformed(java.awt.event.ActionEvent e) {
     83            if (e.getSource() == exportButton) {
     84                SCeditAction.panelS57.setVisible(true);
    7785        setStatus("Select S-57 ENC file for export", Color.yellow);
    7886        int returnVal = efc.showOpenDialog(Main.parent);
    7987        if (returnVal == JFileChooser.APPROVE_OPTION) {
    80                 try {
    81                                                 SCeditAction.panelS57.startExport(efc.getSelectedFile());
    82                                         } catch (IOException e1) {
    83                                                 SCeditAction.panelS57.setVisible(false);
    84                                                 setStatus("IO Exception", Color.red);
    85                                         }
     88            try {
     89                        SCeditAction.panelS57.startExport(efc.getSelectedFile());
     90                    } catch (IOException e1) {
     91                        SCeditAction.panelS57.setVisible(false);
     92                        setStatus("IO Exception", Color.red);
     93                    }
    8694         } else {
    87                                         SCeditAction.panelS57.setVisible(false);
    88                                         clrStatus();
     95                     SCeditAction.panelS57.setVisible(false);
     96                    clrStatus();
    8997         }
    9098      }
    91                 }
    92         };
    93 
    94         public PanelMain() {
    95                 setLayout(null);
    96                 setSize(new Dimension(480, 480));
    97                
    98                 w = h = z = f = 0;
    99                 wt = new JTextField("0");
    100                 wt.setBounds(10, 400, 40, 20);
     99        }
     100    };
     101
     102    public PanelMain() {
     103        setLayout(null);
     104        setSize(new Dimension(480, 480));
     105
     106        w = h = z = f = 0;
     107        wt = new JTextField("0");
     108        wt.setBounds(10, 400, 40, 20);
    101109    add(wt);
    102                 ht = new JTextField("0");
    103                 ht.setBounds(60, 400, 40, 20);
     110        ht = new JTextField("0");
     111        ht.setBounds(60, 400, 40, 20);
    104112    add(ht);
    105                 zt = new JTextField("0");
    106                 zt.setBounds(110, 400, 40, 20);
     113        zt = new JTextField("0");
     114        zt.setBounds(110, 400, 40, 20);
    107115    add(zt);
    108                 ft = new JTextField("0");
    109                 ft.setBounds(160, 400, 40, 20);
     116        ft = new JTextField("0");
     117        ft.setBounds(160, 400, 40, 20);
    110118    add(ft);
    111119
     
    115123    messageBar.setBackground(Color.WHITE);
    116124    add(messageBar);
    117                 importButton = new JButton(new ImageIcon(getClass().getResource("/images/importButton.png")));
    118                 importButton.setBounds(10, 430, 20, 20);
    119                 add(importButton);
    120                 importButton.addActionListener(alImport);
    121                 exportButton = new JButton(new ImageIcon(getClass().getResource("/images/exportButton.png")));
    122                 exportButton.setBounds(40, 430, 20, 20);
    123                 add(exportButton);
    124                 exportButton.addActionListener(alExport);
    125                 saveButton = new JButton();
    126                 saveButton.setBounds(370, 430, 100, 20);
    127                 saveButton.setText(tr("Save"));
    128                 add(saveButton);
    129                 saveButton.addActionListener(alSave);
    130 
    131                 decode = new JTextArea();
    132                 decode.setBounds(0, 0, 480, 420);
    133                 decode.setTabSize(1);
    134                 add(decode);
    135         }
    136        
    137         public void paintComponent(Graphics g){
    138                 super.paintComponent(g);
    139                 Graphics2D g2 = (Graphics2D) g;
    140                 g2.setBackground(new Color(0xb5d0d0));
    141                 if (img != null) g2.clearRect(0, 0, img.getWidth(), img.getHeight());
    142                 g2.drawImage(img, 0, 0, null);
    143         }
    144        
    145         public static void setStatus(String text, Color bg) {
    146                 messageBar.setBackground(bg);
    147                 messageBar.setText(text);
    148         }
    149        
    150         public static void clrStatus() {
    151                 messageBar.setBackground(Color.white);
    152                 messageBar.setText("");
    153         }
    154        
    155         public void parseMark(Feature feature) {
    156                 decode.setText("Selected object:\n");
    157                 decode.append("\t" + tr("Type") + ": " + Messages.getString(feature.type.name()) + "\n");
    158                 if (feature.atts.get(Att.OBJNAM) != null) {
    159                         decode.append("\t" + tr("Name") + ": " + feature.atts.get(Att.OBJNAM).val + "\n");
    160                 }
    161                 decode.append("\tObjects:\n");
    162                 for (Obj obj : feature.objs.keySet()) {
    163                         decode.append("\t\t" + Messages.getString(obj.name()) + "\n");
    164                         if (feature.objs.get(obj).size() != 0) {
    165                                 for (AttMap atts : feature.objs.get(obj).values()) {
    166                                         for (Att att : atts.keySet()) {
    167                                                 AttVal<?> item = atts.get(att);
    168                                                 switch (item.conv) {
    169                                                 case E:
    170                                                         decode.append("\t\t\t" + Messages.getString(att.name()) + ": " + Messages.getString(((Enum<?>)((ArrayList<?>)item.val).get(0)).name()) + "\n");
    171                                                         break;
    172                                                 case L:
    173                                                         decode.append("\t\t\t" + Messages.getString(att.name()) + ": ");
    174                                                         boolean first = true;
    175                                                         for (Object val : (ArrayList<?>)item.val) {
    176                                                                 if (!first) {
    177                                                                         decode.append(", ");
    178                                                                 } else {
    179                                                                         first = false;
    180                                                                 }
    181                                                                 decode.append(Messages.getString(((Enum<?>)val).name()));
    182                                                         }
    183                                                         decode.append("\n");
    184                                                         break;
    185                                                 default:
    186                                                         decode.append("\t\t\t" + Messages.getString(att.name()) + ": " + item.val + "\n");
    187                                                 }
    188                                         }
    189                                 }
    190                         }
    191                 }
    192         }
    193        
    194         public void clearMark() {
    195                 decode.setText(tr("No object selected"));
    196         }
    197        
     125        importButton = new JButton(new ImageIcon(getClass().getResource("/images/importButton.png")));
     126        importButton.setBounds(10, 430, 20, 20);
     127        add(importButton);
     128        importButton.addActionListener(alImport);
     129        exportButton = new JButton(new ImageIcon(getClass().getResource("/images/exportButton.png")));
     130        exportButton.setBounds(40, 430, 20, 20);
     131        add(exportButton);
     132        exportButton.addActionListener(alExport);
     133        saveButton = new JButton();
     134        saveButton.setBounds(370, 430, 100, 20);
     135        saveButton.setText(tr("Save"));
     136        add(saveButton);
     137        saveButton.addActionListener(alSave);
     138
     139        decode = new JTextArea();
     140        decode.setBounds(0, 0, 480, 420);
     141        decode.setTabSize(1);
     142        add(decode);
     143    }
     144
     145    @Override
     146    public void paintComponent(Graphics g) {
     147        super.paintComponent(g);
     148        Graphics2D g2 = (Graphics2D) g;
     149        g2.setBackground(new Color(0xb5d0d0));
     150        if (img != null) g2.clearRect(0, 0, img.getWidth(), img.getHeight());
     151        g2.drawImage(img, 0, 0, null);
     152    }
     153
     154    public static void setStatus(String text, Color bg) {
     155        messageBar.setBackground(bg);
     156        messageBar.setText(text);
     157    }
     158
     159    public static void clrStatus() {
     160        messageBar.setBackground(Color.white);
     161        messageBar.setText("");
     162    }
     163
     164    public void parseMark(Feature feature) {
     165        decode.setText("Selected object:\n");
     166        decode.append("\t" + tr("Type") + ": " + Messages.getString(feature.type.name()) + "\n");
     167        if (feature.atts.get(Att.OBJNAM) != null) {
     168            decode.append("\t" + tr("Name") + ": " + feature.atts.get(Att.OBJNAM).val + "\n");
     169        }
     170        decode.append("\tObjects:\n");
     171        for (Obj obj : feature.objs.keySet()) {
     172            decode.append("\t\t" + Messages.getString(obj.name()) + "\n");
     173            if (feature.objs.get(obj).size() != 0) {
     174                for (AttMap atts : feature.objs.get(obj).values()) {
     175                    for (Att att : atts.keySet()) {
     176                        AttVal<?> item = atts.get(att);
     177                        switch (item.conv) {
     178                        case E:
     179                            decode.append("\t\t\t" + Messages.getString(att.name()) + ": " +
     180                                    Messages.getString(((Enum<?>) ((ArrayList<?>) item.val).get(0)).name()) + "\n");
     181                            break;
     182                        case L:
     183                            decode.append("\t\t\t" + Messages.getString(att.name()) + ": ");
     184                            boolean first = true;
     185                            for (Object val : (ArrayList<?>) item.val) {
     186                                if (!first) {
     187                                    decode.append(", ");
     188                                } else {
     189                                    first = false;
     190                                }
     191                                decode.append(Messages.getString(((Enum<?>) val).name()));
     192                            }
     193                            decode.append("\n");
     194                            break;
     195                        default:
     196                            decode.append("\t\t\t" + Messages.getString(att.name()) + ": " + item.val + "\n");
     197                        }
     198                    }
     199                }
     200            }
     201        }
     202    }
     203
     204    public void clearMark() {
     205        decode.setText(tr("No object selected"));
     206    }
    198207}
  • applications/editors/josm/plugins/seachartedit/src/panels/PanelS57.java

    r32370 r33030  
    1212import java.awt.Color;
    1313import java.awt.Dimension;
    14 import java.io.*;
     14import java.io.File;
     15import java.io.FileInputStream;
     16import java.io.IOException;
    1517import java.util.ArrayList;
    1618import java.util.HashMap;
     
    2426import org.openstreetmap.josm.data.Bounds;
    2527import org.openstreetmap.josm.data.coor.LatLon;
    26 import org.openstreetmap.josm.data.osm.*;
     28import org.openstreetmap.josm.data.osm.DataSet;
     29import org.openstreetmap.josm.data.osm.Node;
     30import org.openstreetmap.josm.data.osm.OsmPrimitive;
     31import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
     32import org.openstreetmap.josm.data.osm.Relation;
     33import org.openstreetmap.josm.data.osm.RelationMember;
     34import org.openstreetmap.josm.data.osm.Way;
    2735import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    2836
    2937import s57.S57att;
     38import s57.S57att.Att;
    3039import s57.S57dec;
     40import s57.S57map;
     41import s57.S57map.AttMap;
     42import s57.S57map.Feature;
     43import s57.S57map.GeomIterator;
     44import s57.S57map.ObjTab;
     45import s57.S57map.Pflag;
     46import s57.S57map.Prim;
     47import s57.S57map.Rflag;
     48import s57.S57map.Snode;
    3149import s57.S57obj;
    32 import s57.S57map;
     50import s57.S57obj.Obj;
    3351import s57.S57val;
    34 import s57.S57att.Att;
    35 import s57.S57map.*;
    36 import s57.S57obj.*;
    3752import s57.S57val.AttVal;
    3853
    3954public class PanelS57 extends JPanel {
    4055
    41         ArrayList<Obj> types = new ArrayList<Obj>();
    42         S57map map;
    43         HashMap<Long, Long> uids = new HashMap<Long, Long>();
    44        
    45         public PanelS57() {
    46                 setLayout(null);
    47                 setSize(new Dimension(480, 480));
    48                 setVisible(false);
    49         }
    50 
    51         public void startImport(File inf) throws IOException {
    52                 FileInputStream in = new FileInputStream(inf);
    53                 PanelMain.setStatus("Select OSM types file", Color.yellow);
    54                 JFileChooser ifc = new JFileChooser(Main.pref.get("smed2plugin.typesfile"));
    55                 ifc.setSelectedFile(new File(Main.pref.get("smed2plugin.typesfile")));
    56                 int returnVal = ifc.showOpenDialog(Main.parent);
    57                 if (returnVal == JFileChooser.APPROVE_OPTION) {
    58                         Main.pref.put("smed2plugin.typesfile", ifc.getSelectedFile().getPath());
    59                         Scanner tin = new Scanner(new FileInputStream(ifc.getSelectedFile()));
    60                         while (tin.hasNext()) {
    61                                 Obj type = S57obj.enumType(tin.next());
    62                                 if (type != Obj.UNKOBJ)
    63                                         types.add(type);
    64                         }
    65                         tin.close();
    66                 }
    67                 map = new S57map(true);
    68                 S57dec.decodeChart(in, map);
    69 
    70                 in.close();
    71                
    72                 DataSet data = new DataSet();
    73                 data.setUploadDiscouraged(true);
    74                
    75                 for (long id : map.index.keySet()) {
    76                         Feature feature = map.index.get(id);
    77                         String type = S57obj.stringType(feature.type);
    78                         if (!type.isEmpty() && (types.isEmpty() || types.contains(feature.type))) {
    79                                 if (feature.reln == Rflag.MASTER) {
    80                                         if (feature.geom.prim == Pflag.POINT) {
    81                                                 for (Prim prim : feature.geom.elems) {
    82                                                         long ref = prim.id;
    83                                                         Snode snode;
    84                                                         while ((snode = map.nodes.get(ref)) != null) {
    85                                                                 if (!uids.containsKey(ref)) {
    86                                                                         Node node = new Node(0, 1);
    87                                                                         node.setCoor((new LatLon(Math.toDegrees(snode.lat), Math.toDegrees(snode.lon))));
    88                                                                         data.addPrimitive(node);
    89                                                                         addKeys(node, feature, type);
    90                                                                         uids.put(ref, node.getUniqueId());
    91                                                                 }
    92                                                                 ref++;
    93                                                         }
    94                                                 }
    95                                         }
    96                                 }
    97                         }
    98                 }
    99                 for (long id : map.index.keySet()) {
    100                         Feature feature = map.index.get(id);
    101                         String type = S57obj.stringType(feature.type);
    102                         if (!type.isEmpty() && (types.isEmpty() || types.contains(feature.type))) {
    103                                 if (feature.reln == Rflag.MASTER) {
    104                                         if ((feature.geom.prim == Pflag.LINE) || ((feature.geom.prim == Pflag.AREA) && (feature.geom.outers == 1) && (feature.geom.inners == 0))) {
    105                                                 GeomIterator git = map.new GeomIterator(feature.geom);
    106                                                 while (git.hasComp()) {
    107                                                         git.nextComp();
    108                                                         while (git.hasEdge()) {
    109                                                                 git.nextEdge();
    110                                                                 while (git.hasNode()) {
    111                                                                         long ref = git.nextRef();
    112                                                                         Snode snode = map.nodes.get(ref);
    113                                                                         if (!uids.containsKey(ref)) {
    114                                                                                 Node node = new Node(0, 1);
    115                                                                                 node.setCoor((new LatLon(Math.toDegrees(snode.lat), Math.toDegrees(snode.lon))));
    116                                                                                 data.addPrimitive(node);
    117                                                                                 uids.put(ref, node.getUniqueId());
    118                                                                         }
    119                                                                 }
    120                                                         }
    121                                                 }
    122                                                 git = map.new GeomIterator(feature.geom);
    123                                                 while (git.hasComp()) {
    124                                                         git.nextComp();
    125                                                         Way way = new Way(0, 1);
    126                                                         data.addPrimitive(way);
    127                                                         while (git.hasEdge()) {
    128                                                                 git.nextEdge();
    129                                                                 while (git.hasNode()) {
    130                                                                         long ref = git.nextRef();
    131                                                                         way.addNode((Node)data.getPrimitiveById(uids.get(ref), OsmPrimitiveType.NODE));
    132                                                                 }
    133                                                         }
    134                                                         addKeys(way, feature, type);
    135                                                 }
    136                                         } else if (feature.geom.prim == Pflag.AREA) {
    137                                                 GeomIterator git = map.new GeomIterator(feature.geom);
    138                                                 while (git.hasComp()) {
    139                                                         git.nextComp();
    140                                                         while (git.hasEdge()) {
    141                                                                 git.nextEdge();
    142                                                                 while (git.hasNode()) {
    143                                                                         long ref = git.nextRef();
    144                                                                         Snode snode = map.nodes.get(ref);
    145                                                                         if (!uids.containsKey(ref)) {
    146                                                                                 Node node = new Node(0, 1);
    147                                                                                 node.setCoor((new LatLon(Math.toDegrees(snode.lat), Math.toDegrees(snode.lon))));
    148                                                                                 data.addPrimitive(node);
    149                                                                                 uids.put(ref, node.getUniqueId());
    150                                                                         }
    151                                                                 }
    152                                                         }
    153                                                 }
    154                                                 git = map.new GeomIterator(feature.geom);
    155                                                 while (git.hasComp()) {
    156                                                         long ref = git.nextComp();
    157                                                         Way way = new Way(0, 1);
    158                                                         uids.put(ref, way.getUniqueId());
    159                                                         data.addPrimitive(way);
    160                                                         while (git.hasEdge()) {
    161                                                                 git.nextEdge();
    162                                                                 while (git.hasNode()) {
    163                                                                         ref = git.nextRef();
    164                                                                         way.addNode((Node) data.getPrimitiveById(uids.get(ref), OsmPrimitiveType.NODE));
    165                                                                 }
    166                                                         }
    167                                                 }
    168                                                 Relation rel = new Relation(0, 1);
    169                                                 data.addPrimitive(rel);
    170                                                 git = map.new GeomIterator(feature.geom);
    171                                                 int outers = feature.geom.outers;
    172                                                 while (git.hasComp()) {
    173                                                         long ref = git.nextComp();
    174                                                         if (outers-- > 0) {
    175                                                                 rel.addMember(new RelationMember("outer", (Way) data.getPrimitiveById(uids.get(ref), OsmPrimitiveType.WAY)));
    176                                                         } else {
    177                                                                 rel.addMember(new RelationMember("inner", (Way) data.getPrimitiveById(uids.get(ref), OsmPrimitiveType.WAY)));
    178                                                         }
    179                                                 }
    180                                                 addKeys(rel, feature, type);
    181                                         }
    182                                 }
    183                         }
    184                 }
    185 
    186                 OsmDataLayer layer = new OsmDataLayer(data, "S-57 Import", null);
    187                 Main.getLayerManager().addLayer(layer);
    188                 Main.map.mapView.zoomTo(new Bounds(Math.toDegrees(map.bounds.minlat), Math.toDegrees(map.bounds.minlon), Math.toDegrees(map.bounds.maxlat), Math.toDegrees(map.bounds.maxlon)));
    189                 PanelMain.setStatus("Import done", Color.green);
    190         }
    191 
    192         void addKeys(OsmPrimitive prim, Feature feature, String type) {
    193                 HashMap<String,String> keys = new HashMap<String,String>();
    194                 if (prim instanceof Relation) {
    195                         keys.put("type", "multipolygon");
    196                 }
    197                 keys.put("seamark:type", type);
    198                 if (feature.type == Obj.SOUNDG) {
    199                         Snode snode = map.nodes.get(feature.geom.elems.get(0).id);
    200                         if (snode.flg == S57map.Nflag.DPTH) {
    201                                 keys.put("seamark:sounding:depth", ((Double)((Snode)snode).val).toString());
    202                         }
    203                 }
    204                 for (Map.Entry<Att, AttVal<?>> item : feature.atts.entrySet()) {
    205                         String attstr = S57att.stringAttribute(item.getKey());
    206                         String valstr = S57val.stringValue(item.getValue(), item.getKey());
    207                         if (!attstr.isEmpty() && !valstr.isEmpty()) {
    208                                         keys.put(("seamark:" + type + ":" + attstr), valstr);
    209                         }
    210                 }
    211                 for (Obj obj : feature.objs.keySet()) {
    212                         ObjTab tab = feature.objs.get(obj);
    213                         for (int ix : tab.keySet()) {
    214                                 type = S57obj.stringType(obj);
    215                                 AttMap atts = tab.get(ix);
    216                                 for (Map.Entry<Att, AttVal<?>> item : atts.entrySet()) {
    217                                         String attstr = S57att.stringAttribute(item.getKey());
    218                                         String valstr = S57val.stringValue(item.getValue(), item.getKey());
    219                                         if (!attstr.isEmpty() && !valstr.isEmpty()) {
    220                                                 if ((ix == 0) && (tab.size() == 1)) {
    221                                                         keys.put(("seamark:" + type + ":" + attstr), valstr);
    222                                                 } else {
    223                                                         keys.put(("seamark:" + type + ":" + (ix+1) + ":" + attstr), valstr);
    224                                                 }
    225                                         }
    226                                 }
    227                         }
    228                 }
    229                 prim.setKeys(keys);
    230         }
    231 
    232        
    233         public void startExport(File outf) throws IOException {
    234                
    235         }
     56    ArrayList<Obj> types = new ArrayList<>();
     57    S57map map;
     58    HashMap<Long, Long> uids = new HashMap<>();
     59
     60    public PanelS57() {
     61        setLayout(null);
     62        setSize(new Dimension(480, 480));
     63        setVisible(false);
     64    }
     65
     66    public void startImport(File inf) throws IOException {
     67        FileInputStream in = new FileInputStream(inf);
     68        PanelMain.setStatus("Select OSM types file", Color.yellow);
     69        JFileChooser ifc = new JFileChooser(Main.pref.get("smed2plugin.typesfile"));
     70        ifc.setSelectedFile(new File(Main.pref.get("smed2plugin.typesfile")));
     71        int returnVal = ifc.showOpenDialog(Main.parent);
     72        if (returnVal == JFileChooser.APPROVE_OPTION) {
     73            Main.pref.put("smed2plugin.typesfile", ifc.getSelectedFile().getPath());
     74            Scanner tin = new Scanner(new FileInputStream(ifc.getSelectedFile()));
     75            while (tin.hasNext()) {
     76                Obj type = S57obj.enumType(tin.next());
     77                if (type != Obj.UNKOBJ)
     78                    types.add(type);
     79            }
     80            tin.close();
     81        }
     82        map = new S57map(true);
     83        S57dec.decodeChart(in, map);
     84
     85        in.close();
     86
     87        DataSet data = new DataSet();
     88        data.setUploadDiscouraged(true);
     89
     90        for (long id : map.index.keySet()) {
     91            Feature feature = map.index.get(id);
     92            String type = S57obj.stringType(feature.type);
     93            if (!type.isEmpty() && (types.isEmpty() || types.contains(feature.type))) {
     94                if (feature.reln == Rflag.MASTER) {
     95                    if (feature.geom.prim == Pflag.POINT) {
     96                        for (Prim prim : feature.geom.elems) {
     97                            long ref = prim.id;
     98                            Snode snode;
     99                            while ((snode = map.nodes.get(ref)) != null) {
     100                                if (!uids.containsKey(ref)) {
     101                                    Node node = new Node(0, 1);
     102                                    node.setCoor((new LatLon(Math.toDegrees(snode.lat), Math.toDegrees(snode.lon))));
     103                                    data.addPrimitive(node);
     104                                    addKeys(node, feature, type);
     105                                    uids.put(ref, node.getUniqueId());
     106                                }
     107                                ref++;
     108                            }
     109                        }
     110                    }
     111                }
     112            }
     113        }
     114        for (long id : map.index.keySet()) {
     115            Feature feature = map.index.get(id);
     116            String type = S57obj.stringType(feature.type);
     117            if (!type.isEmpty() && (types.isEmpty() || types.contains(feature.type))) {
     118                if (feature.reln == Rflag.MASTER) {
     119                    if ((feature.geom.prim == Pflag.LINE) || ((feature.geom.prim == Pflag.AREA)
     120                            && (feature.geom.outers == 1) && (feature.geom.inners == 0))) {
     121                        GeomIterator git = map.new GeomIterator(feature.geom);
     122                        while (git.hasComp()) {
     123                            git.nextComp();
     124                            while (git.hasEdge()) {
     125                                git.nextEdge();
     126                                while (git.hasNode()) {
     127                                    long ref = git.nextRef();
     128                                    Snode snode = map.nodes.get(ref);
     129                                    if (!uids.containsKey(ref)) {
     130                                        Node node = new Node(0, 1);
     131                                        node.setCoor((new LatLon(Math.toDegrees(snode.lat), Math.toDegrees(snode.lon))));
     132                                        data.addPrimitive(node);
     133                                        uids.put(ref, node.getUniqueId());
     134                                    }
     135                                }
     136                            }
     137                        }
     138                        git = map.new GeomIterator(feature.geom);
     139                        while (git.hasComp()) {
     140                            git.nextComp();
     141                            Way way = new Way(0, 1);
     142                            data.addPrimitive(way);
     143                            while (git.hasEdge()) {
     144                                git.nextEdge();
     145                                while (git.hasNode()) {
     146                                    long ref = git.nextRef();
     147                                    way.addNode((Node) data.getPrimitiveById(uids.get(ref), OsmPrimitiveType.NODE));
     148                                }
     149                            }
     150                            addKeys(way, feature, type);
     151                        }
     152                    } else if (feature.geom.prim == Pflag.AREA) {
     153                        GeomIterator git = map.new GeomIterator(feature.geom);
     154                        while (git.hasComp()) {
     155                            git.nextComp();
     156                            while (git.hasEdge()) {
     157                                git.nextEdge();
     158                                while (git.hasNode()) {
     159                                    long ref = git.nextRef();
     160                                    Snode snode = map.nodes.get(ref);
     161                                    if (!uids.containsKey(ref)) {
     162                                        Node node = new Node(0, 1);
     163                                        node.setCoor((new LatLon(Math.toDegrees(snode.lat), Math.toDegrees(snode.lon))));
     164                                        data.addPrimitive(node);
     165                                        uids.put(ref, node.getUniqueId());
     166                                    }
     167                                }
     168                            }
     169                        }
     170                        git = map.new GeomIterator(feature.geom);
     171                        while (git.hasComp()) {
     172                            long ref = git.nextComp();
     173                            Way way = new Way(0, 1);
     174                            uids.put(ref, way.getUniqueId());
     175                            data.addPrimitive(way);
     176                            while (git.hasEdge()) {
     177                                git.nextEdge();
     178                                while (git.hasNode()) {
     179                                    ref = git.nextRef();
     180                                    way.addNode((Node) data.getPrimitiveById(uids.get(ref), OsmPrimitiveType.NODE));
     181                                }
     182                            }
     183                        }
     184                        Relation rel = new Relation(0, 1);
     185                        data.addPrimitive(rel);
     186                        git = map.new GeomIterator(feature.geom);
     187                        int outers = feature.geom.outers;
     188                        while (git.hasComp()) {
     189                            long ref = git.nextComp();
     190                            if (outers-- > 0) {
     191                                rel.addMember(new RelationMember("outer", data.getPrimitiveById(uids.get(ref), OsmPrimitiveType.WAY)));
     192                            } else {
     193                                rel.addMember(new RelationMember("inner", data.getPrimitiveById(uids.get(ref), OsmPrimitiveType.WAY)));
     194                            }
     195                        }
     196                        addKeys(rel, feature, type);
     197                    }
     198                }
     199            }
     200        }
     201
     202        OsmDataLayer layer = new OsmDataLayer(data, "S-57 Import", null);
     203        Main.getLayerManager().addLayer(layer);
     204        Main.map.mapView.zoomTo(new Bounds(Math.toDegrees(map.bounds.minlat), Math.toDegrees(map.bounds.minlon),
     205                                           Math.toDegrees(map.bounds.maxlat), Math.toDegrees(map.bounds.maxlon)));
     206        PanelMain.setStatus("Import done", Color.green);
     207    }
     208
     209    void addKeys(OsmPrimitive prim, Feature feature, String type) {
     210        HashMap<String, String> keys = new HashMap<>();
     211        if (prim instanceof Relation) {
     212            keys.put("type", "multipolygon");
     213        }
     214        keys.put("seamark:type", type);
     215        if (feature.type == Obj.SOUNDG) {
     216            Snode snode = map.nodes.get(feature.geom.elems.get(0).id);
     217            if (snode.flg == S57map.Nflag.DPTH) {
     218                keys.put("seamark:sounding:depth", ((Double) snode.val).toString());
     219            }
     220        }
     221        for (Map.Entry<Att, AttVal<?>> item : feature.atts.entrySet()) {
     222            String attstr = S57att.stringAttribute(item.getKey());
     223            String valstr = S57val.stringValue(item.getValue(), item.getKey());
     224            if (!attstr.isEmpty() && !valstr.isEmpty()) {
     225                    keys.put(("seamark:" + type + ":" + attstr), valstr);
     226            }
     227        }
     228        for (Obj obj : feature.objs.keySet()) {
     229            ObjTab tab = feature.objs.get(obj);
     230            for (int ix : tab.keySet()) {
     231                type = S57obj.stringType(obj);
     232                AttMap atts = tab.get(ix);
     233                for (Map.Entry<Att, AttVal<?>> item : atts.entrySet()) {
     234                    String attstr = S57att.stringAttribute(item.getKey());
     235                    String valstr = S57val.stringValue(item.getValue(), item.getKey());
     236                    if (!attstr.isEmpty() && !valstr.isEmpty()) {
     237                        if ((ix == 0) && (tab.size() == 1)) {
     238                            keys.put(("seamark:" + type + ":" + attstr), valstr);
     239                        } else {
     240                            keys.put(("seamark:" + type + ":" + (ix+1) + ":" + attstr), valstr);
     241                        }
     242                    }
     243                }
     244            }
     245        }
     246        prim.setKeys(keys);
     247    }
     248
     249    public void startExport(File outf) throws IOException {
     250
     251    }
    236252}
  • applications/editors/josm/plugins/seachartedit/src/panels/ShowFrame.java

    r32231 r33030  
    2525import render.Renderer;
    2626import s57.S57map;
    27 import s57.S57map.*;
     27import s57.S57map.Feature;
     28import s57.S57map.Snode;
    2829
    2930public class ShowFrame extends JFrame {
    30        
    31         S57map showMap;
    32         Picture picture;
    3331
    34         class Picture extends JPanel implements ChartContext {
     32    S57map showMap;
     33    Picture picture;
    3534
    36                 public void drawPicture(OsmPrimitive osm, S57map map) {
    37                         long id;
    38                         Feature feature;
    39                        
    40                         id = osm.getUniqueId();
    41                         feature = map.index.get(id);
    42                         showMap = new S57map(true);
    43                         showMap.nodes = map.nodes;
    44                         showMap.edges = map.edges;
    45                         showMap.index = map.index;
    46                         if (feature != null) {
    47                                 showMap.features.put(feature.type, new ArrayList<Feature>());
    48                                 showMap.features.get(feature.type).add(feature);
    49                         }
    50                         repaint();
    51                 }
    52                
    53                 public void paintComponent(Graphics g) {
    54                         Graphics2D g2 = (Graphics2D)g;
    55                         g2.setBackground(new Color(0xb5d0d0));
    56                         Rectangle rect =  new Rectangle(0, 0, 300, 300);
    57                         g2.clearRect(rect.x, rect.y, rect.width, rect.height);
    58                         Renderer.reRender(g2, rect, 16, 32, showMap, this);
    59                 }
     35    class Picture extends JPanel implements ChartContext {
    6036
    61                 public Point2D getPoint(Snode coord) {
    62                         return new Point2D.Double(150, 150);
    63                 }
     37        public void drawPicture(OsmPrimitive osm, S57map map) {
     38            long id;
     39            Feature feature;
    6440
    65                 public double mile(Feature feature) {
    66                         return 1000;
    67                 }
     41            id = osm.getUniqueId();
     42            feature = map.index.get(id);
     43            showMap = new S57map(true);
     44            showMap.nodes = map.nodes;
     45            showMap.edges = map.edges;
     46            showMap.index = map.index;
     47            if (feature != null) {
     48                showMap.features.put(feature.type, new ArrayList<Feature>());
     49                showMap.features.get(feature.type).add(feature);
     50            }
     51            repaint();
     52        }
    6853
    69                 @Override
    70                 public boolean clip() {
    71                         // TODO Auto-generated method stub
    72                         return false;
    73                 }
     54        @Override
     55        public void paintComponent(Graphics g) {
     56            Graphics2D g2 = (Graphics2D) g;
     57            g2.setBackground(new Color(0xb5d0d0));
     58            Rectangle rect = new Rectangle(0, 0, 300, 300);
     59            g2.clearRect(rect.x, rect.y, rect.width, rect.height);
     60            Renderer.reRender(g2, rect, 16, 32, showMap, this);
     61        }
    7462
    75                 @Override
    76                 public Color background(S57map map) {
    77                         // TODO Auto-generated method stub
    78                         return null;
    79                 }
     63        @Override
     64        public Point2D getPoint(Snode coord) {
     65            return new Point2D.Double(150, 150);
     66        }
    8067
    81                 @Override
    82                 public RuleSet ruleset() {
    83                         // TODO Auto-generated method stub
    84                         return null;
    85                 }
    86         }
     68        @Override
     69        public double mile(Feature feature) {
     70            return 1000;
     71        }
    8772
    88         public ShowFrame(String title) {
    89                 super(title);
    90                 picture = new Picture();
    91                 picture.setVisible(true);
    92                 add(picture);
    93                 pack();
    94         }
    95        
    96         public void showFeature(OsmPrimitive osm, S57map map) {
    97                 picture.drawPicture(osm, map);
    98         }
     73        @Override
     74        public boolean clip() {
     75            // TODO Auto-generated method stub
     76            return false;
     77        }
     78
     79        @Override
     80        public Color background(S57map map) {
     81            // TODO Auto-generated method stub
     82            return null;
     83        }
     84
     85        @Override
     86        public RuleSet ruleset() {
     87            // TODO Auto-generated method stub
     88            return null;
     89        }
     90    }
     91
     92    public ShowFrame(String title) {
     93        super(title);
     94        picture = new Picture();
     95        picture.setVisible(true);
     96        add(picture);
     97        pack();
     98    }
     99
     100    public void showFeature(OsmPrimitive osm, S57map map) {
     101        picture.drawPicture(osm, map);
     102    }
    99103}
  • applications/editors/josm/plugins/seachartedit/src/scedit/SCedit.java

    r30895 r33030  
    1717public class SCedit extends Plugin {
    1818
    19         public SCedit(PluginInformation info) {
     19    public SCedit(PluginInformation info) {
    2020        super(info);
    2121        MainMenu.add(Main.main.menu.toolsMenu, new SCeditAction());
  • applications/editors/josm/plugins/seachartedit/src/scedit/SCeditAction.java

    r32370 r33030  
    5454
    5555public class SCeditAction extends JosmAction implements ActiveLayerChangeListener, SelectionChangedListener {
    56         private static String title = tr("SeaChart Editor");
    57         public static JFrame editFrame = null;
    58         public static ShowFrame showFrame = null;
    59         private boolean isOpen = false;
    60         public static PanelMain panelMain = null;
    61         public static PanelS57 panelS57 = null;
    62         public static S57map map = null;
    63         public DataSet data = null;
    64 
    65         private final DataSetListener dataSetListener = new DataSetListener() {
    66 
    67                 @Override
    68                 public void dataChanged(DataChangedEvent e) {
    69                         makeMap();
    70                 }
    71 
    72                 @Override
    73                 public void nodeMoved(NodeMovedEvent e) {
    74                         makeMap();
    75                 }
    76 
    77                 @Override
    78                 public void otherDatasetChange(AbstractDatasetChangedEvent e) {
    79                         makeMap();
    80                 }
    81 
    82                 @Override
    83                 public void primitivesAdded(PrimitivesAddedEvent e) {
    84                         makeMap();
    85                 }
    86 
    87                 @Override
    88                 public void primitivesRemoved(PrimitivesRemovedEvent e) {
    89                         makeMap();
    90                 }
    91 
    92                 @Override
    93                 public void relationMembersChanged(RelationMembersChangedEvent e) {
    94                         makeMap();
    95                 }
    96 
    97                 @Override
    98                 public void tagsChanged(TagsChangedEvent e) {
    99                         makeMap();
    100                 }
    101 
    102                 @Override
    103                 public void wayNodesChanged(WayNodesChangedEvent e) {
    104                         makeMap();
    105                 }
    106         };
    107 
    108         public SCeditAction() {
    109                 super(title, "SC", title, null, true);
    110         }
    111 
    112         @Override
    113         public void actionPerformed(ActionEvent arg0) {
    114                 SwingUtilities.invokeLater(new Runnable() {
    115                         public void run() {
    116                                 if (!isOpen)
    117                                         createFrame();
    118                                 else
    119                                         editFrame.toFront();
    120                                 isOpen = true;
    121                         }
    122                 });
    123         }
    124 
    125         protected void createFrame() {
    126                 editFrame = new JFrame(title);
    127                 editFrame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
    128                 editFrame.addWindowListener(new java.awt.event.WindowAdapter() {
    129                         public void windowClosing(java.awt.event.WindowEvent e) {
    130                                 closeDialog();
    131                         }
    132                 });
    133                 editFrame.setSize(new Dimension(480, 480));
    134                 editFrame.setLocation(100, 200);
    135                 editFrame.setResizable(true);
    136                 editFrame.setAlwaysOnTop(true);
    137                 editFrame.setVisible(true);
    138                 panelMain = new PanelMain();
    139                 editFrame.add(panelMain);
    140 
    141                 panelS57 = new PanelS57();
    142                 editFrame.add(panelS57);
    143 
    144                 showFrame = new ShowFrame(tr("Seamark Inspector"));
    145                 showFrame.setSize(new Dimension(300, 300));
    146                 showFrame.setLocation(50, 400);
    147                 showFrame.setResizable(false);
    148                 showFrame.setAlwaysOnTop(true);
    149                 showFrame.setEnabled(true);
    150                 showFrame.setVisible(false);
    151 
    152                 Main.getLayerManager().addAndFireActiveLayerChangeListener(this);
    153                 DataSet.addSelectionListener(this);
    154         }
    155 
    156         public void closeDialog() {
    157                 if (isOpen) {
    158                         Main.getLayerManager().removeActiveLayerChangeListener(this);
    159                         editFrame.setVisible(false);
    160                         editFrame.dispose();
    161                         data = null;
    162                         map = null;
    163                 }
    164                 isOpen = false;
    165         }
    166 
    167         @Override
    168         public void activeOrEditLayerChanged(ActiveLayerChangeEvent e) {
    169                 if (e.getPreviousEditLayer() != null) {
    170                     e.getPreviousEditLayer().data.removeDataSetListener(dataSetListener);
    171                 }
    172                 OsmDataLayer newLayer = Main.getLayerManager().getEditLayer();
    173                 if (newLayer != null) {
    174                         newLayer.data.addDataSetListener(dataSetListener);
    175                         data = newLayer.data;
    176                         makeMap();
    177                 } else {
    178                         data = null;
    179                         map = null;
    180                 }
    181         }
    182 
    183         @Override
    184         public void selectionChanged(Collection<? extends OsmPrimitive> selection) {
    185                 OsmPrimitive nextFeature = null;
    186                 OsmPrimitive feature = null;
    187 
    188                 showFrame.setVisible(false);
    189                 panelMain.clearMark();
    190                 if (map != null) {
    191                         for (OsmPrimitive osm : selection) {
    192                                 nextFeature = osm;
    193                                 if (selection.size() == 1) {
    194                                         if (nextFeature.compareTo(feature) != 0) {
    195                                                 feature = nextFeature;
    196                                                 Feature id = map.index.get(feature.getUniqueId());
    197                                                 if (id != null) {
    198                                                         panelMain.parseMark(id);
    199                                                         showFrame.setVisible(true);
    200                                                         showFrame.showFeature(feature, map);
    201                                                 }
    202                                         }
    203                                 } else {
    204                                         showFrame.setVisible(false);
    205                                         PanelMain.setStatus(tr("Select only one object"), Color.orange);
    206                                 }
    207                         }
    208                         if (nextFeature == null) {
    209                                 feature = null;
    210                                 panelMain.clearMark();
    211                                 showFrame.setVisible(false);
    212                                 PanelMain.setStatus(tr("Select a map object"), Color.yellow);
    213                         }
    214                 }
    215         }
    216 
    217         void makeMap() {
    218                 map = new S57map(true);
    219                 if (data != null) {
    220                         double minlat = 90;
    221                         double maxlat = -90;
    222                         double minlon = 180;
    223                         double maxlon = -180;
    224                         for (Bounds bounds : data.getDataSourceBounds()) {
    225                                 if (bounds.getMinLat() < minlat) {
    226                                         minlat = bounds.getMinLat();
    227                                 }
    228                                 if (bounds.getMaxLat() > maxlat) {
    229                                         maxlat = bounds.getMaxLat();
    230                                 }
    231                                 if (bounds.getMinLon() < minlon) {
    232                                         minlon = bounds.getMinLon();
    233                                 }
    234                                 if (bounds.getMaxLon() > maxlon) {
    235                                         maxlon = bounds.getMaxLon();
    236                                 }
    237                         }
    238                         map.addNode(1, maxlat, minlon);
    239                         map.addNode(2, minlat, minlon);
    240                         map.addNode(3, minlat, maxlon);
    241                         map.addNode(4, maxlat, maxlon);
    242                         map.bounds.minlat = Math.toRadians(minlat);
    243                         map.bounds.maxlat = Math.toRadians(maxlat);
    244                         map.bounds.minlon = Math.toRadians(minlon);
    245                         map.bounds.maxlon = Math.toRadians(maxlon);
    246                         for (Node node : data.getNodes()) {
    247                                 LatLon coor = node.getCoor();
    248                                 if (coor != null) {
    249                                         map.addNode(node.getUniqueId(), coor.lat(), coor.lon());
    250                                         for (Entry<String, String> entry : node.getKeys().entrySet()) {
    251                                                 map.addTag(entry.getKey(), entry.getValue());
    252                                         }
    253                                         map.tagsDone(node.getUniqueId());
    254                                 }
    255                         }
    256                         for (Way way : data.getWays()) {
    257                                 if (way.getNodesCount() > 0) {
    258                                         map.addEdge(way.getUniqueId());
    259                                         for (Node node : way.getNodes()) {
    260                                                 map.addToEdge((node.getUniqueId()));
    261                                         }
    262                                         for (Entry<String, String> entry : way.getKeys().entrySet()) {
    263                                                 map.addTag(entry.getKey(), entry.getValue());
    264                                         }
    265                                         map.tagsDone(way.getUniqueId());
    266                                 }
    267                         }
    268                         for (Relation rel : data.getRelations()) {
    269                                 if (rel.isMultipolygon() && (rel.getMembersCount() > 0)) {
    270                                         map.addArea(rel.getUniqueId());
    271                                         for (RelationMember mem : rel.getMembers()) {
    272                                                 if (mem.getType() == OsmPrimitiveType.WAY)
    273                                                         map.addToArea(mem.getUniqueId(), (mem.getRole().equals("outer")));
    274                                         }
    275                                         for (Entry<String, String> entry : rel.getKeys().entrySet()) {
    276                                                 map.addTag(entry.getKey(), entry.getValue());
    277                                         }
    278                                         map.tagsDone(rel.getUniqueId());
    279                                 }
    280                         }
    281                         map.mapDone();
    282                 }
    283         }
     56    private static String title = tr("SeaChart Editor");
     57    public static JFrame editFrame = null;
     58    public static ShowFrame showFrame = null;
     59    private boolean isOpen = false;
     60    public static PanelMain panelMain = null;
     61    public static PanelS57 panelS57 = null;
     62    public static S57map map = null;
     63    public DataSet data = null;
     64
     65    private final DataSetListener dataSetListener = new DataSetListener() {
     66
     67        @Override
     68        public void dataChanged(DataChangedEvent e) {
     69            makeMap();
     70        }
     71
     72        @Override
     73        public void nodeMoved(NodeMovedEvent e) {
     74            makeMap();
     75        }
     76
     77        @Override
     78        public void otherDatasetChange(AbstractDatasetChangedEvent e) {
     79            makeMap();
     80        }
     81
     82        @Override
     83        public void primitivesAdded(PrimitivesAddedEvent e) {
     84            makeMap();
     85        }
     86
     87        @Override
     88        public void primitivesRemoved(PrimitivesRemovedEvent e) {
     89            makeMap();
     90        }
     91
     92        @Override
     93        public void relationMembersChanged(RelationMembersChangedEvent e) {
     94            makeMap();
     95        }
     96
     97        @Override
     98        public void tagsChanged(TagsChangedEvent e) {
     99            makeMap();
     100        }
     101
     102        @Override
     103        public void wayNodesChanged(WayNodesChangedEvent e) {
     104            makeMap();
     105        }
     106    };
     107
     108    public SCeditAction() {
     109        super(title, "SC", title, null, true);
     110    }
     111
     112    @Override
     113    public void actionPerformed(ActionEvent arg0) {
     114        SwingUtilities.invokeLater(new Runnable() {
     115            @Override
     116            public void run() {
     117                if (!isOpen)
     118                    createFrame();
     119                else
     120                    editFrame.toFront();
     121                isOpen = true;
     122            }
     123        });
     124    }
     125
     126    protected void createFrame() {
     127        editFrame = new JFrame(title);
     128        editFrame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
     129        editFrame.addWindowListener(new java.awt.event.WindowAdapter() {
     130            @Override
     131            public void windowClosing(java.awt.event.WindowEvent e) {
     132                closeDialog();
     133            }
     134        });
     135        editFrame.setSize(new Dimension(480, 480));
     136        editFrame.setLocation(100, 200);
     137        editFrame.setResizable(true);
     138        editFrame.setAlwaysOnTop(true);
     139        editFrame.setVisible(true);
     140        panelMain = new PanelMain();
     141        editFrame.add(panelMain);
     142
     143        panelS57 = new PanelS57();
     144        editFrame.add(panelS57);
     145
     146        showFrame = new ShowFrame(tr("Seamark Inspector"));
     147        showFrame.setSize(new Dimension(300, 300));
     148        showFrame.setLocation(50, 400);
     149        showFrame.setResizable(false);
     150        showFrame.setAlwaysOnTop(true);
     151        showFrame.setEnabled(true);
     152        showFrame.setVisible(false);
     153
     154        Main.getLayerManager().addAndFireActiveLayerChangeListener(this);
     155        DataSet.addSelectionListener(this);
     156    }
     157
     158    public void closeDialog() {
     159        if (isOpen) {
     160                Main.getLayerManager().removeActiveLayerChangeListener(this);
     161            editFrame.setVisible(false);
     162            editFrame.dispose();
     163            data = null;
     164            map = null;
     165        }
     166        isOpen = false;
     167    }
     168
     169    @Override
     170    public void activeOrEditLayerChanged(ActiveLayerChangeEvent e) {
     171        if (e.getPreviousEditLayer() != null) {
     172            e.getPreviousEditLayer().data.removeDataSetListener(dataSetListener);
     173        }
     174        OsmDataLayer newLayer = Main.getLayerManager().getEditLayer();
     175        if (newLayer != null) {
     176            newLayer.data.addDataSetListener(dataSetListener);
     177            data = newLayer.data;
     178            makeMap();
     179        } else {
     180            data = null;
     181            map = null;
     182        }
     183    }
     184
     185    @Override
     186    public void selectionChanged(Collection<? extends OsmPrimitive> selection) {
     187        OsmPrimitive nextFeature = null;
     188        OsmPrimitive feature = null;
     189
     190        showFrame.setVisible(false);
     191        panelMain.clearMark();
     192        if (map != null) {
     193            for (OsmPrimitive osm : selection) {
     194                nextFeature = osm;
     195                if (selection.size() == 1) {
     196                    if (nextFeature.compareTo(feature) != 0) {
     197                        feature = nextFeature;
     198                        Feature id = map.index.get(feature.getUniqueId());
     199                        if (id != null) {
     200                            panelMain.parseMark(id);
     201                            showFrame.setVisible(true);
     202                            showFrame.showFeature(feature, map);
     203                        }
     204                    }
     205                } else {
     206                    showFrame.setVisible(false);
     207                    PanelMain.setStatus(tr("Select only one object"), Color.orange);
     208                }
     209            }
     210            if (nextFeature == null) {
     211                feature = null;
     212                panelMain.clearMark();
     213                showFrame.setVisible(false);
     214                PanelMain.setStatus(tr("Select a map object"), Color.yellow);
     215            }
     216        }
     217    }
     218
     219    void makeMap() {
     220        map = new S57map(true);
     221        if (data != null) {
     222            double minlat = 90;
     223            double maxlat = -90;
     224            double minlon = 180;
     225            double maxlon = -180;
     226            for (Bounds bounds : data.getDataSourceBounds()) {
     227                if (bounds.getMinLat() < minlat) {
     228                    minlat = bounds.getMinLat();
     229                }
     230                if (bounds.getMaxLat() > maxlat) {
     231                    maxlat = bounds.getMaxLat();
     232                }
     233                if (bounds.getMinLon() < minlon) {
     234                    minlon = bounds.getMinLon();
     235                }
     236                if (bounds.getMaxLon() > maxlon) {
     237                    maxlon = bounds.getMaxLon();
     238                }
     239            }
     240            map.addNode(1, maxlat, minlon);
     241            map.addNode(2, minlat, minlon);
     242            map.addNode(3, minlat, maxlon);
     243            map.addNode(4, maxlat, maxlon);
     244            map.bounds.minlat = Math.toRadians(minlat);
     245            map.bounds.maxlat = Math.toRadians(maxlat);
     246            map.bounds.minlon = Math.toRadians(minlon);
     247            map.bounds.maxlon = Math.toRadians(maxlon);
     248            for (Node node : data.getNodes()) {
     249                LatLon coor = node.getCoor();
     250                if (coor != null) {
     251                    map.addNode(node.getUniqueId(), coor.lat(), coor.lon());
     252                    for (Entry<String, String> entry : node.getKeys().entrySet()) {
     253                        map.addTag(entry.getKey(), entry.getValue());
     254                    }
     255                    map.tagsDone(node.getUniqueId());
     256                }
     257            }
     258            for (Way way : data.getWays()) {
     259                if (way.getNodesCount() > 0) {
     260                    map.addEdge(way.getUniqueId());
     261                    for (Node node : way.getNodes()) {
     262                        map.addToEdge((node.getUniqueId()));
     263                    }
     264                    for (Entry<String, String> entry : way.getKeys().entrySet()) {
     265                        map.addTag(entry.getKey(), entry.getValue());
     266                    }
     267                    map.tagsDone(way.getUniqueId());
     268                }
     269            }
     270            for (Relation rel : data.getRelations()) {
     271                if (rel.isMultipolygon() && (rel.getMembersCount() > 0)) {
     272                    map.addArea(rel.getUniqueId());
     273                    for (RelationMember mem : rel.getMembers()) {
     274                        if (mem.getType() == OsmPrimitiveType.WAY)
     275                            map.addToArea(mem.getUniqueId(), (mem.getRole().equals("outer")));
     276                    }
     277                    for (Entry<String, String> entry : rel.getKeys().entrySet()) {
     278                        map.addTag(entry.getKey(), entry.getValue());
     279                    }
     280                    map.tagsDone(rel.getUniqueId());
     281                }
     282            }
     283            map.mapDone();
     284        }
     285    }
    284286}
Note: See TracChangeset for help on using the changeset viewer.