use of org.apache.pivot.wtk.Button in project pivot by apache.
the class DOMInteractionDemo method startup.
@Override
public void startup(Display display, Map<String, String> properties) throws Exception {
BoxPane boxPane = new BoxPane();
boxPane.getStyles().put(Style.horizontalAlignment, HorizontalAlignment.CENTER);
helloButton = new PushButton("Say Hello");
boxPane.add(helloButton);
helloButton.getButtonPressListeners().add(new ButtonPressListener() {
@Override
public void buttonPressed(Button button) {
BrowserApplicationContext.eval("sayHello(\"Hello from Pivot!\")", DOMInteractionDemo.this);
}
});
Border border = new Border(boxPane);
border.getStyles().put(Style.color, 7);
border.getStyles().put(Style.padding, 5);
window = new Window(border);
window.setMaximized(true);
window.open(display);
}
use of org.apache.pivot.wtk.Button in project pivot by apache.
the class ButtonGroupTest method startup.
@Override
public void startup(Display display, Map<String, String> properties) throws Exception {
ButtonGroup buttonGroup = new ButtonGroup();
buttonGroup.getButtonGroupListeners().add(new ButtonGroupListener() {
@Override
public void selectionChanged(ButtonGroup buttonGroupArgument, Button previousSelection) {
System.out.println("selectionChanged(): previousSelection = " + previousSelection + ", selection = " + buttonGroupArgument.getSelection());
}
@Override
public void buttonAdded(ButtonGroup buttonGroupArgument, Button button) {
System.out.println("buttonAdded(): " + button);
}
@Override
public void buttonRemoved(ButtonGroup buttonGroupArgument, Button button) {
System.out.println("buttonRemoved(): " + button);
}
});
BoxPane boxPane = new BoxPane();
PushButton button1 = new PushButton("One");
button1.setToggleButton(true);
button1.setButtonGroup(buttonGroup);
boxPane.add(button1);
PushButton button2 = new PushButton("Two");
button2.setToggleButton(true);
button2.setButtonGroup(buttonGroup);
boxPane.add(button2);
PushButton button3 = new PushButton("Three");
button3.setToggleButton(true);
button3.setButtonGroup(buttonGroup);
boxPane.add(button3);
PushButton button4 = new PushButton("Four");
button4.setToggleButton(true);
button4.setButtonGroup(buttonGroup);
boxPane.add(button4);
// button1.setSelected(true);
// buttonGroup.setSelection(button1);
// buttonGroup.setSelection(null);
window = new Window(boxPane);
window.setMaximized(true);
window.open(display);
}
use of org.apache.pivot.wtk.Button in project pivot by apache.
the class SheetExampleWindow method initialize.
@Override
public void initialize(Map<String, Object> namespace, URL location, Resources resources) {
editGreetingButton.getButtonPressListeners().add(new ButtonPressListener() {
@Override
public void buttonPressed(Button button) {
HashMap<String, Object> context = new HashMap<>();
store(context);
editGreetingSheet.load(context);
editGreetingSheet.open(SheetExampleWindow.this, new SheetCloseListener() {
@Override
public void sheetClosed(Sheet sheet) {
if (sheet.getResult()) {
HashMap<String, Object> contextLocal = new HashMap<>();
editGreetingSheet.store(contextLocal);
load(contextLocal);
}
}
});
}
});
}
use of org.apache.pivot.wtk.Button in project pivot by apache.
the class TerraRadioButtonSkin method paint.
@Override
public void paint(Graphics2D graphics) {
RadioButton radioButton = (RadioButton) getComponent();
int width = getWidth();
int height = getHeight();
// Paint the button
int offset = (height - BUTTON_DIAMETER) / 2;
graphics.translate(0, offset);
paintButton(graphics, radioButton.isEnabled(), radioButton.isSelected());
graphics.translate(0, -offset);
// Paint the content
Button.DataRenderer dataRenderer = radioButton.getDataRenderer();
Object buttonData = radioButton.getButtonData();
dataRenderer.render(buttonData, radioButton, false);
dataRenderer.setSize(Math.max(width - (BUTTON_DIAMETER + spacing * 2), 0), height);
Graphics2D contentGraphics = (Graphics2D) graphics.create();
contentGraphics.translate(BUTTON_DIAMETER + spacing, 0);
contentGraphics.clipRect(0, 0, dataRenderer.getWidth(), dataRenderer.getHeight());
dataRenderer.paint(contentGraphics);
contentGraphics.dispose();
// Paint the focus state
if (radioButton.isFocused()) {
if (buttonData == null) {
Color focusColor = ColorUtilities.setTransparencyInColor(buttonSelectionColor, ALPHA);
graphics.setColor(focusColor);
graphics.fillOval(0, 0, BUTTON_DIAMETER - 1, BUTTON_DIAMETER - 1);
} else {
BasicStroke dashStroke = new BasicStroke(1.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f, new float[] { 0.0f, 2.0f }, 0.0f);
graphics.setStroke(dashStroke);
graphics.setColor(buttonBorderColor);
GraphicsUtilities.setAntialiasingOn(graphics);
Rectangle2D focusRectangle = new Rectangle2D.Double(BUTTON_DIAMETER + 1, 0.5, dataRenderer.getWidth() + spacing * 2 - 2, dataRenderer.getHeight() - 1);
graphics.draw(focusRectangle);
}
}
}
use of org.apache.pivot.wtk.Button in project pivot by apache.
the class TerraVFSBrowserSheetSkin method install.
@Override
public void install(Component component) {
super.install(component);
final VFSBrowserSheet fileBrowserSheet = (VFSBrowserSheet) component;
fileBrowserSheet.setMinimumWidth(360);
fileBrowserSheet.setMinimumHeight(180);
// Load the sheet content
BXMLSerializer bxmlSerializer = new BXMLSerializer();
Component content;
try {
content = (Component) bxmlSerializer.readObject(TerraVFSBrowserSheetSkin.class, "terra_vfs_browser_sheet_skin.bxml", true);
} catch (IOException exception) {
throw new RuntimeException(exception);
} catch (SerializationException exception) {
throw new RuntimeException(exception);
}
fileBrowserSheet.setContent(content);
bxmlSerializer.bind(this, TerraVFSBrowserSheetSkin.class);
// set the same rootDirectory as the component
try {
FileObject rootDirectory = fileBrowserSheet.getRootDirectory();
fileBrowser.setRootDirectory(rootDirectory);
setHostLabel(rootDirectory);
} catch (FileSystemException fse) {
throw new RuntimeException(fse);
}
// set the same homeDirectory as the component
try {
fileBrowser.setHomeDirectory(fileBrowserSheet.getHomeDirectory());
} catch (FileSystemException fse) {
throw new RuntimeException(fse);
}
saveAsTextInput.getTextInputContentListeners().add(new TextInputContentListener() {
@Override
public void textChanged(TextInput textInput) {
Form.clearFlag(saveAsBoxPane);
updateOKButtonState();
}
});
fileBrowser.getFileBrowserListeners().add(new VFSBrowserListener() {
@Override
public void rootDirectoryChanged(VFSBrowser fileBrowserArgument, FileObject previousRootDirectory) {
updatingSelection = true;
try {
FileObject rootDirectory = fileBrowserArgument.getRootDirectory();
fileBrowserSheet.setRootDirectory(rootDirectory);
setHostLabel(rootDirectory);
} catch (FileSystemException fse) {
throw new RuntimeException(fse);
}
updatingSelection = false;
selectedDirectoryCount = 0;
updateOKButtonState();
}
@Override
public void homeDirectoryChanged(VFSBrowser fileBrowserArgument, FileObject previousHomeDirectory) {
updatingSelection = true;
try {
fileBrowserSheet.setHomeDirectory(fileBrowserArgument.getHomeDirectory());
} catch (FileSystemException fse) {
throw new RuntimeException(fse);
}
updatingSelection = false;
}
@Override
public void selectedFileAdded(VFSBrowser fileBrowserArgument, FileObject file) {
if (file.getName().getType() == FileType.FOLDER) {
selectedDirectoryCount++;
}
updateOKButtonState();
}
@Override
public void selectedFileRemoved(VFSBrowser fileBrowserArgument, FileObject file) {
if (file.getName().getType() == FileType.FOLDER) {
selectedDirectoryCount--;
}
updateOKButtonState();
}
@Override
public void selectedFilesChanged(VFSBrowser fileBrowserArgument, Sequence<FileObject> previousSelectedFiles) {
selectedDirectoryCount = 0;
Sequence<FileObject> selectedFiles = fileBrowserArgument.getSelectedFiles();
for (int i = 0, n = selectedFiles.getLength(); i < n; i++) {
FileObject selectedFile = selectedFiles.get(i);
if (selectedFile.getName().getType() == FileType.FOLDER) {
selectedDirectoryCount++;
}
}
if (!fileBrowserArgument.isMultiSelect()) {
FileObject selectedFile = fileBrowserArgument.getSelectedFile();
if (selectedFile != null && selectedFile.getName().getType() != FileType.FOLDER) {
saveAsTextInput.setText(selectedFile.getName().getPath());
}
}
updateOKButtonState();
}
});
fileBrowser.getComponentMouseButtonListeners().add(new ComponentMouseButtonListener() {
private FileObject file = null;
@Override
public boolean mouseClick(Component componentArgument, Mouse.Button button, int x, int y, int count) {
boolean consumed = false;
VFSBrowserSheet.Mode mode = fileBrowserSheet.getMode();
if (count == 1) {
file = fileBrowser.getFileAt(x, y);
} else if (count == 2) {
FileObject fileLocal = fileBrowser.getFileAt(x, y);
if (fileLocal != null && this.file != null && fileLocal.equals(this.file) && fileBrowser.isFileSelected(fileLocal)) {
if (mode == VFSBrowserSheet.Mode.OPEN || mode == VFSBrowserSheet.Mode.OPEN_MULTIPLE) {
if (fileLocal.getName().getType() != FileType.FOLDER) {
fileBrowserSheet.close(true);
consumed = true;
}
}
}
}
return consumed;
}
});
okButton.getButtonPressListeners().add(new ButtonPressListener() {
@Override
public void buttonPressed(Button button) {
fileBrowserSheet.close(true);
}
});
cancelButton.getButtonPressListeners().add(new ButtonPressListener() {
@Override
public void buttonPressed(Button button) {
fileBrowserSheet.close(false);
}
});
// Add this as a file browser sheet listener
fileBrowserSheet.getFileBrowserSheetListeners().add(this);
modeChanged(fileBrowserSheet, null);
homeDirectoryChanged(fileBrowserSheet, null);
rootDirectoryChanged(fileBrowserSheet, null);
selectedFilesChanged(fileBrowserSheet, null);
}
Aggregations