KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > jaspersoft > jasperserver > irplugin > gui > inputcontrols > ui > BasicInputControlUI


1 /*
2  * BasicInputControlUI.java
3  *
4  * Created on June 7, 2006, 1:50 PM
5  */

6
7 package com.jaspersoft.jasperserver.irplugin.gui.inputcontrols.ui;
8
9 import javax.swing.JLabel JavaDoc;
10
11 /**
12  *
13  * @author gtoffoli
14  */

15 public class BasicInputControlUI extends javax.swing.JPanel JavaDoc implements InputControlUI {
16     
17     /** Creates new form BasicInputControlUI */
18     public BasicInputControlUI() {
19         initComponents();
20     }
21     
22     public Object JavaDoc getValue()
23     {
24         return getJComboBoxValue().getSelectedItem();
25     }
26     
27     public void setValue(Object JavaDoc v)
28     {
29         for (int i=0; i<getJComboBoxValue().getItemCount(); ++i)
30         {
31             Object JavaDoc val = getJComboBoxValue().getItemAt(i);
32             if (val.equals( v))
33             {
34                 getJComboBoxValue().setSelectedIndex(i);
35                 return;
36             }
37         }
38         
39         getJComboBoxValue().setSelectedItem(v);
40     }
41     
42     /** This method is called from within the constructor to
43      * initialize the form.
44      * WARNING: Do NOT modify this code. The content of this method is
45      * always regenerated by the Form Editor.
46      */

47     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
48
private void initComponents() {
49         java.awt.GridBagConstraints JavaDoc gridBagConstraints;
50
51         jLabelName = new javax.swing.JLabel JavaDoc();
52         jComboBoxValue = new javax.swing.JComboBox JavaDoc();
53
54         setLayout(new java.awt.GridBagLayout JavaDoc());
55
56         setPreferredSize(new java.awt.Dimension JavaDoc(250, 40));
57         jLabelName.setText("jLabel1");
58         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
59         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
60         gridBagConstraints.weightx = 1.0;
61         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 4, 0, 4);
62         add(jLabelName, gridBagConstraints);
63
64         jComboBoxValue.setEditable(true);
65         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
66         gridBagConstraints.gridx = 0;
67         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
68         gridBagConstraints.weightx = 1.0;
69         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 4, 0, 4);
70         add(jComboBoxValue, gridBagConstraints);
71
72     }// </editor-fold>//GEN-END:initComponents
73

74     public void setLabel(String JavaDoc lbl)
75     {
76         this.jLabelName.setText(lbl);
77     }
78     
79     public void setHistory(java.util.List JavaDoc values){
80         
81         getJComboBoxValue().removeAllItems();
82         if (values == null) return;
83         for (int i=0; i<values.size(); ++i)
84         {
85             getJComboBoxValue().addItem( values.get(i));
86         }
87         
88         if (getJComboBoxValue().getItemCount() > 0)
89         {
90             getJComboBoxValue().setSelectedIndex(0);
91         }
92         
93         getJComboBoxValue().updateUI();
94     }
95     
96     public void setComboEditable(boolean b)
97     {
98         getJComboBoxValue().setEditable(b);
99     }
100     
101     public boolean getComboEditable()
102     {
103         return getJComboBoxValue().isEditable();
104     }
105     
106     // Variables declaration - do not modify//GEN-BEGIN:variables
107
private javax.swing.JComboBox JavaDoc jComboBoxValue;
108     private javax.swing.JLabel JavaDoc jLabelName;
109     // End of variables declaration//GEN-END:variables
110

111     public void setReadOnly( boolean b )
112     {
113         jLabelName.setEnabled(!b);
114         getJComboBoxValue().setEnabled(!b);
115     }
116
117     public javax.swing.JComboBox JavaDoc getJComboBoxValue() {
118         return jComboBoxValue;
119     }
120
121     public void setJComboBoxValue(javax.swing.JComboBox JavaDoc jComboBoxValue) {
122         this.jComboBoxValue = jComboBoxValue;
123     }
124 }
125
Popular Tags