org.netbeans.swing.tabcontrol.TabData Java Examples

The following examples show how to use org.netbeans.swing.tabcontrol.TabData. 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 File: ProjectColorTabDecorator.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public Color getBackground( TabData tab, boolean selected ) {
    if( selected || !Settings.getDefault().isSameProjectSameColor() )
        return null;
    Color res = null;
    synchronized( tab2color ) {
        res = tab2color.get( tab );
        if( null == res ) {
            res = getColorForTab( tab );
            if( null != res ) {
                tab2color.put( tab, res );
            }
        }
    }
    return res;
}
 
Example #2
Source File: DefaultTabbedContainerUI.java    From netbeans with 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 #3
Source File: SimpleTabDisplayer.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public int dropIndexOfPoint( Point location ) {
    int res = -1;
    location = SwingUtilities.convertPoint( this, location, table );
    TabData tab = table.getTabAt( location );
    if( null != tab ) {
        res = getModel().indexOf( tab );
        Rectangle rect = getTabBounds( res );
        rect = SwingUtilities.convertRectangle( this, rect, table );
        if( orientation == JTabbedPane.VERTICAL ) {
            if( location.y <= rect.y + rect.height/2 ) {
                res = Math.max( 0, res );
            } else {
                res++;
            }
        } else {
            if( location.x <= rect.x + rect.width/2 ) {
                res = Math.max( 0, res );
            } else {
                res++;
            }
        }
    }
    return res;
}
 
Example #4
Source File: AbstractViewTabDisplayerUI.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/** Paints the rectangle occupied by a tab into an image and returns the result */
@Override
public Image createImageOfTab(int index) {
    TabData td = displayer.getModel().getTab(index);
    
    JLabel lbl = new JLabel(td.getText());
    int width = lbl.getFontMetrics(lbl.getFont()).stringWidth(td.getText());
    int height = lbl.getFontMetrics(lbl.getFont()).getHeight();
    width = width + td.getIcon().getIconWidth() + 6;
    height = Math.max(height, td.getIcon().getIconHeight()) + 5;
    
    BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
    Graphics2D g = image.createGraphics();
    g.setColor(lbl.getForeground());
    g.setFont(lbl.getFont());
    td.getIcon().paintIcon(lbl, g, 0, 0);
    g.drawString(td.getText(), 18, height / 2);
    
    
    return image;
}
 
Example #5
Source File: CakePHPTabDecorator.java    From cakephp3-netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public String getText(TabData tab) {
    // show a parent directory name if it's a view file
    // e.g. home.ctp [Pages]
    String text = tab.getText();
    if (text.endsWith(".ctp")) { // NOI18N
        Component component = tab.getComponent();
        if (component instanceof TopComponent) {
            TopComponent topComponent = (TopComponent) component;
            Lookup lookup = topComponent.getLookup();
            if (lookup != null) {
                FileObject fileObject = lookup.lookup(FileObject.class);
                if (fileObject != null) {
                FileObject parent = fileObject.getParent();
                    if (parent != null) {
                        String parentName = parent.getName();
                        return String.format("%s [%s]", text, parentName); // NOI18N
                    }
                }
            }
        }
    }
    return super.getText(tab);
}
 
Example #6
Source File: BasicScrollingTabDisplayerUI.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public void makeTabVisible (int tab) {
    if( tab < 0 ) //#219681 - nobody has set the selected tab yet
        return;
    if (scroll().makeVisible(tab, getTabsAreaWidth())) {
        getTabsVisibleArea(scratch);
        displayer.repaint(scratch.x, scratch.y, scratch.width, scratch.height);
    }

    if( null == btnMaximizeRestore )
        return;
    TabData td = displayer.getModel().getTab(tab);
    Component c = td.getComponent();
    if( !(c instanceof TopComponent) )
        return;
    boolean maximizeEnabled = displayer.getContainerWinsysInfo().isTopComponentMaximizationEnabled((TopComponent)c);
    btnMaximizeRestore.setEnabled(maximizeEnabled);
}
 
Example #7
Source File: ArrayDiff.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the indices of objects which were in the old array and are also
 * in the new array, but at a different index.  The indices returned are
 * indices into the old array.
 */
public Set<Integer> getMovedIndices() {
    HashSet<TabData> set = new HashSet<TabData>(Arrays.asList(nue));
    HashSet<Integer> results = new HashSet<Integer>(old.length);

    for (int i = 0; i < old.length; i++) {
        boolean isPresent = set.contains(old[i]);
        if (isPresent) {
            boolean isMoved = (i < nue.length
                    && !nue[i].equals(old[i])) || i >= nue.length;
            if (isMoved) {
                results.add(new Integer(i));
            }
        }
    }
    return results;
}
 
Example #8
Source File: FolderNameTabDecorator.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public String getText( TabData tab ) {
    if( !settings.isShowFolderName() )
        return null;
    if( tab.getComponent() instanceof TopComponent ) {
        TopComponent tc = ( TopComponent ) tab.getComponent();
        DataObject dob = tc.getLookup().lookup( DataObject.class );
        if( null != dob ) {
            FileObject fo = dob.getPrimaryFile();
            if( fo.isData() ) {
                FileObject folder = fo.getParent();
                if( null != folder ) {
                    String folderName = folder.getNameExt() + pathSeparator;
                    String defaultText = tab.getText();

                    return merge( folderName, defaultText );
                }
            }
        }
    }
    return null;
}
 
Example #9
Source File: LayoutModelTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private void prepareModel() {
    TabData[] td = new TabData[25];
    int ct = 0;
    for (char c='a'; c < 'z'; c++) {
        char[] ch = new char[ct+1];
        Arrays.fill (ch, c);
        String name = new String (ch);
        Component comp = new JLabel(name);
        comp.setName (name);
        td[ct] = new TabData (comp, ic, name, "tip:"+name);
        ct++;
    }
    padX = 2;
    padY = 2;
    mdl = new DefaultTabDataModel (td);
    JLabel jl = new JLabel();
    jl.setBorder (BorderFactory.createEmptyBorder());
    lay = new TestLayoutModel (mdl, jl);
    lay.setPadding (new Dimension(padX, padY));
}
 
Example #10
Source File: TabbedSlideAdapter.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public void setTopComponents(TopComponent[] tcs, TopComponent selected) {
    TabData[] data = new TabData[tcs.length];
    int toSelect=-1;
    for(int i = 0; i < tcs.length; i++) {
        TopComponent tc = tcs[i];
        Image icon = tc.getIcon();
        String displayName = WindowManagerImpl.getInstance().getTopComponentDisplayName(tc);
        data[i] = new TabData(
            tc,
            icon == null ? null : ImageUtilities.image2Icon(icon),
            displayName == null ? "" : displayName, // NOI18N
            tc.getToolTipText());
        if (selected == tcs[i]) {
            toSelect = i;
        }
    }

    dataModel.setTabs(data);
    setSelectedComponent(selected);
}
 
Example #11
Source File: SelectionModelTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void doTestInsertContiguous () {
    System.err.println("testInsertContiguous");

    TabData[] td = new TabData[5];
    for (int i=0; i < 5; i++) {
        String nm = "ic" + Integer.toString(i);
        td[i] = new TabData (new JLabel(), ic, nm, "tip:nm");
    }
    
    int idx = sel.getSelectedIndex();
    mdl.addTabs(0, td);
    assertEventFired();
    assertPravda (idx + 4 == sel.getSelectedIndex(), "After contiguous insert, selection should be " + (idx+5) + " but is " + sel.getSelectedIndex());
    noEvent=true;
    mdl.addTabs (20, td);
    noEvent = false;
}
 
Example #12
Source File: WorkspaceTopComponent.java    From snap-desktop with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void actionPerformed(ActionEvent e) {
    int desktopWidth = desktopPane.getWidth();
    int desktopHeight = desktopPane.getHeight();
    int windowCount = frameToTabMap.size();

    Dimension matrixSize = TileUtilities.computeMatrixSizeForEqualAreaTiling(windowCount);

    int windowWidth = desktopWidth / matrixSize.width;
    int windowHeight = desktopHeight / matrixSize.height;

    List<TabData> tabs = tabbedContainer.getModel().getTabs();
    int windowIndex = 0;
    for (int j = 0; j < matrixSize.height; j++) {
        for (int i = 0; i < matrixSize.width; i++) {
            if (windowIndex < windowCount) {
                TabData tab = tabs.get(windowIndex);
                JInternalFrame internalFrame = tabToFrameMap.get(tab);
                internalFrame.setBounds(i * windowWidth, j * windowHeight, windowWidth, windowHeight);
            }
            windowIndex++;
        }
    }
}
 
Example #13
Source File: BasicTabDisplayerUI.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public Image createImageOfTab(int index) {
    TabData td = displayer.getModel().getTab(index);
    
    JLabel lbl = new JLabel(td.getText());
    int width = lbl.getFontMetrics(lbl.getFont()).stringWidth(td.getText());
    int height = lbl.getFontMetrics(lbl.getFont()).getHeight();
    width = width + td.getIcon().getIconWidth() + 6;
    height = Math.max(height, td.getIcon().getIconHeight()) + 5;
    
    GraphicsConfiguration config = GraphicsEnvironment.getLocalGraphicsEnvironment()
                                    .getDefaultScreenDevice().getDefaultConfiguration();
    
    BufferedImage image = config.createCompatibleImage(width, height);
    Graphics2D g = image.createGraphics();
    g.setColor(lbl.getForeground());
    g.setFont(lbl.getFont());
    td.getIcon().paintIcon(lbl, g, 0, 0);
    g.drawString(td.getText(), 18, height / 2);
    
    
    return image;
}
 
Example #14
Source File: MultiRowTabDisplayer.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public int dropIndexOfPoint( Point location ) {
    int res = -1;
    TabData tab = getTabAt( location );
    if( null != tab ) {
        res = getModel().indexOf( tab );
        if( res == getModel().size()-1 ) {
            Rectangle rect = getTabBounds( res );
            if( location.x > rect.x+rect.width/2 ) {
                res++;
            }
        }
    }
    return res;
}
 
Example #15
Source File: ProjectColorTabDecorator.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static Color getColorForTab( TabData tab ) {
    ProjectProxy p = ProjectSupport.getDefault().getProjectForTab( tab );
    if( null != p ) {
        synchronized( project2color ) {
            return project2color.get( p.getToken() );
        }
    }
    return null;
}
 
Example #16
Source File: ProjectColorTabDecorator.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public void paintAfter( TabData tab, Graphics g, Rectangle tabRect, boolean isSelected ) {
    if( !isSelected || !Settings.getDefault().isSameProjectSameColor() )
        return;
    Color c = null;
    synchronized( tab2color ) {
        c = tab2color.get( tab );
        if( null == c ) {
            c = getColorForTab( tab );
            if( null == c )
                return;
            tab2color.put( tab, c );
        }
    }
    g.setColor( c );
    Rectangle rect = new Rectangle( tabRect );
    int underlineHeight = UIManager.getInt("nb.multitabs.underlineHeight"); // NOI18N
    if( underlineHeight > 0 ) {
        // if the selected tab is highlighted with an "underline" (e.g. in FlatLaf)
        // then paint the project color bar at the top of the tab
        rect.height = underlineHeight;
    } else {
        // bottom project color bar
        rect.y += rect.height - 3;
        rect.grow( -1, -1 );
    }
    g.fillRect( rect.x, rect.y, rect.width, rect.height );
}
 
Example #17
Source File: DocumentSwitcherTable.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public Item( SwitcherTableItem.Activatable activatable, String name, String htmlName,
        TabData tab, boolean active, ProjectProxy project ) {
    super( activatable, name, htmlName, tab.getIcon(), active, tab.getTooltip() );
    this.tabData = tab;
    this.project = project;
    isSeparator = false;
}
 
Example #18
Source File: WorkspaceTopComponent.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void actionPerformed(ActionEvent e) {
    int desktopWidth = desktopPane.getWidth();
    int desktopHeight = desktopPane.getHeight();
    int windowCount = frameToTabMap.size();
    int windowHeight = desktopHeight / windowCount;
    List<TabData> tabs = tabbedContainer.getModel().getTabs();
    for (int windowIndex = 0; windowIndex < windowCount; windowIndex++) {
        TabData tab = tabs.get(windowIndex);
        JInternalFrame internalFrame = tabToFrameMap.get(tab);
        internalFrame.setBounds(0, windowIndex * windowHeight, desktopWidth, windowHeight);
    }
}
 
Example #19
Source File: MultiRowTabDisplayer.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void changeSelection( TabTable source ) {
     if( ignoreSelectionEvents )
        return;
    ignoreSelectionEvents = true;

    int newSelIndex = -1;
    int selRow = source.getSelectedRow();
    int selCol = source.getSelectedColumn();
    if( selRow >= 0 && selCol >= 0 ) {
        TabData td = ( TabData ) source.getValueAt( selRow, selCol );
        if( td != null ) {
            newSelIndex = tabModel.indexOf( td );
            Rectangle rect = source.getCellRect( selRow, selCol, true );
            source.scrollRectToVisible( rect );
            controller.setSelectedIndex( newSelIndex );
        }
        for( TabTable table : rowTables ) {
            if( table != source ) {
                table.clearSelection();
            }
        }
    } else {
        SwingUtilities.invokeLater( new Runnable() {

            @Override
            public void run() {
                int selIndex = controller.getSelectedIndex();
                if( selIndex < 0 )
                    selIndex = 0;
                setSelectedIndex( selIndex );
            }
        });
    }
    ignoreSelectionEvents = false;
}
 
Example #20
Source File: WorkspaceTopComponent.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void actionPerformed(ActionEvent e) {
    TabData tab = tabbedContainer.getModel().getTab(tabIndex);
    JInternalFrame internalFrame = tabToFrameMap.get(tab);
    TopComponent topComponent = dockInternalFrame(internalFrame);
    if (topComponent != null) {
        topComponent.requestActive();
    }
}
 
Example #21
Source File: WorkspaceTopComponent.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void actionPerformed(ActionEvent e) {
    TabData tab = tabbedContainer.getModel().getTab(tabIndex);
    JInternalFrame internalFrame = tabToFrameMap.get(tab);
    try {
        internalFrame.setMaximum(true);
    } catch (PropertyVetoException e1) {
        // ok
    }
}
 
Example #22
Source File: TabTable.java    From netbeans with Apache License 2.0 5 votes vote down vote up
TabData getTabAt( Point p ) {
    if( p.x < 0 || p.y < 0 )
        return null;
    int row = rowAtPoint( p );
    int col = columnAtPoint( p );
    if( row < 0 || col < 0 )
        return null;
    return (TabData)getValueAt( row, col );
}
 
Example #23
Source File: TabLayoutManager.java    From netbeans with Apache License 2.0 5 votes vote down vote up
TabData getTabAt( Point p ) {
    for( TabTable table : rows ) {
        Point location = SwingUtilities.convertPoint( container, p, table );
        if( table.contains( location ) ) {
            return table.getTabAt( location );
        }
    }
    return null;
}
 
Example #24
Source File: TabLayoutManager.java    From netbeans with Apache License 2.0 5 votes vote down vote up
Rectangle getTabBounds( int tabIndex ) {
    TabData tab = tabModel.getTab( tabIndex );
    if( null == tab )
        return null;
    for( SingleRowTabTable table : rows ) {
        if( table.hasTabIndex( tabIndex ) ) {
            Rectangle rect = table.getTabBounds( tabIndex );
            if( null != rect ) {
                rect = SwingUtilities.convertRectangle( table, rect, container );
            }
            return rect;
        }
    }
    return null;
}
 
Example #25
Source File: TabbedImpl.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public int tabForCoordinate( Point p ) {
    p = SwingUtilities.convertPoint( getComponent(), p, getTabDisplayer() );
    TabData td = getTabDisplayer().getTabAt( p );
    if( null == td )
        return -1;
    return tabModel.indexOf( td );
}
 
Example #26
Source File: Controller.java    From netbeans with 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 #27
Source File: TabbedSlideAdapter.java    From netbeans with 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 #28
Source File: CommandManager.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private Tabbed updateSlidedTabContainer(int tabIndex) {
        Tabbed container = getSlidingTabbed();
//        TabDataModel containerModel = container.getModel();
        SlideBarDataModel dataModel = slideBar.getModel();
        // creating new TabData instead of just referencing
        // to be able to compare and track changes between models of slide bar and 
        // slided tabbed container
        TabData origTab = dataModel.getTab(tabIndex);
        TopComponent tc = ( TopComponent ) origTab.getComponent();
        container.setTopComponents( new TopComponent[] { tc }, tc );
        return container;
    }
 
Example #29
Source File: AbstractTabbedImpl.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public void propertyChange(PropertyChangeEvent evt) {
    if (JComponent.TOOL_TIP_TEXT_KEY.equals(evt.getPropertyName())) {
        java.util.List tabs = getTabModel().getTabs();
        JComponent curComp;
        int index = 0;
        for (Iterator iter = tabs.iterator(); iter.hasNext(); index++) {
            curComp = (JComponent)((TabData)iter.next()).getComponent();
            if (curComp == evt.getSource() && index < getTabCount()) {
                setToolTipTextAt(index, (String)evt.getNewValue());
                break;
            }
        }
    }
}
 
Example #30
Source File: WorkspaceTopComponent.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void actionPerformed(ActionEvent e) {
    int desktopWidth = desktopPane.getWidth();
    int desktopHeight = desktopPane.getHeight();
    int windowCount = frameToTabMap.size();
    int windowWidth = desktopWidth / windowCount;
    List<TabData> tabs = tabbedContainer.getModel().getTabs();
    for (int windowIndex = 0; windowIndex < windowCount; windowIndex++) {
        TabData tab = tabs.get(windowIndex);
        JInternalFrame internalFrame = tabToFrameMap.get(tab);
        internalFrame.setBounds(windowIndex * windowWidth, 0, windowWidth, desktopHeight);
    }
}