Search in sources :

Example 6 with SelectionRange

use of org.exbin.deltahex.SelectionRange in project deltahex-java by exbin.

the class DeltaHexEditorBasic method postInit.

private void postInit() {
    codeArea.setComponentPopupMenu(mainPopupMenu);
    setIconImage(new javax.swing.ImageIcon(getClass().getResource("/org/exbin/deltahex/editor/basic/resources/icons/icon.png")).getImage());
    undoHandler.addUndoUpdateListener(new BinaryDataUndoUpdateListener() {

        @Override
        public void undoCommandPositionChanged() {
            updateUndoState();
            codeArea.repaint();
        }

        @Override
        public void undoCommandAdded(@Nonnull BinaryDataCommand command) {
            updateUndoState();
            codeArea.repaint();
        }
    });
    ((EditationModeCapable) codeArea.getWorker()).addEditationModeChangedListener(new EditationModeChangedListener() {

        @Override
        public void editationModeChanged(EditationMode editationMode) {
            switch(editationMode) {
                case INSERT:
                    {
                        editationModeLabel.setText("INS");
                        break;
                    }
                case OVERWRITE:
                    {
                        editationModeLabel.setText("OVR");
                        break;
                    }
                default:
                    {
                        throw new IllegalStateException("Unexpected editation mode " + editationMode.name());
                    }
            }
        }
    });
    ((CaretCapable) codeArea.getWorker()).addCaretMovedListener(new CaretMovedListener() {

        @Override
        public void caretMoved(CaretPosition caretPosition) {
            positionLabel.setText(caretPosition.getDataPosition() + ":" + caretPosition.getCodeOffset());
        }
    });
    ((SelectionCapable) codeArea.getWorker()).addSelectionChangedListener(new SelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionRange selection) {
            updateClipboardState();
        }
    });
    Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
    clipboard.addFlavorListener(new FlavorListener() {

        @Override
        public void flavorsChanged(FlavorEvent e) {
            updateClipboardState();
        }
    });
    updateUndoState();
    updateClipboardState();
    openFileButton.setText("Open");
}
Also used : SelectionChangedListener(org.exbin.deltahex.SelectionChangedListener) FlavorEvent(java.awt.datatransfer.FlavorEvent) EditationModeCapable(org.exbin.deltahex.capability.EditationModeCapable) EditationMode(org.exbin.deltahex.EditationMode) BinaryDataCommand(org.exbin.deltahex.operation.BinaryDataCommand) CaretCapable(org.exbin.deltahex.capability.CaretCapable) BinaryDataUndoUpdateListener(org.exbin.deltahex.operation.undo.BinaryDataUndoUpdateListener) CaretMovedListener(org.exbin.deltahex.CaretMovedListener) SelectionRange(org.exbin.deltahex.SelectionRange) CaretPosition(org.exbin.deltahex.CaretPosition) Clipboard(java.awt.datatransfer.Clipboard) FlavorListener(java.awt.datatransfer.FlavorListener) EditationModeChangedListener(org.exbin.deltahex.EditationModeChangedListener) SelectionCapable(org.exbin.deltahex.capability.SelectionCapable)

Example 7 with SelectionRange

use of org.exbin.deltahex.SelectionRange in project deltahex-java by exbin.

the class DefaultCodeAreaCommandHandler method copyAsCode.

@Override
public void copyAsCode() {
    SelectionRange selection = ((SelectionCapable) codeArea.getWorker()).getSelection();
    if (!selection.isEmpty()) {
        BinaryData data = codeArea.getData();
        if (data == null) {
            return;
        }
        long first = selection.getFirst();
        long last = selection.getLast();
        BinaryData copy = data.copy(first, last - first + 1);
        CodeType codeType = ((CodeTypeCapable) codeArea.getWorker()).getCodeType();
        CodeCharactersCase charactersCase = ((CodeCharactersCaseCapable) codeArea.getWorker()).getCodeCharactersCase();
        CodeAreaUtils.CodeDataClipboardData binaryData = new CodeAreaUtils.CodeDataClipboardData(copy, binaryDataFlavor, codeType, charactersCase);
        setClipboardContent(binaryData);
    }
}
Also used : CodeAreaUtils(org.exbin.deltahex.CodeAreaUtils) CodeCharactersCase(org.exbin.deltahex.CodeCharactersCase) SelectionRange(org.exbin.deltahex.SelectionRange) CodeTypeCapable(org.exbin.deltahex.capability.CodeTypeCapable) CodeType(org.exbin.deltahex.CodeType) CodeCharactersCaseCapable(org.exbin.deltahex.capability.CodeCharactersCaseCapable) EditableBinaryData(org.exbin.utils.binary_data.EditableBinaryData) BinaryData(org.exbin.utils.binary_data.BinaryData) SelectionCapable(org.exbin.deltahex.capability.SelectionCapable)

Example 8 with SelectionRange

use of org.exbin.deltahex.SelectionRange in project deltahex-java by exbin.

the class DefaultCodeAreaCommandHandler method updateSelection.

public void updateSelection(boolean selecting, @Nonnull CaretPosition caretPosition) {
    DefaultCodeAreaCaret caret = (DefaultCodeAreaCaret) ((CaretCapable) codeArea.getWorker()).getCaret();
    SelectionRange selection = ((SelectionCapable) codeArea.getWorker()).getSelection();
    if (selecting) {
        ((SelectionCapable) codeArea.getWorker()).setSelection(selection.getStart(), caret.getDataPosition());
    } else {
        ((SelectionCapable) codeArea.getWorker()).setSelection(caret.getDataPosition(), caret.getDataPosition());
    }
}
Also used : SelectionRange(org.exbin.deltahex.SelectionRange) SelectionCapable(org.exbin.deltahex.capability.SelectionCapable)

Example 9 with SelectionRange

use of org.exbin.deltahex.SelectionRange in project deltahex-java by exbin.

the class DefaultCodeAreaCommandHandler method deleteSelection.

private void deleteSelection() {
    BinaryData data = codeArea.getData();
    if (data == null) {
        return;
    }
    if (!(data instanceof EditableBinaryData)) {
        throw new IllegalStateException("Data is not editable");
    }
    SelectionRange selection = ((SelectionCapable) codeArea.getWorker()).getSelection();
    if (selection.isEmpty()) {
        return;
    }
    long first = selection.getFirst();
    long last = selection.getLast();
    ((EditableBinaryData) data).remove(first, last - first + 1);
    codeArea.clearSelection();
    DefaultCodeAreaCaret caret = (DefaultCodeAreaCaret) ((CaretCapable) codeArea.getWorker()).getCaret();
    caret.setCaretPosition(first);
    revealCursor();
    updateScrollBars();
}
Also used : EditableBinaryData(org.exbin.utils.binary_data.EditableBinaryData) SelectionRange(org.exbin.deltahex.SelectionRange) EditableBinaryData(org.exbin.utils.binary_data.EditableBinaryData) BinaryData(org.exbin.utils.binary_data.BinaryData) SelectionCapable(org.exbin.deltahex.capability.SelectionCapable)

Example 10 with SelectionRange

use of org.exbin.deltahex.SelectionRange in project deltahex-java by exbin.

the class DefaultCodeAreaCommandHandler method copy.

@Override
public void copy() {
    SelectionRange selection = ((SelectionCapable) codeArea.getWorker()).getSelection();
    if (!selection.isEmpty()) {
        BinaryData data = codeArea.getData();
        if (data == null) {
            return;
        }
        long first = selection.getFirst();
        long last = selection.getLast();
        BinaryData copy = data.copy(first, last - first + 1);
        CodeAreaUtils.BinaryDataClipboardData binaryData = new CodeAreaUtils.BinaryDataClipboardData(copy, binaryDataFlavor);
        setClipboardContent(binaryData);
    }
}
Also used : CodeAreaUtils(org.exbin.deltahex.CodeAreaUtils) SelectionRange(org.exbin.deltahex.SelectionRange) EditableBinaryData(org.exbin.utils.binary_data.EditableBinaryData) BinaryData(org.exbin.utils.binary_data.BinaryData) SelectionCapable(org.exbin.deltahex.capability.SelectionCapable)

Aggregations

SelectionRange (org.exbin.deltahex.SelectionRange)10 SelectionCapable (org.exbin.deltahex.capability.SelectionCapable)10 BinaryData (org.exbin.utils.binary_data.BinaryData)5 CodeAreaUtils (org.exbin.deltahex.CodeAreaUtils)4 EditableBinaryData (org.exbin.utils.binary_data.EditableBinaryData)3 CodeCharactersCase (org.exbin.deltahex.CodeCharactersCase)2 CodeType (org.exbin.deltahex.CodeType)2 CodeCharactersCaseCapable (org.exbin.deltahex.capability.CodeCharactersCaseCapable)2 CodeTypeCapable (org.exbin.deltahex.capability.CodeTypeCapable)2 Clipboard (java.awt.datatransfer.Clipboard)1 FlavorEvent (java.awt.datatransfer.FlavorEvent)1 FlavorListener (java.awt.datatransfer.FlavorListener)1 CaretMovedListener (org.exbin.deltahex.CaretMovedListener)1 CaretPosition (org.exbin.deltahex.CaretPosition)1 EditationMode (org.exbin.deltahex.EditationMode)1 EditationModeChangedListener (org.exbin.deltahex.EditationModeChangedListener)1 SelectionChangedListener (org.exbin.deltahex.SelectionChangedListener)1 CaretCapable (org.exbin.deltahex.capability.CaretCapable)1 EditationModeCapable (org.exbin.deltahex.capability.EditationModeCapable)1 BinaryDataCommand (org.exbin.deltahex.operation.BinaryDataCommand)1