/[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 1220 by alfonx, Wed Nov 3 13:09:32 2010 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. Tzeggai - 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          /**   * TODO Dokument
52           * Komponente, in der die Karten, der Massstab und das Koordinaten-Raster   */
53           * dargestellt werden  public class MapView extends JPanel {
54           */          private static final Logger LOGGER = Logger.getLogger(MapView.class);
55          protected final GeoMapPane geoMapPane = new GeoMapPane();  
56            private final JSplitPane splitPane = new JSplitPane(
57  //                          JSplitPane.HORIZONTAL_SPLIT);
58  //      /** This is the layered Pane that holds the buttons and maybe the flying logo * */  
59  //      protected JLayeredPane layeredPane;          protected MapPaneStatusBar statusBar = null;
60            /**
61          protected boolean zoomBackForwardButtonInAction;           * Komponente, in der die Karten, der Massstab und das Koordinaten-Raster
62             * dargestellt werden.
63          private MapPaneToolBar jToolBar;           */
64            protected final GeoMapPane geoMapPane = new GeoMapPane();
65          /**  
66           * Creates a new {@link MapView}. A {@link MapView} is a combination of a          private MapPaneToolBar jToolBar;
67           * {@link GeoMapPane}, a {@link MapContextManagerInterface} on the left,  
68           * and some buttons floating over the {@link JMapPane}          /**
69           */           * Creates a new {@link MapView}. A {@link MapView} is a combination of a
70          public MapView(Window owner2, MapPaneToolBar toolBar) {           * {@link GeoMapPane}, a {@link MapContextManagerInterface} on the left, and
71                  super(new BorderLayout());           * some buttons floating over the {@link SelectableXMapPane}
72                  // Call initialize() by yourself afterwards.           */
73                  // Needed because variables for the overwritten methods          public MapView(Component parentGui, MapPaneToolBar toolBar) {
74                  // are not yet set.                  super(new BorderLayout());
75                  getGeoMapPane().getMapPane().setWaitCursorComponent(owner2);                  // Call initialize() by yourself afterwards.
76                  if ( toolBar == null )                  // Needed because variables for the overwritten methods
77                    toolBar = new MapPaneToolBar(getMapPane());                  // are not yet set.
78                  jToolBar = toolBar;                  jToolBar = toolBar;
79          }  
80                    // By default the MapPane will render with antialiasing on
81      /**                  getGeoMapPane().getMapPane().setAntiAliasing(true);
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(
109          //                                  BorderFactory.createLoweredBevelBorder(),
110          // super.print(g);                                  BorderFactory.createEmptyBorder(2, 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]",
128                  statusBar = new MapPaneStatusBar(getGeoMapPane()                                  "[][grow]"));
129                                  .getMapPane());                  newRight.add(getToolBar());
130                  statusBar.setBorder(BorderFactory.createCompoundBorder(BorderFactory                  newRight.add(getGeoMapPane(), "growx, growy");
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            /**
138                  splitPane.add(getSidePane());           * Returns the tool bar which controls the active mouse actions on the map.
139             *
140                  /***********************************************************************           * @return never <code>null</code>, will rather create a default
141                   * To the right side we now add a JPanel that consists of a toolbar and           */
142                   * a gmp          public MapPaneToolBar getToolBar() {
143                   */                  if (jToolBar == null) {
144                  JPanel newRight = new JPanel(new BorderLayout());                          jToolBar = new MapPaneToolBar(getMapPane());
145                  newRight.add(getToolBar(), BorderLayout.NORTH);                  }
146                  newRight.add(getGeoMapPane(), BorderLayout.CENTER);                  return jToolBar;
147                  splitPane.add(newRight);          }
148    
149                  // gpSize = new Dimension(40,50);          /**
150                  // getGeoMapPane().setSize(gpSize);           * Returns the split pane which divides the layer list from the map panel.
151             */
152                  // layeredPane = new JLayeredPane();          public JSplitPane getSplitPane() {
153                  // layeredPane.add(getGeoMapPane(), JLayeredPane.DEFAULT_LAYER);                  return splitPane;
154                  // createMapButtons(layeredPane);          }
155    
156                  // //****************************************************************************          /**
157                  // // The JLayeredPane doesn't manage the size of its layers.. we do it           * Sets the active tool. Simply calls
158                  // // This listener will actually correct the size of the JLayeredPane           * {@link MapPaneToolBar#setSelectedTool(Integer)}.
159                  // //****************************************************************************           *
160                  // splitPane.addPropertyChangeListener(new PropertyChangeListener() {           * @param tool
161                  //           *            One of {@link #TOOL_INFO}, {@link #TOOL_PAN} .. constants
162                  // public void propertyChange(final PropertyChangeEvent evt) {           */
163                  // final JSplitPane sp = (JSplitPane) evt.getSource();          public void setSelectedTool(Integer tool) {
164                  //                  jToolBar.setSelectedTool(tool);
165                  // adjustSizeOfGeoMapPane();          }
166                  //  
167                  // }          /**
168                  //           * Sets whether a tool is activated or not. Simply calls
169                  // });           * {@link MapPaneToolBar#setButtonEnabled(int, boolean, boolean)}.
170             *
171                  this.add(splitPane, BorderLayout.CENTER);           * @param tool
172          }           *            tool ID
173             * @param enabled
174          /**           *            if {@code true} the tool becomes available
175           * Returns the tool bar which controls the active mouse actions on the map.           * @param hideOnDisable
176           * @return           *            if {@code true} the button is also hidden if {@code enabled}
177           */           *            is {@code false}
178          public MapPaneToolBar getToolBar() {           */
179            return jToolBar;          public void setToolEnabled(Integer tool, boolean enabled,
180          }                          boolean hideOnDisable) {
181                    jToolBar.setButtonEnabled(tool, enabled, hideOnDisable);
182          /**          }
183           * Returns the split pane which divides the layer list from the map panel.  
184           */          /**
185          public JSplitPane getSplitPane() {           * Sets the activation for all tools. Simply calls
186                  return this.splitPane;           * {@link MapPaneToolBar#setAllToolsEnabled(boolean, boolean)}.
187          }           *
188             * @param enabled
189          //           *            if {@code true} all tool becomes available
190          // /**           * @param hideOnDisable
191          // * Called by the listerner. Calculates the exact size of the {@link           *            if {@code true} the buttons are also hidden if {@code enabled}
192          // GeoMapPane} and sets it.           *            is {@code false}
193          // */           */
194          // private void adjustSizeOfGeoMapPane() {          public void setAllToolsEnabled(boolean enabled, boolean hideOnDisable) {
195          // final int newWidth = (int) (splitPane.getSize().getWidth()                  jToolBar.setAllToolsEnabled(enabled, hideOnDisable);
196          // - splitPane.getComponent(1).getSize().getWidth()          }
197          // - splitPane.getComponent(0).getSize().getWidth())  
198          // - 4;          /**
199          // final int newHeight = (int) splitPane.getComponent(1).getSize()           * Checks whether a tool is activated. Simply calls
200          // .getHeight();           * {@link MapPaneToolBar#isButtonEnabled(Integer)}.
201          //           *
202          // if (newWidth <= 20 )           * @param tool
203          // return;           *            tool ID
204          //           * @return {@code false} if an unknown ID is specified
205          // gpSize.setSize(newWidth, newHeight);           */
206          //          public boolean isToolEnabled(Integer tool) {
207          // getGeoMapPane().getMapPane().setWaitCursorDuringNextRepaint(true);                  return jToolBar.isButtonEnabled(tool);
208          //          }
209          // getGeoMapPane().setSize( gpSize );  
210          // // getGeoMapPane().refreshMap(); nicht nötig .. schön          /**
211          //           * called by initialize() to fill the left of the XULUMapView Supposed to be
212          // positionLayeredObjects();           * overwritten by AtlasMapView or DesignMapView
213          // }           */
214  //          public JComponent getSidePane() {
215  //      /**                  return new MapContextControlPane(getGeoMapPane().getMapPane(),
216  //       * Adds the floating Map Contol Buttons to the {@link JLayeredPane}, with Z =                                  new ColorMapManager());
217  //       * 10          }
218  //       *  
219  //       * @param lp          /**
220  //       *            {@link JLayeredPane} that contains the {@link GeoMapPane}           * Liefert die Status-Zeile, in der die Koordinaten und Raster-Werte
221  //       */           * angezeigt werden.
222  //      private void createMapButtons(final JLayeredPane lp) {           */
223  //          public MapPaneStatusBar getStatusBar() {
224  //              final Integer zlayer = new Integer(10);                  return this.statusBar;
225  //          }
226  //              toggleButtonsList = new LinkedList<JToggleButton>();  
227  //              toggleButtonsList.add(infoToggleButton);          /**
228  //              toggleButtonsList.add(panToggleButton);           * Liefert den Karten-Bereich der Komponente.
229  //              toggleButtonsList.add(zoominToggleButton);           */
230  //              toggleButtonsList.add(zoomoutToggleButton);          public final SelectableXMapPane getMapPane() {
231  //                  return getGeoMapPane().getMapPane();
232  //          }
233  //              positionLayeredObjects();  
234  //          public GeoMapPane getGeoMapPane() {
235  //              final ButtonGroup bg = new ButtonGroup();                  return geoMapPane;
236  //              for (final JToggleButton b : toggleButtonsList) {          }
237  //                      // final FontMetrics fm = b.getFontMetrics( b.getFont() );  
238  //                      // final int w = fm.stringWidth( b.getText() );          public int getSelectedTool() {
239  //                  return jToolBar.getSelectedTool();
240  //                      // b.setBorder( BorderFactory.createRaisedBevelBorder() );          }
241  //                      b.setBorder(BorderFactory.createEmptyBorder());  
242  //                      b.setSize(new Dimension(32, 32));          /**
243  //                      bg.add(b);           * Help the garbage collection
244  //                      lp.add(b, zlayer);           */
245  //              }          public void dispose() {
246  //                  if (geoMapPane != null)
247  //              zoomBackButton.setSize(32, 32);                          geoMapPane.dispose();
248  //              zoomBackButton.setBorder(BorderFactory.createEmptyBorder());          }
249  //              lp.add(zoomBackButton, zlayer);  
250  //  }
 //              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.1220

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26