Search in sources :

Example 31 with ArrayList

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;
}
Also used : Modifier(org.apache.pivot.wtk.Keyboard.Modifier) SelectMode(org.apache.pivot.wtk.TableView.SelectMode) Keyboard(org.apache.pivot.wtk.Keyboard) ArrayList(org.apache.pivot.collections.ArrayList) Span(org.apache.pivot.wtk.Span) TableView(org.apache.pivot.wtk.TableView)

Example 32 with ArrayList

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);
    }
}
Also used : SerializationException(org.apache.pivot.serialization.SerializationException) InputStream(java.io.InputStream) Color(java.awt.Color) IOException(java.io.IOException) ArrayList(org.apache.pivot.collections.ArrayList) List(org.apache.pivot.collections.List) Map(org.apache.pivot.collections.Map) HashMap(org.apache.pivot.collections.HashMap) JSONSerializer(org.apache.pivot.json.JSONSerializer)

Example 33 with ArrayList

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;
}
Also used : Vote(org.apache.pivot.util.Vote) FileBrowserSheet(org.apache.pivot.wtk.FileBrowserSheet) Form(org.apache.pivot.wtk.Form) ArrayList(org.apache.pivot.collections.ArrayList) IOException(java.io.IOException) File(java.io.File)

Example 34 with ArrayList

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();
}
Also used : ArrayList(org.apache.pivot.collections.ArrayList) File(java.io.File) Point(org.apache.pivot.wtk.Point)

Example 35 with ArrayList

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();
}
Also used : Form(org.apache.pivot.wtk.Form) Label(org.apache.pivot.wtk.Label) ArrayList(org.apache.pivot.collections.ArrayList) Separator(org.apache.pivot.wtk.Separator) Point(org.apache.pivot.wtk.Point)

Aggregations

ArrayList (org.apache.pivot.collections.ArrayList)41 List (org.apache.pivot.collections.List)9 Span (org.apache.pivot.wtk.Span)8 Test (org.junit.Test)6 IOException (java.io.IOException)5 ListView (org.apache.pivot.wtk.ListView)5 Point (org.apache.pivot.wtk.Point)5 TableView (org.apache.pivot.wtk.TableView)5 StringWriter (java.io.StringWriter)4 HashMap (org.apache.pivot.collections.HashMap)4 CSVSerializer (org.apache.pivot.serialization.CSVSerializer)4 SerializationException (org.apache.pivot.serialization.SerializationException)4 Vote (org.apache.pivot.util.Vote)4 Component (org.apache.pivot.wtk.Component)4 Form (org.apache.pivot.wtk.Form)4 File (java.io.File)3 FileObject (org.apache.commons.vfs2.FileObject)3 BXMLSerializer (org.apache.pivot.beans.BXMLSerializer)3 Bounds (org.apache.pivot.wtk.Bounds)3 ListButton (org.apache.pivot.wtk.ListButton)3