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

The following examples show how to use org.netbeans.swing.tabcontrol.TabData. 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: ArrayDiff.java    License: 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 2
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 3
Source Project: netbeans   Source File: BasicTabDisplayerUI.java    License: 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 4
Source Project: netbeans   Source File: AbstractViewTabDisplayerUI.java    License: 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 Project: cakephp3-netbeans   Source File: CakePHPTabDecorator.java    License: 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 Project: netbeans   Source File: BasicScrollingTabDisplayerUI.java    License: 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 Project: netbeans   Source File: LayoutModelTest.java    License: 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 8
Source Project: netbeans   Source File: SelectionModelTest.java    License: 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 9
@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 10
Source Project: netbeans   Source File: TabbedSlideAdapter.java    License: 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 Project: netbeans   Source File: SimpleTabDisplayer.java    License: 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 12
Source Project: netbeans   Source File: FolderNameTabDecorator.java    License: 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 13
Source Project: netbeans   Source File: ProjectColorTabDecorator.java    License: 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 14
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 15
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 16
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 17
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 18
Source Project: netbeans   Source File: ArrayDiff.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new instance of ArrayDiff
 */
private ArrayDiff(TabData[] old, TabData[] nue) {
    this.old = old;
    this.nue = nue;
    if (nue == null || old == null) {
        throw new NullPointerException(old == null && nue == null ?
                                       "Both arrays are null" :
                                       old == null ?
                                       "Old array is null" :
                                       "New array is null");
    }
}
 
Example 19
Source Project: netbeans   Source File: ArrayDiff.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Returns an ArrayDiff object if the two arrays are not the same, or null
 * if they are
 */
public static ArrayDiff createDiff(TabData[] old, TabData[] nue) {
    if (!Arrays.equals(old, nue)) {
        return new ArrayDiff(old, nue);
    } else {
        return null;
    }
}
 
Example 20
Source Project: netbeans   Source File: ArrayDiff.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Returns the indices of objects in the old array which are not present in
 * the new array.  The resulting array's size will be that of the old array
 */
public Set<Integer> getDeletedIndices() {
    if (deleted == null) {
        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++) {
            if (!set.contains(old[i])) {
                results.add(new Integer(i));
            }
        }
        deleted = results;
    }
    return deleted;
}
 
Example 21
Source Project: netbeans   Source File: ArrayDiff.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Returns the indices of objects in the new array which are not present in
 * the old array
 */
public Set<Integer> getAddedIndices() {
    if (added == null) {
        HashSet<TabData> set = new HashSet<TabData>(Arrays.asList(old));
        Set<Integer> results = new HashSet<Integer>(nue.length);
        for (int i = 0; i < nue.length; i++) {
            if (!set.contains(nue[i])) {
                results.add(new Integer(i));
            }
        }
        added = results;
    }
    return added;
}
 
Example 22
Source Project: netbeans   Source File: ArrayDiff.java    License: Apache License 2.0 5 votes vote down vote up
public boolean equals(Object o) {
    if (o instanceof ArrayDiff) {
        if (o == this) {
            return true;
        }
        TabData[] otherOld = ((ArrayDiff) o).getOldData();
        TabData[] otherNue = ((ArrayDiff) o).getNewData();
        return Arrays.equals(old, otherOld)
                && Arrays.equals(nue, otherNue);
    }
    return false;
}
 
Example 23
Source Project: netbeans   Source File: VeryComplexListDataEvent.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new instance of VeryComplexListDataEvent
 */
public VeryComplexListDataEvent(Object source, TabData[] old,
                                TabData[] nue) {
    super(source, ITEMS_CHANGED, -1, -1);
    this.old = old;
    this.nue = nue;
}
 
Example 24
/**
 * Gets all windows contained in this one.
 *
 * @return The list of all windows which may be empty.
 */
public List<TopComponent> getTopComponents() {
    List<TabData> tabs = tabbedContainer.getModel().getTabs();
    List<TopComponent> topComponents = new ArrayList<>();
    for (TabData tab : tabs) {
        JInternalFrame internalFrame = tabToFrameMap.get(tab);
        topComponents.add(getTopComponent(internalFrame));
    }
    return topComponents;
}
 
Example 25
Source Project: HiJson   Source File: MainView.java    License: Apache License 2.0 5 votes vote down vote up
private JTree getTree(int tabIndex){
    if(tabIndex >= 0){
        TabData selTabData = tabDataModel.getTab(tabIndex);
        return getTree(selTabData);
    }
    return null;
}
 
Example 26
Source Project: netbeans   Source File: DefaultTabbedContainerUI.java    License: Apache License 2.0 5 votes vote down vote up
public void indicesRemoved(ComplexListDataEvent e) {
    int[] indices = e.getIndices();
    TabData[] removedTabs = e.getAffectedItems();
    Component curComp;
    for (int i = 0; i < indices.length; i++) {
        curComp = toComp(removedTabs[i]);
        // TBD - add assertion curComp.getParent() != contentDisplayer
        contentDisplayer.remove(curComp);
    }
}
 
Example 27
Source Project: netbeans   Source File: BasicTabDisplayerUI.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Get the cell renderer for a given tab.  The default implementation simply
 * returns the renderer created by createDefaultRenderer().
 * @param tab
 * @return 
 */
public TabCellRenderer getTabCellRenderer(int tab) {
    defaultRenderer.setShowCloseButton(displayer.isShowCloseButton());
    if( tab >=0 && tab < displayer.getModel().size() ) {
        TabData data = displayer.getModel().getTab(tab);
        boolean closingEnabled = true;
        if( data.getComponent() instanceof TopComponent ) {
            closingEnabled = displayer.getContainerWinsysInfo().isTopComponentClosingEnabled( (TopComponent)data.getComponent() );
        }

        defaultRenderer.setShowCloseButton(displayer.isShowCloseButton() && closingEnabled);
    }
    return defaultRenderer;
}
 
Example 28
Source Project: netbeans   Source File: AbstractTabCellRenderer.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Implementation of getRendererComponent from TabCellRenderer. This
 * method is final, and will configure the text, bounds and icon correctly
 * according to the passed values, and call setState to set the state of the
 * tab.  Implementers must implement <code>stateChanged()</code> to handle
 * any changes (background color, border, etc) necessary to reflect the
 * current state as returned by <code>getState()</code>.
 */
public final javax.swing.JComponent getRendererComponent(TabData data,
                                                         Rectangle bounds,
                                                         int state) {
    setBounds(bounds);
    setText(data.getText());
    setIcon(data.getIcon());
    setState(state);
    return this;
}
 
Example 29
Source Project: netbeans   Source File: TabControlButtonFactory.java    License: Apache License 2.0 5 votes vote down vote up
private static Component getActiveTab( TabDisplayer displayer ) {
    Component res = null;
    int selIndex = displayer.getSelectionModel().getSelectedIndex();
    if( selIndex >= 0 ) {
        TabData tab = displayer.getModel().getTab( selIndex );
        res = tab.getComponent();
    }
    return res;
}
 
Example 30
Source Project: HiJson   Source File: MainView.java    License: Apache License 2.0 5 votes vote down vote up
private JTree getTree(TabData tabData){
    if(tabData==null){
        return null;
    }
    JSplitPane selSplitPane = (JSplitPane)tabData.getComponent();
    JSplitPane rightSplitPane = (JSplitPane)selSplitPane.getRightComponent();
    JScrollPane sp = (JScrollPane)rightSplitPane.getLeftComponent();
    JViewport vp = (JViewport)sp.getComponent(0);
    JTree t = (JTree)vp.getComponent(0);
    return t;
}