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.
134 lines
3.4 KiB
134 lines
3.4 KiB
package siprp.higiene.gestao;
|
|
|
|
import info.clearthought.layout.TableLayout;
|
|
import info.clearthought.layout.TableLayoutConstraints;
|
|
|
|
import java.awt.event.ActionEvent;
|
|
import java.awt.event.ActionListener;
|
|
|
|
import javax.swing.JPanel;
|
|
import javax.swing.JScrollPane;
|
|
import javax.swing.event.TreeSelectionEvent;
|
|
import javax.swing.event.TreeSelectionListener;
|
|
import javax.swing.tree.DefaultMutableTreeNode;
|
|
import javax.swing.tree.DefaultTreeModel;
|
|
import javax.swing.tree.TreePath;
|
|
import javax.swing.tree.TreeSelectionModel;
|
|
|
|
import leaf.ui.LeafButton;
|
|
import leaf.ui.LeafIconButton;
|
|
import leaf.ui.LeafTree;
|
|
|
|
public abstract class AdicionarPanel extends JPanel
|
|
{
|
|
|
|
private static final long serialVersionUID = 1L;
|
|
|
|
private static final String ICON_NAME_SAVE = "siprp/higiene/gestao/add.png";
|
|
|
|
private static final String ICON_NAME_REVERT = "siprp/higiene/gestao/delete.png";
|
|
|
|
protected final LeafButton buttonAdicionar = LeafIconButton.createButton( ICON_NAME_SAVE );
|
|
|
|
protected final LeafButton buttonRemover = LeafIconButton.createButton( ICON_NAME_REVERT );
|
|
|
|
public static final String SELECTION_CHANGED = "SELECTION_CHANGED";
|
|
|
|
protected final DefaultMutableTreeNode root = new DefaultMutableTreeNode();
|
|
|
|
protected final DefaultTreeModel model = new DefaultTreeModel( root );
|
|
|
|
protected final LeafTree tree = new LeafTree( model );
|
|
|
|
protected final JScrollPane scroll = new JScrollPane( tree );
|
|
|
|
public AdicionarPanel()
|
|
{
|
|
startupComponents();
|
|
setupLayout();
|
|
placeComponents();
|
|
startupListeners();
|
|
}
|
|
|
|
private void startupComponents()
|
|
{
|
|
buttonAdicionar.setEnabled( false );
|
|
buttonRemover.setEnabled( false );
|
|
tree.setRootVisible( false );
|
|
tree.getSelectionModel().setSelectionMode( TreeSelectionModel.SINGLE_TREE_SELECTION );
|
|
}
|
|
|
|
private void setupLayout()
|
|
{
|
|
TableLayout layout = new TableLayout( new double[] {
|
|
TableLayout.FILL
|
|
}, new double[] {
|
|
TableLayout.MINIMUM, TableLayout.FILL
|
|
} );
|
|
layout.setHGap( 5 );
|
|
layout.setVGap( 5 );
|
|
setLayout( layout );
|
|
}
|
|
|
|
private void placeComponents()
|
|
{
|
|
JPanel panel = new JPanel();
|
|
TableLayout layout = new TableLayout( new double[] {
|
|
TableLayout.MINIMUM, TableLayout.MINIMUM, TableLayout.FILL
|
|
}, new double[] {
|
|
TableLayout.MINIMUM
|
|
} );
|
|
layout.setHGap( 5 );
|
|
layout.setVGap( 5 );
|
|
panel.setLayout( layout );
|
|
panel.add( buttonAdicionar, new TableLayoutConstraints( 0, 0 ) );
|
|
panel.add( buttonRemover, new TableLayoutConstraints( 1, 0 ) );
|
|
|
|
add( panel, new TableLayoutConstraints( 0, 0 ) );
|
|
add( scroll, new TableLayoutConstraints( 0, 1 ) );
|
|
}
|
|
|
|
private void startupListeners()
|
|
{
|
|
buttonAdicionar.addActionListener( new ActionListener()
|
|
{
|
|
@Override
|
|
public void actionPerformed( ActionEvent e )
|
|
{
|
|
add();
|
|
}
|
|
} );
|
|
buttonRemover.addActionListener( new ActionListener()
|
|
{
|
|
@Override
|
|
public void actionPerformed( ActionEvent e )
|
|
{
|
|
rem();
|
|
}
|
|
} );
|
|
tree.getSelectionModel().addTreeSelectionListener( new TreeSelectionListener()
|
|
{
|
|
@Override
|
|
public void valueChanged( TreeSelectionEvent e )
|
|
{
|
|
TreePath path = tree.getSelectionPath();
|
|
if( path != null )
|
|
{
|
|
Object selection = path.getLastPathComponent();
|
|
firePropertyChange( SELECTION_CHANGED, null, selection );
|
|
}
|
|
setEnabled();
|
|
}
|
|
} );
|
|
}
|
|
|
|
protected abstract void rem();
|
|
|
|
protected abstract void add();
|
|
|
|
protected abstract void setEnabled();
|
|
|
|
public abstract void refresh();
|
|
|
|
}
|