Search in sources :

Example 1 with SelectionLayer

use of com.android.tools.idea.uibuilder.mockup.editor.SelectionLayer in project android by JetBrains.

the class SelectionEditors method createDocumentListener.

/**
   * Create a document listener that will update the {@link MockupViewPanel} selection
   * when the attached document is updated.
   *
   * @return the new document listener
   */
private DocumentListener createDocumentListener() {
    return new DocumentListener() {

        private void processChange(@NotNull DocumentEvent e) {
            if (myBoundsUpdating) {
                return;
            }
            try {
                Document document = e.getDocument();
                int value;
                if (document.getLength() <= 0) {
                    value = 0;
                } else {
                    value = Integer.parseInt(document.getText(0, document.getLength()));
                }
                SelectionLayer selectionLayer = myMockupViewPanel.getSelectionLayer();
                Rectangle selection = selectionLayer.getSelection();
                if (document == myBoundsDocuments[W]) {
                    selectionLayer.setSelection(selection.x, selection.y, value, selection.height);
                } else if (document == myBoundsDocuments[H]) {
                    selectionLayer.setSelection(selection.x, selection.y, selection.width, value);
                } else if (document == myBoundsDocuments[X]) {
                    selectionLayer.setSelection(value, selection.y, selection.width, selection.height);
                } else if (document == myBoundsDocuments[Y]) {
                    selectionLayer.setSelection(selection.x, value, selection.width, selection.height);
                }
            } catch (BadLocationException | NumberFormatException ex) {
            // Do nothing
            }
        }

        @Override
        public void insertUpdate(DocumentEvent e) {
            processChange(e);
        }

        @Override
        public void removeUpdate(DocumentEvent e) {
            processChange(e);
        }

        @Override
        public void changedUpdate(DocumentEvent e) {
        }
    };
}
Also used : DocumentListener(javax.swing.event.DocumentListener) SelectionLayer(com.android.tools.idea.uibuilder.mockup.editor.SelectionLayer) DocumentEvent(javax.swing.event.DocumentEvent) Document(javax.swing.text.Document) NotNull(org.jetbrains.annotations.NotNull) BadLocationException(javax.swing.text.BadLocationException)

Aggregations

SelectionLayer (com.android.tools.idea.uibuilder.mockup.editor.SelectionLayer)1 DocumentEvent (javax.swing.event.DocumentEvent)1 DocumentListener (javax.swing.event.DocumentListener)1 BadLocationException (javax.swing.text.BadLocationException)1 Document (javax.swing.text.Document)1 NotNull (org.jetbrains.annotations.NotNull)1