[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[CASHeW-s-editor-patches] Unique name for nodes!
From: |
X F Liu |
Subject: |
[CASHeW-s-editor-patches] Unique name for nodes! |
Date: |
Mon, 14 Mar 2005 12:39:14 +0000 |
User-agent: |
Internet Messaging Program (IMP) 3.2.2 |
Index: src/nongnu/cashews/eclipse/composer/model/EllipseNode.java
===================================================================
RCS file:
/share/darwin/darwin4/cvs/java/src/nongnu/cashews/eclipse/composer/model/EllipseNode.java,v
retrieving revision 1.4
diff -u -r1.4 EllipseNode.java
--- src/nongnu/cashews/eclipse/composer/model/EllipseNode.java 2005/03/03
16:19:58 1.4
+++ src/nongnu/cashews/eclipse/composer/model/EllipseNode.java 2005/03/14
12:36:42
@@ -24,8 +24,11 @@
// actual fields
+public EllipseNode(String name)
+{
+ setName(name);
+}
-
public void setLocation(Point p) {
if (location.equals(p)) {
return;
@@ -36,14 +39,6 @@
public Point getLocation() {
return location;
- }
-
- public void setName(String name) {
- if (name.equals(name)) {
- return;
- }
- name = name;
- firePropertyChange(NAME, null, name);
}
public String getName() {
Index: src/nongnu/cashews/eclipse/composer/model/EllipseNodeFactory.java
===================================================================
RCS file:
/share/darwin/darwin4/cvs/java/src/nongnu/cashews/eclipse/composer/model/EllipseNodeFactory.java,v
retrieving revision 1.1
diff -u -r1.1 EllipseNodeFactory.java
--- src/nongnu/cashews/eclipse/composer/model/EllipseNodeFactory.java
2005/03/13
23:16:57 1.1
+++ src/nongnu/cashews/eclipse/composer/model/EllipseNodeFactory.java
2005/03/14
12:36:42
@@ -0,0 +1,16 @@
+package nongnu.cashews.eclipse.composer.model;
+
+public class EllipseNodeFactory extends NodeFactory
+{
+
+ public EllipseNodeFactory(Class aClass)
+ {
+ super(aClass);
+ }
+
+ public Node createNode(String name)
+ {
+ return new EllipseNode(name);
+ }
+
+}
\ No newline at end of file
Index: src/nongnu/cashews/eclipse/composer/model/Node.java
===================================================================
RCS file:
/share/darwin/darwin4/cvs/java/src/nongnu/cashews/eclipse/composer/model/Node.java,v
retrieving revision 1.5
diff -u -r1.5 Node.java
--- src/nongnu/cashews/eclipse/composer/model/Node.java 2005/03/03 16:19:58
1.5
+++ src/nongnu/cashews/eclipse/composer/model/Node.java 2005/03/14 12:36:42
@@ -119,4 +119,17 @@
setName((String)value);
}
}
+
+ public boolean equals(Object obj)
+ {
+ if (obj == this)
+ return true;
+ if (obj instanceof Node)
+ {
+ Node cmpNode = (Node) obj;
+ return getName().equals(cmpNode.getName());
+ }
+ else
+ return false;
+ }
}
Index: src/nongnu/cashews/eclipse/composer/model/RectangleNode.java
===================================================================
RCS file:
/share/darwin/darwin4/cvs/java/src/nongnu/cashews/eclipse/composer/model/RectangleNode.java,v
retrieving revision 1.2
diff -u -r1.2 RectangleNode.java
--- src/nongnu/cashews/eclipse/composer/model/RectangleNode.java
2005/03/03
16:19:58 1.2
+++ src/nongnu/cashews/eclipse/composer/model/RectangleNode.java
2005/03/14
12:36:42
@@ -24,6 +24,10 @@
// actual fields
+ public RectangleNode(String name)
+ {
+ setName(name);
+ }
public void setLocation(Point p) {
@@ -36,16 +40,8 @@
public Point getLocation() {
return location;
- }
-
- public void setName(String name) {
- if (name.equals(name)) {
- return;
- }
- super.name = name;
- firePropertyChange(NAME, null, name);
}
-
+
public String getName() {
return name;
}
Index: src/nongnu/cashews/eclipse/composer/model/RectangleNodeFactory.java
===================================================================
RCS file:
/share/darwin/darwin4/cvs/java/src/nongnu/cashews/eclipse/composer/model/RectangleNodeFactory.java,v
retrieving revision 1.1
diff -u -r1.1 RectangleNodeFactory.java
---
src/nongnu/cashews/eclipse/composer/model/RectangleNodeFactory.java
2005/03/13
23:16:57 1.1
+++
src/nongnu/cashews/eclipse/composer/model/RectangleNodeFactory.java
2005/03/14
12:36:42
@@ -2,43 +2,17 @@
package nongnu.cashews.eclipse.composer.model;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-import org.eclipse.gef.requests.SimpleFactory;
-
-public class RectangleNodeFactory extends SimpleFactory
+public class RectangleNodeFactory extends NodeFactory
{
-
- static int autoId;
-
- /**
- * @param aClass
- */
+
public RectangleNodeFactory(Class aClass)
{
super(aClass);
- // TODO Auto-generated constructor stub
- }
- public RectangleNode getNewObject()
- {
- RectangleNode rectangle = new RectangleNode();
- rectangle.setName("Untitled" + autoId);
- ++autoId;
- return rectangle;
}
- public RectangleNode getNewObject(String name)
+
+ public Node createNode(String name)
{
- Pattern untitled = Pattern.compile("Untitled([0-9]*)");
- Matcher matcher = untitled.matcher(name);
- if (matcher.matches())
- {
- int serializedId = Integer.parseInt(matcher.group());
- autoId = serializedId + 1;
- }
- RectangleNode node = new RectangleNode();
- node.setName(name);
- return node;
+ return new RectangleNode(name);
}
}
Index: src/nongnu/cashews/eclipse/composer/ui/PaletteFactory.java
===================================================================
RCS file:
/share/darwin/darwin4/cvs/java/src/nongnu/cashews/eclipse/composer/ui/PaletteFactory.java,v
retrieving revision 1.5
diff -u -r1.5 PaletteFactory.java
--- src/nongnu/cashews/eclipse/composer/ui/PaletteFactory.java 2005/03/13
23:16:57 1.5
+++ src/nongnu/cashews/eclipse/composer/ui/PaletteFactory.java 2005/03/14
12:36:43
@@ -4,6 +4,7 @@
import java.util.List;
import nongnu.cashews.eclipse.composer.model.EllipseNode;
+import nongnu.cashews.eclipse.composer.model.EllipseNodeFactory;
import nongnu.cashews.eclipse.composer.model.RectangleNode;
import nongnu.cashews.eclipse.composer.model.RectangleNodeFactory;
@@ -48,7 +49,7 @@
List entries = new ArrayList();
ToolEntry tool = new CombinedTemplateCreationEntry(
- "Node",
+ "Rectangle",
"Create a new RectangleNode",
RectangleNode.class,
new RectangleNodeFactory(RectangleNode.class),
@@ -59,7 +60,7 @@
"EllipseNode",
"Create a new Node",
EllipseNode.class,
- new SimpleFactory(EllipseNode.class),
+ new EllipseNodeFactory(EllipseNode.class),
null, /* small icon */
null /* large icon */
);
Index: src/nongnu/cashews/eclipse/composer/model/NodeFactory.java
===================================================================
RCS file: src/nongnu/cashews/eclipse/composer/model/NodeFactory.java
diff -N src/nongnu/cashews/eclipse/composer/model/NodeFactory.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ src/nongnu/cashews/eclipse/composer/model/NodeFactory.java 1 Jan 1970
00:00:00 -0000
@@ -0,0 +1,55 @@
+
+
+package nongnu.cashews.eclipse.composer.model;
+
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.eclipse.gef.requests.SimpleFactory;
+
+public abstract class NodeFactory extends SimpleFactory
+{
+
+ static int autoId;
+ private Node node;
+
+ /**
+ * @param aClass
+ */
+ public NodeFactory(Class aClass)
+ {
+ super(aClass);
+ // TODO Auto-generated constructor stub
+ }
+ public Node getNewObject()
+ {
+ do
+ {
+ node = createNode("Untitled" + autoId);
+ ++autoId;
+ } while (!NodeRegistrar.registerNewNode(node));
+ return node;
+ }
+
+ public Node getNewObject(String name)
+ {
+ Pattern untitled = Pattern.compile("Untitled([0-9]*)");
+ Matcher matcher = untitled.matcher(name);
+ if (matcher.matches())
+ {
+ int serializedId = Integer.parseInt(matcher.group());
+ autoId = serializedId + 1;
+ }
+ node = createNode(name);
+ if (!NodeRegistrar.registerNewNode(node))
+ {
+ throw new IllegalStateException("A node with one of the " +
+ "deserialized names already " +
+ "exists.");
+ }
+ return node;
+ }
+
+ public abstract Node createNode(String name);
+
+}
Index: src/nongnu/cashews/eclipse/composer/model/NodeRegistrar.java
===================================================================
RCS file: src/nongnu/cashews/eclipse/composer/model/NodeRegistrar.java
diff -N src/nongnu/cashews/eclipse/composer/model/NodeRegistrar.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ src/nongnu/cashews/eclipse/composer/model/NodeRegistrar.java 1 Jan
1970
00:00:00 -0000
@@ -0,0 +1,37 @@
+/*
+ * Created on 2005-3-14
+ *
+ * TODO To change the template for this generated file go to
+ * Window - Preferences - Java - Code Style - Code Templates
+ */
+package nongnu.cashews.eclipse.composer.model;
+
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @author Roger Liu
+ *
+ * TODO To change the template for this generated type comment go to
+ * Window - Preferences - Java - Code Style - Code Templates
+ */
+public class NodeRegistrar
+{
+
+ private static List<Node> nodes;
+
+ static
+ {
+ nodes = new ArrayList<Node>();
+ }
+
+ public static boolean registerNewNode(Node node)
+ {
+ if (nodes.contains(node))
+ return false;
+ nodes.add(node);
+ return true;
+ }
+
+}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [CASHeW-s-editor-patches] Unique name for nodes!,
X F Liu <=