KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > swingwt > awt > ComponentOrientation


1 /*
2    SwingWT
3    Copyright(c)2003-2004, R. Rawson-Tetley
4  
5    For more information on distributing and using this program, please
6    see the accompanying "COPYING" file.
7  
8    Contact me by electronic mail: bobintetley@users.sourceforge.net
9  
10    $Log: ComponentOrientation.java,v $
11    Revision 1.3 2004/04/23 00:52:31 dannaab
12    Handle borders in a Swing-like way. Implement EmptyBorder & TitledBorder
13
14    Revision 1.2 2004/04/20 16:35:47 bobintetley
15    Code cleanup
16
17  
18  */

19 package swingwt.awt;
20
21 import java.util.Locale JavaDoc;
22 import java.util.ResourceBundle JavaDoc;
23
24 public final class ComponentOrientation implements java.io.Serializable JavaDoc {
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 JavaDoc locale) {
50         String JavaDoc 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 JavaDoc bdl) {
62         ComponentOrientation result = null;
63
64         try {
65             result = (ComponentOrientation) bdl.getObject("Orientation");
66         } catch (Exception JavaDoc 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