コード例 #1
0
  /**
   * Format the style value
   *
   * @param map the read style value
   * @param obj the block instance
   */
  private void formatStyle(StyleMap map, BasicBlock obj) {

    // Append the bloc style if not present.
    String name = obj.getInterfaceFunctionName();
    if (!map.containsKey(name)) {
      map.put(name, null);
    }

    formatStyle(map);
  }
コード例 #2
0
ファイル: TextBlock.java プロジェクト: scitao/scilab
  /**
   * Apply style on setExprs
   *
   * @param exprs the expression to be parsed
   */
  @Override
  public void setExprs(ScilabType exprs) {
    super.setExprs(exprs);

    final StyleMap map = new StyleMap(getStyle());
    map.put(mxConstants.STYLE_FONTFAMILY, getFont().getName());
    map.put(mxConstants.STYLE_FONTSIZE, Integer.toString(getFontSize()));
    setStyle(map.toString());

    setValue(getLocalExprs().getData()[0][0]);
  }
コード例 #3
0
  /**
   * Apply compatibility pattern to the decoded object
   *
   * @param dec Codec that controls the decoding process.
   * @param node XML node to decode the object from.
   * @param obj Object decoded.
   * @return The Object transformed
   * @see org.scilab.modules.xcos.io.codec.XcosObjectCodec#afterDecode(com.mxgraph.io.mxCodec,
   *     org.w3c.dom.Node, java.lang.Object)
   */
  @Override
  public Object afterDecode(mxCodec dec, Node node, Object obj) {
    if (!(obj instanceof BasicBlock)) {
      LOG.severe("Unable to decode " + obj);
      return obj;
    }
    final BasicBlock block = (BasicBlock) obj;

    block.setSimulationFunctionType(SimulationFunctionType.DEFAULT);

    String functionType = (((Element) node).getAttribute(SIMULATION_FUNCTION_TYPE));
    if (functionType != null && functionType.compareTo("") != 0) {
      SimulationFunctionType type = BasicBlock.SimulationFunctionType.valueOf(functionType);
      if (type != null) {
        block.setSimulationFunctionType(type);
      }
    }

    // Re associate the diagram container
    if (block instanceof SuperBlock) {
      final SuperBlock superBlock = (SuperBlock) block;
      if (superBlock.getChild() != null) {
        superBlock.getChild().setContainer(superBlock);
      }
    }

    // update style to replace direction by rotation and add the
    // default style if absent
    StyleMap map = new StyleMap(((Element) node).getAttribute(STYLE));
    formatStyle(map, (BasicBlock) obj);
    block.setStyle(map.toString());
    block.updateFieldsFromStyle();

    /*
     * Compat. to remove old specific implementations
     *
     * These implementation was available from Scilab-5.2.0 to Scilab-5.3.3.
     *
     * Set default values stolen from the old implementation in case of
     * default value.
     */
    if (node.getNodeName().equals("ConstBlock")) {
      if (block.getInterfaceFunctionName().equals(BasicBlock.DEFAULT_INTERFACE_FUNCTION)) {
        block.setInterfaceFunctionName("CONST_m");
      }
      if (block.getSimulationFunctionName().equals(BasicBlock.DEFAULT_SIMULATION_FUNCTION)) {
        block.setSimulationFunctionName("cstblk4");
      }
      if (block.getValue() == null) {
        block.setValue("1");
      }
    }
    if (node.getNodeName().equals("GainBlock")) {
      if (block.getInterfaceFunctionName().equals(BasicBlock.DEFAULT_INTERFACE_FUNCTION)) {
        block.setInterfaceFunctionName("GAINBLK_f");
      }
    }
    // PrintBlock has no default values

    return super.afterDecode(dec, node, obj);
  }