Ignore:
Timestamp:
2010-12-21T19:09:24+01:00 (14 years ago)
Author:
postfix
Message:

in project harbour more search abilities

Location:
applications/editors/josm/plugins/smed/plugs
Files:
1 added
6 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/smed/plugs/harbour/src/harbour/dialogs/HarbourAction.java

    r24677 r24832  
    2525import org.openstreetmap.josm.gui.layer.Layer;
    2626import org.openstreetmap.josm.gui.layer.OsmDataLayer;
     27import javax.swing.SwingConstants;
    2728
    2829public class HarbourAction implements PropertyChangeListener, LayerChangeListener, EditLayerChangeListener, ComponentListener {
     
    6162        private JPanel curPanel = null;
    6263        private PanelSearchPois panelSearchPois = null;
    63         private static LayerHarbour curLayer = new LayerHarbour("Harbour");
     64        private static LayerHarbour curLayer = null;
    6465       
    6566        public HarbourAction() {
     
    9091                panelSearchPois.setBounds(rect);
    9192                panelSearchPois.setVisible(false);
     93               
     94                curLayer = new LayerHarbour("Harbour", panelSearchPois);
     95                panelSearchPois.setLayerHarbour(curLayer);
    9296        }
    9397       
     
    190194                                        relButton.setEnabled(true);
    191195                                       
     196                                        Main.map.mapView.removeLayerChangeListener(curLayer);
    192197                                        Main.main.removeLayer(curLayer);
    193198                                        curPanel = panelGeneral;
     
    224229                                        relButton.setEnabled(true);
    225230                                       
     231                                        Main.map.mapView.removeLayerChangeListener(curLayer);
    226232                                        Main.main.removeLayer(curLayer);
    227233                                        curPanel = panelLimits;
     
    258264                                        relButton.setEnabled(true);
    259265                                       
    260                                        
     266                                        Main.map.mapView.removeLayerChangeListener(curLayer);
    261267                                        Main.main.removeLayer(curLayer);
    262268                                        curPanel = panelServices;
     
    280286                        envButton.addActionListener(new java.awt.event.ActionListener() {
    281287                                public void actionPerformed(java.awt.event.ActionEvent e) {
     288                                        String name = null;
     289                                       
    282290                                        panelGeneral.setVisible(false);
    283291                                        panelLimits.setVisible(false);
     
    293301                                        relButton.setEnabled(true);
    294302
     303                                        panelSearchPois.iniLayer();
     304                                       
     305                                        name = panelSearchPois.getActiveLayer();
     306                                        if(name != null) curLayer.setName("Harbour - " + name);
     307                                        else curLayer.setName("Harbour");
     308
     309                                        Layer tmp = Main.map.mapView.getActiveLayer();
     310                                       
     311                                        Main.map.mapView.addLayerChangeListener(curLayer);
    295312                                        Main.main.addLayer(curLayer);
     313
     314                                        Main.map.mapView.setActiveLayer(tmp);
     315                                       
    296316                                        curPanel = panelEnv;
    297317                                }
     
    327347                                        relButton.setEnabled(false);
    328348                                       
     349                                        Main.map.mapView.removeLayerChangeListener(curLayer);
    329350                                        Main.main.removeLayer(curLayer);
    330351                                        curPanel = panelRelations;
     
    507528                if (chartButton == null) {
    508529                        chartButton = new JToggleButton();
    509                         chartButton.setBounds(new Rectangle(367, 5, 28, 18));
     530                        chartButton.setBounds(new Rectangle(375, 4, 20, 20));
    510531                        chartButton.setSelected(false);
     532                        chartButton.setIcon(new ImageIcon(getClass().getResource("/images/oseam_20x20.png")));
     533                        chartButton.setHorizontalTextPosition(SwingConstants.LEADING);
    511534                        chartButton.setEnabled(false);
    512535                        chartButton.addActionListener(new java.awt.event.ActionListener() {
     
    519542                                                envButton.setEnabled(false);
    520543                                                relButton.setEnabled(false);
     544                                                panelSearchPois.setVisible(true);
    521545                                               
    522                                                 if(curPanel == panelEnv) {
    523                                                         panelEnv.setVisible(false);
    524                                                         panelSearchPois.setVisible(true);
    525                                                 } else if(curPanel == panelRelations) panelRelations.setVisible(false);
     546                                                if(curPanel == panelEnv) panelEnv.setVisible(false);
     547                                                else if(curPanel == panelRelations) panelRelations.setVisible(false);
     548                                               
    526549                                        } else {
    527550                                                comButton.setEnabled(true);
    528551                                                restButton.setEnabled(true);
    529552                                                servButton.setEnabled(true);
    530                                                 envButton.setEnabled(true);
    531                                                 relButton.setEnabled(true);
     553                                                panelSearchPois.setVisible(false);
    532554                                               
    533555                                                if(curPanel == panelEnv) {
    534556                                                        panelEnv.setVisible(true);
    535                                                         panelSearchPois.setVisible(false);
    536                                                 } else if(curPanel == panelRelations) panelRelations.setVisible(true);
     557                                                        relButton.setEnabled(true);
     558                                                } else if(curPanel == panelRelations) {
     559                                                        panelRelations.setVisible(true);
     560                                                        envButton.setEnabled(true);
     561                                                }
    537562                                        }
    538563                                }
  • applications/editors/josm/plugins/smed/plugs/harbour/src/harbour/layers/LayerHarbour.java

    r24574 r24832  
    11package harbour.layers;
    22
     3import static java.lang.Math.sin;
     4import static java.lang.Math.cos;
     5
     6import harbour.panels.PanelSearchPois;
     7
     8import java.awt.BasicStroke;
     9import java.awt.Color;
    310import java.awt.Graphics2D;
     11import java.awt.Point;
    412
    513import javax.swing.Action;
    614import javax.swing.Icon;
     15import javax.swing.JComboBox;
    716
     17import org.openstreetmap.josm.Main;
    818import org.openstreetmap.josm.data.Bounds;
     19import org.openstreetmap.josm.data.coor.LatLon;
     20import org.openstreetmap.josm.data.osm.DataSet;
     21import org.openstreetmap.josm.data.osm.Node;
    922import org.openstreetmap.josm.data.osm.visitor.BoundingXYVisitor;
    1023import org.openstreetmap.josm.gui.MapView;
     24import org.openstreetmap.josm.gui.MapView.LayerChangeListener;
    1125import org.openstreetmap.josm.gui.layer.Layer;
     26import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    1227import org.openstreetmap.josm.tools.ImageProvider;
    1328
    14 public class LayerHarbour extends Layer {
    15 
    16         public LayerHarbour(String name) {
    17                 super(name);
     29public class LayerHarbour extends OsmDataLayer implements LayerChangeListener {
     30       
     31        private JComboBox layerBox              = null;
     32        private PanelSearchPois panel   = null;
     33        private static DataSet ds               = new DataSet();
     34        private double radius                   = -1.0;
     35        private LatLon lm                               = null;
     36        private boolean isChanged               = true;
     37       
     38        public LayerHarbour(String name,PanelSearchPois panel) {
     39                super(ds, name, null);
     40               
     41                this.panel = panel;
     42                panel.setPois(ds);
     43                layerBox = panel.getLayerComboBox();
    1844        }
    1945
     
    5480
    5581        @Override
    56         public void paint(Graphics2D arg0, MapView arg1, Bounds arg2) {
    57                 // TODO Auto-generated method stub
     82        public void paint(Graphics2D g, MapView mv, Bounds box) {
     83                isChanged = false;
    5884               
     85                Point mp = null;
     86                Point mx = null;
     87                               
     88                if(radius > 0.0 && lm != null) {
     89                        LatLon lx = new LatLon(lm.lat(), lm.lon() + radius/65.0);
     90                       
     91                        mp = mv.getPoint(lm);
     92                        mx = mv.getPoint(lx);
     93               
     94                        int r = mx.x - mp.x;
     95
     96                        g.setColor(Color.RED);
     97                        g.setStroke(new BasicStroke(3));
     98               
     99                        g.drawOval(mp.x-r, mp.y-r, 2*r, 2*r);
     100                       
     101                        g.setStroke(new BasicStroke(1));
     102                }
     103               
     104                super.paint(g, mv, box);               
    59105        }
    60106
     
    65111        }
    66112
     113        @Override
     114        public void activeLayerChange(Layer oldLayer, Layer newLayer) {
     115                if(newLayer instanceof OsmDataLayer) {
     116                        String n  = newLayer.getName();
     117                       
     118                        setName("Harbour - " + n);
     119                        layerBox.setSelectedItem(n);
     120                }
     121                else setName("Harbour");
     122        }
     123
     124        @Override
     125        public void layerAdded(Layer arg0) {
     126                // TODO Auto-generated method stub
     127               
     128        }
     129
     130        @Override
     131        public void layerRemoved(Layer arg0) {
     132                // TODO Auto-generated method stub
     133               
     134        }
     135
     136        public void setRadius(double r) {
     137                if(radius != r){
     138                        radius = r;
     139                       
     140                        isChanged = true;
     141                        Main.map.repaint();
     142                }
     143        }
     144       
     145        public boolean isChanged() { return isChanged; }
     146
     147        public void setCenter(LatLon coor) {
     148                if(lm != coor) {
     149                        lm = coor;
     150                       
     151                        isChanged = true;
     152                        Main.map.repaint();
     153                }
     154        }
     155
     156        public boolean isNodeinCircle(Node n) {
     157                if(radius < 0.0) return true;
     158
     159                LatLon coor = n.getCoor();
     160               
     161                if(coor == null) return false;
     162                return coor.greatCircleDistance(lm) < radius * 1000;
     163        }
    67164}
  • applications/editors/josm/plugins/smed/plugs/harbour/src/harbour/models/SearchTableModel.java

    r24751 r24832  
    1212            "Show"};
    1313        private Object[][] data = {
    14                         {"amenity","",                          new Boolean(false) },
    1514                        {"amenity","bank",                      new Boolean(false) },
    1615                        {"amenity","cafe",                      new Boolean(false) },
     
    2524                        {"amenity","telephone",         new Boolean(false) },
    2625                        {"amenity","toilets",           new Boolean(false) },
    27                         {"information","",                      new Boolean(false) },
    2826                        {"information","board",         new Boolean(false) },
    2927                        {"information","citymap",       new Boolean(false) },
     
    7573    }
    7674   
     75    public Boolean isWanted(int i)      { return (Boolean) data[i][2]; }
     76    public String getKey(int i)         { return (String) data[i][0]; }
     77    public String getValue(int i)       { return (String) data[i][1]; }
    7778}
  • applications/editors/josm/plugins/smed/plugs/harbour/src/harbour/panels/PanelSearchPois.java

    r24751 r24832  
    99import java.awt.Rectangle;
    1010import java.awt.Font;
     11import java.awt.event.FocusEvent;
     12import java.awt.event.FocusListener;
     13import java.awt.event.KeyEvent;
     14import java.beans.PropertyChangeEvent;
     15import java.beans.PropertyChangeListener;
     16import java.util.ArrayList;
     17import java.util.Collection;
     18import java.util.Iterator;
     19import java.util.List;
     20import java.util.Map;
     21
    1122import javax.swing.JTextField;
    1223import javax.swing.JButton;
     
    1425import javax.swing.JTable;
    1526import javax.swing.JComboBox;
     27import javax.swing.table.TableModel;
     28
     29import org.openstreetmap.josm.Main;
     30import org.openstreetmap.josm.data.coor.LatLon;
     31import org.openstreetmap.josm.data.gpx.WayPoint;
     32import org.openstreetmap.josm.data.osm.DataSet;
     33import org.openstreetmap.josm.data.osm.Node;
     34import org.openstreetmap.josm.gui.MapView;
     35import org.openstreetmap.josm.gui.layer.Layer;
     36import org.openstreetmap.josm.gui.layer.OsmDataLayer;
     37
     38import harbour.layers.LayerHarbour;
    1639import harbour.models.SearchTableModel;
    1740
    18 public class PanelSearchPois extends JPanel {
     41public class PanelSearchPois extends JPanel implements PropertyChangeListener{
    1942
    2043        private static final long serialVersionUID = 1L;
    21         private JLabel radLabel = null;
    22         private JTextField radTextField = null;
    23         private JLabel unitLabel = null;
    24         private JButton jButton = null;
    25         private JScrollPane jScrollPane = null;
    26         private JTable jTable = null;
    27         private JLabel layerLabel = null;
    28         private JComboBox layerComboBox = null;
    29 
     44        private JLabel radLabel                         = null;
     45        private JTextField radTextField         = null;
     46        private JLabel unitLabel                        = null;
     47        private JButton searchButton            = null;
     48        private JScrollPane jScrollPane         = null;
     49        private JTable searchTable                      = null;
     50        private JLabel layerLabel                       = null;
     51        private JComboBox layerComboBox         = null;
     52        private String activeLayer                      = null;
     53        private LayerHarbour layerHarbour       = null;  //  @jve:decl-index=0:
     54        private List<Layer> layers                      = new ArrayList<Layer>();  //  @jve:decl-index=0:
     55        private JButton setButton                       = null;
     56        private DataSet pois                            = null;
     57       
    3058        /**
    3159         * This is the default constructor
     
    4977                unitLabel.setBounds(new Rectangle(130, 240, 20, 21));
    5078                unitLabel.setFont(new Font("Dialog", Font.PLAIN, 12));
    51                 unitLabel.setText("m");
     79                unitLabel.setText("km");
    5280                radLabel = new JLabel();
    5381                radLabel.setBounds(new Rectangle(5, 240, 55, 20));
     
    6088                this.add(getRadTextField(), null);
    6189                this.add(unitLabel, null);
    62                 this.add(getJButton(), null);
     90                this.add(getSearchButton(), null);
    6391                this.add(getJScrollPane(), null);
    6492                this.add(layerLabel, null);
    6593                this.add(getLayerComboBox(), null);
     94                this.add(getSetButton(), null);
    6695        }
    6796
     
    75104                        radTextField = new JTextField();
    76105                        radTextField.setBounds(new Rectangle(60, 240, 70, 20));
     106                        radTextField.addFocusListener(new FocusListener() {
     107
     108                                @Override
     109                                public void focusGained(FocusEvent arg0) {
     110                                        // nothing to do yet
     111                                }
     112
     113                                @Override
     114                                public void focusLost(FocusEvent arg0) {
     115                                        double r = Double.parseDouble(radTextField.getText());
     116
     117                                        layerHarbour.setRadius(r);
     118                                }
     119                               
     120                        });
     121                       
     122                        radTextField.addKeyListener(new java.awt.event.KeyAdapter() {
     123                                public void keyTyped(java.awt.event.KeyEvent e) {
     124                                        if(e.getKeyChar() == KeyEvent.VK_ENTER) {
     125                                                double r = Double.parseDouble(radTextField.getText());
     126
     127                                                layerHarbour.setRadius(r);
     128                                        }
     129                                }
     130                        });
    77131                }
    78132                return radTextField;
     
    80134
    81135        /**
    82          * This method initializes jButton     
     136         * This method initializes searchButton
    83137         *     
    84138         * @return javax.swing.JButton 
    85139         */
    86         private JButton getJButton() {
    87                 if (jButton == null) {
    88                         jButton = new JButton();
    89                         jButton.setBounds(new Rectangle(240, 240, 80, 20));
    90                         jButton.setText("Suche");
    91                 }
    92                 return jButton;
     140        private JButton getSearchButton() {
     141                if (searchButton == null) {
     142                        searchButton = new JButton();
     143                        searchButton.setBounds(new Rectangle(240, 240, 80, 20));
     144                        searchButton.setFont(new Font("Dialog", Font.PLAIN, 12));
     145                        searchButton.setText("Suche");
     146                        searchButton.addActionListener(new java.awt.event.ActionListener() {
     147                                public void actionPerformed(java.awt.event.ActionEvent e) {
     148                                        searchPois();
     149                                }
     150                        });
     151                }
     152
     153                return searchButton;
    93154        }
    94155
     
    102163                        jScrollPane = new JScrollPane();
    103164                        jScrollPane.setBounds(new Rectangle(10, 35, 310, 195));
    104                         jScrollPane.setViewportView(getJTable());
     165                        jScrollPane.setViewportView(getSearchTable());
    105166                }
    106167                return jScrollPane;
     
    108169
    109170        /**
    110          * This method initializes jTable       
     171         * This method initializes searchTable 
    111172         *     
    112173         * @return javax.swing.JTable   
    113174         */
    114         private JTable getJTable() {
    115                 if (jTable == null) {
    116                         jTable = new JTable();
    117                         jTable.setModel(new SearchTableModel());
    118                 }
    119                 return jTable;
     175        private JTable getSearchTable() {
     176                if (searchTable == null) {
     177                        searchTable = new JTable();
     178                        searchTable.setModel(new SearchTableModel());
     179                }
     180                return searchTable;
    120181        }
    121182
     
    125186         * @return javax.swing.JComboBox       
    126187         */
    127         private JComboBox getLayerComboBox() {
     188        public JComboBox getLayerComboBox() {
    128189                if (layerComboBox == null) {
    129190                        layerComboBox = new JComboBox();
    130191                        layerComboBox.setBounds(new Rectangle(70, 5, 250, 20));
     192                        layerComboBox.addActionListener(new java.awt.event.ActionListener() {
     193                                public void actionPerformed(java.awt.event.ActionEvent e) {
     194                                        int i = layerComboBox.getSelectedIndex();
     195                                       
     196                                        if(i >= 0) {
     197                                                Main.map.mapView.setActiveLayer(layers.get(i));
     198                                        }
     199                                }
     200                        });
    131201                }
    132202                return layerComboBox;
    133203        }
    134204
     205        @Override
     206        public void propertyChange(PropertyChangeEvent event) {
     207                Object src = event.getSource();
     208               
     209                System.out.println("Hello, world");
     210               
     211                if (src instanceof MapView) {
     212                        MapView mapView = (MapView) src;
     213                       
     214                        for (Layer l: mapView.getAllLayers()) {
     215                                if(l instanceof OsmDataLayer) layerComboBox.addItem(l.getName());
     216                        }
     217                }
     218
     219        }
     220
     221        public void iniLayer() {
     222                Layer a = Main.map.mapView.getActiveLayer();
     223                String name = null;
     224                 
     225                layerComboBox.removeAllItems();
     226                layers.clear();
     227
     228                for (Layer l: Main.map.mapView.getAllLayers()) {
     229                        if(l instanceof OsmDataLayer) {
     230                                name = l.getName();
     231                                layers.add(l);
     232                               
     233                                layerComboBox.addItem(name);
     234                                if(l.equals(a)) activeLayer = name;
     235                        }
     236                }
     237        }
     238
     239        public String getActiveLayer() { return activeLayer; }
     240        public void setLayerHarbour(LayerHarbour layer) { layerHarbour = layer; }
     241
     242        /**
     243         * This method initializes setButton   
     244         *     
     245         * @return javax.swing.JButton 
     246         */
     247        private JButton getSetButton() {
     248                if (setButton == null) {
     249                        setButton = new JButton();
     250                        setButton.setBounds(new Rectangle(160, 240, 55, 20));
     251                        setButton.setFont(new Font("Dialog", Font.PLAIN, 12));
     252                        setButton.setText("Set");
     253                        setButton.addActionListener(new java.awt.event.ActionListener() {
     254                                public void actionPerformed(java.awt.event.ActionEvent e) {
     255                                        DataSet ds = Main.main.getCurrentDataSet();
     256                                        Collection<Node> selection = ds.getSelectedNodes();
     257                                        int nodes = selection.size();
     258
     259                                        if(nodes != 0) {
     260                                                Iterator<Node> it = selection.iterator();
     261                                                Node node = it.next();
     262                                               
     263                                                layerHarbour.setCenter(node.getCoor());
     264                                        }
     265                                }
     266                        });
     267                }
     268                return setButton;
     269        }
     270
     271        public void searchPois() {
     272                DataSet data = Main.main.getCurrentDataSet();
     273                Collection<Node> nodes = data.getNodes();
     274                SearchTableModel searchModel = (SearchTableModel) searchTable.getModel();
     275
     276                pois.clear();
     277               
     278                for(Node n : nodes) {
     279                        if(layerHarbour.isNodeinCircle(n)) {
     280                                Map<String, String> keys = n.getKeys();
     281                               
     282                                for(int i = 0; i < searchTable.getRowCount(); i++){
     283                                        if(searchModel.isWanted(i)) {
     284                                                String key = searchModel.getKey(i);
     285                                               
     286                                                if(keys.containsKey(key)) {
     287                                                        String type = keys.get(key);
     288                                                        if(type.equals(searchModel.getValue(i))) {
     289                                                                Node nc = new Node(1);
     290                                                               
     291                                                                nc.cloneFrom(n);
     292                                                                pois.addPrimitive(nc);
     293                                                        }
     294                                                }
     295                                        }
     296                                }
     297                        }
     298                }
     299        }
     300       
     301        public void setPois(DataSet pois) { this.pois = pois; }
     302       
    135303}
  • applications/editors/josm/plugins/smed/plugs/harbour/src/harbour/panels/PanelServices.java

    r24751 r24832  
    11package harbour.panels;
     2
    23
    34import harbour.widgets.CraneTable;
     
    9293                DLLabel = new JLabel();
    9394                DLLabel.setBounds(new Rectangle(3, 165, 147, 20));
     95                DLLabel.setFont(new Font("Dialog", Font.PLAIN, 12));
    9496                DLLabel.setText("weitere Dienstleistungen");
    9597                moorLabel = new JLabel();
     
    99101                loadLabel = new JLabel();
    100102                loadLabel.setBounds(new Rectangle(3, 50, 97, 16));
     103                loadLabel.setFont(new Font("Dialog", Font.PLAIN, 12));
    101104                loadLabel.setText("Laden / Entladen");
    102105                airLabel = new JLabel();
     
    614617                if (craneScrollPane == null) {
    615618                        craneScrollPane = new CraneTable();
    616                         craneScrollPane.setBounds(new Rectangle(3, 90, 207, 66));
     619                        craneScrollPane.setBounds(new Rectangle(3, 90, 207, 71));
    617620                }
    618621                return craneScrollPane;
  • applications/editors/josm/plugins/smed/plugs/smed_about/src/smed_about/SmedAbout.java

    r24632 r24832  
    9191            aboutCopyright.setBounds(new Rectangle(125, 0, 245, 55));
    9292            aboutCopyright.setText("<HTML><BODY>Copyright (c) 2009 / 2010<BR><center>by" +
    93                                         "<BR>Werner Kšnig & Malcolm Herring</BODY></HTML>");
     93                                        "<BR>Werner König & Malcolm Herring</BODY></HTML>");
    9494
    9595            aboutAuthors = new JLabel();
    9696            aboutAuthors.setBounds(new Rectangle(30, 50
    9797                        , 340, 30));
    98             aboutAuthors.setText("Authors: Werner Kšnig and Malcolm Herring");
     98            aboutAuthors.setText("Authors: Werner König and Malcolm Herring");
    9999
    100100            aboutVersion = new JLabel();
Note: See TracChangeset for help on using the changeset viewer.