| 1 | package oseam;
|
|---|
| 2 |
|
|---|
| 3 | import java.awt.Color;
|
|---|
| 4 | import java.awt.Dimension;
|
|---|
| 5 | import java.awt.event.ActionEvent;
|
|---|
| 6 | import java.util.Collection;
|
|---|
| 7 |
|
|---|
| 8 | import javax.swing.JFrame;
|
|---|
| 9 | import javax.swing.JTextField;
|
|---|
| 10 | import javax.swing.SwingUtilities;
|
|---|
| 11 | import javax.swing.WindowConstants;
|
|---|
| 12 |
|
|---|
| 13 | import org.openstreetmap.josm.Main;
|
|---|
| 14 | import org.openstreetmap.josm.actions.JosmAction;
|
|---|
| 15 | import org.openstreetmap.josm.data.SelectionChangedListener;
|
|---|
| 16 | import org.openstreetmap.josm.data.osm.DataSet;
|
|---|
| 17 | import org.openstreetmap.josm.data.osm.Node;
|
|---|
| 18 | import org.openstreetmap.josm.data.osm.OsmPrimitive;
|
|---|
| 19 |
|
|---|
| 20 | import static org.openstreetmap.josm.tools.I18n.tr;
|
|---|
| 21 |
|
|---|
| 22 | import panels.PanelMain;
|
|---|
| 23 |
|
|---|
| 24 | public class OSeaMAction extends JosmAction {
|
|---|
| 25 |
|
|---|
| 26 | private static final long serialVersionUID = 1L;
|
|---|
| 27 | private static String editor = tr("SeaMap Editor");
|
|---|
| 28 | public static JFrame frame = null;
|
|---|
| 29 | private boolean isOpen = false;
|
|---|
| 30 | public JTextField messageBar = null;
|
|---|
| 31 |
|
|---|
| 32 | private OSeaMAction dlg = this;
|
|---|
| 33 | public PanelMain panelMain = null;
|
|---|
| 34 |
|
|---|
| 35 | public Node node = null;
|
|---|
| 36 | private Collection<? extends OsmPrimitive> Selection = null;
|
|---|
| 37 |
|
|---|
| 38 | public SelectionChangedListener SmpListener = new SelectionChangedListener() {
|
|---|
| 39 | public void selectionChanged(
|
|---|
| 40 | Collection<? extends OsmPrimitive> newSelection) {
|
|---|
| 41 | Node nextNode = null;
|
|---|
| 42 | Selection = newSelection;
|
|---|
| 43 |
|
|---|
| 44 | for (OsmPrimitive osm : Selection) {
|
|---|
| 45 | if (osm instanceof Node) {
|
|---|
| 46 | nextNode = (Node) osm;
|
|---|
| 47 | if (Selection.size() == 1) {
|
|---|
| 48 | if (nextNode.compareTo(node) != 0) {
|
|---|
| 49 | node = nextNode;
|
|---|
| 50 | panelMain.mark.parseMark(node);
|
|---|
| 51 | }
|
|---|
| 52 | } else {
|
|---|
| 53 | node = null;
|
|---|
| 54 | panelMain.mark.clrMark();
|
|---|
| 55 | messageBar.setText(Messages.getString("OneNode"));
|
|---|
| 56 | }
|
|---|
| 57 | }
|
|---|
| 58 | }
|
|---|
| 59 | if (nextNode == null) {
|
|---|
| 60 | node = null;
|
|---|
| 61 | panelMain.mark.clrMark();
|
|---|
| 62 | messageBar.setText(Messages.getString("SelectNode"));
|
|---|
| 63 | }
|
|---|
| 64 | }
|
|---|
| 65 | };
|
|---|
| 66 |
|
|---|
| 67 | public OSeaMAction() {
|
|---|
| 68 | super(editor, "Smed", editor, null, true);
|
|---|
| 69 | DataSet.addSelectionListener(SmpListener);
|
|---|
| 70 | String str = Main.pref.get("mappaint.style.sources");
|
|---|
| 71 | if (!str.contains("dev.openseamap.org")) {
|
|---|
| 72 | if (!str.isEmpty())
|
|---|
| 73 | str += new String(new char[] { 0x1e });
|
|---|
| 74 | Main.pref.put("mappaint.style.sources", str
|
|---|
| 75 | + "http://dev.openseamap.org/josm/seamark_styles.xml");
|
|---|
| 76 | }
|
|---|
| 77 | }
|
|---|
| 78 |
|
|---|
| 79 | @Override
|
|---|
| 80 | public void actionPerformed(ActionEvent arg0) {
|
|---|
| 81 | SwingUtilities.invokeLater(new Runnable() {
|
|---|
| 82 | public void run() {
|
|---|
| 83 | if (!isOpen)
|
|---|
| 84 | createFrame();
|
|---|
| 85 | else
|
|---|
| 86 | frame.toFront();
|
|---|
| 87 | isOpen = true;
|
|---|
| 88 | }
|
|---|
| 89 | });
|
|---|
| 90 | }
|
|---|
| 91 |
|
|---|
| 92 | protected void createFrame() {
|
|---|
| 93 | frame = new JFrame(editor);
|
|---|
| 94 | frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
|
|---|
| 95 | frame.setResizable(true);
|
|---|
| 96 | frame.setAlwaysOnTop(false);
|
|---|
| 97 |
|
|---|
| 98 | frame.addWindowListener(new java.awt.event.WindowAdapter() {
|
|---|
| 99 | public void windowClosing(java.awt.event.WindowEvent e) {
|
|---|
| 100 | closeDialog();
|
|---|
| 101 | }
|
|---|
| 102 | });
|
|---|
| 103 | frame.setSize(new Dimension(400, 400));
|
|---|
| 104 | frame.setLocation(100, 200);
|
|---|
| 105 | frame.setAlwaysOnTop(true);
|
|---|
| 106 | frame.setVisible(true);
|
|---|
| 107 | messageBar = new JTextField();
|
|---|
| 108 | messageBar.setBounds(10, 355, 380, 20);
|
|---|
| 109 | messageBar.setEditable(false);
|
|---|
| 110 | messageBar.setBackground(Color.WHITE);
|
|---|
| 111 | frame.add(messageBar);
|
|---|
| 112 | panelMain = new PanelMain(dlg);
|
|---|
| 113 | frame.add(panelMain);
|
|---|
| 114 | panelMain.syncPanel();
|
|---|
| 115 | // System.out.println("hello");
|
|---|
| 116 | }
|
|---|
| 117 |
|
|---|
| 118 | public void closeDialog() {
|
|---|
| 119 | if (isOpen) {
|
|---|
| 120 | frame.setVisible(false);
|
|---|
| 121 | frame.dispose();
|
|---|
| 122 | }
|
|---|
| 123 | isOpen = false;
|
|---|
| 124 | }
|
|---|
| 125 |
|
|---|
| 126 | }
|
|---|