Search in sources :

Example 1 with Item

use of org.netbeans.swing.tabcontrol.DocumentSwitcherTable.Item in project netbeans-rcp-lite by outersky.

the class ButtonPopupSwitcher method createSwitcherItems.

private Item[] createSwitcherItems(final TabDisplayer displayer) {
    java.util.List<TabData> tabs = displayer.getModel().getTabs();
    Item[] items = new Item[tabs.size()];
    int i = 0;
    int selIdx = displayer.getSelectionModel().getSelectedIndex();
    TabData selectedTab = selIdx >= 0 ? displayer.getModel().getTab(selIdx) : null;
    for (TabData tab : tabs) {
        String name;
        String htmlName;
        if (tab.getComponent() instanceof TopComponent) {
            TopComponent tabTC = (TopComponent) tab.getComponent();
            name = tabTC.getDisplayName();
            // #68291 fix - some hostile top components have null display name
            if (name == null) {
                name = tabTC.getName();
            }
            htmlName = tabTC.getHtmlDisplayName();
            if (htmlName == null) {
                htmlName = name;
            }
        } else {
            name = htmlName = tab.getText();
        }
        items[i++] = new Item(new ActivatableTab(tab), name, htmlName, tab, tab == selectedTab);
    }
    return items;
}
Also used : Item(org.netbeans.swing.tabcontrol.DocumentSwitcherTable.Item) SwitcherTableItem(org.netbeans.swing.popupswitcher.SwitcherTableItem) Point(java.awt.Point) TopComponent(org.openide.windows.TopComponent)

Example 2 with Item

use of org.netbeans.swing.tabcontrol.DocumentSwitcherTable.Item in project netbeans-rcp-lite by outersky.

the class ButtonPopupSwitcher method changed.

private void changed() {
    if (!isShown())
        return;
    Item[] items = createSwitcherItems(displayer);
    if (items.length == 0) {
        hideCurrentPopup();
        return;
    }
    Arrays.sort(items);
    pTable.setSwitcherItems(items, y);
    popup.pack();
    int locationX = x - (int) pTable.getPreferredSize().getWidth();
    int locationY = y + 1;
    popup.setLocation(locationX, locationY);
}
Also used : Item(org.netbeans.swing.tabcontrol.DocumentSwitcherTable.Item) SwitcherTableItem(org.netbeans.swing.popupswitcher.SwitcherTableItem) Point(java.awt.Point)

Example 3 with Item

use of org.netbeans.swing.tabcontrol.DocumentSwitcherTable.Item 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

Point (java.awt.Point)3 SwitcherTableItem (org.netbeans.swing.popupswitcher.SwitcherTableItem)3 Item (org.netbeans.swing.tabcontrol.DocumentSwitcherTable.Item)3 TabActionEvent (org.netbeans.swing.tabcontrol.event.TabActionEvent)1 TopComponent (org.openide.windows.TopComponent)1