src/java.desktop/macosx/classes/com/apple/laf/AquaButtonExtendedTypes.java

Print this page




  46 public class AquaButtonExtendedTypes {
  47     protected static Border getBorderForPosition(final AbstractButton c, final Object type, final Object logicalPosition) {
  48         final String name = (logicalPosition == null ? (String)type : type + "-" + getRealPositionForLogicalPosition((String)logicalPosition, c.getComponentOrientation().isLeftToRight()));
  49         final TypeSpecifier specifier = getSpecifierByName(name);
  50         if (specifier == null) return null;
  51 
  52         final Border border = specifier.getBorder();
  53         if (!(border instanceof AquaBorder)) return border;
  54 
  55         return ((AquaBorder)border).deriveBorderForSize(AquaUtilControlSize.getUserSizeFrom(c));
  56     }
  57 
  58     protected static String getRealPositionForLogicalPosition(String logicalPosition, boolean leftToRight) {
  59         if (!leftToRight) {
  60             if ("first".equalsIgnoreCase(logicalPosition)) return "last";
  61             if ("last".equalsIgnoreCase(logicalPosition)) return "first";
  62         }
  63         return logicalPosition;
  64     }
  65 
  66     static abstract class TypeSpecifier {
  67         final String name;
  68         final boolean setIconFont;
  69 
  70         TypeSpecifier(final String name, final boolean setIconFont) {
  71             this.name = name; this.setIconFont = setIconFont;
  72         }
  73 
  74         abstract Border getBorder();
  75     }
  76 
  77     static class BorderDefinedTypeSpecifier extends TypeSpecifier {
  78         final AquaBorder border;
  79 
  80         BorderDefinedTypeSpecifier(final String name, final Widget widget, final SizeVariant variant) {
  81             this(name, widget, variant, 0, 0, 0, 0);
  82         }
  83 
  84         BorderDefinedTypeSpecifier(final String name, final Widget widget, final SizeVariant variant, final int smallW, final int smallH, final int miniW, final int miniH) {
  85             super(name, false);
  86             border = initBorder(widget, new SizeDescriptor(variant) {


 121     }
 122 
 123     public static class SegmentedNamedBorder extends AquaButtonBorder.Named {
 124         public SegmentedNamedBorder(final SegmentedNamedBorder sizeDescriptor) {
 125             super(sizeDescriptor);
 126         }
 127 
 128         public SegmentedNamedBorder(final Widget widget, final SizeDescriptor sizeDescriptor) {
 129             super(widget, sizeDescriptor);
 130         }
 131 
 132         protected boolean isSelectionPressing() {
 133             return false;
 134         }
 135     }
 136 
 137     protected static TypeSpecifier getSpecifierByName(final String name) {
 138         return typeDefinitions.get().get(name);
 139     }
 140 
 141     protected final static RecyclableSingleton<Map<String, TypeSpecifier>> typeDefinitions = new RecyclableSingleton<Map<String, TypeSpecifier>>() {
 142         protected Map<String, TypeSpecifier> getInstance() {
 143             return getAllTypes();
 144         }
 145     };
 146 
 147     protected static Map<String, TypeSpecifier> getAllTypes() {
 148         final Map<String, TypeSpecifier> specifiersByName = new HashMap<String, TypeSpecifier>();
 149 
 150         final Insets focusInsets = new Insets(FOCUS_SIZE, FOCUS_SIZE,
 151                                               FOCUS_SIZE, FOCUS_SIZE);
 152 
 153         final TypeSpecifier[] specifiers = {
 154             new TypeSpecifier("toolbar", true) {
 155                 Border getBorder() { return AquaButtonBorder.getToolBarButtonBorder(); }
 156             },
 157             new TypeSpecifier("icon", true) {
 158                 Border getBorder() { return AquaButtonBorder.getToggleButtonBorder(); }
 159             },
 160             new TypeSpecifier("text", false) {
 161                 Border getBorder() { return UIManager.getBorder("Button.border"); }




  46 public class AquaButtonExtendedTypes {
  47     protected static Border getBorderForPosition(final AbstractButton c, final Object type, final Object logicalPosition) {
  48         final String name = (logicalPosition == null ? (String)type : type + "-" + getRealPositionForLogicalPosition((String)logicalPosition, c.getComponentOrientation().isLeftToRight()));
  49         final TypeSpecifier specifier = getSpecifierByName(name);
  50         if (specifier == null) return null;
  51 
  52         final Border border = specifier.getBorder();
  53         if (!(border instanceof AquaBorder)) return border;
  54 
  55         return ((AquaBorder)border).deriveBorderForSize(AquaUtilControlSize.getUserSizeFrom(c));
  56     }
  57 
  58     protected static String getRealPositionForLogicalPosition(String logicalPosition, boolean leftToRight) {
  59         if (!leftToRight) {
  60             if ("first".equalsIgnoreCase(logicalPosition)) return "last";
  61             if ("last".equalsIgnoreCase(logicalPosition)) return "first";
  62         }
  63         return logicalPosition;
  64     }
  65 
  66     abstract static class TypeSpecifier {
  67         final String name;
  68         final boolean setIconFont;
  69 
  70         TypeSpecifier(final String name, final boolean setIconFont) {
  71             this.name = name; this.setIconFont = setIconFont;
  72         }
  73 
  74         abstract Border getBorder();
  75     }
  76 
  77     static class BorderDefinedTypeSpecifier extends TypeSpecifier {
  78         final AquaBorder border;
  79 
  80         BorderDefinedTypeSpecifier(final String name, final Widget widget, final SizeVariant variant) {
  81             this(name, widget, variant, 0, 0, 0, 0);
  82         }
  83 
  84         BorderDefinedTypeSpecifier(final String name, final Widget widget, final SizeVariant variant, final int smallW, final int smallH, final int miniW, final int miniH) {
  85             super(name, false);
  86             border = initBorder(widget, new SizeDescriptor(variant) {


 121     }
 122 
 123     public static class SegmentedNamedBorder extends AquaButtonBorder.Named {
 124         public SegmentedNamedBorder(final SegmentedNamedBorder sizeDescriptor) {
 125             super(sizeDescriptor);
 126         }
 127 
 128         public SegmentedNamedBorder(final Widget widget, final SizeDescriptor sizeDescriptor) {
 129             super(widget, sizeDescriptor);
 130         }
 131 
 132         protected boolean isSelectionPressing() {
 133             return false;
 134         }
 135     }
 136 
 137     protected static TypeSpecifier getSpecifierByName(final String name) {
 138         return typeDefinitions.get().get(name);
 139     }
 140 
 141     protected static final RecyclableSingleton<Map<String, TypeSpecifier>> typeDefinitions = new RecyclableSingleton<Map<String, TypeSpecifier>>() {
 142         protected Map<String, TypeSpecifier> getInstance() {
 143             return getAllTypes();
 144         }
 145     };
 146 
 147     protected static Map<String, TypeSpecifier> getAllTypes() {
 148         final Map<String, TypeSpecifier> specifiersByName = new HashMap<String, TypeSpecifier>();
 149 
 150         final Insets focusInsets = new Insets(FOCUS_SIZE, FOCUS_SIZE,
 151                                               FOCUS_SIZE, FOCUS_SIZE);
 152 
 153         final TypeSpecifier[] specifiers = {
 154             new TypeSpecifier("toolbar", true) {
 155                 Border getBorder() { return AquaButtonBorder.getToolBarButtonBorder(); }
 156             },
 157             new TypeSpecifier("icon", true) {
 158                 Border getBorder() { return AquaButtonBorder.getToggleButtonBorder(); }
 159             },
 160             new TypeSpecifier("text", false) {
 161                 Border getBorder() { return UIManager.getBorder("Button.border"); }