diff --git a/src/main/java/ui/ActionPerformer.java b/src/main/java/ui/ActionPerformer.java index 283def42a016ff24d1503e38f8e60b7158209a10..26731cbf4916b51d47476ad16c9f847061a3f363 100644 --- a/src/main/java/ui/ActionPerformer.java +++ b/src/main/java/ui/ActionPerformer.java @@ -945,14 +945,6 @@ public class ActionPerformer { mgui.actionOnButton(TGComponentManager.COMPONENT, TGComponentManager.ELN_VOLTAGE_CONTROLLED_VOLTAGE_SOURCE); } else if (command.equals(mgui.actions[TGUIAction.ELN_VOLTAGE_CONTROLLED_CURRENT_SOURCE].getActionCommand())){ mgui.actionOnButton(TGComponentManager.COMPONENT, TGComponentManager.ELN_VOLTAGE_CONTROLLED_CURRENT_SOURCE); - } else if (command.equals(mgui.actions[TGUIAction.ELN_CURRENT_CONTROLLED_VOLTAGE_SOURCE].getActionCommand())){ - mgui.actionOnButton(TGComponentManager.COMPONENT, TGComponentManager.ELN_CURRENT_CONTROLLED_VOLTAGE_SOURCE); - } else if (command.equals(mgui.actions[TGUIAction.ELN_CURRENT_CONTROLLED_CURRENT_SOURCE].getActionCommand())){ - mgui.actionOnButton(TGComponentManager.COMPONENT, TGComponentManager.ELN_CURRENT_CONTROLLED_CURRENT_SOURCE); - } else if (command.equals(mgui.actions[TGUIAction.ELN_NULLOR].getActionCommand())){ - mgui.actionOnButton(TGComponentManager.COMPONENT, TGComponentManager.ELN_NULLOR); - } else if (command.equals(mgui.actions[TGUIAction.ELN_GYRATOR].getActionCommand())){ - mgui.actionOnButton(TGComponentManager.COMPONENT, TGComponentManager.ELN_GYRATOR); } else if (command.equals(mgui.actions[TGUIAction.ELN_IDEAL_TRANSFORMER].getActionCommand())){ mgui.actionOnButton(TGComponentManager.COMPONENT, TGComponentManager.ELN_IDEAL_TRANSFORMER); } else if (command.equals(mgui.actions[TGUIAction.ELN_TRANSMISSION_LINE].getActionCommand())){ @@ -1102,3 +1094,4 @@ public class ActionPerformer { } } } + diff --git a/src/main/java/ui/TDiagramPanel.java b/src/main/java/ui/TDiagramPanel.java index 0f5334a8d6f1a359ccf5df901752ca9816e4eeb4..927224af7328fda9f0004e05d45f611780d946f6 100755 --- a/src/main/java/ui/TDiagramPanel.java +++ b/src/main/java/ui/TDiagramPanel.java @@ -38,9 +38,10 @@ package ui; -import myutil.*; -import myutilsvg.*; -import ui.atd.ATDAttack; +import myutil.GenericTree; +import myutil.GraphicLib; +import myutil.SVGGraphics; +import myutil.TraceManager; import ui.atd.ATDBlock; import ui.avatarad.AvatarADActivity; import ui.avatarbd.AvatarBDBlock; @@ -51,19 +52,14 @@ import ui.avatarmad.AvatarMADAssumption; import ui.avatarrd.AvatarRDRequirement; import ui.avatarsmd.AvatarSMDState; import ui.cd.*; -import ui.eln.*; import ui.eln.sca_eln.*; import ui.syscams.*; -import ui.ftd.FTDFault; import ui.ncdd.NCEqNode; import ui.ncdd.NCRouteArtifact; import ui.ncdd.NCSwitchNode; import ui.ncdd.NCTrafficArtifact; import ui.oscd.TOSClass; import ui.req.Requirement; -import ui.syscams.SysCAMSBlockDE; -import ui.syscams.SysCAMSBlockTDF; -import ui.syscams.SysCAMSCompositeComponent; import ui.tmlcd.TMLTaskOperator; import ui.tmlcompd.TMLCCompositeComponent; import ui.tmlcompd.TMLCPrimitiveComponent; @@ -186,7 +182,7 @@ public abstract class TDiagramPanel extends JPanel implements GenericTree { protected int y2; protected Vector<Point> listPoint; protected TGConnectingPoint p1, p2; - /* protected CAMSConnectingPoint cp1, cp2;*/ + /* protected CAMSConnectingPoint cp1, cp2;*/ protected int type; // For component selection @@ -1278,7 +1274,7 @@ public abstract class TDiagramPanel extends JPanel implements GenericTree { ySel = y; for (TGComponent tgc : this.componentList) if (tgc.isSelected()) { - if ((xSel - oldX != 0) || (ySel - oldY != 0)) { + if ((xSel-oldX != 0 ) || (ySel-oldY != 0 )) { /*TraceManager.addDev("" + tgc + " is selected oldX=" + xSel + " oldY=" + oldY + " xSel=" + xSel + " ySel=" + ySel);*/ } @@ -2319,7 +2315,7 @@ public abstract class TDiagramPanel extends JPanel implements GenericTree { actionOnRemove(t); tgcon.getTGConnectingPointP1().setFree(true); tgcon.getTGConnectingPointP2().setFree(true); - + System.out.println("removing..."); TraceManager.addDev("Removed one connector!"); for (int k = 0; k < tgcon.getNbConnectingPoint(); k++) removeOneConnector(tgcon.tgconnectingPointAtIndex(k)); @@ -2599,7 +2595,7 @@ public abstract class TDiagramPanel extends JPanel implements GenericTree { || (o instanceof TMLCRecordComponent && this.checkTMLCRecordComponent((TMLCRecordComponent) o, name)) || (o instanceof TMLCCompositeComponent && this.checkTMLCCompositeComponent((TMLCCompositeComponent) o, name)) || (o instanceof TMLTaskInterface && this.checkTMLTaskInterface((TMLTaskInterface) o, name)) - || (o instanceof SysCAMSBlockTDF && this.checkSysCAMSBlockTDFComponent((SysCAMSBlockTDF) o, name)) + || (o instanceof SysCAMSBlockTDF && this.checkSysCAMSBlockTDFComponent((SysCAMSBlockTDF) o, name)) || (o instanceof SysCAMSBlockDE && this.checkSysCAMSBlockDEComponent((SysCAMSBlockDE) o, name)) || (o instanceof SysCAMSCompositeComponent && this.checkSysCAMSCompositeComponent((SysCAMSCompositeComponent) o, name)) || (o instanceof ELNComponentResistor && this.checkELNComponentResistor((ELNComponentResistor) o, name)) @@ -2607,17 +2603,11 @@ public abstract class TDiagramPanel extends JPanel implements GenericTree { || (o instanceof ELNComponentInductor && this.checkELNComponentInductor((ELNComponentInductor) o, name)) || (o instanceof ELNComponentVoltageControlledVoltageSource && this.checkELNComponentVoltageControlledVoltageSource((ELNComponentVoltageControlledVoltageSource) o, name)) || (o instanceof ELNComponentVoltageControlledCurrentSource && this.checkELNComponentVoltageControlledCurrentSource((ELNComponentVoltageControlledCurrentSource) o, name)) - || (o instanceof ELNComponentCurrentControlledVoltageSource && this.checkELNComponentCurrentControlledVoltageSource((ELNComponentCurrentControlledVoltageSource) o, name)) - || (o instanceof ELNComponentCurrentControlledCurrentSource && this.checkELNComponentCurrentControlledCurrentSource((ELNComponentCurrentControlledCurrentSource) o, name)) - || (o instanceof ELNComponentNullor && this.checkELNComponentNullor((ELNComponentNullor) o, name)) - || (o instanceof ELNComponentGyrator && this.checkELNComponentGyrator((ELNComponentGyrator) o, name)) || (o instanceof ELNComponentIdealTransformer && this.checkELNComponentIdealTransformer((ELNComponentIdealTransformer) o, name)) || (o instanceof ELNComponentTransmissionLine && this.checkELNComponentTransmissionLine ((ELNComponentTransmissionLine) o, name)) || (o instanceof ELNComponentIndependentVoltageSource && this.checkELNComponentIndependentVoltageSource((ELNComponentIndependentVoltageSource) o, name)) || (o instanceof ELNComponentIndependentCurrentSource && this.checkELNComponentIndependentCurrentSource((ELNComponentIndependentCurrentSource) o, name)) || (o instanceof ATDBlock && this.checkATDBlock((ATDBlock) o, name)) - || (o instanceof ATDAttack && this.checkATDAttack((ATDAttack) o, name)) - || (o instanceof FTDFault && this.checkFTDFault((FTDFault) o, name)) || (o instanceof AvatarBDBlock && this.checkAvatarBDBlock((AvatarBDBlock) o, name)) || (o instanceof AvatarCDBlock && this.checkAvatarCDBlock((AvatarCDBlock) o, name)) || (o instanceof AvatarSMDState && this.checkAvatarSMDState((AvatarSMDState) o, name)) @@ -2665,13 +2655,13 @@ public abstract class TDiagramPanel extends JPanel implements GenericTree { public boolean checkTMLTaskInterface(TMLTaskInterface o, String name) { return false; } - + public boolean checkSysCAMSBlockTDFComponent(SysCAMSBlockTDF o, String name) { - return false; + return false; } - + public boolean checkSysCAMSBlockDEComponent(SysCAMSBlockDE o, String name) { - return false; + return false; } public boolean checkSysCAMSCompositeComponent(SysCAMSCompositeComponent o, String name) { @@ -2698,22 +2688,6 @@ public abstract class TDiagramPanel extends JPanel implements GenericTree { return false; } - public boolean checkELNComponentCurrentControlledVoltageSource(ELNComponentCurrentControlledVoltageSource o, String name) { - return false; - } - - public boolean checkELNComponentCurrentControlledCurrentSource(ELNComponentCurrentControlledCurrentSource o, String name) { - return false; - } - - public boolean checkELNComponentNullor(ELNComponentNullor o, String name) { - return false; - } - - public boolean checkELNComponentGyrator(ELNComponentGyrator o, String name) { - return false; - } - public boolean checkELNComponentIdealTransformer(ELNComponentIdealTransformer o, String name) { return false; } @@ -2734,14 +2708,6 @@ public abstract class TDiagramPanel extends JPanel implements GenericTree { return false; } - public boolean checkATDAttack(ATDAttack o, String name) { - return false; - } - - public boolean checkFTDFault(FTDFault o, String name) { - return false; - } - public boolean checkAvatarBDBlock(AvatarBDBlock o, String name) { return false; } @@ -2861,38 +2827,22 @@ public abstract class TDiagramPanel extends JPanel implements GenericTree { } public String findSysCAMSPrimitiveComponentName(String name) { - return this.findGoodName(name, new NameChecker() { - public boolean checkSysCAMSBlockTDFComponent(SysCAMSBlockTDF o, String name) { - return o.getValue().equals(name); - } - - public boolean checkSysCAMSBlockDEComponent(SysCAMSBlockDE o, String name) { - return o.getValue().equals(name); - } - - public boolean checkSysCAMSCompositeComponent(SysCAMSCompositeComponent o, String name) { - for (int i = 0; i < o.getNbInternalTGComponent(); i++) - if (this.isNameAlreadyTaken(o.getInternalTGComponent(i), name)) - return true; - return false; - } - }); - } - - public String findAttackName(String name) { - return this.findGoodName(name, new NameChecker() { - public boolean checkATDAttack(ATDAttack o, String name) { - return o.getValue().equals(name); - } - }); - } - - public String findFaultName(String name) { - return this.findGoodName(name, new NameChecker() { - public boolean checkFTDFault(FTDFault o, String name) { - return o.getValue().equals(name); - } - }); + return this.findGoodName(name, new NameChecker() { + public boolean checkSysCAMSBlockTDFComponent(SysCAMSBlockTDF o, String name) { + return o.getValue().equals(name); + } + + public boolean checkSysCAMSBlockDEComponent(SysCAMSBlockDE o, String name) { + return o.getValue().equals(name); + } + + public boolean checkSysCAMSCompositeComponent(SysCAMSCompositeComponent o, String name) { + for (int i = 0; i < o.getNbInternalTGComponent(); i++) + if (this.isNameAlreadyTaken(o.getInternalTGComponent(i), name)) + return true; + return false; + } + }); } public String findELNComponentName(String name) { @@ -2912,18 +2862,6 @@ public abstract class TDiagramPanel extends JPanel implements GenericTree { public boolean checkELNComponentVoltageControlledCurrentSource(ELNComponentVoltageControlledCurrentSource o, String name) { return o.getValue().equals(name); } - public boolean checkELNComponentCurrentControlledVoltageSource(ELNComponentCurrentControlledVoltageSource o, String name) { - return o.getValue().equals(name); - } - public boolean checkELNComponentCurrentControlledCurrentSource(ELNComponentCurrentControlledCurrentSource o, String name) { - return o.getValue().equals(name); - } - public boolean checkELNComponentNullor(ELNComponentNullor o, String name) { - return o.getValue().equals(name); - } - public boolean checkELNComponentGyrator(ELNComponentGyrator o, String name) { - return o.getValue().equals(name); - } public boolean checkELNComponentIdealTransformer(ELNComponentIdealTransformer o, String name) { return o.getValue().equals(name); } @@ -3676,53 +3614,6 @@ public abstract class TDiagramPanel extends JPanel implements GenericTree { h = Math.min(h, getHeight() - y); - /*StringBuffer sb = new StringBuffer("<?xml version=\"1.0\" standalone=\"no\"?>\n"); - sb.append("<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n"); - //sb.append(" width=\"" + (w+x) + "\" height=\"" + (h+y) + "\" viewbox=\"" + x + " " + y + " " + w + " " + h + "\">\n"); - sb.append("<svg xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\""); - sb.append(" width=\"" + (w + x) + "\" height=\"" + (h + y) + "\" viewbox=\"" + x + " " + y + " " + w + " " + h + "\">\n"); - - // Issue #14 point 10: Somehow the last graphics that was used is different than the actual one leading - // to an error in calculating string lengths - final SVGGraphics svgg = new SVGGraphics((Graphics2D) getGraphics()); -// SVGGraphics svgg = new SVGGraphics((Graphics2D)lastGraphics); - - RepaintManager.currentManager(this).setDoubleBufferingEnabled(false); - //this.paint(svgg); - //TraceManager.addDev("Painting for svg"); - basicPaintMyComponents(svgg); - //TraceManager.addDev("Painting for svg done"); - sb.append(svgg.getSVGString()); - RepaintManager.currentManager(this).setDoubleBufferingEnabled(true); - - sb.append("</svg>"); - - return sb.toString();*/ - - SVGGeneration gen = new SVGGeneration(); - return gen.getSVGString(this); - } - - public String oldSvgCapture() { - int w = this.getWidth(); - int h = this.getHeight(); - int x = getRealMinX(); - int y = getRealMinY(); - w = getRealMaxX() - x; - h = getRealMaxY() - y; - //TraceManager.addDev("x=" + x + " y=" + y + " w=" + w + " h=" + h + " getWidth = " + this.getWidth() + " getHeight = " + this.getHeight()); - x = x - 5; - y = y - 5; - w = w + 10; - h = h + 10; - w = Math.max(0, w); - h = Math.max(0, h); - x = Math.max(5, x); - y = Math.max(5, y); - w = Math.min(w, getWidth() - x); - h = Math.min(h, getHeight() - y); - - StringBuffer sb = new StringBuffer("<?xml version=\"1.0\" standalone=\"no\"?>\n"); sb.append("<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n"); //sb.append(" width=\"" + (w+x) + "\" height=\"" + (h+y) + "\" viewbox=\"" + x + " " + y + " " + w + " " + h + "\">\n"); @@ -3860,3 +3751,4 @@ public abstract class TDiagramPanel extends JPanel implements GenericTree { } } + diff --git a/src/main/java/ui/TGComponentManager.java b/src/main/java/ui/TGComponentManager.java index 828cd3a8ed99294289948a8bfb69be9b564becae..c810534b30b9238f3ab7c5b56c76de6488ef705b 100644 --- a/src/main/java/ui/TGComponentManager.java +++ b/src/main/java/ui/TGComponentManager.java @@ -351,14 +351,10 @@ public class TGComponentManager { public static final int ELN_INDUCTOR = 1613; public static final int ELN_VOLTAGE_CONTROLLED_VOLTAGE_SOURCE = 1614; public static final int ELN_VOLTAGE_CONTROLLED_CURRENT_SOURCE = 1615; - public static final int ELN_CURRENT_CONTROLLED_VOLTAGE_SOURCE = 1616; - public static final int ELN_CURRENT_CONTROLLED_CURRENT_SOURCE = 1617; - public static final int ELN_NULLOR = 1618; - public static final int ELN_GYRATOR = 1619; - public static final int ELN_IDEAL_TRANSFORMER = 1620; - public static final int ELN_TRANSMISSION_LINE = 1621; - public static final int ELN_INDEPENDENT_VOLTAGE_SOURCE = 1622; - public static final int ELN_INDEPENDENT_CURRENT_SOURCE = 1623; + public static final int ELN_IDEAL_TRANSFORMER = 1616; + public static final int ELN_TRANSMISSION_LINE = 1617; + public static final int ELN_INDEPENDENT_VOLTAGE_SOURCE = 1618; + public static final int ELN_INDEPENDENT_CURRENT_SOURCE = 1619; // SMD diagram public static final int PROSMD_START_STATE = 2000; @@ -1289,18 +1285,6 @@ public class TGComponentManager { case ELN_VOLTAGE_CONTROLLED_CURRENT_SOURCE: tgc = new ELNComponentVoltageControlledCurrentSource(x, y, tdp.getMinX(), tdp.getMaxX(), tdp.getMinY(), tdp.getMaxY(), false, null, tdp); break; - case ELN_CURRENT_CONTROLLED_VOLTAGE_SOURCE: - tgc = new ELNComponentCurrentControlledVoltageSource(x, y, tdp.getMinX(), tdp.getMaxX(), tdp.getMinY(), tdp.getMaxY(), false, null, tdp); - break; - case ELN_CURRENT_CONTROLLED_CURRENT_SOURCE: - tgc = new ELNComponentCurrentControlledCurrentSource(x, y, tdp.getMinX(), tdp.getMaxX(), tdp.getMinY(), tdp.getMaxY(), false, null, tdp); - break; - case ELN_NULLOR: - tgc = new ELNComponentNullor(x, y, tdp.getMinX(), tdp.getMaxX(), tdp.getMinY(), tdp.getMaxY(), false, null, tdp); - break; - case ELN_GYRATOR: - tgc = new ELNComponentGyrator(x, y, tdp.getMinX(), tdp.getMaxX(), tdp.getMinY(), tdp.getMaxY(), false, null, tdp); - break; case ELN_IDEAL_TRANSFORMER: tgc = new ELNComponentIdealTransformer(x, y, tdp.getMinX(), tdp.getMaxX(), tdp.getMinY(), tdp.getMaxY(), false, null, tdp); break; @@ -1721,14 +1705,6 @@ public class TGComponentManager { return ELN_VOLTAGE_CONTROLLED_VOLTAGE_SOURCE; } else if (tgc instanceof ELNComponentInductor) { return ELN_VOLTAGE_CONTROLLED_CURRENT_SOURCE; - } else if (tgc instanceof ELNComponentInductor) { - return ELN_CURRENT_CONTROLLED_VOLTAGE_SOURCE; - } else if (tgc instanceof ELNComponentInductor) { - return ELN_CURRENT_CONTROLLED_CURRENT_SOURCE; - } else if (tgc instanceof ELNComponentNullor) { - return ELN_NULLOR; - } else if (tgc instanceof ELNComponentGyrator) { - return ELN_GYRATOR; } else if (tgc instanceof ELNComponentIdealTransformer) { return ELN_IDEAL_TRANSFORMER; } else if (tgc instanceof ELNComponentTransmissionLine) { @@ -2331,31 +2307,31 @@ public class TGComponentManager { break; case CONNECTOR_INTERACTION: tgc = new TGConnectorInteraction(x, y, tdp.getMinX(), tdp.getMaxX(), tdp.getMinY(), tdp.getMaxY(), false, null, tdp, p1, p2, listPoint); - //TraceManager.addDev("Connector interaction"); + //System.out.println("Connector interaction"); break; case CONNECTOR_MESSAGE_ASYNC_SD: tgc = new ui.sd.TGConnectorMessageAsyncSD(x, y, tdp.getMinX(), tdp.getMaxX(), tdp.getMinY(), tdp.getMaxY(), false, null, tdp, p1, p2, listPoint); - //TraceManager.addDev("Connector interaction"); + //System.out.println("Connector interaction"); break; case CONNECTOR_MESSAGE_SYNC_SD: tgc = new ui.sd.TGConnectorMessageSyncSD(x, y, tdp.getMinX(), tdp.getMaxX(), tdp.getMinY(), tdp.getMaxY(), false, null, tdp, p1, p2, listPoint); - //TraceManager.addDev("Connector interaction"); + //System.out.println("Connector interaction"); break; case CONNECTOR_RELATIVE_TIME_SD: tgc = new ui.sd.TGConnectorRelativeTimeSD(x, y, tdp.getMinX(), tdp.getMaxX(), tdp.getMinY(), tdp.getMaxY(), false, null, tdp, p1, p2, listPoint); - //TraceManager.addDev("Connector interaction"); + //System.out.println("Connector interaction"); break; case CONNECTOR_MESSAGE_ASYNC_SDZV: tgc = new ui.sd2.TGConnectorMessageAsyncSD(x, y, tdp.getMinX(), tdp.getMaxX(), tdp.getMinY(), tdp.getMaxY(), false, null, tdp, p1, p2, listPoint); - //TraceManager.addDev("Connector interaction"); + //System.out.println("Connector interaction"); break; case CONNECTOR_MESSAGE_SYNC_SDZV: tgc = new ui.sd2.TGConnectorMessageSyncSD(x, y, tdp.getMinX(), tdp.getMaxX(), tdp.getMinY(), tdp.getMaxY(), false, null, tdp, p1, p2, listPoint); - //TraceManager.addDev("Connector interaction"); + //System.out.println("Connector interaction"); break; case CONNECTOR_RELATIVE_TIME_SDZV: tgc = new ui.sd2.TGConnectorRelativeTimeSD(x, y, tdp.getMinX(), tdp.getMaxX(), tdp.getMinY(), tdp.getMaxY(), false, null, tdp, p1, p2, listPoint); - //TraceManager.addDev("Connector interaction"); + //System.out.println("Connector interaction"); break; case CONNECTOR_ACTOR_UCD: @@ -2489,3 +2465,4 @@ public class TGComponentManager { }*/ } // Class + diff --git a/src/main/java/ui/TGUIAction.java b/src/main/java/ui/TGUIAction.java index 3c338061363e4a6f185531158debdcde29ada6b9..e4d6fa2f6020d62937166800af15e5cffa58db38 100644 --- a/src/main/java/ui/TGUIAction.java +++ b/src/main/java/ui/TGUIAction.java @@ -293,14 +293,10 @@ public class TGUIAction extends AbstractAction { public static final int ELN_INDUCTOR = 486; public static final int ELN_VOLTAGE_CONTROLLED_VOLTAGE_SOURCE = 487; public static final int ELN_VOLTAGE_CONTROLLED_CURRENT_SOURCE = 488; - public static final int ELN_CURRENT_CONTROLLED_VOLTAGE_SOURCE = 489; - public static final int ELN_CURRENT_CONTROLLED_CURRENT_SOURCE = 490; - public static final int ELN_NULLOR = 491; - public static final int ELN_GYRATOR = 492; - public static final int ELN_IDEAL_TRANSFORMER = 493; - public static final int ELN_TRANSMISSION_LINE = 494; - public static final int ELN_INDEPENDENT_VOLTAGE_SOURCE = 495; - public static final int ELN_INDEPENDENT_CURRENT_SOURCE = 496; + public static final int ELN_IDEAL_TRANSFORMER = 489; + public static final int ELN_TRANSMISSION_LINE = 490; + public static final int ELN_INDEPENDENT_VOLTAGE_SOURCE = 491; + public static final int ELN_INDEPENDENT_CURRENT_SOURCE = 492; public static final int EBRDD_EDIT = 271; public static final int EBRDD_CONNECTOR = 272; @@ -655,7 +651,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 = 498; + public static final int NB_ACTION = 493; private static final TAction [] actions = new TAction[NB_ACTION]; @@ -1131,14 +1127,10 @@ public class TGUIAction extends AbstractAction { actions[ELN_INDUCTOR] = new TAction("eln-inductor", "Add a inductor", IconManager.imgic8012, IconManager.imgic8012, "Self", "Add a inductor to the currently opened ELN Diagram", 0); actions[ELN_VOLTAGE_CONTROLLED_VOLTAGE_SOURCE] = new TAction("eln-VCVS", "Add a voltage controlled voltage source", IconManager.imgic8013, IconManager.imgic8013, "Voltage controlled voltage source", "Add a voltage controlled voltage source to the currently opened ELN Diagram", 0); actions[ELN_VOLTAGE_CONTROLLED_CURRENT_SOURCE] = new TAction("eln-VCCS", "Add a voltage controlled current source", IconManager.imgic8014, IconManager.imgic8014, "Voltage controlled current source", "Add a voltage controlled current source to the currently opened ELN Diagram", 0); - actions[ELN_CURRENT_CONTROLLED_VOLTAGE_SOURCE] = new TAction("eln-CCVS", "Add a current controlled voltage source", IconManager.imgic8015, IconManager.imgic8015, "Current controlled voltage source", "Add a current controlled voltage source to the currently opened ELN Diagram", 0); - actions[ELN_CURRENT_CONTROLLED_CURRENT_SOURCE] = new TAction("eln-CCCS", "Add a current controlled current source", IconManager.imgic8016, IconManager.imgic8016, "Current controlled current source", "Add a current controlled current source to the currently opened ELN Diagram", 0); - actions[ELN_NULLOR] = new TAction("eln-nullor", "Add a nullor", IconManager.imgic8017, IconManager.imgic8017, "Nullor", "Add a nullor to the currently opened ELN Diagram", 0); - actions[ELN_GYRATOR] = new TAction("eln-gyrator", "Add a gyrator", IconManager.imgic8018, IconManager.imgic8018, "Gyrator", "Add a gyrator to the currently opened ELN Diagram", 0); - actions[ELN_IDEAL_TRANSFORMER] = new TAction("eln-ideal-transformer", "Add a ideal transformer", IconManager.imgic8019, IconManager.imgic8019, "Ideal transformer", "Add a ideal transformer to the currently opened ELN Diagram", 0); - actions[ELN_TRANSMISSION_LINE] = new TAction("eln-transmission-line", "Add a transmission line", IconManager.imgic8020, IconManager.imgic8020, "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.imgic8021, IconManager.imgic8021, "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.imgic8022, IconManager.imgic8022, "Independent current source", "Add a independent current source to the currently opened ELN Diagram", 0); + actions[ELN_IDEAL_TRANSFORMER] = new TAction("eln-ideal-transformer", "Add a ideal transformer", IconManager.imgic8015, IconManager.imgic8015, "Ideal transformer", "Add a ideal transformer to the currently opened ELN Diagram", 0); + 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); //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); @@ -1332,7 +1324,7 @@ public class TGUIAction extends AbstractAction { } public void actionPerformed(ActionEvent evt) { - // + //System.out.println("Action performed"); if (listeners != null) { Object[] listenerList = listeners.getListenerList(); @@ -1361,3 +1353,4 @@ public class TGUIAction extends AbstractAction { } } + diff --git a/src/main/java/ui/eln/ELNDiagramToolBar.java b/src/main/java/ui/eln/ELNDiagramToolBar.java index 0ad8c5cabf53ad26ca65c41e6b4367c7165e991a..3316775d3e99369c7d5a67286ba49b9a42349bd0 100644 --- a/src/main/java/ui/eln/ELNDiagramToolBar.java +++ b/src/main/java/ui/eln/ELNDiagramToolBar.java @@ -72,10 +72,6 @@ public class ELNDiagramToolBar extends TToolBar { mgui.actions[TGUIAction.ELN_INDUCTOR].setEnabled(b); mgui.actions[TGUIAction.ELN_VOLTAGE_CONTROLLED_VOLTAGE_SOURCE].setEnabled(b); mgui.actions[TGUIAction.ELN_VOLTAGE_CONTROLLED_CURRENT_SOURCE].setEnabled(b); - mgui.actions[TGUIAction.ELN_CURRENT_CONTROLLED_VOLTAGE_SOURCE].setEnabled(b); - mgui.actions[TGUIAction.ELN_CURRENT_CONTROLLED_CURRENT_SOURCE].setEnabled(b); - mgui.actions[TGUIAction.ELN_NULLOR].setEnabled(b); - mgui.actions[TGUIAction.ELN_GYRATOR].setEnabled(b); mgui.actions[TGUIAction.ELN_IDEAL_TRANSFORMER].setEnabled(b); mgui.actions[TGUIAction.ELN_TRANSMISSION_LINE].setEnabled(b); mgui.actions[TGUIAction.ELN_INDEPENDENT_VOLTAGE_SOURCE].setEnabled(b); @@ -115,18 +111,6 @@ public class ELNDiagramToolBar extends TToolBar { button = this.add(mgui.actions[TGUIAction.ELN_VOLTAGE_CONTROLLED_CURRENT_SOURCE]); button.addMouseListener(mgui.mouseHandler); - button = this.add(mgui.actions[TGUIAction.ELN_CURRENT_CONTROLLED_VOLTAGE_SOURCE]); - button.addMouseListener(mgui.mouseHandler); - - button = this.add(mgui.actions[TGUIAction.ELN_CURRENT_CONTROLLED_CURRENT_SOURCE]); - button.addMouseListener(mgui.mouseHandler); - - button = this.add(mgui.actions[TGUIAction.ELN_NULLOR]); - button.addMouseListener(mgui.mouseHandler); - - button = this.add(mgui.actions[TGUIAction.ELN_GYRATOR]); - button.addMouseListener(mgui.mouseHandler); - button = this.add(mgui.actions[TGUIAction.ELN_IDEAL_TRANSFORMER]); button.addMouseListener(mgui.mouseHandler); @@ -139,4 +123,4 @@ public class ELNDiagramToolBar extends TToolBar { button = this.add(mgui.actions[TGUIAction.ELN_INDEPENDENT_CURRENT_SOURCE]); button.addMouseListener(mgui.mouseHandler); } -} \ No newline at end of file +} diff --git a/src/main/java/ui/eln/sca_eln/ELNComponentCapacitor.java b/src/main/java/ui/eln/sca_eln/ELNComponentCapacitor.java index 9a1a8180f890bb734372c9946e9a34d2d75ad3f7..0723f2df3fa140c2bad27404ada63f19e3e58519 100644 --- a/src/main/java/ui/eln/sca_eln/ELNComponentCapacitor.java +++ b/src/main/java/ui/eln/sca_eln/ELNComponentCapacitor.java @@ -45,289 +45,431 @@ import org.w3c.dom.Node; import org.w3c.dom.NodeList; import ui.*; import ui.eln.ELNConnectingPoint; -import ui.util.IconManager; import ui.window.JDialogELNComponentCapacitor; import javax.swing.*; import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; /** - * Class ELNComponentCapacitor - * Capacitor to be used in ELN diagrams + * Class ELNComponentCapacitor + * Capacitor to be used in ELN diagrams * Creation: 12/06/2018 * @version 1.0 12/06/2018 * @author Irina Kit Yan LEE */ -public class ELNComponentCapacitor extends TGCScalableWithInternalComponent { - protected Color myColor; - protected int orientation; +public class ELNComponentCapacitor extends TGCScalableWithInternalComponent implements ActionListener { + protected Color myColor; + protected int orientation; private int maxFontSize = 14; - private int minFontSize = 4; - private int currentFontSize = -1; -// protected int oldx, oldy; -// protected int currentOrientation = GraphicLib.NORTH; - - private int textX = 15; // border for ports - private double dtextX = 0.0; - protected int decPoint = 3; - - private int fact = 2; - - // Parameters - private double val; - private double q0; + private int minFontSize = 4; + private int currentFontSize = -1; + + private int textX = 15; + private double dtextX = 0.0; + protected int decPoint = 3; + + private double val, q0; private String unit0, unit1; - - public ELNComponentCapacitor(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(50*fact, 20*fact); - - 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("C"); - - myImageIcon = IconManager.imgic1206; - - // Initialization of self attributes - setVal(1.0); - setQ0(0.0); - setUnit0("F"); - setUnit1("C"); - } - - public void initConnectingPoint(int nb) { - nbConnectingPoint = nb; - connectingPoint = new TGConnectingPoint[nb]; - connectingPoint[0] = new ELNConnectingPoint(this, 0, 0, true, true, 0.0, 0.5); - connectingPoint[1] = new ELNConnectingPoint(this, 0, 0, true, true, 1.0, 0.5); - } - - public Color getMyColor() { - return myColor; - } - - public void internalDrawing(Graphics g) { - Font f = g.getFont(); - Font fold = f; - -// if ((x != oldx) | (oldy != y)) { -// // Component has moved! -// manageMove(); -// oldx = x; -// oldy = y; -// } - - if (this.rescaled && !this.tdp.isScaled()) { - this.rescaled = false; - // Must set the font size... - // Incrementally find the biggest font not greater than max_font size - // If font is less than min_font, no text is displayed - - 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); - } - - // Zoom is assumed to be computed - Color c = g.getColor(); - int [] ptx0 = {x, x+width/3, x+width/3, x+width/3, x+width/3}; - int [] pty0 = {y+height/2, y+height/2, y, y+height, y+height/2}; - g.drawPolygon(ptx0, pty0, 5); - int [] ptx1 = {x+width, x+2*width/3, x+2*width/3, x+2*width/3, x+2*width/3}; - int [] pty1 = {y+height/2, y+height/2, y, y+height, y+height/2}; - g.drawPolygon(ptx1, pty1, 5); - g.setColor(c); - - // Set font size - int attributeFontSize = this.currentFontSize * 5 / 6; - 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/(2*fact)); - - g.setFont(fold); - } - -// public void manageMove() { -// if (father != null) { -// Point p = GraphicLib.putPointOnRectangle(x+(width/2), y+(height/2), father.getX(), father.getY(), father.getWidth(), father.getHeight()); -// -// x = p.x - width/2; -// y = p.y - height/2; -// -// setMoveCd(x, y); -// -// int orientation = GraphicLib.getCloserOrientation(x+(width/2), y+(height/2), father.getX(), father.getY(), father.getWidth(), father.getHeight()); -// if (orientation != currentOrientation) { -//// setOrientation(orientation); -// } -// } -// } - - // TGConnecting points .. - // TODO : change the orientation of the component -// public void setOrientation(int orientation) { -// currentOrientation = orientation; -// double w0, h0, w1, h1; -// -//// switch(orientation) { -////// case GraphicLib.NORTH: -////// w0 = 0.5; -////// h0 = 0.0; -////// break; -//// case GraphicLib.WEST: -//// w0 = 0.0; -//// h0 = 0.5; -//// break; -////// case GraphicLib.SOUTH: -////// w0 = 0.5; -////// h0 = 1.0; -////// break; -//// case GraphicLib.EAST: -//// default: -//// w0 = 1.0; -//// h0 = 0.5; -//// } -// -// w0 = 0.0; -// h0 = 0.5; -// w1 = 1.0; -// h1 = 0.5; -// System.out.println(connectingPoint.length); -// ((ELNConnectingPoint) connectingPoint[0]).setW(w0); -// ((ELNConnectingPoint) connectingPoint[0]).setH(h0); -// ((ELNConnectingPoint) connectingPoint[1]).setW(w1); -// ((ELNConnectingPoint) connectingPoint[1]).setH(h1); -// } - - 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_CAPACITOR; - } - - public boolean editOndoubleClick(JFrame frame) { - JDialogELNComponentCapacitor jde = new JDialogELNComponentCapacitor(this); - jde.setVisible(true); - return true; - } - - public StringBuffer encode(String data) { - StringBuffer databuf = new StringBuffer(data); - StringBuffer buffer = new StringBuffer(""); - for(int pos = 0; pos != data.length(); pos++) { - char c = databuf.charAt(pos); - switch(c) { - case '\u03BC' : - buffer.append("μ"); - break; - default : - buffer.append(databuf.charAt(pos)); - break; - } - } - return buffer; - } - - protected String translateExtraParam() { - StringBuffer sb = new StringBuffer("<extraparam>\n"); - sb.append("<attributes value=\"" + val); - sb.append("\" unit0=\""); - sb.append(encode(unit0)); - sb.append("\" q0=\"" + q0); - sb.append("\" unit1=\""); - sb.append(encode(unit1)); - sb.append("\""); - 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 value, q0; - String unit0, unit1; - - 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")) { - value = Double.parseDouble(elt.getAttribute("value")); - q0 = Double.parseDouble(elt.getAttribute("q0")); + + private int position = 0; + private boolean fv = false, fh = false; + private int old; + private boolean first; + + public ELNComponentCapacitor(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(100, 40); + + 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("C"); + + setVal(1.0); + setQ0(0.0); + setUnit0("F"); + setUnit1("C"); + + 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.5, "p"); + connectingPoint[1] = new ELNConnectingPoint(this, 0, 0, true, true, 1.0, 0.5, "n"); + } + + public Color getMyColor() { + return myColor; + } + + public void internalDrawing(Graphics g) { + 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(); + double w0 = ((ELNConnectingPoint) connectingPoint[0]).getW(); + double h0 = ((ELNConnectingPoint) connectingPoint[0]).getH(); + double w1 = ((ELNConnectingPoint) connectingPoint[1]).getW(); + double h1 = ((ELNConnectingPoint) connectingPoint[1]).getH(); + + if (position == 0) { + if (first == false) { + first = true; + old = width; + width = height; + height = old; + } + + rotateTopBottom(g); + + ((ELNConnectingPoint) connectingPoint[0]).setW(w0); + ((ELNConnectingPoint) connectingPoint[0]).setH(h0); + ((ELNConnectingPoint) connectingPoint[1]).setW(w1); + ((ELNConnectingPoint) connectingPoint[1]).setH(h1); + + 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 / 2); + g.setFont(f.deriveFont(Font.PLAIN)); + + if (fh == true) { + g.drawString(((ELNConnectingPoint) connectingPoint[1]).getName(), x - sw1, + y + height / 2 + height / 4 + sh1); + g.drawString(((ELNConnectingPoint) connectingPoint[0]).getName(), x + width, + y + height / 2 + height / 4 + sh0); + } else { + g.drawString(((ELNConnectingPoint) connectingPoint[0]).getName(), x - sw0, + y + height / 2 + height / 4 + sh0); + g.drawString(((ELNConnectingPoint) connectingPoint[1]).getName(), x + width, + y + height / 2 + height / 4 + sh1); + } + } else if (position == 1) { + if (first == false) { + first = true; + old = width; + width = height; + height = old; + } + + rotateRightLeft(g); + + ((ELNConnectingPoint) connectingPoint[0]).setW(h0); + ((ELNConnectingPoint) connectingPoint[0]).setH(w0); + ((ELNConnectingPoint) connectingPoint[1]).setW(h1); + ((ELNConnectingPoint) connectingPoint[1]).setH(w1); + + int attributeFontSize = this.currentFontSize * 5 / 6; + int sh0 = g.getFontMetrics().getAscent(); + 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 / 5); + g.setFont(f.deriveFont(Font.PLAIN)); + + if (fv == true) { + g.drawString(((ELNConnectingPoint) connectingPoint[1]).getName(), x + width / 2 + width / 4, y); + g.drawString(((ELNConnectingPoint) connectingPoint[0]).getName(), x + width / 2 + width / 4, + y + height + sh0); + } else { + g.drawString(((ELNConnectingPoint) connectingPoint[0]).getName(), x + width / 2 + width / 4, y); + g.drawString(((ELNConnectingPoint) connectingPoint[1]).getName(), x + width / 2 + width / 4, + y + height + sh1); + } + } else if (position == 2) { + if (first == false) { + first = true; + old = width; + width = height; + height = old; + } + + rotateTopBottom(g); + + ((ELNConnectingPoint) connectingPoint[0]).setW(w0); + ((ELNConnectingPoint) connectingPoint[0]).setH(h0); + ((ELNConnectingPoint) connectingPoint[1]).setW(w1); + ((ELNConnectingPoint) connectingPoint[1]).setH(h1); + + 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 / 2); + g.setFont(f.deriveFont(Font.PLAIN)); + + if (fh == true) { + g.drawString(((ELNConnectingPoint) connectingPoint[0]).getName(), x - sw1, + y + height / 2 + height / 4 + sh1); + g.drawString(((ELNConnectingPoint) connectingPoint[1]).getName(), x + width, + y + height / 2 + height / 4 + sh0); + } else { + g.drawString(((ELNConnectingPoint) connectingPoint[1]).getName(), x - sw0, + y + height / 2 + height / 4 + sh0); + g.drawString(((ELNConnectingPoint) connectingPoint[0]).getName(), x + width, + y + height / 2 + height / 4 + sh1); + } + } else if (position == 3) { + if (first == false) { + first = true; + old = width; + width = height; + height = old; + } + + rotateRightLeft(g); + + ((ELNConnectingPoint) connectingPoint[0]).setW(h0); + ((ELNConnectingPoint) connectingPoint[0]).setH(w0); + ((ELNConnectingPoint) connectingPoint[1]).setW(h1); + ((ELNConnectingPoint) connectingPoint[1]).setH(w1); + + int attributeFontSize = this.currentFontSize * 5 / 6; + int sh0 = g.getFontMetrics().getAscent(); + 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 / 5); + g.setFont(f.deriveFont(Font.PLAIN)); + + if (fv == true) { + g.drawString(((ELNConnectingPoint) connectingPoint[0]).getName(), x + width / 2 + width / 4, y); + g.drawString(((ELNConnectingPoint) connectingPoint[1]).getName(), x + width / 2 + width / 4, + y + height + sh0); + } else { + g.drawString(((ELNConnectingPoint) connectingPoint[1]).getName(), x + width / 2 + width / 4, y); + g.drawString(((ELNConnectingPoint) connectingPoint[0]).getName(), x + width / 2 + width / 4, + y + height + sh1); + } + } + g.setColor(c); + g.setFont(fold); + } + + private void rotateTopBottom(Graphics g) { + int[] ptx0 = { x, x + 2 * width / 5, x + 2 * width / 5, x + 2 * width / 5, x + 2 * width / 5 }; + int[] pty0 = { y + height / 2, y + height / 2, y, y + height, y + height / 2 }; + g.drawPolygon(ptx0, pty0, 5); + int[] ptx1 = { x + width, x + 3 * width / 5, x + 3 * width / 5, x + 3 * width / 5, x + 3 * width / 5 }; + int[] pty1 = { y + height / 2, y + height / 2, y, y + height, y + height / 2 }; + g.drawPolygon(ptx1, pty1, 5); + } + + private void rotateRightLeft(Graphics g) { + int[] ptx0 = { x + width / 2, x + width / 2, x, x + width, x + width / 2 }; + int[] pty0 = { y, y + 2 * height / 5, y + 2 * height / 5, y + 2 * height / 5, y + 2 * height / 5 }; + g.drawPolygon(ptx0, pty0, 5); + int[] ptx1 = { x + width / 2, x + width / 2, x, x + width, x + width / 2 }; + int[] pty1 = { y + height, y + 3 * height / 5, y + 3 * height / 5, y + 3 * height / 5, y + 3 * height / 5 }; + g.drawPolygon(ptx1, pty1, 5); + } + + 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_CAPACITOR; + } + + public boolean editOndoubleClick(JFrame frame) { + JDialogELNComponentCapacitor jde = new JDialogELNComponentCapacitor(this); + jde.setVisible(true); + return true; + } + + public StringBuffer encode(String data) { + StringBuffer databuf = new StringBuffer(data); + StringBuffer buffer = new StringBuffer(""); + for (int pos = 0; pos != data.length(); pos++) { + char c = databuf.charAt(pos); + switch (c) { + case '\u03BC': + buffer.append("μ"); + break; + default: + buffer.append(databuf.charAt(pos)); + break; + } + } + return buffer; + } + + protected String translateExtraParam() { + StringBuffer sb = new StringBuffer("<extraparam>\n"); + sb.append("<attributes value=\"" + val); + sb.append("\" unit0=\""); + sb.append(encode(unit0)); + sb.append("\" q0=\"" + q0); + sb.append("\" unit1=\""); + sb.append(encode(unit1)); + sb.append("\""); + 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 value, q0; + String unit0, unit1; + + 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")) { + value = Double.parseDouble(elt.getAttribute("value")); + q0 = Double.parseDouble(elt.getAttribute("q0")); unit0 = elt.getAttribute("unit0"); unit1 = elt.getAttribute("unit1"); setVal(value); setQ0(q0); setUnit0(unit0); setUnit1(unit1); - } - } - } - } - } - } catch (Exception e) { - throw new MalformedModelingException(); - } - } - - public int getDefaultConnector() { - return TGComponentManager.ELN_CONNECTOR; - } - - public double getVal() { + } + } + } + } + } + } 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) { + fv = false; + fh = false; + 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 (fv == false) { + fv = true; + } else { + fv = false; + } + } + if (e.getActionCommand().equals("Flip horizontally")) { + if (fh == false) { + fh = true; + } else { + fh = false; + } + } + } + + public int getDefaultConnector() { + return TGComponentManager.ELN_CONNECTOR; + } + + public double getVal() { return val; } public void setVal(double _val) { val = _val; } - + public double getQ0() { return q0; } @@ -343,12 +485,12 @@ public class ELNComponentCapacitor extends TGCScalableWithInternalComponent { public void setUnit0(String _unit0) { unit0 = _unit0; } - + public String getUnit1() { return unit1; } - + public void setUnit1(String _unit1) { unit1 = _unit1; } -} \ No newline at end of file +} diff --git a/src/main/java/ui/eln/sca_eln/ELNComponentCurrentControlledCurrentSource.java b/src/main/java/ui/eln/sca_eln/ELNComponentCurrentControlledCurrentSource.java deleted file mode 100644 index fe2f6ff9c35fe1f784f7781cb94c520bda860b18..0000000000000000000000000000000000000000 --- a/src/main/java/ui/eln/sca_eln/ELNComponentCurrentControlledCurrentSource.java +++ /dev/null @@ -1,305 +0,0 @@ -/* 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; - -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.util.IconManager; -import ui.window.JDialogELNComponentCurrentControlledCurrentSource; - -import javax.swing.*; -import java.awt.*; - -/** - * Class ELNComponentCurrentControlledCurrentSource - * Current controlled current source to be used in ELN diagrams - * Creation: 13/06/2018 - * @version 1.0 13/06/2018 - * @author Irina Kit Yan LEE - */ - -public class ELNComponentCurrentControlledCurrentSource extends TGCScalableWithInternalComponent { - protected Color myColor; - protected int orientation; - private int maxFontSize = 14; - private int minFontSize = 4; - private int currentFontSize = -1; -// protected int oldx, oldy; -// protected int currentOrientation = GraphicLib.NORTH; - - private int textX = 15; // border for ports - private double dtextX = 0.0; - protected int decPoint = 3; - - private int fact = 2; - - // Parameter - private double val; - - public ELNComponentCurrentControlledCurrentSource(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(60*fact, 40*fact); - - dtextX = textX * oldScaleFactor; - textX = (int)dtextX; - dtextX = dtextX - textX; - - minWidth = 1; - minHeight = 1; - - initConnectingPoint(4); - - addTGConnectingPointsComment(); - - moveable = true; - editable = true; - removable = true; - userResizable = false; - value = tdp.findELNComponentName("CCCS"); - - myImageIcon = IconManager.imgic1206; - - // Initialization of cccs attributes - setVal(1.0); - } - - public void initConnectingPoint(int nb) { - nbConnectingPoint = nb; - connectingPoint = new TGConnectingPoint[nb]; - connectingPoint[0] = new ELNConnectingPoint(this, 0, 0, true, true, 0.0, 0.0); - connectingPoint[1] = new ELNConnectingPoint(this, 0, 0, true, true, 1.0, 0.0); - connectingPoint[2] = new ELNConnectingPoint(this, 0, 0, true, true, 0.0, 1.0); - connectingPoint[3] = new ELNConnectingPoint(this, 0, 0, true, true, 1.0, 1.0); - } - - public Color getMyColor() { - return myColor; - } - - public void internalDrawing(Graphics g) { - Font f = g.getFont(); - Font fold = f; - -// if ((x != oldx) | (oldy != y)) { -// // Component has moved! -// manageMove(); -// oldx = x; -// oldy = y; -// } - - if (this.rescaled && !this.tdp.isScaled()) { - this.rescaled = false; - // Must set the font size... - // Incrementally find the biggest font not greater than max_font size - // If font is less than min_font, no text is displayed - - 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); - } - - // Zoom is assumed to be computed - Color c = g.getColor(); - int [] ptx0 = {x, x+2*width/6, x+2*width/6, x, x+2*width/6, x+2*width/6}; - int [] pty0 = {y, y, y+height, y+height, y+height, y}; - g.drawPolygon(ptx0, pty0, 6); - int [] ptx1 = {x+2*width/6-width/(12*fact), x+2*width/6+width/(12*fact), x+2*width/6}; - int [] pty1 = {y+height/2-height/(8*fact), y+height/2-height/(8*fact), y+height/2+height/(8*fact)}; - g.drawPolygon(ptx1, pty1, 3); - g.fillPolygon(ptx1, pty1, 3); - int [] ptx2 = {x+width, x+4*width/6, x+4*width/6, x+3*width/6, x+4*width/6, x+4*width/6, x+width, x+4*width/6, x+4*width/6, x+5*width/6, x+3*width/6, x+5*width/6, x+4*width/6, x+4*width/6}; - int [] pty2 = {y, y, y+height/4, y+2*height/4, y+3*height/4, y+height, y+height, y+height, y+3*height/4, y+2*height/4, y+2*height/4, y+2*height/4, y+height/4, y}; - g.drawPolygon(ptx2, pty2, 14); - int [] ptx3 = {x+5*width/6+width/(6*fact)+width/(12*fact), x+5*width/6+width/(6*fact)+width/(12*fact), x+5*width/6+width/(6*fact), x+5*width/6+width/(6*fact)+width/(12*fact), x+5*width/6+width/(3*fact), x+5*width/6+width/(6*fact)+width/(12*fact)}; - int [] pty3 = {y+height/4, y+3*height/4-height/(4*fact), y+3*height/4-height/(4*fact), y+3*height/4, y+3*height/4-height/(4*fact), y+3*height/4-height/(4*fact)}; - g.drawPolygon(ptx3, pty3, 6); - g.fillPolygon(ptx3, pty3, 6); - g.setColor(c); - - // Set font size - int attributeFontSize = this.currentFontSize * 5 / 6; - 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*fact)); - - g.setFont(fold); - } - -// public void manageMove() { -// if (father != null) { -// Point p = GraphicLib.putPointOnRectangle(x+(width/2), y+(height/2), father.getX(), father.getY(), father.getWidth(), father.getHeight()); -// -// x = p.x - width/2; -// y = p.y - height/2; -// -// setMoveCd(x, y); -// -// int orientation = GraphicLib.getCloserOrientation(x+(width/2), y+(height/2), father.getX(), father.getY(), father.getWidth(), father.getHeight()); -// if (orientation != currentOrientation) { -//// setOrientation(orientation); -// } -// } -// } - - // TGConnecting points .. - // TODO : change the orientation of the component -// public void setOrientation(int orientation) { -// currentOrientation = orientation; -// double w0, h0, w1, h1; -// -//// switch(orientation) { -////// case GraphicLib.NORTH: -////// w0 = 0.5; -////// h0 = 0.0; -////// break; -//// case GraphicLib.WEST: -//// w0 = 0.0; -//// h0 = 0.5; -//// break; -////// case GraphicLib.SOUTH: -////// w0 = 0.5; -////// h0 = 1.0; -////// break; -//// case GraphicLib.EAST: -//// default: -//// w0 = 1.0; -//// h0 = 0.5; -//// } -// -// w0 = 0.0; -// h0 = 0.5; -// w1 = 1.0; -// h1 = 0.5; -// System.out.println(connectingPoint.length); -// ((ELNConnectingPoint) connectingPoint[0]).setW(w0); -// ((ELNConnectingPoint) connectingPoint[0]).setH(h0); -// ((ELNConnectingPoint) connectingPoint[1]).setW(w1); -// ((ELNConnectingPoint) connectingPoint[1]).setH(h1); -// } - - 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_CURRENT_CONTROLLED_CURRENT_SOURCE; - } - - public boolean editOndoubleClick(JFrame frame) { - JDialogELNComponentCurrentControlledCurrentSource jde = new JDialogELNComponentCurrentControlledCurrentSource(this); - jde.setVisible(true); - return true; - } - - protected String translateExtraParam() { - StringBuffer sb = new StringBuffer("<extraparam>\n"); - sb.append("<attributes value=\"" + val + "\""); - 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 value; - - 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")) { - value = Double.parseDouble(elt.getAttribute("value")); - setVal(value); - } - } - } - } - } - } catch (Exception e) { - throw new MalformedModelingException(); - } - } - - public int getDefaultConnector() { - return TGComponentManager.ELN_CONNECTOR; - } - - public double getVal() { - return val; - } - - public void setVal(double _val) { - val = _val; - } -} \ No newline at end of file diff --git a/src/main/java/ui/eln/sca_eln/ELNComponentCurrentControlledVoltageSource.java b/src/main/java/ui/eln/sca_eln/ELNComponentCurrentControlledVoltageSource.java deleted file mode 100644 index 9ae63cc3ba92315f4ff9319b40749fb7681a2215..0000000000000000000000000000000000000000 --- a/src/main/java/ui/eln/sca_eln/ELNComponentCurrentControlledVoltageSource.java +++ /dev/null @@ -1,341 +0,0 @@ -/* 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; - -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.util.IconManager; -import ui.window.JDialogELNComponentCurrentControlledVoltageSource; - -import javax.swing.*; -import java.awt.*; - -/** - * Class ELNComponentCurrentControlledVoltageSource - * Current controlled voltage source to be used in ELN diagrams - * Creation: 13/06/2018 - * @version 1.0 13/06/2018 - * @author Irina Kit Yan LEE - */ - -public class ELNComponentCurrentControlledVoltageSource extends TGCScalableWithInternalComponent { - protected Color myColor; - protected int orientation; - private int maxFontSize = 14; - private int minFontSize = 4; - private int currentFontSize = -1; -// protected int oldx, oldy; -// protected int currentOrientation = GraphicLib.NORTH; - - private int textX = 15; // border for ports - private double dtextX = 0.0; - protected int decPoint = 3; - - private int fact = 2; - - // Parameter - private double val; - private String unit; - - public ELNComponentCurrentControlledVoltageSource(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(60*fact, 40*fact); - - dtextX = textX * oldScaleFactor; - textX = (int)dtextX; - dtextX = dtextX - textX; - - minWidth = 1; - minHeight = 1; - - initConnectingPoint(4); - - addTGConnectingPointsComment(); - - moveable = true; - editable = true; - removable = true; - userResizable = false; - value = tdp.findELNComponentName("CCVS"); - - myImageIcon = IconManager.imgic1206; - - // Initialization of cvvs attributes - setVal(1.0); - setUnit("\u03A9"); - } - - public void initConnectingPoint(int nb) { - nbConnectingPoint = nb; - connectingPoint = new TGConnectingPoint[nb]; - connectingPoint[0] = new ELNConnectingPoint(this, 0, 0, true, true, 0.0, 0.0); - connectingPoint[1] = new ELNConnectingPoint(this, 0, 0, true, true, 1.0, 0.0); - connectingPoint[2] = new ELNConnectingPoint(this, 0, 0, true, true, 0.0, 1.0); - connectingPoint[3] = new ELNConnectingPoint(this, 0, 0, true, true, 1.0, 1.0); - } - - public Color getMyColor() { - return myColor; - } - - public void internalDrawing(Graphics g) { - Font f = g.getFont(); - Font fold = f; - -// if ((x != oldx) | (oldy != y)) { -// // Component has moved! -// manageMove(); -// oldx = x; -// oldy = y; -// } - - if (this.rescaled && !this.tdp.isScaled()) { - this.rescaled = false; - // Must set the font size... - // Incrementally find the biggest font not greater than max_font size - // If font is less than min_font, no text is displayed - - 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); - } - - // Zoom is assumed to be computed - Color c = g.getColor(); - int [] ptx0 = {x, x+2*width/6, x+2*width/6, x, x+2*width/6, x+2*width/6}; - int [] pty0 = {y, y, y+height, y+height, y+height, y}; - g.drawPolygon(ptx0, pty0, 6); - int [] ptx1 = {x+2*width/6-width/(12*fact), x+2*width/6+width/(12*fact), x+2*width/6}; - int [] pty1 = {y+height/2-height/(8*fact), y+height/2-height/(8*fact), y+height/2+height/(8*fact)}; - g.drawPolygon(ptx1, pty1, 3); - g.fillPolygon(ptx1, pty1, 3); - int [] ptx2 = {x+width, x+4*width/6, x+4*width/6, x+3*width/6, x+4*width/6, x+4*width/6, x+5*width/6, x+4*width/6, x+4*width/6, x+width, x+4*width/6, x+4*width/6}; - int [] pty2 = {y, y, y+height/4, y+2*height/4, y+3*height/4, y+height/4, y+2*height/4, y+3*height/4, y+height, y+height, y+height, y}; - g.drawPolygon(ptx2, pty2, 12); - int [] ptx5 = {x+4*width/6+width/(12*fact), x+4*width/6+width/(6*fact), x+4*width/6+width/(6*fact), x+4*width/6+width/(6*fact), x+4*width/6+width/(6*fact), x+4*width/6+width/(6*fact)+width/(12*fact)}; - int [] pty5 = {y+height/(4*fact), y+height/(4*fact), y+height/(8*fact), y+height/(4*fact)+height/(8*fact), y+height/(4*fact), y+height/(4*fact)}; - g.drawPolygon(ptx5, pty5, 6); - int [] ptx6 = {x+4*width/6+width/(12*fact), x+4*width/6+width/(6*fact)+width/(12*fact)}; - int [] pty6 = {y+height-height/(4*fact), y+height-height/(4*fact)}; - g.drawPolygon(ptx6, pty6, 2); - g.setColor(c); - - // Set font size - int attributeFontSize = this.currentFontSize * 5 / 6; - 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*fact)); - - g.setFont(fold); - } - -// public void manageMove() { -// if (father != null) { -// Point p = GraphicLib.putPointOnRectangle(x+(width/2), y+(height/2), father.getX(), father.getY(), father.getWidth(), father.getHeight()); -// -// x = p.x - width/2; -// y = p.y - height/2; -// -// setMoveCd(x, y); -// -// int orientation = GraphicLib.getCloserOrientation(x+(width/2), y+(height/2), father.getX(), father.getY(), father.getWidth(), father.getHeight()); -// if (orientation != currentOrientation) { -//// setOrientation(orientation); -// } -// } -// } - - // TGConnecting points .. - // TODO : change the orientation of the component -// public void setOrientation(int orientation) { -// currentOrientation = orientation; -// double w0, h0, w1, h1; -// -//// switch(orientation) { -////// case GraphicLib.NORTH: -////// w0 = 0.5; -////// h0 = 0.0; -////// break; -//// case GraphicLib.WEST: -//// w0 = 0.0; -//// h0 = 0.5; -//// break; -////// case GraphicLib.SOUTH: -////// w0 = 0.5; -////// h0 = 1.0; -////// break; -//// case GraphicLib.EAST: -//// default: -//// w0 = 1.0; -//// h0 = 0.5; -//// } -// -// w0 = 0.0; -// h0 = 0.5; -// w1 = 1.0; -// h1 = 0.5; -// System.out.println(connectingPoint.length); -// ((ELNConnectingPoint) connectingPoint[0]).setW(w0); -// ((ELNConnectingPoint) connectingPoint[0]).setH(h0); -// ((ELNConnectingPoint) connectingPoint[1]).setW(w1); -// ((ELNConnectingPoint) connectingPoint[1]).setH(h1); -// } - - 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_CURRENT_CONTROLLED_VOLTAGE_SOURCE; - } - - public boolean editOndoubleClick(JFrame frame) { - JDialogELNComponentCurrentControlledVoltageSource jde = new JDialogELNComponentCurrentControlledVoltageSource(this); - jde.setVisible(true); - return true; - } - - public StringBuffer encode(String data) { - StringBuffer databuf = new StringBuffer(data); - StringBuffer buffer = new StringBuffer(""); - for(int pos = 0; pos != data.length(); pos++) { - char c = databuf.charAt(pos); - switch(c) { - case '\u03A9' : - buffer.append("Ω"); - break; - case '\u03BC' : - buffer.append("μ"); - break; - default : - buffer.append(databuf.charAt(pos)); - break; - } - } - return buffer; - } - - protected String translateExtraParam() { - StringBuffer sb = new StringBuffer("<extraparam>\n"); - sb.append("<attributes value=\"" + val); - sb.append("\" unit=\"" + encode(unit) + "\""); - 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 value; - String unit; - - 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")) { - value = Double.parseDouble(elt.getAttribute("value")); - unit = elt.getAttribute("unit"); - setVal(value); - setUnit(unit); - } - } - } - } - } - } catch (Exception e) { - throw new MalformedModelingException(); - } - } - - public int getDefaultConnector() { - return TGComponentManager.ELN_CONNECTOR; - } - - public double getVal() { - return val; - } - - public void setVal(double _val) { - val = _val; - } - - public String getUnit() { - return unit; - } - - public void setUnit(String _unit) { - unit = _unit; - } -} \ No newline at end of file diff --git a/src/main/java/ui/eln/sca_eln/ELNComponentIdealTransformer.java b/src/main/java/ui/eln/sca_eln/ELNComponentIdealTransformer.java index fa5ec31c390025cbd24e01bf4c5d959f6b950bc5..ed0a2452424053510811592cd24b87f359ab117c 100644 --- a/src/main/java/ui/eln/sca_eln/ELNComponentIdealTransformer.java +++ b/src/main/java/ui/eln/sca_eln/ELNComponentIdealTransformer.java @@ -45,280 +45,744 @@ import org.w3c.dom.Node; import org.w3c.dom.NodeList; import ui.*; import ui.eln.ELNConnectingPoint; -import ui.util.IconManager; import ui.window.JDialogELNComponentIdealTransformer; import javax.swing.*; import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; /** - * Class ELNComponentIdealTransformer - * Ideal transformer to be used in ELN diagrams + * Class ELNComponentIdealTransformer + * Ideal transformer to be used in ELN diagrams * Creation: 13/06/2018 * @version 1.0 13/06/2018 * @author Irina Kit Yan LEE */ -public class ELNComponentIdealTransformer extends TGCScalableWithInternalComponent { - protected Color myColor; - protected int orientation; +public class ELNComponentIdealTransformer extends TGCScalableWithInternalComponent implements ActionListener { + protected Color myColor; + protected int orientation; private int maxFontSize = 14; - private int minFontSize = 4; - private int currentFontSize = -1; -// protected int oldx, oldy; -// protected int currentOrientation = GraphicLib.NORTH; - - private int textX = 15; // border for ports - private double dtextX = 0.0; - protected int decPoint = 3; - - private int fact = 2; - - // Parameter + private int minFontSize = 4; + private int currentFontSize = -1; + + private int textX = 15; + private double dtextX = 0.0; + protected int decPoint = 3; + private double ratio; - - public ELNComponentIdealTransformer(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(50*fact, 50*fact); - - dtextX = textX * oldScaleFactor; - textX = (int)dtextX; - dtextX = dtextX - textX; - - minWidth = 1; - minHeight = 1; - - initConnectingPoint(4); - - addTGConnectingPointsComment(); - - moveable = true; - editable = true; - removable = true; - userResizable = false; - value = tdp.findELNComponentName("IdealTransformer"); - - myImageIcon = IconManager.imgic1206; - - // Initialization of ideal transformer attributes - setRatio(1.0); - } - - public void initConnectingPoint(int nb) { - nbConnectingPoint = nb; - connectingPoint = new TGConnectingPoint[nb]; - connectingPoint[0] = new ELNConnectingPoint(this, 0, 0, true, true, 0.0, 0.0); - connectingPoint[1] = new ELNConnectingPoint(this, 0, 0, true, true, 1.0, 0.0); - connectingPoint[2] = new ELNConnectingPoint(this, 0, 0, true, true, 0.0, 1.0); - connectingPoint[3] = new ELNConnectingPoint(this, 0, 0, true, true, 1.0, 1.0); - } - - public Color getMyColor() { - return myColor; - } - - public void internalDrawing(Graphics g) { - Font f = g.getFont(); - Font fold = f; - -// if ((x != oldx) | (oldy != y)) { -// // Component has moved! -// manageMove(); -// oldx = x; -// oldy = y; -// } - - if (this.rescaled && !this.tdp.isScaled()) { - this.rescaled = false; - // Must set the font size... - // Incrementally find the biggest font not greater than max_font size - // If font is less than min_font, no text is displayed - - 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); - } - - // Zoom is assumed to be computed - Color c = g.getColor(); - int [] ptx0 = {x, x+width/5, x+width/5, x+width/5}; - int [] pty0 = {y, y, y+height/5, y}; - g.drawPolygon(ptx0, pty0, 4); - int [] ptx1 = {x, x+width/5, x+width/5, x+width/5}; - int [] pty1 = {y+height, y+height, y+4*height/5, y+height}; - g.drawPolygon(ptx1, pty1, 4); - int [] ptx2 = {x+width, x+4*width/5, x+4*width/5, x+4*width/5}; - int [] pty2 = {y, y, y+height/5, y}; - g.drawPolygon(ptx2, pty2, 4); - int [] ptx3 = {x+width, x+4*width/5, x+4*width/5, x+4*width/5}; - int [] pty3 = {y+height, y+height, y+4*height/5, y+height}; - g.drawPolygon(ptx3, pty3, 4); - g.drawArc(x, y+height/5, 2*width/5, height/5, 270, 180); - g.drawArc(x, y+2*height/5, 2*width/5, height/5, 270, 180); - g.drawArc(x, y+3*height/5, 2*width/5, height/5, 270, 180); - g.drawArc(x+3*width/5, y+height/5, 2*width/5, height/5, 90, 180); - g.drawArc(x+3*width/5, y+2*height/5, 2*width/5, height/5, 90, 180); - g.drawArc(x+3*width/5, y+3*height/5, 2*width/5, height/5, 90, 180); - g.drawOval(x+2*width/5-width/(10*fact), y+width/(10*fact), width/(5*fact), width/(5*fact)); - g.fillOval(x+2*width/5-width/(10*fact), y+width/(10*fact), width/(5*fact), width/(5*fact)); - g.drawOval(x+3*width/5-width/(10*fact), y+width/(10*fact), width/(5*fact), width/(5*fact)); - g.fillOval(x+3*width/5-width/(10*fact), y+width/(10*fact), width/(5*fact), width/(5*fact)); - g.drawArc(x+width/5+width/10, y+4*height/5, 2*width/5, height/5, 180, 180); - int [] ptx4 = {x+width/5+width/10, x+width/5+width/10, x+width/5+width/10+width/10}; - int [] pty4 = {y+4*height/5+height/10+height/10, y+4*height/5+height/10, y+4*height/5+height/10}; - g.drawPolygon(ptx4, pty4, 3); - g.fillPolygon(ptx4, pty4, 3); - int [] ptx5 = {x+width/5+width/10+2*width/5, x+width/5+width/10+2*width/5, x+width/5+width/10+2*width/5-width/10}; - int [] pty5 = {y+4*height/5+height/10+height/10, y+4*height/5+height/10, y+4*height/5+height/10}; - g.drawPolygon(ptx5, pty5, 3); - g.fillPolygon(ptx5, pty5, 3); - g.setColor(c); - - // Set font size - int attributeFontSize = this.currentFontSize * 5 / 6; - 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/(5*fact)); - w = g.getFontMetrics().stringWidth(Double.toString(ratio)); - g.setFont(f.deriveFont(Font.PLAIN)); - g.drawString(Double.toString(ratio), x+(width-w)/2, y+height+attributeFontSize+height/(5*fact)); - g.setFont(fold); - } - -// public void manageMove() { -// if (father != null) { -// Point p = GraphicLib.putPointOnRectangle(x+(width/2), y+(height/2), father.getX(), father.getY(), father.getWidth(), father.getHeight()); -// -// x = p.x - width/2; -// y = p.y - height/2; -// -// setMoveCd(x, y); -// -// int orientation = GraphicLib.getCloserOrientation(x+(width/2), y+(height/2), father.getX(), father.getY(), father.getWidth(), father.getHeight()); -// if (orientation != currentOrientation) { -//// setOrientation(orientation); -// } -// } -// } - - // TGConnecting points .. - // TODO : change the orientation of the component -// public void setOrientation(int orientation) { -// currentOrientation = orientation; -// double w0, h0, w1, h1; -// -//// switch(orientation) { -////// case GraphicLib.NORTH: -////// w0 = 0.5; -////// h0 = 0.0; -////// break; -//// case GraphicLib.WEST: -//// w0 = 0.0; -//// h0 = 0.5; -//// break; -////// case GraphicLib.SOUTH: -////// w0 = 0.5; -////// h0 = 1.0; -////// break; -//// case GraphicLib.EAST: -//// default: -//// w0 = 1.0; -//// h0 = 0.5; -//// } -// -// w0 = 0.0; -// h0 = 0.5; -// w1 = 1.0; -// h1 = 0.5; -// System.out.println(connectingPoint.length); -// ((ELNConnectingPoint) connectingPoint[0]).setW(w0); -// ((ELNConnectingPoint) connectingPoint[0]).setH(h0); -// ((ELNConnectingPoint) connectingPoint[1]).setW(w1); -// ((ELNConnectingPoint) connectingPoint[1]).setH(h1); -// } - - 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_IDEAL_TRANSFORMER; - } - - public boolean editOndoubleClick(JFrame frame) { - JDialogELNComponentIdealTransformer jde = new JDialogELNComponentIdealTransformer(this); - jde.setVisible(true); - return true; - } - - protected String translateExtraParam() { - StringBuffer sb = new StringBuffer("<extraparam>\n"); - sb.append("<attributes ratio=\"" + ratio + "\""); - 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 ratio; - - 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")) { - ratio = Double.parseDouble(elt.getAttribute("ratio")); + + 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 ELNComponentIdealTransformer(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(100, 100); + + dtextX = textX * oldScaleFactor; + textX = (int) dtextX; + dtextX = dtextX - textX; + + minWidth = 1; + minHeight = 1; + + initConnectingPoint(4); + + addTGConnectingPointsComment(); + + moveable = true; + editable = true; + removable = true; + userResizable = false; + value = tdp.findELNComponentName("IdealTransformer"); + + setRatio(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, "p1"); + connectingPoint[1] = new ELNConnectingPoint(this, 0, 0, true, true, 1.0, 0.0, "p2"); + connectingPoint[2] = new ELNConnectingPoint(this, 0, 0, true, true, 0.0, 1.0, "n1"); + connectingPoint[3] = new ELNConnectingPoint(this, 0, 0, true, true, 1.0, 1.0, "n2"); + } + + 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(); + double w0 = ((ELNConnectingPoint) connectingPoint[0]).getW(); + double h0 = ((ELNConnectingPoint) connectingPoint[0]).getH(); + double w1 = ((ELNConnectingPoint) connectingPoint[1]).getW(); + double h1 = ((ELNConnectingPoint) connectingPoint[1]).getH(); + double w2 = ((ELNConnectingPoint) connectingPoint[2]).getW(); + double h2 = ((ELNConnectingPoint) connectingPoint[2]).getH(); + double w3 = ((ELNConnectingPoint) connectingPoint[3]).getW(); + double h3 = ((ELNConnectingPoint) connectingPoint[3]).getH(); + + if (position == 0) { + if (first == false) { + first = true; + old = width; + width = height; + height = old; + } + + ((ELNConnectingPoint) connectingPoint[0]).setW(w0); + ((ELNConnectingPoint) connectingPoint[0]).setH(h0); + ((ELNConnectingPoint) connectingPoint[1]).setW(w1); + ((ELNConnectingPoint) connectingPoint[1]).setH(h1); + ((ELNConnectingPoint) connectingPoint[2]).setW(w2); + ((ELNConnectingPoint) connectingPoint[2]).setH(h2); + ((ELNConnectingPoint) connectingPoint[3]).setW(w3); + ((ELNConnectingPoint) connectingPoint[3]).setH(h3); + + int attributeFontSize = this.currentFontSize * 5 / 6; + int sw0 = g.getFontMetrics().stringWidth("p1"); + int sh0 = g.getFontMetrics().getAscent(); + int sw1 = g.getFontMetrics().stringWidth("p2"); + int sh1 = g.getFontMetrics().getAscent(); + int sw2 = g.getFontMetrics().stringWidth("n1"); + int sh2 = g.getFontMetrics().getAscent(); + int sw3 = g.getFontMetrics().stringWidth("n2"); + int sh3 = 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 / 5); + 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); + g.drawString(((ELNConnectingPoint) connectingPoint[0]).getName(), x - height / 8 - sw0, y); + g.drawString(((ELNConnectingPoint) connectingPoint[1]).getName(), x + width + height / 8, y); + g.drawString(((ELNConnectingPoint) connectingPoint[2]).getName(), x - height / 8 - sw2, + y + height + sh2); + g.drawString(((ELNConnectingPoint) connectingPoint[3]).getName(), x + width + height / 8, + y + height + sh3); + } + 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)) { + rotateTop(g); + g.drawString(((ELNConnectingPoint) connectingPoint[1]).getName(), x - height / 8 - sw1, y); + g.drawString(((ELNConnectingPoint) connectingPoint[0]).getName(), x + width + height / 8, y); + g.drawString(((ELNConnectingPoint) connectingPoint[3]).getName(), x - height / 8 - sw3, + y + height + sh3); + g.drawString(((ELNConnectingPoint) connectingPoint[2]).getName(), x + width + height / 8, + y + height + sh2); + } + 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)) { + rotateBottom(g); + g.drawString(((ELNConnectingPoint) connectingPoint[2]).getName(), x - height / 8 - sw2, y); + g.drawString(((ELNConnectingPoint) connectingPoint[3]).getName(), x + width + height / 8, y); + g.drawString(((ELNConnectingPoint) connectingPoint[0]).getName(), x - height / 8 - sw0, + y + height + sh0); + 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)) { + rotateBottom(g); + g.drawString(((ELNConnectingPoint) connectingPoint[3]).getName(), x - height / 8 - sw3, y); + g.drawString(((ELNConnectingPoint) connectingPoint[2]).getName(), x + width + height / 8, y); + g.drawString(((ELNConnectingPoint) connectingPoint[1]).getName(), x - height / 8 - sw1, + y + height + sh1); + 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; + } + + ((ELNConnectingPoint) connectingPoint[0]).setW(h0); + ((ELNConnectingPoint) connectingPoint[0]).setH(w0); + ((ELNConnectingPoint) connectingPoint[1]).setW(h1); + ((ELNConnectingPoint) connectingPoint[1]).setH(w1); + ((ELNConnectingPoint) connectingPoint[2]).setW(h2); + ((ELNConnectingPoint) connectingPoint[2]).setH(w2); + ((ELNConnectingPoint) connectingPoint[3]).setW(h3); + ((ELNConnectingPoint) connectingPoint[3]).setH(w3); + + int attributeFontSize = this.currentFontSize * 5 / 6; + int sw0 = g.getFontMetrics().stringWidth("p1"); + int sh0 = g.getFontMetrics().getAscent(); + int sw1 = g.getFontMetrics().stringWidth("p2"); + int sh1 = g.getFontMetrics().getAscent(); + int sw2 = g.getFontMetrics().stringWidth("n1"); + int sh2 = g.getFontMetrics().getAscent(); + int sw3 = g.getFontMetrics().stringWidth("n2"); + int sh3 = 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 / 5); + 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); + g.drawString(((ELNConnectingPoint) connectingPoint[2]).getName(), x - width / 8 - sw2, y); + g.drawString(((ELNConnectingPoint) connectingPoint[0]).getName(), x + width + width / 8, y); + g.drawString(((ELNConnectingPoint) connectingPoint[3]).getName(), x - width / 8 - sw3, + y + height + sh3); + 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)) { + rotateRight(g); + g.drawString(((ELNConnectingPoint) connectingPoint[3]).getName(), x - width / 8 - sw3, y); + g.drawString(((ELNConnectingPoint) connectingPoint[1]).getName(), x + width + width / 8, y); + g.drawString(((ELNConnectingPoint) connectingPoint[2]).getName(), x - width / 8 - sw2, + y + height + sh2); + 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)) { + rotateLeft(g); + g.drawString(((ELNConnectingPoint) connectingPoint[0]).getName(), x - width / 8 - sw0, y); + g.drawString(((ELNConnectingPoint) connectingPoint[2]).getName(), x + width + width / 8, y); + g.drawString(((ELNConnectingPoint) connectingPoint[1]).getName(), x - width / 8 - sw1, + y + height + sh1); + g.drawString(((ELNConnectingPoint) connectingPoint[3]).getName(), x + width + width / 8, + y + height + sh3); + } + 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); + g.drawString(((ELNConnectingPoint) connectingPoint[1]).getName(), x - width / 8 - sw1, y); + g.drawString(((ELNConnectingPoint) connectingPoint[3]).getName(), x + width + width / 8, y); + g.drawString(((ELNConnectingPoint) connectingPoint[0]).getName(), x - width / 8 - sw0, + y + height + sh0); + g.drawString(((ELNConnectingPoint) connectingPoint[2]).getName(), x + width + width / 8, + y + height + sh2); + } + } else if (position == 2) { + if (first == false) { + first = true; + old = width; + width = height; + height = old; + } + + ((ELNConnectingPoint) connectingPoint[0]).setW(w0); + ((ELNConnectingPoint) connectingPoint[0]).setH(h0); + ((ELNConnectingPoint) connectingPoint[1]).setW(w1); + ((ELNConnectingPoint) connectingPoint[1]).setH(h1); + ((ELNConnectingPoint) connectingPoint[2]).setW(w2); + ((ELNConnectingPoint) connectingPoint[2]).setH(h2); + ((ELNConnectingPoint) connectingPoint[3]).setW(w3); + ((ELNConnectingPoint) connectingPoint[3]).setH(h3); + + int attributeFontSize = this.currentFontSize * 5 / 6; + int sw0 = g.getFontMetrics().stringWidth("p1"); + int sh0 = g.getFontMetrics().getAscent(); + int sw1 = g.getFontMetrics().stringWidth("p2"); + int sh1 = g.getFontMetrics().getAscent(); + int sw2 = g.getFontMetrics().stringWidth("n1"); + int sh2 = g.getFontMetrics().getAscent(); + int sw3 = g.getFontMetrics().stringWidth("n2"); + int sh3 = 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 / 5); + 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); + g.drawString(((ELNConnectingPoint) connectingPoint[3]).getName(), x - height / 8 - sw3, y); + g.drawString(((ELNConnectingPoint) connectingPoint[2]).getName(), x + width + height / 8, y); + g.drawString(((ELNConnectingPoint) connectingPoint[1]).getName(), x - height / 8 - sw1, + y + height + sh1); + 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)) { + rotateBottom(g); + g.drawString(((ELNConnectingPoint) connectingPoint[2]).getName(), x - height / 8 - sw2, y); + g.drawString(((ELNConnectingPoint) connectingPoint[3]).getName(), x + width + height / 8, y); + g.drawString(((ELNConnectingPoint) connectingPoint[0]).getName(), x - height / 8 - sw0, + y + height + sh0); + 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)) { + rotateTop(g); + g.drawString(((ELNConnectingPoint) connectingPoint[1]).getName(), x - height / 8 - sw1, y); + g.drawString(((ELNConnectingPoint) connectingPoint[0]).getName(), x + width + height / 8, y); + g.drawString(((ELNConnectingPoint) connectingPoint[3]).getName(), x - height / 8 - sw3, + y + height + sh3); + g.drawString(((ELNConnectingPoint) connectingPoint[2]).getName(), x + width + height / 8, + y + height + sh2); + } + 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); + g.drawString(((ELNConnectingPoint) connectingPoint[0]).getName(), x - height / 8 - sw0, y); + g.drawString(((ELNConnectingPoint) connectingPoint[1]).getName(), x + width + height / 8, y); + g.drawString(((ELNConnectingPoint) connectingPoint[2]).getName(), x - height / 8 - sw2, + y + height + sh2); + g.drawString(((ELNConnectingPoint) connectingPoint[3]).getName(), x + width + height / 8, + y + height + sh3); + } + } else if (position == 3) { + if (first == false) { + first = true; + old = width; + width = height; + height = old; + } + + ((ELNConnectingPoint) connectingPoint[0]).setW(h0); + ((ELNConnectingPoint) connectingPoint[0]).setH(w0); + ((ELNConnectingPoint) connectingPoint[1]).setW(h1); + ((ELNConnectingPoint) connectingPoint[1]).setH(w1); + ((ELNConnectingPoint) connectingPoint[2]).setW(h2); + ((ELNConnectingPoint) connectingPoint[2]).setH(w2); + ((ELNConnectingPoint) connectingPoint[3]).setW(h3); + ((ELNConnectingPoint) connectingPoint[3]).setH(w3); + + int attributeFontSize = this.currentFontSize * 5 / 6; + int sw0 = g.getFontMetrics().stringWidth("p1"); + int sh0 = g.getFontMetrics().getAscent(); + int sw1 = g.getFontMetrics().stringWidth("p2"); + int sh1 = g.getFontMetrics().getAscent(); + int sw2 = g.getFontMetrics().stringWidth("n1"); + int sh2 = g.getFontMetrics().getAscent(); + int sw3 = g.getFontMetrics().stringWidth("n2"); + int sh3 = 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 / 5); + 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); + g.drawString(((ELNConnectingPoint) connectingPoint[1]).getName(), x - width / 8 - sw1, y); + g.drawString(((ELNConnectingPoint) connectingPoint[3]).getName(), x + width + width / 8, y); + g.drawString(((ELNConnectingPoint) connectingPoint[0]).getName(), x - width / 8 - sw0, + y + height + sh0); + g.drawString(((ELNConnectingPoint) connectingPoint[2]).getName(), x + width + width / 8, + y + height + sh2); + } + 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)) { + rotateLeft(g); + g.drawString(((ELNConnectingPoint) connectingPoint[0]).getName(), x - width / 8 - sw0, y); + g.drawString(((ELNConnectingPoint) connectingPoint[2]).getName(), x + width + width / 8, y); + g.drawString(((ELNConnectingPoint) connectingPoint[1]).getName(), x - width / 8 - sw1, + y + height + sh1); + g.drawString(((ELNConnectingPoint) connectingPoint[3]).getName(), x + width + width / 8, + y + height + sh3); + } + 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)) { + rotateRight(g); + g.drawString(((ELNConnectingPoint) connectingPoint[3]).getName(), x - width / 8 - sw3, y); + g.drawString(((ELNConnectingPoint) connectingPoint[1]).getName(), x + width + width / 8, y); + g.drawString(((ELNConnectingPoint) connectingPoint[2]).getName(), x - width / 8 - sw2, + y + height + sh2); + 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); + g.drawString(((ELNConnectingPoint) connectingPoint[2]).getName(), x - width / 8 - sw2, y); + g.drawString(((ELNConnectingPoint) connectingPoint[0]).getName(), x + width + width / 8, y); + g.drawString(((ELNConnectingPoint) connectingPoint[3]).getName(), x - width / 8 - sw3, + y + height + sh3); + g.drawString(((ELNConnectingPoint) connectingPoint[1]).getName(), x + width + width / 8, + y + height + sh1); + } + } + g.setColor(c); + g.setFont(fold); + } + + private void rotateTop(Graphics g) { + int[] ptx0 = { x, x + width / 5, x + width / 5, x + width / 5 }; + int[] pty0 = { y, y, y + height / 5, y }; + g.drawPolygon(ptx0, pty0, 4); + int[] ptx1 = { x, x + width / 5, x + width / 5, x + width / 5 }; + int[] pty1 = { y + height, y + height, y + 4 * height / 5, y + height }; + g.drawPolygon(ptx1, pty1, 4); + int[] ptx2 = { x + width, x + 4 * width / 5, x + 4 * width / 5, x + 4 * width / 5 }; + int[] pty2 = { y, y, y + height / 5, y }; + g.drawPolygon(ptx2, pty2, 4); + int[] ptx3 = { x + width, x + 4 * width / 5, x + 4 * width / 5, x + 4 * width / 5 }; + int[] pty3 = { y + height, y + height, y + 4 * height / 5, y + height }; + g.drawPolygon(ptx3, pty3, 4); + g.drawArc(x, y + height / 5, 2 * width / 5, height / 5, 270, 180); + g.drawArc(x, y + 2 * height / 5, 2 * width / 5, height / 5, 270, 180); + g.drawArc(x, y + 3 * height / 5, 2 * width / 5, height / 5, 270, 180); + g.drawArc(x + 3 * width / 5, y + height / 5, 2 * width / 5, height / 5, 90, 180); + g.drawArc(x + 3 * width / 5, y + 2 * height / 5, 2 * width / 5, height / 5, 90, 180); + g.drawArc(x + 3 * width / 5, y + 3 * height / 5, 2 * width / 5, height / 5, 90, 180); + g.drawOval(x + 2 * width / 5 - width / 20, y + width / 20, width / 10, width / 10); + g.fillOval(x + 2 * width / 5 - width / 20, y + width / 20, width / 10, width / 10); + g.drawOval(x + 3 * width / 5 - width / 20, y + width / 20, width / 10, width / 10); + g.fillOval(x + 3 * width / 5 - width / 20, y + width / 20, width / 10, width / 10); + g.drawArc(x + width / 5 + width / 10, y + 4 * height / 5, 2 * width / 5, height / 5, 180, 180); + int[] ptx4 = { x + width / 5 + width / 10, x + width / 5 + width / 10, + x + width / 5 + width / 10 + width / 10 }; + int[] pty4 = { y + 4 * height / 5 + height / 10 + height / 10, y + 4 * height / 5 + height / 10, + y + 4 * height / 5 + height / 10 }; + g.drawPolygon(ptx4, pty4, 3); + g.fillPolygon(ptx4, pty4, 3); + int[] ptx5 = { x + width / 5 + width / 10 + 2 * width / 5, x + width / 5 + width / 10 + 2 * width / 5, + x + width / 5 + width / 10 + 2 * width / 5 - width / 10 }; + int[] pty5 = { y + 4 * height / 5 + height / 10 + height / 10, y + 4 * height / 5 + height / 10, + y + 4 * height / 5 + height / 10 }; + g.drawPolygon(ptx5, pty5, 3); + g.fillPolygon(ptx5, pty5, 3); + + int w = g.getFontMetrics().stringWidth(Double.toString(ratio)); + int h = g.getFontMetrics().getAscent(); + g.drawString(Double.toString(ratio), x + (width - w) / 2, y + height + height / 10 + h); + } + + private void rotateBottom(Graphics g) { + int[] ptx0 = { x, x + width / 5, x + width / 5, x + width / 5 }; + int[] pty0 = { y, y, y + height / 5, y }; + g.drawPolygon(ptx0, pty0, 4); + int[] ptx1 = { x, x + width / 5, x + width / 5, x + width / 5 }; + int[] pty1 = { y + height, y + height, y + 4 * height / 5, y + height }; + g.drawPolygon(ptx1, pty1, 4); + int[] ptx2 = { x + width, x + 4 * width / 5, x + 4 * width / 5, x + 4 * width / 5 }; + int[] pty2 = { y, y, y + height / 5, y }; + g.drawPolygon(ptx2, pty2, 4); + int[] ptx3 = { x + width, x + 4 * width / 5, x + 4 * width / 5, x + 4 * width / 5 }; + int[] pty3 = { y + height, y + height, y + 4 * height / 5, y + height }; + g.drawPolygon(ptx3, pty3, 4); + g.drawArc(x, y + height / 5, 2 * width / 5, height / 5, 270, 180); + g.drawArc(x, y + 2 * height / 5, 2 * width / 5, height / 5, 270, 180); + g.drawArc(x, y + 3 * height / 5, 2 * width / 5, height / 5, 270, 180); + g.drawArc(x + 3 * width / 5, y + height / 5, 2 * width / 5, height / 5, 90, 180); + g.drawArc(x + 3 * width / 5, y + 2 * height / 5, 2 * width / 5, height / 5, 90, 180); + g.drawArc(x + 3 * width / 5, y + 3 * height / 5, 2 * width / 5, height / 5, 90, 180); + g.drawOval(x + 2 * width / 5 - width / 20, y + width - width / 20 - width / 10, width / 10, width / 10); + g.fillOval(x + 2 * width / 5 - width / 20, y + width - width / 20 - width / 10, width / 10, width / 10); + g.drawOval(x + 3 * width / 5 - width / 20, y + width - width / 20 - width / 10, width / 10, width / 10); + g.fillOval(x + 3 * width / 5 - width / 20, y + width - width / 20 - width / 10, width / 10, width / 10); + g.drawArc(x + width / 5 + width / 10, y, 2 * width / 5, height / 5, 0, 180); + int[] ptx4 = { x + width / 5 + width / 10, x + width / 5 + width / 10, + x + width / 5 + width / 10 + width / 10 }; + int[] pty4 = { y + height / 5 - height / 10 - height / 10, y + height / 5 - height / 10, + y + height / 5 - height / 10 }; + g.drawPolygon(ptx4, pty4, 3); + g.fillPolygon(ptx4, pty4, 3); + int[] ptx5 = { x + width / 5 + width / 10 + 2 * width / 5, x + width / 5 + width / 10 + 2 * width / 5, + x + width / 5 + width / 10 + 2 * width / 5 - width / 10 }; + int[] pty5 = { y + height / 5 - height / 10 - height / 10, y + height / 5 - height / 10, + y + height / 5 - height / 10 }; + g.drawPolygon(ptx5, pty5, 3); + g.fillPolygon(ptx5, pty5, 3); + + int w = g.getFontMetrics().stringWidth(Double.toString(ratio)); + g.drawString(Double.toString(ratio), x + (width - w) / 2, y - height / 20); + } + + private void rotateRight(Graphics g) { + int[] ptx0 = { x, x, x + width / 5, x }; + int[] pty0 = { y, y + height / 5, y + height / 5, y + height / 5 }; + g.drawPolygon(ptx0, pty0, 4); + int[] ptx1 = { x + width, x + width, x + 4 * width / 5, x + width }; + int[] pty1 = { y, y + height / 5, y + height / 5, y + height / 5 }; + g.drawPolygon(ptx1, pty1, 4); + int[] ptx2 = { x, x, x + width / 5, x }; + int[] pty2 = { y + height, y + 4 * height / 5, y + 4 * height / 5, y + 4 * height / 5 }; + g.drawPolygon(ptx2, pty2, 4); + int[] ptx3 = { x + width, x + width, x + 4 * width / 5, x + width }; + int[] pty3 = { y + height, y + 4 * height / 5, y + 4 * height / 5, y + 4 * height / 5 }; + g.drawPolygon(ptx3, pty3, 4); + g.drawArc(x + width / 5, y, width / 5, 2 * height / 5, 180, 180); + g.drawArc(x + 2 * width / 5, y, width / 5, 2 * height / 5, 180, 180); + g.drawArc(x + 3 * width / 5, y, width / 5, 2 * height / 5, 180, 180); + g.drawArc(x + width / 5, y + 3 * height / 5, width / 5, 2 * height / 5, 0, 180); + g.drawArc(x + 2 * width / 5, y + 3 * height / 5, width / 5, 2 * height / 5, 0, 180); + g.drawArc(x + 3 * width / 5, y + 3 * height / 5, width / 5, 2 * height / 5, 0, 180); + g.drawOval(x + width - width / 10 - width / 20, y + 2 * height / 5 - height / 20, width / 10, height / 10); + g.fillOval(x + width - width / 10 - width / 20, y + 2 * height / 5 - height / 20, width / 10, height / 10); + g.drawOval(x + width - width / 10 - width / 20, y + 3 * height / 5 - height / 20, width / 10, height / 10); + g.fillOval(x + width - width / 10 - width / 20, y + 3 * height / 5 - height / 20, width / 10, height / 10); + g.drawArc(x, y + height / 5 + height / 10, width / 5, 2 * height / 5, 90, 180); + int[] ptx4 = { x + width / 5 - width / 10 - width / 10, x + width / 5 - width / 10, + x + width / 5 - width / 10 }; + int[] pty4 = { y + height / 5 + height / 10, y + height / 5 + height / 10, + y + height / 5 + height / 10 + height / 10 }; + g.drawPolygon(ptx4, pty4, 3); + g.fillPolygon(ptx4, pty4, 3); + int[] ptx5 = { x + width / 5 - width / 10 - width / 10, x + width / 5 - width / 10, + x + width / 5 - width / 10 }; + int[] pty5 = { y + height / 5 + height / 10 + 2 * height / 5, y + height / 5 + height / 10 + 2 * height / 5, + y + height / 5 + height / 10 + 2 * height / 5 - height / 10 }; + g.drawPolygon(ptx5, pty5, 3); + g.fillPolygon(ptx5, pty5, 3); + + int w = g.getFontMetrics().stringWidth(Double.toString(ratio)); + int h = g.getFontMetrics().getAscent(); + g.drawString(Double.toString(ratio), x - width / 10 - w, y + height / 2 + h / 2); + } + + private void rotateLeft(Graphics g) { + int[] ptx0 = { x, x, x + width / 5, x }; + int[] pty0 = { y, y + height / 5, y + height / 5, y + height / 5 }; + g.drawPolygon(ptx0, pty0, 4); + int[] ptx1 = { x + width, x + width, x + 4 * width / 5, x + width }; + int[] pty1 = { y, y + height / 5, y + height / 5, y + height / 5 }; + g.drawPolygon(ptx1, pty1, 4); + int[] ptx2 = { x, x, x + width / 5, x }; + int[] pty2 = { y + height, y + 4 * height / 5, y + 4 * height / 5, y + 4 * height / 5 }; + g.drawPolygon(ptx2, pty2, 4); + int[] ptx3 = { x + width, x + width, x + 4 * width / 5, x + width }; + int[] pty3 = { y + height, y + 4 * height / 5, y + 4 * height / 5, y + 4 * height / 5 }; + g.drawPolygon(ptx3, pty3, 4); + g.drawArc(x + width / 5, y, width / 5, 2 * height / 5, 180, 180); + g.drawArc(x + 2 * width / 5, y, width / 5, 2 * height / 5, 180, 180); + g.drawArc(x + 3 * width / 5, y, width / 5, 2 * height / 5, 180, 180); + g.drawArc(x + width / 5, y + 3 * height / 5, width / 5, 2 * height / 5, 0, 180); + g.drawArc(x + 2 * width / 5, y + 3 * height / 5, width / 5, 2 * height / 5, 0, 180); + g.drawArc(x + 3 * width / 5, y + 3 * height / 5, width / 5, 2 * height / 5, 0, 180); + g.drawOval(x + width / 20, y + 2 * height / 5 - height / 20, width / 10, height / 10); + g.fillOval(x + width / 20, y + 2 * height / 5 - height / 20, width / 10, height / 10); + g.drawOval(x + width / 20, y + 3 * height / 5 - height / 20, width / 10, height / 10); + g.fillOval(x + width / 20, y + 3 * height / 5 - height / 20, width / 10, height / 10); + g.drawArc(x + 4 * width / 5, y + height / 5 + height / 10, width / 5, 2 * height / 5, 270, 180); + int[] ptx4 = { x + 4 * width / 5 + width / 10 + width / 10, x + 4 * width / 5 + width / 10, + x + 4 * width / 5 + width / 10 }; + int[] pty4 = { y + height / 5 + height / 10, y + height / 5 + height / 10, + y + height / 5 + height / 10 + height / 10 }; + g.drawPolygon(ptx4, pty4, 3); + g.fillPolygon(ptx4, pty4, 3); + int[] ptx5 = { x + 4 * width / 5 + width / 10 + width / 10, x + 4 * width / 5 + width / 10, + x + 4 * width / 5 + width / 10 }; + int[] pty5 = { y + height / 5 + height / 10 + 2 * height / 5, y + height / 5 + height / 10 + 2 * height / 5, + y + height / 5 + height / 10 + 2 * height / 5 - height / 10 }; + g.drawPolygon(ptx5, pty5, 3); + g.fillPolygon(ptx5, pty5, 3); + + int h = g.getFontMetrics().getAscent(); + g.drawString(Double.toString(ratio), x + width + width / 10, y + height / 2 + h / 2); + } + + 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_IDEAL_TRANSFORMER; + } + + public boolean editOndoubleClick(JFrame frame) { + JDialogELNComponentIdealTransformer jde = new JDialogELNComponentIdealTransformer(this); + jde.setVisible(true); + return true; + } + + protected String translateExtraParam() { + StringBuffer sb = new StringBuffer("<extraparam>\n"); + sb.append("<attributes ratio=\"" + ratio + "\""); + 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 ratio; + + 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")) { + ratio = Double.parseDouble(elt.getAttribute("ratio")); setRatio(ratio); - } - } - } - } - } - } catch (Exception e) { - throw new MalformedModelingException(); - } - } - - public int getDefaultConnector() { - return TGComponentManager.ELN_CONNECTOR; - } - - public double getRatio() { + } + } + } + } + } + } 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 getRatio() { return ratio; } public void setRatio(double _ratio) { ratio = _ratio; } -} \ No newline at end of file +} diff --git a/src/main/java/ui/eln/sca_eln/ELNComponentIndependentCurrentSource.java b/src/main/java/ui/eln/sca_eln/ELNComponentIndependentCurrentSource.java new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/src/main/java/ui/eln/sca_eln/ELNComponentIndependentVoltageSource.java b/src/main/java/ui/eln/sca_eln/ELNComponentIndependentVoltageSource.java new file mode 100644 index 0000000000000000000000000000000000000000..f4d18bc0e3de811dc19c64479bea967d0dc2099b --- /dev/null +++ b/src/main/java/ui/eln/sca_eln/ELNComponentIndependentVoltageSource.java @@ -0,0 +1,712 @@ +/* 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; + +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.JDialogELNComponentIndependentVoltageSource; + +import javax.swing.*; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +/** + * Class ELNComponentIndependentVoltageSource + * Independent voltage source to be used in ELN diagrams + * Creation: 15/06/2018 + * @version 1.0 15/06/2018 + * @author Irina Kit Yan LEE + */ + +public class ELNComponentIndependentVoltageSource 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 initValue, offset, amplitude, frequency, phase, acAmplitude, acPhase, acNoiseAmplitude; + private String delay; + private String unit0; + + 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 ELNComponentIndependentVoltageSource(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(40, 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("VSource"); + + setInitValue(0.0); + setOffset(0.0); + setAmplitude(0.0); + setFrequency(0.0); + setUnit0("Hz"); + setPhase(0.0); + setDelay("sc_core::SC_ZERO_TIME"); + setAcAmplitude(0.0); + setAcPhase(0.0); + setAcNoiseAmplitude(0.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.5, 0.0, "p"); + connectingPoint[1] = new ELNConnectingPoint(this, 0, 0, true, true, 0.5, 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(); + double w0 = ((ELNConnectingPoint) connectingPoint[0]).getW(); + double h0 = ((ELNConnectingPoint) connectingPoint[0]).getH(); + double w1 = ((ELNConnectingPoint) connectingPoint[1]).getW(); + double h1 = ((ELNConnectingPoint) connectingPoint[1]).getH(); + + if (position == 0) { + if (first == false) { + first = true; + old = width; + width = height; + height = old; + } + + ((ELNConnectingPoint) connectingPoint[0]).setW(w0); + ((ELNConnectingPoint) connectingPoint[0]).setH(h0); + ((ELNConnectingPoint) connectingPoint[1]).setW(w1); + ((ELNConnectingPoint) connectingPoint[1]).setH(h1); + + int attributeFontSize = this.currentFontSize * 5 / 6; + int sh0 = g.getFontMetrics().getAscent(); + 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); + g.drawString(((ELNConnectingPoint) connectingPoint[0]).getName(), x+width/2+width/2, y); + g.drawString(((ELNConnectingPoint) connectingPoint[1]).getName(), x+width/2+width/2, y+height+sh1); + } + 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)) { + rotateTop(g); + g.drawString(((ELNConnectingPoint) connectingPoint[0]).getName(), x+width/2+width/2, y); + g.drawString(((ELNConnectingPoint) connectingPoint[1]).getName(), x+width/2+width/2, y+height+sh1); + } + 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)) { + rotateBottom(g); + g.drawString(((ELNConnectingPoint) connectingPoint[1]).getName(), x+width/2+width/2, y); + g.drawString(((ELNConnectingPoint) connectingPoint[0]).getName(), x+width/2+width/2, y+height+sh0); + } + 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); + g.drawString(((ELNConnectingPoint) connectingPoint[1]).getName(), x+width/2+width/2, y); + g.drawString(((ELNConnectingPoint) connectingPoint[0]).getName(), x+width/2+width/2, y+height+sh0); + } + } else if (position == 1) { + if (first == false) { + first = true; + old = width; + width = height; + height = old; + } + + ((ELNConnectingPoint) connectingPoint[0]).setW(h0); + ((ELNConnectingPoint) connectingPoint[0]).setH(w0); + ((ELNConnectingPoint) connectingPoint[1]).setW(h1); + ((ELNConnectingPoint) connectingPoint[1]).setH(w1); + + 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 / 2); + 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); + g.drawString(((ELNConnectingPoint) connectingPoint[0]).getName(), x - sw0, + y + height / 2 + height / 4 + sh0); + g.drawString(((ELNConnectingPoint) connectingPoint[1]).getName(), x + width, + y + height / 2 + height / 4 + 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)) { + rotateRight(g); + g.drawString(((ELNConnectingPoint) connectingPoint[0]).getName(), x - sw0, + y + height / 2 + height / 4 + sh0); + g.drawString(((ELNConnectingPoint) connectingPoint[1]).getName(), x + width, + y + height / 2 + height / 4 + 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)) { + rotateLeft(g); + g.drawString(((ELNConnectingPoint) connectingPoint[1]).getName(), x - sw1, + y + height / 2 + height / 4 + sh1); + g.drawString(((ELNConnectingPoint) connectingPoint[0]).getName(), x + width, + y + height / 2 + height / 4 + 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)) { + rotateLeft(g); + g.drawString(((ELNConnectingPoint) connectingPoint[1]).getName(), x - sw1, + y + height / 2 + height / 4 + sh1); + g.drawString(((ELNConnectingPoint) connectingPoint[0]).getName(), x + width, + y + height / 2 + height / 4 + sh0); + } + } else if (position == 2) { + if (first == false) { + first = true; + old = width; + width = height; + height = old; + } + + ((ELNConnectingPoint) connectingPoint[0]).setW(w0); + ((ELNConnectingPoint) connectingPoint[0]).setH(h0); + ((ELNConnectingPoint) connectingPoint[1]).setW(w1); + ((ELNConnectingPoint) connectingPoint[1]).setH(h1); + + int attributeFontSize = this.currentFontSize * 5 / 6; + int sh0 = g.getFontMetrics().getAscent(); + 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); + g.drawString(((ELNConnectingPoint) connectingPoint[1]).getName(), x+width/2+width/2, y); + g.drawString(((ELNConnectingPoint) connectingPoint[0]).getName(), x+width/2+width/2, y+height+sh0); + } + 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)) { + rotateBottom(g); + g.drawString(((ELNConnectingPoint) connectingPoint[1]).getName(), x+width/2+width/2, y); + g.drawString(((ELNConnectingPoint) connectingPoint[0]).getName(), x+width/2+width/2, y+height+sh0); + } + 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)) { + rotateTop(g); + g.drawString(((ELNConnectingPoint) connectingPoint[0]).getName(), x+width/2+width/2, y); + g.drawString(((ELNConnectingPoint) connectingPoint[1]).getName(), x+width/2+width/2, y+height+sh1); + } + 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); + g.drawString(((ELNConnectingPoint) connectingPoint[0]).getName(), x+width/2+width/2, y); + g.drawString(((ELNConnectingPoint) connectingPoint[1]).getName(), x+width/2+width/2, y+height+sh1); + } + } else if (position == 3) { + if (first == false) { + first = true; + old = width; + width = height; + height = old; + } + + ((ELNConnectingPoint) connectingPoint[0]).setW(h0); + ((ELNConnectingPoint) connectingPoint[0]).setH(w0); + ((ELNConnectingPoint) connectingPoint[1]).setW(h1); + ((ELNConnectingPoint) connectingPoint[1]).setH(w1); + + 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 / 2); + 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); + g.drawString(((ELNConnectingPoint) connectingPoint[1]).getName(), x - sw1, + y + height / 2 + height / 4 + sh1); + g.drawString(((ELNConnectingPoint) connectingPoint[0]).getName(), x + width, + y + height / 2 + height / 4 + 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)) { + rotateLeft(g); + g.drawString(((ELNConnectingPoint) connectingPoint[1]).getName(), x - sw1, + y + height / 2 + height / 4 + sh1); + g.drawString(((ELNConnectingPoint) connectingPoint[0]).getName(), x + width, + y + height / 2 + height / 4 + 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)) { + rotateRight(g); + g.drawString(((ELNConnectingPoint) connectingPoint[1]).getName(), x - sw0, + y + height / 2 + height / 4 + sh0); + g.drawString(((ELNConnectingPoint) connectingPoint[0]).getName(), x + width, + y + height / 2 + height / 4 + 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)) { + rotateRight(g); + g.drawString(((ELNConnectingPoint) connectingPoint[0]).getName(), x - sw0, + y + height / 2 + height / 4 + sh0); + g.drawString(((ELNConnectingPoint) connectingPoint[1]).getName(), x + width, + y + height / 2 + height / 4 + sh1); + } + } + g.setColor(c); + g.setFont(fold); + } + + private void rotateTop(Graphics g) { + int [] ptx0 = {x+width/2, x+width/2}; + int [] pty0 = {y, y+height}; + g.drawPolygon(ptx0, pty0, 2); + int [] ptx1 = {x+width/2+width/4, x+width/2+width/4+width/8, x+width/2+width/4+width/8, x+width/2+width/4+width/8, x+width/2+width/4+width/8, x+width}; + int [] pty1 = {y+height/4-height/8, y+height/4-height/8, y+height/4-height/8-width/8, y+height/4-height/8+width/8, y+height/4-height/8, y+height/4-height/8}; + g.drawPolygon(ptx1, pty1, 6); + int [] ptx2 = {x+width/2+width/4, x+width}; + int [] pty2 = {y+3*height/4+height/8, y+3*height/4+height/8}; + g.drawPolygon(ptx2, pty2, 2); + g.drawOval(x, y+height/4, width, height/2); + } + + private void rotateBottom(Graphics g) { + int [] ptx0 = {x+width/2, x+width/2}; + int [] pty0 = {y, y+height}; + g.drawPolygon(ptx0, pty0, 2); + int [] ptx1 = {x+width/2+width/4, x+width/2+width/4+width/8, x+width/2+width/4+width/8, x+width/2+width/4+width/8, x+width/2+width/4+width/8, x+width}; + int [] pty1 = {y+3*height/4+height/8, y+3*height/4+height/8, y+3*height/4+height/8+width/8, y+3*height/4+height/8-width/8, y+3*height/4+height/8, y+3*height/4+height/8}; + g.drawPolygon(ptx1, pty1, 6); + int [] ptx2 = {x+width/2+width/4, x+width}; + int [] pty2 = {y+height/4-height/8, y+height/4-height/8}; + g.drawPolygon(ptx2, pty2, 2); + g.drawOval(x, y+height/4, width, height/2); + } + + private void rotateRight(Graphics g) { + int [] ptx0 = {x, x+width}; + int [] pty0 = {y+height/2, y+height/2}; + g.drawPolygon(ptx0, pty0, 2); + int [] ptx1 = {x+width/4-width/8, x+width/4-width/8, x+width/4-width/8-height/8, x+width/4-width/8+height/8, x+width/4-width/8, x+width/4-width/8}; + int [] pty1 = {y+height/2-height/4, y+height/2-height/4-height/8, y+height/2-height/4-height/8, y+height/2-height/4-height/8, y+height/2-height/4-height/8, y}; + g.drawPolygon(ptx1, pty1, 6); + int [] ptx2 = {x+3*width/4+width/8, x+3*width/4+width/8}; + int [] pty2 = {y+height/2-height/4, y}; + g.drawPolygon(ptx2, pty2, 2); + g.drawOval(x+width/4, y, width/2, height); + } + + private void rotateLeft(Graphics g) { + int [] ptx0 = {x, x+width}; + int [] pty0 = {y+height/2, y+height/2}; + g.drawPolygon(ptx0, pty0, 2); + int [] ptx1 = {x+width-width/8, x+width-width/8, x+width-width/8-height/8, x+width-width/8+height/8, x+width-width/8, x+width-width/8}; + int [] pty1 = {y+height/2-height/4, y+height/2-height/4-height/8, y+height/2-height/4-height/8, y+height/2-height/4-height/8, y+height/2-height/4-height/8, y}; + g.drawPolygon(ptx1, pty1, 6); + int [] ptx2 = {x+width/8, x+width/8}; + int [] pty2 = {y+height/2-height/4, y}; + g.drawPolygon(ptx2, pty2, 2); + g.drawOval(x+width/4, y, width/2, height); + } + + 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_INDEPENDENT_VOLTAGE_SOURCE; + } + + public boolean editOndoubleClick(JFrame frame) { + JDialogELNComponentIndependentVoltageSource jde = new JDialogELNComponentIndependentVoltageSource(this); + jde.setVisible(true); + return true; + } + + public StringBuffer encode(String data) { + StringBuffer databuf = new StringBuffer(data); + StringBuffer buffer = new StringBuffer(""); + for(int pos = 0; pos != data.length(); pos++) { + char c = databuf.charAt(pos); + switch(c) { + case '\u03BC' : + buffer.append("μ"); + break; + default : + buffer.append(databuf.charAt(pos)); + break; + } + } + return buffer; + } + + protected String translateExtraParam() { + StringBuffer sb = new StringBuffer("<extraparam>\n"); + sb.append("<attributes init_value=\"" + initValue); + sb.append("\" offset=\"" + offset); + sb.append("\" amplitude=\"" + amplitude); + sb.append("\" frequency=\"" + frequency); + sb.append("\" unit0=\"" + encode(unit0)); + sb.append("\" phase=\"" + phase); + sb.append("\" delay=\"" + delay); + sb.append("\" ac_amplitude=\"" + acAmplitude); + sb.append("\" ac_phase=\"" + acPhase); + sb.append("\" ac_noise_amplitude=\"" + acNoiseAmplitude + "\""); + 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 initValue, offset, amplitude, frequency, phase, acAmplitude, acPhase, acNoiseAmplitude; + String delay; + String unit0; + + 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")) { + initValue = Double.parseDouble(elt.getAttribute("init_value")); + offset = Double.parseDouble(elt.getAttribute("offset")); + amplitude = Double.parseDouble(elt.getAttribute("amplitude")); + frequency = Double.parseDouble(elt.getAttribute("frequency")); + unit0 = elt.getAttribute("unit0"); + phase = Double.parseDouble(elt.getAttribute("phase")); + delay = elt.getAttribute("delay"); + acAmplitude = Double.parseDouble(elt.getAttribute("ac_amplitude")); + acPhase = Double.parseDouble(elt.getAttribute("ac_phase")); + acNoiseAmplitude = Double.parseDouble(elt.getAttribute("ac_noise_amplitude")); + setInitValue(initValue); + setOffset(offset); + setAmplitude(amplitude); + setFrequency(frequency); + setUnit0(unit0); + setPhase(phase); + setDelay(delay); + setAcAmplitude(acAmplitude); + setAcPhase(acPhase); + setAcNoiseAmplitude(acNoiseAmplitude); + } + } + } + } + } + } 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 getInitValue() { + return initValue; + } + + public void setInitValue(double _initValue) { + initValue = _initValue; + } + + public double getOffset() { + return offset; + } + + public void setOffset(double _offset) { + offset = _offset; + } + + public double getAmplitude() { + return amplitude; + } + + public void setAmplitude(double _amplitude) { + amplitude = _amplitude; + } + + public double getFrequency() { + return frequency; + } + + public void setFrequency(double _frequency) { + frequency = _frequency; + } + + public double getPhase() { + return phase; + } + + public void setPhase(double _phase) { + phase = _phase; + } + + public double getAcAmplitude() { + return acAmplitude; + } + + public void setAcAmplitude(double _acAmplitude) { + acAmplitude = _acAmplitude; + } + + public double getAcPhase() { + return acPhase; + } + + public void setAcPhase(double _acPhase) { + acPhase = _acPhase; + } + + public double getAcNoiseAmplitude() { + return acNoiseAmplitude; + } + + public void setAcNoiseAmplitude(double _acNoiseAmplitude) { + acNoiseAmplitude = _acNoiseAmplitude; + } + + public String getDelay() { + return delay; + } + + public void setDelay(String _delay) { + delay = _delay; + } + + public String getUnit0() { + return unit0; + } + + public void setUnit0(String _unit0) { + unit0 = _unit0; + } +} diff --git a/src/main/java/ui/eln/sca_eln/ELNComponentInductor.java b/src/main/java/ui/eln/sca_eln/ELNComponentInductor.java index efa1cff74b4a75313bca799f2ed090cb5d2df572..5a7b5b3e23abbf14f3cc02cac9ad8d9012ae37e3 100644 --- a/src/main/java/ui/eln/sca_eln/ELNComponentInductor.java +++ b/src/main/java/ui/eln/sca_eln/ELNComponentInductor.java @@ -45,291 +45,569 @@ import org.w3c.dom.Node; import org.w3c.dom.NodeList; import ui.*; import ui.eln.ELNConnectingPoint; -import ui.util.IconManager; import ui.window.JDialogELNComponentInductor; import javax.swing.*; import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; /** - * Class ELNComponentSelf - * Self to be used in ELN diagrams + * Class ELNComponentInductor + * Inductor to be used in ELN diagrams * Creation: 12/06/2018 * @version 1.0 12/06/2018 * @author Irina Kit Yan LEE */ -public class ELNComponentInductor extends TGCScalableWithInternalComponent { - protected Color myColor; - protected int orientation; +public class ELNComponentInductor extends TGCScalableWithInternalComponent implements ActionListener { + protected Color myColor; + protected int orientation; private int maxFontSize = 14; - private int minFontSize = 4; - private int currentFontSize = -1; -// protected int oldx, oldy; -// protected int currentOrientation = GraphicLib.NORTH; - - private int textX = 15; // border for ports - private double dtextX = 0.0; - protected int decPoint = 3; - - private int fact = 2; - - // Parameters + private int minFontSize = 4; + private int currentFontSize = -1; + + private int textX = 15; + private double dtextX = 0.0; + protected int decPoint = 3; + private double val, phi0; private String unit0, unit1; - - public ELNComponentInductor(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(50*fact, 20*fact); - - 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("L"); - - myImageIcon = IconManager.imgic1206; - - // Initialization of inductor attributes - setVal(1.0); - setPhi0(0.0); - setUnit0("H"); - setUnit1("Wb"); - } - - public void initConnectingPoint(int nb) { - nbConnectingPoint = nb; - connectingPoint = new TGConnectingPoint[nb]; - connectingPoint[0] = new ELNConnectingPoint(this, 0, 0, true, true, 0.0, 0.5); - connectingPoint[1] = new ELNConnectingPoint(this, 0, 0, true, true, 1.0, 0.5); - } - - public Color getMyColor() { - return myColor; - } - - public void internalDrawing(Graphics g) { - Font f = g.getFont(); - Font fold = f; - -// if ((x != oldx) | (oldy != y)) { -// // Component has moved! -// manageMove(); -// oldx = x; -// oldy = y; -// } - - if (this.rescaled && !this.tdp.isScaled()) { - this.rescaled = false; - // Must set the font size... - // Incrementally find the biggest font not greater than max_font size - // If font is less than min_font, no text is displayed - - 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); - } - - // Zoom is assumed to be computed - Color c = g.getColor(); - g.drawLine(x, y+height/2, x+width/5, y+height/2); - g.drawLine(x+4*width/5, y+height/2, x+width, y+height/2); - g.drawArc(x+width/5, y, width/5, height, 0, 180); - g.drawArc(x+2*width/5, y, width/5, height, 0, 180); - g.drawArc(x+3*width/5, y, width/5, height, 0, 180); - g.setColor(c); - - // Set font size - int attributeFontSize = this.currentFontSize * 5 / 6; - 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/(2*fact)); - - g.setFont(fold); - } - -// public void manageMove() { -// if (father != null) { -// Point p = GraphicLib.putPointOnRectangle(x+(width/2), y+(height/2), father.getX(), father.getY(), father.getWidth(), father.getHeight()); -// -// x = p.x - width/2; -// y = p.y - height/2; -// -// setMoveCd(x, y); -// -// int orientation = GraphicLib.getCloserOrientation(x+(width/2), y+(height/2), father.getX(), father.getY(), father.getWidth(), father.getHeight()); -// if (orientation != currentOrientation) { -//// setOrientation(orientation); -// } -// } -// } - - // TGConnecting points .. - // TODO : change the orientation of the component -// public void setOrientation(int orientation) { -// currentOrientation = orientation; -// double w0, h0, w1, h1; -// -//// switch(orientation) { -////// case GraphicLib.NORTH: -////// w0 = 0.5; -////// h0 = 0.0; -////// break; -//// case GraphicLib.WEST: -//// w0 = 0.0; -//// h0 = 0.5; -//// break; -////// case GraphicLib.SOUTH: -////// w0 = 0.5; -////// h0 = 1.0; -////// break; -//// case GraphicLib.EAST: -//// default: -//// w0 = 1.0; -//// h0 = 0.5; -//// } -// -// w0 = 0.0; -// h0 = 0.5; -// w1 = 1.0; -// h1 = 0.5; -// System.out.println(connectingPoint.length); -// ((ELNConnectingPoint) connectingPoint[0]).setW(w0); -// ((ELNConnectingPoint) connectingPoint[0]).setH(h0); -// ((ELNConnectingPoint) connectingPoint[1]).setW(w1); -// ((ELNConnectingPoint) connectingPoint[1]).setH(h1); -// } - - 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_INDUCTOR; - } - - public boolean editOndoubleClick(JFrame frame) { - JDialogELNComponentInductor jde = new JDialogELNComponentInductor(this); - jde.setVisible(true); - return true; - } - - public StringBuffer encode(String data) { - StringBuffer databuf = new StringBuffer(data); - StringBuffer buffer = new StringBuffer(""); - for(int pos = 0; pos != data.length(); pos++) { - char c = databuf.charAt(pos); - switch(c) { - case '\u03BC' : - buffer.append("μ"); - break; - default : - buffer.append(databuf.charAt(pos)); - break; - } - } - return buffer; - } - - protected String translateExtraParam() { - StringBuffer sb = new StringBuffer("<extraparam>\n"); - sb.append("<attributes value=\"" + val); - sb.append("\" unit0=\""); - sb.append(encode(unit0)); - sb.append("\" phi0=\"" + phi0); - sb.append("\" unit1=\""); - sb.append(encode(unit1)); - sb.append("\""); - 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 value, phi0; - String unit0, unit1; - - 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")) { - value = Double.parseDouble(elt.getAttribute("value")); - phi0 = Double.parseDouble(elt.getAttribute("phi0")); + + 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 ELNComponentInductor(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(100, 20); + + 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("L"); + + setVal(1.0); + setPhi0(0.0); + setUnit0("H"); + setUnit1("Wb"); + + 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.5, "p"); + connectingPoint[1] = new ELNConnectingPoint(this, 0, 0, true, true, 1.0, 0.5, "n"); + } + + public Color getMyColor() { + return myColor; + } + + public void internalDrawing(Graphics g) { + 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(); + double w0 = ((ELNConnectingPoint) connectingPoint[0]).getW(); + double h0 = ((ELNConnectingPoint) connectingPoint[0]).getH(); + double w1 = ((ELNConnectingPoint) connectingPoint[1]).getW(); + double h1 = ((ELNConnectingPoint) connectingPoint[1]).getH(); + + if (position == 0) { + if (first == false) { + first = true; + old = width; + width = height; + height = old; + } + + ((ELNConnectingPoint) connectingPoint[0]).setW(w0); + ((ELNConnectingPoint) connectingPoint[0]).setH(h0); + ((ELNConnectingPoint) connectingPoint[1]).setW(w1); + ((ELNConnectingPoint) connectingPoint[1]).setH(h1); + + 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); + 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); + g.drawString(((ELNConnectingPoint) connectingPoint[0]).getName(), x - sw0, + y + height / 2 + height / 4 + sh0); + g.drawString(((ELNConnectingPoint) connectingPoint[1]).getName(), x + width, + y + height / 2 + height / 4 + 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)) { + rotateTop(g); + g.drawString(((ELNConnectingPoint) connectingPoint[1]).getName(), x - sw1, + y + height / 2 + height / 4 + sh1); + g.drawString(((ELNConnectingPoint) connectingPoint[0]).getName(), x + width, + y + height / 2 + height / 4 + 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)) { + rotateBottom(g); + g.drawString(((ELNConnectingPoint) connectingPoint[0]).getName(), x - sw0, + y + height / 2 + height / 4 + sh0); + g.drawString(((ELNConnectingPoint) connectingPoint[1]).getName(), x + width, + y + height / 2 + height / 4 + 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)) { + rotateBottom(g); + g.drawString(((ELNConnectingPoint) connectingPoint[1]).getName(), x - sw1, + y + height / 2 + height / 4 + sh1); + g.drawString(((ELNConnectingPoint) connectingPoint[0]).getName(), x + width, + y + height / 2 + height / 4 + sh0); + } + } else if (position == 1) { + if (first == false) { + first = true; + old = width; + width = height; + height = old; + } + + ((ELNConnectingPoint) connectingPoint[0]).setW(h0); + ((ELNConnectingPoint) connectingPoint[0]).setH(w0); + ((ELNConnectingPoint) connectingPoint[1]).setW(h1); + ((ELNConnectingPoint) connectingPoint[1]).setH(w1); + + int attributeFontSize = this.currentFontSize * 5 / 6; + int sh0 = g.getFontMetrics().getAscent(); + 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 / 5); + 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); + g.drawString(((ELNConnectingPoint) connectingPoint[0]).getName(), x + width / 2 + width / 2, y); + g.drawString(((ELNConnectingPoint) connectingPoint[1]).getName(), x + width / 2 + width / 2, + y + height + sh1); + } + 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)) { + rotateRight(g); + g.drawString(((ELNConnectingPoint) connectingPoint[1]).getName(), x + width / 2 + width / 2, y); + g.drawString(((ELNConnectingPoint) connectingPoint[0]).getName(), x + width / 2 + width / 2, + y + height + sh0); + } + 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)) { + rotateLeft(g); + g.drawString(((ELNConnectingPoint) connectingPoint[0]).getName(), x + width / 2 + width / 2, y); + g.drawString(((ELNConnectingPoint) connectingPoint[1]).getName(), x + width / 2 + width / 2, + y + height + sh1); + } + 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); + g.drawString(((ELNConnectingPoint) connectingPoint[1]).getName(), x + width / 2 + width / 2, y); + g.drawString(((ELNConnectingPoint) connectingPoint[0]).getName(), x + width / 2 + width / 2, + y + height + sh0); + } + } else if (position == 2) { + if (first == false) { + first = true; + old = width; + width = height; + height = old; + } + + ((ELNConnectingPoint) connectingPoint[0]).setW(w0); + ((ELNConnectingPoint) connectingPoint[0]).setH(h0); + ((ELNConnectingPoint) connectingPoint[1]).setW(w1); + ((ELNConnectingPoint) connectingPoint[1]).setH(h1); + + 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); + 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); + g.drawString(((ELNConnectingPoint) connectingPoint[1]).getName(), x - sw1, + y + height / 2 + height / 2 + sh1); + g.drawString(((ELNConnectingPoint) connectingPoint[0]).getName(), x + width, + y + height / 2 + height / 2 + sh0); + } + 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)) { + rotateBottom(g); + g.drawString(((ELNConnectingPoint) connectingPoint[0]).getName(), x - sw0, + y + height / 2 + height / 2 + sh0); + g.drawString(((ELNConnectingPoint) connectingPoint[1]).getName(), x + width, + y + height / 2 + height / 2 + sh1); + } + 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)) { + rotateTop(g); + g.drawString(((ELNConnectingPoint) connectingPoint[1]).getName(), x - sw1, + y + height / 2 + height / 2 + sh1); + g.drawString(((ELNConnectingPoint) connectingPoint[0]).getName(), x + width, + y + height / 2 + height / 2 + sh0); + } + 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); + g.drawString(((ELNConnectingPoint) connectingPoint[0]).getName(), x - sw0, + y + height / 2 + height / 2 + sh0); + g.drawString(((ELNConnectingPoint) connectingPoint[1]).getName(), x + width, + y + height / 2 + height / 2 + sh1); + } + } else if (position == 3) { + if (first == false) { + first = true; + old = width; + width = height; + height = old; + } + + ((ELNConnectingPoint) connectingPoint[0]).setW(h0); + ((ELNConnectingPoint) connectingPoint[0]).setH(w0); + ((ELNConnectingPoint) connectingPoint[1]).setW(h1); + ((ELNConnectingPoint) connectingPoint[1]).setH(w1); + + int attributeFontSize = this.currentFontSize * 5 / 6; + int sh0 = g.getFontMetrics().getAscent(); + 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 / 5); + 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); + g.drawString(((ELNConnectingPoint) connectingPoint[1]).getName(), x + width / 2 + width / 2, y); + g.drawString(((ELNConnectingPoint) connectingPoint[0]).getName(), x + width / 2 + width / 2, + y + height + sh0); + } + 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)) { + rotateLeft(g); + g.drawString(((ELNConnectingPoint) connectingPoint[0]).getName(), x + width / 2 + width / 2, y); + g.drawString(((ELNConnectingPoint) connectingPoint[1]).getName(), x + width / 2 + width / 2, + y + height + sh1); + } + 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)) { + rotateRight(g); + g.drawString(((ELNConnectingPoint) connectingPoint[1]).getName(), x + width / 2 + width / 2, y); + g.drawString(((ELNConnectingPoint) connectingPoint[0]).getName(), x + width / 2 + width / 2, + y + height + sh0); + } + 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); + g.drawString(((ELNConnectingPoint) connectingPoint[0]).getName(), x + width / 2 + width / 2, y); + g.drawString(((ELNConnectingPoint) connectingPoint[1]).getName(), x + width / 2 + width / 2, + y + height + sh1); + } + } + g.setColor(c); + g.setFont(fold); + } + + private void rotateTop(Graphics g) { + g.drawLine(x, y + height / 2, x + width / 5, y + height / 2); + g.drawLine(x + 4 * width / 5, y + height / 2, x + width, y + height / 2); + g.drawArc(x + width / 5, y, width / 5, height, 0, 180); + g.drawArc(x + 2 * width / 5, y, width / 5, height, 0, 180); + g.drawArc(x + 3 * width / 5, y, width / 5, height, 0, 180); + } + + private void rotateBottom(Graphics g) { + g.drawLine(x, y + height / 2, x + width / 5, y + height / 2); + g.drawLine(x + 4 * width / 5, y + height / 2, x + width, y + height / 2); + g.drawArc(x + width / 5, y, width / 5, height, 180, 180); + g.drawArc(x + 2 * width / 5, y, width / 5, height, 180, 180); + g.drawArc(x + 3 * width / 5, y, width / 5, height, 180, 180); + } + + private void rotateRight(Graphics g) { + g.drawLine(x + width / 2, y, x + width / 2, y + height / 5); + g.drawLine(x + width / 2, y + 4 * height / 5, x + width / 2, y + height); + g.drawArc(x, y + height / 5, width, height / 5, 270, 180); + g.drawArc(x, y + 2 * height / 5, width, height / 5, 270, 180); + g.drawArc(x, y + 3 * height / 5, width, height / 5, 270, 180); + } + + private void rotateLeft(Graphics g) { + g.drawLine(x + width / 2, y, x + width / 2, y + height / 5); + g.drawLine(x + width / 2, y + 4 * height / 5, x + width / 2, y + height); + g.drawArc(x, y + height / 5, width, height / 5, 90, 180); + g.drawArc(x, y + 2 * height / 5, width, height / 5, 90, 180); + g.drawArc(x, y + 3 * height / 5, width, height / 5, 90, 180); + } + + 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_INDUCTOR; + } + + public boolean editOndoubleClick(JFrame frame) { + JDialogELNComponentInductor jde = new JDialogELNComponentInductor(this); + jde.setVisible(true); + return true; + } + + public StringBuffer encode(String data) { + StringBuffer databuf = new StringBuffer(data); + StringBuffer buffer = new StringBuffer(""); + for (int pos = 0; pos != data.length(); pos++) { + char c = databuf.charAt(pos); + switch (c) { + case '\u03BC': + buffer.append("μ"); + break; + default: + buffer.append(databuf.charAt(pos)); + break; + } + } + return buffer; + } + + protected String translateExtraParam() { + StringBuffer sb = new StringBuffer("<extraparam>\n"); + sb.append("<attributes value=\"" + val); + sb.append("\" unit0=\""); + sb.append(encode(unit0)); + sb.append("\" phi0=\"" + phi0); + sb.append("\" unit1=\""); + sb.append(encode(unit1)); + sb.append("\""); + 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 value, phi0; + String unit0, unit1; + + 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")) { + value = Double.parseDouble(elt.getAttribute("value")); + phi0 = Double.parseDouble(elt.getAttribute("phi0")); unit0 = elt.getAttribute("unit0"); unit1 = elt.getAttribute("unit1"); setVal(value); setPhi0(phi0); setUnit0(unit0); setUnit1(unit1); - } - } - } - } - } - } catch (Exception e) { - throw new MalformedModelingException(); - } - } - - public int getDefaultConnector() { - return TGComponentManager.ELN_CONNECTOR; - } - - public double getVal() { + } + } + } + } + } + } 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 getVal() { return val; } public void setVal(double _val) { val = _val; } - + public double getPhi0() { return phi0; } - + public void setPhi0(double _phi0) { phi0 = _phi0; } @@ -341,12 +619,12 @@ public class ELNComponentInductor extends TGCScalableWithInternalComponent { public void setUnit0(String _unit0) { unit0 = _unit0; } - + public String getUnit1() { return unit1; } - + public void setUnit1(String _unit1) { unit1 = _unit1; } -} \ No newline at end of file +} diff --git a/src/main/java/ui/eln/sca_eln/ELNComponentResistor.java b/src/main/java/ui/eln/sca_eln/ELNComponentResistor.java index 66d9888b84e7dccf6408a0c708597d0f607926df..c8a2a6a13ceabfca8db4c09e91047436f0ee7f07 100644 --- a/src/main/java/ui/eln/sca_eln/ELNComponentResistor.java +++ b/src/main/java/ui/eln/sca_eln/ELNComponentResistor.java @@ -45,295 +45,416 @@ import org.w3c.dom.Node; import org.w3c.dom.NodeList; import ui.*; import ui.eln.ELNConnectingPoint; -import ui.util.IconManager; import ui.window.JDialogELNComponentResistor; import javax.swing.*; import java.awt.*; -import java.awt.geom.AffineTransform; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; /** - * Class ELNComponentResistor - * Resistor to be used in ELN diagrams + * Class ELNComponentResistor + * Resistor to be used in ELN diagrams * Creation: 12/06/2018 * @version 1.0 12/06/2018 * @author Irina Kit Yan LEE */ -public class ELNComponentResistor extends TGCScalableWithInternalComponent { - protected Color myColor; - protected int orientation; +public class ELNComponentResistor extends TGCScalableWithInternalComponent implements ActionListener { + protected Color myColor; + protected int orientation; private int maxFontSize = 14; - private int minFontSize = 4; - private int currentFontSize = -1; -// protected int oldx, oldy; -// protected int currentOrientation = GraphicLib.NORTH; - - private int textX = 15; // border for ports - private double dtextX = 0.0; - protected int decPoint = 3; - - private int fact = 2; - - // Parameters + private int minFontSize = 4; + private int currentFontSize = -1; + + private int textX = 15; + private double dtextX = 0.0; + protected int decPoint = 3; + private double val; private String unit; - - public ELNComponentResistor(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(50*fact, 10*fact); - - 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("R"); - - myImageIcon = IconManager.imgic1206; - - // Initialization of self attributes - setVal(1.0); - setUnit("\u03A9"); - } - - public void initConnectingPoint(int nb) { - nbConnectingPoint = nb; - connectingPoint = new TGConnectingPoint[nb]; - connectingPoint[0] = new ELNConnectingPoint(this, 0, 0, true, true, 0.0, 0.5); - connectingPoint[1] = new ELNConnectingPoint(this, 0, 0, true, true, 1.0, 0.5); - } - - public Color getMyColor() { - return myColor; - } - - public void internalDrawing(Graphics gr) { - Graphics2D g = (Graphics2D) gr; - Font f = g.getFont(); - Font fold = f; - -// if ((x != oldx) | (oldy != y)) { -// // Component has moved! -// manageMove(); -// oldx = x; -// oldy = y; -// } - - if (this.rescaled && !this.tdp.isScaled()) { - this.rescaled = false; - // Must set the font size... - // Incrementally find the biggest font not greater than max_font size - // If font is less than min_font, no text is displayed - - 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); - } - - // Zoom is assumed to be computed + + private int position = 0; + private boolean fv = false, fh = false; + private int old; + private boolean first; + + public ELNComponentResistor(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(100, 20); + + 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("R"); + + setVal(1.0); + setUnit("\u03A9"); + + 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.5, "p"); + connectingPoint[1] = new ELNConnectingPoint(this, 0, 0, true, true, 1.0, 0.5, "n"); + } + + public Color getMyColor() { + return myColor; + } + + public void internalDrawing(Graphics g) { + 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(); - int [] ptx = {x, x+width/4, x+width/4, x+3*width/4, x+3*width/4, x+width, x+3*width/4, x+3*width/4, x+width/4, x+width/4}; - int [] pty = {y+height/2, y+height/2, y, y, y+height/2, y+height/2, y+height/2, y+height, y+height, y+height/2}; - Polygon p = new Polygon(ptx, pty, 10); - g.drawPolygon(p); - - //------------------ - // Save the current transform of the graphics contexts. - AffineTransform saveTransform = g.getTransform(); - // Create a identity affine transform, and apply to the Graphics2D context - AffineTransform identity = new AffineTransform(); - g.setTransform(identity); - - // Paint Shape (with identity transform), centered at (0, 0) as defined. - g.rotate(Math.toRadians(90)); - g.setTransform(identity); - g.drawPolygon(p); - g.fill(p); - - // Restore original transform before returning - g.setTransform(saveTransform); - //------------------ - - //------------------ - + double w0 = ((ELNConnectingPoint) connectingPoint[0]).getW(); + double h0 = ((ELNConnectingPoint) connectingPoint[0]).getH(); + double w1 = ((ELNConnectingPoint) connectingPoint[1]).getW(); + double h1 = ((ELNConnectingPoint) connectingPoint[1]).getH(); + + if (position == 0) { + if (first == false) { + first = true; + old = width; + width = height; + height = old; + } + + rotateTopBottom(g); + + ((ELNConnectingPoint) connectingPoint[0]).setW(w0); + ((ELNConnectingPoint) connectingPoint[0]).setH(h0); + ((ELNConnectingPoint) connectingPoint[1]).setW(w1); + ((ELNConnectingPoint) connectingPoint[1]).setH(h1); + + 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); + g.setFont(f.deriveFont(Font.PLAIN)); + + if (fh == true) { + g.drawString(((ELNConnectingPoint) connectingPoint[1]).getName(), x - sw1, + y + height / 2 + height / 2 + sh1); + g.drawString(((ELNConnectingPoint) connectingPoint[0]).getName(), x + width, + y + height / 2 + height / 2 + sh0); + } else { + g.drawString(((ELNConnectingPoint) connectingPoint[0]).getName(), x - sw0, + y + height / 2 + height / 2 + sh0); + g.drawString(((ELNConnectingPoint) connectingPoint[1]).getName(), x + width, + y + height / 2 + height / 2 + sh1); + } + } else if (position == 1) { + if (first == false) { + first = true; + old = width; + width = height; + height = old; + } + + rotateRightLeft(g); + + ((ELNConnectingPoint) connectingPoint[0]).setW(h0); + ((ELNConnectingPoint) connectingPoint[0]).setH(w0); + ((ELNConnectingPoint) connectingPoint[1]).setW(h1); + ((ELNConnectingPoint) connectingPoint[1]).setH(w1); + + int attributeFontSize = this.currentFontSize * 5 / 6; + int sh0 = g.getFontMetrics().getAscent(); + 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 / 5); + g.setFont(f.deriveFont(Font.PLAIN)); + + if (fv == true) { + g.drawString(((ELNConnectingPoint) connectingPoint[1]).getName(), x + width / 2 + width / 2, y); + g.drawString(((ELNConnectingPoint) connectingPoint[0]).getName(), x + width / 2 + width / 2, + y + height + sh0); + } else { + g.drawString(((ELNConnectingPoint) connectingPoint[0]).getName(), x + width / 2 + width / 2, y); + g.drawString(((ELNConnectingPoint) connectingPoint[1]).getName(), x + width / 2 + width / 2, + y + height + sh1); + } + } else if (position == 2) { + if (first == false) { + first = true; + old = width; + width = height; + height = old; + } + + rotateTopBottom(g); + + ((ELNConnectingPoint) connectingPoint[0]).setW(w0); + ((ELNConnectingPoint) connectingPoint[0]).setH(h0); + ((ELNConnectingPoint) connectingPoint[1]).setW(w1); + ((ELNConnectingPoint) connectingPoint[1]).setH(h1); + + 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); + g.setFont(f.deriveFont(Font.PLAIN)); + + if (fh == true) { + g.drawString(((ELNConnectingPoint) connectingPoint[0]).getName(), x - sw1, + y + height / 2 + height / 2 + sh1); + g.drawString(((ELNConnectingPoint) connectingPoint[1]).getName(), x + width, + y + height / 2 + height / 2 + sh0); + } else { + g.drawString(((ELNConnectingPoint) connectingPoint[1]).getName(), x - sw0, + y + height / 2 + height / 2 + sh0); + g.drawString(((ELNConnectingPoint) connectingPoint[0]).getName(), x + width, + y + height / 2 + height / 2 + sh1); + } + } else if (position == 3) { + if (first == false) { + first = true; + old = width; + width = height; + height = old; + } + + rotateRightLeft(g); + + ((ELNConnectingPoint) connectingPoint[0]).setW(h0); + ((ELNConnectingPoint) connectingPoint[0]).setH(w0); + ((ELNConnectingPoint) connectingPoint[1]).setW(h1); + ((ELNConnectingPoint) connectingPoint[1]).setH(w1); + + int attributeFontSize = this.currentFontSize * 5 / 6; + int sh0 = g.getFontMetrics().getAscent(); + 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 / 5); + g.setFont(f.deriveFont(Font.PLAIN)); + + if (fv == true) { + g.drawString(((ELNConnectingPoint) connectingPoint[0]).getName(), x + width / 2 + width / 2, y); + g.drawString(((ELNConnectingPoint) connectingPoint[1]).getName(), x + width / 2 + width / 2, + y + height + sh0); + } else { + g.drawString(((ELNConnectingPoint) connectingPoint[1]).getName(), x + width / 2 + width / 2, y); + g.drawString(((ELNConnectingPoint) connectingPoint[0]).getName(), x + width / 2 + width / 2, + y + height + sh1); + } + } g.setColor(c); - - // Set font size - int attributeFontSize = this.currentFontSize * 5 / 6; - 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/fact); - - g.setFont(fold); - } - -// public void manageMove() { -// if (father != null) { -// Point p = GraphicLib.putPointOnRectangle(x+(width/2), y+(height/2), father.getX(), father.getY(), father.getWidth(), father.getHeight()); -// -// x = p.x - width/2; -// y = p.y - height/2; -// -// setMoveCd(x, y); -// -// int orientation = GraphicLib.getCloserOrientation(x+(width/2), y+(height/2), father.getX(), father.getY(), father.getWidth(), father.getHeight()); -// if (orientation != currentOrientation) { -//// setOrientation(orientation); -// } -// } -// } - - // TGConnecting points .. - // TODO : change the orientation of the component -// public void setOrientation(int orientation) { -// currentOrientation = orientation; -// double w0, h0, w1, h1; -// -//// switch(orientation) { -////// case GraphicLib.NORTH: -////// w0 = 0.5; -////// h0 = 0.0; -////// break; -//// case GraphicLib.WEST: -//// w0 = 0.0; -//// h0 = 0.5; -//// break; -////// case GraphicLib.SOUTH: -////// w0 = 0.5; -////// h0 = 1.0; -////// break; -//// case GraphicLib.EAST: -//// default: -//// w0 = 1.0; -//// h0 = 0.5; -//// } -// -// w0 = 0.0; -// h0 = 0.5; -// w1 = 1.0; -// h1 = 0.5; -// System.out.println(connectingPoint.length); -// ((ELNConnectingPoint) connectingPoint[0]).setW(w0); -// ((ELNConnectingPoint) connectingPoint[0]).setH(h0); -// ((ELNConnectingPoint) connectingPoint[1]).setW(w1); -// ((ELNConnectingPoint) connectingPoint[1]).setH(h1); -// } - - 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_RESISTOR; - } - - public boolean editOndoubleClick(JFrame frame) { - JDialogELNComponentResistor jde = new JDialogELNComponentResistor(this); - jde.setVisible(true); - return true; - } - - public StringBuffer encode(String data) { - StringBuffer databuf = new StringBuffer(data); - StringBuffer buffer = new StringBuffer(""); - for(int pos = 0; pos != data.length(); pos++) { - char c = databuf.charAt(pos); - switch(c) { - case '\u03A9' : - buffer.append("Ω"); - break; - case '\u03BC' : - buffer.append("μ"); - break; - default : - buffer.append(databuf.charAt(pos)); - break; - } - } - return buffer; - } - - protected String translateExtraParam() { - StringBuffer sb = new StringBuffer("<extraparam>\n"); - sb.append("<attributes value=\"" + val); - sb.append("\" unit=\""); - sb.append(encode(unit)); + g.setFont(fold); + } + + private void rotateTopBottom(Graphics g) { + int[] ptx = { x, x + width / 5, x + width / 5, x + 4 * width / 5, x + 4 * width / 5, x + width, + x + 4 * width / 5, x + 4 * width / 5, x + width / 5, x + width / 5 }; + int[] pty = { y + height / 2, y + height / 2, y, y, y + height / 2, y + height / 2, y + height / 2, y + height, + y + height, y + height / 2 }; + g.drawPolygon(ptx, pty, 10); + } + + private void rotateRightLeft(Graphics g) { + int[] ptx = { x + width / 2, x + width / 2, x, x, x + width / 2, x + width / 2, x + width / 2, x + width, + x + width, x + width / 2 }; + int[] pty = { y, y + height / 5, y + height / 5, y + 4 * height / 5, y + 4 * height / 5, y + height, + y + 4 * height / 5, y + 4 * height / 5, y + height / 5, y + height / 5 }; + g.drawPolygon(ptx, pty, 10); + } + + 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_RESISTOR; + } + + public boolean editOndoubleClick(JFrame frame) { + JDialogELNComponentResistor jde = new JDialogELNComponentResistor(this); + jde.setVisible(true); + return true; + } + + public StringBuffer encode(String data) { + StringBuffer databuf = new StringBuffer(data); + StringBuffer buffer = new StringBuffer(""); + for (int pos = 0; pos != data.length(); pos++) { + char c = databuf.charAt(pos); + switch (c) { + case '\u03A9': + buffer.append("Ω"); + break; + case '\u03BC': + buffer.append("μ"); + break; + default: + buffer.append(databuf.charAt(pos)); + break; + } + } + return buffer; + } + + protected String translateExtraParam() { + StringBuffer sb = new StringBuffer("<extraparam>\n"); + sb.append("<attributes value=\"" + val); + sb.append("\" unit=\""); + sb.append(encode(unit)); sb.append("\""); - 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 value; - String unit; - - 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")) { - value = Double.parseDouble(elt.getAttribute("value")); + 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 value; + String unit; + + 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")) { + value = Double.parseDouble(elt.getAttribute("value")); unit = elt.getAttribute("unit"); setVal(value); setUnit(unit); - } - } - } - } - } - } catch (Exception e) { - throw new MalformedModelingException(); - } - } - - public int getDefaultConnector() { - return TGComponentManager.ELN_CONNECTOR; - } - - public double getVal() { + } + } + } + } + } + } 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) { + fv = false; + fh = false; + 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 (fv == false) { + fv = true; + } else { + fv = false; + } + } + if (e.getActionCommand().equals("Flip horizontally")) { + if (fh == false) { + fh = true; + } else { + fh = false; + } + } + } + + public int getDefaultConnector() { + return TGComponentManager.ELN_CONNECTOR; + } + + public double getVal() { return val; } @@ -348,4 +469,4 @@ public class ELNComponentResistor extends TGCScalableWithInternalComponent { public void setUnit(String _unit) { unit = _unit; } -} \ No newline at end of file +} diff --git a/src/main/java/ui/eln/sca_eln/ELNComponentTransmissionLine.java b/src/main/java/ui/eln/sca_eln/ELNComponentTransmissionLine.java index fd5f07ed4d438b269b7d2e88e3cacf89bab5dd80..97c0825a564763aebf645b88425dc65c98285892 100644 --- a/src/main/java/ui/eln/sca_eln/ELNComponentTransmissionLine.java +++ b/src/main/java/ui/eln/sca_eln/ELNComponentTransmissionLine.java @@ -45,287 +45,626 @@ import org.w3c.dom.Node; import org.w3c.dom.NodeList; import ui.*; import ui.eln.ELNConnectingPoint; -import ui.util.IconManager; import ui.window.JDialogELNComponentTransmissionLine; import javax.swing.*; import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; /** - * Class ELNComponentTransmissionLine - * Transmission line to be used in ELN diagrams + * Class ELNComponentTransmissionLine + * Transmission line to be used in ELN diagrams * Creation: 15/06/2018 * @version 1.0 15/06/2018 * @author Irina Kit Yan LEE */ -public class ELNComponentTransmissionLine extends TGCScalableWithInternalComponent { - protected Color myColor; - protected int orientation; +public class ELNComponentTransmissionLine extends TGCScalableWithInternalComponent implements ActionListener { + protected Color myColor; + protected int orientation; private int maxFontSize = 14; - private int minFontSize = 4; - private int currentFontSize = -1; -// protected int oldx, oldy; -// protected int currentOrientation = GraphicLib.NORTH; - - private int textX = 15; // border for ports - private double dtextX = 0.0; - protected int decPoint = 3; - - private int fact = 2; - - // Parameters + private int minFontSize = 4; + private int currentFontSize = -1; + + private int textX = 15; + private double dtextX = 0.0; + protected int decPoint = 3; + private double z0, delta0; private String delay; private String unit0, unit2; - - public ELNComponentTransmissionLine(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(60*fact, 40*fact); - - dtextX = textX * oldScaleFactor; - textX = (int)dtextX; - dtextX = dtextX - textX; - - minWidth = 1; - minHeight = 1; - - initConnectingPoint(4); - - addTGConnectingPointsComment(); - - moveable = true; - editable = true; - removable = true; - userResizable = false; - value = tdp.findELNComponentName("TransmissionLine"); - - myImageIcon = IconManager.imgic1206; - - // Initialization of transmission line attributes - setZ0(100.0); - setUnit0("\u03A9"); - setDelay("sc_core::SC_ZERO_TIME"); - setDelta0(0.0); - setUnit2("Hz"); - } - - public void initConnectingPoint(int nb) { - nbConnectingPoint = nb; - connectingPoint = new TGConnectingPoint[nb]; - connectingPoint[0] = new ELNConnectingPoint(this, 0, 0, true, true, 0.0, 0.0); - connectingPoint[1] = new ELNConnectingPoint(this, 0, 0, true, true, 1.0, 0.0); - connectingPoint[2] = new ELNConnectingPoint(this, 0, 0, true, true, 0.0, 1.0); - connectingPoint[3] = new ELNConnectingPoint(this, 0, 0, true, true, 1.0, 1.0); - } - - public Color getMyColor() { - return myColor; - } - - public void internalDrawing(Graphics g) { - Font f = g.getFont(); - Font fold = f; - -// if ((x != oldx) | (oldy != y)) { -// // Component has moved! -// manageMove(); -// oldx = x; -// oldy = y; -// } - - if (this.rescaled && !this.tdp.isScaled()) { - this.rescaled = false; - // Must set the font size... - // Incrementally find the biggest font not greater than max_font size - // If font is less than min_font, no text is displayed - - 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); - } - - // Zoom is assumed to be computed - Color c = g.getColor(); - int [] ptx0 = {x, x+width/6, x+5*width/6, x+width, x+5*width/6, x+width/6}; - int [] pty0 = {y, y+height/2-height/8, y+height/2-height/8, y, y+height/2-height/8, y+height/2-height/8}; - g.drawPolygon(ptx0, pty0, 6); - int [] ptx1 = {x, x+width/6, x+5*width/6, x+width, x+5*width/6, x+width/6}; - int [] pty1 = {y+height, y+height/2+height/8, y+height/2+height/8, y+height, y+height/2+height/8, y+height/2+height/8}; - g.drawPolygon(ptx1, pty1, 6); - g.setColor(c); - - // Set font size - int attributeFontSize = this.currentFontSize * 5 / 6; - 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*fact)); - - g.setFont(fold); - } - -// public void manageMove() { -// if (father != null) { -// Point p = GraphicLib.putPointOnRectangle(x+(width/2), y+(height/2), father.getX(), father.getY(), father.getWidth(), father.getHeight()); -// -// x = p.x - width/2; -// y = p.y - height/2; -// -// setMoveCd(x, y); -// -// int orientation = GraphicLib.getCloserOrientation(x+(width/2), y+(height/2), father.getX(), father.getY(), father.getWidth(), father.getHeight()); -// if (orientation != currentOrientation) { -//// setOrientation(orientation); -// } -// } -// } - - // TGConnecting points .. - // TODO : change the orientation of the component -// public void setOrientation(int orientation) { -// currentOrientation = orientation; -// double w0, h0, w1, h1; -// -//// switch(orientation) { -////// case GraphicLib.NORTH: -////// w0 = 0.5; -////// h0 = 0.0; -////// break; -//// case GraphicLib.WEST: -//// w0 = 0.0; -//// h0 = 0.5; -//// break; -////// case GraphicLib.SOUTH: -////// w0 = 0.5; -////// h0 = 1.0; -////// break; -//// case GraphicLib.EAST: -//// default: -//// w0 = 1.0; -//// h0 = 0.5; -//// } -// -// w0 = 0.0; -// h0 = 0.5; -// w1 = 1.0; -// h1 = 0.5; -// System.out.println(connectingPoint.length); -// ((ELNConnectingPoint) connectingPoint[0]).setW(w0); -// ((ELNConnectingPoint) connectingPoint[0]).setH(h0); -// ((ELNConnectingPoint) connectingPoint[1]).setW(w1); -// ((ELNConnectingPoint) connectingPoint[1]).setH(h1); -// } - - 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_TRANSMISSION_LINE; - } - - public boolean editOndoubleClick(JFrame frame) { - JDialogELNComponentTransmissionLine jde = new JDialogELNComponentTransmissionLine(this); - jde.setVisible(true); - return true; - } - - public StringBuffer encode(String data) { - StringBuffer databuf = new StringBuffer(data); - StringBuffer buffer = new StringBuffer(""); - for(int pos = 0; pos != data.length(); pos++) { - char c = databuf.charAt(pos); - switch(c) { - case '\u03A9' : - buffer.append("Ω"); - break; - case '\u03BC' : - buffer.append("μ"); - break; - default : - buffer.append(databuf.charAt(pos)); - break; - } - } - return buffer; - } - - protected String translateExtraParam() { - StringBuffer sb = new StringBuffer("<extraparam>\n"); - sb.append("<attributes z0=\"" + z0); - sb.append("\" unit0=\"" + encode(unit0)); - sb.append("\" delay=\"" + delay); - sb.append("\" delta0=\"" + delta0); - sb.append("\" unit2=\"" + encode(unit2) + "\""); - 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 z0, delta0; - String delay; - String unit0, unit2; - - 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")) { - z0 = Double.parseDouble(elt.getAttribute("z0")); - unit0 = elt.getAttribute("unit0"); - delay = elt.getAttribute("delay"); - delta0 = Double.parseDouble(elt.getAttribute("delta0")); - unit2 = elt.getAttribute("unit2"); + + 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 ELNComponentTransmissionLine(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(120, 80); + + dtextX = textX * oldScaleFactor; + textX = (int) dtextX; + dtextX = dtextX - textX; + + minWidth = 1; + minHeight = 1; + + initConnectingPoint(4); + + addTGConnectingPointsComment(); + + moveable = true; + editable = true; + removable = true; + userResizable = false; + value = tdp.findELNComponentName("TransmissionLine"); + + setZ0(100.0); + setUnit0("\u03A9"); + setDelay("sc_core::SC_ZERO_TIME"); + setDelta0(0.0); + setUnit2("Hz"); + + 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, "a1"); + connectingPoint[1] = new ELNConnectingPoint(this, 0, 0, true, true, 1.0, 0.0, "a2"); + connectingPoint[2] = new ELNConnectingPoint(this, 0, 0, true, true, 0.0, 1.0, "b1"); + connectingPoint[3] = new ELNConnectingPoint(this, 0, 0, true, true, 1.0, 1.0, "b2"); + } + + 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(); + double w0 = ((ELNConnectingPoint) connectingPoint[0]).getW(); + double h0 = ((ELNConnectingPoint) connectingPoint[0]).getH(); + double w1 = ((ELNConnectingPoint) connectingPoint[1]).getW(); + double h1 = ((ELNConnectingPoint) connectingPoint[1]).getH(); + double w2 = ((ELNConnectingPoint) connectingPoint[2]).getW(); + double h2 = ((ELNConnectingPoint) connectingPoint[2]).getH(); + double w3 = ((ELNConnectingPoint) connectingPoint[3]).getW(); + double h3 = ((ELNConnectingPoint) connectingPoint[3]).getH(); + + if (position == 0) { + if (first == false) { + first = true; + old = width; + width = height; + height = old; + } + + rotateTopBottom(g); + + ((ELNConnectingPoint) connectingPoint[0]).setW(w0); + ((ELNConnectingPoint) connectingPoint[0]).setH(h0); + ((ELNConnectingPoint) connectingPoint[1]).setW(w1); + ((ELNConnectingPoint) connectingPoint[1]).setH(h1); + ((ELNConnectingPoint) connectingPoint[2]).setW(w2); + ((ELNConnectingPoint) connectingPoint[2]).setH(h2); + ((ELNConnectingPoint) connectingPoint[3]).setW(w3); + ((ELNConnectingPoint) connectingPoint[3]).setH(h3); + + int attributeFontSize = this.currentFontSize * 5 / 6; + int sw0 = g.getFontMetrics().stringWidth("a1"); + int sh0 = g.getFontMetrics().getAscent(); + int sw1 = g.getFontMetrics().stringWidth("a2"); + int sh1 = g.getFontMetrics().getAscent(); + int sw2 = g.getFontMetrics().stringWidth("b1"); + int sh2 = g.getFontMetrics().getAscent(); + int sw3 = g.getFontMetrics().stringWidth("b2"); + int sh3 = 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)) { + g.drawString(((ELNConnectingPoint) connectingPoint[0]).getName(), x - height / 8 - sw0, y); + g.drawString(((ELNConnectingPoint) connectingPoint[1]).getName(), x + width + height / 8, y); + g.drawString(((ELNConnectingPoint) connectingPoint[2]).getName(), x - height / 8 - sw2, + y + height + sh2); + g.drawString(((ELNConnectingPoint) connectingPoint[3]).getName(), x + width + height / 8, + y + height + sh3); + } + 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)) { + g.drawString(((ELNConnectingPoint) connectingPoint[1]).getName(), x - height / 8 - sw1, y); + g.drawString(((ELNConnectingPoint) connectingPoint[0]).getName(), x + width + height / 8, y); + g.drawString(((ELNConnectingPoint) connectingPoint[3]).getName(), x - height / 8 - sw3, + y + height + sh3); + g.drawString(((ELNConnectingPoint) connectingPoint[2]).getName(), x + width + height / 8, + y + height + sh2); + } + 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)) { + g.drawString(((ELNConnectingPoint) connectingPoint[2]).getName(), x - height / 8 - sw2, y); + g.drawString(((ELNConnectingPoint) connectingPoint[3]).getName(), x + width + height / 8, y); + g.drawString(((ELNConnectingPoint) connectingPoint[0]).getName(), x - height / 8 - sw0, + y + height + sh0); + 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)) { + g.drawString(((ELNConnectingPoint) connectingPoint[3]).getName(), x - height / 8 - sw3, y); + g.drawString(((ELNConnectingPoint) connectingPoint[2]).getName(), x + width + height / 8, y); + g.drawString(((ELNConnectingPoint) connectingPoint[1]).getName(), x - height / 8 - sw1, + y + height + sh1); + 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; + } + + rotateRightLeft(g); + + ((ELNConnectingPoint) connectingPoint[0]).setW(h0); + ((ELNConnectingPoint) connectingPoint[0]).setH(w0); + ((ELNConnectingPoint) connectingPoint[1]).setW(h1); + ((ELNConnectingPoint) connectingPoint[1]).setH(w1); + ((ELNConnectingPoint) connectingPoint[2]).setW(h2); + ((ELNConnectingPoint) connectingPoint[2]).setH(w2); + ((ELNConnectingPoint) connectingPoint[3]).setW(h3); + ((ELNConnectingPoint) connectingPoint[3]).setH(w3); + + int attributeFontSize = this.currentFontSize * 5 / 6; + int sw0 = g.getFontMetrics().stringWidth("a1"); + int sh0 = g.getFontMetrics().getAscent(); + int sw1 = g.getFontMetrics().stringWidth("a2"); + int sh1 = g.getFontMetrics().getAscent(); + int sw2 = g.getFontMetrics().stringWidth("b1"); + int sh2 = g.getFontMetrics().getAscent(); + int sw3 = g.getFontMetrics().stringWidth("b2"); + int sh3 = 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)) { + g.drawString(((ELNConnectingPoint) connectingPoint[2]).getName(), x - width / 8 - sw2, y); + g.drawString(((ELNConnectingPoint) connectingPoint[0]).getName(), x + width + width / 8, y); + g.drawString(((ELNConnectingPoint) connectingPoint[3]).getName(), x - width / 8 - sw3, + y + height + sh3); + 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)) { + g.drawString(((ELNConnectingPoint) connectingPoint[3]).getName(), x - width / 8 - sw3, y); + g.drawString(((ELNConnectingPoint) connectingPoint[1]).getName(), x + width + width / 8, y); + g.drawString(((ELNConnectingPoint) connectingPoint[2]).getName(), x - width / 8 - sw2, + y + height + sh2); + 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)) { + g.drawString(((ELNConnectingPoint) connectingPoint[0]).getName(), x - width / 8 - sw0, y); + g.drawString(((ELNConnectingPoint) connectingPoint[2]).getName(), x + width + width / 8, y); + g.drawString(((ELNConnectingPoint) connectingPoint[1]).getName(), x - width / 8 - sw1, + y + height + sh1); + g.drawString(((ELNConnectingPoint) connectingPoint[3]).getName(), x + width + width / 8, + y + height + sh3); + } + 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)) { + g.drawString(((ELNConnectingPoint) connectingPoint[1]).getName(), x - width / 8 - sw1, y); + g.drawString(((ELNConnectingPoint) connectingPoint[3]).getName(), x + width + width / 8, y); + g.drawString(((ELNConnectingPoint) connectingPoint[0]).getName(), x - width / 8 - sw0, + y + height + sh0); + g.drawString(((ELNConnectingPoint) connectingPoint[2]).getName(), x + width + width / 8, + y + height + sh2); + } + } else if (position == 2) { + if (first == false) { + first = true; + old = width; + width = height; + height = old; + } + + rotateTopBottom(g); + + ((ELNConnectingPoint) connectingPoint[0]).setW(w0); + ((ELNConnectingPoint) connectingPoint[0]).setH(h0); + ((ELNConnectingPoint) connectingPoint[1]).setW(w1); + ((ELNConnectingPoint) connectingPoint[1]).setH(h1); + ((ELNConnectingPoint) connectingPoint[2]).setW(w2); + ((ELNConnectingPoint) connectingPoint[2]).setH(h2); + ((ELNConnectingPoint) connectingPoint[3]).setW(w3); + ((ELNConnectingPoint) connectingPoint[3]).setH(h3); + + int attributeFontSize = this.currentFontSize * 5 / 6; + int sw0 = g.getFontMetrics().stringWidth("a1"); + int sh0 = g.getFontMetrics().getAscent(); + int sw1 = g.getFontMetrics().stringWidth("a2"); + int sh1 = g.getFontMetrics().getAscent(); + int sw2 = g.getFontMetrics().stringWidth("b1"); + int sh2 = g.getFontMetrics().getAscent(); + int sw3 = g.getFontMetrics().stringWidth("b2"); + int sh3 = 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)) { + g.drawString(((ELNConnectingPoint) connectingPoint[3]).getName(), x - height / 8 - sw3, y); + g.drawString(((ELNConnectingPoint) connectingPoint[2]).getName(), x + width + height / 8, y); + g.drawString(((ELNConnectingPoint) connectingPoint[1]).getName(), x - height / 8 - sw1, + y + height + sh1); + 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)) { + g.drawString(((ELNConnectingPoint) connectingPoint[2]).getName(), x - height / 8 - sw2, y); + g.drawString(((ELNConnectingPoint) connectingPoint[3]).getName(), x + width + height / 8, y); + g.drawString(((ELNConnectingPoint) connectingPoint[0]).getName(), x - height / 8 - sw0, + y + height + sh0); + 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)) { + g.drawString(((ELNConnectingPoint) connectingPoint[1]).getName(), x - height / 8 - sw1, y); + g.drawString(((ELNConnectingPoint) connectingPoint[0]).getName(), x + width + height / 8, y); + g.drawString(((ELNConnectingPoint) connectingPoint[3]).getName(), x - height / 8 - sw3, + y + height + sh3); + g.drawString(((ELNConnectingPoint) connectingPoint[2]).getName(), x + width + height / 8, + y + height + sh2); + } + 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)) { + g.drawString(((ELNConnectingPoint) connectingPoint[0]).getName(), x - height / 8 - sw0, y); + g.drawString(((ELNConnectingPoint) connectingPoint[1]).getName(), x + width + height / 8, y); + g.drawString(((ELNConnectingPoint) connectingPoint[2]).getName(), x - height / 8 - sw2, + y + height + sh2); + g.drawString(((ELNConnectingPoint) connectingPoint[3]).getName(), x + width + height / 8, + y + height + sh3); + } + } else if (position == 3) { + if (first == false) { + first = true; + old = width; + width = height; + height = old; + } + + rotateRightLeft(g); + + ((ELNConnectingPoint) connectingPoint[0]).setW(h0); + ((ELNConnectingPoint) connectingPoint[0]).setH(w0); + ((ELNConnectingPoint) connectingPoint[1]).setW(h1); + ((ELNConnectingPoint) connectingPoint[1]).setH(w1); + ((ELNConnectingPoint) connectingPoint[2]).setW(h2); + ((ELNConnectingPoint) connectingPoint[2]).setH(w2); + ((ELNConnectingPoint) connectingPoint[3]).setW(h3); + ((ELNConnectingPoint) connectingPoint[3]).setH(w3); + + int attributeFontSize = this.currentFontSize * 5 / 6; + int sw0 = g.getFontMetrics().stringWidth("a1"); + int sh0 = g.getFontMetrics().getAscent(); + int sw1 = g.getFontMetrics().stringWidth("a2"); + int sh1 = g.getFontMetrics().getAscent(); + int sw2 = g.getFontMetrics().stringWidth("b1"); + int sh2 = g.getFontMetrics().getAscent(); + int sw3 = g.getFontMetrics().stringWidth("b2"); + int sh3 = 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)) { + g.drawString(((ELNConnectingPoint) connectingPoint[1]).getName(), x - width / 8 - sw1, y); + g.drawString(((ELNConnectingPoint) connectingPoint[3]).getName(), x + width + width / 8, y); + g.drawString(((ELNConnectingPoint) connectingPoint[0]).getName(), x - width / 8 - sw0, + y + height + sh0); + g.drawString(((ELNConnectingPoint) connectingPoint[2]).getName(), x + width + width / 8, + y + height + sh2); + } + 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)) { + g.drawString(((ELNConnectingPoint) connectingPoint[0]).getName(), x - width / 8 - sw0, y); + g.drawString(((ELNConnectingPoint) connectingPoint[2]).getName(), x + width + width / 8, y); + g.drawString(((ELNConnectingPoint) connectingPoint[1]).getName(), x - width / 8 - sw1, + y + height + sh1); + g.drawString(((ELNConnectingPoint) connectingPoint[3]).getName(), x + width + width / 8, + y + height + sh3); + } + 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)) { + g.drawString(((ELNConnectingPoint) connectingPoint[3]).getName(), x - width / 8 - sw3, y); + g.drawString(((ELNConnectingPoint) connectingPoint[1]).getName(), x + width + width / 8, y); + g.drawString(((ELNConnectingPoint) connectingPoint[2]).getName(), x - width / 8 - sw2, + y + height + sh2); + 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)) { + g.drawString(((ELNConnectingPoint) connectingPoint[2]).getName(), x - width / 8 - sw2, y); + g.drawString(((ELNConnectingPoint) connectingPoint[0]).getName(), x + width + width / 8, y); + g.drawString(((ELNConnectingPoint) connectingPoint[3]).getName(), x - width / 8 - sw3, + y + height + sh3); + g.drawString(((ELNConnectingPoint) connectingPoint[1]).getName(), x + width + width / 8, + y + height + sh1); + } + } + g.setColor(c); + g.setFont(fold); + } + + private void rotateTopBottom(Graphics g) { + int[] ptx0 = { x, x + width / 6, x + 5 * width / 6, x + width, x + 5 * width / 6, x + width / 6 }; + int[] pty0 = { y, y + height / 2 - height / 8, y + height / 2 - height / 8, y, y + height / 2 - height / 8, + y + height / 2 - height / 8 }; + g.drawPolygon(ptx0, pty0, 6); + int[] ptx1 = { x, x + width / 6, x + 5 * width / 6, x + width, x + 5 * width / 6, x + width / 6 }; + int[] pty1 = { y + height, y + height / 2 + height / 8, y + height / 2 + height / 8, y + height, + y + height / 2 + height / 8, y + height / 2 + height / 8 }; + g.drawPolygon(ptx1, pty1, 6); + } + + private void rotateRightLeft(Graphics g) { + int[] ptx0 = { x, x + width / 2 - width / 8, x + width / 2 - width / 8, x, x + width / 2 - width / 8, + x + width / 2 - width / 8 }; + int[] pty0 = { y, y + height / 6, y + 5 * height / 6, y + height, y + 5 * height / 6, y + height / 6 }; + g.drawPolygon(ptx0, pty0, 6); + int[] ptx1 = { x + width, x + width / 2 + width / 8, x + width / 2 + width / 8, x + width, + x + width / 2 + width / 8, x + width / 2 + width / 8 }; + int[] pty1 = { y, y + height / 6, y + 5 * height / 6, y + height, y + 5 * height / 6, y + height / 6 }; + g.drawPolygon(ptx1, pty1, 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_TRANSMISSION_LINE; + } + + public boolean editOndoubleClick(JFrame frame) { + JDialogELNComponentTransmissionLine jde = new JDialogELNComponentTransmissionLine(this); + jde.setVisible(true); + return true; + } + + public StringBuffer encode(String data) { + StringBuffer databuf = new StringBuffer(data); + StringBuffer buffer = new StringBuffer(""); + for (int pos = 0; pos != data.length(); pos++) { + char c = databuf.charAt(pos); + switch (c) { + case '\u03A9': + buffer.append("Ω"); + break; + case '\u03BC': + buffer.append("μ"); + break; + default: + buffer.append(databuf.charAt(pos)); + break; + } + } + return buffer; + } + + protected String translateExtraParam() { + StringBuffer sb = new StringBuffer("<extraparam>\n"); + sb.append("<attributes z0=\"" + z0); + sb.append("\" unit0=\"" + encode(unit0)); + sb.append("\" delay=\"" + delay); + sb.append("\" delta0=\"" + delta0); + sb.append("\" unit2=\"" + encode(unit2) + "\""); + 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 z0, delta0; + String delay; + String unit0, unit2; + + 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")) { + z0 = Double.parseDouble(elt.getAttribute("z0")); + unit0 = elt.getAttribute("unit0"); + delay = elt.getAttribute("delay"); + delta0 = Double.parseDouble(elt.getAttribute("delta0")); + unit2 = elt.getAttribute("unit2"); setZ0(z0); setUnit0(unit0); setDelay(delay); setDelta0(delta0); setUnit2(unit2); - } - } - } - } - } - } catch (Exception e) { - throw new MalformedModelingException(); - } - } - - public int getDefaultConnector() { - return TGComponentManager.ELN_CONNECTOR; - } + } + } + } + } + } + } 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 getZ0() { return z0; @@ -366,4 +705,4 @@ public class ELNComponentTransmissionLine extends TGCScalableWithInternalCompone public void setUnit2(String _unit2) { unit2 = _unit2; } -} \ No newline at end of file +} diff --git a/src/main/java/ui/eln/sca_eln/ELNComponentVoltageControlledCurrentSource.java b/src/main/java/ui/eln/sca_eln/ELNComponentVoltageControlledCurrentSource.java index 405b00c06afb776bbc1c421bba2ba2de005aee3d..822a618fd3f851eddcf1ff0a6ff453faf2bffa8a 100644 --- a/src/main/java/ui/eln/sca_eln/ELNComponentVoltageControlledCurrentSource.java +++ b/src/main/java/ui/eln/sca_eln/ELNComponentVoltageControlledCurrentSource.java @@ -45,285 +45,848 @@ import org.w3c.dom.Node; import org.w3c.dom.NodeList; import ui.*; import ui.eln.ELNConnectingPoint; -import ui.util.IconManager; import ui.window.JDialogELNComponentVoltageControlledCurrentSource; import javax.swing.*; import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; /** - * Class ELNComponentVoltageControlledCurrentSource - * Voltage controlled current source to be used in ELN diagrams + * Class ELNComponentVoltageControlledCurrentSource + * Voltage controlled current source to be used in ELN diagrams * Creation: 13/06/2018 * @version 1.0 13/06/2018 * @author Irina Kit Yan LEE */ -public class ELNComponentVoltageControlledCurrentSource extends TGCScalableWithInternalComponent { - protected Color myColor; - protected int orientation; +public class ELNComponentVoltageControlledCurrentSource extends TGCScalableWithInternalComponent + implements ActionListener { + protected Color myColor; + protected int orientation; private int maxFontSize = 14; - private int minFontSize = 4; - private int currentFontSize = -1; -// protected int oldx, oldy; -// protected int currentOrientation = GraphicLib.NORTH; - - private int textX = 15; // border for ports - private double dtextX = 0.0; - protected int decPoint = 3; - - private int fact = 2; - - // Parameter + private int minFontSize = 4; + private int currentFontSize = -1; + + private int textX = 15; + private double dtextX = 0.0; + protected int decPoint = 3; + private double val; private String unit; - - public ELNComponentVoltageControlledCurrentSource(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(60*fact, 40*fact); - - dtextX = textX * oldScaleFactor; - textX = (int)dtextX; - dtextX = dtextX - textX; - - minWidth = 1; - minHeight = 1; - - initConnectingPoint(4); - - addTGConnectingPointsComment(); - - moveable = true; - editable = true; - removable = true; - userResizable = false; - value = tdp.findELNComponentName("VCCS"); - - myImageIcon = IconManager.imgic1206; - - // Initialization of vccs attributes - setVal(1.0); - setUnit("S"); - } - - public void initConnectingPoint(int nb) { - nbConnectingPoint = nb; - connectingPoint = new TGConnectingPoint[nb]; - connectingPoint[0] = new ELNConnectingPoint(this, 0, 0, true, true, 0.0, 0.0); - connectingPoint[1] = new ELNConnectingPoint(this, 0, 0, true, true, 1.0, 0.0); - connectingPoint[2] = new ELNConnectingPoint(this, 0, 0, true, true, 0.0, 1.0); - connectingPoint[3] = new ELNConnectingPoint(this, 0, 0, true, true, 1.0, 1.0); - } - - public Color getMyColor() { - return myColor; - } - - public void internalDrawing(Graphics g) { - Font f = g.getFont(); - Font fold = f; - -// if ((x != oldx) | (oldy != y)) { -// // Component has moved! -// manageMove(); -// oldx = x; -// oldy = y; -// } - - if (this.rescaled && !this.tdp.isScaled()) { - this.rescaled = false; - // Must set the font size... - // Incrementally find the biggest font not greater than max_font size - // If font is less than min_font, no text is displayed - - 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); - } - - // Zoom is assumed to be computed - Color c = g.getColor(); - 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 [] ptx2 = {x+width, x+4*width/6, x+4*width/6, x+3*width/6, x+4*width/6, x+4*width/6, x+width, x+4*width/6, x+4*width/6, x+5*width/6, x+3*width/6, x+5*width/6, x+4*width/6, x+4*width/6}; - int [] pty2 = {y, y, y+height/4, y+2*height/4, y+3*height/4, y+height, y+height, y+height, y+3*height/4, y+2*height/4, y+2*height/4, y+2*height/4, y+height/4, y}; - g.drawPolygon(ptx2, pty2, 14); - int [] ptx3 = {x+2*width/6-width/(6*fact)-width/(12*fact), x+2*width/6-width/(6*fact), x+2*width/6-width/(6*fact), x+2*width/6-width/(6*fact), x+2*width/6-width/(6*fact), x+2*width/6-width/(12*fact)}; - int [] pty3 = {y+height/(4*fact), y+height/(4*fact), y+height/(8*fact), y+height/(4*fact)+height/(8*fact), y+height/(4*fact), y+height/(4*fact)}; - g.drawPolygon(ptx3, pty3, 6); - int [] ptx4 = {x+2*width/6-width/(6*fact)-width/(12*fact), x+2*width/6-width/(12*fact)}; - int [] pty4 = {y+height-height/(4*fact), y+height-height/(4*fact)}; - g.drawPolygon(ptx4, pty4, 2); - int [] ptx5 = {x+5*width/6+width/(6*fact)+width/(12*fact), x+5*width/6+width/(6*fact)+width/(12*fact), x+5*width/6+width/(6*fact), x+5*width/6+width/(6*fact)+width/(12*fact), x+5*width/6+width/(3*fact), x+5*width/6+width/(6*fact)+width/(12*fact)}; - int [] pty5 = {y+height/4, y+3*height/4-height/(4*fact), y+3*height/4-height/(4*fact), y+3*height/4, y+3*height/4-height/(4*fact), y+3*height/4-height/(4*fact)}; - g.drawPolygon(ptx5, pty5, 6); - g.fillPolygon(ptx5, pty5, 6); - g.setColor(c); - - // Set font size - int attributeFontSize = this.currentFontSize * 5 / 6; - 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*fact)); - - g.setFont(fold); - } - -// public void manageMove() { -// if (father != null) { -// Point p = GraphicLib.putPointOnRectangle(x+(width/2), y+(height/2), father.getX(), father.getY(), father.getWidth(), father.getHeight()); -// -// x = p.x - width/2; -// y = p.y - height/2; -// -// setMoveCd(x, y); -// -// int orientation = GraphicLib.getCloserOrientation(x+(width/2), y+(height/2), father.getX(), father.getY(), father.getWidth(), father.getHeight()); -// if (orientation != currentOrientation) { -//// setOrientation(orientation); -// } -// } -// } - - // TGConnecting points .. - // TODO : change the orientation of the component -// public void setOrientation(int orientation) { -// currentOrientation = orientation; -// double w0, h0, w1, h1; -// -//// switch(orientation) { -////// case GraphicLib.NORTH: -////// w0 = 0.5; -////// h0 = 0.0; -////// break; -//// case GraphicLib.WEST: -//// w0 = 0.0; -//// h0 = 0.5; -//// break; -////// case GraphicLib.SOUTH: -////// w0 = 0.5; -////// h0 = 1.0; -////// break; -//// case GraphicLib.EAST: -//// default: -//// w0 = 1.0; -//// h0 = 0.5; -//// } -// -// w0 = 0.0; -// h0 = 0.5; -// w1 = 1.0; -// h1 = 0.5; -// System.out.println(connectingPoint.length); -// ((ELNConnectingPoint) connectingPoint[0]).setW(w0); -// ((ELNConnectingPoint) connectingPoint[0]).setH(h0); -// ((ELNConnectingPoint) connectingPoint[1]).setW(w1); -// ((ELNConnectingPoint) connectingPoint[1]).setH(h1); -// } - - 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_VOLTAGE_CONTROLLED_CURRENT_SOURCE; - } - - public boolean editOndoubleClick(JFrame frame) { - JDialogELNComponentVoltageControlledCurrentSource jde = new JDialogELNComponentVoltageControlledCurrentSource(this); - jde.setVisible(true); - return true; - } - - public StringBuffer encode(String data) { - StringBuffer databuf = new StringBuffer(data); - StringBuffer buffer = new StringBuffer(""); - for(int pos = 0; pos != data.length(); pos++) { - char c = databuf.charAt(pos); - switch(c) { - case '\u03BC' : - buffer.append("μ"); - break; - default : - buffer.append(databuf.charAt(pos)); - break; - } - } - return buffer; - } - - protected String translateExtraParam() { - StringBuffer sb = new StringBuffer("<extraparam>\n"); - sb.append("<attributes value=\"" + val); - sb.append("\" unit=\"" + encode(unit) + "\""); - 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 value; - String unit; - - 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")) { - value = Double.parseDouble(elt.getAttribute("value")); - unit = elt.getAttribute("unit"); + + 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 ELNComponentVoltageControlledCurrentSource(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(120, 80); + + dtextX = textX * oldScaleFactor; + textX = (int) dtextX; + dtextX = dtextX - textX; + + minWidth = 1; + minHeight = 1; + + initConnectingPoint(4); + + addTGConnectingPointsComment(); + + moveable = true; + editable = true; + removable = true; + userResizable = false; + value = tdp.findELNComponentName("VCCS"); + + setVal(1.0); + setUnit("S"); + + 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, "ncp"); + connectingPoint[1] = new ELNConnectingPoint(this, 0, 0, true, true, 1.0, 0.0, "np"); + connectingPoint[2] = new ELNConnectingPoint(this, 0, 0, true, true, 0.0, 1.0, "ncn"); + connectingPoint[3] = new ELNConnectingPoint(this, 0, 0, true, true, 1.0, 1.0, "nn"); + } + + 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(); + double w0 = ((ELNConnectingPoint) connectingPoint[0]).getW(); + double h0 = ((ELNConnectingPoint) connectingPoint[0]).getH(); + double w1 = ((ELNConnectingPoint) connectingPoint[1]).getW(); + double h1 = ((ELNConnectingPoint) connectingPoint[1]).getH(); + double w2 = ((ELNConnectingPoint) connectingPoint[2]).getW(); + double h2 = ((ELNConnectingPoint) connectingPoint[2]).getH(); + double w3 = ((ELNConnectingPoint) connectingPoint[3]).getW(); + double h3 = ((ELNConnectingPoint) connectingPoint[3]).getH(); + + if (position == 0) { + if (first == false) { + first = true; + old = width; + width = height; + height = old; + } + ; + + ((ELNConnectingPoint) connectingPoint[0]).setW(w0); + ((ELNConnectingPoint) connectingPoint[0]).setH(h0); + ((ELNConnectingPoint) connectingPoint[1]).setW(w1); + ((ELNConnectingPoint) connectingPoint[1]).setH(h1); + ((ELNConnectingPoint) connectingPoint[2]).setW(w2); + ((ELNConnectingPoint) connectingPoint[2]).setH(h2); + ((ELNConnectingPoint) connectingPoint[3]).setW(w3); + ((ELNConnectingPoint) connectingPoint[3]).setH(h3); + + int attributeFontSize = this.currentFontSize * 5 / 6; + int sw0 = g.getFontMetrics().stringWidth("ncp"); + int sh0 = g.getFontMetrics().getAscent(); + int sw1 = g.getFontMetrics().stringWidth("np"); + int sh1 = g.getFontMetrics().getAscent(); + int sw2 = g.getFontMetrics().stringWidth("ncn"); + int sh2 = g.getFontMetrics().getAscent(); + int sw3 = g.getFontMetrics().stringWidth("nn"); + int sh3 = 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); + g.drawString(((ELNConnectingPoint) connectingPoint[0]).getName(), x - height / 8 - sw0, y); + g.drawString(((ELNConnectingPoint) connectingPoint[1]).getName(), x + width + height / 8, y); + g.drawString(((ELNConnectingPoint) connectingPoint[2]).getName(), x - height / 8 - sw2, + y + height + sh2); + g.drawString(((ELNConnectingPoint) connectingPoint[3]).getName(), x + width + height / 8, + y + height + sh3); + } + 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); + g.drawString(((ELNConnectingPoint) connectingPoint[1]).getName(), x - height / 8 - sw1, y); + g.drawString(((ELNConnectingPoint) connectingPoint[0]).getName(), x + width + height / 8, y); + g.drawString(((ELNConnectingPoint) connectingPoint[3]).getName(), x - height / 8 - sw3, + y + height + sh3); + g.drawString(((ELNConnectingPoint) connectingPoint[2]).getName(), x + width + height / 8, + y + height + sh2); + } + 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); + g.drawString(((ELNConnectingPoint) connectingPoint[2]).getName(), x - height / 8 - sw2, y); + g.drawString(((ELNConnectingPoint) connectingPoint[3]).getName(), x + width + height / 8, y); + g.drawString(((ELNConnectingPoint) connectingPoint[0]).getName(), x - height / 8 - sw0, + y + height + sh0); + 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)) { + rotateBottom(g); + g.drawString(((ELNConnectingPoint) connectingPoint[3]).getName(), x - height / 8 - sw3, y); + g.drawString(((ELNConnectingPoint) connectingPoint[2]).getName(), x + width + height / 8, y); + g.drawString(((ELNConnectingPoint) connectingPoint[1]).getName(), x - height / 8 - sw1, + y + height + sh1); + 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; + } + + ((ELNConnectingPoint) connectingPoint[0]).setW(h0); + ((ELNConnectingPoint) connectingPoint[0]).setH(w0); + ((ELNConnectingPoint) connectingPoint[1]).setW(h1); + ((ELNConnectingPoint) connectingPoint[1]).setH(w1); + ((ELNConnectingPoint) connectingPoint[2]).setW(h2); + ((ELNConnectingPoint) connectingPoint[2]).setH(w2); + ((ELNConnectingPoint) connectingPoint[3]).setW(h3); + ((ELNConnectingPoint) connectingPoint[3]).setH(w3); + + int attributeFontSize = this.currentFontSize * 5 / 6; + int sw0 = g.getFontMetrics().stringWidth("ncp"); + int sh0 = g.getFontMetrics().getAscent(); + int sw1 = g.getFontMetrics().stringWidth("np"); + int sh1 = g.getFontMetrics().getAscent(); + int sw2 = g.getFontMetrics().stringWidth("ncn"); + int sh2 = g.getFontMetrics().getAscent(); + int sw3 = g.getFontMetrics().stringWidth("nn"); + int sh3 = 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); + g.drawString(((ELNConnectingPoint) connectingPoint[2]).getName(), x - width / 8 - sw2, y); + g.drawString(((ELNConnectingPoint) connectingPoint[0]).getName(), x + width + width / 8, y); + g.drawString(((ELNConnectingPoint) connectingPoint[3]).getName(), x - width / 8 - sw3, + y + height + sh3); + 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)) { + rotateRightFlip(g); + g.drawString(((ELNConnectingPoint) connectingPoint[3]).getName(), x - width / 8 - sw3, y); + g.drawString(((ELNConnectingPoint) connectingPoint[1]).getName(), x + width + width / 8, y); + g.drawString(((ELNConnectingPoint) connectingPoint[2]).getName(), x - width / 8 - sw2, + y + height + sh2); + 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); + g.drawString(((ELNConnectingPoint) connectingPoint[0]).getName(), x - width / 8 - sw0, y); + g.drawString(((ELNConnectingPoint) connectingPoint[2]).getName(), x + width + width / 8, y); + g.drawString(((ELNConnectingPoint) connectingPoint[1]).getName(), x - width / 8 - sw1, + y + height + sh1); + g.drawString(((ELNConnectingPoint) connectingPoint[3]).getName(), x + width + width / 8, + y + height + sh3); + } + 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); + g.drawString(((ELNConnectingPoint) connectingPoint[1]).getName(), x - width / 8 - sw1, y); + g.drawString(((ELNConnectingPoint) connectingPoint[3]).getName(), x + width + width / 8, y); + g.drawString(((ELNConnectingPoint) connectingPoint[0]).getName(), x - width / 8 - sw0, + y + height + sh0); + g.drawString(((ELNConnectingPoint) connectingPoint[2]).getName(), x + width + width / 8, + y + height + sh2); + } + } else if (position == 2) { + if (first == false) { + first = true; + old = width; + width = height; + height = old; + } + + ((ELNConnectingPoint) connectingPoint[0]).setW(w0); + ((ELNConnectingPoint) connectingPoint[0]).setH(h0); + ((ELNConnectingPoint) connectingPoint[1]).setW(w1); + ((ELNConnectingPoint) connectingPoint[1]).setH(h1); + ((ELNConnectingPoint) connectingPoint[2]).setW(w2); + ((ELNConnectingPoint) connectingPoint[2]).setH(h2); + ((ELNConnectingPoint) connectingPoint[3]).setW(w3); + ((ELNConnectingPoint) connectingPoint[3]).setH(h3); + + int attributeFontSize = this.currentFontSize * 5 / 6; + int sw0 = g.getFontMetrics().stringWidth("ncp"); + int sh0 = g.getFontMetrics().getAscent(); + int sw1 = g.getFontMetrics().stringWidth("np"); + int sh1 = g.getFontMetrics().getAscent(); + int sw2 = g.getFontMetrics().stringWidth("ncn"); + int sh2 = g.getFontMetrics().getAscent(); + int sw3 = g.getFontMetrics().stringWidth("nn"); + int sh3 = 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); + g.drawString(((ELNConnectingPoint) connectingPoint[3]).getName(), x - height / 8 - sw3, y); + g.drawString(((ELNConnectingPoint) connectingPoint[2]).getName(), x + width + height / 8, y); + g.drawString(((ELNConnectingPoint) connectingPoint[1]).getName(), x - height / 8 - sw1, + y + height + sh1); + 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); + g.drawString(((ELNConnectingPoint) connectingPoint[2]).getName(), x - height / 8 - sw2, y); + g.drawString(((ELNConnectingPoint) connectingPoint[3]).getName(), x + width + height / 8, y); + g.drawString(((ELNConnectingPoint) connectingPoint[0]).getName(), x - height / 8 - sw0, + y + height + sh0); + 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)) { + rotateBottomFlip(g); + g.drawString(((ELNConnectingPoint) connectingPoint[1]).getName(), x - height / 8 - sw1, y); + g.drawString(((ELNConnectingPoint) connectingPoint[0]).getName(), x + width + height / 8, y); + g.drawString(((ELNConnectingPoint) connectingPoint[3]).getName(), x - height / 8 - sw3, + y + height + sh3); + g.drawString(((ELNConnectingPoint) connectingPoint[2]).getName(), x + width + height / 8, + y + height + sh2); + } + 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); + g.drawString(((ELNConnectingPoint) connectingPoint[0]).getName(), x - height / 8 - sw0, y); + g.drawString(((ELNConnectingPoint) connectingPoint[1]).getName(), x + width + height / 8, y); + g.drawString(((ELNConnectingPoint) connectingPoint[2]).getName(), x - height / 8 - sw2, + y + height + sh2); + g.drawString(((ELNConnectingPoint) connectingPoint[3]).getName(), x + width + height / 8, + y + height + sh3); + } + } else if (position == 3) { + if (first == false) { + first = true; + old = width; + width = height; + height = old; + } + + ((ELNConnectingPoint) connectingPoint[0]).setW(h0); + ((ELNConnectingPoint) connectingPoint[0]).setH(w0); + ((ELNConnectingPoint) connectingPoint[1]).setW(h1); + ((ELNConnectingPoint) connectingPoint[1]).setH(w1); + ((ELNConnectingPoint) connectingPoint[2]).setW(h2); + ((ELNConnectingPoint) connectingPoint[2]).setH(w2); + ((ELNConnectingPoint) connectingPoint[3]).setW(h3); + ((ELNConnectingPoint) connectingPoint[3]).setH(w3); + + int attributeFontSize = this.currentFontSize * 5 / 6; + int sw0 = g.getFontMetrics().stringWidth("ncp"); + int sh0 = g.getFontMetrics().getAscent(); + int sw1 = g.getFontMetrics().stringWidth("np"); + int sh1 = g.getFontMetrics().getAscent(); + int sw2 = g.getFontMetrics().stringWidth("ncn"); + int sh2 = g.getFontMetrics().getAscent(); + int sw3 = g.getFontMetrics().stringWidth("nn"); + int sh3 = 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); + g.drawString(((ELNConnectingPoint) connectingPoint[1]).getName(), x - width / 8 - sw1, y); + g.drawString(((ELNConnectingPoint) connectingPoint[3]).getName(), x + width + width / 8, y); + g.drawString(((ELNConnectingPoint) connectingPoint[0]).getName(), x - width / 8 - sw0, + y + height + sh0); + g.drawString(((ELNConnectingPoint) connectingPoint[2]).getName(), x + width + width / 8, + y + height + sh2); + } + 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); + g.drawString(((ELNConnectingPoint) connectingPoint[0]).getName(), x - width / 8 - sw0, y); + g.drawString(((ELNConnectingPoint) connectingPoint[2]).getName(), x + width + width / 8, y); + g.drawString(((ELNConnectingPoint) connectingPoint[1]).getName(), x - width / 8 - sw1, + y + height + sh1); + g.drawString(((ELNConnectingPoint) connectingPoint[3]).getName(), x + width + width / 8, + y + height + sh3); + } + 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); + g.drawString(((ELNConnectingPoint) connectingPoint[3]).getName(), x - width / 8 - sw3, y); + g.drawString(((ELNConnectingPoint) connectingPoint[1]).getName(), x + width + width / 8, y); + g.drawString(((ELNConnectingPoint) connectingPoint[2]).getName(), x - width / 8 - sw2, + y + height + sh2); + 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); + g.drawString(((ELNConnectingPoint) connectingPoint[2]).getName(), x - width / 8 - sw2, y); + g.drawString(((ELNConnectingPoint) connectingPoint[0]).getName(), x + width + width / 8, y); + g.drawString(((ELNConnectingPoint) connectingPoint[3]).getName(), x - width / 8 - sw3, + y + height + sh3); + g.drawString(((ELNConnectingPoint) connectingPoint[1]).getName(), x + width + width / 8, + y + height + sh1); + } + } + 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[] ptx2 = { x + width, x + 4 * width / 6, x + 4 * width / 6, x + 3 * width / 6, x + 4 * width / 6, + x + 4 * width / 6, x + width, x + 4 * width / 6, x + 4 * width / 6, x + 5 * width / 6, + x + 3 * width / 6, x + 5 * width / 6, x + 4 * width / 6, x + 4 * width / 6 }; + int[] pty2 = { y, y, y + height / 4, y + 2 * height / 4, y + 3 * height / 4, y + height, y + height, y + height, + y + 3 * height / 4, y + 2 * height / 4, y + 2 * height / 4, y + 2 * height / 4, y + height / 4, y }; + g.drawPolygon(ptx2, pty2, 14); + 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[] ptx2 = { x + width, x + 4 * width / 6, x + 4 * width / 6, x + 3 * width / 6, x + 4 * width / 6, + x + 4 * width / 6, x + width, x + 4 * width / 6, x + 4 * width / 6, x + 5 * width / 6, + x + 3 * width / 6, x + 5 * width / 6, x + 4 * width / 6, x + 4 * width / 6 }; + int[] pty2 = { y, y, y + height / 4, y + 2 * height / 4, y + 3 * height / 4, y + height, y + height, y + height, + y + 3 * height / 4, y + 2 * height / 4, y + 2 * height / 4, y + 2 * height / 4, y + height / 4, y }; + g.drawPolygon(ptx2, pty2, 14); + 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[] ptx2 = { x, x + 2 * width / 6, x + 2 * width / 6, x + width / 6, x + 2 * width / 6, x + 2 * width / 6, x, + x + 2 * width / 6, x + 2 * width / 6, x + 3 * width / 6, x + width / 6, x + 3 * width / 6, + x + 2 * width / 6, x + 2 * width / 6 }; + int[] pty2 = { y, y, y + height / 4, y + 2 * height / 4, y + 3 * height / 4, y + height, y + height, y + height, + y + 3 * height / 4, y + 2 * height / 4, y + 2 * height / 4, y + 2 * height / 4, y + height / 4, y }; + g.drawPolygon(ptx2, pty2, 14); + 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[] ptx2 = { x, x + 2 * width / 6, x + 2 * width / 6, x + width / 6, x + 2 * width / 6, x + 2 * width / 6, x, + x + 2 * width / 6, x + 2 * width / 6, x + 3 * width / 6, x + width / 6, x + 3 * width / 6, + x + 2 * width / 6, x + 2 * width / 6 }; + int[] pty2 = { y, y, y + height / 4, y + 2 * height / 4, y + 3 * height / 4, y + height, y + height, y + height, + y + 3 * height / 4, y + 2 * height / 4, y + 2 * height / 4, y + 2 * height / 4, y + height / 4, y }; + g.drawPolygon(ptx2, pty2, 14); + 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[] ptx2 = { x, x, x + width / 4, x + 2 * width / 4, x + 3 * width / 4, x + width, x + width, x + width, + x + 3 * width / 4, x + 2 * width / 4, x + 2 * width / 4, x + 2 * width / 4, x + width / 4, x }; + int[] pty2 = { y + height, y + 4 * height / 6, y + 4 * height / 6, y + 3 * height / 6, y + 4 * height / 6, + y + 4 * height / 6, y + height, y + 4 * height / 6, y + 4 * height / 6, y + 5 * height / 6, + y + 3 * height / 6, y + 5 * height / 6, y + 4 * height / 6, y + 4 * height / 6 }; + g.drawPolygon(ptx2, pty2, 14); + 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[] ptx2 = { x, x, x + width / 4, x + 2 * width / 4, x + 3 * width / 4, x + width, x + width, x + width, + x + 3 * width / 4, x + 2 * width / 4, x + 2 * width / 4, x + 2 * width / 4, x + width / 4, x }; + int[] pty2 = { y, y + 2 * height / 6, y + 2 * height / 6, y + height / 6, y + 2 * height / 6, + y + 2 * height / 6, y, y + 2 * height / 6, y + 2 * height / 6, y + 3 * height / 6, y + height / 6, + y + 3 * height / 6, y + 2 * height / 6, y + 2 * height / 6 }; + g.drawPolygon(ptx2, pty2, 14); + 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[] ptx2 = { x, x, x + width / 4, x + 2 * width / 4, x + 3 * width / 4, x + width, x + width, x + width, + x + 3 * width / 4, x + 2 * width / 4, x + 2 * width / 4, x + 2 * width / 4, x + width / 4, x }; + int[] pty2 = { y, y + 2 * height / 6, y + 2 * height / 6, y + height / 6, y + 2 * height / 6, + y + 2 * height / 6, y, y + 2 * height / 6, y + 2 * height / 6, y + 3 * height / 6, y + height / 6, + y + 3 * height / 6, y + 2 * height / 6, y + 2 * height / 6 }; + g.drawPolygon(ptx2, pty2, 14); + 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[] ptx2 = { x, x, x + width / 4, x + 2 * width / 4, x + 3 * width / 4, x + width, x + width, x + width, + x + 3 * width / 4, x + 2 * width / 4, x + 2 * width / 4, x + 2 * width / 4, x + width / 4, x }; + int[] pty2 = { y + height, y + 4 * height / 6, y + 4 * height / 6, y + 3 * height / 6, y + 4 * height / 6, + y + 4 * height / 6, y + height, y + 4 * height / 6, y + 4 * height / 6, y + 5 * height / 6, + y + 3 * height / 6, y + 5 * height / 6, y + 4 * height / 6, y + 4 * height / 6 }; + g.drawPolygon(ptx2, pty2, 14); + 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_VOLTAGE_CONTROLLED_CURRENT_SOURCE; + } + + public boolean editOndoubleClick(JFrame frame) { + JDialogELNComponentVoltageControlledCurrentSource jde = new JDialogELNComponentVoltageControlledCurrentSource( + this); + jde.setVisible(true); + return true; + } + + public StringBuffer encode(String data) { + StringBuffer databuf = new StringBuffer(data); + StringBuffer buffer = new StringBuffer(""); + for (int pos = 0; pos != data.length(); pos++) { + char c = databuf.charAt(pos); + switch (c) { + case '\u03BC': + buffer.append("μ"); + break; + default: + buffer.append(databuf.charAt(pos)); + break; + } + } + return buffer; + } + + protected String translateExtraParam() { + StringBuffer sb = new StringBuffer("<extraparam>\n"); + sb.append("<attributes value=\"" + val); + sb.append("\" unit=\"" + encode(unit) + "\""); + 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 value; + String unit; + + 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")) { + value = Double.parseDouble(elt.getAttribute("value")); + unit = elt.getAttribute("unit"); setVal(value); setUnit(unit); - } - } - } - } - } - } catch (Exception e) { - throw new MalformedModelingException(); - } - } - - public int getDefaultConnector() { - return TGComponentManager.ELN_CONNECTOR; - } - - public double getVal() { + } + } + } + } + } + } 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 getVal() { return val; } @@ -338,4 +901,4 @@ public class ELNComponentVoltageControlledCurrentSource extends TGCScalableWithI public void setUnit(String _unit) { unit = _unit; } -} \ No newline at end of file +} diff --git a/src/main/java/ui/eln/sca_eln/ELNComponentVoltageControlledVoltageSource.java b/src/main/java/ui/eln/sca_eln/ELNComponentVoltageControlledVoltageSource.java index 1a63930fdd5a3d6a1a25bbb26cb42df95f64fbcb..8787333e6c27acd2cb09215940d10acf00316478 100644 --- a/src/main/java/ui/eln/sca_eln/ELNComponentVoltageControlledVoltageSource.java +++ b/src/main/java/ui/eln/sca_eln/ELNComponentVoltageControlledVoltageSource.java @@ -45,268 +45,843 @@ import org.w3c.dom.Node; import org.w3c.dom.NodeList; import ui.*; import ui.eln.ELNConnectingPoint; -import ui.util.IconManager; import ui.window.JDialogELNComponentVoltageControlledVoltageSource; import javax.swing.*; import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; /** - * Class ELNComponentVoltageControlledVoltageSource - * Voltage controlled voltage source to be used in ELN diagrams + * Class ELNComponentVoltageControlledVoltageSource + * Voltage controlled voltage source to be used in ELN diagrams * Creation: 13/06/2018 * @version 1.0 13/06/2018 * @author Irina Kit Yan LEE */ -public class ELNComponentVoltageControlledVoltageSource extends TGCScalableWithInternalComponent { - protected Color myColor; - protected int orientation; +public class ELNComponentVoltageControlledVoltageSource extends TGCScalableWithInternalComponent + implements ActionListener { + protected Color myColor; + protected int orientation; private int maxFontSize = 14; - private int minFontSize = 4; - private int currentFontSize = -1; -// protected int oldx, oldy; -// protected int currentOrientation = GraphicLib.NORTH; - - private int textX = 15; // border for ports - private double dtextX = 0.0; - protected int decPoint = 3; - - private int fact = 2; - - // Parameter + private int minFontSize = 4; + private int currentFontSize = -1; + + private int textX = 15; + private double dtextX = 0.0; + protected int decPoint = 3; + private double val; - - public ELNComponentVoltageControlledVoltageSource(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(60*fact, 40*fact); - - dtextX = textX * oldScaleFactor; - textX = (int)dtextX; - dtextX = dtextX - textX; - - minWidth = 1; - minHeight = 1; - - initConnectingPoint(4); - - addTGConnectingPointsComment(); - - moveable = true; - editable = true; - removable = true; - userResizable = false; - value = tdp.findELNComponentName("VCVS"); - - myImageIcon = IconManager.imgic1206; - - // Initialization of vcvs attributes - setVal(1.0); - } - - public void initConnectingPoint(int nb) { - nbConnectingPoint = nb; - connectingPoint = new TGConnectingPoint[nb]; - connectingPoint[0] = new ELNConnectingPoint(this, 0, 0, true, true, 0.0, 0.0); - connectingPoint[1] = new ELNConnectingPoint(this, 0, 0, true, true, 1.0, 0.0); - connectingPoint[2] = new ELNConnectingPoint(this, 0, 0, true, true, 0.0, 1.0); - connectingPoint[3] = new ELNConnectingPoint(this, 0, 0, true, true, 1.0, 1.0); - } - - public Color getMyColor() { - return myColor; - } - - public void internalDrawing(Graphics g) { - Font f = g.getFont(); - Font fold = f; - -// if ((x != oldx) | (oldy != y)) { -// // Component has moved! -// manageMove(); -// oldx = x; -// oldy = y; -// } - - if (this.rescaled && !this.tdp.isScaled()) { - this.rescaled = false; - // Must set the font size... - // Incrementally find the biggest font not greater than max_font size - // If font is less than min_font, no text is displayed - - 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); - } - - // Zoom is assumed to be computed - Color c = g.getColor(); - 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 [] ptx2 = {x+width, x+4*width/6, x+4*width/6, x+3*width/6, x+4*width/6, x+4*width/6, x+5*width/6, x+4*width/6, x+4*width/6, x+width, x+4*width/6, x+4*width/6}; - int [] pty2 = {y, y, y+height/4, y+2*height/4, y+3*height/4, y+height/4, y+2*height/4, y+3*height/4, y+height, y+height, y+height, y}; - g.drawPolygon(ptx2, pty2, 12); - int [] ptx3 = {x+2*width/6-width/(6*fact)-width/(12*fact), x+2*width/6-width/(6*fact), x+2*width/6-width/(6*fact), x+2*width/6-width/(6*fact), x+2*width/6-width/(6*fact), x+2*width/6-width/(12*fact)}; - int [] pty3 = {y+height/(4*fact), y+height/(4*fact), y+height/(8*fact), y+height/(4*fact)+height/(8*fact), y+height/(4*fact), y+height/(4*fact)}; - g.drawPolygon(ptx3, pty3, 6); - int [] ptx4 = {x+2*width/6-width/(6*fact)-width/(12*fact), x+2*width/6-width/(12*fact)}; - int [] pty4 = {y+height-height/(4*fact), y+height-height/(4*fact)}; - g.drawPolygon(ptx4, pty4, 2); - int [] ptx5 = {x+4*width/6+width/(12*fact), x+4*width/6+width/(6*fact), x+4*width/6+width/(6*fact), x+4*width/6+width/(6*fact), x+4*width/6+width/(6*fact), x+4*width/6+width/(6*fact)+width/(12*fact)}; - int [] pty5 = {y+height/(4*fact), y+height/(4*fact), y+height/(8*fact), y+height/(4*fact)+height/(8*fact), y+height/(4*fact), y+height/(4*fact)}; - g.drawPolygon(ptx5, pty5, 6); - int [] ptx6 = {x+4*width/6+width/(12*fact), x+4*width/6+width/(6*fact)+width/(12*fact)}; - int [] pty6 = {y+height-height/(4*fact), y+height-height/(4*fact)}; - g.drawPolygon(ptx6, pty6, 2); - g.setColor(c); - - // Set font size - int attributeFontSize = this.currentFontSize * 5 / 6; - 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*fact)); - - g.setFont(fold); - } - -// public void manageMove() { -// if (father != null) { -// Point p = GraphicLib.putPointOnRectangle(x+(width/2), y+(height/2), father.getX(), father.getY(), father.getWidth(), father.getHeight()); -// -// x = p.x - width/2; -// y = p.y - height/2; -// -// setMoveCd(x, y); -// -// int orientation = GraphicLib.getCloserOrientation(x+(width/2), y+(height/2), father.getX(), father.getY(), father.getWidth(), father.getHeight()); -// if (orientation != currentOrientation) { -//// setOrientation(orientation); -// } -// } -// } - - // TGConnecting points .. - // TODO : change the orientation of the component -// public void setOrientation(int orientation) { -// currentOrientation = orientation; -// double w0, h0, w1, h1; -// -//// switch(orientation) { -////// case GraphicLib.NORTH: -////// w0 = 0.5; -////// h0 = 0.0; -////// break; -//// case GraphicLib.WEST: -//// w0 = 0.0; -//// h0 = 0.5; -//// break; -////// case GraphicLib.SOUTH: -////// w0 = 0.5; -////// h0 = 1.0; -////// break; -//// case GraphicLib.EAST: -//// default: -//// w0 = 1.0; -//// h0 = 0.5; -//// } -// -// w0 = 0.0; -// h0 = 0.5; -// w1 = 1.0; -// h1 = 0.5; -// System.out.println(connectingPoint.length); -// ((ELNConnectingPoint) connectingPoint[0]).setW(w0); -// ((ELNConnectingPoint) connectingPoint[0]).setH(h0); -// ((ELNConnectingPoint) connectingPoint[1]).setW(w1); -// ((ELNConnectingPoint) connectingPoint[1]).setH(h1); -// } - - 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_VOLTAGE_CONTROLLED_VOLTAGE_SOURCE; - } - - public boolean editOndoubleClick(JFrame frame) { - JDialogELNComponentVoltageControlledVoltageSource jde = new JDialogELNComponentVoltageControlledVoltageSource(this); - jde.setVisible(true); - return true; - } - - protected String translateExtraParam() { - StringBuffer sb = new StringBuffer("<extraparam>\n"); - sb.append("<attributes value=\"" + val + "\""); - 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 value; - - 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")) { - value = Double.parseDouble(elt.getAttribute("value")); + + 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 ELNComponentVoltageControlledVoltageSource(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(120, 80); + + dtextX = textX * oldScaleFactor; + textX = (int) dtextX; + dtextX = dtextX - textX; + + minWidth = 1; + minHeight = 1; + + initConnectingPoint(4); + + addTGConnectingPointsComment(); + + moveable = true; + editable = true; + removable = true; + userResizable = false; + value = tdp.findELNComponentName("VCVS"); + + setVal(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, "ncp"); + connectingPoint[1] = new ELNConnectingPoint(this, 0, 0, true, true, 1.0, 0.0, "np"); + connectingPoint[2] = new ELNConnectingPoint(this, 0, 0, true, true, 0.0, 1.0, "ncn"); + connectingPoint[3] = new ELNConnectingPoint(this, 0, 0, true, true, 1.0, 1.0, "nn"); + } + + 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(); + double w0 = ((ELNConnectingPoint) connectingPoint[0]).getW(); + double h0 = ((ELNConnectingPoint) connectingPoint[0]).getH(); + double w1 = ((ELNConnectingPoint) connectingPoint[1]).getW(); + double h1 = ((ELNConnectingPoint) connectingPoint[1]).getH(); + double w2 = ((ELNConnectingPoint) connectingPoint[2]).getW(); + double h2 = ((ELNConnectingPoint) connectingPoint[2]).getH(); + double w3 = ((ELNConnectingPoint) connectingPoint[3]).getW(); + double h3 = ((ELNConnectingPoint) connectingPoint[3]).getH(); + + if (position == 0) { + if (first == false) { + first = true; + old = width; + width = height; + height = old; + } + ; + + ((ELNConnectingPoint) connectingPoint[0]).setW(w0); + ((ELNConnectingPoint) connectingPoint[0]).setH(h0); + ((ELNConnectingPoint) connectingPoint[1]).setW(w1); + ((ELNConnectingPoint) connectingPoint[1]).setH(h1); + ((ELNConnectingPoint) connectingPoint[2]).setW(w2); + ((ELNConnectingPoint) connectingPoint[2]).setH(h2); + ((ELNConnectingPoint) connectingPoint[3]).setW(w3); + ((ELNConnectingPoint) connectingPoint[3]).setH(h3); + + int attributeFontSize = this.currentFontSize * 5 / 6; + int sw0 = g.getFontMetrics().stringWidth("ncp"); + int sh0 = g.getFontMetrics().getAscent(); + int sw1 = g.getFontMetrics().stringWidth("np"); + int sh1 = g.getFontMetrics().getAscent(); + int sw2 = g.getFontMetrics().stringWidth("ncn"); + int sh2 = g.getFontMetrics().getAscent(); + int sw3 = g.getFontMetrics().stringWidth("nn"); + int sh3 = 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); + g.drawString(((ELNConnectingPoint) connectingPoint[0]).getName(), x - height / 8 - sw0, y); + g.drawString(((ELNConnectingPoint) connectingPoint[1]).getName(), x + width + height / 8, y); + g.drawString(((ELNConnectingPoint) connectingPoint[2]).getName(), x - height / 8 - sw2, + y + height + sh2); + g.drawString(((ELNConnectingPoint) connectingPoint[3]).getName(), x + width + height / 8, + y + height + sh3); + } + 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); + g.drawString(((ELNConnectingPoint) connectingPoint[1]).getName(), x - height / 8 - sw1, y); + g.drawString(((ELNConnectingPoint) connectingPoint[0]).getName(), x + width + height / 8, y); + g.drawString(((ELNConnectingPoint) connectingPoint[3]).getName(), x - height / 8 - sw3, + y + height + sh3); + g.drawString(((ELNConnectingPoint) connectingPoint[2]).getName(), x + width + height / 8, + y + height + sh2); + } + 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); + g.drawString(((ELNConnectingPoint) connectingPoint[2]).getName(), x - height / 8 - sw2, y); + g.drawString(((ELNConnectingPoint) connectingPoint[3]).getName(), x + width + height / 8, y); + g.drawString(((ELNConnectingPoint) connectingPoint[0]).getName(), x - height / 8 - sw0, + y + height + sh0); + 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)) { + rotateBottom(g); + g.drawString(((ELNConnectingPoint) connectingPoint[3]).getName(), x - height / 8 - sw3, y); + g.drawString(((ELNConnectingPoint) connectingPoint[2]).getName(), x + width + height / 8, y); + g.drawString(((ELNConnectingPoint) connectingPoint[1]).getName(), x - height / 8 - sw1, + y + height + sh1); + 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; + } + + ((ELNConnectingPoint) connectingPoint[0]).setW(h0); + ((ELNConnectingPoint) connectingPoint[0]).setH(w0); + ((ELNConnectingPoint) connectingPoint[1]).setW(h1); + ((ELNConnectingPoint) connectingPoint[1]).setH(w1); + ((ELNConnectingPoint) connectingPoint[2]).setW(h2); + ((ELNConnectingPoint) connectingPoint[2]).setH(w2); + ((ELNConnectingPoint) connectingPoint[3]).setW(h3); + ((ELNConnectingPoint) connectingPoint[3]).setH(w3); + + int attributeFontSize = this.currentFontSize * 5 / 6; + int sw0 = g.getFontMetrics().stringWidth("ncp"); + int sh0 = g.getFontMetrics().getAscent(); + int sw1 = g.getFontMetrics().stringWidth("np"); + int sh1 = g.getFontMetrics().getAscent(); + int sw2 = g.getFontMetrics().stringWidth("ncn"); + int sh2 = g.getFontMetrics().getAscent(); + int sw3 = g.getFontMetrics().stringWidth("nn"); + int sh3 = 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); + g.drawString(((ELNConnectingPoint) connectingPoint[2]).getName(), x - width / 8 - sw2, y); + g.drawString(((ELNConnectingPoint) connectingPoint[0]).getName(), x + width + width / 8, y); + g.drawString(((ELNConnectingPoint) connectingPoint[3]).getName(), x - width / 8 - sw3, + y + height + sh3); + 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)) { + rotateRightFlip(g); + g.drawString(((ELNConnectingPoint) connectingPoint[3]).getName(), x - width / 8 - sw3, y); + g.drawString(((ELNConnectingPoint) connectingPoint[1]).getName(), x + width + width / 8, y); + g.drawString(((ELNConnectingPoint) connectingPoint[2]).getName(), x - width / 8 - sw2, + y + height + sh2); + 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); + g.drawString(((ELNConnectingPoint) connectingPoint[0]).getName(), x - width / 8 - sw0, y); + g.drawString(((ELNConnectingPoint) connectingPoint[2]).getName(), x + width + width / 8, y); + g.drawString(((ELNConnectingPoint) connectingPoint[1]).getName(), x - width / 8 - sw1, + y + height + sh1); + g.drawString(((ELNConnectingPoint) connectingPoint[3]).getName(), x + width + width / 8, + y + height + sh3); + } + 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); + g.drawString(((ELNConnectingPoint) connectingPoint[1]).getName(), x - width / 8 - sw1, y); + g.drawString(((ELNConnectingPoint) connectingPoint[3]).getName(), x + width + width / 8, y); + g.drawString(((ELNConnectingPoint) connectingPoint[0]).getName(), x - width / 8 - sw0, + y + height + sh0); + g.drawString(((ELNConnectingPoint) connectingPoint[2]).getName(), x + width + width / 8, + y + height + sh2); + } + } else if (position == 2) { + if (first == false) { + first = true; + old = width; + width = height; + height = old; + } + + ((ELNConnectingPoint) connectingPoint[0]).setW(w0); + ((ELNConnectingPoint) connectingPoint[0]).setH(h0); + ((ELNConnectingPoint) connectingPoint[1]).setW(w1); + ((ELNConnectingPoint) connectingPoint[1]).setH(h1); + ((ELNConnectingPoint) connectingPoint[2]).setW(w2); + ((ELNConnectingPoint) connectingPoint[2]).setH(h2); + ((ELNConnectingPoint) connectingPoint[3]).setW(w3); + ((ELNConnectingPoint) connectingPoint[3]).setH(h3); + + int attributeFontSize = this.currentFontSize * 5 / 6; + int sw0 = g.getFontMetrics().stringWidth("ncp"); + int sh0 = g.getFontMetrics().getAscent(); + int sw1 = g.getFontMetrics().stringWidth("np"); + int sh1 = g.getFontMetrics().getAscent(); + int sw2 = g.getFontMetrics().stringWidth("ncn"); + int sh2 = g.getFontMetrics().getAscent(); + int sw3 = g.getFontMetrics().stringWidth("nn"); + int sh3 = 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); + g.drawString(((ELNConnectingPoint) connectingPoint[3]).getName(), x - height / 8 - sw3, y); + g.drawString(((ELNConnectingPoint) connectingPoint[2]).getName(), x + width + height / 8, y); + g.drawString(((ELNConnectingPoint) connectingPoint[1]).getName(), x - height / 8 - sw1, + y + height + sh1); + 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); + g.drawString(((ELNConnectingPoint) connectingPoint[2]).getName(), x - height / 8 - sw2, y); + g.drawString(((ELNConnectingPoint) connectingPoint[3]).getName(), x + width + height / 8, y); + g.drawString(((ELNConnectingPoint) connectingPoint[0]).getName(), x - height / 8 - sw0, + y + height + sh0); + 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)) { + rotateBottomFlip(g); + g.drawString(((ELNConnectingPoint) connectingPoint[1]).getName(), x - height / 8 - sw1, y); + g.drawString(((ELNConnectingPoint) connectingPoint[0]).getName(), x + width + height / 8, y); + g.drawString(((ELNConnectingPoint) connectingPoint[3]).getName(), x - height / 8 - sw3, + y + height + sh3); + g.drawString(((ELNConnectingPoint) connectingPoint[2]).getName(), x + width + height / 8, + y + height + sh2); + } + 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); + g.drawString(((ELNConnectingPoint) connectingPoint[0]).getName(), x - height / 8 - sw0, y); + g.drawString(((ELNConnectingPoint) connectingPoint[1]).getName(), x + width + height / 8, y); + g.drawString(((ELNConnectingPoint) connectingPoint[2]).getName(), x - height / 8 - sw2, + y + height + sh2); + g.drawString(((ELNConnectingPoint) connectingPoint[3]).getName(), x + width + height / 8, + y + height + sh3); + } + } else if (position == 3) { + if (first == false) { + first = true; + old = width; + width = height; + height = old; + } + + ((ELNConnectingPoint) connectingPoint[0]).setW(h0); + ((ELNConnectingPoint) connectingPoint[0]).setH(w0); + ((ELNConnectingPoint) connectingPoint[1]).setW(h1); + ((ELNConnectingPoint) connectingPoint[1]).setH(w1); + ((ELNConnectingPoint) connectingPoint[2]).setW(h2); + ((ELNConnectingPoint) connectingPoint[2]).setH(w2); + ((ELNConnectingPoint) connectingPoint[3]).setW(h3); + ((ELNConnectingPoint) connectingPoint[3]).setH(w3); + + int attributeFontSize = this.currentFontSize * 5 / 6; + int sw0 = g.getFontMetrics().stringWidth("ncp"); + int sh0 = g.getFontMetrics().getAscent(); + int sw1 = g.getFontMetrics().stringWidth("np"); + int sh1 = g.getFontMetrics().getAscent(); + int sw2 = g.getFontMetrics().stringWidth("ncn"); + int sh2 = g.getFontMetrics().getAscent(); + int sw3 = g.getFontMetrics().stringWidth("nn"); + int sh3 = 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); + g.drawString(((ELNConnectingPoint) connectingPoint[1]).getName(), x - width / 8 - sw1, y); + g.drawString(((ELNConnectingPoint) connectingPoint[3]).getName(), x + width + width / 8, y); + g.drawString(((ELNConnectingPoint) connectingPoint[0]).getName(), x - width / 8 - sw0, + y + height + sh0); + g.drawString(((ELNConnectingPoint) connectingPoint[2]).getName(), x + width + width / 8, + y + height + sh2); + } + 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); + g.drawString(((ELNConnectingPoint) connectingPoint[0]).getName(), x - width / 8 - sw0, y); + g.drawString(((ELNConnectingPoint) connectingPoint[2]).getName(), x + width + width / 8, y); + g.drawString(((ELNConnectingPoint) connectingPoint[1]).getName(), x - width / 8 - sw1, + y + height + sh1); + g.drawString(((ELNConnectingPoint) connectingPoint[3]).getName(), x + width + width / 8, + y + height + sh3); + } + 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); + g.drawString(((ELNConnectingPoint) connectingPoint[3]).getName(), x - width / 8 - sw3, y); + g.drawString(((ELNConnectingPoint) connectingPoint[1]).getName(), x + width + width / 8, y); + g.drawString(((ELNConnectingPoint) connectingPoint[2]).getName(), x - width / 8 - sw2, + y + height + sh2); + 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); + g.drawString(((ELNConnectingPoint) connectingPoint[2]).getName(), x - width / 8 - sw2, y); + g.drawString(((ELNConnectingPoint) connectingPoint[0]).getName(), x + width + width / 8, y); + g.drawString(((ELNConnectingPoint) connectingPoint[3]).getName(), x - width / 8 - sw3, + y + height + sh3); + g.drawString(((ELNConnectingPoint) connectingPoint[1]).getName(), x + width + width / 8, + y + height + sh1); + } + } + 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[] ptx2 = { x + width, x + 4 * width / 6, x + 4 * width / 6, x + 3 * width / 6, x + 4 * width / 6, + x + 4 * width / 6, x + 5 * width / 6, x + 4 * width / 6, x + 4 * width / 6, x + width, + x + 4 * width / 6, x + 4 * width / 6 }; + int[] pty2 = { y, y, y + height / 4, y + 2 * height / 4, y + 3 * height / 4, y + height / 4, y + 2 * height / 4, + y + 3 * height / 4, y + height, y + height, y + height, y }; + g.drawPolygon(ptx2, pty2, 12); + 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 + 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[] pty5 = { y + height / 8, y + height / 8, y + height / 16, y + height / 8 + height / 16, y + height / 8, + y + height / 8 }; + g.drawPolygon(ptx5, pty5, 6); + int[] ptx6 = { x + 4 * width / 6 + width / 24, x + 4 * width / 6 + width / 12 + width / 24 }; + int[] pty6 = { y + height - height / 8, y + height - height / 8 }; + g.drawPolygon(ptx6, pty6, 2); + } + + 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[] ptx2 = { x + width, x + 4 * width / 6, x + 4 * width / 6, x + 3 * width / 6, x + 4 * width / 6, + x + 4 * width / 6, x + 5 * width / 6, x + 4 * width / 6, x + 4 * width / 6, x + width, + x + 4 * width / 6, x + 4 * width / 6 }; + int[] pty2 = { y, y, y + height / 4, y + 2 * height / 4, y + 3 * height / 4, y + height / 4, y + 2 * height / 4, + y + 3 * height / 4, y + height, y + height, y + height, y }; + g.drawPolygon(ptx2, pty2, 12); + 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 + 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[] pty5 = { 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(ptx5, pty5, 6); + int[] ptx6 = { x + 4 * width / 6 + width / 24, x + 4 * width / 6 + width / 12 + width / 24 }; + int[] pty6 = { y + height / 8, y + height / 8 }; + g.drawPolygon(ptx6, pty6, 2); + } + + 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[] ptx2 = { x, x + 2 * width / 6, x + 2 * width / 6, x + width / 6, x + 2 * width / 6, x + 2 * width / 6, + x + 3 * width / 6, x + 2 * width / 6, x + 2 * width / 6, x, x + 2 * width / 6, x + 2 * width / 6 }; + int[] pty2 = { y, y, y + height / 4, y + 2 * height / 4, y + 3 * height / 4, y + height / 4, y + 2 * height / 4, + y + 3 * height / 4, y + height, y + height, y + height, y }; + g.drawPolygon(ptx2, pty2, 12); + 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 + 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[] pty5 = { 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(ptx5, pty5, 6); + int[] ptx6 = { x + 4 * width / 6 + width / 24, x + 4 * width / 6 + width / 12 + width / 24 }; + int[] pty6 = { y + height / 8, y + height / 8 }; + g.drawPolygon(ptx6, pty6, 2); + } + + 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[] ptx2 = { x, x + 2 * width / 6, x + 2 * width / 6, x + width / 6, x + 2 * width / 6, x + 2 * width / 6, + x + 3 * width / 6, x + 2 * width / 6, x + 2 * width / 6, x, x + 2 * width / 6, x + 2 * width / 6 }; + int[] pty2 = { y, y, y + height / 4, y + 2 * height / 4, y + 3 * height / 4, y + height / 4, y + 2 * height / 4, + y + 3 * height / 4, y + height, y + height, y + height, y }; + g.drawPolygon(ptx2, pty2, 12); + 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 + 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[] pty5 = { y + height / 8, y + height / 8, y + height / 16, y + height / 8 + height / 16, y + height / 8, + y + height / 8 }; + g.drawPolygon(ptx5, pty5, 6); + int[] ptx6 = { x + 4 * width / 6 + width / 24, x + 4 * width / 6 + width / 12 + width / 24 }; + int[] pty6 = { y + height - height / 8, y + height - height / 8 }; + g.drawPolygon(ptx6, pty6, 2); + } + + 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[] ptx2 = { x, x, x + width / 4, x + 2 * width / 4, x + 3 * width / 4, x + width / 4, x + 2 * width / 4, + x + 3 * width / 4, x + width, x + width, x + width, x }; + int[] pty2 = { y + height, y + 4 * height / 6, y + 4 * height / 6, y + 3 * height / 6, y + 4 * height / 6, + y + 4 * height / 6, y + 5 * height / 6, y + 4 * height / 6, y + 4 * height / 6, y + height, + y + 4 * height / 6, y + 4 * height / 6 }; + g.drawPolygon(ptx2, pty2, 12); + 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 + 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[] pty5 = { 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(ptx5, pty5, 6); + int[] ptx6 = { x + width / 8, x + width / 8 }; + int[] pty6 = { y + 4 * height / 6 + height / 24, y + 4 * height / 6 + height / 12 + height / 24 }; + g.drawPolygon(ptx6, pty6, 2); + } + + 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[] ptx2 = { x, x, x + width / 4, x + 2 * width / 4, x + 3 * width / 4, x + width / 4, x + 2 * width / 4, + x + 3 * width / 4, x + width, x + width, x + width, x }; + int[] pty2 = { y, y + 2 * height / 6, y + 2 * height / 6, y + height / 6, y + 2 * height / 6, + y + 2 * height / 6, y + 3 * height / 6, y + 2 * height / 6, y + 2 * height / 6, y, y + 2 * height / 6, + y + 2 * height / 6 }; + g.drawPolygon(ptx2, pty2, 12); + 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 + 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[] pty5 = { 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(ptx5, pty5, 6); + int[] ptx6 = { x + width / 8, x + width / 8 }; + int[] pty6 = { y + 4 * height / 6 + height / 24, y + 4 * height / 6 + height / 12 + height / 24 }; + g.drawPolygon(ptx6, pty6, 2); + } + + 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[] ptx2 = { x, x, x + width / 4, x + 2 * width / 4, x + 3 * width / 4, x + width / 4, x + 2 * width / 4, + x + 3 * width / 4, x + width, x + width, x + width, x }; + int[] pty2 = { y, y + 2 * height / 6, y + 2 * height / 6, y + height / 6, y + 2 * height / 6, + y + 2 * height / 6, y + 3 * height / 6, y + 2 * height / 6, y + 2 * height / 6, y, y + 2 * height / 6, + y + 2 * height / 6 }; + g.drawPolygon(ptx2, pty2, 12); + 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 / 8, x + width / 8, x + width / 16, x + width / 8 + width / 16, x + width / 8, + x + width / 8 }; + int[] pty5 = { 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(ptx5, pty5, 6); + int[] ptx6 = { x + width - width / 8, x + width - width / 8 }; + int[] pty6 = { y + 4 * height / 6 + height / 24, y + 4 * height / 6 + height / 12 + height / 24 }; + g.drawPolygon(ptx6, pty6, 2); + } + + 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[] ptx2 = { x, x, x + width / 4, x + 2 * width / 4, x + 3 * width / 4, x + width / 4, x + 2 * width / 4, + x + 3 * width / 4, x + width, x + width, x + width, x }; + int[] pty2 = { y + height, y + 4 * height / 6, y + 4 * height / 6, y + 3 * height / 6, y + 4 * height / 6, + y + 4 * height / 6, y + 5 * height / 6, y + 4 * height / 6, y + 4 * height / 6, y + height, + y + 4 * height / 6, y + 4 * height / 6 }; + g.drawPolygon(ptx2, pty2, 12); + 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 / 8, x + width / 8, x + width / 16, x + width / 8 + width / 16, x + width / 8, + x + width / 8 }; + int[] pty5 = { 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(ptx5, pty5, 6); + int[] ptx6 = { x + width - width / 8, x + width - width / 8 }; + int[] pty6 = { y + 4 * height / 6 + height / 24, y + 4 * height / 6 + height / 12 + height / 24 }; + g.drawPolygon(ptx6, pty6, 2); + } + + 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_VOLTAGE_CONTROLLED_VOLTAGE_SOURCE; + } + + public boolean editOndoubleClick(JFrame frame) { + JDialogELNComponentVoltageControlledVoltageSource jde = new JDialogELNComponentVoltageControlledVoltageSource( + this); + jde.setVisible(true); + return true; + } + + protected String translateExtraParam() { + StringBuffer sb = new StringBuffer("<extraparam>\n"); + sb.append("<attributes value=\"" + val + "\""); + 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 value; + + 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")) { + value = Double.parseDouble(elt.getAttribute("value")); setVal(value); - } - } - } - } - } - } catch (Exception e) { - throw new MalformedModelingException(); - } - } - - public int getDefaultConnector() { - return TGComponentManager.ELN_CONNECTOR; - } - - public double getVal() { + } + } + } + } + } + } 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 getVal() { return val; } public void setVal(double _val) { val = _val; } -} \ No newline at end of file +} diff --git a/src/main/java/ui/util/IconManager.java b/src/main/java/ui/util/IconManager.java index d5fcb896ce8a1b0a063123d738c65027ac08c9f8..4e7784cd5c5eb47bdd484eb0dc00fcd517a15eaf 100755 --- a/src/main/java/ui/util/IconManager.java +++ b/src/main/java/ui/util/IconManager.java @@ -186,14 +186,9 @@ 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, imgic8020, imgic8021, imgic8022; + public static ImageIcon imgic8010, imgic8011, imgic8012, imgic8013, imgic8014, imgic8015, imgic8016, imgic8017, imgic8018; //private static String icon7 = "turtle_large.gif"; - private static String ttoolStringIcon = "starting_logo.gif"; - public static ImageIcon ttoolImageIcon; - public static Image ttoolImage; - private static String icon8 = "turtle_16.gif"; private static String icon9 = "diplodocus2_16.gif"; //Added by Solange @@ -680,14 +675,10 @@ public class IconManager { private static String icon8012 = "elninductor.gif"; private static String icon8013 = "elnvcvs.gif"; private static String icon8014 = "elnvccs.gif"; - private static String icon8015 = "elnccvs.gif"; - private static String icon8016 = "elncccs.gif"; - private static String icon8017 = "elnnullor.gif"; - private static String icon8018 = "elngyrator.gif"; - private static String icon8019 = "elnidealtransformer.gif"; - private static String icon8020 = "elntransmissionline.gif"; - private static String icon8021 = "elnvsource.gif"; - private static String icon8022 = "elnisource.gif"; + private static String icon8015 = "elnidealtransformer.gif"; + private static String icon8016 = "elntransmissionline.gif"; + private static String icon8017 = "elnvsource.gif"; + private static String icon8018 = "elnisource.gif"; public IconManager() { @@ -700,7 +691,7 @@ public class IconManager { if (url != null) { return new ImageIcon(url); } else { - + System.out.println("Could not load " + s); } return null; @@ -710,17 +701,13 @@ public class IconManager { ImageIcon imc = new ImageIcon(IconManager.icon12); Image im = imc.getImage(); if (im == null) { - + System.out.println("Cannot load icons"); } else { - + System.out.println("Icons loaded"); } } public static void loadImg() { - - ttoolImageIcon = getIcon(ttoolStringIcon); - ttoolImage = ttoolImageIcon.getImage(); - imgic8 = getIcon(icon8); imgic9 = getIcon(icon9); if (imgic8 != null) { @@ -1190,11 +1177,8 @@ public class IconManager { imgic8016 = getIcon(icon8016); imgic8017 = getIcon(icon8017); imgic8018 = getIcon(icon8018); - imgic8019 = getIcon(icon8019); - imgic8020 = getIcon(icon8020); - imgic8021 = getIcon(icon8021); - imgic8022 = getIcon(icon8022); } } // Class + diff --git a/src/main/resources/ui/util/elncccs.gif b/src/main/resources/ui/util/elncccs.gif deleted file mode 100644 index b964fd107b2cd31714d93cb2d2aa84b81b6677b3..0000000000000000000000000000000000000000 Binary files a/src/main/resources/ui/util/elncccs.gif and /dev/null differ diff --git a/src/main/resources/ui/util/elnccvs.gif b/src/main/resources/ui/util/elnccvs.gif deleted file mode 100644 index e95efa0918ab43879a5eddb12461d94dde76fccc..0000000000000000000000000000000000000000 Binary files a/src/main/resources/ui/util/elnccvs.gif and /dev/null differ diff --git a/src/main/resources/ui/util/elngyrator.gif b/src/main/resources/ui/util/elngyrator.gif deleted file mode 100644 index be0449bf5d67a33bb8f9b06c9549fa89165d149c..0000000000000000000000000000000000000000 Binary files a/src/main/resources/ui/util/elngyrator.gif and /dev/null differ diff --git a/src/main/resources/ui/util/elnnullor.gif b/src/main/resources/ui/util/elnnullor.gif deleted file mode 100644 index dc3e37ae5e768dc1a5f38e9c44ee3ead0bf919f9..0000000000000000000000000000000000000000 Binary files a/src/main/resources/ui/util/elnnullor.gif and /dev/null differ