src/share/classes/com/sun/java/swing/plaf/motif/MotifComboBoxUI.java

Print this page


   1 /*
   2  * Copyright (c) 1997, 2006, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  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


  27 import java.awt.*;
  28 import javax.swing.*;
  29 import javax.swing.plaf.*;
  30 import javax.swing.border.*;
  31 import javax.swing.plaf.basic.*;
  32 import java.io.Serializable;
  33 import java.awt.event.*;
  34 import java.beans.*;
  35 
  36 /**
  37  * ComboBox motif look and feel
  38  * <p> * <strong>Warning:</strong>
  39  * Serialized objects of this class will not be compatible with
  40  * future Swing releases.  The current serialization support is appropriate
  41  * for short term storage or RMI between applications running the same
  42  * version of Swing.  A future release of Swing will provide support for
  43  * long term persistence.
  44  *
  45  * @author Arnaud Weber
  46  */

  47 public class MotifComboBoxUI extends BasicComboBoxUI implements Serializable {
  48     Icon arrowIcon;
  49     static final int HORIZ_MARGIN = 3;
  50 
  51     public static ComponentUI createUI(JComponent c) {
  52         return new MotifComboBoxUI();
  53     }
  54 
  55     public void installUI(JComponent c) {
  56         super.installUI(c);
  57         arrowIcon = new MotifComboBoxArrowIcon(UIManager.getColor("controlHighlight"),
  58                                                UIManager.getColor("controlShadow"),
  59                                                UIManager.getColor("control"));
  60 
  61         Runnable initCode = new Runnable() {
  62             public void run(){
  63                 if ( motifGetEditor() != null ) {
  64                     motifGetEditor().setBackground( UIManager.getColor( "text" ) );
  65                 }
  66             }


  76         Dimension size;
  77         Insets insets = getInsets();
  78         size = getDisplaySize();
  79         size.height += insets.top + insets.bottom;
  80         int buttonSize = iconAreaWidth();
  81         size.width +=  insets.left + insets.right + buttonSize;
  82 
  83         cachedMinimumSize.setSize( size.width, size.height );
  84         isMinimumSizeDirty = false;
  85 
  86         return size;
  87     }
  88 
  89     protected ComboPopup createPopup() {
  90         return new MotifComboPopup( comboBox );
  91     }
  92 
  93     /**
  94      * Overriden to empty the MouseMotionListener.
  95      */

  96     protected class MotifComboPopup extends BasicComboPopup {
  97 
  98         public MotifComboPopup( JComboBox comboBox ) {
  99             super( comboBox );
 100         }
 101 
 102         /**
 103          * Motif combo popup should not track the mouse in the list.
 104          */
 105         public MouseMotionListener createListMouseMotionListener() {
 106            return new MouseMotionAdapter() {};
 107         }
 108 
 109         public KeyListener createKeyListener() {
 110             return super.createKeyListener();
 111         }
 112 
 113         protected class InvocationKeyHandler extends BasicComboPopup.InvocationKeyHandler {
 114             protected InvocationKeyHandler() {
 115                 MotifComboPopup.this.super();


 262      * This inner class is marked &quot;public&quot; due to a compiler bug.
 263      * This class should be treated as a &quot;protected&quot; inner class.
 264      * Instantiate it only within subclasses of <FooUI>.
 265      */
 266     public class ComboBoxLayoutManager extends BasicComboBoxUI.ComboBoxLayoutManager {
 267         public ComboBoxLayoutManager() {
 268             MotifComboBoxUI.this.super();
 269         }
 270         public void layoutContainer(Container parent) {
 271             if ( motifGetEditor() != null ) {
 272                 Rectangle cvb = rectangleForCurrentValue();
 273                 cvb.x += 1;
 274                 cvb.y += 1;
 275                 cvb.width -= 1;
 276                 cvb.height -= 2;
 277                 motifGetEditor().setBounds(cvb);
 278             }
 279         }
 280     }
 281 

 282     static class MotifComboBoxArrowIcon implements Icon, Serializable {
 283         private Color lightShadow;
 284         private Color darkShadow;
 285         private Color fill;
 286 
 287         public MotifComboBoxArrowIcon(Color lightShadow, Color darkShadow, Color fill) {
 288             this.lightShadow = lightShadow;
 289             this.darkShadow = darkShadow;
 290             this.fill = fill;
 291         }
 292 
 293 
 294         public void paintIcon(Component c, Graphics g, int xo, int yo) {
 295             int w = getIconWidth();
 296             int h = getIconHeight();
 297 
 298             g.setColor(lightShadow);
 299             g.drawLine(xo, yo, xo+w-1, yo);
 300             g.drawLine(xo, yo+1, xo+w-3, yo+1);
 301             g.setColor(darkShadow);


   1 /*
   2  * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  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


  27 import java.awt.*;
  28 import javax.swing.*;
  29 import javax.swing.plaf.*;
  30 import javax.swing.border.*;
  31 import javax.swing.plaf.basic.*;
  32 import java.io.Serializable;
  33 import java.awt.event.*;
  34 import java.beans.*;
  35 
  36 /**
  37  * ComboBox motif look and feel
  38  * <p> * <strong>Warning:</strong>
  39  * Serialized objects of this class will not be compatible with
  40  * future Swing releases.  The current serialization support is appropriate
  41  * for short term storage or RMI between applications running the same
  42  * version of Swing.  A future release of Swing will provide support for
  43  * long term persistence.
  44  *
  45  * @author Arnaud Weber
  46  */
  47 @SuppressWarnings("serial") // Same-version serialization only
  48 public class MotifComboBoxUI extends BasicComboBoxUI implements Serializable {
  49     Icon arrowIcon;
  50     static final int HORIZ_MARGIN = 3;
  51 
  52     public static ComponentUI createUI(JComponent c) {
  53         return new MotifComboBoxUI();
  54     }
  55 
  56     public void installUI(JComponent c) {
  57         super.installUI(c);
  58         arrowIcon = new MotifComboBoxArrowIcon(UIManager.getColor("controlHighlight"),
  59                                                UIManager.getColor("controlShadow"),
  60                                                UIManager.getColor("control"));
  61 
  62         Runnable initCode = new Runnable() {
  63             public void run(){
  64                 if ( motifGetEditor() != null ) {
  65                     motifGetEditor().setBackground( UIManager.getColor( "text" ) );
  66                 }
  67             }


  77         Dimension size;
  78         Insets insets = getInsets();
  79         size = getDisplaySize();
  80         size.height += insets.top + insets.bottom;
  81         int buttonSize = iconAreaWidth();
  82         size.width +=  insets.left + insets.right + buttonSize;
  83 
  84         cachedMinimumSize.setSize( size.width, size.height );
  85         isMinimumSizeDirty = false;
  86 
  87         return size;
  88     }
  89 
  90     protected ComboPopup createPopup() {
  91         return new MotifComboPopup( comboBox );
  92     }
  93 
  94     /**
  95      * Overriden to empty the MouseMotionListener.
  96      */
  97     @SuppressWarnings("serial") // Superclass is not serializable across versions
  98     protected class MotifComboPopup extends BasicComboPopup {
  99 
 100         public MotifComboPopup( JComboBox comboBox ) {
 101             super( comboBox );
 102         }
 103 
 104         /**
 105          * Motif combo popup should not track the mouse in the list.
 106          */
 107         public MouseMotionListener createListMouseMotionListener() {
 108            return new MouseMotionAdapter() {};
 109         }
 110 
 111         public KeyListener createKeyListener() {
 112             return super.createKeyListener();
 113         }
 114 
 115         protected class InvocationKeyHandler extends BasicComboPopup.InvocationKeyHandler {
 116             protected InvocationKeyHandler() {
 117                 MotifComboPopup.this.super();


 264      * This inner class is marked &quot;public&quot; due to a compiler bug.
 265      * This class should be treated as a &quot;protected&quot; inner class.
 266      * Instantiate it only within subclasses of <FooUI>.
 267      */
 268     public class ComboBoxLayoutManager extends BasicComboBoxUI.ComboBoxLayoutManager {
 269         public ComboBoxLayoutManager() {
 270             MotifComboBoxUI.this.super();
 271         }
 272         public void layoutContainer(Container parent) {
 273             if ( motifGetEditor() != null ) {
 274                 Rectangle cvb = rectangleForCurrentValue();
 275                 cvb.x += 1;
 276                 cvb.y += 1;
 277                 cvb.width -= 1;
 278                 cvb.height -= 2;
 279                 motifGetEditor().setBounds(cvb);
 280             }
 281         }
 282     }
 283 
 284     @SuppressWarnings("serial") // Same-version serialization only
 285     static class MotifComboBoxArrowIcon implements Icon, Serializable {
 286         private Color lightShadow;
 287         private Color darkShadow;
 288         private Color fill;
 289 
 290         public MotifComboBoxArrowIcon(Color lightShadow, Color darkShadow, Color fill) {
 291             this.lightShadow = lightShadow;
 292             this.darkShadow = darkShadow;
 293             this.fill = fill;
 294         }
 295 
 296 
 297         public void paintIcon(Component c, Graphics g, int xo, int yo) {
 298             int w = getIconWidth();
 299             int h = getIconHeight();
 300 
 301             g.setColor(lightShadow);
 302             g.drawLine(xo, yo, xo+w-1, yo);
 303             g.drawLine(xo, yo+1, xo+w-3, yo+1);
 304             g.setColor(darkShadow);