@Override public void mouseMoved(final MouseEvent e) { if (coords.size() > 2) { if (justCreated) { coords.remove(coords.size() - 1); coords.remove(coords.size() - 1); coords.add(helper.toCoord(e.getX(), e.getY())); coords.add(helper.toCoord(e.getX(), e.getY())); } else { coords.remove(coords.size() - 1); coords.add(helper.toCoord(e.getX(), e.getY())); } erase = EditionHelper.createPolygon(coords); final Geometry line = EditionHelper.createLinearRing(coords); geometry = (multipolygon) ? EditionHelper.createMultiPolygon(subGeometries) : subGeometries.get(0); try { geometry = geometry.difference(erase); } catch (TopologyException ex) { LOGGER.log(Level.INFO, ex.getLocalizedMessage()); } decoration.setGeometries(UnmodifiableArrayList.wrap(new Geometry[] {geometry, line})); return; } super.mouseMoved(e); }
/** {@inheritDoc } */ public List<Delta> getDeltas() { readLock.lock(); try { List<Delta> cp = readCopy; if (cp != null) { return cp; } } finally { readLock.unlock(); } /* * Double-check: was a deprecated practice before Java 5. * Is okay since Java 5 provided that the readCopy field * is protected by the readlock. */ writeLock.lock(); try { List<Delta> cp = readCopy; if (cp == null) { cp = UnmodifiableArrayList.wrap(deltas.toArray(new Delta[deltas.size()])); readCopy = cp; } return cp; } finally { writeLock.unlock(); } }
public Relation( final List<Member> members, final long id, final int version, final int changeset, final User user, final long timestamp, final Map<String, String> tags) { super(OSMModelConstants.DESC_RELATION, id, version, changeset, user, timestamp, tags); if (members == null || members.isEmpty()) { this.members = Collections.EMPTY_LIST; } else { this.members = UnmodifiableArrayList.wrap(members.toArray(new Member[members.size()])); } }
@Override public void mouseClicked(final MouseEvent e) { final int button = e.getButton(); if (button == MouseEvent.BUTTON1) { if (geometry == null) { setCurrentFeature(helper.grabFeature(e.getX(), e.getY(), false)); } else { if (justCreated) { justCreated = false; // we must modify the second point since two point where added at the start coords.remove(2); coords.remove(1); coords.add(helper.toCoord(e.getX(), e.getY())); coords.add(helper.toCoord(e.getX(), e.getY())); } else if (coords.isEmpty()) { justCreated = true; // this is the first point of the geometry we create // add 3 points that will be used when moving the mouse around coords.add(helper.toCoord(e.getX(), e.getY())); coords.add(helper.toCoord(e.getX(), e.getY())); coords.add(helper.toCoord(e.getX(), e.getY())); } else { justCreated = false; coords.add(helper.toCoord(e.getX(), e.getY())); } erase = EditionHelper.createPolygon(coords); final Geometry line = EditionHelper.createLinearRing(coords); geometry = (multipolygon) ? EditionHelper.createMultiPolygon(subGeometries) : subGeometries.get(0); try { geometry = geometry.difference(erase); } catch (TopologyException ex) { LOGGER.log(Level.INFO, ex.getLocalizedMessage()); } decoration.setGeometries(UnmodifiableArrayList.wrap(new Geometry[] {geometry, line})); } } else if (button == MouseEvent.BUTTON3 && feature != null) { // finish editing the feature helper.sourceModifyFeature(feature, geometry, true); reset(); } }