Search in sources :

Example 11 with EditableBinaryData

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);
}
Also used : EditationModeCapable(org.exbin.deltahex.capability.EditationModeCapable) EditableBinaryData(org.exbin.utils.binary_data.EditableBinaryData) Test(org.junit.Test)

Example 12 with EditableBinaryData

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);
}
Also used : EditableBinaryData(org.exbin.utils.binary_data.EditableBinaryData) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) Test(org.junit.Test)

Example 13 with EditableBinaryData

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);
}
Also used : EditableBinaryData(org.exbin.utils.binary_data.EditableBinaryData) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) Test(org.junit.Test)

Example 14 with EditableBinaryData

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);
}
Also used : EditableBinaryData(org.exbin.utils.binary_data.EditableBinaryData) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) Test(org.junit.Test)

Example 15 with EditableBinaryData

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();
}
Also used : EditableBinaryData(org.exbin.utils.binary_data.EditableBinaryData)

Aggregations

EditableBinaryData (org.exbin.utils.binary_data.EditableBinaryData)27 Test (org.junit.Test)11 IOException (java.io.IOException)10 FileInputStream (java.io.FileInputStream)8 InputStream (java.io.InputStream)5 BinaryData (org.exbin.utils.binary_data.BinaryData)5 JFileChooser (javax.swing.JFileChooser)3 EditationModeCapable (org.exbin.deltahex.capability.EditationModeCapable)3 File (java.io.File)2 FileNotFoundException (java.io.FileNotFoundException)2 Charset (java.nio.charset.Charset)2 FileFilter (javax.swing.filechooser.FileFilter)2 CaretPosition (org.exbin.deltahex.CaretPosition)2 CodeType (org.exbin.deltahex.CodeType)2 CharsetCapable (org.exbin.deltahex.capability.CharsetCapable)2 DeltaHexExampleBasicPanel (org.exbin.deltahex.swing.example.DeltaHexExampleBasicPanel)2 UnsupportedFlavorException (java.awt.datatransfer.UnsupportedFlavorException)1 FileOutputStream (java.io.FileOutputStream)1 SelectionRange (org.exbin.deltahex.SelectionRange)1 CaretCapable (org.exbin.deltahex.capability.CaretCapable)1