use of org.apache.pivot.wtk.Display in project pivot by apache.
the class TerraMenuPopupSkin method windowOpened.
@Override
public void windowOpened(Window window) {
super.windowOpened(window);
Display display = window.getDisplay();
display.getContainerMouseListeners().add(displayMouseListener);
MenuPopup menuPopup = (MenuPopup) window;
Menu menu = menuPopup.getMenu();
if (menu != null) {
Menu.Item activeItem = menu.getActiveItem();
if (activeItem != null) {
activeItem.setActive(false);
}
menu.requestFocus();
}
panorama.setScrollTop(0);
// Always ensure that the menu popup fits on the display.
ApplicationContext.queueCallback(repositionCallback);
}
use of org.apache.pivot.wtk.Display 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);
}
use of org.apache.pivot.wtk.Display in project pivot by apache.
the class SplashScreenTest method startup.
@Override
public void startup(final Display display, final Map<String, String> properties) throws Exception {
File splashFile = new File("org/apache/pivot/tests/splash.png");
System.out.println("Startup the application at " + new Date());
System.out.println("To show the Splash Screen, remember to run as a Standard Java Application this way:\n" + "java -splash:" + splashFile.getPath() + " <mainclassname> --preserveSplashScreen=true\n" + "or no splash screen will be shown.");
// Create a Task that will load a BXML file and simulate some other
// processing while updating a progress meter on the SplashScreen
final Task<Void> prepareApplicationTask = new Task<Void>() {
final SplashScreenProgressOverlay progressOverlay = new SplashScreenProgressOverlay();
@Override
public Void execute() throws TaskExecutionException {
// Load the main BXML
progressOverlay.increment(0);
loadBXML(display, 0.1);
// Simulate other tasks until the progress meter has been filled
final Random random = new Random();
while (progressOverlay.getPercentage() < 1.0) {
// Short random sleep to simulate some processing
try {
Thread.sleep(random.nextInt(50) + 100);
} catch (InterruptedException e) {
e.printStackTrace();
}
// Update the progress meter by a random amount
progressOverlay.increment((1 + random.nextInt(10)) / 100.0);
}
return null;
}
// Load the Pivot UI
private void loadBXML(final Display displayArgument, final double weight) {
try {
ApplicationContext.queueCallback(() -> {
Window window = null;
try {
window = (Window) new BXMLSerializer().readObject(this.getClass().getResource("splash.bxml"));
} catch (Exception e) {
throw new RuntimeException(e);
}
if (window != null) {
window.open(displayArgument);
progressOverlay.increment(weight);
}
});
} catch (Exception e) {
throw new RuntimeException(e);
}
}
};
// Hide the SplashScreen when the Task finishes by making the Pivot host
// window visible.
final TaskListener<Void> taskListener = new TaskListener<Void>() {
@Override
public void taskExecuted(final Task<Void> task) {
finished();
}
@Override
public void executeFailed(final Task<Void> task) {
System.err.println(String.format("Failed\n%s", task.getFault()));
task.getFault().printStackTrace();
finished();
}
private void finished() {
DesktopApplicationContext.replaceSplashScreen(display);
}
};
// Run the Task asynchronously
prepareApplicationTask.execute(new TaskAdapter<>(taskListener));
}
use of org.apache.pivot.wtk.Display in project pivot by apache.
the class ComponentSkin method tooltipTriggered.
@Override
public void tooltipTriggered(Component componentArgument, int x, int y) {
String tooltipText = component.getTooltipText();
if (tooltipText != null) {
Label tooltipLabel = new Label(tooltipText);
boolean tooltipWrapText = component.getTooltipWrapText();
tooltipLabel.getStyles().put(Style.wrapText, tooltipWrapText);
Tooltip tooltip = new Tooltip(tooltipLabel);
Display display = component.getDisplay();
Point location = component.mapPointToAncestor(display, x, y);
// Ensure that the tooltip stays on screen
int tooltipX = location.x + 16;
int tooltipY = location.y;
int tooltipWidth = tooltip.getPreferredWidth();
int tooltipHeight = tooltip.getPreferredHeight();
if (tooltipX + tooltipWidth > display.getWidth()) {
// the cursor
if (tooltipY > tooltipHeight) {
tooltipX = display.getWidth() - tooltipWidth;
} else {
tooltipX = location.x - tooltipWidth - 16;
}
if (tooltipX < 0) {
tooltipX = 0;
}
// these x adjustments
if (tooltipX < location.x && tooltipX + tooltipWidth > location.x) {
tooltipY -= tooltipHeight;
if (tooltipY < 0) {
tooltipY = 0;
}
}
}
if (tooltipY + tooltipHeight > display.getHeight()) {
tooltipY -= tooltipHeight;
}
tooltip.setLocation(tooltipX, tooltipY);
tooltip.open(component.getWindow());
}
}
use of org.apache.pivot.wtk.Display in project pivot by apache.
the class TableViewRowEditor method close.
@Override
public void close() {
Display display = getDisplay();
display.getContainerMouseListeners().remove(displayMouseHandler);
super.close();
}
Aggregations