Search in sources :

Example 1 with HexModel

use of com.cburch.hex.HexModel in project logisim-evolution by reds-heig.

the class Clip method paste.

public void paste() {
    Clipboard clip = editor.getToolkit().getSystemClipboard();
    Transferable xfer = clip.getContents(this);
    int[] data;
    if (xfer.isDataFlavorSupported(binaryFlavor)) {
        try {
            data = (int[]) xfer.getTransferData(binaryFlavor);
        } catch (UnsupportedFlavorException e) {
            return;
        } catch (IOException e) {
            return;
        }
    } else if (xfer.isDataFlavorSupported(DataFlavor.stringFlavor)) {
        String buf;
        try {
            buf = (String) xfer.getTransferData(DataFlavor.stringFlavor);
        } catch (UnsupportedFlavorException e) {
            return;
        } catch (IOException e) {
            return;
        }
        try {
            data = HexFile.parse(new StringReader(buf));
        } catch (IOException e) {
            JOptionPane.showMessageDialog(editor.getRootPane(), e.getMessage(), // Strings.get("hexPasteSupportedError"),
            Strings.get("hexPasteErrorTitle"), JOptionPane.ERROR_MESSAGE);
            return;
        }
    } else {
        JOptionPane.showMessageDialog(editor.getRootPane(), Strings.get("hexPasteSupportedError"), Strings.get("hexPasteErrorTitle"), JOptionPane.ERROR_MESSAGE);
        return;
    }
    Caret caret = editor.getCaret();
    long p0 = caret.getMark();
    long p1 = caret.getDot();
    if (p0 == p1) {
        HexModel model = editor.getModel();
        if (p0 + data.length - 1 <= model.getLastOffset()) {
            model.set(p0, data);
        } else {
            JOptionPane.showMessageDialog(editor.getRootPane(), Strings.get("hexPasteEndError"), Strings.get("hexPasteErrorTitle"), JOptionPane.ERROR_MESSAGE);
        }
    } else {
        if (p0 < 0 || p1 < 0)
            return;
        if (p0 > p1) {
            long t = p0;
            p0 = p1;
            p1 = t;
        }
        p1++;
        HexModel model = editor.getModel();
        if (p1 - p0 == data.length) {
            model.set(p0, data);
        } else {
            JOptionPane.showMessageDialog(editor.getRootPane(), Strings.get("hexPasteSizeError"), Strings.get("hexPasteErrorTitle"), JOptionPane.ERROR_MESSAGE);
        }
    }
}
Also used : Transferable(java.awt.datatransfer.Transferable) StringReader(java.io.StringReader) Clipboard(java.awt.datatransfer.Clipboard) IOException(java.io.IOException) UnsupportedFlavorException(java.awt.datatransfer.UnsupportedFlavorException) Caret(com.cburch.hex.Caret) HexModel(com.cburch.hex.HexModel)

Example 2 with HexModel

use of com.cburch.hex.HexModel in project logisim-evolution by reds-heig.

the class Clip method copy.

public void copy() {
    Caret caret = editor.getCaret();
    long p0 = caret.getMark();
    long p1 = caret.getDot();
    if (p0 < 0 || p1 < 0)
        return;
    if (p0 > p1) {
        long t = p0;
        p0 = p1;
        p1 = t;
    }
    p1++;
    int[] data = new int[(int) (p1 - p0)];
    HexModel model = editor.getModel();
    for (long i = p0; i < p1; i++) {
        data[(int) (i - p0)] = model.get(i);
    }
    Clipboard clip = editor.getToolkit().getSystemClipboard();
    clip.setContents(new Data(data), this);
}
Also used : Clipboard(java.awt.datatransfer.Clipboard) Caret(com.cburch.hex.Caret) HexModel(com.cburch.hex.HexModel)

Aggregations

Caret (com.cburch.hex.Caret)2 HexModel (com.cburch.hex.HexModel)2 Clipboard (java.awt.datatransfer.Clipboard)2 Transferable (java.awt.datatransfer.Transferable)1 UnsupportedFlavorException (java.awt.datatransfer.UnsupportedFlavorException)1 IOException (java.io.IOException)1 StringReader (java.io.StringReader)1