[Schmitzm-commits] r1220 - trunk/src/skrueger/geotools

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Wed Nov 3 14:09:32 CET 2010


Author: alfonx
Date: 2010-11-03 14:09:32 +0100 (Wed, 03 Nov 2010)
New Revision: 1220

Added:
   trunk/src/skrueger/geotools/CrsLabel.java
Modified:
   trunk/src/skrueger/geotools/MapPaneToolBar.java
   trunk/src/skrueger/geotools/MapView.java
Log:


Added: trunk/src/skrueger/geotools/CrsLabel.java
===================================================================
--- trunk/src/skrueger/geotools/CrsLabel.java	2010-11-03 12:47:27 UTC (rev 1219)
+++ trunk/src/skrueger/geotools/CrsLabel.java	2010-11-03 13:09:32 UTC (rev 1220)
@@ -0,0 +1,46 @@
+package skrueger.geotools;
+
+import javax.swing.JLabel;
+
+import schmitzm.geotools.gui.SelectableXMapPane;
+import schmitzm.geotools.gui.XMapPaneEvent;
+import schmitzm.geotools.map.event.JMapPaneListener;
+
+public class CrsLabel extends JLabel {
+
+	private JMapPaneListener listenForCrsChange = new JMapPaneListener() {
+
+		@Override
+		public void performMapPaneEvent(XMapPaneEvent e) {
+			updateCrs();
+		}
+	};
+	
+	private final SelectableXMapPane mapPane;
+
+	CrsLabel(SelectableXMapPane mapPane) {
+		super();
+		this.mapPane = mapPane;
+
+		mapPane.addMapPaneListener(listenForCrsChange);
+
+		updateCrs();
+	}
+
+	public void updateCrs() {
+		try {
+			setText(mapPane.getMapContext().getCoordinateReferenceSystem()
+					.getName().toString());
+		} catch (Exception e) {
+			setText("");
+		}
+	}
+
+	@Override
+	protected void finalize() throws Throwable {
+		super.finalize();
+		if (mapPane != null)
+			mapPane.removeMapPaneListener(listenForCrsChange);
+	}
+
+}


Property changes on: trunk/src/skrueger/geotools/CrsLabel.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain
Name: svn:keywords
   + Id URL
Name: svn:eol-style
   + native

Modified: trunk/src/skrueger/geotools/MapPaneToolBar.java
===================================================================
--- trunk/src/skrueger/geotools/MapPaneToolBar.java	2010-11-03 12:47:27 UTC (rev 1219)
+++ trunk/src/skrueger/geotools/MapPaneToolBar.java	2010-11-03 13:09:32 UTC (rev 1220)
@@ -64,11 +64,11 @@
 import com.vividsolutions.jts.geom.Envelope;
 
 /**
- * A toolbar to control an {@link SelectableXMapPane} (Atlas visualization). This contains
- * two types of buttons. A group of <i>tools</i> for the mouse actions on the
- * map represented by {@link JToggleButton JToggleButtons}, where only one tool
- * can be activated every time. And some (general) <i>actions</i>, represented
- * by normal {@link JButton JButtons}.
+ * A toolbar to control an {@link SelectableXMapPane} (Atlas visualization).
+ * This contains two types of buttons. A group of <i>tools</i> for the mouse
+ * actions on the map represented by {@link JToggleButton JToggleButtons}, where
+ * only one tool can be activated every time. And some (general) <i>actions</i>,
+ * represented by normal {@link JButton JButtons}.
  * 
  * @author <a href="mailto:martin.schmitz at koeln.de">Martin Schmitz</a>
  *         (University of Bonn/Germany)
@@ -168,6 +168,7 @@
 		}
 
 	};
+	private CrsLabel crsViewer;
 
 	/**
 	 * Creates a new toolbar. Notice: This toolbar does nothing until
@@ -204,6 +205,7 @@
 		// Create a Listener to listen to the zooms on the JMapPane
 		this.mapPaneListener = new JMapPaneListener() {
 			public void performMapPaneEvent(XMapPaneEvent e) {
+
 				if (!(e instanceof MapAreaChangedEvent))
 					return;
 
@@ -254,6 +256,7 @@
 				setButtonEnabled(ACTION_ZOOM_BACK, lastZooms.size() > 1);
 				setButtonEnabled(ACTION_ZOOM_FORWARD, false);
 			}
+
 		};
 
 		setMapPane(mapPane);
@@ -263,12 +266,19 @@
 		init();
 	}
 
+	private CrsLabel getCrsComponent() {
+		if (crsViewer == null) {
+			crsViewer = new CrsLabel(this.mapPane);
+		}
+		return crsViewer;
+	}
+
 	/**
 	 * Sets the {@link SelectableXMapPane} controlled by this tool bar.
 	 * 
 	 * @param mapPane
-	 *            {@link SelectableXMapPane} to control (if {@code null} this tool bar
-	 *            controls NOTHING!)
+	 *            {@link SelectableXMapPane} to control (if {@code null} this
+	 *            tool bar controls NOTHING!)
 	 */
 	public void setMapPane(SelectableXMapPane mapPane) {
 		// Remove listener from old MapPane
@@ -297,39 +307,50 @@
 	 * Creates the tool buttons and action buttons and seperators, adds them to
 	 * {@link #toolAndActionButtons} and finally creates a button group for all
 	 * tools. So sub-classes which override this method should FIRST add their
-	 * new tool buttons to {@link #toolAndActionButtons} before calling {@code
-	 * super.initTools()}.
+	 * new tool buttons to {@link #toolAndActionButtons} before calling
+	 * {@code super.initTools()}.
 	 */
 	protected void initToolsAndActions() {
 		// Pan
-		addTool(new MapPaneToolBarAction(TOOL_PAN, this, XMapPaneTool.PAN), false);
-		
+		addTool(new MapPaneToolBarAction(TOOL_PAN, this, XMapPaneTool.PAN),
+				false);
+
 		// Info
-		addTool(new MapPaneToolBarAction(TOOL_INFO, this, XMapPaneTool.INFO), false);
+		addTool(new MapPaneToolBarAction(TOOL_INFO, this, XMapPaneTool.INFO),
+				false);
 
 		// Zoom in
-		addTool(new MapPaneToolBarAction(TOOL_ZOOMIN, this, XMapPaneTool.ZOOM_IN), false);
-		
+		addTool(new MapPaneToolBarAction(TOOL_ZOOMIN, this,
+				XMapPaneTool.ZOOM_IN), false);
+
 		// Zoom out
-		addTool(new MapPaneToolBarAction(TOOL_ZOOMOUT, this, XMapPaneTool.ZOOM_OUT), false);
-		
+		addTool(new MapPaneToolBarAction(TOOL_ZOOMOUT, this,
+				XMapPaneTool.ZOOM_OUT), false);
+
 		// Action button to revert the last zoom
-		addAction(new MapPaneToolBarAction(ACTION_ZOOM_BACK, this, "",
-				new ImageIcon(MapView.class
-						.getResource("resource/icons/zoom_back.png")),
-				R("MapPaneButtons.LastZoom.TT")), false);
+		addAction(
+				new MapPaneToolBarAction(ACTION_ZOOM_BACK, this, "",
+						new ImageIcon(MapView.class
+								.getResource("resource/icons/zoom_back.png")),
+						R("MapPaneButtons.LastZoom.TT")), false);
 		setButtonEnabled(ACTION_ZOOM_BACK, false);
 
 		// Action button to redo the last zoom
-		addAction(new MapPaneToolBarAction(ACTION_ZOOM_FORWARD, this, "",
-				new ImageIcon(MapView.class
-						.getResource("resource/icons/zoom_forward.png")),
-				R("MapPaneButtons.NextZoom.TT")), false);
+		addAction(
+				new MapPaneToolBarAction(
+						ACTION_ZOOM_FORWARD,
+						this,
+						"",
+						new ImageIcon(MapView.class
+								.getResource("resource/icons/zoom_forward.png")),
+						R("MapPaneButtons.NextZoom.TT")), false);
 		setButtonEnabled(ACTION_ZOOM_FORWARD, false);
 
 		// set the selected tool enabled
 		setSelectedTool(selectedTool);
 
+		add(getCrsComponent());
+
 	}
 
 	@Override
@@ -435,7 +456,7 @@
 	protected void performActionButton(int action, ActionEvent e) {
 		if (mapPane == null)
 			return;
-		
+
 		// Perform the action "Zoom back": Revert the last zoom
 		if (action == ACTION_ZOOM_BACK) {
 			if (zoomBackIndex <= 1)
@@ -478,13 +499,12 @@
 	 */
 	public void addTool(MapPaneToolBarAction buttonAction, boolean resetToolBar) {
 		if (isButtonIDUsed(buttonAction.getID())) {
-			LOGGER
-					.warn("addTool(.) ignored because ID already used for tool or action: "
-							+ buttonAction.getID());
+			LOGGER.warn("addTool(.) ignored because ID already used for tool or action: "
+					+ buttonAction.getID());
 			return;
 		}
 		JToggleButton button = new SmallToggleButton(buttonAction);
-		
+
 		toolButtonGroup.add(button);
 		toolAndActionButtons.put(buttonAction.getID(), button);
 		if (resetToolBar)
@@ -515,9 +535,8 @@
 	public void addAction(MapPaneToolBarAction buttonAction,
 			boolean resetToolBar) {
 		if (isButtonIDUsed(buttonAction.getID())) {
-			LOGGER
-					.warn("addAction(.) ignored because ID already used for tool or action: "
-							+ buttonAction.getID());
+			LOGGER.warn("addAction(.) ignored because ID already used for tool or action: "
+					+ buttonAction.getID());
 			return;
 		}
 		JButton button = new SmallButton(buttonAction);
@@ -542,9 +561,8 @@
 	public void addJComponent(JComponent component, int id, boolean resetToolBar) {
 
 		if (isButtonIDUsed(id)) {
-			LOGGER
-					.warn("addAction(.) ignored because ID already used for tool or action: "
-							+ id);
+			LOGGER.warn("addAction(.) ignored because ID already used for tool or action: "
+					+ id);
 			return;
 		}
 
@@ -555,8 +573,7 @@
 
 	public void addSeparator(int id, Separator separator) {
 		if (isButtonIDUsed(id)) {
-			LOGGER
-					.warn("addSeparator(.) ignored because ID already used for tool or action. ");
+			LOGGER.warn("addSeparator(.) ignored because ID already used for tool or action. ");
 			return;
 		}
 		toolAndActionButtons.put(id, separator);
@@ -583,10 +600,11 @@
 	 *         {@linkplain #getToolButton(int) tool button}
 	 */
 	public AbstractButton getButton(int id) {
-		
-		//ACHUTNG: Das ist ein SK QUICK FIX! TODO 
-		if (!(toolAndActionButtons.get(id) instanceof AbstractButton)) return null;
-		
+
+		// ACHUTNG: Das ist ein SK QUICK FIX! TODO
+		if (!(toolAndActionButtons.get(id) instanceof AbstractButton))
+			return null;
+
 		AbstractButton button = (AbstractButton) toolAndActionButtons.get(id);
 		if (button == null)
 			LOGGER.warn("Unknown tool or action ID: " + id);
@@ -653,7 +671,7 @@
 			return -1;
 		return selectedTool;
 	}
-	
+
 	/**
 	 * Sets whether a tool or action is activated or not. The visible property
 	 * of the button is not affected.
@@ -730,11 +748,11 @@
 	public void setAllToolsEnabled(boolean enabled, boolean hideOnDisable) {
 		for (int id : toolAndActionButtons.keySet()) {
 			if (toolAndActionButtons.get(id) instanceof JToggleButton) {
-			setButtonEnabled(id, enabled, hideOnDisable);
+				setButtonEnabled(id, enabled, hideOnDisable);
 			}
 		}
 	}
-	
+
 	/**
 	 * Sets the activation for all actions.
 	 * 
@@ -855,7 +873,8 @@
 			this.toolBar = toolBar;
 		}
 
-		public MapPaneToolBarAction(int id, MapPaneToolBar toolBar, XMapPaneTool tool) {
+		public MapPaneToolBarAction(int id, MapPaneToolBar toolBar,
+				XMapPaneTool tool) {
 			this(id, toolBar, "", tool.getIcon(), tool.getToolTip());
 		}
 
@@ -887,8 +906,7 @@
 	 * Nuetzlich wenn die Componente gedruckt (z.B. wenn ein Screenshot gemacht
 	 * wird) wird. Dann werden wird der Hintergrund auf WEISS gesetzt.
 	 * 
-	 * @author <a href="mailto:skpublic at wikisquare.de">Stefan Alfons
-	 *         Tzeggai</a>
+	 * @author <a href="mailto:skpublic at wikisquare.de">Stefan Alfons Tzeggai</a>
 	 */
 	@Override
 	public void print(Graphics g) {
@@ -902,4 +920,12 @@
 		}
 	}
 
+	@Override
+	protected void finalize() throws Throwable {
+		super.finalize();
+
+		if (mapPane != null && mapPaneListener != null)
+			mapPane.removeMapPaneListener(mapPaneListener);
+	}
+
 }

Modified: trunk/src/skrueger/geotools/MapView.java
===================================================================
--- trunk/src/skrueger/geotools/MapView.java	2010-11-03 12:47:27 UTC (rev 1219)
+++ trunk/src/skrueger/geotools/MapView.java	2010-11-03 13:09:32 UTC (rev 1220)
@@ -48,8 +48,7 @@
 import schmitzm.geotools.styling.ColorMapManager;
 
 /**
- * Achtung! Dieser code ist verwuestet TODO DOKU und initialize schöner machen.
- * SK
+ * TODO Dokument
  */
 public class MapView extends JPanel {
 	private static final Logger LOGGER = Logger.getLogger(MapView.class);



More information about the Schmitzm-commits mailing list