- Timestamp:
- Apr 27, 2004, 8:39:34 PM (22 years ago)
- Location:
- branches/GNU/src/gcc
- Files:
-
- 2 edited
-
. (modified) (1 prop)
-
libjava/java/awt/ComponentOrientation.java (modified) (2 diffs, 1 prop)
Legend:
- Unmodified
- Added
- Removed
-
branches/GNU/src/gcc
- Property svn:ignore
-
old new 26 26 configure.vr 27 27 configure.vrs 28 28 29 Makefile 29 dir.info30 30 lost+found 31 31 update.out
-
- Property svn:ignore
-
branches/GNU/src/gcc/libjava/java/awt/ComponentOrientation.java
-
Property cvs2svn:cvs-rev
changed from
1.1to1.1.1.2
r1390 r1391 1 /* Copyright (C) 2000, 2001, 2002 Free Software Foundation 1 /* ComponentOrientation.java -- describes a component's orientation 2 Copyright (C) 2000, 2001, 2002 Free Software Foundation 2 3 3 4 This file is part of GNU Classpath. … … 35 36 exception statement from your version. */ 36 37 38 39 40 41 42 43 44 45 37 46 /** 38 * @author Bryce McKinlay <[email protected]> 47 * This class is used to differentiate different orientations for text layout. 48 * It controls whether text flows left-to-right or right-to-left, and whether 49 * lines are horizontal or vertical, as in this table:<br> 50 * <pre> 51 * LT RT TL TR 52 * A B C C B A A D G G D A 53 * D E F F E D B E H H E B 54 * G H I I H G C F I I F C 55 * </pre> 56 * <b>LT</b> languages are most common (left-to-right lines, top-to-bottom). 57 * This includes Western European languages, and optionally includes Japanese, 58 * Chinese, and Korean. <b>RT</b> languages (right-to-left lines, 59 * top-to-bottom) are mainly middle eastern, such as Hebrew and Arabic. 60 * <b>TR</b> languages flow top-to-bottom in a line, right-to-left, and are 61 * the basis of Japanese, Chinese, and Korean. Finally, <b>TL</b> languages 62 * flow top-to-bottom in a line, left-to-right, as in Mongolian. 63 * 64 * <p>This is a pretty poor excuse for a type-safe enum, since it is not 65 * guaranteed that orientation objects are unique (thanks to serialization), 66 * yet there is no equals() method. You would be wise to compare the output 67 * of isHorizontal() and isLeftToRight() rather than comparing objects with 68 * ==, especially since more constants may be added in the future. 69 * 70 * @author Bryce McKinlay <[email protected]> 71 * @since 1.0 72 * @status updated to 1.4 39 73 */ 40 41 /* Status: Incomplete. Needs a Locale lookup table. */ 42 43 package java.awt; 44 45 import java.util.Locale; 46 import java.util.ResourceBundle; 47 48 public final class ComponentOrientation implements java.io.Serializable 74 public final class ComponentOrientation implements Serializable 49 75 { 50 // Here is a wild guess. 51 private static int HORIZONTAL_ID = 1 << 0, 52 LEFT_TO_RIGHT_ID = 1 << 1; 53 76 /** 77 * Compatible with JDK 1.0+. 78 */ 79 private static final long serialVersionUID = -4113291392143563828L; 80 81 /** Constant for unknown orientation. */ 82 private static final int UNKNOWN_ID = 1; 83 84 /** Constant for horizontal line orientation. */ 85 private static final int HORIZONTAL_ID = 2; 86 87 /** Constant for left-to-right orientation. */ 88 private static final int LEFT_TO_RIGHT_ID = 4; 89 90 /** 91 * Items run left to right, and lines flow top to bottom. Examples: English, 92 * French. 93 */ 54 94 public static final ComponentOrientation LEFT_TO_RIGHT 55 = new ComponentOrientation(HORIZONTAL_ID & LEFT_TO_RIGHT_ID); 95 = new ComponentOrientation(HORIZONTAL_ID | LEFT_TO_RIGHT_ID); 96 97 /** 98 * Items run right to left, and lines flow top to bottom. Examples: Arabic, 99 * Hebrew. 100 */ 56 101 public static final ComponentOrientation RIGHT_TO_LEFT 57 102 = new ComponentOrientation(HORIZONTAL_ID); 103 104 105 106 107 58 108 public static final ComponentOrientation UNKNOWN 59 = new ComponentOrientation(0); 60 61 // FIXME: This field is from the serialization spec, but what are the 62 // correct values? 63 int orientation; 64 65 ComponentOrientation(int orientation) 109 = new ComponentOrientation(UNKNOWN_ID | HORIZONTAL_ID | LEFT_TO_RIGHT_ID); 110 111 /** 112 * The orientation of this object; bitwise-or of unknown (1), horizontal (2), 113 * and left-to-right (4). 114 * 115 * @serial the orientation 116 */ 117 private final int orientation; 118 119 /** 120 * Construct a given orientation. 121 * 122 * @param orientation the orientation 123 */ 124 private ComponentOrientation(int orientation) 66 125 { 67 126 this.orientation = orientation; 68 127 } 69 128 129 130 131 132 133 134 135 70 136 public boolean isHorizontal() 71 137 { 72 return ((orientation & HORIZONTAL_ID) != 0); 73 } 74 138 return (orientation & HORIZONTAL_ID) != 0; 139 } 140 141 /** 142 * If isHorizontal() returns true, then this determines whether items in 143 * the line flow left-to-right. If isHorizontal() returns false, items in 144 * a line flow top-to-bottom, and this determines if lines flow 145 * left-to-right. 146 * 147 * @return true if this orientation flows left-to-right 148 */ 75 149 public boolean isLeftToRight() 76 150 { 77 return ((orientation & LEFT_TO_RIGHT_ID) != 0); 78 } 79 151 return (orientation & LEFT_TO_RIGHT_ID) != 0; 152 } 153 154 /** 155 * Gets an orientation appropriate for the locale. 156 * 157 * @param locale the locale 158 * @return the orientation for that locale 159 * @throws NullPointerException if locale is null 160 */ 80 161 public static ComponentOrientation getOrientation(Locale locale) 81 162 { 82 // FIXME: Use a table to look this up. 163 // Based on iterating over all languages defined in JDK 1.4, this behavior 164 // matches Sun's. However, it makes me wonder if any non-horizontal 165 // orientations even exist, as it sure contradicts their documentation. 166 String language = locale.getLanguage(); 167 if ("ar".equals(language) || "fa".equals(language) || "iw".equals(language) 168 || "ur".equals(language)) 169 return RIGHT_TO_LEFT; 83 170 return LEFT_TO_RIGHT; 84 171 } 85 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 86 187 public static ComponentOrientation getOrientation(ResourceBundle bdl) 87 188 { 88 189 ComponentOrientation r; 89 90 190 try 91 {92 Object obj =bdl.getObject("Orientation");93 r = (ComponentOrientation) obj;94 if (r != null)95 return r; 96 }97 catch (Exception x)98 {99 // Fall through100 }101 191 { 192 bdl.getObject("Orientation"); 193 194 195 } 196 197 198 199 200 201 } 102 202 try 103 { 104 Locale l = bdl.getLocale(); 105 r = getOrientation(l); 106 if (r != null) 107 return r; 108 } 109 catch (Exception x) 110 { 111 // Fall through 112 } 113 114 return (getOrientation (Locale.getDefault ())); 115 } 116 } 203 { 204 r = getOrientation(bdl.getLocale()); 205 if (r != null) 206 return r; 207 } 208 catch (Exception ignored) 209 { 210 } 211 return getOrientation(Locale.getDefault()); 212 } 213 } // class ComponentOrientation -
Property cvs2svn:cvs-rev
changed from
Note:
See TracChangeset
for help on using the changeset viewer.
