Pre-refactoring cleanup. (Done mostly what inspections suggested)

This commit is contained in:
Maxim Shafirov
2012-05-15 19:24:49 +04:00
parent 8009a2f6e8
commit 5bcfdf9699
19 changed files with 123 additions and 356 deletions
@@ -53,10 +53,6 @@ public class
@Override
protected void paintLastGhost(Graphics2D g2d) {}
public boolean isGhostsAlwaysVisible() {
return false;
}
protected void doPaintInactive(Graphics2D g2d,
boolean leftGhostExists,
TabLabel label,
@@ -19,7 +19,6 @@ import com.intellij.openapi.actionSystem.ActionGroup;
import com.intellij.openapi.actionSystem.DataProvider;
import com.intellij.openapi.util.ActionCallback;
import com.intellij.openapi.util.ActiveRunnable;
import com.intellij.openapi.util.Getter;
import com.intellij.ui.awt.RelativePoint;
import com.intellij.ui.switcher.SwitchProvider;
import org.jetbrains.annotations.NotNull;
@@ -29,8 +28,6 @@ import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.Comparator;
import java.util.List;
public interface JBTabs extends SwitchProvider {
@@ -42,21 +39,10 @@ public interface JBTabs extends SwitchProvider {
ActionCallback removeTab(@Nullable TabInfo info);
ActionCallback removeTab(@Nullable TabInfo info, @Nullable TabInfo forcedSelectionTranfer);
ActionCallback removeTab(@Nullable TabInfo info, @Nullable TabInfo forcedSelectionTranfer, boolean transferFocus);
void removeAllTabs();
@Nullable
ActionGroup getPopupGroup();
@Nullable
String getPopupPlace();
JBTabs setPopupGroup(@NotNull ActionGroup popupGroup, @NotNull String place, final boolean addNavigationGroup);
JBTabs setPopupGroup(@NotNull Getter<ActionGroup> popupGroup, @NotNull String place, final boolean addNavigationGroup);
ActionCallback select(@NotNull TabInfo info, boolean requestFocus);
@Nullable
@@ -65,9 +51,6 @@ public interface JBTabs extends SwitchProvider {
@NotNull
TabInfo getTabAt(int tabIndex);
@NotNull
List<TabInfo> getTabs();
int getTabCount();
@NotNull
@@ -76,31 +59,19 @@ public interface JBTabs extends SwitchProvider {
@Nullable
DataProvider getDataProvider();
JBTabs setDataProvider(@NotNull DataProvider dataProvider);
@Nullable
TabInfo getTargetInfo();
@NotNull
JBTabs addTabMouseListener(@NotNull MouseListener listener);
@NotNull
JBTabs removeTabMouseListener(@NotNull MouseListener listener);
JBTabs addListener(@NotNull TabsListener listener);
JBTabs removeListener(@NotNull TabsListener listener);
JBTabs setSelectionChangeHandler(SelectionChangeHandler handler);
@NotNull
JComponent getComponent();
void updateTabActions(boolean validateNow);
@Nullable
TabInfo findInfo(Component component);
@Nullable
TabInfo findInfo(MouseEvent event);
@@ -109,11 +80,7 @@ public interface JBTabs extends SwitchProvider {
int getIndexOf(@Nullable final TabInfo tabInfo);
void sortTabs(Comparator<TabInfo> comparator);
void requestFocus();
boolean isEditorTabs();
JBTabs setNavigationActionBinding(String prevActiobId, String nextActionId);
JBTabs setNavigationActionsEnabled(boolean enabled);
@@ -122,16 +89,10 @@ public interface JBTabs extends SwitchProvider {
JBTabs setAdditionalSwitchProviderWhenOriginal(SwitchProvider delegate);
Image getComponentImage(TabInfo info);
void resetDropOver(TabInfo tabInfo);
Image startDropOver(TabInfo tabInfo, RelativePoint point);
void processDropOver(TabInfo over, RelativePoint point);
boolean isEmptyVisible();
int getInterTabSpaceLength();
interface SelectionChangeHandler {
ActionCallback execute(final TabInfo info, final boolean requestFocus, ActiveRunnable doChangeSelection);
}
@@ -30,14 +30,10 @@ public interface JBTabsPresentation {
JBTabsPresentation setPaintBorder(int top, int left, int right, int bottom);
JBTabsPresentation setTabSidePaintBorder(int size);
boolean isPaintFocus();
JBTabsPresentation setPaintFocus(boolean paintFocus);
JBTabsPresentation setStealthTabMode(boolean stealthTabMode);
boolean isStealthTabMode();
JBTabsPresentation setSideComponentVertical(boolean vertical);
JBTabsPresentation setSideComponentOnTabs(boolean onTabs);
@@ -46,35 +42,18 @@ public interface JBTabsPresentation {
boolean isSingleRow();
boolean isSideComponentVertical();
boolean isSideComponentOnTabs();
JBTabsPresentation setUiDecorator(@Nullable UiDecorator decorator);
boolean isRequestFocusOnLastFocusedComponent();
JBTabsPresentation setRequestFocusOnLastFocusedComponent(boolean request);
void setPaintBlocked(boolean blocked, final boolean takeSnapshot);
void setFocused(boolean focused);
JBTabsPresentation setInnerInsets(Insets innerInsets);
Insets getInnerInsets();
JBTabsPresentation setGhostsAlwaysVisible(boolean visible);
boolean isGhostsAlwaysVisible();
@NotNull
JBTabsPresentation setAdjustBorders(boolean adjust);
JBTabsPresentation setFocusCycle(final boolean root);
boolean isToDrawBorderIfTabsHidden();
@NotNull
JBTabsPresentation setToDrawBorderIfTabsHidden(boolean draw);
@@ -96,9 +75,7 @@ public interface JBTabsPresentation {
JBTabsPosition getTabsPosition();
JBTabsPresentation setTabDraggingEnabled(boolean enabled);
boolean isTabDraggingEnabled();
JBTabsPresentation setProvideSwitchTargets(boolean provide);
}
}
@@ -127,10 +127,6 @@ class ActionButton extends IconButton implements ActionListener {
}
}
public boolean isAutoHide() {
return myAutoHide;
}
public void toggleShowActions(boolean show) {
if (myAutoHide) {
myButton.setPainting(show);
@@ -37,15 +37,13 @@ public class ActionPanel extends NonOpaquePanel {
private boolean myAutoHide;
private boolean myActionsIsVisible = false;
private final int myGap = 2;
public ActionPanel(JBTabsImpl tabs, TabInfo tabInfo, Pass<MouseEvent> pass) {
myTabs = tabs;
ActionGroup group = tabInfo.getTabLabelActions() != null ? tabInfo.getTabLabelActions() : new DefaultActionGroup();
AnAction[] children = group.getChildren(null);
final NonOpaquePanel wrapper = new NonOpaquePanel(new BorderLayout());
wrapper.add(Box.createHorizontalStrut(myGap), BorderLayout.WEST);
wrapper.add(Box.createHorizontalStrut(2), BorderLayout.WEST);
NonOpaquePanel inner = new NonOpaquePanel();
inner.setLayout(new BoxLayout(inner, BoxLayout.X_AXIS));
wrapper.add(inner, BorderLayout.CENTER);
@@ -29,12 +29,12 @@ import java.awt.event.MouseEvent;
class DragHelper extends MouseDragHelper {
JBTabsImpl myTabs;
TabInfo myDragSource;
Rectangle myDragOriginalRec;
private final JBTabsImpl myTabs;
private TabInfo myDragSource;
private Rectangle myDragOriginalRec;
Rectangle myDragRec;
Dimension myHoldDelta;
private Dimension myHoldDelta;
private TabInfo myDragOutSource;
private TabLabel myPressedTabLabel;
@@ -147,7 +147,7 @@ class DragHelper extends MouseDragHelper {
if (targetLabel != null) {
Rectangle saved = myDragRec;
myDragRec = null;
myTabs.reallocate(myDragSource, targetLabel.getInfo(), true);
myTabs.reallocate(myDragSource, targetLabel.getInfo());
myDragOriginalRec = myTabs.myInfo2Label.get(myDragSource).getBounds();
myDragRec = saved;
myTabs.moveDraggedTabLabel();
@@ -251,4 +251,4 @@ class DragHelper extends MouseDragHelper {
public TabInfo getDragSource() {
return myDragSource;
}
}
}
@@ -19,12 +19,12 @@ import com.intellij.openapi.Disposable;
import com.intellij.openapi.actionSystem.*;
import com.intellij.openapi.application.ModalityState;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.GraphicsConfig;
import com.intellij.openapi.ui.Queryable;
import com.intellij.openapi.ui.ShadowAction;
import com.intellij.openapi.util.*;
import com.intellij.openapi.util.registry.Registry;
import com.intellij.openapi.wm.*;
import com.intellij.openapi.ui.GraphicsConfig;
import com.intellij.ui.CaptionPanel;
import com.intellij.ui.ColorUtil;
import com.intellij.ui.Gray;
@@ -65,12 +65,11 @@ import java.util.concurrent.CopyOnWriteArrayList;
public class JBTabsImpl extends JComponent
implements JBTabs, PropertyChangeListener, TimerListener, DataProvider, PopupMenuListener, Disposable, JBTabsPresentation, Queryable, QuickActionProvider {
public static DataKey<JBTabsImpl> NAVIGATION_ACTIONS_KEY = DataKey.create("JBTabs");
public static final DataKey<JBTabsImpl> NAVIGATION_ACTIONS_KEY = DataKey.create("JBTabs");
public static final String EDITOR_TABS = "main.editor.tabs";
public static final Color MAC_AQUA_BG_COLOR = Gray._200;
ActionManager myActionManager;
final ActionManager myActionManager;
private final List<TabInfo> myVisibleInfos = new ArrayList<TabInfo>();
private final Map<TabInfo, Integer> myHiddenInfos = new HashMap<TabInfo, Integer>();
@@ -83,15 +82,15 @@ public class JBTabsImpl extends JComponent
private final List<EventListener> myTabMouseListeners = new CopyOnWriteArrayList<EventListener>();
private final List<TabsListener> myTabListeners = new CopyOnWriteArrayList<TabsListener>();
public boolean myFocused;
private boolean myFocused;
private Getter<ActionGroup> myPopupGroup;
private String myPopupPlace;
TabInfo myPopupInfo;
DefaultActionGroup myNavigationActions;
final DefaultActionGroup myNavigationActions;
PopupMenuListener myPopupListener;
final PopupMenuListener myPopupListener;
JPopupMenu myActivePopup;
public boolean myHorizontalSide = true;
@@ -130,7 +129,7 @@ public class JBTabsImpl extends JComponent
private boolean myPaintBlocked;
private BufferedImage myImage;
private IdeFocusManager myFocusManager;
private boolean myAdjustBorders = true;
private final boolean myAdjustBorders = true;
boolean myAddNavigationGroup = true;
@@ -177,7 +176,7 @@ public class JBTabsImpl extends JComponent
this(project, project);
}
public JBTabsImpl(@NotNull Project project, @NotNull Disposable parent) {
private JBTabsImpl(@NotNull Project project, @NotNull Disposable parent) {
this(project, ActionManager.getInstance(), IdeFocusManager.getInstance(project), parent);
}
@@ -331,8 +330,7 @@ public class JBTabsImpl extends JComponent
return this;
}
@Override
public Image getComponentImage(TabInfo info) {
public static Image getComponentImage(TabInfo info) {
JComponent cmp = info.getComponent();
BufferedImage img;
@@ -461,7 +459,7 @@ public class JBTabsImpl extends JComponent
return myDropInfo != null && myDropInfo == info;
}
public void setDropInfoIndex(int dropInfoIndex) {
protected void setDropInfoIndex(int dropInfoIndex) {
myDropInfoIndex = dropInfoIndex;
}
@@ -474,8 +472,7 @@ public class JBTabsImpl extends JComponent
public void mouseMoved(final MouseEvent e) {
if (!myTabLabelActionsAutoHide) return;
final Point point = SwingUtilities.convertPoint(e.getComponent(), e.getX(), e.getY(), JBTabsImpl.this);
myLastOverPoint = point;
myLastOverPoint = SwingUtilities.convertPoint(e.getComponent(), e.getX(), e.getY(), JBTabsImpl.this);
processMouseOver();
}
@@ -590,6 +587,7 @@ public class JBTabsImpl extends JComponent
}
@Nullable
private JComponent getToFocus() {
final TabInfo info = getSelectedInfo();
@@ -637,18 +635,6 @@ public class JBTabsImpl extends JComponent
}
}
private JBTabsImpl findTabs(Component c) {
Component eachParent = c;
while (eachParent != null) {
if (eachParent instanceof JBTabsImpl) {
return (JBTabsImpl)eachParent;
}
eachParent = eachParent.getParent();
}
return null;
}
@NotNull
public TabInfo addTab(TabInfo info, int index) {
@@ -669,10 +655,7 @@ public class JBTabsImpl extends JComponent
myInfo2Label.put(info, label);
if (!isDropTarget) {
if (index < 0) {
myVisibleInfos.add(info);
}
else if (index > myVisibleInfos.size() - 1) {
if (index < 0 || index > myVisibleInfos.size() - 1) {
myVisibleInfos.add(info);
}
else {
@@ -719,6 +702,7 @@ public class JBTabsImpl extends JComponent
return addTab(info, -1);
}
@Nullable
public ActionGroup getPopupGroup() {
return myPopupGroup != null ? myPopupGroup.get() : null;
}
@@ -847,7 +831,7 @@ public class JBTabsImpl extends JComponent
}
}
private void fireBeforeSelectionChanged(TabInfo oldInfo, TabInfo newInfo) {
private void fireBeforeSelectionChanged(@Nullable TabInfo oldInfo, TabInfo newInfo) {
if (oldInfo != newInfo) {
myOldSelection = oldInfo;
try {
@@ -861,7 +845,7 @@ public class JBTabsImpl extends JComponent
}
}
private void fireSelectionChanged(TabInfo oldInfo, TabInfo newInfo) {
private void fireSelectionChanged(@Nullable TabInfo oldInfo, TabInfo newInfo) {
if (oldInfo != newInfo) {
for (TabsListener eachListener : myTabListeners) {
if (eachListener != null) {
@@ -956,19 +940,6 @@ public class JBTabsImpl extends JComponent
myDeferredToRemove.clear();
}
private void printRemoveInfo(final Component each) {
TabInfo removingInfo = null;
final List<TabInfo> all = getTabs();
for (TabInfo eachInfo : all) {
if (eachInfo.getComponent() == each) {
removingInfo = eachInfo;
break;
}
}
//System.out.println(" - removing " + (removingInfo != null ? " component for " + removingInfo : each));
}
public void propertyChange(final PropertyChangeEvent evt) {
final TabInfo tabInfo = (TabInfo)evt.getSource();
if (TabInfo.ACTION_GROUP.equals(evt.getPropertyName())) {
@@ -1322,7 +1293,7 @@ public class JBTabsImpl extends JComponent
}
}
public boolean isToDrawBorderIfTabsHidden() {
private boolean isToDrawBorderIfTabsHidden() {
return myToDrawBorderIfTabsHidden;
}
@@ -1339,11 +1310,9 @@ public class JBTabsImpl extends JComponent
public static class Toolbar extends JPanel {
private final JBTabsImpl myTabs;
private final TabInfo myInfo;
public Toolbar(JBTabsImpl tabs, TabInfo info) {
myTabs = tabs;
myInfo = info;
setLayout(new BorderLayout());
@@ -1489,7 +1458,7 @@ public class JBTabsImpl extends JComponent
return this;
}
public Insets getInnerInsets() {
private Insets getInnerInsets() {
return myInnerInsets;
}
@@ -1542,15 +1511,15 @@ public class JBTabsImpl extends JComponent
}
protected int getArcSize() {
private static int getArcSize() {
return 4;
}
protected int getEdgeArcSize() {
private static int getEdgeArcSize() {
return 3;
}
public int getGhostTabLength() {
public static int getGhostTabLength() {
return 15;
}
@@ -1622,7 +1591,8 @@ public class JBTabsImpl extends JComponent
config.restore();
}
protected Color getActiveTabColor(final Color c) {
@Nullable
protected Color getActiveTabColor(@Nullable final Color c) {
final TabInfo info = getSelectedInfo();
if (info == null) {
return c;
@@ -1857,10 +1827,6 @@ public class JBTabsImpl extends JComponent
g2d.drawLine(bottomX - path.deltaX(1), topY + path.deltaY(getArcSize()), bottomX - path.deltaX(1), bottomY - path.deltaY(1));
}
protected SingleRowLayout getSingleRowLayout() {
return mySingleRowLayout;
}
protected void paintLastGhost(Graphics2D g2d) {
final ShapeTransform path = getEffectiveLayout().createShapeTransform(mySingleRowLayout.myLastSingRowLayout.lastGhost);
@@ -1887,25 +1853,21 @@ public class JBTabsImpl extends JComponent
g2d.drawLine(topX, topY + path.deltaY(1), bottomX - path.deltaX(getCurveArc()), topY + path.deltaY(1));
}
protected int getCurveArc() {
private static int getCurveArc() {
return 2;
}
protected Color getBoundsColor() {
private static Color getBoundsColor() {
return Color.gray;
}
protected Color getRightBlockColor() {
private static Color getRightBlockColor() {
return Color.lightGray;
}
protected Color getTopBlockColor() {
private static Color getTopBlockColor() {
return Color.white;
}
protected boolean shouldPaintFocus() {
return myPaintFocus;
}
private void paintNonSelectedTabs(final Graphics2D g2d, final boolean leftGhostExists, final boolean rightGhostExists) {
TabInfo selected = getSelectedInfo();
@@ -1976,18 +1938,6 @@ public class JBTabsImpl extends JComponent
protected LayoutPassInfo getLastLayoutPass() {
return myLastLayoutPass;
}
protected TabLabel getInfoForLabel(TabInfo info) {
return myInfo2Label.get(info);
}
protected TableLayout getTableLayout() {
return myTableLayout;
}
protected DragHelper getDragHelper() {
return myDragHelper;
}
@Override
public Color getBackground() {
@@ -2035,8 +1985,7 @@ public class JBTabsImpl extends JComponent
boolean leftFromSelection = selected != null && tabIndex == myVisibleInfos.indexOf(selected) - 1;
Rectangle originalBounds = effectiveBounds;
final ShapeTransform shape = getEffectiveLayout().createShapeTransform(originalBounds);
final ShapeTransform shape = getEffectiveLayout().createShapeTransform(effectiveBounds);
int leftX = firstShowing ? shape.getX() : shape.getX() - shape.deltaX(arc + 1);
int topY = shape.getY() + shape.deltaY(selectionTabVShift);
@@ -2115,7 +2064,7 @@ public class JBTabsImpl extends JComponent
g2d.draw(shape.getShape());
}
public int getSelectionTabVShift() {
public static int getSelectionTabVShift() {
return 2;
}
@@ -2189,7 +2138,7 @@ public class JBTabsImpl extends JComponent
}
public boolean isStealthModeEffective() {
protected boolean isStealthModeEffective() {
return myStealthTabMode && getTabCount() == 1 &&
(isSideComponentVertical() || !isSideComponentOnTabs()) &&
getTabsPosition() == JBTabsPosition.top;
@@ -2358,16 +2307,8 @@ public class JBTabsImpl extends JComponent
return this;
}
public ActionCallback removeTab(final JComponent component) {
return removeTab(findInfo(component));
}
public ActionCallback removeTab(final TabInfo info) {
return removeTab(info, null);
}
public ActionCallback removeTab(final TabInfo info, @Nullable TabInfo forcedSelectionTransfer) {
return removeTab(info, forcedSelectionTransfer, true);
return removeTab(info, null, true);
}
public ActionCallback removeTab(final TabInfo info, @Nullable TabInfo forcedSelectionTransfer, boolean transferFocus) {
@@ -2442,6 +2383,7 @@ public class JBTabsImpl extends JComponent
myLastPaintedSelection = null;
}
@Nullable
public TabInfo findInfo(Component component) {
for (TabInfo each : getTabs()) {
if (each.getComponent() == component) return each;
@@ -2450,20 +2392,11 @@ public class JBTabsImpl extends JComponent
return null;
}
public TabInfo findInfo(String text) {
if (text == null) return null;
for (TabInfo each : getTabs()) {
if (text.equals(each.getText())) return each;
}
return null;
}
public TabInfo findInfo(MouseEvent event) {
return findInfo(event, false);
}
@Nullable
private TabInfo findInfo(final MouseEvent event, final boolean labelsOnly) {
final Point point = SwingUtilities.convertPoint(event.getComponent(), event.getPoint(), this);
return _findInfo(point, labelsOnly);
@@ -2478,10 +2411,6 @@ public class JBTabsImpl extends JComponent
return null;
}
public TabInfo findTabLabelBy(final Point point) {
return _findInfo(point, true);
}
@Nullable
private TabInfo _findInfo(final Point point, boolean labelsOnly) {
Component component = findComponentAt(point);
@@ -2509,8 +2438,8 @@ public class JBTabsImpl extends JComponent
private static class Max {
Dimension myLabel = new Dimension();
Dimension myToolbar = new Dimension();
final Dimension myLabel = new Dimension();
final Dimension myToolbar = new Dimension();
}
private void updateContainer(boolean forced, final boolean layoutNow) {
@@ -2539,7 +2468,7 @@ public class JBTabsImpl extends JComponent
}
}
mySingleRowLayout.scrollSelectionInView(myVisibleInfos);
mySingleRowLayout.scrollSelectionInView();
relayout(forced, layoutNow);
}
@@ -2569,14 +2498,6 @@ public class JBTabsImpl extends JComponent
return myBorder;
}
@NotNull
public JBTabs addTabMouseMotionListener(@NotNull MouseMotionListener listener) {
removeListeners();
myTabMouseListeners.add(listener);
addListeners();
return this;
}
@NotNull
public JBTabs addTabMouseListener(@NotNull MouseListener listener) {
removeListeners();
@@ -2594,14 +2515,6 @@ public class JBTabsImpl extends JComponent
return false;
}
@NotNull
public JBTabs removeTabMouseListener(@NotNull MouseListener listener) {
removeListeners();
myTabMouseListeners.remove(listener);
addListeners();
return this;
}
private void addListeners() {
for (TabInfo eachInfo : myVisibleInfos) {
final TabLabel label = myInfo2Label.get(eachInfo);
@@ -2646,20 +2559,12 @@ public class JBTabsImpl extends JComponent
return this;
}
public JBTabs removeListener(@NotNull final TabsListener listener) {
myTabListeners.remove(listener);
return this;
}
@Override
public JBTabs setSelectionChangeHandler(SelectionChangeHandler handler) {
mySelectionChangeHandler = handler;
return this;
}
protected void onPopup(final TabInfo popupInfo) {
}
public void setFocused(final boolean focused) {
if (myFocused == focused) return;
@@ -2698,16 +2603,10 @@ public class JBTabsImpl extends JComponent
return size == -1 ? 1 : size;
}
public boolean isPaintFocus() {
private boolean isPaintFocus() {
return myPaintFocus;
}
@NotNull
public JBTabsPresentation setAdjustBorders(final boolean adjust) {
myAdjustBorders = adjust;
return this;
}
@NotNull
public JBTabsPresentation setActiveTabFillIn(@Nullable final Color color) {
if (!isChanged(myActiveTabFillIn, color)) return this;
@@ -2732,7 +2631,7 @@ public class JBTabsImpl extends JComponent
}
@Nullable
public Color getActiveTabFillIn() {
protected Color getActiveTabFillIn() {
return myActiveTabFillIn;
}
@@ -2915,7 +2814,6 @@ public class JBTabsImpl extends JComponent
return !myHorizontalSide;
}
@Override
public boolean isSideComponentOnTabs() {
return mySideComponentOnTabs;
}
@@ -2975,7 +2873,7 @@ public class JBTabsImpl extends JComponent
relayout(true, false);
}
public boolean isRequestFocusOnLastFocusedComponent() {
private boolean isRequestFocusOnLastFocusedComponent() {
return myRequestFocusOnLastFocusedComponent;
}
@@ -3028,7 +2926,7 @@ public class JBTabsImpl extends JComponent
}
public boolean isSelectionClick(final MouseEvent e, boolean canBeQuick) {
public static boolean isSelectionClick(final MouseEvent e, boolean canBeQuick) {
if (e.getClickCount() == 1 || canBeQuick) {
if (!e.isPopupTrigger()) {
return e.getButton() == MouseEvent.BUTTON1 && !e.isControlDown() && !e.isAltDown() && !e.isMetaDown();
@@ -3120,25 +3018,16 @@ public class JBTabsImpl extends JComponent
return this;
}
void reallocate(TabInfo source, TabInfo target, boolean before) {
void reallocate(TabInfo source, TabInfo target) {
if (source == target || source == null || target == null) return;
final int targetIndex = myVisibleInfos.indexOf(target);
final int sourceIndex = myVisibleInfos.indexOf(source);
boolean needsValidation = false;
myVisibleInfos.remove(source);
myVisibleInfos.add(targetIndex, source);
needsValidation = true;
//if (before && targetIndex < sourceIndex || !before && targetIndex > sourceIndex) {
//}
if (needsValidation) {
invalidate();
relayout(true, true);
}
invalidate();
relayout(true, true);
}
boolean isHorizontalTabs() {
@@ -3152,10 +3041,6 @@ public class JBTabsImpl extends JComponent
}
}
public boolean isUseBufferedPaint() {
return myUseBufferedPaint;
}
public void setUseBufferedPaint(boolean useBufferedPaint) {
myUseBufferedPaint = useBufferedPaint;
revalidate();
@@ -3280,13 +3165,11 @@ public class JBTabsImpl extends JComponent
return myDropInfoIndex;
}
@Override
public boolean isEmptyVisible() {
return myVisibleInfos.isEmpty();
}
@Override
public int getInterTabSpaceLength() {
public static int getInterTabSpaceLength() {
return 1;
}
@@ -23,7 +23,7 @@ import java.util.List;
public abstract class LayoutPassInfo {
public List<TabInfo> myVisibleInfos;
public final List<TabInfo> myVisibleInfos;
protected LayoutPassInfo(List<TabInfo> visibleInfos) {
myVisibleInfos = visibleInfos;
@@ -27,23 +27,18 @@ public abstract class ShapeTransform {
private Rectangle myShapeRect;
protected int myXTransform;
protected int myYTransform;
private boolean mySwap;
private final int myXTransform;
private final int myYTransform;
private final boolean mySwap;
public ShapeTransform(Rectangle shapeRect, int xTransform, int yTransform, boolean swap) {
protected ShapeTransform(Rectangle shapeRect, int xTransform, int yTransform, boolean swap) {
myShapeRect = shapeRect;
myXTransform = xTransform;
myYTransform = yTransform;
mySwap = swap;
}
public ShapeTransform(int XTranform, int YTranform) {
myXTransform = XTranform;
myYTransform = YTranform;
}
public final Rectangle getShapeRect() {
protected final Rectangle getShapeRect() {
return myShapeRect;
}
@@ -63,22 +58,10 @@ public abstract class ShapeTransform {
return deltaY * myYTransform;
}
public final <T> T transformX1(T o1, T o2) {
return (mySwap ? myYTransform : myXTransform) == 1 ? o1: o2;
}
public final <T> T transformX2(T o1, T o2) {
return (mySwap ? myYTransform : myXTransform) == 1 ? o2: o1;
}
public final <T> T transformY1(T o1, T o2) {
return (mySwap ? myXTransform : myYTransform) == 1 ? o1: o2;
}
public final <T> T transformY2(T o1, T o2) {
return (mySwap ? myXTransform : myYTransform) == 1 ? o2: o1;
}
public abstract Insets transformInsets(Insets insets);
public abstract Line2D.Float transformLine(int x1, int y1, int x2, int y2);
@@ -136,7 +119,7 @@ public abstract class ShapeTransform {
return reset(null);
}
public final ShapeTransform reset(Rectangle shapeRec) {
protected final ShapeTransform reset(Rectangle shapeRec) {
myPath = new GeneralPath();
if (shapeRec != null) {
myShapeRect = shapeRec;
@@ -65,7 +65,6 @@ public class TabLabel extends JPanel {
private BufferedImage myInactiveStateImage;
private Rectangle myLastPaintedInactiveImageBounds;
private boolean myStretchedByWidth;
public TabLabel(JBTabsImpl tabs, final TabInfo info) {
myTabs = tabs;
@@ -87,7 +86,7 @@ public class TabLabel extends JPanel {
addMouseListener(new MouseAdapter() {
public void mousePressed(final MouseEvent e) {
if (myTabs.isSelectionClick(e, false) && myInfo.isEnabled()) {
if (JBTabsImpl.isSelectionClick(e, false) && myInfo.isEnabled()) {
final TabInfo selectedInfo = myTabs.getSelectedInfo();
if (selectedInfo != myInfo) {
myInfo.setPreviousSelection(selectedInfo);
@@ -150,7 +149,7 @@ public class TabLabel extends JPanel {
if (myTabs.getSelectedInfo() != myInfo) {
myImage = null;
doPaint(g);
} else if (!SystemInfo.isMac) {
} else if (!SystemInfo.isMac || SystemInfo.isJavaVersionAtLeast("1.7")) {
myImage = new BufferedImage(getWidth(), getHeight(), BufferedImage.TYPE_INT_ARGB);
final Graphics2D lg = myImage.createGraphics();
doPaint(lg);
@@ -158,6 +157,16 @@ public class TabLabel extends JPanel {
}
}
@Override
public void setBounds(Rectangle r) {
super.setBounds(r);
}
@Override
public void setBounds(int x, int y, int width, int height) {
super.setBounds(x, y, width, height);
}
public void paintImage(Graphics g) {
final Rectangle b = getBounds();
if (myImage != null) {
@@ -291,7 +300,6 @@ public class TabLabel extends JPanel {
myTabs.myActivePopup.addPopupMenuListener(myTabs);
myTabs.myActivePopup.show(e.getComponent(), e.getX(), e.getY());
myTabs.onPopup(myTabs.myPopupInfo);
}
@@ -350,7 +358,7 @@ public class TabLabel extends JPanel {
return hasIcons;
}
private void setIcon(final Icon icon, int layer) {
private void setIcon(@Nullable final Icon icon, int layer) {
LayeredIcon layeredIcon = getLayeredIcon();
layeredIcon.setIcon(icon, layer);
if (hasIcons()) {
@@ -366,14 +374,6 @@ public class TabLabel extends JPanel {
return myIcon;
}
public void setAttraction(boolean enabled) {
getLayeredIcon().setLayerEnabled(1, enabled);
}
public boolean isAttractionEnabled() {
return getLayeredIcon().isLayerEnabled(1);
}
public TabInfo getInfo() {
return myInfo;
}
@@ -418,10 +418,6 @@ public class TabLabel extends JPanel {
myTabs.revalidateAndRepaint(false);
}
@Override
protected void processMouseEvent(final MouseEvent e) {
super.processMouseEvent(e);
}
private void removeOldActionPanel() {
if (myActionPanel != null) {
@@ -435,7 +431,7 @@ public class TabLabel extends JPanel {
}
private void setAttractionIcon(Icon icon) {
private void setAttractionIcon(@Nullable Icon icon) {
if (myIcon.getIcon(0) == null) {
setIcon(null, 1);
myOverlayedIcon = icon;
@@ -21,7 +21,6 @@ import org.jetbrains.annotations.NotNull;
import java.awt.*;
public abstract class TabLayout {
private Rectangle myHeaderRect;
public ShapeTransform createShapeTransform(Dimension dimension) {
return createShapeTransform(new Rectangle(0, 0, dimension.width, dimension.height));
@@ -34,12 +34,13 @@ public class TabsBorder {
public TabsBorder(JBTabsImpl tabs) {
myTabs = tabs;
myBorderSize = new Insets(tabs.getBorder(-1), tabs.getBorder(-1), tabs.getBorder(-1), tabs.getBorder(-1));
myTabBorderSize = tabs.getBorder(-1);
myBorderSize = new Insets(JBTabsImpl.getBorder(-1), JBTabsImpl.getBorder(-1), JBTabsImpl.getBorder(-1), JBTabsImpl.getBorder(-1));
myTabBorderSize = JBTabsImpl.getBorder(-1);
}
public JBTabsPresentation setPaintBorder(int top, int left, int right, int bottom) {
final Insets newBorder = new Insets(myTabs.getBorder(top), myTabs.getBorder(left), myTabs.getBorder(bottom), myTabs.getBorder(right));
final Insets newBorder = new Insets(
JBTabsImpl.getBorder(top), JBTabsImpl.getBorder(left), JBTabsImpl.getBorder(bottom), JBTabsImpl.getBorder(right));
if (newBorder.equals(myBorderSize)) return myTabs;
myBorderSize = newBorder;
@@ -52,7 +53,7 @@ public class TabsBorder {
}
public JBTabsPresentation setTabSidePaintBorder(int size) {
final int newSize = myTabs.getBorder(size);
final int newSize = JBTabsImpl.getBorder(size);
if (myTabBorderSize == newSize) return myTabs;
myTabBorderSize = newSize;
@@ -65,7 +65,7 @@ public class ScrollableSingleRowLayout extends SingleRowLayout {
}
@Override
public void scrollSelectionInView(List<TabInfo> visibleInfos) {
public void scrollSelectionInView() {
myScrollSelectionInViewPending = true;
}
@@ -29,15 +29,15 @@ import java.util.List;
public class SingleRowLayout extends TabLayout {
JBTabsImpl myTabs;
final JBTabsImpl myTabs;
public SingleRowPassInfo myLastSingRowLayout;
final SingleRowLayoutStrategy myTop;
final SingleRowLayoutStrategy myLeft;
final SingleRowLayoutStrategy myBottom;
final SingleRowLayoutStrategy myRight;
private final SingleRowLayoutStrategy myTop;
private final SingleRowLayoutStrategy myLeft;
private final SingleRowLayoutStrategy myBottom;
private final SingleRowLayoutStrategy myRight;
public MoreTabsIcon myMoreIcon = new MoreTabsIcon() {
public final MoreTabsIcon myMoreIcon = new MoreTabsIcon() {
@Nullable
protected Rectangle getIconRec() {
return myLastSingRowLayout != null ? myLastSingRowLayout.moreRect : null;
@@ -54,8 +54,8 @@ public class SingleRowLayout extends TabLayout {
public JPopupMenu myMorePopup;
public GhostComponent myLeftGhost = new GhostComponent(RowDropPolicy.first, RowDropPolicy.first);
public GhostComponent myRightGhost = new GhostComponent(RowDropPolicy.last, RowDropPolicy.first);
public final GhostComponent myLeftGhost = new GhostComponent(RowDropPolicy.first, RowDropPolicy.first);
public final GhostComponent myRightGhost = new GhostComponent(RowDropPolicy.last, RowDropPolicy.first);
private enum RowDropPolicy {
first, last
@@ -136,7 +136,7 @@ public class SingleRowLayout extends TabLayout {
return 0;
}
public void scrollSelectionInView(List<TabInfo> visibleInfos) {
public void scrollSelectionInView() {
}
public LayoutPassInfo layoutSingleRow(List<TabInfo> visibleInfos) {
@@ -202,7 +202,7 @@ public class SingleRowLayout extends TabLayout {
data.toFitLength = getStrategy().getToFitLength(data);
if (myTabs.isGhostsAlwaysVisible()) {
data.toFitLength -= myTabs.getGhostTabLength() * 2 + (myTabs.getInterTabSpaceLength() * 2);
data.toFitLength -= JBTabsImpl.getGhostTabLength() * 2 + (JBTabsImpl.getInterTabSpaceLength() * 2);
}
}
@@ -218,9 +218,9 @@ public class SingleRowLayout extends TabLayout {
private void layoutLabelsAndGhosts(final SingleRowPassInfo data) {
if (data.firstGhostVisible || myTabs.isGhostsAlwaysVisible()) {
data.firstGhost = getStrategy().getLayoutRect(data, data.position, myTabs.getGhostTabLength());
data.firstGhost = getStrategy().getLayoutRect(data, data.position, JBTabsImpl.getGhostTabLength());
myTabs.layout(myLeftGhost, data.firstGhost);
data.position += getStrategy().getLengthIncrement(data.firstGhost.getSize()) + myTabs.getInterTabSpaceLength();
data.position += getStrategy().getLengthIncrement(data.firstGhost.getSize()) + JBTabsImpl.getInterTabSpaceLength();
}
int deltaToFit = 0;
@@ -257,9 +257,9 @@ public class SingleRowLayout extends TabLayout {
boolean continueLayout = applyTabLayout(data, label, length, deltaToFit);
data.position = getStrategy().getMaxPosition(label.getBounds());
data.position += myTabs.getInterTabSpaceLength();
data.position += JBTabsImpl.getInterTabSpaceLength();
totalLength = getStrategy().getMaxPosition(label.getBounds()) - positionStart + myTabs.getInterTabSpaceLength();
totalLength = getStrategy().getMaxPosition(label.getBounds()) - positionStart + JBTabsImpl.getInterTabSpaceLength();
if (!continueLayout) {
layoutStopped = true;
}
@@ -270,7 +270,7 @@ public class SingleRowLayout extends TabLayout {
}
if (data.lastGhostVisible || myTabs.isGhostsAlwaysVisible()) {
data.lastGhost = getStrategy().getLayoutRect(data, data.position, myTabs.getGhostTabLength());
data.lastGhost = getStrategy().getLayoutRect(data, data.position, JBTabsImpl.getGhostTabLength());
myTabs.layout(myRightGhost, data.lastGhost);
}
}
@@ -344,7 +344,7 @@ public class SingleRowLayout extends TabLayout {
protected int getRequiredLength(TabInfo eachInfo) {
return getStrategy().getLengthIncrement(myTabs.myInfo2Label.get(eachInfo).getPreferredSize())
+ (myTabs.isEditorTabs() ? myTabs.getInterTabSpaceLength() : 0);
+ (myTabs.isEditorTabs() ? JBTabsImpl.getInterTabSpaceLength() : 0);
}
@@ -358,7 +358,7 @@ public class SingleRowLayout extends TabLayout {
private GhostComponent(final RowDropPolicy before, final RowDropPolicy after) {
addMouseListener(new MouseAdapter() {
public void mousePressed(final MouseEvent e) {
if (myTabs.isSelectionClick(e, true) && myInfo != null) {
if (JBTabsImpl.isSelectionClick(e, true) && myInfo != null) {
myRowDropPolicy = before;
myTabs.select(myInfo, true).doWhenDone(new Runnable() {
public void run() {
@@ -395,13 +395,13 @@ public class SingleRowLayout extends TabLayout {
if (!data.firstGhostVisible && isFirstSide) {
data.firstGhostVisible = !myTabs.isEditorTabs();
if (!myTabs.isGhostsAlwaysVisible() && !myTabs.isEditorTabs()) {
data.toFitLength -= myTabs.getGhostTabLength();
data.toFitLength -= JBTabsImpl.getGhostTabLength();
}
}
else if (!data.lastGhostVisible && !isFirstSide) {
data.lastGhostVisible = !myTabs.isEditorTabs();
if (!myTabs.isGhostsAlwaysVisible() && !myTabs.isEditorTabs()) {
data.toFitLength -= myTabs.getGhostTabLength();
data.toFitLength -= JBTabsImpl.getGhostTabLength();
}
}
}
@@ -422,7 +422,7 @@ public class SingleRowLayout extends TabLayout {
Rectangle firstBounds = first.getBounds();
Rectangle secondBounds = second.getBounds();
boolean between = false;
final boolean between;
boolean horizontal = getStrategy() instanceof SingleRowLayoutStrategy.Horizontal;
if (horizontal) {
@@ -25,8 +25,8 @@ import java.awt.*;
public abstract class SingleRowLayoutStrategy {
private static final int MIN_TAB_WIDTH = 120;
SingleRowLayout myLayout;
JBTabsImpl myTabs;
final SingleRowLayout myLayout;
final JBTabsImpl myTabs;
protected SingleRowLayoutStrategy(final SingleRowLayout layout) {
myLayout = layout;
@@ -59,8 +59,6 @@ public abstract class SingleRowLayoutStrategy {
public abstract boolean isToCenterTextWhenStretched();
public abstract Dimension getCompSizeDelta(SingleRowPassInfo data);
public abstract ShapeTransform createShapeTransform(Rectangle rectangle);
public abstract boolean canBeStretched();
@@ -182,7 +180,7 @@ public abstract class SingleRowLayoutStrategy {
else {
x = data.position + (data.lastGhostVisible ? data.lastGhost.width : 0);
}
return new Rectangle(x, data.insets.top + myTabs.getSelectionTabVShift(),
return new Rectangle(x, data.insets.top + JBTabsImpl.getSelectionTabVShift(),
data.moreRectAxisSize - 1, myTabs.myHeaderFitSize.height - 1);
}
@@ -195,7 +193,7 @@ public abstract class SingleRowLayoutStrategy {
final int vToolbarWidth = data.vToolbar != null ? data.vToolbar.getPreferredSize().width : 0;
final int x = vToolbarWidth > 0 ? vToolbarWidth + 1 : 0;
final int hToolbarHeight = !myTabs.isSideComponentOnTabs() && data.hToolbar != null ? data.hToolbar.getPreferredSize().height : 0;
final int y = data.compPosition + myTabs.myHeaderFitSize.height + (myTabs.isEditorTabs() ? 0 : 1) +
final int y = myTabs.myHeaderFitSize.height + (myTabs.isEditorTabs() ? 0 : 1) +
(hToolbarHeight > 0 ? hToolbarHeight - 2 : 0);
if (data.hToolbar != null) {
@@ -218,11 +216,6 @@ public abstract class SingleRowLayoutStrategy {
}
}
}
public Dimension getCompSizeDelta(SingleRowPassInfo data) {
return new Dimension();
}
}
static class Bottom extends Horizontal {
@@ -248,10 +241,6 @@ public abstract class SingleRowLayoutStrategy {
data.moreRectAxisSize - 1, myTabs.myHeaderFitSize.height - 1);
}
public Dimension getCompSizeDelta(SingleRowPassInfo data) {
return new Dimension(0, -(myTabs.myHeaderFitSize.height + 1));
}
@Override
public ShapeTransform createShapeTransform(Rectangle labelRec) {
return new ShapeTransform.Bottom(labelRec);
@@ -276,10 +265,6 @@ public abstract class SingleRowLayoutStrategy {
return myLayout.myMoreIcon.myIcon.getIconHeight() + 4;
}
public Dimension getCompSizeDelta(SingleRowPassInfo data) {
return new Dimension();
}
@Override
public boolean canBeStretched() {
return false;
@@ -351,7 +336,7 @@ public abstract class SingleRowLayoutStrategy {
}
public Rectangle getMoreRect(final SingleRowPassInfo data) {
return new Rectangle(data.insets.left + myTabs.getSelectionTabVShift(),
return new Rectangle(data.insets.left + JBTabsImpl.getSelectionTabVShift(),
myTabs.getHeight() - data.insets.bottom - data.moreRectAxisSize - 1,
myTabs.myHeaderFitSize.width - 1,
data.moreRectAxisSize - 1);
@@ -391,11 +376,6 @@ public abstract class SingleRowLayoutStrategy {
myTabs.myHeaderFitSize.width - 1,
data.moreRectAxisSize - 1);
}
@Override
public Dimension getCompSizeDelta(SingleRowPassInfo data) {
return new Dimension(-myTabs.myHeaderFitSize.width, 0);
}
}
}
}
@@ -26,20 +26,18 @@ import java.util.List;
public class SingleRowPassInfo extends LayoutPassInfo {
final Dimension layoutSize;
int contentCount;
final int contentCount;
int position;
int requiredLength;
int toFitLength;
public final List<TabInfo> toLayout;
public final List<TabInfo> toDrop;
int moreRectAxisSize;
final int moreRectAxisSize;
public Rectangle moreRect;
public JComponent hToolbar;
public JComponent vToolbar;
public int compPosition;
public Rectangle firstGhost;
public boolean firstGhostVisible;
@@ -48,17 +46,16 @@ public class SingleRowPassInfo extends LayoutPassInfo {
public Insets insets;
private final JBTabsImpl myTabs;
public JComponent comp;
public Rectangle tabRectangle;
int scrollOffset;
final int scrollOffset;
public SingleRowPassInfo(SingleRowLayout layout, List<TabInfo> visibleInfos) {
super(visibleInfos);
myTabs = layout.myTabs;
layoutSize = layout.myTabs.getSize();
contentCount = myTabs.getTabCount();
JBTabsImpl tabs = layout.myTabs;
layoutSize = tabs.getSize();
contentCount = tabs.getTabCount();
toLayout = new ArrayList<TabInfo>();
toDrop = new ArrayList<TabInfo>();
moreRectAxisSize = layout.getStrategy().getMoreRectAxisSize();
@@ -56,8 +56,8 @@ public class TableLayout extends TabLayout {
eachX = data.toFitRec.x;
}
myTabs.layout(eachLabel, eachX, 0, size.width, 1);
eachX += size.width + myTabs.getInterTabSpaceLength();
data.requiredWidth += size.width + myTabs.getInterTabSpaceLength();
eachX += size.width + JBTabsImpl.getInterTabSpaceLength();
data.requiredWidth += size.width + JBTabsImpl.getInterTabSpaceLength();
}
int selectedRow = -1;
@@ -84,7 +84,7 @@ public class TableLayout extends TabLayout {
if (myTabs.getSelectedInfo() == eachInfo) {
selectedRow = eachRow;
}
eachX += size.width + myTabs.getInterTabSpaceLength();
eachX += size.width + JBTabsImpl.getInterTabSpaceLength();
}
else {
eachTableRow = new TableRow(data);
@@ -161,9 +161,9 @@ public class TableLayout extends TabLayout {
label.setAlignmentToCenter(deltaToFit > 0);
boolean lastCell = i == eachRow.myColumns.size() - 1;
eachX += width + (lastCell ? 0 : myTabs.getInterTabSpaceLength());
eachX += width + (lastCell ? 0 : JBTabsImpl.getInterTabSpaceLength());
}
eachY += myTabs.myHeaderFitSize.height - 1 + myTabs.getInterTabSpaceLength() - (row < data.table.size() - 1 ? tabUnderlineFix : 0);
eachY += myTabs.myHeaderFitSize.height - 1 + JBTabsImpl.getInterTabSpaceLength() - (row < data.table.size() - 1 ? tabUnderlineFix : 0);
row++;
}
@@ -27,15 +27,15 @@ import java.util.List;
import java.util.Map;
public class TablePassInfo extends LayoutPassInfo {
List<TableRow> table = new ArrayList<TableRow>();
final List<TableRow> table = new ArrayList<TableRow>();
public Rectangle toFitRec;
Map<TabInfo, TableRow> myInfo2Row = new HashMap<TabInfo, TableRow>();
final Map<TabInfo, TableRow> myInfo2Row = new HashMap<TabInfo, TableRow>();
int requiredWidth;
int requiredRows;
int rowToFitMaxX;
JBTabsImpl myTabs;
final JBTabsImpl myTabs;
TablePassInfo(final JBTabsImpl tabs, List<TabInfo> visibleInfos) {
super(visibleInfos);
@@ -17,13 +17,13 @@ package com.intellij.ui.tabs.impl.table;
import com.intellij.ui.tabs.TabInfo;
import java.util.List;
import java.util.ArrayList;
import java.util.List;
class TableRow {
TablePassInfo myData;
List<TabInfo> myColumns = new ArrayList<TabInfo>();
private final TablePassInfo myData;
final List<TabInfo> myColumns = new ArrayList<TabInfo>();
int width;
public TableRow(final TablePassInfo data) {