1 19 package swingwt.awt; 20 21 import java.util.Locale ; 22 import java.util.ResourceBundle ; 23 24 public final class ComponentOrientation implements java.io.Serializable { 25 26 private static final int UNK_BIT = 1; 27 private static final int HORIZ_BIT = 2; 28 private static final int LTR_BIT = 4; 29 30 private int orientation; 31 32 public static final ComponentOrientation LEFT_TO_RIGHT = 33 new ComponentOrientation(HORIZ_BIT | LTR_BIT); 34 35 public static final ComponentOrientation RIGHT_TO_LEFT = 36 new ComponentOrientation(HORIZ_BIT); 37 38 public static final ComponentOrientation UNKNOWN = 39 new ComponentOrientation(HORIZ_BIT | LTR_BIT | UNK_BIT); 40 41 public boolean isHorizontal() { 42 return (orientation & HORIZ_BIT) != 0; 43 } 44 45 public boolean isLeftToRight() { 46 return (orientation & LTR_BIT) != 0; 47 } 48 49 public static ComponentOrientation getOrientation(Locale locale) { 50 String lang = locale.getLanguage(); 51 if ("iw".equals(lang) 52 || "ar".equals(lang) 53 || "fa".equals(lang) 54 || "ur".equals(lang)) { 55 return RIGHT_TO_LEFT; 56 } else { 57 return LEFT_TO_RIGHT; 58 } 59 } 60 61 public static ComponentOrientation getOrientation(ResourceBundle bdl) { 62 ComponentOrientation result = null; 63 64 try { 65 result = (ComponentOrientation) bdl.getObject("Orientation"); 66 } catch (Exception e) { 67 } 68 69 if (result == null) { 70 result = getOrientation(bdl.getLocale()); 71 } 72 if (result == null) { 73 result = getOrientation(Locale.getDefault()); 74 } 75 return result; 76 } 77 78 private ComponentOrientation(int value) { 79 orientation = value; 80 } 81 } | Popular Tags |