/* * Copyright (c) 1998, 2006, Oracle and/or its affiliates. All rights reserved. * ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. * * * * * * * * * * * * * * * * * * * * */ /* * (C) Copyright IBM Corp. 1998 - All Rights Reserved * * The original version of this source code and documentation is copyrighted * and owned by IBM, Inc. These materials are provided under terms of a * License Agreement between IBM and Sun. This technology is protected by * multiple US and International patents. This notice and attribution to IBM * may not be removed. * */ package java.awt; import java.util.Locale; import java.util.ResourceBundle; /** * 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 *
* The orientations are: *
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.
*/
public final class ComponentOrientation implements java.io.Serializable
{
/*
* serialVersionUID
*/
private static final long serialVersionUID = -4113291392143563828L;
// Internal constants used in the implementation
private static final int UNK_BIT = 1;
private static final int HORIZ_BIT = 2;
private static final int LTR_BIT = 4;
/**
* Items run left to right and lines flow top to bottom
* Examples: English, French.
*/
public static final ComponentOrientation LEFT_TO_RIGHT =
new ComponentOrientation(HORIZ_BIT|LTR_BIT);
/**
* Items run right to left and lines flow top to bottom
* Examples: Arabic, Hebrew.
*/
public static final ComponentOrientation RIGHT_TO_LEFT =
new ComponentOrientation(HORIZ_BIT);
/**
* Indicates that a component's orientation has not been set.
* To preserve the behavior of existing applications,
* isLeftToRight will return true for this value.
*/
public static final ComponentOrientation UNKNOWN =
new ComponentOrientation(HORIZ_BIT|LTR_BIT|UNK_BIT);
/**
* Are lines horizontal?
* This will return true for horizontal, left-to-right writing
* systems such as Roman.
*/
public boolean isHorizontal() {
return (orientation & HORIZ_BIT) != 0;
}
/**
* HorizontalLines: Do items run left-to-right?