[Schmitzm-commits] r743 - in trunk/src/schmitzm: jfree/feature swing

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Wed Mar 3 12:42:46 CET 2010


Author: alfonx
Date: 2010-03-03 12:42:44 +0100 (Wed, 03 Mar 2010)
New Revision: 743

Modified:
   trunk/src/schmitzm/jfree/feature/AggregationFunctionJComboBox.java
   trunk/src/schmitzm/swing/SwingUtil.java
Log:
Moved ASUtil.addMouseListenerForCombobox to schmitzm.SwingUtil

Modified: trunk/src/schmitzm/jfree/feature/AggregationFunctionJComboBox.java
===================================================================
--- trunk/src/schmitzm/jfree/feature/AggregationFunctionJComboBox.java	2010-03-03 11:31:16 UTC (rev 742)
+++ trunk/src/schmitzm/jfree/feature/AggregationFunctionJComboBox.java	2010-03-03 11:42:44 UTC (rev 743)
@@ -10,6 +10,7 @@
 
 import schmitzm.jfree.JFreeChartUtil;
 import schmitzm.lang.LangUtil;
+import schmitzm.swing.SwingUtil;
 
 /**
  * A {@link JComboBox} to select one {@link AggregationFunction}s. Can be
@@ -29,7 +30,7 @@
 				new AggregationFunction[] { null }, AggregationFunction
 						.values()) : AggregationFunction.values());
 		setRenderer(listCellRenderer);
-//		ASUtil.addMouseWheelForCombobox(this, false);
+		SwingUtil.addMouseWheelForCombobox(this, false);
 	}
 
 	/**

Modified: trunk/src/schmitzm/swing/SwingUtil.java
===================================================================
--- trunk/src/schmitzm/swing/SwingUtil.java	2010-03-03 11:31:16 UTC (rev 742)
+++ trunk/src/schmitzm/swing/SwingUtil.java	2010-03-03 11:42:44 UTC (rev 743)
@@ -43,6 +43,7 @@
 import java.awt.Rectangle;
 import java.awt.Toolkit;
 import java.awt.Window;
+import java.awt.event.MouseWheelListener;
 import java.awt.image.BufferedImage;
 import java.text.NumberFormat;
 import java.util.Enumeration;
@@ -53,6 +54,7 @@
 import javax.imageio.ImageIO;
 import javax.swing.AbstractButton;
 import javax.swing.ImageIcon;
+import javax.swing.JComboBox;
 import javax.swing.JDialog;
 import javax.swing.JFrame;
 import javax.swing.JInternalFrame;
@@ -131,8 +133,6 @@
 			"resource/cursor/selection_set.png", 10, 10, null);
 	public static final Cursor SELECTION_REMOVE_CURSOR = createCursorFromResourcePath(
 			"resource/cursor/selection_remove.png", 10, 10, null);
-	
-	
 
 	// public static final ImageIcon ICON_RASTER =
 	// createImageIconFromResourcePath("resource/icon/small/raster.png","");
@@ -1087,12 +1087,12 @@
 		if (bgColor != null)
 			graphics.setBackground(bgColor);
 		graphics.clearRect(0, 0, image.getWidth(), image.getHeight());
-//		Composite composite = graphics.getComposite();
-//		graphics.setComposite(AlphaComposite.Clear);
-//		Rectangle2D.Double rect = new Rectangle2D.Double(0, 0,
-//				image.getWidth(), image.getHeight());
-//		graphics.fill(rect);
-//		graphics.setComposite(composite);
+		// Composite composite = graphics.getComposite();
+		// graphics.setComposite(AlphaComposite.Clear);
+		// Rectangle2D.Double rect = new Rectangle2D.Double(0, 0,
+		// image.getWidth(), image.getHeight());
+		// graphics.fill(rect);
+		// graphics.setComposite(composite);
 	}
 
 	/**
@@ -1107,7 +1107,7 @@
 	 */
 	public static void clearAround(Graphics2D graphics, Rectangle paintArea,
 			Rectangle clearArea, Color bgColor) {
-		
+
 		if (bgColor != null)
 			graphics.setBackground(bgColor);
 
@@ -1141,4 +1141,57 @@
 
 	}
 
+	/**
+	 * Adds a {@link MouseWheelListener} to a {@link JComboBox} => allows to
+	 * scroll through the items with the mouse wheel.
+	 * 
+	 * @param upIsUp
+	 *            Can be used to reverse the wheel (Down => Up in list).
+	 * 
+	 * @author <a href="mailto:skpublic at wikisquare.de">Stefan Alfons
+	 *         Kr&uuml;ger</a>
+	 */
+	public static void addMouseWheelForCombobox(final JComboBox comboBox,
+			final boolean upIsUp) {
+
+		if (comboBox.getMouseWheelListeners().length > 0) {
+			LOGGER
+					.warn("There already exists another MouseWheelListener. I will not add mine!");
+			return;
+		}
+
+		comboBox.addMouseWheelListener(new MouseWheelListener() {
+			public void mouseWheelMoved(final java.awt.event.MouseWheelEvent e) {
+
+				if (!comboBox.isEnabled())
+					return;
+
+				if (e.getWheelRotation() < 0 && upIsUp
+						|| e.getWheelRotation() > 0 && !upIsUp) {
+					if (comboBox.getSelectedIndex() < comboBox.getItemCount() - 1)
+						comboBox
+								.setSelectedIndex(comboBox.getSelectedIndex() + 1);
+				} else {
+					if (comboBox.getSelectedIndex() > 0)
+						comboBox
+								.setSelectedIndex(comboBox.getSelectedIndex() - 1);
+				}
+			}
+		});
+	}
+
+	/**
+	 * Adds a {@link MouseWheelListener} to a {@link JComboBox} => allows to
+	 * scroll through the items with the mouse wheel.<br/>
+	 * By default mouseheel up is up in the list.
+	 * 
+	 * 
+	 * @author <a href="mailto:skpublic at wikisquare.de">Stefan Alfons
+	 *         Kr&uuml;ger</a>
+	 */
+	public static void addMouseWheelForCombobox(
+			final JComboBox comboBoxRuleListType) {
+		addMouseWheelForCombobox(comboBoxRuleListType, true);
+	}
+
 }



More information about the Schmitzm-commits mailing list