001         package com.croftsoft.core.gui.list;
002    
003         import java.awt.*;
004         import java.awt.event.*;
005    
006         /*********************************************************************
007         * @version
008         *   $Id: DoubleListDialog.java,v 1.2 2008/09/20 07:57:24 croft Exp $
009         * @since
010         *   1998-04-12
011         * @author
012         *   <a href="https://www.croftsoft.com/">David Wallace Croft</a>
013         *********************************************************************/
014    
015         public class  DoubleListDialog extends Dialog
016           implements ActionListener, ItemListener, WindowListener
017         //////////////////////////////////////////////////////////////////////
018         //////////////////////////////////////////////////////////////////////
019         {
020    
021         private DoubleListDialogListener  doubleListDialogListener;
022         private List    list_l;
023         private List    list_r;
024         private Button  accept_Button;
025         private Button  cancel_Button;
026    
027         //////////////////////////////////////////////////////////////////////
028         //////////////////////////////////////////////////////////////////////
029    
030         public  DoubleListDialog (
031           Frame       parent,
032           String      title,
033           boolean     modal,
034           boolean     multipleMode_left,
035           boolean     multipleMode_right,
036           String [ ]  items_left,
037           String [ ]  items_right,
038           String      accept_label,
039           String      cancel_label,
040           int         x,
041           int         y,
042           int         w,
043           int         h,
044           DoubleListDialogListener  doubleListDialogListener )
045         //////////////////////////////////////////////////////////////////////
046         {
047           super ( parent, title, modal );
048           this.doubleListDialogListener = doubleListDialogListener;
049           setLayout ( null );
050           accept_Button = new Button ( accept_label );
051           cancel_Button = new Button ( cancel_label );
052           int  rows = items_left.length > items_right.length
053             ? items_left.length : items_right.length;
054           list_l = new List ( rows, multipleMode_left  );
055           list_r = new List ( rows, multipleMode_right );
056           for ( int  i = 0; i < items_left.length; i++ )
057             list_l.add ( items_left [ i ] );
058           for ( int  i = 0; i < items_right.length; i++ )
059             list_r.add ( items_right [ i ] );
060           add ( accept_Button );
061           add ( cancel_Button );
062           add ( list_l );
063           add ( list_r );
064           accept_Button.setEnabled ( false );
065           accept_Button.addActionListener ( this );
066           cancel_Button.addActionListener ( this );
067           list_l.addItemListener ( this );
068           list_r.addItemListener ( this );
069           addWindowListener ( this );
070           setBounds ( x, y, w, h );
071           show ( );
072         }
073    
074         public synchronized void  itemStateChanged ( ItemEvent  e )
075         //////////////////////////////////////////////////////////////////////
076         {
077           Object  source = e.getSource ( );
078           if ( ( source == list_l ) || ( source == list_r ) )
079           {
080             accept_Button.setEnabled (
081                  ( list_l.getSelectedItems ( ).length > 0 )
082               && ( list_r.getSelectedItems ( ).length > 0 ) );
083           }
084         }
085    
086         public synchronized void  actionPerformed ( ActionEvent  e )
087         //////////////////////////////////////////////////////////////////////
088         {
089           Object  source = e.getSource ( );
090           if ( source == accept_Button )
091           {
092             doubleListDialogListener.doubleListDialogAccept (
093               list_l.getSelectedItems ( ),
094               list_r.getSelectedItems ( ) );
095             dispose ( );
096           }
097           else if ( source == cancel_Button )
098           {
099             dispose ( );
100           }
101         }
102    
103         public void  windowClosing ( WindowEvent  e )
104         //////////////////////////////////////////////////////////////////////
105         {
106           dispose ( );
107         }
108    
109         public synchronized void  dispose ( )
110         //////////////////////////////////////////////////////////////////////
111         {
112           doubleListDialogListener.doubleListDialogAccept ( null, null );
113           super.dispose ( );
114         }
115    
116         public void  doLayout ( )
117         //////////////////////////////////////////////////////////////////////
118         {
119           Rectangle  bounds = getBounds ( );
120           Insets  insets = getInsets ( );
121    
122           Rectangle  r = new Rectangle ( insets.left, insets.top,
123             bounds.width - insets.left - insets.right,
124             bounds.height - insets.top - insets.bottom );
125    
126           int  button_height = accept_Button.getMinimumSize ( ).height;
127           int  list_height = r.height - button_height;
128    
129           list_l.setBounds ( r.x, r.y, r.width / 2, list_height );
130           list_r.setBounds (
131             r.x + r.width / 2, r.y, r.width / 2, list_height );
132           accept_Button.setBounds ( r.x, r.y + list_height,
133             r.width / 2, button_height );
134           cancel_Button.setBounds ( r.x + r.width / 2, r.y + list_height,
135             r.width / 2, button_height );
136         }
137    
138         public void  windowActivated   ( WindowEvent  e ) { }
139         public void  windowClosed      ( WindowEvent  e ) { }
140         public void  windowDeactivated ( WindowEvent  e ) { }
141         public void  windowDeiconified ( WindowEvent  e ) { }
142         public void  windowIconified   ( WindowEvent  e ) { }
143         public void  windowOpened      ( WindowEvent  e ) { }
144    
145         //////////////////////////////////////////////////////////////////////
146         //////////////////////////////////////////////////////////////////////
147         }