KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openharmonise > him > metadata > range > swing > range > RangeTypeChoice


1 /*
2  * The contents of this file are subject to the
3  * Mozilla Public License Version 1.1 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at http://www.mozilla.org/MPL/
6  *
7  * Software distributed under the License is distributed on an "AS IS"
8  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
9  * See the License for the specific language governing rights and
10  * limitations under the License.
11  *
12  * The Initial Developer of the Original Code is Simulacra Media Ltd.
13  * Portions created by Simulacra Media Ltd are Copyright (C) Simulacra Media Ltd, 2004.
14  *
15  * All Rights Reserved.
16  *
17  * Contributor(s):
18  */

19 package org.openharmonise.him.metadata.range.swing.range;
20
21 import java.awt.*;
22 import java.awt.event.*;
23
24 import javax.swing.*;
25
26 /**
27  * @author Matthew Large
28  * @version $Revision: 1.1 $
29  *
30  */

31 public class RangeTypeChoice extends JPanel implements LayoutManager, ActionListener {
32
33     private RangeRangeDisplay m_display = null;
34     
35     private JComboBox m_comboBox = null;
36     
37     private boolean m_bInitialChoice = true;
38
39     /**
40      *
41      */

42     public RangeTypeChoice(RangeRangeDisplay display) {
43         super();
44         this.m_display = display;
45         this.setup();
46     }
47     
48     private void setup() {
49         this.setLayout(this);
50         
51         String JavaDoc[] aOptions = new String JavaDoc[]{"Text","Number","Date","Boolean","Vocabularies","Compound Property","Relationship"};
52         
53         this.m_comboBox = new JComboBox(aOptions);
54         m_comboBox.addActionListener(this);
55         this.add(this.m_comboBox);
56         
57     }
58
59     /**
60      * @param arg0
61      */

62     private RangeTypeChoice(boolean arg0) {
63         super(arg0);
64     }
65
66     /**
67      * @param arg0
68      */

69     private RangeTypeChoice(LayoutManager arg0) {
70         super(arg0);
71     }
72
73     /**
74      * @param arg0
75      * @param arg1
76      */

77     private RangeTypeChoice(LayoutManager arg0, boolean arg1) {
78         super(arg0, arg1);
79     }
80
81     /* (non-Javadoc)
82      * @see java.awt.LayoutManager#removeLayoutComponent(java.awt.Component)
83      */

84     public void removeLayoutComponent(Component arg0) {
85     }
86
87     /* (non-Javadoc)
88      * @see java.awt.LayoutManager#layoutContainer(java.awt.Container)
89      */

90     public void layoutContainer(Container arg0) {
91         int nHeight = 0;
92         int nSpacing = 40;
93         
94         m_comboBox.setSize(m_comboBox.getPreferredSize());
95         m_comboBox.setLocation(0,nHeight);
96         nHeight = nHeight+nSpacing;
97     }
98     
99     public Dimension getPreferredSize() {
100         return new Dimension(this.m_comboBox.getPreferredSize().width, this.m_comboBox.getPreferredSize().height);
101     }
102
103     /* (non-Javadoc)
104      * @see java.awt.LayoutManager#addLayoutComponent(java.lang.String, java.awt.Component)
105      */

106     public void addLayoutComponent(String JavaDoc arg0, Component arg1) {
107     }
108
109     /* (non-Javadoc)
110      * @see java.awt.LayoutManager#minimumLayoutSize(java.awt.Container)
111      */

112     public Dimension minimumLayoutSize(Container arg0) {
113         return this.getPreferredSize();
114     }
115
116     /* (non-Javadoc)
117      * @see java.awt.LayoutManager#preferredLayoutSize(java.awt.Container)
118      */

119     public Dimension preferredLayoutSize(Container arg0) {
120         return this.getPreferredSize();
121     }
122
123     /* (non-Javadoc)
124      * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
125      */

126     public void actionPerformed(ActionEvent ae) {
127         String JavaDoc sSelectedItem = (String JavaDoc) this.m_comboBox.getSelectedItem();
128         if(sSelectedItem!=null && sSelectedItem.length()>0 && !m_bInitialChoice) {
129             this.m_display.typeSelected(sSelectedItem);
130         }
131         if(m_bInitialChoice) {
132             m_bInitialChoice = false;
133         }
134     }
135     
136     protected void selectChoice(String JavaDoc sTemp) {
137         System.out.println(sTemp);
138         if(sTemp!=null && sTemp.length()>0) {
139             this.m_comboBox.setSelectedItem(sTemp);
140         }
141     }
142
143 }
144
Popular Tags