use of org.apache.pivot.wtk.Insets in project pivot by apache.
the class LabelTest method startup.
@Override
public void startup(Display display, Map<String, String> properties) throws Exception {
frame = new Frame();
frame.setTitle("Label Test");
String line1 = "There's a lady who's sure all that glitters is gold, and " + "she's buying a stairway to heaven. When she gets there she knows, " + "if the stores are closed, with a word she can get what she came " + "for. Woe oh oh oh oh oh and she's buying a stairway to heaven. " + "There's a sign on the wall, but she wants to be sure, and you know " + "sometimes words have two meanings. In a tree by the brook there's " + "a songbird who sings, sometimes all of our thoughts are misgiven. " + "Woe oh oh oh oh oh and she's buying a stairway to heaven.";
String line2 = "And as we wind on down the road, our shadows taller than " + "our souls, there walks a lady we all know who shines white light " + "and wants to show how everything still turns to gold; and if you " + "listen very hard the tune will come to you at last when all are " + "one and one is all:\nto be a rock and not to roll.";
BoxPane boxPane = new BoxPane(Orientation.VERTICAL);
Label label1 = new Label(line1);
label1.getStyles().put(Style.wrapText, true);
label1.getStyles().put(Style.horizontalAlignment, HorizontalAlignment.LEFT);
boxPane.add(label1);
// strikethrough
Label label2 = new Label(line2);
label2.getStyles().put(Style.wrapText, true);
label2.getStyles().put(Style.horizontalAlignment, HorizontalAlignment.LEFT);
label2.getStyles().put(Style.textDecoration, TextDecoration.STRIKETHROUGH);
boxPane.add(label2);
// disabled
Label label3 = new Label(line2);
label3.getStyles().put(Style.wrapText, true);
label3.getStyles().put(Style.horizontalAlignment, HorizontalAlignment.LEFT);
label3.setEnabled(false);
boxPane.add(label3);
boxPane.getStyles().put(Style.fill, true);
boxPane.getStyles().put(Style.padding, new Insets(10));
frame.setContent(boxPane);
frame.setPreferredSize(340, 400);
frame.open(display);
}
use of org.apache.pivot.wtk.Insets in project pivot by apache.
the class DimensionsTest method test.
@Test
public void test() {
Dimensions zero = Dimensions.ZERO;
Dimensions zeroA = new Dimensions(0, 0);
Dimensions zeroB = new Dimensions(0);
Dimensions one = new Dimensions(1, 1);
Dimensions oneA = zero.expand(1);
Dimensions zeroC = oneA.expand(-1, -1);
Dimensions seven = new Dimensions(7);
Dimensions sevenA = new Dimensions(7, 7);
Dimensions sevenB = zero.expand(7);
Dimensions sevenC = zeroA.expand(7, 7);
Dimensions a = Dimensions.decode("2 x 3");
Dimensions a1 = new Dimensions(2, 3);
Dimensions b = Dimensions.decode("{width:4, height:5}");
Dimensions b1 = new Dimensions(4, 5);
Dimensions c = Dimensions.decode("1 , 2");
Dimensions c1 = new Dimensions(1, 2);
Dimensions d = Dimensions.decode("[ 17, 23]");
Dimensions d1 = new Dimensions(17, 23);
Dimensions e = Dimensions.decode("23 ; 45");
Dimensions e1 = new Dimensions(23, 45);
Insets i1 = new Insets(1, 2, 1, 2);
Dimensions f = e1.expand(i1);
Dimensions f1 = new Dimensions(27, 47);
assertEquals(zero, zeroA);
assertEquals(one, oneA);
assertEquals(zeroA, zeroB);
assertEquals(zero, zeroC);
assertEquals(seven, sevenA);
assertEquals(seven, sevenB);
assertEquals(sevenB, sevenC);
assertEquals(a, a1);
assertEquals(b, b1);
assertEquals(c, c1);
assertEquals(d, d1);
assertEquals(e, e1);
assertEquals(f, f1);
}
use of org.apache.pivot.wtk.Insets in project pivot by apache.
the class ButtonDataRenderer method render.
@Override
public void render(Object data, Button button, boolean highlighted) {
Image icon = null;
String text = null;
if (data instanceof BaseContent) {
BaseContent baseContent = (BaseContent) data;
icon = baseContent.getIcon();
} else if (data instanceof Image) {
icon = (Image) data;
}
text = toString(data);
// Update the image view
if (icon == null) {
imageView.setVisible(false);
} else {
imageView.setVisible(true);
imageView.setImage(icon);
imageView.getStyles().put(Style.opacity, button.isEnabled() ? Float.valueOf(1.0f) : Float.valueOf(0.5f));
if (getFillIcon()) {
int buttonWidth = button.getWidth();
int buttonHeight = button.getHeight();
Insets padding = (Insets) button.getStyles().get(Style.padding);
if (buttonWidth > 0) {
imageView.setPreferredWidth(Math.max(buttonWidth - (padding.left + padding.right + 2), 0));
}
if (buttonHeight > 0) {
imageView.setPreferredWidth(Math.max(buttonHeight - (padding.top + padding.bottom + 2), 0));
}
}
}
// Update the label
label.setText(text != null ? text : "");
if (text == null || (text.length() == 0 && getFillIcon())) {
label.setVisible(false);
} else {
label.setVisible(true);
Font font = button.getStyles().getFont(Style.font);
label.getStyles().put(Style.font, font);
Color color;
if (button.isEnabled()) {
color = button.getStyles().getColor(Style.color);
} else {
color = button.getStyles().getColor(Style.disabledColor);
}
label.getStyles().put(Style.color, color);
}
}
use of org.apache.pivot.wtk.Insets in project pivot by apache.
the class ListViewItemEditor method beginEdit.
@Override
public void beginEdit(ListView listViewArgument, int itemIndexArgument) {
this.listView = listViewArgument;
this.itemIndex = itemIndexArgument;
// Get the data being edited
List<?> listData = listViewArgument.getListData();
ListItem listItem = (ListItem) listData.get(itemIndexArgument);
String text = listItem.getText();
textInput.setText(text != null ? text : "");
textInput.selectAll();
// Get the item bounds
Bounds itemBounds = listViewArgument.getItemBounds(itemIndexArgument);
int itemIndent = listViewArgument.getItemIndent();
itemBounds = new Bounds(itemBounds.x + itemIndent, itemBounds.y, itemBounds.width - itemIndent, itemBounds.height);
// Render the item data
ListViewItemRenderer itemRenderer = (ListViewItemRenderer) listViewArgument.getItemRenderer();
itemRenderer.render(listItem, itemIndexArgument, listViewArgument, false, Button.State.UNSELECTED, false, false);
itemRenderer.setSize(itemBounds.width, itemBounds.height);
// Calculate the text bounds
Bounds textBounds = itemRenderer.getTextBounds();
// Calculate the bounds of what is being edited
Insets padding = (Insets) textInput.getStyles().get(Style.padding);
Bounds editBounds = new Bounds(itemBounds.x + textBounds.x - (padding.left + 1), itemBounds.y, itemBounds.width - textBounds.x + (padding.left + 1), itemBounds.height);
// Scroll to make the item as visible as possible
listViewArgument.scrollAreaToVisible(editBounds.x, editBounds.y, textBounds.width + padding.left + 1, editBounds.height);
// Constrain the bounds by what is visible through viewport ancestors
editBounds = listViewArgument.getVisibleArea(editBounds);
Point location = listViewArgument.mapPointToAncestor(listViewArgument.getDisplay(), editBounds.x, editBounds.y);
textInput.setPreferredWidth(editBounds.width);
setLocation(location.x, location.y + (editBounds.height - getPreferredHeight(-1)) / 2);
// Open the editor
open(listViewArgument.getWindow());
}
use of org.apache.pivot.wtk.Insets in project pivot by apache.
the class MenuItemDataRenderer method render.
@Override
public void render(Object data, Button button, boolean highlighted) {
Image icon = null;
String text = null;
Keyboard.KeyStroke keyboardShortcut = null;
if (data instanceof BaseContent) {
BaseContent buttonData = (BaseContent) data;
icon = buttonData.getIcon();
if (buttonData instanceof MenuItemData) {
MenuItemData menuItemData = (MenuItemData) buttonData;
keyboardShortcut = menuItemData.getKeyboardShortcut();
}
} else if (data instanceof Image) {
icon = (Image) data;
}
text = toString(data);
// attempt to retrieve icon from button data
if (button.isSelected()) {
icon = (Image) button.getStyles().get(Style.checkmarkImage);
}
// Update the image view
Menu.Item menuItem = (Menu.Item) button;
Menu menu = (Menu) menuItem.getParent();
int margin = menu.getStyles().getInt(Style.margin);
Insets padding = (Insets) getStyles().get(Style.padding);
imageView.setImage(icon);
imageView.setPreferredWidth(margin - padding.left * 2);
imageView.getStyles().put(Style.opacity, button.isEnabled() ? new Float(1.0f) : new Float(0.5f));
// Update the labels
textLabel.setText(text != null ? text : "");
Font font = menu.getStyles().getFont(Style.font);
textLabel.getStyles().put(Style.font, font);
keyboardShortcutLabel.getStyles().put(Style.font, font.deriveFont(Font.ITALIC));
Color color;
if (button.isEnabled()) {
if (highlighted) {
color = menu.getStyles().getColor(Style.activeColor);
} else {
color = menu.getStyles().getColor(Style.color);
}
} else {
color = menu.getStyles().getColor(Style.disabledColor);
}
textLabel.getStyles().put(Style.color, color);
keyboardShortcutLabel.getStyles().put(Style.color, color);
boolean showKeyboardShortcuts = false;
if (menu.getStyles().containsKey(Style.showKeyboardShortcuts)) {
showKeyboardShortcuts = menu.getStyles().getBoolean(Style.showKeyboardShortcuts);
}
if (showKeyboardShortcuts) {
keyboardShortcutLabel.setVisible(true);
keyboardShortcutLabel.setText(keyboardShortcut != null ? keyboardShortcut.toString() : "");
} else {
keyboardShortcutLabel.setVisible(false);
}
}
Aggregations