KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > core > windows > view > ui > slides > SlideBarContainer


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.core.windows.view.ui.slides;
21
22 import java.awt.BorderLayout JavaDoc;
23 import java.awt.Component JavaDoc;
24 import java.awt.Dimension JavaDoc;
25 import java.awt.Insets JavaDoc;
26 import java.awt.Point JavaDoc;
27 import java.awt.Rectangle JavaDoc;
28 import java.awt.Shape JavaDoc;
29 import java.awt.Window JavaDoc;
30 import javax.swing.JPanel JavaDoc;
31 import javax.swing.SwingUtilities JavaDoc;
32 import javax.swing.border.Border JavaDoc;
33 import javax.swing.border.EmptyBorder JavaDoc;
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 /*
48  * SlideBarContainer.java
49  *
50  * @author Dafe Simonek
51  */

52 public final class SlideBarContainer extends AbstractModeContainer {
53     
54     /** panel displaying content of this container */
55     VisualPanel panel;
56     
57     /** Creates a new instance of SlideBarContainer */
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 JavaDoc getTabBounds(int tabIndex) {
83         return tabbedHandler.getTabBounds(tabIndex);
84     }
85
86     protected Component JavaDoc 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         // #48588 - when in SDI, slidein needs to front the editor frame.
104
if(active) {
105             Window JavaDoc 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 JavaDoc window = SwingUtilities.getWindowAncestor(panel);
114         // #54791 - just a doublecheck, IMHO should not happen anymore
115
// after the winsys reenetrancy fix.
116
return window == null ? false : window.isActive();
117     }
118     
119     protected void updateTitle(String JavaDoc title) {
120         // XXX - we have no title?
121
}
122     
123     /** Builds empty border around slide bar. Computes its correct size
124      * based on given orientation
125      */

126     private static Border JavaDoc computeBorder(String JavaDoc 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 JavaDoc(top, left, bottom, right);
138     }
139     
140     
141     /** Component enclosing slide boxes, implements needed interfaces to talk
142      * to rest of winsys
143      */

144     private static class VisualPanel extends JPanel JavaDoc implements ModeComponent, TopComponentDroppable {
145     
146         private final SlideBarContainer modeContainer;
147         
148         public VisualPanel (SlideBarContainer modeContainer) {
149             super(new BorderLayout JavaDoc());
150             this.modeContainer = modeContainer;
151             // To be able to activate on mouse click.
152
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         // TopComponentDroppable>>
164
public Shape JavaDoc getIndicationForLocation(Point JavaDoc location) {
165             return modeContainer.getIndicationForLocation(location);
166         }
167         
168         public Object JavaDoc getConstraintForLocation(Point JavaDoc location) {
169             return modeContainer.getConstraintForLocation(location);
170         }
171         
172         public Component JavaDoc getDropComponent() {
173             return modeContainer.getDropComponent();
174         }
175         
176         public ViewElement getDropViewElement() {
177             return modeContainer.getDropModeView();
178         }
179         
180         public boolean canDrop(TopComponent transfer, Point JavaDoc 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         // TopComponentDroppable<<
195

196         public Dimension JavaDoc getMinimumSize() {
197             if (modeContainer.getTopComponents().length == 0) {
198                 // have minimum size, to avoid gridbag layout to place the empty component at [0,0] location.
199
// clashes with the dnd
200
Border JavaDoc b = getBorder();
201                 if( null != b ) {
202                     Insets JavaDoc insets = b.getBorderInsets( this );
203                     return new Dimension JavaDoc( Math.max(1, insets.left+insets.right), Math.max(1, insets.top+insets.bottom) );
204                 }
205                 return new Dimension JavaDoc(1,1);
206             }
207             Dimension JavaDoc retValue;
208             retValue = super.getMinimumSize();
209             return retValue;
210         }
211         
212     } // End of VisualPanel
213

214 }
215
Popular Tags