Changeset 15558 in osm for applications/editors/josm/plugins
- Timestamp:
- 2009-06-03T01:31:58+02:00 (16 years ago)
- Location:
- applications/editors/josm/plugins/czechaddress
- Files:
-
- 8 added
- 25 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/czechaddress/build.xml
r15461 r15558 26 26 <!-- compile the plugin --> 27 27 <javac srcdir="src" 28 sourcepath=""29 28 classpath="${josm.jar}" 30 29 destdir="${plugin.build.dir}" 31 debug="true" >30 debug="true"/> 32 31 33 <include name="**/Status*.java"/>34 <include name="**/StringUtils.java"/>35 < include name="**/NotNull*.java"/>36 < include name="**/addressdatabase/*.java"/>37 < include name="**/proposal*/*.java"/>38 < include name="**/intelligence/Reasoner*.java"/>39 < include name="**/intelligence/Match.java"/>40 </ javac>32 <!-- create the manifest --> 33 <manifest file="${plugin.build.dir}/${plugin.basepackage.dir}/MANIFEST.MF"> 34 <attribute name="Author" value="Radomír Černoch"/> 35 <attribute name="Plugin-Description" value="Creating and handling address nodes and buildings within Czech Republic."/> 36 <attribute name="Plugin-Mainversion" value="1607"/> 37 <attribute name="Plugin-Version" value="0.1.2"/> 38 <attribute name="Plugin-Class" value="${plugin.basepackage}.CzechAddressPlugin"/> 39 </manifest> 41 40 41 <!-- include the images --> 42 <copy todir="${plugin.build.dir}/images"> 43 <fileset dir="images"/> 44 </copy> 42 45 </target> 43 46 47 <target name="dist" 48 depends="compile" 49 description="Create the .jar file for distribution"> 50 <mkdir dir="${plugin.dist.dir}"/> 51 <jar destfile="${plugin.jar}" 52 basedir="${plugin.build.dir}" 53 manifest="${plugin.build.dir}/${plugin.basepackage.dir}/MANIFEST.MF"/> 54 </target> 55 56 <target name="doc" description="Create Javadoc API documentation"> 57 <ant antfile="build.xml" target="doc" dir="${josm.base}"/> 58 <mkdir dir="${plugin.javadoc.dir}"/> 59 <javadoc sourcepath="src" 60 packagenames="*" 61 destdir="${plugin.javadoc.dir}" 62 use="true" 63 charset="UTF-8"> 64 <doctitle><![CDATA[Czech Address JOSM plugin]]></doctitle> 65 <bottom><![CDATA[<i>Licenced under GPLv3. Bugreports should be sent to 66 <a href='mailto:radomir.cernoch@gmail.com'>Radomír Černoch</a></i>]]> 67 </bottom> 68 <!--<tag name="todo" scope="all" description="To do:"/>--> 69 <link href="http://java.sun.com/j2se/1.5.0/docs/api/"/> 70 <link href="http://developer.java.sun.com/developer/products/xml/docs/api/"/> 71 <!--<link href="file://${user.home}/devel/core/doc"/>--> 72 </javadoc> 73 </target> 74 75 <target name="install" depends="dist"> 76 <property environment="env"/> 77 <condition property="josm.plugins.dir" 78 value="${env.APPDATA}/JOSM/plugins" 79 else="${user.home}/.josm/plugins"> 80 <and><os family="windows"/></and> 81 </condition> 82 <copy file="${plugin.jar}" todir="${josm.plugins.dir}"/> 83 </target> 44 84 45 85 <!-- Before running "run" target, please "ant dist" the JOSM. --> 46 86 <target name="run" depends="compile"> 47 <java classname=" org.openstreetmap.josm.plugins.czechaddress.intelligence.Reasoner">87 <java classname="JOSM" fork="true"> 48 88 <jvmarg value="-Xmx1024m"/> 49 89 <jvmarg value="-Xdebug"/> … … 57 97 <pathelement path="${java.class.path}"/> 58 98 </classpath> 99 <arg value="/home/radek/Desktop/Hustopeče.osm"/> 59 100 </java> 60 <exec executable="xsltproc" output="log.html">61 <arg value="log.xsl"/>62 <arg value="log.xml"/>63 </exec>64 101 </target> 65 102 -
applications/editors/josm/plugins/czechaddress/log.xsl
r15461 r15558 18 18 <xsl:choose> 19 19 <xsl:when test="level = 'FINEST'"> 20 <td><font color='#AAAAAA'>< xsl:value-of select="level"/></font></td>21 <td><xsl:value-of select="message"/></td>20 <td><font color='#AAAAAA'><i><xsl:value-of select="level"/></i></font></td> 21 <td><i><xsl:value-of select="message"/></i></td> 22 22 </xsl:when> 23 23 <xsl:when test="level = 'FINER'"> … … 26 26 </xsl:when> 27 27 <xsl:when test="level = 'FINE'"> 28 <td><font color='#444444'>< xsl:value-of select="level"/></font></td>29 <td>< xsl:value-of select="message"/></td>28 <td><font color='#444444'><b><xsl:value-of select="level"/></b></font></td> 29 <td><b><xsl:value-of select="message"/></b></td> 30 30 </xsl:when> 31 31 <xsl:when test="level = 'INFO'"> -
applications/editors/josm/plugins/czechaddress/nbproject/project.xml
r15461 r15558 79 79 <compilation-unit> 80 80 <package-root>src</package-root> 81 <classpath mode="compile">../../core/build:../../core/src :tests/junit-4.5.jar</classpath>81 <classpath mode="compile">../../core/build:../../core/src</classpath> 82 82 <built-to>build</built-to> 83 83 <javadoc-built-to>doc</javadoc-built-to> -
applications/editors/josm/plugins/czechaddress/src/org/openstreetmap/josm/plugins/czechaddress/CzechAddressPlugin.java
r15461 r15558 2 2 3 3 import java.awt.event.KeyEvent; 4 import org.openstreetmap.josm.plugins.czechaddress.actions.PointManipulatorAction; 5 import org.openstreetmap.josm.plugins.czechaddress.gui.LocationSelector; 6 import org.openstreetmap.josm.plugins.czechaddress.actions.GroupManipulatorAction; 7 import org.openstreetmap.josm.plugins.czechaddress.gui.ConflictResolver; 4 import java.io.IOException; 8 5 import java.util.ArrayList; 6 import java.util.Enumeration; 7 import java.util.HashSet; 9 8 import java.util.List; 10 import javax.swing.AbstractButton; 9 import java.util.Set; 10 import java.util.logging.FileHandler; 11 import java.util.logging.Handler; 12 import java.util.logging.Level; 13 import java.util.logging.LogManager; 14 import java.util.logging.Logger; 11 15 import javax.swing.JMenu; 12 16 import javax.swing.JMenuItem; 13 17 14 import org.openstreetmap.josm.plugins.czechaddress.addressdatabase.Database;15 import org.openstreetmap.josm.plugins.czechaddress.addressdatabase.ElementWithStreets;16 18 import org.openstreetmap.josm.Main; 19 import org.openstreetmap.josm.data.osm.OsmPrimitive; 17 20 import org.openstreetmap.josm.gui.IconToggleButton; 18 21 import org.openstreetmap.josm.gui.MainMenu; … … 20 23 import org.openstreetmap.josm.plugins.Plugin; 21 24 import org.openstreetmap.josm.plugins.czechaddress.actions.ConflictResolveAction; 22 import org.openstreetmap.josm.plugins.czechaddress.addressdatabase.AddressElement; 25 import org.openstreetmap.josm.plugins.czechaddress.actions.GroupManipulatorAction; 26 import org.openstreetmap.josm.plugins.czechaddress.actions.PointManipulatorAction; 27 import org.openstreetmap.josm.plugins.czechaddress.addressdatabase.Database; 28 import org.openstreetmap.josm.plugins.czechaddress.addressdatabase.ElementWithStreets; 23 29 import org.openstreetmap.josm.plugins.czechaddress.addressdatabase.House; 24 30 import org.openstreetmap.josm.plugins.czechaddress.parser.MvcrParser; … … 27 33 import org.openstreetmap.josm.plugins.czechaddress.actions.ModifierAction; 28 34 import org.openstreetmap.josm.plugins.czechaddress.actions.SplitAreaByEmptyWayAction; 29 import org.openstreetmap.josm.plugins.czechaddress.gui.Inspector; 30 import org.openstreetmap.josm.plugins.czechaddress.gui.Renamer; 35 import org.openstreetmap.josm.plugins.czechaddress.gui.ConflictResolver; 31 36 import org.openstreetmap.josm.plugins.czechaddress.gui.FactoryDialog; 37 import org.openstreetmap.josm.plugins.czechaddress.gui.LocationSelector; 32 38 import org.openstreetmap.josm.plugins.czechaddress.intelligence.Reasoner; 33 39 import org.openstreetmap.josm.plugins.czechaddress.intelligence.SelectionMonitor; … … 41 47 42 48 43 JMenu czechMenu; 44 List<JMenuItem> menuItems = new ArrayList<JMenuItem>(); 49 private JMenu czechMenu; 50 private List<JMenuItem> menuItems = new ArrayList<JMenuItem>(); 51 private static Logger logger = Logger.getLogger(CzechAddressPlugin.class.getName()); 45 52 46 List<AbstractButton> pluginButtons = 47 new ArrayList<AbstractButton>(); 53 public void initLoggers() { 48 54 49 static public Reasoner reasoner = null; 50 static public Database database = null; 55 String filename = getPluginDir() + "-log.xml"; 56 /*final Logger[] loggers = new Logger[] 57 {logger, Reasoner.logger, ConflictResolver.logger};*/ 51 58 52 static public FactoryDialog factoryDialog = null; 53 static public ConflictResolver conflictResolver = null; 59 try { 60 Handler fileHandler = new FileHandler(filename); 61 fileHandler.setLevel(Level.ALL); 62 for (Enumeration<String> e = LogManager.getLogManager().getLoggerNames(); 63 e.hasMoreElements();) { 64 String name = e.nextElement(); 65 if (!name.startsWith(CzechAddressPlugin.class.getPackage().getName())) 66 continue; 54 67 55 static public Renamer renamer = null; 56 static public Inspector inspector = null; 57 58 59 static private String pluginDir = null; 68 System.err.println(name); 69 Logger.getLogger(name).setLevel(Level.FINE); 70 Logger.getLogger(name).addHandler(fileHandler); 71 } 72 73 } catch (IOException ex) { 74 logger.log(Level.SEVERE, "cannot create file", ex); 75 } catch (SecurityException ex) { 76 logger.log(Level.SEVERE, "permission denied", ex); 77 } 78 } 60 79 61 80 public CzechAddressPlugin() { 62 81 63 pluginDir = getPluginDir();64 82 addStatusListener(this); 83 84 Reasoner.getInstance(); 85 ConflictResolver.getInstance(); 86 SelectionMonitor.getInstance(); 65 87 66 factoryDialog = new FactoryDialog(); 67 conflictResolver = new ConflictResolver(); 68 88 initLoggers(); 69 89 70 90 MainMenu.add(Main.main.menu.toolsMenu, new SplitAreaByEmptyWayAction()); 71 91 92 // Prepare for filling the database. 93 final MvcrParser parser = new MvcrParser(); 94 parser.setTargetDatabase(Database.getInstance()); 95 parser.setStorageDir(getPluginDir()); 72 96 73 // Prepare for filling the database. 74 database = new Database(); 75 final MvcrParser parser = new MvcrParser(); 76 //parser.setFilter(null, null, null, ""); 77 //parser.setFilter("HUSTOPEČE", "HUSTOPEČE", null, null); 78 parser.setTargetDatabase(database); 79 parser.setStorageDir(pluginDir); 97 parser.setFilter("HUSTOPEČE", "HUSTOPEČE", null, null); 80 98 81 99 // Fill the database in separate thread. … … 102 120 return; 103 121 104 newFrame.addToggleDialog( factoryDialog);122 newFrame.addToggleDialog(FactoryDialog.getInstance()); 105 123 newFrame.addMapMode(new IconToggleButton(new FactoryAction(newFrame))); 106 124 } 107 125 108 126 static public void initReasoner() { 127 Reasoner reasoner = Reasoner.getInstance(); 109 128 110 // Move houses from list of Houses to list of AddressElements. 111 List<House> houses = location.getAllHouses(); 112 ArrayList<AddressElement> pool 113 = new ArrayList<AddressElement>(houses.size()); 114 for (House house : houses) pool.add(house); 115 116 // Update database according to the map 117 (new Renamer()).setVisible(true); 118 (new Inspector()).setVisible(true); 119 120 // And add them to the reasoner. 121 reasoner = new Reasoner(pool); 122 reasoner.addPrimitives(Main.ds.allPrimitives()); 129 synchronized(reasoner) { 130 reasoner.reset(); 131 reasoner.openTransaction(); 132 //Reasoner.logger.setLevel(Level.OFF); 133 for (House house : location.getAllHouses()) 134 reasoner.consider(house); 135 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); 144 } 145 //Reasoner.logger.setLevel(Level.ALL); 146 reasoner.closeTransaction(); 147 } 123 148 } 124 149 … … 127 152 if (location == null) 128 153 changeLocation(); 129 130 154 return location; 131 155 } … … 139 163 } 140 164 } 141 142 143 165 144 static private List<StatusListener> listeners = 145 new ArrayList<StatusListener>(); 146 147 static public void addStatusListener(StatusListener l) { 148 if (!listeners.contains(l)) 149 listeners.add(l); 150 } 151 152 static public void removeStatusListener(StatusListener l) { 153 listeners.remove(l); 154 } 155 166 static private Set<StatusListener> listeners = new HashSet<StatusListener>(); 167 static public void addStatusListener(StatusListener l) {listeners.add(l);} 168 static public void removeStatusListener(StatusListener l) {listeners.remove(l);} 156 169 static public void broadcastStatusChange(int statusMessage) { 157 for (StatusListener l : listeners)158 l .pluginStatusChanged(statusMessage);170 for (StatusListener listener : listeners) 171 listener.pluginStatusChanged(statusMessage); 159 172 } 160 173 … … 174 187 return; 175 188 } 176 177 178 // SelectionMonitor cannot be used because of synchronization problems.179 /*if (message == MESSAGE_REASONER_REASONED) {180 System.out.println("ReasonerReasoned");181 if (selectionMonitor == null)182 selectionMonitor = new SelectionMonitor();183 }*/184 189 } 185 190 } -
applications/editors/josm/plugins/czechaddress/src/org/openstreetmap/josm/plugins/czechaddress/StatusListener.java
r15461 r15558 38 38 39 39 /** 40 * List of {@code matches} from the reasoner has changed.41 *42 * <p>The current reasoner can be obtained by43 * {@link CzechAddressPlugin}{@code .getReasoner()}.</p>44 *45 * @see Reasoner46 * @see Match47 */48 static final int MESSAGE_MATCHES_CHANGED = 2;49 50 /**51 * There is a new conflict spotted by the reasoner.52 *53 * <p>The current reasoner can be obtained by54 * {@link CzechAddressPlugin}{@code .getReasoner()}.</p>55 *56 * @see Reasoner57 * @see Match58 */59 static final int MESSAGE_CONFLICT_CHANGED = 3;60 61 /**62 40 * All parsers have finished their parsing. 63 41 * … … 68 46 * @see Database 69 47 */ 70 static final int MESSAGE_DATABASE_LOADED = 4; 71 72 /** 73 * The reasoner has finished his reasoning. 74 * 75 * <p>First such message also signalizes, that there is a reasoner 76 * available.</p> 77 * 78 * <p>The current reasoner can be obtained by 79 * {@link CzechAddressPlugin}{@code .getReasoner()}.</p> 80 * 81 * @see Reasoner 82 */ 83 static final int MESSAGE_REASONER_REASONED = 5; 48 static final int MESSAGE_DATABASE_LOADED = 2; 84 49 85 50 /** -
applications/editors/josm/plugins/czechaddress/src/org/openstreetmap/josm/plugins/czechaddress/StringUtils.java
r15461 r15558 12 12 * @author Radomír Černoch, radomir.cernoch@gmail.com 13 13 */ 14 public class StringUtils {14 public abstract class StringUtils { 15 15 16 16 /** … … 55 55 * s2="Náměstí Svobody".</p> 56 56 */ 57 public boolean matchAbbrev(String s1, String s2) {57 public static boolean matchAbbrev(String s1, String s2) { 58 58 String[] parts1 = s1.split(" +"); 59 59 String[] parts2 = s2.split(" +"); … … 116 116 return result; 117 117 } 118 119 118 } -
applications/editors/josm/plugins/czechaddress/src/org/openstreetmap/josm/plugins/czechaddress/actions/ConflictResolveAction.java
r15166 r15558 39 39 */ 40 40 public void actionPerformed(ActionEvent e) { 41 if (CzechAddressPlugin.conflictResolver == null) return; 42 CzechAddressPlugin.conflictResolver.setVisible(true); 41 ConflictResolver.getInstance().setVisible(true); 43 42 } 44 43 } -
applications/editors/josm/plugins/czechaddress/src/org/openstreetmap/josm/plugins/czechaddress/actions/FactoryAction.java
r15461 r15558 11 11 import org.openstreetmap.josm.plugins.czechaddress.CzechAddressPlugin; 12 12 import org.openstreetmap.josm.plugins.czechaddress.addressdatabase.House; 13 import org.openstreetmap.josm.plugins.czechaddress.intelligence.Reasoner; 13 14 import org.openstreetmap.josm.plugins.czechaddress.proposal.ProposalContainer; 14 15 import org.openstreetmap.josm.tools.ImageProvider; … … 53 54 Main.map.mapView.addMouseListener(this); 54 55 55 if (CzechAddressPlugin.reasoner == null) {56 exitMode();57 return;58 }59 60 56 // Switch to next unassigned house. 61 FactoryDialog d = CzechAddressPlugin.factoryDialog;62 if ( CzechAddressPlugin.reasoner.translate(d.getSelectedHouse()) != null)57 FactoryDialog d = FactoryDialog.getInstance(); 58 if (Reasoner.getInstance().translate(d.getSelectedHouse()) != null) 63 59 d.selectNextUnmatchedHouseByCheckBox(); 64 60 } … … 86 82 87 83 // Get the currently selected House in the FactoryDialog. 88 House house = CzechAddressPlugin.factoryDialog.getSelectedHouse();84 House house = FactoryDialog.getInstance().getSelectedHouse(); 89 85 if (house == null) 90 86 return; // TODO: Some meaningful messageBox would be useful. … … 97 93 container.applyAll(); 98 94 95 Reasoner r = Reasoner.getInstance(); 96 synchronized(r) { 97 r.openTransaction(); 98 r.doOverwrite(newNode, house); 99 r.closeTransaction(); 100 } 101 FactoryDialog.getInstance().selectNextUnmatchedHouseByCheckBox(); 102 99 103 // And make the new node selected. 100 104 Main.ds.addPrimitive(newNode); 101 105 Main.ds.setSelected(newNode); 102 103 CzechAddressPlugin.reasoner.overwriteMatch(house, newNode);104 CzechAddressPlugin.factoryDialog.selectNextUnmatchedHouseByCheckBox();105 106 } 106 107 } -
applications/editors/josm/plugins/czechaddress/src/org/openstreetmap/josm/plugins/czechaddress/addressdatabase/AddressElement.java
r15461 r15558 16 16 * @author Radomír Černoch radomir.cernoch@gmail.com 17 17 */ 18 public abstract class AddressElement {18 public abstract class AddressElement implements Comparable<AddressElement> { 19 19 20 20 protected String name; 21 21 protected AddressElement parent = null; 22 23 protected static final String KEY_ADDR_CP = "addr:alternatenumber";24 protected static final String KEY_ADDR_CO = "addr:housenumber";25 protected static final String KEY_ADDR_STREET = "addr:street";26 protected static final String KEY_ADDR_CITY = "addr:city";27 protected static final String KEY_ADDR_COUNTRY = "addr:country";28 protected static final String KEY_IS_IN = "is_in";29 protected static final String KEY_NAME = "name";30 22 31 23 /** … … 199 191 elemValue.trim().toUpperCase())) ? 1 : -1; 200 192 } 201 193 194 public static int matchFieldAbbrev(String elemValue, String primValue) { 195 196 if (elemValue == null) return 0; 197 if (primValue == null) return -1; 198 199 return StringUtils.matchAbbrev(primValue, elemValue) ? 1 : -1; 200 } 201 202 202 203 203 protected int[] getFieldMatchList(OsmPrimitive primitive) { … … 211 211 } 212 212 213 public boolean isMatchable(OsmPrimitive prim) {214 return false;215 }216 217 218 213 public int getMatchQuality(OsmPrimitive primitive) { 219 214 … … 278 273 return result; 279 274 } 275 276 public int compareTo(AddressElement elem) { 277 278 ParentResolver r1 = new ParentResolver(this); 279 ParentResolver r2 = new ParentResolver(elem); 280 281 int retVal = r1.compareTo(r2); 282 if (retVal != 0) return retVal; 283 284 return getName().compareTo(((AddressElement) elem).getName()); 285 } 280 286 } -
applications/editors/josm/plugins/czechaddress/src/org/openstreetmap/josm/plugins/czechaddress/addressdatabase/Database.java
r15166 r15558 14 14 */ 15 15 public class Database { 16 17 private Database() {} 18 private static Database singleton = null; 19 public static Database getInstance() { 20 if (singleton == null) 21 singleton = new Database(); 22 23 return singleton; 24 } 16 25 17 26 /** -
applications/editors/josm/plugins/czechaddress/src/org/openstreetmap/josm/plugins/czechaddress/addressdatabase/House.java
r15461 r15558 4 4 import org.openstreetmap.josm.data.osm.OsmPrimitive; 5 5 import org.openstreetmap.josm.plugins.czechaddress.NotNullList; 6 import org.openstreetmap.josm.plugins.czechaddress.PrimUtils; 7 import org.openstreetmap.josm.plugins.czechaddress.StringUtils; 6 8 import org.openstreetmap.josm.plugins.czechaddress.proposal.Proposal; 7 9 … … 139 141 140 142 // First field is the AlternateNubmer 141 result[0] = matchField(this.cp, prim.get( KEY_ADDR_CP));143 result[0] = matchField(this.cp, prim.get(PrimUtils.KEY_ADDR_CP)); 142 144 143 145 // Second field is the Housenumber 144 146 if (parent instanceof Street) 145 result[1] = Math.min( matchField(parent.getName(), prim.get(KEY_ADDR_STREET)), 146 matchField(this.co, prim.get(KEY_ADDR_CO)) ); 147 result[1] = Math.min( 148 matchFieldAbbrev(parent.getName(), prim.get(PrimUtils.KEY_ADDR_STREET)), 149 matchField( this.co, prim.get(PrimUtils.KEY_ADDR_CO)) ); 147 150 return result; 148 151 } … … 160 163 ParentResolver pr = new ParentResolver(this); 161 164 162 props.add(getStringFieldDiff( KEY_ADDR_CP, prim.get(KEY_ADDR_CP), getCP()));163 props.add(getStringFieldDiff( KEY_ADDR_CO, prim.get(KEY_ADDR_CO), getCO()));164 165 props.add(getStringFieldDiff( KEY_ADDR_COUNTRY,166 prim.get( KEY_ADDR_COUNTRY), "CZ"));165 props.add(getStringFieldDiff(PrimUtils.KEY_ADDR_CP, prim.get(PrimUtils.KEY_ADDR_CP), getCP())); 166 props.add(getStringFieldDiff(PrimUtils.KEY_ADDR_CO, prim.get(PrimUtils.KEY_ADDR_CO), getCO())); 167 168 props.add(getStringFieldDiff(PrimUtils.KEY_ADDR_COUNTRY, 169 prim.get(PrimUtils.KEY_ADDR_COUNTRY), "CZ")); 167 170 168 171 if (pr.parentStreet != null) 169 props.add(getStringFieldDiff( KEY_ADDR_STREET,170 prim.get( KEY_ADDR_STREET),172 props.add(getStringFieldDiff(PrimUtils.KEY_ADDR_STREET, 173 prim.get(PrimUtils.KEY_ADDR_STREET), 171 174 pr.parentStreet.getName())); 172 173 /* if (pr.parentViToCi != null) { 174 String targetIsIn = ""; 175 176 if ((pr.parentSuburb != null) && 177 !(pr.parentViToCi.getName().equals(pr.parentSuburb.getName()))) 178 targetIsIn += pr.parentSuburb.getName() + ", "; 179 180 targetIsIn += pr.parentViToCi.getName() + ", "; 181 182 if (pr.parentRegion != null) 183 targetIsIn += pr.parentRegion.getNuts3Name() + " kraj, "; 184 185 targetIsIn += "CZ"; 186 187 props.add(getStringFieldDiff(KEY_ADDR_CITY, 188 prim.get(KEY_ADDR_CITY), 189 pr.parentViToCi.getName())); 190 */ 191 192 175 193 176 if (parent.parent != null) // For sure our parent is a ElemWithStreets 194 props.add(getStringFieldDiff( KEY_IS_IN,195 prim.get( KEY_IS_IN),177 props.add(getStringFieldDiff(PrimUtils.KEY_IS_IN, 178 prim.get(PrimUtils.KEY_IS_IN), 196 179 parent.parent.getIsIn())); 197 /* }*/198 180 199 181 // If we have added any proposal so far, add the source info as well. … … 204 186 } 205 187 206 public boolean isMatchable(OsmPrimitive prim) {188 public static boolean isMatchable(OsmPrimitive prim) { 207 189 208 190 for (String key : prim.keySet()) { … … 211 193 return true; 212 194 } 213 214 195 return false; 215 196 } 197 198 @Override 199 public int compareTo(AddressElement o) { 200 // Most important criterion is the street 201 int val = super.compareTo(o); 202 if (val != 0) return val; 203 if (!(o instanceof House)) return val; 204 205 House house = (House) o; 206 207 // Second most important is the "CO" 208 if (co != null && house.co != null) 209 val = co.compareTo(house.co); 210 if (val != 0) return val; 211 212 // Third most important is the "CP" 213 if (cp != null && house.cp != null) 214 val = cp.compareTo(house.cp); 215 return val; 216 } 216 217 } -
applications/editors/josm/plugins/czechaddress/src/org/openstreetmap/josm/plugins/czechaddress/addressdatabase/ParentResolver.java
r15166 r15558 10 10 * @author Radomír Černoch, radomir.cernoch@gmail.com 11 11 */ 12 public class ParentResolver {12 public class ParentResolver implements Comparable<ParentResolver> { 13 13 14 14 public Street parentStreet = null; … … 39 39 } 40 40 } 41 42 public int compareTo(ParentResolver o) { 43 int val = 0; 44 45 if (parentRegion != null && o.parentRegion != null) 46 val = parentRegion.compareTo(o.parentRegion); 47 if (val != 0) 48 return val; 49 50 if (parentViToCi != null && o.parentViToCi != null) 51 val = parentViToCi.compareTo(o.parentViToCi); 52 if (val != 0) 53 return val; 54 55 if (parentSuburb != null && o.parentSuburb != null) 56 val = parentSuburb.compareTo(o.parentSuburb); 57 if (val != 0) 58 return val; 59 60 if (parentStreet != null && o.parentStreet != null) 61 val = parentStreet.compareTo(o.parentStreet); 62 return val; 63 } 41 64 } -
applications/editors/josm/plugins/czechaddress/src/org/openstreetmap/josm/plugins/czechaddress/gui/ConflictResolver.form
r15166 r15558 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="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,36,0,0,2,13"/>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,0,93,0,0,2,-114"/> 21 21 </AuxValues> 22 22 … … 33 33 <Group type="102" alignment="1" attributes="0"> 34 34 <Group type="103" groupAlignment="0" attributes="0"> 35 <Component id="jLabel4" min="-2" max="-2" attributes="0"/> 36 <Component id="jLabel5" min="-2" max="-2" attributes="0"/> 37 <Component id="jLabel6" min="-2" max="-2" attributes="0"/> 35 <Component id="candLabel" min="-2" max="-2" attributes="0"/> 36 <Component id="mainLabel" min="-2" max="-2" attributes="0"/> 38 37 </Group> 39 <EmptySpace min="-2" max="-2" attributes="0"/>38 <EmptySpace min="-2" pref="6" max="-2" attributes="0"/> 40 39 <Group type="103" groupAlignment="0" attributes="0"> 41 <Group type="102" alignment="1" attributes="0"> 42 <Component id="candTextField" pref="232" max="32767" attributes="1"/> 43 <EmptySpace max="-2" attributes="0"/> 44 <Component id="candReassignButton" min="-2" max="-2" attributes="0"/> 45 </Group> 46 <Component id="bestTextField" alignment="0" pref="319" max="32767" attributes="1"/> 47 <Component id="mainTextField" alignment="0" pref="319" max="32767" attributes="1"/> 40 <Component id="candField" alignment="1" pref="430" max="32767" attributes="1"/> 41 <Component id="mainField" alignment="0" pref="430" max="32767" attributes="1"/> 48 42 </Group> 49 <EmptySpace m in="-2" max="-2" attributes="0"/>43 <EmptySpace max="-2" attributes="0"/> 50 44 <Group type="103" groupAlignment="1" attributes="0"> 45 <Component id="candZoomButton" min="-2" max="-2" attributes="0"/> 51 46 <Component id="mainZoomButton" min="-2" max="-2" attributes="0"/> 52 <Component id="bestZoomButton" min="-2" max="-2" attributes="0"/> 53 <Component id="candZoomButton" min="-2" max="-2" attributes="0"/> 47 </Group> 48 <EmptySpace max="-2" attributes="0"/> 49 <Group type="103" groupAlignment="0" attributes="0"> 50 <Component id="mainPickButton" min="-2" max="-2" attributes="0"/> 51 <Component id="candPickButton" alignment="0" min="-2" max="-2" attributes="0"/> 54 52 </Group> 55 53 </Group> 56 <Component id="jTabbedPane1" alignment="0" pref="525" max="32767" attributes="1"/> 54 <Group type="102" alignment="1" attributes="0"> 55 <EmptySpace max="-2" attributes="0"/> 56 <Component id="reassignButton" min="-2" max="-2" attributes="0"/> 57 </Group> 57 58 </Group> 58 59 </DimensionLayout> 59 60 <DimensionLayout dim="1"> 60 61 <Group type="103" groupAlignment="0" attributes="0"> 61 <Group type="102" alignment="1" attributes="0"> 62 <Component id="jTabbedPane1" pref="199" max="32767" attributes="0"/> 63 <EmptySpace max="-2" attributes="0"/> 64 <Group type="103" groupAlignment="3" attributes="0"> 65 <Component id="mainTextField" alignment="3" min="-2" max="-2" attributes="0"/> 66 <Component id="mainZoomButton" alignment="3" min="-2" max="-2" attributes="0"/> 67 <Component id="jLabel4" alignment="3" min="-2" max="-2" attributes="0"/> 62 <Group type="102" alignment="0" attributes="0"> 63 <Group type="103" groupAlignment="0" attributes="0"> 64 <Group type="103" alignment="0" groupAlignment="3" attributes="0"> 65 <Component id="mainField" alignment="3" min="-2" max="-2" attributes="0"/> 66 <Component id="mainLabel" alignment="3" min="-2" max="-2" attributes="0"/> 67 </Group> 68 <Group type="102" attributes="0"> 69 <Group type="103" groupAlignment="3" attributes="0"> 70 <Component id="mainZoomButton" alignment="3" min="-2" max="-2" attributes="0"/> 71 <Component id="mainPickButton" alignment="3" min="-2" max="-2" attributes="0"/> 72 </Group> 73 <EmptySpace max="-2" attributes="0"/> 74 <Group type="103" groupAlignment="3" attributes="0"> 75 <Component id="candPickButton" alignment="3" min="-2" max="-2" attributes="0"/> 76 <Component id="candZoomButton" alignment="3" min="-2" max="-2" attributes="0"/> 77 <Component id="candField" alignment="3" min="-2" max="-2" attributes="0"/> 78 <Component id="candLabel" alignment="3" min="-2" max="-2" attributes="0"/> 79 </Group> 80 </Group> 68 81 </Group> 69 <EmptySpace max="-2" attributes="0"/> 70 <Group type="103" groupAlignment="3" attributes="0"> 71 <Component id="bestTextField" alignment="3" min="-2" max="-2" attributes="0"/> 72 <Component id="bestZoomButton" alignment="3" min="-2" max="-2" attributes="0"/> 73 <Component id="jLabel5" alignment="3" min="-2" max="-2" attributes="0"/> 74 </Group> 75 <EmptySpace max="-2" attributes="0"/> 76 <Group type="103" groupAlignment="3" attributes="0"> 77 <Component id="candReassignButton" alignment="3" min="-2" max="-2" attributes="0"/> 78 <Component id="candTextField" alignment="3" min="-2" max="-2" attributes="0"/> 79 <Component id="candZoomButton" alignment="3" min="-2" max="-2" attributes="0"/> 80 <Component id="jLabel6" alignment="3" min="-2" max="-2" attributes="0"/> 81 </Group> 82 <EmptySpace max="32767" attributes="0"/> 83 <Component id="reassignButton" min="-2" max="-2" attributes="0"/> 82 84 </Group> 83 85 </Group> … … 88 90 <Properties> 89 91 <Property name="text" type="java.lang.String" value=" "/> 92 <Property name="enabled" type="boolean" value="false"/> 90 93 </Properties> 91 94 <Events> … … 93 96 </Events> 94 97 </Component> 95 <Component class="javax.swing.J Button" name="bestZoomButton">98 <Component class="javax.swing.JLabel" name="mainLabel"> 96 99 <Properties> 97 <Property name="text" type="java.lang.String" value=" "/> 98 </Properties> 99 <Events> 100 <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="bestZoomButtonActionPerformed"/> 101 </Events> 102 </Component> 103 <Container class="javax.swing.JTabbedPane" name="jTabbedPane1"> 104 105 <Layout class="org.netbeans.modules.form.compat2.layouts.support.JTabbedPaneSupportLayout"/> 106 <SubComponents> 107 <Container class="javax.swing.JScrollPane" name="jScrollPane1"> 108 <AuxValues> 109 <AuxValue name="autoScrollPane" type="java.lang.Boolean" value="true"/> 110 </AuxValues> 111 <Constraints> 112 <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.support.JTabbedPaneSupportLayout" value="org.netbeans.modules.form.compat2.layouts.support.JTabbedPaneSupportLayout$JTabbedPaneConstraintsDescription"> 113 <JTabbedPaneConstraints tabName="Dle databáze"> 114 <Property name="tabTitle" type="java.lang.String" value="Dle databáze"/> 115 </JTabbedPaneConstraints> 116 </Constraint> 117 </Constraints> 118 119 <Layout class="org.netbeans.modules.form.compat2.layouts.support.JScrollPaneSupportLayout"/> 120 <SubComponents> 121 <Component class="javax.swing.JTree" name="elemConflictTree"> 122 <Events> 123 <EventHandler event="valueChanged" listener="javax.swing.event.TreeSelectionListener" parameters="javax.swing.event.TreeSelectionEvent" handler="treeValueChanged"/> 124 </Events> 125 </Component> 126 </SubComponents> 127 </Container> 128 <Container class="javax.swing.JScrollPane" name="jScrollPane2"> 129 <AuxValues> 130 <AuxValue name="autoScrollPane" type="java.lang.Boolean" value="true"/> 131 </AuxValues> 132 <Constraints> 133 <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.support.JTabbedPaneSupportLayout" value="org.netbeans.modules.form.compat2.layouts.support.JTabbedPaneSupportLayout$JTabbedPaneConstraintsDescription"> 134 <JTabbedPaneConstraints tabName="Dle mapy"> 135 <Property name="tabTitle" type="java.lang.String" value="Dle mapy"/> 136 </JTabbedPaneConstraints> 137 </Constraint> 138 </Constraints> 139 140 <Layout class="org.netbeans.modules.form.compat2.layouts.support.JScrollPaneSupportLayout"/> 141 <SubComponents> 142 <Component class="javax.swing.JTree" name="primConflictTree"> 143 <Events> 144 <EventHandler event="valueChanged" listener="javax.swing.event.TreeSelectionListener" parameters="javax.swing.event.TreeSelectionEvent" handler="treeValueChanged"/> 145 </Events> 146 </Component> 147 </SubComponents> 148 </Container> 149 </SubComponents> 150 </Container> 151 <Component class="javax.swing.JLabel" name="jLabel4"> 152 <Properties> 153 <Property name="text" type="java.lang.String" value="Objekt v konfliktu:"/> 100 <Property name="text" type="java.lang.String" value="Nejednoznačný prvek:"/> 154 101 </Properties> 155 102 </Component> 156 <Component class="javax.swing.J TextField" name="mainTextField">103 <Component class="javax.swing.JButton" name="reassignButton"> 157 104 <Properties> 158 <Property name="editable" type="boolean" value="false"/> 159 </Properties> 160 </Component> 161 <Component class="javax.swing.JTextField" name="bestTextField"> 162 <Properties> 163 <Property name="editable" type="boolean" value="false"/> 164 </Properties> 165 </Component> 166 <Component class="javax.swing.JLabel" name="jLabel5"> 167 <Properties> 168 <Property name="text" type="java.lang.String" value="Nejlepší přiřazení:"/> 169 </Properties> 170 </Component> 171 <Component class="javax.swing.JTextField" name="candTextField"> 172 <Properties> 173 <Property name="editable" type="boolean" value="false"/> 174 </Properties> 175 </Component> 176 <Component class="javax.swing.JButton" name="candReassignButton"> 177 <Properties> 178 <Property name="text" type="java.lang.String" value="Přiřadit"/> 105 <Property name="text" type="java.lang.String" value="Určit jako nejlepší přiřažení"/> 179 106 <Property name="enabled" type="boolean" value="false"/> 180 107 </Properties> 181 108 <Events> 182 <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler=" candReassignButtonActionPerformed"/>109 <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="reassignButtonActionPerformed"/> 183 110 </Events> 184 111 </Component> 185 <Component class="javax.swing.JLabel" name=" jLabel6">112 <Component class="javax.swing.JLabel" name="candLabel"> 186 113 <Properties> 187 <Property name="text" type="java.lang.String" value=" Problémový element:"/>114 <Property name="text" type="java.lang.String" value="Kandidáti na přiřazení:"/> 188 115 </Properties> 189 116 </Component> … … 191 118 <Properties> 192 119 <Property name="text" type="java.lang.String" value=" "/> 120 <Property name="enabled" type="boolean" value="false"/> 193 121 </Properties> 194 122 <Events> 195 123 <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="mainZoomButtonActionPerformed"/> 124 </Events> 125 </Component> 126 <Component class="javax.swing.JComboBox" name="mainField"> 127 <Properties> 128 <Property name="model" type="javax.swing.ComboBoxModel" editor="org.netbeans.modules.form.editors2.ComboBoxModelEditor"> 129 <StringArray count="4"> 130 <StringItem index="0" value="Item 1"/> 131 <StringItem index="1" value="Item 2"/> 132 <StringItem index="2" value="Item 3"/> 133 <StringItem index="3" value="Item 4"/> 134 </StringArray> 135 </Property> 136 <Property name="renderer" type="javax.swing.ListCellRenderer" editor="org.netbeans.modules.form.RADConnectionPropertyEditor"> 137 <Connection code="new UniversalListRenderer()" type="code"/> 138 </Property> 139 </Properties> 140 </Component> 141 <Component class="javax.swing.JComboBox" name="candField"> 142 <Properties> 143 <Property name="model" type="javax.swing.ComboBoxModel" editor="org.netbeans.modules.form.editors2.ComboBoxModelEditor"> 144 <StringArray count="1"> 145 <StringItem index="0" value=" "/> 146 </StringArray> 147 </Property> 148 <Property name="renderer" type="javax.swing.ListCellRenderer" editor="org.netbeans.modules.form.RADConnectionPropertyEditor"> 149 <Connection code="new UniversalListRenderer()" type="code"/> 150 </Property> 151 </Properties> 152 </Component> 153 <Component class="javax.swing.JButton" name="candPickButton"> 154 <Properties> 155 <Property name="text" type="java.lang.String" value=" "/> 156 <Property name="enabled" type="boolean" value="false"/> 157 </Properties> 158 </Component> 159 <Component class="javax.swing.JButton" name="mainPickButton"> 160 <Properties> 161 <Property name="text" type="java.lang.String" value=" "/> 162 <Property name="enabled" type="boolean" value="false"/> 163 </Properties> 164 <Events> 165 <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="mainPickButtonActionPerformed"/> 196 166 </Events> 197 167 </Component> -
applications/editors/josm/plugins/czechaddress/src/org/openstreetmap/josm/plugins/czechaddress/gui/ConflictResolver.java
r15461 r15558 1 1 package org.openstreetmap.josm.plugins.czechaddress.gui; 2 2 3 import java.awt.Component; 4 import java.awt.Font; 5 import java.util.ArrayList; 6 import java.util.Collections; 7 import java.util.HashSet; 3 8 import java.util.List; 9 import java.util.Set; 10 import java.util.logging.Level; 4 11 import java.util.logging.Logger; 5 import org.openstreetmap.josm.plugins.czechaddress.*; 12 import javax.swing.ComboBoxModel; 13 import javax.swing.DefaultComboBoxModel; 14 import javax.swing.JList; 15 import javax.swing.event.ListDataListener; 6 16 import javax.swing.Icon; 7 import javax.swing.tree.TreePath; 17 import javax.swing.JButton; 18 import javax.swing.event.ListDataEvent; 8 19 import org.openstreetmap.josm.Main; 9 20 import org.openstreetmap.josm.data.osm.OsmPrimitive; 10 21 import org.openstreetmap.josm.gui.ExtendedDialog; 22 import org.openstreetmap.josm.plugins.czechaddress.MapUtils; 23 import org.openstreetmap.josm.plugins.czechaddress.NotNullList; 24 import org.openstreetmap.josm.plugins.czechaddress.PrimUtils; 11 25 import org.openstreetmap.josm.plugins.czechaddress.addressdatabase.AddressElement; 12 import org.openstreetmap.josm.plugins.czechaddress.intelligence.Match; 26 import org.openstreetmap.josm.plugins.czechaddress.addressdatabase.House; 27 import org.openstreetmap.josm.plugins.czechaddress.addressdatabase.Street; 13 28 import org.openstreetmap.josm.plugins.czechaddress.intelligence.Reasoner; 29 import org.openstreetmap.josm.plugins.czechaddress.intelligence.ReasonerListener; 30 import org.openstreetmap.josm.plugins.czechaddress.gui.utils.UniversalListRenderer; 14 31 import org.openstreetmap.josm.tools.ImageProvider; 15 32 16 33 /** 17 * Dialog for displaying and handling conflicts.34 * Dialog for displaying and handling getConflicts. 18 35 * 19 36 * @author Radomír Černoch, radomir.cernoch@gmail.com 20 37 */ 21 public class ConflictResolver extends ExtendedDialog 22 implements StatusListener { 23 24 private Object selMainObj = null; 25 private Object selBestFit = null; 26 private Object selCandObj = null; 38 public class ConflictResolver extends ExtendedDialog { 39 40 private static ConflictResolver singleton = null; 41 public static ConflictResolver getInstance() { 42 if (singleton == null) 43 singleton = new ConflictResolver(); 44 return singleton; 45 } 46 47 public static Logger logger = Logger.getLogger(ConflictResolver.class.getName()); 27 48 28 49 /** 29 50 * Creates new dialog, but does not display it, nor hook to messages. 30 51 */ 31 public ConflictResolver() { 32 33 super(Main.parent, "Řešení konfliktů", 34 new String[] { }, true); 35 52 private ConflictResolver() { 53 54 super(Main.parent, "Řešení konfliktů", new String[] {}, true); 36 55 initComponents(); 37 56 38 elemConflictTree.setModel(new ElemTreeModel()); 39 primConflictTree.setModel(new PrimTreeModel()); 40 41 elemConflictTree.setCellRenderer(new UniversalTreeRenderer()); 42 primConflictTree.setCellRenderer(new UniversalTreeRenderer()); 57 mainField.setModel(conflictModel); 58 // conflictModel.addListDataListener(mainField); 59 60 Reasoner.getInstance().addListener(new ReasonerHook()); 43 61 44 62 // Create those lovely 'zoom' icons for professional look. 45 63 Icon zoomIcon = ImageProvider.get("zoom.png"); 46 64 mainZoomButton.setIcon(zoomIcon); mainZoomButton.setText(""); 47 bestZoomButton.setIcon(zoomIcon); bestZoomButton.setText("");48 65 candZoomButton.setIcon(zoomIcon); candZoomButton.setText(""); 49 66 67 Icon cursorIcon = ImageProvider.get("cursor.png"); 68 mainPickButton.setIcon(cursorIcon); mainPickButton.setText(""); 69 candPickButton.setIcon(cursorIcon); candPickButton.setText(""); 70 50 71 // And finalize initializing the form. 51 setupDialog(mainPanel, new String[] { }); 52 setAlwaysOnTop(false); 53 72 setupDialog(mainPanel, new String[] {}); 54 73 // TODO: Why does it always crash if the modality is set in constructor? 55 74 setModal(false); … … 62 81 */ 63 82 @SuppressWarnings("unchecked") 64 // <editor-fold defaultstate="collapsed" desc=" Generated Code">//GEN-BEGIN:initComponents83 // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents 65 84 private void initComponents() { 85 66 86 mainPanel = new javax.swing.JPanel(); 67 87 candZoomButton = new javax.swing.JButton(); 68 bestZoomButton = new javax.swing.JButton(); 69 jTabbedPane1 = new javax.swing.JTabbedPane(); 70 jScrollPane1 = new javax.swing.JScrollPane(); 71 elemConflictTree = new javax.swing.JTree(); 72 jScrollPane2 = new javax.swing.JScrollPane(); 73 primConflictTree = new javax.swing.JTree(); 74 jLabel4 = new javax.swing.JLabel(); 75 mainTextField = new javax.swing.JTextField(); 76 bestTextField = new javax.swing.JTextField(); 77 jLabel5 = new javax.swing.JLabel(); 78 candTextField = new javax.swing.JTextField(); 79 candReassignButton = new javax.swing.JButton(); 80 jLabel6 = new javax.swing.JLabel(); 88 mainLabel = new javax.swing.JLabel(); 89 reassignButton = new javax.swing.JButton(); 90 candLabel = new javax.swing.JLabel(); 81 91 mainZoomButton = new javax.swing.JButton(); 82 92 mainField = new javax.swing.JComboBox(); 93 candField = new javax.swing.JComboBox(); 94 candPickButton = new javax.swing.JButton(); 95 mainPickButton = new javax.swing.JButton(); 96 97 setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); 83 98 getContentPane().setLayout(new java.awt.GridLayout(1, 0)); 84 99 85 setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);86 100 candZoomButton.setText(" "); 101 candZoomButton.setEnabled(false); 87 102 candZoomButton.addActionListener(new java.awt.event.ActionListener() { 88 103 public void actionPerformed(java.awt.event.ActionEvent evt) { … … 91 106 }); 92 107 93 bestZoomButton.setText(" "); 94 bestZoomButton.addActionListener(new java.awt.event.ActionListener() { 108 mainLabel.setText("Nejednoznačný prvek:"); 109 110 reassignButton.setText("Určit jako nejlepší přiřažení"); 111 reassignButton.setEnabled(false); 112 reassignButton.addActionListener(new java.awt.event.ActionListener() { 95 113 public void actionPerformed(java.awt.event.ActionEvent evt) { 96 bestZoomButtonActionPerformed(evt);114 reassignButtonActionPerformed(evt); 97 115 } 98 116 }); 99 117 100 elemConflictTree.addTreeSelectionListener(new javax.swing.event.TreeSelectionListener() { 101 public void valueChanged(javax.swing.event.TreeSelectionEvent evt) { 102 treeValueChanged(evt); 103 } 104 }); 105 106 jScrollPane1.setViewportView(elemConflictTree); 107 108 jTabbedPane1.addTab("Dle datab\u00e1ze", jScrollPane1); 109 110 primConflictTree.addTreeSelectionListener(new javax.swing.event.TreeSelectionListener() { 111 public void valueChanged(javax.swing.event.TreeSelectionEvent evt) { 112 treeValueChanged(evt); 113 } 114 }); 115 116 jScrollPane2.setViewportView(primConflictTree); 117 118 jTabbedPane1.addTab("Dle mapy", jScrollPane2); 119 120 jLabel4.setText("Objekt v konfliktu:"); 121 122 mainTextField.setEditable(false); 123 124 bestTextField.setEditable(false); 125 126 jLabel5.setText("Nejlep\u0161\u00ed p\u0159i\u0159azen\u00ed:"); 127 128 candTextField.setEditable(false); 129 130 candReassignButton.setText("P\u0159i\u0159adit"); 131 candReassignButton.setEnabled(false); 132 candReassignButton.addActionListener(new java.awt.event.ActionListener() { 133 public void actionPerformed(java.awt.event.ActionEvent evt) { 134 candReassignButtonActionPerformed(evt); 135 } 136 }); 137 138 jLabel6.setText("Probl\u00e9mov\u00fd element:"); 118 candLabel.setText("Kandidáti na přiřazení:"); 139 119 140 120 mainZoomButton.setText(" "); 121 mainZoomButton.setEnabled(false); 141 122 mainZoomButton.addActionListener(new java.awt.event.ActionListener() { 142 123 public void actionPerformed(java.awt.event.ActionEvent evt) { 143 124 mainZoomButtonActionPerformed(evt); 125 } 126 }); 127 128 mainField.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" })); 129 mainField.setRenderer(new UniversalListRenderer()); 130 131 candField.setModel(new javax.swing.DefaultComboBoxModel(new String[] { " " })); 132 candField.setRenderer(new UniversalListRenderer()); 133 134 candPickButton.setText(" "); 135 candPickButton.setEnabled(false); 136 137 mainPickButton.setText(" "); 138 mainPickButton.setEnabled(false); 139 mainPickButton.addActionListener(new java.awt.event.ActionListener() { 140 public void actionPerformed(java.awt.event.ActionEvent evt) { 141 mainPickButtonActionPerformed(evt); 144 142 } 145 143 }); … … 151 149 .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, mainPanelLayout.createSequentialGroup() 152 150 .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 153 .addComponent(jLabel4) 154 .addComponent(jLabel5) 155 .addComponent(jLabel6)) 151 .addComponent(candLabel) 152 .addComponent(mainLabel)) 153 .addGap(6, 6, 6) 154 .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 155 .addComponent(candField, javax.swing.GroupLayout.Alignment.TRAILING, 0, 430, Short.MAX_VALUE) 156 .addComponent(mainField, 0, 430, Short.MAX_VALUE)) 157 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) 158 .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) 159 .addComponent(candZoomButton) 160 .addComponent(mainZoomButton)) 156 161 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) 157 162 .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 158 .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, mainPanelLayout.createSequentialGroup() 159 .addComponent(candTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 232, Short.MAX_VALUE) 160 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) 161 .addComponent(candReassignButton)) 162 .addComponent(bestTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 319, Short.MAX_VALUE) 163 .addComponent(mainTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 319, Short.MAX_VALUE)) 164 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) 165 .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) 166 .addComponent(mainZoomButton) 167 .addComponent(bestZoomButton) 168 .addComponent(candZoomButton))) 169 .addComponent(jTabbedPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 525, Short.MAX_VALUE) 163 .addComponent(mainPickButton) 164 .addComponent(candPickButton))) 165 .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, mainPanelLayout.createSequentialGroup() 166 .addContainerGap() 167 .addComponent(reassignButton)) 170 168 ); 171 169 mainPanelLayout.setVerticalGroup( 172 170 mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 173 .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, mainPanelLayout.createSequentialGroup() 174 .addComponent(jTabbedPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 199, Short.MAX_VALUE) 175 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) 176 .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) 177 .addComponent(mainTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) 178 .addComponent(mainZoomButton) 179 .addComponent(jLabel4)) 180 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) 181 .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) 182 .addComponent(bestTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) 183 .addComponent(bestZoomButton) 184 .addComponent(jLabel5)) 185 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) 186 .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) 187 .addComponent(candReassignButton) 188 .addComponent(candTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) 189 .addComponent(candZoomButton) 190 .addComponent(jLabel6))) 171 .addGroup(mainPanelLayout.createSequentialGroup() 172 .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 173 .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) 174 .addComponent(mainField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) 175 .addComponent(mainLabel)) 176 .addGroup(mainPanelLayout.createSequentialGroup() 177 .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) 178 .addComponent(mainZoomButton) 179 .addComponent(mainPickButton)) 180 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) 181 .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) 182 .addComponent(candPickButton) 183 .addComponent(candZoomButton) 184 .addComponent(candField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) 185 .addComponent(candLabel)))) 186 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) 187 .addComponent(reassignButton)) 191 188 ); 189 192 190 getContentPane().add(mainPanel); 193 191 … … 195 193 }// </editor-fold>//GEN-END:initComponents 196 194 197 private void treeValueChanged(javax.swing.event.TreeSelectionEvent evt) {//GEN-FIRST:event_treeValueChanged198 selMainObj = null;199 selBestFit = null;200 selCandObj = null;201 202 Reasoner r = CzechAddressPlugin.getReasoner();203 TreePath tp = evt.getPath();204 205 if (tp.getPathCount() >= 2)206 selMainObj = tp.getPathComponent(1);207 208 if (selMainObj instanceof AddressElement)209 selBestFit = r.translate((AddressElement) selMainObj);210 else if (selMainObj instanceof OsmPrimitive)211 selBestFit = r.translate((OsmPrimitive) selMainObj);212 213 mainTextField.setText(AddressElement.getName(selMainObj));214 bestTextField.setText(AddressElement.getName(selBestFit));215 216 if (tp.getPathCount() >= 3)217 selCandObj = tp.getPathComponent(2);218 219 candTextField.setText(AddressElement.getName(selCandObj));220 221 if (selCandObj != null) {222 if (selBestFit == null)223 bestTextField.setText(224 "žádný neexistuje, objekty v konfliktu jsou rovnocenné");225 226 candReassignButton.setEnabled(true);227 } else228 candReassignButton.setEnabled(false);229 230 mainZoomButton.setEnabled(selMainObj instanceof OsmPrimitive);231 bestZoomButton.setEnabled(selBestFit instanceof OsmPrimitive);232 candZoomButton.setEnabled(selCandObj instanceof OsmPrimitive);233 234 }//GEN-LAST:event_treeValueChanged235 236 195 private void mainZoomButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mainZoomButtonActionPerformed 237 assert selMainObj instanceof OsmPrimitive; 238 MapUtils.zoomTo((OsmPrimitive) selMainObj); 196 zoomTo(mainField.getSelectedItem()); 239 197 }//GEN-LAST:event_mainZoomButtonActionPerformed 240 198 241 private void bestZoomButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bestZoomButtonActionPerformed242 assert selBestFit instanceof OsmPrimitive;243 MapUtils.zoomTo((OsmPrimitive) selBestFit);244 }//GEN-LAST:event_bestZoomButtonActionPerformed245 246 199 private void candZoomButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_candZoomButtonActionPerformed 247 assert selCandObj instanceof OsmPrimitive; 248 MapUtils.zoomTo((OsmPrimitive) selCandObj); 200 zoomTo(candField.getSelectedItem()); 249 201 }//GEN-LAST:event_candZoomButtonActionPerformed 250 202 251 private void candReassignButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_candReassignButtonActionPerformed 252 Reasoner r = CzechAddressPlugin.getReasoner(); 253 254 if ( (selMainObj instanceof OsmPrimitive) 255 && (selCandObj instanceof AddressElement)) { 256 257 Match best = r.findMatch((AddressElement) selBestFit); 258 if (best != null) best.qualityChanged(); 259 260 List<Match> competitors = r.conflicts((OsmPrimitive) selMainObj); 261 if (competitors != null) for (Match competitor : competitors) 262 competitor.qualityChanged(); 263 264 r.overwriteMatch((AddressElement) selCandObj, (OsmPrimitive) selMainObj); 265 } 266 267 else if ((selMainObj instanceof AddressElement) 268 && (selCandObj instanceof OsmPrimitive)) { 269 270 Match best = r.findMatch((OsmPrimitive) selBestFit); 271 if (best != null) best.qualityChanged(); 272 273 List<Match> competitors = r.conflicts((AddressElement) selMainObj); 274 if (competitors != null) for (Match competitor : competitors) 275 competitor.qualityChanged(); 276 277 r.overwriteMatch((AddressElement) selMainObj, (OsmPrimitive) selCandObj); 278 } 279 203 private void zoomTo(Object item) { 204 if (item instanceof OsmPrimitive) 205 MapUtils.zoomTo((OsmPrimitive) item); 206 207 else if (item instanceof AddressElement) { 208 OsmPrimitive prim = Reasoner.getInstance().translate((AddressElement) item); 209 if (prim != null) 210 MapUtils.zoomTo(prim); 211 } 212 } 213 214 private void reassignButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_reassignButtonActionPerformed 215 216 Reasoner r = Reasoner.getInstance(); 217 218 synchronized (r) { 219 r.openTransaction(); 220 221 if (conflictModel.getSelectedItem() instanceof OsmPrimitive) { 222 OsmPrimitive prim = (OsmPrimitive) conflictModel.getSelectedItem(); 223 224 if (r.translate(prim) != null) 225 r.unOverwrite(prim, r.translate(prim)); 226 227 ComboBoxModel model = candField.getModel(); 228 for (int i = 0; i < model.getSize(); i++) { 229 AddressElement elem = (AddressElement) model.getElementAt(i); 230 r.unOverwrite(prim, elem); 231 if (r.translate(elem) != null) 232 r.unOverwrite(r.translate(elem), elem); 233 } 234 235 r.doOverwrite(prim, (AddressElement) model.getSelectedItem()); 236 } 237 238 if (conflictModel.getSelectedItem() instanceof AddressElement) { 239 AddressElement elem = (AddressElement) conflictModel.getSelectedItem(); 240 241 if (r.translate(elem) != null) 242 r.unOverwrite(r.translate(elem), elem); 243 244 ComboBoxModel model = candField.getModel(); 245 for (int i = 0; i < model.getSize(); i++) { 246 OsmPrimitive prim = (OsmPrimitive) model.getElementAt(i); 247 r.unOverwrite(prim, elem); 248 if (r.translate(prim) != null) 249 r.unOverwrite(prim, r.translate(prim)); 250 } 251 252 r.doOverwrite((OsmPrimitive) model.getSelectedItem(), elem); 253 } 254 255 r.closeTransaction(); 256 } 257 }//GEN-LAST:event_reassignButtonActionPerformed 258 259 private void mainPickButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mainPickButtonActionPerformed 260 // TODO add your handling code here: 261 }//GEN-LAST:event_mainPickButtonActionPerformed 262 263 // Variables declaration - do not modify//GEN-BEGIN:variables 264 private javax.swing.JComboBox candField; 265 private javax.swing.JLabel candLabel; 266 private javax.swing.JButton candPickButton; 267 private javax.swing.JButton candZoomButton; 268 private javax.swing.JComboBox mainField; 269 private javax.swing.JLabel mainLabel; 270 private javax.swing.JPanel mainPanel; 271 private javax.swing.JButton mainPickButton; 272 private javax.swing.JButton mainZoomButton; 273 private javax.swing.JButton reassignButton; 274 // End of variables declaration//GEN-END:variables 275 276 //============================================================================== 277 278 private class ReasonerHook implements ReasonerListener { 279 280 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); 283 284 if (Reasoner.getInstance().inConflict(elem)) 285 conflictModel.put(elem); 286 else 287 conflictModel.remove(elem); 288 } 289 290 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); 293 294 if (Reasoner.getInstance().inConflict(prim)) 295 conflictModel.put(prim); 296 else 297 conflictModel.remove(prim); 298 } 299 300 public void resonerReseted() { 301 } 302 } 303 304 //============================================================================== 305 306 private ConflictsModel conflictModel = new ConflictsModel(); 307 private class ConflictsModel implements ComboBoxModel { 308 309 ArrayList<AddressElement> elements = new ArrayList<AddressElement>(); 310 ArrayList<OsmPrimitive> primitives = new ArrayList<OsmPrimitive>(); 311 Set<ListDataListener> listeners = new HashSet<ListDataListener>(); 312 313 Object selected = null; 314 315 public void put(AddressElement elem) { 316 int index = Collections.binarySearch(elements, elem); 317 if (index < 0) { 318 logger.log(Level.FINE, "conflicts: adding element", 319 "[" + String.valueOf(-index-1) + "]=„" 320 + elem.getName() + "“"); 321 elements.add(-index-1, elem); 322 323 ListDataEvent evt = new ListDataEvent(this, 324 ListDataEvent.INTERVAL_ADDED, 325 -index-1, -index-1); 326 for (ListDataListener listener : listeners) 327 listener.intervalAdded(evt); 328 329 if (mainField.getSelectedItem() == null) 330 mainField.setSelectedIndex(-index-1); 331 } 332 } 333 334 public void put(OsmPrimitive prim) { 335 int index = Collections.binarySearch(primitives, prim, new PrimUtils()); 336 if (index < 0) { 337 logger.log(Level.FINE, "conflicts: adding primitive", 338 "[" + String.valueOf(-index-1) + "]=„" 339 + AddressElement.getName(prim) + "“"); 340 primitives.add(-index-1, prim); 341 342 ListDataEvent evt = new ListDataEvent(this, 343 ListDataEvent.INTERVAL_ADDED, 344 -index-1 + elements.size(), -index-1 + elements.size()); 345 for (ListDataListener listener : listeners) 346 listener.intervalAdded(evt); 347 348 if (mainField.getSelectedItem() == null) 349 mainField.setSelectedIndex(-index-1); 350 } 351 } 352 353 public void remove(AddressElement elem) { 354 int index = Collections.binarySearch(elements, elem); 355 //index = primitives.indexOf(elem); 356 if (index >= 0) { 357 logger.log(Level.FINE, "conflicts: removing element", 358 "[" + String.valueOf(index) + "]=„" 359 + elem.getName() + "“"); 360 elements.remove(index); 361 362 if (selected == elem) 363 setSelectedItem(null); 364 365 ListDataEvent evt = new ListDataEvent(this, 366 ListDataEvent.INTERVAL_REMOVED, 367 index, index); 368 for (ListDataListener listener : listeners) 369 listener.intervalRemoved(evt); 370 } 371 } 372 373 public void remove(OsmPrimitive prim) { 374 int index = Collections.binarySearch(primitives, prim); 375 index = primitives.indexOf(prim); 376 if (index >= 0) { 377 logger.log(Level.FINE, "conflicts: removing primitive", 378 "[" + String.valueOf(index) + "]=„" 379 + AddressElement.getName(prim) + "“"); 380 primitives.remove(index); 381 382 if (selected == prim) 383 setSelectedItem(null); 384 385 ListDataEvent evt = new ListDataEvent(this, 386 ListDataEvent.INTERVAL_REMOVED, 387 index + elements.size(), index + elements.size()); 388 for (ListDataListener listener : listeners) 389 listener.intervalRemoved(evt); 390 } 391 } 392 393 public void clear() { 394 logger.log(Level.FINE, "conflicts: clearing"); 395 396 ListDataEvent evt = new ListDataEvent(this, 397 ListDataEvent.CONTENTS_CHANGED, 398 0, elements.size() + primitives.size() - 1); 399 400 elements.clear(); 401 primitives.clear(); 402 403 for (ListDataListener listener : listeners) 404 listener.contentsChanged(evt); 405 } 406 407 public void setSelectedItem(Object anItem) { 408 409 if (anItem == null && getSize() > 0) { 410 mainField.setSelectedIndex(0); 411 return; 412 } 413 selected = anItem; 414 updateZoomButtons(selected, mainZoomButton); 415 updatePickButtons(selected, mainPickButton); 416 updateCandidatesModel(anItem); 417 } 418 419 public Object getSelectedItem() { 420 return selected; 421 } 422 423 public int getSize() { 424 return primitives.size() + elements.size(); 425 } 426 427 public Object getElementAt(int index) { 428 if (index< elements.size()) 429 return elements.get(index); 430 431 index -= elements.size(); 432 433 if (index< primitives.size()) 434 return primitives.get(index); 435 436 return null; 437 } 438 439 public void addListDataListener(ListDataListener l) { 440 listeners.add(l); 441 } 442 443 public void removeListDataListener(ListDataListener l) { 444 listeners.remove(l); 445 } 446 } 447 448 private void updateCandidatesModel(Object selected) { 449 450 if (selected instanceof AddressElement) { 451 AddressElement selElem = (AddressElement) selected; 452 List<OsmPrimitive> conflPrims = new NotNullList<OsmPrimitive>(); 453 conflPrims.addAll(Reasoner.getInstance().getCandidates(selElem)); 454 Collections.sort(conflPrims, new PrimUtils()); 455 candField.setModel(new CandidatesModel<OsmPrimitive>(conflPrims)); 456 457 } else if (selected instanceof OsmPrimitive) { 458 OsmPrimitive selElem = (OsmPrimitive) selected; 459 List<AddressElement> conflElems = new NotNullList<AddressElement>(); 460 conflElems.addAll(Reasoner.getInstance().getCandidates(selElem)); 461 Collections.sort(conflElems); 462 candField.setModel(new CandidatesModel<AddressElement>(conflElems)); 463 464 } else { 465 candField.setModel(new DefaultComboBoxModel()); 466 candZoomButton.setEnabled(false); 467 reassignButton.setEnabled(false); 468 } 469 470 candZoomButton.setEnabled(false); 471 candPickButton.setEnabled(false); 472 reassignButton.setEnabled(false); 473 if (candField.getModel().getSize() > 0) 474 candField.setSelectedIndex(0); 280 475 else 281 assert false; 282 }//GEN-LAST:event_candReassignButtonActionPerformed 283 284 // Variables declaration - do not modify//GEN-BEGIN:variables 285 private javax.swing.JTextField bestTextField; 286 private javax.swing.JButton bestZoomButton; 287 private javax.swing.JButton candReassignButton; 288 private javax.swing.JTextField candTextField; 289 private javax.swing.JButton candZoomButton; 290 private javax.swing.JTree elemConflictTree; 291 private javax.swing.JLabel jLabel4; 292 private javax.swing.JLabel jLabel5; 293 private javax.swing.JLabel jLabel6; 294 private javax.swing.JScrollPane jScrollPane1; 295 private javax.swing.JScrollPane jScrollPane2; 296 private javax.swing.JTabbedPane jTabbedPane1; 297 private javax.swing.JPanel mainPanel; 298 private javax.swing.JTextField mainTextField; 299 private javax.swing.JButton mainZoomButton; 300 private javax.swing.JTree primConflictTree; 301 // End of variables declaration//GEN-END:variables 302 303 public void pluginStatusChanged(int message) { 304 305 if (message == MESSAGE_CONFLICT_CHANGED) { 306 setVisible(true); 307 308 ((HalfCookedTreeModel) elemConflictTree.getModel()).notifyAllListeners(); 309 ((HalfCookedTreeModel) primConflictTree.getModel()).notifyAllListeners(); 310 311 /* TODO: For some reason the previous call does not repaint. 312 * Lines below fix it for now.*/ 313 elemConflictTree.setModel(new ElemTreeModel()); 314 primConflictTree.setModel(new PrimTreeModel()); 315 } 316 } 317 318 319 //============================================================================== 320 476 candField.setSelectedIndex(-1); 477 } 478 479 private void updateZoomButtons(Object selected, JButton button) { 480 if (selected instanceof OsmPrimitive) { 481 button.setEnabled(true); 482 } else if (selected instanceof AddressElement) { 483 button.setEnabled(Reasoner.getInstance().translate( 484 (AddressElement) selected) != null); 485 } else { 486 button.setEnabled(false); 487 } 488 } 489 490 private void updatePickButtons(Object selected, JButton button) { 491 button.setEnabled(selected instanceof House || selected instanceof Street); 492 } 493 494 private class CandidatesModel<E> implements ComboBoxModel { 495 496 Set<ListDataListener> listeners = new HashSet<ListDataListener>(); 497 List<? extends E> primitives; 498 Object selected = null; 499 500 public CandidatesModel(List<? extends E> data) { 501 primitives = data; 502 } 503 504 public void setSelectedItem(Object anItem) { 505 selected = anItem; 506 updateZoomButtons(selected, candZoomButton); 507 updatePickButtons(selected, candPickButton); 508 509 if (conflictModel.getSelectedItem() instanceof AddressElement) { 510 reassignButton.setEnabled( selected != 511 Reasoner.getInstance().getStrictlyBest( 512 (AddressElement) conflictModel.getSelectedItem())); 513 514 reassignButton.setEnabled(true); 515 } else if (conflictModel.getSelectedItem() instanceof OsmPrimitive) { 516 reassignButton.setEnabled( selected != 517 Reasoner.getInstance().getStrictlyBest( 518 (OsmPrimitive) conflictModel.getSelectedItem())); 519 reassignButton.setEnabled(true); 520 } else 521 reassignButton.setEnabled(false); 522 523 524 } 525 526 public Object getSelectedItem() { 527 return selected; 528 } 529 530 public int getSize() { 531 return primitives.size(); 532 } 533 534 public Object getElementAt(int index) { 535 if (index < primitives.size()) 536 return primitives.get(index); 537 return null; 538 } 539 540 public void addListDataListener(ListDataListener l) { 541 listeners.add(l); 542 } 543 544 public void removeListDataListener(ListDataListener l) { 545 listeners.remove(l); 546 } 547 } 548 549 private class CandidatesRenderer extends UniversalListRenderer { 550 551 @Override 552 public Component getListCellRendererComponent(JList list, Object value, 553 int index, boolean isSelected, boolean cellHasFocus) { 554 Component c = super.getListCellRendererComponent(list, value, index, 555 isSelected, cellHasFocus); 556 557 if ( (value instanceof AddressElement && 558 Reasoner.getInstance().translate((AddressElement) value) != null) 559 || (value instanceof OsmPrimitive && 560 Reasoner.getInstance().translate((OsmPrimitive) value) != null) ) 561 setFont(getFont().deriveFont(Font.BOLD)); 562 563 return c; 564 } 565 } 566 567 /* 321 568 private class ElemTreeModel extends HalfCookedTreeModel { 322 569 … … 333 580 334 581 if (parent instanceof AddressElement) 335 return r. conflicts((AddressElement) parent).get(index).prim;582 return r.getConflicts((AddressElement) parent).get(index).prim; 336 583 337 584 } catch (Exception e) { } … … 347 594 348 595 if (parent instanceof AddressElement) 349 return r. conflicts((AddressElement) parent).size();596 return r.getConflicts((AddressElement) parent).size(); 350 597 351 598 } catch (Exception exp) { } … … 361 608 362 609 if (parent instanceof AddressElement) 363 return r. conflicts((AddressElement) parent).indexOf(child);610 return r.getConflicts((AddressElement) parent).indexOf(child); 364 611 365 612 } catch (Exception exp) { } … … 417 664 return -1; 418 665 } 419 } 666 }*/ 420 667 } -
applications/editors/josm/plugins/czechaddress/src/org/openstreetmap/josm/plugins/czechaddress/gui/FactoryDialog.form
r15461 r15558 25 25 <DimensionLayout dim="0"> 26 26 <Group type="103" groupAlignment="0" attributes="0"> 27 <Group type="102" a ttributes="0">28 <Component id="streetComboBox" pref=" 92" max="32767" attributes="0"/>27 <Group type="102" alignment="1" attributes="0"> 28 <Component id="streetComboBox" pref="199" max="32767" attributes="0"/> 29 29 <EmptySpace max="-2" attributes="0"/> 30 30 <Component id="relocateButton" min="-2" max="-2" attributes="0"/> 31 <EmptySpace max="-2" attributes="0"/>32 <Component id="ensureConsistencyButton" min="-2" max="-2" attributes="0"/>33 31 </Group> 34 32 <Group type="102" alignment="0" attributes="0"> … … 45 43 <Component id="streetComboBox" alignment="3" min="-2" max="-2" attributes="0"/> 46 44 <Component id="relocateButton" alignment="3" min="-2" max="-2" attributes="0"/> 47 <Component id="ensureConsistencyButton" alignment="3" min="-2" max="-2" attributes="0"/>48 45 </Group> 49 46 <EmptySpace max="-2" attributes="0"/> … … 105 102 </Properties> 106 103 </Component> 107 <Component class="javax.swing.JButton" name="ensureConsistencyButton">108 <Properties>109 <Property name="icon" type="javax.swing.Icon" editor="org.netbeans.modules.form.RADConnectionPropertyEditor">110 <Connection code="ImageProvider.get("actions", "refresh-small.png")" type="code"/>111 </Property>112 <Property name="text" type="java.lang.String" editor="org.netbeans.modules.form.RADConnectionPropertyEditor">113 <Connection code="""" type="code"/>114 </Property>115 <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."/>116 <Property name="enabled" type="boolean" value="false"/>117 </Properties>118 <Events>119 <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="ensureConsistencyButtonActionPerformed"/>120 </Events>121 </Component>122 104 </SubComponents> 123 105 </Container> -
applications/editors/josm/plugins/czechaddress/src/org/openstreetmap/josm/plugins/czechaddress/gui/FactoryDialog.java
r15461 r15558 9 9 import java.util.ArrayList; 10 10 import java.util.Collection; 11 import java.util.Collections; 11 12 import java.util.List; 12 13 import javax.swing.DefaultListCellRenderer; … … 26 27 import org.openstreetmap.josm.plugins.czechaddress.addressdatabase.Street; 27 28 import org.openstreetmap.josm.plugins.czechaddress.intelligence.Reasoner; 29 import org.openstreetmap.josm.plugins.czechaddress.intelligence.ReasonerListener; 28 30 import org.openstreetmap.josm.tools.ImageProvider; 29 31 import org.openstreetmap.josm.tools.Shortcut; … … 35 37 */ 36 38 public class FactoryDialog extends ToggleDialog 37 implements SelectionChangedListener, StatusListener { 38 39 HouseListModel houseModel = new HouseListModel(); 40 StreetListModel streetModel = new StreetListModel(); 39 implements SelectionChangedListener, StatusListener, ReasonerListener { 40 41 42 private static FactoryDialog singleton = null; 43 public static FactoryDialog getInstance() { 44 if (singleton == null) 45 singleton = new FactoryDialog(); 46 return singleton; 47 } 48 49 private HouseListModel houseModel = new HouseListModel(); 50 private StreetListModel streetModel = new StreetListModel(); 41 51 42 p ublicFactoryDialog() {52 private FactoryDialog() { 43 53 44 54 super( "Továrna na adresy", … … 88 98 } 89 99 90 100 /* if (message == MESSAGE_REASONER_REASONED) { 91 101 ensureConsistencyButton.setEnabled(true); 92 102 } … … 95 105 houseModel.notifyAllListeners(); 96 106 return; 97 } 107 }*/ 98 108 } 99 109 … … 106 116 107 117 public boolean existsAvailableHouse() { 108 Reasoner r = CzechAddressPlugin.reasoner;118 Reasoner r = Reasoner.getInstance(); 109 119 110 120 int i = houseList.getSelectedIndex(); … … 126 136 127 137 public void selectNextUnmatchedHouse() { 128 129 138 int index = houseList.getSelectedIndex(); 130 139 … … 132 141 Object current; 133 142 while ( (current = houseModel.getElementAt(index)) != null 134 && CzechAddressPlugin.reasoner.translate((House) current) != null)143 && Reasoner.getInstance().translate((House) current) != null) 135 144 index++; 136 145 … … 225 234 */ 226 235 @SuppressWarnings("unchecked") 227 // <editor-fold defaultstate="collapsed" desc=" Generated Code">//GEN-BEGIN:initComponents236 // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents 228 237 private void initComponents() { 238 229 239 mainPanel = new javax.swing.JPanel(); 230 240 jScrollPane1 = new javax.swing.JScrollPane(); … … 233 243 relocateButton = new javax.swing.JButton(); 234 244 streetComboBox = new javax.swing.JComboBox(); 235 ensureConsistencyButton = new javax.swing.JButton();236 245 237 246 setLayout(new java.awt.GridLayout(1, 0)); … … 250 259 } 251 260 }); 252 253 261 jScrollPane1.setViewportView(houseList); 254 262 255 263 keepOddityCheckBox.setSelected(true); 256 keepOddityCheckBox.setText("Zachov \u00e1vat sudost / lichost");264 keepOddityCheckBox.setText("Zachovávat sudost / lichost"); 257 265 keepOddityCheckBox.setEnabled(false); 258 266 … … 269 277 streetComboBox.setFocusable(false); 270 278 271 ensureConsistencyButton.setIcon(ImageProvider.get("actions", "refresh-small.png"));272 ensureConsistencyButton.setText("");273 ensureConsistencyButton.setToolTipText("Provede nov\u00e9 p\u0159i\u0159azen\u00ed prvk\u016f mapy na elementy datab\u00e1ze.\nTouto volbou se zru\u0161\u00ed v\u0161echny manu\u00e1ln\u011b vy\u0159e\u0161en\u00e9 konflikty.");274 ensureConsistencyButton.setEnabled(false);275 ensureConsistencyButton.addActionListener(new java.awt.event.ActionListener() {276 public void actionPerformed(java.awt.event.ActionEvent evt) {277 ensureConsistencyButtonActionPerformed(evt);278 }279 });280 281 279 javax.swing.GroupLayout mainPanelLayout = new javax.swing.GroupLayout(mainPanel); 282 280 mainPanel.setLayout(mainPanelLayout); 283 281 mainPanelLayout.setHorizontalGroup( 284 282 mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 283 .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, mainPanelLayout.createSequentialGroup() 284 .addComponent(streetComboBox, 0, 199, Short.MAX_VALUE) 285 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) 286 .addComponent(relocateButton)) 285 287 .addGroup(mainPanelLayout.createSequentialGroup() 286 .addComponent(streetComboBox, 0, 50, Short.MAX_VALUE) 287 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) 288 .addComponent(relocateButton) 289 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) 290 .addComponent(ensureConsistencyButton)) 291 .addGroup(mainPanelLayout.createSequentialGroup() 292 .addComponent(keepOddityCheckBox, javax.swing.GroupLayout.DEFAULT_SIZE, 282, Short.MAX_VALUE) 288 .addComponent(keepOddityCheckBox, javax.swing.GroupLayout.DEFAULT_SIZE, 278, Short.MAX_VALUE) 293 289 .addContainerGap()) 294 290 .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 290, Short.MAX_VALUE) … … 299 295 .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) 300 296 .addComponent(streetComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) 301 .addComponent(relocateButton) 302 .addComponent(ensureConsistencyButton)) 297 .addComponent(relocateButton)) 303 298 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) 304 299 .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 125, Short.MAX_VALUE) … … 306 301 .addComponent(keepOddityCheckBox)) 307 302 ); 303 308 304 add(mainPanel); 309 310 305 }// </editor-fold>//GEN-END:initComponents 311 306 … … 316 311 private void houseListClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_houseListClicked 317 312 if (evt.getClickCount() == 2 && evt.getButton() == MouseEvent.BUTTON1) { 318 Reasoner r = CzechAddressPlugin.reasoner;313 Reasoner r = Reasoner.getInstance(); 319 314 320 315 if (r.translate(getSelectedHouse()) != null) { … … 324 319 325 320 // TODO: The following code does not work... for some reason. 326 /*List<Match> conflicts = r.getConflictsForElement(getSelectegetConflicts if (conflicts != null) {321 /* List<Match> getConflicts = r.getConflictsForElement(getSelectegetConflicts if (getConflicts != null) { 327 322 List<OsmPrimitive> toZoom 328 = new ArrayList<OsmPrimitive>( conflicts.size());329 for (Match conflict : conflicts)323 = new ArrayList<OsmPrimitive>(getConflicts.size()); 324 for (Match conflict : getConflicts) 330 325 toZoom.add(conflict.prim); 331 326 332 327 MapUtils.zoomToMany(toZoom); 333 328 return; 334 }*/329 */ 335 330 } 336 331 }//GEN-LAST:event_houseListClicked 337 332 338 private void ensureConsistencyButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ensureConsistencyButtonActionPerformed339 CzechAddressPlugin.reasoner.ensureConsistency();340 }//GEN-LAST:event_ensureConsistencyButtonActionPerformed341 342 333 343 334 // Variables declaration - do not modify//GEN-BEGIN:variables 344 private javax.swing.JButton ensureConsistencyButton;345 335 private javax.swing.JList houseList; 346 336 private javax.swing.JScrollPane jScrollPane1; … … 351 341 // End of variables declaration//GEN-END:variables 352 342 343 public void elementChanged(AddressElement elem) { 344 houseModel.notifyAllListeners(); 345 } 346 347 public void primitiveChanged(OsmPrimitive prim) {} 348 349 public void resonerReseted() { 350 throw new UnsupportedOperationException("Not supported yet."); 351 } 352 353 353 private class StreetListRenderer extends DefaultListCellRenderer { 354 354 … … 367 367 setText(((Street) value).getName()); 368 368 369 } else {369 } else if (value instanceof ElementWithHouses) { 370 370 setFont(boldFont); 371 if (value instanceof ElementWithStreets) setText("[domy bez ulice]"); 372 if (value instanceof AllStreetProvider) setText("[všechny domy]"); 373 if (value instanceof FreeStreetProvider) setText("[nepřiřazené domy]"); 374 371 setText("[" + ((ElementWithHouses) value).getName() + "]"); 375 372 } 376 373 … … 395 392 if (boldFont == null) boldFont = getFont().deriveFont(Font.BOLD); 396 393 397 Reasoner r = CzechAddressPlugin.reasoner;394 Reasoner r = Reasoner.getInstance(); 398 395 399 396 if (value instanceof House) { … … 403 400 setFont(plainFont); 404 401 405 if ( r.conflicts(house) != null)402 if (r.inConflict(house)) 406 403 setIcon(envelopeExclIcon); 407 else if ( r.translate(house) == null) { 404 405 else if (r.translate(house) == null) { 408 406 setIcon(envelopeStarIcon); 409 407 setFont(boldFont); … … 418 416 private class AllStreetProvider extends ElementWithHouses { 419 417 public AllStreetProvider() { 420 super(" Všechny domy");418 super("všechny domy"); 421 419 } 422 420 … … 428 426 429 427 private class FreeStreetProvider extends ElementWithHouses 430 implements StatusListener {428 implements ReasonerListener { 431 429 432 430 public FreeStreetProvider() { 433 super(" Nepřiřazené domy");434 CzechAddressPlugin.addStatusListener(this);431 super("nepřiřazené domy"); 432 Reasoner.getInstance().addListener(this); 435 433 rebuild(); 436 434 } … … 441 439 } 442 440 443 public void pluginStatusChanged(int message) {444 if (message == StatusListener.MESSAGE_MATCHES_CHANGED)445 rebuild();446 }447 441 448 442 public void rebuild() { 449 Reasoner r = CzechAddressPlugin.reasoner;450 if (r == null) return;451 452 443 houses.clear(); 453 for (AddressElement house : r.getElementPool()) 454 if (r.translate(house) == null) 455 if (house instanceof House) 456 houses.add((House) house); 457 } 444 for (AddressElement house : Reasoner.getInstance().getUnassignedElements()) 445 if (house instanceof House) 446 houses.add((House) house); 447 448 Collections.sort(houses); 449 } 450 451 public void resonerReseted() { houses.clear(); } 452 public void primitiveChanged(OsmPrimitive prim) {} 453 public void elementChanged(AddressElement elem) { 454 if (!(elem instanceof House)) 455 return; 456 House house = (House) elem; 457 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 458 467 } 459 468 … … 532 541 = (ElementWithHouses) streetComboBox.getSelectedItem(); 533 542 534 if ((index < 0) || (index >= selected.getHouses().size())) return null; 543 if ((index < 0) || (index >= selected.getHouses().size())) 544 return null; 535 545 return selected.getHouses().get(index); 536 546 } … … 540 550 } 541 551 } 542 543 552 } -
applications/editors/josm/plugins/czechaddress/src/org/openstreetmap/josm/plugins/czechaddress/gui/GroupManipulatorDialog.java
r15166 r15558 67 67 68 68 public void pluginStatusChanged(int message) { 69 if (message == StatusListener.MESSAGE_MATCHES_CHANGED) {69 /*if (message == StatusListener.MESSAGE_MATCHES_CHANGED) { 70 70 int retval = (new ExtendedDialog(Main.parent, "Změna umístění", 71 71 "Došlo ke změně v přiřazení databáze.\n" + … … 76 76 if (retval == 1) 77 77 recreateProposals(); 78 } 78 }*/ 79 79 } 80 80 … … 93 93 94 94 public void recreateProposals() { 95 locationTextField.setText(CzechAddressPlugin.getLocation().toString());95 /* locationTextField.setText(CzechAddressPlugin.getLocation().toString()); 96 96 97 97 Reasoner r = CzechAddressPlugin.getReasoner(); 98 proposalTree.setModel(r.getProposals()); 98 proposalTree.setModel(r.getProposals());*/ 99 99 } 100 100 -
applications/editors/josm/plugins/czechaddress/src/org/openstreetmap/josm/plugins/czechaddress/gui/LocationSelector.java
r15166 r15558 24 24 import org.openstreetmap.josm.data.osm.visitor.BoundingXYVisitor; 25 25 import org.openstreetmap.josm.gui.ExtendedDialog; 26 import org.openstreetmap.josm.plugins.czechaddress.addressdatabase.Database; 26 27 27 28 /** … … 58 59 59 60 oblastComboBox.setModel(new DefaultComboBoxModel( 60 CzechAddressPlugin.getDatabase().regions.toArray()));61 Database.getInstance().regions.toArray())); 61 62 62 63 autodetectLocation(); … … 140 141 + "\t " + bestFit.get("name")); 141 142 142 for (Region oblast : CzechAddressPlugin.getDatabase().regions) {143 for (Region oblast : Database.getInstance().regions) { 143 144 for (ViToCi obec : oblast.getViToCis()) { 144 145 if (!bestFit.get("place").equals("suburb")) { -
applications/editors/josm/plugins/czechaddress/src/org/openstreetmap/josm/plugins/czechaddress/gui/PointManipulatorDialog.form
r15166 r15558 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 <NonVisualComponents> 5 5 <Component class="javax.swing.JLabel" name="jLabel4"> … … 44 44 <Group type="103" groupAlignment="0" attributes="0"> 45 45 <Group type="102" alignment="1" attributes="0"> 46 <Component id="locationEdit" pref="2 15" max="32767" attributes="0"/>46 <Component id="locationEdit" pref="228" max="32767" attributes="0"/> 47 47 <EmptySpace max="-2" attributes="0"/> 48 48 <Component id="changeLocationButton" min="-2" max="-2" attributes="0"/> 49 49 </Group> 50 <Component id="alternateNumberEdit" alignment="0" pref="29 9" max="32767" attributes="0"/>50 <Component id="alternateNumberEdit" alignment="0" pref="293" max="32767" attributes="0"/> 51 51 <Group type="102" alignment="1" attributes="0"> 52 <Component id="matchesComboBox" pref="1 74" max="32767" attributes="0"/>52 <Component id="matchesComboBox" pref="186" max="32767" attributes="0"/> 53 53 <EmptySpace max="-2" attributes="0"/> 54 54 <Component id="ensureConsistencyButton" min="-2" max="-2" attributes="0"/> … … 78 78 <Component id="ensureConsistencyButton" alignment="3" min="-2" max="-2" attributes="0"/> 79 79 </Group> 80 <EmptySpace pref="1 86" max="32767" attributes="0"/>80 <EmptySpace pref="176" max="32767" attributes="0"/> 81 81 </Group> 82 82 <Group type="102" alignment="0" attributes="0"> -
applications/editors/josm/plugins/czechaddress/src/org/openstreetmap/josm/plugins/czechaddress/gui/PointManipulatorDialog.java
r15461 r15558 91 91 protected void buttonAction(ActionEvent evt) { 92 92 super.buttonAction(evt); 93 if (getValue() == 1) {93 /* if (getValue() == 1) { 94 94 95 95 if (updateMatchesTimer.isRunning()) { … … 108 108 r.overwriteMatch(m.elem, m.prim); 109 109 } 110 } 110 }*/ 111 111 112 112 CzechAddressPlugin.removeStatusListener(this); … … 125 125 public void updateMatches() { 126 126 127 if (proposalContainer.getTarget().deleted) {127 /* if (proposalContainer.getTarget().deleted) { 128 128 setVisible(false); 129 129 } … … 156 156 fakeHouse.setParent(CzechAddressPlugin.getLocation()); 157 157 proposalContainer.setProposals( 158 fakeHouse.getDiff(proposalContainer.getTarget())); 158 fakeHouse.getDiff(proposalContainer.getTarget()));*/ 159 159 } 160 160 … … 162 162 163 163 // If location changes, we block the dialog until reasoning is done. 164 if (message == MESSAGE_LOCATION_CHANGED) {164 /* if (message == MESSAGE_LOCATION_CHANGED) { 165 165 updateLocation(); 166 166 mainPanel.setEnabled(false); … … 170 170 updateMatches(); 171 171 mainPanel.setEnabled(true); 172 } 172 }*/ 173 173 } 174 174 … … 326 326 327 327 private void ensureConsistencyButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ensureConsistencyButtonActionPerformed 328 CzechAddressPlugin.getReasoner().ensureConsistency();328 // CzechAddressPlugin.getReasoner().ensureConsistency(); 329 329 }//GEN-LAST:event_ensureConsistencyButtonActionPerformed 330 330 … … 358 358 Component c = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); 359 359 360 Reasoner r = CzechAddressPlugin.getReasoner();360 /* Reasoner r = CzechAddressPlugin.getReasoner(); 361 361 setIcon(null); 362 362 … … 373 373 setIcon(envelopeNormIcon); 374 374 } 375 } 375 }*/ 376 376 377 377 return c; -
applications/editors/josm/plugins/czechaddress/src/org/openstreetmap/josm/plugins/czechaddress/gui/UniversalTreeRenderer.java
r15461 r15558 2 2 3 3 import java.awt.Component; 4 import javax.swing.ImageIcon;5 4 import javax.swing.JTree; 6 5 import javax.swing.tree.DefaultTreeCellRenderer; 7 import org.openstreetmap.josm.data.osm.Node;8 6 import org.openstreetmap.josm.data.osm.OsmPrimitive; 9 import org.openstreetmap.josm.data.osm.Relation;10 import org.openstreetmap.josm.data.osm.Way;11 import org.openstreetmap.josm.plugins.czechaddress.CzechAddressPlugin;12 7 import org.openstreetmap.josm.plugins.czechaddress.addressdatabase.AddressElement; 13 import org.openstreetmap.josm.plugins.czechaddress.addressdatabase.House; 14 import org.openstreetmap.josm.plugins.czechaddress.intelligence.Reasoner; 15 import org.openstreetmap.josm.plugins.czechaddress.proposal.AddKeyValueProposal; 16 import org.openstreetmap.josm.plugins.czechaddress.proposal.KeyValueChangeProposal; 17 import org.openstreetmap.josm.plugins.czechaddress.proposal.ProposalContainer; 18 import org.openstreetmap.josm.plugins.czechaddress.proposal.RemoveKeyProposal; 19 import org.openstreetmap.josm.tools.ImageProvider; 8 import org.openstreetmap.josm.plugins.czechaddress.gui.utils.UniversalRenderer; 20 9 21 10 /** … … 26 15 */ 27 16 public class UniversalTreeRenderer extends DefaultTreeCellRenderer { 28 static ImageIcon iconAdd = ImageProvider.get("actions", "add.png");29 static ImageIcon iconEdit = ImageProvider.get("actions", "edit.png");30 static ImageIcon iconRemove = ImageProvider.get("actions", "remove.png");31 32 static ImageIcon nodeIcon = ImageProvider.get("Mf_node.png");33 static ImageIcon wayIcon = ImageProvider.get("Mf_way.png");34 static ImageIcon closedWayIcon = ImageProvider.get("Mf_closedway.png");35 static ImageIcon relationIcon = ImageProvider.get("Mf_relation.png");36 37 static ImageIcon envelopeNormIcon = ImageProvider.get("envelope-closed-small.png");38 static ImageIcon envelopeStarIcon = ImageProvider.get("envelope-closed-star-small.png");39 static ImageIcon envelopeExclIcon = ImageProvider.get("envelope-closed-exclamation-small.png");40 17 41 18 @Override … … 47 24 expanded, leaf, row, hasFocus); 48 25 49 /*if (plainFont == null) plainFont = getFont().deriveFont(Font.PLAIN); 50 if ( boldFont == null) boldFont = getFont().deriveFont(Font.BOLD);*/ 51 Reasoner r = CzechAddressPlugin.getReasoner(); 26 setIcon(UniversalRenderer.getIcon(value)); 27 setText(UniversalRenderer.getText(value)); 52 28 53 54 if (value instanceof ProposalContainer) {55 value = ((ProposalContainer) value).getTarget();56 }57 58 if ((value instanceof AddressElement) || (value instanceof OsmPrimitive)) {59 setText(AddressElement.getName(value));60 }61 62 if (value instanceof AddKeyValueProposal) setIcon(iconAdd);63 else if (value instanceof KeyValueChangeProposal) setIcon(iconEdit);64 else if (value instanceof RemoveKeyProposal) setIcon(iconRemove);65 66 67 if (value instanceof House && r != null) {68 House house = (House) value;69 70 setIcon(envelopeNormIcon);71 if ( r.conflicts(house) != null )72 setIcon(envelopeExclIcon);73 else if ( r.translate(house) == null)74 setIcon(envelopeStarIcon);75 76 } else if (value instanceof Node) {77 setIcon(nodeIcon);78 } else if (value instanceof Relation) {79 setIcon(relationIcon);80 } else if (value instanceof Way) {81 if (((Way) value).isClosed()) {82 setIcon(closedWayIcon);83 } else {84 setIcon(wayIcon);85 }86 }87 88 29 return c; 89 30 } -
applications/editors/josm/plugins/czechaddress/src/org/openstreetmap/josm/plugins/czechaddress/intelligence/Capitalizator.java
r15201 r15558 1 1 package org.openstreetmap.josm.plugins.czechaddress.intelligence; 2 2 3 import java.util.ArrayList;4 3 import java.util.HashMap; 5 4 import java.util.List; … … 13 12 import java.util.logging.Level; 14 13 import java.util.logging.Logger; 15 import javax.swing.event.TableModelListener;16 import javax.swing.table.TableModel;17 14 import org.openstreetmap.josm.data.osm.OsmPrimitive; 18 import org.openstreetmap.josm.plugins.czechaddress.NotNullList;19 15 import org.openstreetmap.josm.plugins.czechaddress.StringUtils; 20 16 import org.openstreetmap.josm.plugins.czechaddress.addressdatabase.AddressElement; … … 63 59 private AddressElement elem; 64 60 private List<OsmPrimitive> prims; 65 private StringUtils strUtils = new StringUtils();66 61 67 62 public StreetMatcher(AddressElement elem, List<OsmPrimitive> prims) { … … 81 76 return prim; 82 77 83 if ( strUtils.matchAbbrev(prim.get("name"), elem.getName()))78 if (StringUtils.matchAbbrev(prim.get("name"), elem.getName())) 84 79 candidate = prim; 85 80 } -
applications/editors/josm/plugins/czechaddress/src/org/openstreetmap/josm/plugins/czechaddress/intelligence/Reasoner.java
r15461 r15558 5 5 import java.util.Map; 6 6 import java.util.Set; 7 import java.util.logging.FileHandler;8 import java.util.logging.Handler;9 7 import java.util.logging.Level; 10 8 import java.util.logging.Logger; 9 import javax.crypto.Mac; 11 10 import org.openstreetmap.josm.data.osm.Node; 12 11 import org.openstreetmap.josm.data.osm.OsmPrimitive; … … 35 34 public class Reasoner { 36 35 37 /* A list of {@link OsmPrimitive}s, for which there was no suitable match. */ 38 //private List<OsmPrimitive> notMatchable = new ArrayList<OsmPrimitive>(); 36 /* A list of {@link OsmPrimitive}s, for which there was no suitable match.*/ 39 37 40 38 private Map<OsmPrimitive, AddressElement> primBestIndex … … 50 48 private Set<OsmPrimitive> primToUpdate = new HashSet<OsmPrimitive>(); 51 49 private Set<AddressElement> elemToUpdate = new HashSet<AddressElement>(); 52 // private Map<Object,Integer> statusBefore = new HashMap<Object,Integer>(); 53 54 public Logger logger = Logger.getLogger("Reasoner"); 55 56 public static final int STATUS_UNKNOWN = 0; 57 public static final int STATUS_CONFLICT = 1; 58 public static final int STATUS_MATCH = 2; 50 51 public static Logger logger = Logger.getLogger(Reasoner.class.getName()); 59 52 60 53 private Reasoner() {} … … 74 67 primBestIndex.clear(); 75 68 primBestIndex.clear(); 76 } 77 78 private AddressElement getBest(OsmPrimitive prim) { 69 70 for (ReasonerListener listener : listeners) 71 listener.resonerReseted(); 72 } 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) { 79 113 80 114 Map<AddressElement, Integer> matches = primMatchIndex.get(prim); 81 if (matches == null) return null;115 //if (matches == null) return null; 82 116 83 117 AddressElement bestE = null; … … 97 131 } 98 132 99 p rivate OsmPrimitive getBest(AddressElement prim) {133 public OsmPrimitive getStrictlyBest(AddressElement prim) { 100 134 101 135 Map<OsmPrimitive, Integer> matches = elemMatchIndex.get(prim); 102 if (matches == null) return null;136 //if (matches == null) return null; 103 137 104 138 OsmPrimitive bestE = null; … … 125 159 public void closeTransaction() { 126 160 127 Set<Object> changes = new HashSet<Object>(); 161 Set<AddressElement> elemChanges = new HashSet<AddressElement>(); 162 Set<OsmPrimitive> primChanges = new HashSet<OsmPrimitive>(); 128 163 129 164 for (OsmPrimitive prim : primToUpdate) { 130 AddressElement bestMatch = get Best(prim);165 AddressElement bestMatch = getStrictlyBest(prim); 131 166 132 167 if (primBestIndex.get(prim) != bestMatch) { 133 168 if (bestMatch == null) { 134 logger.log(Level. INFO, "primitive has no longer best match",169 logger.log(Level.FINE, "primitive has no longer best match", 135 170 AddressElement.getName(prim)); 136 171 primBestIndex.remove(prim); 137 172 } else { 138 logger.log(Level. INFO, "primitive has a new best match",173 logger.log(Level.FINE, "primitive has a new best match", 139 174 "prim=„" + AddressElement.getName(prim) + "“ → " + 140 175 "elem=„" + bestMatch + "“"); 176 elemChanges.add(primBestIndex.get(prim)); 141 177 primBestIndex.put(prim, bestMatch); 142 178 } 143 changes.add(prim);144 179 } 145 180 } 146 primToUpdate.clear();147 181 148 182 149 183 for (AddressElement elem : elemToUpdate) { 150 OsmPrimitive bestMatch = get Best(elem);184 OsmPrimitive bestMatch = getStrictlyBest(elem); 151 185 152 186 if (elemBestIndex.get(elem) != bestMatch) { 153 187 if (bestMatch == null) { 154 logger.log(Level. INFO, "element has no longer best match", elem);188 logger.log(Level.FINE, "element has no longer best match", elem); 155 189 elemBestIndex.remove(elem); 156 190 } else { 157 logger.log(Level. INFO, "element has a new best match",191 logger.log(Level.FINE, "element has a new best match", 158 192 "elem=„" + elem + "“ → " + 159 193 "prim=„" + AddressElement.getName(bestMatch) + "“"); 194 primChanges.add(elemBestIndex.get(elem)); 160 195 elemBestIndex.put(elem, bestMatch); 161 196 } 162 changes.add(elem);163 197 } 164 198 } 199 200 elemToUpdate.addAll(elemChanges); 201 primToUpdate.addAll(primChanges); 202 203 for (ReasonerListener listener : listeners) { 204 for (AddressElement elem : elemToUpdate) 205 if (elem != null) 206 listener.elementChanged(elem); 207 208 for (OsmPrimitive prim : primToUpdate) 209 if (prim != null) 210 listener.primitiveChanged(prim); 211 } 212 213 primToUpdate.clear(); 165 214 elemToUpdate.clear(); 166 167 for (Object change : changes) {168 if (change instanceof OsmPrimitive)169 for (ReasonerListener listener : listeners)170 listener.primitiveChanged((OsmPrimitive) change);171 172 if (change instanceof AddressElement)173 for (ReasonerListener listener : listeners)174 listener.elementChanged((AddressElement) change);175 }176 215 } 177 216 … … 184 223 185 224 if (oldQ != newQ) { 186 logger.log(Level. INFO, "reconsidering match",225 logger.log(Level.FINE, "reconsidering match", 187 226 "q=" + String.valueOf(oldQ) + "→" + String.valueOf(newQ) + "; " + 188 227 "elem=„" + elem + "“; " + … … 192 231 primToUpdate.add(prim); 193 232 elemToUpdate.add(elem); 233 234 primToUpdate.addAll(elemMatchIndex.get(elem).keySet()); 235 elemToUpdate.addAll(primMatchIndex.get(prim).keySet()); 194 236 } 195 237 } 196 238 197 239 public void consider(OsmPrimitive prim) { 198 logger.log(Level.FINE , "considering primitive", AddressElement.getName(prim));240 logger.log(Level.FINER, "considering primitive", AddressElement.getName(prim)); 199 241 200 242 Map<AddressElement, Integer> matches = primMatchIndex.get(prim); 201 243 if (matches == null) { 202 logger.log(Level. INFO, "new primitive detected", AddressElement.getName(prim));244 logger.log(Level.FINE, "new primitive detected", AddressElement.getName(prim)); 203 245 matches = new HashMap<AddressElement, Integer>(); 204 246 primMatchIndex.put(prim, matches); … … 210 252 211 253 public void consider(AddressElement elem) { 212 logger.log(Level.FINE , "considering element", elem);254 logger.log(Level.FINER, "considering element", elem); 213 255 214 256 Map<OsmPrimitive, Integer> matches = elemMatchIndex.get(elem); 215 257 if (matches == null) { 216 logger.log(Level. INFO, "new element detected", elem);258 logger.log(Level.FINE, "new element detected", elem); 217 259 matches = new HashMap<OsmPrimitive, Integer>(); 218 260 elemMatchIndex.put(elem, matches); … … 223 265 } 224 266 225 /*private int getStatus(OsmPrimitive prim) {226 if (primMatchIndex.get(prim) == null) return STATUS_UNKNOWN;227 if (primMatchIndex.get(prim).size()==0) return STATUS_UNKNOWN;228 if (translate(prim) != null) return STATUS_MATCH;229 return STATUS_CONFLICT;230 }231 232 private int getStatus(AddressElement elem) {233 if (elemMatchIndex.get(elem) == null) return STATUS_UNKNOWN;234 if (elemMatchIndex.get(elem).size()==0) return STATUS_UNKNOWN;235 if (translate(elem) != null) return STATUS_MATCH;236 return STATUS_CONFLICT;237 }*/238 239 267 public int getQ(OsmPrimitive prim, AddressElement elem) { 240 if (primMatchIndex.get(prim) == null) return 0; 241 if (elemMatchIndex.get(elem) == null) return 0; 242 243 assert primMatchIndex.get(prim).get(elem) == elemMatchIndex.get(elem).get(prim); 268 assert primMatchIndex.get(prim).get(elem) 269 == elemMatchIndex.get(elem).get(prim); 244 270 245 271 if (primMatchIndex.get(prim).get(elem) == null) … … 254 280 primMatchIndex.get(prim).remove(elem); 255 281 elemMatchIndex.get(elem).remove(prim); 256 257 if (primMatchIndex.get(prim).size() == 0)258 primMatchIndex.put(prim, null);259 if (elemMatchIndex.get(elem).size() == 0)260 elemMatchIndex.put(elem, null);261 262 282 } else { 263 283 primMatchIndex.get(prim).put(elem, qVal); … … 267 287 268 288 public AddressElement translate(OsmPrimitive prim) { 289 if (prim == null) return null; 290 269 291 AddressElement elem = primBestIndex.get(prim); 270 292 if (elemBestIndex.get(elem) == prim) … … 274 296 275 297 public OsmPrimitive translate(AddressElement elem) { 298 if (elem == null) return null; 299 276 300 OsmPrimitive prim = elemBestIndex.get(elem); 277 301 if (primBestIndex.get(prim) == elem) … … 280 304 } 281 305 282 public Set<AddressElement> conflicts(OsmPrimitive prim) { 283 284 Set<AddressElement> result = new HashSet<AddressElement>(); 285 result.addAll(primMatchIndex.get(prim).keySet()); 286 306 public Set<AddressElement> getConflicts(OsmPrimitive prim) { 307 308 Set<AddressElement> result = getCandidates(prim); 287 309 AddressElement match = translate(prim); 288 310 if (match != null) … … 292 314 } 293 315 294 public Set<OsmPrimitive> conflicts(AddressElement elem) { 295 296 Set<OsmPrimitive> result = new HashSet<OsmPrimitive>(); 297 result.addAll(elemMatchIndex.get(elem).keySet()); 298 316 public Set<OsmPrimitive> getConflicts(AddressElement elem) { 317 318 Set<OsmPrimitive> result = getCandidates(elem); 299 319 OsmPrimitive match = translate(elem); 300 320 if (match != null) … … 304 324 } 305 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 306 334 public static void main(String[] args) { 307 335 try { 308 336 309 Reasoner r = new Reasoner(); 310 311 Handler h = new FileHandler("log.xml"); 312 313 r.logger.addHandler(h); 314 r.logger.setLevel(Level.ALL); 337 Reasoner r = Reasoner.getInstance(); 338 Reasoner.logger.setLevel(Level.ALL); 315 339 316 Match.logger.addHandler(h);317 Match.logger.setLevel(Level.ALL);318 319 320 340 Street s1 = new Street("Jarní"); 321 341 Street s2 = new Street("Letní"); … … 341 361 r.closeTransaction(); 342 362 assert r.translate(n1) == h4; 343 assert r. conflicts(n1).size() == 0;363 assert r.getConflicts(n1).size() == 0; 344 364 345 365 … … 351 371 r.closeTransaction(); 352 372 assert r.translate(n2) == null; 353 assert r. conflicts(n2).contains(h1);354 assert r. conflicts(n2).contains(i4);373 assert r.getConflicts(n2).contains(h1); 374 assert r.getConflicts(n2).contains(i4); 355 375 356 376 n2.put("addr:street", "Letní"); … … 360 380 r.closeTransaction(); 361 381 assert r.translate(n2) == i4; 362 assert r.conflicts(n2).contains(h1);363 382 364 383 … … 367 386 r.consider(n2); 368 387 r.closeTransaction(); 369 370 388 assert r.translate(n2) == null; 371 389 … … 375 393 } 376 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 422 public boolean inConflict(OsmPrimitive prim) { 423 return primMatchIndex.get(prim).size() > 0 424 && translate(translate(prim)) != prim; 425 } 426 427 public boolean inConflict(AddressElement elem) { 428 return elemMatchIndex.get(elem).size() > 0 429 && translate(translate(elem)) != elem; 430 } 431 432 public Set<AddressElement> getUnassignedElements() { 433 Set<AddressElement> result = new HashSet<AddressElement>(); 434 for (AddressElement elem : elemMatchIndex.keySet()) 435 if (elemMatchIndex.get(elem).size() == 0) 436 result.add(elem); 437 return result; 438 } 377 439 } -
applications/editors/josm/plugins/czechaddress/src/org/openstreetmap/josm/plugins/czechaddress/intelligence/SelectionMonitor.java
r15166 r15558 5 5 import org.openstreetmap.josm.data.osm.DataSet; 6 6 import org.openstreetmap.josm.data.osm.OsmPrimitive; 7 import org.openstreetmap.josm.plugins.czechaddress.CzechAddressPlugin;8 7 import org.openstreetmap.josm.plugins.czechaddress.NotNullList; 9 8 10 9 /** 11 10 * Listenes to the current selection for reasoning 12 * 11 * 13 12 * <p>Currently JOSM has no way of giving notice about a changed or deleted 14 13 * node. This class tries to overcome this at the cost of computational … … 19 18 public class SelectionMonitor implements SelectionChangedListener { 20 19 21 NotNullList<OsmPrimitive> lastSelection = new NotNullList<OsmPrimitive>();20 Collection<OsmPrimitive> lastSelection = new NotNullList<OsmPrimitive>(); 22 21 23 public SelectionMonitor() { 24 DataSet.selListeners.add(this); 22 private SelectionMonitor() {} 23 private static SelectionMonitor singleton = null; 24 public static SelectionMonitor getInstance() { 25 if (singleton == null) { 26 singleton = new SelectionMonitor(); 27 DataSet.selListeners.add(singleton); 28 } 29 return singleton; 25 30 } 26 31 27 public void selectionChanged( 28 Collection<? extends OsmPrimitive>newSelection) {29 Reasoner r = CzechAddressPlugin.getReasoner();32 public void selectionChanged(Collection<? extends OsmPrimitive> 33 newSelection) { 34 Reasoner r = Reasoner.getInstance(); 30 35 31 r.addPrimitives(lastSelection); 36 synchronized(r) { 37 r.openTransaction(); 38 for (OsmPrimitive selectedPrim :newSelection) 39 r.consider(selectedPrim); 40 for (OsmPrimitive selectedPrim :lastSelection) 41 r.consider(selectedPrim); 42 r.closeTransaction(); 43 } 32 44 33 45 lastSelection.clear(); -
applications/editors/josm/plugins/czechaddress/src/org/openstreetmap/josm/plugins/czechaddress/parser/DatabaseParser.java
r15166 r15558 103 103 if (con.getResponseCode() != 200) 104 104 throw new DatabaseLoadException( 105 "Požadavek na server MVČRselhal, číslo chyby: " + String.valueOf( con.getResponseCode() ));105 "Požadavek na server selhal, číslo chyby: " + String.valueOf( con.getResponseCode() )); 106 106 107 107 BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(getDatabasePath()));
Note:
See TracChangeset
for help on using the changeset viewer.