/*
* UI_ListChooser.java
*
* Created on 25 2008 ., 14:57
*/
package fgen.ui;
import fgen.IListChooserListener;
import fgen.ListChooserEvent;
import javax.swing.event.EventListenerList;
/**
*
* @author 109
*/
public class UI_ListChooser extends javax.swing.JFrame {
protected EventListenerList listenerList = new EventListenerList();
public void addListener(IListChooserListener aListener) {
listenerList.add(IListChooserListener.class,aListener);
}
/** Removes an <code>ItemListener</code>.
*
* @param aListener the <code>ItemListener</code> to remove
*/
public void removeListener(IListChooserListener aListener) {
listenerList.remove(IListChooserListener.class,aListener);
}
protected void fireValueChanged(ListChooserEvent e) {
// Guaranteed to return a non-null array
Object[] listeners = listenerList.getListenerList();
// Process the listeners last to first, notifying
// those that are interested in this event
for ( int i = listeners.length-2; i>=0; i-=2 ) {
if ( listeners[i]==IListChooserListener.class ) {
// Lazily create the event:
// if (changeEvent == null)
// changeEvent = new ChangeEvent(this);
((IListChooserListener)listeners[i+1]).valueChanged(e);
}
}
}
/** Creates new form UI_ListChooser */
public UI_ListChooser( String[] theList,
int selectedIndex,
boolean isModal,
IListChooserListener theParent) {
initComponents();
this.setAlwaysOnTop(isModal);
setList(theList);
CB_my.setSelectedIndex(selectedIndex);
}
public void setList(String[] theList) {
CB_my.setModel(new javax.swing.DefaultComboBoxModel(theList));
}
public void setSelectedItem(int selectedIndex) {
CB_my.setSelectedIndex(selectedIndex);
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
CB_my = new javax.swing.JComboBox();
B_my = new javax.swing.JButton();
setTitle("Choose...");
setBackground(java.awt.Color.lightGray);
B_my.setText("ok");
B_my.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
B_myActionPerformed(evt);
}
});
org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.addContainerGap()
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
.add(B_my, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 90, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(94, 94, 94))
.add(layout.createSequentialGroup()
.add(CB_my, 0, 262, Short.MAX_VALUE)
.addContainerGap())))
);
layout.setVerticalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.add(23, 23, 23)
.add(CB_my, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
.add(B_my)
.addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
pack();
}// </editor-fold>//GEN-END:initComponents
private void B_myActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_B_myActionPerformed
// TODO add your handling code here:
fireValueChanged( new ListChooserEvent(this,CB_my.getSelectedItem()) );
this.setVisible(false);
}//GEN-LAST:event_B_myActionPerformed
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton B_my;
private javax.swing.JComboBox CB_my;
// End of variables declaration//GEN-END:variables
}
|