use of org.apache.pivot.wtk.ContainerMouseListener 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);
}
});
}
Aggregations