/[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 505 by alfonx, Sat Oct 31 10:53:43 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 176  public class JMapPane extends JPanel imp Line 178  public class JMapPane extends JPanel imp
178           */           */
179          private boolean panning_started = false;          private boolean panning_started = false;
180    
181            /**
182             * This color is used as the default background color when painting a map.
183             */
184            private Color mapBackgroundColor = Color.WHITE;
185    
186          public JMapPane() {          public JMapPane() {
187                  this(null, true, null, null);                  this(null, true, null, null);
188          }          }
# Line 339  public class JMapPane extends JPanel imp Line 346  public class JMapPane extends JPanel imp
346    
347                  if (changed) { /* if the map changed then redraw */                  if (changed) { /* if the map changed then redraw */
348                          changed = false;                          changed = false;
349                            
350                            // The baseImage should not have alpha
351                          baseImage = new BufferedImage(dr.width, dr.height,                          baseImage = new BufferedImage(dr.width, dr.height,
352                                          BufferedImage.TYPE_INT_ARGB);                                          BufferedImage.TYPE_INT_RGB);
353    
354                          final Graphics2D ig = baseImage.createGraphics();                          final Graphics2D ig = baseImage.createGraphics();
355                          /* System.out.println("rendering"); */                          ig.setBackground(getMapBackgroundColor());
356                            ig.fillRect(0, 0, dr.width, dr.height);
357                            
358    //                      /* System.out.println("rendering"); */
359                          if (renderer.getContext() != null)                          if (renderer.getContext() != null)
360                                  renderer.setContext(context);                                  renderer.setContext(context);
361                          labelCache.clear(); // work around anoying labelcache bug  
362                            // TODO is this clearing still needed? We already replace all that stuff whenever we change the style. Deactivated 31.10.09.. let's see
363    //                      labelCache.clear(); // work around anoying labelcache bug
364    
365                          // draw the map                          // draw the map
366                          renderer.paint((Graphics2D) ig, dr, mapArea);                          renderer.paint(ig, dr, mapArea);
367    
368                          // TODO nur machen, wenn panning beginnt                          // TODO nur machen, wenn panning beginnt
369                          panningImage = new BufferedImage(dr.width, dr.height,                          panningImage = new BufferedImage(dr.width, dr.height,
# Line 483  public class JMapPane extends JPanel imp Line 497  public class JMapPane extends JPanel imp
497                                  final int dy = lastY - startY;                                  final int dy = lastY - startY;
498                                  // System.out.println("translate "+dx+","+dy);                                  // System.out.println("translate "+dx+","+dy);
499                                  final Graphics2D g2 = panningImage.createGraphics();                                  final Graphics2D g2 = panningImage.createGraphics();
500                                  g2.setBackground(new Color(240, 240, 240)); // TODO richtige                                  g2.setBackground(getMapBackgroundColor());
                                 // farbe? am besten  
                                 // vom L&F die  
                                 // hintergrundfarbe  
                                 // auslesen...  
501    
502                                  g2.clearRect(0, 0, this.getWidth(), this.getHeight());                                  g2.clearRect(0, 0, this.getWidth(), this.getHeight());
503                                  g2.drawImage(baseImage, dx, dy, this);                                  g2.drawImage(baseImage, dx, dy, this);
# Line 644  public class JMapPane extends JPanel imp Line 654  public class JMapPane extends JPanel imp
654                          setMapArea(bestAllowedMapArea(new Envelope(ll, ur)));                          setMapArea(bestAllowedMapArea(new Envelope(ll, ur)));
655    
656                          // sk.sc                          // sk.sc
657                          // {                           {
658                          // // SK tries to paint a preview of the zoom ;-9 aha.... well                          // // SK tries to paint a preview of the zoom ;-9 aha.... well
659                          // Graphics2D graphics = (Graphics2D) JMapPane.this.getGraphics();  //                              
660                          // graphics.setRenderingHint(RenderingHints.KEY_INTERPOLATION,  //                               double reductionFactor = 1/8.;
661                          // RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR);  ////                            
662                          // graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING,  ////                     BufferedImage reducedBaseImage = new BufferedImage((int)(baseImage.getWidth()*reductionFactor), (int)(baseImage.getHeight()*reductionFactor), BufferedImage.TYPE_INT_RGB);
663                          // RenderingHints.VALUE_ANTIALIAS_OFF);  ////                     Graphics2D reducedG = (Graphics2D) reducedBaseImage.getGraphics();
664                          // graphics.setRenderingHint(RenderingHints.KEY_RENDERING,  //                       AffineTransform reductionTransform =new AffineTransform();
665                          // RenderingHints.VALUE_RENDER_SPEED);  //                       reductionTransform.scale(reductionFactor, reductionFactor);
666                          // graphics.drawImage(baseImage, 0, 0, JMapPane.this.getWidth(),  ////                    reducedG.drawImage(baseImage, reductionTransform, null);
667                          // JMapPane.this.getHeight(), x1, y1, x2, y2, null);  //                      
668                          // }  //                       Graphics2D graphics = (Graphics2D) JMapPane.this.getGraphics();
669    ////                     graphics.getTransform().scale(reductionFactor, reductionFactor);
670    //                      
671    //                       graphics.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
672    //                       RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR);
673    //                       graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
674    //                       RenderingHints.VALUE_ANTIALIAS_OFF);
675    //                       graphics.setRenderingHint(RenderingHints.KEY_RENDERING,
676    //                       RenderingHints.VALUE_RENDER_SPEED);
677    //                       graphics.drawImage(baseImage, 0, 0, JMapPane.this.getWidth(),
678    //                       JMapPane.this.getHeight(), x1, y1, x2, y2, null);
679                             }
680                          // xulu.ec                          // xulu.ec
681                  } else if (state == JMapPane.ZoomOut) {                  } else if (state == JMapPane.ZoomOut) {
682                          drawRectangle(this.getGraphics());                          drawRectangle(this.getGraphics());
# Line 1103  public class JMapPane extends JPanel imp Line 1124  public class JMapPane extends JPanel imp
1124                  return maxExtend;                  return maxExtend;
1125          }          }
1126    
1127            /**
1128             * Set the background color of the map.
1129             * @param if <code>null</code>, white is used.
1130             */
1131            public void setMapBackgroundColor(Color bgColor) {
1132                    if (bgColor == null) bgColor = Color.WHITE;
1133                    this.mapBackgroundColor = bgColor;
1134            }
1135    
1136            /**
1137             * Returns the background {@link Color} of the map pane. Default is white.
1138            **/
1139            public Color getMapBackgroundColor() {
1140                    return mapBackgroundColor;
1141            }
1142    
1143  }  }

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26