/[schmitzm]/branches/2.2.x/src/skrueger/geotools/MapView.java
ViewVC logotype

Diff of /branches/2.2.x/src/skrueger/geotools/MapView.java

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

trunk/src/skrueger/geotools/MapView.java revision 2 by mojays, Tue Feb 24 22:43:52 2009 UTC branches/1.0-gt2-2.6/src/skrueger/geotools/MapView.java revision 315 by mojays, Wed Aug 26 11:03:27 2009 UTC
# Line 1  Line 1 
1  package skrueger.geotools;  /*******************************************************************************
2     * Copyright (c) 2009 Martin O. J. Schmitz.
3  import java.awt.BorderLayout;   *
4  import java.awt.Dimension;   * This file is part of the SCHMITZM library - a collection of utility
5  import java.awt.Window;   * classes based on Java 1.6, focusing (not only) on Java Swing
6  import java.awt.event.ActionEvent;   * and the Geotools library.
7  import java.util.ArrayList;   *
8  import java.util.LinkedList;   * The SCHMITZM project is hosted at:
9     * http://wald.intevation.org/projects/schmitzm/
10  import javax.swing.AbstractAction;   *
11  import javax.swing.BorderFactory;   * This program is free software; you can redistribute it and/or
12  import javax.swing.ButtonGroup;   * modify it under the terms of the GNU Lesser General Public License
13  import javax.swing.ImageIcon;   * as published by the Free Software Foundation; either version 3
14  import javax.swing.JButton;   * of the License, or (at your option) any later version.
15  import javax.swing.JComponent;   *
16  import javax.swing.JLabel;   * This program is distributed in the hope that it will be useful,
17  import javax.swing.JPanel;   * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  import javax.swing.JSplitPane;   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  import javax.swing.JToggleButton;   * GNU General Public License for more details.
20  import javax.swing.JToolBar;   *
21     * You should have received a copy of the GNU Lesser General Public License (license.txt)
22  import org.apache.log4j.Logger;   * along with this program; if not, write to the Free Software
23     * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
24  import schmitzm.geotools.gui.GeoMapPane;   * or try this link: http://www.gnu.org/licenses/lgpl.html
25  import schmitzm.geotools.gui.JMapPane;   *
26  import schmitzm.geotools.gui.MapContextControlPane;   * Contributors:
27  import schmitzm.geotools.gui.MapPaneStatusBar;   *     Martin O. J. Schmitz - initial API and implementation
28  import schmitzm.geotools.map.event.JMapPaneEvent;   *     Stefan A. Krüger - additional utility classes
29  import schmitzm.geotools.map.event.JMapPaneListener;   ******************************************************************************/
30  import schmitzm.geotools.map.event.MapAreaChangedEvent;  package skrueger.geotools;
31  import schmitzm.geotools.styling.ColorMapManager;  
32  import schmitzm.swing.SwingUtil;  import java.awt.BorderLayout;
33    import java.awt.Component;
34  import com.vividsolutions.jts.geom.Envelope;  
35    import javax.swing.BorderFactory;
36  /**  import javax.swing.JComponent;
37   * Achtung! Dieser code ist verwuestet  import javax.swing.JPanel;
38   */  import javax.swing.JSplitPane;
39    
40  /**  import org.apache.log4j.Logger;
41   * TODO DOKU und initialize schöner machen. SK  
42   */  import schmitzm.geotools.gui.GeoMapPane;
43  public class MapView extends JPanel {  import schmitzm.geotools.gui.JMapPane;
44          private static final Logger LOGGER = Logger.getLogger(MapView.class);  import schmitzm.geotools.gui.MapContextControlPane;
45    import schmitzm.geotools.gui.MapPaneStatusBar;
46          private final JSplitPane splitPane = new JSplitPane(  import schmitzm.geotools.styling.ColorMapManager;
47                          JSplitPane.HORIZONTAL_SPLIT);  
48    /**
49          protected MapPaneStatusBar statusBar = null;   * Achtung! Dieser code ist verwuestet TODO DOKU und initialize schöner machen.
50             * SK
51          /**   */
52           * Komponente, in der die Karten, der Massstab und das Koordinaten-Raster  public class MapView extends JPanel {
53           * dargestellt werden          private static final Logger LOGGER = Logger.getLogger(MapView.class);
54           */  
55          protected final GeoMapPane geoMapPane = new GeoMapPane();          private final JSplitPane splitPane = new JSplitPane(
56                            JSplitPane.HORIZONTAL_SPLIT);
57  //  
58  //      /** This is the layered Pane that holds the buttons and maybe the flying logo * */          protected MapPaneStatusBar statusBar = null;
59  //      protected JLayeredPane layeredPane;  
60            /**
61          protected boolean zoomBackForwardButtonInAction;           * Komponente, in der die Karten, der Massstab und das Koordinaten-Raster
62             * dargestellt werden.
63          private MapPaneToolBar jToolBar;           */
64    
65          /**          protected final GeoMapPane geoMapPane = new GeoMapPane();
66           * Creates a new {@link MapView}. A {@link MapView} is a combination of a  
67           * {@link GeoMapPane}, a {@link MapContextManagerInterface} on the left,          private MapPaneToolBar jToolBar;
68           * and some buttons floating over the {@link JMapPane}  
69           */          /**
70          public MapView(Window owner2, MapPaneToolBar toolBar) {           * Creates a new {@link MapView}. A {@link MapView} is a combination of a
71                  super(new BorderLayout());           * {@link GeoMapPane}, a {@link MapContextManagerInterface} on the left, and
72                  // Call initialize() by yourself afterwards.           * some buttons floating over the {@link JMapPane}
73                  // Needed because variables for the overwritten methods           */
74                  // are not yet set.          public MapView(Component parentGui, MapPaneToolBar toolBar) {
75                  getGeoMapPane().getMapPane().setWaitCursorComponent(owner2);                  super(new BorderLayout());
76                  if ( toolBar == null )                  // Call initialize() by yourself afterwards.
77                    toolBar = new MapPaneToolBar(getMapPane());                  // Needed because variables for the overwritten methods
78                  jToolBar = toolBar;                  // are not yet set.
79          }                  getGeoMapPane().getMapPane().setWaitCursorComponent(parentGui);
80                    if (toolBar == null)
81      /**                          toolBar = new MapPaneToolBar(getMapPane());
82       * Creates a new {@link MapView}. A {@link MapView} is a combination of a                  jToolBar = toolBar;
83       * {@link GeoMapPane}, a {@link MapContextManagerInterface} on the left,          }
84       * and some buttons floating over the {@link JMapPane}  
85       */          /**
86      public MapView(Window owner2) {           * Creates a new {@link MapView}. A {@link MapView} is a combination of a
87        this(owner2, null);           * {@link GeoMapPane}, a {@link MapContextManagerInterface} on the left, and
88      }           * some buttons floating over the {@link JMapPane}
89             */
90      // /**          public MapView(Component parentGui) {
91          // * Nuetzlich wenn die Componente gedruckt wird. Dann wird der Hintergrund                  this(parentGui, null);
92          // auf {@link Color#WHITE} gesetzt.zoomoutToggleButton          }
93          // *  
94          // * @author <a href="mailto:[email protected]">Stefan Alfons          /**
95          // Kr&uuml;ger</a>           * This routine creates the main components of the GUI: The left Side and
96          // */           * the map on the right side.<br/>
97          // @Override           * Calls #getSidePanel() which can be overwritten (call super!).<br/>
98          // public void print(Graphics g) {           *
99          //                         * This method initialized the variables {@link #statusBar} and
100          // // SK: Ich habe keine Ahnung mehr, was das soll... Ich habs mal           * {@link #splitPane}
101          // auskommentiert.           *
102          //           * @see #adjustSizeOfGeoMapPane()
103          // // wrap in try/finally so that we always restore the state           */
104          // try {          public void initialize() {
105          // panToggleButton.setVisible(false);                  // horizontales SplitPane initialisieren
106          // zoominToggleButton.setVisible(false);  
107          // zoomoutToggleButton.setVisible(false);                  // Status-Line to show Coordinates and Rastervalues.
108          // infoToggleButton.setVisible(false);                  statusBar = new MapPaneStatusBar(getGeoMapPane().getMapPane());
109          //                  statusBar.setBorder(BorderFactory.createCompoundBorder(BorderFactory
110          // super.print(g);                                  .createLoweredBevelBorder(), BorderFactory.createEmptyBorder(2,
111          // } finally {                                  5, 2, 5)));
112          // panToggleButton.setVisible(true);                  this.add(statusBar, BorderLayout.SOUTH);
113          // zoominToggleButton.setVisible(true);  
114          // zoomoutToggleButton.setVisible(true);                  /**
115          // infoToggleButton.setVisible(true);                   * The layout of the split pane can be configured in the atlas.
116          // }                   * setDividerLocation(-1); has no effect here because the component is
117          // }                   * not visible yet.
118                     */
119          /**                  getSplitPane().setDividerSize(5);
120           * Calls #getSidePanel() which can be overwritten.  
121           *                  getSplitPane().setResizeWeight(0.0);
122           * @see #adjustSizeOfGeoMapPane()                  getSplitPane().add(getSidePane());
123           */  
124          public void initialize() {                  /***********************************************************************
125                  // horizontales SplitPane initialisieren                   * To the right side we now add a JPanel that consists of a toolbar and
126                     * a gmp
127                  // Status-Zeile                   */
128                  statusBar = new MapPaneStatusBar(getGeoMapPane()                  JPanel newRight = new JPanel(new BorderLayout());
129                                  .getMapPane());                  newRight.add(getToolBar(), BorderLayout.NORTH);
130                  statusBar.setBorder(BorderFactory.createCompoundBorder(BorderFactory                  newRight.add(getGeoMapPane(), BorderLayout.CENTER);
131                                  .createLoweredBevelBorder(), BorderFactory.createEmptyBorder(2,                  getSplitPane().add(newRight);
132                                  5, 2, 5)));  
133                  this.add(statusBar, BorderLayout.SOUTH);                  this.add(getSplitPane(), BorderLayout.CENTER);
134            }
135                  splitPane.setDividerLocation(0.4);  
136                  splitPane.setDividerSize(5);          /**
137             * Returns the tool bar which controls the active mouse actions on the map.
138                  splitPane.add(getSidePane());           *
139             * @return
140                  /***********************************************************************           */
141                   * To the right side we now add a JPanel that consists of a toolbar and          public MapPaneToolBar getToolBar() {
142                   * a gmp                  return jToolBar;
143                   */          }
144                  JPanel newRight = new JPanel(new BorderLayout());  
145                  newRight.add(getToolBar(), BorderLayout.NORTH);          /**
146                  newRight.add(getGeoMapPane(), BorderLayout.CENTER);           * Returns the split pane which divides the layer list from the map panel.
147                  splitPane.add(newRight);           */
148            public JSplitPane getSplitPane() {
149                  // gpSize = new Dimension(40,50);                  return splitPane;
150                  // getGeoMapPane().setSize(gpSize);          }
151    
152                  // layeredPane = new JLayeredPane();          /**
153                  // layeredPane.add(getGeoMapPane(), JLayeredPane.DEFAULT_LAYER);           * Sets the active tool. Simply calls
154                  // createMapButtons(layeredPane);           * {@link MapPaneToolBar#setSelectedTool(Integer)}.
155             *
156                  // //****************************************************************************           * @param tool
157                  // // The JLayeredPane doesn't manage the size of its layers.. we do it           *            One of {@link #TOOL_INFO}, {@link #TOOL_PAN} .. constants
158                  // // This listener will actually correct the size of the JLayeredPane           */
159                  // //****************************************************************************          public void setSelectedTool(Integer tool) {
160                  // splitPane.addPropertyChangeListener(new PropertyChangeListener() {                  jToolBar.setSelectedTool(tool);
161                  //          }
162                  // public void propertyChange(final PropertyChangeEvent evt) {  
163                  // final JSplitPane sp = (JSplitPane) evt.getSource();          /**
164                  //           * Sets whether a tool is activated or not. Simply calls
165                  // adjustSizeOfGeoMapPane();           * {@link MapPaneToolBar#setButtonEnabled(int, boolean, boolean)}.
166                  //           *
167                  // }           * @param tool
168                  //           *            tool ID
169                  // });           * @param enabled
170             *            if {@code true} the tool becomes available
171                  this.add(splitPane, BorderLayout.CENTER);           * @param hideOnDisable
172          }           *            if {@code true} the button is also hidden if {@code enabled}
173             *            is {@code false}
174          /**           */
175           * Returns the tool bar which controls the active mouse actions on the map.          public void setToolEnabled(Integer tool, boolean enabled,
176           * @return                          boolean hideOnDisable) {
177           */                  jToolBar.setButtonEnabled(tool, enabled, hideOnDisable);
178          public MapPaneToolBar getToolBar() {          }
179            return jToolBar;  
180          }          /**
181             * Sets the activation for all tools. Simply calls
182          /**           * {@link MapPaneToolBar#setAllToolsEnabled(boolean, boolean)}.
183           * Returns the split pane which divides the layer list from the map panel.           *
184           */           * @param enabled
185          public JSplitPane getSplitPane() {           *            if {@code true} all tool becomes available
186                  return this.splitPane;           * @param hideOnDisable
187          }           *            if {@code true} the buttons are also hidden if {@code enabled}
188             *            is {@code false}
189          //           */
190          // /**          public void setAllToolsEnabled(boolean enabled, boolean hideOnDisable) {
191          // * Called by the listerner. Calculates the exact size of the {@link                  jToolBar.setAllToolsEnabled(enabled, hideOnDisable);
192          // GeoMapPane} and sets it.          }
193          // */  
194          // private void adjustSizeOfGeoMapPane() {          /**
195          // final int newWidth = (int) (splitPane.getSize().getWidth()           * Checks whether a tool is activated. Simply calls
196          // - splitPane.getComponent(1).getSize().getWidth()           * {@link MapPaneToolBar#isButtonEnabled(Integer)}.
197          // - splitPane.getComponent(0).getSize().getWidth())           *
198          // - 4;           * @param tool
199          // final int newHeight = (int) splitPane.getComponent(1).getSize()           *            tool ID
200          // .getHeight();           * @return {@code false} if an unknown ID is specified
201          //           */
202          // if (newWidth <= 20 )          public boolean isToolEnabled(Integer tool) {
203          // return;                  return jToolBar.isButtonEnabled(tool);
204          //          }
205          // gpSize.setSize(newWidth, newHeight);  
206          //          /**
207          // getGeoMapPane().getMapPane().setWaitCursorDuringNextRepaint(true);           * called by initialize() to fill the left of the XULUMapView Supposed to be
208          //           * overwritten by AtlasMapView or DesignMapView
209          // getGeoMapPane().setSize( gpSize );           */
210          // // getGeoMapPane().refreshMap(); nicht nötig .. schön          public JComponent getSidePane() {
211          //                  return new MapContextControlPane(getGeoMapPane().getMapPane(),
212          // positionLayeredObjects();                                  new ColorMapManager());
213          // }          }
214  //  
215  //      /**          /**
216  //       * Adds the floating Map Contol Buttons to the {@link JLayeredPane}, with Z =           * Liefert die Status-Zeile, in der die Koordinaten und Raster-Werte
217  //       * 10           * angezeigt werden.
218  //       *           */
219  //       * @param lp          public MapPaneStatusBar getStatusBar() {
220  //       *            {@link JLayeredPane} that contains the {@link GeoMapPane}                  return this.statusBar;
221  //       */          }
222  //      private void createMapButtons(final JLayeredPane lp) {  
223  //          /**
224  //              final Integer zlayer = new Integer(10);           * Liefert den Karten-Bereich der Komponente.
225  //           */
226  //              toggleButtonsList = new LinkedList<JToggleButton>();          public final JMapPane getMapPane() {
227  //              toggleButtonsList.add(infoToggleButton);                  return getGeoMapPane().getMapPane();
228  //              toggleButtonsList.add(panToggleButton);          }
229  //              toggleButtonsList.add(zoominToggleButton);  
230  //              toggleButtonsList.add(zoomoutToggleButton);          public GeoMapPane getGeoMapPane() {
231  //                  return geoMapPane;
232  //          }
233  //              positionLayeredObjects();  
234  //          public int getSelectedTool() {
235  //              final ButtonGroup bg = new ButtonGroup();                  return jToolBar.getSelectedTool();
236  //              for (final JToggleButton b : toggleButtonsList) {          }
237  //                      // final FontMetrics fm = b.getFontMetrics( b.getFont() );  
238  //                      // 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")));  
 //  
 //      }  
   
         /**  
          * Sets the active tool.  
          * Simply calls {@link MapPaneToolBar#setSelectedTool(Integer)}.  
          * @param tool  
          *            One of {@link #TOOL_INFO}, {@link #TOOL_PAN} .. constants  
          */  
         public void setSelectedTool(Integer tool) {  
           jToolBar.setSelectedTool(tool);  
         }  
           
     /**  
      * Sets whether a tool is activated or not.  
      * Simply calls {@link MapPaneToolBar#setButtonEnabled(int, boolean, boolean)}.  
      * @param tool tool ID  
      * @param enabled if {@code true} the tool becomes available  
      * @param hideOnDisable if {@code true} the button is also hidden if  
      *                      {@code enabled} is {@code false}  
      */  
         public void setToolEnabled(Integer tool, boolean enabled, boolean hideOnDisable) {  
            jToolBar.setButtonEnabled(tool,enabled,hideOnDisable);  
         }  
   
     /**  
      * Sets the activation for all tools.  
      * Simply calls {@link MapPaneToolBar#setAllToolsEnabled(boolean, boolean)}.  
      * @param enabled if {@code true} all tool becomes available  
      * @param hideOnDisable if {@code true} the buttons are also hidden if  
      *                      {@code enabled} is {@code false}  
      */  
     public void setAllToolsEnabled(boolean enabled, boolean hideOnDisable) {  
       jToolBar.setAllToolsEnabled(enabled, hideOnDisable);  
     }    
   
     /**  
          * Checks whether a tool is activated.  
      * Simply calls {@link MapPaneToolBar#isButtonEnabled(Integer)}.  
          * @param tool tool ID  
          * @return {@code false} if an unknown ID is specified  
          */  
         public boolean isToolEnabled(Integer tool) {  
           return jToolBar.isButtonEnabled(tool);  
         }  
 //  
 //      /**  
 //       * 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);  
 //      }  
   
         /**  
          * called by initialize() to fill the left of the XULUMapView Supposed to be  
          * overwritten by AtlasMapView or DesignMapView  
          */  
         public JComponent getSidePane() {  
                 return new MapContextControlPane(getGeoMapPane().getMapPane(),  
                                 new ColorMapManager());  
         }  
   
         /**  
          * Liefert die Status-Zeile, in der die Koordinaten und Raster-Werte  
          * angezeigt werden.  
          */  
         public MapPaneStatusBar getStatusBar() {  
           return this.statusBar;  
         }  
           
         /**  
          * Liefert den Karten-Bereich der Komponente.  
          */  
         public final JMapPane getMapPane() {  
                 return getGeoMapPane().getMapPane();  
         }  
   
         // /**  
         // * Liefert das in einem Layer dargestellte Objekt.  
         // *  
         // * @param layer  
         // * ein Layer  
         // */  
         // public Object getMapObject(final MapLayer layer) {  
         // // return layerObjects.get(layer);  
         // return null;  
         // }  
   
         public GeoMapPane getGeoMapPane() {  
                 return geoMapPane;  
         }  
   
         public int getSelectedTool() {  
                 return jToolBar.getSelectedTool();  
         }  
   
 }  

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26