use of org.apache.pivot.wtk.ComponentMouseButtonListener in project pivot by apache.
the class ComponentExplorerWindow method initialize.
@Override
public void initialize(Map<String, Object> namespace, URL location, Resources resources) {
splitPane = (SplitPane) namespace.get("splitPane");
treeView = (TreeView) namespace.get("treeView");
contentScrollPane = (ScrollPane) namespace.get("contentScrollPane");
contentPane = (Border) namespace.get("contentPane");
sourceTextArea = (TextArea) namespace.get("sourceTextArea");
componentPropertyInspector = (ComponentPropertyInspector) namespace.get("componentPropertyInspector");
componentStyleInspector = (ComponentStyleInspector) namespace.get("componentStyleInspector");
eventLogger = (EventLogger) namespace.get("eventLogger");
horizontalScrollBarPolicyGroup = (ButtonGroup) namespace.get("horizontalScrollBarPolicyGroup");
verticalScrollBarPolicyGroup = (ButtonGroup) namespace.get("verticalScrollBarPolicyGroup");
horizontalAutoButton = (Button) namespace.get("horizontalAutoButton");
horizontalFillButton = (Button) namespace.get("horizontalFillButton");
horizontalFillToCapacityButton = (Button) namespace.get("horizontalFillToCapacityButton");
horizontalNeverButton = (Button) namespace.get("horizontalNeverButton");
horizontalAlwaysButton = (Button) namespace.get("horizontalAlwaysButton");
verticalAutoButton = (Button) namespace.get("verticalAutoButton");
verticalFillButton = (Button) namespace.get("verticalFillButton");
verticalFillToCapacityButton = (Button) namespace.get("verticalFillToCapacityButton");
verticalNeverButton = (Button) namespace.get("verticalNeverButton");
verticalAlwaysButton = (Button) namespace.get("verticalAlwaysButton");
treeView.getTreeViewSelectionListeners().add(new TreeViewSelectionListener() {
@Override
public void selectedPathsChanged(TreeView treeViewArgument, Sequence<Path> previousSelectedPaths) {
Component component = null;
Object node = treeViewArgument.getSelectedNode();
if (node instanceof ComponentNode) {
ComponentNode componentNode = (ComponentNode) node;
URL url = componentNode.getSrc();
try {
sourceTextArea.setText(url);
} catch (IOException exception) {
throw new RuntimeException(exception);
}
BXMLSerializer bxmlSerializer = new BXMLSerializer();
try {
component = (Component) bxmlSerializer.readObject(url);
} catch (IOException exception) {
throw new RuntimeException(exception);
} catch (SerializationException exception) {
throw new RuntimeException(exception);
}
switch(componentNode.getHorizontalScrollBarPolicy()) {
case AUTO:
horizontalScrollBarPolicyGroup.setSelection(horizontalAutoButton);
break;
case FILL:
horizontalScrollBarPolicyGroup.setSelection(horizontalFillButton);
break;
case FILL_TO_CAPACITY:
horizontalScrollBarPolicyGroup.setSelection(horizontalFillToCapacityButton);
break;
case NEVER:
horizontalScrollBarPolicyGroup.setSelection(horizontalNeverButton);
break;
case ALWAYS:
horizontalScrollBarPolicyGroup.setSelection(horizontalAlwaysButton);
break;
default:
break;
}
switch(componentNode.getVerticalScrollBarPolicy()) {
case AUTO:
verticalScrollBarPolicyGroup.setSelection(verticalAutoButton);
break;
case FILL:
verticalScrollBarPolicyGroup.setSelection(verticalFillButton);
break;
case FILL_TO_CAPACITY:
verticalScrollBarPolicyGroup.setSelection(verticalFillToCapacityButton);
break;
case NEVER:
verticalScrollBarPolicyGroup.setSelection(verticalNeverButton);
break;
case ALWAYS:
verticalScrollBarPolicyGroup.setSelection(verticalAlwaysButton);
break;
default:
break;
}
} else {
sourceTextArea.setText("");
}
contentPane.setContent(component);
componentPropertyInspector.setSource(component);
componentStyleInspector.setSource(component);
eventLogger.setSource(component);
eventLogger.clearLog();
}
});
treeView.getComponentMouseButtonListeners().add(new ComponentMouseButtonListener() {
@Override
public boolean mouseClick(Component component, Mouse.Button button, int x, int y, int count) {
if (button == Mouse.Button.LEFT && count == 2) {
Path path = treeView.getNodeAt(y);
if (path != null) {
List<?> treeData = treeView.getTreeData();
Object node = Tree.get(treeData, path);
if (node instanceof List<?>) {
treeView.setBranchExpanded(path, !treeView.isBranchExpanded(path));
}
}
}
return false;
}
});
horizontalScrollBarPolicyGroup.getButtonGroupListeners().add(new ButtonGroupListener() {
@Override
public void selectionChanged(ButtonGroup buttonGroup, Button previousSelection) {
Button button = buttonGroup.getSelection();
ScrollBarPolicy horizontalScrollBarPolicy = null;
if (button == horizontalAutoButton) {
horizontalScrollBarPolicy = ScrollBarPolicy.AUTO;
} else if (button == horizontalFillButton) {
horizontalScrollBarPolicy = ScrollBarPolicy.FILL;
} else if (button == horizontalFillToCapacityButton) {
horizontalScrollBarPolicy = ScrollBarPolicy.FILL_TO_CAPACITY;
} else if (button == horizontalNeverButton) {
horizontalScrollBarPolicy = ScrollBarPolicy.NEVER;
} else if (button == horizontalAlwaysButton) {
horizontalScrollBarPolicy = ScrollBarPolicy.ALWAYS;
}
if (horizontalScrollBarPolicy != null) {
contentScrollPane.setHorizontalScrollBarPolicy(horizontalScrollBarPolicy);
}
}
});
verticalScrollBarPolicyGroup.getButtonGroupListeners().add(new ButtonGroupListener() {
@Override
public void selectionChanged(ButtonGroup buttonGroup, Button previousSelection) {
Button button = buttonGroup.getSelection();
ScrollBarPolicy verticalScrollBarPolicy = null;
if (button == verticalAutoButton) {
verticalScrollBarPolicy = ScrollBarPolicy.AUTO;
} else if (button == verticalFillButton) {
verticalScrollBarPolicy = ScrollBarPolicy.FILL;
} else if (button == verticalFillToCapacityButton) {
verticalScrollBarPolicy = ScrollBarPolicy.FILL_TO_CAPACITY;
} else if (button == verticalNeverButton) {
verticalScrollBarPolicy = ScrollBarPolicy.NEVER;
} else if (button == verticalAlwaysButton) {
verticalScrollBarPolicy = ScrollBarPolicy.ALWAYS;
}
if (verticalScrollBarPolicy != null) {
contentScrollPane.setVerticalScrollBarPolicy(verticalScrollBarPolicy);
}
}
});
}
use of org.apache.pivot.wtk.ComponentMouseButtonListener in project pivot by apache.
the class Pivot811 method startup.
@Override
public void startup(final Display displayArgument, Map<String, String> properties) throws Exception {
this.display = displayArgument;
Frame listFrame = new Frame();
listFrame.setTitle("List Frame");
listFrame.setPreferredSize(400, 300);
listFrame.setLocation(20, 20);
listFrame.getStyles().put(Style.padding, Insets.NONE);
BoxPane boxPane = new BoxPane();
boxPane.getStyles().put(Style.fill, true);
boxPane.setOrientation(Orientation.VERTICAL);
listFrame.setContent(boxPane);
Label infoLabel = new Label("Double click on a list item to open a detail frame");
boxPane.add(infoLabel);
ScrollPane scrollPane = new ScrollPane();
scrollPane.setHorizontalScrollBarPolicy(ScrollBarPolicy.FILL);
scrollPane.setVerticalScrollBarPolicy(ScrollBarPolicy.FILL_TO_CAPACITY);
// workaround for pivot-738,
scrollPane.setRepaintAllViewport(true);
// needed only in in some cases
boxPane.add(scrollPane);
final ListView listView = new ListView();
List<String> listData = new ArrayList<>();
for (int i = 0; i < 50; ++i) {
listData.add("List Item " + i);
}
listView.setListData(listData);
scrollPane.setView(listView);
listView.getListViewSelectionListeners().add(new ListViewSelectionListener() {
@Override
public void selectedItemChanged(ListView listViewArgument, Object previousSelectedItem) {
System.out.println("selectedItemChanged : " + listViewArgument.getSelectedItem());
}
});
listView.getComponentMouseButtonListeners().add(new ComponentMouseButtonListener() {
@Override
public boolean mouseClick(Component component, Mouse.Button button, int x, int y, int count) {
System.out.println("mouseClick : " + count);
if (count == 2) {
System.out.println("double click, now open a detail frame");
Frame detailFrame = new Frame();
detailFrame.setTitle("Detail Frame");
detailFrame.setPreferredSize(400, 300);
int selectedIndex = listView.getSelectedIndex();
detailFrame.setLocation(80 + (selectedIndex * 10), 80 + (selectedIndex * 10));
detailFrame.getStyles().put(Style.padding, Insets.NONE);
BoxPane boxPaneLocal = new BoxPane();
boxPaneLocal.getStyles().put(Style.fill, true);
boxPaneLocal.setOrientation(Orientation.VERTICAL);
detailFrame.setContent(boxPaneLocal);
String selectedItem = listView.getSelectedItem().toString();
Label label = new Label("Selected Item is \"" + selectedItem + "\"");
boxPaneLocal.add(label);
// spacer
boxPaneLocal.add(new Label(""));
boxPaneLocal.add(new Label("Click inside the text input to focus it"));
TextInput textInput = new TextInput();
textInput.setText("Focusable component");
// workaround for pivot-811:
boxPaneLocal.add(textInput);
// add a focusable element
// inside the frame
detailFrame.open(displayArgument);
// workaround for pivot-811: force the focus on the first
// focusable element inside the frame
detailFrame.requestFocus();
// textInput.requestFocus(); // or use this ...
}
return true;
}
});
listFrame.open(displayArgument);
listView.setSelectedIndex(0);
listView.requestFocus();
}
use of org.apache.pivot.wtk.ComponentMouseButtonListener in project pivot by apache.
the class TerraFileBrowserSheetSkin method install.
@Override
public void install(Component component) {
super.install(component);
final FileBrowserSheet fileBrowserSheet = (FileBrowserSheet) component;
fileBrowserSheet.setMinimumWidth(360);
fileBrowserSheet.setMinimumHeight(180);
// Load the sheet content
BXMLSerializer bxmlSerializer = new BXMLSerializer();
Component content;
try {
content = (Component) bxmlSerializer.readObject(TerraFileBrowserSheetSkin.class, "terra_file_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, TerraFileBrowserSheetSkin.class);
// set the same rootDirectory to fileBrowser
fileBrowser.setRootDirectory(fileBrowserSheet.getRootDirectory());
saveAsTextInput.getTextInputContentListeners().add(new TextInputContentListener() {
@Override
public void textChanged(TextInput textInput) {
Form.clearFlag(saveAsBoxPane);
updateOKButtonState();
}
});
fileBrowser.getFileBrowserListeners().add(new FileBrowserListener() {
@Override
public void rootDirectoryChanged(FileBrowser fileBrowserArgument, File previousRootDirectory) {
updatingSelection = true;
fileBrowserSheet.setRootDirectory(fileBrowserArgument.getRootDirectory());
updatingSelection = false;
selectedDirectoryCount = 0;
updateOKButtonState();
}
@Override
public void selectedFileAdded(FileBrowser fileBrowserArgument, File file) {
if (file.isDirectory()) {
selectedDirectoryCount++;
}
updateOKButtonState();
}
@Override
public void selectedFileRemoved(FileBrowser fileBrowserArgument, File file) {
if (file.isDirectory()) {
selectedDirectoryCount--;
}
updateOKButtonState();
}
@Override
public void selectedFilesChanged(FileBrowser fileBrowserArgument, Sequence<File> previousSelectedFiles) {
selectedDirectoryCount = 0;
Sequence<File> selectedFiles = fileBrowserArgument.getSelectedFiles();
for (int i = 0, n = selectedFiles.getLength(); i < n; i++) {
File selectedFile = selectedFiles.get(i);
if (selectedFile.isDirectory()) {
selectedDirectoryCount++;
}
}
if (!fileBrowserArgument.isMultiSelect()) {
File selectedFile = fileBrowserArgument.getSelectedFile();
if (selectedFile != null && !selectedFile.isDirectory()) {
saveAsTextInput.setText(selectedFile.getName());
}
}
updateOKButtonState();
}
});
fileBrowser.getComponentMouseButtonListeners().add(new ComponentMouseButtonListener() {
private File file = null;
@Override
public boolean mouseClick(Component componentArgument, Mouse.Button button, int x, int y, int count) {
boolean consumed = false;
FileBrowserSheet.Mode mode = fileBrowserSheet.getMode();
if (count == 1) {
file = fileBrowser.getFileAt(x, y);
} else if (count == 2) {
File fileLocal = fileBrowser.getFileAt(x, y);
if (fileLocal != null && this.file != null && fileLocal.equals(this.file) && fileBrowser.isFileSelected(fileLocal)) {
if (mode == FileBrowserSheet.Mode.OPEN || mode == FileBrowserSheet.Mode.OPEN_MULTIPLE) {
if (!fileLocal.isDirectory()) {
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);
rootDirectoryChanged(fileBrowserSheet, null);
selectedFilesChanged(fileBrowserSheet, null);
}
use of org.apache.pivot.wtk.ComponentMouseButtonListener 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.ComponentMouseButtonListener in project pivot by apache.
the class Pivot951 method startup.
@Override
public void startup(Display display, Map<String, String> properties) {
window = new Window();
Border brd = new Border();
brd.getComponentMouseButtonListeners().add(new ComponentMouseButtonListener() {
@Override
public boolean mouseClick(Component component, Button button, int x, int y, int count) {
if (count == 1) {
System.out.println("Click!");
} else {
System.out.println("Double Click!");
}
return true;
}
});
window.setContent(brd);
window.setTitle("Pivot951: Cannot click twice");
window.setMaximized(true);
window.open(display);
}
Aggregations