From 4397b908a771610387e430c6f4fe610aaa305e56 Mon Sep 17 00:00:00 2001 From: "Irina Lee [m1]" <irina.lee@etu.upmc.fr> Date: Sat, 7 Jul 2018 13:05:31 +0200 Subject: [PATCH] updated (eln) --- src/main/java/ui/TGComponentManager.java | 36 +-- src/main/java/ui/eln/ELNPortTerminal.java | 232 ++++++++++++++++++ .../ui/eln/sca_eln/ELNComponentResistor.java | 184 ++++++++------ .../java/ui/window/JDialogELNTerminal.java | 151 ++++++++++++ 4 files changed, 518 insertions(+), 85 deletions(-) create mode 100644 src/main/java/ui/eln/ELNPortTerminal.java create mode 100644 src/main/java/ui/window/JDialogELNTerminal.java diff --git a/src/main/java/ui/TGComponentManager.java b/src/main/java/ui/TGComponentManager.java index 47d4eb598a..e64212db6a 100644 --- a/src/main/java/ui/TGComponentManager.java +++ b/src/main/java/ui/TGComponentManager.java @@ -347,18 +347,19 @@ public class TGComponentManager { // ELN public static final int ELN_CONNECTOR = 1610; - public static final int ELN_RESISTOR = 1611; - public static final int ELN_CAPACITOR = 1612; - public static final int ELN_INDUCTOR = 1613; - public static final int ELN_VOLTAGE_CONTROLLED_VOLTAGE_SOURCE = 1614; - public static final int ELN_VOLTAGE_CONTROLLED_CURRENT_SOURCE = 1615; - public static final int ELN_IDEAL_TRANSFORMER = 1616; - public static final int ELN_TRANSMISSION_LINE = 1617; - public static final int ELN_INDEPENDENT_VOLTAGE_SOURCE = 1618; - public static final int ELN_INDEPENDENT_CURRENT_SOURCE = 1619; - public static final int ELN_NODE_REF = 1620; - public static final int ELN_TDF_VOLTAGE_SINK = 1621; - public static final int ELN_TDF_CURRENT_SINK = 1622; + public static final int ELN_PORT_TERMINAL = 1611; + public static final int ELN_RESISTOR = 1612; + public static final int ELN_CAPACITOR = 1613; + public static final int ELN_INDUCTOR = 1614; + public static final int ELN_VOLTAGE_CONTROLLED_VOLTAGE_SOURCE = 1615; + public static final int ELN_VOLTAGE_CONTROLLED_CURRENT_SOURCE = 1616; + public static final int ELN_IDEAL_TRANSFORMER = 1617; + public static final int ELN_TRANSMISSION_LINE = 1618; + public static final int ELN_INDEPENDENT_VOLTAGE_SOURCE = 1619; + public static final int ELN_INDEPENDENT_CURRENT_SOURCE = 1620; + public static final int ELN_NODE_REF = 1621; + public static final int ELN_TDF_VOLTAGE_SINK = 1622; + public static final int ELN_TDF_CURRENT_SINK = 1623; // SMD diagram public static final int PROSMD_START_STATE = 2000; @@ -1278,6 +1279,9 @@ public class TGComponentManager { tgc = new SysCAMSCompositeComponent(x, y, tdp.getMinX(), tdp.getMaxX(), tdp.getMinY(), tdp.getMaxY(), false, null, tdp); break; // ELN + case ELN_PORT_TERMINAL: + tgc = new ELNPortTerminal(x, y, tdp.getMinX(), tdp.getMaxX(), tdp.getMinY(), tdp.getMaxY(), false, null, tdp); + break; case ELN_RESISTOR: tgc = new ELNComponentResistor(x, y, tdp.getMinX(), tdp.getMaxX(), tdp.getMinY(), tdp.getMaxY(), false, null, tdp); break; @@ -1714,6 +1718,8 @@ public class TGComponentManager { // ELN } else if (tgc instanceof ELNConnector) { return ELN_CONNECTOR; + } else if (tgc instanceof ELNPortTerminal) { + return ELN_PORT_TERMINAL; } else if (tgc instanceof ELNComponentResistor) { return ELN_RESISTOR; } else if (tgc instanceof ELNComponentCapacitor) { @@ -1732,11 +1738,11 @@ public class TGComponentManager { return ELN_INDEPENDENT_VOLTAGE_SOURCE; } else if (tgc instanceof ELNComponentIndependentCurrentSource) { return ELN_INDEPENDENT_CURRENT_SOURCE; - } else if (tgc instanceof ELNComponentNodeRef) { + } else if (tgc instanceof ELNComponentNodeRef) { return ELN_NODE_REF; - } else if (tgc instanceof ELNComponentVoltageSinkTDF) { + } else if (tgc instanceof ELNComponentVoltageSinkTDF) { return ELN_TDF_VOLTAGE_SINK; - } else if (tgc instanceof ELNComponentCurrentSinkTDF) { + } else if (tgc instanceof ELNComponentCurrentSinkTDF) { return ELN_TDF_CURRENT_SINK; // Others diff --git a/src/main/java/ui/eln/ELNPortTerminal.java b/src/main/java/ui/eln/ELNPortTerminal.java new file mode 100644 index 0000000000..94d385a842 --- /dev/null +++ b/src/main/java/ui/eln/ELNPortTerminal.java @@ -0,0 +1,232 @@ +/* Copyright or (C) or Copr. GET / ENST, Telecom-Paris, Ludovic Apvrille + * + * ludovic.apvrille AT enst.fr + * + * This software is a computer program whose purpose is to allow the + * edition of TURTLE analysis, design and deployment diagrams, to + * allow the generation of RT-LOTOS or Java code from this diagram, + * and at last to allow the analysis of formal validation traces + * obtained from external tools, e.g. RTL from LAAS-CNRS and CADP + * from INRIA Rhone-Alpes. + * + * This software is governed by the CeCILL license under French law and + * abiding by the rules of distribution of free software. You can use, + * modify and/ or redistribute the software under the terms of the CeCILL + * license as circulated by CEA, CNRS and INRIA at the following URL + * "http://www.cecill.info". + * + * As a counterpart to the access to the source code and rights to copy, + * modify and redistribute granted by the license, users are provided only + * with a limited warranty and the software's author, the holder of the + * economic rights, and the successive licensors have only limited + * liability. + * + * In this respect, the user's attention is drawn to the risks associated + * with loading, using, modifying and/or developing or reproducing the + * software by the user in light of its specific status of free software, + * that may mean that it is complicated to manipulate, and that also + * therefore means that it is reserved for developers and experienced + * professionals having in-depth computer knowledge. Users are therefore + * encouraged to load and test the software's suitability as regards their + * requirements in conditions enabling the security of their systems and/or + * data to be ensured and, more generally, to use and operate it in the + * same conditions as regards security. + * + * The fact that you are presently reading this means that you have had + * knowledge of the CeCILL license and that you accept its terms. + */ + +package ui.eln; + +import myutil.GraphicLib; + +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; +import ui.*; +import ui.eln.ELNConnectingPoint; +import ui.window.JDialogELNTerminal; + +import javax.swing.*; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +/** + * Class ELNPortTerminal + * Port terminal to be used in ELN diagrams + * Creation: 06/07/2018 + * @version 1.0 06/07/2018 + * @author Irina Kit Yan LEE + */ + +public class ELNPortTerminal extends TGCScalableWithInternalComponent implements ActionListener, SwallowedTGComponent { + protected Color myColor; + protected int orientation; + private int maxFontSize = 14; + private int minFontSize = 4; + private int currentFontSize = -1; + protected int oldx, oldy; + + private int textX = 15; + private double dtextX = 0.0; + protected int decPoint = 3; + + public ELNPortTerminal(int _x, int _y, int _minX, int _maxX, int _minY, int _maxY, boolean _pos, + TGComponent _father, TDiagramPanel _tdp) { + super(_x, _y, _minX, _maxX, _minY, _maxY, _pos, _father, _tdp); + + initScaling(10, 10); + + dtextX = textX * oldScaleFactor; + textX = (int) dtextX; + dtextX = dtextX - textX; + + minWidth = 1; + minHeight = 1; + + initConnectingPoint(1); + + addTGConnectingPointsComment(); + + moveable = false; + editable = true; + removable = true; + userResizable = false; + + setValue(""); + } + + public void initConnectingPoint(int nb) { + nbConnectingPoint = nb; + connectingPoint = new TGConnectingPoint[nb]; + connectingPoint[0] = new ELNConnectingPoint(this, 0, 0, true, true, 0.0, 0.5, ""); + } + + public Color getMyColor() { + return myColor; + } + + public void internalDrawing(Graphics g) { + Font f = g.getFont(); + Font fold = f; + + if (this.rescaled && !this.tdp.isScaled()) { + this.rescaled = false; + int maxCurrentFontSize = Math.max(0, Math.min(this.height, (int) (this.maxFontSize * this.tdp.getZoom()))); + f = f.deriveFont((float) maxCurrentFontSize); + + while (maxCurrentFontSize > (this.minFontSize * this.tdp.getZoom() - 1)) { + if (g.getFontMetrics().stringWidth(value) < (width - (2 * textX))) { + break; + } + maxCurrentFontSize--; + f = f.deriveFont((float) maxCurrentFontSize); + } + + if (this.currentFontSize < this.minFontSize * this.tdp.getZoom()) { + maxCurrentFontSize++; + f = f.deriveFont((float) maxCurrentFontSize); + } + g.setFont(f); + this.currentFontSize = maxCurrentFontSize; + } else { + f = f.deriveFont(this.currentFontSize); + } + + Color c = g.getColor(); + g.fillRect(x, y, width, height); + g.setColor(c); + g.setFont(fold); + } + + public TGComponent isOnOnlyMe(int _x, int _y) { + if (GraphicLib.isInRectangle(_x, _y, x, y, width, height)) { + return this; + } + return null; + } + + public int getType() { + return TGComponentManager.ELN_PORT_TERMINAL; + } + + public boolean editOndoubleClick(JFrame frame) { + JDialogELNTerminal jde = new JDialogELNTerminal(this); + jde.setVisible(true); + return true; + } + + protected String translateExtraParam() { + StringBuffer sb = new StringBuffer("<extraparam>\n"); + sb.append("<attributes name=\"" + getValue() + "\""); + sb.append("/>\n"); + sb.append("</extraparam>\n"); + return new String(sb); + } + + public void loadExtraParam(NodeList nl, int decX, int decY, int decId) throws MalformedModelingException { + try { + NodeList nli; + Node n1, n2; + Element elt; + + String name; + + for (int i = 0; i < nl.getLength(); i++) { + n1 = nl.item(i); + if (n1.getNodeType() == Node.ELEMENT_NODE) { + nli = n1.getChildNodes(); + for (int j = 0; j < nli.getLength(); j++) { + n2 = nli.item(j); + if (n2.getNodeType() == Node.ELEMENT_NODE) { + elt = (Element) n2; + if (elt.getTagName().equals("attributes")) { + name = elt.getAttribute("name"); + setValue(name); + } + } + } + } + } + } catch (Exception e) { + throw new MalformedModelingException(); + } + } + + public void actionPerformed(ActionEvent arg0) { + return; + } + + public int getDefaultConnector() { + return TGComponentManager.ELN_CONNECTOR; + } + + public void wasSwallowed() { + myColor = null; + } + + public void wasUnswallowed() { + myColor = null; + setFather(null); + TDiagramPanel tdp = getTDiagramPanel(); + setCdRectangle(tdp.getMinX(), tdp.getMaxX(), tdp.getMinY(), tdp.getMaxY()); + } + + public void resizeWithFather() { + if ((father != null) && (father instanceof SysCAMSBlockTDF)) { + // Too large to fit in the father? -> resize it! + setCdRectangle(0-getWidth()/2, father.getWidth() - (getWidth()/2), 0-getHeight()/2, father.getHeight() - (getHeight()/2)); + setMoveCd(x, y); + oldx = -1; + oldy = -1; + } + if ((father != null) && (father instanceof SysCAMSBlockDE)) { + // Too large to fit in the father? -> resize it! + setCdRectangle(0-getWidth()/2, father.getWidth() - (getWidth()/2), 0-getHeight()/2, father.getHeight() - (getHeight()/2)); + setMoveCd(x, y); + oldx = -1; + oldy = -1; + } + } +} \ 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 cdf00566d3..3abfe88704 100644 --- a/src/main/java/ui/eln/sca_eln/ELNComponentResistor.java +++ b/src/main/java/ui/eln/sca_eln/ELNComponentResistor.java @@ -45,12 +45,14 @@ import org.w3c.dom.Node; import org.w3c.dom.NodeList; import ui.*; import ui.eln.ELNConnectingPoint; +import ui.eln.ELNPortTerminal; import ui.window.JDialogELNComponentResistor; import javax.swing.*; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import java.awt.event.ComponentListener; /** * Class ELNComponentResistor @@ -60,7 +62,7 @@ import java.awt.event.ActionListener; * @author Irina Kit Yan LEE */ -public class ELNComponentResistor extends TGCScalableWithInternalComponent implements ActionListener { +public class ELNComponentResistor extends TGCScalableWithInternalComponent implements ActionListener, SwallowTGComponent { protected Color myColor; protected int orientation; private int maxFontSize = 14; @@ -77,7 +79,7 @@ public class ELNComponentResistor extends TGCScalableWithInternalComponent imple private int position = 0; private boolean fv = false, fh = false; private int old; - private boolean first; + private boolean first, f = true; public ELNComponentResistor(int _x, int _y, int _minX, int _maxX, int _minY, int _maxY, boolean _pos, TGComponent _father, TDiagramPanel _tdp) { @@ -92,8 +94,7 @@ public class ELNComponentResistor extends TGCScalableWithInternalComponent imple minWidth = 1; minHeight = 1; - initConnectingPoint(2); - +// initConnectingPoint(2); addTGConnectingPointsComment(); moveable = true; @@ -110,18 +111,26 @@ public class ELNComponentResistor extends TGCScalableWithInternalComponent imple height = old; } - public void initConnectingPoint(int nb) { - nbConnectingPoint = nb; - connectingPoint = new TGConnectingPoint[nb]; - connectingPoint[0] = new ELNConnectingPoint(this, 0, 0, true, true, 0.0, 0.5, "p"); - connectingPoint[1] = new ELNConnectingPoint(this, 0, 0, true, true, 1.0, 0.5, "n"); - } +// public void initConnectingPoint(int nb) { +// nbConnectingPoint = nb; +// connectingPoint = new TGConnectingPoint[nb]; +// connectingPoint[0] = new ELNConnectingPoint(this, 0, 0, true, true, 0.0, 0.5, "p"); +// connectingPoint[1] = new ELNConnectingPoint(this, 0, 0, true, true, 1.0, 0.5, "n"); +// } public Color getMyColor() { return myColor; } public void internalDrawing(Graphics g) { + if (f == true) { + ELNPortTerminal term0 = new ELNPortTerminal(x, y+width/2-width/4, this.minX, this.maxX, this.minY, this.maxY, false, this.father, this.tdp); + term0.setValue("p"); + getTDiagramPanel().getComponentList().add(term0); + term0.getTDiagramPanel().addComponent(term0, x, y+width/2-width/4, true, false); + f = false; + } + Font f = g.getFont(); Font fold = f; @@ -173,23 +182,23 @@ public class ELNComponentResistor extends TGCScalableWithInternalComponent imple g.setFont(f.deriveFont(Font.PLAIN)); if (fh == true) { - ((ELNConnectingPoint) connectingPoint[0]).setW(1.0); - ((ELNConnectingPoint) connectingPoint[0]).setH(0.5); - ((ELNConnectingPoint) connectingPoint[1]).setW(0.0); - ((ELNConnectingPoint) connectingPoint[1]).setH(0.5); - g.drawString(((ELNConnectingPoint) connectingPoint[1]).getName(), x - sw1, - y + height / 2 + height / 2 + sh1); - g.drawString(((ELNConnectingPoint) connectingPoint[0]).getName(), x + width, - y + height / 2 + height / 2 + sh0); +// ((ELNConnectingPoint) connectingPoint[0]).setW(1.0); +// ((ELNConnectingPoint) connectingPoint[0]).setH(0.5); +// ((ELNConnectingPoint) connectingPoint[1]).setW(0.0); +// ((ELNConnectingPoint) connectingPoint[1]).setH(0.5); +// g.drawString(((ELNConnectingPoint) connectingPoint[1]).getName(), x - sw1, +// y + height / 2 + height / 2 + sh1); +// g.drawString(((ELNConnectingPoint) connectingPoint[0]).getName(), x + width, +// y + height / 2 + height / 2 + sh0); } else { - ((ELNConnectingPoint) connectingPoint[0]).setW(0.0); - ((ELNConnectingPoint) connectingPoint[0]).setH(0.5); - ((ELNConnectingPoint) connectingPoint[1]).setW(1.0); - ((ELNConnectingPoint) connectingPoint[1]).setH(0.5); - g.drawString(((ELNConnectingPoint) connectingPoint[0]).getName(), x - sw0, - y + height / 2 + height / 2 + sh0); - g.drawString(((ELNConnectingPoint) connectingPoint[1]).getName(), x + width, - y + height / 2 + height / 2 + sh1); +// ((ELNConnectingPoint) connectingPoint[0]).setW(0.0); +// ((ELNConnectingPoint) connectingPoint[0]).setH(0.5); +// ((ELNConnectingPoint) connectingPoint[1]).setW(1.0); +// ((ELNConnectingPoint) connectingPoint[1]).setH(0.5); +// g.drawString(((ELNConnectingPoint) connectingPoint[0]).getName(), x - sw0, +// y + height / 2 + height / 2 + sh0); +// g.drawString(((ELNConnectingPoint) connectingPoint[1]).getName(), x + width, +// y + height / 2 + height / 2 + sh1); } } else if (position == 1) { if (first == false) { @@ -212,21 +221,21 @@ public class ELNComponentResistor extends TGCScalableWithInternalComponent imple g.setFont(f.deriveFont(Font.PLAIN)); if (fv == true) { - ((ELNConnectingPoint) connectingPoint[0]).setW(0.5); - ((ELNConnectingPoint) connectingPoint[0]).setH(1.0); - ((ELNConnectingPoint) connectingPoint[1]).setW(0.5); - ((ELNConnectingPoint) connectingPoint[1]).setH(0.0); - g.drawString(((ELNConnectingPoint) connectingPoint[1]).getName(), x + width / 2 + width / 2, y); - g.drawString(((ELNConnectingPoint) connectingPoint[0]).getName(), x + width / 2 + width / 2, - y + height + sh0); +// ((ELNConnectingPoint) connectingPoint[0]).setW(0.5); +// ((ELNConnectingPoint) connectingPoint[0]).setH(1.0); +// ((ELNConnectingPoint) connectingPoint[1]).setW(0.5); +// ((ELNConnectingPoint) connectingPoint[1]).setH(0.0); +// g.drawString(((ELNConnectingPoint) connectingPoint[1]).getName(), x + width / 2 + width / 2, y); +// g.drawString(((ELNConnectingPoint) connectingPoint[0]).getName(), x + width / 2 + width / 2, +// y + height + sh0); } else { - ((ELNConnectingPoint) connectingPoint[0]).setW(0.5); - ((ELNConnectingPoint) connectingPoint[0]).setH(0.0); - ((ELNConnectingPoint) connectingPoint[1]).setW(0.5); - ((ELNConnectingPoint) connectingPoint[1]).setH(1.0); - g.drawString(((ELNConnectingPoint) connectingPoint[0]).getName(), x + width / 2 + width / 2, y); - g.drawString(((ELNConnectingPoint) connectingPoint[1]).getName(), x + width / 2 + width / 2, - y + height + sh1); +// ((ELNConnectingPoint) connectingPoint[0]).setW(0.5); +// ((ELNConnectingPoint) connectingPoint[0]).setH(0.0); +// ((ELNConnectingPoint) connectingPoint[1]).setW(0.5); +// ((ELNConnectingPoint) connectingPoint[1]).setH(1.0); +// g.drawString(((ELNConnectingPoint) connectingPoint[0]).getName(), x + width / 2 + width / 2, y); +// g.drawString(((ELNConnectingPoint) connectingPoint[1]).getName(), x + width / 2 + width / 2, +// y + height + sh1); } } else if (position == 2) { if (first == false) { @@ -251,23 +260,23 @@ public class ELNComponentResistor extends TGCScalableWithInternalComponent imple g.setFont(f.deriveFont(Font.PLAIN)); if (fh == true) { - ((ELNConnectingPoint) connectingPoint[0]).setW(0.0); - ((ELNConnectingPoint) connectingPoint[0]).setH(0.5); - ((ELNConnectingPoint) connectingPoint[1]).setW(1.0); - ((ELNConnectingPoint) connectingPoint[1]).setH(0.5); - g.drawString(((ELNConnectingPoint) connectingPoint[0]).getName(), x - sw1, - y + height / 2 + height / 2 + sh1); - g.drawString(((ELNConnectingPoint) connectingPoint[1]).getName(), x + width, - y + height / 2 + height / 2 + sh0); +// ((ELNConnectingPoint) connectingPoint[0]).setW(0.0); +// ((ELNConnectingPoint) connectingPoint[0]).setH(0.5); +// ((ELNConnectingPoint) connectingPoint[1]).setW(1.0); +// ((ELNConnectingPoint) connectingPoint[1]).setH(0.5); +// g.drawString(((ELNConnectingPoint) connectingPoint[0]).getName(), x - sw1, +// y + height / 2 + height / 2 + sh1); +// g.drawString(((ELNConnectingPoint) connectingPoint[1]).getName(), x + width, +// y + height / 2 + height / 2 + sh0); } else { - ((ELNConnectingPoint) connectingPoint[0]).setW(1.0); - ((ELNConnectingPoint) connectingPoint[0]).setH(0.5); - ((ELNConnectingPoint) connectingPoint[1]).setW(0.0); - ((ELNConnectingPoint) connectingPoint[1]).setH(0.5); - g.drawString(((ELNConnectingPoint) connectingPoint[1]).getName(), x - sw0, - y + height / 2 + height / 2 + sh0); - g.drawString(((ELNConnectingPoint) connectingPoint[0]).getName(), x + width, - y + height / 2 + height / 2 + sh1); +// ((ELNConnectingPoint) connectingPoint[0]).setW(1.0); +// ((ELNConnectingPoint) connectingPoint[0]).setH(0.5); +// ((ELNConnectingPoint) connectingPoint[1]).setW(0.0); +// ((ELNConnectingPoint) connectingPoint[1]).setH(0.5); +// g.drawString(((ELNConnectingPoint) connectingPoint[1]).getName(), x - sw0, +// y + height / 2 + height / 2 + sh0); +// g.drawString(((ELNConnectingPoint) connectingPoint[0]).getName(), x + width, +// y + height / 2 + height / 2 + sh1); } } else if (position == 3) { if (first == false) { @@ -290,21 +299,21 @@ public class ELNComponentResistor extends TGCScalableWithInternalComponent imple g.setFont(f.deriveFont(Font.PLAIN)); if (fv == true) { - ((ELNConnectingPoint) connectingPoint[0]).setW(0.5); - ((ELNConnectingPoint) connectingPoint[0]).setH(0.0); - ((ELNConnectingPoint) connectingPoint[1]).setW(0.5); - ((ELNConnectingPoint) connectingPoint[1]).setH(1.0); - g.drawString(((ELNConnectingPoint) connectingPoint[0]).getName(), x + width / 2 + width / 2, y); - g.drawString(((ELNConnectingPoint) connectingPoint[1]).getName(), x + width / 2 + width / 2, - y + height + sh0); +// ((ELNConnectingPoint) connectingPoint[0]).setW(0.5); +// ((ELNConnectingPoint) connectingPoint[0]).setH(0.0); +// ((ELNConnectingPoint) connectingPoint[1]).setW(0.5); +// ((ELNConnectingPoint) connectingPoint[1]).setH(1.0); +// g.drawString(((ELNConnectingPoint) connectingPoint[0]).getName(), x + width / 2 + width / 2, y); +// g.drawString(((ELNConnectingPoint) connectingPoint[1]).getName(), x + width / 2 + width / 2, +// y + height + sh0); } else { - ((ELNConnectingPoint) connectingPoint[0]).setW(0.5); - ((ELNConnectingPoint) connectingPoint[0]).setH(1.0); - ((ELNConnectingPoint) connectingPoint[1]).setW(0.5); - ((ELNConnectingPoint) connectingPoint[1]).setH(0.0); - g.drawString(((ELNConnectingPoint) connectingPoint[1]).getName(), x + width / 2 + width / 2, y); - g.drawString(((ELNConnectingPoint) connectingPoint[0]).getName(), x + width / 2 + width / 2, - y + height + sh1); +// ((ELNConnectingPoint) connectingPoint[0]).setW(0.5); +// ((ELNConnectingPoint) connectingPoint[0]).setH(1.0); +// ((ELNConnectingPoint) connectingPoint[1]).setW(0.5); +// ((ELNConnectingPoint) connectingPoint[1]).setH(0.0); +// g.drawString(((ELNConnectingPoint) connectingPoint[1]).getName(), x + width / 2 + width / 2, y); +// g.drawString(((ELNConnectingPoint) connectingPoint[0]).getName(), x + width / 2 + width / 2, +// y + height + sh1); } } g.setColor(c); @@ -528,4 +537,39 @@ public class ELNComponentResistor extends TGCScalableWithInternalComponent imple public void setFirst(boolean first) { this.first = first; } + + public boolean acceptSwallowedTGComponent(TGComponent tgc) { + if (tgc instanceof ELNPortTerminal) { + return tgc instanceof ELNPortTerminal; + } else { + return true; + } + } + + public boolean addSwallowedTGComponent(TGComponent tgc, int x, int y) { + if (tgc instanceof ELNPortTerminal) { + tgc.setFather(this); + tgc.setDrawingZone(true); + tgc.resizeWithFather(); + addInternalComponent(tgc, 0); + return true; + } + return false; + } + + public void removeSwallowedTGComponent(TGComponent tgc) { + removeInternalComponent(tgc); + } + + public void hasBeenResized() { + rescaled = true; + for(int i=0; i<nbInternalTGComponent; i++) { + if (tgcomponent[i] instanceof ELNPortTerminal) { + tgcomponent[i].resizeWithFather(); + } + } + if (getFather() != null) { + resizeWithFather(); + } + } } diff --git a/src/main/java/ui/window/JDialogELNTerminal.java b/src/main/java/ui/window/JDialogELNTerminal.java new file mode 100644 index 0000000000..24ade84f5c --- /dev/null +++ b/src/main/java/ui/window/JDialogELNTerminal.java @@ -0,0 +1,151 @@ +/* Copyright or (C) or Copr. GET / ENST, Telecom-Paris, Ludovic Apvrille + * + * ludovic.apvrille AT enst.fr + * + * This software is a computer program whose purpose is to allow the + * edition of TURTLE analysis, design and deployment diagrams, to + * allow the generation of RT-LOTOS or Java code from this diagram, + * and at last to allow the analysis of formal validation traces + * obtained from external tools, e.g. RTL from LAAS-CNRS and CADP + * from INRIA Rhone-Alpes. + * + * This software is governed by the CeCILL license under French law and + * abiding by the rules of distribution of free software. You can use, + * modify and/ or redistribute the software under the terms of the CeCILL + * license as circulated by CEA, CNRS and INRIA at the following URL + * "http://www.cecill.info". + * + * As a counterpart to the access to the source code and rights to copy, + * modify and redistribute granted by the license, users are provided only + * with a limited warranty and the software's author, the holder of the + * economic rights, and the successive licensors have only limited + * liability. + * + * In this respect, the user's attention is drawn to the risks associated + * with loading, using, modifying and/or developing or reproducing the + * software by the user in light of its specific status of free software, + * that may mean that it is complicated to manipulate, and that also + * therefore means that it is reserved for developers and experienced + * professionals having in-depth computer knowledge. Users are therefore + * encouraged to load and test the software's suitability as regards their + * requirements in conditions enabling the security of their systems and/or + * data to be ensured and, more generally, to use and operate it in the + * same conditions as regards security. + * + * The fact that you are presently reading this means that you have had + * knowledge of the CeCILL license and that you accept its terms. + */ + +package ui.window; + +import ui.eln.ELNPortTerminal; +import ui.util.*; +import java.awt.*; +import java.awt.event.*; +import javax.swing.*; + +/** + * Class JDialogELNTerminal + * Dialog for managing of ELN port terminal + * Creation: 06/07/2018 + * @version 1.0 06/07/2018 + * @author Irina Kit Yan LEE + */ + +@SuppressWarnings("serial") + +public class JDialogELNTerminal extends JDialog implements ActionListener { + + private JTextField nameTextField; + + private ELNPortTerminal term; + + public JDialogELNTerminal(ELNPortTerminal term) { + this.setTitle("Setting Port Terminal Attributes"); + this.setLocationRelativeTo(null); + this.setVisible(true); + this.setAlwaysOnTop(true); + this.setResizable(false); + + this.term = term; + + getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke("ESCAPE"), "close"); + getRootPane().getActionMap().put("close", new AbstractAction() { + public void actionPerformed(ActionEvent e) { + dispose(); + } + }); + + dialog(); + } + + public void dialog() { + JPanel mainPanel = new JPanel(new BorderLayout()); + this.add(mainPanel); + + JPanel attributesMainPanel = new JPanel(); + mainPanel.add(attributesMainPanel, BorderLayout.NORTH); + + attributesMainPanel.setLayout(new BorderLayout()); + + Box attributesBox = Box.createVerticalBox(); + attributesBox.setBorder(BorderFactory.createTitledBorder("Setting port terminal attributes")); + + GridBagLayout gridBag = new GridBagLayout(); + GridBagConstraints constraints = new GridBagConstraints(); + JPanel attributesBoxPanel = new JPanel(); + attributesBoxPanel.setFont(new Font("Helvetica", Font.PLAIN, 14)); + attributesBoxPanel.setLayout(gridBag); + + JLabel labelName = new JLabel("Name : "); + constraints = new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, + new Insets(15, 10, 5, 10), 0, 0); + gridBag.setConstraints(labelName, constraints); + attributesBoxPanel.add(labelName); + + if (term.getValue().toString().equals("")) { + nameTextField = new JTextField(10); + } else { + nameTextField = new JTextField(term.getValue().toString(), 10); + } + constraints = new GridBagConstraints(1, 0, 2, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, + new Insets(15, 10, 5, 10), 0, 0); + gridBag.setConstraints(nameTextField, constraints); + attributesBoxPanel.add(nameTextField); + + attributesBox.add(attributesBoxPanel); + + attributesMainPanel.add(attributesBox, BorderLayout.NORTH); + + JPanel downPanel = new JPanel(new FlowLayout()); + + JButton saveCloseButton = new JButton("Save and close"); + saveCloseButton.setIcon(IconManager.imgic25); + saveCloseButton.setActionCommand("Save_Close"); + saveCloseButton.addActionListener(this); + saveCloseButton.setPreferredSize(new Dimension(200, 30)); + downPanel.add(saveCloseButton); + + JButton cancelButton = new JButton("Cancel"); + cancelButton.setIcon(IconManager.imgic27); + cancelButton.setActionCommand("Cancel"); + cancelButton.addActionListener(this); + cancelButton.setPreferredSize(new Dimension(200, 30)); + downPanel.add(cancelButton); + + mainPanel.add(downPanel, BorderLayout.CENTER); + pack(); + this.getRootPane().setDefaultButton(saveCloseButton); + } + + public void actionPerformed(ActionEvent e) { + if ("Save_Close".equals(e.getActionCommand())) { + term.setValue(new String(nameTextField.getText())); + this.dispose(); + } + + if ("Cancel".equals(e.getActionCommand())) { + this.dispose(); + } + } +} \ No newline at end of file -- GitLab