Changeset 29623 in osm


Ignore:
Timestamp:
2013-06-04T22:36:05+02:00 (11 years ago)
Author:
donvip
Message:

[josm_terracer] fix #josm6270 - offer building types instead of always using building=yes

Location:
applications/editors/josm/plugins/terracer/src/terracer
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/terracer/src/terracer/HouseNumberInputDialog.java

    r29035 r29623  
    1919import java.util.ArrayList;
    2020import java.util.Iterator;
     21import java.util.List;
    2122import java.util.TreeSet;
    2223
     
    3435import org.openstreetmap.josm.gui.ExtendedDialog;
    3536import org.openstreetmap.josm.gui.tagging.ac.AutoCompletingComboBox;
     37import org.openstreetmap.josm.gui.tagging.ac.AutoCompletionListItem;
    3638import org.openstreetmap.josm.tools.GBC;
    3739
     
    5961    //final private Way street;
    6062    final private String streetName;
     63    final private String buildingType;
    6164    final private boolean relationExists;
    6265    final ArrayList<Node> housenumbers;
     
    7477    private JLabel streetLabel;
    7578    AutoCompletingComboBox streetComboBox;
     79    private JLabel buildingLabel;
     80    AutoCompletingComboBox buildingComboBox;
    7681    private JLabel segmentsLabel;
    7782    JTextField segments;
     
    9095     *        street line or the house numbers which are guaranteed to have the
    9196     *        same name attached (may be null)
     97     * @param buildingType The value to add for building key
    9298     * @param relationExists If the buildings can be added to an existing relation or not.
    9399     * @param housenumbers a list of house numbers in this outline (may be empty)
    94100     */
    95     public HouseNumberInputDialog(HouseNumberInputHandler handler, Way street, String streetName, boolean relationExists, ArrayList<Node> housenumbers) {
     101    public HouseNumberInputDialog(HouseNumberInputHandler handler, Way street, String streetName, String buildingType, boolean relationExists, ArrayList<Node> housenumbers) {
    96102        super(Main.parent,
    97103                tr("Terrace a house"),
     
    102108        //this.street = street;
    103109        this.streetName = streetName;
     110        this.buildingType = buildingType;
    104111        this.relationExists = relationExists;
    105112        this.housenumbers = housenumbers;
     
    163170            messageLabel.setFocusable(false); // Needed so that lowest number can have focus immediately
    164171
    165             interpolationLabel = new JLabel();
    166             interpolationLabel.setText(tr("Interpolation"));
    167             segmentsLabel = new JLabel();
    168             segmentsLabel.setText(tr("Segments"));
    169             streetLabel = new JLabel();
    170             streetLabel.setText(tr("Street"));
    171             loLabel = new JLabel();
    172             loLabel.setText(tr("Lowest Number"));
     172            interpolationLabel = new JLabel(tr("Interpolation"));
     173            segmentsLabel = new JLabel(tr("Segments"));
     174            streetLabel = new JLabel(tr("Street"));
     175            buildingLabel = new JLabel(tr("Building"));
     176            loLabel = new JLabel(tr("Lowest Number"));
    173177            loLabel.setPreferredSize(new Dimension(111, 16));
    174178            loLabel.setToolTipText(tr("Lowest housenumber of the terraced house"));
    175             hiLabel = new JLabel();
    176             hiLabel.setText(tr("Highest Number"));
    177             numbersLabel = new JLabel();
    178             numbersLabel.setText(tr("List of Numbers"));
     179            hiLabel = new JLabel(tr("Highest Number"));
     180            numbersLabel = new JLabel(tr("List of Numbers"));
    179181            loLabel.setPreferredSize(new Dimension(111, 16));
    180182            final String txt = relationExists ? tr("add to existing associatedStreet relation") : tr("create an associatedStreet relation");
     
    204206            } else {
    205207                inputPanel.add(new JLabel(tr("Street name: ")+"\""+streetName+"\""), GBC.eol().insets(3,3,0,0));
     208            }
     209            if (buildingType == null) {
     210                inputPanel.add(buildingLabel, GBC.std().insets(3,3,0,0));
     211                inputPanel.add(getBuilding(), GBC.eol().insets(5,3,0,0));
     212            } else {
     213                inputPanel.add(new JLabel(tr("Building: ")+"\""+buildingType+"\""), GBC.eol().insets(3,3,0,0));
    206214            }
    207215            inputPanel.add(handleRelationCheckBox, GBC.eol().insets(3,3,0,0));
     
    290298     * This method initializes street
    291299     *
    292      * @return javax.swing.JTextField
     300     * @return AutoCompletingComboBox
    293301     */
    294302    private AutoCompletingComboBox getStreet() {
     
    304312        }
    305313        return streetComboBox;
     314    }
     315   
     316    /**
     317     * This method initializes building
     318     *
     319     * @return AutoCompletingComboBox
     320     */
     321    private AutoCompletingComboBox getBuilding() {
     322
     323        if (buildingComboBox == null) {
     324            final List<AutoCompletionListItem> values = Main.main.getCurrentDataSet().getAutoCompletionManager().getValues("building");
     325
     326            buildingComboBox = new AutoCompletingComboBox();
     327            buildingComboBox.setPossibleACItems(values);
     328            buildingComboBox.setEditable(true);
     329            buildingComboBox.setSelectedItem("yes");
     330
     331        }
     332        return buildingComboBox;
    306333    }
    307334
  • applications/editors/josm/plugins/terracer/src/terracer/HouseNumberInputHandler.java

    r29509 r29623  
    3131import org.openstreetmap.josm.data.osm.Relation;
    3232import org.openstreetmap.josm.data.osm.Way;
     33import org.openstreetmap.josm.gui.tagging.ac.AutoCompletingComboBox;
    3334import org.openstreetmap.josm.gui.tagging.ac.AutoCompletionListItem;
    3435
     
    4849    private final Way outline, street;
    4950    private final String streetName;
     51    private final String buildingType;
    5052    private final Node init;
    5153    private final Relation associatedStreet;
     
    6365     *            the house numbers which are guaranteed to have the same name
    6466     *            attached (may be null)
     67     * @param buildingType The value to add for building key
    6568     * @param associatedStreet a relation where we can add the houses (may be null)
    6669     * @param housenumbers a list of house number nodes in this outline (may be empty)
     
    6871     */
    6972    public HouseNumberInputHandler(final TerracerAction terracerAction,
    70             final Way outline, final Node init, final Way street, final String streetName,
     73            final Way outline, final Node init, final Way street, final String streetName, final String buildingType,
    7174            final Relation associatedStreet,
    7275            final ArrayList<Node> housenumbers, final String title) {
     
    7679        this.street = street;
    7780        this.streetName = streetName;
     81        this.buildingType = buildingType;
    7882        this.associatedStreet = associatedStreet;
    7983        this.housenumbers = housenumbers;
    8084
    8185        // This dialog is started modal
    82         this.dialog = new HouseNumberInputDialog(this, street, streetName,
     86        this.dialog = new HouseNumberInputDialog(this, street, streetName, buildingType,
    8387                associatedStreet != null, housenumbers);
    8488
     
    318322                            streetName(),
    319323                            doHandleRelation(),
    320                             doDeleteOutline());
     324                            doDeleteOutline(), buildingType());
    321325                    } catch (UserCancelException ex) {
    322326                        // Ignore
     
    393397            return streetName;
    394398
    395         Object selected = dialog.streetComboBox.getSelectedItem();
     399        return getItemText(dialog.streetComboBox);
     400    }
     401   
     402    /**
     403     * Gets the building type.
     404     *
     405     * @return the building type or null, if not set / invalid.
     406     */
     407    public String buildingType() {
     408        if (buildingType != null)
     409            return buildingType;
     410
     411        return getItemText(dialog.buildingComboBox);
     412    }
     413   
     414    private static String getItemText(AutoCompletingComboBox box) {
     415        Object selected = box.getSelectedItem();
    396416        if (selected == null) {
    397417            return null;
  • applications/editors/josm/plugins/terracer/src/terracer/TerracerAction.java

    r29509 r29623  
    221221            // Don't open the dialog
    222222            try {
    223                 terraceBuilding(outline, init, street, associatedStreet, 0, null, null, 0, housenumbers, streetname, associatedStreet != null, false);
     223                terraceBuilding(outline, init, street, associatedStreet, 0, null, null, 0, housenumbers, streetname, associatedStreet != null, false, "yes");
    224224            } catch (UserCancelException ex) {
    225225                // Ignore
     
    231231            String title = trn("Change {0} object", "Change {0} objects", sel.size(), sel.size());
    232232            // show input dialog.
    233             new HouseNumberInputHandler(this, outline, init, street, streetname,
     233            new HouseNumberInputHandler(this, outline, init, street, streetname, null,
    234234                    associatedStreet, housenumbers, title);
    235235        }
     
    312312     *        existing relation
    313313     * @param deleteOutline If the outline way should be deleted when done
     314     * @param buildingValue The value for {@code building} key to add
    314315     * @throws UserCancelException
    315316     */
     
    325326                String streetName,
    326327                boolean handleRelations,
    327                 boolean deleteOutline) throws UserCancelException {
     328                boolean deleteOutline, String buildingValue) throws UserCancelException {
    328329        final int nb;
    329330        Integer to = null, from = null;
     
    397398                TagCollection.from(outline).applyTo(terr);
    398399                ways.add(addressBuilding(terr, street, streetName, associatedStreet, housenumbers, i,
    399                         from != null ? Integer.toString(from + i * step) : null));
     400                        from != null ? Integer.toString(from + i * step) : null, buildingValue));
    400401               
    401402                this.commands.add(new AddCommand(terr));
     
    417418        } else {
    418419            // Single building, just add the address details
    419             ways.add(addressBuilding(outline, street, streetName, associatedStreet, housenumbers, 0, From));
     420            ways.add(addressBuilding(outline, street, streetName, associatedStreet, housenumbers, 0, From, buildingValue));
    420421        }
    421422
     
    473474     * @param streetName the name of a street (may be null). Used if not null and street is null.
    474475     * @param associatedStreet The associated street. Used to determine if addr:street should be set or not.
     476     * @param buildingValue The value for {@code building} key to add
    475477     * @return {@code outline}
    476478     * @throws UserCancelException
    477479     */
    478     private Way addressBuilding(Way outline, Way street, String streetName, Relation associatedStreet, ArrayList<Node> housenumbers, int i, String defaultNumber) throws UserCancelException {
     480    private Way addressBuilding(Way outline, Way street, String streetName, Relation associatedStreet, ArrayList<Node> housenumbers, int i, String defaultNumber, String buildingValue) throws UserCancelException {
    479481        Node houseNum = (housenumbers != null && i >= 0 && i < housenumbers.size()) ? housenumbers.get(i) : null;
    480482        boolean buildingAdded = false;
     
    498500        }
    499501        if (!outline.hasKey("building") && !buildingAdded) {
    500             this.commands.add(new ChangePropertyCommand(outline, "building", "yes"));
     502            this.commands.add(new ChangePropertyCommand(outline, "building", buildingValue));
    501503        }
    502504        if (defaultNumber != null && !numberAdded) {
Note: See TracChangeset for help on using the changeset viewer.