Java Code Examples for org.netbeans.swing.tabcontrol.TabData#getText()

The following examples show how to use org.netbeans.swing.tabcontrol.TabData#getText() . 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: 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 2
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 3
Source File: BasicSlidingTabDisplayerUI.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;
    
    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 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 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: TabbedContainerBridgeImpl.java    From netbeans with 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 7
Source File: AbstractViewTabDisplayerUI.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public void paint(Graphics g, JComponent c) {

    ColorUtil.setupAntialiasing(g);

    TabData tabData;
    int x, y, width, height;
    String text;
    
    paintDisplayerBackground( g, c );

    for (int i = 0; i < dataModel.size(); i++) {
        // gather data
        tabData = dataModel.getTab(i);
        x = layoutModel.getX(i);
        y = layoutModel.getY(i);
        width = layoutModel.getW(i);
        height = layoutModel.getH(i);
        text = tabData.getText();
        // perform paint
        if (g.hitClip(x, y, width, height)) {
            paintTabBackground(g, i, x, y, width, height);
            paintTabContent(g, i, text, x, y, width, height);
            paintTabBorder(g, i, x, y, width, height);
        }
    }
}
 
Example 8
Source File: ButtonPopupSwitcher.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private Item[] createSwitcherItems(final Controller controller) {
    ProjectSupport projectSupport = ProjectSupport.getDefault();
    final boolean sortByProject = Settings.getDefault().isSortDocumentListByProject()
            && projectSupport.isEnabled();
    java.util.List<TabData> tabs = controller.getTabModel().getTabs();
    ArrayList<Item> items = new ArrayList<Item>(tabs.size());
    int selIdx = controller.getSelectedIndex();
    TabData selectedTab = selIdx >= 0 && selIdx < controller.getTabModel().size() ? controller.getTabModel().getTab(selIdx) : null;
    boolean hasProjectInfo = false;
    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();
        }
        ProjectProxy project = null;
        if( sortByProject ) {
            project = projectSupport.getProjectForTab( tab );
            hasProjectInfo |= null != project;
        }
        items.add( new Item(
                new ActivatableTab(tab),
                name,
                htmlName,
                tab,
                tab == selectedTab,
                project));
    }
    Collections.sort( items );
    if( sortByProject && hasProjectInfo ) {
        //add project headers
        ProjectProxy currentProject = null;
        for( int i=0; i<items.size(); i++ ) {
            Item item = items.get( i );
            ProjectProxy p = item.getProject();
            if( null != p && !p.equals( currentProject ) ) {
                items.add( i, Item.create( p ) );
            } else if( null == p && null != currentProject ) {
                items.add( i, DocumentSwitcherTable.NO_PROJECT_SEPARATOR );
            }
            currentProject = p;
        }
    }
    return items.toArray( new Item[items.size()] );
}
 
Example 9
Source File: TabDataRenderer.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
public Component getTableCellRendererComponent( JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column ) {
    renderer.clear();
    Rectangle rect = table.getCellRect( row, column, true );
    renderer.setSize( rect.width, rect.height );
    if( value instanceof TabData ) {
        TabData tab = ( TabData ) value;
        String text = tab.getText();
        Icon icon = tab.getIcon();
        Color colBackground = isSelected ? table.getSelectionBackground() : table.getBackground();
        Color colForeground = isSelected ? table.getSelectionForeground() : table.getForeground();

        boolean isActive = (activeBackground != null || underlineColor != null)
            ? TabbedImpl.isActive(table) : false;
        if (!isSelected && isActive && activeBackground != null) {
            colBackground = activeBackground;
        }

        for( TabDecorator td : decorators ) {
            Color c = td.getBackground( tab, isSelected );
            if( null != c )
                colBackground = c;
            c = td.getForeground( tab, isSelected );
            if( null != c )
                colForeground = c;

            String s = td.getText( tab );
            if( null != s )
                text = s;

            Icon i = td.getIcon( tab );
            if( null != i ) {
                icon = i;
            }
        }
        boolean isHover = (hoverBackground != null && TabTableUI.isHover(table, row, column));
        if (isHover) {
            colBackground = hoverBackground;
        }
        renderer.label.setText( text );
        renderer.label.setIcon( icon );
        renderer.label.setFont( table.getFont() );
        renderer.setBackground( colBackground );
        renderer.label.setForeground( colForeground );
        renderer.tabData = tab;
        renderer.isSelected = isSelected;
        renderer.isActive = isActive;
        renderer.tabsLocation = (table instanceof TabTable) ? ((TabTable)table).getTabsLocation() : JTabbedPane.TOP;

        if( table instanceof TabTable ) {
            TabTable tabTable = ( TabTable ) table;
            if( isClosable(tab) ) {
                boolean inCloseButton = tabTable.isCloseButtonHighlighted( row, column );
                renderer.closeButton.setVisible( true );
                renderer.closeButton.getModel().setRollover( inCloseButton );
                renderer.closeButton.getModel().setArmed( inCloseButton );
            } else {
                renderer.closeButton.setVisible( false );
            }
        }
    }
    return renderer;
}
 
Example 10
Source File: TabDataRenderer.java    From netbeans with Apache License 2.0 4 votes vote down vote up
int getPreferredWidth( Object value ) {
    int res = -1;
    renderer.clear();
    if( value instanceof TabData ) {
        TabData tab = ( TabData ) value;
        String text = tab.getText();
        Icon icon = tab.getIcon();

        for( TabDecorator td : decorators ) {
            String s = td.getText( tab );
            if( null != s )
                text = s;

            Icon i = td.getIcon( tab );
            if( null != i ) {
                icon = i;
            }
        }

        // On startup, this method is invoked very often if many files are open
        // (~60000 times for 200 open files).
        // The text (usually a filename) always starts with "<html>",
        // but does not contain other HTML tags.
        // The HTML rendering makes startup slow (and CPU load high).
        // To workaround this, remove the leading "<html>" if text does not
        // contain HTML tags or entities.
        String prefix = "<html>"; // NOI18N
        if (text.startsWith(prefix)
                && text.indexOf('<', prefix.length()) < 0
                && text.indexOf('&', prefix.length()) < 0) {
            text = text.substring(prefix.length());
        }

        renderer.label.setText( text );
        renderer.label.setIcon( icon );
        renderer.tabData = tab;

        res = renderer.getPreferredSize().width;
    }
    return res;
}