use of org.apache.pivot.wtk.Insets in project pivot by apache.
the class TreeViewNodeEditor method beginEdit.
@Override
public void beginEdit(TreeView treeViewArgument, Path pathArgument) {
this.treeView = treeViewArgument;
this.path = pathArgument;
// Get the data being edited
List<?> treeData = treeViewArgument.getTreeData();
TreeNode treeNode = (TreeNode) Sequence.Tree.get(treeData, pathArgument);
String text = treeNode.getText();
textInput.setText(text != null ? text : "");
textInput.selectAll();
// Get the node bounds
Bounds nodeBounds = treeViewArgument.getNodeBounds(pathArgument);
int nodeIndent = treeViewArgument.getNodeIndent(pathArgument.getLength());
nodeBounds = new Bounds(nodeBounds.x + nodeIndent, nodeBounds.y, nodeBounds.width - nodeIndent, nodeBounds.height);
// Render the node data
TreeViewNodeRenderer nodeRenderer = (TreeViewNodeRenderer) treeViewArgument.getNodeRenderer();
nodeRenderer.render(treeNode, pathArgument, treeViewArgument.getRowIndex(pathArgument), treeViewArgument, false, false, TreeView.NodeCheckState.UNCHECKED, false, false);
nodeRenderer.setSize(nodeBounds.width, nodeBounds.height);
// Get the text bounds
Bounds textBounds = nodeRenderer.getTextBounds();
// Calculate the bounds of what is being edited
Insets padding = (Insets) textInput.getStyles().get(Style.padding);
Bounds editBounds = new Bounds(nodeBounds.x + textBounds.x - (padding.left + 1), nodeBounds.y, nodeBounds.width - textBounds.x + (padding.left + 1), nodeBounds.height);
// Scroll to make the node as visible as possible
treeViewArgument.scrollAreaToVisible(editBounds.x, editBounds.y, textBounds.width + padding.left + 1, editBounds.height);
// Constrain the bounds by what is visible through viewport ancestors
editBounds = treeViewArgument.getVisibleArea(editBounds);
Point location = treeViewArgument.mapPointToAncestor(treeViewArgument.getDisplay(), editBounds.x, editBounds.y);
textInput.setPreferredWidth(editBounds.width);
setLocation(location.x, location.y + (editBounds.height - getPreferredHeight(-1)) / 2);
// Open the editor
open(treeViewArgument.getWindow());
}
use of org.apache.pivot.wtk.Insets in project pivot by apache.
the class NumberRulerSkin method install.
@Override
public void install(Component component) {
super.install(component);
Theme theme = Theme.getTheme();
setFont(theme.getFont());
setColor(0);
setBackgroundColor(19);
markerSpacing = 5;
markerInsets = new Insets(0);
rowPadding = new Insets(0);
// Note: these aren't settable
majorDivision = 10;
minorDivision = 5;
// But these are
showMajorNumbers = true;
showMinorNumbers = false;
NumberRuler ruler = (NumberRuler) component;
ruler.getRulerListeners().add(this);
}
use of org.apache.pivot.wtk.Insets in project pivot by apache.
the class InsetsTest method test.
@Test
public void test() {
Insets i0 = Insets.NONE;
Insets i0a = new Insets(0);
Insets i1 = new Insets(1);
Insets i1a = new Insets(1, 1, 1, 1);
Insets i2 = new Insets(2);
Insets i2a = new Insets(2.0f);
Insets i2b = Insets.decode("[ 2, 2, 2, 2 ]");
Insets i3 = new Insets(1, 2, 3, 4);
Insets i3a = Insets.decode("{top:1, left:2, bottom:3, right:4}");
Insets i4 = new Insets(5, 6, 7, 8);
Insets i4a = Insets.decode("5, 6; 7, 8");
Dimensions dim5 = new Dimensions(5);
Insets i5 = new Insets(dim5);
Insets i5a = new Insets(2, 2, 3, 3);
Dimensions dim5a = i5.getSize();
Dimensions dim5b = i5a.getSize();
assertEquals(i0, i0a);
assertEquals(i1, i1a);
assertEquals(i2, i2a);
assertEquals(i2, i2b);
assertEquals(i3, i3a);
assertEquals(i3.toString(), "Insets [1, 2, 3, 4]");
assertEquals(i0.getWidth(), 0);
assertEquals(i0.getHeight(), 0);
assertEquals(i3.getWidth(), 6);
assertEquals(i3.getHeight(), 4);
assertEquals(i4, i4a);
assertEquals(i4a.getWidth(), 14);
assertEquals(i4a.getHeight(), 12);
assertEquals(i4a.toString(), "Insets [5, 6, 7, 8]");
assertEquals(i5, i5a);
assertEquals(dim5, dim5a);
assertEquals(dim5a, dim5b);
assertEquals(i5.toString(), "Insets [2, 2, 3, 3]");
}
use of org.apache.pivot.wtk.Insets in project pivot by apache.
the class ComponentInspectorSkin method addInsetsControl.
private static Component addInsetsControl(final Dictionary<String, Object> dictionary, final String key, Form.Section section) {
Insets insets = (Insets) dictionary.get(key);
BoxPane boxPane = new BoxPane(Orientation.VERTICAL);
section.add(boxPane);
Form.setLabel(boxPane, key);
FlowPane flowPane = new FlowPane();
flowPane.getStyles().put(Style.alignToBaseline, true);
flowPane.getStyles().put(Style.horizontalSpacing, 5);
boxPane.add(flowPane);
TextInput textInput = new TextInput();
textInput.setTextSize(4);
textInput.setMaximumLength(4);
textInput.setValidator(new IntValidator());
textInput.setText(String.valueOf(insets.top));
flowPane.add(textInput);
textInput.getComponentStateListeners().add(new ComponentStateListener() {
@Override
public void focusedChanged(Component component, Component obverseComponent) {
if (!component.isFocused()) {
TextInput textInputLocal = (TextInput) component;
Insets insetsLocal = (Insets) dictionary.get(key);
try {
int top = Integer.parseInt(textInputLocal.getText());
dictionary.put(key, new Insets(top, insetsLocal.left, insetsLocal.bottom, insetsLocal.right));
} catch (Exception exception) {
displayErrorMessage(exception, component.getWindow());
textInputLocal.setText(String.valueOf(insetsLocal.top));
}
}
}
});
Label label = new Label("top");
label.getStyles().put(Style.font, "{italic:true}");
flowPane.add(label);
flowPane = new FlowPane();
flowPane.getStyles().put(Style.alignToBaseline, true);
flowPane.getStyles().put(Style.horizontalSpacing, 5);
boxPane.add(flowPane);
textInput = new TextInput();
textInput.setTextSize(4);
textInput.setMaximumLength(4);
textInput.setValidator(new IntValidator());
textInput.setText(String.valueOf(insets.left));
flowPane.add(textInput);
textInput.getComponentStateListeners().add(new ComponentStateListener() {
@Override
public void focusedChanged(Component component, Component obverseComponent) {
if (!component.isFocused()) {
TextInput textInputLocal = (TextInput) component;
Insets insetsLocal = (Insets) dictionary.get(key);
try {
int left = Integer.parseInt(textInputLocal.getText());
dictionary.put(key, new Insets(insetsLocal.top, left, insetsLocal.bottom, insetsLocal.right));
} catch (Exception exception) {
displayErrorMessage(exception, component.getWindow());
textInputLocal.setText(String.valueOf(insetsLocal.left));
}
}
}
});
label = new Label("left");
label.getStyles().put(Style.font, "{italic:true}");
flowPane.add(label);
flowPane = new FlowPane();
flowPane.getStyles().put(Style.alignToBaseline, true);
flowPane.getStyles().put(Style.horizontalSpacing, 5);
boxPane.add(flowPane);
textInput = new TextInput();
textInput.setTextSize(4);
textInput.setMaximumLength(4);
textInput.setValidator(new IntValidator());
textInput.setText(String.valueOf(insets.bottom));
flowPane.add(textInput);
textInput.getComponentStateListeners().add(new ComponentStateListener() {
@Override
public void focusedChanged(Component component, Component obverseComponent) {
if (!component.isFocused()) {
TextInput textInputLocal = (TextInput) component;
Insets insetsLocal = (Insets) dictionary.get(key);
try {
int bottom = Integer.parseInt(textInputLocal.getText());
dictionary.put(key, new Insets(insetsLocal.top, insetsLocal.left, bottom, insetsLocal.right));
} catch (Exception exception) {
displayErrorMessage(exception, component.getWindow());
textInputLocal.setText(String.valueOf(insetsLocal.bottom));
}
}
}
});
label = new Label("bottom");
label.getStyles().put(Style.font, "{italic:true}");
flowPane.add(label);
flowPane = new FlowPane();
flowPane.getStyles().put(Style.alignToBaseline, true);
flowPane.getStyles().put(Style.horizontalSpacing, 5);
boxPane.add(flowPane);
textInput = new TextInput();
textInput.setTextSize(4);
textInput.setMaximumLength(4);
textInput.setValidator(new IntValidator());
textInput.setText(String.valueOf(insets.right));
flowPane.add(textInput);
textInput.getComponentStateListeners().add(new ComponentStateListener() {
@Override
public void focusedChanged(Component component, Component obverseComponent) {
if (!component.isFocused()) {
TextInput textInputLocal = (TextInput) component;
Insets insetsLocal = (Insets) dictionary.get(key);
try {
int right = Integer.parseInt(textInputLocal.getText());
dictionary.put(key, new Insets(insetsLocal.top, insetsLocal.left, insetsLocal.bottom, right));
} catch (Exception exception) {
displayErrorMessage(exception, component.getWindow());
textInputLocal.setText(String.valueOf(insetsLocal.right));
}
}
}
});
label = new Label("right");
label.getStyles().put(Style.font, "{italic:true}");
flowPane.add(label);
return boxPane;
}
Aggregations