forked from Coded/SIPRP
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
157 lines
3.8 KiB
157 lines
3.8 KiB
package siprp.medicina.processo.ui;
|
|
|
|
import info.clearthought.layout.TableLayout;
|
|
import info.clearthought.layout.TableLayoutConstraints;
|
|
|
|
import java.awt.Dimension;
|
|
import java.awt.event.ActionEvent;
|
|
import java.awt.event.ActionListener;
|
|
import java.awt.event.MouseEvent;
|
|
import java.awt.event.MouseListener;
|
|
import java.util.HashMap;
|
|
import java.util.Iterator;
|
|
import java.util.Map;
|
|
import java.util.Set;
|
|
|
|
import javax.swing.BorderFactory;
|
|
import javax.swing.JComponent;
|
|
import javax.swing.JDialog;
|
|
import javax.swing.JFrame;
|
|
import javax.swing.JTextArea;
|
|
|
|
public class LeafTextDialog extends JDialog
|
|
{
|
|
private static final long serialVersionUID = 1L;
|
|
|
|
private static final Dimension buttonSize = new Dimension( 15, 15 );
|
|
|
|
private static final Dimension textSize = new Dimension( 150, 15 );
|
|
|
|
private static final Dimension expandedTextSize = new Dimension( 100, 200 );
|
|
|
|
private String text = null;
|
|
|
|
private String defaultText = null;
|
|
|
|
private boolean expanded = false;
|
|
|
|
private final JTextArea textArea = new JTextArea();
|
|
private final LeafButton expandButton = new LeafButton( "+" );
|
|
private final LeafButton okButton = new LeafButton( "Ok" );
|
|
private final LeafButton cancelButton = new LeafButton( "X" );
|
|
|
|
private TableLayout layout = null;
|
|
private TableLayout expandedLayout = null;
|
|
|
|
/** Creates a new instance of JCalendarDialog */
|
|
public LeafTextDialog(JFrame parentFrame, JComponent parent, String defaultText)
|
|
{
|
|
super( parentFrame );
|
|
this.defaultText = defaultText == null ? "" : defaultText;
|
|
this.text = this.defaultText;
|
|
setModal( true );
|
|
setContentPane( new LeafGradientPanel() );
|
|
textArea.setText( text );
|
|
expandButton.setSize( buttonSize );
|
|
cancelButton.setSize( buttonSize );
|
|
okButton.setSize( buttonSize );
|
|
setupLayout();
|
|
setUndecorated( true );
|
|
setLocationRelativeTo( parent );
|
|
expand( expanded );
|
|
addListeners();
|
|
setVisible( true );
|
|
}
|
|
|
|
private void setupLayout()
|
|
{
|
|
double[] cols = new double[] {
|
|
TableLayout.PREFERRED, TableLayout.FILL, TableLayout.PREFERRED, TableLayout.PREFERRED
|
|
};
|
|
double[] rows = new double[] {
|
|
TableLayout.PREFERRED
|
|
};
|
|
layout = new TableLayout( cols, rows );
|
|
|
|
cols = new double[] {
|
|
TableLayout.PREFERRED, TableLayout.FILL, TableLayout.PREFERRED, TableLayout.PREFERRED
|
|
};
|
|
rows = new double[] {
|
|
TableLayout.PREFERRED
|
|
};
|
|
expandedLayout = new TableLayout( cols, rows );
|
|
}
|
|
|
|
private void placeComponents(boolean expand)
|
|
{
|
|
getContentPane().add( expandButton, new TableLayoutConstraints( 0, 0 ) );
|
|
getContentPane().add( textArea, new TableLayoutConstraints( 1, 0 ) );
|
|
getContentPane().add( okButton, new TableLayoutConstraints( 2, 0 ) );
|
|
getContentPane().add( cancelButton, new TableLayoutConstraints( 3, 0 ) );
|
|
|
|
((JComponent) getContentPane()).setBorder( BorderFactory.createRaisedBevelBorder() );
|
|
|
|
setSize( layout.preferredLayoutSize( this.getContentPane() ) );
|
|
}
|
|
|
|
private void setupComponents(boolean expand)
|
|
{
|
|
getContentPane().setLayout( expand ? expandedLayout : layout);
|
|
textArea.setSize( expand ? expandedTextSize : textSize );
|
|
expandButton.setText( expand ? "-" : "+" );
|
|
placeComponents(expand);
|
|
}
|
|
|
|
private void expand( boolean expand )
|
|
{
|
|
setupComponents(expand);
|
|
}
|
|
|
|
private void addListeners()
|
|
{
|
|
expandButton.addActionListener( new ActionListener()
|
|
{
|
|
@Override
|
|
public void actionPerformed( ActionEvent e )
|
|
{
|
|
expanded = !expanded;
|
|
expand( expanded );
|
|
}
|
|
} );
|
|
|
|
okButton.addActionListener( new ActionListener()
|
|
{
|
|
@Override
|
|
public void actionPerformed( ActionEvent e )
|
|
{
|
|
text = textArea.getText();
|
|
close();
|
|
}
|
|
} );
|
|
|
|
cancelButton.addActionListener( new ActionListener()
|
|
{
|
|
|
|
@Override
|
|
public void actionPerformed( ActionEvent e )
|
|
{
|
|
text = defaultText;
|
|
close();
|
|
}
|
|
|
|
} );
|
|
}
|
|
|
|
public String getText()
|
|
{
|
|
return text;
|
|
}
|
|
|
|
public void close()
|
|
{
|
|
setVisible( false );
|
|
dispose();
|
|
}
|
|
|
|
}
|