|
|
|
|
@ -8,6 +8,9 @@ import java.awt.Insets;
|
|
|
|
|
import java.awt.Toolkit;
|
|
|
|
|
import java.awt.event.ActionEvent;
|
|
|
|
|
import java.awt.event.ActionListener;
|
|
|
|
|
import java.util.Enumeration;
|
|
|
|
|
import java.util.LinkedList;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
import javax.swing.JDialog;
|
|
|
|
|
import javax.swing.JLabel;
|
|
|
|
|
@ -21,6 +24,7 @@ import javax.swing.tree.TreePath;
|
|
|
|
|
import javax.swing.tree.TreeSelectionModel;
|
|
|
|
|
|
|
|
|
|
import com.evolute.adt.TreeTools;
|
|
|
|
|
import com.evolute.utils.error.ErrorLogger;
|
|
|
|
|
import com.evolute.utils.images.ImageException;
|
|
|
|
|
import com.evolute.utils.images.ImageIconLoader;
|
|
|
|
|
|
|
|
|
|
@ -61,6 +65,8 @@ public class TreeInserterDialog extends JDialog
|
|
|
|
|
|
|
|
|
|
private final LeafButton buttonCancel = new LeafButton( "Cancelar" );
|
|
|
|
|
|
|
|
|
|
private static List<Object> expandedNodes = new LinkedList<Object>();
|
|
|
|
|
|
|
|
|
|
public TreeInserterDialog( String title, DefaultMutableTreeNode root )
|
|
|
|
|
{
|
|
|
|
|
this.allRoot = root;
|
|
|
|
|
@ -74,13 +80,13 @@ public class TreeInserterDialog extends JDialog
|
|
|
|
|
buttonRemove = new LeafButton( ImageIconLoader.loadImageIcon( ICON_NAME_REM ) );
|
|
|
|
|
} catch( ImageException e )
|
|
|
|
|
{
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
ErrorLogger.logException( e );
|
|
|
|
|
}
|
|
|
|
|
startupComponents();
|
|
|
|
|
setupLayout();
|
|
|
|
|
placeComponents();
|
|
|
|
|
startupListeners();
|
|
|
|
|
TreeTools.refreshTree(allTree, allRoot, true);
|
|
|
|
|
loadExpansionState();
|
|
|
|
|
setEnabled();
|
|
|
|
|
Toolkit tk = Toolkit.getDefaultToolkit();
|
|
|
|
|
if( tk != null )
|
|
|
|
|
@ -96,6 +102,15 @@ public class TreeInserterDialog extends JDialog
|
|
|
|
|
this.setVisible( true );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void loadExpansionState()
|
|
|
|
|
{
|
|
|
|
|
TreeTools.refreshTree( allTree, allRoot, expandedNodes.isEmpty() );
|
|
|
|
|
for( Object userObject : expandedNodes )
|
|
|
|
|
{
|
|
|
|
|
TreeTools.expandNodeForObject( userObject, allTree );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void startupComponents()
|
|
|
|
|
{
|
|
|
|
|
newTree.setRootVisible( false );
|
|
|
|
|
@ -106,8 +121,6 @@ public class TreeInserterDialog extends JDialog
|
|
|
|
|
allScroll.setHorizontalScrollBarPolicy( JScrollPane.HORIZONTAL_SCROLLBAR_NEVER );
|
|
|
|
|
newScroll.setVerticalScrollBarPolicy( JScrollPane.VERTICAL_SCROLLBAR_ALWAYS );
|
|
|
|
|
newScroll.setHorizontalScrollBarPolicy( JScrollPane.HORIZONTAL_SCROLLBAR_NEVER );
|
|
|
|
|
// allScroll.setPreferredSize( ALL_DIMENSION );
|
|
|
|
|
// newScroll.setPreferredSize( NEW_DIMENSION );
|
|
|
|
|
buttonAdd.setToolTipText( "Adicionar" );
|
|
|
|
|
buttonRemove.setToolTipText( "Remover" );
|
|
|
|
|
buttonAdd.setMargin( new Insets(0,0,0,0) );
|
|
|
|
|
@ -253,6 +266,7 @@ public class TreeInserterDialog extends JDialog
|
|
|
|
|
|
|
|
|
|
private void close()
|
|
|
|
|
{
|
|
|
|
|
saveExpandedState();
|
|
|
|
|
setVisible( false );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -271,4 +285,45 @@ public class TreeInserterDialog extends JDialog
|
|
|
|
|
return newRoot;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void saveExpandedState( )
|
|
|
|
|
{
|
|
|
|
|
expandedNodes.clear();
|
|
|
|
|
if( allTree != null )
|
|
|
|
|
{
|
|
|
|
|
Object root = allTree.getModel().getRoot();
|
|
|
|
|
if( root != null )
|
|
|
|
|
{
|
|
|
|
|
savePath( new TreePath(root) );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void savePath( TreePath treePath )
|
|
|
|
|
{
|
|
|
|
|
if( treePath != null )
|
|
|
|
|
{
|
|
|
|
|
Enumeration<TreePath> expanded = allTree.getExpandedDescendants(treePath);
|
|
|
|
|
if( expanded != null )
|
|
|
|
|
{
|
|
|
|
|
while( expanded.hasMoreElements() )
|
|
|
|
|
{
|
|
|
|
|
TreePath path = expanded.nextElement();
|
|
|
|
|
if( path != null )
|
|
|
|
|
{
|
|
|
|
|
Object leaf = path.getLastPathComponent();
|
|
|
|
|
if( leaf instanceof DefaultMutableTreeNode )
|
|
|
|
|
{
|
|
|
|
|
Object userObject = ((DefaultMutableTreeNode)leaf).getUserObject();
|
|
|
|
|
if( userObject != null )
|
|
|
|
|
{
|
|
|
|
|
expandedNodes.add(userObject);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
savePath(path);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|