< prev index next >

src/share/classes/sun/swing/plaf/synth/DefaultSynthStyle.java

Print this page
rev 1580 : 6727661: Code improvement and warnings removing from the swing/plaf packages
Summary: Removed unnecessary castings and other warnings
Reviewed-by: alexp
Contributed-by: Florian Brunner <fbrunnerlist@gmx.ch>


  27 import javax.swing.plaf.synth.*;
  28 import java.awt.*;
  29 import java.util.*;
  30 import javax.swing.*;
  31 import javax.swing.border.Border;
  32 import javax.swing.plaf.*;
  33 
  34 /**
  35  * Default implementation of SynthStyle. Has setters for the various
  36  * SynthStyle methods. Many of the properties can be specified for all states,
  37  * using SynthStyle directly, or a specific state using one of the StateInfo
  38  * methods.
  39  * <p>
  40  * Beyond the constructor a subclass should override the <code>addTo</code>
  41  * and <code>clone</code> methods, these are used when the Styles are being
  42  * merged into a resulting style.
  43  *
  44  * @author Scott Violet
  45  */
  46 public class DefaultSynthStyle extends SynthStyle implements Cloneable {
  47     private static final Object PENDING = new String("Pending");
  48 
  49     /**
  50      * Should the component be opaque?
  51      */
  52     private boolean opaque;
  53     /**
  54      * Insets.
  55      */
  56     private Insets insets;
  57     /**
  58      * Information specific to ComponentState.
  59      */
  60     private StateInfo[] states;
  61     /**
  62      * User specific data.
  63      */
  64     private Map data;
  65 
  66     /**
  67      * Font to use if there is no matching StateInfo, or the StateInfo doesn't


 673 
 674 
 675     public String toString() {
 676         StringBuffer buf = new StringBuffer();
 677 
 678         buf.append(super.toString()).append(',');
 679 
 680         buf.append("data=").append(data).append(',');
 681 
 682         buf.append("font=").append(font).append(',');
 683 
 684         buf.append("insets=").append(insets).append(',');
 685 
 686         buf.append("synthGraphics=").append(synthGraphics).append(',');
 687 
 688         buf.append("painter=").append(painter).append(',');
 689 
 690         StateInfo[] states = getStateInfo();
 691         if (states != null) {
 692             buf.append("states[");
 693             for (int i = 0; i < states.length; i++) {
 694                 buf.append(states[i].toString()).append(',');
 695             }
 696             buf.append(']').append(',');
 697         }
 698 
 699         // remove last newline
 700         buf.deleteCharAt(buf.length() - 1);
 701 
 702         return buf.toString();
 703     }
 704 
 705 
 706     /**
 707      * StateInfo represents Style information specific to the state of
 708      * a component.
 709      */
 710     public static class StateInfo {
 711         private Map data;
 712         private Font font;
 713         private Color[] colors;
 714         private int state;


 871          * @param state info.
 872          */
 873         public void setComponentState(int state) {
 874             this.state = state;
 875         }
 876 
 877         /**
 878          * Returns the state this StateInfo corresponds to.
 879          *
 880          * @see SynthConstants
 881          * @return state info.
 882          */
 883         public int getComponentState() {
 884             return state;
 885         }
 886 
 887         /**
 888          * Returns the number of states that are similar between the
 889          * ComponentState this StateInfo represents and val.
 890          */
 891         private final int getMatchCount(int val) {
 892             // This comes from BigInteger.bitCnt
 893             val &= state;
 894             val -= (0xaaaaaaaa & val) >>> 1;
 895             val = (val & 0x33333333) + ((val >>> 2) & 0x33333333);
 896             val = val + (val >>> 4) & 0x0f0f0f0f;
 897             val += val >>> 8;
 898             val += val >>> 16;
 899             return val & 0xff;
 900         }
 901 
 902         /**
 903          * Creates and returns a copy of this StateInfo.
 904          *
 905          * @return Copy of this StateInfo.
 906          */
 907         public Object clone() {
 908             return new StateInfo(this);
 909         }
 910 
 911         public String toString() {


  27 import javax.swing.plaf.synth.*;
  28 import java.awt.*;
  29 import java.util.*;
  30 import javax.swing.*;
  31 import javax.swing.border.Border;
  32 import javax.swing.plaf.*;
  33 
  34 /**
  35  * Default implementation of SynthStyle. Has setters for the various
  36  * SynthStyle methods. Many of the properties can be specified for all states,
  37  * using SynthStyle directly, or a specific state using one of the StateInfo
  38  * methods.
  39  * <p>
  40  * Beyond the constructor a subclass should override the <code>addTo</code>
  41  * and <code>clone</code> methods, these are used when the Styles are being
  42  * merged into a resulting style.
  43  *
  44  * @author Scott Violet
  45  */
  46 public class DefaultSynthStyle extends SynthStyle implements Cloneable {
  47     private static final String PENDING = "Pending";
  48 
  49     /**
  50      * Should the component be opaque?
  51      */
  52     private boolean opaque;
  53     /**
  54      * Insets.
  55      */
  56     private Insets insets;
  57     /**
  58      * Information specific to ComponentState.
  59      */
  60     private StateInfo[] states;
  61     /**
  62      * User specific data.
  63      */
  64     private Map data;
  65 
  66     /**
  67      * Font to use if there is no matching StateInfo, or the StateInfo doesn't


 673 
 674 
 675     public String toString() {
 676         StringBuffer buf = new StringBuffer();
 677 
 678         buf.append(super.toString()).append(',');
 679 
 680         buf.append("data=").append(data).append(',');
 681 
 682         buf.append("font=").append(font).append(',');
 683 
 684         buf.append("insets=").append(insets).append(',');
 685 
 686         buf.append("synthGraphics=").append(synthGraphics).append(',');
 687 
 688         buf.append("painter=").append(painter).append(',');
 689 
 690         StateInfo[] states = getStateInfo();
 691         if (states != null) {
 692             buf.append("states[");
 693             for (StateInfo state : states) {
 694                 buf.append(state.toString()).append(',');
 695             }
 696             buf.append(']').append(',');
 697         }
 698 
 699         // remove last newline
 700         buf.deleteCharAt(buf.length() - 1);
 701 
 702         return buf.toString();
 703     }
 704 
 705 
 706     /**
 707      * StateInfo represents Style information specific to the state of
 708      * a component.
 709      */
 710     public static class StateInfo {
 711         private Map data;
 712         private Font font;
 713         private Color[] colors;
 714         private int state;


 871          * @param state info.
 872          */
 873         public void setComponentState(int state) {
 874             this.state = state;
 875         }
 876 
 877         /**
 878          * Returns the state this StateInfo corresponds to.
 879          *
 880          * @see SynthConstants
 881          * @return state info.
 882          */
 883         public int getComponentState() {
 884             return state;
 885         }
 886 
 887         /**
 888          * Returns the number of states that are similar between the
 889          * ComponentState this StateInfo represents and val.
 890          */
 891         private int getMatchCount(int val) {
 892             // This comes from BigInteger.bitCnt
 893             val &= state;
 894             val -= (0xaaaaaaaa & val) >>> 1;
 895             val = (val & 0x33333333) + ((val >>> 2) & 0x33333333);
 896             val = val + (val >>> 4) & 0x0f0f0f0f;
 897             val += val >>> 8;
 898             val += val >>> 16;
 899             return val & 0xff;
 900         }
 901 
 902         /**
 903          * Creates and returns a copy of this StateInfo.
 904          *
 905          * @return Copy of this StateInfo.
 906          */
 907         public Object clone() {
 908             return new StateInfo(this);
 909         }
 910 
 911         public String toString() {
< prev index next >