From 51bd275a962b4ded12c33b87bd2c2be463a5f23a Mon Sep 17 00:00:00 2001 From: lempinen Date: Wed, 24 Feb 2010 17:32:31 +0000 Subject: [PATCH] No spaces allowed when renaming variables in equation view or diagram. (both copy&paste and typing) git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@14388 ac1ea38d-2e2b-0410-8846-a27921b304fc --- .../src/org/simantics/h2d/node/TextNode.java | 360 +++++++++--------- .../org/simantics/objmap/impl/Mapping.java | 7 +- org.simantics.sysdyn.ui/META-INF/MANIFEST.MF | 4 +- org.simantics.sysdyn.ui/plugin.xml | 49 ++- .../sysdyn/ui/equation/NameComposite.java | 26 ++ 5 files changed, 245 insertions(+), 201 deletions(-) diff --git a/org.simantics.h2d/src/org/simantics/h2d/node/TextNode.java b/org.simantics.h2d/src/org/simantics/h2d/node/TextNode.java index 6c359cf9..997a563a 100644 --- a/org.simantics.h2d/src/org/simantics/h2d/node/TextNode.java +++ b/org.simantics.h2d/src/org/simantics/h2d/node/TextNode.java @@ -18,11 +18,11 @@ import java.awt.geom.Rectangle2D; import org.simantics.scenegraph.g2d.G2DNode; public class TextNode extends G2DNode { - - //static final FontRenderContext FRC = new FontRenderContext( - // new AffineTransform(1.0,0.0,0.0,1.0,0.0,0.0), true, true); - - private static final long serialVersionUID = 654692698101485672L; + + //static final FontRenderContext FRC = new FontRenderContext( + // new AffineTransform(1.0,0.0,0.0,1.0,0.0,0.0), true, true); + + private static final long serialVersionUID = 654692698101485672L; protected String text = null; protected Font font = null; @@ -30,13 +30,13 @@ public class TextNode extends G2DNode { protected double x; protected double y; protected double scale; - + boolean editAllowed; int caret = 0; int selectionTail = 0; - + ITextListener textListener; - + /** * Enables or disables edit mode. It also sets * the caret at the end of text all selects the @@ -44,11 +44,11 @@ public class TextNode extends G2DNode { * beginning to edit one line texts). * @param editAllowed */ - public void setEditMode(boolean editAllowed) { - this.editAllowed = editAllowed; - caret = text.length(); - selectionTail = 0; - } + public void setEditMode(boolean editAllowed) { + this.editAllowed = editAllowed; + caret = text.length(); + selectionTail = 0; + } @SyncField({"text", "font", "color", "x", "y", "scale"}) public void init(String text, Font font, Color color, double x, double y, double scale) { @@ -59,59 +59,59 @@ public class TextNode extends G2DNode { this.y = y; this.scale = scale; } - + @SyncField({"color"}) public void setColor(Color color) { this.color = color; } - + public String getText() { - return text; + return text; } - + private double getLength(FontRenderContext frc, String str) { - Rectangle2D bounds = font.getStringBounds(str, frc); - return bounds.getWidth(); + Rectangle2D bounds = font.getStringBounds(str, frc); + return bounds.getWidth(); } @Override public void render(Graphics2D g) { - if(text == null || font == null || color == null) return; - g.setFont(font); - g.translate(x, y); + if(text == null || font == null || color == null) return; + g.setFont(font); + g.translate(x, y); g.scale(scale, scale); - - if(editAllowed) { - FontRenderContext frc = g.getFontRenderContext(); - - int selectionMin = Math.min(caret, selectionTail); - int selectionMax = Math.max(caret, selectionTail); - double selectionMinPos = getLength(frc, text.substring(0, selectionMin)); - double selectionMaxPos = getLength(frc, text.substring(0, selectionMax)); - - // Selection background - g.setColor(new Color(0x316ac5)); - g.fill(new Rectangle2D.Double(selectionMinPos, -12.0, - selectionMaxPos-selectionMinPos, 12.0)); - - // Text - g.setColor(color); - g.drawString(text.substring(0, selectionMin), 0f, 0f); - g.drawString(text.substring(selectionMax), (float)selectionMaxPos, 0f); - - g.setColor(Color.WHITE); - g.drawString(text.substring(selectionMin, selectionMax), (float)selectionMinPos, 0f); - - // Caret - double caretPos = getLength(frc, text.substring(0, caret)); - //g.setXORMode(Color.BLACK); - g.setColor(Color.BLACK); - g.draw(new Line2D.Double(caretPos, 0, caretPos, -12.0)); - } - else { - g.setColor(color); - g.drawString(text, 0f, 0f); - } + + if(editAllowed) { + FontRenderContext frc = g.getFontRenderContext(); + + int selectionMin = Math.min(caret, selectionTail); + int selectionMax = Math.max(caret, selectionTail); + double selectionMinPos = getLength(frc, text.substring(0, selectionMin)); + double selectionMaxPos = getLength(frc, text.substring(0, selectionMax)); + + // Selection background + g.setColor(new Color(0x316ac5)); + g.fill(new Rectangle2D.Double(selectionMinPos, -12.0, + selectionMaxPos-selectionMinPos, 12.0)); + + // Text + g.setColor(color); + g.drawString(text.substring(0, selectionMin), 0f, 0f); + g.drawString(text.substring(selectionMax), (float)selectionMaxPos, 0f); + + g.setColor(Color.WHITE); + g.drawString(text.substring(selectionMin, selectionMax), (float)selectionMinPos, 0f); + + // Caret + double caretPos = getLength(frc, text.substring(0, caret)); + //g.setXORMode(Color.BLACK); + g.setColor(Color.BLACK); + g.draw(new Line2D.Double(caretPos, 0, caretPos, -12.0)); + } + else { + g.setColor(color); + g.drawString(text, 0f, 0f); + } } /** @@ -123,141 +123,143 @@ public class TextNode extends G2DNode { */ @SyncField("text") protected void insert(String content) { - int selectionMin = Math.min(caret, selectionTail); - int selectionMax = Math.max(caret, selectionTail); - - String begin = text.substring(0, selectionMin); - String end = text.substring(selectionMax); - text = begin + content + end; - caret = selectionMin + content.length(); - selectionTail = caret; + if(!content.contains(" ")) { + int selectionMin = Math.min(caret, selectionTail); + int selectionMax = Math.max(caret, selectionTail); + + String begin = text.substring(0, selectionMin); + String end = text.substring(selectionMax); + text = begin + content + end; + caret = selectionMin + content.length(); + selectionTail = caret; + } } - - + + @ServerSide protected void fireTextChanged() { - if(textListener != null) - textListener.textChanged(); + if(textListener != null) + textListener.textChanged(); } - + public void setTextListener(ITextListener listener) { - this.textListener = listener; + this.textListener = listener; } - + private void handleKeyPressed(KeyEvent event) { - char c = event.getKeyChar(); - //System.out.println("Key pressed " + c + " " + event.getKeyCode()); - if(event.isControlDown()) - switch(event.getKeyCode()) { - case KeyEvent.VK_C: - if(caret != selectionTail) { - int selectionMin = Math.min(caret, selectionTail); - int selectionMax = Math.max(caret, selectionTail); - setCliboardContent(text.substring(selectionMin, selectionMax)); - } - break; - - case KeyEvent.VK_V: - { - String content = getCliboardContent(); - if(content != null) - insert(content); - } - break; - default: - return; - } - else if(event.isAltDown()) - return; - else - switch(event.getKeyCode()) { - case KeyEvent.VK_LEFT: - if(caret > 0) { - --caret; - if(!event.isShiftDown()) - selectionTail = caret; - } - break; - case KeyEvent.VK_RIGHT: - if(caret < text.length()) { - ++caret; - if(!event.isShiftDown()) - selectionTail = caret; - } - break; - case KeyEvent.VK_HOME: - caret = 0; - if(!event.isShiftDown()) - selectionTail = caret; - break; - case KeyEvent.VK_END: - caret = text.length(); - if(!event.isShiftDown()) - selectionTail = caret; - break; - - case KeyEvent.VK_BACK_SPACE: - if(caret == selectionTail && caret > 0) - --caret; - insert(""); - break; - - case KeyEvent.VK_DELETE: - if(caret == selectionTail && caret < text.length()) - ++caret; - insert(""); - break; - - default: - if(c == 65535 || Character.getType(c) == Character.CONTROL) - return; - //System.out.println("Char " + (int)c + " " + Character.getType(c)); - insert(new String(new char[] {c})); - } - // FIXME This is called even if just caret was moved. - // This is currently necessary for repaints. - fireTextChanged(); - event.consume(); + char c = event.getKeyChar(); + //System.out.println("Key pressed " + c + " " + event.getKeyCode()); + if(event.isControlDown()) + switch(event.getKeyCode()) { + case KeyEvent.VK_C: + if(caret != selectionTail) { + int selectionMin = Math.min(caret, selectionTail); + int selectionMax = Math.max(caret, selectionTail); + setCliboardContent(text.substring(selectionMin, selectionMax)); + } + break; + + case KeyEvent.VK_V: + { + String content = getCliboardContent(); + if(content != null) + insert(content); + } + break; + default: + return; + } + else if(event.isAltDown()) + return; + else + switch(event.getKeyCode()) { + case KeyEvent.VK_LEFT: + if(caret > 0) { + --caret; + if(!event.isShiftDown()) + selectionTail = caret; + } + break; + case KeyEvent.VK_RIGHT: + if(caret < text.length()) { + ++caret; + if(!event.isShiftDown()) + selectionTail = caret; + } + break; + case KeyEvent.VK_HOME: + caret = 0; + if(!event.isShiftDown()) + selectionTail = caret; + break; + case KeyEvent.VK_END: + caret = text.length(); + if(!event.isShiftDown()) + selectionTail = caret; + break; + + case KeyEvent.VK_BACK_SPACE: + if(caret == selectionTail && caret > 0) + --caret; + insert(""); + break; + + case KeyEvent.VK_DELETE: + if(caret == selectionTail && caret < text.length()) + ++caret; + insert(""); + break; + + default: + if(c == 65535 || Character.getType(c) == Character.CONTROL) + return; + //System.out.println("Char " + (int)c + " " + Character.getType(c)); + insert(new String(new char[] {c})); + } + // FIXME This is called even if just caret was moved. + // This is currently necessary for repaints. + fireTextChanged(); + event.consume(); + } + + private void handleMousePressed(MouseEvent event) { + // TODO } - - private void handleMousePressed(MouseEvent event) { - // TODO - } - + @Override public void handleEvent(AWTEvent event) { - if(editAllowed) { - if(caret > text.length()) - caret = text.length(); - switch(event.getID()) { - case KeyEvent.KEY_PRESSED: - handleKeyPressed((KeyEvent)event); - break; - case MouseEvent.MOUSE_PRESSED: - handleMousePressed((MouseEvent)event); - break; - } - } + if(editAllowed) { + if(caret > text.length()) + caret = text.length(); + switch(event.getID()) { + case KeyEvent.KEY_PRESSED: + handleKeyPressed((KeyEvent)event); + break; + case MouseEvent.MOUSE_PRESSED: + handleMousePressed((MouseEvent)event); + break; + } + } + } + + @Override + public Rectangle2D getBoundsInLocal() { + return null; + } + + public String getCliboardContent() { + Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); + Transferable clipData = clipboard.getContents(this); + try { + return (String) (clipData.getTransferData(DataFlavor.stringFlavor)); + } catch (Exception ee) { + return null; + } } - @Override - public Rectangle2D getBoundsInLocal() { - return null; - } - - public String getCliboardContent() { - Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); - Transferable clipData = clipboard.getContents(this); - try { - return (String) (clipData.getTransferData(DataFlavor.stringFlavor)); - } catch (Exception ee) { - return null; - } - } - - public void setCliboardContent(String content) { - Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); - StringSelection data = new StringSelection(content); - clipboard.setContents(data, data); - } + public void setCliboardContent(String content) { + Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); + StringSelection data = new StringSelection(content); + clipboard.setContents(data, data); + } } diff --git a/org.simantics.objmap/src/org/simantics/objmap/impl/Mapping.java b/org.simantics.objmap/src/org/simantics/objmap/impl/Mapping.java index ef630547..ae3b0170 100644 --- a/org.simantics.objmap/src/org/simantics/objmap/impl/Mapping.java +++ b/org.simantics.objmap/src/org/simantics/objmap/impl/Mapping.java @@ -13,6 +13,7 @@ import org.apache.log4j.Logger; import org.simantics.db.ReadGraph; import org.simantics.db.Resource; import org.simantics.db.WriteGraph; +import org.simantics.db.exception.DatabaseException; import org.simantics.objmap.IFunction; import org.simantics.objmap.ILinkType; import org.simantics.objmap.IMapping; @@ -262,7 +263,11 @@ public class Mapping implements IMapping { if(listensDomain) { RangeUpdateRequest request = new RangeUpdateRequest(link, map, this); - g.syncRequest(request, request); + try { + g.syncRequest(request, request); + } catch (DatabaseException e) { + throw new MappingException(e); + } // TODO check if really modified updated.add(link.rangeElement); } diff --git a/org.simantics.sysdyn.ui/META-INF/MANIFEST.MF b/org.simantics.sysdyn.ui/META-INF/MANIFEST.MF index cb322707..e234fc6a 100644 --- a/org.simantics.sysdyn.ui/META-INF/MANIFEST.MF +++ b/org.simantics.sysdyn.ui/META-INF/MANIFEST.MF @@ -24,6 +24,8 @@ Require-Bundle: org.simantics.h2d;bundle-version="1.0.0", org.simantics.browsing.ui;bundle-version="0.9.0", org.simantics.browsing.ui.common;bundle-version="0.9.0", org.apache.log4j;bundle-version="1.2.15", - org.eclipse.ui.console;bundle-version="3.4.0" + org.eclipse.ui.console;bundle-version="3.4.0", + org.simantics.browsing.ui.graph;bundle-version="0.9.0", + org.simantics.modeling.ui;bundle-version="1.0.0" Bundle-Activator: org.simantics.sysdyn.ui.Activator Bundle-ActivationPolicy: lazy diff --git a/org.simantics.sysdyn.ui/plugin.xml b/org.simantics.sysdyn.ui/plugin.xml index e6a66754..257af079 100644 --- a/org.simantics.sysdyn.ui/plugin.xml +++ b/org.simantics.sysdyn.ui/plugin.xml @@ -78,6 +78,28 @@ tooltip="Pins the trend so that it does not react to selection changes"> + + + + + + + + + + + + - - - - - - - - - - + locationURI="popup:#SysdynModelBrowserPopup?after=wbStart"> + +