From ec402ca145697292d2eb05e7d34e354028bca2fb Mon Sep 17 00:00:00 2001 From: "Irina Lee [m1]" <irina.lee@etu.upmc.fr> Date: Mon, 18 Jun 2018 18:04:17 +0200 Subject: [PATCH] add cluster in avatardd and test rotation in syscams component --- src/main/java/ui/avatardd/ADDClusterNode.java | 63 +++++++++++++++++-- .../ui/eln/sca_eln/ELNComponentResistor.java | 29 ++++++++- 2 files changed, 85 insertions(+), 7 deletions(-) diff --git a/src/main/java/ui/avatardd/ADDClusterNode.java b/src/main/java/ui/avatardd/ADDClusterNode.java index f700db8170..633adb38c6 100644 --- a/src/main/java/ui/avatardd/ADDClusterNode.java +++ b/src/main/java/ui/avatardd/ADDClusterNode.java @@ -42,10 +42,13 @@ import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; import ui.*; +import ui.syscams.SysCAMSComponentTaskDiagramPanel; import ui.util.IconManager; import javax.swing.*; + import java.awt.*; +import java.util.Vector; /** * Class ADDClusterNode @@ -61,6 +64,9 @@ public class ADDClusterNode extends ADDNode implements WithAttributes { private int derivationx = 2; private int derivationy = 3; private String stereotype = "Cluster"; + private int currentFontSize = -1; + private int textX = 15; // border for ports + public String oldValue; private int index = 0; @@ -98,14 +104,13 @@ public class ADDClusterNode extends ADDNode implements WithAttributes { nbInternalTGComponent = 0; moveable = true; + multieditable = true; editable = true; removable = true; userResizable = true; name = tdp.findNodeName("Cluster"); value = "name"; - -// myImageIcon = IconManager.imgic8006; } public void internalDrawing(Graphics g) { @@ -167,7 +172,57 @@ public class ADDClusterNode extends ADDNode implements WithAttributes { return index; } - public boolean editOndoubleClick(JFrame frame) { + public boolean editOndoubleClick(JFrame frame, int _x, int _y) { + int i; + MainGUI mgui = getTDiagramPanel().getMainGUI(); + Vector<TURTLEPanel> listPanel = mgui.getTabs(); + + // On the name ? + if (_y <= (y + currentFontSize + textX)) { + //TraceManager.addDev("Edit on double click x=" + _x + " y=" + _y); + oldValue = value; + String s = (String)JOptionPane.showInputDialog(frame, "Name:", "Setting component name", + JOptionPane.PLAIN_MESSAGE, IconManager.imgic100, + null, + getValue()); + if ((s != null) && (s.length() > 0)) { + // Check whether this name is already in use, or not + + if (!TAttribute.isAValidId(s, false, false)) { + JOptionPane.showMessageDialog(frame, + "Could not change the name of the component: the new name is not a valid name", + "Error", + JOptionPane.INFORMATION_MESSAGE); + return false; + } +// if (oldValue.compareTo(s) != 0) { +// if (((SysCAMSComponentTaskDiagramPanel)(tdp)).nameBlockTDFComponentInUse(oldValue, s)) { +// JOptionPane.showMessageDialog(frame, +// "Error: the name is already in use", +// "Name modification", +// JOptionPane.ERROR_MESSAGE); +// return false; +// } +// } + + + //TraceManager.addDev("Set value with change"); + setComponentName(s); + setValueWithChange(s); +// isAttacker = s.contains("Attacker"); +// rescaled = true; + //TraceManager.addDev("return true"); + return true; + + } + return false; + } + + for (i = 0; i < listPanel.size(); i++) { + if (mgui.getTitleAt(listPanel.get(i)).equals("SystemC_AMS")) { + mgui.selectMainTab("SystemC_AMS"); + } + } return true; } @@ -233,4 +288,4 @@ public class ADDClusterNode extends ADDNode implements WithAttributes { attr += "index = " + index + "\n"; return attr; } -} +} \ No newline at end of file diff --git a/src/main/java/ui/eln/sca_eln/ELNComponentResistor.java b/src/main/java/ui/eln/sca_eln/ELNComponentResistor.java index 85b415bc9b..66d9888b84 100644 --- a/src/main/java/ui/eln/sca_eln/ELNComponentResistor.java +++ b/src/main/java/ui/eln/sca_eln/ELNComponentResistor.java @@ -50,6 +50,7 @@ import ui.window.JDialogELNComponentResistor; import javax.swing.*; import java.awt.*; +import java.awt.geom.AffineTransform; /** * Class ELNComponentResistor @@ -118,7 +119,8 @@ public class ELNComponentResistor extends TGCScalableWithInternalComponent { return myColor; } - public void internalDrawing(Graphics g) { + public void internalDrawing(Graphics gr) { + Graphics2D g = (Graphics2D) gr; Font f = g.getFont(); Font fold = f; @@ -156,11 +158,32 @@ public class ELNComponentResistor extends TGCScalableWithInternalComponent { f = f.deriveFont(this.currentFontSize); } - // Zoom is assumed to be computed + // Zoom is assumed to be computed Color c = g.getColor(); int [] ptx = {x, x+width/4, x+width/4, x+3*width/4, x+3*width/4, x+width, x+3*width/4, x+3*width/4, x+width/4, x+width/4}; int [] pty = {y+height/2, y+height/2, y, y, y+height/2, y+height/2, y+height/2, y+height, y+height, y+height/2}; - g.drawPolygon(ptx, pty, 10); + Polygon p = new Polygon(ptx, pty, 10); + g.drawPolygon(p); + + //------------------ + // Save the current transform of the graphics contexts. + AffineTransform saveTransform = g.getTransform(); + // Create a identity affine transform, and apply to the Graphics2D context + AffineTransform identity = new AffineTransform(); + g.setTransform(identity); + + // Paint Shape (with identity transform), centered at (0, 0) as defined. + g.rotate(Math.toRadians(90)); + g.setTransform(identity); + g.drawPolygon(p); + g.fill(p); + + // Restore original transform before returning + g.setTransform(saveTransform); + //------------------ + + //------------------ + g.setColor(c); // Set font size -- GitLab