use of org.exbin.utils.binary_data.EditableBinaryData in project deltahex-java by exbin.
the class ExtendedCodeAreaTest method testCopyPasteInInsertMode.
@Test
public void testCopyPasteInInsertMode() {
CodeArea codeArea = new CodeArea();
((EditationModeCapable) codeArea.getWorker()).setEditationMode(EditationMode.INSERT);
EditableBinaryData sampleData = getSampleData(SAMPLE_ALLBYTES);
codeArea.setData(sampleData);
long dataSize = sampleData.getDataSize();
codeArea.selectAll();
codeArea.copy();
codeArea.clearSelection();
codeArea.paste();
Assert.assertTrue(codeArea.getDataSize() == dataSize * 2);
}
use of org.exbin.utils.binary_data.EditableBinaryData in project deltahex-java by exbin.
the class DeltaDocumentSaveTest method testSwapMiddleSaveDocument.
@Test
public void testSwapMiddleSaveDocument() {
DeltaDocument document = openTempDeltaDocument();
assertEquals(SAMPLE_ALLBYTES_SIZE, document.getDataSize());
EditableBinaryData quarterCopy = (EditableBinaryData) document.copy(64, 64);
document.remove(64, 64);
document.validatePointerPosition();
document.insert(128, quarterCopy);
document.validatePointerPosition();
quarterCopy.dispose();
try {
document.save();
InputStream comparisionFile;
try (InputStream dataInputStream = document.getDataInputStream()) {
comparisionFile = new FileInputStream(DeltaDocumentSaveTest.class.getResource(SAMPLE_SWAP_MIDDLE).getFile());
TestUtils.assertEqualsInputStream(comparisionFile, dataInputStream);
}
comparisionFile.close();
} catch (IOException ex) {
Logger.getLogger(DeltaDocumentSaveTest.class.getName()).log(Level.SEVERE, null, ex);
fail("Exception: " + ex.getMessage());
}
document.validatePointerPosition();
document.clear();
assertEquals(0, document.getSegments().size());
closeTempDeltaDocument(document);
}
use of org.exbin.utils.binary_data.EditableBinaryData in project deltahex-java by exbin.
the class DeltaDocumentSaveTest method testSwapHalfSaveDocument.
@Test
public void testSwapHalfSaveDocument() {
DeltaDocument document = openTempDeltaDocument();
assertEquals(SAMPLE_ALLBYTES_SIZE, document.getDataSize());
EditableBinaryData halfCopy = (EditableBinaryData) document.copy(0, 128);
document.remove(0, 128);
document.validatePointerPosition();
document.insert(128, halfCopy);
document.validatePointerPosition();
halfCopy.dispose();
try {
document.save();
InputStream comparisionFile;
try (InputStream dataInputStream = document.getDataInputStream()) {
comparisionFile = new FileInputStream(DeltaDocumentSaveTest.class.getResource(SAMPLE_SWAP_HALF).getFile());
TestUtils.assertEqualsInputStream(comparisionFile, dataInputStream);
}
comparisionFile.close();
} catch (IOException ex) {
Logger.getLogger(DeltaDocumentSaveTest.class.getName()).log(Level.SEVERE, null, ex);
fail("Exception: " + ex.getMessage());
}
document.validatePointerPosition();
document.clear();
assertEquals(0, document.getSegments().size());
closeTempDeltaDocument(document);
}
use of org.exbin.utils.binary_data.EditableBinaryData in project deltahex-java by exbin.
the class DeltaDocumentSaveTest method testSwapFirstQuarterSaveDocument.
@Test
public void testSwapFirstQuarterSaveDocument() {
DeltaDocument document = openTempDeltaDocument();
assertEquals(SAMPLE_ALLBYTES_SIZE, document.getDataSize());
EditableBinaryData quarterCopy = (EditableBinaryData) document.copy(0, 64);
document.remove(0, 64);
document.validatePointerPosition();
document.insert(192, quarterCopy);
document.validatePointerPosition();
quarterCopy.dispose();
try {
document.save();
InputStream comparisionFile;
try (InputStream dataInputStream = document.getDataInputStream()) {
comparisionFile = new FileInputStream(DeltaDocumentSaveTest.class.getResource(SAMPLE_SWAP_FIRST_QUARTER).getFile());
TestUtils.assertEqualsInputStream(comparisionFile, dataInputStream);
}
comparisionFile.close();
} catch (IOException ex) {
Logger.getLogger(DeltaDocumentSaveTest.class.getName()).log(Level.SEVERE, null, ex);
fail("Exception: " + ex.getMessage());
}
document.validatePointerPosition();
document.clear();
assertEquals(0, document.getSegments().size());
closeTempDeltaDocument(document);
}
use of org.exbin.utils.binary_data.EditableBinaryData in project deltahex-java by exbin.
the class DeleteCharEditDataOperation method appendEdit.
@Override
public void appendEdit(char value) {
EditableBinaryData data = (EditableBinaryData) codeArea.getData();
switch(value) {
case BACKSPACE_CHAR:
{
if (position > 0) {
position--;
if (undoData == null) {
undoData = (EditableBinaryData) data.copy(position, 1);
} else {
EditableBinaryData dataCopy = (EditableBinaryData) data.copy(position, 1);
undoData.insert(0, dataCopy);
dataCopy.dispose();
}
data.remove(position, 1);
}
break;
}
case DELETE_CHAR:
{
if (position < data.getDataSize()) {
if (undoData == null) {
undoData = (EditableBinaryData) data.copy(position, 1);
} else {
EditableBinaryData dataCopy = (EditableBinaryData) data.copy(position, 1);
undoData.insert(0, dataCopy);
dataCopy.dispose();
}
data.remove(position, 1);
}
break;
}
default:
{
throw new IllegalStateException("Unexpected character " + value);
}
}
((CaretCapable) codeArea.getWorker()).getCaret().setCaretPosition(position);
codeArea.repaint();
}
Aggregations