KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > core > windows > view > ui > DefaultSplitContainer


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
21 package org.netbeans.core.windows.view.ui;
22
23
24 import org.netbeans.core.windows.Constants;
25 import org.netbeans.core.windows.WindowManagerImpl;
26 import org.netbeans.core.windows.view.ModeView;
27 import org.netbeans.core.windows.view.ViewElement;
28 import org.netbeans.core.windows.view.dnd.TopComponentDroppable;
29 import org.netbeans.core.windows.view.dnd.WindowDnDManager;
30 import org.netbeans.core.windows.view.ui.tabcontrol.TabbedAdapter;
31 import org.openide.windows.TopComponent;
32
33 import javax.swing.*;
34 import java.awt.*;
35
36
37 /**
38  * Implementation of <code>ModeContainer</code> for joined mode kind.
39  *
40  * @author Peter Zavadsky
41  */

42 public final class DefaultSplitContainer extends AbstractModeContainer {
43
44
45     /** JPanel instance representing split mode. */
46     private final JPanel panel;
47     
48
49     /** Creates a DefaultSeparateContainer. */
50     public DefaultSplitContainer(ModeView modeView, WindowDnDManager windowDnDManager, int kind) {
51         super(modeView, windowDnDManager, kind);
52         
53         panel = new ModePanel(this);
54         
55         panel.add(this.tabbedHandler.getComponent(), BorderLayout.CENTER);
56         
57         // To be able to move split dividers.
58
panel.setMinimumSize(new Dimension(1, 1));
59     }
60     
61     public void requestAttention (TopComponent tc) {
62         tabbedHandler.requestAttention(tc);
63     }
64     
65     public void cancelRequestAttention (TopComponent tc) {
66         tabbedHandler.cancelRequestAttention(tc);
67     }
68
69     /** */
70     protected Component getModeComponent() {
71         return panel;
72     }
73     
74     protected Tabbed createTabbed() {
75         Tabbed tabbed;
76         if(getKind() == Constants.MODE_KIND_EDITOR) {
77             tabbed = new TabbedAdapter(Constants.MODE_KIND_EDITOR);
78         } else {
79             tabbed = new TabbedAdapter(Constants.MODE_KIND_VIEW);
80         }
81         return tabbed;
82     }
83     
84     protected void updateTitle(String JavaDoc title) {
85         // no op
86
}
87     
88     protected void updateActive(boolean active) {
89         if(active) {
90             Window window = SwingUtilities.getWindowAncestor(panel);
91             if(window != null && !window.isActive() && WindowManagerImpl.getInstance().getEditorAreaState() == Constants.EDITOR_AREA_SEPARATED) {
92                 // only front in SDI, in MID assume that it's either active or user doens't want it active..
93
window.toFront();
94             }
95         }
96     }
97     
98     public boolean isActive() {
99         Window window = SwingUtilities.getWindowAncestor(panel);
100         // #54791 and #56613 - just a doublecheck, IMHO should not happen anymore
101
// after the winsys reenetrancy fix.
102
return window != null ? window.isActive() : false;
103     }
104
105     protected boolean isAttachingPossible() {
106         return true;
107     }
108     
109     protected TopComponentDroppable getModeDroppable() {
110         return (ModePanel)panel;
111     }
112
113
114     /** */
115     private static class ModePanel extends JPanel
116     implements ModeComponent, TopComponentDroppable {
117     
118         private final AbstractModeContainer abstractModeContainer;
119         
120         public ModePanel(AbstractModeContainer abstractModeContainer) {
121             super(new BorderLayout());
122             this.abstractModeContainer = abstractModeContainer;
123             // To be able to activate on mouse click.
124
enableEvents(java.awt.AWTEvent.MOUSE_EVENT_MASK);
125 // Color fillC = (Color)UIManager.get("nb_workplace_fill"); //NOI18N
126
// if (fillC != null) setBackground (fillC);
127
}
128         
129         public ModeView getModeView() {
130             return abstractModeContainer.getModeView();
131         }
132         
133         public int getKind() {
134             return abstractModeContainer.getKind();
135         }
136         
137         // TopComponentDroppable>>
138
public Shape getIndicationForLocation(Point location) {
139             return abstractModeContainer.getIndicationForLocation(location);
140         }
141         
142         public Object JavaDoc getConstraintForLocation(Point location) {
143             return abstractModeContainer.getConstraintForLocation(location);
144         }
145         
146         public Component getDropComponent() {
147             return abstractModeContainer.getDropComponent();
148         }
149         
150         public ViewElement getDropViewElement() {
151             return abstractModeContainer.getDropModeView();
152         }
153         
154         public boolean canDrop(TopComponent transfer, Point location) {
155             return abstractModeContainer.canDrop(transfer);
156         }
157         
158         public boolean supportsKind(int kind, TopComponent transfer) {
159             if(Constants.SWITCH_MODE_ADD_NO_RESTRICT
160             || WindowManagerImpl.getInstance().isTopComponentAllowedToMoveAnywhere(transfer)) {
161                 return true;
162             }
163             
164             boolean isNonEditor = kind == Constants.MODE_KIND_VIEW || kind == Constants.MODE_KIND_SLIDING;
165             boolean thisIsNonEditor = getKind() == Constants.MODE_KIND_VIEW || getKind() == Constants.MODE_KIND_SLIDING;
166
167             return (isNonEditor == thisIsNonEditor);
168
169         }
170         // TopComponentDroppable<<
171
} // End of ModePanel.
172
}
173
174
Popular Tags