Search in sources :

Example 1 with TabClosableTitle

use of com.revolsys.swing.component.TabClosableTitle in project com.revolsys.open by revolsys.

the class ProjectFrame method addBottomTab.

public void addBottomTab(final ProjectFramePanel panel, final Map<String, Object> config) {
    Invoke.later(() -> {
        final TabbedPane tabs = getBottomTabs();
        final Object tableView = panel.getProperty(BOTTOM_TAB);
        Component component = null;
        if (tableView instanceof Component) {
            component = (Component) tableView;
            if (component.getParent() != tabs) {
                component = null;
            }
        }
        if (component == null) {
            component = panel.newPanelComponent(config);
            if (component != null) {
                final Component panelComponent = component;
                panel.activatePanelComponent(panelComponent, config);
                final int tabIndex = tabs.getTabCount();
                panel.setPropertyWeak(BOTTOM_TAB, panelComponent);
                final String layerPath = panel.getPath();
                final Runnable closeAction = () -> removeBottomTab(panel);
                synchronized (this.bottomTabLayerPaths) {
                    this.bottomTabLayerPaths.add(layerPath);
                }
                final String name = panel.getName();
                final Icon icon = panel.getIcon();
                final TabClosableTitle tab = tabs.addClosableTab(name, icon, panelComponent, closeAction);
                tab.setMenu(panel);
                tabs.setSelectedIndex(tabIndex);
                panel.setPropertyWeak(BOTTOM_TAB_LISTENER, // 
                Arrays.asList(EventQueue.addPropertyChange(panel, "name", () -> {
                    final int index = tabs.indexOfComponent(panelComponent);
                    if (index != -1) {
                        final String newName = panel.getName();
                        tabs.setTitleAt(index, newName);
                    }
                }), // 
                EventQueue.addPropertyChange(panel, "icon", () -> {
                    final int index = tabs.indexOfComponent(panelComponent);
                    if (index != -1) {
                        final Icon newName = panel.getIcon();
                        tabs.setIconAt(index, newName);
                    }
                })));
            }
        } else {
            panel.activatePanelComponent(component, config);
            tabs.setSelectedComponent(component);
        }
    });
}
Also used : DnDTabbedPane(com.revolsys.swing.component.DnDTabbedPane) JTabbedPane(javax.swing.JTabbedPane) TabbedPane(com.revolsys.swing.TabbedPane) Icon(javax.swing.Icon) TabClosableTitle(com.revolsys.swing.component.TabClosableTitle) Component(java.awt.Component) JComponent(javax.swing.JComponent)

Example 2 with TabClosableTitle

use of com.revolsys.swing.component.TabClosableTitle in project com.revolsys.open by revolsys.

the class TabbedPane method addClosableTab.

public TabClosableTitle addClosableTab(final String title, final Icon icon, final Component component, final Runnable closeAction) {
    final int tabIndex = getTabCount();
    addTab(title, icon, component);
    final TabClosableTitle tabTitle = new TabClosableTitle(this, closeAction);
    setTabComponentAt(tabIndex, tabTitle);
    return tabTitle;
}
Also used : TabClosableTitle(com.revolsys.swing.component.TabClosableTitle)

Aggregations

TabClosableTitle (com.revolsys.swing.component.TabClosableTitle)2 TabbedPane (com.revolsys.swing.TabbedPane)1 DnDTabbedPane (com.revolsys.swing.component.DnDTabbedPane)1 Component (java.awt.Component)1 Icon (javax.swing.Icon)1 JComponent (javax.swing.JComponent)1 JTabbedPane (javax.swing.JTabbedPane)1