use of org.apache.pivot.wtk.WindowStateListener in project pivot by apache.
the class Pivot765 method startup.
@Override
public void startup(final Display display, Map<String, String> properties) throws Exception {
final MenuButton button = new MenuButton();
button.setButtonData("Populate menu and open!");
Window window = new Window(button);
button.getListPopup().getWindowStateListeners().add(new WindowStateListener() {
@Override
public Vote previewWindowOpen(Window windowArgument) {
Menu menu = new Menu();
Menu.Section section = new Menu.Section();
menu.getSections().add(section);
section.add(new Menu.Item("A dynamically added menu item"));
button.setMenu(menu);
menuPopulated = true;
return Vote.APPROVE;
}
@Override
public void windowOpened(Window windowArgument) {
if (!menuPopulated) {
Alert.alert("Window was opened before the menu was populated." + "Either previewWindowOpen threw an exception, or it wasn't called before the Window was opened.", windowArgument);
}
}
@Override
public void windowClosed(Window windowArgument, Display displayArgument, Window owner) {
// Remove menu for subsequent open attempt
button.setMenu(null);
menuPopulated = false;
}
});
window.open(display);
}
use of org.apache.pivot.wtk.WindowStateListener in project pivot by apache.
the class SheetSlideDirectionWindow method initialize.
@Override
public void initialize(Map<String, Object> namespace, URL location, Resources resources) {
// Populate the ListButton with values from the enum
listButton.setListData(new ArrayList<>(SheetPlacement.values()));
listButton = null;
// Populate the form with data from the Sheet's styles
form.load(sheet.getStyles());
// Common ButtonPressListener to be applied to all four of
// the PushButtons representing a slide direction
ButtonPressListener openSheetButtonPressListener = new ButtonPressListener() {
@Override
public void buttonPressed(Button button) {
StyleDictionary sheetStyles = sheet.getStyles();
form.store(sheetStyles);
button.store(sheetStyles);
form.load(sheetStyles);
sheet.load(sheetStyles);
sheet.open(button.getWindow());
}
};
// Apply the common ButtonPressListener to the PushButtons
for (Iterator<Component> it = tablePane.iterator(); it.hasNext(); ) {
Component component = it.next();
if (component instanceof PushButton) {
PushButton button = (PushButton) component;
button.getButtonPressListeners().add(openSheetButtonPressListener);
button.setTooltipText("Press me!");
}
}
tablePane = null;
// Mouse handler to enable users to quickly close the sheet
final ContainerMouseListener displayMouseHandler = new ContainerMouseListener() {
@Override
public boolean mouseDown(Container container, Mouse.Button button, int x, int y) {
Display display = (Display) container;
Component component = display.getComponentAt(x, y);
// Close the sheet by clicking away from it.
// This allows resizing etc to work without requiring
// a close button or similar on the sheet.
boolean consumed = (component != sheet);
if (consumed) {
sheet.close();
}
return consumed;
}
};
// Add/remove the mouse handler based on the Sheet's state
sheet.getWindowStateListeners().add(new WindowStateListener() {
@Override
public void windowOpened(Window window) {
window.getDisplay().getContainerMouseListeners().add(displayMouseHandler);
}
@Override
public void windowClosed(Window window, Display display, Window owner) {
display.getContainerMouseListeners().remove(displayMouseHandler);
}
});
}
use of org.apache.pivot.wtk.WindowStateListener in project pivot by apache.
the class SheetTest method startup.
@SuppressWarnings("unused")
@Override
public void startup(final Display display, Map<String, String> properties) throws Exception {
Picture picture = (Picture) Image.load(getClass().getResource("IMG_0767_2.jpg"));
picture.resample(120);
BoxPane windowContent = new BoxPane();
PushButton button = new PushButton(picture);
button.getStyles().put(Style.toolbar, true);
windowContent.add(button);
frame = new Frame(windowContent);
frame.setPreferredSize(480, 360);
frame.getStyles().put(Style.padding, 0);
frame.open(display);
final TablePane tablePane = new TablePane();
tablePane.setPreferredSize(320, 240);
new TablePane.Column(tablePane, 1, true);
TablePane.Row row0 = new TablePane.Row(tablePane, 1, true);
TablePane.Row row1 = new TablePane.Row(tablePane, -1);
final Label sheetContent = new Label("Sheet Content");
sheetContent.getStyles().put(Style.wrapText, true);
sheetContent.getStyles().put(Style.horizontalAlignment, HorizontalAlignment.CENTER);
sheetContent.getStyles().put(Style.verticalAlignment, VerticalAlignment.CENTER);
row0.add(sheetContent);
Label promptBody = new Label("Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an AS IS BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.");
promptBody.getStyles().put(Style.wrapText, true);
final Prompt prompt = new Prompt(MessageType.INFO, "Prompt", new ArrayList<>("OK"), promptBody);
prompt.setTitle("Prompt");
prompt.getStyles().put(Style.resizable, true);
prompt.getComponentMouseListeners().add(new ComponentMouseListener() {
@Override
public void mouseOver(Component component) {
System.out.println("Mouse Over");
}
@Override
public void mouseOut(Component component) {
System.out.println("Mouse out");
}
});
Label alertBody = new Label("Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an AS IS BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.");
alertBody.getStyles().put(Style.wrapText, true);
final Alert alert = new Alert(MessageType.INFO, "Alert", new ArrayList<>("OK"), alertBody);
alert.setTitle("Alert");
BoxPane boxPane = new BoxPane();
row1.add(boxPane);
boxPane.getStyles().put(Style.horizontalAlignment, HorizontalAlignment.RIGHT);
final PushButton closeButton = new PushButton("Close");
closeButton.getStyles().put(Style.minimumAspectRatio, 3);
boxPane.add(closeButton);
sheet = new Sheet(tablePane);
closeButton.getButtonPressListeners().add(new ButtonPressListener() {
@Override
public void buttonPressed(Button buttonArgument) {
buttonArgument.getWindow().close();
}
});
button.getButtonPressListeners().add(new ButtonPressListener() {
@Override
public void buttonPressed(Button buttonArgument) {
prompt.open(frame);
Display displayLocal = DesktopApplicationContext.createDisplay(640, 480, 100, 100, true, true, false, buttonArgument.getDisplay().getHostWindow(), null);
Window window = new Window();
window.setTitle("New Secondary Window");
window.setMaximized(true);
window.setContent(new Label("I am a secondary window!"));
window.open(displayLocal);
}
});
sheet.getWindowStateListeners().add(new WindowStateListener() {
@Override
public void windowOpened(Window window) {
closeButton.requestFocus();
}
});
DesktopApplicationContext.sizeHostToFit(frame);
}
Aggregations