Search in sources :

Example 1 with SwitcherTableItem

use of org.netbeans.swing.popupswitcher.SwitcherTableItem in project netbeans-rcp-lite by outersky.

the class DocumentSwitcherTable method prepareRenderer.

@Override
public Component prepareRenderer(TableCellRenderer renderer, int row, int column) {
    SwitcherTableItem item = (SwitcherTableItem) getModel().getValueAt(row, column);
    boolean selected = row == getSelectedRow() && column == getSelectedColumn() && item != null;
    Component renComponent = super.prepareRenderer(renderer, row, column);
    if (selected && isClosable((Item) item)) {
        if (renComponent instanceof JLabel) {
            String text = ((JLabel) renComponent).getText();
            if (text.endsWith(" ←")) {
                // NOI18N
                text = text.substring(0, text.length() - 2);
                ((JLabel) renComponent).setText(text);
            }
        }
        JPanel res = new JPanel(new BorderLayout(0, 0));
        res.add(renComponent, BorderLayout.CENTER);
        res.add(btnClose, BorderLayout.EAST);
        res.setBackground(renComponent.getBackground());
        return res;
    }
    return renComponent;
}
Also used : SwitcherTableItem(org.netbeans.swing.popupswitcher.SwitcherTableItem) SwitcherTableItem(org.netbeans.swing.popupswitcher.SwitcherTableItem) TopComponent(org.openide.windows.TopComponent)

Example 2 with SwitcherTableItem

use of org.netbeans.swing.popupswitcher.SwitcherTableItem in project netbeans-rcp-lite by outersky.

the class ButtonPopupSwitcher method mouseClicked.

@Override
public void mouseClicked(MouseEvent e) {
    Point p = e.getPoint();
    p = SwingUtilities.convertPoint((Component) e.getSource(), p, pTable);
    if (pTable.contains(p)) {
        if (!pTable.onMouseEvent(e)) {
            final SwitcherTableItem item = pTable.getSelectedItem();
            if (item != null) {
                hideCurrentPopup();
                item.activate();
            }
        }
    }
    isDragging = false;
    e.consume();
}
Also used : Point(java.awt.Point) SwitcherTableItem(org.netbeans.swing.popupswitcher.SwitcherTableItem) JComponent(javax.swing.JComponent) TopComponent(org.openide.windows.TopComponent) Component(java.awt.Component)

Example 3 with SwitcherTableItem

use of org.netbeans.swing.popupswitcher.SwitcherTableItem in project netbeans-rcp-lite by outersky.

the class DocumentSwitcherTable method getToolTipText.

@Override
public String getToolTipText(MouseEvent event) {
    int row = rowAtPoint(event.getPoint());
    int col = columnAtPoint(event.getPoint());
    if (row >= 0 && col <= 0) {
        SwitcherTableItem item = (SwitcherTableItem) getModel().getValueAt(row, col);
        return item.getDescription();
    }
    return null;
}
Also used : SwitcherTableItem(org.netbeans.swing.popupswitcher.SwitcherTableItem)

Example 4 with SwitcherTableItem

use of org.netbeans.swing.popupswitcher.SwitcherTableItem in project netbeans-rcp-lite by outersky.

the class ButtonPopupSwitcher method changeSelection.

/**
 * Allow keyboard navigation in document dropdown list.
 *
 * @param event
 * @return
 */
private boolean changeSelection(KeyEvent event) {
    int key = event.getKeyCode();
    int selRow = pTable.getSelectedRow();
    int selCol = pTable.getSelectedColumn();
    if (selRow < 0)
        selRow = 0;
    if (selCol < 0)
        selCol = 0;
    boolean switched = true;
    switch(key) {
        case KeyEvent.VK_LEFT:
            selCol--;
            if (selCol < 0) {
                selCol = pTable.getColumnCount() - 1;
            }
            break;
        case KeyEvent.VK_RIGHT:
            selCol++;
            if (selCol > pTable.getColumnCount() - 1) {
                selCol = 0;
            }
            break;
        case KeyEvent.VK_DOWN:
            selRow++;
            if (selRow > pTable.getRowCount() - 1) {
                selCol++;
                selRow = 0;
                if (selCol > pTable.getColumnCount() - 1) {
                    selCol = 0;
                }
            }
            break;
        case KeyEvent.VK_UP:
            selRow--;
            if (selRow < 0) {
                selCol--;
                selRow = pTable.getRowCount() - 1;
                if (selCol < 0) {
                    selCol = pTable.getColumnCount() - 1;
                }
            }
            break;
        case KeyEvent.VK_DELETE:
            {
                Item item = (Item) pTable.getModel().getValueAt(selRow, selCol);
                if (null != item && pTable.isClosable(item)) {
                    TabData tab = item.getTabData();
                    int tabIndex = displayer.getModel().indexOf(tab);
                    if (tabIndex >= 0) {
                        if (displayer.getModel().size() == 1) {
                            SwingUtilities.invokeLater(new Runnable() {

                                @Override
                                public void run() {
                                    hideCurrentPopup();
                                }
                            });
                        }
                        TabActionEvent evt = new TabActionEvent(displayer, TabDisplayer.COMMAND_CLOSE, tabIndex);
                        displayer.postActionEvent(evt);
                        selRow = Math.min(pTable.getModel().getRowCount() - 1, selRow);
                        selCol = Math.min(pTable.getModel().getColumnCount() - 1, selCol);
                        switched = true;
                    }
                }
                break;
            }
        case KeyEvent.VK_ENTER:
            final SwitcherTableItem item = pTable.getSelectedItem();
            if (item != null) {
                item.activate();
                hideCurrentPopup();
            }
            break;
        default:
            switched = false;
    }
    if (switched) {
        pTable.changeSelection(selRow, selCol, false, false);
    }
    return switched;
}
Also used : TabActionEvent(org.netbeans.swing.tabcontrol.event.TabActionEvent) Item(org.netbeans.swing.tabcontrol.DocumentSwitcherTable.Item) SwitcherTableItem(org.netbeans.swing.popupswitcher.SwitcherTableItem) SwitcherTableItem(org.netbeans.swing.popupswitcher.SwitcherTableItem) Point(java.awt.Point)

Aggregations

SwitcherTableItem (org.netbeans.swing.popupswitcher.SwitcherTableItem)4 Point (java.awt.Point)2 TopComponent (org.openide.windows.TopComponent)2 Component (java.awt.Component)1 JComponent (javax.swing.JComponent)1 Item (org.netbeans.swing.tabcontrol.DocumentSwitcherTable.Item)1 TabActionEvent (org.netbeans.swing.tabcontrol.event.TabActionEvent)1