f250c4ec7f
dans l'arbre)
84 lines
3.0 KiB
Java
84 lines
3.0 KiB
Java
package fenetres.create_act;
|
|
|
|
import java.awt.event.ActionEvent;
|
|
import java.awt.event.KeyEvent;
|
|
|
|
import javax.swing.AbstractAction;
|
|
import javax.swing.Action;
|
|
import javax.swing.ImageIcon;
|
|
import javax.swing.JOptionPane;
|
|
import javax.swing.KeyStroke;
|
|
import javax.swing.tree.DefaultMutableTreeNode;
|
|
import javax.swing.tree.DefaultTreeModel;
|
|
import javax.swing.tree.TreePath;
|
|
|
|
import cXML.node;
|
|
import fenetres.create;
|
|
|
|
public class actUpNode extends AbstractAction{
|
|
|
|
/**
|
|
*
|
|
*/
|
|
private static final long serialVersionUID = 1L;
|
|
{
|
|
putValue( Action.NAME, "Monter le node" );
|
|
putValue( Action.SMALL_ICON, new ImageIcon(create.class.getResource("/resources/upnodemini.png")) );
|
|
putValue( Action.SHORT_DESCRIPTION, "Monter le node (CTRL+SHIFT+C)" );
|
|
putValue( Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_U, KeyEvent.SHIFT_DOWN_MASK) );
|
|
}
|
|
@Override
|
|
public void actionPerformed(ActionEvent e) {
|
|
if(fenetres.create.getTree().getSelectionPath()!=null) {
|
|
// DefaultMutableTreeNode selectNode = (DefaultMutableTreeNode) fenetres.create.getTree().getSelectionPath().getLastPathComponent();
|
|
|
|
node nod = (node) fenetres.create.getSelectNode().getUserObject();
|
|
DefaultMutableTreeNode selectNode = fenetres.create.getSelectNode();
|
|
|
|
int a = JOptionPane.showConfirmDialog(null,"Voulez-vous monter le node " + selectNode.toString()+ "?", "Sélectionner un choix", JOptionPane.YES_NO_OPTION);
|
|
|
|
if(a == JOptionPane.YES_NO_OPTION) {
|
|
|
|
if(!nod.chemin().contains("setting")) {
|
|
|
|
TreePath path = fenetres.create.getTree().getSelectionPath().getParentPath();
|
|
|
|
nod.getParent().upNodeEnfant(nod);
|
|
|
|
DefaultMutableTreeNode SelectParentNode = (DefaultMutableTreeNode) selectNode.getParent();
|
|
SelectParentNode.removeAllChildren();
|
|
SelectParentNode = addNodeMutable(nod.getParent(),SelectParentNode);
|
|
|
|
|
|
DefaultTreeModel model = (DefaultTreeModel) fenetres.create.getTree().getModel();
|
|
DefaultMutableTreeNode root = (DefaultMutableTreeNode) model.getRoot();
|
|
model.reload(root);
|
|
|
|
fenetres.create.getTree().setSelectionPath(path);
|
|
fenetres.create.getTree().expandPath(path);
|
|
|
|
// fenetres.create.constructionTree();
|
|
}else {
|
|
JOptionPane.showMessageDialog(null,"Vous ne devez pas déplacer ce node !", "Oh non!!!", JOptionPane.INFORMATION_MESSAGE);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private static DefaultMutableTreeNode addNodeMutable(node nod, DefaultMutableTreeNode parent) {
|
|
if(nod!=null) {
|
|
DefaultMutableTreeNode node1 = null;
|
|
|
|
for(int i = 0 ; i < nod.getNodes().size(); i++) {
|
|
if(!nod.getNodes().get(i).getNomElt().equals("setting")) {
|
|
node1 = new DefaultMutableTreeNode(nod.getNodes().get(i));
|
|
addNodeMutable(nod.getNodes().get(i), node1);
|
|
parent.add(node1);
|
|
}
|
|
}
|
|
}
|
|
return parent;
|
|
}
|
|
|
|
}
|