diff --git a/modeling/can.xml b/modeling/can.xml deleted file mode 100644 index c578492f2d8feb5d4127e086538b93b8d7873470..0000000000000000000000000000000000000000 --- a/modeling/can.xml +++ /dev/null @@ -1,138 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> - -<TURTLEGMODELING version="1.0beta"> - -<Modeling type="SystemC-AMS" nameTab="SystemC_AMS" > -<SysCAMSComponentTaskDiagramPanel name="SystemC-AMS Component Diagram" minX="10" maxX="2500" minY="10" maxY="1500" TDF="true" DE="true" zoom="1.0" > -<COMPONENT type="1607" id="48" > -<cdparam x="342" y="148" /> -<sizeparam width="663" height="284" minWidth="1" minHeight="1" maxWidth="2000" maxHeight="2000" minDesiredWidth="0" minDesiredHeight="0" /> -<hidden value="false" /> -<cdrectangleparam minX="10" maxX="2500" minY="10" maxY="1500" /> -<infoparam name="Composite component" value="distance_sensor" /> -<TGConnectingPoint num="0" id="40" /> -<TGConnectingPoint num="1" id="41" /> -<TGConnectingPoint num="2" id="42" /> -<TGConnectingPoint num="3" id="43" /> -<TGConnectingPoint num="4" id="44" /> -<TGConnectingPoint num="5" id="45" /> -<TGConnectingPoint num="6" id="46" /> -<TGConnectingPoint num="7" id="47" /> -<extraparam> -<info hiddeni="false" /> -</extraparam> -</COMPONENT> -<SUBCOMPONENT type="1602" id="50" > -<father id="48" num="0" /> -<cdparam x="392" y="213" /> -<sizeparam width="200" height="150" minWidth="1" minHeight="1" maxWidth="2000" maxHeight="2000" minDesiredWidth="0" minDesiredHeight="0" /> -<hidden value="false" /> -<cdrectangleparam minX="0" maxX="463" minY="0" maxY="134" /> -<infoparam name="Primitive component - Block TDF" value="Block_TDF_0" /> -<TGConnectingPoint num="0" id="51" /> -<TGConnectingPoint num="1" id="52" /> -<TGConnectingPoint num="2" id="53" /> -<TGConnectingPoint num="3" id="54" /> -<TGConnectingPoint num="4" id="55" /> -<TGConnectingPoint num="5" id="56" /> -<TGConnectingPoint num="6" id="57" /> -<TGConnectingPoint num="7" id="58" /> -<extraparam> -<Data isAttacker="No" /> -<Attribute period="-1" processCode="void processing() { - -}" /> -</extraparam> -</SUBCOMPONENT> -<SUBCOMPONENT type="1602" id="39" > -<father id="48" num="1" /> -<cdparam x="713" y="214" /> -<sizeparam width="200" height="150" minWidth="1" minHeight="1" maxWidth="2000" maxHeight="2000" minDesiredWidth="0" minDesiredHeight="0" /> -<hidden value="false" /> -<cdrectangleparam minX="0" maxX="463" minY="0" maxY="134" /> -<infoparam name="Primitive component" value="analog_to_digital" /> -<TGConnectingPoint num="0" id="31" /> -<TGConnectingPoint num="1" id="32" /> -<TGConnectingPoint num="2" id="33" /> -<TGConnectingPoint num="3" id="34" /> -<TGConnectingPoint num="4" id="35" /> -<TGConnectingPoint num="5" id="36" /> -<TGConnectingPoint num="6" id="37" /> -<TGConnectingPoint num="7" id="38" /> -<extraparam> -<Data isAttacker="No" /> -<Attribute period="-1" processCode="void processing() { -} -" /> -</extraparam> -</SUBCOMPONENT> -<SUBCOMPONENT type="1604" id="10" > -<father id="39" num="0" /> -<cdparam x="700" y="281" /> -<sizeparam width="26" height="26" minWidth="1" minHeight="1" maxWidth="2000" maxHeight="2000" minDesiredWidth="0" minDesiredHeight="0" /> -<hidden value="false" /> -<cdrectangleparam minX="-13" maxX="187" minY="-13" maxY="137" /> -<infoparam name="Primitive port" value="sensorIn" /> -<TGConnectingPoint num="0" id="1" /> -<TGConnectingPoint num="1" id="2" /> -<TGConnectingPoint num="2" id="3" /> -<TGConnectingPoint num="3" id="4" /> -<TGConnectingPoint num="4" id="5" /> -<TGConnectingPoint num="5" id="6" /> -<TGConnectingPoint num="6" id="7" /> -<TGConnectingPoint num="7" id="8" /> -<TGConnectingPoint num="8" id="9" /> -<extraparam> -<Prop commName="sensorIn" commType="0" origin="0" period="-1" time="us" rate="1" delay="0" type="double" /> -</extraparam> -</SUBCOMPONENT> -<SUBCOMPONENT type="1606" id="20" > -<father id="39" num="1" /> -<cdparam x="900" y="245" /> -<sizeparam width="26" height="26" minWidth="1" minHeight="1" maxWidth="2000" maxHeight="2000" minDesiredWidth="0" minDesiredHeight="0" /> -<hidden value="false" /> -<cdrectangleparam minX="-13" maxX="187" minY="-13" maxY="137" /> -<infoparam name="Primitive port" value="soclibIn" /> -<TGConnectingPoint num="0" id="11" /> -<TGConnectingPoint num="1" id="12" /> -<TGConnectingPoint num="2" id="13" /> -<TGConnectingPoint num="3" id="14" /> -<TGConnectingPoint num="4" id="15" /> -<TGConnectingPoint num="5" id="16" /> -<TGConnectingPoint num="6" id="17" /> -<TGConnectingPoint num="7" id="18" /> -<TGConnectingPoint num="8" id="19" /> -<extraparam> -<Prop commName="soclibIn" commType="0" origin="0" period="-1" time="us" rate="1" delay="0" type="int" /> -</extraparam> -</SUBCOMPONENT> -<SUBCOMPONENT type="1606" id="30" > -<father id="39" num="2" /> -<cdparam x="900" y="311" /> -<sizeparam width="26" height="26" minWidth="1" minHeight="1" maxWidth="2000" maxHeight="2000" minDesiredWidth="0" minDesiredHeight="0" /> -<hidden value="false" /> -<cdrectangleparam minX="-13" maxX="187" minY="-13" maxY="137" /> -<infoparam name="Primitive port" value="soclibOut" /> -<TGConnectingPoint num="0" id="21" /> -<TGConnectingPoint num="1" id="22" /> -<TGConnectingPoint num="2" id="23" /> -<TGConnectingPoint num="3" id="24" /> -<TGConnectingPoint num="4" id="25" /> -<TGConnectingPoint num="5" id="26" /> -<TGConnectingPoint num="6" id="27" /> -<TGConnectingPoint num="7" id="28" /> -<TGConnectingPoint num="8" id="29" /> -<extraparam> -<Prop commName="soclibOut" commType="0" origin="1" period="-1" time="us" rate="1" delay="0" type="int" /> -</extraparam> -</SUBCOMPONENT> - - -</SysCAMSComponentTaskDiagramPanel> - -</Modeling> - - - - -</TURTLEGMODELING> \ No newline at end of file diff --git a/modeling/sin_source_sink.xml b/modeling/sin_source_sink.xml deleted file mode 100644 index 23c7962060d240d457586831048d42b279f8be61..0000000000000000000000000000000000000000 --- a/modeling/sin_source_sink.xml +++ /dev/null @@ -1,122 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> - -<TURTLEGMODELING version="1.0beta"> - -<Modeling type="SystemC-AMS" nameTab="SystemC_AMS" > -<SysCAMSComponentTaskDiagramPanel name="SystemC-AMS Component Diagram" minX="10" maxX="2500" minY="10" maxY="1500" TDF="true" DE="true" zoom="1.0" > -<CONNECTOR type="1601" id="1" > -<cdparam x="400" y="247" /> -<sizeparam width="0" height="0" minWidth="0" minHeight="0" maxWidth="2000" maxHeight="2000" minDesiredWidth="0" minDesiredHeight="0" /> -<infoparam name="connector" value="Connector between ports" /> -<P1 x="400" y="247" id="21" /> -<P2 x="483" y="247" id="2" /> -<AutomaticDrawing data="true" /> -</CONNECTOR> -<COMPONENT type="1607" id="48" > -<cdparam x="123" y="94" /> -<sizeparam width="674" height="332" minWidth="1" minHeight="1" maxWidth="2000" maxHeight="2000" minDesiredWidth="0" minDesiredHeight="0" /> -<hidden value="false" /> -<cdrectangleparam minX="10" maxX="2500" minY="10" maxY="1500" /> -<infoparam name="Composite component" value="sin_source_sink" /> -<TGConnectingPoint num="0" id="40" /> -<TGConnectingPoint num="1" id="41" /> -<TGConnectingPoint num="2" id="42" /> -<TGConnectingPoint num="3" id="43" /> -<TGConnectingPoint num="4" id="44" /> -<TGConnectingPoint num="5" id="45" /> -<TGConnectingPoint num="6" id="46" /> -<TGConnectingPoint num="7" id="47" /> -<extraparam> -<info hiddeni="false" /> -</extraparam> -</COMPONENT> -<SUBCOMPONENT type="1602" id="20" > -<father id="48" num="0" /> -<cdparam x="496" y="175" /> -<sizeparam width="200" height="150" minWidth="1" minHeight="1" maxWidth="2000" maxHeight="2000" minDesiredWidth="0" minDesiredHeight="0" /> -<hidden value="false" /> -<cdrectangleparam minX="0" maxX="474" minY="0" maxY="182" /> -<infoparam name="Primitive component" value="sink" /> -<TGConnectingPoint num="0" id="12" /> -<TGConnectingPoint num="1" id="13" /> -<TGConnectingPoint num="2" id="14" /> -<TGConnectingPoint num="3" id="15" /> -<TGConnectingPoint num="4" id="16" /> -<TGConnectingPoint num="5" id="17" /> -<TGConnectingPoint num="6" id="18" /> -<TGConnectingPoint num="7" id="19" /> -<extraparam> -<Data isAttacker="No" /> -<Attribute period="0" processCode="void processing() { using namespace std; cout << this->name() << " @ " << this->get_time() << ": " << in.read() << endl; } " /> -</extraparam> -</SUBCOMPONENT> -<SUBCOMPONENT type="1604" id="11" > -<father id="20" num="0" /> -<cdparam x="483" y="234" /> -<sizeparam width="26" height="26" minWidth="1" minHeight="1" maxWidth="2000" maxHeight="2000" minDesiredWidth="0" minDesiredHeight="0" /> -<hidden value="false" /> -<cdrectangleparam minX="-13" maxX="187" minY="-13" maxY="137" /> -<infoparam name="Primitive port" value="Port TDF in" /> -<TGConnectingPoint num="0" id="2" /> -<TGConnectingPoint num="1" id="3" /> -<TGConnectingPoint num="2" id="4" /> -<TGConnectingPoint num="3" id="5" /> -<TGConnectingPoint num="4" id="6" /> -<TGConnectingPoint num="5" id="7" /> -<TGConnectingPoint num="6" id="8" /> -<TGConnectingPoint num="7" id="9" /> -<TGConnectingPoint num="8" id="10" /> -<extraparam> -<Prop commName="in" commType="0" origin="0" period="0" time="us" rate="0" delay="0" type="double" /> -</extraparam> -</SUBCOMPONENT> -<SUBCOMPONENT type="1602" id="39" > -<father id="48" num="1" /> -<cdparam x="187" y="177" /> -<sizeparam width="200" height="150" minWidth="1" minHeight="1" maxWidth="2000" maxHeight="2000" minDesiredWidth="0" minDesiredHeight="0" /> -<hidden value="false" /> -<cdrectangleparam minX="0" maxX="474" minY="0" maxY="182" /> -<infoparam name="Primitive component" value="sin_source" /> -<TGConnectingPoint num="0" id="31" /> -<TGConnectingPoint num="1" id="32" /> -<TGConnectingPoint num="2" id="33" /> -<TGConnectingPoint num="3" id="34" /> -<TGConnectingPoint num="4" id="35" /> -<TGConnectingPoint num="5" id="36" /> -<TGConnectingPoint num="6" id="37" /> -<TGConnectingPoint num="7" id="38" /> -<extraparam> -<Data isAttacker="No" /> -<Attribute period="0" processCode="void processing() { double t = out.get_time().to_seconds(); double x = 1.5 * sin(2.0 * M_PI * 50.0 * t); out.write(x); }" /> -</extraparam> -</SUBCOMPONENT> -<SUBCOMPONENT type="1604" id="30" > -<father id="39" num="0" /> -<cdparam x="374" y="234" /> -<sizeparam width="26" height="26" minWidth="1" minHeight="1" maxWidth="2000" maxHeight="2000" minDesiredWidth="0" minDesiredHeight="0" /> -<hidden value="false" /> -<cdrectangleparam minX="-13" maxX="187" minY="-13" maxY="137" /> -<infoparam name="Primitive port" value="Port TDF out" /> -<TGConnectingPoint num="0" id="21" /> -<TGConnectingPoint num="1" id="22" /> -<TGConnectingPoint num="2" id="23" /> -<TGConnectingPoint num="3" id="24" /> -<TGConnectingPoint num="4" id="25" /> -<TGConnectingPoint num="5" id="26" /> -<TGConnectingPoint num="6" id="27" /> -<TGConnectingPoint num="7" id="28" /> -<TGConnectingPoint num="8" id="29" /> -<extraparam> -<Prop commName="out" commType="0" origin="1" period="1" time="us" rate="0" delay="0" type="double" /> -</extraparam> -</SUBCOMPONENT> - - -</SysCAMSComponentTaskDiagramPanel> - -</Modeling> - - - - -</TURTLEGMODELING> \ No newline at end of file diff --git a/src/main/java/ui/ActionPerformer.java b/src/main/java/ui/ActionPerformer.java index c736b98e075a7d191d2544ca1b34f1e06a19d62d..7e9f90ef5790ae8a0d560448c54b152946f9e3c7 100644 --- a/src/main/java/ui/ActionPerformer.java +++ b/src/main/java/ui/ActionPerformer.java @@ -955,6 +955,10 @@ public class ActionPerformer { mgui.actionOnButton(TGComponentManager.COMPONENT, TGComponentManager.ELN_INDEPENDENT_CURRENT_SOURCE); } else if (command.equals(mgui.actions[TGUIAction.ELN_NODE_REF].getActionCommand())){ mgui.actionOnButton(TGComponentManager.COMPONENT, TGComponentManager.ELN_NODE_REF); + } else if (command.equals(mgui.actions[TGUIAction.ELN_TDF_VOLTAGE_SINK].getActionCommand())){ + mgui.actionOnButton(TGComponentManager.COMPONENT, TGComponentManager.ELN_TDF_VOLTAGE_SINK); + } else if (command.equals(mgui.actions[TGUIAction.ELN_TDF_CURRENT_SINK].getActionCommand())){ + mgui.actionOnButton(TGComponentManager.COMPONENT, TGComponentManager.ELN_TDF_CURRENT_SINK); // Attack Tree Diagrams } else if (command.equals(mgui.actions[TGUIAction.ATD_BLOCK].getActionCommand())) { diff --git a/src/main/java/ui/TGComponentManager.java b/src/main/java/ui/TGComponentManager.java index 80ee7c7b3b5839c8fa76087baaaac0d76ce7ff74..47d4eb598ab845d877c8ec507549be021a05ae42 100644 --- a/src/main/java/ui/TGComponentManager.java +++ b/src/main/java/ui/TGComponentManager.java @@ -61,6 +61,7 @@ import ui.diplodocusmethodology.*; import ui.ebrdd.*; import ui.eln.*; import ui.eln.sca_eln.*; +import ui.eln.sca_eln_sca_tdf.*; import ui.ftd.*; import ui.iod.*; import ui.ncdd.*; @@ -356,6 +357,8 @@ public class TGComponentManager { 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; // SMD diagram public static final int PROSMD_START_STATE = 2000; @@ -1305,6 +1308,12 @@ public class TGComponentManager { case ELN_NODE_REF: tgc = new ELNComponentNodeRef(x, y, tdp.getMinX(), tdp.getMaxX(), tdp.getMinY(), tdp.getMaxY(), false, null, tdp); break; + case ELN_TDF_VOLTAGE_SINK: + tgc = new ELNComponentVoltageSinkTDF(x, y, tdp.getMinX(), tdp.getMaxX(), tdp.getMinY(), tdp.getMaxY(), false, null, tdp); + break; + case ELN_TDF_CURRENT_SINK: + tgc = new ELNComponentCurrentSinkTDF(x, y, tdp.getMinX(), tdp.getMaxX(), tdp.getMinY(), tdp.getMaxY(), false, null, tdp); + break; // Communication patterns + SD case TMLCP_CHOICE: tgc = new TMLCPChoice(x, y, tdp.getMinX(), tdp.getMaxX(), tdp.getMinY(), tdp.getMaxY(), false, null, tdp); @@ -1725,6 +1734,10 @@ public class TGComponentManager { return ELN_INDEPENDENT_CURRENT_SOURCE; } else if (tgc instanceof ELNComponentNodeRef) { return ELN_NODE_REF; + } else if (tgc instanceof ELNComponentVoltageSinkTDF) { + return ELN_TDF_VOLTAGE_SINK; + } else if (tgc instanceof ELNComponentCurrentSinkTDF) { + return ELN_TDF_CURRENT_SINK; // Others } else if (tgc instanceof TADDeterministicDelay) { diff --git a/src/main/java/ui/TGUIAction.java b/src/main/java/ui/TGUIAction.java index b2197e4670f2fed309bdd4a653d0ba5d98d0315c..568238ee573902be02cd0faa0581367020d9fc13 100644 --- a/src/main/java/ui/TGUIAction.java +++ b/src/main/java/ui/TGUIAction.java @@ -298,6 +298,8 @@ public class TGUIAction extends AbstractAction { public static final int ELN_INDEPENDENT_VOLTAGE_SOURCE = 491; public static final int ELN_INDEPENDENT_CURRENT_SOURCE = 492; public static final int ELN_NODE_REF = 494; + public static final int ELN_TDF_VOLTAGE_SINK = 495; + public static final int ELN_TDF_CURRENT_SINK = 496; public static final int EBRDD_EDIT = 271; public static final int EBRDD_CONNECTOR = 272; @@ -652,7 +654,7 @@ public class TGUIAction extends AbstractAction { public static final int MOVE_ENABLED = 463; public static final int FIRST_DIAGRAM = 464; - public static final int NB_ACTION = 495; + public static final int NB_ACTION = 497; private static final TAction [] actions = new TAction[NB_ACTION]; @@ -1132,7 +1134,10 @@ public class TGUIAction extends AbstractAction { actions[ELN_TRANSMISSION_LINE] = new TAction("eln-transmission-line", "Add a transmission line", IconManager.imgic8016, IconManager.imgic8016, "Transmission line", "Add a transmission line to the currently opened ELN Diagram", 0); actions[ELN_INDEPENDENT_VOLTAGE_SOURCE] = new TAction("eln-vsource", "Add a independent voltage source", IconManager.imgic8017, IconManager.imgic8017, "Independent voltage source", "Add a independent voltage source to the currently opened ELN Diagram", 0); actions[ELN_INDEPENDENT_CURRENT_SOURCE] = new TAction("eln-isource", "Add a independent current source", IconManager.imgic8018, IconManager.imgic8018, "Independent current source", "Add a independent current source to the currently opened ELN Diagram", 0); - actions[ELN_NODE_REF] = new TAction("eln-node-ref", "Add a reference node", IconManager.imgic8019, IconManager.imgic8019, "Reference node", "Add a reference node to the currently opened ELN Diagram", 0); + actions[ELN_NODE_REF] = new TAction("eln-node-ref", "Add a reference node", IconManager.imgic8019, IconManager.imgic8019, "Reference node", "Add a reference node to the currently opened ELN Diagram", 0); + actions[ELN_TDF_VOLTAGE_SINK] = new TAction("eln-tdf-vsink", "Add a conversion voltage to a TDF output signal", IconManager.imgic8020, IconManager.imgic8020, "Converts voltage to a TDF output signal", "Add a converts voltage to a TDF output signal to the currently opened ELN Diagram", 0); + actions[ELN_TDF_CURRENT_SINK] = new TAction("eln-tdf-isink", "Add a conversion current to a TDF output signal", IconManager.imgic8021, IconManager.imgic8021, "Converts current to a TDF output signal", "Add a converts current to a TDF output signal to the currently opened ELN Diagram", 0); + //ProActive State Machine Diagram actions[PROSMD_EDIT] = new TAction("edit-prosmd-diagram", "Edit ProActive state machine diagram", IconManager.imgic100, IconManager.imgic101, "Edit ProActive state machine diagram", "Make it possible to edit the currently opened ProActive state machine diagram", 0); diff --git a/src/main/java/ui/eln/ELNDiagramToolBar.java b/src/main/java/ui/eln/ELNDiagramToolBar.java index 020f91dacda317522657f2c99ff308e026a9662b..612a161b2ca220459f039b49edc3733b3bf9188a 100644 --- a/src/main/java/ui/eln/ELNDiagramToolBar.java +++ b/src/main/java/ui/eln/ELNDiagramToolBar.java @@ -78,6 +78,8 @@ public class ELNDiagramToolBar extends TToolBar { mgui.actions[TGUIAction.ELN_INDEPENDENT_VOLTAGE_SOURCE].setEnabled(b); mgui.actions[TGUIAction.ELN_INDEPENDENT_CURRENT_SOURCE].setEnabled(b); mgui.actions[TGUIAction.ELN_NODE_REF].setEnabled(b); + mgui.actions[TGUIAction.ELN_TDF_VOLTAGE_SINK].setEnabled(b); + mgui.actions[TGUIAction.ELN_TDF_CURRENT_SINK].setEnabled(b); mgui.actions[TGUIAction.ACT_MODEL_CHECKING].setEnabled(b); mgui.actions[TGUIAction.ACT_ONECLICK_LOTOS_RG].setEnabled(b); @@ -130,6 +132,14 @@ public class ELNDiagramToolBar extends TToolBar { this.addSeparator(); + button = this.add(mgui.actions[TGUIAction.ELN_TDF_VOLTAGE_SINK]); + button.addMouseListener(mgui.mouseHandler); + + button = this.add(mgui.actions[TGUIAction.ELN_TDF_CURRENT_SINK]); + button.addMouseListener(mgui.mouseHandler); + + this.addSeparator(); + button = this.add(mgui.actions[TGUIAction.ELN_CONNECTOR]); button.addMouseListener(mgui.mouseHandler); } diff --git a/src/main/java/ui/eln/sca_eln_sca_tdf/ELNComponentCurrentSinkTDF.java b/src/main/java/ui/eln/sca_eln_sca_tdf/ELNComponentCurrentSinkTDF.java new file mode 100644 index 0000000000000000000000000000000000000000..7df9b59d53a37242734e08e74838cc4418fd8ec8 --- /dev/null +++ b/src/main/java/ui/eln/sca_eln_sca_tdf/ELNComponentCurrentSinkTDF.java @@ -0,0 +1,851 @@ +/* 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.sca_eln_sca_tdf; + +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.JDialogELNComponentCurrentSinkTDF; +import ui.window.JDialogELNComponentVoltageSinkTDF; + +import javax.swing.*; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +/** + * Class ELNComponentCurrentSinkTDF + * Converts current to a TDF output signal to be used in ELN diagrams + * Creation: 29/06/2018 + * @version 1.0 29/06/2018 + * @author Irina Kit Yan LEE + */ + +public class ELNComponentCurrentSinkTDF extends TGCScalableWithInternalComponent implements ActionListener { + protected Color myColor; + protected int orientation; + private int maxFontSize = 14; + private int minFontSize = 4; + private int currentFontSize = -1; + + private int textX = 15; + private double dtextX = 0.0; + protected int decPoint = 3; + + private double scale; + + private int position = 0; + private boolean fv_0_2 = false, fv_1_3 = false, fh_0_2 = false, fh_1_3 = false; + private int old; + private boolean first; + + public ELNComponentCurrentSinkTDF(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(80, 80); + + dtextX = textX * oldScaleFactor; + textX = (int) dtextX; + dtextX = dtextX - textX; + + minWidth = 1; + minHeight = 1; + + initConnectingPoint(2); + + addTGConnectingPointsComment(); + + moveable = true; + editable = true; + removable = true; + userResizable = false; + value = tdp.findELNComponentName("TDF_ISink"); + + setScale(1.0); + + old = width; + width = height; + 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.0, "p"); + connectingPoint[1] = new ELNConnectingPoint(this, 0, 0, true, true, 0.0, 1.0, "n"); + } + + 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(); + + if (position == 0) { + if (first == false) { + first = true; + old = width; + width = height; + height = old; + } + + int attributeFontSize = this.currentFontSize * 5 / 6; + int sw0 = g.getFontMetrics().stringWidth("p"); + int sh0 = g.getFontMetrics().getAscent(); + int sw1 = g.getFontMetrics().stringWidth("n"); + int sh1 = g.getFontMetrics().getAscent(); + int w = g.getFontMetrics().stringWidth(value); + g.setFont(f.deriveFont((float) attributeFontSize)); + g.setFont(f); + g.setFont(f.deriveFont(Font.BOLD)); + g.drawString(value, x + (width - w) / 2, y - height / 4); + g.setFont(f.deriveFont(Font.PLAIN)); + + if ((fv_0_2 == false && fv_1_3 == false && fh_0_2 == false && fh_1_3 == false) + || (fv_0_2 == true && fv_1_3 == false && fh_0_2 == false && fh_1_3 == true) + || (fv_0_2 == false && fv_1_3 == true && fh_0_2 == true && fh_1_3 == false) + || (fv_0_2 == true && fv_1_3 == true && fh_0_2 == true && fh_1_3 == true)) { + rotateTop(g); + ((ELNConnectingPoint) connectingPoint[0]).setW(0.0); + ((ELNConnectingPoint) connectingPoint[0]).setH(0.0); + ((ELNConnectingPoint) connectingPoint[1]).setW(0.0); + ((ELNConnectingPoint) connectingPoint[1]).setH(1.0); + g.drawString(((ELNConnectingPoint) connectingPoint[0]).getName(), x - height / 8 - sw0, y); + g.drawString(((ELNConnectingPoint) connectingPoint[1]).getName(), x - height / 8 - sw1, + y + height + sh1); + } + if ((fv_0_2 == false && fv_1_3 == false && fh_0_2 == true && fh_1_3 == false) + || (fv_0_2 == false && fv_1_3 == true && fh_0_2 == false && fh_1_3 == false) + || (fv_0_2 == true && fv_1_3 == false && fh_0_2 == true && fh_1_3 == true) + || (fv_0_2 == true && fv_1_3 == true && fh_0_2 == false && fh_1_3 == true)) { + rotateBottomFlip(g); + ((ELNConnectingPoint) connectingPoint[0]).setW(1.0); + ((ELNConnectingPoint) connectingPoint[0]).setH(0.0); + ((ELNConnectingPoint) connectingPoint[1]).setW(1.0); + ((ELNConnectingPoint) connectingPoint[1]).setH(1.0); + g.drawString(((ELNConnectingPoint) connectingPoint[0]).getName(), x + width + height / 8, y); + g.drawString(((ELNConnectingPoint) connectingPoint[1]).getName(), x + width + height / 8, + y + height + sh1); + } + if ((fv_0_2 == true && fv_1_3 == false && fh_0_2 == false && fh_1_3 == false) + || (fv_0_2 == false && fv_1_3 == false && fh_0_2 == false && fh_1_3 == true) + || (fv_0_2 == false && fv_1_3 == true && fh_0_2 == true && fh_1_3 == true) + || (fv_0_2 == true && fv_1_3 == true && fh_0_2 == true && fh_1_3 == false)) { + rotateTopFlip(g); + ((ELNConnectingPoint) connectingPoint[0]).setW(0.0); + ((ELNConnectingPoint) connectingPoint[0]).setH(1.0); + ((ELNConnectingPoint) connectingPoint[1]).setW(0.0); + ((ELNConnectingPoint) connectingPoint[1]).setH(0.0); + g.drawString(((ELNConnectingPoint) connectingPoint[1]).getName(), x - height / 8 - sw1, y); + g.drawString(((ELNConnectingPoint) connectingPoint[0]).getName(), x - height / 8 - sw0, + y + height + sh0); + } + if ((fv_0_2 == true && fv_1_3 == false && fh_0_2 == true && fh_1_3 == false) + || (fv_0_2 == false && fv_1_3 == true && fh_0_2 == false && fh_1_3 == true) + || (fv_0_2 == true && fv_1_3 == true && fh_0_2 == false && fh_1_3 == false) + || (fv_0_2 == false && fv_1_3 == false && fh_0_2 == true && fh_1_3 == true)) { + rotateBottom(g); + ((ELNConnectingPoint) connectingPoint[0]).setW(1.0); + ((ELNConnectingPoint) connectingPoint[0]).setH(1.0); + ((ELNConnectingPoint) connectingPoint[1]).setW(1.0); + ((ELNConnectingPoint) connectingPoint[1]).setH(0.0); + g.drawString(((ELNConnectingPoint) connectingPoint[1]).getName(), x + width + height / 8, y); + g.drawString(((ELNConnectingPoint) connectingPoint[0]).getName(), x + width + height / 8, + y + height + sh0); + } + } else if (position == 1) { + if (first == false) { + first = true; + old = width; + width = height; + height = old; + } + + int attributeFontSize = this.currentFontSize * 5 / 6; + int sw0 = g.getFontMetrics().stringWidth("p"); + int sh0 = g.getFontMetrics().getAscent(); + int sw1 = g.getFontMetrics().stringWidth("n"); + int sh1 = g.getFontMetrics().getAscent(); + int w = g.getFontMetrics().stringWidth(value); + g.setFont(f.deriveFont((float) attributeFontSize)); + g.setFont(f); + g.setFont(f.deriveFont(Font.BOLD)); + g.drawString(value, x + (width - w) / 2, y - height / 6); + g.setFont(f.deriveFont(Font.PLAIN)); + + if ((fv_0_2 == false && fv_1_3 == false && fh_0_2 == false && fh_1_3 == false) + || (fv_0_2 == true && fv_1_3 == false && fh_0_2 == false && fh_1_3 == true) + || (fv_0_2 == false && fv_1_3 == true && fh_0_2 == true && fh_1_3 == false) + || (fv_0_2 == true && fv_1_3 == true && fh_0_2 == true && fh_1_3 == true)) { + rotateRight(g); + ((ELNConnectingPoint) connectingPoint[0]).setW(1.0); + ((ELNConnectingPoint) connectingPoint[0]).setH(0.0); + ((ELNConnectingPoint) connectingPoint[1]).setW(0.0); + ((ELNConnectingPoint) connectingPoint[1]).setH(0.0); + g.drawString(((ELNConnectingPoint) connectingPoint[1]).getName(), x - width / 8 - sw1, y); + g.drawString(((ELNConnectingPoint) connectingPoint[0]).getName(), x + width + width / 8, y); + } + if ((fv_0_2 == false && fv_1_3 == false && fh_0_2 == true && fh_1_3 == false) + || (fv_0_2 == false && fv_1_3 == true && fh_0_2 == false && fh_1_3 == false) + || (fv_0_2 == true && fv_1_3 == false && fh_0_2 == true && fh_1_3 == true) + || (fv_0_2 == true && fv_1_3 == true && fh_0_2 == false && fh_1_3 == true)) { + rotateRightFlip(g); + ((ELNConnectingPoint) connectingPoint[0]).setW(1.0); + ((ELNConnectingPoint) connectingPoint[0]).setH(1.0); + ((ELNConnectingPoint) connectingPoint[1]).setW(0.0); + ((ELNConnectingPoint) connectingPoint[1]).setH(1.0); + g.drawString(((ELNConnectingPoint) connectingPoint[1]).getName(), x - width / 8 - sw1, + y + height + sh1); + g.drawString(((ELNConnectingPoint) connectingPoint[0]).getName(), x + width + width / 8, + y + height + sh0); + } + if ((fv_0_2 == true && fv_1_3 == false && fh_0_2 == false && fh_1_3 == false) + || (fv_0_2 == false && fv_1_3 == false && fh_0_2 == false && fh_1_3 == true) + || (fv_0_2 == false && fv_1_3 == true && fh_0_2 == true && fh_1_3 == true) + || (fv_0_2 == true && fv_1_3 == true && fh_0_2 == true && fh_1_3 == false)) { + rotateLeftFlip(g); + ((ELNConnectingPoint) connectingPoint[0]).setW(0.0); + ((ELNConnectingPoint) connectingPoint[0]).setH(0.0); + ((ELNConnectingPoint) connectingPoint[1]).setW(1.0); + ((ELNConnectingPoint) connectingPoint[1]).setH(0.0); + g.drawString(((ELNConnectingPoint) connectingPoint[0]).getName(), x - width / 8 - sw0, y); + g.drawString(((ELNConnectingPoint) connectingPoint[1]).getName(), x + width + width / 8, y); + } + if ((fv_0_2 == true && fv_1_3 == false && fh_0_2 == true && fh_1_3 == false) + || (fv_0_2 == false && fv_1_3 == true && fh_0_2 == false && fh_1_3 == true) + || (fv_0_2 == true && fv_1_3 == true && fh_0_2 == false && fh_1_3 == false) + || (fv_0_2 == false && fv_1_3 == false && fh_0_2 == true && fh_1_3 == true)) { + rotateLeft(g); + ((ELNConnectingPoint) connectingPoint[0]).setW(0.0); + ((ELNConnectingPoint) connectingPoint[0]).setH(1.0); + ((ELNConnectingPoint) connectingPoint[1]).setW(1.0); + ((ELNConnectingPoint) connectingPoint[1]).setH(1.0); + g.drawString(((ELNConnectingPoint) connectingPoint[0]).getName(), x - width / 8 - sw0, + y + height + sh0); + g.drawString(((ELNConnectingPoint) connectingPoint[1]).getName(), x + width + width / 8, + y + height + sh1); + } + } else if (position == 2) { + if (first == false) { + first = true; + old = width; + width = height; + height = old; + } + + int attributeFontSize = this.currentFontSize * 5 / 6; + int sw0 = g.getFontMetrics().stringWidth("p"); + int sh0 = g.getFontMetrics().getAscent(); + int sw1 = g.getFontMetrics().stringWidth("n"); + int sh1 = g.getFontMetrics().getAscent(); + int w = g.getFontMetrics().stringWidth(value); + g.setFont(f.deriveFont((float) attributeFontSize)); + g.setFont(f); + g.setFont(f.deriveFont(Font.BOLD)); + g.drawString(value, x + (width - w) / 2, y - height / 4); + g.setFont(f.deriveFont(Font.PLAIN)); + + if ((fv_0_2 == false && fv_1_3 == false && fh_0_2 == false && fh_1_3 == false) + || (fv_0_2 == true && fv_1_3 == false && fh_0_2 == false && fh_1_3 == true) + || (fv_0_2 == false && fv_1_3 == true && fh_0_2 == true && fh_1_3 == false) + || (fv_0_2 == true && fv_1_3 == true && fh_0_2 == true && fh_1_3 == true)) { + rotateBottom(g); + ((ELNConnectingPoint) connectingPoint[0]).setW(1.0); + ((ELNConnectingPoint) connectingPoint[0]).setH(1.0); + ((ELNConnectingPoint) connectingPoint[1]).setW(1.0); + ((ELNConnectingPoint) connectingPoint[1]).setH(0.0); + g.drawString(((ELNConnectingPoint) connectingPoint[1]).getName(), x + width + height / 8, y); + g.drawString(((ELNConnectingPoint) connectingPoint[0]).getName(), x + width + height / 8, + y + height + sh0); + } + if ((fv_0_2 == false && fv_1_3 == false && fh_0_2 == true && fh_1_3 == false) + || (fv_0_2 == false && fv_1_3 == true && fh_0_2 == false && fh_1_3 == false) + || (fv_0_2 == true && fv_1_3 == false && fh_0_2 == true && fh_1_3 == true) + || (fv_0_2 == true && fv_1_3 == true && fh_0_2 == false && fh_1_3 == true)) { + rotateTopFlip(g); + ((ELNConnectingPoint) connectingPoint[0]).setW(0.0); + ((ELNConnectingPoint) connectingPoint[0]).setH(1.0); + ((ELNConnectingPoint) connectingPoint[1]).setW(0.0); + ((ELNConnectingPoint) connectingPoint[1]).setH(0.0); + g.drawString(((ELNConnectingPoint) connectingPoint[1]).getName(), x - height / 8 - sw1, y); + g.drawString(((ELNConnectingPoint) connectingPoint[0]).getName(), x - height / 8 - sw0, + y + height + sh0); + } + if ((fv_0_2 == true && fv_1_3 == false && fh_0_2 == false && fh_1_3 == false) + || (fv_0_2 == false && fv_1_3 == false && fh_0_2 == false && fh_1_3 == true) + || (fv_0_2 == false && fv_1_3 == true && fh_0_2 == true && fh_1_3 == true) + || (fv_0_2 == true && fv_1_3 == true && fh_0_2 == true && fh_1_3 == false)) { + rotateBottomFlip(g); + ((ELNConnectingPoint) connectingPoint[0]).setW(1.0); + ((ELNConnectingPoint) connectingPoint[0]).setH(0.0); + ((ELNConnectingPoint) connectingPoint[1]).setW(1.0); + ((ELNConnectingPoint) connectingPoint[1]).setH(1.0); + g.drawString(((ELNConnectingPoint) connectingPoint[0]).getName(), x + width + height / 8, y); + g.drawString(((ELNConnectingPoint) connectingPoint[1]).getName(), x + width + height / 8, + y + height + sh1); + } + if ((fv_0_2 == true && fv_1_3 == false && fh_0_2 == true && fh_1_3 == false) + || (fv_0_2 == false && fv_1_3 == true && fh_0_2 == false && fh_1_3 == true) + || (fv_0_2 == true && fv_1_3 == true && fh_0_2 == false && fh_1_3 == false) + || (fv_0_2 == false && fv_1_3 == false && fh_0_2 == true && fh_1_3 == true)) { + rotateTop(g); + ((ELNConnectingPoint) connectingPoint[0]).setW(0.0); + ((ELNConnectingPoint) connectingPoint[0]).setH(0.0); + ((ELNConnectingPoint) connectingPoint[1]).setW(0.0); + ((ELNConnectingPoint) connectingPoint[1]).setH(1.0); + g.drawString(((ELNConnectingPoint) connectingPoint[0]).getName(), x - height / 8 - sw0, y); + g.drawString(((ELNConnectingPoint) connectingPoint[1]).getName(), x - height / 8 - sw1, + y + height + sh1); + } + } else if (position == 3) { + if (first == false) { + first = true; + old = width; + width = height; + height = old; + } + + int attributeFontSize = this.currentFontSize * 5 / 6; + int sw0 = g.getFontMetrics().stringWidth("p"); + int sh0 = g.getFontMetrics().getAscent(); + int sw1 = g.getFontMetrics().stringWidth("n"); + int sh1 = g.getFontMetrics().getAscent(); + int w = g.getFontMetrics().stringWidth(value); + g.setFont(f.deriveFont((float) attributeFontSize)); + g.setFont(f); + g.setFont(f.deriveFont(Font.BOLD)); + g.drawString(value, x + (width - w) / 2, y - height / 6); + g.setFont(f.deriveFont(Font.PLAIN)); + + if ((fv_0_2 == false && fv_1_3 == false && fh_0_2 == false && fh_1_3 == false) + || (fv_0_2 == true && fv_1_3 == false && fh_0_2 == false && fh_1_3 == true) + || (fv_0_2 == false && fv_1_3 == true && fh_0_2 == true && fh_1_3 == false) + || (fv_0_2 == true && fv_1_3 == true && fh_0_2 == true && fh_1_3 == true)) { + rotateLeft(g); + ((ELNConnectingPoint) connectingPoint[0]).setW(1.0); + ((ELNConnectingPoint) connectingPoint[0]).setH(1.0); + ((ELNConnectingPoint) connectingPoint[1]).setW(1.0); + ((ELNConnectingPoint) connectingPoint[1]).setH(0.0); + g.drawString(((ELNConnectingPoint) connectingPoint[0]).getName(), x - width / 8 - sw0, + y + height + sh0); + g.drawString(((ELNConnectingPoint) connectingPoint[1]).getName(), x + width + width / 8, + y + height + sh1); + } + if ((fv_0_2 == false && fv_1_3 == false && fh_0_2 == true && fh_1_3 == false) + || (fv_0_2 == false && fv_1_3 == true && fh_0_2 == false && fh_1_3 == false) + || (fv_0_2 == true && fv_1_3 == false && fh_0_2 == true && fh_1_3 == true) + || (fv_0_2 == true && fv_1_3 == true && fh_0_2 == false && fh_1_3 == true)) { + rotateLeftFlip(g); + ((ELNConnectingPoint) connectingPoint[0]).setW(0.0); + ((ELNConnectingPoint) connectingPoint[0]).setH(0.0); + ((ELNConnectingPoint) connectingPoint[1]).setW(1.0); + ((ELNConnectingPoint) connectingPoint[1]).setH(0.0); + g.drawString(((ELNConnectingPoint) connectingPoint[0]).getName(), x - width / 8 - sw0, y); + g.drawString(((ELNConnectingPoint) connectingPoint[1]).getName(), x + width + width / 8, y); + } + if ((fv_0_2 == true && fv_1_3 == false && fh_0_2 == false && fh_1_3 == false) + || (fv_0_2 == false && fv_1_3 == false && fh_0_2 == false && fh_1_3 == true) + || (fv_0_2 == false && fv_1_3 == true && fh_0_2 == true && fh_1_3 == true) + || (fv_0_2 == true && fv_1_3 == true && fh_0_2 == true && fh_1_3 == false)) { + rotateRightFlip(g); + ((ELNConnectingPoint) connectingPoint[0]).setW(1.0); + ((ELNConnectingPoint) connectingPoint[0]).setH(1.0); + ((ELNConnectingPoint) connectingPoint[1]).setW(0.0); + ((ELNConnectingPoint) connectingPoint[1]).setH(1.0); + g.drawString(((ELNConnectingPoint) connectingPoint[1]).getName(), x - width / 8 - sw1, + y + height + sh1); + g.drawString(((ELNConnectingPoint) connectingPoint[0]).getName(), x + width + width / 8, + y + height + sh0); + } + if ((fv_0_2 == true && fv_1_3 == false && fh_0_2 == true && fh_1_3 == false) + || (fv_0_2 == false && fv_1_3 == true && fh_0_2 == false && fh_1_3 == true) + || (fv_0_2 == true && fv_1_3 == true && fh_0_2 == false && fh_1_3 == false) + || (fv_0_2 == false && fv_1_3 == false && fh_0_2 == true && fh_1_3 == true)) { + rotateRight(g); + ((ELNConnectingPoint) connectingPoint[0]).setW(1.0); + ((ELNConnectingPoint) connectingPoint[0]).setH(0.0); + ((ELNConnectingPoint) connectingPoint[1]).setW(0.0); + ((ELNConnectingPoint) connectingPoint[1]).setH(0.0); + g.drawString(((ELNConnectingPoint) connectingPoint[1]).getName(), x - width / 8 - sw1, y); + g.drawString(((ELNConnectingPoint) connectingPoint[0]).getName(), x + width + width / 8, y); + } + } + g.setColor(c); + g.setFont(fold); + } + + private void rotateTop(Graphics g) { + int[] ptx0 = { x, x + 2 * width / 6 }; + int[] pty0 = { y, y }; + g.drawPolygon(ptx0, pty0, 2); + int[] ptx1 = { x, x + 2 * width / 6 }; + int[] pty1 = { y + height, y + height }; + g.drawPolygon(ptx1, pty1, 2); + int[] ptx3 = { x + 2 * width / 6 - width / 12 - width / 24, x + 2 * width / 6 - width / 12, + x + 2 * width / 6 - width / 12, x + 2 * width / 6 - width / 12, x + 2 * width / 6 - width / 12, + x + 2 * width / 6 - width / 24 }; + int[] pty3 = { y + height / 8, y + height / 8, y + height / 16, y + height / 8 + height / 16, y + height / 8, + y + height / 8 }; + g.drawPolygon(ptx3, pty3, 6); + int[] ptx4 = { x + 2 * width / 6 - width / 12 - width / 24, x + 2 * width / 6 - width / 24 }; + int[] pty4 = { y + height - height / 8, y + height - height / 8 }; + g.drawPolygon(ptx4, pty4, 2); + int[] ptx5 = { x + 5 * width / 6 + width / 12 + width / 24, x + 5 * width / 6 + width / 12 + width / 24, + x + 5 * width / 6 + width / 12, x + 5 * width / 6 + width / 12 + width / 24, + x + 5 * width / 6 + width / 6, x + 5 * width / 6 + width / 12 + width / 24 }; + int[] pty5 = { y + height / 4, y + 3 * height / 4 - height / 8, y + 3 * height / 4 - height / 8, + y + 3 * height / 4, y + 3 * height / 4 - height / 8, y + 3 * height / 4 - height / 8 }; + g.drawPolygon(ptx5, pty5, 6); + g.fillPolygon(ptx5, pty5, 6); + } + + private void rotateTopFlip(Graphics g) { + int[] ptx0 = { x, x + 2 * width / 6 }; + int[] pty0 = { y, y }; + g.drawPolygon(ptx0, pty0, 2); + int[] ptx1 = { x, x + 2 * width / 6 }; + int[] pty1 = { y + height, y + height }; + g.drawPolygon(ptx1, pty1, 2); + int[] ptx3 = { x + 2 * width / 6 - width / 12 - width / 24, x + 2 * width / 6 - width / 12, + x + 2 * width / 6 - width / 12, x + 2 * width / 6 - width / 12, x + 2 * width / 6 - width / 12, + x + 2 * width / 6 - width / 24 }; + int[] pty3 = { y + height - height / 8, y + height - height / 8, y + height - height / 16, + y + height - height / 8 - height / 16, y + height - height / 8, y + height - height / 8 }; + g.drawPolygon(ptx3, pty3, 6); + int[] ptx4 = { x + 2 * width / 6 - width / 12 - width / 24, x + 2 * width / 6 - width / 24 }; + int[] pty4 = { y + height / 8, y + height / 8 }; + g.drawPolygon(ptx4, pty4, 2); + int[] ptx5 = { x + 5 * width / 6 + width / 12 + width / 24, x + 5 * width / 6 + width / 12 + width / 24, + x + 5 * width / 6 + width / 12, x + 5 * width / 6 + width / 12 + width / 24, + x + 5 * width / 6 + width / 6, x + 5 * width / 6 + width / 12 + width / 24 }; + int[] pty5 = { y + 3 * height / 4, y + height / 4 + height / 8, y + height / 4 + height / 8, y + height / 4, + y + height / 4 + height / 8, y + height / 4 + height / 8 }; + g.drawPolygon(ptx5, pty5, 6); + g.fillPolygon(ptx5, pty5, 6); + } + + private void rotateBottom(Graphics g) { + int[] ptx0 = { x + 4 * width / 6, x + width }; + int[] pty0 = { y, y }; + g.drawPolygon(ptx0, pty0, 2); + int[] ptx1 = { x + 4 * width / 6, x + width }; + int[] pty1 = { y + height, y + height }; + g.drawPolygon(ptx1, pty1, 2); + int[] ptx3 = { x + 4 * width / 6 + width / 24, x + 4 * width / 6 + width / 12, x + 4 * width / 6 + width / 12, + x + 4 * width / 6 + width / 12, x + 4 * width / 6 + width / 12, + x + 4 * width / 6 + width / 12 + width / 24 }; + int[] pty3 = { y + height - height / 8, y + height - height / 8, y + height - height / 16, + y + height - height / 8 - height / 16, y + height - height / 8, y + height - height / 8 }; + g.drawPolygon(ptx3, pty3, 6); + int[] ptx4 = { x + 4 * width / 6 + width / 24, x + 4 * width / 6 + width / 12 + width / 24 }; + int[] pty4 = { y + height / 8, y + height / 8 }; + g.drawPolygon(ptx4, pty4, 2); + int[] ptx5 = { x + width / 6 - width / 12 - width / 24, x + width / 6 - width / 12 - width / 24, + x + width / 6 - width / 12, x + width / 6 - width / 12 - width / 24, x + width / 6 - width / 6, + x + width / 6 - width / 12 - width / 24 }; + int[] pty5 = { y + 3 * height / 4, y + height / 4 + height / 8, y + height / 4 + height / 8, y + height / 4, + y + height / 4 + height / 8, y + height / 4 + height / 8 }; + g.drawPolygon(ptx5, pty5, 6); + g.fillPolygon(ptx5, pty5, 6); + } + + private void rotateBottomFlip(Graphics g) { + int[] ptx0 = { x + 4 * width / 6, x + width }; + int[] pty0 = { y, y }; + g.drawPolygon(ptx0, pty0, 2); + int[] ptx1 = { x + 4 * width / 6, x + width }; + int[] pty1 = { y + height, y + height }; + g.drawPolygon(ptx1, pty1, 2); + int[] ptx3 = { x + 4 * width / 6 + width / 24, x + 4 * width / 6 + width / 12, x + 4 * width / 6 + width / 12, + x + 4 * width / 6 + width / 12, x + 4 * width / 6 + width / 12, + x + 4 * width / 6 + width / 12 + width / 24 }; + int[] pty3 = { y + height / 8, y + height / 8, y + height / 16, y + height / 8 + height / 16, y + height / 8, + y + height / 8 }; + g.drawPolygon(ptx3, pty3, 6); + int[] ptx4 = { x + 4 * width / 6 + width / 24, x + 4 * width / 6 + width / 12 + width / 24 }; + int[] pty4 = { y + height - height / 8, y + height - height / 8 }; + g.drawPolygon(ptx4, pty4, 2); + int[] ptx5 = { x + width / 6 - width / 12 - width / 24, x + width / 6 - width / 12 - width / 24, + x + width / 6 - width / 12, x + width / 6 - width / 12 - width / 24, x + width / 6 - width / 6, + x + width / 6 - width / 12 - width / 24 }; + int[] pty5 = { y + height / 4, y + 3 * height / 4 - height / 8, y + 3 * height / 4 - height / 8, + y + 3 * height / 4, y + 3 * height / 4 - height / 8, y + 3 * height / 4 - height / 8 }; + g.drawPolygon(ptx5, pty5, 6); + g.fillPolygon(ptx5, pty5, 6); + } + + private void rotateRight(Graphics g) { + int[] ptx0 = { x, x }; + int[] pty0 = { y, y + 2 * height / 6 }; + g.drawPolygon(ptx0, pty0, 2); + int[] ptx1 = { x + width, x + width }; + int[] pty1 = { y, y + 2 * height / 6 }; + g.drawPolygon(ptx1, pty1, 2); + int[] ptx3 = { x + width - width / 8, x + width - width / 8, x + width - width / 16, + x + width - width / 8 - width / 16, x + width - width / 8, x + width - width / 8 }; + int[] pty3 = { y + 2 * height / 6 - height / 12 - height / 24, y + 2 * height / 6 - height / 12, + y + 2 * height / 6 - height / 12, y + 2 * height / 6 - height / 12, y + 2 * height / 6 - height / 12, + y + 2 * height / 6 - height / 24 }; + g.drawPolygon(ptx3, pty3, 6); + int[] ptx4 = { x + width / 8, x + width / 8 }; + int[] pty4 = { y + 2 * height / 6 - height / 12 - height / 24, y + 2 * height / 6 - height / 24 }; + g.drawPolygon(ptx4, pty4, 2); + int[] ptx5 = { x + 3 * width / 4, x + width / 4 + width / 8, x + width / 4 + width / 8, x + width / 4, + x + width / 4 + width / 8, x + width / 4 + width / 8 }; + int[] pty5 = { y + 5 * height / 6 + height / 12 + height / 24, y + 5 * height / 6 + height / 12 + height / 24, + y + 5 * height / 6 + height / 12, y + 5 * height / 6 + height / 12 + height / 24, + y + 5 * height / 6 + height / 6, y + 5 * height / 6 + height / 12 + height / 24 }; + g.drawPolygon(ptx5, pty5, 6); + g.fillPolygon(ptx5, pty5, 6); + } + + private void rotateRightFlip(Graphics g) { + int[] ptx0 = { x, x }; + int[] pty0 = { y + 4 * height / 6, y + height }; + g.drawPolygon(ptx0, pty0, 2); + int[] ptx1 = { x + width, x + width }; + int[] pty1 = { y + 4 * height / 6, y + height }; + g.drawPolygon(ptx1, pty1, 2); + int[] ptx3 = { x + width - width / 8, x + width - width / 8, x + width - width / 16, + x + width - width / 8 - width / 16, x + width - width / 8, x + width - width / 8 }; + int[] pty3 = { y + 4 * height / 6 + height / 24, y + 4 * height / 6 + height / 12, + y + 4 * height / 6 + height / 12, y + 4 * height / 6 + height / 12, y + 4 * height / 6 + height / 12, + y + 4 * height / 6 + height / 12 + height / 24 }; + g.drawPolygon(ptx3, pty3, 6); + int[] ptx4 = { x + width / 8, x + width / 8 }; + int[] pty4 = { y + 4 * height / 6 + height / 24, y + 4 * height / 6 + height / 12 + height / 24 }; + g.drawPolygon(ptx4, pty4, 2); + int[] ptx5 = { x + 3 * width / 4, x + width / 4 + width / 8, x + width / 4 + width / 8, x + width / 4, + x + width / 4 + width / 8, x + width / 4 + width / 8 }; + int[] pty5 = { y + height / 6 - height / 12 - height / 24, y + height / 6 - height / 12 - height / 24, + y + height / 6 - height / 12, y + height / 6 - height / 12 - height / 24, y + height / 6 - height / 6, + y + height / 6 - height / 12 - height / 24 }; + g.drawPolygon(ptx5, pty5, 6); + g.fillPolygon(ptx5, pty5, 6); + } + + private void rotateLeft(Graphics g) { + int[] ptx0 = { x, x }; + int[] pty0 = { y + 4 * height / 6, y + height }; + g.drawPolygon(ptx0, pty0, 2); + int[] ptx1 = { x + width, x + width }; + int[] pty1 = { y + 4 * height / 6, y + height }; + g.drawPolygon(ptx1, pty1, 2); + int[] ptx3 = { x + width / 8, x + width / 8, x + width / 16, x + width / 8 + width / 16, x + width / 8, + x + width / 8 }; + int[] pty3 = { y + 4 * height / 6 + height / 24, y + 4 * height / 6 + height / 12, + y + 4 * height / 6 + height / 12, y + 4 * height / 6 + height / 12, y + 4 * height / 6 + height / 12, + y + 4 * height / 6 + height / 12 + height / 24 }; + g.drawPolygon(ptx3, pty3, 6); + int[] ptx4 = { x + width - width / 8, x + width - width / 8 }; + int[] pty4 = { y + 4 * height / 6 + height / 24, y + 4 * height / 6 + height / 12 + height / 24 }; + g.drawPolygon(ptx4, pty4, 2); + int[] ptx5 = { x + width / 4, x + 3 * width / 4 - width / 8, x + 3 * width / 4 - width / 8, x + 3 * width / 4, + x + 3 * width / 4 - width / 8, x + 3 * width / 4 - width / 8 }; + int[] pty5 = { y + height / 6 - height / 12 - height / 24, y + height / 6 - height / 12 - height / 24, + y + height / 6 - height / 12, y + height / 6 - height / 12 - height / 24, y + height / 6 - height / 6, + y + height / 6 - height / 12 - height / 24 }; + g.drawPolygon(ptx5, pty5, 6); + g.fillPolygon(ptx5, pty5, 6); + } + + private void rotateLeftFlip(Graphics g) { + int[] ptx0 = { x, x }; + int[] pty0 = { y, y + 2 * height / 6 }; + g.drawPolygon(ptx0, pty0, 2); + int[] ptx1 = { x + width, x + width }; + int[] pty1 = { y, y + 2 * height / 6 }; + g.drawPolygon(ptx1, pty1, 2); + int[] ptx3 = { x + width / 8, x + width / 8, x + width / 16, x + width / 8 + width / 16, x + width / 8, + x + width / 8 }; + int[] pty3 = { y + 2 * height / 6 - height / 12 - height / 24, y + 2 * height / 6 - height / 12, + y + 2 * height / 6 - height / 12, y + 2 * height / 6 - height / 12, y + 2 * height / 6 - height / 12, + y + 2 * height / 6 - height / 24 }; + g.drawPolygon(ptx3, pty3, 6); + int[] ptx4 = { x + width - width / 8, x + width - width / 8 }; + int[] pty4 = { y + 2 * height / 6 - height / 12 - height / 24, y + 2 * height / 6 - height / 24 }; + g.drawPolygon(ptx4, pty4, 2); + int[] ptx5 = { x + width / 4, x + 3 * width / 4 - width / 8, x + 3 * width / 4 - width / 8, x + 3 * width / 4, + x + 3 * width / 4 - width / 8, x + 3 * width / 4 - width / 8 }; + int[] pty5 = { y + 5 * height / 6 + height / 12 + height / 24, y + 5 * height / 6 + height / 12 + height / 24, + y + 5 * height / 6 + height / 12, y + 5 * height / 6 + height / 12 + height / 24, + y + 5 * height / 6 + height / 6, y + 5 * height / 6 + height / 12 + height / 24 }; + g.drawPolygon(ptx5, pty5, 6); + g.fillPolygon(ptx5, pty5, 6); + } + + 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_TDF_CURRENT_SINK; + } + + public boolean editOndoubleClick(JFrame frame) { + JDialogELNComponentCurrentSinkTDF jde = new JDialogELNComponentCurrentSinkTDF(this); + jde.setVisible(true); + return true; + } + + protected String translateExtraParam() { + StringBuffer sb = new StringBuffer("<extraparam>\n"); + sb.append("<attributes scale=\"" + scale); + sb.append("\" position=\"" + position); + sb.append("\" width=\"" + width); + sb.append("\" height=\"" + height); + sb.append("\" fv_0_2=\"" + fv_0_2); + sb.append("\" fv_1_3=\"" + fv_1_3); + sb.append("\" fh_0_2=\"" + fh_0_2); + sb.append("\" fh_1_3=\"" + fh_1_3); + sb.append("\" first=\"" + first + "\""); + 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; + + double scale; + int position, width, height; + boolean fv_0_2, fv_1_3, fh_0_2, fh_1_3, first; + + 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")) { + scale = Double.parseDouble(elt.getAttribute("scale")); + position = Integer.parseInt(elt.getAttribute("position")); + width = Integer.parseInt(elt.getAttribute("width")); + height = Integer.parseInt(elt.getAttribute("height")); + fv_0_2 = Boolean.parseBoolean(elt.getAttribute("fv_0_2")); + fv_1_3 = Boolean.parseBoolean(elt.getAttribute("fv_1_3")); + fh_0_2 = Boolean.parseBoolean(elt.getAttribute("fh_0_2")); + fh_1_3 = Boolean.parseBoolean(elt.getAttribute("fh_1_3")); + first = Boolean.parseBoolean(elt.getAttribute("first")); + setScale(scale); + setPosition(position); + this.width = width; + this.height = height; + setFv_0_2(fv_0_2); + setFv_1_3(fv_1_3); + setFh_0_2(fh_0_2); + setFh_1_3(fh_1_3); + setFirst(first); + } + } + } + } + } + } catch (Exception e) { + throw new MalformedModelingException(); + } + } + + public void addActionToPopupMenu(JPopupMenu componentMenu, ActionListener menuAL, int x, int y) { + componentMenu.addSeparator(); + + JMenuItem rotateright = new JMenuItem("Rotate right 90°"); + rotateright.addActionListener(this); + componentMenu.add(rotateright); + + JMenuItem rotateleft = new JMenuItem("Rotate left 90°"); + rotateleft.addActionListener(this); + componentMenu.add(rotateleft); + + componentMenu.addSeparator(); + + JMenuItem rotatevertically = new JMenuItem("Flip vertically"); + rotatevertically.addActionListener(this); + componentMenu.add(rotatevertically); + + JMenuItem rotatehorizontally = new JMenuItem("Flip horizontally"); + rotatehorizontally.addActionListener(this); + componentMenu.add(rotatehorizontally); + } + + public void actionPerformed(ActionEvent e) { + if (e.getActionCommand().equals("Rotate right 90°")) { + position++; + position %= 4; + first = false; + } + if (e.getActionCommand().equals("Rotate left 90°")) { + position = position + 3; + position %= 4; + first = false; + } + if (e.getActionCommand().equals("Flip vertically")) { + if (position == 0 || position == 2) { + if (fv_0_2 == false) { + fv_0_2 = true; + } else { + fv_0_2 = false; + } + } + if (position == 1 || position == 3) { + if (fv_1_3 == false) { + fv_1_3 = true; + } else { + fv_1_3 = false; + } + } + } + if (e.getActionCommand().equals("Flip horizontally")) { + if (position == 0 || position == 2) { + if (fh_0_2 == false) { + fh_0_2 = true; + } else { + fh_0_2 = false; + } + } + if (position == 1 || position == 3) { + if (fh_1_3 == false) { + fh_1_3 = true; + } else { + fh_1_3 = false; + } + } + } + } + + public int getDefaultConnector() { + return TGComponentManager.ELN_CONNECTOR; + } + + public double getScale() { + return scale; + } + + public void setScale(double _scale) { + scale = _scale; + } + + public int getPosition() { + return position; + } + + public void setPosition(int position) { + this.position = position; + } + + public boolean isFv_0_2() { + return fv_0_2; + } + + public void setFv_0_2(boolean fv_0_2) { + this.fv_0_2 = fv_0_2; + } + + public boolean isFv_1_3() { + return fv_1_3; + } + + public void setFv_1_3(boolean fv_1_3) { + this.fv_1_3 = fv_1_3; + } + + public boolean isFh_0_2() { + return fh_0_2; + } + + public void setFh_0_2(boolean fh_0_2) { + this.fh_0_2 = fh_0_2; + } + + public boolean isFh_1_3() { + return fh_1_3; + } + + public void setFh_1_3(boolean fh_1_3) { + this.fh_1_3 = fh_1_3; + } + + public boolean isFirst() { + return first; + } + + public void setFirst(boolean first) { + this.first = first; + } +} diff --git a/src/main/java/ui/eln/sca_eln_sca_tdf/ELNComponentVoltageSinkTDF.java b/src/main/java/ui/eln/sca_eln_sca_tdf/ELNComponentVoltageSinkTDF.java new file mode 100644 index 0000000000000000000000000000000000000000..e513c56c7b35f2c5d200d6397da6b8a3edbb3b50 --- /dev/null +++ b/src/main/java/ui/eln/sca_eln_sca_tdf/ELNComponentVoltageSinkTDF.java @@ -0,0 +1,850 @@ +/* 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.sca_eln_sca_tdf; + +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.JDialogELNComponentVoltageSinkTDF; + +import javax.swing.*; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +/** + * Class ELNComponentVoltageSinkTDF + * Converts voltage to a TDF output signal to be used in ELN diagrams + * Creation: 29/06/2018 + * @version 1.0 29/06/2018 + * @author Irina Kit Yan LEE + */ + +public class ELNComponentVoltageSinkTDF extends TGCScalableWithInternalComponent implements ActionListener { + protected Color myColor; + protected int orientation; + private int maxFontSize = 14; + private int minFontSize = 4; + private int currentFontSize = -1; + + private int textX = 15; + private double dtextX = 0.0; + protected int decPoint = 3; + + private double scale; + + private int position = 0; + private boolean fv_0_2 = false, fv_1_3 = false, fh_0_2 = false, fh_1_3 = false; + private int old; + private boolean first; + + public ELNComponentVoltageSinkTDF(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(80, 80); + + dtextX = textX * oldScaleFactor; + textX = (int) dtextX; + dtextX = dtextX - textX; + + minWidth = 1; + minHeight = 1; + + initConnectingPoint(2); + + addTGConnectingPointsComment(); + + moveable = true; + editable = true; + removable = true; + userResizable = false; + value = tdp.findELNComponentName("TDF_VSink"); + + setScale(1.0); + + old = width; + width = height; + 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.0, "p"); + connectingPoint[1] = new ELNConnectingPoint(this, 0, 0, true, true, 0.0, 1.0, "n"); + } + + 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(); + + if (position == 0) { + if (first == false) { + first = true; + old = width; + width = height; + height = old; + } + + int attributeFontSize = this.currentFontSize * 5 / 6; + int sw0 = g.getFontMetrics().stringWidth("p"); + int sh0 = g.getFontMetrics().getAscent(); + int sw1 = g.getFontMetrics().stringWidth("n"); + int sh1 = g.getFontMetrics().getAscent(); + int w = g.getFontMetrics().stringWidth(value); + g.setFont(f.deriveFont((float) attributeFontSize)); + g.setFont(f); + g.setFont(f.deriveFont(Font.BOLD)); + g.drawString(value, x + (width - w) / 2, y - height / 4); + g.setFont(f.deriveFont(Font.PLAIN)); + + if ((fv_0_2 == false && fv_1_3 == false && fh_0_2 == false && fh_1_3 == false) + || (fv_0_2 == true && fv_1_3 == false && fh_0_2 == false && fh_1_3 == true) + || (fv_0_2 == false && fv_1_3 == true && fh_0_2 == true && fh_1_3 == false) + || (fv_0_2 == true && fv_1_3 == true && fh_0_2 == true && fh_1_3 == true)) { + rotateTop(g); + ((ELNConnectingPoint) connectingPoint[0]).setW(0.0); + ((ELNConnectingPoint) connectingPoint[0]).setH(0.0); + ((ELNConnectingPoint) connectingPoint[1]).setW(0.0); + ((ELNConnectingPoint) connectingPoint[1]).setH(1.0); + g.drawString(((ELNConnectingPoint) connectingPoint[0]).getName(), x - height / 8 - sw0, y); + g.drawString(((ELNConnectingPoint) connectingPoint[1]).getName(), x - height / 8 - sw1, + y + height + sh1); + } + if ((fv_0_2 == false && fv_1_3 == false && fh_0_2 == true && fh_1_3 == false) + || (fv_0_2 == false && fv_1_3 == true && fh_0_2 == false && fh_1_3 == false) + || (fv_0_2 == true && fv_1_3 == false && fh_0_2 == true && fh_1_3 == true) + || (fv_0_2 == true && fv_1_3 == true && fh_0_2 == false && fh_1_3 == true)) { + rotateBottomFlip(g); + ((ELNConnectingPoint) connectingPoint[0]).setW(1.0); + ((ELNConnectingPoint) connectingPoint[0]).setH(0.0); + ((ELNConnectingPoint) connectingPoint[1]).setW(1.0); + ((ELNConnectingPoint) connectingPoint[1]).setH(1.0); + g.drawString(((ELNConnectingPoint) connectingPoint[0]).getName(), x + width + height / 8, y); + g.drawString(((ELNConnectingPoint) connectingPoint[1]).getName(), x + width + height / 8, + y + height + sh1); + } + if ((fv_0_2 == true && fv_1_3 == false && fh_0_2 == false && fh_1_3 == false) + || (fv_0_2 == false && fv_1_3 == false && fh_0_2 == false && fh_1_3 == true) + || (fv_0_2 == false && fv_1_3 == true && fh_0_2 == true && fh_1_3 == true) + || (fv_0_2 == true && fv_1_3 == true && fh_0_2 == true && fh_1_3 == false)) { + rotateTopFlip(g); + ((ELNConnectingPoint) connectingPoint[0]).setW(0.0); + ((ELNConnectingPoint) connectingPoint[0]).setH(1.0); + ((ELNConnectingPoint) connectingPoint[1]).setW(0.0); + ((ELNConnectingPoint) connectingPoint[1]).setH(0.0); + g.drawString(((ELNConnectingPoint) connectingPoint[1]).getName(), x - height / 8 - sw1, y); + g.drawString(((ELNConnectingPoint) connectingPoint[0]).getName(), x - height / 8 - sw0, + y + height + sh0); + } + if ((fv_0_2 == true && fv_1_3 == false && fh_0_2 == true && fh_1_3 == false) + || (fv_0_2 == false && fv_1_3 == true && fh_0_2 == false && fh_1_3 == true) + || (fv_0_2 == true && fv_1_3 == true && fh_0_2 == false && fh_1_3 == false) + || (fv_0_2 == false && fv_1_3 == false && fh_0_2 == true && fh_1_3 == true)) { + rotateBottom(g); + ((ELNConnectingPoint) connectingPoint[0]).setW(1.0); + ((ELNConnectingPoint) connectingPoint[0]).setH(1.0); + ((ELNConnectingPoint) connectingPoint[1]).setW(1.0); + ((ELNConnectingPoint) connectingPoint[1]).setH(0.0); + g.drawString(((ELNConnectingPoint) connectingPoint[1]).getName(), x + width + height / 8, y); + g.drawString(((ELNConnectingPoint) connectingPoint[0]).getName(), x + width + height / 8, + y + height + sh0); + } + } else if (position == 1) { + if (first == false) { + first = true; + old = width; + width = height; + height = old; + } + + int attributeFontSize = this.currentFontSize * 5 / 6; + int sw0 = g.getFontMetrics().stringWidth("p"); + int sh0 = g.getFontMetrics().getAscent(); + int sw1 = g.getFontMetrics().stringWidth("n"); + int sh1 = g.getFontMetrics().getAscent(); + int w = g.getFontMetrics().stringWidth(value); + g.setFont(f.deriveFont((float) attributeFontSize)); + g.setFont(f); + g.setFont(f.deriveFont(Font.BOLD)); + g.drawString(value, x + (width - w) / 2, y - height / 6); + g.setFont(f.deriveFont(Font.PLAIN)); + + if ((fv_0_2 == false && fv_1_3 == false && fh_0_2 == false && fh_1_3 == false) + || (fv_0_2 == true && fv_1_3 == false && fh_0_2 == false && fh_1_3 == true) + || (fv_0_2 == false && fv_1_3 == true && fh_0_2 == true && fh_1_3 == false) + || (fv_0_2 == true && fv_1_3 == true && fh_0_2 == true && fh_1_3 == true)) { + rotateRight(g); + ((ELNConnectingPoint) connectingPoint[0]).setW(1.0); + ((ELNConnectingPoint) connectingPoint[0]).setH(0.0); + ((ELNConnectingPoint) connectingPoint[1]).setW(0.0); + ((ELNConnectingPoint) connectingPoint[1]).setH(0.0); + g.drawString(((ELNConnectingPoint) connectingPoint[1]).getName(), x - width / 8 - sw1, y); + g.drawString(((ELNConnectingPoint) connectingPoint[0]).getName(), x + width + width / 8, y); + } + if ((fv_0_2 == false && fv_1_3 == false && fh_0_2 == true && fh_1_3 == false) + || (fv_0_2 == false && fv_1_3 == true && fh_0_2 == false && fh_1_3 == false) + || (fv_0_2 == true && fv_1_3 == false && fh_0_2 == true && fh_1_3 == true) + || (fv_0_2 == true && fv_1_3 == true && fh_0_2 == false && fh_1_3 == true)) { + rotateRightFlip(g); + ((ELNConnectingPoint) connectingPoint[0]).setW(1.0); + ((ELNConnectingPoint) connectingPoint[0]).setH(1.0); + ((ELNConnectingPoint) connectingPoint[1]).setW(0.0); + ((ELNConnectingPoint) connectingPoint[1]).setH(1.0); + g.drawString(((ELNConnectingPoint) connectingPoint[1]).getName(), x - width / 8 - sw1, + y + height + sh1); + g.drawString(((ELNConnectingPoint) connectingPoint[0]).getName(), x + width + width / 8, + y + height + sh0); + } + if ((fv_0_2 == true && fv_1_3 == false && fh_0_2 == false && fh_1_3 == false) + || (fv_0_2 == false && fv_1_3 == false && fh_0_2 == false && fh_1_3 == true) + || (fv_0_2 == false && fv_1_3 == true && fh_0_2 == true && fh_1_3 == true) + || (fv_0_2 == true && fv_1_3 == true && fh_0_2 == true && fh_1_3 == false)) { + rotateLeftFlip(g); + ((ELNConnectingPoint) connectingPoint[0]).setW(0.0); + ((ELNConnectingPoint) connectingPoint[0]).setH(0.0); + ((ELNConnectingPoint) connectingPoint[1]).setW(1.0); + ((ELNConnectingPoint) connectingPoint[1]).setH(0.0); + g.drawString(((ELNConnectingPoint) connectingPoint[0]).getName(), x - width / 8 - sw0, y); + g.drawString(((ELNConnectingPoint) connectingPoint[1]).getName(), x + width + width / 8, y); + } + if ((fv_0_2 == true && fv_1_3 == false && fh_0_2 == true && fh_1_3 == false) + || (fv_0_2 == false && fv_1_3 == true && fh_0_2 == false && fh_1_3 == true) + || (fv_0_2 == true && fv_1_3 == true && fh_0_2 == false && fh_1_3 == false) + || (fv_0_2 == false && fv_1_3 == false && fh_0_2 == true && fh_1_3 == true)) { + rotateLeft(g); + ((ELNConnectingPoint) connectingPoint[0]).setW(0.0); + ((ELNConnectingPoint) connectingPoint[0]).setH(1.0); + ((ELNConnectingPoint) connectingPoint[1]).setW(1.0); + ((ELNConnectingPoint) connectingPoint[1]).setH(1.0); + g.drawString(((ELNConnectingPoint) connectingPoint[0]).getName(), x - width / 8 - sw0, + y + height + sh0); + g.drawString(((ELNConnectingPoint) connectingPoint[1]).getName(), x + width + width / 8, + y + height + sh1); + } + } else if (position == 2) { + if (first == false) { + first = true; + old = width; + width = height; + height = old; + } + + int attributeFontSize = this.currentFontSize * 5 / 6; + int sw0 = g.getFontMetrics().stringWidth("p"); + int sh0 = g.getFontMetrics().getAscent(); + int sw1 = g.getFontMetrics().stringWidth("n"); + int sh1 = g.getFontMetrics().getAscent(); + int w = g.getFontMetrics().stringWidth(value); + g.setFont(f.deriveFont((float) attributeFontSize)); + g.setFont(f); + g.setFont(f.deriveFont(Font.BOLD)); + g.drawString(value, x + (width - w) / 2, y - height / 4); + g.setFont(f.deriveFont(Font.PLAIN)); + + if ((fv_0_2 == false && fv_1_3 == false && fh_0_2 == false && fh_1_3 == false) + || (fv_0_2 == true && fv_1_3 == false && fh_0_2 == false && fh_1_3 == true) + || (fv_0_2 == false && fv_1_3 == true && fh_0_2 == true && fh_1_3 == false) + || (fv_0_2 == true && fv_1_3 == true && fh_0_2 == true && fh_1_3 == true)) { + rotateBottom(g); + ((ELNConnectingPoint) connectingPoint[0]).setW(1.0); + ((ELNConnectingPoint) connectingPoint[0]).setH(1.0); + ((ELNConnectingPoint) connectingPoint[1]).setW(1.0); + ((ELNConnectingPoint) connectingPoint[1]).setH(0.0); + g.drawString(((ELNConnectingPoint) connectingPoint[1]).getName(), x + width + height / 8, y); + g.drawString(((ELNConnectingPoint) connectingPoint[0]).getName(), x + width + height / 8, + y + height + sh0); + } + if ((fv_0_2 == false && fv_1_3 == false && fh_0_2 == true && fh_1_3 == false) + || (fv_0_2 == false && fv_1_3 == true && fh_0_2 == false && fh_1_3 == false) + || (fv_0_2 == true && fv_1_3 == false && fh_0_2 == true && fh_1_3 == true) + || (fv_0_2 == true && fv_1_3 == true && fh_0_2 == false && fh_1_3 == true)) { + rotateTopFlip(g); + ((ELNConnectingPoint) connectingPoint[0]).setW(0.0); + ((ELNConnectingPoint) connectingPoint[0]).setH(1.0); + ((ELNConnectingPoint) connectingPoint[1]).setW(0.0); + ((ELNConnectingPoint) connectingPoint[1]).setH(0.0); + g.drawString(((ELNConnectingPoint) connectingPoint[1]).getName(), x - height / 8 - sw1, y); + g.drawString(((ELNConnectingPoint) connectingPoint[0]).getName(), x - height / 8 - sw0, + y + height + sh0); + } + if ((fv_0_2 == true && fv_1_3 == false && fh_0_2 == false && fh_1_3 == false) + || (fv_0_2 == false && fv_1_3 == false && fh_0_2 == false && fh_1_3 == true) + || (fv_0_2 == false && fv_1_3 == true && fh_0_2 == true && fh_1_3 == true) + || (fv_0_2 == true && fv_1_3 == true && fh_0_2 == true && fh_1_3 == false)) { + rotateBottomFlip(g); + ((ELNConnectingPoint) connectingPoint[0]).setW(1.0); + ((ELNConnectingPoint) connectingPoint[0]).setH(0.0); + ((ELNConnectingPoint) connectingPoint[1]).setW(1.0); + ((ELNConnectingPoint) connectingPoint[1]).setH(1.0); + g.drawString(((ELNConnectingPoint) connectingPoint[0]).getName(), x + width + height / 8, y); + g.drawString(((ELNConnectingPoint) connectingPoint[1]).getName(), x + width + height / 8, + y + height + sh1); + } + if ((fv_0_2 == true && fv_1_3 == false && fh_0_2 == true && fh_1_3 == false) + || (fv_0_2 == false && fv_1_3 == true && fh_0_2 == false && fh_1_3 == true) + || (fv_0_2 == true && fv_1_3 == true && fh_0_2 == false && fh_1_3 == false) + || (fv_0_2 == false && fv_1_3 == false && fh_0_2 == true && fh_1_3 == true)) { + rotateTop(g); + ((ELNConnectingPoint) connectingPoint[0]).setW(0.0); + ((ELNConnectingPoint) connectingPoint[0]).setH(0.0); + ((ELNConnectingPoint) connectingPoint[1]).setW(0.0); + ((ELNConnectingPoint) connectingPoint[1]).setH(1.0); + g.drawString(((ELNConnectingPoint) connectingPoint[0]).getName(), x - height / 8 - sw0, y); + g.drawString(((ELNConnectingPoint) connectingPoint[1]).getName(), x - height / 8 - sw1, + y + height + sh1); + } + } else if (position == 3) { + if (first == false) { + first = true; + old = width; + width = height; + height = old; + } + + int attributeFontSize = this.currentFontSize * 5 / 6; + int sw0 = g.getFontMetrics().stringWidth("p"); + int sh0 = g.getFontMetrics().getAscent(); + int sw1 = g.getFontMetrics().stringWidth("n"); + int sh1 = g.getFontMetrics().getAscent(); + int w = g.getFontMetrics().stringWidth(value); + g.setFont(f.deriveFont((float) attributeFontSize)); + g.setFont(f); + g.setFont(f.deriveFont(Font.BOLD)); + g.drawString(value, x + (width - w) / 2, y - height / 6); + g.setFont(f.deriveFont(Font.PLAIN)); + + if ((fv_0_2 == false && fv_1_3 == false && fh_0_2 == false && fh_1_3 == false) + || (fv_0_2 == true && fv_1_3 == false && fh_0_2 == false && fh_1_3 == true) + || (fv_0_2 == false && fv_1_3 == true && fh_0_2 == true && fh_1_3 == false) + || (fv_0_2 == true && fv_1_3 == true && fh_0_2 == true && fh_1_3 == true)) { + rotateLeft(g); + ((ELNConnectingPoint) connectingPoint[0]).setW(1.0); + ((ELNConnectingPoint) connectingPoint[0]).setH(1.0); + ((ELNConnectingPoint) connectingPoint[1]).setW(1.0); + ((ELNConnectingPoint) connectingPoint[1]).setH(0.0); + g.drawString(((ELNConnectingPoint) connectingPoint[0]).getName(), x - width / 8 - sw0, + y + height + sh0); + g.drawString(((ELNConnectingPoint) connectingPoint[1]).getName(), x + width + width / 8, + y + height + sh1); + } + if ((fv_0_2 == false && fv_1_3 == false && fh_0_2 == true && fh_1_3 == false) + || (fv_0_2 == false && fv_1_3 == true && fh_0_2 == false && fh_1_3 == false) + || (fv_0_2 == true && fv_1_3 == false && fh_0_2 == true && fh_1_3 == true) + || (fv_0_2 == true && fv_1_3 == true && fh_0_2 == false && fh_1_3 == true)) { + rotateLeftFlip(g); + ((ELNConnectingPoint) connectingPoint[0]).setW(0.0); + ((ELNConnectingPoint) connectingPoint[0]).setH(0.0); + ((ELNConnectingPoint) connectingPoint[1]).setW(1.0); + ((ELNConnectingPoint) connectingPoint[1]).setH(0.0); + g.drawString(((ELNConnectingPoint) connectingPoint[0]).getName(), x - width / 8 - sw0, y); + g.drawString(((ELNConnectingPoint) connectingPoint[1]).getName(), x + width + width / 8, y); + } + if ((fv_0_2 == true && fv_1_3 == false && fh_0_2 == false && fh_1_3 == false) + || (fv_0_2 == false && fv_1_3 == false && fh_0_2 == false && fh_1_3 == true) + || (fv_0_2 == false && fv_1_3 == true && fh_0_2 == true && fh_1_3 == true) + || (fv_0_2 == true && fv_1_3 == true && fh_0_2 == true && fh_1_3 == false)) { + rotateRightFlip(g); + ((ELNConnectingPoint) connectingPoint[0]).setW(1.0); + ((ELNConnectingPoint) connectingPoint[0]).setH(1.0); + ((ELNConnectingPoint) connectingPoint[1]).setW(0.0); + ((ELNConnectingPoint) connectingPoint[1]).setH(1.0); + g.drawString(((ELNConnectingPoint) connectingPoint[1]).getName(), x - width / 8 - sw1, + y + height + sh1); + g.drawString(((ELNConnectingPoint) connectingPoint[0]).getName(), x + width + width / 8, + y + height + sh0); + } + if ((fv_0_2 == true && fv_1_3 == false && fh_0_2 == true && fh_1_3 == false) + || (fv_0_2 == false && fv_1_3 == true && fh_0_2 == false && fh_1_3 == true) + || (fv_0_2 == true && fv_1_3 == true && fh_0_2 == false && fh_1_3 == false) + || (fv_0_2 == false && fv_1_3 == false && fh_0_2 == true && fh_1_3 == true)) { + rotateRight(g); + ((ELNConnectingPoint) connectingPoint[0]).setW(1.0); + ((ELNConnectingPoint) connectingPoint[0]).setH(0.0); + ((ELNConnectingPoint) connectingPoint[1]).setW(0.0); + ((ELNConnectingPoint) connectingPoint[1]).setH(0.0); + g.drawString(((ELNConnectingPoint) connectingPoint[1]).getName(), x - width / 8 - sw1, y); + g.drawString(((ELNConnectingPoint) connectingPoint[0]).getName(), x + width + width / 8, y); + } + } + g.setColor(c); + g.setFont(fold); + } + + private void rotateTop(Graphics g) { + int[] ptx0 = { x, x + 2 * width / 6 }; + int[] pty0 = { y, y }; + g.drawPolygon(ptx0, pty0, 2); + int[] ptx1 = { x, x + 2 * width / 6 }; + int[] pty1 = { y + height, y + height }; + g.drawPolygon(ptx1, pty1, 2); + int[] ptx3 = { x + 2 * width / 6 - width / 12 - width / 24, x + 2 * width / 6 - width / 12, + x + 2 * width / 6 - width / 12, x + 2 * width / 6 - width / 12, x + 2 * width / 6 - width / 12, + x + 2 * width / 6 - width / 24 }; + int[] pty3 = { y + height / 8, y + height / 8, y + height / 16, y + height / 8 + height / 16, y + height / 8, + y + height / 8 }; + g.drawPolygon(ptx3, pty3, 6); + int[] ptx4 = { x + 2 * width / 6 - width / 12 - width / 24, x + 2 * width / 6 - width / 24 }; + int[] pty4 = { y + height - height / 8, y + height - height / 8 }; + g.drawPolygon(ptx4, pty4, 2); + int[] ptx5 = { x + 5 * width / 6 + width / 12 + width / 24, x + 5 * width / 6 + width / 12 + width / 24, + x + 5 * width / 6 + width / 12, x + 5 * width / 6 + width / 12 + width / 24, + x + 5 * width / 6 + width / 6, x + 5 * width / 6 + width / 12 + width / 24 }; + int[] pty5 = { y + height / 4, y + 3 * height / 4 - height / 8, y + 3 * height / 4 - height / 8, + y + 3 * height / 4, y + 3 * height / 4 - height / 8, y + 3 * height / 4 - height / 8 }; + g.drawPolygon(ptx5, pty5, 6); + g.fillPolygon(ptx5, pty5, 6); + } + + private void rotateTopFlip(Graphics g) { + int[] ptx0 = { x, x + 2 * width / 6 }; + int[] pty0 = { y, y }; + g.drawPolygon(ptx0, pty0, 2); + int[] ptx1 = { x, x + 2 * width / 6 }; + int[] pty1 = { y + height, y + height }; + g.drawPolygon(ptx1, pty1, 2); + int[] ptx3 = { x + 2 * width / 6 - width / 12 - width / 24, x + 2 * width / 6 - width / 12, + x + 2 * width / 6 - width / 12, x + 2 * width / 6 - width / 12, x + 2 * width / 6 - width / 12, + x + 2 * width / 6 - width / 24 }; + int[] pty3 = { y + height - height / 8, y + height - height / 8, y + height - height / 16, + y + height - height / 8 - height / 16, y + height - height / 8, y + height - height / 8 }; + g.drawPolygon(ptx3, pty3, 6); + int[] ptx4 = { x + 2 * width / 6 - width / 12 - width / 24, x + 2 * width / 6 - width / 24 }; + int[] pty4 = { y + height / 8, y + height / 8 }; + g.drawPolygon(ptx4, pty4, 2); + int[] ptx5 = { x + 5 * width / 6 + width / 12 + width / 24, x + 5 * width / 6 + width / 12 + width / 24, + x + 5 * width / 6 + width / 12, x + 5 * width / 6 + width / 12 + width / 24, + x + 5 * width / 6 + width / 6, x + 5 * width / 6 + width / 12 + width / 24 }; + int[] pty5 = { y + 3 * height / 4, y + height / 4 + height / 8, y + height / 4 + height / 8, y + height / 4, + y + height / 4 + height / 8, y + height / 4 + height / 8 }; + g.drawPolygon(ptx5, pty5, 6); + g.fillPolygon(ptx5, pty5, 6); + } + + private void rotateBottom(Graphics g) { + int[] ptx0 = { x + 4 * width / 6, x + width }; + int[] pty0 = { y, y }; + g.drawPolygon(ptx0, pty0, 2); + int[] ptx1 = { x + 4 * width / 6, x + width }; + int[] pty1 = { y + height, y + height }; + g.drawPolygon(ptx1, pty1, 2); + int[] ptx3 = { x + 4 * width / 6 + width / 24, x + 4 * width / 6 + width / 12, x + 4 * width / 6 + width / 12, + x + 4 * width / 6 + width / 12, x + 4 * width / 6 + width / 12, + x + 4 * width / 6 + width / 12 + width / 24 }; + int[] pty3 = { y + height - height / 8, y + height - height / 8, y + height - height / 16, + y + height - height / 8 - height / 16, y + height - height / 8, y + height - height / 8 }; + g.drawPolygon(ptx3, pty3, 6); + int[] ptx4 = { x + 4 * width / 6 + width / 24, x + 4 * width / 6 + width / 12 + width / 24 }; + int[] pty4 = { y + height / 8, y + height / 8 }; + g.drawPolygon(ptx4, pty4, 2); + int[] ptx5 = { x + width / 6 - width / 12 - width / 24, x + width / 6 - width / 12 - width / 24, + x + width / 6 - width / 12, x + width / 6 - width / 12 - width / 24, x + width / 6 - width / 6, + x + width / 6 - width / 12 - width / 24 }; + int[] pty5 = { y + 3 * height / 4, y + height / 4 + height / 8, y + height / 4 + height / 8, y + height / 4, + y + height / 4 + height / 8, y + height / 4 + height / 8 }; + g.drawPolygon(ptx5, pty5, 6); + g.fillPolygon(ptx5, pty5, 6); + } + + private void rotateBottomFlip(Graphics g) { + int[] ptx0 = { x + 4 * width / 6, x + width }; + int[] pty0 = { y, y }; + g.drawPolygon(ptx0, pty0, 2); + int[] ptx1 = { x + 4 * width / 6, x + width }; + int[] pty1 = { y + height, y + height }; + g.drawPolygon(ptx1, pty1, 2); + int[] ptx3 = { x + 4 * width / 6 + width / 24, x + 4 * width / 6 + width / 12, x + 4 * width / 6 + width / 12, + x + 4 * width / 6 + width / 12, x + 4 * width / 6 + width / 12, + x + 4 * width / 6 + width / 12 + width / 24 }; + int[] pty3 = { y + height / 8, y + height / 8, y + height / 16, y + height / 8 + height / 16, y + height / 8, + y + height / 8 }; + g.drawPolygon(ptx3, pty3, 6); + int[] ptx4 = { x + 4 * width / 6 + width / 24, x + 4 * width / 6 + width / 12 + width / 24 }; + int[] pty4 = { y + height - height / 8, y + height - height / 8 }; + g.drawPolygon(ptx4, pty4, 2); + int[] ptx5 = { x + width / 6 - width / 12 - width / 24, x + width / 6 - width / 12 - width / 24, + x + width / 6 - width / 12, x + width / 6 - width / 12 - width / 24, x + width / 6 - width / 6, + x + width / 6 - width / 12 - width / 24 }; + int[] pty5 = { y + height / 4, y + 3 * height / 4 - height / 8, y + 3 * height / 4 - height / 8, + y + 3 * height / 4, y + 3 * height / 4 - height / 8, y + 3 * height / 4 - height / 8 }; + g.drawPolygon(ptx5, pty5, 6); + g.fillPolygon(ptx5, pty5, 6); + } + + private void rotateRight(Graphics g) { + int[] ptx0 = { x, x }; + int[] pty0 = { y, y + 2 * height / 6 }; + g.drawPolygon(ptx0, pty0, 2); + int[] ptx1 = { x + width, x + width }; + int[] pty1 = { y, y + 2 * height / 6 }; + g.drawPolygon(ptx1, pty1, 2); + int[] ptx3 = { x + width - width / 8, x + width - width / 8, x + width - width / 16, + x + width - width / 8 - width / 16, x + width - width / 8, x + width - width / 8 }; + int[] pty3 = { y + 2 * height / 6 - height / 12 - height / 24, y + 2 * height / 6 - height / 12, + y + 2 * height / 6 - height / 12, y + 2 * height / 6 - height / 12, y + 2 * height / 6 - height / 12, + y + 2 * height / 6 - height / 24 }; + g.drawPolygon(ptx3, pty3, 6); + int[] ptx4 = { x + width / 8, x + width / 8 }; + int[] pty4 = { y + 2 * height / 6 - height / 12 - height / 24, y + 2 * height / 6 - height / 24 }; + g.drawPolygon(ptx4, pty4, 2); + int[] ptx5 = { x + 3 * width / 4, x + width / 4 + width / 8, x + width / 4 + width / 8, x + width / 4, + x + width / 4 + width / 8, x + width / 4 + width / 8 }; + int[] pty5 = { y + 5 * height / 6 + height / 12 + height / 24, y + 5 * height / 6 + height / 12 + height / 24, + y + 5 * height / 6 + height / 12, y + 5 * height / 6 + height / 12 + height / 24, + y + 5 * height / 6 + height / 6, y + 5 * height / 6 + height / 12 + height / 24 }; + g.drawPolygon(ptx5, pty5, 6); + g.fillPolygon(ptx5, pty5, 6); + } + + private void rotateRightFlip(Graphics g) { + int[] ptx0 = { x, x }; + int[] pty0 = { y + 4 * height / 6, y + height }; + g.drawPolygon(ptx0, pty0, 2); + int[] ptx1 = { x + width, x + width }; + int[] pty1 = { y + 4 * height / 6, y + height }; + g.drawPolygon(ptx1, pty1, 2); + int[] ptx3 = { x + width - width / 8, x + width - width / 8, x + width - width / 16, + x + width - width / 8 - width / 16, x + width - width / 8, x + width - width / 8 }; + int[] pty3 = { y + 4 * height / 6 + height / 24, y + 4 * height / 6 + height / 12, + y + 4 * height / 6 + height / 12, y + 4 * height / 6 + height / 12, y + 4 * height / 6 + height / 12, + y + 4 * height / 6 + height / 12 + height / 24 }; + g.drawPolygon(ptx3, pty3, 6); + int[] ptx4 = { x + width / 8, x + width / 8 }; + int[] pty4 = { y + 4 * height / 6 + height / 24, y + 4 * height / 6 + height / 12 + height / 24 }; + g.drawPolygon(ptx4, pty4, 2); + int[] ptx5 = { x + 3 * width / 4, x + width / 4 + width / 8, x + width / 4 + width / 8, x + width / 4, + x + width / 4 + width / 8, x + width / 4 + width / 8 }; + int[] pty5 = { y + height / 6 - height / 12 - height / 24, y + height / 6 - height / 12 - height / 24, + y + height / 6 - height / 12, y + height / 6 - height / 12 - height / 24, y + height / 6 - height / 6, + y + height / 6 - height / 12 - height / 24 }; + g.drawPolygon(ptx5, pty5, 6); + g.fillPolygon(ptx5, pty5, 6); + } + + private void rotateLeft(Graphics g) { + int[] ptx0 = { x, x }; + int[] pty0 = { y + 4 * height / 6, y + height }; + g.drawPolygon(ptx0, pty0, 2); + int[] ptx1 = { x + width, x + width }; + int[] pty1 = { y + 4 * height / 6, y + height }; + g.drawPolygon(ptx1, pty1, 2); + int[] ptx3 = { x + width / 8, x + width / 8, x + width / 16, x + width / 8 + width / 16, x + width / 8, + x + width / 8 }; + int[] pty3 = { y + 4 * height / 6 + height / 24, y + 4 * height / 6 + height / 12, + y + 4 * height / 6 + height / 12, y + 4 * height / 6 + height / 12, y + 4 * height / 6 + height / 12, + y + 4 * height / 6 + height / 12 + height / 24 }; + g.drawPolygon(ptx3, pty3, 6); + int[] ptx4 = { x + width - width / 8, x + width - width / 8 }; + int[] pty4 = { y + 4 * height / 6 + height / 24, y + 4 * height / 6 + height / 12 + height / 24 }; + g.drawPolygon(ptx4, pty4, 2); + int[] ptx5 = { x + width / 4, x + 3 * width / 4 - width / 8, x + 3 * width / 4 - width / 8, x + 3 * width / 4, + x + 3 * width / 4 - width / 8, x + 3 * width / 4 - width / 8 }; + int[] pty5 = { y + height / 6 - height / 12 - height / 24, y + height / 6 - height / 12 - height / 24, + y + height / 6 - height / 12, y + height / 6 - height / 12 - height / 24, y + height / 6 - height / 6, + y + height / 6 - height / 12 - height / 24 }; + g.drawPolygon(ptx5, pty5, 6); + g.fillPolygon(ptx5, pty5, 6); + } + + private void rotateLeftFlip(Graphics g) { + int[] ptx0 = { x, x }; + int[] pty0 = { y, y + 2 * height / 6 }; + g.drawPolygon(ptx0, pty0, 2); + int[] ptx1 = { x + width, x + width }; + int[] pty1 = { y, y + 2 * height / 6 }; + g.drawPolygon(ptx1, pty1, 2); + int[] ptx3 = { x + width / 8, x + width / 8, x + width / 16, x + width / 8 + width / 16, x + width / 8, + x + width / 8 }; + int[] pty3 = { y + 2 * height / 6 - height / 12 - height / 24, y + 2 * height / 6 - height / 12, + y + 2 * height / 6 - height / 12, y + 2 * height / 6 - height / 12, y + 2 * height / 6 - height / 12, + y + 2 * height / 6 - height / 24 }; + g.drawPolygon(ptx3, pty3, 6); + int[] ptx4 = { x + width - width / 8, x + width - width / 8 }; + int[] pty4 = { y + 2 * height / 6 - height / 12 - height / 24, y + 2 * height / 6 - height / 24 }; + g.drawPolygon(ptx4, pty4, 2); + int[] ptx5 = { x + width / 4, x + 3 * width / 4 - width / 8, x + 3 * width / 4 - width / 8, x + 3 * width / 4, + x + 3 * width / 4 - width / 8, x + 3 * width / 4 - width / 8 }; + int[] pty5 = { y + 5 * height / 6 + height / 12 + height / 24, y + 5 * height / 6 + height / 12 + height / 24, + y + 5 * height / 6 + height / 12, y + 5 * height / 6 + height / 12 + height / 24, + y + 5 * height / 6 + height / 6, y + 5 * height / 6 + height / 12 + height / 24 }; + g.drawPolygon(ptx5, pty5, 6); + g.fillPolygon(ptx5, pty5, 6); + } + + 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_TDF_VOLTAGE_SINK; + } + + public boolean editOndoubleClick(JFrame frame) { + JDialogELNComponentVoltageSinkTDF jde = new JDialogELNComponentVoltageSinkTDF(this); + jde.setVisible(true); + return true; + } + + protected String translateExtraParam() { + StringBuffer sb = new StringBuffer("<extraparam>\n"); + sb.append("<attributes scale=\"" + scale); + sb.append("\" position=\"" + position); + sb.append("\" width=\"" + width); + sb.append("\" height=\"" + height); + sb.append("\" fv_0_2=\"" + fv_0_2); + sb.append("\" fv_1_3=\"" + fv_1_3); + sb.append("\" fh_0_2=\"" + fh_0_2); + sb.append("\" fh_1_3=\"" + fh_1_3); + sb.append("\" first=\"" + first + "\""); + 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; + + double scale; + int position, width, height; + boolean fv_0_2, fv_1_3, fh_0_2, fh_1_3, first; + + 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")) { + scale = Double.parseDouble(elt.getAttribute("scale")); + position = Integer.parseInt(elt.getAttribute("position")); + width = Integer.parseInt(elt.getAttribute("width")); + height = Integer.parseInt(elt.getAttribute("height")); + fv_0_2 = Boolean.parseBoolean(elt.getAttribute("fv_0_2")); + fv_1_3 = Boolean.parseBoolean(elt.getAttribute("fv_1_3")); + fh_0_2 = Boolean.parseBoolean(elt.getAttribute("fh_0_2")); + fh_1_3 = Boolean.parseBoolean(elt.getAttribute("fh_1_3")); + first = Boolean.parseBoolean(elt.getAttribute("first")); + setScale(scale); + setPosition(position); + this.width = width; + this.height = height; + setFv_0_2(fv_0_2); + setFv_1_3(fv_1_3); + setFh_0_2(fh_0_2); + setFh_1_3(fh_1_3); + setFirst(first); + } + } + } + } + } + } catch (Exception e) { + throw new MalformedModelingException(); + } + } + + public void addActionToPopupMenu(JPopupMenu componentMenu, ActionListener menuAL, int x, int y) { + componentMenu.addSeparator(); + + JMenuItem rotateright = new JMenuItem("Rotate right 90°"); + rotateright.addActionListener(this); + componentMenu.add(rotateright); + + JMenuItem rotateleft = new JMenuItem("Rotate left 90°"); + rotateleft.addActionListener(this); + componentMenu.add(rotateleft); + + componentMenu.addSeparator(); + + JMenuItem rotatevertically = new JMenuItem("Flip vertically"); + rotatevertically.addActionListener(this); + componentMenu.add(rotatevertically); + + JMenuItem rotatehorizontally = new JMenuItem("Flip horizontally"); + rotatehorizontally.addActionListener(this); + componentMenu.add(rotatehorizontally); + } + + public void actionPerformed(ActionEvent e) { + if (e.getActionCommand().equals("Rotate right 90°")) { + position++; + position %= 4; + first = false; + } + if (e.getActionCommand().equals("Rotate left 90°")) { + position = position + 3; + position %= 4; + first = false; + } + if (e.getActionCommand().equals("Flip vertically")) { + if (position == 0 || position == 2) { + if (fv_0_2 == false) { + fv_0_2 = true; + } else { + fv_0_2 = false; + } + } + if (position == 1 || position == 3) { + if (fv_1_3 == false) { + fv_1_3 = true; + } else { + fv_1_3 = false; + } + } + } + if (e.getActionCommand().equals("Flip horizontally")) { + if (position == 0 || position == 2) { + if (fh_0_2 == false) { + fh_0_2 = true; + } else { + fh_0_2 = false; + } + } + if (position == 1 || position == 3) { + if (fh_1_3 == false) { + fh_1_3 = true; + } else { + fh_1_3 = false; + } + } + } + } + + public int getDefaultConnector() { + return TGComponentManager.ELN_CONNECTOR; + } + + public double getScale() { + return scale; + } + + public void setScale(double _scale) { + scale = _scale; + } + + public int getPosition() { + return position; + } + + public void setPosition(int position) { + this.position = position; + } + + public boolean isFv_0_2() { + return fv_0_2; + } + + public void setFv_0_2(boolean fv_0_2) { + this.fv_0_2 = fv_0_2; + } + + public boolean isFv_1_3() { + return fv_1_3; + } + + public void setFv_1_3(boolean fv_1_3) { + this.fv_1_3 = fv_1_3; + } + + public boolean isFh_0_2() { + return fh_0_2; + } + + public void setFh_0_2(boolean fh_0_2) { + this.fh_0_2 = fh_0_2; + } + + public boolean isFh_1_3() { + return fh_1_3; + } + + public void setFh_1_3(boolean fh_1_3) { + this.fh_1_3 = fh_1_3; + } + + public boolean isFirst() { + return first; + } + + public void setFirst(boolean first) { + this.first = first; + } +} diff --git a/src/main/java/ui/util/IconManager.java b/src/main/java/ui/util/IconManager.java index bcd9a94bfc31b064d3ef9c4b58af62bc2af482f3..24cc34118927f73fa0b14595e707f6ac470c5d26 100755 --- a/src/main/java/ui/util/IconManager.java +++ b/src/main/java/ui/util/IconManager.java @@ -186,7 +186,8 @@ public class IconManager { public static ImageIcon imgic8000, imgic8001, imgic8002, imgic8003, imgic8004, imgic8005, imgic8006, imgic8007, imgic8008; // ELN - public static ImageIcon imgic8010, imgic8011, imgic8012, imgic8013, imgic8014, imgic8015, imgic8016, imgic8017, imgic8018, imgic8019; + public static ImageIcon imgic8010, imgic8011, imgic8012, imgic8013, imgic8014, imgic8015, imgic8016, imgic8017, imgic8018, imgic8019, imgic8020, + imgic8021; //private static String icon7 = "turtle_large.gif"; private static String ttoolStringIcon = "starting_logo.gif"; @@ -684,7 +685,9 @@ public class IconManager { private static String icon8017 = "elnvsource.gif"; private static String icon8018 = "elnisource.gif"; private static String icon8019 = "elnground.gif"; - + private static String icon8020 = "elntdfvsink.gif"; + private static String icon8021 = "elntdfisink.gif"; + public IconManager() { @@ -1192,6 +1195,8 @@ public class IconManager { imgic8017 = getIcon(icon8017); imgic8018 = getIcon(icon8018); imgic8019 = getIcon(icon8019); + imgic8020 = getIcon(icon8020); + imgic8021 = getIcon(icon8021); } } // Class diff --git a/src/main/java/ui/window/JDialogELNComponentCurrentSinkTDF.java b/src/main/java/ui/window/JDialogELNComponentCurrentSinkTDF.java new file mode 100644 index 0000000000000000000000000000000000000000..cb4bce01538ac016e83f218367d267fa6df3b6c8 --- /dev/null +++ b/src/main/java/ui/window/JDialogELNComponentCurrentSinkTDF.java @@ -0,0 +1,212 @@ +/* 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.sca_eln_sca_tdf.ELNComponentCurrentSinkTDF; +import ui.util.IconManager; + +import java.awt.BorderLayout; +import java.awt.Dimension; +import java.awt.FlowLayout; +import java.awt.Font; +import java.awt.GridBagConstraints; +import java.awt.GridBagLayout; +import java.awt.GridLayout; +import java.awt.Insets; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +import javax.swing.AbstractAction; +import javax.swing.BorderFactory; +import javax.swing.Box; +import javax.swing.JButton; +import javax.swing.JComponent; +import javax.swing.JDialog; +import javax.swing.JLabel; +import javax.swing.JOptionPane; +import javax.swing.JPanel; +import javax.swing.JTextField; +import javax.swing.KeyStroke; + +/** + * Class JDialogELNComponentCurrentSinkTDF + * Dialog for managing the conversion of a ELN current to a TDF output signal + * Creation: 29/06/2018 + * @version 1.0 29/06/2018 + * @author Irina Kit Yan LEE +*/ + +@SuppressWarnings("serial") + +public class JDialogELNComponentCurrentSinkTDF extends JDialog implements ActionListener { + + /** Access to ActionPerformed **/ + private JTextField nameTextField; + private JTextField valueTextField; + + /** Parameters **/ + private ELNComponentCurrentSinkTDF isink; + + /** Constructor **/ + public JDialogELNComponentCurrentSinkTDF(ELNComponentCurrentSinkTDF _isink) { + /** Set JDialog **/ + setTitle("Setting the conversion of current to TDF output signal"); + setLocationRelativeTo(null); + setVisible(true); + setAlwaysOnTop(true); + setResizable(false); + + /** Parameters **/ + isink = _isink; + + 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 **/ + JPanel mainPanel = new JPanel(new BorderLayout()); + this.add(mainPanel); + + JPanel attributesMainPanel = new JPanel(new GridLayout()); + mainPanel.add(attributesMainPanel, BorderLayout.NORTH); + + // Left Side + Box box = Box.createVerticalBox(); + box.setBorder(BorderFactory.createTitledBorder("Setting eln_tdf_isink attributes")); + + GridBagLayout gridBag = new GridBagLayout(); + GridBagConstraints constraints = new GridBagConstraints(); + JPanel boxPanel = new JPanel(); + boxPanel.setFont(new Font("Helvetica", Font.PLAIN, 14)); + boxPanel.setLayout(gridBag); + + JLabel labelName = new JLabel("nm : "); + constraints = new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0, + GridBagConstraints.CENTER, + GridBagConstraints.BOTH, + new Insets(5, 10, 5, 10), 0, 0); + gridBag.setConstraints(labelName, constraints); + boxPanel.add(labelName); + + nameTextField = new JTextField(isink.getValue().toString(), 10); + constraints = new GridBagConstraints(1, 0, 2, 1, 1.0, 1.0, + GridBagConstraints.CENTER, + GridBagConstraints.BOTH, + new Insets(5, 10, 5, 10), 0, 0); + gridBag.setConstraints(nameTextField, constraints); + boxPanel.add(nameTextField); + + JLabel valueLabel = new JLabel("scale : "); + constraints = new GridBagConstraints(0, 1, 1, 1, 1.0, 1.0, + GridBagConstraints.CENTER, + GridBagConstraints.BOTH, + new Insets(5, 10, 5, 10), 0, 0); + gridBag.setConstraints(valueLabel, constraints); + boxPanel.add(valueLabel); + + valueTextField = new JTextField("" + isink.getScale(), 10); + constraints = new GridBagConstraints(1, 1, 1, 1, 1.0, 1.0, + GridBagConstraints.CENTER, + GridBagConstraints.BOTH, + new Insets(5, 10, 5, 10), 0, 0); + gridBag.setConstraints(valueTextField, constraints); + boxPanel.add(valueTextField); + + box.add(boxPanel); + attributesMainPanel.add(box); + + // Down Side + 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())) { + isink.setValue(new String(nameTextField.getText())); + + if (!(valueTextField.getText().isEmpty())) { + Boolean valValueDouble = false; + try { + Double.parseDouble(valueTextField.getText()); + } catch (NumberFormatException e1) { + JDialog msg = new JDialog(this); + msg.setLocationRelativeTo(null); + JOptionPane.showMessageDialog(msg, "The scale coefficient is not a Double", "Warning !", + JOptionPane.WARNING_MESSAGE); + valValueDouble = true; + } + if (valValueDouble == false) { + isink.setScale(Double.parseDouble(valueTextField.getText())); + } + } else { + isink.setScale(1.0); + } + + this.dispose(); + } + + if ("Cancel".equals(e.getActionCommand())) { + this.dispose(); + } + } +} diff --git a/src/main/java/ui/window/JDialogELNComponentVoltageSinkTDF.java b/src/main/java/ui/window/JDialogELNComponentVoltageSinkTDF.java new file mode 100644 index 0000000000000000000000000000000000000000..1bb8d0ff4c6da116b90157dcb7aa14cc47524592 --- /dev/null +++ b/src/main/java/ui/window/JDialogELNComponentVoltageSinkTDF.java @@ -0,0 +1,212 @@ +/* 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.sca_eln_sca_tdf.ELNComponentVoltageSinkTDF; +import ui.util.IconManager; + +import java.awt.BorderLayout; +import java.awt.Dimension; +import java.awt.FlowLayout; +import java.awt.Font; +import java.awt.GridBagConstraints; +import java.awt.GridBagLayout; +import java.awt.GridLayout; +import java.awt.Insets; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +import javax.swing.AbstractAction; +import javax.swing.BorderFactory; +import javax.swing.Box; +import javax.swing.JButton; +import javax.swing.JComponent; +import javax.swing.JDialog; +import javax.swing.JLabel; +import javax.swing.JOptionPane; +import javax.swing.JPanel; +import javax.swing.JTextField; +import javax.swing.KeyStroke; + +/** + * Class JDialogELNComponentVoltageSinkTDF + * Dialog for managing the conversion of a ELN voltage to a TDF output signal + * Creation: 29/06/2018 + * @version 1.0 29/06/2018 + * @author Irina Kit Yan LEE +*/ + +@SuppressWarnings("serial") + +public class JDialogELNComponentVoltageSinkTDF extends JDialog implements ActionListener { + + /** Access to ActionPerformed **/ + private JTextField nameTextField; + private JTextField valueTextField; + + /** Parameters **/ + private ELNComponentVoltageSinkTDF vsink; + + /** Constructor **/ + public JDialogELNComponentVoltageSinkTDF(ELNComponentVoltageSinkTDF _vsink) { + /** Set JDialog **/ + setTitle("Setting the conversion of voltage to TDF output signal"); + setLocationRelativeTo(null); + setVisible(true); + setAlwaysOnTop(true); + setResizable(false); + + /** Parameters **/ + vsink = _vsink; + + 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 **/ + JPanel mainPanel = new JPanel(new BorderLayout()); + this.add(mainPanel); + + JPanel attributesMainPanel = new JPanel(new GridLayout()); + mainPanel.add(attributesMainPanel, BorderLayout.NORTH); + + // Left Side + Box box = Box.createVerticalBox(); + box.setBorder(BorderFactory.createTitledBorder("Setting eln_tdf_vsink attributes")); + + GridBagLayout gridBag = new GridBagLayout(); + GridBagConstraints constraints = new GridBagConstraints(); + JPanel boxPanel = new JPanel(); + boxPanel.setFont(new Font("Helvetica", Font.PLAIN, 14)); + boxPanel.setLayout(gridBag); + + JLabel labelName = new JLabel("nm : "); + constraints = new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0, + GridBagConstraints.CENTER, + GridBagConstraints.BOTH, + new Insets(5, 10, 5, 10), 0, 0); + gridBag.setConstraints(labelName, constraints); + boxPanel.add(labelName); + + nameTextField = new JTextField(vsink.getValue().toString(), 10); + constraints = new GridBagConstraints(1, 0, 2, 1, 1.0, 1.0, + GridBagConstraints.CENTER, + GridBagConstraints.BOTH, + new Insets(5, 10, 5, 10), 0, 0); + gridBag.setConstraints(nameTextField, constraints); + boxPanel.add(nameTextField); + + JLabel valueLabel = new JLabel("scale : "); + constraints = new GridBagConstraints(0, 1, 1, 1, 1.0, 1.0, + GridBagConstraints.CENTER, + GridBagConstraints.BOTH, + new Insets(5, 10, 5, 10), 0, 0); + gridBag.setConstraints(valueLabel, constraints); + boxPanel.add(valueLabel); + + valueTextField = new JTextField("" + vsink.getScale(), 10); + constraints = new GridBagConstraints(1, 1, 1, 1, 1.0, 1.0, + GridBagConstraints.CENTER, + GridBagConstraints.BOTH, + new Insets(5, 10, 5, 10), 0, 0); + gridBag.setConstraints(valueTextField, constraints); + boxPanel.add(valueTextField); + + box.add(boxPanel); + attributesMainPanel.add(box); + + // Down Side + 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())) { + vsink.setValue(new String(nameTextField.getText())); + + if (!(valueTextField.getText().isEmpty())) { + Boolean valValueDouble = false; + try { + Double.parseDouble(valueTextField.getText()); + } catch (NumberFormatException e1) { + JDialog msg = new JDialog(this); + msg.setLocationRelativeTo(null); + JOptionPane.showMessageDialog(msg, "The scale coefficient is not a Double", "Warning !", + JOptionPane.WARNING_MESSAGE); + valValueDouble = true; + } + if (valValueDouble == false) { + vsink.setScale(Double.parseDouble(valueTextField.getText())); + } + } else { + vsink.setScale(1.0); + } + + this.dispose(); + } + + if ("Cancel".equals(e.getActionCommand())) { + this.dispose(); + } + } +} diff --git a/src/main/resources/ui/util/elntdfisink.gif b/src/main/resources/ui/util/elntdfisink.gif new file mode 100644 index 0000000000000000000000000000000000000000..52215961d6fd3cd031d62073fe0e70d163b3bae2 Binary files /dev/null and b/src/main/resources/ui/util/elntdfisink.gif differ diff --git a/src/main/resources/ui/util/elntdfvsink.gif b/src/main/resources/ui/util/elntdfvsink.gif new file mode 100644 index 0000000000000000000000000000000000000000..b6e05f57a8764f47f822444bbe397ead434cb89c Binary files /dev/null and b/src/main/resources/ui/util/elntdfvsink.gif differ