19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package javax.swing.plaf.basic;
27
28 import javax.accessibility.AccessibleContext;
29 import javax.swing.*;
30 import javax.swing.border.Border;
31 import javax.swing.border.LineBorder;
32 import javax.swing.event.*;
33 import java.awt.*;
34 import java.awt.event.*;
35 import java.beans.PropertyChangeListener;
36 import java.beans.PropertyChangeEvent;
37 import java.io.Serializable;
38
39
40 /**
41 * This is a basic implementation of the <code>ComboPopup</code> interface.
42 *
43 * This class represents the ui for the popup portion of the combo box.
44 * <p>
45 * All event handling is handled by listener classes created with the
46 * <code>createxxxListener()</code> methods and internal classes.
47 * You can change the behavior of this class by overriding the
48 * <code>createxxxListener()</code> methods and supplying your own
49 * event listeners or subclassing from the ones supplied in this class.
50 * <p>
51 * <strong>Warning:</strong>
52 * Serialized objects of this class will not be compatible with
53 * future Swing releases. The current serialization support is
54 * appropriate for short term storage or RMI between applications running
55 * the same version of Swing. As of 1.4, support for long term storage
56 * of all JavaBeans™
57 * has been added to the <code>java.beans</code> package.
58 * Please see {@link java.beans.XMLEncoder}.
517 handler = new Handler();
518 }
519 return handler;
520 }
521
522 /**
523 * Creates the JList used in the popup to display
524 * the items in the combo box model. This method is called when the UI class
525 * is created.
526 *
527 * @return a <code>JList</code> used to display the combo box items
528 */
529 protected JList<Object> createList() {
530 return new JList<Object>( comboBox.getModel() ) {
531 @SuppressWarnings("deprecation")
532 public void processMouseEvent(MouseEvent e) {
533 if (BasicGraphicsUtils.isMenuShortcutKeyDown(e)) {
534 // Fix for 4234053. Filter out the Control Key from the list.
535 // ie., don't allow CTRL key deselection.
536 Toolkit toolkit = Toolkit.getDefaultToolkit();
537 e = new MouseEvent((Component)e.getSource(), e.getID(), e.getWhen(),
538 e.getModifiers() ^ toolkit.getMenuShortcutKeyMask(),
539 e.getX(), e.getY(),
540 e.getXOnScreen(), e.getYOnScreen(),
541 e.getClickCount(),
542 e.isPopupTrigger(),
543 MouseEvent.NOBUTTON);
544 }
545 super.processMouseEvent(e);
546 }
547 };
548 }
549
550 /**
551 * Configures the list which is used to hold the combo box items in the
552 * popup. This method is called when the UI class
553 * is created.
554 *
555 * @see #createList
556 */
557 protected void configureList() {
558 list.setFont( comboBox.getFont() );
559 list.setForeground( comboBox.getForeground() );
560 list.setBackground( comboBox.getBackground() );
561 list.setSelectionForeground( UIManager.getColor( "ComboBox.selectionForeground" ) );
562 list.setSelectionBackground( UIManager.getColor( "ComboBox.selectionBackground" ) );
563 list.setBorder( null );
1234 * Converts mouse event.
1235 *
1236 * @param e a mouse event
1237 * @return converted mouse event
1238 */
1239 protected MouseEvent convertMouseEvent( MouseEvent e ) {
1240 Point convertedPoint = SwingUtilities.convertPoint( (Component)e.getSource(),
1241 e.getPoint(), list );
1242 @SuppressWarnings("deprecation")
1243 MouseEvent newEvent = new MouseEvent( (Component)e.getSource(),
1244 e.getID(),
1245 e.getWhen(),
1246 e.getModifiers(),
1247 convertedPoint.x,
1248 convertedPoint.y,
1249 e.getXOnScreen(),
1250 e.getYOnScreen(),
1251 e.getClickCount(),
1252 e.isPopupTrigger(),
1253 MouseEvent.NOBUTTON );
1254 return newEvent;
1255 }
1256
1257
1258 /**
1259 * Retrieves the height of the popup based on the current
1260 * ListCellRenderer and the maximum row count.
1261 *
1262 * @param maxRowCount the row count
1263 * @return the height of the popup
1264 */
1265 protected int getPopupHeightForRowCount(int maxRowCount) {
1266 // Set the cached value of the minimum row count
1267 int minRowCount = Math.min( maxRowCount, comboBox.getItemCount() );
1268 int height = 0;
1269 ListCellRenderer<Object> renderer = list.getCellRenderer();
1270 Object value = null;
1271
1272 for ( int i = 0; i < minRowCount; ++i ) {
1273 value = list.getModel().getElementAt( i );
|
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package javax.swing.plaf.basic;
27
28 import javax.accessibility.AccessibleContext;
29 import javax.swing.*;
30 import javax.swing.border.Border;
31 import javax.swing.border.LineBorder;
32 import javax.swing.event.*;
33 import java.awt.*;
34 import java.awt.event.*;
35 import java.beans.PropertyChangeListener;
36 import java.beans.PropertyChangeEvent;
37 import java.io.Serializable;
38
39 import sun.awt.AWTAccessor;
40 import sun.awt.AWTAccessor.MouseEventAccessor;
41
42 /**
43 * This is a basic implementation of the <code>ComboPopup</code> interface.
44 *
45 * This class represents the ui for the popup portion of the combo box.
46 * <p>
47 * All event handling is handled by listener classes created with the
48 * <code>createxxxListener()</code> methods and internal classes.
49 * You can change the behavior of this class by overriding the
50 * <code>createxxxListener()</code> methods and supplying your own
51 * event listeners or subclassing from the ones supplied in this class.
52 * <p>
53 * <strong>Warning:</strong>
54 * Serialized objects of this class will not be compatible with
55 * future Swing releases. The current serialization support is
56 * appropriate for short term storage or RMI between applications running
57 * the same version of Swing. As of 1.4, support for long term storage
58 * of all JavaBeans™
59 * has been added to the <code>java.beans</code> package.
60 * Please see {@link java.beans.XMLEncoder}.
519 handler = new Handler();
520 }
521 return handler;
522 }
523
524 /**
525 * Creates the JList used in the popup to display
526 * the items in the combo box model. This method is called when the UI class
527 * is created.
528 *
529 * @return a <code>JList</code> used to display the combo box items
530 */
531 protected JList<Object> createList() {
532 return new JList<Object>( comboBox.getModel() ) {
533 @SuppressWarnings("deprecation")
534 public void processMouseEvent(MouseEvent e) {
535 if (BasicGraphicsUtils.isMenuShortcutKeyDown(e)) {
536 // Fix for 4234053. Filter out the Control Key from the list.
537 // ie., don't allow CTRL key deselection.
538 Toolkit toolkit = Toolkit.getDefaultToolkit();
539 MouseEvent newEvent = new MouseEvent(
540 (Component)e.getSource(), e.getID(), e.getWhen(),
541 e.getModifiers() ^ toolkit.getMenuShortcutKeyMask(),
542 e.getX(), e.getY(),
543 e.getXOnScreen(), e.getYOnScreen(),
544 e.getClickCount(),
545 e.isPopupTrigger(),
546 MouseEvent.NOBUTTON);
547 MouseEventAccessor meAccessor = AWTAccessor.getMouseEventAccessor();
548 meAccessor.setCausedByTouchEvent(newEvent,
549 meAccessor.isCausedByTouchEvent(e));
550 e = newEvent;
551 }
552 super.processMouseEvent(e);
553 }
554 };
555 }
556
557 /**
558 * Configures the list which is used to hold the combo box items in the
559 * popup. This method is called when the UI class
560 * is created.
561 *
562 * @see #createList
563 */
564 protected void configureList() {
565 list.setFont( comboBox.getFont() );
566 list.setForeground( comboBox.getForeground() );
567 list.setBackground( comboBox.getBackground() );
568 list.setSelectionForeground( UIManager.getColor( "ComboBox.selectionForeground" ) );
569 list.setSelectionBackground( UIManager.getColor( "ComboBox.selectionBackground" ) );
570 list.setBorder( null );
1241 * Converts mouse event.
1242 *
1243 * @param e a mouse event
1244 * @return converted mouse event
1245 */
1246 protected MouseEvent convertMouseEvent( MouseEvent e ) {
1247 Point convertedPoint = SwingUtilities.convertPoint( (Component)e.getSource(),
1248 e.getPoint(), list );
1249 @SuppressWarnings("deprecation")
1250 MouseEvent newEvent = new MouseEvent( (Component)e.getSource(),
1251 e.getID(),
1252 e.getWhen(),
1253 e.getModifiers(),
1254 convertedPoint.x,
1255 convertedPoint.y,
1256 e.getXOnScreen(),
1257 e.getYOnScreen(),
1258 e.getClickCount(),
1259 e.isPopupTrigger(),
1260 MouseEvent.NOBUTTON );
1261 MouseEventAccessor meAccessor = AWTAccessor.getMouseEventAccessor();
1262 meAccessor.setCausedByTouchEvent(newEvent,
1263 meAccessor.isCausedByTouchEvent(e));
1264 return newEvent;
1265 }
1266
1267
1268 /**
1269 * Retrieves the height of the popup based on the current
1270 * ListCellRenderer and the maximum row count.
1271 *
1272 * @param maxRowCount the row count
1273 * @return the height of the popup
1274 */
1275 protected int getPopupHeightForRowCount(int maxRowCount) {
1276 // Set the cached value of the minimum row count
1277 int minRowCount = Math.min( maxRowCount, comboBox.getItemCount() );
1278 int height = 0;
1279 ListCellRenderer<Object> renderer = list.getCellRenderer();
1280 Object value = null;
1281
1282 for ( int i = 0; i < minRowCount; ++i ) {
1283 value = list.getModel().getElementAt( i );
|