analyseWriter/src/action/actUpNode.java

82 lines
3.1 KiB
Java
Raw Normal View History

package action;
2022-06-19 21:01:30 +02:00
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
2022-06-19 21:01:30 +02:00
import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.ImageIcon;
import javax.swing.JOptionPane;
import javax.swing.KeyStroke;
2022-06-19 21:01:30 +02:00
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeModel;
import javax.swing.tree.TreePath;
2022-06-19 21:01:30 +02:00
import MEPTL.commandes;
2022-06-19 21:01:30 +02:00
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) );
2022-06-19 21:01:30 +02:00
}
@Override
public void actionPerformed(ActionEvent e) {
if(fenetres.create.getTree().getSelectionPath()!=null) {
// DefaultMutableTreeNode selectNode = (DefaultMutableTreeNode) fenetres.create.getTree().getSelectionPath().getLastPathComponent();
2022-06-19 21:01:30 +02:00
node nod = (node) fenetres.create.getSelectNode().getUserObject();
DefaultMutableTreeNode selectNode = fenetres.create.getSelectNode();
2022-11-24 12:33:03 +01:00
DefaultMutableTreeNode selectParentNode = (DefaultMutableTreeNode) selectNode.getParent();
int selectedNodeIndex = selectNode.getParent().getIndex(selectNode);
int a = JOptionPane.showConfirmDialog(null,"Voulez-vous monter le node " + selectNode.toString()+ "?", "Sélectionner un choix", JOptionPane.YES_NO_OPTION);
2022-06-19 21:01:30 +02:00
if(a == JOptionPane.YES_NO_OPTION) {
if(!nod.chemin().contains("setting")) {
TreePath path = fenetres.create.getTree().getSelectionPath();
2022-11-24 12:33:03 +01:00
if(selectedNodeIndex>0) {
nod.getParent().upNodeEnfant(nod);
DefaultTreeModel treeModel = (DefaultTreeModel) fenetres.create.getTree().getModel();
treeModel.insertNodeInto(selectNode, selectParentNode, selectedNodeIndex-1);
String nameNode = nod.getNomElt();
if(nameNode.equals("text:p")||nameNode.equals("text:h")||nameNode.equals("text:list-item")||nameNode.equals("text:list")
||nameNode.equals("text:span")||nameNode.equals("text:line-break")) {
actNewFichierAnalyse.placeIsDoublonInStructure(commandes.sujet.retourneFirstEnfantsByName("structurepage"));
}
DefaultMutableTreeNode root = (DefaultMutableTreeNode) treeModel.getRoot();
fenetres.create.setTree(treeModel);
treeModel.reload(root);
2022-11-24 12:33:03 +01:00
fenetres.create.getTree().setSelectionPath(path);
fenetres.create.getTree().expandPath(path);
}
}else {
JOptionPane.showMessageDialog(null,"Vous ne devez pas déplacer ce node !", "Oh non!!!", JOptionPane.INFORMATION_MESSAGE);
}
2022-06-19 21:01:30 +02:00
}
}
}
}