Ignore:
Timestamp:
2018-01-04T11:05:03+01:00 (7 years ago)
Author:
rebeccas95
Message:

Update indoorhelper plugin to support the Simple Indoor Tagging scheme

File:
1 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/indoorhelper/src/views/LevelSelectorView.java

    r32637 r33974  
    1 /*
    2  * Indoorhelper is a JOSM plug-in to support users when creating their own indoor maps.
    3  *  Copyright (C) 2016  Erik Gruschka
    4  *
    5  *  This program is free software: you can redistribute it and/or modify
    6  *  it under the terms of the GNU General Public License as published by
    7  *  the Free Software Foundation, either version 3 of the License, or
    8  *  (at your option) any later version.
    9  *
    10  *  This program is distributed in the hope that it will be useful,
    11  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
    12  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    13  *  GNU General Public License for more details.
    14  *
    15  *  You should have received a copy of the GNU General Public License
    16  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
    17  */
    18 
    191package views;
    202
     
    224
    235import java.awt.BorderLayout;
    24 import java.awt.Container;
    256import java.awt.GridBagConstraints;
    267import java.awt.GridBagLayout;
    278import java.awt.Insets;
    289import java.awt.event.ActionListener;
     10import java.awt.event.FocusEvent;
     11import java.awt.event.FocusListener;
     12import java.awt.event.WindowListener;
    2913
    3014import javax.swing.JButton;
     
    3216import javax.swing.JLabel;
    3317import javax.swing.JPanel;
    34 import javax.swing.JSpinner;
    35 import javax.swing.JSpinner.DefaultEditor;
    3618import javax.swing.border.EmptyBorder;
    3719
     20import org.openstreetmap.josm.gui.widgets.DisableShortcutsOnFocusGainedTextField;
     21
    3822/**
    39  * Class for the pop-up window which provides an level selector to get a user input.
    40  * In this window the user declares the lowest and the highest level of the building he wants to map.
     23 * This is the level selector toolbox of the indoorhelper plug-in.
    4124 *
    42  * @author egru
     25 * @author rebsc
    4326 *
    4427 */
    45 
    46 @SuppressWarnings("serial")
    4728public class LevelSelectorView extends JFrame {
    4829
    49     private JPanel dialogPane;
     30        private static final long serialVersionUID = 1L;
     31        private JPanel dialogPane;
    5032    private JPanel contentPanel;
    51     private JLabel minLabel;
    52     private JSpinner minSpinner;
    53     private JLabel maxLabel;
    54     private JSpinner maxSpinner;
     33    private JPanel infoBar;
    5534    private JPanel buttonBar;
    5635    private JButton okButton;
    5736    private JButton cancelButton;
     37    private JLabel label1;
     38    private JLabel label2;
     39    private DisableShortcutsOnFocusGainedTextField field;
    5840
    5941    public LevelSelectorView() {
     
    6446        dialogPane = new JPanel();
    6547        contentPanel = new JPanel();
    66         minLabel = new JLabel();
    67         minSpinner = new JSpinner();
    68         maxLabel = new JLabel();
    69         maxSpinner = new JSpinner();
     48        infoBar = new JPanel();
    7049        buttonBar = new JPanel();
    7150        okButton = new JButton();
    7251        cancelButton = new JButton();
     52        label1 = new JLabel();
     53        label2 = new JLabel();
     54        field = new DisableShortcutsOnFocusGainedTextField();
    7355
    7456        //======== this ========
    75         setTitle(tr("Level Selection"));
    76         Container contentPane = getContentPane();
     57        setTitle(tr("Add a new level"));
     58        java.awt.Container contentPane = getContentPane();
    7759        contentPane.setLayout(new BorderLayout());
    7860
     
    8264            dialogPane.setLayout(new BorderLayout());
    8365
     66
     67                //======== infoBar ========
     68                {
     69
     70                        //---- Label1 ----
     71                        label1.setText(tr("<html> Please insert the new level number you want to add.<br> "
     72                                        + " <i>Info</i>: <br> If the OK button got pressed you will switch to the drawing action.<br>"
     73                                        + "To finish the new object please press the spacebar. The new level<br>will be tagged automatically. </html>"));
     74                        infoBar.add(label1);
     75                }
     76                dialogPane.add(infoBar,BorderLayout.NORTH);
     77
     78
    8479            //======== contentPanel ========
    8580            {
    86                 contentPanel.setLayout(new GridBagLayout());
     81                contentPanel.setLayout(new GridBagLayout());
    8782                ((GridBagLayout) contentPanel.getLayout()).columnWidths = new int[] {0, 0, 0, 0, 0};
    8883                ((GridBagLayout) contentPanel.getLayout()).rowHeights = new int[] {0, 0, 0, 0, 0, 0};
     
    9085                ((GridBagLayout) contentPanel.getLayout()).rowWeights = new double[] {0.0, 0.0, 0.0, 0.0, 0.0, 1.0E-4};
    9186
    92                 //---- minLabel ----
    93                 minLabel.setText(tr("Lowest Level"));
    94                 contentPanel.add(maxLabel, new GridBagConstraints(0, 0, 2, 1, 0.0, 0.0,
    95                     GridBagConstraints.CENTER, GridBagConstraints.BOTH,
    96                     new Insets(0, 0, 5, 5), 0, 0));
    97                 JSpinner.DefaultEditor minEditor = (DefaultEditor) maxSpinner.getEditor();
    98                 minEditor.getTextField().setColumns(2);
    99                 maxSpinner.setToolTipText(tr("The lowest level of your building."));
    100                 contentPanel.add(maxSpinner, new GridBagConstraints(2, 0, 2, 1, 0.0, 0.0,
    101                     GridBagConstraints.CENTER, GridBagConstraints.BOTH,
    102                     new Insets(0, 0, 5, 0), 0, 0));
    10387
    104                 //---- maxLabel ----
    105                 maxLabel.setText(tr("Highest Level"));
    106                 contentPanel.add(minLabel, new GridBagConstraints(0, 2, 2, 1, 0.0, 0.0,
    107                     GridBagConstraints.CENTER, GridBagConstraints.BOTH,
    108                     new Insets(0, 0, 5, 5), 0, 0));
    109                 JSpinner.DefaultEditor maxEditor = (DefaultEditor) minSpinner.getEditor();
    110                 maxEditor.getTextField().setColumns(2);
    111                 minSpinner.setToolTipText(tr("The highest level of your building."));
    112                 contentPanel.add(minSpinner, new GridBagConstraints(2, 2, 2, 1, 0.0, 0.0,
    113                     GridBagConstraints.CENTER, GridBagConstraints.BOTH,
    114                     new Insets(0, 0, 5, 0), 0, 0));
     88                //---- Label2 ----
     89                label2.setText(tr("level number:"));
     90                contentPanel.add(label2,new GridBagConstraints(0, 0, 3, 1, 0.0, 0.0,
     91                        GridBagConstraints.CENTER, GridBagConstraints.BOTH,
     92                        new Insets(5, 5, 5, 30), 0, 0));
     93
     94                //---- Field ----
     95                field.setToolTipText(tr("Example: '2' or '3'"));
     96                field.addFocusListener(new FocusListener() {
     97
     98                    @Override
     99                    public void focusLost(FocusEvent e) {}
     100
     101                    @Override
     102                    public void focusGained(FocusEvent e) {
     103                        field.selectAll();
     104                    }
     105                });
     106                contentPanel.add(field, new GridBagConstraints(3, 0, 2, 1, 0.0, 0.0,
     107                        GridBagConstraints.CENTER, GridBagConstraints.BOTH,
     108                        new Insets(5, 0, 5, 200), 0, 0));
     109
    115110            }
    116111            dialogPane.add(contentPanel, BorderLayout.CENTER);
     
    126121                okButton.setText(tr("OK"));
    127122                buttonBar.add(okButton, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0,
    128                     GridBagConstraints.CENTER, GridBagConstraints.BOTH,
    129                     new Insets(0, 0, 0, 5), 0, 0));
     123                        GridBagConstraints.CENTER, GridBagConstraints.BOTH,
     124                        new Insets(0, 0, 0, 5), 0, 0));
    130125
    131                 //---- cancelButton ----
    132                 cancelButton.setText(tr("Cancel"));
     126                //---- Button ----
     127               cancelButton.setText(tr("Cancel"));
    133128                buttonBar.add(cancelButton, new GridBagConstraints(2, 0, 1, 1, 0.0, 0.0,
    134                     GridBagConstraints.CENTER, GridBagConstraints.BOTH,
    135                     new Insets(0, 0, 0, 0), 0, 0));
    136             }
    137             dialogPane.add(contentPanel, BorderLayout.CENTER);
    138 
    139             //======== buttonBar ========
    140             {
    141                 buttonBar.setBorder(new EmptyBorder(12, 0, 0, 0));
    142                 buttonBar.setLayout(new GridBagLayout());
    143                 ((GridBagLayout) buttonBar.getLayout()).columnWidths = new int[] {0, 85, 80};
    144                 ((GridBagLayout) buttonBar.getLayout()).columnWeights = new double[] {1.0, 0.0, 0.0};
    145 
    146                 //---- okButton ----
    147                 okButton.setText(tr("OK"));
    148                 buttonBar.add(okButton, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0,
    149                     GridBagConstraints.CENTER, GridBagConstraints.BOTH,
    150                     new Insets(0, 0, 0, 5), 0, 0));
    151 
    152                 //---- cancelButton ----
    153                 cancelButton.setText(tr("Cancel"));
    154                 buttonBar.add(cancelButton, new GridBagConstraints(2, 0, 1, 1, 0.0, 0.0,
    155                     GridBagConstraints.CENTER, GridBagConstraints.BOTH,
    156                     new Insets(0, 0, 0, 0), 0, 0));
     129                        GridBagConstraints.CENTER, GridBagConstraints.BOTH,
     130                        new Insets(0, 0, 0, 0), 0, 0));
    157131            }
    158132            dialogPane.add(buttonBar, BorderLayout.SOUTH);
     
    164138    }
    165139
     140/*************************************************
     141* GETTER
     142*
     143*/
    166144    /**
     145     * Getter for the level number field.
     146     *
     147     * @return the {@link String}
     148     */
     149    public String getLevelNumber() {
     150        return this.field.getText();
     151    }
     152
     153/*************************************************
     154* SELECTOR VIEW LISTENER
     155*
     156*/
     157
     158        /**
    167159     * Set the listener for the OK button.
    168160     *
     
    173165    }
    174166
    175     /**
    176      * Set the listener for the cancel button.
     167        /**
     168     * Set the listener for the Cancel button.
    177169     *
    178170     * @param l the listener to set
     
    183175
    184176    /**
    185      * Getter for the lowest level.
     177     * Set the listener for window {@Link LevelSelectorView}
    186178     *
    187      * @return Integer which represents the lowest level of the building.
     179     * @param l the listener to set
    188180     */
    189     public int getMin() {
    190         return (int) this.minSpinner.getValue();
     181    public void setSelectorWindowListener(WindowListener l) {
     182        this.addWindowListener(l);
    191183    }
    192184
    193     /**
    194      * Getter for the highest level.
    195      *
    196      * @return Integer which represents the highest level of the building.
    197      */
    198     public int getMax() {
    199         return (int) this.maxSpinner.getValue();
    200     }
     185/**
     186*
     187*
     188*
     189*
     190*
     191*
     192*
     193*
     194*/
    201195}
Note: See TracChangeset for help on using the changeset viewer.