From 2d0347082cf90d3a342d5d8b14e858f3d2265f3a Mon Sep 17 00:00:00 2001 From: "Irina Lee [m1]" <irina.lee@etu.upmc.fr> Date: Fri, 13 Jul 2018 12:32:43 +0200 Subject: [PATCH] added new component : module (eln) --- src/main/java/ui/eln/ELNModule.java | 57 ++++++- .../sca_eln/ELNComponentIdealTransformer.java | 6 +- .../ELNComponentIndependentCurrentSource.java | 6 +- .../ELNComponentIndependentVoltageSource.java | 6 +- .../ui/eln/sca_eln/ELNComponentInductor.java | 6 +- .../ui/eln/sca_eln/ELNComponentNodeRef.java | 2 +- .../ui/eln/sca_eln/ELNComponentResistor.java | 6 +- .../sca_eln/ELNComponentTransmissionLine.java | 6 +- ...mponentVoltageControlledCurrentSource.java | 6 +- ...mponentVoltageControlledVoltageSource.java | 6 +- .../SysCAMSComponentTaskDiagramPanel.java | 29 ---- .../ui/syscams/SysCAMSCompositeComponent.java | 82 +-------- src/main/java/ui/window/JDialogELNModule.java | 155 ++++++++++++++++++ .../java/ui/window/JDialogSysCAMSBlockDE.java | 1 + 14 files changed, 252 insertions(+), 122 deletions(-) create mode 100644 src/main/java/ui/window/JDialogELNModule.java diff --git a/src/main/java/ui/eln/ELNModule.java b/src/main/java/ui/eln/ELNModule.java index 517a64c6fb..72d7cd971c 100644 --- a/src/main/java/ui/eln/ELNModule.java +++ b/src/main/java/ui/eln/ELNModule.java @@ -40,14 +40,20 @@ package ui.eln; import myutil.GraphicLib; import ui.*; -import ui.eln.sca_eln.ELNComponentCapacitor; import ui.eln.sca_eln.ELNComponentNodeRef; +import ui.syscams.SysCAMSComponentTaskDiagramPanel; +import ui.util.IconManager; +import ui.window.JDialogELNComponentCapacitor; +import ui.window.JDialogELNModule; import java.awt.*; +import javax.swing.JFrame; +import javax.swing.JOptionPane; + /** - * Class ELNComponentCapacitor - * Capacitor to be used in ELN diagrams + * Class ELNModule + * Module to be used in ELN diagrams * Creation: 12/06/2018 * @version 1.0 12/06/2018 * @author Irina Kit Yan LEE @@ -63,12 +69,13 @@ public class ELNModule extends TGCScalableWithInternalComponent implements Swall private int textX = 15; private double dtextX = 0.0; protected int decPoint = 3; - + public ELNModule(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(250, 200); + oldScaleFactor = tdp.getZoom(); dtextX = textX * oldScaleFactor; textX = (int) dtextX; dtextX = dtextX - textX; @@ -79,9 +86,10 @@ public class ELNModule extends TGCScalableWithInternalComponent implements Swall addTGConnectingPointsComment(); moveable = true; + multieditable = true; editable = true; removable = true; - userResizable = false; + userResizable = true; value = tdp.findELNComponentName("Module_"); } @@ -142,6 +150,13 @@ public class ELNModule extends TGCScalableWithInternalComponent implements Swall g.setFont(fold); } + public void rescale(double scaleFactor){ + dtextX = (textX + dtextX) / oldScaleFactor * scaleFactor; + textX = (int)(dtextX); + dtextX = dtextX - textX; + super.rescale(scaleFactor); + } + public TGComponent isOnOnlyMe(int _x, int _y) { if (GraphicLib.isInRectangle(_x, _y, x, y, width, height)) { return this; @@ -152,6 +167,38 @@ public class ELNModule extends TGCScalableWithInternalComponent implements Swall public int getType() { return TGComponentManager.ELN_MODULE; } + + public boolean editOndoubleClick(JFrame frame, int _x, int _y) { + // On the name ? + if (_y <= (y + currentFontSize + textX)) { + String s = (String)JOptionPane.showInputDialog(frame, "Name:", "Setting component name", + JOptionPane.PLAIN_MESSAGE, IconManager.imgic100, + null, + getValue()); + if ((s != null) && (s.length() > 0)) { + + if (!TAttribute.isAValidId(s, false, false)) { + JOptionPane.showMessageDialog(frame, + "Could not change the name of the component: the new name is not a valid name", + "Error", + JOptionPane.INFORMATION_MESSAGE); + return false; + } + setComponentName(s); + setValueWithChange(s); + setValue(s); + rescaled = true; + return true; + + } + return false; + } + + JDialogELNModule jde = new JDialogELNModule(this); + jde.setVisible(true); + rescaled = true; + return true; + } public int getDefaultConnector() { return TGComponentManager.ELN_CONNECTOR; diff --git a/src/main/java/ui/eln/sca_eln/ELNComponentIdealTransformer.java b/src/main/java/ui/eln/sca_eln/ELNComponentIdealTransformer.java index ece4f8dc60..90e765b3cf 100644 --- a/src/main/java/ui/eln/sca_eln/ELNComponentIdealTransformer.java +++ b/src/main/java/ui/eln/sca_eln/ELNComponentIdealTransformer.java @@ -58,7 +58,7 @@ import java.awt.event.ActionListener; * @author Irina Kit Yan LEE */ -public class ELNComponentIdealTransformer extends TGCScalableWithInternalComponent implements ActionListener, SwallowTGComponent, ELNComponent { +public class ELNComponentIdealTransformer extends TGCScalableWithInternalComponent implements ActionListener, SwallowTGComponent, SwallowedTGComponent, ELNComponent { protected Color myColor; protected int orientation; private int maxFontSize = 14; @@ -1019,6 +1019,10 @@ public class ELNComponentIdealTransformer extends TGCScalableWithInternalCompone tgcomponent[i].resizeWithFather(); } } + + if (getFather() != null) { + resizeWithFather(); + } } public void resizeWithFather() { diff --git a/src/main/java/ui/eln/sca_eln/ELNComponentIndependentCurrentSource.java b/src/main/java/ui/eln/sca_eln/ELNComponentIndependentCurrentSource.java index f6da94c2c7..76aaf26191 100644 --- a/src/main/java/ui/eln/sca_eln/ELNComponentIndependentCurrentSource.java +++ b/src/main/java/ui/eln/sca_eln/ELNComponentIndependentCurrentSource.java @@ -58,7 +58,7 @@ import java.awt.event.ActionListener; * @author Irina Kit Yan LEE */ -public class ELNComponentIndependentCurrentSource extends TGCScalableWithInternalComponent implements ActionListener, SwallowTGComponent, ELNComponent { +public class ELNComponentIndependentCurrentSource extends TGCScalableWithInternalComponent implements ActionListener, SwallowTGComponent, SwallowedTGComponent, ELNComponent { protected Color myColor; protected int orientation; private int maxFontSize = 14; @@ -975,6 +975,10 @@ public class ELNComponentIndependentCurrentSource extends TGCScalableWithInterna tgcomponent[i].resizeWithFather(); } } + + if (getFather() != null) { + resizeWithFather(); + } } public void resizeWithFather() { diff --git a/src/main/java/ui/eln/sca_eln/ELNComponentIndependentVoltageSource.java b/src/main/java/ui/eln/sca_eln/ELNComponentIndependentVoltageSource.java index fb73a46a4b..07c764496d 100644 --- a/src/main/java/ui/eln/sca_eln/ELNComponentIndependentVoltageSource.java +++ b/src/main/java/ui/eln/sca_eln/ELNComponentIndependentVoltageSource.java @@ -58,7 +58,7 @@ import java.awt.event.ActionListener; * @author Irina Kit Yan LEE */ -public class ELNComponentIndependentVoltageSource extends TGCScalableWithInternalComponent implements ActionListener, SwallowTGComponent, ELNComponent { +public class ELNComponentIndependentVoltageSource extends TGCScalableWithInternalComponent implements ActionListener, SwallowTGComponent, SwallowedTGComponent, ELNComponent { protected Color myColor; protected int orientation; private int maxFontSize = 14; @@ -947,6 +947,10 @@ public class ELNComponentIndependentVoltageSource extends TGCScalableWithInterna tgcomponent[i].resizeWithFather(); } } + + if (getFather() != null) { + resizeWithFather(); + } } public void resizeWithFather() { diff --git a/src/main/java/ui/eln/sca_eln/ELNComponentInductor.java b/src/main/java/ui/eln/sca_eln/ELNComponentInductor.java index 64780a38de..f7358f3cb8 100644 --- a/src/main/java/ui/eln/sca_eln/ELNComponentInductor.java +++ b/src/main/java/ui/eln/sca_eln/ELNComponentInductor.java @@ -59,7 +59,7 @@ import java.awt.event.ActionListener; * @author Irina Kit Yan LEE */ -public class ELNComponentInductor extends TGCScalableWithInternalComponent implements ActionListener, SwallowTGComponent, ELNComponent { +public class ELNComponentInductor extends TGCScalableWithInternalComponent implements ActionListener, SwallowTGComponent, SwallowedTGComponent, ELNComponent { protected Color myColor; protected int orientation; private int maxFontSize = 14; @@ -779,6 +779,10 @@ public class ELNComponentInductor extends TGCScalableWithInternalComponent imple tgcomponent[i].resizeWithFather(); } } + + if (getFather() != null) { + resizeWithFather(); + } } public void resizeWithFather() { diff --git a/src/main/java/ui/eln/sca_eln/ELNComponentNodeRef.java b/src/main/java/ui/eln/sca_eln/ELNComponentNodeRef.java index ce80540ea2..fb868d0ba4 100644 --- a/src/main/java/ui/eln/sca_eln/ELNComponentNodeRef.java +++ b/src/main/java/ui/eln/sca_eln/ELNComponentNodeRef.java @@ -60,7 +60,7 @@ import java.awt.event.ActionListener; * @author Irina Kit Yan LEE */ -public class ELNComponentNodeRef extends TGCScalableWithInternalComponent implements ActionListener { +public class ELNComponentNodeRef extends TGCScalableWithInternalComponent implements SwallowedTGComponent, ActionListener { protected Color myColor; protected int orientation; private int maxFontSize = 14; diff --git a/src/main/java/ui/eln/sca_eln/ELNComponentResistor.java b/src/main/java/ui/eln/sca_eln/ELNComponentResistor.java index f6693bacd9..31e9712b3e 100644 --- a/src/main/java/ui/eln/sca_eln/ELNComponentResistor.java +++ b/src/main/java/ui/eln/sca_eln/ELNComponentResistor.java @@ -58,7 +58,7 @@ import java.awt.event.ActionListener; * @author Irina Kit Yan LEE */ -public class ELNComponentResistor extends TGCScalableWithInternalComponent implements ActionListener, SwallowTGComponent, ELNComponent { +public class ELNComponentResistor extends TGCScalableWithInternalComponent implements ActionListener, SwallowTGComponent, SwallowedTGComponent, ELNComponent { protected Color myColor; protected int orientation; private int maxFontSize = 14; @@ -732,6 +732,10 @@ public class ELNComponentResistor extends TGCScalableWithInternalComponent imple tgcomponent[i].resizeWithFather(); } } + + if (getFather() != null) { + resizeWithFather(); + } } public void resizeWithFather() { diff --git a/src/main/java/ui/eln/sca_eln/ELNComponentTransmissionLine.java b/src/main/java/ui/eln/sca_eln/ELNComponentTransmissionLine.java index 08fe7876aa..3b3551de6d 100644 --- a/src/main/java/ui/eln/sca_eln/ELNComponentTransmissionLine.java +++ b/src/main/java/ui/eln/sca_eln/ELNComponentTransmissionLine.java @@ -58,7 +58,7 @@ import java.awt.event.ActionListener; * @author Irina Kit Yan LEE */ -public class ELNComponentTransmissionLine extends TGCScalableWithInternalComponent implements ActionListener, SwallowTGComponent, ELNComponent { +public class ELNComponentTransmissionLine extends TGCScalableWithInternalComponent implements ActionListener, SwallowTGComponent, SwallowedTGComponent, ELNComponent { protected Color myColor; protected int orientation; private int maxFontSize = 14; @@ -935,6 +935,10 @@ public class ELNComponentTransmissionLine extends TGCScalableWithInternalCompone tgcomponent[i].resizeWithFather(); } } + + if (getFather() != null) { + resizeWithFather(); + } } public void resizeWithFather() { diff --git a/src/main/java/ui/eln/sca_eln/ELNComponentVoltageControlledCurrentSource.java b/src/main/java/ui/eln/sca_eln/ELNComponentVoltageControlledCurrentSource.java index b53dc02644..da6a457557 100644 --- a/src/main/java/ui/eln/sca_eln/ELNComponentVoltageControlledCurrentSource.java +++ b/src/main/java/ui/eln/sca_eln/ELNComponentVoltageControlledCurrentSource.java @@ -58,7 +58,7 @@ import java.awt.event.ActionListener; * @author Irina Kit Yan LEE */ -public class ELNComponentVoltageControlledCurrentSource extends TGCScalableWithInternalComponent implements ActionListener, SwallowTGComponent, ELNComponent { +public class ELNComponentVoltageControlledCurrentSource extends TGCScalableWithInternalComponent implements ActionListener, SwallowTGComponent, SwallowedTGComponent, ELNComponent { protected Color myColor; protected int orientation; private int maxFontSize = 14; @@ -1137,6 +1137,10 @@ public class ELNComponentVoltageControlledCurrentSource extends TGCScalableWithI tgcomponent[i].resizeWithFather(); } } + + if (getFather() != null) { + resizeWithFather(); + } } public void resizeWithFather() { diff --git a/src/main/java/ui/eln/sca_eln/ELNComponentVoltageControlledVoltageSource.java b/src/main/java/ui/eln/sca_eln/ELNComponentVoltageControlledVoltageSource.java index 3f2f0d9dbb..4d3793de72 100644 --- a/src/main/java/ui/eln/sca_eln/ELNComponentVoltageControlledVoltageSource.java +++ b/src/main/java/ui/eln/sca_eln/ELNComponentVoltageControlledVoltageSource.java @@ -58,7 +58,7 @@ import java.awt.event.ActionListener; * @author Irina Kit Yan LEE */ -public class ELNComponentVoltageControlledVoltageSource extends TGCScalableWithInternalComponent implements ActionListener, SwallowTGComponent, ELNComponent { +public class ELNComponentVoltageControlledVoltageSource extends TGCScalableWithInternalComponent implements ActionListener, SwallowTGComponent, SwallowedTGComponent, ELNComponent { protected Color myColor; protected int orientation; private int maxFontSize = 14; @@ -1120,6 +1120,10 @@ public class ELNComponentVoltageControlledVoltageSource extends TGCScalableWithI tgcomponent[i].resizeWithFather(); } } + + if (getFather() != null) { + resizeWithFather(); + } } public void resizeWithFather() { diff --git a/src/main/java/ui/syscams/SysCAMSComponentTaskDiagramPanel.java b/src/main/java/ui/syscams/SysCAMSComponentTaskDiagramPanel.java index db49a89e9e..c09ac89b80 100644 --- a/src/main/java/ui/syscams/SysCAMSComponentTaskDiagramPanel.java +++ b/src/main/java/ui/syscams/SysCAMSComponentTaskDiagramPanel.java @@ -504,35 +504,6 @@ public class SysCAMSComponentTaskDiagramPanel extends TDiagramPanel implements T return null; } - public void hideConnectors() { - Iterator<TGComponent> iterator = componentList.listIterator(); - SysCAMSPortConnector connector; - TGComponent tgc; - TGComponent tgc1; - TGComponent tgc2; - - while (iterator.hasNext()) { - tgc = iterator.next(); - - if (tgc instanceof SysCAMSPortConnector) { - connector = (SysCAMSPortConnector) tgc; - tgc1 = getComponentToWhichBelongs(connector.getTGConnectingPointP1()); - tgc2 = getComponentToWhichBelongs(connector.getTGConnectingPointP2()); - if ((tgc1 != null) && (tgc2 != null)) { - if (tgc1.hasAnHiddenAncestor()) { - tgc.setHidden(true); - } else { - if (tgc2.hasAnHiddenAncestor()) { - tgc.setHidden(true); - } else { - tgc.setHidden(false); - } - } - } - } - } - } - public void loadExtraParameters(Element elt) { } diff --git a/src/main/java/ui/syscams/SysCAMSCompositeComponent.java b/src/main/java/ui/syscams/SysCAMSCompositeComponent.java index 6818355c24..a260d627c7 100644 --- a/src/main/java/ui/syscams/SysCAMSCompositeComponent.java +++ b/src/main/java/ui/syscams/SysCAMSCompositeComponent.java @@ -58,20 +58,16 @@ import java.util.ListIterator; * @author Irina Kit Yan LEE */ -public class SysCAMSCompositeComponent extends TGCScalableWithInternalComponent implements SwallowTGComponent, HiddenInternalComponents { +public class SysCAMSCompositeComponent extends TGCScalableWithInternalComponent implements SwallowTGComponent { private int maxFontSize = 20; private int minFontSize = 4; private int currentFontSize = -1; private Color myColor; private int iconSize = 17; - private int textX = 15; // border for ports + private int textX = 15; private double dtextX = 0.0; - private boolean hiddeni; - - private int compositePortNb = 0; - public SysCAMSCompositeComponent(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); @@ -115,10 +111,6 @@ public class SysCAMSCompositeComponent extends TGCScalableWithInternalComponent if (this.rescaled && !this.tdp.isScaled()) { this.rescaled = false; - // Must set the font size... - // Incrementally find the biggest font not greater than max_font size - // If font is less than min_font, no text is displayed - int maxCurrentFontSize = Math.max(0, Math.min(this.height, (int) (this.maxFontSize * this.tdp.getZoom()))); f = f.deriveFont((float) maxCurrentFontSize); @@ -140,7 +132,6 @@ public class SysCAMSCompositeComponent extends TGCScalableWithInternalComponent f = f.deriveFont(this.currentFontSize); } - // Zoom is assumed to be computed Color col = g.getColor(); g.drawRect(x, y, width, height); if ((width > 2) && (height > 2)) { @@ -149,7 +140,6 @@ public class SysCAMSCompositeComponent extends TGCScalableWithInternalComponent g.setColor(col); } - // Set font size int attributeFontSize = this.currentFontSize * 5 / 6; g.setFont(f.deriveFont((float) attributeFontSize)); g.setFont(f); @@ -238,21 +228,15 @@ public class SysCAMSCompositeComponent extends TGCScalableWithInternalComponent if (!acceptSwallowedTGComponent(tgc)) { return false; } - // Choose its position - - // Make it an internal component - // It's one of my son tgc.setFather(this); tgc.setDrawingZone(true); - //Set its coordinates if (tgc instanceof SysCAMSBlockTDF) { tgc.resizeWithFather(); } if (tgc instanceof SysCAMSBlockDE) { tgc.resizeWithFather(); } - //add it addInternalComponent(tgc, 0); return true; } @@ -377,55 +361,6 @@ public class SysCAMSCompositeComponent extends TGCScalableWithInternalComponent return null; } - public void setInternalsHidden(boolean hide) { - hiddeni = hide; - - if (tdp instanceof SysCAMSComponentTaskDiagramPanel) { - ((SysCAMSComponentTaskDiagramPanel)tdp).hideConnectors(); - } - } - - public boolean areInternalsHidden() { - return hiddeni; - } - - protected String translateExtraParam() { - StringBuffer sb = new StringBuffer("<extraparam>\n"); - sb.append("<info hiddeni=\"" + hiddeni + "\" "); - 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; - - 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("info")) { - if (elt.getAttribute("hiddeni").equals("true")) { - setInternalsHidden(true); - } - } - - } - } - } - } - } catch (Exception e) { - throw new MalformedModelingException(); - } - } - public void drawTGConnectingPoint(Graphics g, int type) { for (int i=0; i<nbConnectingPoint; i++) { if (connectingPoint[i].isCompatibleWith(type)) { @@ -434,10 +369,7 @@ public class SysCAMSCompositeComponent extends TGCScalableWithInternalComponent } for(int i=0; i<nbInternalTGComponent; i++) { - if (hiddeni) { - } else { - tgcomponent[i].drawTGConnectingPoint(g, type); - } + tgcomponent[i].drawTGConnectingPoint(g, type); } } @@ -470,14 +402,6 @@ public class SysCAMSCompositeComponent extends TGCScalableWithInternalComponent } } - public int getCompositePortNb() { - return compositePortNb; - } - - public void portRemoved() { - compositePortNb --; - } - public boolean hasRefencesTo(SysCAMSCompositeComponent syscamscc) { boolean b; diff --git a/src/main/java/ui/window/JDialogELNModule.java b/src/main/java/ui/window/JDialogELNModule.java new file mode 100644 index 0000000000..470bd965c6 --- /dev/null +++ b/src/main/java/ui/window/JDialogELNModule.java @@ -0,0 +1,155 @@ +/* Copyright or (C) or Copr. GET / ENST, Telecom-Paris, Ludovic Apvrille + * + * ludovic.apvrille AT enst.fr + * + * This software is a computer program whose purpose is to allow the + * edition of TURTLE analysis, design and deployment diagrams, to + * allow the generation of RT-LOTOS or Java code from this diagram, + * and at last to allow the analysis of formal validation traces + * obtained from external tools, e.g. RTL from LAAS-CNRS and CADP + * from INRIA Rhone-Alpes. + * + * This software is governed by the CeCILL license under French law and + * abiding by the rules of distribution of free software. You can use, + * modify and/ or redistribute the software under the terms of the CeCILL + * license as circulated by CEA, CNRS and INRIA at the following URL + * "http://www.cecill.info". + * + * As a counterpart to the access to the source code and rights to copy, + * modify and redistribute granted by the license, users are provided only + * with a limited warranty and the software's author, the holder of the + * economic rights, and the successive licensors have only limited + * liability. + * + * In this respect, the user's attention is drawn to the risks associated + * with loading, using, modifying and/or developing or reproducing the + * software by the user in light of its specific status of free software, + * that may mean that it is complicated to manipulate, and that also + * therefore means that it is reserved for developers and experienced + * professionals having in-depth computer knowledge. Users are therefore + * encouraged to load and test the software's suitability as regards their + * requirements in conditions enabling the security of their systems and/or + * data to be ensured and, more generally, to use and operate it in the + * same conditions as regards security. + * + * The fact that you are presently reading this means that you have had + * knowledge of the CeCILL license and that you accept its terms. + */ + +package ui.window; + +import ui.eln.ELNModule; +import ui.util.*; +import java.awt.*; +import java.awt.event.*; +import java.util.*; +import javax.swing.*; +import javax.swing.border.*; +import javax.swing.event.*; + +/** + * Class JDialogELNModule + * Dialog for managing of ELN module + * Creation: 13/07/2018 + * @version 1.0 13/07/2018 + * @author Irina Kit Yan LEE + */ + +@SuppressWarnings("serial") + +public class JDialogELNModule extends JDialog implements ActionListener { + + private JTextField nameTextField; + + private ELNModule module; + + public JDialogELNModule(ELNModule _module) { + setTitle("Setting ELN Module Attributes"); + setLocationRelativeTo(null); + setVisible(true); + setAlwaysOnTop(true); + setResizable(false); + + module = _module; + + getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke("ESCAPE"), "close"); + getRootPane().getActionMap().put("close", new AbstractAction() { + public void actionPerformed(ActionEvent e) { + dispose(); + } + }); + + dialog(); + } + + public void dialog() { + JPanel mainPanel = new JPanel(new BorderLayout()); + this.add(mainPanel); + + JPanel attributesMainPanel = new JPanel(); + mainPanel.add(attributesMainPanel, BorderLayout.NORTH); + + // --- Attributes ---// + attributesMainPanel.setLayout(new BorderLayout()); + + Box attributesBox = Box.createVerticalBox(); + attributesBox.setBorder(BorderFactory.createTitledBorder("Setting ELN module attributes")); + + GridBagLayout gridBag = new GridBagLayout(); + GridBagConstraints constraints = new GridBagConstraints(); + JPanel attributesBoxPanel = new JPanel(); + attributesBoxPanel.setFont(new Font("Helvetica", Font.PLAIN, 14)); + attributesBoxPanel.setLayout(gridBag); + + JLabel labelName = new JLabel("Name : "); + constraints = new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, + new Insets(15, 10, 5, 10), 0, 0); + gridBag.setConstraints(labelName, constraints); + attributesBoxPanel.add(labelName); + + if (module.getValue().toString().equals("")) { + nameTextField = new JTextField(10); + } else { + nameTextField = new JTextField(module.getValue().toString(), 10); + } + constraints = new GridBagConstraints(1, 0, 2, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, + new Insets(15, 10, 5, 10), 0, 0); + gridBag.setConstraints(nameTextField, constraints); + attributesBoxPanel.add(nameTextField); + + attributesBox.add(attributesBoxPanel); + attributesMainPanel.add(attributesBox, BorderLayout.NORTH); + + // -- Button -- / + JPanel downPanel = new JPanel(new FlowLayout()); + + JButton saveCloseButton = new JButton("Save and close"); + saveCloseButton.setIcon(IconManager.imgic25); + saveCloseButton.setActionCommand("Save_Close"); + saveCloseButton.addActionListener(this); + saveCloseButton.setPreferredSize(new Dimension(200, 30)); + downPanel.add(saveCloseButton); + + JButton cancelButton = new JButton("Cancel"); + cancelButton.setIcon(IconManager.imgic27); + cancelButton.setActionCommand("Cancel"); + cancelButton.addActionListener(this); + cancelButton.setPreferredSize(new Dimension(200, 30)); + downPanel.add(cancelButton); + + mainPanel.add(downPanel, BorderLayout.CENTER); + pack(); + this.getRootPane().setDefaultButton(saveCloseButton); + } + + public void actionPerformed(ActionEvent e) { + if ("Save_Close".equals(e.getActionCommand())) { + module.setValue(new String(nameTextField.getText())); + this.dispose(); + } + + if ("Cancel".equals(e.getActionCommand())) { + this.dispose(); + } + } +} \ No newline at end of file diff --git a/src/main/java/ui/window/JDialogSysCAMSBlockDE.java b/src/main/java/ui/window/JDialogSysCAMSBlockDE.java index 7d8a3a8484..6096eb2903 100644 --- a/src/main/java/ui/window/JDialogSysCAMSBlockDE.java +++ b/src/main/java/ui/window/JDialogSysCAMSBlockDE.java @@ -46,6 +46,7 @@ import java.util.*; import javax.swing.*; import javax.swing.border.*; import javax.swing.event.*; + /** * Class JDialogSystemCAMSBlockDE * Dialog for managing of SystemC-AMS DE Block -- GitLab