jdk/src/java.desktop/macosx/classes/apple/laf/JRSUIConstants.java
changeset 40719 4ae72a69bd3b
parent 25859 3317bb8137f4
child 44654 ca968890962d
equal deleted inserted replaced
40718:fe2adbe4d101 40719:4ae72a69bd3b
    23  * questions.
    23  * questions.
    24  */
    24  */
    25 
    25 
    26 package apple.laf;
    26 package apple.laf;
    27 
    27 
    28 import java.lang.reflect.Field;
       
    29 import java.nio.ByteBuffer;
    28 import java.nio.ByteBuffer;
    30 
    29 
    31 import java.lang.annotation.Native;
    30 import java.lang.annotation.Native;
    32 
    31 
    33 public final class JRSUIConstants {
    32 public final class JRSUIConstants {
    66         long getConstantPtr() {
    65         long getConstantPtr() {
    67             if (ptr != 0) return ptr;
    66             if (ptr != 0) return ptr;
    68             ptr = getPtrForConstant(constant);
    67             ptr = getPtrForConstant(constant);
    69             if (ptr != 0) return ptr;
    68             if (ptr != 0) return ptr;
    70             throw new RuntimeException("Constant not implemented in native: " + this);
    69             throw new RuntimeException("Constant not implemented in native: " + this);
       
    70         }
       
    71 
       
    72         private String getConstantName(Key hit) {
       
    73             if (hit == VALUE) {
       
    74                 return "VALUE";
       
    75             } else if (hit == THUMB_PROPORTION) {
       
    76                 return "THUMB_PROPORTION";
       
    77             } else if (hit == THUMB_START) {
       
    78                 return "THUMB_START";
       
    79             } else if (hit == WINDOW_TITLE_BAR_HEIGHT) {
       
    80                 return "WINDOW_TITLE_BAR_HEIGHT";
       
    81             } else if (hit == THUMB_START) {
       
    82                 return "ANIMATION_FRAME";
       
    83             }
       
    84             return getClass().getSimpleName();
    71         }
    85         }
    72 
    86 
    73         public String toString() {
    87         public String toString() {
    74             return getConstantName(this) + (ptr == 0 ? "(unlinked)" : "");
    88             return getConstantName(this) + (ptr == 0 ? "(unlinked)" : "");
    75         }
    89         }
   136         public long apply(final long encodedState) {
   150         public long apply(final long encodedState) {
   137             return (encodedState & ~encoding.mask) | value;
   151             return (encodedState & ~encoding.mask) | value;
   138         }
   152         }
   139 
   153 
   140         public String toString() {
   154         public String toString() {
   141             return getConstantName(this);
   155             return getClass().getSimpleName();
   142         }
   156         }
   143     }
   157     }
   144 
   158 
   145     public static class Size extends Property {
   159     public static class Size extends Property {
   146         @Native private static final byte SHIFT = 0;
   160         @Native private static final byte SHIFT = 0;
   777 
   791 
   778         public boolean isHit() {
   792         public boolean isHit() {
   779             return hit > 0;
   793             return hit > 0;
   780         }
   794         }
   781 
   795 
       
   796         private String getConstantName(Hit hit) {
       
   797             if (hit == UNKNOWN) {
       
   798                 return "UNKNOWN";
       
   799             } else if (hit == NONE) {
       
   800                 return "NONE";
       
   801             } else if (hit == HIT) {
       
   802                 return "HIT";
       
   803             }
       
   804             return getClass().getSimpleName();
       
   805         }
       
   806 
   782         public String toString() {
   807         public String toString() {
   783             return getConstantName(this);
   808             return getConstantName(this);
   784         }
   809         }
   785     }
   810     }
   786 
   811 
   827             case ScrollBarHit._arrowMinInside:
   852             case ScrollBarHit._arrowMinInside:
   828                 return ScrollBarHit.ARROW_MIN_INSIDE;
   853                 return ScrollBarHit.ARROW_MIN_INSIDE;
   829         }
   854         }
   830         return Hit.UNKNOWN;
   855         return Hit.UNKNOWN;
   831     }
   856     }
   832 
       
   833     static String getConstantName(final Object object) {
       
   834         final Class<? extends Object> clazz = object.getClass();
       
   835         try {
       
   836             for (final Field field : clazz.getFields()) {
       
   837                 if (field.get(null) == object) {
       
   838                     return field.getName();
       
   839                 }
       
   840             }
       
   841         } catch (final Exception e) {}
       
   842         return clazz.getSimpleName();
       
   843     }
       
   844 }
   857 }