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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26