use of org.apache.pivot.wtk.Span in project pivot by apache.
the class TerraVFSBrowserSkin method updateSelectedFiles.
private void updateSelectedFiles(VFSBrowser fileBrowser) {
if (!updatingSelection) {
Sequence<FileObject> selectedFiles = fileBrowser.getSelectedFiles();
ArrayList<Span> selectedRanges = new ArrayList<>();
for (int i = 0, n = selectedFiles.getLength(); i < n; i++) {
FileObject selectedFile = selectedFiles.get(i);
@SuppressWarnings("unchecked") List<FileObject> files = (List<FileObject>) fileTableView.getTableData();
int index = files.indexOf(selectedFile);
if (index != -1) {
selectedRanges.add(new Span(index, index));
}
}
updatingSelection = true;
fileTableView.setSelectedRanges(selectedRanges);
updatingSelection = false;
}
}
use of org.apache.pivot.wtk.Span in project pivot by apache.
the class SpanTest method test.
@Test
public void test() {
Span spMinus1 = new Span(-1, 0);
Span sp0 = new Span(0);
Span sp1 = new Span(0, 1);
Span sp2 = Span.decode("[1, 0]");
Span sp3 = Span.decode("{start:2, end:3}");
Span sp3a = new Span(2, 3);
Span sp4 = new Span(4);
Span sp5 = sp3a.offset(1);
Span sp5a = new Span(3, 4);
Span sp5b = new Span(4, 3);
Span spN = new Span(0, 4);
Span spAll = sp1.union(sp0).union(sp2).union(sp3).union(sp4);
Span sp6 = Span.decode("4, 6");
Span sp6a = new Span(4, 6);
assertEquals(spMinus1.getLength(), 2);
assertEquals(sp0.getLength(), 1);
assertTrue(sp1.contains(sp0));
assertTrue(spMinus1.intersects(sp0));
assertTrue(sp0.intersects(sp1));
assertEquals(sp0.intersect(sp1), sp0);
assertTrue(sp5b.intersects(sp3a));
assertTrue(sp0.union(sp1).equals(sp1));
assertFalse(sp0.equals(sp1));
assertTrue(sp1.equals(sp2.normalize()));
assertEquals(sp3, sp3a);
assertFalse(sp0.adjacentTo(sp2));
assertTrue(sp1.adjacentTo(sp3));
assertTrue(sp3.adjacentTo(sp1));
assertTrue(sp4.adjacentTo(sp3a));
assertTrue(sp3.adjacentTo(sp4));
assertTrue(sp5.equals(sp5a));
assertEquals(spN, spAll);
assertEquals(sp2.normalStart(), 0);
assertEquals(sp2.normalEnd(), 1);
assertTrue(sp5a.normalEquals(sp5b));
assertTrue(sp4.after(sp1));
assertTrue(sp3a.before(sp4));
assertEquals(sp6, sp6a);
assertEquals(sp6.getLength(), 3);
assertEquals(sp6.toString(), "Span {start:4, end:6}");
}
use of org.apache.pivot.wtk.Span in project pivot by apache.
the class TerraFileBrowserSkin method updateSelectedFiles.
private void updateSelectedFiles(FileBrowser fileBrowser) {
if (!updatingSelection) {
Sequence<File> selectedFiles = fileBrowser.getSelectedFiles();
ArrayList<Span> selectedRanges = new ArrayList<>();
for (int i = 0, n = selectedFiles.getLength(); i < n; i++) {
File selectedFile = selectedFiles.get(i);
@SuppressWarnings("unchecked") List<File> files = (List<File>) fileTableView.getTableData();
int index = files.indexOf(selectedFile);
if (index != -1) {
selectedRanges.add(new Span(index, index));
}
}
updatingSelection = true;
fileTableView.setSelectedRanges(selectedRanges);
updatingSelection = false;
}
}
use of org.apache.pivot.wtk.Span 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.Span in project pivot by apache.
the class Pivot718 method controlList.
private void controlList(BXMLSerializer bxmlSerializer) {
listDelButton = (PushButton) bxmlSerializer.getNamespace().get("listDelButton");
list = (ListView) bxmlSerializer.getNamespace().get("list");
list.getListViewSelectionListeners().add(new ListViewSelectionListener() {
@Override
public void selectedRangeAdded(ListView listView, int rangeStart, int rangeEnd) {
System.out.println("selectedRangeAdded");
}
@Override
public void selectedRangeRemoved(ListView listView, int rangeStart, int rangeEnd) {
System.out.println("selectedRangeRemoved");
}
@Override
public void selectedRangesChanged(ListView listView, Sequence<Span> previousSelectedRanges) {
System.out.println("selectedRangesChanged");
}
@Override
public void selectedItemChanged(ListView listView, Object previousSelectedItem) {
System.out.println("selectedItemChanged :::" + listView.getSelectedItem());
}
});
listDelButton.getButtonPressListeners().add(new ButtonPressListener() {
@Override
public void buttonPressed(Button button) {
Object x = list.getSelectedItem();
System.out.println("delete :: " + x);
// List data = list.getListData();
@SuppressWarnings("unchecked") List<Object> data = (List<Object>) list.getListData();
data.remove(x);
}
});
}
Aggregations