@ -3,6 +3,7 @@ package siprp.medicina.processo.ui;
import info.clearthought.layout.TableLayout ;
import info.clearthought.layout.TableLayoutConstraints ;
import java.awt.Dimension ;
import java.beans.PropertyChangeEvent ;
import java.beans.PropertyChangeListener ;
import java.util.ArrayList ;
@ -16,13 +17,17 @@ import javax.swing.BorderFactory;
import javax.swing.JComponent ;
import javax.swing.JDialog ;
import javax.swing.JLabel ;
import javax.swing.JSeparator ;
public class LeafOptionDialog < KeyClass extends Object > extends JDialog
{
private static final Dimension OPTION_SIZE = new Dimension ( 0 , 20 ) ;
private static final Dimension BUTTON_SIZE = new Dimension ( 0 , 20 ) ;
private static final long serialVersionUID = 1L ;
private static final String CANCEL_LABEL = "Cancelar" ;
private static String okLabel = "Ok" ;
private final JLabel labelMessage = new JLabel ( ) ;
@ -37,64 +42,46 @@ public class LeafOptionDialog<KeyClass extends Object> extends JDialog
private List < KeyClass > selected = new ArrayList < KeyClass > ( ) ;
private Map < KeyClass , Boolean > mapEnabledForKey = new HashMap < KeyClass , Boolean > ( ) ;
private Map < KeyClass , Boolean > mapChosenForKey = new HashMap < KeyClass , Boolean > ( ) ;
private String message = null ;
private boolean ordered = false ;
public LeafOptionDialog ( Map < KeyClass , ? extends Object > map )
{
super ( ) ;
startup ( map , null ) ;
}
public LeafOptionDialog ( Map < KeyClass , ? extends Object > map , String message , boolean cancelActive )
{
super ( ) ;
this . cancelActive = cancelActive ;
this . message = message ;
startup ( map , null ) ;
}
public LeafOptionDialog ( Map < KeyClass , ? extends Object > map , String message , String okButton , boolean cancelActive )
{
super ( ) ;
this . cancelActive = cancelActive ;
this . message = message ;
this . okLabel = okButton ;
super ( ) ;
startup ( map , null ) ;
}
public LeafOptionDialog ( Map < KeyClass , ? extends Object > map , String message )
{
super ( ) ;
super ( ) ;
this . message = message ;
startup ( map , null ) ;
}
public LeafOptionDialog ( OrderedMap < KeyClass > orderedMap , String message )
public LeafOptionDialog ( OrderedMap < KeyClass > orderedMap , Map < KeyClass , Boolean > chosen , Map < KeyClass , Boolean > enabled , String message , String okButton )
{
super ( ) ;
ordered = true ;
this . message = message ;
startup ( null , orderedMap ) ;
}
/** Creates a new instance of JCalendarDialog */
public LeafOptionDialog ( Map < KeyClass , ? extends Object > map , String message , String okButton )
{
super ( ) ;
this . message = message ;
this . okLabel = okButton ;
startup ( map , null ) ;
}
/** Creates a new instance of JCalendarDialog */
public LeafOptionDialog ( OrderedMap < KeyClass > orderedMap , String message , String okButton )
{
super ( ) ;
super ( ) ;
ordered = true ;
this . message = message ;
this . okLabel = okButton ;
this . mapChosenForKey = chosen ;
this . mapEnabledForKey = enabled ;
if ( chosen ! = null )
{
for ( KeyClass key : chosen . keySet ( ) )
{
Boolean isChosen = chosen . get ( key ) ;
if ( isChosen ! = null & & isChosen )
{
selected . add ( key ) ;
}
}
}
startup ( null , orderedMap ) ;
}
@ -116,24 +103,23 @@ public class LeafOptionDialog<KeyClass extends Object> extends JDialog
{
this . orderedMap = orderedMap ;
}
setupComponents ( map = = null ? orderedMap . keySet( ) : map . keySet ( ) , map = = null ? true : false ) ;
setupComponents ( map = = null ? orderedMap . iterator( ) : map . keySet( ) . iterator ( ) , map = = null ? orderedMap . rows ( ) : map . keySet ( ) . size ( ) , map = = null ? true : false ) ;
setModal ( true ) ;
setUndecorated ( true ) ;
setVisible ( true ) ;
}
private void setupComponents ( Set< KeyClass > keySet , boolean ordered )
private void setupComponents ( Iterator< KeyClass > iterator , Integer size , boolean ordered )
{
Iterator < KeyClass > iterator = keySet . iterator ( ) ;
KeyClass current = null ;
double [ ] cols = new double [ ] {
TableLayout . FILL
} ;
double [ ] rows = new double [ ( message = = null ? 0 : 1) + keySet . size ( ) + ( cancelActive ? 1 : 0 ) ] ;
double [ ] rows = new double [ ( message = = null ? 0 : 2) + size + ( cancelActive ? 2 : 0 ) ] ;
for ( int i = 0 ; i < rows . length ; + + i )
{
rows [ i ] = TableLayout . FILL ;
rows [ i ] = TableLayout . PREFERRED ;
}
TableLayout layout = new TableLayout ( cols , rows ) ;
layout . setVGap ( 3 ) ;
@ -145,8 +131,9 @@ public class LeafOptionDialog<KeyClass extends Object> extends JDialog
{
labelMessage . setText ( message ) ;
getContentPane ( ) . add ( labelMessage , new TableLayoutConstraints ( 0 , shift + + ) ) ;
getContentPane ( ) . add ( new JSeparator ( ) , new TableLayoutConstraints ( 0 , shift + + ) ) ;
}
for ( int i = 0 ; i < keySet. size( ) & & iterator . hasNext ( ) ; + + i )
for ( int i = 0 ; i < size & & iterator . hasNext ( ) ; + + i )
{
current = iterator . next ( ) ;
LeafInputField < Object > component = new LeafInputField < Object > ( ) ;
@ -161,15 +148,24 @@ public class LeafOptionDialog<KeyClass extends Object> extends JDialog
value = map . get ( current ) ;
}
component . setObject ( value ) ;
component . setClickable ( true ) ;
Boolean isChosen = mapChosenForKey . get ( current ) ;
component . setSelected ( isChosen ! = null & & isChosen ) ;
Boolean isEnabled = mapEnabledForKey . get ( current ) ;
component . setClickable ( isEnabled ! = null & & isEnabled ) ;
component . setPreferredSize ( OPTION_SIZE ) ;
getContentPane ( ) . add ( component , new TableLayoutConstraints ( 0 , i + shift ) ) ;
addListenerToComponent ( component ) ;
}
if ( cancelActive )
{
getContentPane ( ) . add ( new JSeparator ( ) , new TableLayoutConstraints ( 0 , size + shift + + ) ) ;
submitButton . setObject ( ordered ? okLabel : CANCEL_LABEL ) ;
submitButton . setClickable ( true ) ;
getContentPane ( ) . add ( submitButton , new TableLayoutConstraints ( 0 , keySet . size ( ) + shift ) ) ;
submitButton . setPreferredSize ( BUTTON_SIZE ) ;
getContentPane ( ) . add ( submitButton , new TableLayoutConstraints ( 0 , size + shift ) ) ;
addListenerToComponent ( submitButton ) ;
}
( ( JComponent ) getContentPane ( ) ) . setBorder ( BorderFactory . createRaisedBevelBorder ( ) ) ;