Search in sources :

Example 71 with ListSelectionModel

use of javax.swing.ListSelectionModel in project sldeditor by robward-scisys.

the class SortByPanel method selectDestination.

/**
 * Select destination rows.
 *
 * @param selectedIndexes the selected indexes
 */
protected void selectDestination(int[] selectedIndexes) {
    ListSelectionModel model = destinationTable.getSelectionModel();
    model.clearSelection();
    for (int index : selectedIndexes) {
        model.addSelectionInterval(index, index);
    }
}
Also used : ListSelectionModel(javax.swing.ListSelectionModel)

Example 72 with ListSelectionModel

use of javax.swing.ListSelectionModel in project sldeditor by robward-scisys.

the class SortByPanel method moveDestinationDown.

/**
 * Move destination down.
 */
protected void moveDestinationDown() {
    int[] indices = destinationTable.getSelectedRows();
    int[] updatedIndices = new int[indices.length];
    for (int arrayIndex = indices.length - 1; arrayIndex >= 0; arrayIndex--) {
        int index = indices[arrayIndex];
        if (index < destinationModel.getRowCount() - 1) {
            destinationModel.moveRowDown(index);
            updatedIndices[arrayIndex] = index + 1;
        } else {
            // At the bottom of the list so make sure it is still highlighted
            updatedIndices[arrayIndex] = index;
        }
    }
    // Reselect the items after they have moved
    ListSelectionModel model = destinationTable.getSelectionModel();
    model.clearSelection();
    for (int index : updatedIndices) {
        model.addSelectionInterval(index, index);
    }
}
Also used : ListSelectionModel(javax.swing.ListSelectionModel)

Example 73 with ListSelectionModel

use of javax.swing.ListSelectionModel in project sldeditor by robward-scisys.

the class SortByPanel method setText.

/**
 * Sets the text.
 *
 * @param value the new text
 */
public void setText(String value) {
    Map<String, String> options = new HashMap<>();
    ListSelectionModel model = destinationTable.getSelectionModel();
    model.clearSelection();
    SortBy[] sortArray = null;
    if (!value.isEmpty()) {
        options.put(FeatureTypeStyle.SORT_BY, value);
        sortArray = SLDStyleFactory.getSortBy(options);
    }
    destinationModel.populate(sortArray);
    updateLists();
    btnMoveDown.setEnabled(false);
    btnMoveUp.setEnabled(false);
    btnDestToSrcButton.setEnabled(false);
    btnSrcToDestButton.setEnabled(false);
}
Also used : HashMap(java.util.HashMap) SortBy(org.opengis.filter.sort.SortBy) ListSelectionModel(javax.swing.ListSelectionModel)

Example 74 with ListSelectionModel

use of javax.swing.ListSelectionModel in project sldeditor by robward-scisys.

the class SortByPanel method createUI.

/**
 * Creates the UI.
 */
private void createUI(int noOfRows) {
    int xPos = 0;
    int width = BasePanel.FIELD_PANEL_WIDTH - xPos - 20;
    int height = BasePanel.WIDGET_HEIGHT * (noOfRows - 1);
    this.setBounds(0, 0, width, height);
    JPanel panel = new JPanel();
    add(panel, BorderLayout.CENTER);
    panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS));
    // Source list
    JScrollPane scrollPaneSource = new JScrollPane();
    scrollPaneSource.setPreferredSize(new Dimension(200, 200));
    panel.add(scrollPaneSource);
    sourceList = new JList<>(sourceModel);
    sourceList.addListSelectionListener(new ListSelectionListener() {

        public void valueChanged(ListSelectionEvent e) {
            if (!e.getValueIsAdjusting()) {
                sourceSelected();
            }
        }
    });
    scrollPaneSource.setViewportView(sourceList);
    JPanel panel1 = new JPanel();
    panel1.setLayout(new BorderLayout(0, 0));
    JPanel centrePanel = new JPanel();
    centrePanel.setPreferredSize(new Dimension(50, 50));
    centrePanel.setMaximumSize(new Dimension(50, 50));
    panel.add(centrePanel);
    centrePanel.setLayout(new BoxLayout(centrePanel, BoxLayout.Y_AXIS));
    btnSrcToDestButton = new JButton("->");
    btnSrcToDestButton.setEnabled(false);
    btnSrcToDestButton.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            moveSrcToDestination();
        }
    });
    centrePanel.add(btnSrcToDestButton);
    btnDestToSrcButton = new JButton("<-");
    btnDestToSrcButton.setEnabled(false);
    btnDestToSrcButton.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            moveDestinationToSource();
        }
    });
    centrePanel.add(btnDestToSrcButton);
    // Destination list
    JScrollPane scrollPaneDest = new JScrollPane();
    scrollPaneDest.setPreferredSize(new Dimension(200, 200));
    panel.add(scrollPaneDest);
    destinationTable = new JTable();
    destinationTable.setModel(destinationModel);
    TableColumnModel columnModel = destinationTable.getColumnModel();
    TableColumn col = columnModel.getColumn(SortByTableModel.getSortOrderColumn());
    SortByCheckBoxRenderer checkBoxRenderer = new SortByCheckBoxRenderer();
    col.setCellRenderer(checkBoxRenderer);
    col.setCellEditor(new SortByOptionalValueEditor(destinationModel));
    destinationTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {

        public void valueChanged(ListSelectionEvent e) {
            if (!e.getValueIsAdjusting()) {
                ListSelectionModel model = destinationTable.getSelectionModel();
                if (!model.isSelectionEmpty()) {
                    destinationSelected();
                }
            }
        }
    });
    destinationModel.addTableModelListener(new TableModelListener() {

        @Override
        public void tableChanged(TableModelEvent e) {
            if (e.getColumn() == SortByTableModel.getSortOrderColumn()) {
                ListSelectionModel model = destinationTable.getSelectionModel();
                model.clearSelection();
                btnMoveDown.setEnabled(false);
                btnMoveUp.setEnabled(false);
                btnSrcToDestButton.setEnabled(false);
                btnDestToSrcButton.setEnabled(false);
            }
        }
    });
    scrollPaneDest.setViewportView(destinationTable);
    JPanel buttonPanel = new JPanel();
    FlowLayout flButtonPanel = (FlowLayout) buttonPanel.getLayout();
    flButtonPanel.setAlignment(FlowLayout.RIGHT);
    add(buttonPanel, BorderLayout.SOUTH);
    btnMoveUp = new JButton(Localisation.getString(SortByPanel.class, "sortby.up"));
    btnMoveUp.setEnabled(false);
    btnMoveUp.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            moveDestinationUp();
        }
    });
    buttonPanel.add(btnMoveUp);
    btnMoveDown = new JButton(Localisation.getString(SortByPanel.class, "sortby.down"));
    btnMoveDown.setEnabled(false);
    btnMoveDown.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            moveDestinationDown();
        }
    });
    buttonPanel.add(btnMoveDown);
}
Also used : JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) FlowLayout(java.awt.FlowLayout) ActionEvent(java.awt.event.ActionEvent) TableModelEvent(javax.swing.event.TableModelEvent) BoxLayout(javax.swing.BoxLayout) ListSelectionEvent(javax.swing.event.ListSelectionEvent) JButton(javax.swing.JButton) TableColumnModel(javax.swing.table.TableColumnModel) ListSelectionModel(javax.swing.ListSelectionModel) Dimension(java.awt.Dimension) TableColumn(javax.swing.table.TableColumn) ListSelectionListener(javax.swing.event.ListSelectionListener) BorderLayout(java.awt.BorderLayout) ActionListener(java.awt.event.ActionListener) JTable(javax.swing.JTable) TableModelListener(javax.swing.event.TableModelListener)

Example 75 with ListSelectionModel

use of javax.swing.ListSelectionModel in project sldeditor by robward-scisys.

the class ConfigureLayerStyleDialog method createUI.

/**
 * Creates the ui.
 */
private void createUI() {
    JPanel panel = new JPanel();
    getContentPane().add(panel, BorderLayout.CENTER);
    panel.setLayout(new BorderLayout(0, 0));
    table = new JTable(dataModel);
    dataModel.setColumnRenderer(table.getColumnModel());
    ListSelectionModel selectionModel = table.getSelectionModel();
    selectionModel.addListSelectionListener(new ListSelectionListener() {

        @Override
        public void valueChanged(ListSelectionEvent e) {
            if (e.getValueIsAdjusting()) {
                return;
            }
            itemSelected();
        }
    });
    JScrollPane scrollPane = new JScrollPane(table);
    panel.add(scrollPane, BorderLayout.CENTER);
    // 
    // Button panel
    // 
    JPanel buttonPanel = new JPanel();
    FlowLayout flowLayout = (FlowLayout) buttonPanel.getLayout();
    flowLayout.setAlignment(FlowLayout.TRAILING);
    getContentPane().add(buttonPanel, BorderLayout.SOUTH);
    JButton btnOk = new JButton(Localisation.getString(ConfigureLayerStyleDialog.class, "common.ok"));
    btnOk.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            okButtonPressed = false;
            updatedLayerList = dataModel.getUpdatedLayers();
            if (!updatedLayerList.isEmpty()) {
                okButtonPressed = true;
            }
            setVisible(false);
        }
    });
    buttonPanel.add(btnOk);
    JButton btnCancel = new JButton(Localisation.getString(ConfigureLayerStyleDialog.class, "common.cancel"));
    btnCancel.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            okButtonPressed = false;
            setVisible(false);
        }
    });
    buttonPanel.add(btnCancel);
    geoServerStyleTree = new GeoServerStyleTree(this);
    getContentPane().add(geoServerStyleTree, BorderLayout.EAST);
}
Also used : JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) FlowLayout(java.awt.FlowLayout) ActionEvent(java.awt.event.ActionEvent) ListSelectionEvent(javax.swing.event.ListSelectionEvent) JButton(javax.swing.JButton) ListSelectionModel(javax.swing.ListSelectionModel) ListSelectionListener(javax.swing.event.ListSelectionListener) BorderLayout(java.awt.BorderLayout) ActionListener(java.awt.event.ActionListener) JTable(javax.swing.JTable)

Aggregations

ListSelectionModel (javax.swing.ListSelectionModel)80 BorderLayout (java.awt.BorderLayout)20 Dimension (java.awt.Dimension)20 JButton (javax.swing.JButton)20 JPanel (javax.swing.JPanel)19 ListSelectionEvent (javax.swing.event.ListSelectionEvent)19 ListSelectionListener (javax.swing.event.ListSelectionListener)19 ActionEvent (java.awt.event.ActionEvent)18 JTable (javax.swing.JTable)18 ActionListener (java.awt.event.ActionListener)17 Point (java.awt.Point)16 JScrollPane (javax.swing.JScrollPane)15 MouseEvent (java.awt.event.MouseEvent)14 MouseAdapter (java.awt.event.MouseAdapter)13 DefaultListSelectionModel (javax.swing.DefaultListSelectionModel)13 TableColumn (javax.swing.table.TableColumn)13 Insets (java.awt.Insets)12 TableModel (javax.swing.table.TableModel)11 TableRowSorter (javax.swing.table.TableRowSorter)10 FlowLayout (java.awt.FlowLayout)9