From: <doc...@us...> - 2007-08-21 20:15:16
|
Revision: 157 http://openpcl.svn.sourceforge.net/openpcl/?rev=157&view=rev Author: documentsystems Date: 2007-08-21 13:14:39 -0700 (Tue, 21 Aug 2007) Log Message: ----------- Howard Hoagland. Changed PosToolbarDropdownItemRenderer to change the background color on JLabels in JLists by which one the mouse is hovering over, which was set in PosHoverColorMouseMotionAdapter so the user has visual confirmation of which item in the drop down will be seleced if clicked there. Modified Paths: -------------- openpcl/src/com/openpcl/viewer/util/PosToolbarDropdownItemRenderer.java Modified: openpcl/src/com/openpcl/viewer/util/PosToolbarDropdownItemRenderer.java =================================================================== --- openpcl/src/com/openpcl/viewer/util/PosToolbarDropdownItemRenderer.java 2007-08-21 20:09:04 UTC (rev 156) +++ openpcl/src/com/openpcl/viewer/util/PosToolbarDropdownItemRenderer.java 2007-08-21 20:14:39 UTC (rev 157) @@ -1,10 +1,13 @@ package com.openpcl.viewer.util; +import java.awt.Color; import java.awt.Component; import javax.swing.DefaultListCellRenderer; import javax.swing.JLabel; import javax.swing.JList; +import javax.swing.SwingConstants; +import javax.swing.UIManager; /** * Subclass of the DefaultListCellRenderer which is a subclass of JLabel. @@ -17,6 +20,8 @@ */ public class PosToolbarDropdownItemRenderer extends DefaultListCellRenderer { private static final long serialVersionUID = 1L; + private Color mBkgSelectionColor = null; + private Color mBkgNonSelectionColor = null; @Override public Component getListCellRendererComponent( @@ -24,11 +29,23 @@ super.getListCellRendererComponent(pList, pValue, pIndex, pIsSelected, pCellHasFocus); - + + // Need to get the color again every time because the user might have changed the Look and Feel from last time + mBkgSelectionColor = UIManager.getColor("List.selectionBackground"); + mBkgNonSelectionColor = UIManager.getColor("List.background"); + if (pValue instanceof JLabel) { JLabel tJLabel = (JLabel)pValue; setIcon(tJLabel.getIcon()); setText(tJLabel.getText()); + + if (tJLabel.getVerticalAlignment() == SwingConstants.TOP) { + // Setting the vertical alignment to TOP doesn't change the text placement when a JLabel is in a JList, but this + // is a trick to use something in a JLabel to know which JLabel in the JList the mouse is hovering over right now. + setBackground(mBkgSelectionColor); + } else { + setBackground(mBkgNonSelectionColor); + } } return this; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |