diff --git a/core.windows/manifest.mf b/core.windows/manifest.mf --- a/core.windows/manifest.mf +++ b/core.windows/manifest.mf @@ -6,5 +6,5 @@ OpenIDE-Module-Recommends: org.netbeans.core.windows.nativeaccess.NativeWindowSystem AutoUpdate-Show-In-Client: false AutoUpdate-Essential-Module: true -OpenIDE-Module-Specification-Version: 2.42 +OpenIDE-Module-Specification-Version: 2.43 diff --git a/core.windows/nbproject/project.xml b/core.windows/nbproject/project.xml --- a/core.windows/nbproject/project.xml +++ b/core.windows/nbproject/project.xml @@ -85,7 +85,7 @@ - 1.27 + 1.33 diff --git a/core.windows/src/org/netbeans/core/windows/view/dnd/DragAndDropFeedbackVisualizer.java b/core.windows/src/org/netbeans/core/windows/view/dnd/DragAndDropFeedbackVisualizer.java --- a/core.windows/src/org/netbeans/core/windows/view/dnd/DragAndDropFeedbackVisualizer.java +++ b/core.windows/src/org/netbeans/core/windows/view/dnd/DragAndDropFeedbackVisualizer.java @@ -59,7 +59,7 @@ import javax.swing.SwingUtilities; import org.netbeans.core.windows.nativeaccess.NativeWindowSystem; import org.netbeans.core.windows.options.WinSysPrefs; -import org.netbeans.core.windows.view.ui.Tabbed; +import org.netbeans.swing.tabcontrol.customtabs.Tabbed; /** * diff --git a/core.windows/src/org/netbeans/core/windows/view/dnd/DragWindow.java b/core.windows/src/org/netbeans/core/windows/view/dnd/DragWindow.java --- a/core.windows/src/org/netbeans/core/windows/view/dnd/DragWindow.java +++ b/core.windows/src/org/netbeans/core/windows/view/dnd/DragWindow.java @@ -62,7 +62,7 @@ import javax.swing.SwingUtilities; import javax.swing.Timer; import org.netbeans.core.windows.options.WinSysPrefs; -import org.netbeans.core.windows.view.ui.Tabbed; +import org.netbeans.swing.tabcontrol.customtabs.Tabbed; /** * diff --git a/core.windows/src/org/netbeans/core/windows/view/dnd/TopComponentDragSupport.java b/core.windows/src/org/netbeans/core/windows/view/dnd/TopComponentDragSupport.java --- a/core.windows/src/org/netbeans/core/windows/view/dnd/TopComponentDragSupport.java +++ b/core.windows/src/org/netbeans/core/windows/view/dnd/TopComponentDragSupport.java @@ -47,6 +47,7 @@ +import org.netbeans.swing.tabcontrol.customtabs.Tabbed; import java.awt.AWTEvent; import java.awt.Color; import java.awt.Component; @@ -273,18 +274,11 @@ TopComponent tc = null; Tabbed tabbed; - if(srcComp instanceof Tabbed) { - tabbed = (Tabbed)srcComp; + if(srcComp instanceof Tabbed.Accessor) { + tabbed = ((Tabbed.Accessor)srcComp).getTabbed(); } else { - tabbed = (Tabbed)SwingUtilities.getAncestorOfClass(Tabbed.class, srcComp); - } - if (tabbed == null) { - if(srcComp instanceof Tabbed.Accessor) { - tabbed = ((Tabbed.Accessor)srcComp).getTabbed(); - } else { - Tabbed.Accessor acc = (Tabbed.Accessor)SwingUtilities.getAncestorOfClass(Tabbed.Accessor.class, srcComp); - tabbed = acc != null ? acc.getTabbed() : null; - } + Tabbed.Accessor acc = (Tabbed.Accessor)SwingUtilities.getAncestorOfClass(Tabbed.Accessor.class, srcComp); + tabbed = acc != null ? acc.getTabbed() : null; } if(tabbed == null) { return; @@ -396,13 +390,10 @@ addListening(); hackESC = false; - Tabbed tabbed = (Tabbed) SwingUtilities.getAncestorOfClass (Tabbed.class, - startingComp); - if (tabbed == null) { - Tabbed.Accessor acc = (Tabbed.Accessor) SwingUtilities.getAncestorOfClass (Tabbed.Accessor.class, - startingComp); - tabbed = acc != null ? acc.getTabbed() : null; - } + Tabbed tabbed = null; + Tabbed.Accessor acc = (Tabbed.Accessor) SwingUtilities.getAncestorOfClass (Tabbed.Accessor.class, + startingComp); + tabbed = acc != null ? acc.getTabbed() : null; int tabIndex = -1; Image img = createDragImage(); diff --git a/core.windows/src/org/netbeans/core/windows/view/ui/AbstractModeContainer.java b/core.windows/src/org/netbeans/core/windows/view/ui/AbstractModeContainer.java --- a/core.windows/src/org/netbeans/core/windows/view/ui/AbstractModeContainer.java +++ b/core.windows/src/org/netbeans/core/windows/view/ui/AbstractModeContainer.java @@ -46,6 +46,7 @@ package org.netbeans.core.windows.view.ui; +import org.netbeans.swing.tabcontrol.customtabs.Tabbed; import org.netbeans.core.windows.Constants; import org.netbeans.core.windows.WindowManagerImpl; import org.netbeans.core.windows.view.ModeContainer; @@ -206,7 +207,7 @@ // Support for TopComponentDroppable protected Shape getIndicationForLocation(Point location) { return tabbedHandler.getIndicationForLocation(location, - windowDnDManager.getStartingTransfer(), + windowDnDManager.getStartingTransfer().getTopComponent(), windowDnDManager.getStartingPoint(), isAttachingPossible()); } diff --git a/core.windows/src/org/netbeans/core/windows/view/ui/DefaultSeparateContainer.java b/core.windows/src/org/netbeans/core/windows/view/ui/DefaultSeparateContainer.java --- a/core.windows/src/org/netbeans/core/windows/view/ui/DefaultSeparateContainer.java +++ b/core.windows/src/org/netbeans/core/windows/view/ui/DefaultSeparateContainer.java @@ -46,6 +46,7 @@ package org.netbeans.core.windows.view.ui; +import org.netbeans.swing.tabcontrol.customtabs.Tabbed; import java.text.MessageFormat; import javax.swing.plaf.basic.BasicHTML; import org.netbeans.core.windows.Constants; @@ -68,6 +69,9 @@ import java.util.logging.Logger; import org.netbeans.core.windows.options.WinSysPrefs; import org.netbeans.core.windows.view.dnd.TopComponentDraggable; +import org.netbeans.swing.tabcontrol.customtabs.TabbedComponentFactory; +import org.netbeans.swing.tabcontrol.customtabs.TabbedType; +import org.openide.util.Lookup; import org.openide.windows.WindowManager; @@ -118,13 +122,9 @@ @Override protected Tabbed createTabbed() { - Tabbed tabbed; - if(getKind() == Constants.MODE_KIND_EDITOR) { - tabbed = new TabbedAdapter(Constants.MODE_KIND_EDITOR); - } else { - tabbed = new TabbedAdapter(Constants.MODE_KIND_VIEW); - } - return tabbed; + TabbedComponentFactory factory = Lookup.getDefault().lookup(TabbedComponentFactory.class); + TabbedType type = getKind() == Constants.MODE_KIND_EDITOR ? TabbedType.EDITOR : TabbedType.VIEW; + return factory.createTabbedComponent( type, new TabbedAdapter.WinsysInfo(getKind())); } @Override diff --git a/core.windows/src/org/netbeans/core/windows/view/ui/DefaultSplitContainer.java b/core.windows/src/org/netbeans/core/windows/view/ui/DefaultSplitContainer.java --- a/core.windows/src/org/netbeans/core/windows/view/ui/DefaultSplitContainer.java +++ b/core.windows/src/org/netbeans/core/windows/view/ui/DefaultSplitContainer.java @@ -46,6 +46,7 @@ package org.netbeans.core.windows.view.ui; +import org.netbeans.swing.tabcontrol.customtabs.Tabbed; import org.netbeans.core.windows.Constants; import org.netbeans.core.windows.WindowManagerImpl; import org.netbeans.core.windows.view.ModeView; @@ -59,6 +60,9 @@ import java.awt.*; import org.netbeans.core.windows.ModeImpl; import org.netbeans.core.windows.view.dnd.TopComponentDraggable; +import org.netbeans.swing.tabcontrol.customtabs.TabbedComponentFactory; +import org.netbeans.swing.tabcontrol.customtabs.TabbedType; +import org.openide.util.Lookup; import org.openide.windows.Mode; @@ -96,14 +100,11 @@ return panel; } + @Override protected Tabbed createTabbed() { - Tabbed tabbed; - if(getKind() == Constants.MODE_KIND_EDITOR) { - tabbed = new TabbedAdapter(Constants.MODE_KIND_EDITOR); - } else { - tabbed = new TabbedAdapter(Constants.MODE_KIND_VIEW); - } - return tabbed; + TabbedComponentFactory factory = Lookup.getDefault().lookup(TabbedComponentFactory.class); + TabbedType type = getKind() == Constants.MODE_KIND_EDITOR ? TabbedType.EDITOR : TabbedType.VIEW; + return factory.createTabbedComponent( type, new TabbedAdapter.WinsysInfo(getKind())); } protected void updateTitle(String title) { diff --git a/core.windows/src/org/netbeans/core/windows/view/ui/Tabbed.java b/core.windows/src/org/netbeans/core/windows/view/ui/Tabbed.java deleted file mode 100644 --- a/core.windows/src/org/netbeans/core/windows/view/ui/Tabbed.java +++ /dev/null @@ -1,144 +0,0 @@ -/* - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - * - * Copyright 1997-2010 Oracle and/or its affiliates. All rights reserved. - * - * Oracle and Java are registered trademarks of Oracle and/or its affiliates. - * Other names may be trademarks of their respective owners. - * - * The contents of this file are subject to the terms of either the GNU - * General Public License Version 2 only ("GPL") or the Common - * Development and Distribution License("CDDL") (collectively, the - * "License"). You may not use this file except in compliance with the - * License. You can obtain a copy of the License at - * http://www.netbeans.org/cddl-gplv2.html - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the - * specific language governing permissions and limitations under the - * License. When distributing the software, include this License Header - * Notice in each file and include the License file at - * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the GPL Version 2 section of the License file that - * accompanied this code. If applicable, add the following below the - * License Header, with the fields enclosed by brackets [] replaced by - * your own identifying information: - * "Portions Copyrighted [year] [name of copyright owner]" - * - * Contributor(s): - * - * The Original Software is NetBeans. The Initial Developer of the Original - * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun - * Microsystems, Inc. All Rights Reserved. - * - * If you wish your version of this file to be governed by only the CDDL - * or only the GPL Version 2, indicate your decision by adding - * "[Contributor] elects to include this software in this distribution - * under the [CDDL or GPL Version 2] license." If you do not indicate a - * single choice of license, a recipient has the option to distribute - * your version of this file under either the CDDL, the GPL Version 2 or - * to extend the choice of license to its licensees as provided above. - * However, if you add GPL Version 2 code and therefore, elected the GPL - * Version 2 license, then the option applies only if the new code is - * made subject to such option by the copyright holder. - */ - - -package org.netbeans.core.windows.view.ui; - - -import org.openide.windows.TopComponent; - -import javax.swing.*; -import javax.swing.event.ChangeListener; -import java.awt.*; -import java.awt.event.ActionListener; -import org.netbeans.core.windows.view.dnd.TopComponentDraggable; - - -/** - * Interface describing component which is used inside SimpleContainer. - * There will be at two implementations one for view and second one for editor type. - * - * @author Peter Zavadsky - */ -public interface Tabbed { - - public void requestAttention(TopComponent tc); - - public void cancelRequestAttention(TopComponent tc); - - public void addTopComponent(String name, Icon icon, TopComponent tc, String toolTip); - - public void insertComponent(String name, Icon icon, Component comp, String toolTip, int position); - - public void setTopComponents(TopComponent[] tcs, TopComponent selected); - - public int getTabCount(); - - public TopComponent[] getTopComponents(); - - public TopComponent getTopComponentAt(int index); - - public int indexOf(Component tc); - - public void removeComponent(Component comp); - - public void setTitleAt(int index, String title); - - public void setIconAt(int index, Icon icon); - - public void setToolTipTextAt(int index, String toolTip); - - public void setSelectedComponent(Component comp); - - public TopComponent getSelectedTopComponent(); - - public void addChangeListener(ChangeListener listener); - - public void removeChangeListener(ChangeListener listener); - - public void addActionListener (ActionListener al); - - public void removeActionListener (ActionListener al); - - public void setActive(boolean active); - - public int tabForCoordinate(Point p); - - public Shape getIndicationForLocation(Point location, TopComponentDraggable startingTransfer, - Point startingPoint, boolean attachingPossible); - - public Object getConstraintForLocation(Point location, boolean attachingPossible); - - public Image createImageOfTab (int tabIndex); - - /** Accessor for visual component holding components */ - public Component getComponent(); - - /** Allows tabbed implementors to speficy content of popup menu on tab - * with given index. Incoming actions are default set by winsys - */ - public Action[] getPopupActions(Action[] defaultActions, int tabIndex); - - /** Returns bounds of tab with given index */ - public Rectangle getTabBounds(int tabIndex); - - /** - * @return Bounds of the area which displays the tab headers. - * @since 2.32 - */ - public Rectangle getTabsArea(); - - public boolean isTransparent(); - - public void setTransparent( boolean transparent ); - - /** Interface for simple accessing of Tabbed instance */ - public interface Accessor { - - public Tabbed getTabbed (); - - } // end of Accessor - -} - diff --git a/core.windows/src/org/netbeans/core/windows/view/ui/TabbedHandler.java b/core.windows/src/org/netbeans/core/windows/view/ui/TabbedHandler.java --- a/core.windows/src/org/netbeans/core/windows/view/ui/TabbedHandler.java +++ b/core.windows/src/org/netbeans/core/windows/view/ui/TabbedHandler.java @@ -46,6 +46,7 @@ package org.netbeans.core.windows.view.ui; +import org.netbeans.swing.tabcontrol.customtabs.Tabbed; import org.netbeans.core.windows.Constants; import org.netbeans.core.windows.actions.ActionUtils; import org.netbeans.core.windows.actions.MaximizeWindowAction; @@ -69,7 +70,6 @@ import java.util.logging.Logger; import org.netbeans.core.windows.ModeImpl; import org.netbeans.core.windows.Switches; -import org.netbeans.core.windows.view.dnd.TopComponentDraggable; import org.netbeans.core.windows.view.ui.slides.SlideBar; import org.netbeans.core.windows.view.ui.slides.SlideBarActionEvent; import org.netbeans.core.windows.view.ui.slides.SlideOperationFactory; @@ -299,7 +299,7 @@ } // DnD>> - public Shape getIndicationForLocation(Point location, TopComponentDraggable startingTransfer, + public Shape getIndicationForLocation(Point location, TopComponent startingTransfer, Point startingPoint, boolean attachingPossible) { return tabbed.getIndicationForLocation(location, startingTransfer, startingPoint, attachingPossible); @@ -463,13 +463,13 @@ /** Possibly invokes the (un)maximization. */ public static void handleMaximization(TabActionEvent tae) { Component c = (Component) tae.getSource(); - while (c != null && !(c instanceof Tabbed)) + while (c != null && !(c instanceof Tabbed.Accessor)) c = c.getParent(); if (c == null) { return; } - final Tabbed tab = (Tabbed) c; + final Tabbed tab = ((Tabbed.Accessor) c).getTabbed(); TopComponent tc = tab.getTopComponentAt(tae.getTabIndex()); // perform action MaximizeWindowAction mwa = new MaximizeWindowAction(tc); diff --git a/core.windows/src/org/netbeans/core/windows/view/ui/slides/SlideBar.java b/core.windows/src/org/netbeans/core/windows/view/ui/slides/SlideBar.java --- a/core.windows/src/org/netbeans/core/windows/view/ui/slides/SlideBar.java +++ b/core.windows/src/org/netbeans/core/windows/view/ui/slides/SlideBar.java @@ -79,7 +79,7 @@ import org.netbeans.core.windows.ModeImpl; import org.netbeans.core.windows.Switches; import org.netbeans.core.windows.WindowManagerImpl; -import org.netbeans.core.windows.view.ui.Tabbed; +import org.netbeans.swing.tabcontrol.customtabs.Tabbed; import org.netbeans.core.windows.view.ui.tabcontrol.TabbedAdapter; import org.netbeans.swing.tabcontrol.SlideBarDataModel; import org.netbeans.swing.tabcontrol.SlidingButton; @@ -407,7 +407,7 @@ public Tabbed getTabbed () { return tabbed; } - + /********* implementation of WinsysInfoForTabbedContainer **************/ public WinsysInfoForTabbedContainer createWinsysInfo() { diff --git a/core.windows/src/org/netbeans/core/windows/view/ui/slides/SlideBarContainer.java b/core.windows/src/org/netbeans/core/windows/view/ui/slides/SlideBarContainer.java --- a/core.windows/src/org/netbeans/core/windows/view/ui/slides/SlideBarContainer.java +++ b/core.windows/src/org/netbeans/core/windows/view/ui/slides/SlideBarContainer.java @@ -69,7 +69,7 @@ import org.netbeans.core.windows.view.ui.AbstractModeContainer; import org.netbeans.core.windows.view.ui.ModeComponent; import org.netbeans.core.windows.view.dnd.TopComponentDroppable; -import org.netbeans.core.windows.view.ui.Tabbed; +import org.netbeans.swing.tabcontrol.customtabs.Tabbed; import org.openide.windows.TopComponent; diff --git a/core.windows/src/org/netbeans/core/windows/view/ui/slides/TabbedSlideAdapter.java b/core.windows/src/org/netbeans/core/windows/view/ui/slides/TabbedSlideAdapter.java --- a/core.windows/src/org/netbeans/core/windows/view/ui/slides/TabbedSlideAdapter.java +++ b/core.windows/src/org/netbeans/core/windows/view/ui/slides/TabbedSlideAdapter.java @@ -65,14 +65,13 @@ import org.netbeans.core.windows.ModeImpl; import org.netbeans.core.windows.WindowManagerImpl; import org.netbeans.core.windows.actions.ActionUtils; -import org.netbeans.core.windows.view.ui.Tabbed; import org.netbeans.swing.tabcontrol.DefaultTabDataModel; import org.netbeans.core.windows.view.dnd.DragAndDropFeedbackVisualizer; -import org.netbeans.core.windows.view.dnd.TopComponentDraggable; import org.netbeans.swing.tabcontrol.SlideBarDataModel; import org.netbeans.swing.tabcontrol.TabData; import org.netbeans.swing.tabcontrol.TabDataModel; import org.netbeans.swing.tabcontrol.TabbedContainer; +import org.netbeans.swing.tabcontrol.customtabs.Tabbed; import org.openide.util.ChangeSupport; import org.openide.windows.TopComponent; @@ -83,7 +82,7 @@ * * @author Dafe Simonek */ -public final class TabbedSlideAdapter implements Tabbed { +public final class TabbedSlideAdapter extends Tabbed { /** data model of informations about top components in container */ private TabDataModel dataModel; @@ -313,7 +312,7 @@ } @Override - public Shape getIndicationForLocation(Point location, TopComponentDraggable startingTransfer, + public Shape getIndicationForLocation(Point location, TopComponent startingTransfer, Point startingPoint, boolean attachingPossible) { // int tab = tabForCoordinate(location); diff --git a/core.windows/src/org/netbeans/core/windows/view/ui/tabcontrol/TabbedAdapter.java b/core.windows/src/org/netbeans/core/windows/view/ui/tabcontrol/TabbedAdapter.java --- a/core.windows/src/org/netbeans/core/windows/view/ui/tabcontrol/TabbedAdapter.java +++ b/core.windows/src/org/netbeans/core/windows/view/ui/tabcontrol/TabbedAdapter.java @@ -52,7 +52,7 @@ import org.netbeans.core.windows.Constants; import org.netbeans.core.windows.Debug; import org.netbeans.core.windows.WindowManagerImpl; -import org.netbeans.core.windows.view.ui.Tabbed; +import org.netbeans.swing.tabcontrol.customtabs.Tabbed; import org.netbeans.swing.tabcontrol.ComponentConverter; import org.netbeans.swing.tabcontrol.TabData; import org.netbeans.swing.tabcontrol.TabbedContainer; @@ -64,12 +64,11 @@ import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; import java.awt.*; -import java.util.ArrayList; +import java.awt.event.ActionListener; import java.util.Arrays; import org.netbeans.core.windows.ModeImpl; import org.netbeans.core.windows.Switches; import org.netbeans.core.windows.actions.ActionUtils; -import org.netbeans.core.windows.view.dnd.TopComponentDraggable; import org.netbeans.swing.tabcontrol.TabDisplayer; import org.netbeans.swing.tabcontrol.WinsysInfoForTabbedContainer; import org.netbeans.swing.tabcontrol.event.TabActionEvent; @@ -81,7 +80,7 @@ * * @author Tim Boudreau */ -public class TabbedAdapter extends TabbedContainer implements Tabbed, Tabbed.Accessor, SlideController { +public class TabbedAdapter extends TabbedContainer implements Tabbed.Accessor, SlideController { public static final int DOCUMENT = 1; @@ -93,8 +92,8 @@ private PropertyChangeListener tooltipListener, weakTooltipListener; /** Creates a new instance of TabbedAdapter */ - public TabbedAdapter (int type) { - super (null, type, new WinsysInfo(type)); + public TabbedAdapter (int type, WinsysInfoForTabbedContainer winsysInfo) { + super (null, type, winsysInfo); getSelectionModel().addChangeListener(new ChangeListener() { @Override public void stateChanged (ChangeEvent ce) { @@ -104,98 +103,10 @@ } } }); -// Color fillC = (Color)UIManager.get("nb_workplace_fill"); //NOI18N -// if (fillC != null) setBackground (fillC); } - @Override - public void addTopComponent(String name, javax.swing.Icon icon, TopComponent tc, String toolTip) { - insertComponent (name, icon, tc, toolTip, getTabCount()); - } - - @Override - public TopComponent getTopComponentAt(int index) { - if (index == -1 || index >= getModel().size()) { - return null; - } - return (TopComponent)getModel().getTab(index).getComponent(); - } - - @Override - public TopComponent getSelectedTopComponent() { - int i = getSelectionModel().getSelectedIndex(); - return i == -1 ? null : getTopComponentAt(i); - } - - @Override - public void requestAttention (TopComponent tc) { - int idx = indexOf(tc); - if (idx >= 0) { - requestAttention(idx); - } else { - Logger.getAnonymousLogger().fine( - "RequestAttention on component unknown to container: " + tc); //NOI18N - } - } - - @Override - public void cancelRequestAttention (TopComponent tc) { - int idx = indexOf(tc); - if (idx >= 0) { - cancelRequestAttention(idx); - } else { - throw new IllegalArgumentException ("TopComponent " + tc - + " is not a child of this container"); //NOI18N - } - } - - @Override - public void insertComponent(String name, javax.swing.Icon icon, Component comp, String toolTip, int position) { - TabData td = new TabData (comp, icon, name, toolTip); - - if(DEBUG) { - debugLog("InsertTab: " + name + " hash:" + System.identityHashCode(comp)); // NOI18N - } - - getModel().addTab(position, td); - comp.addPropertyChangeListener(JComponent.TOOL_TIP_TEXT_KEY, getTooltipListener(comp)); - } - - @Override - public void setSelectedComponent(Component comp) { - int i = indexOf (comp); - if (i == -1 && null != comp) { - throw new IllegalArgumentException ( - "Component not a child of this control: " + comp); //NOI18N - } else { - getSelectionModel().setSelectedIndex(i); - } - } - - @Override - public TopComponent[] getTopComponents() { - ComponentConverter cc = getComponentConverter(); - TabData[] td = (TabData[]) getModel().getTabs().toArray(new TabData[0]); - TopComponent[] result = new TopComponent[getModel().size()]; - for (int i=0; i < td.length; i++) { - result[i] = (TopComponent) cc.getComponent(td[i]); - } - return result; - } - - @Override - public void removeComponent(Component comp) { - int i=indexOf(comp); - getModel().removeTab(i); - comp.removePropertyChangeListener(JComponent.TOOL_TIP_TEXT_KEY, getTooltipListener(comp)); - if (getModel().size() == 0) { - revalidate(); - repaint(); - } - } public void addComponents(Component[] comps, String[] names, javax.swing.Icon[] icons, String[] tips) { - ArrayList al = new ArrayList (comps.length); TabData[] data = new TabData[comps.length]; for (int i=0; i < comps.length; i++) { TabData td = new TabData (comps[i], icons[i], names[i], tips[i]); @@ -205,65 +116,6 @@ getModel().addTabs (0, data); } - @Override - public void setTopComponents(TopComponent[] tcs, TopComponent selected) { - // #100144 - correct null selection and log, probably some problem in - // winsys model consistency, but without reproduction no chance to find out - if (selected == null && tcs.length > 0) { - selected = tcs[0]; - Logger.getLogger(TabbedAdapter.class.getName()).warning( - "Selected component is null although open components are " + - Arrays.asList(tcs)); - } - int sizeBefore = getModel().size(); - - detachTooltipListeners(getModel().getTabs()); - - 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 : new ImageIcon(icon), - displayName == null ? "" : displayName, // NOI18N - tc.getToolTipText()); - if (selected == tcs[i]) { - toSelect = i; - } - tc.addPropertyChangeListener(JComponent.TOOL_TIP_TEXT_KEY, getTooltipListener(tc)); - } - - //DO NOT DELETE THIS ASSERTION AGAIN! - //If it triggered, it means there is a problem in the state of the - //window system's model. If it is just diagnostic logging, there - //*will* be an exception later, it just won't contain any useful - //information. See issue 39914 for what happens if it is deleted. - assert selected != null && toSelect != -1 : "Tried to set a selected component that was " + - " not in the array of open components. ToSelect: " + selected + " ToSelectName=" + selected.getDisplayName() + - " ToSelectClass=" + selected.getClass() + - " open components: " + Arrays.asList(tcs); - - getModel().setTabs(data); - - if (toSelect != -1) { - getSelectionModel().setSelectedIndex(toSelect); - } else if (selected != null) { - //Assertions are off - Logger.getAnonymousLogger().warning("Tried to" + - "set a selected component that was not in the array of open " + - "components. ToSelect: " + selected + " components: " + - Arrays.asList(tcs)); - } - int sizeNow = getModel().size(); - if (sizeBefore != 0 && sizeNow == 0) { - //issue 40076, ensure repaint if the control has been emptied. - revalidate(); - repaint(); - } - } /** Removes tooltip listeners from given tabs */ private void detachTooltipListeners(List tabs) { @@ -275,87 +127,6 @@ } } - // DnD>> - /** Finds tab which contains x coordinate of given location point. - * @param location The point for which a constraint is required - * @return Integer object representing found tab index. Returns null if - * no such tab can be found. - */ - @Override - public Object getConstraintForLocation(Point location, boolean attachingPossible) { - //#47909 - // first process the tabs when mouse is inside the tabs area.. - int tab = tabForCoordinate(location); - if (tab != -1) { - int index = dropIndexOfPoint(location); - return index < 0 ? null : Integer.valueOf(index); - } - // ---- - if(attachingPossible) { - String s = getSideForLocation(location); - if(s != null) { - return s; - } - } - int index = dropIndexOfPoint(location); - return index < 0 ? null : Integer.valueOf(index); - } - - /** Computes and returns feedback indication shape for given location - * point. - * TBD - extend for various feedback types - * @return Shape representing feedback indication - */ - @Override - public Shape getIndicationForLocation(Point location, - TopComponentDraggable startingTransfer, Point startingPoint, boolean attachingPossible) { - - Rectangle rect = getBounds(); - rect.setLocation(0, 0); - - TopComponent draggedTC = startingTransfer.getTopComponent(); - //#47909 - int tab = tabForCoordinate(location); - // first process the tabs when mouse is inside the tabs area.. - // need to process before the side resolution. - if (tab != -1) { - Shape s = getDropIndication(draggedTC, location); - if(s != null) { - return s; - } - } - - String side; - if(attachingPossible) { - side = getSideForLocation(location); - } else { - side = null; - } - - double ratio = Constants.DROP_TO_SIDE_RATIO; - if(side == Constants.TOP) { - return new Rectangle(0, 0, rect.width, (int)(rect.height * ratio)); - } else if(side == Constants.LEFT) { - return new Rectangle(0, 0, (int)(rect.width * ratio), rect.height); - } else if(side == Constants.RIGHT) { - return new Rectangle(rect.width - (int)(rect.width * ratio), 0, (int)(rect.width * ratio), rect.height); - } else if(side == Constants.BOTTOM) { - return new Rectangle(0, rect.height - (int)(rect.height * ratio), rect.width, (int)(rect.height * ratio)); - } - - // #47909 now check shape again.. when no sides were checked, assume changing tabs when in component center. - Shape s = getDropIndication(draggedTC, location); - if(s != null) { - return s; - } - - if( startingTransfer.isTopComponentTransfer() && startingPoint != null - && indexOf(startingTransfer.getTopComponent()) != -1) { - return getStartingIndication(startingPoint, location); - } - - return rect; - } private String getSideForLocation(Point location) { Rectangle bounds = getBounds(); @@ -420,24 +191,6 @@ // DnD<< - /** Registers ChangeListener to receive events. - * @param listener The listener to register. - * - */ - @Override - public void addChangeListener(ChangeListener listener) { - cs.addChangeListener(listener); - } - - /** Removes ChangeListener from the list of listeners. - * @param listener The listener to remove. - * - */ - @Override - public void removeChangeListener(ChangeListener listener) { - cs.removeChangeListener(listener); - } - /** Notifies all registered listeners about the event. */ private void fireStateChanged() { if (!SwingUtilities.isEventDispatchThread()) { @@ -472,25 +225,8 @@ Debug.log(TabbedAdapter.class, message); } - @Override - public Component getComponent() { - return this; - } - - /** Add action for enabling auto hide of views */ - @Override - public Action[] getPopupActions(Action[] defaultActions, int tabIndex) { - if( tabIndex < 0 ) { - ModeImpl mode = getModeImpl(); - if( null != mode ) - return ActionUtils.createDefaultPopupActions( mode ); - return null; - } - return defaultActions; - } - private ModeImpl getModeImpl() { - TopComponent[] topComponents = getTopComponents(); + TopComponent[] topComponents = tabbedImpl.getTopComponents(); if( topComponents.length < 1 ) return null; return ( ModeImpl ) WindowManagerImpl.getInstance().findMode( topComponents[0] ); @@ -525,22 +261,12 @@ @Override public Tabbed getTabbed() { - return this; - } - - @Override - public Rectangle getTabBounds(int tabIndex) { - return getTabRect(tabIndex, new Rectangle()); - } - - @Override - public Rectangle getTabsArea() { - return getUI().getTabsArea(); + return tabbedImpl; } /********* implementation of WinsysInfoForTabbed ********/ - static class WinsysInfo extends WinsysInfoForTabbedContainer { + public static class WinsysInfo extends WinsysInfoForTabbedContainer { private int containerType; public WinsysInfo( int containerType ) { this.containerType = containerType; @@ -628,6 +354,342 @@ } return weakTooltipListener; } + + private final Tabbed tabbedImpl = new Tabbed() { + + @Override + public void addTopComponent(String name, javax.swing.Icon icon, TopComponent tc, String toolTip) { + insertComponent (name, icon, tc, toolTip, getTabCount()); + } + + @Override + public TopComponent getTopComponentAt(int index) { + if (index == -1 || index >= getModel().size()) { + return null; + } + return (TopComponent)getModel().getTab(index).getComponent(); + } + + @Override + public TopComponent getSelectedTopComponent() { + int i = getSelectionModel().getSelectedIndex(); + return i == -1 ? null : getTopComponentAt(i); + } + + @Override + public void requestAttention (TopComponent tc) { + int idx = indexOf(tc); + if (idx >= 0) { + TabbedAdapter.this.requestAttention(idx); + } else { + Logger.getAnonymousLogger().fine( + "RequestAttention on component unknown to container: " + tc); //NOI18N + } + } + + @Override + public void cancelRequestAttention (TopComponent tc) { + int idx = indexOf(tc); + if (idx >= 0) { + TabbedAdapter.this.cancelRequestAttention(idx); + } else { + throw new IllegalArgumentException ("TopComponent " + tc + + " is not a child of this container"); //NOI18N + } + } + + @Override + public void insertComponent(String name, javax.swing.Icon icon, Component comp, String toolTip, int position) { + TabData td = new TabData (comp, icon, name, toolTip); + + if(DEBUG) { + debugLog("InsertTab: " + name + " hash:" + System.identityHashCode(comp)); // NOI18N + } + + getModel().addTab(position, td); + comp.addPropertyChangeListener(JComponent.TOOL_TIP_TEXT_KEY, getTooltipListener(comp)); + } + + @Override + public void setSelectedComponent(Component comp) { + int i = indexOf (comp); + if (i == -1 && null != comp) { + throw new IllegalArgumentException ( + "Component not a child of this control: " + comp); //NOI18N + } else { + getSelectionModel().setSelectedIndex(i); + } + } + + @Override + public TopComponent[] getTopComponents() { + ComponentConverter cc = getComponentConverter(); + TabData[] td = (TabData[]) getModel().getTabs().toArray(new TabData[0]); + TopComponent[] result = new TopComponent[getModel().size()]; + for (int i=0; i < td.length; i++) { + result[i] = (TopComponent) cc.getComponent(td[i]); + } + return result; + } + + @Override + public void removeComponent(Component comp) { + int i=indexOf(comp); + getModel().removeTab(i); + comp.removePropertyChangeListener(JComponent.TOOL_TIP_TEXT_KEY, getTooltipListener(comp)); + if (getModel().size() == 0) { + revalidate(); + repaint(); + } + } + + @Override + public Rectangle getTabBounds(int tabIndex) { + return getTabRect(tabIndex, new Rectangle()); + } + + @Override + public Rectangle getTabsArea() { + return getUI().getTabsArea(); + } + + @Override + public void setTopComponents(TopComponent[] tcs, TopComponent selected) { + // #100144 - correct null selection and log, probably some problem in + // winsys model consistency, but without reproduction no chance to find out + if (selected == null && tcs.length > 0) { + selected = tcs[0]; + Logger.getLogger(TabbedAdapter.class.getName()).warning( + "Selected component is null although open components are " + + Arrays.asList(tcs)); + } + int sizeBefore = getModel().size(); + + detachTooltipListeners(getModel().getTabs()); + + 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 : new ImageIcon(icon), + displayName == null ? "" : displayName, // NOI18N + tc.getToolTipText()); + if (selected == tcs[i]) { + toSelect = i; + } + tc.addPropertyChangeListener(JComponent.TOOL_TIP_TEXT_KEY, getTooltipListener(tc)); + } + + //DO NOT DELETE THIS ASSERTION AGAIN! + //If it triggered, it means there is a problem in the state of the + //window system's model. If it is just diagnostic logging, there + //*will* be an exception later, it just won't contain any useful + //information. See issue 39914 for what happens if it is deleted. + assert selected != null && toSelect != -1 : "Tried to set a selected component that was " + + " not in the array of open components. ToSelect: " + selected + " ToSelectName=" + selected.getDisplayName() + + " ToSelectClass=" + selected.getClass() + + " open components: " + Arrays.asList(tcs); + + getModel().setTabs(data); + + if (toSelect != -1) { + getSelectionModel().setSelectedIndex(toSelect); + } else if (selected != null) { + //Assertions are off + Logger.getAnonymousLogger().warning("Tried to" + + "set a selected component that was not in the array of open " + + "components. ToSelect: " + selected + " components: " + + Arrays.asList(tcs)); + } + int sizeNow = getModel().size(); + if (sizeBefore != 0 && sizeNow == 0) { + //issue 40076, ensure repaint if the control has been emptied. + revalidate(); + repaint(); + } + } + // DnD>> + /** Finds tab which contains x coordinate of given location point. + * @param location The point for which a constraint is required + * @return Integer object representing found tab index. Returns null if + * no such tab can be found. + */ + @Override + public Object getConstraintForLocation(Point location, boolean attachingPossible) { + //#47909 + // first process the tabs when mouse is inside the tabs area.. + int tab = tabForCoordinate(location); + if (tab != -1) { + int index = dropIndexOfPoint(location); + return index < 0 ? null : Integer.valueOf(index); + } + // ---- + if(attachingPossible) { + String s = getSideForLocation(location); + if(s != null) { + return s; + } + } + int index = dropIndexOfPoint(location); + return index < 0 ? null : Integer.valueOf(index); + } + + /** Computes and returns feedback indication shape for given location + * point. + * TBD - extend for various feedback types + * @return Shape representing feedback indication + */ + @Override + public Shape getIndicationForLocation(Point location, + TopComponent startingTransfer, Point startingPoint, boolean attachingPossible) { + + Rectangle rect = getBounds(); + rect.setLocation(0, 0); + + TopComponent draggedTC = startingTransfer; + //#47909 + int tab = tabForCoordinate(location); + // first process the tabs when mouse is inside the tabs area.. + // need to process before the side resolution. + if (tab != -1) { + Shape s = getDropIndication(draggedTC, location); + if(s != null) { + return s; + } + } + + String side; + if(attachingPossible) { + side = getSideForLocation(location); + } else { + side = null; + } + + double ratio = Constants.DROP_TO_SIDE_RATIO; + if(side == Constants.TOP) { + return new Rectangle(0, 0, rect.width, (int)(rect.height * ratio)); + } else if(side == Constants.LEFT) { + return new Rectangle(0, 0, (int)(rect.width * ratio), rect.height); + } else if(side == Constants.RIGHT) { + return new Rectangle(rect.width - (int)(rect.width * ratio), 0, (int)(rect.width * ratio), rect.height); + } else if(side == Constants.BOTTOM) { + return new Rectangle(0, rect.height - (int)(rect.height * ratio), rect.width, (int)(rect.height * ratio)); + } + + // #47909 now check shape again.. when no sides were checked, assume changing tabs when in component center. + Shape s = getDropIndication(draggedTC, location); + if(s != null) { + return s; + } + + if( null != startingTransfer && startingPoint != null + && indexOf(startingTransfer) != -1) { + return getStartingIndication(startingPoint, location); + } + + return rect; + } + + @Override + public Component getComponent() { + return TabbedAdapter.this; + } + + /** Add action for enabling auto hide of views */ + @Override + public Action[] getPopupActions(Action[] defaultActions, int tabIndex) { + if( tabIndex < 0 ) { + ModeImpl mode = getModeImpl(); + if( null != mode ) + return ActionUtils.createDefaultPopupActions( mode ); + return null; + } + return defaultActions; + } + + /** Registers ChangeListener to receive events. + * @param listener The listener to register. + * + */ + @Override + public void addChangeListener(ChangeListener listener) { + cs.addChangeListener(listener); + } + + /** Removes ChangeListener from the list of listeners. + * @param listener The listener to remove. + * + */ + @Override + public void removeChangeListener(ChangeListener listener) { + cs.removeChangeListener(listener); + } + + @Override + public int getTabCount() { + return TabbedAdapter.this.getTabCount(); + } + + @Override + public int indexOf( Component tc ) { + return TabbedAdapter.this.indexOf( tc ); + } + + @Override + public void setTitleAt( int index, String title ) { + TabbedAdapter.this.setTitleAt( index, title ); + } + + @Override + public void setIconAt( int index, Icon icon ) { + TabbedAdapter.this.setIconAt( index, icon ); + } + + @Override + public void setToolTipTextAt( int index, String toolTip ) { + TabbedAdapter.this.setToolTipTextAt( index, toolTip ); + } + + @Override + public void addActionListener( ActionListener al ) { + TabbedAdapter.this.addActionListener( al ); + } + + @Override + public void removeActionListener( ActionListener al ) { + TabbedAdapter.this.removeActionListener( al ); + } + + @Override + public void setActive( boolean active ) { + TabbedAdapter.this.setActive( active ); + } + + @Override + public int tabForCoordinate( Point p ) { + return TabbedAdapter.this.tabForCoordinate( p ); + } + + @Override + public Image createImageOfTab( int tabIndex ) { + return TabbedAdapter.this.createImageOfTab( tabIndex ); + } + + @Override + public boolean isTransparent() { + return TabbedAdapter.this.isTransparent(); + } + + @Override + public void setTransparent( boolean transparent ) { + TabbedAdapter.this.setTransparent( transparent ); + } + + }; /** Listening to changes of tooltips of currently asociated top components */ private class ToolTipListener implements PropertyChangeListener {