X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.spreadsheet.ui%2Fsrc%2Forg%2Fsimantics%2Fspreadsheet%2Fui%2FExpressionTextListener.java;h=881cdad0dfd4faf3e6f982f7a1c625009f551337;hb=5915c1bbd6d0c6125aa3c815c7843339190f28e4;hp=98aed3f8e3258c75d9bfb148d78623e2e6265c2d;hpb=969bd23cab98a79ca9101af33334000879fb60c5;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.spreadsheet.ui/src/org/simantics/spreadsheet/ui/ExpressionTextListener.java b/bundles/org.simantics.spreadsheet.ui/src/org/simantics/spreadsheet/ui/ExpressionTextListener.java index 98aed3f8e..881cdad0d 100644 --- a/bundles/org.simantics.spreadsheet.ui/src/org/simantics/spreadsheet/ui/ExpressionTextListener.java +++ b/bundles/org.simantics.spreadsheet.ui/src/org/simantics/spreadsheet/ui/ExpressionTextListener.java @@ -1,87 +1,87 @@ -package org.simantics.spreadsheet.ui; - -import java.awt.event.FocusEvent; -import java.awt.event.FocusListener; -import java.awt.event.KeyEvent; -import java.awt.event.KeyListener; - -import javax.swing.JTextField; - -import org.simantics.databoard.Bindings; -import org.simantics.databoard.binding.mutable.Variant; -import org.simantics.spreadsheet.CellEditor; -import org.simantics.spreadsheet.ClientModel; -import org.simantics.spreadsheet.util.SpreadsheetUtils; - -public class ExpressionTextListener implements FocusListener, KeyListener { - - final private JTextField text; - final private CellEditor editor; - - String undoPoint = null; - int currentRow; - int currentColumn; - - public ExpressionTextListener(JTextField text, CellEditor editor) { - this.text = text; - this.editor = editor; - } - - void setCell(String text, int row, int column) { - this.text.setText(text); - this.undoPoint = text; - this.currentRow = row; - this.currentColumn = column; - } - - void apply() { - if(undoPoint == null) { - // No selection - return; - } - String current = text.getText(); - if(current.equals(undoPoint)) return; - if(currentRow == -1 || currentColumn == -1) return; - - if (current.startsWith("=")) { - editor.edit(null, SpreadsheetUtils.cellName(currentRow, currentColumn), ClientModel.CONTENT_EXPRESSION, current, Bindings.STRING, null); - } else { - editor.edit(null, SpreadsheetUtils.cellName(currentRow, currentColumn), Variant.ofInstance(current), null); - } - undoPoint = current; - - } - - void cancel() { - if(undoPoint != null) - text.setText(undoPoint); - } - - @Override - public void keyTyped(KeyEvent e) { - } - - @Override - public void keyReleased(KeyEvent e) { - if(e.getKeyCode() == KeyEvent.VK_ENTER) { - apply(); - } - if(e.getKeyCode() == KeyEvent.VK_ESCAPE) { - cancel(); - } - } - - @Override - public void keyPressed(KeyEvent e) { - } - - @Override - public void focusGained(FocusEvent e) { - } - - @Override - public void focusLost(FocusEvent e) { - apply(); - } - -} +package org.simantics.spreadsheet.ui; + +import java.awt.event.FocusEvent; +import java.awt.event.FocusListener; +import java.awt.event.KeyEvent; +import java.awt.event.KeyListener; + +import javax.swing.JTextField; + +import org.simantics.databoard.Bindings; +import org.simantics.databoard.binding.mutable.Variant; +import org.simantics.spreadsheet.CellEditor; +import org.simantics.spreadsheet.ClientModel; +import org.simantics.spreadsheet.util.SpreadsheetUtils; + +public class ExpressionTextListener implements FocusListener, KeyListener { + + final private JTextField text; + final private CellEditor editor; + + String undoPoint = null; + int currentRow; + int currentColumn; + + public ExpressionTextListener(JTextField text, CellEditor editor) { + this.text = text; + this.editor = editor; + } + + void setCell(String text, int row, int column) { + this.text.setText(text); + this.undoPoint = text; + this.currentRow = row; + this.currentColumn = column; + } + + void apply() { + if(undoPoint == null) { + // No selection + return; + } + String current = text.getText(); + if(current.equals(undoPoint)) return; + if(currentRow == -1 || currentColumn == -1) return; + + if (current.startsWith("=")) { + editor.edit(null, SpreadsheetUtils.cellName(currentRow, currentColumn), ClientModel.CONTENT_EXPRESSION, current, Bindings.STRING, null); + } else { + editor.edit(null, SpreadsheetUtils.cellName(currentRow, currentColumn), Variant.ofInstance(current), null); + } + undoPoint = current; + + } + + void cancel() { + if(undoPoint != null) + text.setText(undoPoint); + } + + @Override + public void keyTyped(KeyEvent e) { + } + + @Override + public void keyReleased(KeyEvent e) { + if(e.getKeyCode() == KeyEvent.VK_ENTER) { + apply(); + } + if(e.getKeyCode() == KeyEvent.VK_ESCAPE) { + cancel(); + } + } + + @Override + public void keyPressed(KeyEvent e) { + } + + @Override + public void focusGained(FocusEvent e) { + } + + @Override + public void focusLost(FocusEvent e) { + apply(); + } + +}