diff --git a/src/main/java/ui/eln/sca_eln/ELNComponentCapacitor.java b/src/main/java/ui/eln/sca_eln/ELNComponentCapacitor.java index 0723f2df3fa140c2bad27404ada63f19e3e58519..c1e05630b1ca4f676d2d2e52a96a0c050c9953cf 100644 --- a/src/main/java/ui/eln/sca_eln/ELNComponentCapacitor.java +++ b/src/main/java/ui/eln/sca_eln/ELNComponentCapacitor.java @@ -365,7 +365,12 @@ public class ELNComponentCapacitor extends TGCScalableWithInternalComponent impl sb.append("\" q0=\"" + q0); sb.append("\" unit1=\""); sb.append(encode(unit1)); - sb.append("\""); + sb.append("\" position=\"" + position); + sb.append("\" width=\"" + width); + sb.append("\" height=\"" + height); + sb.append("\" fv=\"" + fv); + sb.append("\" fh=\"" + fh); + sb.append("\" first=\"" + first + "\""); sb.append("/>\n"); sb.append("</extraparam>\n"); return new String(sb); @@ -379,6 +384,8 @@ public class ELNComponentCapacitor extends TGCScalableWithInternalComponent impl double value, q0; String unit0, unit1; + int position, width, height; + boolean fv, fh, first; for (int i = 0; i < nl.getLength(); i++) { n1 = nl.item(i); @@ -393,10 +400,22 @@ public class ELNComponentCapacitor extends TGCScalableWithInternalComponent impl q0 = Double.parseDouble(elt.getAttribute("q0")); unit0 = elt.getAttribute("unit0"); unit1 = elt.getAttribute("unit1"); + position = Integer.parseInt(elt.getAttribute("position")); + width = Integer.parseInt(elt.getAttribute("width")); + height = Integer.parseInt(elt.getAttribute("height")); + fv = Boolean.parseBoolean(elt.getAttribute("fv")); + fh = Boolean.parseBoolean(elt.getAttribute("fh")); + first = Boolean.parseBoolean(elt.getAttribute("first")); setVal(value); setQ0(q0); setUnit0(unit0); setUnit1(unit1); + setPosition(position); + this.width = width; + this.height = height; + setFv(fv); + setFh(fh); + setFirst(first); } } } @@ -493,4 +512,36 @@ public class ELNComponentCapacitor extends TGCScalableWithInternalComponent impl public void setUnit1(String _unit1) { unit1 = _unit1; } + + public int getPosition() { + return position; + } + + public void setPosition(int position) { + this.position = position; + } + + public boolean isFv() { + return fv; + } + + public void setFv(boolean fv) { + this.fv = fv; + } + + public boolean isFh() { + return fh; + } + + public void setFh(boolean fh) { + this.fh = fh; + } + + public boolean isFirst() { + return first; + } + + public void setFirst(boolean first) { + this.first = first; + } } diff --git a/src/main/java/ui/eln/sca_eln/ELNComponentIdealTransformer.java b/src/main/java/ui/eln/sca_eln/ELNComponentIdealTransformer.java index ed0a2452424053510811592cd24b87f359ab117c..6cea5ddc756e30abb878f406b5ff11156e54f0fc 100644 --- a/src/main/java/ui/eln/sca_eln/ELNComponentIdealTransformer.java +++ b/src/main/java/ui/eln/sca_eln/ELNComponentIdealTransformer.java @@ -672,7 +672,15 @@ public class ELNComponentIdealTransformer extends TGCScalableWithInternalCompone protected String translateExtraParam() { StringBuffer sb = new StringBuffer("<extraparam>\n"); - sb.append("<attributes ratio=\"" + ratio + "\""); + sb.append("<attributes ratio=\"" + ratio); + sb.append("\" position=\"" + position); + sb.append("\" width=\"" + width); + sb.append("\" height=\"" + height); + sb.append("\" fv_0_2=\"" + fv_0_2); + sb.append("\" fv_1_3=\"" + fv_1_3); + sb.append("\" fh_0_2=\"" + fh_0_2); + sb.append("\" fh_1_3=\"" + fh_1_3); + sb.append("\" first=\"" + first + "\""); sb.append("/>\n"); sb.append("</extraparam>\n"); return new String(sb); @@ -685,6 +693,8 @@ public class ELNComponentIdealTransformer extends TGCScalableWithInternalCompone Element elt; double ratio; + int position, width, height; + boolean fv_0_2, fv_1_3, fh_0_2, fh_1_3, first; for (int i = 0; i < nl.getLength(); i++) { n1 = nl.item(i); @@ -696,7 +706,23 @@ public class ELNComponentIdealTransformer extends TGCScalableWithInternalCompone elt = (Element) n2; if (elt.getTagName().equals("attributes")) { ratio = Double.parseDouble(elt.getAttribute("ratio")); + position = Integer.parseInt(elt.getAttribute("position")); + width = Integer.parseInt(elt.getAttribute("width")); + height = Integer.parseInt(elt.getAttribute("height")); + fv_0_2 = Boolean.parseBoolean(elt.getAttribute("fv_0_2")); + fv_1_3 = Boolean.parseBoolean(elt.getAttribute("fv_1_3")); + fh_0_2 = Boolean.parseBoolean(elt.getAttribute("fh_0_2")); + fh_1_3 = Boolean.parseBoolean(elt.getAttribute("fh_1_3")); + first = Boolean.parseBoolean(elt.getAttribute("first")); setRatio(ratio); + setPosition(position); + this.width = width; + this.height = height; + setFv_0_2(fv_0_2); + setFv_1_3(fv_1_3); + setFh_0_2(fh_0_2); + setFh_1_3(fh_1_3); + setFirst(first); } } } @@ -785,4 +811,52 @@ public class ELNComponentIdealTransformer extends TGCScalableWithInternalCompone public void setRatio(double _ratio) { ratio = _ratio; } + + public int getPosition() { + return position; + } + + public void setPosition(int position) { + this.position = position; + } + + public boolean isFv_0_2() { + return fv_0_2; + } + + public void setFv_0_2(boolean fv_0_2) { + this.fv_0_2 = fv_0_2; + } + + public boolean isFv_1_3() { + return fv_1_3; + } + + public void setFv_1_3(boolean fv_1_3) { + this.fv_1_3 = fv_1_3; + } + + public boolean isFh_0_2() { + return fh_0_2; + } + + public void setFh_0_2(boolean fh_0_2) { + this.fh_0_2 = fh_0_2; + } + + public boolean isFh_1_3() { + return fh_1_3; + } + + public void setFh_1_3(boolean fh_1_3) { + this.fh_1_3 = fh_1_3; + } + + public boolean isFirst() { + return first; + } + + public void setFirst(boolean first) { + this.first = first; + } } diff --git a/src/main/java/ui/eln/sca_eln/ELNComponentIndependentCurrentSource.java b/src/main/java/ui/eln/sca_eln/ELNComponentIndependentCurrentSource.java index ab2d0c6c1291fc8ae9f11463a01c0446d1c87ca9..3eda5b50c32ddb46dd692d433e5b185b59fdab00 100644 --- a/src/main/java/ui/eln/sca_eln/ELNComponentIndependentCurrentSource.java +++ b/src/main/java/ui/eln/sca_eln/ELNComponentIndependentCurrentSource.java @@ -53,111 +53,112 @@ import java.awt.event.ActionEvent; import java.awt.event.ActionListener; /** - * Class ELNComponentIndependentCurrentSource - * Independent current source to be used in ELN diagrams + * Class ELNComponentIndependentCurrentSource + * Independent current source to be used in ELN diagrams * Creation: 15/06/2018 * @version 1.0 15/06/2018 * @author Irina Kit Yan LEE */ public class ELNComponentIndependentCurrentSource extends TGCScalableWithInternalComponent implements ActionListener { - protected Color myColor; - protected int orientation; + protected Color myColor; + protected int orientation; private int maxFontSize = 14; - private int minFontSize = 4; - private int currentFontSize = -1; + private int minFontSize = 4; + private int currentFontSize = -1; - private int textX = 15; - private double dtextX = 0.0; - protected int decPoint = 3; + 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 ELNComponentIndependentCurrentSource(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, 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("ISource"); - - 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; + + public ELNComponentIndependentCurrentSource(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, 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("ISource"); + + 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, 1.0/3.0, 0.0, "p"); - connectingPoint[1] = new ELNConnectingPoint(this, 0, 0, true, true, 1.0/3.0, 1.0, "n"); - } - - public Color getMyColor() { - return myColor; - } - - public void internalDrawing(Graphics g) { - Font f = g.getFont(); - Font fold = f; - - if (this.rescaled && !this.tdp.isScaled()) { - this.rescaled = false; - int maxCurrentFontSize = Math.max(0, Math.min(this.height, (int) (this.maxFontSize * this.tdp.getZoom()))); - f = f.deriveFont((float) maxCurrentFontSize); - - while (maxCurrentFontSize > (this.minFontSize * this.tdp.getZoom() - 1)) { - if (g.getFontMetrics().stringWidth(value) < (width - (2 * textX))) { - break; - } - maxCurrentFontSize--; - f = f.deriveFont((float) maxCurrentFontSize); - } - - if (this.currentFontSize < this.minFontSize * this.tdp.getZoom()) { - maxCurrentFontSize++; - f = f.deriveFont((float) maxCurrentFontSize); - } - g.setFont(f); - this.currentFontSize = maxCurrentFontSize; - } else { - f = f.deriveFont(this.currentFontSize); - } - - Color c = g.getColor(); - double w0 = ((ELNConnectingPoint) connectingPoint[0]).getW(); + } + + public void initConnectingPoint(int nb) { + nbConnectingPoint = nb; + connectingPoint = new TGConnectingPoint[nb]; + connectingPoint[0] = new ELNConnectingPoint(this, 0, 0, true, true, 1.0 / 3.0, 0.0, "p"); + connectingPoint[1] = new ELNConnectingPoint(this, 0, 0, true, true, 1.0 / 3.0, 1.0, "n"); + } + + public Color getMyColor() { + return myColor; + } + + public void internalDrawing(Graphics g) { + Font f = g.getFont(); + Font fold = f; + + if (this.rescaled && !this.tdp.isScaled()) { + this.rescaled = false; + int maxCurrentFontSize = Math.max(0, Math.min(this.height, (int) (this.maxFontSize * this.tdp.getZoom()))); + f = f.deriveFont((float) maxCurrentFontSize); + + while (maxCurrentFontSize > (this.minFontSize * this.tdp.getZoom() - 1)) { + if (g.getFontMetrics().stringWidth(value) < (width - (2 * textX))) { + break; + } + maxCurrentFontSize--; + f = f.deriveFont((float) maxCurrentFontSize); + } + + if (this.currentFontSize < this.minFontSize * this.tdp.getZoom()) { + maxCurrentFontSize++; + f = f.deriveFont((float) maxCurrentFontSize); + } + g.setFont(f); + this.currentFontSize = maxCurrentFontSize; + } else { + f = f.deriveFont(this.currentFontSize); + } + + Color c = g.getColor(); + double w0 = ((ELNConnectingPoint) connectingPoint[0]).getW(); double h0 = ((ELNConnectingPoint) connectingPoint[0]).getH(); double w1 = ((ELNConnectingPoint) connectingPoint[1]).getW(); double h1 = ((ELNConnectingPoint) connectingPoint[1]).getH(); @@ -170,11 +171,6 @@ public class ELNComponentIndependentCurrentSource extends TGCScalableWithInterna 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(); @@ -190,32 +186,52 @@ public class ELNComponentIndependentCurrentSource extends TGCScalableWithInterna || (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); + ((ELNConnectingPoint) connectingPoint[0]).setW(w0); + ((ELNConnectingPoint) connectingPoint[0]).setH(h0); + ((ELNConnectingPoint) connectingPoint[1]).setW(w1); + ((ELNConnectingPoint) connectingPoint[1]).setH(h1); + g.drawString(((ELNConnectingPoint) connectingPoint[0]).getName(), x + width / 3 + width / 6, y); + g.drawString(((ELNConnectingPoint) connectingPoint[1]).getName(), x + width / 3 + width / 6, + 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); + rotateBottomFlip(g); + ((ELNConnectingPoint) connectingPoint[0]).setW(1.0 - w0); + ((ELNConnectingPoint) connectingPoint[0]).setH(h0); + ((ELNConnectingPoint) connectingPoint[1]).setW(1.0 - w1); + ((ELNConnectingPoint) connectingPoint[1]).setH(h1); + g.drawString(((ELNConnectingPoint) connectingPoint[0]).getName(), x + 2 * width / 3 + width / 6, y); + g.drawString(((ELNConnectingPoint) connectingPoint[1]).getName(), x + 2 * width / 3 + width / 6, + 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); + rotateTopFlip(g); + ((ELNConnectingPoint) connectingPoint[0]).setW(w0); + ((ELNConnectingPoint) connectingPoint[0]).setH(h0); + ((ELNConnectingPoint) connectingPoint[1]).setW(w1); + ((ELNConnectingPoint) connectingPoint[1]).setH(h1); + g.drawString(((ELNConnectingPoint) connectingPoint[1]).getName(), x + width / 3 + width / 6, y); + g.drawString(((ELNConnectingPoint) connectingPoint[0]).getName(), x + width / 3 + width / 6, + 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); + ((ELNConnectingPoint) connectingPoint[0]).setW(1.0 - w0); + ((ELNConnectingPoint) connectingPoint[0]).setH(h0); + ((ELNConnectingPoint) connectingPoint[1]).setW(1.0 - w1); + ((ELNConnectingPoint) connectingPoint[1]).setH(h1); + g.drawString(((ELNConnectingPoint) connectingPoint[1]).getName(), x + 2 * width / 3 + width / 6, y); + g.drawString(((ELNConnectingPoint) connectingPoint[0]).getName(), x + 2 * width / 3 + width / 6, + y + height + sh0); } } else if (position == 1) { if (first == false) { @@ -225,11 +241,6 @@ public class ELNComponentIndependentCurrentSource extends TGCScalableWithInterna 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(); @@ -239,7 +250,7 @@ public class ELNComponentIndependentCurrentSource extends TGCScalableWithInterna 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.drawString(value, x + (width - w) / 2, y - height / 3); g.setFont(f.deriveFont(Font.PLAIN)); if ((fv_0_2 == false && fv_1_3 == false && fh_0_2 == false && fh_1_3 == false) @@ -247,40 +258,56 @@ public class ELNComponentIndependentCurrentSource extends TGCScalableWithInterna || (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); + ((ELNConnectingPoint) connectingPoint[0]).setW(h0); + ((ELNConnectingPoint) connectingPoint[0]).setH(w0); + ((ELNConnectingPoint) connectingPoint[1]).setW(h1); + ((ELNConnectingPoint) connectingPoint[1]).setH(w1); + g.drawString(((ELNConnectingPoint) connectingPoint[1]).getName(), x - sw1, + y + height / 3 + height / 6 + sh1); + g.drawString(((ELNConnectingPoint) connectingPoint[0]).getName(), x + width, + y + height / 3 + height / 6 + 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)) { - 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); + rotateRightFlip(g); + ((ELNConnectingPoint) connectingPoint[0]).setW(h0); + ((ELNConnectingPoint) connectingPoint[0]).setH(1.0 - w0); + ((ELNConnectingPoint) connectingPoint[1]).setW(h1); + ((ELNConnectingPoint) connectingPoint[1]).setH(1.0 - w1); + g.drawString(((ELNConnectingPoint) connectingPoint[1]).getName(), x - sw1, + y + 2 * height / 3 + height / 6 + sh1); + g.drawString(((ELNConnectingPoint) connectingPoint[0]).getName(), x + width, + y + 2 * height / 3 + height / 6 + 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[1]).getName(), x - sw1, - y + height / 2 + height / 4 + sh1); - g.drawString(((ELNConnectingPoint) connectingPoint[0]).getName(), x + width, - y + height / 2 + height / 4 + sh0); + rotateLeftFlip(g); + ((ELNConnectingPoint) connectingPoint[0]).setW(h0); + ((ELNConnectingPoint) connectingPoint[0]).setH(w0); + ((ELNConnectingPoint) connectingPoint[1]).setW(h1); + ((ELNConnectingPoint) connectingPoint[1]).setH(w1); + g.drawString(((ELNConnectingPoint) connectingPoint[0]).getName(), x - sw0, + y + height / 3 + height / 6 + sh0); + g.drawString(((ELNConnectingPoint) connectingPoint[1]).getName(), x + width, + y + height / 3 + height / 6 + 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 - sw1, - y + height / 2 + height / 4 + sh1); - g.drawString(((ELNConnectingPoint) connectingPoint[0]).getName(), x + width, - y + height / 2 + height / 4 + sh0); + ((ELNConnectingPoint) connectingPoint[0]).setW(h0); + ((ELNConnectingPoint) connectingPoint[0]).setH(1.0 - w0); + ((ELNConnectingPoint) connectingPoint[1]).setW(h1); + ((ELNConnectingPoint) connectingPoint[1]).setH(1.0 - w1); + g.drawString(((ELNConnectingPoint) connectingPoint[0]).getName(), x - sw0, + y + 2 * height / 3 + height / 6 + sh0); + g.drawString(((ELNConnectingPoint) connectingPoint[1]).getName(), x + width, + y + 2 * height / 3 + height / 6 + sh1); } } else if (position == 2) { if (first == false) { @@ -290,11 +317,6 @@ public class ELNComponentIndependentCurrentSource extends TGCScalableWithInterna 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(); @@ -310,32 +332,52 @@ public class ELNComponentIndependentCurrentSource extends TGCScalableWithInterna || (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); + ((ELNConnectingPoint) connectingPoint[0]).setW(1.0 - w0); + ((ELNConnectingPoint) connectingPoint[0]).setH(h0); + ((ELNConnectingPoint) connectingPoint[1]).setW(1.0 - w1); + ((ELNConnectingPoint) connectingPoint[1]).setH(h1); + g.drawString(((ELNConnectingPoint) connectingPoint[1]).getName(), x + 2 * width / 3 + width / 6, y); + g.drawString(((ELNConnectingPoint) connectingPoint[0]).getName(), x + 2 * width / 3 + width / 6, + 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); + rotateTopFlip(g); + ((ELNConnectingPoint) connectingPoint[0]).setW(w0); + ((ELNConnectingPoint) connectingPoint[0]).setH(h0); + ((ELNConnectingPoint) connectingPoint[1]).setW(w1); + ((ELNConnectingPoint) connectingPoint[1]).setH(h1); + g.drawString(((ELNConnectingPoint) connectingPoint[1]).getName(), x + width / 3 + width / 6, y); + g.drawString(((ELNConnectingPoint) connectingPoint[0]).getName(), x + width / 3 + width / 6, + 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); + rotateBottomFlip(g); + ((ELNConnectingPoint) connectingPoint[0]).setW(1.0 - w0); + ((ELNConnectingPoint) connectingPoint[0]).setH(h0); + ((ELNConnectingPoint) connectingPoint[1]).setW(1.0 - w1); + ((ELNConnectingPoint) connectingPoint[1]).setH(h1); + g.drawString(((ELNConnectingPoint) connectingPoint[0]).getName(), x + 2 * width / 3 + width / 6, y); + g.drawString(((ELNConnectingPoint) connectingPoint[1]).getName(), x + 2 * width / 3 + width / 6, + 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); + ((ELNConnectingPoint) connectingPoint[0]).setW(w0); + ((ELNConnectingPoint) connectingPoint[0]).setH(h0); + ((ELNConnectingPoint) connectingPoint[1]).setW(w1); + ((ELNConnectingPoint) connectingPoint[1]).setH(h1); + g.drawString(((ELNConnectingPoint) connectingPoint[0]).getName(), x + width / 3 + width / 6, y); + g.drawString(((ELNConnectingPoint) connectingPoint[1]).getName(), x + width / 3 + width / 6, + y + height + sh1); } } else if (position == 3) { if (first == false) { @@ -359,7 +401,7 @@ public class ELNComponentIndependentCurrentSource extends TGCScalableWithInterna 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.drawString(value, x + (width - w) / 2, y - height / 3); g.setFont(f.deriveFont(Font.PLAIN)); if ((fv_0_2 == false && fv_1_3 == false && fh_0_2 == false && fh_1_3 == false) @@ -367,204 +409,346 @@ public class ELNComponentIndependentCurrentSource extends TGCScalableWithInterna || (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); + ((ELNConnectingPoint) connectingPoint[0]).setW(h0); + ((ELNConnectingPoint) connectingPoint[0]).setH(1.0 - w0); + ((ELNConnectingPoint) connectingPoint[1]).setW(h1); + ((ELNConnectingPoint) connectingPoint[1]).setH(1.0 - w1); + g.drawString(((ELNConnectingPoint) connectingPoint[0]).getName(), x - sw0, + y + 2 * height / 3 + height / 6 + sh0); + g.drawString(((ELNConnectingPoint) connectingPoint[1]).getName(), x + width, + y + 2 * height / 3 + height / 6 + 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)) { - 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); + rotateLeftFlip(g); + ((ELNConnectingPoint) connectingPoint[0]).setW(h0); + ((ELNConnectingPoint) connectingPoint[0]).setH(w0); + ((ELNConnectingPoint) connectingPoint[1]).setW(h1); + ((ELNConnectingPoint) connectingPoint[1]).setH(w1); + g.drawString(((ELNConnectingPoint) connectingPoint[0]).getName(), x - sw0, + y + height / 3 + height / 6 + sh0); + g.drawString(((ELNConnectingPoint) connectingPoint[1]).getName(), x + width, + y + height / 3 + height / 6 + 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 - sw0, - y + height / 2 + height / 4 + sh0); + rotateRightFlip(g); + ((ELNConnectingPoint) connectingPoint[0]).setW(h0); + ((ELNConnectingPoint) connectingPoint[0]).setH(1.0 - w0); + ((ELNConnectingPoint) connectingPoint[1]).setW(h1); + ((ELNConnectingPoint) connectingPoint[1]).setH(1.0 - w1); + g.drawString(((ELNConnectingPoint) connectingPoint[1]).getName(), x - sw1, + y + 2 * height / 3 + height / 6 + sh1); g.drawString(((ELNConnectingPoint) connectingPoint[0]).getName(), x + width, - y + height / 2 + height / 4 + sh1); + y + 2 * height / 3 + height / 6 + 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 - sw0, - y + height / 2 + height / 4 + sh0); - g.drawString(((ELNConnectingPoint) connectingPoint[1]).getName(), x + width, - y + height / 2 + height / 4 + sh1); + ((ELNConnectingPoint) connectingPoint[0]).setW(h0); + ((ELNConnectingPoint) connectingPoint[0]).setH(w0); + ((ELNConnectingPoint) connectingPoint[1]).setW(h1); + ((ELNConnectingPoint) connectingPoint[1]).setH(w1); + g.drawString(((ELNConnectingPoint) connectingPoint[1]).getName(), x - sw1, + y + height / 3 + height / 6 + sh1); + g.drawString(((ELNConnectingPoint) connectingPoint[0]).getName(), x + width, + y + height / 3 + height / 6 + sh0); } } - g.setColor(c); - g.setFont(fold); - } - - private void rotateTop(Graphics g) { - int [] ptx0 = {x+width/3, x+width/3}; - int [] pty0 = {y, y+height/4}; - g.drawPolygon(ptx0, pty0, 2); - int [] ptx1 = {x+width/3, x+width/3}; - int [] pty1 = {y+3*height/4, y+height}; - g.drawPolygon(ptx1, pty1, 2); - int [] ptx2 = {x, x+2*width/3}; - int [] pty2 = {y+height/2, y+height/2}; - g.drawPolygon(ptx2, pty2, 2); - g.drawOval(x, y+height/4, 2*width/3, height/2); - int [] ptx3 = {x+2*width/3+width/6, x+2*width/3+width/6, x+2*width/3, x+2*width/3+width/6, x+width, x+2*width/3+width/6}; - int [] pty3 = {y+height/4, y+3*height/4, y+3*height/4-width/6, y+3*height/4, y+3*height/4-width/6, y+3*height/4}; - g.drawPolygon(ptx3, pty3, 6); - } - - private void rotateBottom(Graphics g) { - int [] ptx0 = {x+2*width/3, x+2*width/3}; - int [] pty0 = {y, y+height/4}; - g.drawPolygon(ptx0, pty0, 2); - int [] ptx1 = {x+2*width/3, x+2*width/3}; - int [] pty1 = {y+3*height/4, y+height}; - g.drawPolygon(ptx1, pty1, 2); - int [] ptx2 = {x+width/3, x+width}; - int [] pty2 = {y+height/2, y+height/2}; - g.drawPolygon(ptx2, pty2, 2); - g.drawOval(x+width/3, y+height/4, 2*width/3, height/2); - int [] ptx3 = {x+width/6, x+width/6, x, x+width/6, x+width/3, x+width/6}; - int [] pty3 = {y+height/4, y+3*height/4, y+3*height/4-width/6, y+3*height/4, y+3*height/4-width/6, y+3*height/4}; - g.drawPolygon(ptx3, pty3, 6); - } - - 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_CURRENT_SOURCE; - } - - public boolean editOndoubleClick(JFrame frame) { - JDialogELNComponentIndependentCurrentSource jde = new JDialogELNComponentIndependentCurrentSource(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")); + g.setColor(c); + g.setFont(fold); + } + + private void rotateTop(Graphics g) { + int[] ptx0 = { x + width / 3, x + width / 3 }; + int[] pty0 = { y, y + height / 4 }; + g.drawPolygon(ptx0, pty0, 2); + int[] ptx1 = { x + width / 3, x + width / 3 }; + int[] pty1 = { y + 3 * height / 4, y + height }; + g.drawPolygon(ptx1, pty1, 2); + int[] ptx2 = { x, x + 2 * width / 3 }; + int[] pty2 = { y + height / 2, y + height / 2 }; + g.drawPolygon(ptx2, pty2, 2); + g.drawOval(x, y + height / 4, 2 * width / 3, height / 2); + int[] ptx3 = { x + 2 * width / 3 + width / 6, x + 2 * width / 3 + width / 6, + x + 2 * width / 3 + width / 6 - width / 12, x + 2 * width / 3 + width / 6, + x + 2 * width / 3 + width / 6 + width / 12, x + 2 * width / 3 + width / 6 }; + int[] pty3 = { 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(ptx3, pty3, 6); + g.fillPolygon(ptx3, pty3, 6); + } + + private void rotateTopFlip(Graphics g) { + int[] ptx0 = { x + width / 3, x + width / 3 }; + int[] pty0 = { y, y + height / 4 }; + g.drawPolygon(ptx0, pty0, 2); + int[] ptx1 = { x + width / 3, x + width / 3 }; + int[] pty1 = { y + 3 * height / 4, y + height }; + g.drawPolygon(ptx1, pty1, 2); + int[] ptx2 = { x, x + 2 * width / 3 }; + int[] pty2 = { y + height / 2, y + height / 2 }; + g.drawPolygon(ptx2, pty2, 2); + g.drawOval(x, y + height / 4, 2 * width / 3, height / 2); + int[] ptx3 = { x + 2 * width / 3 + width / 6, x + 2 * width / 3 + width / 6, + x + 2 * width / 3 + width / 6 - width / 12, x + 2 * width / 3 + width / 6, + x + 2 * width / 3 + width / 6 + width / 12, x + 2 * width / 3 + width / 6 }; + int[] pty3 = { 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(ptx3, pty3, 6); + g.fillPolygon(ptx3, pty3, 6); + } + + private void rotateBottom(Graphics g) { + int[] ptx0 = { x + 2 * width / 3, x + 2 * width / 3 }; + int[] pty0 = { y, y + height / 4 }; + g.drawPolygon(ptx0, pty0, 2); + int[] ptx1 = { x + 2 * width / 3, x + 2 * width / 3 }; + int[] pty1 = { y + 3 * height / 4, y + height }; + g.drawPolygon(ptx1, pty1, 2); + int[] ptx2 = { x + width / 3, x + width }; + int[] pty2 = { y + height / 2, y + height / 2 }; + g.drawPolygon(ptx2, pty2, 2); + g.drawOval(x + width / 3, y + height / 4, 2 * width / 3, height / 2); + int[] ptx3 = { x + width / 6, x + width / 6, x + width / 6 - width / 12, x + width / 6, + x + width / 6 + width / 12, x + width / 6 }; + int[] pty3 = { 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(ptx3, pty3, 6); + g.fillPolygon(ptx3, pty3, 6); + } + + private void rotateBottomFlip(Graphics g) { + int[] ptx0 = { x + 2 * width / 3, x + 2 * width / 3 }; + int[] pty0 = { y, y + height / 4 }; + g.drawPolygon(ptx0, pty0, 2); + int[] ptx1 = { x + 2 * width / 3, x + 2 * width / 3 }; + int[] pty1 = { y + 3 * height / 4, y + height }; + g.drawPolygon(ptx1, pty1, 2); + int[] ptx2 = { x + width / 3, x + width }; + int[] pty2 = { y + height / 2, y + height / 2 }; + g.drawPolygon(ptx2, pty2, 2); + g.drawOval(x + width / 3, y + height / 4, 2 * width / 3, height / 2); + int[] ptx3 = { x + width / 6, x + width / 6, x + width / 6 - width / 12, x + width / 6, + x + width / 6 + width / 12, x + width / 6 }; + int[] pty3 = { 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(ptx3, pty3, 6); + g.fillPolygon(ptx3, pty3, 6); + } + + private void rotateRight(Graphics g) { + int[] ptx0 = { x, x + width / 4 }; + int[] pty0 = { y + height / 3, y + height / 3 }; + g.drawPolygon(ptx0, pty0, 2); + int[] ptx1 = { x + 3 * width / 4, x + width }; + int[] pty1 = { y + height / 3, y + height / 3 }; + g.drawPolygon(ptx1, pty1, 2); + int[] ptx2 = { x + width / 2, x + width / 2 }; + int[] pty2 = { y, y + 2 * height / 3 }; + g.drawPolygon(ptx2, pty2, 2); + g.drawOval(x + width / 4, y, width / 2, 2 * height / 3); + int[] ptx3 = { 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[] pty3 = { y + 2 * height / 3 + height / 6, y + 2 * height / 3 + height / 6, + y + 2 * height / 3 + height / 6 - height / 12, y + 2 * height / 3 + height / 6, + y + 2 * height / 3 + height / 6 + height / 12, y + 2 * height / 3 + height / 6 }; + g.drawPolygon(ptx3, pty3, 6); + g.fillPolygon(ptx3, pty3, 6); + } + + private void rotateRightFlip(Graphics g) { + int[] ptx0 = { x, x + width / 4 }; + int[] pty0 = { y + 2 * height / 3, y + 2 * height / 3 }; + g.drawPolygon(ptx0, pty0, 2); + int[] ptx1 = { x + 3 * width / 4, x + width }; + int[] pty1 = { y + 2 * height / 3, y + 2 * height / 3 }; + g.drawPolygon(ptx1, pty1, 2); + int[] ptx2 = { x + width / 2, x + width / 2 }; + int[] pty2 = { y + height / 3, y + height }; + g.drawPolygon(ptx2, pty2, 2); + g.drawOval(x + width / 4, y + height / 3, width / 2, 2 * height / 3); + int[] ptx3 = { 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[] pty3 = { y + height / 3 - height / 6, y + height / 3 - height / 6, + y + height / 3 - height / 6 - height / 12, y + height / 3 - height / 6, + y + height / 3 - height / 6 + height / 12, y + height / 3 - height / 6 }; + g.drawPolygon(ptx3, pty3, 6); + g.fillPolygon(ptx3, pty3, 6); + } + + private void rotateLeft(Graphics g) { + int[] ptx0 = { x, x + width / 4 }; + int[] pty0 = { y + 2 * height / 3, y + 2 * height / 3 }; + g.drawPolygon(ptx0, pty0, 2); + int[] ptx1 = { x + 3 * width / 4, x + width }; + int[] pty1 = { y + 2 * height / 3, y + 2 * height / 3 }; + g.drawPolygon(ptx1, pty1, 2); + int[] ptx2 = { x + width / 2, x + width / 2 }; + int[] pty2 = { y + height / 3, y + height }; + g.drawPolygon(ptx2, pty2, 2); + g.drawOval(x + width / 4, y + height / 3, width / 2, 2 * height / 3); + int[] ptx3 = { 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[] pty3 = { y + height / 3 - height / 6, y + height / 3 - height / 6, + y + height / 3 - height / 6 - height / 12, y + height / 3 - height / 6, + y + height / 3 - height / 6 + height / 12, y + height / 3 - height / 6 }; + g.drawPolygon(ptx3, pty3, 6); + g.fillPolygon(ptx3, pty3, 6); + } + + private void rotateLeftFlip(Graphics g) { + int[] ptx0 = { x, x + width / 4 }; + int[] pty0 = { y + height / 3, y + height / 3 }; + g.drawPolygon(ptx0, pty0, 2); + int[] ptx1 = { x + 3 * width / 4, x + width }; + int[] pty1 = { y + height / 3, y + height / 3 }; + g.drawPolygon(ptx1, pty1, 2); + int[] ptx2 = { x + width / 2, x + width / 2 }; + int[] pty2 = { y, y + 2 * height / 3 }; + g.drawPolygon(ptx2, pty2, 2); + g.drawOval(x + width / 4, y, width / 2, 2 * height / 3); + int[] ptx3 = { 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[] pty3 = { y + 2 * height / 3 + height / 6, y + 2 * height / 3 + height / 6, + y + 2 * height / 3 + height / 6 - height / 12, y + 2 * height / 3 + height / 6, + y + 2 * height / 3 + height / 6 + height / 12, y + 2 * height / 3 + height / 6 }; + g.drawPolygon(ptx3, pty3, 6); + g.fillPolygon(ptx3, pty3, 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_INDEPENDENT_CURRENT_SOURCE; + } + + public boolean editOndoubleClick(JFrame frame) { + JDialogELNComponentIndependentCurrentSource jde = new JDialogELNComponentIndependentCurrentSource(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("\" position=\"" + position); + sb.append("\" width=\"" + width); + sb.append("\" height=\"" + height); + sb.append("\" fv_0_2=\"" + fv_0_2); + sb.append("\" fv_1_3=\"" + fv_1_3); + sb.append("\" fh_0_2=\"" + fh_0_2); + sb.append("\" fh_1_3=\"" + fh_1_3); + sb.append("\" first=\"" + first + "\""); + sb.append("/>\n"); + sb.append("</extraparam>\n"); + return new String(sb); + } + + public void loadExtraParam(NodeList nl, int decX, int decY, int decId) throws MalformedModelingException { + try { + NodeList nli; + Node n1, n2; + Element elt; + + double initValue, offset, amplitude, frequency, phase, acAmplitude, acPhase, acNoiseAmplitude; + String delay; + String unit0; + int position, width, height; + boolean fv_0_2, fv_1_3, fh_0_2, fh_1_3, first; + + for (int i = 0; i < nl.getLength(); i++) { + n1 = nl.item(i); + if (n1.getNodeType() == Node.ELEMENT_NODE) { + nli = n1.getChildNodes(); + for (int j = 0; j < nli.getLength(); j++) { + n2 = nli.item(j); + if (n2.getNodeType() == Node.ELEMENT_NODE) { + elt = (Element) n2; + if (elt.getTagName().equals("attributes")) { + 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")); + position = Integer.parseInt(elt.getAttribute("position")); + width = Integer.parseInt(elt.getAttribute("width")); + height = Integer.parseInt(elt.getAttribute("height")); + fv_0_2 = Boolean.parseBoolean(elt.getAttribute("fv_0_2")); + fv_1_3 = Boolean.parseBoolean(elt.getAttribute("fv_1_3")); + fh_0_2 = Boolean.parseBoolean(elt.getAttribute("fh_0_2")); + fh_1_3 = Boolean.parseBoolean(elt.getAttribute("fh_1_3")); + first = Boolean.parseBoolean(elt.getAttribute("first")); setInitValue(initValue); setOffset(offset); setAmplitude(amplitude); setFrequency(frequency); - setUnit0(unit0); - setPhase(phase); + setUnit0(unit0); + setPhase(phase); setDelay(delay); setAcAmplitude(acAmplitude); setAcPhase(acPhase); setAcNoiseAmplitude(acNoiseAmplitude); - } - } - } - } - } - } catch (Exception e) { - throw new MalformedModelingException(); - } - } - + setPosition(position); + this.width = width; + this.height = height; + setFv_0_2(fv_0_2); + setFv_1_3(fv_1_3); + setFh_0_2(fh_0_2); + setFh_1_3(fh_1_3); + setFirst(first); + } + } + } + } + } + } catch (Exception e) { + throw new MalformedModelingException(); + } + } + public void addActionToPopupMenu(JPopupMenu componentMenu, ActionListener menuAL, int x, int y) { componentMenu.addSeparator(); @@ -632,9 +816,9 @@ public class ELNComponentIndependentCurrentSource extends TGCScalableWithInterna } } - public int getDefaultConnector() { - return TGComponentManager.ELN_CONNECTOR; - } + public int getDefaultConnector() { + return TGComponentManager.ELN_CONNECTOR; + } public double getInitValue() { return initValue; @@ -715,4 +899,52 @@ public class ELNComponentIndependentCurrentSource extends TGCScalableWithInterna public void setUnit0(String _unit0) { unit0 = _unit0; } + + public int getPosition() { + return position; + } + + public void setPosition(int position) { + this.position = position; + } + + public boolean isFv_0_2() { + return fv_0_2; + } + + public void setFv_0_2(boolean fv_0_2) { + this.fv_0_2 = fv_0_2; + } + + public boolean isFv_1_3() { + return fv_1_3; + } + + public void setFv_1_3(boolean fv_1_3) { + this.fv_1_3 = fv_1_3; + } + + public boolean isFh_0_2() { + return fh_0_2; + } + + public void setFh_0_2(boolean fh_0_2) { + this.fh_0_2 = fh_0_2; + } + + public boolean isFh_1_3() { + return fh_1_3; + } + + public void setFh_1_3(boolean fh_1_3) { + this.fh_1_3 = fh_1_3; + } + + public boolean isFirst() { + return first; + } + + public void setFirst(boolean first) { + this.first = first; + } } diff --git a/src/main/java/ui/eln/sca_eln/ELNComponentIndependentVoltageSource.java b/src/main/java/ui/eln/sca_eln/ELNComponentIndependentVoltageSource.java index f90f09aa2f6557b2c86467d59e78347bd3d8714b..e30d15c5128eee5452eeb95f71d851628c8e732c 100644 --- a/src/main/java/ui/eln/sca_eln/ELNComponentIndependentVoltageSource.java +++ b/src/main/java/ui/eln/sca_eln/ELNComponentIndependentVoltageSource.java @@ -53,111 +53,112 @@ import java.awt.event.ActionEvent; import java.awt.event.ActionListener; /** - * Class ELNComponentIndependentVoltageSource - * Independent voltage source to be used in ELN diagrams + * 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; + protected Color myColor; + protected int orientation; private int maxFontSize = 14; - private int minFontSize = 4; - private int currentFontSize = -1; + private int minFontSize = 4; + private int currentFontSize = -1; - private int textX = 15; - private double dtextX = 0.0; - protected int decPoint = 3; + 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; + + 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(); + } + + 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(); @@ -190,32 +191,36 @@ public class ELNComponentIndependentVoltageSource extends TGCScalableWithInterna || (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); + 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)) { rotateBottomFlip(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.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)) { rotateTopFlip(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); + 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); + 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) { @@ -310,32 +315,36 @@ public class ELNComponentIndependentVoltageSource extends TGCScalableWithInterna || (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); + 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)) { rotateTopFlip(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); + 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)) { rotateBottomFlip(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.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); + 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) { @@ -403,214 +412,266 @@ public class ELNComponentIndependentVoltageSource extends TGCScalableWithInterna 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 rotateTopFlip(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/8, y+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 rotateBottomFlip(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/8, y+height/8, y+height/8+width/8, y+height/8-width/8, y+height/8, y+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 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-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+height}; - g.drawPolygon(ptx1, pty1, 6); - int [] ptx2 = {x+width/8, x+width/8}; - int [] pty2 = {y+height/2+height/4, y+height}; - g.drawPolygon(ptx2, pty2, 2); - g.drawOval(x+width/4, y, width/2, height); - } - - private void rotateRightFlip(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/4, y+height/4+height/8, y+height/4+height/8, y+height/4+height/8, y+height/4+height/8, y}; - g.drawPolygon(ptx1, pty1, 6); - int [] ptx2 = {x+width/8, x+width/8}; - int [] pty2 = {y+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/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 rotateLeftFlip(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+height}; - 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+height}; - 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")); + 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 rotateTopFlip(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 / 8, y + 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 rotateBottomFlip(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 / 8, y + height / 8, y + height / 8 + width / 8, y + height / 8 - width / 8, + y + height / 8, y + 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 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 - 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 + height }; + g.drawPolygon(ptx1, pty1, 6); + int[] ptx2 = { x + width / 8, x + width / 8 }; + int[] pty2 = { y + height / 2 + height / 4, y + height }; + g.drawPolygon(ptx2, pty2, 2); + g.drawOval(x + width / 4, y, width / 2, height); + } + + private void rotateRightFlip(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 / 4, y + height / 4 + height / 8, y + height / 4 + height / 8, + y + height / 4 + height / 8, y + height / 4 + height / 8, y }; + g.drawPolygon(ptx1, pty1, 6); + int[] ptx2 = { x + width / 8, x + width / 8 }; + int[] pty2 = { y + 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 / 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 rotateLeftFlip(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 + height }; + 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 + height }; + 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("\" position=\"" + position); + sb.append("\" width=\"" + width); + sb.append("\" height=\"" + height); + sb.append("\" fv_0_2=\"" + fv_0_2); + sb.append("\" fv_1_3=\"" + fv_1_3); + sb.append("\" fh_0_2=\"" + fh_0_2); + sb.append("\" fh_1_3=\"" + fh_1_3); + sb.append("\" first=\"" + first + "\""); + sb.append("/>\n"); + sb.append("</extraparam>\n"); + return new String(sb); + } + + public void loadExtraParam(NodeList nl, int decX, int decY, int decId) throws MalformedModelingException { + try { + NodeList nli; + Node n1, n2; + Element elt; + + double initValue, offset, amplitude, frequency, phase, acAmplitude, acPhase, acNoiseAmplitude; + String delay; + String unit0; + int position, width, height; + boolean fv_0_2, fv_1_3, fh_0_2, fh_1_3, first; + + for (int i = 0; i < nl.getLength(); i++) { + n1 = nl.item(i); + if (n1.getNodeType() == Node.ELEMENT_NODE) { + nli = n1.getChildNodes(); + for (int j = 0; j < nli.getLength(); j++) { + n2 = nli.item(j); + if (n2.getNodeType() == Node.ELEMENT_NODE) { + elt = (Element) n2; + if (elt.getTagName().equals("attributes")) { + 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")); + position = Integer.parseInt(elt.getAttribute("position")); + width = Integer.parseInt(elt.getAttribute("width")); + height = Integer.parseInt(elt.getAttribute("height")); + fv_0_2 = Boolean.parseBoolean(elt.getAttribute("fv_0_2")); + fv_1_3 = Boolean.parseBoolean(elt.getAttribute("fv_1_3")); + fh_0_2 = Boolean.parseBoolean(elt.getAttribute("fh_0_2")); + fh_1_3 = Boolean.parseBoolean(elt.getAttribute("fh_1_3")); + first = Boolean.parseBoolean(elt.getAttribute("first")); setInitValue(initValue); setOffset(offset); setAmplitude(amplitude); setFrequency(frequency); - setUnit0(unit0); - setPhase(phase); + setUnit0(unit0); + setPhase(phase); setDelay(delay); setAcAmplitude(acAmplitude); setAcPhase(acPhase); setAcNoiseAmplitude(acNoiseAmplitude); - } - } - } - } - } - } catch (Exception e) { - throw new MalformedModelingException(); - } - } - + setPosition(position); + this.width = width; + this.height = height; + setFv_0_2(fv_0_2); + setFv_1_3(fv_1_3); + setFh_0_2(fh_0_2); + setFh_1_3(fh_1_3); + setFirst(first); + } + } + } + } + } + } catch (Exception e) { + throw new MalformedModelingException(); + } + } + public void addActionToPopupMenu(JPopupMenu componentMenu, ActionListener menuAL, int x, int y) { componentMenu.addSeparator(); @@ -678,9 +739,9 @@ public class ELNComponentIndependentVoltageSource extends TGCScalableWithInterna } } - public int getDefaultConnector() { - return TGComponentManager.ELN_CONNECTOR; - } + public int getDefaultConnector() { + return TGComponentManager.ELN_CONNECTOR; + } public double getInitValue() { return initValue; @@ -761,4 +822,52 @@ public class ELNComponentIndependentVoltageSource extends TGCScalableWithInterna public void setUnit0(String _unit0) { unit0 = _unit0; } + + public int getPosition() { + return position; + } + + public void setPosition(int position) { + this.position = position; + } + + public boolean isFv_0_2() { + return fv_0_2; + } + + public void setFv_0_2(boolean fv_0_2) { + this.fv_0_2 = fv_0_2; + } + + public boolean isFv_1_3() { + return fv_1_3; + } + + public void setFv_1_3(boolean fv_1_3) { + this.fv_1_3 = fv_1_3; + } + + public boolean isFh_0_2() { + return fh_0_2; + } + + public void setFh_0_2(boolean fh_0_2) { + this.fh_0_2 = fh_0_2; + } + + public boolean isFh_1_3() { + return fh_1_3; + } + + public void setFh_1_3(boolean fh_1_3) { + this.fh_1_3 = fh_1_3; + } + + public boolean isFirst() { + return first; + } + + public void setFirst(boolean first) { + this.first = first; + } } diff --git a/src/main/java/ui/eln/sca_eln/ELNComponentInductor.java b/src/main/java/ui/eln/sca_eln/ELNComponentInductor.java index 5a7b5b3e23abbf14f3cc02cac9ad8d9012ae37e3..c2286bb155bb8b59c020d92e38dcd0dfa423974a 100644 --- a/src/main/java/ui/eln/sca_eln/ELNComponentInductor.java +++ b/src/main/java/ui/eln/sca_eln/ELNComponentInductor.java @@ -483,7 +483,14 @@ public class ELNComponentInductor extends TGCScalableWithInternalComponent imple sb.append("\" phi0=\"" + phi0); sb.append("\" unit1=\""); sb.append(encode(unit1)); - sb.append("\""); + sb.append("\" position=\"" + position); + sb.append("\" width=\"" + width); + sb.append("\" height=\"" + height); + sb.append("\" fv_0_2=\"" + fv_0_2); + sb.append("\" fv_1_3=\"" + fv_1_3); + sb.append("\" fh_0_2=\"" + fh_0_2); + sb.append("\" fh_1_3=\"" + fh_1_3); + sb.append("\" first=\"" + first + "\""); sb.append("/>\n"); sb.append("</extraparam>\n"); return new String(sb); @@ -497,6 +504,8 @@ public class ELNComponentInductor extends TGCScalableWithInternalComponent imple double value, phi0; String unit0, unit1; + int position, width, height; + boolean fv_0_2, fv_1_3, fh_0_2, fh_1_3, first; for (int i = 0; i < nl.getLength(); i++) { n1 = nl.item(i); @@ -511,10 +520,26 @@ public class ELNComponentInductor extends TGCScalableWithInternalComponent imple phi0 = Double.parseDouble(elt.getAttribute("phi0")); unit0 = elt.getAttribute("unit0"); unit1 = elt.getAttribute("unit1"); + position = Integer.parseInt(elt.getAttribute("position")); + width = Integer.parseInt(elt.getAttribute("width")); + height = Integer.parseInt(elt.getAttribute("height")); + fv_0_2 = Boolean.parseBoolean(elt.getAttribute("fv_0_2")); + fv_1_3 = Boolean.parseBoolean(elt.getAttribute("fv_1_3")); + fh_0_2 = Boolean.parseBoolean(elt.getAttribute("fh_0_2")); + fh_1_3 = Boolean.parseBoolean(elt.getAttribute("fh_1_3")); + first = Boolean.parseBoolean(elt.getAttribute("first")); setVal(value); setPhi0(phi0); setUnit0(unit0); setUnit1(unit1); + setPosition(position); + this.width = width; + this.height = height; + setFv_0_2(fv_0_2); + setFv_1_3(fv_1_3); + setFh_0_2(fh_0_2); + setFh_1_3(fh_1_3); + setFirst(first); } } } @@ -627,4 +652,52 @@ public class ELNComponentInductor extends TGCScalableWithInternalComponent imple public void setUnit1(String _unit1) { unit1 = _unit1; } + + public int getPosition() { + return position; + } + + public void setPosition(int position) { + this.position = position; + } + + public boolean isFv_0_2() { + return fv_0_2; + } + + public void setFv_0_2(boolean fv_0_2) { + this.fv_0_2 = fv_0_2; + } + + public boolean isFv_1_3() { + return fv_1_3; + } + + public void setFv_1_3(boolean fv_1_3) { + this.fv_1_3 = fv_1_3; + } + + public boolean isFh_0_2() { + return fh_0_2; + } + + public void setFh_0_2(boolean fh_0_2) { + this.fh_0_2 = fh_0_2; + } + + public boolean isFh_1_3() { + return fh_1_3; + } + + public void setFh_1_3(boolean fh_1_3) { + this.fh_1_3 = fh_1_3; + } + + public boolean isFirst() { + return first; + } + + public void setFirst(boolean first) { + this.first = first; + } } diff --git a/src/main/java/ui/eln/sca_eln/ELNComponentResistor.java b/src/main/java/ui/eln/sca_eln/ELNComponentResistor.java index c8a2a6a13ceabfca8db4c09e91047436f0ee7f07..280c3d6450ac4d31ff4cae1fcd01c6c5c4bcefdf 100644 --- a/src/main/java/ui/eln/sca_eln/ELNComponentResistor.java +++ b/src/main/java/ui/eln/sca_eln/ELNComponentResistor.java @@ -361,12 +361,17 @@ public class ELNComponentResistor extends TGCScalableWithInternalComponent imple sb.append("<attributes value=\"" + val); sb.append("\" unit=\""); sb.append(encode(unit)); - sb.append("\""); + sb.append("\" position=\"" + position); + sb.append("\" width=\"" + width); + sb.append("\" height=\"" + height); + sb.append("\" fv=\"" + fv); + sb.append("\" fh=\"" + fh); + sb.append("\" first=\"" + first + "\""); sb.append("/>\n"); sb.append("</extraparam>\n"); return new String(sb); } - + public void loadExtraParam(NodeList nl, int decX, int decY, int decId) throws MalformedModelingException { try { NodeList nli; @@ -375,7 +380,9 @@ public class ELNComponentResistor extends TGCScalableWithInternalComponent imple double value; String unit; - + int position, width, height; + boolean fv, fh, first; + for (int i = 0; i < nl.getLength(); i++) { n1 = nl.item(i); if (n1.getNodeType() == Node.ELEMENT_NODE) { @@ -387,8 +394,20 @@ public class ELNComponentResistor extends TGCScalableWithInternalComponent imple if (elt.getTagName().equals("attributes")) { value = Double.parseDouble(elt.getAttribute("value")); unit = elt.getAttribute("unit"); + position = Integer.parseInt(elt.getAttribute("position")); + width = Integer.parseInt(elt.getAttribute("width")); + height = Integer.parseInt(elt.getAttribute("height")); + fv = Boolean.parseBoolean(elt.getAttribute("fv")); + fh = Boolean.parseBoolean(elt.getAttribute("fh")); + first = Boolean.parseBoolean(elt.getAttribute("first")); setVal(value); setUnit(unit); + setPosition(position); + this.width = width; + this.height = height; + setFv(fv); + setFh(fh); + setFirst(first); } } } @@ -469,4 +488,36 @@ public class ELNComponentResistor extends TGCScalableWithInternalComponent imple public void setUnit(String _unit) { unit = _unit; } + + public int getPosition() { + return position; + } + + public void setPosition(int position) { + this.position = position; + } + + public boolean isFv() { + return fv; + } + + public void setFv(boolean fv) { + this.fv = fv; + } + + public boolean isFh() { + return fh; + } + + public void setFh(boolean fh) { + this.fh = fh; + } + + public boolean isFirst() { + return first; + } + + public void setFirst(boolean first) { + this.first = first; + } } diff --git a/src/main/java/ui/eln/sca_eln/ELNComponentTransmissionLine.java b/src/main/java/ui/eln/sca_eln/ELNComponentTransmissionLine.java index 97c0825a564763aebf645b88425dc65c98285892..b60f2dbb98a754fea43b81cc61038bf0b7f7d11b 100644 --- a/src/main/java/ui/eln/sca_eln/ELNComponentTransmissionLine.java +++ b/src/main/java/ui/eln/sca_eln/ELNComponentTransmissionLine.java @@ -550,7 +550,15 @@ public class ELNComponentTransmissionLine extends TGCScalableWithInternalCompone sb.append("\" unit0=\"" + encode(unit0)); sb.append("\" delay=\"" + delay); sb.append("\" delta0=\"" + delta0); - sb.append("\" unit2=\"" + encode(unit2) + "\""); + sb.append("\" unit2=\"" + encode(unit2)); + sb.append("\" position=\"" + position); + sb.append("\" width=\"" + width); + sb.append("\" height=\"" + height); + sb.append("\" fv_0_2=\"" + fv_0_2); + sb.append("\" fv_1_3=\"" + fv_1_3); + sb.append("\" fh_0_2=\"" + fh_0_2); + sb.append("\" fh_1_3=\"" + fh_1_3); + sb.append("\" first=\"" + first + "\""); sb.append("/>\n"); sb.append("</extraparam>\n"); return new String(sb); @@ -565,6 +573,8 @@ public class ELNComponentTransmissionLine extends TGCScalableWithInternalCompone double z0, delta0; String delay; String unit0, unit2; + int position, width, height; + boolean fv_0_2, fv_1_3, fh_0_2, fh_1_3, first; for (int i = 0; i < nl.getLength(); i++) { n1 = nl.item(i); @@ -580,11 +590,27 @@ public class ELNComponentTransmissionLine extends TGCScalableWithInternalCompone delay = elt.getAttribute("delay"); delta0 = Double.parseDouble(elt.getAttribute("delta0")); unit2 = elt.getAttribute("unit2"); + position = Integer.parseInt(elt.getAttribute("position")); + width = Integer.parseInt(elt.getAttribute("width")); + height = Integer.parseInt(elt.getAttribute("height")); + fv_0_2 = Boolean.parseBoolean(elt.getAttribute("fv_0_2")); + fv_1_3 = Boolean.parseBoolean(elt.getAttribute("fv_1_3")); + fh_0_2 = Boolean.parseBoolean(elt.getAttribute("fh_0_2")); + fh_1_3 = Boolean.parseBoolean(elt.getAttribute("fh_1_3")); + first = Boolean.parseBoolean(elt.getAttribute("first")); setZ0(z0); setUnit0(unit0); setDelay(delay); setDelta0(delta0); setUnit2(unit2); + setPosition(position); + this.width = width; + this.height = height; + setFv_0_2(fv_0_2); + setFv_1_3(fv_1_3); + setFh_0_2(fh_0_2); + setFh_1_3(fh_1_3); + setFirst(first); } } } @@ -705,4 +731,52 @@ public class ELNComponentTransmissionLine extends TGCScalableWithInternalCompone public void setUnit2(String _unit2) { unit2 = _unit2; } + + public int getPosition() { + return position; + } + + public void setPosition(int position) { + this.position = position; + } + + public boolean isFv_0_2() { + return fv_0_2; + } + + public void setFv_0_2(boolean fv_0_2) { + this.fv_0_2 = fv_0_2; + } + + public boolean isFv_1_3() { + return fv_1_3; + } + + public void setFv_1_3(boolean fv_1_3) { + this.fv_1_3 = fv_1_3; + } + + public boolean isFh_0_2() { + return fh_0_2; + } + + public void setFh_0_2(boolean fh_0_2) { + this.fh_0_2 = fh_0_2; + } + + public boolean isFh_1_3() { + return fh_1_3; + } + + public void setFh_1_3(boolean fh_1_3) { + this.fh_1_3 = fh_1_3; + } + + public boolean isFirst() { + return first; + } + + public void setFirst(boolean first) { + this.first = first; + } } diff --git a/src/main/java/ui/eln/sca_eln/ELNComponentVoltageControlledCurrentSource.java b/src/main/java/ui/eln/sca_eln/ELNComponentVoltageControlledCurrentSource.java index a7fcf1b30d75ed68bf5849b132e85636cda31e6b..fc6e6f745244d43b8bbcd51b7895bc165a3c6488 100644 --- a/src/main/java/ui/eln/sca_eln/ELNComponentVoltageControlledCurrentSource.java +++ b/src/main/java/ui/eln/sca_eln/ELNComponentVoltageControlledCurrentSource.java @@ -776,7 +776,15 @@ public class ELNComponentVoltageControlledCurrentSource extends TGCScalableWithI protected String translateExtraParam() { StringBuffer sb = new StringBuffer("<extraparam>\n"); sb.append("<attributes value=\"" + val); - sb.append("\" unit=\"" + encode(unit) + "\""); + sb.append("\" unit=\"" + encode(unit)); + sb.append("\" position=\"" + position); + sb.append("\" width=\"" + width); + sb.append("\" height=\"" + height); + sb.append("\" fv_0_2=\"" + fv_0_2); + sb.append("\" fv_1_3=\"" + fv_1_3); + sb.append("\" fh_0_2=\"" + fh_0_2); + sb.append("\" fh_1_3=\"" + fh_1_3); + sb.append("\" first=\"" + first + "\""); sb.append("/>\n"); sb.append("</extraparam>\n"); return new String(sb); @@ -790,6 +798,8 @@ public class ELNComponentVoltageControlledCurrentSource extends TGCScalableWithI double value; String unit; + int position, width, height; + boolean fv_0_2, fv_1_3, fh_0_2, fh_1_3, first; for (int i = 0; i < nl.getLength(); i++) { n1 = nl.item(i); @@ -802,8 +812,24 @@ public class ELNComponentVoltageControlledCurrentSource extends TGCScalableWithI if (elt.getTagName().equals("attributes")) { value = Double.parseDouble(elt.getAttribute("value")); unit = elt.getAttribute("unit"); + position = Integer.parseInt(elt.getAttribute("position")); + width = Integer.parseInt(elt.getAttribute("width")); + height = Integer.parseInt(elt.getAttribute("height")); + fv_0_2 = Boolean.parseBoolean(elt.getAttribute("fv_0_2")); + fv_1_3 = Boolean.parseBoolean(elt.getAttribute("fv_1_3")); + fh_0_2 = Boolean.parseBoolean(elt.getAttribute("fh_0_2")); + fh_1_3 = Boolean.parseBoolean(elt.getAttribute("fh_1_3")); + first = Boolean.parseBoolean(elt.getAttribute("first")); setVal(value); setUnit(unit); + setPosition(position); + this.width = width; + this.height = height; + setFv_0_2(fv_0_2); + setFv_1_3(fv_1_3); + setFh_0_2(fh_0_2); + setFh_1_3(fh_1_3); + setFirst(first); } } } @@ -900,4 +926,52 @@ public class ELNComponentVoltageControlledCurrentSource extends TGCScalableWithI public void setUnit(String _unit) { unit = _unit; } + + public int getPosition() { + return position; + } + + public void setPosition(int position) { + this.position = position; + } + + public boolean isFv_0_2() { + return fv_0_2; + } + + public void setFv_0_2(boolean fv_0_2) { + this.fv_0_2 = fv_0_2; + } + + public boolean isFv_1_3() { + return fv_1_3; + } + + public void setFv_1_3(boolean fv_1_3) { + this.fv_1_3 = fv_1_3; + } + + public boolean isFh_0_2() { + return fh_0_2; + } + + public void setFh_0_2(boolean fh_0_2) { + this.fh_0_2 = fh_0_2; + } + + public boolean isFh_1_3() { + return fh_1_3; + } + + public void setFh_1_3(boolean fh_1_3) { + this.fh_1_3 = fh_1_3; + } + + public boolean isFirst() { + return first; + } + + public void setFirst(boolean first) { + this.first = first; + } } diff --git a/src/main/java/ui/eln/sca_eln/ELNComponentVoltageControlledVoltageSource.java b/src/main/java/ui/eln/sca_eln/ELNComponentVoltageControlledVoltageSource.java index 3a1934db3f9e313cad779fd6b31452adf58c2e71..0fc0e07597b6c5dadfd8a404882748a294b9ccae 100644 --- a/src/main/java/ui/eln/sca_eln/ELNComponentVoltageControlledVoltageSource.java +++ b/src/main/java/ui/eln/sca_eln/ELNComponentVoltageControlledVoltageSource.java @@ -770,7 +770,15 @@ public class ELNComponentVoltageControlledVoltageSource extends TGCScalableWithI protected String translateExtraParam() { StringBuffer sb = new StringBuffer("<extraparam>\n"); - sb.append("<attributes value=\"" + val + "\""); + sb.append("<attributes value=\"" + val); + sb.append("\" position=\"" + position); + sb.append("\" width=\"" + width); + sb.append("\" height=\"" + height); + sb.append("\" fv_0_2=\"" + fv_0_2); + sb.append("\" fv_1_3=\"" + fv_1_3); + sb.append("\" fh_0_2=\"" + fh_0_2); + sb.append("\" fh_1_3=\"" + fh_1_3); + sb.append("\" first=\"" + first + "\""); sb.append("/>\n"); sb.append("</extraparam>\n"); return new String(sb); @@ -783,6 +791,8 @@ public class ELNComponentVoltageControlledVoltageSource extends TGCScalableWithI Element elt; double value; + int position, width, height; + boolean fv_0_2, fv_1_3, fh_0_2, fh_1_3, first; for (int i = 0; i < nl.getLength(); i++) { n1 = nl.item(i); @@ -794,7 +804,23 @@ public class ELNComponentVoltageControlledVoltageSource extends TGCScalableWithI elt = (Element) n2; if (elt.getTagName().equals("attributes")) { value = Double.parseDouble(elt.getAttribute("value")); + position = Integer.parseInt(elt.getAttribute("position")); + width = Integer.parseInt(elt.getAttribute("width")); + height = Integer.parseInt(elt.getAttribute("height")); + fv_0_2 = Boolean.parseBoolean(elt.getAttribute("fv_0_2")); + fv_1_3 = Boolean.parseBoolean(elt.getAttribute("fv_1_3")); + fh_0_2 = Boolean.parseBoolean(elt.getAttribute("fh_0_2")); + fh_1_3 = Boolean.parseBoolean(elt.getAttribute("fh_1_3")); + first = Boolean.parseBoolean(elt.getAttribute("first")); setVal(value); + setPosition(position); + this.width = width; + this.height = height; + setFv_0_2(fv_0_2); + setFv_1_3(fv_1_3); + setFh_0_2(fh_0_2); + setFh_1_3(fh_1_3); + setFirst(first); } } } @@ -883,4 +909,52 @@ public class ELNComponentVoltageControlledVoltageSource extends TGCScalableWithI public void setVal(double _val) { val = _val; } + + public int getPosition() { + return position; + } + + public void setPosition(int position) { + this.position = position; + } + + public boolean isFv_0_2() { + return fv_0_2; + } + + public void setFv_0_2(boolean fv_0_2) { + this.fv_0_2 = fv_0_2; + } + + public boolean isFv_1_3() { + return fv_1_3; + } + + public void setFv_1_3(boolean fv_1_3) { + this.fv_1_3 = fv_1_3; + } + + public boolean isFh_0_2() { + return fh_0_2; + } + + public void setFh_0_2(boolean fh_0_2) { + this.fh_0_2 = fh_0_2; + } + + public boolean isFh_1_3() { + return fh_1_3; + } + + public void setFh_1_3(boolean fh_1_3) { + this.fh_1_3 = fh_1_3; + } + + public boolean isFirst() { + return first; + } + + public void setFirst(boolean first) { + this.first = first; + } } diff --git a/src/main/resources/ui/util/elnidealtransformer.gif b/src/main/resources/ui/util/elnidealtransformer.gif index 31ccc71c22feb4dffbd1f0bd281ddf5aa4103218..b5c551d05e3c502ee30bd514b5d3b94918498606 100644 Binary files a/src/main/resources/ui/util/elnidealtransformer.gif and b/src/main/resources/ui/util/elnidealtransformer.gif differ diff --git a/src/main/resources/ui/util/elninductor.gif b/src/main/resources/ui/util/elninductor.gif index 117084ae95e3a654607c891b89903694a73f8b6f..9baf5d1151cfa7d05fef0b4b2e1ddb2bfce47270 100644 Binary files a/src/main/resources/ui/util/elninductor.gif and b/src/main/resources/ui/util/elninductor.gif differ