Ignore:
Timestamp:
2009-06-03T23:42:55+02:00 (16 years ago)
Author:
rcernoch
Message:

CzechAddress: version 0.2.0 is nearly ready

Location:
applications/editors/josm/plugins/czechaddress/src/org/openstreetmap/josm/plugins/czechaddress
Files:
1 deleted
27 edited
4 moved

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/czechaddress/src/org/openstreetmap/josm/plugins/czechaddress/CzechAddressPlugin.java

    r15558 r15582  
    3131import org.openstreetmap.josm.plugins.czechaddress.actions.FactoryAction;
    3232import org.openstreetmap.josm.plugins.czechaddress.actions.HelpAction;
    33 import org.openstreetmap.josm.plugins.czechaddress.actions.ModifierAction;
     33import org.openstreetmap.josm.plugins.czechaddress.actions.ManagerAction;
    3434import org.openstreetmap.josm.plugins.czechaddress.actions.SplitAreaByEmptyWayAction;
     35import org.openstreetmap.josm.plugins.czechaddress.addressdatabase.Street;
    3536import org.openstreetmap.josm.plugins.czechaddress.gui.ConflictResolver;
    3637import org.openstreetmap.josm.plugins.czechaddress.gui.FactoryDialog;
    3738import org.openstreetmap.josm.plugins.czechaddress.gui.LocationSelector;
     39import org.openstreetmap.josm.plugins.czechaddress.gui.ManagerDialog;
    3840import org.openstreetmap.josm.plugins.czechaddress.intelligence.Reasoner;
    3941import org.openstreetmap.josm.plugins.czechaddress.intelligence.SelectionMonitor;
     
    8284        addStatusListener(this);
    8385       
    84         Reasoner.getInstance();
    8586        ConflictResolver.getInstance();
    8687        SelectionMonitor.getInstance();
     88        FactoryDialog.getInstance();
     89        Reasoner.getInstance();
    8790
    88         initLoggers();
     91        boolean assertionsEnabled = false;
     92        assert assertionsEnabled = true;
     93        if (assertionsEnabled) initLoggers();
    8994       
    9095        MainMenu.add(Main.main.menu.toolsMenu, new SplitAreaByEmptyWayAction());
     
    9499        parser.setTargetDatabase(Database.getInstance());
    95100        parser.setStorageDir(getPluginDir());
    96 
    97         parser.setFilter("HUSTOPEČE", "HUSTOPEČE", null, null);
    98101
    99102        // Fill the database in separate thread.
     
    130133            reasoner.reset();
    131134            reasoner.openTransaction();
    132             //Reasoner.logger.setLevel(Level.OFF);
    133135            for (House house : location.getAllHouses())
    134                 reasoner.consider(house);
     136                reasoner.update(house);
     137
     138            for (Street street : location.getAllStreets())
     139                reasoner.update(street);
     140
    135141            for (OsmPrimitive prim : Main.ds.allPrimitives()) {
    136                 boolean include = false;
    137                 for (String key : prim.keySet())
    138                     if (key.startsWith("addr:")) {
    139                         include = true;
    140                         break;
    141                     }
    142                 if (include)
    143                     reasoner.consider(prim);
     142                if (House.isMatchable(prim) || Street.isMatchable(prim))
     143                    reasoner.update(prim);
    144144            }
    145             //Reasoner.logger.setLevel(Level.ALL);
    146145            reasoner.closeTransaction();
    147146        }
     147        ManagerDialog dialog = new ManagerDialog();
     148        if (dialog.countAutomaticRenameProposals() > 0)
     149            dialog.setVisible(true);
    148150    }
    149151
     
    178180            menuItems.add(MainMenu.add(czechMenu, new GroupManipulatorAction()));
    179181            menuItems.add(MainMenu.add(czechMenu, new ConflictResolveAction()));
    180             menuItems.add(MainMenu.add(czechMenu, new ModifierAction()));
     182            menuItems.add(MainMenu.add(czechMenu, new ManagerAction()));
    181183            menuItems.add(MainMenu.add(czechMenu, new HelpAction()));
    182184            return;
  • applications/editors/josm/plugins/czechaddress/src/org/openstreetmap/josm/plugins/czechaddress/PrimUtils.java

    r15558 r15582  
    77
    88import java.util.Comparator;
    9 import org.openstreetmap.josm.data.coor.LatLon;
    10 import org.openstreetmap.josm.data.osm.Node;
    119import org.openstreetmap.josm.data.osm.OsmPrimitive;
    12 import org.openstreetmap.josm.data.osm.Way;
    1310
    1411/**
     
    1613 * @author Radomír Černoch, radomir.cernoch@gmail.com
    1714 */
    18 public class PrimUtils implements Comparator<OsmPrimitive> {
     15public class PrimUtils {
     16
     17    public static final String KEY_HIGHWAY      = "highway";
     18    public static final String KEY_PLACE        = "place";
    1919
    2020    public static final String KEY_ADDR_CP      = "addr:alternatenumber";
     
    2828
    2929    private static final String[] keysToCompare = new String[]
    30         {KEY_ADDR_COUNTRY, KEY_ADDR_CITY, KEY_IS_IN,
    31          KEY_ADDR_STREET, KEY_ADDR_CO, KEY_ADDR_CP, KEY_NAME };
     30        {KEY_PLACE, KEY_NAME, KEY_ADDR_COUNTRY, KEY_ADDR_CITY, KEY_IS_IN,
     31         KEY_ADDR_STREET, KEY_ADDR_CO, KEY_ADDR_CP };
    3232
    33     public int compare(OsmPrimitive o1, OsmPrimitive o2) {
     33    public static final Comparator<OsmPrimitive> comparator =
     34        new Comparator<OsmPrimitive>() {
    3435
    35         for (String key : keysToCompare) {
    36             if (o1.get(key) == null) continue;
    37             if (o2.get(key) == null) continue;
     36        public int compare(OsmPrimitive o1, OsmPrimitive o2) {
    3837
    39             int val = o1.get(key).compareTo(o2.get(key));
    40             if (val != 0) return val;
    41         }
     38            for (String key : keysToCompare) {
     39                if (o1.get(key) == null) {
     40                    continue;
     41                }
     42                if (o2.get(key) == null) {
     43                    continue;
     44                }
    4245
     46                int val = o1.get(key).compareTo(o2.get(key));
     47                if (val != 0) {
     48                    return val;
     49                }
     50            }
    4351
    44         return o1.toString().compareTo(o2.toString());
     52            return o1.toString().compareTo(o2.toString());
    4553
    46         /*LatLon pos1 = null;
    47         LatLon pos2 = null;
    48         if (o1 instanceof Node) pos1 = ((Node) o1).coor;
    49         if (o1 instanceof Way)  pos1 = ((Way)  o1).lastNode().coor;
    50         if (o2 instanceof Node) pos1 = ((Node) o2).coor;
    51         if (o2 instanceof Way)  pos1 = ((Way)  o2).lastNode().coor;
     54            /*LatLon pos1 = null;
     55            LatLon pos2 = null;
     56            if (o1 instanceof Node) pos1 = ((Node) o1).coor;
     57            if (o1 instanceof Way)  pos1 = ((Way)  o1).lastNode().coor;
     58            if (o2 instanceof Node) pos1 = ((Node) o2).coor;
     59            if (o2 instanceof Way)  pos1 = ((Way)  o2).lastNode().coor;
    5260
    53         if (pos1 != null && pos2 != null) {
     61            if (pos1 != null && pos2 != null) {
    5462            if (pos1.lat() < pos2.lat()) return -1;
    5563            if (pos1.lat() > pos2.lat()) return  1;
    5664            if (pos1.lon() < pos2.lon()) return -1;
    5765            if (pos1.lon() > pos2.lon()) return  1;
    58         }*/
    59     }
     66            }*/
     67        }
     68    };
    6069
    6170}
  • applications/editors/josm/plugins/czechaddress/src/org/openstreetmap/josm/plugins/czechaddress/StringUtils.java

    r15558 r15582  
    11package org.openstreetmap.josm.plugins.czechaddress;
    22
     3import java.text.Normalizer;
    34import org.openstreetmap.josm.data.coor.LatLon;
    45
     
    5051
    5152    /**
    52      * String matcher with abbreviations
     53     * String matcher with abbreviations and regardless of diacritics.
    5354     *
    54      * <p>Returns {@code true} even if s1="Nám. Svobody" and
     55     * <p>Returns {@code true} even if s1="Nam. Svobody" and
    5556     * s2="Náměstí Svobody".</p>
    5657     */
    5758    public static boolean matchAbbrev(String s1, String s2) {
    58         String[] parts1 = s1.split(" +");
    59         String[] parts2 = s2.split(" +");
     59        String[] parts1 = anglicize(s1).split(" +");
     60        String[] parts2 = anglicize(s2).split(" +");
    6061
    6162        if (parts1.length != parts2.length)
     
    110111        }
    111112
    112         String[] noCapitalize = { "Nad", "Pod", "U", "Na" };
     113        String[] noCapitalize = { "Nad", "Pod", "U", "Na", "Z" };
    113114        for (String noc : noCapitalize)
    114115            result = result.replaceAll(" "+noc+" ", " "+noc.toLowerCase()+" ");
     
    116117        return result;
    117118    }
     119
     120    /**
     121     * Remove diacritics from the string.
     122     *
     123     * <p>This method was posted on the
     124     * <a href='http://forums.sun.com/thread.jspa?messageID=10190825#10190825'>
     125     * SUN forum</a> by
     126     * <a href='http://forums.sun.com/profile.jspa?userID=43408'>
     127     * <i>Alan Moore</i></a>.</p>
     128     */
     129    public static String anglicize(String str) {
     130        String strNFD = Normalizer.normalize(str, Normalizer.Form.NFD);
     131        StringBuilder sb = new StringBuilder();
     132        for (char ch : strNFD.toCharArray()) {
     133            if (Character.getType(ch) != Character.NON_SPACING_MARK) {
     134                sb.append(ch);
     135            }
     136        }
     137        return sb.toString();
     138    }
    118139}
  • applications/editors/josm/plugins/czechaddress/src/org/openstreetmap/josm/plugins/czechaddress/actions/FactoryAction.java

    r15558 r15582  
    99import org.openstreetmap.josm.data.osm.Node;
    1010import org.openstreetmap.josm.gui.MapFrame;
    11 import org.openstreetmap.josm.plugins.czechaddress.CzechAddressPlugin;
    1211import org.openstreetmap.josm.plugins.czechaddress.addressdatabase.House;
    1312import org.openstreetmap.josm.plugins.czechaddress.intelligence.Reasoner;
     
    9998            r.closeTransaction();
    10099        }
     100       
     101        FactoryDialog.getInstance().selectionListenerActivated = false;
    101102        FactoryDialog.getInstance().selectNextUnmatchedHouseByCheckBox();
    102 
    103         // And make the new node selected.
    104         Main.ds.addPrimitive(newNode);
     103        Main.ds.addPrimitive(newNode);       
    105104        Main.ds.setSelected(newNode);
     105        FactoryDialog.getInstance().selectionListenerActivated = true;
    106106    }
    107107}
  • applications/editors/josm/plugins/czechaddress/src/org/openstreetmap/josm/plugins/czechaddress/actions/ManagerAction.java

    r15461 r15582  
    1 /*
    2  * To change this template, choose Tools | Templates
    3  * and open the template in the editor.
    4  */
    5 
    61package org.openstreetmap.josm.plugins.czechaddress.actions;
    72
     
    94import java.awt.event.KeyEvent;
    105import org.openstreetmap.josm.actions.JosmAction;
    11 import org.openstreetmap.josm.plugins.czechaddress.gui.Renamer;
     6import org.openstreetmap.josm.plugins.czechaddress.gui.ManagerDialog;
    127import org.openstreetmap.josm.tools.Shortcut;
    138
     
    1611 * @author Radomír Černoch, radomir.cernoch@gmail.com
    1712 */
    18 public class ModifierAction extends JosmAction {
     13public class ManagerAction extends JosmAction {
    1914
    20     public ModifierAction() {
     15    public ManagerAction() {
    2116        super("Upravit databázi",
    2217              null,//"envelope-closed-big.png",
     
    2924
    3025    public void actionPerformed(ActionEvent e) {
    31         (new Renamer()).setVisible(true);
     26        (new ManagerDialog()).setVisible(true);
    3227    }
    3328}
  • applications/editors/josm/plugins/czechaddress/src/org/openstreetmap/josm/plugins/czechaddress/addressdatabase/AddressElement.java

    r15558 r15582  
    66import org.openstreetmap.josm.data.osm.Way;
    77import org.openstreetmap.josm.plugins.czechaddress.StringUtils;
    8 import org.openstreetmap.josm.plugins.czechaddress.intelligence.Match;
     8import org.openstreetmap.josm.plugins.czechaddress.intelligence.Reasoner;
    99import org.openstreetmap.josm.plugins.czechaddress.proposal.Proposal;
    1010
     
    206206    }
    207207
     208    protected int[] getAdditionalFieldMatchList(OsmPrimitive primitive) {
     209        int[] result = {0};
     210        return result;
     211    }
    208212
    209213    public List<Proposal> getDiff(OsmPrimitive prim) {
     
    211215    }
    212216
    213     public int getMatchQuality(OsmPrimitive primitive) {
     217    public int getQ(OsmPrimitive primitive) {
    214218       
    215219        // Firstly get integers representing a match of every matchable field.
     
    234238        // has nothing to do with our field.
    235239        if (maxVal <= 0)
    236             return Match.MATCH_NOMATCH;
     240            return Reasoner.MATCH_NOMATCH;
    237241       
    238242        // If all fields are 1    --> ROCKSOLID MATCH
     
    240244        // If some are 1, some -1 --> CONFLICT
    241245        switch (minVal * maxVal) {
    242             case -1 : return Match.MATCH_CONFLICT;
    243             case  0 : return Match.MATCH_PARTIAL;
    244             case +1 : return Match.MATCH_ROCKSOLID;   
     246            case -1 : return Reasoner.MATCH_CONFLICT;
     247            case  0 : return Reasoner.MATCH_PARTIAL;
     248            case +1 : return Reasoner.MATCH_ROCKSOLID;
    245249        }
    246250       
    247251        return 0; // <-- just to make compilers happy. We cannot get here.
    248     }
    249 
    250 
    251 
    252     public String getIsIn() {
    253         return getIsIn(null);
    254     }
    255 
    256     protected String getIsInName() {
    257         return getName();
    258     }
    259 
    260     private String getIsIn(String childString) {
    261 
    262         String result = "";
    263 
    264         if (getIsInName() != null  &&  !getIsInName().equals(childString)) {
    265             result += getIsInName() + ", ";
    266         }
    267 
    268         if (parent != null)
    269             result += parent.getIsIn(getIsInName());
    270         else
    271             result += "CZ";
    272        
    273         return result;
    274252    }
    275253
     
    282260        if (retVal != 0) return retVal;
    283261
    284         return getName().compareTo(((AddressElement) elem).getName());
     262        return toString().compareTo(((AddressElement) elem).toString());
    285263    }
    286264}
  • applications/editors/josm/plugins/czechaddress/src/org/openstreetmap/josm/plugins/czechaddress/addressdatabase/ElementWithHouses.java

    r15166 r15582  
    99 * @author Radomir Cernoch radomir.cernoch@gmail.com
    1010 */
    11 abstract public class ElementWithHouses extends AddressElement {
     11public abstract class ElementWithHouses extends AddressElement {
    1212
    1313    /**
  • applications/editors/josm/plugins/czechaddress/src/org/openstreetmap/josm/plugins/czechaddress/addressdatabase/ElementWithStreets.java

    r15166 r15582  
    1616 * @author Radomir Cernoch radomir.cernoch@gmail.com
    1717 */
    18 abstract public class ElementWithStreets extends ElementWithHouses {
     18public abstract class ElementWithStreets extends ElementWithHouses {
    1919
    2020    private ArrayList<Street> streets = new ArrayList<Street>();
     
    6060    }
    6161
     62    public List<Street> getAllStreets() {
     63        return getStreets();
     64    }
     65
     66
    6267    public Street findStreet(String streetName) {
    6368
  • applications/editors/josm/plugins/czechaddress/src/org/openstreetmap/josm/plugins/czechaddress/addressdatabase/House.java

    r15558 r15582  
    55import org.openstreetmap.josm.plugins.czechaddress.NotNullList;
    66import org.openstreetmap.josm.plugins.czechaddress.PrimUtils;
    7 import org.openstreetmap.josm.plugins.czechaddress.StringUtils;
    87import org.openstreetmap.josm.plugins.czechaddress.proposal.Proposal;
    98
     
    133132     * {@link AddressElement}{@code .getFieldMatchList()}.</p>
    134133     *
    135      * <p>First elemtn of the returned array corresponds to the CP
     134     * <p>First element of the returned array corresponds to the CP
    136135     * (číslo popisné), the second one to the combination of Street+CO.</p>
    137136     */
     
    139138    protected int[] getFieldMatchList(OsmPrimitive prim) {
    140139        int[] result = {0, 0};
    141                
     140        if (!isMatchable(prim)) return result;
     141
    142142        // First field is the AlternateNubmer
    143143        result[0] = matchField(this.cp, prim.get(PrimUtils.KEY_ADDR_CP));
     
    150150        return result;
    151151    }
     152
     153    @Override
     154    protected int[] getAdditionalFieldMatchList(OsmPrimitive prim) {
     155        int[] result = {0};
     156        if (!isMatchable(prim)) return result;
     157
     158        ParentResolver resolver = new ParentResolver(this);
     159        result[0] = matchField(resolver.getIsIn(), prim.get(PrimUtils.KEY_IS_IN));
     160        return result;
     161    }
     162
    152163   
     164
    153165    /**
    154166     * Gives all proposals to make the primitive be an address primitive.
     
    161173       
    162174        List<Proposal> props = new NotNullList<Proposal>();
    163         ParentResolver pr = new ParentResolver(this);
     175        ParentResolver resolver = new ParentResolver(this);
    164176
    165177        props.add(getStringFieldDiff(PrimUtils.KEY_ADDR_CP, prim.get(PrimUtils.KEY_ADDR_CP), getCP()));
     
    169181                            prim.get(PrimUtils.KEY_ADDR_COUNTRY), "CZ"));
    170182
    171         if (pr.parentStreet != null)
     183        if (resolver.parentStreet != null)
    172184            props.add(getStringFieldDiff(PrimUtils.KEY_ADDR_STREET,
    173185                                prim.get(PrimUtils.KEY_ADDR_STREET),
    174                                 pr.parentStreet.getName()));
    175 
    176         if (parent.parent != null) // For sure our parent is a ElemWithStreets
     186                                resolver.parentStreet.getName()));
     187
     188        AddressElement isInElem = parent;
     189        if (isInElem instanceof Street) isInElem = parent.parent;
     190        if (isInElem != null) // For sure our parent is a ElemWithStreets
    177191            props.add(getStringFieldDiff(PrimUtils.KEY_IS_IN,
    178192                                prim.get(PrimUtils.KEY_IS_IN),
    179                                 parent.parent.getIsIn()));
     193                                resolver.getIsIn()));
    180194
    181195        // If we have added any proposal so far, add the source info as well.
     
    187201
    188202    public static boolean isMatchable(OsmPrimitive prim) {
    189        
    190         for (String key : prim.keySet()) {
    191             String value = prim.get(key);
    192             if (value != null && value.startsWith("addr:"))
     203        for (String key : prim.keySet())
     204            if (key.startsWith("addr:"))
    193205                return true;
    194         }
    195206        return false;
    196207    }
  • applications/editors/josm/plugins/czechaddress/src/org/openstreetmap/josm/plugins/czechaddress/addressdatabase/ParentResolver.java

    r15558 r15582  
    4040    }
    4141
     42    public String getIsIn() {
     43        String result = "";
     44        String last = "";
     45
     46        if (parentSuburb != null && !last.equals(parentSuburb.getName())) {
     47            result += parentSuburb.getName() + ", ";
     48            last = parentSuburb.getName();
     49        }
     50
     51        if (parentViToCi != null && !last.equals(parentViToCi.getName())) {
     52            result += parentViToCi.getName() + ", ";
     53            last = parentViToCi.getName();
     54        }
     55
     56        if (parentRegion != null && parentRegion.getNuts3Name() != null &&
     57                                    !last.equals(parentRegion.getNuts3Name())) {
     58            result += parentRegion.getNuts3Name() + " kraj, ";
     59            last = parentRegion.getNuts3Name();
     60        }
     61
     62        return result + "CZ";
     63    }
     64
    4265    public int compareTo(ParentResolver o) {
    4366        int val = 0;
  • applications/editors/josm/plugins/czechaddress/src/org/openstreetmap/josm/plugins/czechaddress/addressdatabase/Region.java

    r15461 r15582  
    9595        return thisString;
    9696    }
    97 
    98     @Override
    99     protected String getIsInName() {
    100 
    101         if (nuts3name != null)
    102             return nuts3name + " kraj";
    103 
    104         if (nuts4name != null)
    105             return nuts3name + " okres";
    106 
    107         return null;
    108     }
    10997}
  • applications/editors/josm/plugins/czechaddress/src/org/openstreetmap/josm/plugins/czechaddress/addressdatabase/Street.java

    r15201 r15582  
    11package org.openstreetmap.josm.plugins.czechaddress.addressdatabase;
    22
     3import java.util.List;
    34import org.openstreetmap.josm.data.osm.OsmPrimitive;
     5import org.openstreetmap.josm.plugins.czechaddress.NotNullList;
     6import org.openstreetmap.josm.plugins.czechaddress.PrimUtils;
     7import org.openstreetmap.josm.plugins.czechaddress.proposal.Proposal;
     8
     9import static org.openstreetmap.josm.plugins.czechaddress.proposal.ProposalFactory.getStringFieldDiff;
    410
    511/**
     
    2935    protected int[] getFieldMatchList(OsmPrimitive primitive) {
    3036        int[] result = {0};
     37        if (!isMatchable(primitive)) return result;
    3138       
    32         if (primitive.get("highway") == null)
    33             return result;
    34        
    35         result[0] = matchField(name, primitive.get("name"));
    36 
    37         if (primitive.get("name") != null) {
    38             String[] parts1 = primitive.get("name").split("\\.* +");
    39             String[] parts2 =                  name.split("\\.* +");
    40             for (String p : parts1)
    41                 System.out.println("X: " + p);
    42             for (String p : parts2)
    43                 System.out.println("Y: " + p);
    44         }
    45 
     39        result[0] = matchFieldAbbrev(name, primitive.get("name"));
    4640        return result;
    4741    }
     42
     43    @Override
     44    public List<Proposal> getDiff(OsmPrimitive prim) {
     45        List<Proposal> props = new NotNullList<Proposal>();
     46       
     47        props.add(getStringFieldDiff(PrimUtils.KEY_NAME, prim.get(PrimUtils.KEY_NAME), getName()));
     48        return props;
     49    }
     50
     51    public static boolean isMatchable(OsmPrimitive prim) {
     52        return (prim.get(PrimUtils.KEY_HIGHWAY) != null);
     53    }
     54
    4855}
  • applications/editors/josm/plugins/czechaddress/src/org/openstreetmap/josm/plugins/czechaddress/addressdatabase/Suburb.java

    r15166 r15582  
    11package org.openstreetmap.josm.plugins.czechaddress.addressdatabase;
     2
     3import org.openstreetmap.josm.data.osm.OsmPrimitive;
     4import org.openstreetmap.josm.plugins.czechaddress.PrimUtils;
    25
    36/**
     
    1114        super(name);
    1215    }
     16
     17    public static boolean isMatchable(OsmPrimitive prim) {
     18        for (String key : prim.keySet())
     19            if (key.equals(PrimUtils.KEY_PLACE))
     20                return true;
     21        return false;
     22    }
    1323}
  • applications/editors/josm/plugins/czechaddress/src/org/openstreetmap/josm/plugins/czechaddress/addressdatabase/ViToCi.java

    r15166 r15582  
    33import java.util.List;
    44import java.util.ArrayList;
    5 import org.openstreetmap.josm.data.osm.OsmPrimitive;
    65
    76/**
     
    5655        return null;
    5756    }
     57
     58    @Override
     59    public List<Street> getAllStreets() {
     60        List<Street> result = super.getAllStreets();
     61        for (Suburb suburb : suburbs)
     62            result.addAll(suburb.getAllStreets());
     63        return result;
     64    }
     65
     66    @Override
     67    public List<House> getAllHouses() {
     68        List<House> result = super.getAllHouses();
     69        for (Suburb suburb : suburbs)
     70            result.addAll(suburb.getAllHouses());
     71        return result;
     72    }
    5873}
  • applications/editors/josm/plugins/czechaddress/src/org/openstreetmap/josm/plugins/czechaddress/gui/ConflictResolver.form

    r15558 r15582  
    156156            <Property name="enabled" type="boolean" value="false"/>
    157157          </Properties>
     158          <Events>
     159            <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="candPickButtonActionPerformed"/>
     160          </Events>
    158161        </Component>
    159162        <Component class="javax.swing.JButton" name="mainPickButton">
  • applications/editors/josm/plugins/czechaddress/src/org/openstreetmap/josm/plugins/czechaddress/gui/ConflictResolver.java

    r15558 r15582  
    2424import org.openstreetmap.josm.plugins.czechaddress.PrimUtils;
    2525import org.openstreetmap.josm.plugins.czechaddress.addressdatabase.AddressElement;
     26import org.openstreetmap.josm.plugins.czechaddress.addressdatabase.ElementWithHouses;
    2627import org.openstreetmap.josm.plugins.czechaddress.addressdatabase.House;
    2728import org.openstreetmap.josm.plugins.czechaddress.addressdatabase.Street;
     
    134135        candPickButton.setText("     ");
    135136        candPickButton.setEnabled(false);
     137        candPickButton.addActionListener(new java.awt.event.ActionListener() {
     138            public void actionPerformed(java.awt.event.ActionEvent evt) {
     139                candPickButtonActionPerformed(evt);
     140            }
     141        });
    136142
    137143        mainPickButton.setText("     ");
     
    212218    }
    213219
     220    public void focusElement(AddressElement elem) {
     221        int index = Collections.binarySearch(conflictModel.elements, elem);
     222        if (index >= 0) {
     223            mainField.setSelectedIndex(index);
     224            mainField.repaint();
     225            setVisible(true);
     226        }
     227    }
     228
    214229    private void reassignButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_reassignButtonActionPerformed
    215230
     
    258273
    259274    private void mainPickButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mainPickButtonActionPerformed
    260         // TODO add your handling code here:
     275        if (mainField.getSelectedItem() instanceof House)
     276            FactoryDialog.getInstance().setSelectedHouse((House) mainField.getSelectedItem());
    261277    }//GEN-LAST:event_mainPickButtonActionPerformed
     278
     279    private void candPickButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_candPickButtonActionPerformed
     280        if (candField.getSelectedItem() instanceof House)
     281            FactoryDialog.getInstance().setSelectedHouse((House) candField.getSelectedItem());
     282    }//GEN-LAST:event_candPickButtonActionPerformed
    262283
    263284    // Variables declaration - do not modify//GEN-BEGIN:variables
     
    279300
    280301        public void elementChanged(AddressElement elem) {
    281             String delStr = Reasoner.getInstance().inConflict(elem) ? " in conflict" : " no conflict";
    282             logger.log(Level.FINER, "hook: element changed", elem.getName() + delStr);
     302            if (!(elem instanceof House)) return;
     303            logger.log(Level.FINER, "hook: element changed", elem.getName());
    283304
    284305            if (Reasoner.getInstance().inConflict(elem))
     
    289310
    290311        public void primitiveChanged(OsmPrimitive prim) {
    291             String delStr = Reasoner.getInstance().inConflict(prim) ? " in conflict" : " no conflict";
    292             logger.log(Level.FINER, "hook: primitive changed", AddressElement.getName(prim) + delStr);
     312            if (!House.isMatchable(prim)) return;
     313            logger.log(Level.FINER, "hook: primitive changed", AddressElement.getName(prim));
    293314
    294315            if (Reasoner.getInstance().inConflict(prim))
     
    333354
    334355        public void put(OsmPrimitive prim) {
    335             int index = Collections.binarySearch(primitives, prim, new PrimUtils());
     356            int index = Collections.binarySearch(primitives, prim, PrimUtils.comparator);
    336357            if (index < 0) {
    337358                logger.log(Level.FINE, "conflicts: adding primitive",
    338                                         "[" + String.valueOf(-index-1) + "]=„"
    339                                         + AddressElement.getName(prim) + "“");
     359                                       "["+String.valueOf(-index-1)+"]=„"
     360                                        +AddressElement.getName(prim) + "“");
    340361                primitives.add(-index-1, prim);
    341362               
     
    452473            List<OsmPrimitive> conflPrims = new NotNullList<OsmPrimitive>();
    453474            conflPrims.addAll(Reasoner.getInstance().getCandidates(selElem));
    454             Collections.sort(conflPrims, new PrimUtils());
     475            Collections.sort(conflPrims, PrimUtils.comparator);
    455476            candField.setModel(new CandidatesModel<OsmPrimitive>(conflPrims));
    456477
  • applications/editors/josm/plugins/czechaddress/src/org/openstreetmap/josm/plugins/czechaddress/gui/FactoryDialog.java

    r15558 r15582  
    9696            keepOddityCheckBox.setEnabled(true);
    9797            return;
    98         }
    99        
    100 /*      if (message == MESSAGE_REASONER_REASONED) {
    101             ensureConsistencyButton.setEnabled(true);
    102         }
    103        
    104         if (message == MESSAGE_MATCHES_CHANGED || message == MESSAGE_CONFLICT_CHANGED) {
    105             houseModel.notifyAllListeners();
    106             return;
    107         }*/
     98        }       
     99    }
     100
     101    public void setSelectedHouse(House house) {
     102
     103        for (int i=0; i<streetModel.getSize(); i++)
     104            if (streetModel.getElementAt(i) == house.getParent()) {
     105                streetComboBox.setSelectedIndex(i);
     106                streetComboBox.repaint();
     107                break;
     108            }
     109
     110        for (int i=0; i<houseModel.getSize(); i++)
     111            if (houseModel.getHouseAt(i) == house) {
     112                houseList.setSelectedIndex(i);
     113                houseList.ensureIndexIsVisible(i);
     114                break;
     115            }
    108116    }
    109117
     
    111119        if (houseList.getSelectedValue() instanceof House)
    112120            return (House) houseList.getSelectedValue();
    113         else
    114             return null;
     121        return null;
    115122    }
    116123
     
    138145        int index = houseList.getSelectedIndex();
    139146
    140         index++;
    141         Object current;
    142         while ( (current = houseModel.getElementAt(index)) != null
    143               && Reasoner.getInstance().translate((House) current) != null)
     147        index++; // Initial kick to do at least one move.
     148        House current;
     149        while ( (current = houseModel.getHouseAt(index)) != null
     150             && Reasoner.getInstance().translate(current) != null)
    144151            index++;
    145152
     
    171178                newNum = Integer.valueOf(newStr);
    172179
    173             } while ( (oldNum + newNum) % 2 == 1 &&
    174                       houseList.getSelectedIndex() != 0 );
     180            } while ((oldNum + newNum) % 2 == 1 &&
     181                     houseList.getSelectedIndex() != 0);
    175182           
    176183        } catch (Exception exp) {}
     
    184191    }
    185192
     193    public boolean selectionListenerActivated = true;
    186194    public void selectionChanged(Collection<? extends OsmPrimitive> newSelection) {
    187195
     196        if (!selectionListenerActivated) return;
    188197        if (newSelection.size() != 1) return;
    189198
    190199        OsmPrimitive selectedPrim = (OsmPrimitive) newSelection.toArray()[0];
    191 
    192200        String streetName;
    193201
     
    215223        for (House currHouse : selectedStreet.getHouses()) {
    216224
    217             int currQuality = currHouse.getMatchQuality(selectedPrim);
     225            int currQuality = currHouse.getQ(selectedPrim);
    218226
    219227            if (currQuality > bestQuality) {
     
    225233        if (bestHouse == null) return;
    226234        houseList.setSelectedValue(bestHouse, true);
     235        houseList.ensureIndexIsVisible(houseList.getSelectedIndex());
    227236        houseModel.notifyAllListeners();
    228237    }
     
    313322            Reasoner r = Reasoner.getInstance();
    314323
    315             if (r.translate(getSelectedHouse()) != null) {
     324            if (r.translate(getSelectedHouse()) != null)
    316325                MapUtils.zoomTo(r.translate(getSelectedHouse()));
    317                 return;
    318             }
    319 
    320             // TODO: The following code does not work... for some reason.
    321 /*            List<Match> getConflicts = r.getConflictsForElement(getSelectegetConflicts if (getConflicts != null) {
    322                 List<OsmPrimitive> toZoom
    323                         = new ArrayList<OsmPrimitive>(getConflicts.size());
    324                 for (Match conflict : getConflicts)
    325                     toZoom.add(conflict.prim);
    326 
    327                 MapUtils.zoomToMany(toZoom);
    328                 return;
    329 */
     326            else
     327                ConflictResolver.getInstance().focusElement(getSelectedHouse());
    330328        }
    331329    }//GEN-LAST:event_houseListClicked
     
    344342        houseModel.notifyAllListeners();
    345343    }
    346 
    347344    public void primitiveChanged(OsmPrimitive prim) {}
    348 
    349     public void resonerReseted() {
    350         throw new UnsupportedOperationException("Not supported yet.");
    351     }
     345    public void resonerReseted() {}
     346
     347//==============================================================================
    352348
    353349    private class StreetListRenderer extends DefaultListCellRenderer {
    354 
    355         Font plainFont = null;
    356         Font boldFont = null;
    357 
    358350        @Override
    359351        public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
    360352            Component c = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
    361353
    362             if (plainFont == null) plainFont = getFont().deriveFont(Font.PLAIN);
    363             if (boldFont  == null)  boldFont = getFont().deriveFont(Font.BOLD);
    364 
    365354            if (value instanceof Street) {
    366                 setFont(plainFont);
     355                setFont(getFont().deriveFont(Font.PLAIN));
    367356                setText(((Street) value).getName());
    368357               
    369358            } else if (value instanceof ElementWithHouses) {
    370                 setFont(boldFont);
     359                setFont(getFont().deriveFont(Font.BOLD));
    371360                setText("[" + ((ElementWithHouses) value).getName() + "]");
    372361            }
    373 
     362           
    374363            return c;
    375364        }
    376365    }
     366
     367//==============================================================================
    377368
    378369    private class HouseListRenderer extends DefaultListCellRenderer {
     
    392383            if (boldFont == null) boldFont = getFont().deriveFont(Font.BOLD);
    393384
    394             Reasoner r = Reasoner.getInstance();
    395 
    396385            if (value instanceof House) {
    397386                House house = (House) value;
     
    400389                setFont(plainFont);
    401390
    402                 if (r.inConflict(house))
     391                if (Reasoner.getInstance().inConflict(house))
    403392                    setIcon(envelopeExclIcon);
    404393
    405                 else if (r.translate(house) == null) {
     394                else if (Reasoner.getInstance().translate(house) == null) {
    406395                    setIcon(envelopeStarIcon);
    407396                    setFont(boldFont);
     
    414403    }
    415404
     405//==============================================================================
     406
    416407    private class AllStreetProvider extends ElementWithHouses {
    417408        public AllStreetProvider() {
     
    431422            super("nepřiřazené domy");
    432423            Reasoner.getInstance().addListener(this);
    433             rebuild();
    434         }
    435 
    436         @Override
    437         public void setHouses(List<House> houses) {
    438             this.houses = houses;
    439         }
    440 
    441 
    442         public void rebuild() {
    443             houses.clear();
     424
    444425            for (AddressElement house : Reasoner.getInstance().getUnassignedElements())
    445426                if (house instanceof House)
     
    452433        public void primitiveChanged(OsmPrimitive prim) {}
    453434        public void elementChanged(AddressElement elem) {
    454             if (!(elem instanceof House))
    455                 return;
     435            if (!(elem instanceof House)) return;
    456436            House house = (House) elem;
     437            int index = Collections.binarySearch(houses, house);
    457438           
    458             if (Reasoner.getInstance().translate(house) != null)
    459                 houses.remove(house);
    460             else if (!houses.contains(house)) {
    461                 houses.add(house);
    462                 Collections.sort(houses);
    463             }
    464         }
    465 
    466 
    467     }
     439            if (Reasoner.getInstance().translate(house) != null) {
     440                if (index >= 0) houses.remove(index);
     441            } else {
     442                if (index < 0)  houses.add(-index-1, house);
     443            }
     444           
     445            houseModel.notifyAllListeners();
     446        }
     447    }
     448
     449//==============================================================================
    468450
    469451    private class StreetListModel extends HalfCookedComboBoxModel {
     
    481463        }
    482464
    483 
    484 
    485465        public int getSize() {
    486466            if (parent == null) return 0;
     
    491471            if (parent == null) return;
    492472
    493             selected = parent;
    494             this.parent = parent;
     473            this.selected = parent;
     474            this.parent   = parent;
     475           
    495476            metaElem.set(0, parent);
    496 
    497477            metaElem.get(1).setHouses(parent.getAllHouses());
    498478            notifyAllListeners();
     
    500480
    501481        public Object getElementAt(int index) {
    502 
    503482            if (parent == null) return null;
    504             if (index <  0) return null;
    505483
    506484            if (index < metaElem.size())
     
    508486
    509487            index -= metaElem.size();
    510             // Now the index points to the list of streets
     488
    511489            if (index < parent.getStreets().size())
    512490                return parent.getStreets().get(index);
     
    526504    }
    527505
    528     private class HouseListModel extends HalfCookedListModel {
     506//==============================================================================
     507
     508    private class HouseListModel extends HalfCookedListModel
     509                                 implements ReasonerListener {
     510
     511        public HouseListModel() {
     512            Reasoner.getInstance().addListener(this);
     513        }
    529514
    530515        public int getSize() {
     
    549534            return getHouseAt(index);
    550535        }
     536
     537        public void primitiveChanged(OsmPrimitive prim) {}
     538        public void elementChanged(AddressElement elem) {
     539            notifyAllListeners();
     540        }
     541
     542        public void resonerReseted() {
     543            notifyAllListeners();
     544        }
    551545    }
    552546}
  • applications/editors/josm/plugins/czechaddress/src/org/openstreetmap/josm/plugins/czechaddress/gui/GroupManipulatorDialog.java

    r15558 r15582  
    11package org.openstreetmap.josm.plugins.czechaddress.gui;
    22
     3import org.openstreetmap.josm.data.osm.OsmPrimitive;
     4import org.openstreetmap.josm.plugins.czechaddress.addressdatabase.AddressElement;
     5import org.openstreetmap.josm.plugins.czechaddress.gui.utils.UniversalTreeRenderer;
    36import java.awt.event.ActionEvent;
    47import java.awt.event.KeyEvent;
     
    912import org.openstreetmap.josm.plugins.czechaddress.StatusListener;
    1013import org.openstreetmap.josm.plugins.czechaddress.intelligence.Reasoner;
     14import org.openstreetmap.josm.plugins.czechaddress.intelligence.ReasonerListener;
    1115import org.openstreetmap.josm.plugins.czechaddress.proposal.Proposal;
    1216import org.openstreetmap.josm.plugins.czechaddress.proposal.ProposalContainer;
     
    2529 * @see ConflictDatabase
    2630 */
    27 public class GroupManipulatorDialog extends ExtendedDialog implements StatusListener {
     31public class GroupManipulatorDialog extends ExtendedDialog implements ReasonerListener {
    2832
    2933    private static GroupManipulatorDialog singleton = null;
     
    3337        return singleton;
    3438    }
     39
     40    private ProposalDatabase database = null;
    3541
    3642    /**
     
    5258        setAlwaysOnTop(false);
    5359
    54         // Start receiving plugin-wide messages.
    55         CzechAddressPlugin.addStatusListener(this);
    56 
    5760        // TODO: Why does it always crash if the modality is set in constructor?
    5861        setModal(false);
     
    6366        super.buttonAction(evt);
    6467        if (getValue() == 1)
    65             ((ProposalDatabase) proposalTree.getModel()).applyAll();
    66     }
    67 
    68     public void pluginStatusChanged(int message) {
    69         /*if (message == StatusListener.MESSAGE_MATCHES_CHANGED) {
    70             int retval = (new ExtendedDialog(Main.parent, "Změna umístění",
    71                     "Došlo ke změně v přiřazení databáze.\n" +
    72                     "Přejete si znovu načíst seznam navrhovaných změn?",
    73                     new String[] {"Ano", "Ne"},
    74                     new String[] {"ok.png", "cancel.png"})).getValue();
    75 
    76             if (retval == 1)
    77                 recreateProposals();
    78         }*/
     68            database.applyAll();
    7969    }
    8070
    8171    @Override
    82     public void setVisible(boolean b) {
    83         if (!isVisible() && b)
     72    public void setVisible(boolean visible) {
     73
     74        if (!isVisible() && visible) {
     75            Reasoner.getInstance().addListener(this);
    8476            recreateProposals();
    85 
    86         if (b)
    87             CzechAddressPlugin.addStatusListener(this);
    88         else
    89             CzechAddressPlugin.removeStatusListener(this);
    90 
    91         super.setVisible(b);
     77        } else
     78            Reasoner.getInstance().removeListener(this);
     79
     80        super.setVisible(visible);
    9281    }
    9382
    9483    public void recreateProposals() {
    95 /*        locationTextField.setText(CzechAddressPlugin.getLocation().toString());
     84        locationTextField.setText(CzechAddressPlugin.getLocation().toString());
    9685       
    97         Reasoner r = CzechAddressPlugin.getReasoner();
    98         proposalTree.setModel(r.getProposals());*/
     86        database = Reasoner.getInstance().getProposals();
     87        proposalTree.setModel(database);
    9988    }
    10089
     
    210199    // End of variables declaration//GEN-END:variables
    211200
     201    public void elementChanged(AddressElement elem) {
     202        for (ProposalContainer container : database.getContainers()) {
     203            if (Reasoner.getInstance().translate(elem) == container.getTarget()) {
     204                recreateProposals();
     205                break;
     206            }
     207        }
     208    }
     209
     210    public void primitiveChanged(OsmPrimitive prim) {
     211        for (ProposalContainer container : database.getContainers()) {
     212            if (container.getTarget() == prim) {
     213                recreateProposals();
     214                break;
     215            }
     216        }
     217    }
     218
     219    public void resonerReseted() {
     220        recreateProposals();
     221    }
     222
    212223}
  • applications/editors/josm/plugins/czechaddress/src/org/openstreetmap/josm/plugins/czechaddress/gui/LocationSelector.form

    r15166 r15582  
    11<?xml version="1.0" encoding="UTF-8" ?>
    22
    3 <Form version="1.3" type="org.netbeans.modules.form.forminfo.JDialogFormInfo">
     3<Form version="1.3" maxVersion="1.3" type="org.netbeans.modules.form.forminfo.JDialogFormInfo">
    44  <Properties>
    55    <Property name="title" type="java.lang.String" value="V&#xfd;b&#x11b;r um&#xed;st&#x11b;n&#xed;"/>
    66    <Property name="modal" type="boolean" value="true"/>
    7     <Property name="name" type="java.lang.String" value="locationSelector"/>
     7    <Property name="name" type="java.lang.String" value="locationSelector" noResource="true"/>
    88  </Properties>
    99  <SyntheticProperties>
     
    4141                  <EmptySpace max="-2" attributes="0"/>
    4242                  <Group type="103" groupAlignment="1" attributes="0">
    43                       <Component id="castObceComboBox" pref="340" max="32767" attributes="0"/>
    44                       <Component id="obecComboBox" pref="340" max="32767" attributes="0"/>
    45                       <Component id="oblastComboBox" pref="340" max="32767" attributes="0"/>
     43                      <Component id="suburbComboBox" pref="341" max="32767" attributes="0"/>
     44                      <Component id="vitociComboBox" pref="341" max="32767" attributes="0"/>
     45                      <Component id="oblastComboBox" pref="341" max="32767" attributes="0"/>
    4646                  </Group>
    4747              </Group>
     
    5858                  <Group type="103" groupAlignment="3" attributes="0">
    5959                      <Component id="obecLabel" alignment="3" min="-2" max="-2" attributes="0"/>
    60                       <Component id="obecComboBox" alignment="3" min="-2" pref="25" max="-2" attributes="0"/>
     60                      <Component id="vitociComboBox" alignment="3" min="-2" pref="25" max="-2" attributes="0"/>
    6161                  </Group>
    6262                  <EmptySpace max="-2" attributes="0"/>
    6363                  <Group type="103" groupAlignment="3" attributes="0">
    6464                      <Component id="castObceLabel" alignment="3" min="-2" max="-2" attributes="0"/>
    65                       <Component id="castObceComboBox" alignment="3" min="-2" pref="25" max="-2" attributes="0"/>
     65                      <Component id="suburbComboBox" alignment="3" min="-2" pref="25" max="-2" attributes="0"/>
    6666                  </Group>
    6767                  <EmptySpace max="32767" attributes="0"/>
     
    8181          </Events>
    8282        </Component>
    83         <Component class="javax.swing.JComboBox" name="castObceComboBox">
     83        <Component class="javax.swing.JComboBox" name="suburbComboBox">
    8484          <Properties>
    8585            <Property name="model" type="javax.swing.ComboBoxModel" editor="org.netbeans.modules.form.editors2.ComboBoxModelEditor">
     
    8888          </Properties>
    8989          <Events>
    90             <EventHandler event="itemStateChanged" listener="java.awt.event.ItemListener" parameters="java.awt.event.ItemEvent" handler="castObceComboBoxItemStateChanged"/>
     90            <EventHandler event="itemStateChanged" listener="java.awt.event.ItemListener" parameters="java.awt.event.ItemEvent" handler="suburbComboBoxItemStateChanged"/>
    9191          </Events>
    9292        </Component>
    93         <Component class="javax.swing.JComboBox" name="obecComboBox">
     93        <Component class="javax.swing.JComboBox" name="vitociComboBox">
    9494          <Properties>
    9595            <Property name="model" type="javax.swing.ComboBoxModel" editor="org.netbeans.modules.form.editors2.ComboBoxModelEditor">
     
    9898          </Properties>
    9999          <Events>
    100             <EventHandler event="itemStateChanged" listener="java.awt.event.ItemListener" parameters="java.awt.event.ItemEvent" handler="obecComboBoxItemStateChanged"/>
     100            <EventHandler event="itemStateChanged" listener="java.awt.event.ItemListener" parameters="java.awt.event.ItemEvent" handler="vitociComboBoxItemStateChanged"/>
    101101          </Events>
    102102        </Component>
     
    113113        <Component class="javax.swing.JLabel" name="oblastLabel">
    114114          <Properties>
    115             <Property name="text" type="java.lang.String" value="Oblast:"/>
     115            <Property name="text" type="java.lang.String" value="ORP:"/>
    116116          </Properties>
    117117        </Component>
  • applications/editors/josm/plugins/czechaddress/src/org/openstreetmap/josm/plugins/czechaddress/gui/LocationSelector.java

    r15558 r15582  
    11package org.openstreetmap.josm.plugins.czechaddress.gui;
    22
    3 import org.openstreetmap.josm.plugins.czechaddress.*;
    43import java.awt.Component;
     4import java.awt.Font;
    55import java.util.ArrayList;
    66
     
    5555
    5656        oblastComboBox.setRenderer(new AddressElementRenderer());
    57         obecComboBox.setRenderer(new AddressElementRenderer());
    58         castObceComboBox.setRenderer(new AddressElementRenderer());
     57        vitociComboBox.setRenderer(new AddressElementRenderer());
     58        suburbComboBox.setRenderer(new SuburbRenderer());
    5959
    6060        oblastComboBox.setModel(new DefaultComboBoxModel(
     
    146146                        if (obec.getName().toUpperCase().equals(bestFit.get("name").toUpperCase())) {
    147147                            oblastComboBox.setSelectedItem(oblast);
    148                             obecComboBox.setSelectedItem(obec);
     148                            vitociComboBox.setSelectedItem(obec);
    149149                            for (Suburb castObce : obec.getSuburbs()) {
    150150                                if (castObce.getName().toUpperCase().equals(bestFit.get("name").toUpperCase())) {
    151                                     castObceComboBox.setSelectedItem(castObce);
     151                                    suburbComboBox.setSelectedItem(castObce);
    152152                                    break;
    153153                                }
     
    159159                            if (castObce.getName().toUpperCase().equals(bestFit.get("name").toUpperCase())) {
    160160                                oblastComboBox.setSelectedItem(oblast);
    161                                 obecComboBox.setSelectedItem(obec);
    162                                 castObceComboBox.setSelectedItem(castObce);
     161                                vitociComboBox.setSelectedItem(obec);
     162                                suburbComboBox.setSelectedItem(castObce);
    163163                                break;
    164164                            }
     
    176176     */
    177177    @SuppressWarnings("unchecked")
    178     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
     178    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    179179    private void initComponents() {
     180
    180181        mainPanel = new javax.swing.JPanel();
    181182        oblastComboBox = new javax.swing.JComboBox();
    182         castObceComboBox = new javax.swing.JComboBox();
    183         obecComboBox = new javax.swing.JComboBox();
     183        suburbComboBox = new javax.swing.JComboBox();
     184        vitociComboBox = new javax.swing.JComboBox();
    184185        obecLabel = new javax.swing.JLabel();
    185186        castObceLabel = new javax.swing.JLabel();
    186187        oblastLabel = new javax.swing.JLabel();
    187188
     189        setTitle("Výběr umístění");
     190        setModal(true);
     191        setName("locationSelector"); // NOI18N
    188192        getContentPane().setLayout(new java.awt.GridLayout(1, 0));
    189193
    190         setTitle("V\u00fdb\u011br um\u00edst\u011bn\u00ed");
    191         setModal(true);
    192         setName("locationSelector");
    193194        oblastComboBox.addItemListener(new java.awt.event.ItemListener() {
    194195            public void itemStateChanged(java.awt.event.ItemEvent evt) {
     
    197198        });
    198199
    199         castObceComboBox.addItemListener(new java.awt.event.ItemListener() {
     200        suburbComboBox.addItemListener(new java.awt.event.ItemListener() {
    200201            public void itemStateChanged(java.awt.event.ItemEvent evt) {
    201                 castObceComboBoxItemStateChanged(evt);
     202                suburbComboBoxItemStateChanged(evt);
    202203            }
    203204        });
    204205
    205         obecComboBox.addItemListener(new java.awt.event.ItemListener() {
     206        vitociComboBox.addItemListener(new java.awt.event.ItemListener() {
    206207            public void itemStateChanged(java.awt.event.ItemEvent evt) {
    207                 obecComboBoxItemStateChanged(evt);
     208                vitociComboBoxItemStateChanged(evt);
    208209            }
    209210        });
     
    211212        obecLabel.setText("Obec:");
    212213
    213         castObceLabel.setText("\u010c\u00e1st obce:");
    214 
    215         oblastLabel.setText("Oblast:");
     214        castObceLabel.setText("Část obce:");
     215
     216        oblastLabel.setText("ORP:");
    216217
    217218        javax.swing.GroupLayout mainPanelLayout = new javax.swing.GroupLayout(mainPanel);
     
    226227                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
    227228                .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
    228                     .addComponent(castObceComboBox, 0, 340, Short.MAX_VALUE)
    229                     .addComponent(obecComboBox, 0, 340, Short.MAX_VALUE)
    230                     .addComponent(oblastComboBox, 0, 340, Short.MAX_VALUE)))
     229                    .addComponent(suburbComboBox, 0, 341, Short.MAX_VALUE)
     230                    .addComponent(vitociComboBox, 0, 341, Short.MAX_VALUE)
     231                    .addComponent(oblastComboBox, 0, 341, Short.MAX_VALUE)))
    231232        );
    232233        mainPanelLayout.setVerticalGroup(
     
    239240                .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
    240241                    .addComponent(obecLabel)
    241                     .addComponent(obecComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE))
     242                    .addComponent(vitociComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE))
    242243                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
    243244                .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
    244245                    .addComponent(castObceLabel)
    245                     .addComponent(castObceComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE))
     246                    .addComponent(suburbComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE))
    246247                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
    247248        );
     249
    248250        getContentPane().add(mainPanel);
    249 
    250251    }// </editor-fold>//GEN-END:initComponents
    251252
     
    278279        if (oblast == null) return;
    279280
    280         obecComboBox.setModel(new DefaultComboBoxModel(oblast.getViToCis().toArray()));
    281         obecComboBox.setEnabled(obecComboBox.getModel().getSize() > 1);
    282 
    283         obecComboBoxItemStateChanged(null);
     281        vitociComboBox.setModel(new DefaultComboBoxModel(oblast.getViToCis().toArray()));
     282        vitociComboBox.setEnabled(vitociComboBox.getModel().getSize() > 1);
     283        vitociComboBoxItemStateChanged(null);
    284284    }//GEN-LAST:event_oblastComboBoxItemStateChanged
    285285
    286     private void obecComboBoxItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_obecComboBoxItemStateChanged
    287 
    288         ViToCi obec = (ViToCi) obecComboBox.getSelectedItem();
     286    private void vitociComboBoxItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_vitociComboBoxItemStateChanged
     287
     288        ViToCi obec = (ViToCi) vitociComboBox.getSelectedItem();
    289289        if (obec == null) return;
    290290
    291         castObceComboBox.setModel(new DefaultComboBoxModel(obec.getSuburbs().toArray()));
    292         castObceComboBox.setEnabled(castObceComboBox.getModel().getSize() > 1);
    293 
    294         castObceComboBoxItemStateChanged(null);
    295     }//GEN-LAST:event_obecComboBoxItemStateChanged
    296 
    297         private void castObceComboBoxItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_castObceComboBoxItemStateChanged
     291        if (obec.getSuburbs().size() > 0) {
     292            Object[] suburbs = new Object[obec.getSuburbs().size() + 1];
     293            suburbs[0] = obec;
     294            for (int i=0; i<obec.getSuburbs().size(); i++)
     295                suburbs[i+1] = obec.getSuburbs().get(i);
     296            suburbComboBox.setModel(new DefaultComboBoxModel(suburbs));
     297        } else
     298            suburbComboBox.setModel(new DefaultComboBoxModel());
     299
     300        suburbComboBox.setEnabled(suburbComboBox.getModel().getSize() > 1);
     301        suburbComboBoxItemStateChanged(null);
     302    }//GEN-LAST:event_vitociComboBoxItemStateChanged
     303
     304        private void suburbComboBoxItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_suburbComboBoxItemStateChanged
    298305
    299306        /*if (castObceComboBox.getSelectedItem() != null)
     
    306313            checkSetSelected((ElementWithStreets) oblastComboBox.getSelectedItem());*/
    307314
    308         if (castObceComboBox.getSelectedItem() != null)
    309             selectedElement = ((ElementWithStreets) castObceComboBox.getSelectedItem());
    310 
    311         else if (obecComboBox.getSelectedItem() != null)
    312             selectedElement = ((ElementWithStreets) obecComboBox.getSelectedItem());
     315        if (suburbComboBox.getSelectedItem() != null)
     316            selectedElement = ((ElementWithStreets) suburbComboBox.getSelectedItem());
     317
     318        else if (vitociComboBox.getSelectedItem() != null)
     319            selectedElement = ((ElementWithStreets) vitociComboBox.getSelectedItem());
    313320
    314321        else if (oblastComboBox.getSelectedItem() != null)
    315322            selectedElement = ((ElementWithStreets) oblastComboBox.getSelectedItem());
    316323       
    317         }//GEN-LAST:event_castObceComboBoxItemStateChanged
     324        }//GEN-LAST:event_suburbComboBoxItemStateChanged
    318325
    319326    // Variables declaration - do not modify//GEN-BEGIN:variables
    320     private javax.swing.JComboBox castObceComboBox;
    321327    private javax.swing.JLabel castObceLabel;
    322328    private javax.swing.JPanel mainPanel;
    323     private javax.swing.JComboBox obecComboBox;
    324329    private javax.swing.JLabel obecLabel;
    325330    private javax.swing.JComboBox oblastComboBox;
    326331    private javax.swing.JLabel oblastLabel;
     332    private javax.swing.JComboBox suburbComboBox;
     333    private javax.swing.JComboBox vitociComboBox;
    327334    // End of variables declaration//GEN-END:variables
    328335
    329336    private class AddressElementRenderer extends DefaultListCellRenderer {
    330 
    331337        @Override
    332338        public Component getListCellRendererComponent(
     
    334340                    boolean isSelected, boolean cellHasFocus) {
    335341
    336             Component c = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
     342            Component c = super.getListCellRendererComponent(list, value, index,
     343                                                      isSelected, cellHasFocus);
    337344
    338345            if (value instanceof AddressElement && !(value instanceof Region))
     
    342349        }
    343350    }
     351
     352    private class SuburbRenderer extends AddressElementRenderer {
     353        @Override
     354        public Component getListCellRendererComponent(JList list, Object value,
     355                          int index, boolean isSelected, boolean cellHasFocus) {
     356            Component c = super.getListCellRendererComponent(list, value,
     357                                               index, isSelected, cellHasFocus);
     358
     359            if (value instanceof ViToCi) {
     360                setFont(getFont().deriveFont(Font.BOLD));
     361                setText(((ViToCi) value).getName() + ", všechny části obce");
     362            } else
     363                setFont(getFont().deriveFont(Font.PLAIN));
     364
     365            return c;
     366        }
     367    }
    344368}
  • applications/editors/josm/plugins/czechaddress/src/org/openstreetmap/josm/plugins/czechaddress/gui/ManagerDialog.form

    r15558 r15582  
    11<?xml version="1.0" encoding="UTF-8" ?>
    22
    3 <Form version="1.3" maxVersion="1.7" type="org.netbeans.modules.form.forminfo.JDialogFormInfo">
     3<Form version="1.5" maxVersion="1.7" type="org.netbeans.modules.form.forminfo.JDialogFormInfo">
    44  <Properties>
    55    <Property name="defaultCloseOperation" type="int" value="2"/>
     
    1818    <AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
    1919    <AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
     20    <AuxValue name="designerSize" type="java.awt.Dimension" value="-84,-19,0,5,115,114,0,18,106,97,118,97,46,97,119,116,46,68,105,109,101,110,115,105,111,110,65,-114,-39,-41,-84,95,68,20,2,0,2,73,0,6,104,101,105,103,104,116,73,0,5,119,105,100,116,104,120,112,0,0,1,-84,0,0,1,-74"/>
    2021  </AuxValues>
    2122
     
    2728    <Container class="javax.swing.JPanel" name="mainPanel">
    2829
    29       <Layout>
    30         <DimensionLayout dim="0">
    31           <Group type="103" groupAlignment="0" attributes="0">
    32               <Component id="jScrollPane1" min="-2" pref="400" max="-2" attributes="0"/>
    33           </Group>
    34         </DimensionLayout>
    35         <DimensionLayout dim="1">
    36           <Group type="103" groupAlignment="0" attributes="0">
    37               <Component id="jScrollPane1" min="-2" pref="300" max="-2" attributes="0"/>
    38           </Group>
    39         </DimensionLayout>
     30      <Layout class="org.netbeans.modules.form.compat2.layouts.DesignGridLayout">
     31        <Property name="columns" type="int" value="0"/>
     32        <Property name="rows" type="int" value="1"/>
    4033      </Layout>
    4134      <SubComponents>
    42         <Container class="javax.swing.JScrollPane" name="jScrollPane1">
    43           <AuxValues>
    44             <AuxValue name="autoScrollPane" type="java.lang.Boolean" value="true"/>
    45           </AuxValues>
     35        <Container class="javax.swing.JTabbedPane" name="tabbedPane">
    4636
    47           <Layout class="org.netbeans.modules.form.compat2.layouts.support.JScrollPaneSupportLayout"/>
     37          <Layout class="org.netbeans.modules.form.compat2.layouts.support.JTabbedPaneSupportLayout"/>
    4838          <SubComponents>
    49             <Component class="javax.swing.JTree" name="tree">
    50             </Component>
     39            <Container class="javax.swing.JPanel" name="jPanel1">
     40              <Constraints>
     41                <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.support.JTabbedPaneSupportLayout" value="org.netbeans.modules.form.compat2.layouts.support.JTabbedPaneSupportLayout$JTabbedPaneConstraintsDescription">
     42                  <JTabbedPaneConstraints tabName="N&#xe1;vrhy na p&#x159;ejmenov&#xe1;n&#xed;">
     43                    <Property name="tabTitle" type="java.lang.String" value="N&#xe1;vrhy na p&#x159;ejmenov&#xe1;n&#xed;"/>
     44                  </JTabbedPaneConstraints>
     45                </Constraint>
     46              </Constraints>
     47
     48              <Layout>
     49                <DimensionLayout dim="0">
     50                  <Group type="103" groupAlignment="0" attributes="0">
     51                      <Group type="102" alignment="1" attributes="0">
     52                          <EmptySpace pref="253" max="32767" attributes="0"/>
     53                          <Component id="renamerButton" min="-2" max="-2" attributes="0"/>
     54                          <EmptySpace max="-2" attributes="0"/>
     55                      </Group>
     56                      <Component id="streetScrollPane" alignment="0" pref="426" max="32767" attributes="0"/>
     57                  </Group>
     58                </DimensionLayout>
     59                <DimensionLayout dim="1">
     60                  <Group type="103" groupAlignment="0" attributes="0">
     61                      <Group type="102" alignment="1" attributes="0">
     62                          <Component id="streetScrollPane" pref="342" max="32767" attributes="0"/>
     63                          <EmptySpace max="-2" attributes="0"/>
     64                          <Component id="renamerButton" min="-2" max="-2" attributes="0"/>
     65                          <EmptySpace max="-2" attributes="0"/>
     66                      </Group>
     67                  </Group>
     68                </DimensionLayout>
     69              </Layout>
     70              <SubComponents>
     71                <Container class="javax.swing.JScrollPane" name="streetScrollPane">
     72                  <AuxValues>
     73                    <AuxValue name="autoScrollPane" type="java.lang.Boolean" value="true"/>
     74                  </AuxValues>
     75
     76                  <Layout class="org.netbeans.modules.form.compat2.layouts.support.JScrollPaneSupportLayout"/>
     77                  <SubComponents>
     78                    <Component class="javax.swing.JTable" name="renameTable">
     79                      <Properties>
     80                        <Property name="model" type="javax.swing.table.TableModel" editor="org.netbeans.modules.form.editors2.TableModelEditor">
     81                          <Table columnCount="2" rowCount="4">
     82                            <Column editable="false" title="P&#x16f;vodn&#xed; n&#xe1;zev" type="java.lang.Object"/>
     83                            <Column editable="true" title="N&#xe1;vrh z mapy" type="java.lang.String"/>
     84                          </Table>
     85                        </Property>
     86                        <Property name="columnSelectionAllowed" type="boolean" value="true"/>
     87                        <Property name="tableHeader" type="javax.swing.table.JTableHeader" editor="org.netbeans.modules.form.editors2.JTableHeaderEditor">
     88                          <TableHeader reorderingAllowed="true" resizingAllowed="true"/>
     89                        </Property>
     90                      </Properties>
     91                    </Component>
     92                  </SubComponents>
     93                </Container>
     94                <Component class="javax.swing.JButton" name="renamerButton">
     95                  <Properties>
     96                    <Property name="text" type="java.lang.String" value="Pou&#x17e;&#xed;t navr&#x17e;en&#xe9; zm&#x11b;ny"/>
     97                  </Properties>
     98                  <Events>
     99                    <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="renamerButtonActionPerformed"/>
     100                  </Events>
     101                </Component>
     102              </SubComponents>
     103            </Container>
     104            <Container class="javax.swing.JPanel" name="jPanel2">
     105              <Constraints>
     106                <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.support.JTabbedPaneSupportLayout" value="org.netbeans.modules.form.compat2.layouts.support.JTabbedPaneSupportLayout$JTabbedPaneConstraintsDescription">
     107                  <JTabbedPaneConstraints tabName="Inspektor datab&#xe1;ze">
     108                    <Property name="tabTitle" type="java.lang.String" value="Inspektor datab&#xe1;ze"/>
     109                  </JTabbedPaneConstraints>
     110                </Constraint>
     111              </Constraints>
     112
     113              <Layout>
     114                <DimensionLayout dim="0">
     115                  <Group type="103" groupAlignment="0" attributes="0">
     116                      <Component id="jScrollPane1" alignment="0" pref="426" max="32767" attributes="0"/>
     117                      <Group type="102" alignment="1" attributes="0">
     118                          <EmptySpace pref="356" max="32767" attributes="0"/>
     119                          <Component id="dbEditButton" min="-2" max="-2" attributes="0"/>
     120                          <EmptySpace max="-2" attributes="0"/>
     121                      </Group>
     122                  </Group>
     123                </DimensionLayout>
     124                <DimensionLayout dim="1">
     125                  <Group type="103" groupAlignment="0" attributes="0">
     126                      <Group type="102" alignment="1" attributes="0">
     127                          <Component id="jScrollPane1" pref="342" max="32767" attributes="0"/>
     128                          <EmptySpace max="-2" attributes="0"/>
     129                          <Component id="dbEditButton" min="-2" max="-2" attributes="0"/>
     130                          <EmptySpace max="-2" attributes="0"/>
     131                      </Group>
     132                  </Group>
     133                </DimensionLayout>
     134              </Layout>
     135              <SubComponents>
     136                <Container class="javax.swing.JScrollPane" name="jScrollPane1">
     137                  <AuxValues>
     138                    <AuxValue name="autoScrollPane" type="java.lang.Boolean" value="true"/>
     139                  </AuxValues>
     140
     141                  <Layout class="org.netbeans.modules.form.compat2.layouts.support.JScrollPaneSupportLayout"/>
     142                  <SubComponents>
     143                    <Component class="javax.swing.JTree" name="dbTree">
     144                      <Events>
     145                        <EventHandler event="valueChanged" listener="javax.swing.event.TreeSelectionListener" parameters="javax.swing.event.TreeSelectionEvent" handler="dbTreeValueChanged"/>
     146                      </Events>
     147                    </Component>
     148                  </SubComponents>
     149                </Container>
     150                <Component class="javax.swing.JButton" name="dbEditButton">
     151                  <Properties>
     152                    <Property name="text" type="java.lang.String" value="Upravit"/>
     153                    <Property name="enabled" type="boolean" value="false"/>
     154                  </Properties>
     155                  <Events>
     156                    <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="dbEditButtonActionPerformed"/>
     157                  </Events>
     158                </Component>
     159              </SubComponents>
     160            </Container>
    51161          </SubComponents>
    52162        </Container>
  • applications/editors/josm/plugins/czechaddress/src/org/openstreetmap/josm/plugins/czechaddress/gui/ManagerDialog.java

    r15558 r15582  
    11package org.openstreetmap.josm.plugins.czechaddress.gui;
    22
     3import java.awt.Component;
     4import java.awt.event.MouseEvent;
     5import java.util.ArrayList;
     6import java.util.List;
     7import javax.swing.DefaultComboBoxModel;
     8import javax.swing.JComboBox;
     9import javax.swing.JTable;
     10import javax.swing.event.TableModelListener;
     11import javax.swing.table.DefaultTableCellRenderer;
     12import javax.swing.table.TableModel;
     13import org.openstreetmap.josm.plugins.czechaddress.gui.utils.UniversalTreeRenderer;
    314import org.openstreetmap.josm.Main;
    415import org.openstreetmap.josm.gui.ExtendedDialog;
    516import org.openstreetmap.josm.plugins.czechaddress.CzechAddressPlugin;
     17import org.openstreetmap.josm.plugins.czechaddress.addressdatabase.AddressElement;
    618import org.openstreetmap.josm.plugins.czechaddress.addressdatabase.Database;
    719import org.openstreetmap.josm.plugins.czechaddress.addressdatabase.House;
     
    1022import org.openstreetmap.josm.plugins.czechaddress.addressdatabase.Suburb;
    1123import org.openstreetmap.josm.plugins.czechaddress.addressdatabase.ViToCi;
    12 
    13 public class Inspector extends ExtendedDialog {
    14 
    15     /** Creates new form Inspector */
    16     public Inspector() {
     24import org.openstreetmap.josm.plugins.czechaddress.gui.databaseeditors.StreetEditor;
     25import org.openstreetmap.josm.plugins.czechaddress.intelligence.Capitalizator;
     26import org.openstreetmap.josm.plugins.czechaddress.intelligence.Reasoner;
     27
     28public class ManagerDialog extends ExtendedDialog {
     29
     30    RenameModel<Street> streetModel = new RenameModel<Street>();
     31
     32    public ManagerDialog() {
    1733        super(Main.parent, "Inspektor databáze", new String[] {}, true);
    1834        initComponents();
    1935
    20         //tree.setModel(new Model());
    21         tree.setCellRenderer(new UniversalTreeRenderer());
     36        dbTree.setModel(new DatabaseModel());
     37        dbTree.setCellRenderer(new UniversalTreeRenderer());
     38
     39        Capitalizator cap = new Capitalizator(
     40                                Main.ds.allPrimitives(),
     41                                CzechAddressPlugin.getLocation().getStreets());
     42
     43        for (Street capStreet : cap.getCapitalised()) {
     44            assert cap.translate(capStreet).get("name") != null : capStreet;
     45
     46            String elemName = capStreet.getName();
     47            String primName = cap.translate(capStreet).get("name");
     48
     49            if (!elemName.equals(primName)) {
     50                streetModel.elems.add(capStreet);
     51                streetModel.names.add(primName);
     52            }
     53        }
     54
     55        renameTable.setModel(streetModel);
     56        renameTable.setDefaultRenderer( AddressElement.class,
     57                                        new AddressElementRenderer());
     58        renameTable.setDefaultRenderer( String.class,
     59                                        new AddressElementRenderer());
    2260
    2361        // And finalize initializing the form.
     
    2563    }
    2664
    27     /*private class Model extends HalfCookedTreeModel {
     65    public int countAutomaticRenameProposals() {
     66        return streetModel.getRowCount();
     67    }
     68
     69    private class DatabaseModel extends HalfCookedTreeModel {
    2870
    2971        @Override
    3072        public Object getRoot() {
    31             return CzechAddressPlugin.database;
     73            return CzechAddressPlugin.getLocation();
    3274        }
    3375
     
    130172        }
    131173       
    132     }*/
     174    }
    133175
    134176    /** This method is called from within the constructor to
     
    142184
    143185        mainPanel = new javax.swing.JPanel();
     186        tabbedPane = new javax.swing.JTabbedPane();
     187        jPanel1 = new javax.swing.JPanel();
     188        streetScrollPane = new javax.swing.JScrollPane();
     189        renameTable = new javax.swing.JTable();
     190        renamerButton = new javax.swing.JButton();
     191        jPanel2 = new javax.swing.JPanel();
    144192        jScrollPane1 = new javax.swing.JScrollPane();
    145         tree = new javax.swing.JTree();
     193        dbTree = new javax.swing.JTree();
     194        dbEditButton = new javax.swing.JButton();
    146195
    147196        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
    148         getContentPane().setLayout(new java.awt.GridLayout());
    149 
    150         jScrollPane1.setViewportView(tree);
    151 
    152         javax.swing.GroupLayout mainPanelLayout = new javax.swing.GroupLayout(mainPanel);
    153         mainPanel.setLayout(mainPanelLayout);
    154         mainPanelLayout.setHorizontalGroup(
    155             mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
    156             .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 400, javax.swing.GroupLayout.PREFERRED_SIZE)
     197        getContentPane().setLayout(new java.awt.GridLayout(1, 0));
     198
     199        mainPanel.setLayout(new java.awt.GridLayout(1, 0));
     200
     201        renameTable.setModel(new javax.swing.table.DefaultTableModel(
     202            new Object [][] {
     203                {null, null},
     204                {null, null},
     205                {null, null},
     206                {null, null}
     207            },
     208            new String [] {
     209                "Původní název", "Návrh z mapy"
     210            }
     211        ) {
     212            Class[] types = new Class [] {
     213                java.lang.Object.class, java.lang.String.class
     214            };
     215            boolean[] canEdit = new boolean [] {
     216                false, true
     217            };
     218
     219            public Class getColumnClass(int columnIndex) {
     220                return types [columnIndex];
     221            }
     222
     223            public boolean isCellEditable(int rowIndex, int columnIndex) {
     224                return canEdit [columnIndex];
     225            }
     226        });
     227        renameTable.setColumnSelectionAllowed(true);
     228        streetScrollPane.setViewportView(renameTable);
     229
     230        renamerButton.setText("Použít navržené změny");
     231        renamerButton.addActionListener(new java.awt.event.ActionListener() {
     232            public void actionPerformed(java.awt.event.ActionEvent evt) {
     233                renamerButtonActionPerformed(evt);
     234            }
     235        });
     236
     237        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
     238        jPanel1.setLayout(jPanel1Layout);
     239        jPanel1Layout.setHorizontalGroup(
     240            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
     241            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
     242                .addContainerGap(253, Short.MAX_VALUE)
     243                .addComponent(renamerButton)
     244                .addContainerGap())
     245            .addComponent(streetScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 426, Short.MAX_VALUE)
    157246        );
    158         mainPanelLayout.setVerticalGroup(
    159             mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
    160             .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 300, javax.swing.GroupLayout.PREFERRED_SIZE)
     247        jPanel1Layout.setVerticalGroup(
     248            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
     249            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
     250                .addComponent(streetScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 342, Short.MAX_VALUE)
     251                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
     252                .addComponent(renamerButton)
     253                .addContainerGap())
    161254        );
     255
     256        tabbedPane.addTab("Návrhy na přejmenování", jPanel1);
     257
     258        dbTree.addTreeSelectionListener(new javax.swing.event.TreeSelectionListener() {
     259            public void valueChanged(javax.swing.event.TreeSelectionEvent evt) {
     260                dbTreeValueChanged(evt);
     261            }
     262        });
     263        jScrollPane1.setViewportView(dbTree);
     264
     265        dbEditButton.setText("Upravit");
     266        dbEditButton.setEnabled(false);
     267        dbEditButton.addActionListener(new java.awt.event.ActionListener() {
     268            public void actionPerformed(java.awt.event.ActionEvent evt) {
     269                dbEditButtonActionPerformed(evt);
     270            }
     271        });
     272
     273        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
     274        jPanel2.setLayout(jPanel2Layout);
     275        jPanel2Layout.setHorizontalGroup(
     276            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
     277            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 426, Short.MAX_VALUE)
     278            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
     279                .addContainerGap(356, Short.MAX_VALUE)
     280                .addComponent(dbEditButton)
     281                .addContainerGap())
     282        );
     283        jPanel2Layout.setVerticalGroup(
     284            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
     285            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
     286                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 342, Short.MAX_VALUE)
     287                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
     288                .addComponent(dbEditButton)
     289                .addContainerGap())
     290        );
     291
     292        tabbedPane.addTab("Inspektor databáze", jPanel2);
     293
     294        mainPanel.add(tabbedPane);
    162295
    163296        getContentPane().add(mainPanel);
     
    166299    }// </editor-fold>//GEN-END:initComponents
    167300
     301    private void renamerButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_renamerButtonActionPerformed
     302        assert streetModel.elems.size() == streetModel.names.size();
     303        Reasoner r = Reasoner.getInstance();
     304
     305        synchronized (r) {
     306            r.openTransaction();
     307            for(int i=0; i<streetModel.elems.size(); i++) {
     308                streetModel.elems.get(i).setName(streetModel.names.get(i));
     309                r.update(streetModel.elems.get(i));
     310            }
     311            r.closeTransaction();
     312        }
     313
     314        streetModel.elems.clear();
     315        streetModel.names.clear();
     316        jPanel1.setVisible(false);
     317    }//GEN-LAST:event_renamerButtonActionPerformed
     318
     319    private AddressElement dbTreeValue = null;
     320
     321    private void dbTreeValueChanged(javax.swing.event.TreeSelectionEvent evt) {//GEN-FIRST:event_dbTreeValueChanged
     322        dbTreeValue = (AddressElement) dbTree.getSelectionPath().getLastPathComponent();
     323        dbEditButton.setEnabled(dbTreeValue instanceof Street);
     324    }//GEN-LAST:event_dbTreeValueChanged
     325
     326    private void dbEditButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_dbEditButtonActionPerformed
     327        if (dbTreeValue instanceof Street)
     328            if (StreetEditor.editStreet((Street) dbTreeValue))
     329                dbTree.repaint();
     330    }//GEN-LAST:event_dbEditButtonActionPerformed
     331
    168332    // Variables declaration - do not modify//GEN-BEGIN:variables
     333    private javax.swing.JButton dbEditButton;
     334    private javax.swing.JTree dbTree;
     335    private javax.swing.JPanel jPanel1;
     336    private javax.swing.JPanel jPanel2;
    169337    private javax.swing.JScrollPane jScrollPane1;
    170338    private javax.swing.JPanel mainPanel;
    171     private javax.swing.JTree tree;
     339    private javax.swing.JTable renameTable;
     340    private javax.swing.JButton renamerButton;
     341    private javax.swing.JScrollPane streetScrollPane;
     342    private javax.swing.JTabbedPane tabbedPane;
    172343    // End of variables declaration//GEN-END:variables
    173344
     345    private class AddressElementRenderer extends DefaultTableCellRenderer {
     346
     347        public AddressElementRenderer() {}
     348
     349        @Override
     350        protected void setValue(Object value) {
     351            super.setValue(value);
     352
     353            if (value instanceof AddressElement)
     354                setText(((AddressElement) value).getName() );
     355        }
     356    }
     357
     358    private class RenameModel<Element> implements TableModel {
     359
     360        List<Element> elems = new ArrayList<Element>();
     361        List<String>  names = new ArrayList<String>();
     362
     363        public int getRowCount() {
     364            assert elems.size() == names.size();
     365            return elems.size();
     366        }
     367
     368        public int getColumnCount() {
     369            return 2;
     370        }
     371
     372        public String getColumnName(int columnIndex) {
     373            if (columnIndex == 0) return "Původní název";
     374            if (columnIndex == 1) return "Navržený název";
     375            assert false : columnIndex;
     376            return null;
     377        }
     378
     379        public Class<?> getColumnClass(int columnIndex) {
     380            if (columnIndex == 0) return AddressElement.class;
     381            if (columnIndex == 1) return String.class;
     382            assert false : columnIndex;
     383            return null;
     384        }
     385
     386        public boolean isCellEditable(int rowIndex, int columnIndex) {
     387            return columnIndex == 1;
     388        }
     389
     390        public Object getValueAt(int rowIndex, int columnIndex) {
     391            if (columnIndex == 0) return elems.get(rowIndex);
     392            if (columnIndex == 1) return names.get(rowIndex);
     393            assert false : columnIndex;
     394            return null;
     395        }
     396
     397        public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
     398            assert columnIndex == 1;
     399            names.set(rowIndex, (String) aValue);
     400        }
     401
     402        public void addTableModelListener(TableModelListener l) {
     403
     404        }
     405
     406        public void removeTableModelListener(TableModelListener l) {
     407
     408        }
     409    }
    174410}
  • applications/editors/josm/plugins/czechaddress/src/org/openstreetmap/josm/plugins/czechaddress/gui/PointManipulatorDialog.form

    r15558 r15582  
    2222    <AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
    2323    <AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
    24     <AuxValue name="designerSize" type="java.awt.Dimension" value="-84,-19,0,5,115,114,0,18,106,97,118,97,46,97,119,116,46,68,105,109,101,110,115,105,111,110,65,-114,-39,-41,-84,95,68,20,2,0,2,73,0,6,104,101,105,103,104,116,73,0,5,119,105,100,116,104,120,112,0,0,1,11,0,0,1,-79"/>
     24    <AuxValue name="designerSize" type="java.awt.Dimension" value="-84,-19,0,5,115,114,0,18,106,97,118,97,46,97,119,116,46,68,105,109,101,110,115,105,111,110,65,-114,-39,-41,-84,95,68,20,2,0,2,73,0,6,104,101,105,103,104,116,73,0,5,119,105,100,116,104,120,112,0,0,1,21,0,0,1,-79"/>
    2525  </AuxValues>
    2626
     
    4949                      </Group>
    5050                      <Component id="alternateNumberEdit" alignment="0" pref="293" max="32767" attributes="0"/>
    51                       <Group type="102" alignment="1" attributes="0">
    52                           <Component id="matchesComboBox" pref="186" max="32767" attributes="0"/>
    53                           <EmptySpace max="-2" attributes="0"/>
    54                           <Component id="ensureConsistencyButton" min="-2" max="-2" attributes="0"/>
    55                       </Group>
     51                      <Component id="matchesComboBox" alignment="0" pref="293" max="32767" attributes="0"/>
    5652                  </Group>
    5753              </Group>
    58               <Component id="jScrollPane1" alignment="1" pref="433" max="32767" attributes="0"/>
     54              <Component id="statusLabel" alignment="0" pref="433" max="32767" attributes="0"/>
     55              <Component id="jScrollPane1" alignment="0" pref="433" max="32767" attributes="0"/>
    5956          </Group>
    6057        </DimensionLayout>
     
    7673                      <Component id="jLabel6" alignment="3" min="-2" max="-2" attributes="0"/>
    7774                      <Component id="matchesComboBox" alignment="3" min="-2" max="-2" attributes="0"/>
    78                       <Component id="ensureConsistencyButton" alignment="3" min="-2" max="-2" attributes="0"/>
    7975                  </Group>
    80                   <EmptySpace pref="176" max="32767" attributes="0"/>
    81               </Group>
    82               <Group type="102" alignment="0" attributes="0">
    83                   <EmptySpace min="-2" pref="92" max="-2" attributes="0"/>
    84                   <Component id="jScrollPane1" pref="175" max="32767" attributes="0"/>
     76                  <EmptySpace max="-2" attributes="0"/>
     77                  <Component id="jScrollPane1" pref="161" max="32767" attributes="0"/>
     78                  <EmptySpace max="-2" attributes="0"/>
     79                  <Component id="statusLabel" min="-2" max="-2" attributes="0"/>
    8580              </Group>
    8681          </Group>
     
    154149          </Properties>
    155150        </Component>
    156         <Component class="javax.swing.JButton" name="ensureConsistencyButton">
     151        <Component class="javax.swing.JLabel" name="statusLabel">
    157152          <Properties>
    158             <Property name="icon" type="javax.swing.Icon" editor="org.netbeans.modules.form.RADConnectionPropertyEditor">
    159               <Connection code="ImageProvider.get(&quot;actions&quot;, &quot;refresh-small.png&quot;)" type="code"/>
    160             </Property>
    161             <Property name="text" type="java.lang.String" editor="org.netbeans.modules.form.RADConnectionPropertyEditor">
    162               <Connection code="&quot;&quot;" type="code"/>
    163             </Property>
    164             <Property name="toolTipText" type="java.lang.String" value="Provede nov&#xe9; p&#x159;i&#x159;azen&#xed; prvk&#x16f; mapy na elementy datab&#xe1;ze.&#xa;Touto volbou se zru&#x161;&#xed; v&#x161;echny manu&#xe1;ln&#x11b; vy&#x159;e&#x161;en&#xe9; konflikty."/>
     153            <Property name="text" type="java.lang.String" value=" "/>
    165154          </Properties>
    166           <Events>
    167             <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="ensureConsistencyButtonActionPerformed"/>
    168           </Events>
    169155        </Component>
    170156      </SubComponents>
  • applications/editors/josm/plugins/czechaddress/src/org/openstreetmap/josm/plugins/czechaddress/gui/PointManipulatorDialog.java

    r15558 r15582  
    11package org.openstreetmap.josm.plugins.czechaddress.gui;
    22
    3 import java.awt.Component;
    43import java.awt.event.ActionEvent;
    54import java.awt.event.KeyEvent;
    65import java.util.List;
    76import java.util.Map;
    8 import javax.swing.JList;
    97import javax.swing.AbstractAction;
    108import javax.swing.Action;
    11 import javax.swing.DefaultListCellRenderer;
    12 import javax.swing.ImageIcon;
    139import javax.swing.Timer;
    1410import org.openstreetmap.josm.Main;
     
    2117import org.openstreetmap.josm.plugins.czechaddress.addressdatabase.AddressElement;
    2218import org.openstreetmap.josm.plugins.czechaddress.addressdatabase.House;
    23 import org.openstreetmap.josm.plugins.czechaddress.intelligence.Match;
     19import org.openstreetmap.josm.plugins.czechaddress.gui.utils.UniversalListRenderer;
    2420import org.openstreetmap.josm.plugins.czechaddress.intelligence.Reasoner;
    2521import org.openstreetmap.josm.plugins.czechaddress.proposal.Proposal;
    2622import org.openstreetmap.josm.plugins.czechaddress.proposal.ProposalContainer;
    27 import org.openstreetmap.josm.plugins.czechaddress.proposal.ProposalListPainter;
    2823import org.openstreetmap.josm.tools.ImageProvider;
    2924
     
    5550        // Create action for delaying the database query...
    5651        updateMatchesAction = new AbstractAction() {
    57             boolean shouldDraw = false;
    5852            public void actionPerformed(ActionEvent e) {
    5953                updateMatches();
     
    6862        proposalContainer = new ProposalContainer(primitive);
    6963        proposalList.setModel(proposalContainer);
    70         proposalList.setCellRenderer(new ProposalListPainter());
     64        proposalList.setCellRenderer(new UniversalListRenderer());
    7165
    7266        // Init the "match" combobox.
    7367        matchesComboBox.setModel(new MatchesComboBoxModel());
    74         matchesComboBox.setRenderer(new MatchesComboBoxPainter());
     68        matchesComboBox.setRenderer(new UniversalListRenderer());
    7569
    7670        if (primitive.get("addr:alternatenumber") != null) {
     
    9185    protected void buttonAction(ActionEvent evt) {
    9286        super.buttonAction(evt);
    93 /*        if (getValue() == 1) {
     87        if (getValue() == 1) {
    9488           
    9589            if (updateMatchesTimer.isRunning()) {
     
    10397            Main.ds.setSelected(proposalContainer.getTarget());
    10498           
    105             Reasoner r = CzechAddressPlugin.getReasoner();
    106             Match    m = (Match) matchesComboBox.getSelectedItem();
    107             if (m != null) {
    108                 r.overwriteMatch(m.elem, m.prim);
    109             }
    110         }*/
     99            AddressElement elem = (AddressElement) matchesComboBox.getSelectedItem();
     100            if (elem != null) {
     101                Reasoner r = Reasoner.getInstance();
     102                synchronized (r) {
     103                    r.openTransaction();
     104                    r.doOverwrite(proposalContainer.getTarget(), elem);
     105                    r.closeTransaction();
     106                }
     107            }
     108        }
    111109
    112110        CzechAddressPlugin.removeStatusListener(this);
     
    125123    public void updateMatches() {
    126124       
    127 /*        if (proposalContainer.getTarget().deleted) {
     125        if (proposalContainer.getTarget().deleted)
    128126            setVisible(false);
     127        OsmPrimitive prim = this.proposalContainer.getTarget();
     128        Reasoner r = Reasoner.getInstance();
     129        List<AddressElement> elems = new NotNullList<AddressElement>();
     130
     131        synchronized (r) {
     132            Map<String,String> backup = prim.keys;
     133            r.openTransaction();
     134            prim.keys = null;
     135            prim.put("addr:alternatenumber", alternateNumberEdit.getText());
     136            r.update(prim);
     137            elems.addAll(r.getCandidates(prim));
     138            prim.keys = backup;
     139            r.update(prim);
     140            r.closeTransaction();
    129141        }
    130142       
    131         OsmPrimitive prim = this.proposalContainer.getTarget();
    132        
    133         Map<String,String> backup = prim.keys;
    134         prim.keys = null;
    135         prim.put("addr:alternatenumber", alternateNumberEdit.getText());
    136        
    137         Reasoner r = CzechAddressPlugin.getReasoner();
    138         NotNullList<Match> matches = r.getMatchesForPrimitive(prim);
    139 
    140         prim.keys = backup;
    141        
    142         // TODO: Here we should sort matches according to their quality.
    143 
    144143        MatchesComboBoxModel matchesModel =
    145144                ((MatchesComboBoxModel) matchesComboBox.getModel());
    146145
    147146        // Fill the combobox with suitable houses.
    148         matchesModel.setMatches(matches);
     147        matchesModel.setElements(elems);
    149148        if (matchesModel.getSize() > 0) {
    150149            matchesComboBox.setSelectedIndex(0);
     
    156155        fakeHouse.setParent(CzechAddressPlugin.getLocation());
    157156        proposalContainer.setProposals(
    158                 fakeHouse.getDiff(proposalContainer.getTarget()));*/
     157                fakeHouse.getDiff(proposalContainer.getTarget()));
    159158    }
    160159
     
    162161
    163162        // If location changes, we block the dialog until reasoning is done.
    164 /*        if (message == MESSAGE_LOCATION_CHANGED) {
     163        if (message == MESSAGE_LOCATION_CHANGED) {
    165164            updateLocation();
    166165            mainPanel.setEnabled(false);
    167 
    168         // When reasoning is done, dialog gets enabled and new proposals are added.
    169         } else if (message == MESSAGE_MATCHES_CHANGED) {
    170             updateMatches();
    171             mainPanel.setEnabled(true);
    172         }*/
     166        }
    173167    }
    174168
     
    195189        matchesComboBox = new javax.swing.JComboBox();
    196190        jLabel6 = new javax.swing.JLabel();
    197         ensureConsistencyButton = new javax.swing.JButton();
     191        statusLabel = new javax.swing.JLabel();
    198192
    199193        jLabel4.setText("jLabel4");
     
    238232        jLabel6.setText("Zaznam v databazi:");
    239233
    240         ensureConsistencyButton.setIcon(ImageProvider.get("actions", "refresh-small.png"));
    241         ensureConsistencyButton.setText("");
    242         ensureConsistencyButton.setToolTipText("Provede nové přiřazení prvků mapy na elementy databáze.\nTouto volbou se zruší všechny manuálně vyřešené konflikty."); // NOI18N
    243         ensureConsistencyButton.addActionListener(new java.awt.event.ActionListener() {
    244             public void actionPerformed(java.awt.event.ActionEvent evt) {
    245                 ensureConsistencyButtonActionPerformed(evt);
    246             }
    247         });
     234        statusLabel.setText(" ");
    248235
    249236        javax.swing.GroupLayout mainPanelLayout = new javax.swing.GroupLayout(mainPanel);
     
    259246                .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
    260247                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, mainPanelLayout.createSequentialGroup()
    261                         .addComponent(locationEdit, javax.swing.GroupLayout.DEFAULT_SIZE, 249, Short.MAX_VALUE)
     248                        .addComponent(locationEdit, javax.swing.GroupLayout.DEFAULT_SIZE, 228, Short.MAX_VALUE)
    262249                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
    263250                        .addComponent(changeLocationButton))
    264                     .addComponent(alternateNumberEdit, javax.swing.GroupLayout.DEFAULT_SIZE, 306, Short.MAX_VALUE)
    265                     .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, mainPanelLayout.createSequentialGroup()
    266                         .addComponent(matchesComboBox, 0, 208, Short.MAX_VALUE)
    267                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
    268                         .addComponent(ensureConsistencyButton))))
    269             .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
    270                 .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 433, Short.MAX_VALUE))
     251                    .addComponent(alternateNumberEdit, javax.swing.GroupLayout.DEFAULT_SIZE, 293, Short.MAX_VALUE)
     252                    .addComponent(matchesComboBox, 0, 293, Short.MAX_VALUE)))
     253            .addComponent(statusLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 433, Short.MAX_VALUE)
     254            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 433, Short.MAX_VALUE)
    271255        );
    272256        mainPanelLayout.setVerticalGroup(
     
    284268                .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
    285269                    .addComponent(jLabel6)
    286                     .addComponent(matchesComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
    287                     .addComponent(ensureConsistencyButton))
    288                 .addContainerGap(179, Short.MAX_VALUE))
    289             .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
    290                 .addGroup(mainPanelLayout.createSequentialGroup()
    291                     .addGap(92, 92, 92)
    292                     .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 175, Short.MAX_VALUE)))
     270                    .addComponent(matchesComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
     271                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
     272                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 161, Short.MAX_VALUE)
     273                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
     274                .addComponent(statusLabel))
    293275        );
    294276
     
    319301
    320302        if (matchesComboBox.getSelectedItem() == null) return;       
    321         Match match = (Match) matchesComboBox.getSelectedItem();
    322 
    323         proposalContainer.setProposals(match.elem.getDiff(
     303        AddressElement selectedElement
     304                           = (AddressElement) matchesComboBox.getSelectedItem();
     305
     306        proposalContainer.setProposals(selectedElement.getDiff(
    324307                                                proposalContainer.getTarget()));
    325308    }//GEN-LAST:event_matchChanged
    326 
    327     private void ensureConsistencyButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ensureConsistencyButtonActionPerformed
    328 //        CzechAddressPlugin.getReasoner().ensureConsistency();
    329     }//GEN-LAST:event_ensureConsistencyButtonActionPerformed
    330309
    331310
     
    333312    private javax.swing.JTextField alternateNumberEdit;
    334313    private javax.swing.JButton changeLocationButton;
    335     private javax.swing.JButton ensureConsistencyButton;
    336314    private javax.swing.JLabel jLabel1;
    337315    private javax.swing.JLabel jLabel4;
     
    343321    private javax.swing.JComboBox matchesComboBox;
    344322    private javax.swing.JList proposalList;
     323    private javax.swing.JLabel statusLabel;
    345324    // End of variables declaration//GEN-END:variables
    346325
    347326    /**
    348      * Painter for adding icons to the {@code matchesComboBox}.
    349      */
    350     private class MatchesComboBoxPainter extends DefaultListCellRenderer {
    351 
    352         ImageIcon envelopeNormIcon = ImageProvider.get("envelope-closed-small.png");
    353         ImageIcon envelopeStarIcon = ImageProvider.get("envelope-closed-star-small.png");
    354         ImageIcon envelopeExclIcon = ImageProvider.get("envelope-closed-exclamation-small.png");
    355 
    356         @Override
    357         public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
    358             Component c = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
    359 
    360 /*            Reasoner r = CzechAddressPlugin.getReasoner();
    361             setIcon(null);
    362 
    363             if (value instanceof Match) {
    364                 Match match = (Match) value;
    365 
    366                 setText(AddressElement.getName(match.elem));
    367 
    368                 if (match.elem instanceof House) {
    369                     setIcon(envelopeStarIcon);
    370                     if ( r.conflicts(match.elem) != null )
    371                         setIcon(envelopeExclIcon);
    372                     else if ( r.translate(match.elem) != null)
    373                         setIcon(envelopeNormIcon);
    374                 }
    375             }*/
    376 
    377             return c;
    378         }
    379     }
    380 
    381     /**
    382327     * Container for all Houses, which match the given 'alternatenumber'.
    383328     */
    384329    private class MatchesComboBoxModel extends HalfCookedComboBoxModel {
    385330
    386         private List<Match> matches = null;
    387         int selectedIndex = -1;
    388 
    389         public void setMatches(List<Match> matches) {
    390             this.matches = matches;
    391             selectedIndex = -1;
     331        private List<AddressElement> matches = null;
     332        AddressElement selected = null;
     333
     334        public void setElements(List<AddressElement> elements) {
     335            this.matches = elements;
     336            selected = null;
    392337            notifyAllListeners();
    393338        }
     
    395340        public void setSelectedItem(Object anItem) {
    396341            if (matches == null) return;
    397             selectedIndex = matches.indexOf(anItem);
     342            selected = (AddressElement) anItem;
     343            if (Reasoner.getInstance().translate(selected) != proposalContainer.getTarget())
     344                statusLabel.setText("Vybraná adresa už v mapě existuje."+
     345                                    " Potvrzením vznikne konflikt.");
     346            else
     347                statusLabel.setText(" ");
    398348        }
    399349
    400350        public Object getSelectedItem() {
    401             return getElementAt(selectedIndex);
     351            return selected;
    402352        }
    403353
     
    409359        public Object getElementAt(int index) {
    410360            if (matches == null) return null;
    411             if ((index < 0) || (index >= matches.size())) return null;
     361            if (index >= matches.size()) return null;
    412362            return matches.get(index);
    413363        }
  • applications/editors/josm/plugins/czechaddress/src/org/openstreetmap/josm/plugins/czechaddress/gui/Renamer.java

    r15461 r15582  
    1212package org.openstreetmap.josm.plugins.czechaddress.gui;
    1313
    14 import java.awt.Component;
    1514import java.awt.event.ActionEvent;
    1615import java.util.ArrayList;
    1716import java.util.List;
    18 import javax.swing.JTable;
    1917import javax.swing.event.TableModelListener;
    2018import javax.swing.table.DefaultTableCellRenderer;
  • applications/editors/josm/plugins/czechaddress/src/org/openstreetmap/josm/plugins/czechaddress/gui/utils/UniversalTreeRenderer.java

    r15558 r15582  
    1 package org.openstreetmap.josm.plugins.czechaddress.gui;
     1package org.openstreetmap.josm.plugins.czechaddress.gui.utils;
    22
    33import java.awt.Component;
  • applications/editors/josm/plugins/czechaddress/src/org/openstreetmap/josm/plugins/czechaddress/intelligence/Reasoner.java

    r15558 r15582  
    11package org.openstreetmap.josm.plugins.czechaddress.intelligence;
    22
     3import java.util.Collections;
    34import java.util.HashMap;
    45import java.util.HashSet;
     
    78import java.util.logging.Level;
    89import java.util.logging.Logger;
    9 import javax.crypto.Mac;
    10 import org.openstreetmap.josm.data.osm.Node;
    1110import org.openstreetmap.josm.data.osm.OsmPrimitive;
    1211import org.openstreetmap.josm.plugins.czechaddress.addressdatabase.AddressElement;
    13 import org.openstreetmap.josm.plugins.czechaddress.addressdatabase.House;
    14 import org.openstreetmap.josm.plugins.czechaddress.addressdatabase.Street;
     12import org.openstreetmap.josm.plugins.czechaddress.proposal.ProposalContainer;
     13import org.openstreetmap.josm.plugins.czechaddress.proposal.ProposalDatabase;
    1514
    1615/**
    1716 * Intended to concentrate all intelligence of
    18  * {@link House}-{@link OsmPrimitive} matching.
     17 * {@link AddressElement}-{@link OsmPrimitive} matching.
    1918 *
    20  * <p>HouseReasoner holds the relations between House and OsmPrimitive
    21  * and also tries to keep it consistent with the state of the map.
    22  * Firstly it is initialised by {@code initReasoner()} and subsequently and
    23  * change done to the map should be reflected in HouseReasoner by calling
    24  * {@code addPrimitive} or {@code removePrimitive}.</p>
     19 * <p>Reasoner holds the relations between AddressElement and OsmPrimitive
     20 * and also tries to keep it consistent with the state of the map.</p>
     21 *
     22 * <p>You can imagine data model as a big matrix, whose rows consist of
     23 * {@code AddressElement}s and columns are {@code OsmPrimitive}s. The cell
     24 * of this matrix is a so-called "quality", which says how well the primitive
     25 * and element fit together (see {@code MATCH_*} for details).
     26 * Through the documentation we will use <tt><b>Q(prim, elem)</b></tt> notation
     27 * for this matrix. The reasoner is memory-efficient iff most of the Q values
     28 * are equal to {@code MATCH_NOMATCH}.</p>
    2529 *
    2630 * <p><b>NOTE:</b> Currently there is no known way of adding a hook into JOSM
    27  * to detect changed or deleted elements. Therefore every call of
    28  * {@code ensureConsistency()} checks for deleted elements, which is rather
    29  * inefficient. Moreover there is a listener for selectionChanged, which
    30  * checks deselcted items for their change. Again, inefficient.</p>
     31 * to detect changed or deleted elements. Therefore there is a
     32 * {@link SelectionMonitor}, which passes every selected primitive to
     33 * the reasoner.</p>
    3134 *
    3235 * @author Radomír Černoch radomir.cernoch@gmail.com
     
    3437public class Reasoner {
    3538
    36     /* A list of {@link OsmPrimitive}s, for which there was no suitable match.*/
     39    public static final int MATCH_OVERWRITE = 4;
     40    public static final int MATCH_ROCKSOLID = 3;
     41    public static final int MATCH_PARTIAL   = 2;
     42    public static final int MATCH_CONFLICT  = 1;
     43    public static final int MATCH_NOMATCH   = 0;
    3744
    3845    private     Map<OsmPrimitive, AddressElement> primBestIndex
     
    5966    }
    6067
     68//==============================================================================
     69// INPUT METHODS
     70//==============================================================================
     71
     72    /**
     73     * Brings the reasoner to the initial state
     74     */
    6175    public void reset() {
    6276        primToUpdate.clear();
     
    6882        primBestIndex.clear();
    6983
     84        transactionOpened = false;
     85
    7086        for (ReasonerListener listener : listeners)
    7187            listener.resonerReseted();
    7288    }
    73    
    74     public Set<AddressElement> getCandidates(OsmPrimitive prim) {
    75 
    76         int best = Match.MATCH_NOMATCH;
    77         for (AddressElement elem : primMatchIndex.get(prim).keySet()) {
    78             int cand = primMatchIndex.get(prim).get(elem);
    79             if (best < cand)
    80                 best = cand;
    81         }
    82 
    83         Set<AddressElement> result = new HashSet<AddressElement>();
    84 
    85         for (AddressElement elem : primMatchIndex.get(prim).keySet()) {
    86             int cand = primMatchIndex.get(prim).get(elem);
    87             if (best == cand)
    88                 result.add(elem);
    89         }
    90         return result;
    91     }
    92 
    93     public Set<OsmPrimitive> getCandidates(AddressElement elem) {
    94 
    95         int best = Match.MATCH_NOMATCH;
    96         for (OsmPrimitive prim : elemMatchIndex.get(elem).keySet()) {
    97             int cand = elemMatchIndex.get(elem).get(prim);
    98             if (best < cand)
    99                 best = cand;
    100         }
    101 
    102         Set<OsmPrimitive> result = new HashSet<OsmPrimitive>();
    103        
    104         for (OsmPrimitive prim : elemMatchIndex.get(elem).keySet()) {
    105             int cand = elemMatchIndex.get(elem).get(prim);
    106             if (best == cand)
    107                 result.add(prim);
    108         }
    109         return result;
    110     }
    111 
    112     public AddressElement getStrictlyBest(OsmPrimitive prim) {
    113 
    114         Map<AddressElement, Integer> matches = primMatchIndex.get(prim);
    115         //if (matches == null) return null;
    116 
    117         AddressElement bestE = null;
    118         int bestQ = Match.MATCH_NOMATCH;
    119 
    120         for (AddressElement elem : matches.keySet()) {
    121             if (matches.get(elem) == bestQ)
    122                 bestE = null;
    123 
    124             if (matches.get(elem) > bestQ) {
    125                 bestQ = matches.get(elem);
    126                 bestE = elem;
    127             }
    128         }
    129 
    130         return bestE;
    131     }
    132 
    133     public OsmPrimitive getStrictlyBest(AddressElement prim) {
    134 
    135         Map<OsmPrimitive, Integer> matches = elemMatchIndex.get(prim);
    136         //if (matches == null) return null;
    137 
    138         OsmPrimitive bestE = null;
    139         int bestQ = Match.MATCH_NOMATCH;
    140 
    141         for (OsmPrimitive elem : matches.keySet()) {
    142             if (matches.get(elem) == bestQ)
    143                 bestE = null;
    144 
    145             if (matches.get(elem) > bestQ) {
    146                 bestQ = matches.get(elem);
    147                 bestE = elem;
    148             }
    149         }
    150 
    151         return bestE;
    152     }
    153 
     89
     90    /**
     91     * Indicates whether there is currently an open transaction
     92     */
     93    private boolean transactionOpened = false;
     94
     95    /**
     96     * Prepares reasoner to modify its data.
     97     *
     98     * <p>This method must be called before <u>any</u> method, which might
     99     * modify the data in the reasoner.
     100     * The only exception is {@code reset()}.</p>
     101     *
     102     * <p>When there's an open transaction, the result of most output methods
     103     * undefined. Exceptions to this rules are indicated.</p>
     104     *
     105     * <p><b>Transactions:</b> This method requires a closed transaction.</p>
     106     */
    154107    public void openTransaction() {
    155108        assert primToUpdate.size() == 0;
    156109        assert elemToUpdate.size() == 0;
    157     }
    158 
     110        assert !transactionOpened;
     111
     112        primToUpdate.clear();
     113        elemToUpdate.clear();
     114        transactionOpened = true;
     115    }
     116
     117    /**
     118     * Turns the reasoner back into consistent state.
     119     *
     120     * <p>Recreates {@code *BestIndex} indexes, sends notification to
     121     * all listeners about changed elements/primitives and closes
     122     * the transaction.</p>
     123     *
     124     * <p><b>Transactions:</b> This method requires an open transaction.</p>
     125     */
    159126    public void closeTransaction() {
     127        assert transactionOpened;
    160128
    161129        Set<AddressElement> elemChanges = new HashSet<AddressElement>();
     
    168136                if (bestMatch == null) {
    169137                    logger.log(Level.FINE, "primitive has no longer best match",
    170                             AddressElement.getName(prim));
     138                                           AddressElement.getName(prim));
    171139                    primBestIndex.remove(prim);
    172140                } else {
     
    200168        elemToUpdate.addAll(elemChanges);
    201169        primToUpdate.addAll(primChanges);
     170        transactionOpened = false;
    202171
    203172        for (ReasonerListener listener : listeners) {
     
    205174                if (elem != null)
    206175                    listener.elementChanged(elem);
    207            
     176
    208177            for (OsmPrimitive prim : primToUpdate)
    209178                if (prim != null)
    210179                    listener.primitiveChanged(prim);
    211180        }
    212        
     181
    213182        primToUpdate.clear();
    214183        elemToUpdate.clear();
    215184    }
    216185
    217     private Set<ReasonerListener> listeners = new HashSet<ReasonerListener>();
    218 
    219     public void reconsider(OsmPrimitive prim, AddressElement elem) {
     186    /**
     187     * Update all relations of the given primitive.
     188     *
     189     * <p>If the primitive is unknown to the reasoner, it's added.
     190     * Then it updates all cells in the Q matrix's column, which corresponds
     191     * to the provided primitive. In the Q-matrix analogy is roughly equivalent
     192     * to doing an update
     193     * <center>∀ elem. Q(elem, prim) ← elem.getQ(prim).</center>
     194     * Hence its time complexity is linear.</p>
     195     *
     196     * <p><b>Transactions:</b> This method requires an open transaction.</p>
     197     */
     198    public void update(OsmPrimitive prim) {
     199        logger.log(Level.FINER, "considering primitive", AddressElement.getName(prim));
     200        assert transactionOpened;
     201
     202
     203        Map<AddressElement, Integer> matches = primMatchIndex.get(prim);
     204        if (matches == null) {
     205            logger.log(Level.FINE, "new primitive detected", AddressElement.getName(prim));
     206            matches = new HashMap<AddressElement, Integer>();
     207            primMatchIndex.put(prim, matches);
     208        }
     209
     210        for (AddressElement elem : elemMatchIndex.keySet())
     211            reconsider(prim, elem);
     212    }
     213
     214    /**
     215     * Update all relations of the given element
     216     *
     217     * <p>If the primitive is unknown to the reasoner, it's added.
     218     * Then it updates all cells in the Q matrix's row, which corresponds
     219     * to the provided element.In the Q-matrix analogy is roughly equivalent
     220     * to doing an update
     221     * <center>∀ prim. Q(elem, prim) ← elem.getQ(prim).</center>
     222     * Hence its time complexity is linear.</p>
     223     *
     224     * <p><b>Transactions:</b> This method requires an open transaction.</p>
     225     */
     226    public void update(AddressElement elem) {
     227        logger.log(Level.FINER, "considering element", elem);
     228        assert transactionOpened;
     229
     230        Map<OsmPrimitive, Integer> matches = elemMatchIndex.get(elem);
     231        if (matches == null) {
     232            logger.log(Level.FINE, "new element detected", elem);
     233            matches = new HashMap<OsmPrimitive, Integer>();
     234            elemMatchIndex.put(elem, matches);
     235        }
     236
     237        for (OsmPrimitive prim : primMatchIndex.keySet())
     238            reconsider(prim, elem);
     239    }
     240
     241    /**
     242     * Internal method for doing the actual Q value update.
     243     */
     244    private void reconsider(OsmPrimitive prim, AddressElement elem) {
     245        assert transactionOpened;
    220246
    221247        int oldQ = getQ(prim, elem);
    222         int newQ = Match.evalQ(prim, elem, oldQ);
     248        int newQ = evalQ(prim, elem, oldQ);
    223249
    224250        if (oldQ != newQ) {
     
    237263    }
    238264
    239     public void consider(OsmPrimitive prim) {
    240         logger.log(Level.FINER, "considering primitive", AddressElement.getName(prim));
    241 
    242         Map<AddressElement, Integer> matches = primMatchIndex.get(prim);
    243         if (matches == null) {
    244             logger.log(Level.FINE, "new primitive detected", AddressElement.getName(prim));
    245             matches = new HashMap<AddressElement, Integer>();
    246             primMatchIndex.put(prim, matches);
    247         }
    248 
    249         for (AddressElement elem : elemMatchIndex.keySet())
    250             reconsider(prim, elem);
    251     }
    252 
    253     public void consider(AddressElement elem) {
    254         logger.log(Level.FINER, "considering element", elem);
    255 
    256         Map<OsmPrimitive, Integer> matches = elemMatchIndex.get(elem);
    257         if (matches == null) {
    258             logger.log(Level.FINE, "new element detected", elem);
    259             matches = new HashMap<OsmPrimitive, Integer>();
    260             elemMatchIndex.put(elem, matches);
    261         }
    262 
    263         for (OsmPrimitive prim : primMatchIndex.keySet())
    264             reconsider(prim, elem);
    265     }
    266 
    267     public int getQ(OsmPrimitive prim, AddressElement elem) {
     265    /**
     266     * Sets the relation's Q value to highest possible.
     267     *
     268     * <p>Regardless of how well the primitive and element pair fits
     269     * together, it assings their Q value to {@code MATCH_OVERWRITE}.</p>
     270     *
     271     * <p><b>Transactions:</b> This method requires an open transaction.</p>
     272     */
     273    public void doOverwrite(OsmPrimitive prim, AddressElement elem) {
     274        logger.log(Level.FINER, "overwriting match",
     275                    "elem=„" + elem + "“; " +
     276                    "prim=„" + AddressElement.getName(prim) + "“");
     277        assert transactionOpened;
     278
     279        update(prim);
     280        update(elem);
     281        putQ(prim, elem, MATCH_OVERWRITE);
     282
     283        primToUpdate.add(prim);
     284        elemToUpdate.add(elem);
     285    }
     286
     287    /**
     288     * Sets the relation to its original Q value.
     289     *
     290     * <p>If the element-primitive pair was previously edited by
     291     * {@code doOverwrite()} method, this returns their Q to the
     292     * original value, which is determined by {@code evalQ()}.</p>
     293     *
     294     * <p><b>Transactions:</b> This method requires an open transaction.</p>
     295     */
     296    public void unOverwrite(OsmPrimitive prim, AddressElement elem) {
     297        logger.log(Level.FINER, "unoverwriting match",
     298                    "elem=„" + elem + "“; " +
     299                    "prim=„" + AddressElement.getName(prim) + "“");
     300        assert transactionOpened;
     301
     302        update(prim);
     303        update(elem);
     304        putQ(prim, elem, evalQ(prim, elem, MATCH_NOMATCH));
     305
     306        primToUpdate.add(prim);
     307        elemToUpdate.add(elem);
     308    }
     309
     310    /**
     311     * Returns the Q value of the given primitive-element relation.
     312     */
     313    private int getQ(OsmPrimitive prim, AddressElement elem) {
    268314        assert primMatchIndex.get(prim).get(elem)
    269315            == elemMatchIndex.get(elem).get(prim);
     
    275321    }
    276322
    277     public void putQ(OsmPrimitive prim, AddressElement elem, int qVal) {
    278        
    279         if (qVal == Match.MATCH_NOMATCH) {
     323    /**
     324     * Sets the Q value of the given primitive-element relation.
     325     */
     326    private void putQ(OsmPrimitive prim, AddressElement elem, int qVal) {
     327
     328        if (qVal == MATCH_NOMATCH) {
    280329            primMatchIndex.get(prim).remove(elem);
    281330            elemMatchIndex.get(elem).remove(prim);
     
    286335    }
    287336
     337    /**
     338     * Evaluates the Q value between the given primitive and element.
     339     *
     340     * <p>If {@code oldQ} is {@code MATCH_OVERWRITE}, it is preserved.</p>
     341     */
     342    private int evalQ(OsmPrimitive prim, AddressElement elem, Integer oldQ) {
     343
     344        if (prim.deleted)
     345            return MATCH_NOMATCH;
     346
     347        if (oldQ == MATCH_OVERWRITE)
     348            return MATCH_OVERWRITE;
     349
     350        return elem.getQ(prim);
     351    }
     352
     353//==============================================================================
     354// OUTPUT METHODS
     355//==============================================================================
     356
     357    /**
     358     * Returns the primitive, which is a unique counterpart of the element.
     359     *
     360     * <p>This method is probably the single most used method of the reasoner.
     361     * It allows the unique translation between map and the database.</p>
     362     *
     363     * <p>An element <i>elem</i> and primitive <i>prim</i> can be translated
     364     * between each other iff
     365     * <center>[∄ <i>prim'</i>. Q(elem, prim') ≥ Q(elem, prim)] ∧
     366     *         [∄ <i>elem'</i>. Q(elem', prim) ≥ Q(elem, prim)].</center>
     367     * In other words, the cell at Q(elem, prim) is the strictly greatest one
     368     * in both its row and the column of the Q matrix.</p>
     369     *
     370     * <p>This method depends on {@code getStrictlyBest()}, which induces its
     371     * complexity properties.</p>
     372     *
     373     * <p><b>Transactions:</b> Can be called regardless of transaction state.
     374     * However if the transaction is closed, its time-complexity reduces to
     375     * constant thanks to using indexes.</p>
     376     */
    288377    public AddressElement translate(OsmPrimitive prim) {
    289378        if (prim == null) return null;
    290379
    291         AddressElement elem = primBestIndex.get(prim);
    292         if (elemBestIndex.get(elem) == prim)
     380        AddressElement elem = getStrictlyBest(prim);
     381        if (getStrictlyBest(elem) == prim)
    293382            return elem;
     383       
    294384        return null;
    295385    }
    296386
     387    /**
     388     * Returns the element, which is a unique counterpart of the primitive.
     389     *
     390     * <p>This method is probably the single most used method of the reasoner.
     391     * It allows the unique translation between map and the database.</p>
     392     *
     393     * <p>An element <i>elem</i> and primitive <i>prim</i> can be translated
     394     * between each other iff
     395     * <center>[∄ <i>prim'</i>. Q(elem, prim') ≥ Q(elem, prim)] ∧
     396     *         [∄ <i>elem'</i>. Q(elem', prim) ≥ Q(elem, prim)].</center>
     397     * In other words, the cell at Q(elem, prim) is the strictly greatest one
     398     * in both its row and the column of the Q matrix.</p>
     399     *
     400     * <p>This method depends on {@code getStrictlyBest()}, which induces its
     401     * complexity properties.</p>
     402     *
     403     * <p><b>Transactions:</b> Can be called regardless of transaction state.
     404     * However if the transaction is closed, its time-complexity reduces to
     405     * constant thanks to using indexes.</p>
     406     */
    297407    public OsmPrimitive translate(AddressElement elem) {
    298408        if (elem == null) return null;
    299409
    300         OsmPrimitive prim = elemBestIndex.get(elem);
    301         if (primBestIndex.get(prim) == elem)
     410        OsmPrimitive prim = getStrictlyBest(elem);
     411        if (getStrictlyBest(prim) == elem)
    302412            return prim;
     413       
    303414        return null;
    304415    }
    305416
    306     public Set<AddressElement> getConflicts(OsmPrimitive prim) {
    307 
    308         Set<AddressElement> result = getCandidates(prim);
    309         AddressElement match = translate(prim);
    310         if (match != null)
    311             result.remove(match);
    312 
    313         return result;
    314     }
    315 
    316     public Set<OsmPrimitive> getConflicts(AddressElement elem) {
    317 
    318         Set<OsmPrimitive> result = getCandidates(elem);
    319         OsmPrimitive match = translate(elem);
    320         if (match != null)
    321             result.remove(match);
    322 
    323         return result;
    324     }
    325 
    326     public void addListener(ReasonerListener listener) {
    327         listeners.add(listener);
    328     }
    329 
    330     public void removeListener(ReasonerListener listener) {
    331         listeners.remove(listener);
    332     }
    333 
    334     public static void main(String[] args) {
    335         try {
    336 
    337             Reasoner r = Reasoner.getInstance();
    338             Reasoner.logger.setLevel(Level.ALL);
    339            
    340             Street s1 = new Street("Jarní");
    341             Street s2 = new Street("Letní");
    342 
    343             House h1 = new House("240", "1"); s1.addHouse(h1); r.consider(h1);
    344             House h2 = new House("241", "2"); s1.addHouse(h2); r.consider(h2);
    345             House h3 = new House("241", "3"); s1.addHouse(h3); r.consider(h3);
    346             House h4 = new House("242", "4"); s1.addHouse(h4); r.consider(h4);
    347 
    348             House i1 = new House("42",  "1"); s2.addHouse(i1); r.consider(i1);
    349             House i2 = new House("45",  "2"); s2.addHouse(i2); r.consider(i2);
    350             House i3 = new House("61",  "3"); s2.addHouse(i3); r.consider(i3);
    351             House i4 = new House("240", "4"); s2.addHouse(i4); r.consider(i4);
    352 
    353 
    354            
    355             Node n1 = new Node(1);
    356             n1.put("addr:street", "Jarní");
    357             n1.put("addr:alternatenumber", "242");
    358 
    359             r.openTransaction();
    360             r.consider(n1);
    361             r.closeTransaction();
    362             assert r.translate(n1) == h4;
    363             assert r.getConflicts(n1).size() == 0;
    364 
    365 
    366 
    367             Node n2 = new Node(2);
    368             n2.put("addr:alternatenumber", "240");
    369             r.openTransaction();
    370             r.consider(n2);
    371             r.closeTransaction();
    372             assert r.translate(n2) == null;
    373             assert r.getConflicts(n2).contains(h1);
    374             assert r.getConflicts(n2).contains(i4);
    375 
    376             n2.put("addr:street", "Letní");
    377             n2.put("addr:housenumber", "4");
    378             r.openTransaction();
    379             r.consider(n2);
    380             r.closeTransaction();
    381             assert r.translate(n2) == i4;
    382 
    383 
    384             n2.deleted = true;
    385             r.openTransaction();
    386             r.consider(n2);
    387             r.closeTransaction();
    388             assert r.translate(n2) == null;
    389            
    390         } catch (Exception ex) {
    391            
    392             ex.printStackTrace();
    393         }
    394     }
    395 
    396     public void doOverwrite(OsmPrimitive prim, AddressElement elem) {
    397         logger.log(Level.FINER, "overwriting match",
    398                     "elem=„" + elem + "“; " +
    399                     "prim=„" + AddressElement.getName(prim) + "“");
    400 
    401         consider(prim);
    402         consider(elem);
    403         putQ(prim, elem, Match.MATCH_OVERWRITE);
    404 
    405         primToUpdate.add(prim);
    406         elemToUpdate.add(elem);
    407     }
    408 
    409     public void unOverwrite(OsmPrimitive prim, AddressElement elem) {
    410         logger.log(Level.FINER, "unoverwriting match",
    411                     "elem=„" + elem + "“; " +
    412                     "prim=„" + AddressElement.getName(prim) + "“");
    413 
    414         consider(prim);
    415         consider(elem);
    416         putQ(prim, elem, Match.evalQ(prim, elem, Match.MATCH_NOMATCH));
    417 
    418         primToUpdate.add(prim);
    419         elemToUpdate.add(elem);
    420     }
    421 
     417    /**
     418     * Says whether the given primitive has a conflict.
     419     *
     420     * <p>There are two conditions for a primitive to be in a conflict. It must
     421     * be at least partially fitting to some element, but it cannot be
     422     * uniquely translatable.
     423     * <center> [∃ elem. Q(elem, prim) > NO_MATCH] ∧
     424     *          ]∄ elem. elem = translate(prim)] ,</center>
     425     * which is equivalent to saying that
     426     * <center>|getCandidates(prim)| ≥ 2</center></p>
     427     */
    422428    public boolean inConflict(OsmPrimitive prim) {
     429        if (primMatchIndex.get(prim) == null) return false;
    423430        return primMatchIndex.get(prim).size() > 0
    424431            && translate(translate(prim)) != prim;
    425432    }
    426433
     434    /**
     435     * Says whether the given element has a conflict.
     436     *
     437     * <p>There are two conditions for a element to be in a conflict. It must
     438     * be at least partially fitting to some primitive, but it cannot be
     439     * uniquely translatable.
     440     * <center> [∃ prim. Q(elem, prim) > NO_MATCH] ∧
     441     *          [∄ prim. prim = translate(elem)] ,</center>
     442     * which is equivalent to saying that
     443     * <center>|getCandidates(prim)| ≥ 2</center></p>
     444     */
    427445    public boolean inConflict(AddressElement elem) {
     446        if (elemMatchIndex.get(elem) == null) return false;
    428447        return elemMatchIndex.get(elem).size() > 0
    429448            && translate(translate(elem)) != elem;
    430449    }
    431450
     451
     452    /**
     453     * Returns elements having the best quality for the given primitive.
     454     *
     455     * <p>It searches among all Q values corresponding to the given primitive
     456     * and returns a set of all elements, whose relation has the greatest
     457     * Q value. Formally we can write that the output is a set
     458     * <center>{elem |   Q(elem, prim) > MATCH_NOMATCH
     459     *                 ∧ ∀ elem'. Q(elem, prim) ≥ Q(elem', prim)}.</center></p>
     460     *
     461     * <p><b>Transactions:</b> Can be called regardless of transaction state.</p>
     462     *
     463     * @return A new set, which can be freely manipulated. Changes are not
     464     * reflected in the reasoner.
     465     */
     466    public Set<AddressElement> getCandidates(OsmPrimitive prim) {
     467
     468        int best = MATCH_NOMATCH;
     469        for (AddressElement elem : primMatchIndex.get(prim).keySet()) {
     470            int cand = primMatchIndex.get(prim).get(elem);
     471            if (best < cand)
     472                best = cand;
     473        }
     474
     475        Set<AddressElement> result = new HashSet<AddressElement>();
     476
     477        for (AddressElement elem : primMatchIndex.get(prim).keySet()) {
     478            int cand = primMatchIndex.get(prim).get(elem);
     479            if (best == cand)
     480                result.add(elem);
     481        }
     482        return result;
     483    }
     484
     485    /**
     486     * Returns primitives having the best quality for the given element.
     487     *
     488     * <p>It searches among all Q values corresponding to the given element
     489     * and returns a set of all primitives, whose relation has the greatest
     490     * Q value. Formally we can write that the output is a set
     491     * <center>{prim |   Q(elem, prim) > MATCH_NOMATCH
     492     *                 ∧ ∀ prim'. Q(elem, prim) ≥ Q(elem, prim')}.</center></p>
     493     *
     494     * <p><b>Transactions:</b> Can be called regardless of transaction state.</p>
     495     *
     496     * @return A new set, which can be freely manipulated. Changes are not
     497     * reflected in the reasoner.
     498     */
     499    public Set<OsmPrimitive> getCandidates(AddressElement elem) {
     500
     501        int best = MATCH_NOMATCH;
     502        for (OsmPrimitive prim : elemMatchIndex.get(elem).keySet()) {
     503            int cand = elemMatchIndex.get(elem).get(prim);
     504            if (best < cand)
     505                best = cand;
     506        }
     507
     508        Set<OsmPrimitive> result = new HashSet<OsmPrimitive>();
     509       
     510        for (OsmPrimitive prim : elemMatchIndex.get(elem).keySet()) {
     511            int cand = elemMatchIndex.get(elem).get(prim);
     512            if (best == cand)
     513                result.add(prim);
     514        }
     515        return result;
     516    }
     517
     518    /**
     519     * Returns the element having the best quality for the given primitive.
     520     *
     521     * <p>It searches among all Q values corresponding to the given primitive
     522     * and returns such an element, whose relation has the greatest
     523     * Q value. If there are more of them, {@code null} is returned.
     524     * Formally we can write that the output is a primitive
     525     * <center>elem: Q(elem, prim) > MATCH_NOMATCH
     526     *             ∧ ∀ elem'. Q(elem, prim) > Q(elem', prim)}.</center></p>
     527     *
     528     * <p>If {@code getCandidates(prim)} returns exactly one element,
     529     * this method should return the same one. Otherwise {@code null}.</p>
     530     *
     531     * <p><b>Transactions:</b> Can be called regardless of transaction state.
     532     * However if the transaction is closed, its time-complexity reduces to
     533     * constant thanks to using indexes.</p>
     534     */
     535    public AddressElement getStrictlyBest(OsmPrimitive prim) {
     536
     537        if (!transactionOpened)
     538            return primBestIndex.get(prim);
     539
     540        Map<AddressElement, Integer> matches = primMatchIndex.get(prim);
     541        AddressElement bestE = null;
     542        int bestQ = MATCH_NOMATCH;
     543
     544        for (AddressElement elem : matches.keySet()) {
     545            if (matches.get(elem) == bestQ)
     546                bestE = null;
     547
     548            if (matches.get(elem) > bestQ) {
     549                bestQ = matches.get(elem);
     550                bestE = elem;
     551            }
     552        }
     553
     554        return bestE;
     555    }
     556
     557    /**
     558     * Returns the primitive having the best quality for the given element.
     559     *
     560     * <p>It searches among all Q values corresponding to the given element
     561     * and returns sucha  primitive, whose relation has the greatest
     562     * Q value. If there are more of them, {@code null} is returned.
     563     * Formally we can write that the output is a primitive
     564     * <center>prim: Q(elem, prim) > MATCH_NOMATCH
     565     *             ∧ ∀ prim'. Q(elem, prim) > Q(elem', prim)}.</center></p>
     566     *
     567     * <p>If {@code getCandidates(elem)} returns exactly one primitive,
     568     * this method should return the same one. Otherwise {@code null}.</p>
     569     *
     570     * <p><b>Transactions:</b> Can be called regardless of transaction state.
     571     * However if the transaction is closed, its time-complexity reduces to
     572     * constant thanks to using indexes.</p>
     573     */
     574    public OsmPrimitive getStrictlyBest(AddressElement elem) {
     575
     576        if (!transactionOpened)
     577            return elemBestIndex.get(elem);
     578
     579        Map<OsmPrimitive, Integer> matches = elemMatchIndex.get(elem);
     580        OsmPrimitive bestE = null;
     581        int bestQ = MATCH_NOMATCH;
     582
     583        for (OsmPrimitive prim : matches.keySet()) {
     584            if (matches.get(prim) == bestQ)
     585                bestE = null;
     586
     587            if (matches.get(prim) > bestQ) {
     588                bestQ = matches.get(prim);
     589                bestE = prim;
     590            }
     591        }
     592
     593        return bestE;
     594    }
     595
     596    /**
     597     * Returns all elements which are not translatable.
     598     */
    432599    public Set<AddressElement> getUnassignedElements() {
    433600        Set<AddressElement> result = new HashSet<AddressElement>();
    434601        for (AddressElement elem : elemMatchIndex.keySet())
    435             if (elemMatchIndex.get(elem).size() == 0)
     602            if (translate(elem) == null)
    436603                result.add(elem);
    437604        return result;
    438605    }
     606
     607    /**
     608     * Returns all primitives which are not translatable.
     609     */
     610    public Set<OsmPrimitive> getUnassignedPrimitives() {
     611        Set<OsmPrimitive> result = new HashSet<OsmPrimitive>();
     612        for (OsmPrimitive prim : primMatchIndex.keySet())
     613            if (translate(prim) == null)
     614                result.add(prim);
     615        return result;
     616    }
     617
     618    /**
     619     * Returns all elements, which were {@code update}d from
     620     * the last {@code reset}.
     621     */
     622    public Set<AddressElement> getAllElements() {
     623        Set<AddressElement> result = new HashSet<AddressElement>();
     624        result.addAll(elemMatchIndex.keySet());
     625        return result;
     626    }
     627
     628    /**
     629     * Returns all elements, which were {@code update}d from
     630     * the last {@code reset}.
     631     */
     632    public Set<OsmPrimitive> getAllPrimitives() {
     633        Set<OsmPrimitive> result = new HashSet<OsmPrimitive>();
     634        result.addAll(primMatchIndex.keySet());
     635        return result;
     636    }
     637
     638//==============================================================================
     639// MISC METHODS
     640//==============================================================================
     641
     642    /**
     643     * Returns proposals to fit all translatable primitives to their elements.
     644     */
     645    public ProposalDatabase getProposals() {
     646        ProposalDatabase database = new ProposalDatabase();
     647
     648        // We can go only over primBestIndex to save some iterations.
     649        // A primitive cannot be translated unless contained in primBestIndex.
     650        for (OsmPrimitive prim : primBestIndex.keySet()) {
     651            AddressElement elem = translate(prim);
     652            if (elem == null) continue;
     653
     654            ProposalContainer container = new ProposalContainer(prim);
     655            container.addProposals(elem.getDiff(prim));
     656           
     657            if (container.getProposals().size() > 0)
     658                database.addContainer(container);
     659        }
     660
     661        Collections.sort(database.getContainers());
     662        return database;
     663    }
     664
     665    /**
     666     * Set of listeners currently hooked to changes in this reasoner.
     667     */
     668    private Set<ReasonerListener> listeners = new HashSet<ReasonerListener>();
     669
     670    /**
     671     * Adds a new listener to receive reasoner's status changes.
     672     */
     673    public void addListener(ReasonerListener listener) {
     674        listeners.add(listener);
     675    }
     676
     677    /**
     678     * Stops the listener to receive reasoner's status changes.
     679     */
     680    public void removeListener(ReasonerListener listener) {
     681        listeners.remove(listener);
     682    }
     683
    439684}
  • applications/editors/josm/plugins/czechaddress/src/org/openstreetmap/josm/plugins/czechaddress/intelligence/SelectionMonitor.java

    r15558 r15582  
    66import org.openstreetmap.josm.data.osm.OsmPrimitive;
    77import org.openstreetmap.josm.plugins.czechaddress.NotNullList;
     8import org.openstreetmap.josm.plugins.czechaddress.addressdatabase.House;
     9import org.openstreetmap.josm.plugins.czechaddress.addressdatabase.Street;
    810
    911/**
     
    3739            r.openTransaction();
    3840            for (OsmPrimitive selectedPrim :newSelection)
    39                 r.consider(selectedPrim);
     41                if (House.isMatchable(selectedPrim) || Street.isMatchable(selectedPrim))
     42                    r.update(selectedPrim);
    4043            for (OsmPrimitive selectedPrim :lastSelection)
    41                 r.consider(selectedPrim);
     44                if (House.isMatchable(selectedPrim) || Street.isMatchable(selectedPrim))
     45                    r.update(selectedPrim);
    4246            r.closeTransaction();
    4347        }
  • applications/editors/josm/plugins/czechaddress/src/org/openstreetmap/josm/plugins/czechaddress/parser/DatabaseParser.java

    r15558 r15582  
    108108
    109109            int total = 0, count;
    110             byte[] buffer = new byte[1024*128];
     110            byte[] buffer = new byte[1024*512];
    111111            while ((count = con.getInputStream().read(buffer)) >= 0) {
    112112                bos.write(buffer, 0, count);
  • applications/editors/josm/plugins/czechaddress/src/org/openstreetmap/josm/plugins/czechaddress/parser/MvcrParser.java

    r15461 r15582  
    4444
    4545            // If the region filter is on, apply it!
    46             if (filRegion != null && !attributes.getValue("nazev").equals(filRegion))
    47                 return;
     46            if (filRegion != null && !attributes.getValue("nazev").equals(filRegion)) {
     47                curRegion = null;
     48                curViToCi = null;
     49                curSuburb = null;
     50                curStreet = null;
     51                return;
     52            }
    4853
    4954            /*curRegion = target.findRegion(
     
    7075
    7176            // If the viToCi filter is on, apply it!
    72             if (filViToCi != null && !attributes.getValue("nazev").equals(filViToCi))
    73                 return;
     77            if (filViToCi != null && !attributes.getValue("nazev").equals(filViToCi)) {
     78                curViToCi = null;
     79                curSuburb = null;
     80                curStreet = null;
     81                return;
     82            }
    7483
    7584            //curViToCi = curRegion.findViToCi(attributes.getValue("nazev"));
     
    8796
    8897            // If the suburb filter is on, apply it!
    89             if (filSuburb != null && !attributes.getValue("nazev").equals(filSuburb))
    90                 return;
     98            if (filSuburb != null && !attributes.getValue("nazev").equals(filSuburb)) {
     99                curSuburb = null;
     100                curStreet = null;
     101                return;
     102            }
    91103
    92104            //curSuburb = curViToCi.findSuburb(attributes.getValue("nazev"));
     
    102114
    103115            // If the street filter is on, apply it!
    104             if (filStreet != null && !attributes.getValue("nazev").equals(filStreet))
    105                 return;
     116            if (filStreet != null && !attributes.getValue("nazev").equals(filStreet)) {
     117                curStreet = null;
     118                return;
     119            }
    106120
    107121            ElementWithStreets   topElem = curSuburb;
  • applications/editors/josm/plugins/czechaddress/src/org/openstreetmap/josm/plugins/czechaddress/proposal/ProposalContainer.java

    r15166 r15582  
    99import javax.swing.event.ListDataListener;
    1010import org.openstreetmap.josm.data.osm.OsmPrimitive;
     11import org.openstreetmap.josm.plugins.czechaddress.PrimUtils;
    1112
    1213/**
     
    2223 * @see Proposal
    2324 */
    24 public class ProposalContainer implements ListModel {
     25public class ProposalContainer implements ListModel, Comparable<ProposalContainer> {
    2526
    2627
     
    216217    }
    217218
     219    public int compareTo(ProposalContainer o) {
     220        return PrimUtils.comparator.compare(this.target, o.target);
     221    }
     222
    218223}
Note: See TracChangeset for help on using the changeset viewer.