Java Code Examples for org.netbeans.swing.tabcontrol.TabbedContainer

The following examples show how to use org.netbeans.swing.tabcontrol.TabbedContainer. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: netbeans   Source File: DefaultTabbedContainerUI.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Fills contentDisplayer container with components retrieved from model.
 */
protected void initDisplayer() {
    if (container.getContentPolicy() == TabbedContainer.CONTENT_POLICY_ADD_ALL) {
        List tabs = container.getModel().getTabs();
        Component curC = null;
        for (Iterator iter = tabs.iterator(); iter.hasNext();) {
            curC = toComp ((TabData) iter.next());
            // string parameter is needed for StackLayout to kick in correctly
            contentDisplayer.add(curC, "");
        }
    } else {
        int i = tabDisplayer.getSelectionModel().getSelectedIndex();
        if (i != -1) {
            TabData td = container.getModel().getTab(i);
            contentDisplayer.add(toComp(td), "");
        }
    }
    updateActiveState();
}
 
Example 2
Source Project: netbeans   Source File: DefaultTabbedContainerUI.java    License: Apache License 2.0 6 votes vote down vote up
public void hierarchyChanged(HierarchyEvent e) {
    if ((e.getChangeFlags() & HierarchyEvent.SHOWING_CHANGED) != 0) {
        boolean showing = container.isShowing();
        if (showing != bug4924561knownShowing) {
            if (container.isShowing()) {
                initDisplayer();
                attachModelAndSelectionListeners();
                ensureSelectedComponentIsShowing();
                if (container.getType() == TabbedContainer.TYPE_SLIDING) {
                    updateOrientation();
                }
            } else {
                detachModelAndSelectionListeners();
                if (container.getType() == TabbedContainer.TYPE_SLIDING) {
                    updateOrientation();
                }
            }
        }
        bug4924561knownShowing = showing;
    }
}
 
Example 3
Source Project: netbeans   Source File: AbstractViewTabDisplayerUI.java    License: Apache License 2.0 6 votes vote down vote up
/** Registers shortcut for enable/ disable auto-hide functionality */
@Override
public void registerShortcuts(JComponent comp) {
    comp.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).
        put(KeyStroke.getKeyStroke(KeyEvent.VK_BACK_SPACE,
                            InputEvent.CTRL_DOWN_MASK), PIN_ACTION);
    comp.getActionMap().put(PIN_ACTION, pinAction);

    //TODO make shortcut configurable
    comp.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).
        put(KeyStroke.getKeyStroke(KeyEvent.VK_NUMPAD0,
                            InputEvent.CTRL_DOWN_MASK), TRANSPARENCY_ACTION);
    comp.getActionMap().put(TRANSPARENCY_ACTION, new AbstractAction() {
        @Override
        public void actionPerformed(ActionEvent e) {
            shouldPerformAction(TabbedContainer.COMMAND_TOGGLE_TRANSPARENCY, getSelectionModel().getSelectedIndex(), null);
        }
    });
}
 
Example 4
Source Project: netbeans   Source File: ButtonFactory.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Creates button to maximize currently selected document in the given tab displayer.
 * @param controller Tab displayer's controller.
 * @return Button to maximize selected document tab.
 */
public static JButton createMaximizeButton( final Controller controller ) {
    final JButton btn = new JButton();
    Icon icon = UIManager.getIcon("nb.multitabs.button.maximize.icon");
    if (icon == null) {
        icon = ImageUtilities.loadImageIcon( "org/netbeans/core/multitabs/resources/maximize.png", true ); //NOI18N
    }
    btn.setIcon( icon );
    btn.setToolTipText( NbBundle.getMessage(ButtonFactory.class, "Hint_MaximizeRestore") );
    btn.addActionListener( new ActionListener() {

        @Override
        public void actionPerformed( ActionEvent e ) {
            controller.postActionEvent( new TabActionEvent( btn, TabbedContainer.COMMAND_MAXIMIZE, -1 ) );
        }
    });
    btn.setFocusable( false );
    return btn;
}
 
Example 5
Source Project: netbeans   Source File: TopComponentOperator.java    License: Apache License 2.0 6 votes vote down vote up
/** Makes top component active and pushes given menu on its tab.
 * @param popupPath menu path separated by '|' (e.g. "CVS|Refresh")
 */
public void pushMenuOnTab(String popupPath) {
    if (isOpened()) {
        this.makeComponentVisible();
        TabbedContainer ta = findTabbedAdapter();

        int index = ta.indexOf((TopComponent) getSource());

        Rectangle r = new Rectangle();
        ta.getTabRect(index, r);
        Point p = new Point(r.x + (r.width / 2), r.y + (r.height / 2));
        Component tabsComp = ta.getComponentAt(p);
        new JPopupMenuOperator(JPopupMenuOperator.callPopup(tabsComp, p.x, p.y)).pushMenu(popupPath);
    } else {
        // try to find enclosing MultiviewTopComponent
        TopComponentOperator parent = findParentTopComponent();
        if (parent != null) {
            parent.pushMenuOnTab(popupPath);
        }
    }
}
 
Example 6
Source Project: netbeans   Source File: TabbedContainerBridgeImpl.java    License: Apache License 2.0 5 votes vote down vote up
public Object[] getItems(JComponent jc) {
    TabbedContainer cont = (TabbedContainer) jc;
    List l = cont.getModel().getTabs();
    Object[] items = new Object[l.size()];
    for (int i=0; i < items.length; i++) {
        items[i] = ((TabData) l.get(i)).getUserObject();
    }
    return items;
}
 
Example 7
Source Project: netbeans   Source File: TabbedContainerBridgeImpl.java    License: Apache License 2.0 5 votes vote down vote up
public Object getSelectedItem(JComponent jc) {
    Object result = null;
    TabbedContainer cont = (TabbedContainer) jc;
    int i = cont.getSelectionModel().getSelectedIndex();
    if (i != -1) {
        result = cont.getModel().getTab(i).getUserObject();
    }
    return result;
}
 
Example 8
Source Project: netbeans   Source File: TabbedContainerBridgeImpl.java    License: Apache License 2.0 5 votes vote down vote up
public void setSelectedItem(JComponent jc, Object selection) {
    TabbedContainer cont = (TabbedContainer) jc;
    TabDataModel mdl = cont.getModel();
    int max = mdl.size();
    for (int i=0; i < max; i++) {
        TabData td = mdl.getTab(i);
        if (td.getUserObject() == selection) {
            cont.getSelectionModel().setSelectedIndex(i);
            break;
        }
    }
}
 
Example 9
Source Project: netbeans   Source File: TabbedContainerBridgeImpl.java    License: Apache License 2.0 5 votes vote down vote up
public boolean setSelectionByName(JComponent jc, String tabname) {
    TabbedContainer cont = (TabbedContainer) jc;
    TabDataModel mdl = cont.getModel();
    int max = mdl.size();
    for (int i=0; i < max; i++) {
        TabData td = mdl.getTab(i);
        if (tabname.equals(td.getText())) {
            cont.getSelectionModel().setSelectedIndex(i);
            return true;
        }
    }
    return false;
}
 
Example 10
Source Project: netbeans   Source File: TabbedContainerBridgeImpl.java    License: Apache License 2.0 5 votes vote down vote up
public String getCurrentSelectedTabName(JComponent jc) {
    TabbedContainer cont = (TabbedContainer) jc;
    int sel = cont.getSelectionModel().getSelectedIndex();
    if (sel != -1) {
        TabData td = cont.getModel().getTab(sel);
        return td.getText();
    }
    return null;
}
 
Example 11
Source Project: netbeans   Source File: DefaultTabbedContainerUI.java    License: Apache License 2.0 5 votes vote down vote up
/** Sets the active state of the displayer to match that of the container */
private void updateActiveState() {
    //#45630 - more of a hack than a fix.
    //apparently uninstallUI() was called before the the ContainerPropertyChangeListener instance was removed in 
    //ContainerHierarchyListener's hierarchyChanged method.
    // for such case the property change should be a noop.
    TabDisplayer displ = tabDisplayer;
    TabbedContainer cont = container;
    if (displ != null && cont != null) {
        displ.setActive(cont.isActive());
    }
    
}
 
Example 12
Source Project: netbeans   Source File: DefaultTabbedContainerUI.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * DefaultTabDataModel will always call this method with an instance of
 * ComplexListDataEvent.
 */
public void contentsChanged(ListDataEvent e) {
    //Only need to reread components on setTab (does winsys even use it?)
    if (e instanceof ComplexListDataEvent) {
        ComplexListDataEvent clde = (ComplexListDataEvent) e;
        int index = clde.getIndex0();
        if (clde.isUserObjectChanged() && index != -1) {
            Component comp = contentDisplayer.getComponent(
                    index);
            Component nue = toComp(tabDisplayer.getModel().getTab(index));
            contentDisplayer.remove(comp);
            
            boolean add = 
                container.getContentPolicy() == 
                TabbedContainer.CONTENT_POLICY_ADD_ALL || 
                index == 
                container.getSelectionModel().getSelectedIndex();
            
            if (add) {
                contentDisplayer.add(nue, index);
            }
        }
        if (clde.isTextChanged()) {
            maybeMakeSelectedTabVisible(clde);
        }
    }
}
 
Example 13
Source Project: netbeans   Source File: DefaultTabbedContainerUI.java    License: Apache License 2.0 5 votes vote down vote up
public void intervalAdded(ListDataEvent e) {
    if (container.getContentPolicy() == TabbedContainer.CONTENT_POLICY_ADD_ALL) {
        Component curC = null;
        for (int i = e.getIndex0(); i <= e.getIndex1(); i++) {
            curC = toComp(container.getModel().getTab(i));
            contentDisplayer.add(curC, "");
        }
    }
}
 
Example 14
Source Project: netbeans   Source File: DefaultTabbedContainerUI.java    License: Apache License 2.0 5 votes vote down vote up
public void indicesAdded(ComplexListDataEvent e) {
    Component curC = null;
    if (container.getContentPolicy() == TabbedContainer.CONTENT_POLICY_ADD_ALL) {
        int[] indices = e.getIndices();
        for (int i = 0; i < indices.length; i++) {
            curC = toComp(container.getModel().getTab(indices[i]));
            contentDisplayer.add(curC, "");
        }
    }
}
 
Example 15
Source Project: netbeans   Source File: DesktopImpl.java    License: Apache License 2.0 5 votes vote down vote up
private Component findTabbed( Component comp ) {
    while( comp.getParent() != null ) {
        if( comp.getParent() instanceof TabbedContainer ) {
            return comp.getParent();
        }
        comp = comp.getParent();
    }
    return null;
}
 
Example 16
Source Project: netbeans   Source File: TabbedSlideAdapter.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public Image createImageOfTab(int tabIndex) {
    TabData dt = slideBar.getModel().getTab(tabIndex);
    if (dt.getComponent() instanceof TopComponent) {
        DefaultTabDataModel tempModel = new DefaultTabDataModel( new TabData[] { dt } );
        TabbedContainer temp = new TabbedContainer( tempModel, TabbedContainer.TYPE_VIEW );
        temp.setSize( 300,300 );
        
        return temp.createImageOfTab(0);
    }
    
    return null;
}
 
Example 17
Source Project: netbeans   Source File: Controller.java    License: Apache License 2.0 5 votes vote down vote up
private void maybeShowPopup( MouseEvent e ) {
    if( !e.isPopupTrigger() )
        return;
    Point p = e.getPoint();
    p = SwingUtilities.convertPoint( e.getComponent(), p, displayer );
    TabData tab = displayer.getTabAt( p );
    if( null == tab )
        return;
    final int tabIndex = tabModel.indexOf( tab );
    //popup menu
    TabActionEvent tae = new TabActionEvent( this, TabbedContainer.COMMAND_POPUP_REQUEST, tabIndex, e );
    postActionEvent( tae );
}
 
Example 18
Source Project: netbeans   Source File: DocumentSwitcherTable.java    License: Apache License 2.0 5 votes vote down vote up
boolean onMouseEvent( MouseEvent e ) {
    Point p = e.getPoint();
    p = SwingUtilities.convertPoint((Component) e.getSource(), p, this);
    int selRow = getSelectedRow();
    int selCol = getSelectedColumn();
    if( selRow < 0 || selCol < 0 )
        return false;
    Rectangle rect = getCellRect( selRow, selCol, false );
    if( rect.contains( p ) ) {
        Dimension size = btnClose.getPreferredSize();
        int x = rect.x+rect.width-size.width;
        int y = rect.y + (rect.height-size.height)/2;
        Rectangle btnRect = new Rectangle( x, y, size.width, size.height);
        boolean inButton = btnRect.contains( p );
        boolean mustRepaint = inCloseButtonRect != inButton;
        inCloseButtonRect = inButton;
        if( inButton ) {
            if( e.getID() == MouseEvent.MOUSE_PRESSED ) {
                Item item = ( Item ) getModel().getValueAt( selRow, selCol );
                TabData tab = item.getTabData();
                int tabIndex = controller.getTabModel().indexOf( tab );
                if( tabIndex >= 0 ) {
                    TabActionEvent tae = new TabActionEvent( this, TabbedContainer.COMMAND_CLOSE, tabIndex );
                    controller.postActionEvent( tae );
                    return true;
                }
            }
        }
        if( mustRepaint && lastRow == selRow && lastCol == selCol )
            repaint( btnRect );
        lastCol = selCol;
        lastRow = selRow;
        return inButton;
    }
    return false;
}
 
Example 19
Source Project: netbeans   Source File: CloseButtonHandler.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void mouseClicked( MouseEvent e ) {
    if( e.getSource() instanceof TabTable ) {
        TabTable table = ( TabTable ) e.getSource();
        if( !table.isShowing() )
            return;
        Point p = e.getPoint();
        int row = table.rowAtPoint( p );
        int col = table.columnAtPoint( p );
        if( row >= 0 && col >= 0 ) {
            if( table.isCloseButtonHighlighted( row, col ) ) {
                TabData tab = table.getTabAt( p );
                if( null != tab ) {
                    int tabIndex = displayer.getModel().indexOf( tab );
                    if( tabIndex >= 0 && e.getButton() == MouseEvent.BUTTON1 ) {
                        TabActionEvent tae = null;
                        if( (e.getModifiersEx()& MouseEvent.SHIFT_DOWN_MASK) > 0 ) {
                            tae = new TabActionEvent( displayer, TabbedContainer.COMMAND_CLOSE_ALL, tabIndex );
                        } else if( (e.getModifiersEx()& MouseEvent.ALT_DOWN_MASK) > 0  ) {
                            tae = new TabActionEvent( displayer, TabbedContainer.COMMAND_CLOSE_ALL_BUT_THIS, tabIndex );
                        } else {
                            tae = new TabActionEvent( displayer, TabbedContainer.COMMAND_CLOSE, tabIndex );
                        }
                        if( null != tae )
                            controller.postActionEvent( tae );
                    }
                }
            }
        }
    }
}
 
Example 20
Source Project: netbeans   Source File: TopComponentOperator.java    License: Apache License 2.0 5 votes vote down vote up
/** Returns TabbedAdapter component from parents hierarchy.
 * Used also in EditorWindowOperator.
 */
public TabbedContainer findTabbedAdapter() {
    Container parent = getSource().getParent();
    while (parent != null) {
        if (parent instanceof TabbedContainer) { // NOI18N
            return (TabbedContainer) parent;
        } else {
            parent = parent.getParent();
        }
    }
    return null;
}
 
Example 21
private void initComponents() {
    setLayout(new BorderLayout());

    DefaultTabDataModel tabDataModel = new DefaultTabDataModel();
    tabbedContainer = new TabbedContainer(tabDataModel,
                                          TabbedContainer.TYPE_EDITOR,
                                          WinsysInfoForTabbedContainer.getDefault(new MyWinsysInfoForTabbedContainer()));
    tabbedContainer.setVisible(false);

    desktopPane = new JDesktopPane();

    add(tabbedContainer, BorderLayout.NORTH);
    add(desktopPane, BorderLayout.CENTER);
}
 
Example 22
Source Project: netbeans   Source File: TabbedContainerBridgeImpl.java    License: Apache License 2.0 4 votes vote down vote up
public void attachSelectionListener(JComponent jc, ChangeListener listener) {
    TabbedContainer cont = (TabbedContainer) jc;
    cont.getSelectionModel().addChangeListener(listener);
}
 
Example 23
Source Project: netbeans   Source File: TabbedContainerBridgeImpl.java    License: Apache License 2.0 4 votes vote down vote up
public JComponent createTabbedContainer() {
    return new TabbedContainer(TabbedContainer.TYPE_TOOLBAR);
}
 
Example 24
Source Project: netbeans   Source File: TabbedContainerBridgeImpl.java    License: Apache License 2.0 4 votes vote down vote up
public void detachSelectionListener(JComponent jc, ChangeListener listener) {
    TabbedContainer cont = (TabbedContainer) jc;
    cont.getSelectionModel().removeChangeListener(listener);
}
 
Example 25
Source Project: netbeans   Source File: TabbedContainerBridgeImpl.java    License: Apache License 2.0 4 votes vote down vote up
public void setInnerComponent(JComponent jc, JComponent inner) {
    TabbedContainer cont = (TabbedContainer) jc;
    ComponentConverter cc = new ComponentConverter.Fixed (inner);
    cont.setComponentConverter(cc);
}
 
Example 26
Source Project: netbeans   Source File: TabbedContainerBridgeImpl.java    License: Apache License 2.0 4 votes vote down vote up
public JComponent getInnerComponent(JComponent jc) {
    TabbedContainer cont = (TabbedContainer) jc;
    return (JComponent) cont.getComponentConverter().getComponent(null);
}
 
Example 27
Source Project: netbeans   Source File: DefaultTabbedContainerUI.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * Creates a new instance of DefaultTabbedContainerUI
 */
public DefaultTabbedContainerUI(TabbedContainer c) {
    super(c);
}
 
Example 28
Source Project: netbeans   Source File: DefaultTabbedContainerUI.java    License: Apache License 2.0 4 votes vote down vote up
public static ComponentUI createUI(JComponent c) {
    return new DefaultTabbedContainerUI((TabbedContainer) c);
}
 
Example 29
Source Project: netbeans   Source File: DefaultTabbedContainerUI.java    License: Apache License 2.0 4 votes vote down vote up
public void propertyChange(PropertyChangeEvent evt) {
    if (TabbedContainer.PROP_ACTIVE.equals(evt.getPropertyName())) {
        updateActiveState();
    }
}
 
Example 30
Source Project: netbeans   Source File: DefaultTabbedContainerUI.java    License: Apache License 2.0 4 votes vote down vote up
/** Checks the position of the tabbed container relative to its parent
 * window, and potentially updates its orientation client property.
 *
 * @see TabDisplayer#PROP_ORIENTATION
 */
protected final void updateOrientation() {
    if (!container.isDisplayable()) {
        return;
    }
    if (Boolean.FALSE.equals(container.getClientProperty (TabbedContainer.PROP_MANAGE_TAB_POSITION))) {
        //The client has specified that it does not want automatic management
        //of the displayer orientation
        return;
    }
    Object currOrientation = tabDisplayer.getClientProperty(TabDisplayer.PROP_ORIENTATION);
    Container window = container.getTopLevelAncestor();

    Rectangle containerBounds = container.getBounds();
    containerBounds = SwingUtilities.convertRectangle(container, containerBounds, window);

    boolean longestIsVertical = containerBounds.width < containerBounds.height;

    int distanceToLeft = containerBounds.x;
    int distanceToTop = containerBounds.y;
    int distanceToRight = window.getWidth() - (containerBounds.x + containerBounds.width);
    int distanceToBottom = window.getHeight() - (containerBounds.y + containerBounds.height);

    Object orientation;
    if (!longestIsVertical) {
        if (distanceToBottom > distanceToTop) {
            orientation = TabDisplayer.ORIENTATION_NORTH;
        } else {
            orientation = TabDisplayer.ORIENTATION_SOUTH;
        }
    } else {
        if (distanceToLeft > distanceToRight) {
            orientation = TabDisplayer.ORIENTATION_EAST;
        } else {
            orientation = TabDisplayer.ORIENTATION_WEST;
        }
    }

    if (currOrientation != orientation) {
        tabDisplayer.putClientProperty(
            TabDisplayer.PROP_ORIENTATION, orientation);
        container.validate();
    }
}