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

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

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

revision 2 by mojays, Tue Feb 24 22:43:52 2009 UTC revision 165 by alfonx, Tue Jun 23 16:31:32 2009 UTC
# Line 1  Line 1 
1  package skrueger.geotools;  package skrueger.geotools;
2    
3  import java.awt.BorderLayout;  import java.awt.BorderLayout;
 import java.awt.Dimension;  
4  import java.awt.Window;  import java.awt.Window;
 import java.awt.event.ActionEvent;  
 import java.util.ArrayList;  
 import java.util.LinkedList;  
5    
 import javax.swing.AbstractAction;  
6  import javax.swing.BorderFactory;  import javax.swing.BorderFactory;
 import javax.swing.ButtonGroup;  
 import javax.swing.ImageIcon;  
 import javax.swing.JButton;  
7  import javax.swing.JComponent;  import javax.swing.JComponent;
 import javax.swing.JLabel;  
8  import javax.swing.JPanel;  import javax.swing.JPanel;
9  import javax.swing.JSplitPane;  import javax.swing.JSplitPane;
 import javax.swing.JToggleButton;  
 import javax.swing.JToolBar;  
10    
11  import org.apache.log4j.Logger;  import org.apache.log4j.Logger;
12    import org.geotools.renderer.lite.StreamingRenderer;
13    
14  import schmitzm.geotools.gui.GeoMapPane;  import schmitzm.geotools.gui.GeoMapPane;
15  import schmitzm.geotools.gui.JMapPane;  import schmitzm.geotools.gui.JMapPane;
16  import schmitzm.geotools.gui.MapContextControlPane;  import schmitzm.geotools.gui.MapContextControlPane;
17  import schmitzm.geotools.gui.MapPaneStatusBar;  import schmitzm.geotools.gui.MapPaneStatusBar;
 import schmitzm.geotools.map.event.JMapPaneEvent;  
 import schmitzm.geotools.map.event.JMapPaneListener;  
 import schmitzm.geotools.map.event.MapAreaChangedEvent;  
18  import schmitzm.geotools.styling.ColorMapManager;  import schmitzm.geotools.styling.ColorMapManager;
 import schmitzm.swing.SwingUtil;  
   
 import com.vividsolutions.jts.geom.Envelope;  
19    
20  /**  /**
21   * Achtung! Dieser code ist verwuestet   * Achtung! Dieser code ist verwuestet TODO DOKU und initialize schöner machen.
22   */   * SK
   
 /**  
  * TODO DOKU und initialize schöner machen. SK  
23   */   */
24  public class MapView extends JPanel {  public class MapView extends JPanel {
25          private static final Logger LOGGER = Logger.getLogger(MapView.class);          private static final Logger LOGGER = Logger.getLogger(MapView.class);
# Line 47  public class MapView extends JPanel { Line 28  public class MapView extends JPanel {
28                          JSplitPane.HORIZONTAL_SPLIT);                          JSplitPane.HORIZONTAL_SPLIT);
29    
30          protected MapPaneStatusBar statusBar = null;          protected MapPaneStatusBar statusBar = null;
31            
32          /**          /**
33           * Komponente, in der die Karten, der Massstab und das Koordinaten-Raster           * Komponente, in der die Karten, der Massstab und das Koordinaten-Raster
34           * dargestellt werden           * dargestellt werden.
35           */           */
         protected final GeoMapPane geoMapPane = new GeoMapPane();  
36    
37  //          /**
38  //      /** This is the layered Pane that holds the buttons and maybe the flying logo * */           * SK: 21.6.09: ShapeFileRenderer is supposed to be about 5x faster on
39  //      protected JLayeredPane layeredPane;           * ShapeFiles. The ShapeFileRenderer falls back to the StreamingRenderer.
40             */
41          protected boolean zoomBackForwardButtonInAction;          // Old code:
42            // protected final GeoMapPane geoMapPane = new
43            // GeoMapPane(null,null,null,null, new StreamingRenderer());
44            // New Code uses Streaming renderer.
45            protected final GeoMapPane geoMapPane = new GeoMapPane(null, null, null,
46                            null, new StreamingRenderer());
47    
48          private MapPaneToolBar jToolBar;          private MapPaneToolBar jToolBar;
49    
50          /**          /**
51           * Creates a new {@link MapView}. A {@link MapView} is a combination of a           * Creates a new {@link MapView}. A {@link MapView} is a combination of a
52           * {@link GeoMapPane}, a {@link MapContextManagerInterface} on the left,           * {@link GeoMapPane}, a {@link MapContextManagerInterface} on the left, and
53           * and some buttons floating over the {@link JMapPane}           * some buttons floating over the {@link JMapPane}
54           */           */
55          public MapView(Window owner2, MapPaneToolBar toolBar) {          public MapView(Window parentGui, MapPaneToolBar toolBar) {
56                  super(new BorderLayout());                  super(new BorderLayout());
57                  // Call initialize() by yourself afterwards.                  // Call initialize() by yourself afterwards.
58                  // Needed because variables for the overwritten methods                  // Needed because variables for the overwritten methods
59                  // are not yet set.                  // are not yet set.
60                  getGeoMapPane().getMapPane().setWaitCursorComponent(owner2);                  getGeoMapPane().getMapPane().setWaitCursorComponent(parentGui);
61                  if ( toolBar == null )                  if (toolBar == null)
62                    toolBar = new MapPaneToolBar(getMapPane());                          toolBar = new MapPaneToolBar(getMapPane());
63                  jToolBar = toolBar;                  jToolBar = toolBar;
64          }          }
   
     /**  
      * Creates a new {@link MapView}. A {@link MapView} is a combination of a  
      * {@link GeoMapPane}, a {@link MapContextManagerInterface} on the left,  
      * and some buttons floating over the {@link JMapPane}  
      */  
     public MapView(Window owner2) {  
       this(owner2, null);  
     }  
   
     // /**  
         // * Nuetzlich wenn die Componente gedruckt wird. Dann wird der Hintergrund  
         // auf {@link Color#WHITE} gesetzt.zoomoutToggleButton  
         // *  
         // * @author <a href="mailto:[email protected]">Stefan Alfons  
         // Kr&uuml;ger</a>  
         // */  
         // @Override  
         // public void print(Graphics g) {  
         //                
         // // SK: Ich habe keine Ahnung mehr, was das soll... Ich habs mal  
         // auskommentiert.  
         //  
         // // wrap in try/finally so that we always restore the state  
         // try {  
         // panToggleButton.setVisible(false);  
         // zoominToggleButton.setVisible(false);  
         // zoomoutToggleButton.setVisible(false);  
         // infoToggleButton.setVisible(false);  
         //  
         // super.print(g);  
         // } finally {  
         // panToggleButton.setVisible(true);  
         // zoominToggleButton.setVisible(true);  
         // zoomoutToggleButton.setVisible(true);  
         // infoToggleButton.setVisible(true);  
         // }  
         // }  
65    
66          /**          /**
67           * Calls #getSidePanel() which can be overwritten.           * Creates a new {@link MapView}. A {@link MapView} is a combination of a
68             * {@link GeoMapPane}, a {@link MapContextManagerInterface} on the left, and
69             * some buttons floating over the {@link JMapPane}
70             */
71            public MapView(Window parentGui) {
72                    this(parentGui, null);
73            }
74    
75            /**
76             * This routine creates the main components of the GUI: The left Side and
77             * the map on the right side.<br/>
78             * Calls #getSidePanel() which can be overwritten (call super!).<br/>
79             *
80             * This method initialized the variables {@link #statusBar} and
81             * {@link #splitPane}
82           *           *
83           * @see #adjustSizeOfGeoMapPane()           * @see #adjustSizeOfGeoMapPane()
84           */           */
85          public void initialize() {          public void initialize() {
86                  // horizontales SplitPane initialisieren                  // horizontales SplitPane initialisieren
87    
88                  // Status-Zeile                  // Status-Line to show Coordinates and Rastervalues.
89                  statusBar = new MapPaneStatusBar(getGeoMapPane()                  statusBar = new MapPaneStatusBar(getGeoMapPane().getMapPane());
                                 .getMapPane());  
90                  statusBar.setBorder(BorderFactory.createCompoundBorder(BorderFactory                  statusBar.setBorder(BorderFactory.createCompoundBorder(BorderFactory
91                                  .createLoweredBevelBorder(), BorderFactory.createEmptyBorder(2,                                  .createLoweredBevelBorder(), BorderFactory.createEmptyBorder(2,
92                                  5, 2, 5)));                                  5, 2, 5)));
93                  this.add(statusBar, BorderLayout.SOUTH);                  this.add(statusBar, BorderLayout.SOUTH);
94    
95                  splitPane.setDividerLocation(0.4);                  /**
96                  splitPane.setDividerSize(5);                   * The layout of the split pane can be configured in the atlas.
97                     * setDividerLocation(-1); has no effect here because the component is
98                     * not visible yet.
99                     */
100                    getSplitPane().setDividerSize(5);
101    
102                  splitPane.add(getSidePane());                  getSplitPane().setResizeWeight(0.0);
103                    getSplitPane().add(getSidePane());
104    
105                  /***********************************************************************                  /***********************************************************************
106                   * To the right side we now add a JPanel that consists of a toolbar and                   * To the right side we now add a JPanel that consists of a toolbar and
# Line 144  public class MapView extends JPanel { Line 109  public class MapView extends JPanel {
109                  JPanel newRight = new JPanel(new BorderLayout());                  JPanel newRight = new JPanel(new BorderLayout());
110                  newRight.add(getToolBar(), BorderLayout.NORTH);                  newRight.add(getToolBar(), BorderLayout.NORTH);
111                  newRight.add(getGeoMapPane(), BorderLayout.CENTER);                  newRight.add(getGeoMapPane(), BorderLayout.CENTER);
112                  splitPane.add(newRight);                  getSplitPane().add(newRight);
   
                 // gpSize = new Dimension(40,50);  
                 // getGeoMapPane().setSize(gpSize);  
113    
114                  // layeredPane = new JLayeredPane();                  this.add(getSplitPane(), BorderLayout.CENTER);
                 // layeredPane.add(getGeoMapPane(), JLayeredPane.DEFAULT_LAYER);  
                 // createMapButtons(layeredPane);  
   
                 // //****************************************************************************  
                 // // The JLayeredPane doesn't manage the size of its layers.. we do it  
                 // // This listener will actually correct the size of the JLayeredPane  
                 // //****************************************************************************  
                 // splitPane.addPropertyChangeListener(new PropertyChangeListener() {  
                 //  
                 // public void propertyChange(final PropertyChangeEvent evt) {  
                 // final JSplitPane sp = (JSplitPane) evt.getSource();  
                 //  
                 // adjustSizeOfGeoMapPane();  
                 //  
                 // }  
                 //  
                 // });  
   
                 this.add(splitPane, BorderLayout.CENTER);  
115          }          }
116    
117          /**          /**
118           * Returns the tool bar which controls the active mouse actions on the map.           * Returns the tool bar which controls the active mouse actions on the map.
119             *
120           * @return           * @return
121           */           */
122          public MapPaneToolBar getToolBar() {          public MapPaneToolBar getToolBar() {
123            return jToolBar;                  return jToolBar;
124          }          }
125    
126          /**          /**
127           * Returns the split pane which divides the layer list from the map panel.           * Returns the split pane which divides the layer list from the map panel.
128           */           */
129          public JSplitPane getSplitPane() {          public JSplitPane getSplitPane() {
130                  return this.splitPane;                  return splitPane;
131          }          }
132    
         //  
         // /**  
         // * Called by the listerner. Calculates the exact size of the {@link  
         // GeoMapPane} and sets it.  
         // */  
         // private void adjustSizeOfGeoMapPane() {  
         // final int newWidth = (int) (splitPane.getSize().getWidth()  
         // - splitPane.getComponent(1).getSize().getWidth()  
         // - splitPane.getComponent(0).getSize().getWidth())  
         // - 4;  
         // final int newHeight = (int) splitPane.getComponent(1).getSize()  
         // .getHeight();  
         //  
         // if (newWidth <= 20 )  
         // return;  
         //  
         // gpSize.setSize(newWidth, newHeight);  
         //  
         // getGeoMapPane().getMapPane().setWaitCursorDuringNextRepaint(true);  
         //  
         // getGeoMapPane().setSize( gpSize );  
         // // getGeoMapPane().refreshMap(); nicht nötig .. schön  
         //  
         // positionLayeredObjects();  
         // }  
 //  
 //      /**  
 //       * Adds the floating Map Contol Buttons to the {@link JLayeredPane}, with Z =  
 //       * 10  
 //       *  
 //       * @param lp  
 //       *            {@link JLayeredPane} that contains the {@link GeoMapPane}  
 //       */  
 //      private void createMapButtons(final JLayeredPane lp) {  
 //  
 //              final Integer zlayer = new Integer(10);  
 //  
 //              toggleButtonsList = new LinkedList<JToggleButton>();  
 //              toggleButtonsList.add(infoToggleButton);  
 //              toggleButtonsList.add(panToggleButton);  
 //              toggleButtonsList.add(zoominToggleButton);  
 //              toggleButtonsList.add(zoomoutToggleButton);  
 //  
 //  
 //              positionLayeredObjects();  
 //  
 //              final ButtonGroup bg = new ButtonGroup();  
 //              for (final JToggleButton b : toggleButtonsList) {  
 //                      // final FontMetrics fm = b.getFontMetrics( b.getFont() );  
 //                      // final int w = fm.stringWidth( b.getText() );  
 //  
 //                      // b.setBorder( BorderFactory.createRaisedBevelBorder() );  
 //                      b.setBorder(BorderFactory.createEmptyBorder());  
 //                      b.setSize(new Dimension(32, 32));  
 //                      bg.add(b);  
 //                      lp.add(b, zlayer);  
 //              }  
 //  
 //              zoomBackButton.setSize(32, 32);  
 //              zoomBackButton.setBorder(BorderFactory.createEmptyBorder());  
 //              lp.add(zoomBackButton, zlayer);  
 //  
 //              zoomForwardButton.setSize(32, 32);  
 //              zoomForwardButton.setBorder(BorderFactory.createEmptyBorder());  
 //              lp.add(zoomForwardButton, zlayer);  
 //      }  
   
 //      /**  
 //       * This method will update the  
 //       */  
 //      public void updateIconsForButtons() {  
 //              if (zoomoutToggleButton.isSelected())  
 //                      zoomoutToggleButton.setIcon(new ImageIcon(MapView.class  
 //                                      .getResource("zoom_out.png")));  
 //              else  
 //                      zoomoutToggleButton.setIcon(new ImageIcon(MapView.class  
 //                                      .getResource("zoom_out.png")));  
 //  
 //              if (zoominToggleButton.isSelected())  
 //                      zoominToggleButton.setIcon(new ImageIcon(MapView.class  
 //                                      .getResource("zoom_in.png")));  
 //              else  
 //                      zoominToggleButton.setIcon(new ImageIcon(MapView.class  
 //                                      .getResource("zoom_in.png")));  
 //  
 //              if (infoToggleButton.isSelected())  
 //                      infoToggleButton.setIcon(new ImageIcon(MapView.class  
 //                                      .getResource("info.png")));  
 //              else  
 //                      infoToggleButton.setIcon(new ImageIcon(MapView.class  
 //                                      .getResource("info_aus.png")));  
 //  
 //              if (panToggleButton.isSelected())  
 //                      panToggleButton.setIcon(new ImageIcon(MapView.class  
 //                                      .getResource("pan.png")));  
 //              else  
 //                      panToggleButton.setIcon(new ImageIcon(MapView.class  
 //                                      .getResource("pan_aus.png")));  
 //  
 //      }  
   
133          /**          /**
134           * Sets the active tool.           * Sets the active tool. Simply calls
135           * Simply calls {@link MapPaneToolBar#setSelectedTool(Integer)}.           * {@link MapPaneToolBar#setSelectedTool(Integer)}.
136             *
137           * @param tool           * @param tool
138           *            One of {@link #TOOL_INFO}, {@link #TOOL_PAN} .. constants           *            One of {@link #TOOL_INFO}, {@link #TOOL_PAN} .. constants
139           */           */
140          public void setSelectedTool(Integer tool) {          public void setSelectedTool(Integer tool) {
141            jToolBar.setSelectedTool(tool);                  jToolBar.setSelectedTool(tool);
142            }
143    
144            /**
145             * Sets whether a tool is activated or not. Simply calls
146             * {@link MapPaneToolBar#setButtonEnabled(int, boolean, boolean)}.
147             *
148             * @param tool
149             *            tool ID
150             * @param enabled
151             *            if {@code true} the tool becomes available
152             * @param hideOnDisable
153             *            if {@code true} the button is also hidden if {@code enabled}
154             *            is {@code false}
155             */
156            public void setToolEnabled(Integer tool, boolean enabled,
157                            boolean hideOnDisable) {
158                    jToolBar.setButtonEnabled(tool, enabled, hideOnDisable);
159          }          }
160            
161      /**          /**
162       * Sets whether a tool is activated or not.           * Sets the activation for all tools. Simply calls
163       * Simply calls {@link MapPaneToolBar#setButtonEnabled(int, boolean, boolean)}.           * {@link MapPaneToolBar#setAllToolsEnabled(boolean, boolean)}.
164       * @param tool tool ID           *
165       * @param enabled if {@code true} the tool becomes available           * @param enabled
166       * @param hideOnDisable if {@code true} the button is also hidden if           *            if {@code true} all tool becomes available
167       *                      {@code enabled} is {@code false}           * @param hideOnDisable
168       */           *            if {@code true} the buttons are also hidden if {@code enabled}
169          public void setToolEnabled(Integer tool, boolean enabled, boolean hideOnDisable) {           *            is {@code false}
170             jToolBar.setButtonEnabled(tool,enabled,hideOnDisable);           */
171          }          public void setAllToolsEnabled(boolean enabled, boolean hideOnDisable) {
172                    jToolBar.setAllToolsEnabled(enabled, hideOnDisable);
173      /**          }
174       * Sets the activation for all tools.  
175       * Simply calls {@link MapPaneToolBar#setAllToolsEnabled(boolean, boolean)}.          /**
176       * @param enabled if {@code true} all tool becomes available           * Checks whether a tool is activated. Simply calls
177       * @param hideOnDisable if {@code true} the buttons are also hidden if           * {@link MapPaneToolBar#isButtonEnabled(Integer)}.
178       *                      {@code enabled} is {@code false}           *
179       */           * @param tool
180      public void setAllToolsEnabled(boolean enabled, boolean hideOnDisable) {           *            tool ID
       jToolBar.setAllToolsEnabled(enabled, hideOnDisable);  
     }    
   
     /**  
          * Checks whether a tool is activated.  
      * Simply calls {@link MapPaneToolBar#isButtonEnabled(Integer)}.  
          * @param tool tool ID  
181           * @return {@code false} if an unknown ID is specified           * @return {@code false} if an unknown ID is specified
182           */           */
183          public boolean isToolEnabled(Integer tool) {          public boolean isToolEnabled(Integer tool) {
184            return jToolBar.isButtonEnabled(tool);                  return jToolBar.isButtonEnabled(tool);
185          }          }
 //  
 //      /**  
 //       * Positions the Map Control Buttons on top of the {@link GeoMapPane}  
 //       *  
 //       * @author <a href="mailto:[email protected]">Stefan Alfons Kr&uuml;ger</a>  
 //       *  
 //       */  
 //      protected void positionLayeredObjects() {  
 //  
 //              // Abstand zwischen den Buttons und Button zu Rand  
 //              final int gap = 10;  
 //  
 //              // 45 entspicht der breite des Grids/ der Gradanzeige  
 //              // TODO den wert aus der geomappane auslesen...  
 //              int x = GridPanel.VERT_WIDTH;  
 //  
 //              for (final JToggleButton b : toggleButtonsList) {  
 //                      x += gap;  
 //                      // final FontMetrics fm = b.getFontMetrics( b.getFont() );  
 //                      b.setLocation(x, 10);  
 //  
 //                      final int w = 32;  
 //                      x += w;  
 //                      // y += b.getWidth();  
 //              }  
 //  
 //              // Und noch die zwei ZoomBackup und ZoomForward Buttons  
 //              zoomBackButton.setLocation(x + 32 + gap, 10);  
 //              zoomForwardButton.setLocation(x + 64 + gap * 2, 10);  
 //      }  
186    
187          /**          /**
188           * called by initialize() to fill the left of the XULUMapView Supposed to be           * called by initialize() to fill the left of the XULUMapView Supposed to be
# Line 371  public class MapView extends JPanel { Line 195  public class MapView extends JPanel {
195    
196          /**          /**
197           * Liefert die Status-Zeile, in der die Koordinaten und Raster-Werte           * Liefert die Status-Zeile, in der die Koordinaten und Raster-Werte
198           * angezeigt werden.           * angezeigt werden.
199           */           */
200          public MapPaneStatusBar getStatusBar() {          public MapPaneStatusBar getStatusBar() {
201            return this.statusBar;                  return this.statusBar;
202          }          }
203            
204          /**          /**
205           * Liefert den Karten-Bereich der Komponente.           * Liefert den Karten-Bereich der Komponente.
206           */           */
# Line 384  public class MapView extends JPanel { Line 208  public class MapView extends JPanel {
208                  return getGeoMapPane().getMapPane();                  return getGeoMapPane().getMapPane();
209          }          }
210    
         // /**  
         // * Liefert das in einem Layer dargestellte Objekt.  
         // *  
         // * @param layer  
         // * ein Layer  
         // */  
         // public Object getMapObject(final MapLayer layer) {  
         // // return layerObjects.get(layer);  
         // return null;  
         // }  
   
211          public GeoMapPane getGeoMapPane() {          public GeoMapPane getGeoMapPane() {
212                  return geoMapPane;                  return geoMapPane;
213          }          }

Legend:
Removed from v.2  
changed lines
  Added in v.165

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26