Search in sources :

Example 1 with JKseTable

use of org.kse.gui.JKseTable in project keystore-explorer by kaikramer.

the class DEnvironmentVariables method initComponents.

private void initComponents() {
    EnvironmentVariablesTableModel evModel = new EnvironmentVariablesTableModel();
    evModel.load();
    jtEnvironmentVariables = new JKseTable(evModel);
    jtEnvironmentVariables.setRowMargin(0);
    jtEnvironmentVariables.getColumnModel().setColumnMargin(0);
    jtEnvironmentVariables.getTableHeader().setReorderingAllowed(false);
    jtEnvironmentVariables.setAutoResizeMode(JKseTable.AUTO_RESIZE_OFF);
    RowSorter<TableModel> sorter = new TableRowSorter<TableModel>(evModel);
    jtEnvironmentVariables.setRowSorter(sorter);
    for (int i = 0; i < jtEnvironmentVariables.getColumnCount(); i++) {
        TableColumn column = jtEnvironmentVariables.getColumnModel().getColumn(i);
        if (i == 0) {
            column.setPreferredWidth(200);
        } else {
            column.setPreferredWidth(300);
        }
        column.setCellRenderer(new EnvironmentVariablesTableCellRend());
    }
    jspEnvironmentVariablesTable = PlatformUtil.createScrollPane(jtEnvironmentVariables, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    jspEnvironmentVariablesTable.getViewport().setBackground(jtEnvironmentVariables.getBackground());
    jpEnvironmentVariablesTable = new JPanel(new BorderLayout(10, 10));
    jpEnvironmentVariablesTable.setPreferredSize(new Dimension(500, 300));
    jpEnvironmentVariablesTable.add(jspEnvironmentVariablesTable, BorderLayout.CENTER);
    jpEnvironmentVariablesTable.setBorder(new EmptyBorder(5, 5, 5, 5));
    jbOK = new JButton(res.getString("DEnvironmentVariables.jbOK.text"));
    jbOK.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent evt) {
            okPressed();
        }
    });
    jpOK = PlatformUtil.createDialogButtonPanel(jbOK, false);
    getContentPane().add(jpEnvironmentVariablesTable, BorderLayout.CENTER);
    getContentPane().add(jpOK, BorderLayout.SOUTH);
    setResizable(false);
    addWindowListener(new WindowAdapter() {

        @Override
        public void windowClosing(WindowEvent evt) {
            closeDialog();
        }
    });
    getRootPane().setDefaultButton(jbOK);
    pack();
    SwingUtilities.invokeLater(new Runnable() {

        @Override
        public void run() {
            jbOK.requestFocus();
        }
    });
}
Also used : JPanel(javax.swing.JPanel) ActionEvent(java.awt.event.ActionEvent) JKseTable(org.kse.gui.JKseTable) JButton(javax.swing.JButton) WindowAdapter(java.awt.event.WindowAdapter) Dimension(java.awt.Dimension) TableColumn(javax.swing.table.TableColumn) BorderLayout(java.awt.BorderLayout) ActionListener(java.awt.event.ActionListener) WindowEvent(java.awt.event.WindowEvent) EmptyBorder(javax.swing.border.EmptyBorder) TableModel(javax.swing.table.TableModel) TableRowSorter(javax.swing.table.TableRowSorter)

Example 2 with JKseTable

use of org.kse.gui.JKseTable in project keystore-explorer by kaikramer.

the class JGeneralSubtrees method initComponents.

private void initComponents() {
    jbAdd = new JButton(new ImageIcon(Toolkit.getDefaultToolkit().createImage(getClass().getResource(res.getString("JGeneralSubtrees.jbAdd.image")))));
    jbAdd.setMargin(new Insets(2, 2, 0, 0));
    jbAdd.setToolTipText(res.getString("JGeneralSubtrees.jbAdd.tooltip"));
    jbAdd.setMnemonic(res.getString("JGeneralSubtrees.jbAdd.mnemonic").charAt(0));
    jbAdd.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent evt) {
            try {
                CursorUtil.setCursorBusy(JGeneralSubtrees.this);
                addPressed();
            } finally {
                CursorUtil.setCursorFree(JGeneralSubtrees.this);
            }
        }
    });
    jbEdit = new JButton(new ImageIcon(Toolkit.getDefaultToolkit().createImage(getClass().getResource(res.getString("JGeneralSubtrees.jbEdit.image")))));
    jbEdit.setMargin(new Insets(2, 2, 0, 0));
    jbEdit.setToolTipText(res.getString("JGeneralSubtrees.jbEdit.tooltip"));
    jbEdit.setMnemonic(res.getString("JGeneralSubtrees.jbEdit.mnemonic").charAt(0));
    jbEdit.setEnabled(false);
    jbEdit.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent evt) {
            try {
                CursorUtil.setCursorBusy(JGeneralSubtrees.this);
                editPressed();
            } finally {
                CursorUtil.setCursorFree(JGeneralSubtrees.this);
            }
        }
    });
    jbRemove = new JButton(new ImageIcon(Toolkit.getDefaultToolkit().createImage(getClass().getResource(res.getString("JGeneralSubtrees.jbRemove.image")))));
    jbRemove.setMargin(new Insets(2, 2, 0, 0));
    jbRemove.setToolTipText(res.getString("JGeneralSubtrees.jbRemove.tooltip"));
    jbRemove.setMnemonic(res.getString("JGeneralSubtrees.jbRemove.mnemonic").charAt(0));
    jbRemove.setEnabled(false);
    jbRemove.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent evt) {
            try {
                CursorUtil.setCursorBusy(JGeneralSubtrees.this);
                removePressed();
            } finally {
                CursorUtil.setCursorFree(JGeneralSubtrees.this);
            }
        }
    });
    jpGeneralSubtreeButtons = new JPanel();
    jpGeneralSubtreeButtons.setLayout(new BoxLayout(jpGeneralSubtreeButtons, BoxLayout.Y_AXIS));
    jpGeneralSubtreeButtons.add(Box.createVerticalGlue());
    jpGeneralSubtreeButtons.add(jbAdd);
    jpGeneralSubtreeButtons.add(Box.createVerticalStrut(3));
    jpGeneralSubtreeButtons.add(jbEdit);
    jpGeneralSubtreeButtons.add(Box.createVerticalStrut(3));
    jpGeneralSubtreeButtons.add(jbRemove);
    jpGeneralSubtreeButtons.add(Box.createVerticalGlue());
    GeneralSubtreesTableModel generalSubtreesTableModel = new GeneralSubtreesTableModel();
    jtGeneralSubtrees = new JKseTable(generalSubtreesTableModel);
    TableRowSorter<TableModel> sorter = new TableRowSorter<TableModel>(generalSubtreesTableModel);
    sorter.setComparator(0, new GeneralSubtreesTableModel.GeneralSubtreeBaseComparator());
    sorter.setComparator(1, new GeneralSubtreesTableModel.GeneralSubtreeMinimumComparator());
    sorter.setComparator(2, new GeneralSubtreesTableModel.GeneralSubtreeMaximumComparator());
    jtGeneralSubtrees.setRowSorter(sorter);
    jtGeneralSubtrees.setShowGrid(false);
    jtGeneralSubtrees.setRowMargin(0);
    jtGeneralSubtrees.getColumnModel().setColumnMargin(0);
    jtGeneralSubtrees.getTableHeader().setReorderingAllowed(false);
    jtGeneralSubtrees.setAutoResizeMode(JKseTable.AUTO_RESIZE_ALL_COLUMNS);
    jtGeneralSubtrees.setRowHeight(Math.max(18, jtGeneralSubtrees.getRowHeight()));
    for (int i = 0; i < jtGeneralSubtrees.getColumnCount(); i++) {
        TableColumn column = jtGeneralSubtrees.getColumnModel().getColumn(i);
        column.setHeaderRenderer(new GeneralSubtreesTableHeadRend(jtGeneralSubtrees.getTableHeader().getDefaultRenderer()));
        column.setCellRenderer(new GeneralSubtreesTableCellRend());
    }
    ListSelectionModel selectionModel = jtGeneralSubtrees.getSelectionModel();
    selectionModel.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    selectionModel.addListSelectionListener(new ListSelectionListener() {

        @Override
        public void valueChanged(ListSelectionEvent evt) {
            if (!evt.getValueIsAdjusting()) {
                updateButtonControls();
            }
        }
    });
    jtGeneralSubtrees.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseClicked(MouseEvent evt) {
            maybeEditGeneralSubtree(evt);
        }
    });
    jtGeneralSubtrees.addKeyListener(new KeyAdapter() {

        boolean deleteLastPressed = false;

        @Override
        public void keyPressed(KeyEvent evt) {
            // Record delete pressed on non-Macs
            if (!OperatingSystem.isMacOs()) {
                deleteLastPressed = evt.getKeyCode() == KeyEvent.VK_DELETE;
            }
        }

        @Override
        public void keyReleased(KeyEvent evt) {
            // Delete on non-Mac if delete was pressed and is now released
            if (!OperatingSystem.isMacOs() && deleteLastPressed && evt.getKeyCode() == KeyEvent.VK_DELETE) {
                try {
                    CursorUtil.setCursorBusy(JGeneralSubtrees.this);
                    deleteLastPressed = false;
                    removeSelectedGeneralSubtree();
                } finally {
                    CursorUtil.setCursorFree(JGeneralSubtrees.this);
                }
            }
        }

        @Override
        public void keyTyped(KeyEvent evt) {
            // Delete on Mac if back space typed
            if (OperatingSystem.isMacOs() && evt.getKeyChar() == 0x08) {
                try {
                    CursorUtil.setCursorBusy(JGeneralSubtrees.this);
                    removeSelectedGeneralSubtree();
                } finally {
                    CursorUtil.setCursorFree(JGeneralSubtrees.this);
                }
            }
        }
    });
    jspGeneralSubtrees = PlatformUtil.createScrollPane(jtGeneralSubtrees, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
    jspGeneralSubtrees.getViewport().setBackground(jtGeneralSubtrees.getBackground());
    this.setLayout(new BorderLayout(5, 5));
    setPreferredSize(new Dimension(400, 150));
    add(jspGeneralSubtrees, BorderLayout.CENTER);
    add(jpGeneralSubtreeButtons, BorderLayout.EAST);
    populate();
}
Also used : ImageIcon(javax.swing.ImageIcon) JPanel(javax.swing.JPanel) Insets(java.awt.Insets) ActionEvent(java.awt.event.ActionEvent) BoxLayout(javax.swing.BoxLayout) KeyAdapter(java.awt.event.KeyAdapter) JButton(javax.swing.JButton) ListSelectionEvent(javax.swing.event.ListSelectionEvent) KeyEvent(java.awt.event.KeyEvent) BorderLayout(java.awt.BorderLayout) TableRowSorter(javax.swing.table.TableRowSorter) MouseEvent(java.awt.event.MouseEvent) JKseTable(org.kse.gui.JKseTable) MouseAdapter(java.awt.event.MouseAdapter) ListSelectionModel(javax.swing.ListSelectionModel) Dimension(java.awt.Dimension) TableColumn(javax.swing.table.TableColumn) Point(java.awt.Point) ListSelectionListener(javax.swing.event.ListSelectionListener) ActionListener(java.awt.event.ActionListener) TableModel(javax.swing.table.TableModel)

Example 3 with JKseTable

use of org.kse.gui.JKseTable in project keystore-explorer by kaikramer.

the class JPolicyInformation method initComponents.

private void initComponents() {
    jbAdd = new JButton(new ImageIcon(Toolkit.getDefaultToolkit().createImage(getClass().getResource(res.getString("JPolicyInformation.jbAdd.image")))));
    jbAdd.setMargin(new Insets(2, 2, 0, 0));
    jbAdd.setToolTipText(res.getString("JPolicyInformation.jbAdd.tooltip"));
    jbAdd.setMnemonic(res.getString("JPolicyInformation.jbAdd.mnemonic").charAt(0));
    jbAdd.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent evt) {
            try {
                CursorUtil.setCursorBusy(JPolicyInformation.this);
                addPressed();
            } finally {
                CursorUtil.setCursorFree(JPolicyInformation.this);
            }
        }
    });
    jbEdit = new JButton(new ImageIcon(Toolkit.getDefaultToolkit().createImage(getClass().getResource(res.getString("JPolicyInformation.jbEdit.image")))));
    jbEdit.setMargin(new Insets(2, 2, 0, 0));
    jbEdit.setToolTipText(res.getString("JPolicyInformation.jbEdit.tooltip"));
    jbEdit.setMnemonic(res.getString("JPolicyInformation.jbEdit.mnemonic").charAt(0));
    jbEdit.setEnabled(false);
    jbEdit.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent evt) {
            try {
                CursorUtil.setCursorBusy(JPolicyInformation.this);
                editPressed();
            } finally {
                CursorUtil.setCursorFree(JPolicyInformation.this);
            }
        }
    });
    jbRemove = new JButton(new ImageIcon(Toolkit.getDefaultToolkit().createImage(getClass().getResource(res.getString("JPolicyInformation.jbRemove.image")))));
    jbRemove.setMargin(new Insets(2, 2, 0, 0));
    jbRemove.setToolTipText(res.getString("JPolicyInformation.jbRemove.tooltip"));
    jbRemove.setMnemonic(res.getString("JPolicyInformation.jbRemove.mnemonic").charAt(0));
    jbRemove.setEnabled(false);
    jbRemove.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent evt) {
            try {
                CursorUtil.setCursorBusy(JPolicyInformation.this);
                removePressed();
            } finally {
                CursorUtil.setCursorFree(JPolicyInformation.this);
            }
        }
    });
    jpPolicyInformationButtons = new JPanel();
    jpPolicyInformationButtons.setLayout(new BoxLayout(jpPolicyInformationButtons, BoxLayout.Y_AXIS));
    jpPolicyInformationButtons.add(Box.createVerticalGlue());
    jpPolicyInformationButtons.add(jbAdd);
    jpPolicyInformationButtons.add(Box.createVerticalStrut(3));
    jpPolicyInformationButtons.add(jbEdit);
    jpPolicyInformationButtons.add(Box.createVerticalStrut(3));
    jpPolicyInformationButtons.add(jbRemove);
    jpPolicyInformationButtons.add(Box.createVerticalGlue());
    PolicyInformationTableModel policyInformationTableModel = new PolicyInformationTableModel();
    jtPolicyInformation = new JKseTable(policyInformationTableModel);
    TableRowSorter<TableModel> sorter = new TableRowSorter<TableModel>(policyInformationTableModel);
    sorter.setComparator(0, new PolicyInformationTableModel.PolicyInformationComparator());
    jtPolicyInformation.setRowSorter(sorter);
    jtPolicyInformation.setShowGrid(false);
    jtPolicyInformation.setRowMargin(0);
    jtPolicyInformation.getColumnModel().setColumnMargin(0);
    jtPolicyInformation.getTableHeader().setReorderingAllowed(false);
    jtPolicyInformation.setAutoResizeMode(JKseTable.AUTO_RESIZE_ALL_COLUMNS);
    jtPolicyInformation.setRowHeight(Math.max(18, jtPolicyInformation.getRowHeight()));
    for (int i = 0; i < jtPolicyInformation.getColumnCount(); i++) {
        TableColumn column = jtPolicyInformation.getColumnModel().getColumn(i);
        column.setHeaderRenderer(new PolicyInformationTableHeadRend(jtPolicyInformation.getTableHeader().getDefaultRenderer()));
        column.setCellRenderer(new PolicyInformationTableCellRend());
    }
    ListSelectionModel selectionModel = jtPolicyInformation.getSelectionModel();
    selectionModel.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    selectionModel.addListSelectionListener(new ListSelectionListener() {

        @Override
        public void valueChanged(ListSelectionEvent evt) {
            if (!evt.getValueIsAdjusting()) {
                updateButtonControls();
            }
        }
    });
    jtPolicyInformation.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseClicked(MouseEvent evt) {
            maybeEditPolicyInformation(evt);
        }
    });
    jtPolicyInformation.addKeyListener(new KeyAdapter() {

        boolean deleteLastPressed = false;

        @Override
        public void keyPressed(KeyEvent evt) {
            // Record delete pressed on non-Macs
            if (!OperatingSystem.isMacOs()) {
                deleteLastPressed = evt.getKeyCode() == KeyEvent.VK_DELETE;
            }
        }

        @Override
        public void keyReleased(KeyEvent evt) {
            // Delete on non-Mac if delete was pressed and is now released
            if (!OperatingSystem.isMacOs() && deleteLastPressed && evt.getKeyCode() == KeyEvent.VK_DELETE) {
                try {
                    CursorUtil.setCursorBusy(JPolicyInformation.this);
                    deleteLastPressed = false;
                    removeSelectedPolicyInformation();
                } finally {
                    CursorUtil.setCursorFree(JPolicyInformation.this);
                }
            }
        }

        @Override
        public void keyTyped(KeyEvent evt) {
            // Delete on Mac if back space typed
            if (OperatingSystem.isMacOs() && evt.getKeyChar() == 0x08) {
                try {
                    CursorUtil.setCursorBusy(JPolicyInformation.this);
                    removeSelectedPolicyInformation();
                } finally {
                    CursorUtil.setCursorFree(JPolicyInformation.this);
                }
            }
        }
    });
    jspPolicyInformation = PlatformUtil.createScrollPane(jtPolicyInformation, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
    jspPolicyInformation.getViewport().setBackground(jtPolicyInformation.getBackground());
    this.setLayout(new BorderLayout(5, 5));
    setPreferredSize(new Dimension(250, 150));
    add(jspPolicyInformation, BorderLayout.CENTER);
    add(jpPolicyInformationButtons, BorderLayout.EAST);
    populate();
}
Also used : ImageIcon(javax.swing.ImageIcon) JPanel(javax.swing.JPanel) Insets(java.awt.Insets) ActionEvent(java.awt.event.ActionEvent) BoxLayout(javax.swing.BoxLayout) KeyAdapter(java.awt.event.KeyAdapter) JButton(javax.swing.JButton) ListSelectionEvent(javax.swing.event.ListSelectionEvent) KeyEvent(java.awt.event.KeyEvent) BorderLayout(java.awt.BorderLayout) TableRowSorter(javax.swing.table.TableRowSorter) MouseEvent(java.awt.event.MouseEvent) JKseTable(org.kse.gui.JKseTable) MouseAdapter(java.awt.event.MouseAdapter) ListSelectionModel(javax.swing.ListSelectionModel) Dimension(java.awt.Dimension) TableColumn(javax.swing.table.TableColumn) Point(java.awt.Point) ListSelectionListener(javax.swing.event.ListSelectionListener) ActionListener(java.awt.event.ActionListener) TableModel(javax.swing.table.TableModel)

Example 4 with JKseTable

use of org.kse.gui.JKseTable in project keystore-explorer by kaikramer.

the class JAccessDescriptions method initComponents.

private void initComponents() {
    jbAdd = new JButton(new ImageIcon(Toolkit.getDefaultToolkit().createImage(getClass().getResource(res.getString("JAccessDescriptions.jbAdd.image")))));
    jbAdd.setMargin(new Insets(2, 2, 0, 0));
    jbAdd.setToolTipText(res.getString("JAccessDescriptions.jbAdd.tooltip"));
    jbAdd.setMnemonic(res.getString("JAccessDescriptions.jbAdd.mnemonic").charAt(0));
    jbAdd.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent evt) {
            try {
                CursorUtil.setCursorBusy(JAccessDescriptions.this);
                addPressed();
            } finally {
                CursorUtil.setCursorFree(JAccessDescriptions.this);
            }
        }
    });
    jbEdit = new JButton(new ImageIcon(Toolkit.getDefaultToolkit().createImage(getClass().getResource(res.getString("JAccessDescriptions.jbEdit.image")))));
    jbEdit.setMargin(new Insets(2, 2, 0, 0));
    jbEdit.setToolTipText(res.getString("JAccessDescriptions.jbEdit.tooltip"));
    jbEdit.setMnemonic(res.getString("JAccessDescriptions.jbEdit.mnemonic").charAt(0));
    jbEdit.setEnabled(false);
    jbEdit.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent evt) {
            try {
                CursorUtil.setCursorBusy(JAccessDescriptions.this);
                editPressed();
            } finally {
                CursorUtil.setCursorFree(JAccessDescriptions.this);
            }
        }
    });
    jbRemove = new JButton(new ImageIcon(Toolkit.getDefaultToolkit().createImage(getClass().getResource(res.getString("JAccessDescriptions.jbRemove.image")))));
    jbRemove.setMargin(new Insets(2, 2, 0, 0));
    jbRemove.setToolTipText(res.getString("JAccessDescriptions.jbRemove.tooltip"));
    jbRemove.setMnemonic(res.getString("JAccessDescriptions.jbRemove.mnemonic").charAt(0));
    jbRemove.setEnabled(false);
    jbRemove.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent evt) {
            try {
                CursorUtil.setCursorBusy(JAccessDescriptions.this);
                removePressed();
            } finally {
                CursorUtil.setCursorFree(JAccessDescriptions.this);
            }
        }
    });
    jpAccessDescriptionButtons = new JPanel();
    jpAccessDescriptionButtons.setLayout(new BoxLayout(jpAccessDescriptionButtons, BoxLayout.Y_AXIS));
    jpAccessDescriptionButtons.add(Box.createVerticalGlue());
    jpAccessDescriptionButtons.add(jbAdd);
    jpAccessDescriptionButtons.add(Box.createVerticalStrut(3));
    jpAccessDescriptionButtons.add(jbEdit);
    jpAccessDescriptionButtons.add(Box.createVerticalStrut(3));
    jpAccessDescriptionButtons.add(jbRemove);
    jpAccessDescriptionButtons.add(Box.createVerticalGlue());
    AccessDescriptionsTableModel accessDescriptionsTableModel = new AccessDescriptionsTableModel();
    jtAccessDescriptions = new JKseTable(accessDescriptionsTableModel);
    TableRowSorter<TableModel> sorter = new TableRowSorter<TableModel>(accessDescriptionsTableModel);
    sorter.setComparator(0, new AccessDescriptionsTableModel.AccessDescriptionMethodComparator());
    sorter.setComparator(1, new AccessDescriptionsTableModel.AccessDescriptionLocationComparator());
    jtAccessDescriptions.setRowSorter(sorter);
    jtAccessDescriptions.setShowGrid(false);
    jtAccessDescriptions.setRowMargin(0);
    jtAccessDescriptions.getColumnModel().setColumnMargin(0);
    jtAccessDescriptions.getTableHeader().setReorderingAllowed(false);
    jtAccessDescriptions.setAutoResizeMode(JKseTable.AUTO_RESIZE_ALL_COLUMNS);
    jtAccessDescriptions.setRowHeight(Math.max(18, jtAccessDescriptions.getRowHeight()));
    for (int i = 0; i < jtAccessDescriptions.getColumnCount(); i++) {
        TableColumn column = jtAccessDescriptions.getColumnModel().getColumn(i);
        column.setHeaderRenderer(new AccessDescriptionsTableHeadRend(jtAccessDescriptions.getTableHeader().getDefaultRenderer()));
        column.setCellRenderer(new AccessDescriptionsTableCellRend());
    }
    ListSelectionModel selectionModel = jtAccessDescriptions.getSelectionModel();
    selectionModel.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    selectionModel.addListSelectionListener(new ListSelectionListener() {

        @Override
        public void valueChanged(ListSelectionEvent evt) {
            if (!evt.getValueIsAdjusting()) {
                updateButtonControls();
            }
        }
    });
    jtAccessDescriptions.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseClicked(MouseEvent evt) {
            maybeEditAccessDescription(evt);
        }
    });
    jtAccessDescriptions.addKeyListener(new KeyAdapter() {

        boolean deleteLastPressed = false;

        @Override
        public void keyPressed(KeyEvent evt) {
            // Record delete pressed on non-Macs
            if (!OperatingSystem.isMacOs()) {
                deleteLastPressed = evt.getKeyCode() == KeyEvent.VK_DELETE;
            }
        }

        @Override
        public void keyReleased(KeyEvent evt) {
            // Delete on non-Mac if delete was pressed and is now released
            if (!OperatingSystem.isMacOs() && deleteLastPressed && evt.getKeyCode() == KeyEvent.VK_DELETE) {
                try {
                    CursorUtil.setCursorBusy(JAccessDescriptions.this);
                    deleteLastPressed = false;
                    removeSelectedAccessDescription();
                } finally {
                    CursorUtil.setCursorFree(JAccessDescriptions.this);
                }
            }
        }

        @Override
        public void keyTyped(KeyEvent evt) {
            // Delete on Mac if back space typed
            if (OperatingSystem.isMacOs() && evt.getKeyChar() == 0x08) {
                try {
                    CursorUtil.setCursorBusy(JAccessDescriptions.this);
                    removeSelectedAccessDescription();
                } finally {
                    CursorUtil.setCursorFree(JAccessDescriptions.this);
                }
            }
        }
    });
    jspAccessDescriptions = PlatformUtil.createScrollPane(jtAccessDescriptions, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
    jspAccessDescriptions.getViewport().setBackground(jtAccessDescriptions.getBackground());
    this.setLayout(new BorderLayout(5, 5));
    setPreferredSize(new Dimension(400, 150));
    add(jspAccessDescriptions, BorderLayout.CENTER);
    add(jpAccessDescriptionButtons, BorderLayout.EAST);
    populate();
}
Also used : ImageIcon(javax.swing.ImageIcon) JPanel(javax.swing.JPanel) Insets(java.awt.Insets) ActionEvent(java.awt.event.ActionEvent) BoxLayout(javax.swing.BoxLayout) KeyAdapter(java.awt.event.KeyAdapter) JButton(javax.swing.JButton) ListSelectionEvent(javax.swing.event.ListSelectionEvent) KeyEvent(java.awt.event.KeyEvent) BorderLayout(java.awt.BorderLayout) TableRowSorter(javax.swing.table.TableRowSorter) MouseEvent(java.awt.event.MouseEvent) JKseTable(org.kse.gui.JKseTable) MouseAdapter(java.awt.event.MouseAdapter) ListSelectionModel(javax.swing.ListSelectionModel) Dimension(java.awt.Dimension) TableColumn(javax.swing.table.TableColumn) Point(java.awt.Point) ListSelectionListener(javax.swing.event.ListSelectionListener) ActionListener(java.awt.event.ActionListener) TableModel(javax.swing.table.TableModel)

Example 5 with JKseTable

use of org.kse.gui.JKseTable in project keystore-explorer by kaikramer.

the class JPolicyMappings method initComponents.

private void initComponents() {
    jbAdd = new JButton(new ImageIcon(Toolkit.getDefaultToolkit().createImage(getClass().getResource(res.getString("JPolicyMappings.jbAdd.image")))));
    jbAdd.setMargin(new Insets(2, 2, 0, 0));
    jbAdd.setToolTipText(res.getString("JPolicyMappings.jbAdd.tooltip"));
    jbAdd.setMnemonic(res.getString("JPolicyMappings.jbAdd.mnemonic").charAt(0));
    jbAdd.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent evt) {
            try {
                CursorUtil.setCursorBusy(JPolicyMappings.this);
                addPressed();
            } finally {
                CursorUtil.setCursorFree(JPolicyMappings.this);
            }
        }
    });
    jbEdit = new JButton(new ImageIcon(Toolkit.getDefaultToolkit().createImage(getClass().getResource(res.getString("JPolicyMappings.jbEdit.image")))));
    jbEdit.setMargin(new Insets(2, 2, 0, 0));
    jbEdit.setToolTipText(res.getString("JPolicyMappings.jbEdit.tooltip"));
    jbEdit.setMnemonic(res.getString("JPolicyMappings.jbEdit.mnemonic").charAt(0));
    jbEdit.setEnabled(false);
    jbEdit.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent evt) {
            try {
                CursorUtil.setCursorBusy(JPolicyMappings.this);
                editPressed();
            } finally {
                CursorUtil.setCursorFree(JPolicyMappings.this);
            }
        }
    });
    jbRemove = new JButton(new ImageIcon(Toolkit.getDefaultToolkit().createImage(getClass().getResource(res.getString("JPolicyMappings.jbRemove.image")))));
    jbRemove.setMargin(new Insets(2, 2, 0, 0));
    jbRemove.setToolTipText(res.getString("JPolicyMappings.jbRemove.tooltip"));
    jbRemove.setMnemonic(res.getString("JPolicyMappings.jbRemove.mnemonic").charAt(0));
    jbRemove.setEnabled(false);
    jbRemove.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent evt) {
            try {
                CursorUtil.setCursorBusy(JPolicyMappings.this);
                removePressed();
            } finally {
                CursorUtil.setCursorFree(JPolicyMappings.this);
            }
        }
    });
    jpPolicyMappingButtons = new JPanel();
    jpPolicyMappingButtons.setLayout(new BoxLayout(jpPolicyMappingButtons, BoxLayout.Y_AXIS));
    jpPolicyMappingButtons.add(Box.createVerticalGlue());
    jpPolicyMappingButtons.add(jbAdd);
    jpPolicyMappingButtons.add(Box.createVerticalStrut(3));
    jpPolicyMappingButtons.add(jbEdit);
    jpPolicyMappingButtons.add(Box.createVerticalStrut(3));
    jpPolicyMappingButtons.add(jbRemove);
    jpPolicyMappingButtons.add(Box.createVerticalGlue());
    PolicyMappingsTableModel policyMappingsTableModel = new PolicyMappingsTableModel();
    jtPolicyMappings = new JKseTable(policyMappingsTableModel);
    TableRowSorter<TableModel> sorter = new TableRowSorter<TableModel>(policyMappingsTableModel);
    sorter.setComparator(0, new PolicyMappingsTableModel.IssuerDomainPolicyComparator());
    sorter.setComparator(1, new PolicyMappingsTableModel.SubjectDomainPolicyComparator());
    jtPolicyMappings.setRowSorter(sorter);
    jtPolicyMappings.setShowGrid(false);
    jtPolicyMappings.setRowMargin(0);
    jtPolicyMappings.getColumnModel().setColumnMargin(0);
    jtPolicyMappings.getTableHeader().setReorderingAllowed(false);
    jtPolicyMappings.setAutoResizeMode(JKseTable.AUTO_RESIZE_ALL_COLUMNS);
    jtPolicyMappings.setRowHeight(Math.max(18, jtPolicyMappings.getRowHeight()));
    for (int i = 0; i < jtPolicyMappings.getColumnCount(); i++) {
        TableColumn column = jtPolicyMappings.getColumnModel().getColumn(i);
        column.setHeaderRenderer(new PolicyMappingsTableHeadRend(jtPolicyMappings.getTableHeader().getDefaultRenderer()));
        column.setCellRenderer(new PolicyMappingsTableCellRend());
    }
    ListSelectionModel selectionModel = jtPolicyMappings.getSelectionModel();
    selectionModel.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    selectionModel.addListSelectionListener(new ListSelectionListener() {

        @Override
        public void valueChanged(ListSelectionEvent evt) {
            if (!evt.getValueIsAdjusting()) {
                updateButtonControls();
            }
        }
    });
    jtPolicyMappings.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseClicked(MouseEvent evt) {
            maybeEditPolicyMapping(evt);
        }
    });
    jtPolicyMappings.addKeyListener(new KeyAdapter() {

        boolean deleteLastPressed = false;

        @Override
        public void keyPressed(KeyEvent evt) {
            // Record delete pressed on non-Macs
            if (!OperatingSystem.isMacOs()) {
                deleteLastPressed = evt.getKeyCode() == KeyEvent.VK_DELETE;
            }
        }

        @Override
        public void keyReleased(KeyEvent evt) {
            // Delete on non-Mac if delete was pressed and is now released
            if (!OperatingSystem.isMacOs() && deleteLastPressed && evt.getKeyCode() == KeyEvent.VK_DELETE) {
                try {
                    CursorUtil.setCursorBusy(JPolicyMappings.this);
                    deleteLastPressed = false;
                    removeSelectedPolicyMapping();
                } finally {
                    CursorUtil.setCursorFree(JPolicyMappings.this);
                }
            }
        }

        @Override
        public void keyTyped(KeyEvent evt) {
            // Delete on Mac if back space typed
            if (OperatingSystem.isMacOs() && evt.getKeyChar() == 0x08) {
                try {
                    CursorUtil.setCursorBusy(JPolicyMappings.this);
                    removeSelectedPolicyMapping();
                } finally {
                    CursorUtil.setCursorFree(JPolicyMappings.this);
                }
            }
        }
    });
    jspPolicyMappings = PlatformUtil.createScrollPane(jtPolicyMappings, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
    jspPolicyMappings.getViewport().setBackground(jtPolicyMappings.getBackground());
    this.setLayout(new BorderLayout(5, 5));
    setPreferredSize(new Dimension(400, 150));
    add(jspPolicyMappings, BorderLayout.CENTER);
    add(jpPolicyMappingButtons, BorderLayout.EAST);
    populate();
}
Also used : ImageIcon(javax.swing.ImageIcon) JPanel(javax.swing.JPanel) Insets(java.awt.Insets) ActionEvent(java.awt.event.ActionEvent) BoxLayout(javax.swing.BoxLayout) KeyAdapter(java.awt.event.KeyAdapter) JButton(javax.swing.JButton) ListSelectionEvent(javax.swing.event.ListSelectionEvent) KeyEvent(java.awt.event.KeyEvent) BorderLayout(java.awt.BorderLayout) TableRowSorter(javax.swing.table.TableRowSorter) MouseEvent(java.awt.event.MouseEvent) JKseTable(org.kse.gui.JKseTable) MouseAdapter(java.awt.event.MouseAdapter) ListSelectionModel(javax.swing.ListSelectionModel) Dimension(java.awt.Dimension) TableColumn(javax.swing.table.TableColumn) Point(java.awt.Point) ListSelectionListener(javax.swing.event.ListSelectionListener) ActionListener(java.awt.event.ActionListener) TableModel(javax.swing.table.TableModel)

Aggregations

BorderLayout (java.awt.BorderLayout)12 Dimension (java.awt.Dimension)12 ActionEvent (java.awt.event.ActionEvent)12 ActionListener (java.awt.event.ActionListener)12 JButton (javax.swing.JButton)12 JPanel (javax.swing.JPanel)12 TableColumn (javax.swing.table.TableColumn)12 TableModel (javax.swing.table.TableModel)12 TableRowSorter (javax.swing.table.TableRowSorter)12 JKseTable (org.kse.gui.JKseTable)12 ListSelectionModel (javax.swing.ListSelectionModel)9 ListSelectionEvent (javax.swing.event.ListSelectionEvent)9 ListSelectionListener (javax.swing.event.ListSelectionListener)9 Insets (java.awt.Insets)8 Point (java.awt.Point)8 MouseAdapter (java.awt.event.MouseAdapter)8 MouseEvent (java.awt.event.MouseEvent)8 KeyAdapter (java.awt.event.KeyAdapter)7 KeyEvent (java.awt.event.KeyEvent)7 BoxLayout (javax.swing.BoxLayout)7