Search in sources :

Example 1 with CharsetCapable

use of org.exbin.deltahex.capability.CharsetCapable in project deltahex-java by exbin.

the class OverwriteCharEditDataOperation method appendEdit.

@Override
public void appendEdit(char value) {
    EditableBinaryData data = (EditableBinaryData) codeArea.getData();
    long editedDataPosition = startPosition + length;
    Charset charset = ((CharsetCapable) codeArea.getWorker()).getCharset();
    byte[] bytes = CodeAreaUtils.characterToBytes(value, charset);
    if (editedDataPosition < data.getDataSize()) {
        long overwritten = data.getDataSize() - editedDataPosition;
        if (overwritten > bytes.length) {
            overwritten = bytes.length;
        }
        EditableBinaryData overwrittenData = (EditableBinaryData) data.copy(editedDataPosition, overwritten);
        if (undoData == null) {
            undoData = overwrittenData;
        } else {
            undoData.insert(undoData.getDataSize(), overwrittenData);
        }
        for (int i = 0; i < overwritten; i++) {
            data.setByte(editedDataPosition + i, bytes[i]);
        }
    }
    if (editedDataPosition + bytes.length > data.getDataSize()) {
        if (editedDataPosition == data.getDataSize()) {
            data.insert(editedDataPosition, bytes);
        } else {
            int inserted = (int) (editedDataPosition + bytes.length - data.getDataSize());
            long insertPosition = editedDataPosition + bytes.length - inserted;
            data.insert(insertPosition, inserted);
            for (int i = 0; i < inserted; i++) {
                data.setByte(insertPosition + i, bytes[bytes.length - inserted + i]);
            }
        }
    }
    length += bytes.length;
    ((CaretCapable) codeArea.getWorker()).getCaret().setCaretPosition(startPosition + length);
}
Also used : CharsetCapable(org.exbin.deltahex.capability.CharsetCapable) EditableBinaryData(org.exbin.utils.binary_data.EditableBinaryData) Charset(java.nio.charset.Charset)

Example 2 with CharsetCapable

use of org.exbin.deltahex.capability.CharsetCapable in project deltahex-java by exbin.

the class InsertCharEditDataOperation method appendEdit.

@Override
public void appendEdit(char value) {
    EditableBinaryData data = (EditableBinaryData) codeArea.getData();
    long editedDataPosition = startPosition + length;
    Charset charset = ((CharsetCapable) codeArea.getWorker()).getCharset();
    byte[] bytes = CodeAreaUtils.characterToBytes(value, charset);
    data.insert(editedDataPosition, bytes);
    length += bytes.length;
    ((CaretCapable) codeArea.getWorker()).getCaret().setCaretPosition(startPosition + length);
}
Also used : CharsetCapable(org.exbin.deltahex.capability.CharsetCapable) EditableBinaryData(org.exbin.utils.binary_data.EditableBinaryData) Charset(java.nio.charset.Charset)

Aggregations

Charset (java.nio.charset.Charset)2 CharsetCapable (org.exbin.deltahex.capability.CharsetCapable)2 EditableBinaryData (org.exbin.utils.binary_data.EditableBinaryData)2