From: <doc...@us...> - 2007-08-21 20:09:16
|
Revision: 156 http://openpcl.svn.sourceforge.net/openpcl/?rev=156&view=rev Author: documentsystems Date: 2007-08-21 13:09:04 -0700 (Tue, 21 Aug 2007) Log Message: ----------- Howard Hoagland. Added new class PosHoverColorMouseMotionAdapter to set a value in the hovered over JLabel in the JList that causes the PosToolbarDropdownItemRenderer to set the background color as the user moves the mouse from one selection to another so the user has visual confirmation of which item in the drop down will be seleced if clicked there. Added Paths: ----------- openpcl/src/com/openpcl/viewer/util/PosHoverColorMouseMotionAdapter.java Added: openpcl/src/com/openpcl/viewer/util/PosHoverColorMouseMotionAdapter.java =================================================================== --- openpcl/src/com/openpcl/viewer/util/PosHoverColorMouseMotionAdapter.java (rev 0) +++ openpcl/src/com/openpcl/viewer/util/PosHoverColorMouseMotionAdapter.java 2007-08-21 20:09:04 UTC (rev 156) @@ -0,0 +1,65 @@ +package com.openpcl.viewer.util; + +import java.awt.Point; +import java.awt.event.MouseEvent; +import java.awt.event.MouseMotionAdapter; + +import javax.swing.JLabel; +import javax.swing.JList; +import javax.swing.SwingConstants; + +/** + * Mouse motion adapter to set a value in the hovered over JLabel in the JList that causes the + * PosToolbarDropdownItemRenderer to set the background color as the user moves the mouse from one selection to another + * so the user has visual confirmation of which item in the drop down will be seleced if clicked there. + * + * @author DocMagic, Document Systems Inc, HowardH. 8/20/07 + */ +public class PosHoverColorMouseMotionAdapter extends MouseMotionAdapter { + private JList mJList = null; + private int mLastHoverIndex = -1; + private int mCurrentHoverIndex = -1; + private Object mHoverObject = null; + + public PosHoverColorMouseMotionAdapter(JList pJList) { + super(); + mJList = pJList; + } + + public void mouseMoved(MouseEvent pE) { + mCurrentHoverIndex = mJList.locationToIndex(new Point(pE.getX(), pE.getY())); + if (mCurrentHoverIndex < 0) { return; } + + if (mLastHoverIndex < 0 ) { + // Get the item in the JList that is being hovered over + mHoverObject = mJList.getModel().getElementAt(mCurrentHoverIndex); + if (mHoverObject instanceof JLabel) { + // Change the background to the current Look and Feel selection color + ((JLabel)mHoverObject).setVerticalAlignment(SwingConstants.TOP); + mJList.repaint(); + } + + // When Last was not set yet, make last same as current + mLastHoverIndex = mCurrentHoverIndex; + + } else if (mCurrentHoverIndex != mLastHoverIndex) { + // Get the item in the JList that was hovered over but isn't now + mHoverObject = mJList.getModel().getElementAt(mLastHoverIndex); + if (mHoverObject instanceof JLabel) { + // Change the background to the current Look and Feel non selection color + ((JLabel)mHoverObject).setVerticalAlignment(SwingConstants.CENTER); + } + + // Get the item in the JList that is being hovered over + mHoverObject = mJList.getModel().getElementAt(mCurrentHoverIndex); + if (mHoverObject instanceof JLabel) { + // Change the background to the current Look and Feel selection color + ((JLabel)mHoverObject).setVerticalAlignment(SwingConstants.TOP); + mJList.repaint(); + } + + // Make last same as current + mLastHoverIndex = mCurrentHoverIndex; + } + } +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |