/[schmitzm]/trunk/src/skrueger/geotools/XMapPane.java
ViewVC logotype

Diff of /trunk/src/skrueger/geotools/XMapPane.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 306 by alfonx, Thu Jul 16 07:37:43 2009 UTC revision 307 by alfonx, Thu Aug 20 13:49:50 2009 UTC
# Line 277  public class JMapPane extends JPanel imp Line 277  public class JMapPane extends JPanel imp
277           * @param context           * @param context
278           *            - the map context to display           *            - the map context to display
279           */           */
280          public JMapPane(GTRenderer render, MapContext context) {          public JMapPane(final GTRenderer render, final MapContext context) {
281                  this(null, true, render, context);                  this(null, true, render, context);
282          }          }
283    
# Line 293  public class JMapPane extends JPanel imp Line 293  public class JMapPane extends JPanel imp
293           * @param context           * @param context
294           *            - what to draw           *            - what to draw
295           */           */
296          public JMapPane(LayoutManager layout, boolean isDoubleBuffered,          public JMapPane(final LayoutManager layout, final boolean isDoubleBuffered,
297                          GTRenderer render, MapContext context) {                          final GTRenderer render, final MapContext context) {
298                  super(layout, isDoubleBuffered);                  super(layout, isDoubleBuffered);
299    
300                  ff = (FilterFactory2) org.geotools.factory.CommonFactoryFinder                  ff = (FilterFactory2) org.geotools.factory.CommonFactoryFinder
# Line 328  public class JMapPane extends JPanel imp Line 328  public class JMapPane extends JPanel imp
328                  return renderer;                  return renderer;
329          }          }
330    
331          public void setRenderer(GTRenderer renderer) {          public void setRenderer(final GTRenderer renderer) {
332                  Map hints = new HashMap();                  Map hints = new HashMap();
333                    
334                    this.renderer = renderer;
335                    
336                  if (renderer instanceof StreamingRenderer || renderer instanceof TransitionShapefileRenderer) {                  if (renderer instanceof StreamingRenderer || renderer instanceof TransitionShapefileRenderer) {
337                          hints = renderer.getRendererHints();                          hints = renderer.getRendererHints();
338                          if (hints == null) {                          if (hints == null) {
# Line 341  public class JMapPane extends JPanel imp Line 344  public class JMapPane extends JPanel imp
344                          } else {                          } else {
345                                  hints.put(StreamingRenderer.LABEL_CACHE_KEY, labelCache);                                  hints.put(StreamingRenderer.LABEL_CACHE_KEY, labelCache);
346                          }                          }
347    
348                            hints.put("memoryPreloadingEnabled", Boolean.TRUE);
349                            
350                          renderer.setRendererHints(hints);                          renderer.setRendererHints(hints);
351                  }                  }
352    
                 this.renderer = renderer;  
353  //              this.highlightRenderer = new StreamingRenderer();  //              this.highlightRenderer = new StreamingRenderer();
354  //              this.selectionRenderer = new StreamingRenderer();  //              this.selectionRenderer = new StreamingRenderer();
355    
                 hints.put("memoryPreloadingEnabled", Boolean.FALSE);  
356  //              highlightRenderer.setRendererHints(hints);  //              highlightRenderer.setRendererHints(hints);
357  //              selectionRenderer.setRendererHints(hints);  //              selectionRenderer.setRendererHints(hints);
358                    
359    //              renderer.setRendererHints(hints);
360    
361                  if (this.context != null) {                  if (this.context != null) {
362                          this.renderer.setContext(this.context);                          this.renderer.setContext(this.context);
# Line 361  public class JMapPane extends JPanel imp Line 367  public class JMapPane extends JPanel imp
367                  return context;                  return context;
368          }          }
369    
370          public void setContext(MapContext context) {          public void setContext(final MapContext context) {
371                  if (this.context != null) {                  if (this.context != null) {
372                          this.context.removeMapLayerListListener(this);                          this.context.removeMapLayerListListener(this);
373                  }                  }
# Line 381  public class JMapPane extends JPanel imp Line 387  public class JMapPane extends JPanel imp
387                  return mapArea;                  return mapArea;
388          }          }
389    
390          public void setMapArea(Envelope mapArea) {          public void setMapArea(final Envelope mapArea) {
391                  this.mapArea = mapArea;                  this.mapArea = mapArea;
392          }          }
393    
# Line 389  public class JMapPane extends JPanel imp Line 395  public class JMapPane extends JPanel imp
395                  return state;                  return state;
396          }          }
397    
398          public void setState(int state) {          public void setState(final int state) {
399                  this.state = state;                  this.state = state;
400    
401                  // System.out.println("State: " + state);                  // System.out.println("State: " + state);
# Line 399  public class JMapPane extends JPanel imp Line 405  public class JMapPane extends JPanel imp
405                  return zoomFactor;                  return zoomFactor;
406          }          }
407    
408          public void setZoomFactor(double zoomFactor) {          public void setZoomFactor(final double zoomFactor) {
409                  this.zoomFactor = zoomFactor;                  this.zoomFactor = zoomFactor;
410          }          }
411    
# Line 407  public class JMapPane extends JPanel imp Line 413  public class JMapPane extends JPanel imp
413                  return selectionLayer;                  return selectionLayer;
414          }          }
415    
416          public void setSelectionLayer(MapLayer selectionLayer) {          public void setSelectionLayer(final MapLayer selectionLayer) {
417                  this.selectionLayer = selectionLayer;                  this.selectionLayer = selectionLayer;
418                  if (selectionManager != null) {                  if (selectionManager != null) {
419                          selectionManager.setSelectionLayer(selectionLayer);                          selectionManager.setSelectionLayer(selectionLayer);
# Line 418  public class JMapPane extends JPanel imp Line 424  public class JMapPane extends JPanel imp
424                  return highlight;                  return highlight;
425          }          }
426    
427          public void setHighlight(boolean highlight) {          public void setHighlight(final boolean highlight) {
428                  this.highlight = highlight;                  this.highlight = highlight;
429          }          }
430    
# Line 426  public class JMapPane extends JPanel imp Line 432  public class JMapPane extends JPanel imp
432                  return highlightLayer;                  return highlightLayer;
433          }          }
434    
435          public void setHighlightLayer(MapLayer highlightLayer) {          public void setHighlightLayer(final MapLayer highlightLayer) {
436                  this.highlightLayer = highlightLayer;                  this.highlightLayer = highlightLayer;
437    
438                  if (highlightManager != null) {                  if (highlightManager != null) {
# Line 438  public class JMapPane extends JPanel imp Line 444  public class JMapPane extends JPanel imp
444                  return highlightManager;                  return highlightManager;
445          }          }
446    
447          public void setHighlightManager(HighlightManager highlightManager) {          public void setHighlightManager(final HighlightManager highlightManager) {
448                  this.highlightManager = highlightManager;                  this.highlightManager = highlightManager;
449                  this.highlightManager.addHighlightChangeListener(this);                  this.highlightManager.addHighlightChangeListener(this);
450                  this.addMouseMotionListener(this.highlightManager);                  this.addMouseMotionListener(this.highlightManager);
# Line 448  public class JMapPane extends JPanel imp Line 454  public class JMapPane extends JPanel imp
454                  return lineHighlightStyle;                  return lineHighlightStyle;
455          }          }
456    
457          public void setLineHighlightStyle(Style lineHighlightStyle) {          public void setLineHighlightStyle(final Style lineHighlightStyle) {
458                  this.lineHighlightStyle = lineHighlightStyle;                  this.lineHighlightStyle = lineHighlightStyle;
459          }          }
460    
# Line 456  public class JMapPane extends JPanel imp Line 462  public class JMapPane extends JPanel imp
462                  return lineSelectionStyle;                  return lineSelectionStyle;
463          }          }
464    
465          public void setLineSelectionStyle(Style lineSelectionStyle) {          public void setLineSelectionStyle(final Style lineSelectionStyle) {
466                  this.lineSelectionStyle = lineSelectionStyle;                  this.lineSelectionStyle = lineSelectionStyle;
467          }          }
468    
# Line 464  public class JMapPane extends JPanel imp Line 470  public class JMapPane extends JPanel imp
470                  return pointHighlightStyle;                  return pointHighlightStyle;
471          }          }
472    
473          public void setPointHighlightStyle(Style pointHighlightStyle) {          public void setPointHighlightStyle(final Style pointHighlightStyle) {
474                  this.pointHighlightStyle = pointHighlightStyle;                  this.pointHighlightStyle = pointHighlightStyle;
475          }          }
476    
# Line 472  public class JMapPane extends JPanel imp Line 478  public class JMapPane extends JPanel imp
478                  return pointSelectionStyle;                  return pointSelectionStyle;
479          }          }
480    
481          public void setPointSelectionStyle(Style pointSelectionStyle) {          public void setPointSelectionStyle(final Style pointSelectionStyle) {
482                  this.pointSelectionStyle = pointSelectionStyle;                  this.pointSelectionStyle = pointSelectionStyle;
483          }          }
484    
# Line 480  public class JMapPane extends JPanel imp Line 486  public class JMapPane extends JPanel imp
486                  return polygonHighlightStyle;                  return polygonHighlightStyle;
487          }          }
488    
489          public void setPolygonHighlightStyle(Style polygonHighlightStyle) {          public void setPolygonHighlightStyle(final Style polygonHighlightStyle) {
490                  this.polygonHighlightStyle = polygonHighlightStyle;                  this.polygonHighlightStyle = polygonHighlightStyle;
491          }          }
492    
# Line 488  public class JMapPane extends JPanel imp Line 494  public class JMapPane extends JPanel imp
494                  return polygonSelectionStyle;                  return polygonSelectionStyle;
495          }          }
496    
497          public void setPolygonSelectionStyle(Style polygonSelectionStyle) {          public void setPolygonSelectionStyle(final Style polygonSelectionStyle) {
498                  this.polygonSelectionStyle = polygonSelectionStyle;                  this.polygonSelectionStyle = polygonSelectionStyle;
499          }          }
500    
501          protected void paintComponent(Graphics g) {          protected void paintComponent(final Graphics g) {
502                  super.paintComponent(g);                  super.paintComponent(g);
503    
504                  if ((renderer == null) || (mapArea == null)) {                  if ((renderer == null) || (mapArea == null)) {
505                          return;                          return;
506                  }                  }
507    
508                  Rectangle r = getBounds();                  final Rectangle r = getBounds();
509                  Rectangle dr = new Rectangle(r.width, r.height);                  final Rectangle dr = new Rectangle(r.width, r.height);
510    
511                  if (!r.equals(oldRect) || reset) {                  if (!r.equals(oldRect) || reset) {
512                          if (!r.equals(oldRect) && (mapArea == null)) {                          if (!r.equals(oldRect) && (mapArea == null)) {
513                                  try {                                  try {
514                                          mapArea = context.getLayerBounds();                                          mapArea = context.getLayerBounds();
515                                  } catch (IOException e) {                                  } catch (final IOException e) {
516                                          // TODO Auto-generated catch block                                          // TODO Auto-generated catch block
517                                          e.printStackTrace();                                          e.printStackTrace();
518                                  }                                  }
# Line 536  public class JMapPane extends JPanel imp Line 542  public class JMapPane extends JPanel imp
542                          baseImage = new BufferedImage(dr.width, dr.height,                          baseImage = new BufferedImage(dr.width, dr.height,
543                                          BufferedImage.TYPE_INT_ARGB);                                          BufferedImage.TYPE_INT_ARGB);
544    
545                          Graphics2D ig = baseImage.createGraphics();                          final Graphics2D ig = baseImage.createGraphics();
546                          /* System.out.println("rendering"); */                          /* System.out.println("rendering"); */
547                          renderer.setContext(context);                          if (renderer.getContext() != null)
548                                    renderer.setContext(context);
549                          labelCache.clear(); // work around anoying labelcache bug                          labelCache.clear(); // work around anoying labelcache bug
550    
551                          // draw the map                          // draw the map
# Line 580  public class JMapPane extends JPanel imp Line 587  public class JMapPane extends JPanel imp
587                          selectImage = new BufferedImage(dr.width, dr.height,                          selectImage = new BufferedImage(dr.width, dr.height,
588                                          BufferedImage.TYPE_INT_ARGB);                                          BufferedImage.TYPE_INT_ARGB);
589    
590                          Graphics2D ig = selectImage.createGraphics();                          final Graphics2D ig = selectImage.createGraphics();
591                          /* System.out.println("rendering selection"); */                          /* System.out.println("rendering selection"); */
592                          selectionRenderer.paint((Graphics2D) ig, dr, mapArea);                          selectionRenderer.paint((Graphics2D) ig, dr, mapArea);
593    
# Line 610  public class JMapPane extends JPanel imp Line 617  public class JMapPane extends JPanel imp
617                                  highlightStyle = lineHighlightStyle;                                  highlightStyle = lineHighlightStyle;
618                          }                          }
619    
620                          MapContext highlightContext = new DefaultMapContext(                          final MapContext highlightContext = new DefaultMapContext(
621                                          DefaultGeographicCRS.WGS84);                                          DefaultGeographicCRS.WGS84);
622    
623                          highlightContext.addLayer(highlightFeature, highlightStyle);                          highlightContext.addLayer(highlightFeature, highlightStyle);
# Line 621  public class JMapPane extends JPanel imp Line 628  public class JMapPane extends JPanel imp
628                  }                  }
629          }          }
630    
631          private Envelope fixAspectRatio(Rectangle r, Envelope mapArea) {          private Envelope fixAspectRatio(final Rectangle r, final Envelope mapArea) {
632    
633                  double mapWidth = mapArea.getWidth(); /* get the extent of the map */                  final double mapWidth = mapArea.getWidth(); /* get the extent of the map */
634                  double mapHeight = mapArea.getHeight();                  final double mapHeight = mapArea.getHeight();
635                  double scaleX = r.getWidth() / mapArea.getWidth(); /*                  final double scaleX = r.getWidth() / mapArea.getWidth(); /*
636                                                                                                                           * calculate the new                                                                                                                           * calculate the new
637                                                                                                                           * scale                                                                                                                           * scale
638                                                                                                                           */                                                                                                                           */
639    
640                  double scaleY = r.getHeight() / mapArea.getHeight();                  final double scaleY = r.getHeight() / mapArea.getHeight();
641                  double scale = 1.0; // stupid compiler!                  double scale = 1.0; // stupid compiler!
642    
643                  if (scaleX < scaleY) { /* pick the smaller scale */                  if (scaleX < scaleY) { /* pick the smaller scale */
# Line 640  public class JMapPane extends JPanel imp Line 647  public class JMapPane extends JPanel imp
647                  }                  }
648    
649                  /* calculate the difference in width and height of the new extent */                  /* calculate the difference in width and height of the new extent */
650                  double deltaX = /* Math.abs */((r.getWidth() / scale) - mapWidth);                  final double deltaX = /* Math.abs */((r.getWidth() / scale) - mapWidth);
651                  double deltaY = /* Math.abs */((r.getHeight() / scale) - mapHeight);                  final double deltaY = /* Math.abs */((r.getHeight() / scale) - mapHeight);
652    
653                  /*                  /*
654                   * System.out.println("delta x " + deltaX);                   * System.out.println("delta x " + deltaX);
# Line 649  public class JMapPane extends JPanel imp Line 656  public class JMapPane extends JPanel imp
656                   */                   */
657    
658                  /* create the new extent */                  /* create the new extent */
659                  Coordinate ll = new Coordinate(mapArea.getMinX() - (deltaX / 2.0),                  final Coordinate ll = new Coordinate(mapArea.getMinX() - (deltaX / 2.0),
660                                  mapArea.getMinY() - (deltaY / 2.0));                                  mapArea.getMinY() - (deltaY / 2.0));
661                  Coordinate ur = new Coordinate(mapArea.getMaxX() + (deltaX / 2.0),                  final Coordinate ur = new Coordinate(mapArea.getMaxX() + (deltaX / 2.0),
662                                  mapArea.getMaxY() + (deltaY / 2.0));                                  mapArea.getMaxY() + (deltaY / 2.0));
663    
664                  return new Envelope(ll, ur);                  return new Envelope(ll, ur);
665          }          }
666    
667          public void doSelection(double x, double y, MapLayer layer) {          public void doSelection(final double x, final double y, final MapLayer layer) {
668    
669                  Geometry geometry = gf.createPoint(new Coordinate(x, y));                  final Geometry geometry = gf.createPoint(new Coordinate(x, y));
670    
671                  // org.opengis.geometry.Geometry geometry = new Point();                  // org.opengis.geometry.Geometry geometry = new Point();
672    
# Line 674  public class JMapPane extends JPanel imp Line 681  public class JMapPane extends JPanel imp
681           *            - the index of the layer to search           *            - the index of the layer to search
682           * @throws IndexOutOfBoundsException           * @throws IndexOutOfBoundsException
683           */           */
684          private void findFeature(Geometry geometry, MapLayer layer)          private void findFeature(final Geometry geometry, final MapLayer layer)
685                          throws IndexOutOfBoundsException {                          throws IndexOutOfBoundsException {
686                  org.opengis.filter.spatial.BinarySpatialOperator f = null;                  org.opengis.filter.spatial.BinarySpatialOperator f = null;
687    
# Line 697  public class JMapPane extends JPanel imp Line 704  public class JMapPane extends JPanel imp
704                                          selectionManager.selectionChanged(this, f);                                          selectionManager.selectionChanged(this, f);
705    
706                                  }                                  }
707                          } catch (IllegalFilterException e) {                          } catch (final IllegalFilterException e) {
708                                  // TODO Auto-generated catch block                                  // TODO Auto-generated catch block
709                                  e.printStackTrace();                                  e.printStackTrace();
710                          }                          }
# Line 726  public class JMapPane extends JPanel imp Line 733  public class JMapPane extends JPanel imp
733                           * = (Feature) fi.next(); System.out.println("selected " +                           * = (Feature) fi.next(); System.out.println("selected " +
734                           * feat.getAttribute("STATE_NAME")); }                           * feat.getAttribute("STATE_NAME")); }
735                           */                           */
736                  } catch (IllegalFilterException e) {                  } catch (final IllegalFilterException e) {
737                          // TODO Auto-generated catch block                          // TODO Auto-generated catch block
738                          e.printStackTrace();                          e.printStackTrace();
739                  }                  }
740                  return;                  return;
741          }          }
742    
743          public void mouseClicked(MouseEvent e) {          public void mouseClicked(final MouseEvent e) {
744                  if (mapArea == null) return;                  if (mapArea == null) return;
745                  // System.out.println("before area "+mapArea+"\nw:"+mapArea.getWidth()+"                  // System.out.println("before area "+mapArea+"\nw:"+mapArea.getWidth()+"
746                  // h:"+mapArea.getHeight());                  // h:"+mapArea.getHeight());
747                  Rectangle bounds = this.getBounds();                  final Rectangle bounds = this.getBounds();
748                  double x = (double) (e.getX());                  final double x = (double) (e.getX());
749                  double y = (double) (e.getY());                  final double y = (double) (e.getY());
750                  double width = mapArea.getWidth();                  final double width = mapArea.getWidth();
751                  double height = mapArea.getHeight();                  final double height = mapArea.getHeight();
752                  // xulu.sc                  // xulu.sc
753                  // double width2 = mapArea.getWidth() / 2.0;                  // double width2 = mapArea.getWidth() / 2.0;
754                  // double height2 = mapArea.getHeight() / 2.0;                  // double height2 = mapArea.getHeight() / 2.0;
755                  double width2 = width / 2.0;                  final double width2 = width / 2.0;
756                  double height2 = height / 2.0;                  final double height2 = height / 2.0;
757                  // xulu.ec                  // xulu.ec
758                  double mapX = ((x * width) / (double) bounds.width) + mapArea.getMinX();                  final double mapX = ((x * width) / (double) bounds.width) + mapArea.getMinX();
759                  double mapY = (((bounds.getHeight() - y) * height) / (double) bounds.height)                  final double mapY = (((bounds.getHeight() - y) * height) / (double) bounds.height)
760                                  + mapArea.getMinY();                                  + mapArea.getMinY();
761    
762                  /*                  /*
# Line 789  public class JMapPane extends JPanel imp Line 796  public class JMapPane extends JPanel imp
796                          return;                          return;
797                  }                  }
798    
799                  Coordinate ll = new Coordinate(mapX - (width2 / zlevel), mapY                  final Coordinate ll = new Coordinate(mapX - (width2 / zlevel), mapY
800                                  - (height2 / zlevel));                                  - (height2 / zlevel));
801                  Coordinate ur = new Coordinate(mapX + (width2 / zlevel), mapY                  final Coordinate ur = new Coordinate(mapX + (width2 / zlevel), mapY
802                                  + (height2 / zlevel));                                  + (height2 / zlevel));
803                  // xulu.sc SK: Check for min/max scale                  // xulu.sc SK: Check for min/max scale
804                  // mapArea = new Envelope(ll, ur);                  // mapArea = new Envelope(ll, ur);
# Line 806  public class JMapPane extends JPanel imp Line 813  public class JMapPane extends JPanel imp
813                  repaint();                  repaint();
814          }          }
815    
816          public void mouseEntered(MouseEvent e) {          public void mouseEntered(final MouseEvent e) {
817          }          }
818    
819          public void mouseExited(MouseEvent e) {          public void mouseExited(final MouseEvent e) {
820          }          }
821    
822          public void mousePressed(MouseEvent e) {          public void mousePressed(final MouseEvent e) {
823                  startX = e.getX();                  startX = e.getX();
824                  startY = e.getY();                  startY = e.getY();
825                  lastX = 0;                  lastX = 0;
826                  lastY = 0;                  lastY = 0;
827          }          }
828    
829          public void mouseReleased(MouseEvent e) {          public void mouseReleased(final MouseEvent e) {
830                  int endX = e.getX();                  final int endX = e.getX();
831                  int endY = e.getY();                  final int endY = e.getY();
832    
833                  processDrag(startX, startY, endX, endY, e);                  processDrag(startX, startY, endX, endY, e);
834                  lastX = 0;                  lastX = 0;
# Line 833  public class JMapPane extends JPanel imp Line 840  public class JMapPane extends JPanel imp
840                  panning_started = false;                  panning_started = false;
841          }          }
842    
843          public void mouseDragged(MouseEvent e) {          public void mouseDragged(final MouseEvent e) {
844                  Graphics graphics = this.getGraphics();                  final Graphics graphics = this.getGraphics();
845                  int x = e.getX();                  final int x = e.getX();
846                  int y = e.getY();                  final int y = e.getY();
847    
848                  if ((state == JMapPane.Pan)                  if ((state == JMapPane.Pan)
849                                  || ((e.getModifiersEx() & InputEvent.BUTTON3_DOWN_MASK) != 0)) {                                  || ((e.getModifiersEx() & InputEvent.BUTTON3_DOWN_MASK) != 0)) {
# Line 850  public class JMapPane extends JPanel imp Line 857  public class JMapPane extends JPanel imp
857    
858                          // move the image with the mouse                          // move the image with the mouse
859                          if ((lastX > 0) && (lastY > 0)) {                          if ((lastX > 0) && (lastY > 0)) {
860                                  int dx = lastX - startX;                                  final int dx = lastX - startX;
861                                  int dy = lastY - startY;                                  final int dy = lastY - startY;
862                                  // System.out.println("translate "+dx+","+dy);                                  // System.out.println("translate "+dx+","+dy);
863                                  final Graphics2D g2 = panningImage.createGraphics();                                  final Graphics2D g2 = panningImage.createGraphics();
864                                  g2.setBackground(new Color(240, 240, 240)); // TODO richtige                                  g2.setBackground(new Color(240, 240, 240)); // TODO richtige
# Line 884  public class JMapPane extends JPanel imp Line 891  public class JMapPane extends JPanel imp
891                  } else if (state == JMapPane.Select && selectionLayer != null) {                  } else if (state == JMapPane.Select && selectionLayer != null) {
892    
893                          // construct a new bbox filter                          // construct a new bbox filter
894                          Rectangle bounds = this.getBounds();                          final Rectangle bounds = this.getBounds();
895    
896                          double mapWidth = mapArea.getWidth();                          final double mapWidth = mapArea.getWidth();
897                          double mapHeight = mapArea.getHeight();                          final double mapHeight = mapArea.getHeight();
898    
899                          double x1 = ((this.startX * mapWidth) / (double) bounds.width)                          final double x1 = ((this.startX * mapWidth) / (double) bounds.width)
900                                          + mapArea.getMinX();                                          + mapArea.getMinX();
901                          double y1 = (((bounds.getHeight() - this.startY) * mapHeight) / (double) bounds.height)                          final double y1 = (((bounds.getHeight() - this.startY) * mapHeight) / (double) bounds.height)
902                                          + mapArea.getMinY();                                          + mapArea.getMinY();
903                          double x2 = ((x * mapWidth) / (double) bounds.width)                          final double x2 = ((x * mapWidth) / (double) bounds.width)
904                                          + mapArea.getMinX();                                          + mapArea.getMinX();
905                          double y2 = (((bounds.getHeight() - y) * mapHeight) / (double) bounds.height)                          final double y2 = (((bounds.getHeight() - y) * mapHeight) / (double) bounds.height)
906                                          + mapArea.getMinY();                                          + mapArea.getMinY();
907                          double left = Math.min(x1, x2);                          final double left = Math.min(x1, x2);
908                          double right = Math.max(x1, x2);                          final double right = Math.max(x1, x2);
909                          double bottom = Math.min(y1, y2);                          final double bottom = Math.min(y1, y2);
910                          double top = Math.max(y1, y2);                          final double top = Math.max(y1, y2);
911    
912                          String name = selectionLayer.getFeatureSource().getSchema()                          String name = selectionLayer.getFeatureSource().getSchema()
913                                          .getDefaultGeometry().getName();                                          .getDefaultGeometry().getName();
# Line 908  public class JMapPane extends JPanel imp Line 915  public class JMapPane extends JPanel imp
915                          if (name == "") {                          if (name == "") {
916                                  name = "the_geom";                                  name = "the_geom";
917                          }                          }
918                          Filter bb = ff.bbox(ff.property(name), left, bottom, right, top,                          final Filter bb = ff.bbox(ff.property(name), left, bottom, right, top,
919                                          getContext().getCoordinateReferenceSystem().toString());                                          getContext().getCoordinateReferenceSystem().toString());
920                          if (selectionManager != null) {                          if (selectionManager != null) {
921                                  selectionManager.selectionChanged(this, bb);                                  selectionManager.selectionChanged(this, bb);
# Line 932  public class JMapPane extends JPanel imp Line 939  public class JMapPane extends JPanel imp
939          // private void processDrag(int x1, int y1, int x2, int y2) {          // private void processDrag(int x1, int y1, int x2, int y2) {
940          // sk.ce          // sk.ce
941          protected void processDrag(final int x1, final int y1, final int x2,          protected void processDrag(final int x1, final int y1, final int x2,
942                          final int y2, MouseEvent e) {                          final int y2, final MouseEvent e) {
943    
944                  /****                  /****
945                   * If no layer is availabe we dont want a NullPointerException                   * If no layer is availabe we dont want a NullPointerException
# Line 951  public class JMapPane extends JPanel imp Line 958  public class JMapPane extends JPanel imp
958                          return;                          return;
959                  }                  }
960    
961                  Rectangle bounds = this.getBounds();                  final Rectangle bounds = this.getBounds();
962    
963                  double mapWidth = mapArea.getWidth();                  final double mapWidth = mapArea.getWidth();
964                  double mapHeight = mapArea.getHeight();                  final double mapHeight = mapArea.getHeight();
965    
966                  double startX = ((x1 * mapWidth) / (double) bounds.width)                  final double startX = ((x1 * mapWidth) / (double) bounds.width)
967                                  + mapArea.getMinX();                                  + mapArea.getMinX();
968                  double startY = (((bounds.getHeight() - y1) * mapHeight) / (double) bounds.height)                  final double startY = (((bounds.getHeight() - y1) * mapHeight) / (double) bounds.height)
969                                  + mapArea.getMinY();                                  + mapArea.getMinY();
970                  double endX = ((x2 * mapWidth) / (double) bounds.width)                  final double endX = ((x2 * mapWidth) / (double) bounds.width)
971                                  + mapArea.getMinX();                                  + mapArea.getMinX();
972                  double endY = (((bounds.getHeight() - y2) * mapHeight) / (double) bounds.height)                  final double endY = (((bounds.getHeight() - y2) * mapHeight) / (double) bounds.height)
973                                  + mapArea.getMinY();                                  + mapArea.getMinY();
974    
975                  if ((state == JMapPane.Pan) || (e.getButton() == MouseEvent.BUTTON3)) {                  if ((state == JMapPane.Pan) || (e.getButton() == MouseEvent.BUTTON3)) {
976                          // move the image with the mouse                          // move the image with the mouse
977                          // calculate X offsets from start point to the end Point                          // calculate X offsets from start point to the end Point
978                          double deltaX1 = endX - startX;                          final double deltaX1 = endX - startX;
979    
980                          // System.out.println("deltaX " + deltaX1);                          // System.out.println("deltaX " + deltaX1);
981                          // new edges                          // new edges
982                          double left = mapArea.getMinX() - deltaX1;                          final double left = mapArea.getMinX() - deltaX1;
983                          double right = mapArea.getMaxX() - deltaX1;                          final double right = mapArea.getMaxX() - deltaX1;
984    
985                          // now for Y                          // now for Y
986                          double deltaY1 = endY - startY;                          final double deltaY1 = endY - startY;
987    
988                          // System.out.println("deltaY " + deltaY1);                          // System.out.println("deltaY " + deltaY1);
989                          double bottom = mapArea.getMinY() - deltaY1;                          final double bottom = mapArea.getMinY() - deltaY1;
990                          double top = mapArea.getMaxY() - deltaY1;                          final double top = mapArea.getMaxY() - deltaY1;
991                          Coordinate ll = new Coordinate(left, bottom);                          final Coordinate ll = new Coordinate(left, bottom);
992                          Coordinate ur = new Coordinate(right, top);                          final Coordinate ur = new Coordinate(right, top);
993                          // xulu.sc                          // xulu.sc
994                          // mapArea = fixAspectRatio(this.getBounds(), new Envelope(ll, ur));                          // mapArea = fixAspectRatio(this.getBounds(), new Envelope(ll, ur));
995                          setMapArea(fixAspectRatio(this.getBounds(), new Envelope(ll, ur)));                          setMapArea(fixAspectRatio(this.getBounds(), new Envelope(ll, ur)));
# Line 997  public class JMapPane extends JPanel imp Line 1004  public class JMapPane extends JPanel imp
1004    
1005                          drawRectangle(this.getGraphics());                          drawRectangle(this.getGraphics());
1006                          // make the dragged rectangle (in map coords) the new BBOX                          // make the dragged rectangle (in map coords) the new BBOX
1007                          double left = Math.min(startX, endX);                          final double left = Math.min(startX, endX);
1008                          double right = Math.max(startX, endX);                          final double right = Math.max(startX, endX);
1009                          double bottom = Math.min(startY, endY);                          final double bottom = Math.min(startY, endY);
1010                          double top = Math.max(startY, endY);                          final double top = Math.max(startY, endY);
1011                          Coordinate ll = new Coordinate(left, bottom);                          final Coordinate ll = new Coordinate(left, bottom);
1012                          Coordinate ur = new Coordinate(right, top);                          final Coordinate ur = new Coordinate(right, top);
1013                          // xulu.sc                          // xulu.sc
1014    
1015                          // mapArea = fixAspectRatio(this.getBounds(), new Envelope(ll, ur));                          // mapArea = fixAspectRatio(this.getBounds(), new Envelope(ll, ur));
# Line 1026  public class JMapPane extends JPanel imp Line 1033  public class JMapPane extends JPanel imp
1033                          drawRectangle(this.getGraphics());                          drawRectangle(this.getGraphics());
1034    
1035                          // make the dragged rectangle in screen coords the new map size?                          // make the dragged rectangle in screen coords the new map size?
1036                          double left = Math.min(startX, endX);                          final double left = Math.min(startX, endX);
1037                          double right = Math.max(startX, endX);                          final double right = Math.max(startX, endX);
1038                          double bottom = Math.min(startY, endY);                          final double bottom = Math.min(startY, endY);
1039                          double top = Math.max(startY, endY);                          final double top = Math.max(startY, endY);
1040                          double nWidth = (mapWidth * mapWidth) / (right - left);                          final double nWidth = (mapWidth * mapWidth) / (right - left);
1041                          double nHeight = (mapHeight * mapHeight) / (top - bottom);                          final double nHeight = (mapHeight * mapHeight) / (top - bottom);
1042                          double deltaX1 = left - mapArea.getMinX();                          final double deltaX1 = left - mapArea.getMinX();
1043                          double nDeltaX1 = (deltaX1 * nWidth) / mapWidth;                          final double nDeltaX1 = (deltaX1 * nWidth) / mapWidth;
1044                          double deltaY1 = bottom - mapArea.getMinY();                          final double deltaY1 = bottom - mapArea.getMinY();
1045                          double nDeltaY1 = (deltaY1 * nHeight) / mapHeight;                          final double nDeltaY1 = (deltaY1 * nHeight) / mapHeight;
1046                          Coordinate ll = new Coordinate(mapArea.getMinX() - nDeltaX1,                          final Coordinate ll = new Coordinate(mapArea.getMinX() - nDeltaX1,
1047                                          mapArea.getMinY() - nDeltaY1);                                          mapArea.getMinY() - nDeltaY1);
1048                          double deltaX2 = mapArea.getMaxX() - right;                          final double deltaX2 = mapArea.getMaxX() - right;
1049                          double nDeltaX2 = (deltaX2 * nWidth) / mapWidth;                          final double nDeltaX2 = (deltaX2 * nWidth) / mapWidth;
1050                          double deltaY2 = mapArea.getMaxY() - top;                          final double deltaY2 = mapArea.getMaxY() - top;
1051                          double nDeltaY2 = (deltaY2 * nHeight) / mapHeight;                          final double nDeltaY2 = (deltaY2 * nHeight) / mapHeight;
1052                          Coordinate ur = new Coordinate(mapArea.getMaxX() + nDeltaX2,                          final Coordinate ur = new Coordinate(mapArea.getMaxX() + nDeltaX2,
1053                                          mapArea.getMaxY() + nDeltaY2);                                          mapArea.getMaxY() + nDeltaY2);
1054                          // xulu.sc                          // xulu.sc
1055                          // mapArea = fixAspectRatio(this.getBounds(), new Envelope(ll, ur));                          // mapArea = fixAspectRatio(this.getBounds(), new Envelope(ll, ur));
# Line 1050  public class JMapPane extends JPanel imp Line 1057  public class JMapPane extends JPanel imp
1057    
1058                          // xulu.ec                          // xulu.ec
1059                  } else if (state == JMapPane.Select && selectionLayer != null) {                  } else if (state == JMapPane.Select && selectionLayer != null) {
1060                          double left = Math.min(startX, endX);                          final double left = Math.min(startX, endX);
1061                          double right = Math.max(startX, endX);                          final double right = Math.max(startX, endX);
1062                          double bottom = Math.min(startY, endY);                          final double bottom = Math.min(startY, endY);
1063                          double top = Math.max(startY, endY);                          final double top = Math.max(startY, endY);
1064    
1065                          String name = selectionLayer.getFeatureSource().getSchema()                          String name = selectionLayer.getFeatureSource().getSchema()
1066                                          .getDefaultGeometry().getLocalName();                                          .getDefaultGeometry().getLocalName();
# Line 1061  public class JMapPane extends JPanel imp Line 1068  public class JMapPane extends JPanel imp
1068                          if (name == "") {                          if (name == "") {
1069                                  name = "the_geom";                                  name = "the_geom";
1070                          }                          }
1071                          Filter bb = ff.bbox(ff.property(name), left, bottom, right, top,                          final Filter bb = ff.bbox(ff.property(name), left, bottom, right, top,
1072                                          getContext().getCoordinateReferenceSystem().toString());                                          getContext().getCoordinateReferenceSystem().toString());
1073                          // System.out.println(bb.toString());                          // System.out.println(bb.toString());
1074                          if (selectionManager != null) {                          if (selectionManager != null) {
# Line 1084  public class JMapPane extends JPanel imp Line 1091  public class JMapPane extends JPanel imp
1091                  return clickable;                  return clickable;
1092          }          }
1093    
1094          private org.geotools.styling.Style setupStyle(int type, Color color) {          private org.geotools.styling.Style setupStyle(final int type, final Color color) {
1095                  StyleFactory sf = org.geotools.factory.CommonFactoryFinder                  final StyleFactory sf = org.geotools.factory.CommonFactoryFinder
1096                                  .getStyleFactory(null);                                  .getStyleFactory(null);
1097                  StyleBuilder sb = new StyleBuilder();                  final StyleBuilder sb = new StyleBuilder();
1098    
1099                  org.geotools.styling.Style s = sf.createStyle();                  org.geotools.styling.Style s = sf.createStyle();
1100                  s.setTitle("selection");                  s.setTitle("selection");
1101    
1102                  // TODO parameterise the color                  // TODO parameterise the color
1103                  PolygonSymbolizer ps = sb.createPolygonSymbolizer(color);                  final PolygonSymbolizer ps = sb.createPolygonSymbolizer(color);
1104                  ps.setStroke(sb.createStroke(color));                  ps.setStroke(sb.createStroke(color));
1105    
1106                  LineSymbolizer ls = sb.createLineSymbolizer(color);                  final LineSymbolizer ls = sb.createLineSymbolizer(color);
1107                  Graphic h = sb.createGraphic();                  final Graphic h = sb.createGraphic();
1108                  h.setMarks(new Mark[] { sb.createMark("square", color) });                  h.setMarks(new Mark[] { sb.createMark("square", color) });
1109    
1110                  PointSymbolizer pts = sb.createPointSymbolizer(h);                  final PointSymbolizer pts = sb.createPointSymbolizer(h);
1111    
1112                  // Rule r = sb.createRule(new Symbolizer[]{ps,ls,pts});                  // Rule r = sb.createRule(new Symbolizer[]{ps,ls,pts});
1113                  switch (type) {                  switch (type) {
# Line 1121  public class JMapPane extends JPanel imp Line 1128  public class JMapPane extends JPanel imp
1128                  return s;                  return s;
1129          }          }
1130    
1131          public void highlightChanged(HighlightChangedEvent e) {          public void highlightChanged(final HighlightChangedEvent e) {
1132                  org.opengis.filter.Filter f = e.getFilter();                  final org.opengis.filter.Filter f = e.getFilter();
1133    
1134                  try {                  try {
1135                          highlightFeature = highlightLayer.getFeatureSource().getFeatures(f);                          highlightFeature = highlightLayer.getFeatureSource().getFeatures(f);
1136                  } catch (IOException e1) {                  } catch (final IOException e1) {
1137                          // TODO Auto-generated catch block                          // TODO Auto-generated catch block
1138                          e1.printStackTrace();                          e1.printStackTrace();
1139                  }                  }
# Line 1134  public class JMapPane extends JPanel imp Line 1141  public class JMapPane extends JPanel imp
1141                  repaint();                  repaint();
1142          }          }
1143    
1144          public void propertyChange(PropertyChangeEvent evt) {          public void propertyChange(final PropertyChangeEvent evt) {
1145                  String prop = evt.getPropertyName();                  final String prop = evt.getPropertyName();
1146    
1147                  if (prop.equalsIgnoreCase("crs")) {                  if (prop.equalsIgnoreCase("crs")) {
1148                          context.setAreaOfInterest(context.getAreaOfInterest(),                          context.setAreaOfInterest(context.getAreaOfInterest(),
# Line 1147  public class JMapPane extends JPanel imp Line 1154  public class JMapPane extends JPanel imp
1154                  return reset;                  return reset;
1155          }          }
1156    
1157          public void setReset(boolean reset) {          public void setReset(final boolean reset) {
1158                  this.reset = reset;                  this.reset = reset;
1159          }          }
1160    
1161          public void layerAdded(MapLayerListEvent event) {          public void layerAdded(final MapLayerListEvent event) {
1162                  changed = true;                  changed = true;
1163    
1164                  if (context.getLayers().length == 1) { // the first one                  if (context.getLayers().length == 1) { // the first one
# Line 1163  public class JMapPane extends JPanel imp Line 1170  public class JMapPane extends JPanel imp
1170                                  if (mapArea == null)                                  if (mapArea == null)
1171                                          mapArea = context.getLayerBounds();                                          mapArea = context.getLayerBounds();
1172                                  // xulu.ec                                  // xulu.ec
1173                          } catch (IOException e) {                          } catch (final IOException e) {
1174                                  // TODO Auto-generated catch block                                  // TODO Auto-generated catch block
1175                                  e.printStackTrace();                                  e.printStackTrace();
1176                          }                          }
# Line 1174  public class JMapPane extends JPanel imp Line 1181  public class JMapPane extends JPanel imp
1181                  repaint();                  repaint();
1182          }          }
1183    
1184          public void layerRemoved(MapLayerListEvent event) {          public void layerRemoved(final MapLayerListEvent event) {
1185                  changed = true;                  changed = true;
1186                  repaint();                  repaint();
1187          }          }
1188    
1189          public void layerChanged(MapLayerListEvent event) {          public void layerChanged(final MapLayerListEvent event) {
1190                  changed = true;                  changed = true;
1191                  // System.out.println("layer changed - repaint");                  // System.out.println("layer changed - repaint");
1192                  repaint();                  repaint();
1193          }          }
1194    
1195          public void layerMoved(MapLayerListEvent event) {          public void layerMoved(final MapLayerListEvent event) {
1196                  changed = true;                  changed = true;
1197                  repaint();                  repaint();
1198          }          }
1199    
1200          protected void drawRectangle(Graphics graphics) {          protected void drawRectangle(final Graphics graphics) {
1201                  // undraw last box/draw new box                  // undraw last box/draw new box
1202                  int left = Math.min(startX, lastX);                  final int left = Math.min(startX, lastX);
1203                  int right = Math.max(startX, lastX);                  final int right = Math.max(startX, lastX);
1204                  int top = Math.max(startY, lastY);                  final int top = Math.max(startY, lastY);
1205                  int bottom = Math.min(startY, lastY);                  final int bottom = Math.min(startY, lastY);
1206                  int width = right - left;                  final int width = right - left;
1207                  int height = top - bottom;                  final int height = top - bottom;
1208                  // System.out.println("drawing rect("+left+","+bottom+","+ width+","+                  // System.out.println("drawing rect("+left+","+bottom+","+ width+","+
1209                  // height+")");                  // height+")");
1210                  graphics.drawRect(left, bottom, width, height);                  graphics.drawRect(left, bottom, width, height);
# Line 1209  public class JMapPane extends JPanel imp Line 1216  public class JMapPane extends JPanel imp
1216           *           *
1217           * @param clickable           * @param clickable
1218           */           */
1219          public void setClickable(boolean clickable) {          public void setClickable(final boolean clickable) {
1220                  this.clickable = clickable;                  this.clickable = clickable;
1221          }          }
1222    
1223          public void mouseMoved(MouseEvent e) {          public void mouseMoved(final MouseEvent e) {
1224          }          }
1225    
1226          public FeatureCollection getSelection() {          public FeatureCollection getSelection() {
1227                  return selection;                  return selection;
1228          }          }
1229    
1230          public void setSelection(FeatureCollection selection) {          public void setSelection(final FeatureCollection selection) {
1231                  this.selection = selection;                  this.selection = selection;
1232                  repaint();                  repaint();
1233          }          }
# Line 1232  public class JMapPane extends JPanel imp Line 1239  public class JMapPane extends JPanel imp
1239           * org.geotools.gui.swing.event.SelectionChangeListener#selectionChanged           * org.geotools.gui.swing.event.SelectionChangeListener#selectionChanged
1240           * (org.geotools.gui.swing.event.SelectionChangedEvent)           * (org.geotools.gui.swing.event.SelectionChangedEvent)
1241           */           */
1242          public void selectionChanged(SelectionChangedEvent e) {          public void selectionChanged(final SelectionChangedEvent e) {
1243    
1244                  try {                  try {
1245                          selection = selectionLayer.getFeatureSource().getFeatures(                          selection = selectionLayer.getFeatureSource().getFeatures(
1246                                          e.getFilter());                                          e.getFilter());
1247                          repaint();                          repaint();
1248                  } catch (IOException e1) {                  } catch (final IOException e1) {
1249                          e1.printStackTrace();                          e1.printStackTrace();
1250                  }                  }
1251          }          }
# Line 1247  public class JMapPane extends JPanel imp Line 1254  public class JMapPane extends JPanel imp
1254                  return selectionManager;                  return selectionManager;
1255          }          }
1256    
1257          public void setSelectionManager(SelectionManager selectionManager) {          public void setSelectionManager(final SelectionManager selectionManager) {
1258                  this.selectionManager = selectionManager;                  this.selectionManager = selectionManager;
1259                  this.selectionManager.addSelectionChangeListener(this);                  this.selectionManager.addSelectionChangeListener(this);
1260    
# Line 1277  public class JMapPane extends JPanel imp Line 1284  public class JMapPane extends JPanel imp
1284                   */                   */
1285                  env = fixAspectRatio(this.getBounds(), env);                  env = fixAspectRatio(this.getBounds(), env);
1286    
1287                  double scale = env.getWidth() / getWidth();                  final double scale = env.getWidth() / getWidth();
1288                  double centerX = env.getMinX() + env.getWidth() / 2.;                  final double centerX = env.getMinX() + env.getWidth() / 2.;
1289                  double centerY = env.getMinY() + env.getHeight() / 2.;                  final double centerY = env.getMinY() + env.getHeight() / 2.;
1290                  double newWidth2;                  double newWidth2;
1291                  double newHeight2;                  double newHeight2;
1292                  if (scale < getMaxZoomScale()) {                  if (scale < getMaxZoomScale()) {
# Line 1301  public class JMapPane extends JPanel imp Line 1308  public class JMapPane extends JPanel imp
1308                          return env;                          return env;
1309                  }                  }
1310    
1311                  Coordinate ll = new Coordinate(centerX - newWidth2, centerY                  final Coordinate ll = new Coordinate(centerX - newWidth2, centerY
1312                                  - newHeight2);                                  - newHeight2);
1313                  Coordinate ur = new Coordinate(centerX + newWidth2, centerY                  final Coordinate ur = new Coordinate(centerX + newWidth2, centerY
1314                                  + newHeight2);                                  + newHeight2);
1315    
1316                  return new Envelope(ll, ur);                  return new Envelope(ll, ur);
# Line 1338  public class JMapPane extends JPanel imp Line 1345  public class JMapPane extends JPanel imp
1345           * @author <a href="mailto:[email protected]">Stefan Alfons           * @author <a href="mailto:[email protected]">Stefan Alfons
1346           *         Kr&uuml;ger</a>           *         Kr&uuml;ger</a>
1347           */           */
1348          public void setMaxZoomScale(Double maxZoomScale) {          public void setMaxZoomScale(final Double maxZoomScale) {
1349                  // System.out.println("setting max scale to "+maxZoomScale);                  // System.out.println("setting max scale to "+maxZoomScale);
1350                  this.maxZoomScale = maxZoomScale;                  this.maxZoomScale = maxZoomScale;
1351          }          }
# Line 1350  public class JMapPane extends JPanel imp Line 1357  public class JMapPane extends JPanel imp
1357           * @author <a href="mailto:[email protected]">Stefan Alfons           * @author <a href="mailto:[email protected]">Stefan Alfons
1358           *         Kr&uuml;ger</a>           *         Kr&uuml;ger</a>
1359           */           */
1360          public void setMinZoomScale(Double minZoomScale) {          public void setMinZoomScale(final Double minZoomScale) {
1361                  this.minZoomScale = minZoomScale;                  this.minZoomScale = minZoomScale;
1362          }          }
1363          // xulu.en          // xulu.en

Legend:
Removed from v.306  
changed lines
  Added in v.307

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26