use of org.apache.pivot.collections.ArrayList in project pivot by apache.
the class ShutdownTest method shutdown.
@Override
public boolean shutdown(boolean optional) {
System.out.println("shutdown()");
if (alert == null) {
ArrayList<String> options = new ArrayList<>();
options.add("Yes");
options.add("No");
alert = new Alert(MessageType.QUESTION, "Cancel shutdown?", options);
alert.setModal(false);
alert.open(display, new DialogCloseListener() {
@Override
public void dialogClosed(Dialog dialog, boolean modal) {
if (!(dialog instanceof Alert)) {
return;
}
Alert alertLocal = (Alert) dialog;
if (alertLocal.getResult()) {
if (alertLocal.getSelectedOptionIndex() == 1) {
cancelShutdown = false;
DesktopApplicationContext.exit();
}
}
ShutdownTest.this.alert = null;
}
});
}
return cancelShutdown;
}
use of org.apache.pivot.collections.ArrayList in project pivot by apache.
the class TerraTableViewSkin method layout.
@Override
public void layout() {
columnWidths = getColumnWidths((TableView) getComponent(), getWidth());
TableView tableView = (TableView) getComponent();
TableView.ColumnSequence columns = tableView.getColumns();
if (variableRowHeight) {
@SuppressWarnings("unchecked") List<Object> tableData = (List<Object>) tableView.getTableData();
int n = tableData.getLength();
rowBoundaries = new ArrayList<>(n);
int rowY = 0;
for (int i = 0; i < n; i++) {
Object rowData = tableData.get(i);
int rowHeight = 0;
for (int columnIndex = 0, columnCount = columns.getLength(); columnIndex < columnCount; columnIndex++) {
TableView.Column column = columns.get(columnIndex);
TableView.CellRenderer cellRenderer = column.getCellRenderer();
int columnWidth = columnWidths.get(columnIndex).intValue();
cellRenderer.render(rowData, i, columnIndex, tableView, column.getName(), false, false, false);
rowHeight = Math.max(rowHeight, cellRenderer.getPreferredHeight(columnWidth));
}
rowY += rowHeight;
rowBoundaries.add(Integer.valueOf(rowY));
rowY++;
}
} else {
fixedRowHeight = calculateFixedRowHeight(tableView);
}
if (validateSelection) {
// Ensure that the selection is visible
Sequence<Span> selectedRanges = tableView.getSelectedRanges();
if (selectedRanges.getLength() > 0) {
int rangeStart = selectedRanges.get(0).start;
int rangeEnd = selectedRanges.get(selectedRanges.getLength() - 1).end;
Bounds selectionBounds = getRowBounds(rangeStart);
selectionBounds = selectionBounds.union(getRowBounds(rangeEnd));
Bounds visibleSelectionBounds = tableView.getVisibleArea(selectionBounds);
if (visibleSelectionBounds != null && visibleSelectionBounds.height < selectionBounds.height) {
tableView.scrollAreaToVisible(selectionBounds);
}
}
}
validateSelection = false;
}
use of org.apache.pivot.collections.ArrayList in project pivot by apache.
the class TerraTableViewSkin method getBaseline.
@Override
public int getBaseline(int width, int height) {
TableView tableView = (TableView) getComponent();
@SuppressWarnings("unchecked") List<Object> tableData = (List<Object>) tableView.getTableData();
int baseline = -1;
TableView.ColumnSequence columns = tableView.getColumns();
ArrayList<Integer> columnWidthsLocal = getColumnWidths(tableView, width);
if (variableRowHeight) {
int rowHeight = getVariableRowHeight(0, columnWidthsLocal);
Object rowData = tableData.get(0);
for (int i = 0, n = columns.getLength(); i < n; i++) {
TableView.Column column = columns.get(i);
TableView.CellRenderer cellRenderer = column.getCellRenderer();
cellRenderer.render(rowData, 0, i, tableView, column.getName(), false, false, false);
baseline = Math.max(baseline, cellRenderer.getBaseline(columnWidthsLocal.get(i).intValue(), rowHeight));
}
} else {
int rowHeight = calculateFixedRowHeight(tableView);
for (int i = 0, n = columns.getLength(); i < n; i++) {
TableView.Column column = columns.get(i);
TableView.CellRenderer cellRenderer = column.getCellRenderer();
cellRenderer.render(null, -1, i, tableView, column.getName(), false, false, false);
baseline = Math.max(baseline, cellRenderer.getBaseline(columnWidthsLocal.get(i).intValue(), rowHeight));
}
}
return baseline;
}
use of org.apache.pivot.collections.ArrayList in project pivot by apache.
the class TerraTreeViewSkin method showMixedCheckmarkStateChanged.
@Override
public void showMixedCheckmarkStateChanged(TreeView treeView) {
if (treeView.getCheckmarksEnabled()) {
// The check state of all *branch* nodes may have changed, so we
// need to update the cached check state of all BranchNode
// instances in our hierarchy
Sequence<NodeInfo> nodes = new ArrayList<>();
nodes.add(rootBranchInfo);
while (nodes.getLength() > 0) {
NodeInfo nodeInfo = nodes.get(0);
nodes.remove(0, 1);
// Only branch nodes can be affected by this event
if (nodeInfo instanceof BranchInfo) {
BranchInfo branchInfo = (BranchInfo) nodeInfo;
// Update the cached entry for this branch
Path path = branchInfo.getPath();
branchInfo.setCheckState(treeView.getNodeCheckState(path));
// Add the branch's children to the queue
if (branchInfo.children != null) {
for (int i = 0, n = branchInfo.children.getLength(); i < n; i++) {
nodes.insert(branchInfo.children.get(i), i);
}
}
}
}
repaintComponent();
}
}
use of org.apache.pivot.collections.ArrayList in project pivot by apache.
the class TerraVFSBrowserSheetSkin method previewSheetClose.
@Override
public Vote previewSheetClose(final Sheet sheet, final boolean result) {
Vote vote = null;
if (result && !okButton.isEnabled()) {
vote = Vote.DENY;
} else {
if (result) {
updatingSelection = true;
VFSBrowserSheet fileBrowserSheet = (VFSBrowserSheet) sheet;
VFSBrowserSheet.Mode mode = fileBrowserSheet.getMode();
FileSystemManager manager = fileBrowserSheet.getManager();
FileName baseFileName = fileBrowserSheet.getBaseFileName();
switch(mode) {
case OPEN:
case OPEN_MULTIPLE:
case SAVE_TO:
{
try {
fileBrowserSheet.setSelectedFiles(fileBrowser.getSelectedFiles());
} catch (FileSystemException fse) {
throw new RuntimeException(fse);
}
break;
}
case SAVE_AS:
{
String fileName = saveAsTextInput.getText();
// current location and let the chips fall ...
try {
FileObject selectedFile = manager.resolveFile(fileBrowser.getRootDirectory(), fileName);
// !fileName.startsWith(File.separator)) {
if (selectedFile.exists() && selectedFile.getType() == FileType.FOLDER) {
try {
// TODO: what to do about canonical file representations?
FileObject root = /* selectedFile.getCanonicalFile(); */
selectedFile;
fileBrowserSheet.setRootDirectory(root);
fileBrowser.setRootDirectory(root);
setHostLabel(root);
saveAsTextInput.setText("");
} catch (IOException ioe) {
Form.setFlag(saveAsBoxPane, new Form.Flag());
}
selectedFile = null;
vote = Vote.DENY;
} else {
FileObject root = selectedFile.getParent();
if (root != null && root.exists() && root.getType() == FileType.FOLDER) {
try {
// TODO: canonical file again
// fileBrowserSheet.setRootDirectory(root.getCanonicalFile());
fileBrowserSheet.setRootDirectory(root);
setHostLabel(root);
selectedFile = manager.resolveFile(selectedFile.getName().getURI());
} catch (IOException ioe) {
Form.setFlag(saveAsBoxPane, new Form.Flag());
selectedFile = null;
vote = Vote.DENY;
}
} else {
// Could be an error message here
// ("Directory does not exist")
Form.setFlag(saveAsBoxPane, new Form.Flag());
selectedFile = null;
vote = Vote.DENY;
}
}
if (selectedFile != null) {
fileBrowserSheet.setSelectedFiles(new ArrayList<>(selectedFile));
}
} catch (FileSystemException fse) {
Form.setFlag(saveAsBoxPane, new Form.Flag());
vote = Vote.DENY;
}
break;
}
default:
break;
}
updatingSelection = false;
}
if (vote == null) {
vote = super.previewSheetClose(sheet, result);
}
}
return vote;
}
Aggregations