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) {
}
};
}
Aggregations