Search in sources :

Example 11 with JKseTable

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

the class JPolicyQualifierInfo method initComponents.

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

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

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

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

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

        @Override
        public void mouseClicked(MouseEvent evt) {
            maybeEditPolicyQualifierInfo(evt);
        }
    });
    jtPolicyQualifierInfo.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(JPolicyQualifierInfo.this);
                    deleteLastPressed = false;
                    removeSelectedPolicyQualifierInfo();
                } finally {
                    CursorUtil.setCursorFree(JPolicyQualifierInfo.this);
                }
            }
        }

        @Override
        public void keyTyped(KeyEvent evt) {
            // Delete on Mac if back space typed
            if (OperatingSystem.isMacOs() && evt.getKeyChar() == 0x08) {
                try {
                    CursorUtil.setCursorBusy(JPolicyQualifierInfo.this);
                    removeSelectedPolicyQualifierInfo();
                } finally {
                    CursorUtil.setCursorFree(JPolicyQualifierInfo.this);
                }
            }
        }
    });
    jspPolicyQualifierInfo = PlatformUtil.createScrollPane(jtPolicyQualifierInfo, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
    jspPolicyQualifierInfo.getViewport().setBackground(jtPolicyQualifierInfo.getBackground());
    this.setLayout(new BorderLayout(5, 5));
    setPreferredSize(new Dimension(400, 150));
    add(jspPolicyQualifierInfo, BorderLayout.CENTER);
    add(jpPolicyQualifierInfoButtons, 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 12 with JKseTable

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

the class DViewExtensions method initComponents.

private void initComponents() {
    ExtensionsTableModel extensionsTableModel = new ExtensionsTableModel();
    jtExtensions = new JKseTable(extensionsTableModel);
    TableRowSorter<TableModel> sorter = new TableRowSorter<TableModel>(extensionsTableModel);
    sorter.setComparator(2, new ObjectIdComparator());
    jtExtensions.setRowSorter(sorter);
    jtExtensions.setShowGrid(false);
    jtExtensions.setRowMargin(0);
    jtExtensions.getColumnModel().setColumnMargin(0);
    jtExtensions.getTableHeader().setReorderingAllowed(false);
    jtExtensions.setAutoResizeMode(JKseTable.AUTO_RESIZE_ALL_COLUMNS);
    jtExtensions.setRowHeight(Math.max(18, jtExtensions.getRowHeight()));
    for (int i = 0; i < jtExtensions.getColumnCount(); i++) {
        TableColumn column = jtExtensions.getColumnModel().getColumn(i);
        column.setHeaderRenderer(new ExtensionsTableHeadRend(jtExtensions.getTableHeader().getDefaultRenderer()));
        column.setCellRenderer(new ExtensionsTableCellRend());
    }
    TableColumn criticalCol = jtExtensions.getColumnModel().getColumn(0);
    criticalCol.setResizable(false);
    criticalCol.setMinWidth(28);
    criticalCol.setMaxWidth(28);
    criticalCol.setPreferredWidth(28);
    ListSelectionModel selectionModel = jtExtensions.getSelectionModel();
    selectionModel.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    selectionModel.addListSelectionListener(new ListSelectionListener() {

        @Override
        public void valueChanged(ListSelectionEvent evt) {
            if (!evt.getValueIsAdjusting()) {
                try {
                    CursorUtil.setCursorBusy(DViewExtensions.this);
                    updateExtensionValue();
                } finally {
                    CursorUtil.setCursorFree(DViewExtensions.this);
                }
            }
        }
    });
    jspExtensionsTable = PlatformUtil.createScrollPane(jtExtensions, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
    jspExtensionsTable.getViewport().setBackground(jtExtensions.getBackground());
    jpExtensionsTable = new JPanel(new BorderLayout(5, 5));
    jpExtensionsTable.setPreferredSize(new Dimension(500, 200));
    jpExtensionsTable.add(jspExtensionsTable, BorderLayout.CENTER);
    jpExtensionValue = new JPanel(new BorderLayout(5, 5));
    jlExtensionValue = new JLabel(res.getString("DViewExtensions.jlExtensionValue.text"));
    jpExtensionValue.add(jlExtensionValue, BorderLayout.NORTH);
    jepExtensionValue = new JEditorPane();
    jepExtensionValue.setFont(new Font(Font.MONOSPACED, Font.PLAIN, LnfUtil.getDefaultFontSize()));
    jepExtensionValue.setEditable(false);
    jepExtensionValue.setToolTipText(res.getString("DViewExtensions.jtaExtensionValue.tooltip"));
    // JGoodies - keep uneditable color same as editable
    jepExtensionValue.putClientProperty("JTextArea.infoBackground", Boolean.TRUE);
    // for displaying URLs in extensions as clickable links
    jepExtensionValue.setContentType("text/html");
    jepExtensionValue.addHyperlinkListener(this);
    // use default font and foreground color from the component
    jepExtensionValue.putClientProperty(JEditorPane.HONOR_DISPLAY_PROPERTIES, Boolean.TRUE);
    jspExtensionValue = PlatformUtil.createScrollPane(jepExtensionValue, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    jpExtensionValueTextArea = new JPanel(new BorderLayout(5, 5));
    jpExtensionValueTextArea.setPreferredSize(new Dimension(500, 200));
    jpExtensionValueTextArea.add(jspExtensionValue, BorderLayout.CENTER);
    jpExtensionValue.add(jpExtensionValueTextArea, BorderLayout.CENTER);
    jbAsn1 = new JButton(res.getString("DViewExtensions.jbAsn1.text"));
    PlatformUtil.setMnemonic(jbAsn1, res.getString("DViewExtensions.jbAsn1.mnemonic").charAt(0));
    jbAsn1.setToolTipText(res.getString("DViewExtensions.jbAsn1.tooltip"));
    jbAsn1.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent evt) {
            try {
                CursorUtil.setCursorBusy(DViewExtensions.this);
                asn1DumpPressed();
            } finally {
                CursorUtil.setCursorFree(DViewExtensions.this);
            }
        }
    });
    jpExtensionValueAsn1 = new JPanel(new FlowLayout(FlowLayout.RIGHT));
    jpExtensionValueAsn1.add(jbAsn1);
    jpExtensionValue.add(jpExtensionValueAsn1, BorderLayout.SOUTH);
    jpExtensions = new JPanel(new GridLayout(2, 1, 5, 5));
    jpExtensions.setBorder(new CompoundBorder(new EmptyBorder(5, 5, 5, 5), new CompoundBorder(new EtchedBorder(), new EmptyBorder(5, 5, 5, 5))));
    jpExtensions.add(jpExtensionsTable);
    jpExtensions.add(jpExtensionValue);
    jbOK = new JButton(res.getString("DViewExtensions.jbOK.text"));
    jbOK.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent evt) {
            okPressed();
        }
    });
    jpOK = PlatformUtil.createDialogButtonPanel(jbOK, false);
    extensionsTableModel.load(extensions);
    if (extensionsTableModel.getRowCount() > 0) {
        jtExtensions.changeSelection(0, 0, false, false);
    }
    getContentPane().add(jpExtensions, 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) FlowLayout(java.awt.FlowLayout) ActionEvent(java.awt.event.ActionEvent) ListSelectionEvent(javax.swing.event.ListSelectionEvent) JButton(javax.swing.JButton) WindowAdapter(java.awt.event.WindowAdapter) ObjectIdComparator(org.kse.utilities.oid.ObjectIdComparator) Font(java.awt.Font) GridLayout(java.awt.GridLayout) BorderLayout(java.awt.BorderLayout) CompoundBorder(javax.swing.border.CompoundBorder) EmptyBorder(javax.swing.border.EmptyBorder) TableRowSorter(javax.swing.table.TableRowSorter) JKseTable(org.kse.gui.JKseTable) ListSelectionModel(javax.swing.ListSelectionModel) JLabel(javax.swing.JLabel) Dimension(java.awt.Dimension) TableColumn(javax.swing.table.TableColumn) ListSelectionListener(javax.swing.event.ListSelectionListener) EtchedBorder(javax.swing.border.EtchedBorder) ActionListener(java.awt.event.ActionListener) WindowEvent(java.awt.event.WindowEvent) JEditorPane(javax.swing.JEditorPane) 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