/** * Fill the port with the parameters from the graphics structure. * * @param port the target instance */ private void decodeGraphics(InputPort port) { // protection against previously stored blocks if (graphics.size() > GRAPHICS_INSTYLE_INDEX && !isEmptyField(graphics.get(GRAPHICS_INSTYLE_INDEX))) { final ScilabString styles = (ScilabString) graphics.get(GRAPHICS_INSTYLE_INDEX); boolean isColumnDominant = styles.getHeight() >= styles.getWidth(); int[] indexes = getIndexes(alreadyDecodedCount, isColumnDominant); if (canGet(styles, indexes)) { final String style; style = styles.getData()[indexes[0]][indexes[1]]; port.setStyle(new StyleMap(port.getStyle()).putAll(style).toString()); } } // protection against previously stored blocks if (graphics.size() > GRAPHICS_INLABEL_INDEX && !isEmptyField(graphics.get(GRAPHICS_INLABEL_INDEX))) { final ScilabString labels = (ScilabString) graphics.get(GRAPHICS_INLABEL_INDEX); boolean isColumnDominant = labels.getHeight() >= labels.getWidth(); int[] indexes = getIndexes(alreadyDecodedCount, isColumnDominant); if (canGet(labels, indexes)) { final String label = labels.getData()[indexes[0]][indexes[1]]; if (label != null) { port.setValue(label); } else { port.setValue(""); } } } }
/** * Change the label of the port according to the integer parameters property. * * @param source the source of the block */ public void updateLabel(final BasicBlock source) { /** Get the input port children */ final List<InputPort> ports = new ArrayList<InputPort>(); for (int i = 0; i < source.getChildCount(); i++) { final mxICell port = source.getChildAt(i); if (port instanceof InputPort) { ports.add((InputPort) port); } } /** Set the ports labels */ JavaController controller = new JavaController(); VectorOfInt ipar = new VectorOfInt(); controller.getObjectProperty(source.getUID(), Kind.BLOCK, ObjectProperties.IPAR, ipar); for (int i = 0; i < ports.size(); i++) { final int gain; if (i < ipar.size()) { gain = ipar.get(i); } else { gain = 1; } ports.get(i).setValue(getLabel(gain)); } /** Check if all the values are equal to the default one. */ if (!hasDefaultValue(ports)) { return; } /** When all values are equal to the default one, set it to the block and hide the children. */ source.setValue(NOT_PRINTED_LABEL); for (InputPort port : ports) { port.setValue(""); } }