/[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 504 by alfonx, Tue Oct 27 12:57:58 2009 UTC revision 506 by alfonx, Sat Oct 31 12:15:37 2009 UTC
# Line 43  import java.awt.Graphics; Line 43  import java.awt.Graphics;
43  import java.awt.Graphics2D;  import java.awt.Graphics2D;
44  import java.awt.LayoutManager;  import java.awt.LayoutManager;
45  import java.awt.Rectangle;  import java.awt.Rectangle;
46    import java.awt.RenderingHints;
47  import java.awt.event.InputEvent;  import java.awt.event.InputEvent;
48  import java.awt.event.MouseEvent;  import java.awt.event.MouseEvent;
49  import java.awt.event.MouseListener;  import java.awt.event.MouseListener;
50  import java.awt.event.MouseMotionListener;  import java.awt.event.MouseMotionListener;
51    import java.awt.geom.AffineTransform;
52  import java.awt.image.BufferedImage;  import java.awt.image.BufferedImage;
53  import java.beans.PropertyChangeEvent;  import java.beans.PropertyChangeEvent;
54  import java.beans.PropertyChangeListener;  import java.beans.PropertyChangeListener;
# Line 111  public class JMapPane extends JPanel imp Line 113  public class JMapPane extends JPanel imp
113           */           */
114          protected Rectangle oldRect = null;          protected Rectangle oldRect = null;
115    
116          /**          /** We store the old mapArea for a moment to use it for the
117           * the last map area drawn.          "quick scaled preview" in case of ZoomOut **/
          */  
118          protected Envelope oldMapArea = null;          protected Envelope oldMapArea = null;
119    
120          /**          /**
# Line 176  public class JMapPane extends JPanel imp Line 177  public class JMapPane extends JPanel imp
177           */           */
178          private boolean panning_started = false;          private boolean panning_started = false;
179    
180            /**
181             * This color is used as the default background color when painting a map.
182             */
183            private Color mapBackgroundColor = Color.WHITE;
184    
185          public JMapPane() {          public JMapPane() {
186                  this(null, true, null, null);                  this(null, true, null, null);
187          }          }
# Line 339  public class JMapPane extends JPanel imp Line 345  public class JMapPane extends JPanel imp
345    
346                  if (changed) { /* if the map changed then redraw */                  if (changed) { /* if the map changed then redraw */
347                          changed = false;                          changed = false;
348                            
349                            // The baseImage should not have alpha
350                          baseImage = new BufferedImage(dr.width, dr.height,                          baseImage = new BufferedImage(dr.width, dr.height,
351                                          BufferedImage.TYPE_INT_ARGB);                                          BufferedImage.TYPE_INT_RGB);
352    
353                          final Graphics2D ig = baseImage.createGraphics();                          final Graphics2D ig = baseImage.createGraphics();
354                          /* System.out.println("rendering"); */                          ig.setBackground(getMapBackgroundColor());
355                            ig.fillRect(0, 0, dr.width, dr.height);
356                            
357    //                      /* System.out.println("rendering"); */
358                          if (renderer.getContext() != null)                          if (renderer.getContext() != null)
359                                  renderer.setContext(context);                                  renderer.setContext(context);
360                          labelCache.clear(); // work around anoying labelcache bug  
361                            // TODO is this clearing still needed? We already replace all that stuff whenever we change the style. Deactivated 31.10.09.. let's see
362    //                      labelCache.clear(); // work around anoying labelcache bug
363    
364                          // draw the map                          // draw the map
365                          renderer.paint((Graphics2D) ig, dr, mapArea);                          renderer.paint(ig, dr, mapArea);
366    
367                          // TODO nur machen, wenn panning beginnt                          panningImage = new BufferedImage(dr.width, dr.height, BufferedImage.TYPE_INT_RGB);
                         panningImage = new BufferedImage(dr.width, dr.height,  
                                         BufferedImage.TYPE_INT_RGB);  
368    
369                  }                  }
370    
# Line 483  public class JMapPane extends JPanel imp Line 494  public class JMapPane extends JPanel imp
494                                  final int dy = lastY - startY;                                  final int dy = lastY - startY;
495                                  // System.out.println("translate "+dx+","+dy);                                  // System.out.println("translate "+dx+","+dy);
496                                  final Graphics2D g2 = panningImage.createGraphics();                                  final Graphics2D g2 = panningImage.createGraphics();
497                                  g2.setBackground(new Color(240, 240, 240)); // TODO richtige                                  g2.setBackground(getMapBackgroundColor());
                                 // farbe? am besten  
                                 // vom L&F die  
                                 // hintergrundfarbe  
                                 // auslesen...  
498    
499                                  g2.clearRect(0, 0, this.getWidth(), this.getHeight());                                  g2.clearRect(0, 0, this.getWidth(), this.getHeight());
500                                  g2.drawImage(baseImage, dx, dy, this);                                  g2.drawImage(baseImage, dx, dy, this);
# Line 608  public class JMapPane extends JPanel imp Line 615  public class JMapPane extends JPanel imp
615                          // new edges                          // new edges
616                          final double left = mapArea.getMinX() - deltaX1;                          final double left = mapArea.getMinX() - deltaX1;
617                          final double right = mapArea.getMaxX() - deltaX1;                          final double right = mapArea.getMaxX() - deltaX1;
   
                         // now for Y  
618                          final double deltaY1 = endY - startY;                          final double deltaY1 = endY - startY;
619    
620                          // System.out.println("deltaY " + deltaY1);                          // System.out.println("deltaY " + deltaY1);
# Line 643  public class JMapPane extends JPanel imp Line 648  public class JMapPane extends JPanel imp
648                          // mapArea = fixAspectRatio(this.getBounds(), new Envelope(ll, ur));                          // mapArea = fixAspectRatio(this.getBounds(), new Envelope(ll, ur));
649                          setMapArea(bestAllowedMapArea(new Envelope(ll, ur)));                          setMapArea(bestAllowedMapArea(new Envelope(ll, ur)));
650    
                         // sk.sc  
                         // {  
                         // // SK tries to paint a preview of the zoom ;-9 aha.... well  
                         // Graphics2D graphics = (Graphics2D) JMapPane.this.getGraphics();  
                         // graphics.setRenderingHint(RenderingHints.KEY_INTERPOLATION,  
                         // RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR);  
                         // graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING,  
                         // RenderingHints.VALUE_ANTIALIAS_OFF);  
                         // graphics.setRenderingHint(RenderingHints.KEY_RENDERING,  
                         // RenderingHints.VALUE_RENDER_SPEED);  
                         // graphics.drawImage(baseImage, 0, 0, JMapPane.this.getWidth(),  
                         // JMapPane.this.getHeight(), x1, y1, x2, y2, null);  
                         // }  
                         // xulu.ec  
651                  } else if (state == JMapPane.ZoomOut) {                  } else if (state == JMapPane.ZoomOut) {
652                          drawRectangle(this.getGraphics());                          drawRectangle(this.getGraphics());
653    
# Line 721  public class JMapPane extends JPanel imp Line 712  public class JMapPane extends JPanel imp
712                  return clickable;                  return clickable;
713          }          }
714    
         //  
         // private org.geotools.styling.Style setupStyle(final int type, final Color  
         // color) {  
         // final StyleFactory sf = org.geotools.factory.CommonFactoryFinder  
         // .getStyleFactory(null);  
         // final StyleBuilder sb = new StyleBuilder();  
         //  
         // org.geotools.styling.Style s = sf.createStyle();  
         // s.setTitle("selection");  
         //  
         // // TODO parameterise the color  
         // final PolygonSymbolizer ps = sb.createPolygonSymbolizer(color);  
         // ps.setStroke(sb.createStroke(color));  
         //  
         // final LineSymbolizer ls = sb.createLineSymbolizer(color);  
         // final Graphic h = sb.createGraphic();  
         // h.setMarks(new Mark[] { sb.createMark("square", color) });  
         //  
         // final PointSymbolizer pts = sb.createPointSymbolizer(h);  
         //  
         // // Rule r = sb.createRule(new Symbolizer[]{ps,ls,pts});  
         // switch (type) {  
         // case POLYGON:  
         // s = sb.createStyle(ps);  
         //  
         // break;  
         //  
         // case POINT:  
         // s = sb.createStyle(pts);  
         //  
         // break;  
         //  
         // case LINE:  
         // s = sb.createStyle(ls);  
         // }  
         //  
         // return s;  
         // }  
   
715          public void propertyChange(final PropertyChangeEvent evt) {          public void propertyChange(final PropertyChangeEvent evt) {
716                  final String prop = evt.getPropertyName();                  final String prop = evt.getPropertyName();
717    
# Line 790  public class JMapPane extends JPanel imp Line 742  public class JMapPane extends JPanel imp
742                                          mapArea = context.getLayerBounds();                                          mapArea = context.getLayerBounds();
743                                  // xulu.ec                                  // xulu.ec
744                          } catch (final IOException e) {                          } catch (final IOException e) {
745                                  // TODO Auto-generated catch block                                  LOGGER.error(e);
                                 e.printStackTrace();  
746                          }                          }
747    
748                          reset = true;                          reset = true;
# Line 1103  public class JMapPane extends JPanel imp Line 1054  public class JMapPane extends JPanel imp
1054                  return maxExtend;                  return maxExtend;
1055          }          }
1056    
1057            /**
1058             * Set the background color of the map.
1059             * @param if <code>null</code>, white is used.
1060             */
1061            public void setMapBackgroundColor(Color bgColor) {
1062                    if (bgColor == null) bgColor = Color.WHITE;
1063                    this.mapBackgroundColor = bgColor;
1064            }
1065    
1066            /**
1067             * Returns the background {@link Color} of the map pane. Default is white.
1068            **/
1069            public Color getMapBackgroundColor() {
1070                    return mapBackgroundColor;
1071            }
1072    
1073  }  }

Legend:
Removed from v.504  
changed lines
  Added in v.506

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26