Changeset 15582 in osm for applications/editors/josm/plugins/czechaddress/src/org
- Timestamp:
- 2009-06-03T23:42:55+02:00 (16 years ago)
- 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 31 31 import org.openstreetmap.josm.plugins.czechaddress.actions.FactoryAction; 32 32 import org.openstreetmap.josm.plugins.czechaddress.actions.HelpAction; 33 import org.openstreetmap.josm.plugins.czechaddress.actions.M odifierAction;33 import org.openstreetmap.josm.plugins.czechaddress.actions.ManagerAction; 34 34 import org.openstreetmap.josm.plugins.czechaddress.actions.SplitAreaByEmptyWayAction; 35 import org.openstreetmap.josm.plugins.czechaddress.addressdatabase.Street; 35 36 import org.openstreetmap.josm.plugins.czechaddress.gui.ConflictResolver; 36 37 import org.openstreetmap.josm.plugins.czechaddress.gui.FactoryDialog; 37 38 import org.openstreetmap.josm.plugins.czechaddress.gui.LocationSelector; 39 import org.openstreetmap.josm.plugins.czechaddress.gui.ManagerDialog; 38 40 import org.openstreetmap.josm.plugins.czechaddress.intelligence.Reasoner; 39 41 import org.openstreetmap.josm.plugins.czechaddress.intelligence.SelectionMonitor; … … 82 84 addStatusListener(this); 83 85 84 Reasoner.getInstance();85 86 ConflictResolver.getInstance(); 86 87 SelectionMonitor.getInstance(); 88 FactoryDialog.getInstance(); 89 Reasoner.getInstance(); 87 90 88 initLoggers(); 91 boolean assertionsEnabled = false; 92 assert assertionsEnabled = true; 93 if (assertionsEnabled) initLoggers(); 89 94 90 95 MainMenu.add(Main.main.menu.toolsMenu, new SplitAreaByEmptyWayAction()); … … 94 99 parser.setTargetDatabase(Database.getInstance()); 95 100 parser.setStorageDir(getPluginDir()); 96 97 parser.setFilter("HUSTOPEČE", "HUSTOPEČE", null, null);98 101 99 102 // Fill the database in separate thread. … … 130 133 reasoner.reset(); 131 134 reasoner.openTransaction(); 132 //Reasoner.logger.setLevel(Level.OFF);133 135 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 135 141 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); 144 144 } 145 //Reasoner.logger.setLevel(Level.ALL);146 145 reasoner.closeTransaction(); 147 146 } 147 ManagerDialog dialog = new ManagerDialog(); 148 if (dialog.countAutomaticRenameProposals() > 0) 149 dialog.setVisible(true); 148 150 } 149 151 … … 178 180 menuItems.add(MainMenu.add(czechMenu, new GroupManipulatorAction())); 179 181 menuItems.add(MainMenu.add(czechMenu, new ConflictResolveAction())); 180 menuItems.add(MainMenu.add(czechMenu, new M odifierAction()));182 menuItems.add(MainMenu.add(czechMenu, new ManagerAction())); 181 183 menuItems.add(MainMenu.add(czechMenu, new HelpAction())); 182 184 return; -
applications/editors/josm/plugins/czechaddress/src/org/openstreetmap/josm/plugins/czechaddress/PrimUtils.java
r15558 r15582 7 7 8 8 import java.util.Comparator; 9 import org.openstreetmap.josm.data.coor.LatLon;10 import org.openstreetmap.josm.data.osm.Node;11 9 import org.openstreetmap.josm.data.osm.OsmPrimitive; 12 import org.openstreetmap.josm.data.osm.Way;13 10 14 11 /** … … 16 13 * @author Radomír Černoch, radomir.cernoch@gmail.com 17 14 */ 18 public class PrimUtils implements Comparator<OsmPrimitive> { 15 public class PrimUtils { 16 17 public static final String KEY_HIGHWAY = "highway"; 18 public static final String KEY_PLACE = "place"; 19 19 20 20 public static final String KEY_ADDR_CP = "addr:alternatenumber"; … … 28 28 29 29 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 }; 32 32 33 public int compare(OsmPrimitive o1, OsmPrimitive o2) { 33 public static final Comparator<OsmPrimitive> comparator = 34 new Comparator<OsmPrimitive>() { 34 35 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) { 38 37 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 } 42 45 46 int val = o1.get(key).compareTo(o2.get(key)); 47 if (val != 0) { 48 return val; 49 } 50 } 43 51 44 return o1.toString().compareTo(o2.toString());52 return o1.toString().compareTo(o2.toString()); 45 53 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; 52 60 53 if (pos1 != null && pos2 != null) {61 if (pos1 != null && pos2 != null) { 54 62 if (pos1.lat() < pos2.lat()) return -1; 55 63 if (pos1.lat() > pos2.lat()) return 1; 56 64 if (pos1.lon() < pos2.lon()) return -1; 57 65 if (pos1.lon() > pos2.lon()) return 1; 58 }*/ 59 } 66 }*/ 67 } 68 }; 60 69 61 70 } -
applications/editors/josm/plugins/czechaddress/src/org/openstreetmap/josm/plugins/czechaddress/StringUtils.java
r15558 r15582 1 1 package org.openstreetmap.josm.plugins.czechaddress; 2 2 3 import java.text.Normalizer; 3 4 import org.openstreetmap.josm.data.coor.LatLon; 4 5 … … 50 51 51 52 /** 52 * String matcher with abbreviations 53 * String matcher with abbreviations and regardless of diacritics. 53 54 * 54 * <p>Returns {@code true} even if s1="N ám. Svobody" and55 * <p>Returns {@code true} even if s1="Nam. Svobody" and 55 56 * s2="Náměstí Svobody".</p> 56 57 */ 57 58 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(" +"); 60 61 61 62 if (parts1.length != parts2.length) … … 110 111 } 111 112 112 String[] noCapitalize = { "Nad", "Pod", "U", "Na" };113 String[] noCapitalize = { "Nad", "Pod", "U", "Na", "Z" }; 113 114 for (String noc : noCapitalize) 114 115 result = result.replaceAll(" "+noc+" ", " "+noc.toLowerCase()+" "); … … 116 117 return result; 117 118 } 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 } 118 139 } -
applications/editors/josm/plugins/czechaddress/src/org/openstreetmap/josm/plugins/czechaddress/actions/FactoryAction.java
r15558 r15582 9 9 import org.openstreetmap.josm.data.osm.Node; 10 10 import org.openstreetmap.josm.gui.MapFrame; 11 import org.openstreetmap.josm.plugins.czechaddress.CzechAddressPlugin;12 11 import org.openstreetmap.josm.plugins.czechaddress.addressdatabase.House; 13 12 import org.openstreetmap.josm.plugins.czechaddress.intelligence.Reasoner; … … 99 98 r.closeTransaction(); 100 99 } 100 101 FactoryDialog.getInstance().selectionListenerActivated = false; 101 102 FactoryDialog.getInstance().selectNextUnmatchedHouseByCheckBox(); 102 103 // And make the new node selected. 104 Main.ds.addPrimitive(newNode); 103 Main.ds.addPrimitive(newNode); 105 104 Main.ds.setSelected(newNode); 105 FactoryDialog.getInstance().selectionListenerActivated = true; 106 106 } 107 107 } -
applications/editors/josm/plugins/czechaddress/src/org/openstreetmap/josm/plugins/czechaddress/actions/ManagerAction.java
r15461 r15582 1 /*2 * To change this template, choose Tools | Templates3 * and open the template in the editor.4 */5 6 1 package org.openstreetmap.josm.plugins.czechaddress.actions; 7 2 … … 9 4 import java.awt.event.KeyEvent; 10 5 import org.openstreetmap.josm.actions.JosmAction; 11 import org.openstreetmap.josm.plugins.czechaddress.gui. Renamer;6 import org.openstreetmap.josm.plugins.czechaddress.gui.ManagerDialog; 12 7 import org.openstreetmap.josm.tools.Shortcut; 13 8 … … 16 11 * @author Radomír Černoch, radomir.cernoch@gmail.com 17 12 */ 18 public class M odifierAction extends JosmAction {13 public class ManagerAction extends JosmAction { 19 14 20 public M odifierAction() {15 public ManagerAction() { 21 16 super("Upravit databázi", 22 17 null,//"envelope-closed-big.png", … … 29 24 30 25 public void actionPerformed(ActionEvent e) { 31 (new Renamer()).setVisible(true);26 (new ManagerDialog()).setVisible(true); 32 27 } 33 28 } -
applications/editors/josm/plugins/czechaddress/src/org/openstreetmap/josm/plugins/czechaddress/addressdatabase/AddressElement.java
r15558 r15582 6 6 import org.openstreetmap.josm.data.osm.Way; 7 7 import org.openstreetmap.josm.plugins.czechaddress.StringUtils; 8 import org.openstreetmap.josm.plugins.czechaddress.intelligence. Match;8 import org.openstreetmap.josm.plugins.czechaddress.intelligence.Reasoner; 9 9 import org.openstreetmap.josm.plugins.czechaddress.proposal.Proposal; 10 10 … … 206 206 } 207 207 208 protected int[] getAdditionalFieldMatchList(OsmPrimitive primitive) { 209 int[] result = {0}; 210 return result; 211 } 208 212 209 213 public List<Proposal> getDiff(OsmPrimitive prim) { … … 211 215 } 212 216 213 public int get MatchQuality(OsmPrimitive primitive) {217 public int getQ(OsmPrimitive primitive) { 214 218 215 219 // Firstly get integers representing a match of every matchable field. … … 234 238 // has nothing to do with our field. 235 239 if (maxVal <= 0) 236 return Match.MATCH_NOMATCH;240 return Reasoner.MATCH_NOMATCH; 237 241 238 242 // If all fields are 1 --> ROCKSOLID MATCH … … 240 244 // If some are 1, some -1 --> CONFLICT 241 245 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; 245 249 } 246 250 247 251 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 else271 result += "CZ";272 273 return result;274 252 } 275 253 … … 282 260 if (retVal != 0) return retVal; 283 261 284 return getName().compareTo(((AddressElement) elem).getName());262 return toString().compareTo(((AddressElement) elem).toString()); 285 263 } 286 264 } -
applications/editors/josm/plugins/czechaddress/src/org/openstreetmap/josm/plugins/czechaddress/addressdatabase/ElementWithHouses.java
r15166 r15582 9 9 * @author Radomir Cernoch radomir.cernoch@gmail.com 10 10 */ 11 abstract publicclass ElementWithHouses extends AddressElement {11 public abstract class ElementWithHouses extends AddressElement { 12 12 13 13 /** -
applications/editors/josm/plugins/czechaddress/src/org/openstreetmap/josm/plugins/czechaddress/addressdatabase/ElementWithStreets.java
r15166 r15582 16 16 * @author Radomir Cernoch radomir.cernoch@gmail.com 17 17 */ 18 abstract publicclass ElementWithStreets extends ElementWithHouses {18 public abstract class ElementWithStreets extends ElementWithHouses { 19 19 20 20 private ArrayList<Street> streets = new ArrayList<Street>(); … … 60 60 } 61 61 62 public List<Street> getAllStreets() { 63 return getStreets(); 64 } 65 66 62 67 public Street findStreet(String streetName) { 63 68 -
applications/editors/josm/plugins/czechaddress/src/org/openstreetmap/josm/plugins/czechaddress/addressdatabase/House.java
r15558 r15582 5 5 import org.openstreetmap.josm.plugins.czechaddress.NotNullList; 6 6 import org.openstreetmap.josm.plugins.czechaddress.PrimUtils; 7 import org.openstreetmap.josm.plugins.czechaddress.StringUtils;8 7 import org.openstreetmap.josm.plugins.czechaddress.proposal.Proposal; 9 8 … … 133 132 * {@link AddressElement}{@code .getFieldMatchList()}.</p> 134 133 * 135 * <p>First elem tnof the returned array corresponds to the CP134 * <p>First element of the returned array corresponds to the CP 136 135 * (číslo popisné), the second one to the combination of Street+CO.</p> 137 136 */ … … 139 138 protected int[] getFieldMatchList(OsmPrimitive prim) { 140 139 int[] result = {0, 0}; 141 140 if (!isMatchable(prim)) return result; 141 142 142 // First field is the AlternateNubmer 143 143 result[0] = matchField(this.cp, prim.get(PrimUtils.KEY_ADDR_CP)); … … 150 150 return result; 151 151 } 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 152 163 164 153 165 /** 154 166 * Gives all proposals to make the primitive be an address primitive. … … 161 173 162 174 List<Proposal> props = new NotNullList<Proposal>(); 163 ParentResolver pr = new ParentResolver(this);175 ParentResolver resolver = new ParentResolver(this); 164 176 165 177 props.add(getStringFieldDiff(PrimUtils.KEY_ADDR_CP, prim.get(PrimUtils.KEY_ADDR_CP), getCP())); … … 169 181 prim.get(PrimUtils.KEY_ADDR_COUNTRY), "CZ")); 170 182 171 if ( pr.parentStreet != null)183 if (resolver.parentStreet != null) 172 184 props.add(getStringFieldDiff(PrimUtils.KEY_ADDR_STREET, 173 185 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 177 191 props.add(getStringFieldDiff(PrimUtils.KEY_IS_IN, 178 192 prim.get(PrimUtils.KEY_IS_IN), 179 parent.parent.getIsIn()));193 resolver.getIsIn())); 180 194 181 195 // If we have added any proposal so far, add the source info as well. … … 187 201 188 202 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:")) 193 205 return true; 194 }195 206 return false; 196 207 } -
applications/editors/josm/plugins/czechaddress/src/org/openstreetmap/josm/plugins/czechaddress/addressdatabase/ParentResolver.java
r15558 r15582 40 40 } 41 41 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 42 65 public int compareTo(ParentResolver o) { 43 66 int val = 0; -
applications/editors/josm/plugins/czechaddress/src/org/openstreetmap/josm/plugins/czechaddress/addressdatabase/Region.java
r15461 r15582 95 95 return thisString; 96 96 } 97 98 @Override99 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 }109 97 } -
applications/editors/josm/plugins/czechaddress/src/org/openstreetmap/josm/plugins/czechaddress/addressdatabase/Street.java
r15201 r15582 1 1 package org.openstreetmap.josm.plugins.czechaddress.addressdatabase; 2 2 3 import java.util.List; 3 4 import org.openstreetmap.josm.data.osm.OsmPrimitive; 5 import org.openstreetmap.josm.plugins.czechaddress.NotNullList; 6 import org.openstreetmap.josm.plugins.czechaddress.PrimUtils; 7 import org.openstreetmap.josm.plugins.czechaddress.proposal.Proposal; 8 9 import static org.openstreetmap.josm.plugins.czechaddress.proposal.ProposalFactory.getStringFieldDiff; 4 10 5 11 /** … … 29 35 protected int[] getFieldMatchList(OsmPrimitive primitive) { 30 36 int[] result = {0}; 37 if (!isMatchable(primitive)) return result; 31 38 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")); 46 40 return result; 47 41 } 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 48 55 } -
applications/editors/josm/plugins/czechaddress/src/org/openstreetmap/josm/plugins/czechaddress/addressdatabase/Suburb.java
r15166 r15582 1 1 package org.openstreetmap.josm.plugins.czechaddress.addressdatabase; 2 3 import org.openstreetmap.josm.data.osm.OsmPrimitive; 4 import org.openstreetmap.josm.plugins.czechaddress.PrimUtils; 2 5 3 6 /** … … 11 14 super(name); 12 15 } 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 } 13 23 } -
applications/editors/josm/plugins/czechaddress/src/org/openstreetmap/josm/plugins/czechaddress/addressdatabase/ViToCi.java
r15166 r15582 3 3 import java.util.List; 4 4 import java.util.ArrayList; 5 import org.openstreetmap.josm.data.osm.OsmPrimitive;6 5 7 6 /** … … 56 55 return null; 57 56 } 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 } 58 73 } -
applications/editors/josm/plugins/czechaddress/src/org/openstreetmap/josm/plugins/czechaddress/gui/ConflictResolver.form
r15558 r15582 156 156 <Property name="enabled" type="boolean" value="false"/> 157 157 </Properties> 158 <Events> 159 <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="candPickButtonActionPerformed"/> 160 </Events> 158 161 </Component> 159 162 <Component class="javax.swing.JButton" name="mainPickButton"> -
applications/editors/josm/plugins/czechaddress/src/org/openstreetmap/josm/plugins/czechaddress/gui/ConflictResolver.java
r15558 r15582 24 24 import org.openstreetmap.josm.plugins.czechaddress.PrimUtils; 25 25 import org.openstreetmap.josm.plugins.czechaddress.addressdatabase.AddressElement; 26 import org.openstreetmap.josm.plugins.czechaddress.addressdatabase.ElementWithHouses; 26 27 import org.openstreetmap.josm.plugins.czechaddress.addressdatabase.House; 27 28 import org.openstreetmap.josm.plugins.czechaddress.addressdatabase.Street; … … 134 135 candPickButton.setText(" "); 135 136 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 }); 136 142 137 143 mainPickButton.setText(" "); … … 212 218 } 213 219 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 214 229 private void reassignButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_reassignButtonActionPerformed 215 230 … … 258 273 259 274 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()); 261 277 }//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 262 283 263 284 // Variables declaration - do not modify//GEN-BEGIN:variables … … 279 300 280 301 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()); 283 304 284 305 if (Reasoner.getInstance().inConflict(elem)) … … 289 310 290 311 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)); 293 314 294 315 if (Reasoner.getInstance().inConflict(prim)) … … 333 354 334 355 public void put(OsmPrimitive prim) { 335 int index = Collections.binarySearch(primitives, prim, new PrimUtils());356 int index = Collections.binarySearch(primitives, prim, PrimUtils.comparator); 336 357 if (index < 0) { 337 358 logger.log(Level.FINE, "conflicts: adding primitive", 338 "[" + String.valueOf(-index-1) +"]=„"339 + 359 "["+String.valueOf(-index-1)+"]=„" 360 +AddressElement.getName(prim) + "“"); 340 361 primitives.add(-index-1, prim); 341 362 … … 452 473 List<OsmPrimitive> conflPrims = new NotNullList<OsmPrimitive>(); 453 474 conflPrims.addAll(Reasoner.getInstance().getCandidates(selElem)); 454 Collections.sort(conflPrims, new PrimUtils());475 Collections.sort(conflPrims, PrimUtils.comparator); 455 476 candField.setModel(new CandidatesModel<OsmPrimitive>(conflPrims)); 456 477 -
applications/editors/josm/plugins/czechaddress/src/org/openstreetmap/josm/plugins/czechaddress/gui/FactoryDialog.java
r15558 r15582 96 96 keepOddityCheckBox.setEnabled(true); 97 97 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 } 108 116 } 109 117 … … 111 119 if (houseList.getSelectedValue() instanceof House) 112 120 return (House) houseList.getSelectedValue(); 113 else 114 return null; 121 return null; 115 122 } 116 123 … … 138 145 int index = houseList.getSelectedIndex(); 139 146 140 index++; 141 Objectcurrent;142 while ( (current = houseModel.get ElementAt(index))!= null143 && 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) 144 151 index++; 145 152 … … 171 178 newNum = Integer.valueOf(newStr); 172 179 173 } while ( 174 houseList.getSelectedIndex() != 0);180 } while ((oldNum + newNum) % 2 == 1 && 181 houseList.getSelectedIndex() != 0); 175 182 176 183 } catch (Exception exp) {} … … 184 191 } 185 192 193 public boolean selectionListenerActivated = true; 186 194 public void selectionChanged(Collection<? extends OsmPrimitive> newSelection) { 187 195 196 if (!selectionListenerActivated) return; 188 197 if (newSelection.size() != 1) return; 189 198 190 199 OsmPrimitive selectedPrim = (OsmPrimitive) newSelection.toArray()[0]; 191 192 200 String streetName; 193 201 … … 215 223 for (House currHouse : selectedStreet.getHouses()) { 216 224 217 int currQuality = currHouse.get MatchQuality(selectedPrim);225 int currQuality = currHouse.getQ(selectedPrim); 218 226 219 227 if (currQuality > bestQuality) { … … 225 233 if (bestHouse == null) return; 226 234 houseList.setSelectedValue(bestHouse, true); 235 houseList.ensureIndexIsVisible(houseList.getSelectedIndex()); 227 236 houseModel.notifyAllListeners(); 228 237 } … … 313 322 Reasoner r = Reasoner.getInstance(); 314 323 315 if (r.translate(getSelectedHouse()) != null) {324 if (r.translate(getSelectedHouse()) != null) 316 325 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()); 330 328 } 331 329 }//GEN-LAST:event_houseListClicked … … 344 342 houseModel.notifyAllListeners(); 345 343 } 346 347 344 public void primitiveChanged(OsmPrimitive prim) {} 348 349 public void resonerReseted() { 350 throw new UnsupportedOperationException("Not supported yet."); 351 } 345 public void resonerReseted() {} 346 347 //============================================================================== 352 348 353 349 private class StreetListRenderer extends DefaultListCellRenderer { 354 355 Font plainFont = null;356 Font boldFont = null;357 358 350 @Override 359 351 public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { 360 352 Component c = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); 361 353 362 if (plainFont == null) plainFont = getFont().deriveFont(Font.PLAIN);363 if (boldFont == null) boldFont = getFont().deriveFont(Font.BOLD);364 365 354 if (value instanceof Street) { 366 setFont( plainFont);355 setFont(getFont().deriveFont(Font.PLAIN)); 367 356 setText(((Street) value).getName()); 368 357 369 358 } else if (value instanceof ElementWithHouses) { 370 setFont( boldFont);359 setFont(getFont().deriveFont(Font.BOLD)); 371 360 setText("[" + ((ElementWithHouses) value).getName() + "]"); 372 361 } 373 362 374 363 return c; 375 364 } 376 365 } 366 367 //============================================================================== 377 368 378 369 private class HouseListRenderer extends DefaultListCellRenderer { … … 392 383 if (boldFont == null) boldFont = getFont().deriveFont(Font.BOLD); 393 384 394 Reasoner r = Reasoner.getInstance();395 396 385 if (value instanceof House) { 397 386 House house = (House) value; … … 400 389 setFont(plainFont); 401 390 402 if ( r.inConflict(house))391 if (Reasoner.getInstance().inConflict(house)) 403 392 setIcon(envelopeExclIcon); 404 393 405 else if ( r.translate(house) == null) {394 else if (Reasoner.getInstance().translate(house) == null) { 406 395 setIcon(envelopeStarIcon); 407 396 setFont(boldFont); … … 414 403 } 415 404 405 //============================================================================== 406 416 407 private class AllStreetProvider extends ElementWithHouses { 417 408 public AllStreetProvider() { … … 431 422 super("nepřiřazené domy"); 432 423 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 444 425 for (AddressElement house : Reasoner.getInstance().getUnassignedElements()) 445 426 if (house instanceof House) … … 452 433 public void primitiveChanged(OsmPrimitive prim) {} 453 434 public void elementChanged(AddressElement elem) { 454 if (!(elem instanceof House)) 455 return; 435 if (!(elem instanceof House)) return; 456 436 House house = (House) elem; 437 int index = Collections.binarySearch(houses, house); 457 438 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 //============================================================================== 468 450 469 451 private class StreetListModel extends HalfCookedComboBoxModel { … … 481 463 } 482 464 483 484 485 465 public int getSize() { 486 466 if (parent == null) return 0; … … 491 471 if (parent == null) return; 492 472 493 selected = parent; 494 this.parent = parent; 473 this.selected = parent; 474 this.parent = parent; 475 495 476 metaElem.set(0, parent); 496 497 477 metaElem.get(1).setHouses(parent.getAllHouses()); 498 478 notifyAllListeners(); … … 500 480 501 481 public Object getElementAt(int index) { 502 503 482 if (parent == null) return null; 504 if (index < 0) return null;505 483 506 484 if (index < metaElem.size()) … … 508 486 509 487 index -= metaElem.size(); 510 // Now the index points to the list of streets 488 511 489 if (index < parent.getStreets().size()) 512 490 return parent.getStreets().get(index); … … 526 504 } 527 505 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 } 529 514 530 515 public int getSize() { … … 549 534 return getHouseAt(index); 550 535 } 536 537 public void primitiveChanged(OsmPrimitive prim) {} 538 public void elementChanged(AddressElement elem) { 539 notifyAllListeners(); 540 } 541 542 public void resonerReseted() { 543 notifyAllListeners(); 544 } 551 545 } 552 546 } -
applications/editors/josm/plugins/czechaddress/src/org/openstreetmap/josm/plugins/czechaddress/gui/GroupManipulatorDialog.java
r15558 r15582 1 1 package org.openstreetmap.josm.plugins.czechaddress.gui; 2 2 3 import org.openstreetmap.josm.data.osm.OsmPrimitive; 4 import org.openstreetmap.josm.plugins.czechaddress.addressdatabase.AddressElement; 5 import org.openstreetmap.josm.plugins.czechaddress.gui.utils.UniversalTreeRenderer; 3 6 import java.awt.event.ActionEvent; 4 7 import java.awt.event.KeyEvent; … … 9 12 import org.openstreetmap.josm.plugins.czechaddress.StatusListener; 10 13 import org.openstreetmap.josm.plugins.czechaddress.intelligence.Reasoner; 14 import org.openstreetmap.josm.plugins.czechaddress.intelligence.ReasonerListener; 11 15 import org.openstreetmap.josm.plugins.czechaddress.proposal.Proposal; 12 16 import org.openstreetmap.josm.plugins.czechaddress.proposal.ProposalContainer; … … 25 29 * @see ConflictDatabase 26 30 */ 27 public class GroupManipulatorDialog extends ExtendedDialog implements StatusListener {31 public class GroupManipulatorDialog extends ExtendedDialog implements ReasonerListener { 28 32 29 33 private static GroupManipulatorDialog singleton = null; … … 33 37 return singleton; 34 38 } 39 40 private ProposalDatabase database = null; 35 41 36 42 /** … … 52 58 setAlwaysOnTop(false); 53 59 54 // Start receiving plugin-wide messages.55 CzechAddressPlugin.addStatusListener(this);56 57 60 // TODO: Why does it always crash if the modality is set in constructor? 58 61 setModal(false); … … 63 66 super.buttonAction(evt); 64 67 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(); 79 69 } 80 70 81 71 @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); 84 76 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); 92 81 } 93 82 94 83 public void recreateProposals() { 95 /*locationTextField.setText(CzechAddressPlugin.getLocation().toString());84 locationTextField.setText(CzechAddressPlugin.getLocation().toString()); 96 85 97 Reasoner r = CzechAddressPlugin.getReasoner();98 proposalTree.setModel( r.getProposals());*/86 database = Reasoner.getInstance().getProposals(); 87 proposalTree.setModel(database); 99 88 } 100 89 … … 210 199 // End of variables declaration//GEN-END:variables 211 200 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 212 223 } -
applications/editors/josm/plugins/czechaddress/src/org/openstreetmap/josm/plugins/czechaddress/gui/LocationSelector.form
r15166 r15582 1 1 <?xml version="1.0" encoding="UTF-8" ?> 2 2 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"> 4 4 <Properties> 5 5 <Property name="title" type="java.lang.String" value="Výběr umístění"/> 6 6 <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"/> 8 8 </Properties> 9 9 <SyntheticProperties> … … 41 41 <EmptySpace max="-2" attributes="0"/> 42 42 <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="34 0" 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"/> 46 46 </Group> 47 47 </Group> … … 58 58 <Group type="103" groupAlignment="3" attributes="0"> 59 59 <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"/> 61 61 </Group> 62 62 <EmptySpace max="-2" attributes="0"/> 63 63 <Group type="103" groupAlignment="3" attributes="0"> 64 64 <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"/> 66 66 </Group> 67 67 <EmptySpace max="32767" attributes="0"/> … … 81 81 </Events> 82 82 </Component> 83 <Component class="javax.swing.JComboBox" name=" castObceComboBox">83 <Component class="javax.swing.JComboBox" name="suburbComboBox"> 84 84 <Properties> 85 85 <Property name="model" type="javax.swing.ComboBoxModel" editor="org.netbeans.modules.form.editors2.ComboBoxModelEditor"> … … 88 88 </Properties> 89 89 <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"/> 91 91 </Events> 92 92 </Component> 93 <Component class="javax.swing.JComboBox" name=" obecComboBox">93 <Component class="javax.swing.JComboBox" name="vitociComboBox"> 94 94 <Properties> 95 95 <Property name="model" type="javax.swing.ComboBoxModel" editor="org.netbeans.modules.form.editors2.ComboBoxModelEditor"> … … 98 98 </Properties> 99 99 <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"/> 101 101 </Events> 102 102 </Component> … … 113 113 <Component class="javax.swing.JLabel" name="oblastLabel"> 114 114 <Properties> 115 <Property name="text" type="java.lang.String" value="O blast:"/>115 <Property name="text" type="java.lang.String" value="ORP:"/> 116 116 </Properties> 117 117 </Component> -
applications/editors/josm/plugins/czechaddress/src/org/openstreetmap/josm/plugins/czechaddress/gui/LocationSelector.java
r15558 r15582 1 1 package org.openstreetmap.josm.plugins.czechaddress.gui; 2 2 3 import org.openstreetmap.josm.plugins.czechaddress.*;4 3 import java.awt.Component; 4 import java.awt.Font; 5 5 import java.util.ArrayList; 6 6 … … 55 55 56 56 oblastComboBox.setRenderer(new AddressElementRenderer()); 57 obecComboBox.setRenderer(new AddressElementRenderer());58 castObceComboBox.setRenderer(new AddressElementRenderer());57 vitociComboBox.setRenderer(new AddressElementRenderer()); 58 suburbComboBox.setRenderer(new SuburbRenderer()); 59 59 60 60 oblastComboBox.setModel(new DefaultComboBoxModel( … … 146 146 if (obec.getName().toUpperCase().equals(bestFit.get("name").toUpperCase())) { 147 147 oblastComboBox.setSelectedItem(oblast); 148 obecComboBox.setSelectedItem(obec);148 vitociComboBox.setSelectedItem(obec); 149 149 for (Suburb castObce : obec.getSuburbs()) { 150 150 if (castObce.getName().toUpperCase().equals(bestFit.get("name").toUpperCase())) { 151 castObceComboBox.setSelectedItem(castObce);151 suburbComboBox.setSelectedItem(castObce); 152 152 break; 153 153 } … … 159 159 if (castObce.getName().toUpperCase().equals(bestFit.get("name").toUpperCase())) { 160 160 oblastComboBox.setSelectedItem(oblast); 161 obecComboBox.setSelectedItem(obec);162 castObceComboBox.setSelectedItem(castObce);161 vitociComboBox.setSelectedItem(obec); 162 suburbComboBox.setSelectedItem(castObce); 163 163 break; 164 164 } … … 176 176 */ 177 177 @SuppressWarnings("unchecked") 178 // <editor-fold defaultstate="collapsed" desc=" Generated Code">//GEN-BEGIN:initComponents178 // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents 179 179 private void initComponents() { 180 180 181 mainPanel = new javax.swing.JPanel(); 181 182 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(); 184 185 obecLabel = new javax.swing.JLabel(); 185 186 castObceLabel = new javax.swing.JLabel(); 186 187 oblastLabel = new javax.swing.JLabel(); 187 188 189 setTitle("Výběr umístění"); 190 setModal(true); 191 setName("locationSelector"); // NOI18N 188 192 getContentPane().setLayout(new java.awt.GridLayout(1, 0)); 189 193 190 setTitle("V\u00fdb\u011br um\u00edst\u011bn\u00ed");191 setModal(true);192 setName("locationSelector");193 194 oblastComboBox.addItemListener(new java.awt.event.ItemListener() { 194 195 public void itemStateChanged(java.awt.event.ItemEvent evt) { … … 197 198 }); 198 199 199 castObceComboBox.addItemListener(new java.awt.event.ItemListener() {200 suburbComboBox.addItemListener(new java.awt.event.ItemListener() { 200 201 public void itemStateChanged(java.awt.event.ItemEvent evt) { 201 castObceComboBoxItemStateChanged(evt);202 suburbComboBoxItemStateChanged(evt); 202 203 } 203 204 }); 204 205 205 obecComboBox.addItemListener(new java.awt.event.ItemListener() {206 vitociComboBox.addItemListener(new java.awt.event.ItemListener() { 206 207 public void itemStateChanged(java.awt.event.ItemEvent evt) { 207 obecComboBoxItemStateChanged(evt);208 vitociComboBoxItemStateChanged(evt); 208 209 } 209 210 }); … … 211 212 obecLabel.setText("Obec:"); 212 213 213 castObceLabel.setText(" \u010c\u00e1st obce:");214 215 oblastLabel.setText("O blast:");214 castObceLabel.setText("Část obce:"); 215 216 oblastLabel.setText("ORP:"); 216 217 217 218 javax.swing.GroupLayout mainPanelLayout = new javax.swing.GroupLayout(mainPanel); … … 226 227 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) 227 228 .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, 34 0, 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))) 231 232 ); 232 233 mainPanelLayout.setVerticalGroup( … … 239 240 .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) 240 241 .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)) 242 243 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) 243 244 .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) 244 245 .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)) 246 247 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) 247 248 ); 249 248 250 getContentPane().add(mainPanel); 249 250 251 }// </editor-fold>//GEN-END:initComponents 251 252 … … 278 279 if (oblast == null) return; 279 280 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); 284 284 }//GEN-LAST:event_oblastComboBoxItemStateChanged 285 285 286 private void obecComboBoxItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_obecComboBoxItemStateChanged287 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(); 289 289 if (obec == null) return; 290 290 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 298 305 299 306 /*if (castObceComboBox.getSelectedItem() != null) … … 306 313 checkSetSelected((ElementWithStreets) oblastComboBox.getSelectedItem());*/ 307 314 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()); 313 320 314 321 else if (oblastComboBox.getSelectedItem() != null) 315 322 selectedElement = ((ElementWithStreets) oblastComboBox.getSelectedItem()); 316 323 317 }//GEN-LAST:event_ castObceComboBoxItemStateChanged324 }//GEN-LAST:event_suburbComboBoxItemStateChanged 318 325 319 326 // Variables declaration - do not modify//GEN-BEGIN:variables 320 private javax.swing.JComboBox castObceComboBox;321 327 private javax.swing.JLabel castObceLabel; 322 328 private javax.swing.JPanel mainPanel; 323 private javax.swing.JComboBox obecComboBox;324 329 private javax.swing.JLabel obecLabel; 325 330 private javax.swing.JComboBox oblastComboBox; 326 331 private javax.swing.JLabel oblastLabel; 332 private javax.swing.JComboBox suburbComboBox; 333 private javax.swing.JComboBox vitociComboBox; 327 334 // End of variables declaration//GEN-END:variables 328 335 329 336 private class AddressElementRenderer extends DefaultListCellRenderer { 330 331 337 @Override 332 338 public Component getListCellRendererComponent( … … 334 340 boolean isSelected, boolean cellHasFocus) { 335 341 336 Component c = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); 342 Component c = super.getListCellRendererComponent(list, value, index, 343 isSelected, cellHasFocus); 337 344 338 345 if (value instanceof AddressElement && !(value instanceof Region)) … … 342 349 } 343 350 } 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 } 344 368 } -
applications/editors/josm/plugins/czechaddress/src/org/openstreetmap/josm/plugins/czechaddress/gui/ManagerDialog.form
r15558 r15582 1 1 <?xml version="1.0" encoding="UTF-8" ?> 2 2 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"> 4 4 <Properties> 5 5 <Property name="defaultCloseOperation" type="int" value="2"/> … … 18 18 <AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/> 19 19 <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"/> 20 21 </AuxValues> 21 22 … … 27 28 <Container class="javax.swing.JPanel" name="mainPanel"> 28 29 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"/> 40 33 </Layout> 41 34 <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"> 46 36 47 <Layout class="org.netbeans.modules.form.compat2.layouts.support.J ScrollPaneSupportLayout"/>37 <Layout class="org.netbeans.modules.form.compat2.layouts.support.JTabbedPaneSupportLayout"/> 48 38 <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ávrhy na přejmenování"> 43 <Property name="tabTitle" type="java.lang.String" value="Návrhy na přejmenování"/> 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ůvodní název" type="java.lang.Object"/> 83 <Column editable="true" title="Ná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žít navržené změ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áze"> 108 <Property name="tabTitle" type="java.lang.String" value="Inspektor databá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> 51 161 </SubComponents> 52 162 </Container> -
applications/editors/josm/plugins/czechaddress/src/org/openstreetmap/josm/plugins/czechaddress/gui/ManagerDialog.java
r15558 r15582 1 1 package org.openstreetmap.josm.plugins.czechaddress.gui; 2 2 3 import java.awt.Component; 4 import java.awt.event.MouseEvent; 5 import java.util.ArrayList; 6 import java.util.List; 7 import javax.swing.DefaultComboBoxModel; 8 import javax.swing.JComboBox; 9 import javax.swing.JTable; 10 import javax.swing.event.TableModelListener; 11 import javax.swing.table.DefaultTableCellRenderer; 12 import javax.swing.table.TableModel; 13 import org.openstreetmap.josm.plugins.czechaddress.gui.utils.UniversalTreeRenderer; 3 14 import org.openstreetmap.josm.Main; 4 15 import org.openstreetmap.josm.gui.ExtendedDialog; 5 16 import org.openstreetmap.josm.plugins.czechaddress.CzechAddressPlugin; 17 import org.openstreetmap.josm.plugins.czechaddress.addressdatabase.AddressElement; 6 18 import org.openstreetmap.josm.plugins.czechaddress.addressdatabase.Database; 7 19 import org.openstreetmap.josm.plugins.czechaddress.addressdatabase.House; … … 10 22 import org.openstreetmap.josm.plugins.czechaddress.addressdatabase.Suburb; 11 23 import org.openstreetmap.josm.plugins.czechaddress.addressdatabase.ViToCi; 12 13 public class Inspector extends ExtendedDialog { 14 15 /** Creates new form Inspector */ 16 public Inspector() { 24 import org.openstreetmap.josm.plugins.czechaddress.gui.databaseeditors.StreetEditor; 25 import org.openstreetmap.josm.plugins.czechaddress.intelligence.Capitalizator; 26 import org.openstreetmap.josm.plugins.czechaddress.intelligence.Reasoner; 27 28 public class ManagerDialog extends ExtendedDialog { 29 30 RenameModel<Street> streetModel = new RenameModel<Street>(); 31 32 public ManagerDialog() { 17 33 super(Main.parent, "Inspektor databáze", new String[] {}, true); 18 34 initComponents(); 19 35 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()); 22 60 23 61 // And finalize initializing the form. … … 25 63 } 26 64 27 /*private class Model extends HalfCookedTreeModel { 65 public int countAutomaticRenameProposals() { 66 return streetModel.getRowCount(); 67 } 68 69 private class DatabaseModel extends HalfCookedTreeModel { 28 70 29 71 @Override 30 72 public Object getRoot() { 31 return CzechAddressPlugin. database;73 return CzechAddressPlugin.getLocation(); 32 74 } 33 75 … … 130 172 } 131 173 132 } */174 } 133 175 134 176 /** This method is called from within the constructor to … … 142 184 143 185 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(); 144 192 jScrollPane1 = new javax.swing.JScrollPane(); 145 tree = new javax.swing.JTree(); 193 dbTree = new javax.swing.JTree(); 194 dbEditButton = new javax.swing.JButton(); 146 195 147 196 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) 157 246 ); 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()) 161 254 ); 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); 162 295 163 296 getContentPane().add(mainPanel); … … 166 299 }// </editor-fold>//GEN-END:initComponents 167 300 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 168 332 // 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; 169 337 private javax.swing.JScrollPane jScrollPane1; 170 338 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; 172 343 // End of variables declaration//GEN-END:variables 173 344 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 } 174 410 } -
applications/editors/josm/plugins/czechaddress/src/org/openstreetmap/josm/plugins/czechaddress/gui/PointManipulatorDialog.form
r15558 r15582 22 22 <AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/> 23 23 <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"/> 25 25 </AuxValues> 26 26 … … 49 49 </Group> 50 50 <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"/> 56 52 </Group> 57 53 </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"/> 59 56 </Group> 60 57 </DimensionLayout> … … 76 73 <Component id="jLabel6" alignment="3" min="-2" max="-2" attributes="0"/> 77 74 <Component id="matchesComboBox" alignment="3" min="-2" max="-2" attributes="0"/> 78 <Component id="ensureConsistencyButton" alignment="3" min="-2" max="-2" attributes="0"/>79 75 </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"/> 85 80 </Group> 86 81 </Group> … … 154 149 </Properties> 155 150 </Component> 156 <Component class="javax.swing.J Button" name="ensureConsistencyButton">151 <Component class="javax.swing.JLabel" name="statusLabel"> 157 152 <Properties> 158 <Property name="icon" type="javax.swing.Icon" editor="org.netbeans.modules.form.RADConnectionPropertyEditor"> 159 <Connection code="ImageProvider.get("actions", "refresh-small.png")" type="code"/> 160 </Property> 161 <Property name="text" type="java.lang.String" editor="org.netbeans.modules.form.RADConnectionPropertyEditor"> 162 <Connection code="""" type="code"/> 163 </Property> 164 <Property name="toolTipText" type="java.lang.String" value="Provede nové přiřazení prvků mapy na elementy databáze.
Touto volbou se zruší všechny manuálně vyřešené konflikty."/> 153 <Property name="text" type="java.lang.String" value=" "/> 165 154 </Properties> 166 <Events>167 <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="ensureConsistencyButtonActionPerformed"/>168 </Events>169 155 </Component> 170 156 </SubComponents> -
applications/editors/josm/plugins/czechaddress/src/org/openstreetmap/josm/plugins/czechaddress/gui/PointManipulatorDialog.java
r15558 r15582 1 1 package org.openstreetmap.josm.plugins.czechaddress.gui; 2 2 3 import java.awt.Component;4 3 import java.awt.event.ActionEvent; 5 4 import java.awt.event.KeyEvent; 6 5 import java.util.List; 7 6 import java.util.Map; 8 import javax.swing.JList;9 7 import javax.swing.AbstractAction; 10 8 import javax.swing.Action; 11 import javax.swing.DefaultListCellRenderer;12 import javax.swing.ImageIcon;13 9 import javax.swing.Timer; 14 10 import org.openstreetmap.josm.Main; … … 21 17 import org.openstreetmap.josm.plugins.czechaddress.addressdatabase.AddressElement; 22 18 import org.openstreetmap.josm.plugins.czechaddress.addressdatabase.House; 23 import org.openstreetmap.josm.plugins.czechaddress. intelligence.Match;19 import org.openstreetmap.josm.plugins.czechaddress.gui.utils.UniversalListRenderer; 24 20 import org.openstreetmap.josm.plugins.czechaddress.intelligence.Reasoner; 25 21 import org.openstreetmap.josm.plugins.czechaddress.proposal.Proposal; 26 22 import org.openstreetmap.josm.plugins.czechaddress.proposal.ProposalContainer; 27 import org.openstreetmap.josm.plugins.czechaddress.proposal.ProposalListPainter;28 23 import org.openstreetmap.josm.tools.ImageProvider; 29 24 … … 55 50 // Create action for delaying the database query... 56 51 updateMatchesAction = new AbstractAction() { 57 boolean shouldDraw = false;58 52 public void actionPerformed(ActionEvent e) { 59 53 updateMatches(); … … 68 62 proposalContainer = new ProposalContainer(primitive); 69 63 proposalList.setModel(proposalContainer); 70 proposalList.setCellRenderer(new ProposalListPainter());64 proposalList.setCellRenderer(new UniversalListRenderer()); 71 65 72 66 // Init the "match" combobox. 73 67 matchesComboBox.setModel(new MatchesComboBoxModel()); 74 matchesComboBox.setRenderer(new MatchesComboBoxPainter());68 matchesComboBox.setRenderer(new UniversalListRenderer()); 75 69 76 70 if (primitive.get("addr:alternatenumber") != null) { … … 91 85 protected void buttonAction(ActionEvent evt) { 92 86 super.buttonAction(evt); 93 /*if (getValue() == 1) {87 if (getValue() == 1) { 94 88 95 89 if (updateMatchesTimer.isRunning()) { … … 103 97 Main.ds.setSelected(proposalContainer.getTarget()); 104 98 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 } 111 109 112 110 CzechAddressPlugin.removeStatusListener(this); … … 125 123 public void updateMatches() { 126 124 127 /* if (proposalContainer.getTarget().deleted) { 125 if (proposalContainer.getTarget().deleted) 128 126 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(); 129 141 } 130 142 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 144 143 MatchesComboBoxModel matchesModel = 145 144 ((MatchesComboBoxModel) matchesComboBox.getModel()); 146 145 147 146 // Fill the combobox with suitable houses. 148 matchesModel.set Matches(matches);147 matchesModel.setElements(elems); 149 148 if (matchesModel.getSize() > 0) { 150 149 matchesComboBox.setSelectedIndex(0); … … 156 155 fakeHouse.setParent(CzechAddressPlugin.getLocation()); 157 156 proposalContainer.setProposals( 158 fakeHouse.getDiff(proposalContainer.getTarget())); */157 fakeHouse.getDiff(proposalContainer.getTarget())); 159 158 } 160 159 … … 162 161 163 162 // If location changes, we block the dialog until reasoning is done. 164 /*if (message == MESSAGE_LOCATION_CHANGED) {163 if (message == MESSAGE_LOCATION_CHANGED) { 165 164 updateLocation(); 166 165 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 } 173 167 } 174 168 … … 195 189 matchesComboBox = new javax.swing.JComboBox(); 196 190 jLabel6 = new javax.swing.JLabel(); 197 ensureConsistencyButton = new javax.swing.JButton();191 statusLabel = new javax.swing.JLabel(); 198 192 199 193 jLabel4.setText("jLabel4"); … … 238 232 jLabel6.setText("Zaznam v databazi:"); 239 233 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(" "); 248 235 249 236 javax.swing.GroupLayout mainPanelLayout = new javax.swing.GroupLayout(mainPanel); … … 259 246 .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 260 247 .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, mainPanelLayout.createSequentialGroup() 261 .addComponent(locationEdit, javax.swing.GroupLayout.DEFAULT_SIZE, 2 49, Short.MAX_VALUE)248 .addComponent(locationEdit, javax.swing.GroupLayout.DEFAULT_SIZE, 228, Short.MAX_VALUE) 262 249 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) 263 250 .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) 271 255 ); 272 256 mainPanelLayout.setVerticalGroup( … … 284 268 .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) 285 269 .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)) 293 275 ); 294 276 … … 319 301 320 302 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( 324 307 proposalContainer.getTarget())); 325 308 }//GEN-LAST:event_matchChanged 326 327 private void ensureConsistencyButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ensureConsistencyButtonActionPerformed328 // CzechAddressPlugin.getReasoner().ensureConsistency();329 }//GEN-LAST:event_ensureConsistencyButtonActionPerformed330 309 331 310 … … 333 312 private javax.swing.JTextField alternateNumberEdit; 334 313 private javax.swing.JButton changeLocationButton; 335 private javax.swing.JButton ensureConsistencyButton;336 314 private javax.swing.JLabel jLabel1; 337 315 private javax.swing.JLabel jLabel4; … … 343 321 private javax.swing.JComboBox matchesComboBox; 344 322 private javax.swing.JList proposalList; 323 private javax.swing.JLabel statusLabel; 345 324 // End of variables declaration//GEN-END:variables 346 325 347 326 /** 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 @Override357 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 /**382 327 * Container for all Houses, which match the given 'alternatenumber'. 383 328 */ 384 329 private class MatchesComboBoxModel extends HalfCookedComboBoxModel { 385 330 386 private List< Match> matches = null;387 int selectedIndex = -1;388 389 public void set Matches(List<Match> matches) {390 this.matches = matches;391 selected Index = -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; 392 337 notifyAllListeners(); 393 338 } … … 395 340 public void setSelectedItem(Object anItem) { 396 341 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(" "); 398 348 } 399 349 400 350 public Object getSelectedItem() { 401 return getElementAt(selectedIndex);351 return selected; 402 352 } 403 353 … … 409 359 public Object getElementAt(int index) { 410 360 if (matches == null) return null; 411 if ( (index < 0) || (index >= matches.size())) return null;361 if (index >= matches.size()) return null; 412 362 return matches.get(index); 413 363 } -
applications/editors/josm/plugins/czechaddress/src/org/openstreetmap/josm/plugins/czechaddress/gui/Renamer.java
r15461 r15582 12 12 package org.openstreetmap.josm.plugins.czechaddress.gui; 13 13 14 import java.awt.Component;15 14 import java.awt.event.ActionEvent; 16 15 import java.util.ArrayList; 17 16 import java.util.List; 18 import javax.swing.JTable;19 17 import javax.swing.event.TableModelListener; 20 18 import 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 ;1 package org.openstreetmap.josm.plugins.czechaddress.gui.utils; 2 2 3 3 import java.awt.Component; -
applications/editors/josm/plugins/czechaddress/src/org/openstreetmap/josm/plugins/czechaddress/intelligence/Reasoner.java
r15558 r15582 1 1 package org.openstreetmap.josm.plugins.czechaddress.intelligence; 2 2 3 import java.util.Collections; 3 4 import java.util.HashMap; 4 5 import java.util.HashSet; … … 7 8 import java.util.logging.Level; 8 9 import java.util.logging.Logger; 9 import javax.crypto.Mac;10 import org.openstreetmap.josm.data.osm.Node;11 10 import org.openstreetmap.josm.data.osm.OsmPrimitive; 12 11 import 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;12 import org.openstreetmap.josm.plugins.czechaddress.proposal.ProposalContainer; 13 import org.openstreetmap.josm.plugins.czechaddress.proposal.ProposalDatabase; 15 14 16 15 /** 17 16 * Intended to concentrate all intelligence of 18 * {@link House}-{@link OsmPrimitive} matching.17 * {@link AddressElement}-{@link OsmPrimitive} matching. 19 18 * 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> 25 29 * 26 30 * <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> 31 34 * 32 35 * @author Radomír Černoch radomir.cernoch@gmail.com … … 34 37 public class Reasoner { 35 38 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; 37 44 38 45 private Map<OsmPrimitive, AddressElement> primBestIndex … … 59 66 } 60 67 68 //============================================================================== 69 // INPUT METHODS 70 //============================================================================== 71 72 /** 73 * Brings the reasoner to the initial state 74 */ 61 75 public void reset() { 62 76 primToUpdate.clear(); … … 68 82 primBestIndex.clear(); 69 83 84 transactionOpened = false; 85 70 86 for (ReasonerListener listener : listeners) 71 87 listener.resonerReseted(); 72 88 } 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 */ 154 107 public void openTransaction() { 155 108 assert primToUpdate.size() == 0; 156 109 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 */ 159 126 public void closeTransaction() { 127 assert transactionOpened; 160 128 161 129 Set<AddressElement> elemChanges = new HashSet<AddressElement>(); … … 168 136 if (bestMatch == null) { 169 137 logger.log(Level.FINE, "primitive has no longer best match", 170 AddressElement.getName(prim));138 AddressElement.getName(prim)); 171 139 primBestIndex.remove(prim); 172 140 } else { … … 200 168 elemToUpdate.addAll(elemChanges); 201 169 primToUpdate.addAll(primChanges); 170 transactionOpened = false; 202 171 203 172 for (ReasonerListener listener : listeners) { … … 205 174 if (elem != null) 206 175 listener.elementChanged(elem); 207 176 208 177 for (OsmPrimitive prim : primToUpdate) 209 178 if (prim != null) 210 179 listener.primitiveChanged(prim); 211 180 } 212 181 213 182 primToUpdate.clear(); 214 183 elemToUpdate.clear(); 215 184 } 216 185 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; 220 246 221 247 int oldQ = getQ(prim, elem); 222 int newQ = Match.evalQ(prim, elem, oldQ);248 int newQ = evalQ(prim, elem, oldQ); 223 249 224 250 if (oldQ != newQ) { … … 237 263 } 238 264 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) { 268 314 assert primMatchIndex.get(prim).get(elem) 269 315 == elemMatchIndex.get(elem).get(prim); … … 275 321 } 276 322 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) { 280 329 primMatchIndex.get(prim).remove(elem); 281 330 elemMatchIndex.get(elem).remove(prim); … … 286 335 } 287 336 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 */ 288 377 public AddressElement translate(OsmPrimitive prim) { 289 378 if (prim == null) return null; 290 379 291 AddressElement elem = primBestIndex.get(prim);292 if ( elemBestIndex.get(elem) == prim)380 AddressElement elem = getStrictlyBest(prim); 381 if (getStrictlyBest(elem) == prim) 293 382 return elem; 383 294 384 return null; 295 385 } 296 386 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 */ 297 407 public OsmPrimitive translate(AddressElement elem) { 298 408 if (elem == null) return null; 299 409 300 OsmPrimitive prim = elemBestIndex.get(elem);301 if ( primBestIndex.get(prim) == elem)410 OsmPrimitive prim = getStrictlyBest(elem); 411 if (getStrictlyBest(prim) == elem) 302 412 return prim; 413 303 414 return null; 304 415 } 305 416 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 */ 422 428 public boolean inConflict(OsmPrimitive prim) { 429 if (primMatchIndex.get(prim) == null) return false; 423 430 return primMatchIndex.get(prim).size() > 0 424 431 && translate(translate(prim)) != prim; 425 432 } 426 433 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 */ 427 445 public boolean inConflict(AddressElement elem) { 446 if (elemMatchIndex.get(elem) == null) return false; 428 447 return elemMatchIndex.get(elem).size() > 0 429 448 && translate(translate(elem)) != elem; 430 449 } 431 450 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 */ 432 599 public Set<AddressElement> getUnassignedElements() { 433 600 Set<AddressElement> result = new HashSet<AddressElement>(); 434 601 for (AddressElement elem : elemMatchIndex.keySet()) 435 if ( elemMatchIndex.get(elem).size() == 0)602 if (translate(elem) == null) 436 603 result.add(elem); 437 604 return result; 438 605 } 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 439 684 } -
applications/editors/josm/plugins/czechaddress/src/org/openstreetmap/josm/plugins/czechaddress/intelligence/SelectionMonitor.java
r15558 r15582 6 6 import org.openstreetmap.josm.data.osm.OsmPrimitive; 7 7 import org.openstreetmap.josm.plugins.czechaddress.NotNullList; 8 import org.openstreetmap.josm.plugins.czechaddress.addressdatabase.House; 9 import org.openstreetmap.josm.plugins.czechaddress.addressdatabase.Street; 8 10 9 11 /** … … 37 39 r.openTransaction(); 38 40 for (OsmPrimitive selectedPrim :newSelection) 39 r.consider(selectedPrim); 41 if (House.isMatchable(selectedPrim) || Street.isMatchable(selectedPrim)) 42 r.update(selectedPrim); 40 43 for (OsmPrimitive selectedPrim :lastSelection) 41 r.consider(selectedPrim); 44 if (House.isMatchable(selectedPrim) || Street.isMatchable(selectedPrim)) 45 r.update(selectedPrim); 42 46 r.closeTransaction(); 43 47 } -
applications/editors/josm/plugins/czechaddress/src/org/openstreetmap/josm/plugins/czechaddress/parser/DatabaseParser.java
r15558 r15582 108 108 109 109 int total = 0, count; 110 byte[] buffer = new byte[1024* 128];110 byte[] buffer = new byte[1024*512]; 111 111 while ((count = con.getInputStream().read(buffer)) >= 0) { 112 112 bos.write(buffer, 0, count); -
applications/editors/josm/plugins/czechaddress/src/org/openstreetmap/josm/plugins/czechaddress/parser/MvcrParser.java
r15461 r15582 44 44 45 45 // 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 } 48 53 49 54 /*curRegion = target.findRegion( … … 70 75 71 76 // 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 } 74 83 75 84 //curViToCi = curRegion.findViToCi(attributes.getValue("nazev")); … … 87 96 88 97 // 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 } 91 103 92 104 //curSuburb = curViToCi.findSuburb(attributes.getValue("nazev")); … … 102 114 103 115 // 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 } 106 120 107 121 ElementWithStreets topElem = curSuburb; -
applications/editors/josm/plugins/czechaddress/src/org/openstreetmap/josm/plugins/czechaddress/proposal/ProposalContainer.java
r15166 r15582 9 9 import javax.swing.event.ListDataListener; 10 10 import org.openstreetmap.josm.data.osm.OsmPrimitive; 11 import org.openstreetmap.josm.plugins.czechaddress.PrimUtils; 11 12 12 13 /** … … 22 23 * @see Proposal 23 24 */ 24 public class ProposalContainer implements ListModel {25 public class ProposalContainer implements ListModel, Comparable<ProposalContainer> { 25 26 26 27 … … 216 217 } 217 218 219 public int compareTo(ProposalContainer o) { 220 return PrimUtils.comparator.compare(this.target, o.target); 221 } 222 218 223 }
Note:
See TracChangeset
for help on using the changeset viewer.