Changeset 4087 in josm
- Timestamp:
- 2011-05-15T23:51:25+02:00 (14 years ago)
- Location:
- trunk
- Files:
-
- 3 added
- 1 deleted
- 15 edited
- 2 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/WireframeToggleAction.java
r3894 r4087 6 6 import java.awt.event.ActionEvent; 7 7 import java.awt.event.KeyEvent; 8 import java.util.ArrayList;9 import java.util.List;10 11 import javax.swing.ButtonModel;12 8 13 9 import org.openstreetmap.josm.Main; 10 import org.openstreetmap.josm.data.osm.visitor.paint.MapRendererFactory; 11 import org.openstreetmap.josm.data.osm.visitor.paint.StyledMapRenderer; 12 import org.openstreetmap.josm.data.osm.visitor.paint.WireframeMapRenderer; 14 13 import org.openstreetmap.josm.tools.Shortcut; 15 14 16 15 public class WireframeToggleAction extends JosmAction { 17 private final List<ButtonModel> buttonModels = new ArrayList<ButtonModel>();18 //FIXME: replace with property Action.SELECTED_KEY when migrating to19 // Java 620 private boolean selected;21 16 public WireframeToggleAction() { 22 17 super( … … 27 22 true /* register shortcut */ 28 23 ); 29 selected = Main.pref.getBoolean("draw.wireframe", false); 30 notifySelectedState(); 24 putValue(SELECTED_KEY, MapRendererFactory.getInstance().isWireframeMapRendererActive()); 31 25 } 32 26 33 public void addButtonModel(ButtonModel model) { 34 if (model != null && !buttonModels.contains(model)) { 35 buttonModels.add(model); 36 model.setSelected(selected); 27 public void toggleSelectedState() { 28 boolean selected = (Boolean)getValue(SELECTED_KEY); 29 30 if (selected){ 31 MapRendererFactory.getInstance().activate(WireframeMapRenderer.class); 32 } else { 33 MapRendererFactory.getInstance().activate(StyledMapRenderer.class); 37 34 } 38 }39 40 public void removeButtonModel(ButtonModel model) {41 if (model != null && buttonModels.contains(model)) {42 buttonModels.remove(model);43 }44 }45 46 protected void notifySelectedState() {47 for (ButtonModel model: buttonModels) {48 if (model.isSelected() != selected) {49 model.setSelected(selected);50 }51 }52 }53 54 protected void toggleSelectedState() {55 selected = !selected;56 Main.pref.put("draw.wireframe", selected);57 notifySelectedState();58 35 if (Main.map != null) { 59 36 Main.map.mapView.repaint(); 60 37 } 61 38 } 39 62 40 public void actionPerformed(ActionEvent e) { 63 41 toggleSelectedState(); … … 66 44 @Override 67 45 protected void updateEnabledState() { 68 setEnabled(Main.map != null && Main.main.getEditLayer() != null); 69 } 70 71 public boolean isSelected() { 72 return selected; 46 setEnabled(Main.main.getEditLayer() != null); 73 47 } 74 48 } -
trunk/src/org/openstreetmap/josm/actions/mapmode/SelectAction.java
r4039 r4087 37 37 import org.openstreetmap.josm.data.osm.WaySegment; 38 38 import org.openstreetmap.josm.data.osm.visitor.AllNodesVisitor; 39 import org.openstreetmap.josm.data.osm.visitor.paint. SimplePaintVisitor;39 import org.openstreetmap.josm.data.osm.visitor.paint.WireframeMapRenderer; 40 40 import org.openstreetmap.josm.gui.ExtendedDialog; 41 41 import org.openstreetmap.josm.gui.MapFrame; … … 298 298 Point2D p1 = mv.getPoint2D(wnp.a = w.getNode(ws.lowerIndex)); 299 299 Point2D p2 = mv.getPoint2D(wnp.b = w.getNode(ws.lowerIndex + 1)); 300 if ( SimplePaintVisitor.isLargeSegment(p1, p2, virtualSpace)) {300 if (WireframeMapRenderer.isLargeSegment(p1, p2, virtualSpace)) { 301 301 Point2D pc = new Point2D.Double((p1.getX() + p2.getX()) / 2, (p1.getY() + p2.getY()) / 2); 302 302 if (p.distanceSq(pc) < virtualSnapDistSq) { -
trunk/src/org/openstreetmap/josm/data/Bounds.java
r4065 r4087 205 205 } 206 206 207 /** 208 * <p>Replies true, if this bounds are <em>collapsed</em>, i.e. if the min 209 * and the max corner are equal.</p> 210 * 211 * @return true, if this bounds are <em>collapsed</em> 212 */ 213 public boolean isCollapsed() { 214 return getMin().equals(getMax()); 215 } 216 207 217 @Override 208 218 public int hashCode() { -
trunk/src/org/openstreetmap/josm/data/osm/DataSet.java
r4064 r4087 20 20 import java.util.concurrent.locks.ReentrantReadWriteLock; 21 21 22 import org.openstreetmap.josm.data.Bounds; 22 23 import org.openstreetmap.josm.data.SelectionChangedListener; 23 24 import org.openstreetmap.josm.data.coor.EastNorth; … … 145 146 public LinkedList<Collection<? extends OsmPrimitive>> getSelectionHistory() { 146 147 return selectionHistory; 147 } 148 } 148 149 149 150 /** … … 151 152 */ 152 153 public void clearSelectionHistory() { 153 154 154 selectionHistory.clear(); 155 } 155 156 156 157 /** … … 1041 1042 } 1042 1043 } 1044 1045 /** 1046 * <p>Replies the list of data source bounds.</p> 1047 * 1048 * <p>Dataset maintains a list of data sources which have been merged into the 1049 * data set. Each of these sources can optionally declare a bounding box of the 1050 * data it supplied to the dataset.</p> 1051 * 1052 * <p>This method replies the list of defined (non {@code null}) bounding boxes.</p> 1053 * 1054 * @return the list of data source bounds. An empty list, if no non-null data source 1055 * bounds are defined. 1056 */ 1057 public List<Bounds> getDataSourceBounds() { 1058 List<Bounds> ret = new ArrayList<Bounds>(dataSources.size()); 1059 for (DataSource ds : dataSources) { 1060 if (ds.bounds != null) { 1061 ret.add(ds.bounds); 1062 } 1063 } 1064 return ret; 1065 } 1043 1066 } -
trunk/src/org/openstreetmap/josm/data/osm/visitor/paint/MapPainter.java
r4042 r4087 80 80 public MapPainter(MapPaintSettings settings, Graphics2D g, 81 81 boolean inactive, NavigatableComponent nc, boolean virtual, 82 double circum, boolean leftHandTraffic) 83 { 82 double circum, boolean leftHandTraffic){ 84 83 this.settings = settings; 85 84 this.g = g; … … 163 162 final double sy = l * (p1.y - p2.y); 164 163 165 double tmp = p2.x + cosPHI * sx - sinPHI * sy;166 164 orientationArrows.moveTo (p2.x + cosPHI * sx - sinPHI * sy, p2.y + sinPHI * sx + cosPHI * sy); 167 165 orientationArrows.lineTo(p2.x, p2.y); … … 699 697 continue; 700 698 } 701 drawArea(r, p, 699 drawArea(r, p, 702 700 pd.selected ? settings.getRelationSelectedColor(color.getAlpha()) : color, 703 fillImage, fillImageAlpha, text);701 fillImage, fillImageAlpha, text); 704 702 } 705 703 } … … 985 983 } 986 984 987 public boolean isInactive() {988 return inactive;989 }990 991 985 public boolean isShowNames() { 992 986 return showNames; … … 1001 995 } 1002 996 997 public boolean isInactiveMode() { 998 return inactive; 999 } 1003 1000 } -
trunk/src/org/openstreetmap/josm/data/osm/visitor/paint/StyledMapRenderer.java
r4081 r4087 24 24 import org.openstreetmap.josm.gui.mappaint.StyleCache.StyleList; 25 25 26 public class MapPaintVisitor implements PaintVisitor { 27 28 private Graphics2D g;29 private boolean inactive;30 private NavigatableComponent nc; 26 /** 27 * <p>A map renderer which renders a map according to style rules in a set of style sheets.</p> 28 * 29 */ 30 public class StyledMapRenderer extends AbstractMapRenderer{ 31 31 32 32 private ElemStyles styles; … … 69 69 z_index2 += 600f; 70 70 } 71 71 72 72 int d1 = Float.compare(z_index1, z_index2); 73 73 if (d1 != 0) 74 74 return d1; 75 75 76 76 // simple node on top of icons and shapes 77 77 if (this.style == NodeElemStyle.SIMPLE_NODE_ELEMSTYLE && other.style != NodeElemStyle.SIMPLE_NODE_ELEMSTYLE) … … 79 79 if (this.style != NodeElemStyle.SIMPLE_NODE_ELEMSTYLE && other.style == NodeElemStyle.SIMPLE_NODE_ELEMSTYLE) 80 80 return -1; 81 81 82 82 // newer primitives to the front 83 83 long id = this.osm.getUniqueId() - other.osm.getUniqueId(); … … 86 86 if (id < 0) 87 87 return -1; 88 88 89 89 return Float.compare(this.style.object_z_index, other.style.object_z_index); 90 90 } 91 91 } 92 92 93 93 private class StyleCollector { 94 94 private final boolean drawArea; … … 137 137 for (StyleRecord r : styleElems) { 138 138 r.style.paintPrimitive( 139 r.osm, 140 paintSettings, 141 painter, 142 (r.flags & FLAG_SELECTED) != 0, 139 r.osm, 140 paintSettings, 141 painter, 142 (r.flags & FLAG_SELECTED) != 0, 143 143 (r.flags & FLAG_MEMBER_OF_SELECTED) != 0 144 144 ); … … 147 147 } 148 148 149 public void visitAll(final DataSet data, boolean virtual, Bounds bounds) { 150 //long start = System.currentTimeMillis(); 151 BBox bbox = new BBox(bounds); 152 153 styles = MapPaintStyles.getStyles(); 154 155 this.paintSettings = MapPaintSettings.INSTANCE; 156 157 circum = nc.getDist100Pixel(); 158 boolean drawArea = circum <= Main.pref.getInteger("mappaint.fillareas", 10000000); 159 boolean drawMultipolygon = drawArea && Main.pref.getBoolean("mappaint.multipolygon", true); 160 styles.setDrawMultipolygon(drawMultipolygon); 161 boolean drawRestriction = Main.pref.getBoolean("mappaint.restriction", true); 162 boolean leftHandTraffic = Main.pref.getBoolean("mappaint.lefthandtraffic", false); 163 164 g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, 165 Main.pref.getBoolean("mappaint.use-antialiasing", true) ? 166 RenderingHints.VALUE_ANTIALIAS_ON : RenderingHints.VALUE_ANTIALIAS_OFF); 167 168 this.painter = new MapPainter(paintSettings, g, inactive, nc, virtual, circum, leftHandTraffic); 169 170 StyleCollector sc = new StyleCollector(drawArea, drawMultipolygon, drawRestriction); 171 149 /** 150 * {@inheritDoc} 151 */ 152 public StyledMapRenderer(Graphics2D g, NavigatableComponent nc, boolean isInactiveMode) { 153 super(g, nc, isInactiveMode); 154 } 155 156 private void collectNodeStyles(DataSet data, StyleCollector sc, BBox bbox) { 172 157 for (final Node n: data.searchNodes(bbox)) { 173 158 if (n.isDrawable()) { … … 183 168 } 184 169 } 170 } 171 172 private void collectWayStyles(DataSet data, StyleCollector sc, BBox bbox) { 185 173 for (final Way w : data.searchWays(bbox)) { 186 174 if (w.isDrawable()) { … … 196 184 } 197 185 } 186 } 187 188 private void collectRelationStyles(DataSet data, StyleCollector sc, BBox bbox) { 198 189 for (Relation r: data.searchRelations(bbox)) { 199 190 if (r.isDrawable()) { … … 207 198 } 208 199 } 209 200 } 201 202 @Override 203 public void render(final DataSet data, boolean renderVirtualNodes, Bounds bounds) { 204 //long start = System.currentTimeMillis(); 205 BBox bbox = new BBox(bounds); 206 207 styles = MapPaintStyles.getStyles(); 208 209 this.paintSettings = MapPaintSettings.INSTANCE; 210 211 circum = nc.getDist100Pixel(); 212 boolean drawArea = circum <= Main.pref.getInteger("mappaint.fillareas", 10000000); 213 boolean drawMultipolygon = drawArea && Main.pref.getBoolean("mappaint.multipolygon", true); 214 styles.setDrawMultipolygon(drawMultipolygon); 215 boolean drawRestriction = Main.pref.getBoolean("mappaint.restriction", true); 216 boolean leftHandTraffic = Main.pref.getBoolean("mappaint.lefthandtraffic", false); 217 218 g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, 219 Main.pref.getBoolean("mappaint.use-antialiasing", true) ? 220 RenderingHints.VALUE_ANTIALIAS_ON : RenderingHints.VALUE_ANTIALIAS_OFF); 221 222 this.painter = new MapPainter(paintSettings, g, isInactiveMode, nc, renderVirtualNodes, circum, leftHandTraffic); 223 224 StyleCollector sc = new StyleCollector(drawArea, drawMultipolygon, drawRestriction); 225 collectNodeStyles(data, sc, bbox); 226 collectWayStyles(data, sc, bbox); 227 collectRelationStyles(data, sc, bbox); 210 228 //long phase1 = System.currentTimeMillis(); 211 212 229 sc.drawAll(); 213 230 sc = null; 214 215 231 painter.drawVirtualNodes(data.searchWays(bbox)); 216 232 217 233 //long now = System.currentTimeMillis(); 218 234 //System.err.println(String.format("PAINTING TOOK %d [PHASE1 took %d] (at scale %s)", now - start, phase1 - start, circum)); 219 235 } 220 221 public void setGraphics(Graphics2D g) {222 this.g = g;223 }224 225 public void setInactive(boolean inactive) {226 this.inactive = inactive;227 }228 229 public void setNavigatableComponent(NavigatableComponent nc) {230 this.nc = nc;231 }232 236 } -
trunk/src/org/openstreetmap/josm/data/osm/visitor/paint/WireframeMapRenderer.java
r4081 r4087 1 1 /* License: GPL. Copyright 2007 by Immanuel Scholz and others */ 2 2 package org.openstreetmap.josm.data.osm.visitor.paint; 3 4 /* To enable debugging or profiling remove the double / signs */5 3 6 4 import java.awt.BasicStroke; … … 20 18 import org.openstreetmap.josm.data.Bounds; 21 19 import org.openstreetmap.josm.data.osm.BBox; 20 import org.openstreetmap.josm.data.osm.Changeset; 22 21 import org.openstreetmap.josm.data.osm.DataSet; 23 22 import org.openstreetmap.josm.data.osm.Node; … … 26 25 import org.openstreetmap.josm.data.osm.RelationMember; 27 26 import org.openstreetmap.josm.data.osm.Way; 28 import org.openstreetmap.josm.data.osm.visitor. AbstractVisitor;27 import org.openstreetmap.josm.data.osm.visitor.Visitor; 29 28 import org.openstreetmap.josm.gui.NavigatableComponent; 30 29 31 30 /** 32 * A visitor that paints a simple scheme of every primitive it visits to a31 * A map renderer that paints a simple scheme of every primitive it visits to a 33 32 * previous set graphic environment. 34 33 * 35 34 * @author imi 36 35 */ 37 public class SimplePaintVisitor extends AbstractVisitor implements PaintVisitor { 38 /** 39 * The environment to paint to. 40 */ 41 protected Graphics2D g; 42 /** 43 * MapView to get screen coordinates. 44 */ 45 protected NavigatableComponent nc; 46 47 public boolean inactive; 36 public class WireframeMapRenderer extends AbstractMapRenderer implements Visitor { 48 37 49 38 /** … … 85 74 protected GeneralPath currentPath = new GeneralPath(); 86 75 76 /** 77 * {@inheritDoc} 78 */ 79 public WireframeMapRenderer(Graphics2D g, NavigatableComponent nc, boolean isInactiveMode) { 80 super(g, nc, isInactiveMode); 81 } 82 87 83 public void getColors() 88 84 { … … 132 128 133 129 DataSet ds; 134 public void visitAll(DataSet data, boolean virtual, Bounds bounds) {130 public void render(DataSet data, boolean virtual, Bounds bounds) { 135 131 BBox bbox = new BBox(bounds); 136 132 this.ds = data; 137 //boolean profiler = Main.pref.getBoolean("simplepaint.profiler",false);138 //long profilerStart = java.lang.System.currentTimeMillis();139 //long profilerLast = profilerStart;140 //int profilerN = 0;141 //if(profiler)142 // System.out.println("Simplepaint Profiler");143 144 133 getSettings(virtual); 145 146 //if(profiler)147 //{148 // System.out.format("Prepare : %4dms\n", (java.lang.System.currentTimeMillis()-profilerLast));149 // profilerLast = java.lang.System.currentTimeMillis();150 //}151 134 152 135 /* draw tagged ways first, then untagged ways. takes 153 136 time to iterate through list twice, OTOH does not 154 137 require changing the colour while painting... */ 155 //profilerN = 0;156 138 for (final OsmPrimitive osm: data.searchRelations(bbox)) { 157 139 if (!osm.isDeleted() && !ds.isSelected(osm) && !osm.isDisabledAndHidden()) { 158 140 osm.visit(this); 159 // profilerN++; 160 } 161 } 162 163 //if(profiler) 164 //{ 165 // System.out.format("Relations: %4dms, n=%5d\n", (java.lang.System.currentTimeMillis()-profilerLast), profilerN); 166 // profilerLast = java.lang.System.currentTimeMillis(); 167 //} 168 169 //profilerN = 0; 141 } 142 } 143 170 144 for (final OsmPrimitive osm:data.searchWays(bbox)){ 171 145 if (!osm.isDeleted() && !ds.isSelected(osm) && !osm.isDisabledAndHidden() && osm.isTagged()) { 172 146 osm.visit(this); 173 // profilerN++;174 147 } 175 148 } … … 179 152 if (!osm.isDeleted() && !ds.isSelected(osm) && !osm.isDisabledAndHidden() && !osm.isTagged()) { 180 153 osm.visit(this); 181 // profilerN++;182 154 } 183 155 } 184 156 displaySegments(); 185 186 //if(profiler)187 //{188 // System.out.format("Ways : %4dms, n=%5d\n",189 // (java.lang.System.currentTimeMillis()-profilerLast), profilerN);190 // profilerLast = java.lang.System.currentTimeMillis();191 //}192 193 //profilerN = 0;194 157 for (final OsmPrimitive osm : data.getSelected()) { 195 158 if (!osm.isDeleted()) { 196 159 osm.visit(this); 197 // profilerN++;198 160 } 199 161 } 200 162 displaySegments(); 201 163 202 //if(profiler)203 //{204 // System.out.format("Selected : %4dms, n=%5d\n", (java.lang.System.currentTimeMillis()-profilerLast), profilerN);205 // profilerLast = java.lang.System.currentTimeMillis();206 //}207 208 //profilerN = 0;209 164 for (final OsmPrimitive osm: data.searchNodes(bbox)) { 210 165 if (!osm.isDeleted() && !ds.isSelected(osm) && !osm.isDisabledAndHidden()) 211 166 { 212 167 osm.visit(this); 213 // profilerN++; 214 } 215 } 216 217 //if(profiler) 218 //{ 219 // System.out.format("Nodes : %4dms, n=%5d\n", 220 // (java.lang.System.currentTimeMillis()-profilerLast), profilerN); 221 // profilerLast = java.lang.System.currentTimeMillis(); 222 //} 223 168 } 169 } 224 170 drawVirtualNodes(data.searchWays(bbox)); 225 226 //if(profiler)227 //{228 // System.out.format("All : %4dms\n", (profilerLast-profilerStart));229 //}230 171 } 231 172 … … 248 189 Color color; 249 190 250 if (i nactive || n.isDisabled()) {191 if (isInactiveMode || n.isDisabled()) { 251 192 color = inactiveColor; 252 193 } else if (ds.isSelected(n)) { … … 339 280 Color wayColor; 340 281 341 if (i nactive || w.isDisabled()) {282 if (isInactiveMode || w.isDisabled()) { 342 283 wayColor = inactiveColor; 343 284 } else if(w.isHighlighted()) { … … 372 313 373 314 Color col; 374 if (i nactive || r.isDisabled()) {315 if (isInactiveMode || r.isDisabled()) { 375 316 col = inactiveColor; 376 317 } else if (ds.isSelected(r)) { … … 415 356 } 416 357 } 358 359 @Override 360 public void visit(Changeset cs) {/* ignore */} 417 361 418 362 /** … … 519 463 } 520 464 521 public void setGraphics(Graphics2D g) {522 this.g = g;523 }524 525 public void setNavigatableComponent(NavigatableComponent nc) {526 this.nc = nc;527 }528 529 465 protected void displaySegments() { 530 466 displaySegments(null); … … 538 474 } 539 475 } 540 541 public void setInactive(boolean inactive) {542 this.inactive = inactive;543 }544 476 } -
trunk/src/org/openstreetmap/josm/gui/MainMenu.java
r4086 r4087 277 277 viewMenu.add(wireframe); 278 278 wireframe.setAccelerator(wireFrameToggleAction.getShortcut().getKeyStroke()); 279 wireFrameToggleAction.addButtonModel(wireframe.getModel());280 279 281 280 viewMenu.addSeparator(); -
trunk/src/org/openstreetmap/josm/gui/dialogs/MapPaintDialog.java
r4072 r4087 13 13 import java.awt.Rectangle; 14 14 import java.awt.event.ActionEvent; 15 import java.awt.event.ActionListener;16 15 import java.awt.event.KeyEvent; 17 16 import java.awt.event.MouseEvent; … … 28 27 29 28 import javax.swing.AbstractAction; 30 import javax.swing.DefaultButtonModel;31 29 import javax.swing.DefaultListSelectionModel; 32 30 import javax.swing.JCheckBox; … … 99 97 JLabel wfLabel = new JLabel(tr("Wireframe View"), ImageProvider.get("dialogs/mappaint", "wireframe_small"), JLabel.HORIZONTAL); 100 98 wfLabel.setFont(wfLabel.getFont().deriveFont(Font.PLAIN)); 101 102 cbWireframe.setModel(new DefaultButtonModel() { 103 @Override 104 public void setSelected(boolean b) { 105 super.setSelected(b); 106 tblStyles.setEnabled(!b); 107 onoffAction.updateEnabledState(); 108 upAction.updateEnabledState(); 109 downAction.updateEnabledState(); 110 } 111 }); 112 cbWireframe.addActionListener(new ActionListener() { 113 public void actionPerformed(ActionEvent e) { 114 Main.main.menu.wireFrameToggleAction.actionPerformed(null); 115 } 116 }); 99 cbWireframe.setFont(cbWireframe.getFont().deriveFont(Font.PLAIN)); 100 cbWireframe.setAction(Main.main.menu.wireFrameToggleAction); 117 101 cbWireframe.setBorder(new EmptyBorder(new Insets(1,1,1,1))); 118 102 cbWireframe.setText(""); 119 103 tblStyles = new StylesTable(model); 120 104 tblStyles.setSelectionModel(selectionModel= new DefaultListSelectionModel()); … … 130 114 tblStyles.setShowGrid(false); 131 115 tblStyles.setIntercellSpacing(new Dimension(0, 0)); 116 cbWireframe.addChangeListener(tblStyles); 132 117 133 118 JPanel p = new JPanel(new GridBagLayout()); … … 137 122 138 123 pnl.add(new JScrollPane(p), BorderLayout.CENTER); 139 140 124 pnl.add(buildButtonRow(), BorderLayout.SOUTH); 141 142 125 add(pnl, BorderLayout.CENTER); 143 126 } 144 127 145 protected static class StylesTable extends JTable{128 protected class StylesTable extends JTable implements ChangeListener{ 146 129 147 130 public StylesTable(TableModel dm) { … … 157 140 rect.setLocation(rect.x - pt.x, rect.y - pt.y); 158 141 viewport.scrollRectToVisible(rect); 142 } 143 144 @Override 145 public void stateChanged(ChangeEvent e) { 146 setEnabled(!cbWireframe.isSelected()); 159 147 } 160 148 } … … 170 158 selectionModel.addListSelectionListener(upAction); 171 159 selectionModel.addListSelectionListener(downAction); 160 cbWireframe.addChangeListener(onoffAction); 161 cbWireframe.addChangeListener(upAction); 162 cbWireframe.addChangeListener(downAction); 163 172 164 p.add(new SideButton(onoffAction)); 173 165 p.add(new SideButton(upAction)); … … 180 172 @Override 181 173 public void showNotify() { 174 cbWireframe.setAction(Main.main.menu.wireFrameToggleAction); 182 175 MapPaintStyles.addMapPaintSylesUpdateListener(model); 183 Main.main.menu.wireFrameToggleAction.addButtonModel(cbWireframe.getModel());184 176 } 185 177 186 178 @Override 187 179 public void hideNotify() { 188 Main.main.menu.wireFrameToggleAction.removeButtonModel(cbWireframe.getModel());180 cbWireframe.setAction(null); 189 181 MapPaintStyles.removeMapPaintSylesUpdateListener(model); 190 182 } … … 304 296 } 305 297 306 protected class OnOffAction extends AbstractAction implements ListSelectionListener { 298 protected abstract class EventListeningAction extends AbstractAction implements ListSelectionListener, ChangeListener { 299 300 protected abstract void updateEnabledState(); 301 302 @Override 303 public void valueChanged(ListSelectionEvent e) { 304 updateEnabledState(); 305 } 306 307 @Override 308 public void stateChanged(ChangeEvent e) { 309 updateEnabledState(); 310 } 311 } 312 313 protected class OnOffAction extends EventListeningAction { 307 314 public OnOffAction() { 308 315 putValue(SHORT_DESCRIPTION, tr("Turn selected styles on or off")); … … 311 318 } 312 319 320 @Override 313 321 protected void updateEnabledState() { 314 322 setEnabled(!cbWireframe.isSelected() && tblStyles.getSelectedRowCount() > 0); 315 }316 317 @Override318 public void valueChanged(ListSelectionEvent e) {319 updateEnabledState();320 323 } 321 324 … … 334 337 * The action to move down the currently selected entries in the list. 335 338 */ 336 protected class MoveUpDownAction extends AbstractAction implements ListSelectionListener{339 protected class MoveUpDownAction extends EventListeningAction { 337 340 338 341 final int increment; … … 345 348 } 346 349 350 @Override 347 351 public void updateEnabledState() { 348 352 int[] sel = tblStyles.getSelectedRows(); … … 360 364 } 361 365 model.ensureSelectedIsVisible(); 362 }363 364 public void valueChanged(ListSelectionEvent e) {365 updateEnabledState();366 366 } 367 367 } … … 503 503 error = true; 504 504 } finally { 505 if (bis != null) { 506 try { 507 bis.close(); 508 } catch (IOException e) { 509 e.printStackTrace(); 510 } 511 } 512 if (bos != null) { 513 try { 514 bos.close(); 515 } catch (IOException e) { 516 e.printStackTrace(); 517 } 518 } 505 Utils.close(bis); 506 Utils.close(bos); 519 507 } 520 508 } … … 648 636 txtSource.append("<ERROR: failed to read file!>"); 649 637 } finally { 650 try { 651 is.close(); 652 } catch (IOException ex) { 653 } 638 Utils.close(is); 654 639 } 655 640 } -
trunk/src/org/openstreetmap/josm/gui/layer/OsmDataLayer.java
r4046 r4087 42 42 import org.openstreetmap.josm.data.conflict.Conflict; 43 43 import org.openstreetmap.josm.data.conflict.ConflictCollection; 44 import org.openstreetmap.josm.data.coor.EastNorth;45 44 import org.openstreetmap.josm.data.coor.LatLon; 46 45 import org.openstreetmap.josm.data.gpx.GpxData; … … 61 60 import org.openstreetmap.josm.data.osm.visitor.AbstractVisitor; 62 61 import org.openstreetmap.josm.data.osm.visitor.BoundingXYVisitor; 63 import org.openstreetmap.josm.data.osm.visitor.paint.MapPaintVisitor; 64 import org.openstreetmap.josm.data.osm.visitor.paint.PaintVisitor; 65 import org.openstreetmap.josm.data.osm.visitor.paint.SimplePaintVisitor; 62 import org.openstreetmap.josm.data.osm.visitor.paint.MapRendererFactory; 63 import org.openstreetmap.josm.data.osm.visitor.paint.Rendering; 66 64 import org.openstreetmap.josm.data.validation.TestError; 67 65 import org.openstreetmap.josm.gui.HelpAwareOptionPane; … … 241 239 Area a = new Area(b); 242 240 243 // now succesively subtract downloaded areas 244 for (DataSource src : data.dataSources) { 245 if (src.bounds != null && !src.bounds.getMin().equals(src.bounds.getMax())) { 246 EastNorth en1 = mv.getProjection().latlon2eastNorth(src.bounds.getMin()); 247 EastNorth en2 = mv.getProjection().latlon2eastNorth(src.bounds.getMax()); 248 Point p1 = mv.getPoint(en1); 249 Point p2 = mv.getPoint(en2); 250 Rectangle r = new Rectangle(Math.min(p1.x, p2.x),Math.min(p1.y, p2.y),Math.abs(p2.x-p1.x),Math.abs(p2.y-p1.y)); 251 a.subtract(new Area(r)); 241 // now successively subtract downloaded areas 242 for (Bounds bounds : data.getDataSourceBounds()) { 243 if (bounds.isCollapsed()) { 244 continue; 252 245 } 246 Point p1 = mv.getPoint(bounds.getMin()); 247 Point p2 = mv.getPoint(bounds.getMax()); 248 Rectangle r = new Rectangle(Math.min(p1.x, p2.x),Math.min(p1.y, p2.y),Math.abs(p2.x-p1.x),Math.abs(p2.y-p1.y)); 249 a.subtract(new Area(r)); 253 250 } 254 251 … … 258 255 } 259 256 260 PaintVisitor painter; 261 if (Main.pref.getBoolean("draw.wireframe")) { 262 painter = new SimplePaintVisitor(); 263 } else { 264 painter = new MapPaintVisitor(); 265 } 266 painter.setGraphics(g); 267 painter.setNavigatableComponent(mv); 268 painter.setInactive(inactive); 269 painter.visitAll(data, virtual, box); 257 Rendering painter = MapRendererFactory.getInstance().createActiveRenderer(g, mv, inactive); 258 painter.render(data, virtual, box); 270 259 Main.map.conflictDialog.paintConflicts(g, mv); 271 260 } … … 528 517 } 529 518 String name = n.get("name"); 530 if (name == null) 531 continue; 519 if (name == null) { 520 continue; 521 } 532 522 WayPoint wpt = new WayPoint(n.getCoor()); 533 523 wpt.attr.put("name", name); … … 538 528 String desc = n.get("description"); 539 529 if (desc != null) { 540 wpt.attr.put("desc", desc);541 530 wpt.attr.put("desc", desc); 531 } 542 532 543 533 gpxData.waypoints.add(wpt); -
trunk/src/org/openstreetmap/josm/gui/mappaint/NodeElemStyle.java
r4005 r4087 127 127 } 128 128 129 @Override 129 130 protected String toStringImpl() { 130 131 return super.toStringImpl() + " hAlign=" + hAlign + " vAlign=" + vAlign; … … 207 208 } 208 209 209 return new NodeElemStyle(c, 210 return new NodeElemStyle(c, 210 211 icon == null ? null : icon.a, 211 212 icon == null ? null : icon.b, … … 342 343 Node n = (Node) primitive; 343 344 if (icon != null && painter.isShowIcons()) { 344 painter.drawNodeIcon(n, (painter.isInactive () || n.isDisabled()) ? getDisabledIcon() : icon,345 painter.drawNodeIcon(n, (painter.isInactiveMode() || n.isDisabled()) ? getDisabledIcon() : icon, 345 346 Utils.color_int2float(iconAlpha), selected, member, text); 346 347 } else if (symbol != null) { … … 350 351 fillColor = settings.getHighlightColor(); 351 352 } else { 352 if (painter.isInactive () || n.isDisabled()) {353 if (painter.isInactiveMode() || n.isDisabled()) { 353 354 fillColor = settings.getInactiveColor(); 354 355 } else if (selected) { … … 364 365 strokeColor = settings.getHighlightColor(); 365 366 } else { 366 if (painter.isInactive () || n.isDisabled()) {367 if (painter.isInactiveMode() || n.isDisabled()) { 367 368 strokeColor = settings.getInactiveColor(); 368 369 } else if (selected) { … … 381 382 boolean isConnection = n.isConnectionNode(); 382 383 383 if (painter.isInactive () || n.isDisabled()) {384 if (painter.isInactiveMode() || n.isDisabled()) { 384 385 color = settings.getInactiveColor(); 385 386 } else if (selected) { … … 402 403 403 404 final int size = Utils.max((selected ? settings.getSelectedNodeSize() : 0), 404 405 406 405 (n.isTagged() ? settings.getTaggedNodeSize() : 0), 406 (isConnection ? settings.getConnectionNodeSize() : 0), 407 settings.getUnselectedNodeSize()); 407 408 408 409 final boolean fill = (selected && settings.isFillSelectedNode()) || 409 410 411 410 (n.isTagged() && settings.isFillTaggedNode()) || 411 (isConnection && settings.isFillConnectionNode()) || 412 settings.isFillUnselectedNode(); 412 413 413 414 painter.drawNode(n, color, size, fill, text); … … 474 475 return s.toString(); 475 476 } 476 477 477 } -
trunk/src/org/openstreetmap/josm/plugins/PluginDownloadTask.java
r3530 r4087 24 24 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 25 25 import org.openstreetmap.josm.tools.CheckParameterUtil; 26 import org.openstreetmap.josm.tools.Utils; 26 27 import org.xml.sax.SAXException; 27 28 … … 145 146 throw new PluginDownloadException(e); 146 147 } finally { 147 if (in != null) { 148 try { 149 in.close(); 150 } catch(IOException e) { /* ignore */} 151 } 148 Utils.close(in); 152 149 synchronized(this) { 153 150 downloadConnection = null; 154 151 } 155 if (out != null) { 156 try { 157 out.close(); 158 } catch(IOException e) { /* ignore */} 159 } 152 Utils.close(out); 160 153 } 161 154 } -
trunk/src/org/openstreetmap/josm/plugins/ReadLocalPluginInformationTask.java
r3874 r4087 18 18 import org.openstreetmap.josm.io.OsmTransferException; 19 19 import org.openstreetmap.josm.tools.ImageProvider; 20 import org.openstreetmap.josm.tools.Utils; 20 21 import org.xml.sax.SAXException; 21 22 … … 186 187 throw new PluginListParseException(e); 187 188 } finally { 188 if (fin != null) { 189 try { 190 fin.close(); 191 } catch(IOException e){ /* ignore */} 192 } 189 Utils.close(fin); 193 190 } 194 191 } -
trunk/src/org/openstreetmap/josm/plugins/ReadRemotePluginInformationTask.java
r3730 r4087 34 34 import org.openstreetmap.josm.io.OsmTransferException; 35 35 import org.openstreetmap.josm.tools.ImageProvider; 36 import org.openstreetmap.josm.tools.Utils; 36 37 import org.xml.sax.SAXException; 37 38 … … 188 189 connection = null; 189 190 } 190 if (in != null) { 191 try { 192 in.close(); 193 } catch(IOException e){/* ignore */} 194 } 191 Utils.close(in); 195 192 monitor.finishTask(); 196 193 } … … 242 239 connection = null; 243 240 } 244 if (in != null) { 245 try { 246 in.close(); 247 } catch(IOException e){/* ignore */} 248 } 241 Utils.close(in); 249 242 monitor.finishTask(); 250 243 } -
trunk/src/org/openstreetmap/josm/tools/Utils.java
r4069 r4087 7 7 import java.io.InputStream; 8 8 import java.io.OutputStream; 9 import java.io.Reader; 9 10 import java.text.MessageFormat; 10 11 import java.util.Collection; … … 202 203 return( path.delete() ); 203 204 } 205 206 /** 207 * <p>Utility method for closing an input stream.</p> 208 * 209 * @param is the input stream. May be null. 210 */ 211 public static void close(InputStream is){ 212 if (is == null) return; 213 try { 214 is.close(); 215 } catch(IOException e){ 216 // ignore 217 } 218 } 219 220 /** 221 * <p>Utility method for closing an output stream.</p> 222 * 223 * @param os the output stream. May be null. 224 */ 225 public static void close(OutputStream os){ 226 if (os == null) return; 227 try { 228 os.close(); 229 } catch(IOException e){ 230 // ignore 231 } 232 } 233 234 /** 235 * <p>Utility method for closing a reader.</p> 236 * 237 * @param reader the reader. May be null. 238 */ 239 public static void close(Reader reader){ 240 if (reader == null) return; 241 try { 242 reader.close(); 243 } catch(IOException e){ 244 // ignore 245 } 246 } 204 247 } -
trunk/test/functional/mapcss/performance/PerformanceTest.groovy
r4074 r4087 12 12 import org.openstreetmap.josm.data.Bounds 13 13 import org.openstreetmap.josm.data.osm.DataSet 14 import org.openstreetmap.josm.data.osm.visitor.paint. MapPaintVisitor14 import org.openstreetmap.josm.data.osm.visitor.paint.StyledMapRenderer 15 15 import org.openstreetmap.josm.gui.MainApplication 16 16 import org.openstreetmap.josm.gui.layer.OsmDataLayer … … 116 116 Graphics2D g = img.createGraphics() 117 117 g.setClip(0,0, mv.getWidth(), mv.getHeight()) 118 def visitor = new MapPaintVisitor()118 def visitor = new StyledMapRenderer() 119 119 visitor.setNavigatableComponent(Main.map.mapView) 120 120 visitor.setGraphics(g) … … 122 122 print "Rendering ..." 123 123 long time = timed { 124 visitor. visitAll(ds, false, new Bounds(-90,-180,90,180))124 visitor.render(ds, false, new Bounds(-90,-180,90,180)) 125 125 } 126 126 println "DONE" -
trunk/test/performance/org/openstreetmap/josm/data/osm/MapPaintVisitorPerformanceTest.java
r3350 r4087 10 10 import org.openstreetmap.josm.Main; 11 11 import org.openstreetmap.josm.data.Bounds; 12 import org.openstreetmap.josm.data.osm.visitor.paint. MapPaintVisitor;13 import org.openstreetmap.josm.data.osm.visitor.paint. PaintVisitor;12 import org.openstreetmap.josm.data.osm.visitor.paint.Rendering; 13 import org.openstreetmap.josm.data.osm.visitor.paint.StyledMapRenderer; 14 14 import org.openstreetmap.josm.data.projection.Mercator; 15 15 import org.openstreetmap.josm.gui.NavigatableComponent; … … 52 52 53 53 private static void test(int iterations, DataSet ds, Bounds bounds) throws Exception { 54 PaintVisitor visitor = new MapPaintVisitor();54 Rendering visitor = new StyledMapRenderer(g,nc,false); 55 55 nc.zoomTo(bounds); 56 visitor.setGraphics(g);57 visitor.setNavigatableComponent(nc);58 visitor.setInactive(false);59 56 for (int i=0; i<iterations; i++) { 60 visitor. visitAll(ds, true, bounds);57 visitor.render(ds, true, bounds); 61 58 } 62 59 }
Note:
See TracChangeset
for help on using the changeset viewer.