LayoutControlPanelpublic class LayoutControlPanel extends JPanel implements SwingConstants
Fields Summary |
---|
private boolean | absolutePositions | private DirectionPanel | textPosition | private DirectionPanel | labelAlignment | private ButtonDemo | demo |
Constructors Summary |
---|
LayoutControlPanel(ButtonDemo demo)
// private ComponentOrientChanger componentOrientChanger = null;
this.demo = demo;
// this.componentOrientationChanger = componentOrientationChanger;
setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
setAlignmentX(LEFT_ALIGNMENT);
setAlignmentY(TOP_ALIGNMENT);
JLabel l;
// If SwingSet has a ComponentOrientationChanger, then include control
// for choosing between absolute and relative positioning. This will
// only happen when we're running on JDK 1.2 or above.
//
// if(componentOrientationChanger != null ) {
// l = new JLabel("Positioning:");
// add(l);
//
// ButtonGroup group = new ButtonGroup();
// PositioningListener positioningListener = new PositioningListener();
// JRadioButton absolutePos = new JRadioButton("Absolute");
// absolutePos.setMnemonic('a');
// absolutePos.setToolTipText("Text/Content positioning is independant of line direction");
// group.add(absolutePos);
// absolutePos.addItemListener(positioningListener);
// add(absolutePos);
//
// JRadioButton relativePos = new JRadioButton("Relative");
// relativePos.setMnemonic('r');
// relativePos.setToolTipText("Text/Content positioning depends on line direction.");
// group.add(relativePos);
// relativePos.addItemListener(positioningListener);
// add(relativePos);
//
// add(Box.createRigidArea(demo.VGAP20));
//
// absolutePositions = false;
// relativePos.setSelected(true);
//
// componentOrientationChanger.addActionListener( new OrientationChangeListener() );
//} else {
absolutePositions = true;
//}
textPosition = new DirectionPanel(true, "E", new TextPositionListener());
labelAlignment = new DirectionPanel(true, "C", new LabelAlignmentListener());
// Make sure the controls' text position and label alignment match
// the initial value of the associated direction panel.
for(int i = 0; i < demo.getCurrentControls().size(); i++) {
Component c = (Component) demo.getCurrentControls().elementAt(i);
setPosition(c, RIGHT, CENTER);
setAlignment(c,CENTER,CENTER);
}
l = new JLabel("Text Position:");
add(l);
add(textPosition);
add(Box.createRigidArea(demo.VGAP20));
l = new JLabel("Content Alignment:");
add(l);
add(labelAlignment);
add(Box.createGlue());
|
Methods Summary |
---|
void | setAlignment(java.awt.Component c, int hPos, int vPos)
boolean ltr = true;
ltr = c.getComponentOrientation().isLeftToRight();
if( absolutePositions ) {
if( hPos == LEADING ) {
hPos = ltr ? LEFT : RIGHT;
} else if( hPos == TRAILING ) {
hPos = ltr ? RIGHT : LEFT;
}
} else {
if( hPos == LEFT ) {
hPos = ltr ? LEADING : TRAILING;
} else if( hPos == RIGHT ) {
hPos = ltr ? TRAILING : LEADING;
}
}
if(c instanceof AbstractButton) {
AbstractButton x = (AbstractButton) c;
x.setHorizontalAlignment(hPos);
x.setVerticalAlignment(vPos);
} else if(c instanceof JLabel) {
JLabel x = (JLabel) c;
x.setHorizontalAlignment(hPos);
x.setVerticalAlignment(vPos);
}
| void | setPosition(java.awt.Component c, int hPos, int vPos)
boolean ltr = true;
ltr = c.getComponentOrientation().isLeftToRight();
if( absolutePositions ) {
if( hPos == LEADING ) {
hPos = ltr ? LEFT : RIGHT;
} else if( hPos == TRAILING ) {
hPos = ltr ? RIGHT : LEFT;
}
} else {
if( hPos == LEFT ) {
hPos = ltr ? LEADING : TRAILING;
} else if( hPos == RIGHT ) {
hPos = ltr ? TRAILING : LEADING;
}
}
if(c instanceof AbstractButton) {
AbstractButton x = (AbstractButton) c;
x.setHorizontalTextPosition(hPos);
x.setVerticalTextPosition(vPos);
} else if(c instanceof JLabel) {
JLabel x = (JLabel) c;
x.setHorizontalTextPosition(hPos);
x.setVerticalTextPosition(vPos);
}
|
|