2023-02-05 17:46:02 +01:00
|
|
|
package action;
|
2022-06-19 21:01:30 +02:00
|
|
|
|
|
|
|
import java.awt.event.ActionEvent;
|
2022-11-22 22:17:32 +01:00
|
|
|
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;
|
2022-11-22 22:17:32 +01:00
|
|
|
import javax.swing.KeyStroke;
|
2022-06-19 21:01:30 +02:00
|
|
|
import javax.swing.tree.DefaultMutableTreeNode;
|
2022-11-22 22:17:32 +01:00
|
|
|
import javax.swing.tree.DefaultTreeModel;
|
|
|
|
import javax.swing.tree.TreePath;
|
2022-06-19 21:01:30 +02:00
|
|
|
|
2022-12-17 17:11:22 +01: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")) );
|
2022-11-22 22:17:32 +01:00
|
|
|
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) {
|
2022-11-22 22:17:32 +01:00
|
|
|
// DefaultMutableTreeNode selectNode = (DefaultMutableTreeNode) fenetres.create.getTree().getSelectionPath().getLastPathComponent();
|
2022-06-19 21:01:30 +02:00
|
|
|
|
2022-11-22 22:17:32 +01: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);
|
|
|
|
|
|
|
|
|
2022-11-22 22:17:32 +01:00
|
|
|
|
|
|
|
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) {
|
2022-11-22 22:17:32 +01:00
|
|
|
|
|
|
|
if(!nod.chemin().contains("setting")) {
|
|
|
|
|
2022-11-30 21:18:53 +01:00
|
|
|
TreePath path = fenetres.create.getTree().getSelectionPath();
|
2022-11-22 22:17:32 +01:00
|
|
|
|
2022-11-24 12:33:03 +01:00
|
|
|
if(selectedNodeIndex>0) {
|
|
|
|
nod.getParent().upNodeEnfant(nod);
|
2022-11-24 17:01:49 +01:00
|
|
|
|
|
|
|
DefaultTreeModel treeModel = (DefaultTreeModel) fenetres.create.getTree().getModel();
|
|
|
|
treeModel.insertNodeInto(selectNode, selectParentNode, selectedNodeIndex-1);
|
2022-11-30 21:18:53 +01:00
|
|
|
|
2022-12-17 17:11:22 +01:00
|
|
|
String nameNode = nod.getNomElt();
|
2022-12-18 16:22:56 +01:00
|
|
|
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"));
|
2022-12-17 17:11:22 +01:00
|
|
|
}
|
|
|
|
|
2022-11-24 17:01:49 +01:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2022-11-22 22:17:32 +01:00
|
|
|
|
|
|
|
}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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|