use of org.apache.pivot.collections.ArrayList in project pivot by apache.
the class TerraTableViewSkin method mouseDown.
@Override
public boolean mouseDown(Component component, Mouse.Button button, int x, int y) {
boolean consumed = super.mouseDown(component, button, x, y);
TableView tableView = (TableView) getComponent();
int rowIndex = getRowAt(y);
if (rowIndex >= 0 && !tableView.isRowDisabled(rowIndex)) {
TableView.SelectMode selectMode = tableView.getSelectMode();
if (button == Mouse.Button.LEFT) {
Keyboard.Modifier commandModifier = Platform.getCommandModifier();
if (Keyboard.isPressed(Keyboard.Modifier.SHIFT) && selectMode == TableView.SelectMode.MULTI) {
Filter<?> disabledRowFilter = tableView.getDisabledRowFilter();
if (disabledRowFilter == null) {
// Select the range
int startIndex = tableView.getFirstSelectedIndex();
int endIndex = tableView.getLastSelectedIndex();
// indicated row
if (startIndex == -1) {
tableView.addSelectedIndex(rowIndex);
} else {
// otherwise select the range of rows
Span selectedRange = (rowIndex > startIndex) ? new Span(startIndex, rowIndex) : new Span(rowIndex, endIndex);
ArrayList<Span> selectedRanges = new ArrayList<>();
selectedRanges.add(selectedRange);
tableView.setSelectedRanges(selectedRanges);
}
}
} else if (Keyboard.isPressed(commandModifier) && selectMode == TableView.SelectMode.MULTI) {
// Toggle the item's selection state
if (tableView.isRowSelected(rowIndex)) {
tableView.removeSelectedIndex(rowIndex);
} else {
tableView.addSelectedIndex(rowIndex);
}
} else if (Keyboard.isPressed(commandModifier) && selectMode == TableView.SelectMode.SINGLE) {
// Toggle the item's selection state
if (tableView.isRowSelected(rowIndex)) {
tableView.setSelectedIndex(-1);
} else {
tableView.setSelectedIndex(rowIndex);
}
} else {
if (selectMode != TableView.SelectMode.NONE) {
if (!tableView.isRowSelected(rowIndex)) {
tableView.setSelectedIndex(rowIndex);
}
selectIndex = rowIndex;
}
}
}
}
tableView.requestFocus();
if (editOnMouseDown) {
if (selectIndex != -1 && button == Mouse.Button.LEFT) {
TableView.RowEditor rowEditor = tableView.getRowEditor();
if (rowEditor != null) {
if (rowEditor.isEditing()) {
rowEditor.endEdit(true);
}
rowEditor.beginEdit(tableView, selectIndex, getColumnAt(x));
}
}
}
return consumed;
}
use of org.apache.pivot.collections.ArrayList in project pivot by apache.
the class TerraTheme method load.
private void load(URL location) {
Utils.checkNull(location, "location");
try (InputStream inputStream = location.openStream()) {
JSONSerializer serializer = new JSONSerializer();
@SuppressWarnings("unchecked") Map<String, ?> properties = (Map<String, ?>) serializer.readObject(inputStream);
font = Font.decode((String) properties.get(FONT_PROPERTY));
String defaultStylesName = (String) properties.get(DEFAULT_STYLES_PROPERTY);
if (defaultStylesName != null && !defaultStylesName.isEmpty()) {
defaultStylesFile = defaultStylesName;
}
String namedStylesName = (String) properties.get(NAMED_STYLES_PROPERTY);
if (namedStylesName != null && !namedStylesName.isEmpty()) {
namedStylesFile = namedStylesName;
}
@SuppressWarnings("unchecked") List<String> colorCodes = (List<String>) properties.get(COLORS_PROPERTY);
numberOfPaletteColors = colorCodes.getLength();
int numberOfColors = numberOfPaletteColors * 3;
colors = new ArrayList<>(numberOfColors);
Double mult = (Double) properties.get(COLOR_MULTIPLIER_PROPERTY);
if (mult != null) {
colorMultiplier = mult.floatValue();
}
themeIsDark = properties.getBoolean(THEME_IS_DARK_PROPERTY, false);
themeIsFlat = properties.getBoolean(THEME_IS_FLAT_PROPERTY, false);
transitionEnabled = properties.getBoolean(TRANSITION_ENABLED_PROPERTY, true);
for (String colorCode : colorCodes) {
Color baseColor = GraphicsUtilities.decodeColor(colorCode, "baseColor");
colors.add(darken(baseColor));
colors.add(baseColor);
colors.add(brighten(baseColor));
}
@SuppressWarnings("unchecked") Map<String, String> messageIconNames = (Map<String, String>) properties.get(MESSAGE_ICONS_PROPERTY);
messageIcons = new HashMap<>();
loadMessageIcons(messageIconNames, messageIcons);
@SuppressWarnings("unchecked") Map<String, String> smallMessageIconNames = (Map<String, String>) properties.get(SMALL_MESSAGE_ICONS_PROPERTY);
smallMessageIcons = new HashMap<>();
loadMessageIcons(smallMessageIconNames, smallMessageIcons);
if ((defaultBackgroundColor = getColorProperty(properties, DEFAULT_BACKGROUND_COLOR_PROPERTY)) == null) {
defaultBackgroundColor = super.getDefaultBackgroundColor();
}
if ((defaultForegroundColor = getColorProperty(properties, DEFAULT_FOREGROUND_COLOR_PROPERTY)) == null) {
defaultForegroundColor = super.getDefaultForegroundColor();
}
} catch (IOException exception) {
throw new RuntimeException(exception);
} catch (SerializationException exception) {
throw new RuntimeException(exception);
}
}
use of org.apache.pivot.collections.ArrayList in project pivot by apache.
the class TerraFileBrowserSheetSkin 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;
FileBrowserSheet fileBrowserSheet = (FileBrowserSheet) sheet;
FileBrowserSheet.Mode mode = fileBrowserSheet.getMode();
switch(mode) {
case OPEN:
case OPEN_MULTIPLE:
case SAVE_TO:
{
fileBrowserSheet.setSelectedFiles(fileBrowser.getSelectedFiles());
break;
}
case SAVE_AS:
{
String fileName = saveAsTextInput.getText();
// Contents of the entry field could be:
// 1. Just a new file name in the current root directory
// 2. A relative or absolute path that is an existing directory
// to navigate to
// 3. A relative or absolute path including the new file name
// in an existing directory
// So, first make it an absolute path
File selectedFile = new File(fileName);
if (!selectedFile.isAbsolute() && !fileName.startsWith(File.separator)) {
selectedFile = new File(fileBrowser.getRootDirectory(), fileName);
} else {
selectedFile = selectedFile.getAbsoluteFile();
}
if (selectedFile.exists() && selectedFile.isDirectory()) {
try {
File root = selectedFile.getCanonicalFile();
fileBrowserSheet.setRootDirectory(root);
fileBrowser.setRootDirectory(root);
saveAsTextInput.setText("");
} catch (IOException ioe) {
Form.setFlag(saveAsBoxPane, new Form.Flag());
}
selectedFile = null;
vote = Vote.DENY;
} else {
File root = selectedFile.getParentFile();
if (root != null && root.exists() && root.isDirectory()) {
try {
fileBrowserSheet.setRootDirectory(root.getCanonicalFile());
selectedFile = new File(selectedFile.getName());
} 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));
}
break;
}
default:
{
break;
}
}
updatingSelection = false;
}
if (vote == null) {
vote = super.previewSheetClose(sheet, result);
}
}
return vote;
}
use of org.apache.pivot.collections.ArrayList in project pivot by apache.
the class TerraFileBrowserSkin method rootDirectoryChanged.
@Override
public void rootDirectoryChanged(FileBrowser fileBrowser, File previousRootDirectory) {
ArrayList<File> path = new ArrayList<>();
File rootDirectory = fileBrowser.getRootDirectory();
File ancestorDirectory = rootDirectory.getParentFile();
while (ancestorDirectory != null) {
path.add(ancestorDirectory);
ancestorDirectory = ancestorDirectory.getParentFile();
}
@SuppressWarnings("unchecked") ArrayList<File> drives = (ArrayList<File>) driveListButton.getListData();
if (refreshRoots) {
File[] roots = File.listRoots();
drives = new ArrayList<>();
for (int i = 0; i < roots.length; i++) {
File root = roots[i];
if (root.exists()) {
drives.add(root);
}
}
driveListButton.setListData(drives);
refreshRoots = false;
}
driveListButton.setVisible(drives.getLength() > 1);
File drive;
if (path.getLength() == 0) {
drive = rootDirectory;
} else {
drive = path.get(path.getLength() - 1);
}
selectingDriveFromRootDirectory = true;
driveListButton.setSelectedItem(drive);
selectingDriveFromRootDirectory = false;
pathListButton.setListData(path);
pathListButton.setButtonData(rootDirectory);
pathListButton.setEnabled(rootDirectory.getParentFile() != null);
goUpButton.setEnabled(pathListButton.isEnabled());
goHomeButton.setEnabled(!rootDirectory.equals(HOME_DIRECTORY));
fileScrollPane.setScrollTop(0);
fileScrollPane.setScrollLeft(0);
searchTextInput.setText("");
fileTableView.requestFocus();
}
use of org.apache.pivot.collections.ArrayList in project pivot by apache.
the class TerraFormSkin method insertSection.
private void insertSection(Form.Section section, int index) {
Form form = (Form) getComponent();
// Insert separator
Separator separator = new Separator(section.getHeading());
separator.getStyles().put(Style.color, separatorColor);
separator.getStyles().put(Style.headingColor, separatorHeadingColor);
separators.insert(separator, index);
form.add(separator);
// Insert label list
ArrayList<Label> sectionLabels = new ArrayList<>();
labels.insert(sectionLabels, index);
// Insert fields
for (int i = 0, n = section.getLength(); i < n; i++) {
insertField(section, section.get(i), i);
}
invalidateComponent();
}
Aggregations