* Copyright (C) 2009 - DIGITEO - Bruno JOFRET
* Copyright (C) 2010 - DIGITEO - Clement DAVID
* Copyright (C) 2011-2017 - Scilab Enterprises - Clement DAVID
+ * Copyright (C) 2017-2018 - ESI Group - Clement DAVID
*
* Copyright (C) 2012 - 2016 - Scilab Enterprises
*
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
-import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import org.scilab.modules.gui.utils.BarUpdater;
import org.scilab.modules.gui.utils.ClosingOperationsManager;
import org.scilab.modules.gui.utils.WindowsConfigurationManager;
-import org.scilab.modules.localization.Messages;
import org.scilab.modules.xcos.actions.ExternalAction;
import org.scilab.modules.xcos.actions.StopAction;
import org.scilab.modules.xcos.configuration.ConfigurationManager;
import javax.swing.Timer;
import org.scilab.modules.commons.ScilabCommons;
import org.scilab.modules.xcos.graph.model.ScicosObjectOwner;
+import org.scilab.modules.xcos.graph.model.XcosCell;
import org.scilab.modules.xcos.graph.model.XcosGraphModel;
/**
/**
* Look for the parent diagram of the cell in the diagram hierarchy.
- *
- * @param cell
- * the cell to search for
+ * @param controller
+ * the shared controller
+ * @param uid
+ * the cell UID to search for
+ * @param kind
+ * the cell Kind to search for
* @return the associated diagram
*/
- public static XcosDiagram findParent(Object cell) {
+ public static XcosDiagram findParent(JavaController controller, long uid, Kind kind) {
final Xcos instance = getInstance();
+ long[] parent = {0};
+
+ // use parent / children model property
+ controller.getObjectProperty(uid, kind, ObjectProperties.PARENT_BLOCK, parent);
+ if (parent[0] == 0) {
+ controller.getObjectProperty(uid, kind, ObjectProperties.PARENT_DIAGRAM, parent);
+ }
+
for (Collection<XcosDiagram> diags : instance.diagrams.values()) {
for (XcosDiagram diag : diags) {
- final mxGraphModel model = (mxGraphModel) diag.getModel();
+ final Object defaultParent = diag.getDefaultParent();
- // use the O(1) lookup
- if (cell instanceof mxICell && model.getCell(((mxICell) cell).getId()) != null) {
+ if (defaultParent instanceof XcosCell && ((XcosCell) defaultParent).getUID() == parent[0]) {
return diag;
}
}
import com.mxgraph.model.mxCell;
import com.mxgraph.model.mxGraphModel;
+import com.mxgraph.model.mxICell;
import com.mxgraph.util.mxConstants;
import com.mxgraph.util.mxEvent;
import com.mxgraph.util.mxEventObject;
import com.mxgraph.util.mxUtils;
-import javax.swing.AbstractAction;
-import org.scilab.modules.localization.Messages;
-import org.scilab.modules.xcos.block.BasicBlock;
+import java.util.List;
+import org.scilab.modules.xcos.JavaController;
+import org.scilab.modules.xcos.Kind;
+import org.scilab.modules.xcos.ObjectProperties;
+import org.scilab.modules.xcos.VectorOfDouble;
+import org.scilab.modules.xcos.Xcos;
+import org.scilab.modules.xcos.block.SuperBlock;
+import org.scilab.modules.xcos.block.io.ContextUpdate;
+import org.scilab.modules.xcos.graph.model.XcosCell;
+import org.scilab.modules.xcos.graph.model.XcosGraphModel;
/**
* Customize the block representation.
}
oneliner = str.toString();
+ //
+ // Update the cell value and cell identifier value (related annotation)
+ //
+
graph.cellLabelChanged(cell, oneliner, false);
graph.fireEvent(new mxEventObject(mxEvent.LABEL_CHANGED, "cell", cell, "value", text, "parent", cell.getParent()));
graph.cellLabelChanged(identifier, text, false);
graph.fireEvent(new mxEventObject(mxEvent.LABEL_CHANGED, "cell", identifier, "value", text, "parent", cell));
+
+ //
+ // Update the corresponding port if the block is an I/O block
+ //
+ if (cell instanceof ContextUpdate) {
+ JavaController controller = new JavaController();
+
+ VectorOfDouble ipar = new VectorOfDouble();
+ controller.getObjectProperty(((ContextUpdate) cell).getUID(), Kind.BLOCK, ObjectProperties.IPAR, ipar);
+ int portNumber = (int) (ipar.size() > 0 ? ipar.get(0) : 1);
+
+ XcosCell parent = (XcosCell) graph.getDefaultParent();
+ XcosDiagram parentGraph = Xcos.findParent(controller, parent.getUID(), parent.getKind());
+ if (parentGraph != null) {
+ String[] jgraphxID = {""};
+ controller.getObjectProperty(parent.getUID(), parent.getKind(), ObjectProperties.UID, jgraphxID);
+
+ XcosGraphModel parentModel = (XcosGraphModel) parentGraph.getModel();
+ Object superBlock = parentModel.getCell(jgraphxID[0]);
+ if (superBlock instanceof SuperBlock) {
+ List<mxICell> ports = ContextUpdate.IOBlocks.getPorts((SuperBlock) superBlock, (Class<? extends ContextUpdate>) cell.getClass());
+
+ if (ports.size() >= portNumber) {
+ mxICell port = ports.get(portNumber - 1);
+ parentGraph.cellLabelChanged(port, oneliner, false);
+ parentGraph.fireEvent(new mxEventObject(mxEvent.LABEL_CHANGED, "cell", port, "value", text, "parent", superBlock));
+ }
+ }
+
+ }
+
+ }
}
// CSON: NPathComplexity
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTabbedPane mainTab;
private javax.swing.JTextField labelArea;
- private javax.swing.JTextArea textArea;
+ private javax.swing.JTextPane textArea;
private javax.swing.JPanel textFormat;
private javax.swing.JButton cancelButton;
labelArea.setToolTipText(XcosMessages.ONELINE_DESCRIPTION_TOOLTIP);
jScrollPane1 = new javax.swing.JScrollPane();
- textArea = new javax.swing.JTextArea();
+ textArea = new javax.swing.JTextPane();
textArea.setToolTipText(XcosMessages.MULTILINE_DESCRIPTION_TOOLTIP);
- textArea.setColumns(TEXT_AREA_COLUMNS);
- textArea.setRows(TEXT_AREA_ROWS);
- textArea.setLineWrap(true);
- textArea.setWrapStyleWord(true);
+ textArea.setContentType("text/html");
cancelButton = new javax.swing.JButton(XcosMessages.CANCEL);
okButton = new javax.swing.JButton(XcosMessages.OK);
graph.getModel().beginUpdate();
EditFormatAction.updateFromDialog(getDialog(), borderColorChooser.getColor(), backgroundColorChooser.getColor(),
(String) fontNameComboBox.getSelectedItem(), (Integer) fontSizeSpinner.getValue(), textColorChooser.getColor(),
- fontStyleBold.isSelected(), fontStyleItalic.isSelected(), labelArea.getText(), textArea.getText(), imagePath.getText());
+ fontStyleBold.isSelected(), fontStyleItalic.isSelected(), labelArea.getText(), mxUtils.getBodyMarkup(textArea.getText(), false), imagePath.getText());
graph.getModel().endUpdate();
getDialog().dispose();
}