01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: /**
18: * @author Michael Danilov, Dmitry A. Durnev
19: * @version $Revision$
20: */package java.awt;
21:
22: import java.io.Serializable;
23: import java.util.*;
24:
25: public final class ComponentOrientation implements Serializable {
26: private static final long serialVersionUID = -4113291392143563828L;
27:
28: public static final ComponentOrientation LEFT_TO_RIGHT = new ComponentOrientation(
29: true, true);
30:
31: public static final ComponentOrientation RIGHT_TO_LEFT = new ComponentOrientation(
32: true, false);
33:
34: public static final ComponentOrientation UNKNOWN = new ComponentOrientation(
35: true, true);
36:
37: private static final Set<String> rlLangs = new HashSet<String>(); //RIGHT_TO_LEFT languages
38:
39: private final boolean horizontal;
40:
41: private final boolean left2right;
42:
43: static {
44: rlLangs.add("ar"); //$NON-NLS-1$
45: rlLangs.add("fa"); //$NON-NLS-1$
46: rlLangs.add("iw"); //$NON-NLS-1$
47: rlLangs.add("ur"); //$NON-NLS-1$
48: }
49:
50: /**
51: * @deprecated
52: */
53: @Deprecated
54: public static ComponentOrientation getOrientation(ResourceBundle bdl) {
55: Object obj = null;
56: try {
57: obj = bdl.getObject("Orientation"); //$NON-NLS-1$
58: } catch (MissingResourceException mre) {
59: obj = null;
60: }
61: if (obj instanceof ComponentOrientation) {
62: return (ComponentOrientation) obj;
63: }
64: Locale locale = bdl.getLocale();
65: if (locale == null) {
66: locale = Locale.getDefault();
67: }
68: return getOrientation(locale);
69: }
70:
71: public static ComponentOrientation getOrientation(Locale locale) {
72: String lang = locale.getLanguage();
73: return rlLangs.contains(lang) ? RIGHT_TO_LEFT : LEFT_TO_RIGHT;
74: }
75:
76: private ComponentOrientation(boolean hor, boolean l2r) {
77: horizontal = hor;
78: left2right = l2r;
79: }
80:
81: public boolean isHorizontal() {
82: return horizontal;
83: }
84:
85: public boolean isLeftToRight() {
86: return left2right;
87: }
88:
89: }
|