src/share/classes/java/awt/ComponentOrientation.java

Print this page


   1 /*
   2  * Copyright (c) 1998, 2006, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 109 
 110     /**
 111      * Items run right to left and lines flow top to bottom
 112      * Examples: Arabic, Hebrew.
 113      */
 114     public static final ComponentOrientation RIGHT_TO_LEFT =
 115                     new ComponentOrientation(HORIZ_BIT);
 116 
 117     /**
 118      * Indicates that a component's orientation has not been set.
 119      * To preserve the behavior of existing applications,
 120      * isLeftToRight will return true for this value.
 121      */
 122     public static final ComponentOrientation UNKNOWN =
 123                     new ComponentOrientation(HORIZ_BIT|LTR_BIT|UNK_BIT);
 124 
 125     /**
 126      * Are lines horizontal?
 127      * This will return true for horizontal, left-to-right writing
 128      * systems such as Roman.


 129      */
 130     public boolean isHorizontal() {
 131         return (orientation & HORIZ_BIT) != 0;
 132     }
 133 
 134     /**
 135      * HorizontalLines: Do items run left-to-right?<br>
 136      * Vertical Lines:  Do lines run left-to-right?<br>
 137      * This will return true for horizontal, left-to-right writing
 138      * systems such as Roman.


 139      */
 140     public boolean isLeftToRight() {
 141         return (orientation & LTR_BIT) != 0;
 142     }
 143 
 144     /**
 145      * Returns the orientation that is appropriate for the given locale.

 146      * @param locale the specified locale

 147      */
 148     public static ComponentOrientation getOrientation(Locale locale) {
 149         // A more flexible implementation would consult a ResourceBundle
 150         // to find the appropriate orientation.  Until pluggable locales
 151         // are introduced however, the flexiblity isn't really needed.
 152         // So we choose efficiency instead.
 153         String lang = locale.getLanguage();
 154         if( "iw".equals(lang) || "ar".equals(lang)
 155             || "fa".equals(lang) || "ur".equals(lang) )
 156         {
 157             return RIGHT_TO_LEFT;
 158         } else {
 159             return LEFT_TO_RIGHT;
 160         }
 161     }
 162 
 163     /**
 164      * Returns the orientation appropriate for the given ResourceBundle's
 165      * localization.  Three approaches are tried, in the following order:
 166      * <ol>
 167      * <li>Retrieve a ComponentOrientation object from the ResourceBundle
 168      *      using the string "Orientation" as the key.
 169      * <li>Use the ResourceBundle.getLocale to determine the bundle's
 170      *      locale, then return the orientation for that locale.
 171      * <li>Return the default locale's orientation.
 172      * </ol>
 173      *


 174      * @deprecated As of J2SE 1.4, use {@link #getOrientation(java.util.Locale)}.
 175      */
 176     @Deprecated
 177     public static ComponentOrientation getOrientation(ResourceBundle bdl)
 178     {
 179         ComponentOrientation result = null;
 180 
 181         try {
 182             result = (ComponentOrientation)bdl.getObject("Orientation");
 183         }
 184         catch (Exception e) {
 185         }
 186 
 187         if (result == null) {
 188             result = getOrientation(bdl.getLocale());
 189         }
 190         if (result == null) {
 191             result = getOrientation(Locale.getDefault());
 192         }
 193         return result;
   1 /*
   2  * Copyright (c) 1998, 2014, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 109 
 110     /**
 111      * Items run right to left and lines flow top to bottom
 112      * Examples: Arabic, Hebrew.
 113      */
 114     public static final ComponentOrientation RIGHT_TO_LEFT =
 115                     new ComponentOrientation(HORIZ_BIT);
 116 
 117     /**
 118      * Indicates that a component's orientation has not been set.
 119      * To preserve the behavior of existing applications,
 120      * isLeftToRight will return true for this value.
 121      */
 122     public static final ComponentOrientation UNKNOWN =
 123                     new ComponentOrientation(HORIZ_BIT|LTR_BIT|UNK_BIT);
 124 
 125     /**
 126      * Are lines horizontal?
 127      * This will return true for horizontal, left-to-right writing
 128      * systems such as Roman.
 129      *
 130      * @return {@code true} if this orientation has horizontal lines
 131      */
 132     public boolean isHorizontal() {
 133         return (orientation & HORIZ_BIT) != 0;
 134     }
 135 
 136     /**
 137      * HorizontalLines: Do items run left-to-right?<br>
 138      * Vertical Lines:  Do lines run left-to-right?<br>
 139      * This will return true for horizontal, left-to-right writing
 140      * systems such as Roman.
 141      *
 142      * @return {@code true} if this orientation is left-to-right
 143      */
 144     public boolean isLeftToRight() {
 145         return (orientation & LTR_BIT) != 0;
 146     }
 147 
 148     /**
 149      * Returns the orientation that is appropriate for the given locale.
 150      *
 151      * @param locale the specified locale
 152      * @return the orientation for the locale
 153      */
 154     public static ComponentOrientation getOrientation(Locale locale) {
 155         // A more flexible implementation would consult a ResourceBundle
 156         // to find the appropriate orientation.  Until pluggable locales
 157         // are introduced however, the flexiblity isn't really needed.
 158         // So we choose efficiency instead.
 159         String lang = locale.getLanguage();
 160         if( "iw".equals(lang) || "ar".equals(lang)
 161             || "fa".equals(lang) || "ur".equals(lang) )
 162         {
 163             return RIGHT_TO_LEFT;
 164         } else {
 165             return LEFT_TO_RIGHT;
 166         }
 167     }
 168 
 169     /**
 170      * Returns the orientation appropriate for the given ResourceBundle's
 171      * localization.  Three approaches are tried, in the following order:
 172      * <ol>
 173      * <li>Retrieve a ComponentOrientation object from the ResourceBundle
 174      *      using the string "Orientation" as the key.
 175      * <li>Use the ResourceBundle.getLocale to determine the bundle's
 176      *      locale, then return the orientation for that locale.
 177      * <li>Return the default locale's orientation.
 178      * </ol>
 179      *
 180      * @param  bdl the bundle to use
 181      * @return the orientation
 182      * @deprecated As of J2SE 1.4, use {@link #getOrientation(java.util.Locale)}.
 183      */
 184     @Deprecated
 185     public static ComponentOrientation getOrientation(ResourceBundle bdl)
 186     {
 187         ComponentOrientation result = null;
 188 
 189         try {
 190             result = (ComponentOrientation)bdl.getObject("Orientation");
 191         }
 192         catch (Exception e) {
 193         }
 194 
 195         if (result == null) {
 196             result = getOrientation(bdl.getLocale());
 197         }
 198         if (result == null) {
 199             result = getOrientation(Locale.getDefault());
 200         }
 201         return result;