use of com.cburch.hex.Caret 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);
}
}
}
use of com.cburch.hex.Caret 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);
}
Aggregations