use of org.apache.pivot.wtk.Frame in project pivot by apache.
the class TerraFrameSkin method getPreferredSize.
@Override
public Dimensions getPreferredSize() {
int preferredWidth = 0;
int preferredHeight = 0;
Frame frame = (Frame) getComponent();
// Include title bar width plus left/right title bar borders
Dimensions titleBarSize = titleBarTablePane.getPreferredSize();
preferredWidth = Math.max(preferredWidth, titleBarSize.width + 2);
// Include title bar height plus top/bottom title bar borders
preferredHeight += titleBarSize.height + 2;
// Include menu bar size
MenuBar menuBar = frame.getMenuBar();
if (menuBar != null) {
Dimensions preferredMenuBarSize = menuBar.getPreferredSize();
preferredWidth = Math.max(preferredWidth, preferredMenuBarSize.width);
preferredHeight += preferredMenuBarSize.height;
}
Component content = frame.getContent();
if (content != null) {
Dimensions preferredContentSize = content.getPreferredSize();
preferredWidth = Math.max(preferredWidth, preferredContentSize.width);
preferredHeight += preferredContentSize.height;
}
// Add padding, borders, and content bevel
preferredWidth += (padding.left + padding.right) + 2;
preferredHeight += (padding.top + padding.bottom) + (showContentBevel ? 1 : 0) + 2;
return new Dimensions(preferredWidth, preferredHeight);
}
use of org.apache.pivot.wtk.Frame in project pivot by apache.
the class TerraFrameSkin method layout.
@Override
public void layout() {
Frame frame = (Frame) getComponent();
int width = getWidth();
int height = getHeight();
boolean maximized = frame.isMaximized();
if (!maximized || getShowWindowControls()) {
int clientX = 1;
int clientY = 1;
int clientWidth = Math.max(width - 2, 0);
int clientHeight = Math.max(height - 2, 0);
// Size/position title bar
titleBarTablePane.setLocation(clientX, clientY);
titleBarTablePane.setSize(clientWidth, titleBarTablePane.getPreferredHeight());
titleBarTablePane.setVisible(true);
// Add bottom title bar border, top content border, and content
// bevel
clientY += titleBarTablePane.getHeight() + (showContentBevel ? 1 : 0) + 2;
// Size/position resize handle
resizeHandle.setSize(resizeHandle.getPreferredSize());
resizeHandle.setLocation(clientWidth - resizeHandle.getWidth(), clientHeight - resizeHandle.getHeight());
resizeHandle.setVisible(resizable && !maximized && (frame.isPreferredWidthSet() || frame.isPreferredHeightSet()));
// Size/position menu bar
MenuBar menuBar = frame.getMenuBar();
if (menuBar != null && menuBar.isVisible()) {
menuBar.setLocation(clientX, clientY);
menuBar.setSize(clientWidth, menuBar.getPreferredHeight());
clientY += menuBar.getHeight();
}
// Size/position content
Component content = frame.getContent();
if (content != null) {
int contentX = clientX + padding.left;
int contentY = clientY + padding.top;
int contentWidth = Math.max(clientWidth - (padding.left + padding.right), 0);
int contentHeight = Math.max(clientHeight - (clientY + padding.top + padding.bottom) + (showContentBevel ? 1 : 0), 0);
content.setLocation(contentX, contentY);
content.setSize(contentWidth, contentHeight);
}
} else {
titleBarTablePane.setVisible(false);
resizeHandle.setVisible(false);
// Size/position menu bar
int clientY = 0;
MenuBar menuBar = frame.getMenuBar();
if (menuBar != null && menuBar.isVisible()) {
menuBar.setLocation(0, clientY);
menuBar.setSize(width, menuBar.getPreferredHeight());
clientY += menuBar.getHeight();
}
Component content = frame.getContent();
if (content != null) {
content.setLocation(padding.left, clientY + padding.top);
content.setSize(Math.max(width - (padding.left + padding.right), 0), Math.max(height - (clientY + padding.top + padding.bottom), 0));
}
}
}
use of org.apache.pivot.wtk.Frame in project pivot by apache.
the class TerraFrameSkin method mouseMove.
@Override
public boolean mouseMove(Component component, int x, int y) {
boolean consumed = super.mouseMove(component, x, y);
if (Mouse.getCapturer() == component) {
Frame frame = (Frame) getComponent();
Display display = frame.getDisplay();
Point location = frame.mapPointToAncestor(display, x, y);
// Pretend that the mouse can't move off screen (off the display)
location = new Point(Math.min(Math.max(location.x, 0), display.getWidth() - 1), Math.min(Math.max(location.y, 0), display.getHeight() - 1));
if (dragOffset != null) {
// Move the frame
frame.setLocation(location.x - dragOffset.x, location.y - dragOffset.y);
} else {
if (resizeOffset != null) {
// Resize the frame
int preferredWidth = -1;
int preferredHeight = -1;
if (frame.isPreferredWidthSet()) {
preferredWidth = Math.max(location.x - frame.getX() + resizeOffset.x, titleBarTablePane.getPreferredWidth(-1) + 2);
preferredWidth = Math.min(preferredWidth, frame.getMaximumWidth());
preferredWidth = Math.max(preferredWidth, frame.getMinimumWidth());
}
if (frame.isPreferredHeightSet()) {
preferredHeight = Math.max(location.y - frame.getY() + resizeOffset.y, titleBarTablePane.getHeight() + resizeHandle.getHeight() + (showContentBevel ? 1 : 0) + 6);
preferredHeight = Math.min(preferredHeight, frame.getMaximumHeight());
preferredHeight = Math.max(preferredHeight, frame.getMinimumHeight());
}
frame.setPreferredSize(preferredWidth, preferredHeight);
}
}
} else {
Cursor cursor = null;
if (resizeHandle.isVisible() && x > resizeHandle.getX() && y > resizeHandle.getY()) {
boolean preferredWidthSet = component.isPreferredWidthSet();
boolean preferredHeightSet = component.isPreferredHeightSet();
if (preferredWidthSet && preferredHeightSet) {
cursor = Cursor.RESIZE_SOUTH_EAST;
} else if (preferredWidthSet) {
cursor = Cursor.RESIZE_EAST;
} else if (preferredHeightSet) {
cursor = Cursor.RESIZE_SOUTH;
}
}
component.setCursor(cursor);
}
return consumed;
}
use of org.apache.pivot.wtk.Frame in project pivot by apache.
the class Windows method startup.
@Override
public void startup(Display displayArgument, Map<String, String> properties) throws Exception {
this.display = displayArgument;
int x = 0;
int y = 0;
for (int i = 0; i < 3; i++) {
BXMLSerializer bxmlSerializer = new BXMLSerializer();
bxmlSerializer.getNamespace().put("application", this);
Frame frame;
try {
frame = (Frame) bxmlSerializer.readObject(Windows.class, "frame.bxml");
} catch (SerializationException exception) {
throw new RuntimeException(exception);
} catch (IOException exception) {
throw new RuntimeException(exception);
}
frame.setTitle("Frame " + (i + 1));
frame.setLocation(x, y);
x += 20;
y += 20;
frame.open(displayArgument);
}
}
Aggregations