use of org.apache.pivot.wtk.ListButton in project pivot by apache.
the class LargeData method startup.
@Override
public void startup(Display display, Map<String, String> properties) throws Exception {
basePath = properties.get(BASE_PATH_KEY);
if (basePath == null) {
throw new IllegalArgumentException(BASE_PATH_KEY + " is required.");
}
origin = ApplicationContext.getOrigin();
if (origin == null) {
System.out.println("Running as a Standalone Java Application, with user home: \"" + USER_HOME + "\"");
if (USER_HOME != null) {
System.out.println("Set as origin the user home");
origin = (new File(USER_HOME).toURI()).toURL();
}
}
BXMLSerializer bxmlSerializer = new BXMLSerializer();
window = (Window) bxmlSerializer.readObject(LargeData.class, "large_data.bxml");
fileListButton = (ListButton) bxmlSerializer.getNamespace().get("fileListButton");
loadDataButton = (PushButton) bxmlSerializer.getNamespace().get("loadDataButton");
cancelButton = (PushButton) bxmlSerializer.getNamespace().get("cancelButton");
clearButton = (PushButton) bxmlSerializer.getNamespace().get("clearButton");
statusLabel = (Label) bxmlSerializer.getNamespace().get("statusLabel");
tableView = (TableView) bxmlSerializer.getNamespace().get("tableView");
fileListButton.getListButtonSelectionListeners().add(new ListButtonSelectionListener() {
@Override
public void selectedItemChanged(ListButton listButtonArgument, Object previousSelectedItem) {
Object selectedItem = listButtonArgument.getSelectedItem();
System.out.println("Selected: " + selectedItem.toString() + ", now clear table data ...");
// empty the table
tableView.getTableData().clear();
}
});
loadDataButton.getButtonPressListeners().add((button) -> {
loadDataButton.setEnabled(false);
cancelButton.setEnabled(true);
loadData();
});
cancelButton.getButtonPressListeners().add((button) -> {
if (loadDataTask != null) {
loadDataTask.abort();
}
loadDataButton.setEnabled(true);
cancelButton.setEnabled(false);
});
clearButton.getButtonPressListeners().add((button) -> {
if (loadDataTask != null) {
loadDataTask.abort();
}
// empty the table
tableView.getTableData().clear();
statusLabel.setText("");
});
tableView.getTableViewSortListeners().add(new TableViewSortListener() {
@Override
public void sortChanged(TableView tableViewArgument) {
@SuppressWarnings("unchecked") List<Object> tableData = (List<Object>) tableViewArgument.getTableData();
long startTime = System.currentTimeMillis();
tableData.setComparator(new TableViewRowComparator(tableViewArgument));
long endTime = System.currentTimeMillis();
statusLabel.setText("Data sorted in " + (endTime - startTime) + " ms.");
}
});
window.open(display);
}
use of org.apache.pivot.wtk.ListButton in project pivot by apache.
the class SheetSlideDirectionWindow method initialize.
@Override
public void initialize(Map<String, Object> namespace, URL location, Resources resources) {
// Populate the ListButton with values from the enum
listButton.setListData(new ArrayList<>(SheetPlacement.values()));
listButton = null;
// Populate the form with data from the Sheet's styles
form.load(sheet.getStyles());
// Common ButtonPressListener to be applied to all four of
// the PushButtons representing a slide direction
ButtonPressListener openSheetButtonPressListener = new ButtonPressListener() {
@Override
public void buttonPressed(Button button) {
StyleDictionary sheetStyles = sheet.getStyles();
form.store(sheetStyles);
button.store(sheetStyles);
form.load(sheetStyles);
sheet.load(sheetStyles);
sheet.open(button.getWindow());
}
};
// Apply the common ButtonPressListener to the PushButtons
for (Iterator<Component> it = tablePane.iterator(); it.hasNext(); ) {
Component component = it.next();
if (component instanceof PushButton) {
PushButton button = (PushButton) component;
button.getButtonPressListeners().add(openSheetButtonPressListener);
button.setTooltipText("Press me!");
}
}
tablePane = null;
// Mouse handler to enable users to quickly close the sheet
final ContainerMouseListener displayMouseHandler = new ContainerMouseListener() {
@Override
public boolean mouseDown(Container container, Mouse.Button button, int x, int y) {
Display display = (Display) container;
Component component = display.getComponentAt(x, y);
// Close the sheet by clicking away from it.
// This allows resizing etc to work without requiring
// a close button or similar on the sheet.
boolean consumed = (component != sheet);
if (consumed) {
sheet.close();
}
return consumed;
}
};
// Add/remove the mouse handler based on the Sheet's state
sheet.getWindowStateListeners().add(new WindowStateListener() {
@Override
public void windowOpened(Window window) {
window.getDisplay().getContainerMouseListeners().add(displayMouseHandler);
}
@Override
public void windowClosed(Window window, Display display, Window owner) {
display.getContainerMouseListeners().remove(displayMouseHandler);
}
});
}
use of org.apache.pivot.wtk.ListButton in project pivot by apache.
the class TerraFileBrowserSkin method install.
@Override
public void install(Component component) {
super.install(component);
final FileBrowser fileBrowser = (FileBrowser) component;
BXMLSerializer bxmlSerializer = new BXMLSerializer();
try {
content = (Component) bxmlSerializer.readObject(TerraFileBrowserSkin.class, "terra_file_browser_skin.bxml", true);
} catch (IOException exception) {
throw new RuntimeException(exception);
} catch (SerializationException exception) {
throw new RuntimeException(exception);
}
fileBrowser.add(content);
bxmlSerializer.bind(this, TerraFileBrowserSkin.class);
driveListButton.getListButtonSelectionListeners().add(new ListButtonSelectionListener() {
@Override
public void selectedItemChanged(ListButton listButton, Object previousSelectedItem) {
if (previousSelectedItem != null) {
File drive = (File) listButton.getSelectedItem();
if (drive != null && drive.canRead()) {
if (!selectingDriveFromRootDirectory) {
fileBrowser.setRootDirectory(drive);
}
} else {
refreshRoots = true;
listButton.setSelectedItem(previousSelectedItem);
}
}
}
});
pathListButton.getListButtonSelectionListeners().add(new ListButtonSelectionListener() {
@Override
public void selectedItemChanged(ListButton listButton, Object previousSelectedItem) {
File ancestorDirectory = (File) listButton.getSelectedItem();
if (ancestorDirectory != null) {
fileBrowser.setRootDirectory(ancestorDirectory);
}
}
});
goUpButton.getButtonPressListeners().add(new ButtonPressListener() {
@Override
public void buttonPressed(Button button) {
File rootDirectory = fileBrowser.getRootDirectory();
File parentDirectory = rootDirectory.getParentFile();
fileBrowser.setRootDirectory(parentDirectory);
}
});
newFolderButton.getButtonPressListeners().add(new ButtonPressListener() {
@Override
public void buttonPressed(Button button) {
// TODO
}
});
goHomeButton.getButtonPressListeners().add(new ButtonPressListener() {
@Override
public void buttonPressed(Button button) {
fileBrowser.setRootDirectory(HOME_DIRECTORY);
}
});
/**
* {@link KeyCode#DOWN DOWN} Transfer focus to the file list and select
* the first item.<br> {@link KeyCode#ESCAPE ESCAPE} Clear the search
* field.
*/
searchTextInput.getComponentKeyListeners().add(new ComponentKeyListener() {
@Override
public boolean keyPressed(Component componentArgument, int keyCode, Keyboard.KeyLocation keyLocation) {
boolean consumed = false;
if (keyCode == Keyboard.KeyCode.ESCAPE) {
searchTextInput.setText("");
consumed = true;
} else if (keyCode == Keyboard.KeyCode.DOWN) {
if (fileTableView.getTableData().getLength() > 0) {
fileTableView.setSelectedIndex(0);
fileTableView.requestFocus();
}
}
return consumed;
}
});
searchTextInput.getTextInputContentListeners().add(new TextInputContentListener() {
@Override
public void textChanged(TextInput textInput) {
refreshFileList();
}
});
fileTableView.getTableViewSelectionListeners().add(new TableViewSelectionListener() {
@Override
public void selectedRangeAdded(TableView tableView, int rangeStart, int rangeEnd) {
if (!updatingSelection) {
updatingSelection = true;
for (int i = rangeStart; i <= rangeEnd; i++) {
@SuppressWarnings("unchecked") List<File> files = (List<File>) fileTableView.getTableData();
File file = files.get(i);
fileBrowser.addSelectedFile(file);
}
updatingSelection = false;
}
}
@Override
public void selectedRangeRemoved(TableView tableView, int rangeStart, int rangeEnd) {
if (!updatingSelection) {
updatingSelection = true;
for (int i = rangeStart; i <= rangeEnd; i++) {
@SuppressWarnings("unchecked") List<File> files = (List<File>) fileTableView.getTableData();
File file = files.get(i);
fileBrowser.removeSelectedFile(file);
}
updatingSelection = false;
}
}
@Override
public void selectedRangesChanged(TableView tableView, Sequence<Span> previousSelectedRanges) {
if (!updatingSelection && previousSelectedRanges != null) {
updatingSelection = true;
@SuppressWarnings("unchecked") Sequence<File> files = (Sequence<File>) tableView.getSelectedRows();
for (int i = 0, n = files.getLength(); i < n; i++) {
File file = files.get(i);
files.update(i, file);
}
fileBrowser.setSelectedFiles(files);
updatingSelection = false;
}
}
@Override
public void selectedRowChanged(TableView tableView, Object previousSelectedRow) {
// No-op
}
});
fileTableView.getTableViewSortListeners().add(new TableViewSortListener() {
@Override
public void sortChanged(TableView tableView) {
TableView.SortDictionary sort = fileTableView.getSort();
if (!sort.isEmpty()) {
Dictionary.Pair<String, SortDirection> pair = fileTableView.getSort().get(0);
@SuppressWarnings("unchecked") List<File> files = (List<File>) fileTableView.getTableData();
files.setComparator(getFileComparator(pair.key, pair.value));
}
}
});
fileTableView.getComponentMouseButtonListeners().add(new ComponentMouseButtonListener() {
private int index = -1;
@Override
public boolean mouseClick(Component componentArgument, Mouse.Button button, int x, int y, int count) {
boolean consumed = false;
if (count == 1) {
index = fileTableView.getRowAt(y);
} else if (count == 2) {
int indexLocal = fileTableView.getRowAt(y);
if (indexLocal != -1 && indexLocal == this.index && fileTableView.isRowSelected(indexLocal)) {
File file = (File) fileTableView.getTableData().get(indexLocal);
if (file.isDirectory()) {
fileBrowser.setRootDirectory(file);
consumed = true;
}
}
}
return consumed;
}
});
fileBrowser.setFocusTraversalPolicy(new IndexFocusTraversalPolicy() {
@Override
public Component getNextComponent(Container container, Component componentArgument, FocusTraversalDirection direction) {
Component nextComponent;
if (componentArgument == null) {
nextComponent = fileTableView;
} else {
nextComponent = super.getNextComponent(container, componentArgument, direction);
}
return nextComponent;
}
});
fileTableView.setSort(TableViewFileRenderer.NAME_KEY, SortDirection.ASCENDING);
fileTableView.getComponentTooltipListeners().add(new ComponentTooltipListener() {
@Override
public void tooltipTriggered(Component comp, int x, int y) {
// Check that we are on the first column.
if (fileTableView.getColumnAt(x) != 0) {
return;
}
// Gets the underlying file
int row = fileTableView.getRowAt(y);
if (row < 0) {
return;
}
File file = (File) fileTableView.getTableData().get(row);
// Construct and show the tooltip.
final Tooltip tooltip = new Tooltip();
String text = null;
if (file != null) {
text = file.getName();
}
if (text == null || text.isEmpty()) {
return;
}
TextArea toolTipTextArea = new TextArea();
toolTipTextArea.setText(text);
toolTipTextArea.getStyles().put(Style.wrapText, true);
toolTipTextArea.getStyles().put(Style.backgroundColor, null);
tooltip.setContent(toolTipTextArea);
Point location = comp.getDisplay().getMouseLocation();
x = location.x;
y = location.y;
// Ensure that the tooltip stays on screen
Display display = comp.getDisplay();
int tooltipHeight = tooltip.getPreferredHeight();
if (y + tooltipHeight > display.getHeight()) {
y -= tooltipHeight;
}
int tooltipXOffset = 16;
int padding = 15;
toolTipTextArea.setMaximumWidth(display.getWidth() - (x + tooltipXOffset + padding));
tooltip.setLocation(x + tooltipXOffset, y);
tooltip.open(comp.getWindow());
}
});
rootDirectoryChanged(fileBrowser, null);
selectedFilesChanged(fileBrowser, null);
}
use of org.apache.pivot.wtk.ListButton in project pivot by apache.
the class TerraListButtonSkin method paint.
@Override
public void paint(Graphics2D graphics) {
ListButton listButton = (ListButton) getComponent();
int width = getWidth();
int height = getHeight();
Color colorLocal = null;
Color backgroundColorLocal = null;
Color bevelColorLocal = null;
Color borderColorLocal = null;
if (listButton.isEnabled()) {
colorLocal = this.color;
backgroundColorLocal = this.backgroundColor;
bevelColorLocal = (pressed || (listViewPopup.isOpen() && !listViewPopup.isClosing())) ? pressedBevelColor : this.bevelColor;
borderColorLocal = this.borderColor;
} else {
colorLocal = disabledColor;
backgroundColorLocal = disabledBackgroundColor;
bevelColorLocal = disabledBevelColor;
borderColorLocal = disabledBorderColor;
}
graphics.setStroke(new BasicStroke());
// Paint the background
GraphicsUtilities.setAntialiasingOn(graphics);
if (!themeIsFlat()) {
graphics.setPaint(new GradientPaint(width / 2f, 0, bevelColorLocal, width / 2f, height / 2f, backgroundColorLocal));
} else {
graphics.setPaint(backgroundColorLocal);
}
graphics.fill(new RoundRectangle2D.Double(0.5, 0.5, width - 1, height - 1, CORNER_RADIUS, CORNER_RADIUS));
// Paint the content
GraphicsUtilities.setAntialiasingOff(graphics);
Bounds contentBounds = new Bounds(0, 0, Math.max(width - TRIGGER_WIDTH - 1, 0), Math.max(height - 1, 0));
Button.DataRenderer dataRenderer = listButton.getDataRenderer();
dataRenderer.render(listButton.getButtonData(), listButton, false);
dataRenderer.setSize(Math.max(contentBounds.width - (padding.getWidth() + 2) + 1, 0), Math.max(contentBounds.height - (padding.getHeight() + 2) + 1, 0));
Graphics2D contentGraphics = (Graphics2D) graphics.create();
contentGraphics.translate(padding.left + 1, padding.top + 1);
contentGraphics.clipRect(0, 0, dataRenderer.getWidth(), dataRenderer.getHeight());
dataRenderer.paint(contentGraphics);
contentGraphics.dispose();
GraphicsUtilities.setAntialiasingOn(graphics);
// Paint the border
if (!themeIsFlat()) {
graphics.setPaint(borderColorLocal);
graphics.setStroke(new BasicStroke(1));
graphics.draw(new RoundRectangle2D.Double(0.5, 0.5, width - 1, height - 1, CORNER_RADIUS, CORNER_RADIUS));
graphics.draw(new Line2D.Double(contentBounds.x + contentBounds.width, 0.5, contentBounds.x + contentBounds.width, contentBounds.height));
}
// Paint the focus state
if (listButton.isFocused()) {
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(borderColorLocal);
graphics.draw(new RoundRectangle2D.Double(2.5, 2.5, Math.max(contentBounds.width - 4, 0), Math.max(contentBounds.height - 4, 0), CORNER_RADIUS / 2, CORNER_RADIUS / 2));
}
GraphicsUtilities.setAntialiasingOff(graphics);
// Paint the trigger
GeneralPath triggerIconShape = new GeneralPath(Path2D.WIND_EVEN_ODD);
triggerIconShape.moveTo(0, 0);
triggerIconShape.lineTo(3, 3);
triggerIconShape.lineTo(6, 0);
triggerIconShape.closePath();
Graphics2D triggerGraphics = (Graphics2D) graphics.create();
triggerGraphics.setStroke(new BasicStroke(0));
triggerGraphics.setPaint(colorLocal);
Bounds triggerBounds = getTriggerBounds();
int tx = triggerBounds.x + Math.round((triggerBounds.width - triggerIconShape.getBounds().width) / 2f) - 1;
int ty = triggerBounds.y + Math.round((triggerBounds.height - triggerIconShape.getBounds().height) / 2f) - 1;
triggerGraphics.translate(tx, ty);
triggerGraphics.draw(triggerIconShape);
triggerGraphics.fill(triggerIconShape);
triggerGraphics.dispose();
// Paint the trigger highlight
if (listButton.isRepeatable()) {
Point mouseLocation = listButton.getMouseLocation();
if (mouseLocation != null) {
graphics.setPaint(new Color(0, 0, 0, 0.25f));
if (triggerBounds.contains(mouseLocation)) {
graphics.clipRect(triggerBounds.x, triggerBounds.y, triggerBounds.width, height);
} else {
graphics.clipRect(0, 0, width - triggerBounds.width, height);
}
GraphicsUtilities.setAntialiasingOn(graphics);
graphics.fill(new RoundRectangle2D.Double(0.5, 0.5, width - 1, height - 1, CORNER_RADIUS, CORNER_RADIUS));
GraphicsUtilities.setAntialiasingOff(graphics);
}
}
}
use of org.apache.pivot.wtk.ListButton in project pivot by apache.
the class TerraListButtonSkin method getBaseline.
@Override
public int getBaseline(int width, int height) {
ListButton listButton = (ListButton) getComponent();
Button.DataRenderer dataRenderer = listButton.getDataRenderer();
dataRenderer.render(listButton.getButtonData(), listButton, false);
int clientWidth = Math.max(width - (TRIGGER_WIDTH + padding.getWidth() + 2), 0);
int clientHeight = Math.max(height - (padding.getHeight() + 2), 0);
int baseline = dataRenderer.getBaseline(clientWidth, clientHeight);
if (baseline != -1) {
baseline += padding.top + 1;
}
return baseline;
}
Aggregations