KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > schema > abe > ExtraPropertiesPanel


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-2007 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19 /*
20  * ExtraPropertiesPanel.java
21  *
22  * Created on June 12, 2006, 3:54 PM
23  *
24  * To change this template, choose Tools | Template Manager
25  * and open the template in the editor.
26  */

27
28 package org.netbeans.modules.xml.schema.abe;
29
30 import java.awt.Component JavaDoc;
31 import java.awt.event.MouseAdapter JavaDoc;
32 import java.awt.event.MouseEvent JavaDoc;
33 import javax.swing.SpringLayout JavaDoc;
34
35 /**
36  *
37  * @author girix
38  */

39 public class ExtraPropertiesPanel extends AutoSizingPanel{
40     private static final long serialVersionUID = 7526472295622776147L;
41     SpringLayout JavaDoc layout;
42     boolean leftToRight = true;
43     /** Creates a new instance of ExtraPropertiesPanel */
44     public ExtraPropertiesPanel(boolean leftToRight, InstanceUIContext context) {
45         super(context);
46         if(leftToRight){
47             setFixedHeight(true);
48             setHorizontalScaling(true);
49             setFixedPanelHeight(AttributePanel.getAttributePanelHeight());
50             setInterComponentSpacing(5);
51         }else{
52             setVerticalScaling(true);
53             setInterComponentSpacing(-2);
54         }
55         setOpaque(false);
56         this.leftToRight = leftToRight;
57     }
58     
59     public void append(Component JavaDoc component, boolean transmitEvent2parent){
60         if(leftToRight)
61             appendRight(component, transmitEvent2parent);
62         else
63             appendBelow(component);
64         
65     }
66     
67     Component JavaDoc lastComponent;
68     private void appendRight(Component JavaDoc component, boolean transmitEvent2Parent){
69         boolean alreadyAdded = false;
70         if(layout == null){
71             layout = new SpringLayout JavaDoc();
72             setLayout(layout);
73             alreadyAdded = true;
74             add(component);
75             layout.putConstraint(SpringLayout.WEST, component, getInterComponentSpacing(),
76                     SpringLayout.WEST, this);
77             lastComponent = component;
78         }
79         if(!alreadyAdded){
80             add(component);
81             layout.putConstraint(SpringLayout.WEST, component, getInterComponentSpacing(),
82                     SpringLayout.EAST, lastComponent);
83         }
84         layout.putConstraint(SpringLayout.NORTH, component, 0,
85                 SpringLayout.NORTH, this);
86         lastComponent = component;
87         if(transmitEvent2Parent)
88             component.addMouseListener(new MouseAdapter JavaDoc(){
89                 public void mouseReleased(MouseEvent JavaDoc e) {
90                     ExtraPropertiesPanel.this.dispatchEvent(e);
91                 }
92                 
93                 public void mouseClicked(MouseEvent JavaDoc e) {
94                     ExtraPropertiesPanel.this.dispatchEvent(e);
95                 }
96                 
97                 public void mousePressed(MouseEvent JavaDoc e) {
98                     ExtraPropertiesPanel.this.dispatchEvent(e);
99                 }
100                 
101             });
102     }
103     
104     private void appendBelow(Component JavaDoc component){
105         boolean alreadyAdded = false;
106         if(layout == null){
107             layout = new SpringLayout JavaDoc();
108             setLayout(layout);
109             alreadyAdded = true;
110             add(component);
111             layout.putConstraint(SpringLayout.NORTH, component, getInterComponentSpacing(),
112                     SpringLayout.NORTH, this);
113             lastComponent = component;
114         }
115         if(!alreadyAdded){
116             add(component);
117             layout.putConstraint(SpringLayout.NORTH, component, getInterComponentSpacing(),
118                     SpringLayout.SOUTH, lastComponent);
119         }
120         layout.putConstraint(SpringLayout.WEST, component, 0,
121                 SpringLayout.WEST, this);
122         lastComponent = component;
123         
124         component.addMouseListener(new MouseAdapter JavaDoc(){
125             public void mouseReleased(MouseEvent JavaDoc e) {
126                 ExtraPropertiesPanel.this.dispatchEvent(e);
127             }
128             
129             public void mouseClicked(MouseEvent JavaDoc e) {
130                 ExtraPropertiesPanel.this.dispatchEvent(e);
131             }
132             
133             public void mousePressed(MouseEvent JavaDoc e) {
134                 ExtraPropertiesPanel.this.dispatchEvent(e);
135             }
136             
137         });
138     }
139     
140     public void cleanupAll(){
141         for(Component JavaDoc child: getComponents()){
142             remove(child);
143         }
144         layout = null;
145     }
146     
147     
148     
149 }
150
Popular Tags