FileDocCategorySizeDatePackage
ComponentOrientationChanger.javaAPI DocExample5204Tue Jun 29 07:21:12 BST 1999None

ComponentOrientationChanger

public class ComponentOrientationChanger extends JMenu implements ItemListener

Fields Summary
JRadioButtonMenuItem
ltrRb
JRadioButtonMenuItem
rtlRb
Constructors Summary
public ComponentOrientationChanger()

        super("Component Orientation");

        getAccessibleContext().setAccessibleDescription(
           "Sub-menu containing options for changing the orientation of the Swing Components.");

        ButtonGroup orientationGroup = new ButtonGroup();

        ltrRb = (JRadioButtonMenuItem)add(new JRadioButtonMenuItem("Left To Right"));
        ltrRb.getAccessibleContext().setAccessibleDescription("Orient Components for left to right languages.");
        ltrRb.setSelected(true);
        ltrRb.addItemListener(this);
        orientationGroup.add(ltrRb);
        
        rtlRb = (JRadioButtonMenuItem)add(new JRadioButtonMenuItem("Right To Left"));
        rtlRb.getAccessibleContext().setAccessibleDescription("Orient Components for left to right languages.");
        rtlRb.addItemListener(this);
        orientationGroup.add(rtlRb);
    
Methods Summary
private voidapplyOrientation(java.awt.Component c, java.awt.ComponentOrientation o)

        c.setComponentOrientation(o);

        if( c instanceof JMenu ) {
            JMenu menu = (JMenu)c;
            int ncomponents = menu.getMenuComponentCount();
            for (int i = 0 ; i < ncomponents ; ++i) {
                applyOrientation( menu.getMenuComponent(i), o );
            }
        }
        else if( c instanceof Container ) {
            Container container = (Container)c;
            int ncomponents = container.getComponentCount();
            for (int i = 0 ; i < ncomponents ; ++i) {
                applyOrientation( container.getComponent(i), o );
            }
        }
    
static ComponentOrientationChangercreate()

        
        return new ComponentOrientationChanger();
        


    
private voiddumpOrientation(java.awt.Component c, int level)

        ComponentOrientation o = c.getComponentOrientation();
        for(int i=0; i<level; i++)
            System.out.print("\t");
        System.out.println(c + " isLTR=" + o.isLeftToRight() );

        if( c instanceof Container ) {
            Container container = (Container)c;
            int ncomponents = container.getComponentCount();
            for (int i = 0 ; i < ncomponents ; ++i) {
                dumpOrientation( container.getComponent(i), level+1);
            }
        }
    
public voiditemStateChanged(java.awt.event.ItemEvent e)

        
        JRadioButtonMenuItem rb = (JRadioButtonMenuItem) e.getSource();
        if (rb.isSelected()) {
            String selected = rb.getText();
            ComponentOrientation orientation;
            if (selected.equals("Left To Right")) {
                orientation = ComponentOrientation.LEFT_TO_RIGHT;
            } else  {
                orientation = ComponentOrientation.RIGHT_TO_LEFT;
            } 
            Container swingRoot = SwingSet.sharedInstance().getRootComponent();
            applyOrientation( swingRoot, orientation );
            fireActionPerformed(new ActionEvent(this,0,"OrientationChanged"));
            swingRoot.validate();
            swingRoot.repaint();
        }