use of org.apache.pivot.wtk.Palette in project pivot by apache.
the class WindowTest method startup.
@Override
public void startup(final Display display, final Map<String, String> properties) {
window1.setTitle("Window 1");
window1.setPreferredSize(640, 480);
window1.setMaximumWidth(640);
window1.setMaximumHeight(480);
window1.setMinimumWidth(320);
window1.setMinimumHeight(240);
window1.getComponentListeners().add(new ComponentListener() {
@Override
public void sizeChanged(final Component component, final int previousWidth, final int previousHeight) {
window1.align(window1.getDisplay().getBounds(), HorizontalAlignment.CENTER, VerticalAlignment.CENTER);
window1.getComponentListeners().remove(this);
}
});
display.getStyles().put(Style.backgroundColor, new Color(0, 127, 127));
window1.setContent(new Label("Hello Bar"));
window1.open(display);
ApplicationContext.queueCallback(() -> {
final Sheet sheet = new Sheet();
sheet.setPreferredSize(120, 60);
sheet.open(window1);
ApplicationContext.queueCallback(() -> {
Sheet sheet2 = new Sheet();
sheet2.setPreferredSize(60, 30);
sheet2.open(sheet);
});
});
Frame window1a = new Frame();
window1a.setTitle("Window 1 A");
window1a.setLocation(30, 280);
window1a.setPreferredSize(160, 120);
window1a.open(window1);
Frame window1ai = new Frame();
window1ai.setTitle("Window 1 A I");
window1ai.setLocation(150, 300);
window1ai.setPreferredSize(320, 200);
window1ai.open(window1a);
window1ai.getDecorators().update(0, new ReflectionDecorator());
Frame window1aii = new Frame();
window1aii.setTitle("Window 1 A II");
window1aii.setLocation(50, 400);
window1aii.setPreferredSize(320, 200);
window1aii.open(window1a);
Frame window1b = new Frame();
window1b.setTitle("Window 1 B");
window1b.setPreferredSize(160, 120);
window1b.setLocation(260, 60);
window1b.open(window1);
Frame window1bi = new Frame();
window1bi.setTitle("Window 1 B I");
window1bi.setPreferredSize(180, 60);
window1bi.setLocation(270, 160);
window1bi.setContent(new Label("This window is not enabled"));
// to test even a not enabled window ...
window1bi.setEnabled(false);
window1bi.open(window1b);
Frame window1bii = new Frame();
window1bii.setTitle("Window 1 B II");
window1bii.setPreferredSize(160, 60);
window1bii.setLocation(320, 10);
window1bii.open(window1b);
Palette palette1 = new Palette();
palette1.setTitle("Palette 1bii 1");
palette1.setPreferredSize(160, 60);
palette1.setLocation(290, 210);
palette1.open(window1bii);
Palette palette2 = new Palette();
palette2.setTitle("Palette 1bii 2");
palette2.setPreferredSize(160, 60);
palette2.setLocation(600, 200);
palette2.setContent(new Label("This palette is not enabled"));
// to test even a not enabled palette ...
palette2.setEnabled(false);
palette2.open(window1bii);
dialogOwner.setTitle("Dialog Owner");
dialogOwner.setPreferredSize(320, 120);
dialogOwner.open(display);
// window1bii.requestFocus();
ApplicationContext.queueCallback(() -> {
final Dialog dialog = new Dialog();
dialog.setTitle("Dialog 1");
dialog.setPreferredSize(280, 100);
dialog.open(dialogOwner);
ApplicationContext.queueCallback(() -> {
Dialog dialog2 = new Dialog();
dialog2.setTitle("Dialog 2");
dialog2.setPreferredSize(220, 80);
dialog2.open(dialog);
});
});
}
use of org.apache.pivot.wtk.Palette in project pivot by apache.
the class TerraPaletteSkin method getPreferredSize.
@Override
public Dimensions getPreferredSize() {
int preferredWidth = 0;
int preferredHeight = 0;
Palette palette = (Palette) getComponent();
Component content = palette.getContent();
Dimensions preferredTitleBarSize = titleBarTablePane.getPreferredSize();
preferredWidth = preferredTitleBarSize.width;
preferredHeight = preferredTitleBarSize.height;
if (content != null) {
Dimensions preferredContentSize = content.getPreferredSize();
preferredWidth = Math.max(preferredWidth, preferredContentSize.width);
preferredHeight += preferredContentSize.height;
}
preferredWidth += padding.getWidth() + 2;
preferredHeight += padding.getHeight() + 4;
return new Dimensions(preferredWidth, preferredHeight);
}
use of org.apache.pivot.wtk.Palette in project pivot by apache.
the class TerraPaletteSkin method getPreferredWidth.
@Override
public int getPreferredWidth(int height) {
int preferredWidth = 0;
Palette palette = (Palette) getComponent();
Component content = palette.getContent();
Dimensions preferredTitleBarSize = titleBarTablePane.getPreferredSize();
preferredWidth = preferredTitleBarSize.width;
if (content != null) {
if (height != -1) {
height = Math.max(height - preferredTitleBarSize.height - 4 - padding.getHeight(), 0);
}
preferredWidth = Math.max(preferredWidth, content.getPreferredWidth(height));
}
preferredWidth += padding.getWidth() + 2;
return preferredWidth;
}
use of org.apache.pivot.wtk.Palette in project pivot by apache.
the class TerraPaletteSkin method mouseMove.
@Override
public boolean mouseMove(Component component, int x, int y) {
boolean consumed = super.mouseMove(component, x, y);
if (Mouse.getCapturer() == component) {
Palette palette = (Palette) getComponent();
Display display = palette.getDisplay();
Point location = palette.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 window
palette.setLocation(location.x - dragOffset.x, location.y - dragOffset.y);
} else {
if (resizeOffset != null) {
// Resize the frame
int preferredWidth = -1;
int preferredHeight = -1;
if (palette.isPreferredWidthSet()) {
preferredWidth = Math.max(location.x - palette.getX() + resizeOffset.x, titleBarTablePane.getPreferredWidth(-1) + 2);
preferredWidth = Math.min(preferredWidth, palette.getMaximumWidth());
preferredWidth = Math.max(preferredWidth, palette.getMinimumWidth());
}
if (palette.isPreferredHeightSet()) {
preferredHeight = Math.max(location.y - palette.getY() + resizeOffset.y, titleBarTablePane.getHeight() + resizeHandle.getHeight() + 7);
preferredHeight = Math.min(preferredHeight, palette.getMaximumHeight());
preferredHeight = Math.max(preferredHeight, palette.getMinimumHeight());
}
palette.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.Palette in project pivot by apache.
the class TerraPaletteSkin method paint.
@Override
public void paint(Graphics2D graphics) {
// Call the base class to paint the background
super.paint(graphics);
int width = getWidth();
int height = getHeight();
int titleBarHeight = titleBarTablePane.getHeight();
graphics.setStroke(new BasicStroke());
Palette palette = (Palette) getComponent();
boolean active = palette.getOwner().isActive();
boolean enabled = palette.isEnabled();
Color currentTitleBarBackgroundColor = (active && enabled) ? titleBarBackgroundColor : inactiveTitleBarBackgroundColor;
Color currentTitleBarBorderColor = (active && enabled) ? titleBarBorderColor : inactiveTitleBarBorderColor;
Color titleBarBevelColor = TerraTheme.brighten(currentTitleBarBackgroundColor);
if (!themeIsFlat()) {
// Draw the title area
graphics.setPaint(new GradientPaint(width / 2f, 0, titleBarBevelColor, width / 2f, titleBarHeight + 1, currentTitleBarBackgroundColor));
graphics.fillRect(0, 0, width, titleBarHeight + 1);
// Draw the border
graphics.setPaint(currentTitleBarBorderColor);
GraphicsUtilities.drawRect(graphics, 0, 0, width, titleBarHeight + 1);
// Draw the content area
Bounds contentAreaRectangle = new Bounds(0, titleBarHeight + 2, width, height - (titleBarHeight + 2));
graphics.setPaint(contentBorderColor);
GraphicsUtilities.drawRect(graphics, contentAreaRectangle.x, contentAreaRectangle.y, contentAreaRectangle.width, contentAreaRectangle.height);
graphics.setPaint(contentBevelColor);
GraphicsUtilities.drawLine(graphics, contentAreaRectangle.x + 1, contentAreaRectangle.y + 1, contentAreaRectangle.width - 2, Orientation.HORIZONTAL);
} else {
// Draw the title area
graphics.setPaint(currentTitleBarBackgroundColor);
graphics.fillRect(0, 0, width, titleBarHeight + 1);
}
}
Aggregations