use of org.apache.pivot.wtk.Sheet 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.Sheet in project pivot by apache.
the class FileBrowsing method initialize.
@Override
public void initialize(Map<String, Object> namespace, URL location, Resources resources) {
openSheetButton.getButtonPressListeners().add(new ButtonPressListener() {
@Override
public void buttonPressed(Button button) {
Button selection = fileBrowserSheetModeGroup.getSelection();
String mode = (String) selection.getUserData().get("mode");
FileBrowserSheet.Mode fileBrowserSheetMode = FileBrowserSheet.Mode.valueOf(mode.toUpperCase());
final FileBrowserSheet fileBrowserSheet = new FileBrowserSheet();
if (fileBrowserSheetMode == FileBrowserSheet.Mode.SAVE_AS) {
fileBrowserSheet.setSelectedFile(new File(fileBrowserSheet.getRootDirectory(), "New File"));
}
fileBrowserSheet.setMode(fileBrowserSheetMode);
fileBrowserSheet.open(FileBrowsing.this, new SheetCloseListener() {
@Override
public void sheetClosed(Sheet sheet) {
if (sheet.getResult()) {
Sequence<File> selectedFiles = fileBrowserSheet.getSelectedFiles();
ListView listView = new ListView();
listView.setListData(new ArrayList<>(selectedFiles));
listView.setSelectMode(ListView.SelectMode.NONE);
listView.getStyles().put(Style.backgroundColor, null);
Alert.alert(MessageType.INFO, "You selected:", listView, FileBrowsing.this);
} else {
Alert.alert(MessageType.INFO, "You didn't select anything.", FileBrowsing.this);
}
}
});
}
});
}
use of org.apache.pivot.wtk.Sheet in project pivot by apache.
the class Pivot832 method startup.
@Override
public void startup(Display display, Map<String, String> properties) throws Exception {
BXMLSerializer bxmlSerializer = new BXMLSerializer();
window = (Window) bxmlSerializer.readObject(getClass().getResource("pivot_832.bxml"));
bxmlSerializer.bind(this, Pivot832.class);
selectFolderButton.getButtonPressListeners().add(new ButtonPressListener() {
@Override
public void buttonPressed(Button button) {
final FileBrowserSheet fileBrowserSheet = new FileBrowserSheet();
// to
fileBrowserSheet.setMode(FileBrowserSheet.Mode.SAVE_TO);
// be
// able
// to
// select
// a
// folder
fileBrowserSheet.open(window, new SheetCloseListener() {
@Override
public void sheetClosed(Sheet sheet) {
if (sheet.getResult()) {
File loadedFile = fileBrowserSheet.getSelectedFile();
try {
selectedFolder = loadedFile.getCanonicalPath();
System.out.println("Selected folder '" + selectedFolder + "'");
// multiple tests ...
System.out.println("Verify: Root folder (display from getName) was set to '" + fileBrowserSheet.getRootDirectory().getName() + "'");
System.out.println("Verify: Root folder (display from getCanonicalPath) was set to '" + fileBrowserSheet.getRootDirectory().getCanonicalPath() + "'");
System.out.println("Verify: Root folder (display from getCanonicalFile) was set to '" + fileBrowserSheet.getRootDirectory().getCanonicalFile() + "'");
openFileButton.setEnabled(true);
} catch (IOException e) {
e.printStackTrace();
openFileButton.setEnabled(false);
}
window.setTitle("Selected folder: " + selectedFolder);
}
}
});
}
});
openFileButton.getButtonPressListeners().add(new ButtonPressListener() {
@Override
public void buttonPressed(Button button) {
System.out.println("Now opening a BrowserSheet starting from the previous selected folder: \"" + selectedFolder + "\"");
final FileBrowserSheet fileBrowserSheet = new FileBrowserSheet(FileBrowserSheet.Mode.OPEN, selectedFolder);
try {
// multiple tests ...
System.out.println("Verify: Root folder (display from getName) was set to '" + fileBrowserSheet.getRootDirectory().getName() + "'");
System.out.println("Verify: Root folder (display from getCanonicalPath) was set to '" + fileBrowserSheet.getRootDirectory().getCanonicalPath() + "'");
System.out.println("Verify: Root folder (display from getCanonicalFile) was set to '" + fileBrowserSheet.getRootDirectory().getCanonicalFile() + "'");
} catch (IOException e) {
e.printStackTrace();
}
fileBrowserSheet.open(window, new SheetCloseListener() {
@Override
public void sheetClosed(Sheet sheet) {
// empty block
}
});
}
});
window.open(display);
}
use of org.apache.pivot.wtk.Sheet in project pivot by apache.
the class TextPaneDemo method startup.
@Override
public void startup(Display display, Map<String, String> properties) throws Exception {
System.out.println("startup(...)");
System.out.println("\n" + "In this test application as a sample for setting the display scale on startup, use startup argument \"--scale=n\" property; \n" + "for instance, using \"--scale=2.0\" will set double scale on the whole application.\n" + "\n" + "Anyway, using Ctrl-Shift-MouseWheel will scale the display up and down as well, for the user of your application.\n");
BXMLSerializer bxmlSerializer = new BXMLSerializer();
window = (Window) bxmlSerializer.readObject(TextPaneDemo.class, "text_pane_demo.bxml");
bxmlSerializer.bind(this, TextPaneDemo.class);
window.setTitle("Apache Pivot Rich Text Editor Demo");
// make the text on the "bold" button bold
Font boldButtonFont = boldButton.getStyles().getFont(Style.font);
boldButton.getStyles().put(Style.font, boldButtonFont.deriveFont(Font.BOLD));
// make the text on the "italic" button italic
Font italicButtonFont = italicButton.getStyles().getFont(Style.font);
italicButton.getStyles().put(Style.font, italicButtonFont.deriveFont(Font.ITALIC));
fontFamilyListButton.setListData(new ArrayList<>(GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames()));
fontSizeListButton.setSelectedItem(fontFamilyListButton.getListData().get(0));
fontFamilyListButton.setItemRenderer(new ListViewItemRenderer() {
@Override
public void render(Object item, int index, ListView listView, boolean selected, Button.State state, boolean highlighted, boolean disabled) {
super.render(item, index, listView, selected, state, highlighted, disabled);
if (item != null) {
String fontFamilyName = (String) item;
label.getStyles().put(Style.font, Font.decode(fontFamilyName + "-12"));
}
}
});
fontFamilyListButton.setDataRenderer(new ListButtonDataRenderer() {
@Override
public void render(Object data, Button button, boolean highlight) {
super.render(data, button, highlight);
if (data != null) {
String fontFamilyName = (String) data;
label.getStyles().put(Style.font, Font.decode(fontFamilyName + "-12"));
}
}
});
fontSizeListButton.setListData(new NumericSpinnerData(12, 30, 1));
fontSizeListButton.setSelectedItem(12);
openFileButton.getButtonPressListeners().add(new ButtonPressListener() {
@Override
public void buttonPressed(Button button) {
final FileBrowserSheet fileBrowserSheet = new FileBrowserSheet();
fileBrowserSheet.setMode(FileBrowserSheet.Mode.OPEN);
fileBrowserSheet.open(window, new SheetCloseListener() {
@Override
public void sheetClosed(Sheet sheet) {
if (sheet.getResult()) {
loadedFile = fileBrowserSheet.getSelectedFile();
try {
BufferedReader reader = new BufferedReader(new FileReader(loadedFile));
PlainTextSerializer serializer = new PlainTextSerializer();
textPane.setDocument(serializer.readObject(reader));
reader.close();
window.setTitle(loadedFile.getCanonicalPath());
} catch (IOException ex) {
ex.printStackTrace();
Alert.alert(ex.getMessage(), window);
}
}
}
});
}
});
saveFileButton.getButtonPressListeners().add(new ButtonPressListener() {
@Override
public void buttonPressed(Button button) {
final FileBrowserSheet fileBrowserSheet = new FileBrowserSheet();
if (loadedFile != null) {
fileBrowserSheet.setSelectedFile(loadedFile);
}
fileBrowserSheet.setMode(FileBrowserSheet.Mode.SAVE_AS);
fileBrowserSheet.open(window, new SheetCloseListener() {
@Override
public void sheetClosed(Sheet sheet) {
if (sheet.getResult()) {
File selectedFile = fileBrowserSheet.getSelectedFile();
try {
FileWriter writer = new FileWriter(selectedFile);
PlainTextSerializer serializer = new PlainTextSerializer();
serializer.writeObject(textPane.getDocument(), writer);
writer.close();
loadedFile = selectedFile;
window.setTitle(loadedFile.getCanonicalPath());
} catch (IOException ex) {
ex.printStackTrace();
Alert.alert(ex.getMessage(), window);
}
}
}
});
}
});
boldButton.getButtonPressListeners().add(new ButtonPressListener() {
@Override
public void buttonPressed(Button button) {
applyStyleToSelection(new StyleApplicator() {
@Override
public void apply(TextSpan span) {
if (span.getFont() != null) {
Font font = span.getFont();
if (font.getStyle() == Font.PLAIN) {
font = font.deriveFont(Font.BOLD);
} else if (font.getStyle() == Font.BOLD) {
font = font.deriveFont(Font.PLAIN);
} else {
// the font is BOLD+ITALIC
font = font.deriveFont(Font.ITALIC);
}
span.setFont(font);
} else {
span.setFont("Arial BOLD 12");
}
}
});
requestTextPaneFocus();
}
});
italicButton.getButtonPressListeners().add(new ButtonPressListener() {
@Override
public void buttonPressed(Button button) {
applyStyleToSelection(new StyleApplicator() {
@Override
public void apply(TextSpan span) {
if (span.getFont() != null) {
Font font = span.getFont();
if (font.getStyle() == Font.PLAIN) {
font = font.deriveFont(Font.ITALIC);
} else if (font.getStyle() == Font.ITALIC) {
font = font.deriveFont(Font.PLAIN);
} else {
// the font is BOLD+ITALIC
font = font.deriveFont(Font.BOLD);
}
span.setFont(font);
} else {
span.setFont("Arial ITALIC 12");
}
}
});
requestTextPaneFocus();
}
});
underlineButton.getButtonPressListeners().add(new ButtonPressListener() {
@Override
public void buttonPressed(Button button) {
applyStyleToSelection(new StyleApplicator() {
@Override
public void apply(TextSpan span) {
span.setUnderline(!span.isUnderline());
}
});
requestTextPaneFocus();
}
});
strikethroughButton.getButtonPressListeners().add(new ButtonPressListener() {
@Override
public void buttonPressed(Button button) {
applyStyleToSelection(new StyleApplicator() {
@Override
public void apply(TextSpan span) {
span.setStrikethrough(!span.isStrikethrough());
}
});
requestTextPaneFocus();
}
});
foregroundColorChooserButton.getColorChooserButtonSelectionListeners().add(new ColorChooserButtonSelectionListener() {
@Override
public void selectedColorChanged(ColorChooserButton colorChooserButton, Color previousSelectedColor) {
applyStyleToSelection(new StyleApplicator() {
@Override
public void apply(TextSpan span) {
span.setForegroundColor(foregroundColorChooserButton.getSelectedColor());
}
});
requestTextPaneFocus();
}
});
backgroundColorChooserButton.getColorChooserButtonSelectionListeners().add(new ColorChooserButtonSelectionListener() {
@Override
public void selectedColorChanged(ColorChooserButton colorChooserButton, Color previousSelectedColor) {
applyStyleToSelection(new StyleApplicator() {
@Override
public void apply(TextSpan span) {
span.setBackgroundColor(backgroundColorChooserButton.getSelectedColor());
}
});
requestTextPaneFocus();
}
});
ListButtonSelectionListener fontButtonPressListener = new ListButtonSelectionListener() {
@Override
public void selectedItemChanged(ListButton listButton, Object previousSelectedItem) {
int selectedFontSize = ((Integer) fontSizeListButton.getSelectedItem()).intValue();
String selectedFontFamily = (String) fontFamilyListButton.getSelectedItem();
final Font derivedFont = Font.decode(selectedFontFamily + " " + selectedFontSize);
applyStyleToSelection(new StyleApplicator() {
@Override
public void apply(TextSpan span) {
span.setFont(derivedFont);
}
});
requestTextPaneFocus();
}
};
fontFamilyListButton.getListButtonSelectionListeners().add(fontButtonPressListener);
fontSizeListButton.getListButtonSelectionListeners().add(fontButtonPressListener);
wrapTextCheckbox.getButtonPressListeners().add(new ButtonPressListener() {
@Override
public void buttonPressed(Button button) {
textPane.getStyles().put(Style.wrapText, wrapTextCheckbox.isSelected());
requestTextPaneFocus();
}
});
alignLeftButton.getButtonPressListeners().add(new ButtonPressListener() {
@Override
public void buttonPressed(Button button) {
applyAlignmentStyle(HorizontalAlignment.LEFT);
requestTextPaneFocus();
}
});
alignCentreButton.getButtonPressListeners().add(new ButtonPressListener() {
@Override
public void buttonPressed(Button button) {
applyAlignmentStyle(HorizontalAlignment.CENTER);
requestTextPaneFocus();
}
});
alignRightButton.getButtonPressListeners().add(new ButtonPressListener() {
@Override
public void buttonPressed(Button button) {
applyAlignmentStyle(HorizontalAlignment.RIGHT);
requestTextPaneFocus();
}
});
String scaleProperty = properties.get("scale");
if (scaleProperty != null && !scaleProperty.isEmpty()) {
try {
double scaleFactor = Double.parseDouble(scaleProperty);
System.out.println("Got scaling factor \"" + scaleProperty + "\" from command line arguments, now applying to display");
display.getDisplayHost().setScale(scaleFactor);
} catch (NumberFormatException nfe) {
System.err.println("(NumberFormatException: " + nfe.getMessage());
}
}
window.open(display);
requestTextPaneFocus();
}
use of org.apache.pivot.wtk.Sheet in project pivot by apache.
the class TerraSheetSkin method mouseMove.
@Override
public boolean mouseMove(Component component, int x, int y) {
boolean consumed = super.mouseMove(component, x, y);
if (Mouse.getCapturer() == component) {
Sheet sheet = (Sheet) getComponent();
Display display = sheet.getDisplay();
Point location = sheet.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 (resizeOffset != null) {
// Resize the frame
int preferredWidth = -1;
int preferredHeight = -1;
boolean preferredWidthSet = component.isPreferredWidthSet();
boolean preferredHeightSet = component.isPreferredHeightSet();
boolean noPreferredSet = !(preferredWidthSet || preferredHeightSet);
if (preferredWidthSet || noPreferredSet) {
preferredWidth = Math.max(location.x - sheet.getX() + resizeOffset.x, 2);
preferredWidth = Math.min(preferredWidth, sheet.getMaximumWidth());
preferredWidth = Math.max(preferredWidth, sheet.getMinimumWidth());
}
if (preferredHeightSet || noPreferredSet) {
preferredHeight = Math.max(location.y - sheet.getY() + resizeOffset.y, resizeHandle.getHeight() + 7);
preferredHeight = Math.min(preferredHeight, sheet.getMaximumHeight());
preferredHeight = Math.max(preferredHeight, sheet.getMinimumHeight());
}
sheet.setPreferredSize(preferredWidth, preferredHeight);
}
} else {
Cursor cursor = null;
Bounds resizeHandleBounds = resizeHandle.getBounds();
if (resizable && resizeHandleBounds.contains(x, y)) {
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;
} else {
cursor = Cursor.RESIZE_SOUTH_EAST;
}
}
component.setCursor(cursor);
}
return consumed;
}
Aggregations