]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.spreadsheet.ui/src/org/simantics/spreadsheet/ui/ExpressionTextListener.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.spreadsheet.ui / src / org / simantics / spreadsheet / ui / ExpressionTextListener.java
index 98aed3f8e3258c75d9bfb148d78623e2e6265c2d..881cdad0dfd4faf3e6f982f7a1c625009f551337 100644 (file)
@@ -1,87 +1,87 @@
-package org.simantics.spreadsheet.ui;\r
-\r
-import java.awt.event.FocusEvent;\r
-import java.awt.event.FocusListener;\r
-import java.awt.event.KeyEvent;\r
-import java.awt.event.KeyListener;\r
-\r
-import javax.swing.JTextField;\r
-\r
-import org.simantics.databoard.Bindings;\r
-import org.simantics.databoard.binding.mutable.Variant;\r
-import org.simantics.spreadsheet.CellEditor;\r
-import org.simantics.spreadsheet.ClientModel;\r
-import org.simantics.spreadsheet.util.SpreadsheetUtils;\r
-\r
-public class ExpressionTextListener implements FocusListener, KeyListener {\r
-\r
-       final private JTextField text;\r
-       final private CellEditor editor;\r
-       \r
-       String undoPoint = null;\r
-       int currentRow;\r
-       int currentColumn;\r
-       \r
-       public ExpressionTextListener(JTextField text, CellEditor editor) {\r
-               this.text = text;\r
-               this.editor = editor;\r
-       }\r
-       \r
-       void setCell(String text, int row, int column) {\r
-               this.text.setText(text);\r
-               this.undoPoint = text;\r
-               this.currentRow = row;\r
-               this.currentColumn = column;\r
-       }\r
-       \r
-       void apply() {\r
-               if(undoPoint == null) {\r
-                       // No selection\r
-                       return;\r
-               }\r
-               String current = text.getText();\r
-               if(current.equals(undoPoint)) return;\r
-               if(currentRow == -1 || currentColumn == -1) return;\r
-               \r
-               if (current.startsWith("=")) {\r
-                   editor.edit(null, SpreadsheetUtils.cellName(currentRow, currentColumn), ClientModel.CONTENT_EXPRESSION, current, Bindings.STRING, null);\r
-               } else {\r
-                   editor.edit(null, SpreadsheetUtils.cellName(currentRow, currentColumn), Variant.ofInstance(current), null);\r
-               }\r
-               undoPoint = current;\r
-               \r
-       }\r
-       \r
-       void cancel() {\r
-               if(undoPoint != null)\r
-                       text.setText(undoPoint);\r
-       }\r
-       \r
-       @Override\r
-       public void keyTyped(KeyEvent e) {\r
-       }\r
-       \r
-       @Override\r
-       public void keyReleased(KeyEvent e) {\r
-               if(e.getKeyCode() == KeyEvent.VK_ENTER) {\r
-                       apply();\r
-               }\r
-               if(e.getKeyCode() == KeyEvent.VK_ESCAPE) {\r
-                       cancel();\r
-               }\r
-       }\r
-       \r
-       @Override\r
-       public void keyPressed(KeyEvent e) {\r
-       }\r
-       \r
-       @Override\r
-       public void focusGained(FocusEvent e) {\r
-       }\r
-\r
-       @Override\r
-       public void focusLost(FocusEvent e) {\r
-               apply();\r
-       }\r
-       \r
-}\r
+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();
+       }
+       
+}