/[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 520 by alfonx, Tue Nov 17 12:50:05 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 net.miginfocom.swing.MigLayout;
41   * TODO DOKU und initialize schöner machen. SK  
42   */  import org.apache.log4j.Logger;
43  public class MapView extends JPanel {  
44          private static final Logger LOGGER = Logger.getLogger(MapView.class);  import schmitzm.geotools.gui.GeoMapPane;
45    import schmitzm.geotools.gui.MapContextControlPane;
46          private final JSplitPane splitPane = new JSplitPane(  import schmitzm.geotools.gui.MapPaneStatusBar;
47                          JSplitPane.HORIZONTAL_SPLIT);  import schmitzm.geotools.gui.SelectableXMapPane;
48    import schmitzm.geotools.styling.ColorMapManager;
49          protected MapPaneStatusBar statusBar = null;  
50            /**
51          /**   * Achtung! Dieser code ist verwuestet TODO DOKU und initialize schöner machen.
52           * Komponente, in der die Karten, der Massstab und das Koordinaten-Raster   * SK
53           * dargestellt werden   */
54           */  public class MapView extends JPanel {
55          protected final GeoMapPane geoMapPane = new GeoMapPane();          private static final Logger LOGGER = Logger.getLogger(MapView.class);
56    
57  //          private final JSplitPane splitPane = new JSplitPane(
58  //      /** This is the layered Pane that holds the buttons and maybe the flying logo * */                          JSplitPane.HORIZONTAL_SPLIT);
59  //      protected JLayeredPane layeredPane;  
60            protected MapPaneStatusBar statusBar = null;
61          protected boolean zoomBackForwardButtonInAction;  
62            /**
63          private MapPaneToolBar jToolBar;           * Komponente, in der die Karten, der Massstab und das Koordinaten-Raster
64             * dargestellt werden.
65          /**           */
66           * Creates a new {@link MapView}. A {@link MapView} is a combination of a  
67           * {@link GeoMapPane}, a {@link MapContextManagerInterface} on the left,          protected final GeoMapPane geoMapPane = new GeoMapPane();
68           * and some buttons floating over the {@link JMapPane}  
69           */          private MapPaneToolBar jToolBar;
70          public MapView(Window owner2, MapPaneToolBar toolBar) {  
71                  super(new BorderLayout());          /**
72                  // Call initialize() by yourself afterwards.           * Creates a new {@link MapView}. A {@link MapView} is a combination of a
73                  // Needed because variables for the overwritten methods           * {@link GeoMapPane}, a {@link MapContextManagerInterface} on the left, and
74                  // are not yet set.           * some buttons floating over the {@link SelectableXMapPane}
75                  getGeoMapPane().getMapPane().setWaitCursorComponent(owner2);           */
76                  if ( toolBar == null )          public MapView(Component parentGui, MapPaneToolBar toolBar) {
77                    toolBar = new MapPaneToolBar(getMapPane());                  super(new BorderLayout());
78                  jToolBar = toolBar;                  // Call initialize() by yourself afterwards.
79          }                  // Needed because variables for the overwritten methods
80                    // are not yet set.
81      /**                  jToolBar = toolBar;
82       * Creates a new {@link MapView}. A {@link MapView} is a combination of a          }
83       * {@link GeoMapPane}, a {@link MapContextManagerInterface} on the left,  
84       * and some buttons floating over the {@link JMapPane}          /**
85       */           * Creates a new {@link MapView}. A {@link MapView} is a combination of a
86      public MapView(Window owner2) {           * {@link GeoMapPane}, a {@link MapContextManagerInterface} on the left, and
87        this(owner2, null);           * some buttons floating over the {@link SelectableXMapPane}
88      }           */
89            public MapView(Component parentGui) {
90      // /**                  this(parentGui, null);
91          // * Nuetzlich wenn die Componente gedruckt wird. Dann wird der Hintergrund          }
92          // auf {@link Color#WHITE} gesetzt.zoomoutToggleButton  
93          // *          /**
94          // * @author <a href="mailto:[email protected]">Stefan Alfons           * This routine creates the main components of the GUI: The left Side and
95          // Kr&uuml;ger</a>           * the map on the right side.<br/>
96          // */           * Calls #getSidePanel() which can be overwritten (call super!).<br/>
97          // @Override           *
98          // public void print(Graphics g) {           * This method initialized the variables {@link #statusBar} and
99          //                         * {@link #splitPane}
100          // // SK: Ich habe keine Ahnung mehr, was das soll... Ich habs mal           *
101          // auskommentiert.           * @see #adjustSizeOfGeoMapPane()
102          //           */
103          // // wrap in try/finally so that we always restore the state          public void initialize() {
104          // try {                  // horizontales SplitPane initialisieren
105          // panToggleButton.setVisible(false);  
106          // zoominToggleButton.setVisible(false);                  // Status-Line to show Coordinates and Rastervalues.
107          // zoomoutToggleButton.setVisible(false);                  statusBar = new MapPaneStatusBar(getGeoMapPane().getMapPane());
108          // infoToggleButton.setVisible(false);                  statusBar.setBorder(BorderFactory.createCompoundBorder(BorderFactory
109          //                                  .createLoweredBevelBorder(), BorderFactory.createEmptyBorder(2,
110          // super.print(g);                                  5, 2, 5)));
111          // } finally {                  this.add(statusBar, BorderLayout.SOUTH);
112          // panToggleButton.setVisible(true);  
113          // zoominToggleButton.setVisible(true);                  /**
114          // zoomoutToggleButton.setVisible(true);                   * The layout of the split pane can be configured in the atlas.
115          // infoToggleButton.setVisible(true);                   * setDividerLocation(-1); has no effect here because the component is
116          // }                   * not visible yet.
117          // }                   */
118                    getSplitPane().setDividerSize(5);
119          /**  
120           * Calls #getSidePanel() which can be overwritten.                  getSplitPane().setResizeWeight(0.0);
121           *                  getSplitPane().add(getSidePane());
122           * @see #adjustSizeOfGeoMapPane()  
123           */                  /***********************************************************************
124          public void initialize() {                   * To the right side we now add a JPanel that consists of a toolbar and
125                  // horizontales SplitPane initialisieren                   * a gmp
126                     */
127                  // Status-Zeile                  JPanel newRight = new JPanel(new MigLayout("center, wrap 1","[grow]","[][grow]"));
128                  statusBar = new MapPaneStatusBar(getGeoMapPane()                  newRight.add(getToolBar());
129                                  .getMapPane());                  newRight.add(getGeoMapPane(),"growx, growy");
130                  statusBar.setBorder(BorderFactory.createCompoundBorder(BorderFactory                  getSplitPane().add(newRight);
131                                  .createLoweredBevelBorder(), BorderFactory.createEmptyBorder(2,  
132                                  5, 2, 5)));                  this.add(getSplitPane(), BorderLayout.CENTER);
133                  this.add(statusBar, BorderLayout.SOUTH);                  
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 never <code>null</code>, will rather create a default
140                  /***********************************************************************           */
141                   * To the right side we now add a JPanel that consists of a toolbar and          public MapPaneToolBar getToolBar() {
142                   * a gmp                  if (jToolBar == null) {
143                   */                          jToolBar = new MapPaneToolBar(getMapPane());
144                  JPanel newRight = new JPanel(new BorderLayout());                  }
145                  newRight.add(getToolBar(), BorderLayout.NORTH);                  return jToolBar;
146                  newRight.add(getGeoMapPane(), BorderLayout.CENTER);          }
147                  splitPane.add(newRight);  
148            /**
149                  // gpSize = new Dimension(40,50);           * Returns the split pane which divides the layer list from the map panel.
150                  // getGeoMapPane().setSize(gpSize);           */
151            public JSplitPane getSplitPane() {
152                  // layeredPane = new JLayeredPane();                  return splitPane;
153                  // layeredPane.add(getGeoMapPane(), JLayeredPane.DEFAULT_LAYER);          }
154                  // createMapButtons(layeredPane);  
155            /**
156                  // //****************************************************************************           * Sets the active tool. Simply calls
157                  // // The JLayeredPane doesn't manage the size of its layers.. we do it           * {@link MapPaneToolBar#setSelectedTool(Integer)}.
158                  // // This listener will actually correct the size of the JLayeredPane           *
159                  // //****************************************************************************           * @param tool
160                  // splitPane.addPropertyChangeListener(new PropertyChangeListener() {           *            One of {@link #TOOL_INFO}, {@link #TOOL_PAN} .. constants
161                  //           */
162                  // public void propertyChange(final PropertyChangeEvent evt) {          public void setSelectedTool(Integer tool) {
163                  // final JSplitPane sp = (JSplitPane) evt.getSource();                  jToolBar.setSelectedTool(tool);
164                  //          }
165                  // adjustSizeOfGeoMapPane();  
166                  //          /**
167                  // }           * Sets whether a tool is activated or not. Simply calls
168                  //           * {@link MapPaneToolBar#setButtonEnabled(int, boolean, boolean)}.
169                  // });           *
170             * @param tool
171                  this.add(splitPane, BorderLayout.CENTER);           *            tool ID
172          }           * @param enabled
173             *            if {@code true} the tool becomes available
174          /**           * @param hideOnDisable
175           * Returns the tool bar which controls the active mouse actions on the map.           *            if {@code true} the button is also hidden if {@code enabled}
176           * @return           *            is {@code false}
177           */           */
178          public MapPaneToolBar getToolBar() {          public void setToolEnabled(Integer tool, boolean enabled,
179            return jToolBar;                          boolean hideOnDisable) {
180          }                  jToolBar.setButtonEnabled(tool, enabled, hideOnDisable);
181            }
182          /**  
183           * Returns the split pane which divides the layer list from the map panel.          /**
184           */           * Sets the activation for all tools. Simply calls
185          public JSplitPane getSplitPane() {           * {@link MapPaneToolBar#setAllToolsEnabled(boolean, boolean)}.
186                  return this.splitPane;           *
187          }           * @param enabled
188             *            if {@code true} all tool becomes available
189          //           * @param hideOnDisable
190          // /**           *            if {@code true} the buttons are also hidden if {@code enabled}
191          // * Called by the listerner. Calculates the exact size of the {@link           *            is {@code false}
192          // GeoMapPane} and sets it.           */
193          // */          public void setAllToolsEnabled(boolean enabled, boolean hideOnDisable) {
194          // private void adjustSizeOfGeoMapPane() {                  jToolBar.setAllToolsEnabled(enabled, hideOnDisable);
195          // final int newWidth = (int) (splitPane.getSize().getWidth()          }
196          // - splitPane.getComponent(1).getSize().getWidth()  
197          // - splitPane.getComponent(0).getSize().getWidth())          /**
198          // - 4;           * Checks whether a tool is activated. Simply calls
199          // final int newHeight = (int) splitPane.getComponent(1).getSize()           * {@link MapPaneToolBar#isButtonEnabled(Integer)}.
200          // .getHeight();           *
201          //           * @param tool
202          // if (newWidth <= 20 )           *            tool ID
203          // return;           * @return {@code false} if an unknown ID is specified
204          //           */
205          // gpSize.setSize(newWidth, newHeight);          public boolean isToolEnabled(Integer tool) {
206          //                  return jToolBar.isButtonEnabled(tool);
207          // getGeoMapPane().getMapPane().setWaitCursorDuringNextRepaint(true);          }
208          //  
209          // getGeoMapPane().setSize( gpSize );          /**
210          // // getGeoMapPane().refreshMap(); nicht nötig .. schön           * called by initialize() to fill the left of the XULUMapView Supposed to be
211          //           * overwritten by AtlasMapView or DesignMapView
212          // positionLayeredObjects();           */
213          // }          public JComponent getSidePane() {
214  //                  return new MapContextControlPane(getGeoMapPane().getMapPane(),
215  //      /**                                  new ColorMapManager());
216  //       * Adds the floating Map Contol Buttons to the {@link JLayeredPane}, with Z =          }
217  //       * 10  
218  //       *          /**
219  //       * @param lp           * Liefert die Status-Zeile, in der die Koordinaten und Raster-Werte
220  //       *            {@link JLayeredPane} that contains the {@link GeoMapPane}           * angezeigt werden.
221  //       */           */
222  //      private void createMapButtons(final JLayeredPane lp) {          public MapPaneStatusBar getStatusBar() {
223  //                  return this.statusBar;
224  //              final Integer zlayer = new Integer(10);          }
225  //  
226  //              toggleButtonsList = new LinkedList<JToggleButton>();          /**
227  //              toggleButtonsList.add(infoToggleButton);           * Liefert den Karten-Bereich der Komponente.
228  //              toggleButtonsList.add(panToggleButton);           */
229  //              toggleButtonsList.add(zoominToggleButton);          public final SelectableXMapPane getMapPane() {
230  //              toggleButtonsList.add(zoomoutToggleButton);                  return getGeoMapPane().getMapPane();
231  //          }
232  //  
233  //              positionLayeredObjects();          public GeoMapPane getGeoMapPane() {
234  //                  return geoMapPane;
235  //              final ButtonGroup bg = new ButtonGroup();          }
236  //              for (final JToggleButton b : toggleButtonsList) {  
237  //                      // final FontMetrics fm = b.getFontMetrics( b.getFont() );          public int getSelectedTool() {
238  //                      // final int w = fm.stringWidth( b.getText() );                  return jToolBar.getSelectedTool();
239  //          }
240  //                      // b.setBorder( BorderFactory.createRaisedBevelBorder() );  
241  //                      b.setBorder(BorderFactory.createEmptyBorder());          /**
242  //                      b.setSize(new Dimension(32, 32));           * Help the garbage collection
243  //                      bg.add(b);           */
244  //                      lp.add(b, zlayer);          public void dispose() {
245  //              }                  if (geoMapPane != null)
246  //                          geoMapPane.dispose();
247  //              zoomBackButton.setSize(32, 32);          }
248  //              zoomBackButton.setBorder(BorderFactory.createEmptyBorder());  
249  //              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.520

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26