1 19 20 package org.netbeans.core.windows.view.ui.slides; 21 22 import java.awt.BorderLayout ; 23 import java.awt.Component ; 24 import java.awt.Dimension ; 25 import java.awt.Insets ; 26 import java.awt.Point ; 27 import java.awt.Rectangle ; 28 import java.awt.Shape ; 29 import java.awt.Window ; 30 import javax.swing.JPanel ; 31 import javax.swing.SwingUtilities ; 32 import javax.swing.border.Border ; 33 import javax.swing.border.EmptyBorder ; 34 import org.netbeans.core.windows.Constants; 35 import org.netbeans.core.windows.WindowManagerImpl; 36 import org.netbeans.core.windows.view.ModeView; 37 import org.netbeans.core.windows.view.SlidingView; 38 import org.netbeans.core.windows.view.ViewElement; 39 import org.netbeans.core.windows.view.dnd.WindowDnDManager; 40 import org.netbeans.core.windows.view.ui.AbstractModeContainer; 41 import org.netbeans.core.windows.view.ui.ModeComponent; 42 import org.netbeans.core.windows.view.dnd.TopComponentDroppable; 43 import org.netbeans.core.windows.view.ui.Tabbed; 44 import org.openide.windows.TopComponent; 45 46 47 52 public final class SlideBarContainer extends AbstractModeContainer { 53 54 55 VisualPanel panel; 56 57 58 public SlideBarContainer(ModeView modeView, WindowDnDManager windowDnDManager) { 59 super(modeView, windowDnDManager, Constants.MODE_KIND_SLIDING); 60 61 panel = new VisualPanel(this); 62 panel.setBorder(computeBorder(getSlidingView().getSide())); 63 panel.add(this.tabbedHandler.getComponent(), BorderLayout.CENTER); 64 } 65 66 67 private SlidingView getSlidingView() { 68 return (SlidingView)super.getModeView(); 69 } 70 public void requestAttention (TopComponent tc) { 71 tabbedHandler.requestAttention(tc); 72 } 73 74 public void cancelRequestAttention (TopComponent tc) { 75 tabbedHandler.cancelRequestAttention (tc); 76 } 77 78 public void setTopComponents(TopComponent[] tcs, TopComponent selected) { 79 super.setTopComponents(tcs, selected); 80 } 81 82 public Rectangle getTabBounds(int tabIndex) { 83 return tabbedHandler.getTabBounds(tabIndex); 84 } 85 86 protected Component getModeComponent() { 87 return panel; 88 } 89 90 protected Tabbed createTabbed() { 91 return new TabbedSlideAdapter(((SlidingView)modeView).getSide()); 92 } 93 94 protected boolean isAttachingPossible() { 95 return false; 96 } 97 98 protected TopComponentDroppable getModeDroppable() { 99 return panel; 100 } 101 102 protected void updateActive(boolean active) { 103 if(active) { 105 Window window = SwingUtilities.getWindowAncestor(panel); 106 if(window != null && !window.isActive() && WindowManagerImpl.getInstance().getEditorAreaState() == Constants.EDITOR_AREA_SEPARATED) { 107 window.toFront(); 108 } 109 } 110 } 111 112 public boolean isActive() { 113 Window window = SwingUtilities.getWindowAncestor(panel); 114 return window == null ? false : window.isActive(); 117 } 118 119 protected void updateTitle(String title) { 120 } 122 123 126 private static Border computeBorder(String orientation) { 127 int bottom = 0, left = 0, right = 0, top = 0; 128 if (Constants.LEFT.equals(orientation)) { 129 top = 1; left = 1; bottom = 1; right = 2; 130 } 131 if (Constants.BOTTOM.equals(orientation)) { 132 top = 2; left = 1; bottom = 1; right = 1; 133 } 134 if (Constants.RIGHT.equals(orientation)) { 135 top = 1; left = 2; bottom = 1; right = 1; 136 } 137 return new EmptyBorder (top, left, bottom, right); 138 } 139 140 141 144 private static class VisualPanel extends JPanel implements ModeComponent, TopComponentDroppable { 145 146 private final SlideBarContainer modeContainer; 147 148 public VisualPanel (SlideBarContainer modeContainer) { 149 super(new BorderLayout ()); 150 this.modeContainer = modeContainer; 151 enableEvents(java.awt.AWTEvent.MOUSE_EVENT_MASK); 153 } 154 155 public ModeView getModeView() { 156 return modeContainer.getModeView(); 157 } 158 159 public int getKind() { 160 return modeContainer.getKind(); 161 } 162 163 public Shape getIndicationForLocation(Point location) { 165 return modeContainer.getIndicationForLocation(location); 166 } 167 168 public Object getConstraintForLocation(Point location) { 169 return modeContainer.getConstraintForLocation(location); 170 } 171 172 public Component getDropComponent() { 173 return modeContainer.getDropComponent(); 174 } 175 176 public ViewElement getDropViewElement() { 177 return modeContainer.getDropModeView(); 178 } 179 180 public boolean canDrop(TopComponent transfer, Point location) { 181 return modeContainer.canDrop(transfer); 182 } 183 184 public boolean supportsKind(int kind, TopComponent transfer) { 185 if(Constants.SWITCH_MODE_ADD_NO_RESTRICT 186 || WindowManagerImpl.getInstance().isTopComponentAllowedToMoveAnywhere(transfer)) { 187 return true; 188 } 189 boolean isNonEditor = kind == Constants.MODE_KIND_VIEW || kind == Constants.MODE_KIND_SLIDING; 190 boolean thisIsNonEditor = getKind() == Constants.MODE_KIND_VIEW || getKind() == Constants.MODE_KIND_SLIDING; 191 192 return (isNonEditor == thisIsNonEditor); 193 } 194 196 public Dimension getMinimumSize() { 197 if (modeContainer.getTopComponents().length == 0) { 198 Border b = getBorder(); 201 if( null != b ) { 202 Insets insets = b.getBorderInsets( this ); 203 return new Dimension ( Math.max(1, insets.left+insets.right), Math.max(1, insets.top+insets.bottom) ); 204 } 205 return new Dimension (1,1); 206 } 207 Dimension retValue; 208 retValue = super.getMinimumSize(); 209 return retValue; 210 } 211 212 } 214 } 215 | Popular Tags |