use of org.apache.pivot.wtk.BoxPane in project pivot by apache.
the class Pivot964Pivot method startup.
@Override
public void startup(Display display, Map<String, String> properties) {
// force dimensions for host frame
display.getHostWindow().setSize(1028, 600);
window = new Window();
prepareSVG();
final ImageView image = new ImageView(new Drawing(diagram));
BoxPane bp = new BoxPane();
TablePane tp = new TablePane();
setStyles(tp, "{padding: 4}");
TablePane.Column c1 = new TablePane.Column(-1);
TablePane.Column c2 = new TablePane.Column(-1);
tp.getColumns().add(c1);
tp.getColumns().add(c2);
TablePane.Row r1 = new TablePane.Row(-1);
TablePane.Row r2 = new TablePane.Row(-1);
TablePane.Row r3 = new TablePane.Row(-1);
PushButton pb1 = new PushButton("Visible");
PushButton pb2 = new PushButton("Invisible (bug)");
r1.add(pb1);
r1.add(pb2);
final Spinner sp1 = new Spinner(new ListAdapter<>(spinnerData));
sp1.setPreferredWidth(80);
sp1.setSelectedIndex(0);
final Spinner sp2 = new Spinner(new ListAdapter<>(spinnerData));
sp2.setPreferredWidth(80);
sp2.setSelectedIndex(0);
BoxPane bp1 = new BoxPane();
setStyles(bp1, "{verticalAlignment:'center', padding: 4, spacing: 2}");
bp1.add(new Label("X:"));
bp1.add(sp1);
r2.add(bp1);
BoxPane bp2 = new BoxPane();
setStyles(bp2, "{verticalAlignment:'center', padding: 4, spacing: 2}");
bp2.add(new Label("Y:"));
bp2.add(sp2);
r2.add(bp2);
tp.getRows().add(r1);
tp.getRows().add(r2);
r3.add(new Label(" Max X=507"));
r3.add(new Label(" Max Y=269"));
tp.getRows().add(r3);
bp.add(image);
bp.add(tp);
pb1.getButtonPressListeners().add(new ButtonPressListener() {
@Override
public void buttonPressed(Button arg0) {
try {
root.setAttribute("viewBox", AnimationElement.AT_XML, "0 0 2368 1652");
root.updateTime(0f);
image.repaint();
} catch (SVGElementException e) {
e.printStackTrace();
} catch (SVGException e) {
e.printStackTrace();
}
}
});
pb2.getButtonPressListeners().add(new ButtonPressListener() {
@Override
public void buttonPressed(Button arg0) {
try {
String xOffset = (String) sp1.getSelectedItem();
String yOffset = (String) sp2.getSelectedItem();
String viewBox = String.format("%1$s %2$s 2368 1652", xOffset, yOffset);
root.setAttribute("viewBox", AnimationElement.AT_XML, viewBox);
root.updateTime(0f);
image.repaint();
} catch (SVGElementException e) {
e.printStackTrace();
} catch (SVGException e) {
e.printStackTrace();
}
}
});
window.setContent(bp);
window.setMaximized(true);
window.open(display);
}
use of org.apache.pivot.wtk.BoxPane in project pivot by apache.
the class Pivot811 method startup.
@Override
public void startup(final Display displayArgument, Map<String, String> properties) throws Exception {
this.display = displayArgument;
Frame listFrame = new Frame();
listFrame.setTitle("List Frame");
listFrame.setPreferredSize(400, 300);
listFrame.setLocation(20, 20);
listFrame.getStyles().put(Style.padding, Insets.NONE);
BoxPane boxPane = new BoxPane();
boxPane.getStyles().put(Style.fill, true);
boxPane.setOrientation(Orientation.VERTICAL);
listFrame.setContent(boxPane);
Label infoLabel = new Label("Double click on a list item to open a detail frame");
boxPane.add(infoLabel);
ScrollPane scrollPane = new ScrollPane();
scrollPane.setHorizontalScrollBarPolicy(ScrollBarPolicy.FILL);
scrollPane.setVerticalScrollBarPolicy(ScrollBarPolicy.FILL_TO_CAPACITY);
// workaround for pivot-738,
scrollPane.setRepaintAllViewport(true);
// needed only in in some cases
boxPane.add(scrollPane);
final ListView listView = new ListView();
List<String> listData = new ArrayList<>();
for (int i = 0; i < 50; ++i) {
listData.add("List Item " + i);
}
listView.setListData(listData);
scrollPane.setView(listView);
listView.getListViewSelectionListeners().add(new ListViewSelectionListener() {
@Override
public void selectedItemChanged(ListView listViewArgument, Object previousSelectedItem) {
System.out.println("selectedItemChanged : " + listViewArgument.getSelectedItem());
}
});
listView.getComponentMouseButtonListeners().add(new ComponentMouseButtonListener() {
@Override
public boolean mouseClick(Component component, Mouse.Button button, int x, int y, int count) {
System.out.println("mouseClick : " + count);
if (count == 2) {
System.out.println("double click, now open a detail frame");
Frame detailFrame = new Frame();
detailFrame.setTitle("Detail Frame");
detailFrame.setPreferredSize(400, 300);
int selectedIndex = listView.getSelectedIndex();
detailFrame.setLocation(80 + (selectedIndex * 10), 80 + (selectedIndex * 10));
detailFrame.getStyles().put(Style.padding, Insets.NONE);
BoxPane boxPaneLocal = new BoxPane();
boxPaneLocal.getStyles().put(Style.fill, true);
boxPaneLocal.setOrientation(Orientation.VERTICAL);
detailFrame.setContent(boxPaneLocal);
String selectedItem = listView.getSelectedItem().toString();
Label label = new Label("Selected Item is \"" + selectedItem + "\"");
boxPaneLocal.add(label);
// spacer
boxPaneLocal.add(new Label(""));
boxPaneLocal.add(new Label("Click inside the text input to focus it"));
TextInput textInput = new TextInput();
textInput.setText("Focusable component");
// workaround for pivot-811:
boxPaneLocal.add(textInput);
// add a focusable element
// inside the frame
detailFrame.open(displayArgument);
// workaround for pivot-811: force the focus on the first
// focusable element inside the frame
detailFrame.requestFocus();
// textInput.requestFocus(); // or use this ...
}
return true;
}
});
listFrame.open(displayArgument);
listView.setSelectedIndex(0);
listView.requestFocus();
}
use of org.apache.pivot.wtk.BoxPane in project pivot by apache.
the class WindowFocusTest method startup.
@Override
public void startup(final Display display, final Map<String, String> properties) throws Exception {
BoxPane boxPane1 = new BoxPane(Orientation.VERTICAL);
TextInput textInput1 = new TextInput();
textInput1.setText("ABCD");
boxPane1.add(textInput1);
boxPane1.add(new TextInput());
boxPane1.add(new TextInput());
frame1 = new Frame(boxPane1);
frame1.setPreferredSize(320, 240);
frame1.open(display);
BoxPane boxPane2 = new BoxPane(Orientation.VERTICAL);
TextInput textInput2 = new TextInput();
textInput2.setText("1234");
boxPane2.add(textInput2);
boxPane2.add(new TextInput());
boxPane2.add(new TextInput());
frame2 = new Frame(boxPane2);
frame2.setPreferredSize(320, 240);
frame2.open(display);
frame2.requestFocus();
}
use of org.apache.pivot.wtk.BoxPane in project pivot by apache.
the class BoxPaneSkin method getPreferredHeight.
@Override
public int getPreferredHeight(int width) {
BoxPane boxPane = (BoxPane) getComponent();
int preferredHeight = 0;
Orientation orientation = boxPane.getOrientation();
if (orientation == Orientation.HORIZONTAL) {
// Preferred height is the maximum preferred height of all components
for (int i = 0, n = boxPane.getLength(); i < n; i++) {
Component component = boxPane.get(i);
if (component.isVisible()) {
preferredHeight = Math.max(preferredHeight, component.getPreferredHeight());
}
}
} else {
int widthUpdated = width;
// Include padding in constraint
if (widthUpdated != -1) {
widthUpdated = Math.max(widthUpdated - padding.getWidth(), 0);
}
// Preferred height is the sum of the preferred heights of all
// components
int j = 0;
for (int i = 0, n = boxPane.getLength(); i < n; i++) {
Component component = boxPane.get(i);
if (component.isVisible()) {
preferredHeight += component.getPreferredHeight(fill ? widthUpdated : -1);
j++;
}
}
// Include spacing
if (j > 1) {
preferredHeight += spacing * (j - 1);
}
}
// Include top and bottom padding values
preferredHeight += padding.getHeight();
return preferredHeight;
}
use of org.apache.pivot.wtk.BoxPane in project pivot by apache.
the class BoxPaneSkin method install.
@Override
public void install(Component component) {
super.install(component);
BoxPane boxPane = (BoxPane) component;
boxPane.getBoxPaneListeners().add(this);
}
Aggregations