JavaTM 2 Platform
Std. Ed. v1.3.1

java.awt
Class ComponentOrientation

java.lang.Object
  |
  +--java.awt.ComponentOrientation
All Implemented Interfaces:
Serializable

public final class ComponentOrientation
extends Object
implements Serializable

The ComponentOrientation class encapsulates the language-sensitive orientation that is to be used to order the elements of a component or of text. It is used to reflect the differences in this ordering between Western alphabets, Middle Eastern (such as Hebrew), and Far Eastern (such as Japanese).

Fundamentally, this governs items (such as characters) which are laid out in lines, with the lines then laid out in a block. This also applies to items in a widget: for example, in a check box where the box is positioned relative to the text.

There are four different orientations used in modern languages as in the following table.

 LT          RT          TL          TR   
 A B C       C B A       A D G       G D A
 D E F       F E D       B E H       H E B
 G H I       I H G       C F I       I F C
 

(In the header, the two-letter abbreviation represents the item direction in the first letter, and the line direction in the second. For example, LT means "items left-to-right, lines top-to-bottom", BL means "items bottom-to-top, lines bottom-to-top", and so on.)

The orientations are:

Components whose view and controller code depends on orientation should use the isLeftToRight() and isHorizontal() methods to determine their behavior. They should not include switch-like code that keys off of the constants, such as:
 if (orientation == LEFT_TO_RIGHT) {
   ...
 } else if (orientation == RIGHT_TO_LEFT) {
   ...
 } else {
   // Oops
 }
 
This is unsafe, since more constants may be added in the future and since it is not guaranteed that orientation objects will be unique.

See Also:
Serialized Form

Field Summary
static ComponentOrientation LEFT_TO_RIGHT
          Items run left to right and lines flow top to bottom Examples: English, French.
static ComponentOrientation RIGHT_TO_LEFT
          Items run right to left and lines flow top to bottom Examples: Arabic, Hebrew.
static ComponentOrientation UNKNOWN
          Indicates that a component's orientation has not been set.
 
Method Summary
static ComponentOrientation getOrientation(Locale locale)
          Return the orientation that is appropriate for the given locale
static ComponentOrientation getOrientation(ResourceBundle bdl)
          Return the orientation appropriate for the given ResourceBundle's localization.
 boolean isHorizontal()
          Are lines horizontal? This will return true for horizontal, left-to-right writing systems such as Roman.
 boolean isLeftToRight()
          HorizontalLines: Do items run left-to-right?
Vertical Lines: Do lines run left-to-right?
This will return true for horizontal, left-to-right writing systems such as Roman.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LEFT_TO_RIGHT

public static final ComponentOrientation LEFT_TO_RIGHT
Items run left to right and lines flow top to bottom Examples: English, French.

RIGHT_TO_LEFT

public static final ComponentOrientation RIGHT_TO_LEFT
Items run right to left and lines flow top to bottom Examples: Arabic, Hebrew.

UNKNOWN

public static final ComponentOrientation UNKNOWN
Indicates that a component's orientation has not been set. To preserve the behavior of existing applications, isLeftToRight will return true for this value.
Method Detail

isHorizontal

public boolean isHorizontal()
Are lines horizontal? This will return true for horizontal, left-to-right writing systems such as Roman.

isLeftToRight

public boolean isLeftToRight()
HorizontalLines: Do items run left-to-right?
Vertical Lines: Do lines run left-to-right?
This will return true for horizontal, left-to-right writing systems such as Roman.

getOrientation

public static ComponentOrientation getOrientation(Locale locale)
Return the orientation that is appropriate for the given locale
Parameters:
locale - used as a key to look up the orientation in an internal resource bundle.

getOrientation

public static ComponentOrientation getOrientation(ResourceBundle bdl)
Return the orientation appropriate for the given ResourceBundle's localization. Three approaches are tried, inn the following order:
  1. Retrieve a ComponentOrientation object from the ResourceBundle using the string "Orientation" as the key.
  2. Use the ResourceBundle.getLocale to determine the bundle's locale, then return the orientation for that locale.
  3. Return the default locale's orientation.

JavaTM 2 Platform
Std. Ed. v1.3.1

Submit a bug or feature
For further API reference and developer documentation, see Java 2 SDK SE Developer Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.

Java, Java 2D, and JDBC are trademarks or registered trademarks of Sun Microsystems, Inc. in the US and other countries.
Copyright 1993-2001 Sun Microsystems, Inc. 901 San Antonio Road
Palo Alto, California, 94303, U.S.A. All Rights Reserved.