69 lines
2.2 KiB
Java
69 lines
2.2 KiB
Java
package fenetres.create_act;
|
|
|
|
import java.awt.Toolkit;
|
|
import java.awt.datatransfer.Clipboard;
|
|
import java.awt.datatransfer.DataFlavor;
|
|
import java.awt.datatransfer.UnsupportedFlavorException;
|
|
import java.awt.event.ActionEvent;
|
|
import java.awt.event.InputEvent;
|
|
import java.awt.event.KeyEvent;
|
|
import java.io.IOException;
|
|
import java.util.logging.Level;
|
|
import java.util.logging.Logger;
|
|
|
|
import javax.swing.AbstractAction;
|
|
import javax.swing.Action;
|
|
import javax.swing.ImageIcon;
|
|
import javax.swing.JOptionPane;
|
|
import javax.swing.KeyStroke;
|
|
import cXML.Run;
|
|
import cXML.node;
|
|
|
|
|
|
public class actPaste extends AbstractAction{
|
|
|
|
/**
|
|
*
|
|
*/
|
|
private static final long serialVersionUID = 1L;
|
|
{
|
|
putValue( Action.NAME, "Coller" );
|
|
putValue( Action.SMALL_ICON, new ImageIcon( getClass().getResource("/paste.png") ) );
|
|
putValue( Action.MNEMONIC_KEY, KeyEvent.VK_V );
|
|
putValue( Action.SHORT_DESCRIPTION, "Coller (CTRL+V)" );
|
|
putValue( Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_V, InputEvent.CTRL_DOWN_MASK) );
|
|
}
|
|
@Override
|
|
public void actionPerformed(ActionEvent e) {
|
|
String initial = "";
|
|
|
|
Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
|
|
String paste;
|
|
try {
|
|
paste = c.getContents(null).getTransferData(DataFlavor.stringFlavor).toString();
|
|
if (!paste.equals(initial)) {
|
|
node nodCopy = Run.XMLContent(paste);
|
|
if(!nodCopy.getNomElt().isEmpty()) {
|
|
node nod = (node) fenetres.create.getSelectNode().getUserObject();
|
|
nod.getNodes().add(nodCopy);
|
|
fenetres.create.constructionTree();
|
|
initial = paste;
|
|
}else {
|
|
JOptionPane.showMessageDialog(null, "Le collage n'est pas réalisé.<br>Ce n'est pas un node.");
|
|
}
|
|
|
|
}
|
|
} catch (UnsupportedFlavorException | IOException e1) {
|
|
JOptionPane.showConfirmDialog(null, e1.toString());
|
|
e1.printStackTrace();
|
|
}
|
|
|
|
try {
|
|
Thread.sleep(40);
|
|
} catch (InterruptedException ex) {
|
|
}
|
|
|
|
}
|
|
|
|
}
|