Package org.freeplane.core.io

Examples of org.freeplane.core.io.IAttributeHandler


      return;
    }
  }

  private void registerAttributeHandlers(final ReadManager reader) {
    final IAttributeHandler colorHandler = new IAttributeHandler() {
      public void setAttribute(final Object userObject, final String value) {
        if (value.length() == 7) {
          final NodeModel node = (NodeModel) userObject;
          NodeStyleModel.setColor(node, ColorUtils.stringToColor(value));
        }
      }
    };
    reader.addAttributeHandler(NodeBuilder.XML_NODE, "COLOR", colorHandler);
    reader.addAttributeHandler(NodeBuilder.XML_STYLENODE, "COLOR", colorHandler);
    final IAttributeHandler bgHandler = new IAttributeHandler() {
      public void setAttribute(final Object userObject, final String value) {
        if (value.length() == 7) {
          final NodeModel node = (NodeModel) userObject;
          NodeStyleModel.setBackgroundColor(node, ColorUtils.stringToColor(value));
        }
      }
    };
    reader.addAttributeHandler(NodeBuilder.XML_NODE, "BACKGROUND_COLOR", bgHandler);
    reader.addAttributeHandler(NodeBuilder.XML_STYLENODE, "BACKGROUND_COLOR", bgHandler);
    final IAttributeHandler styleHandler = new IAttributeHandler() {
      public void setAttribute(final Object userObject, final String value) {
        final NodeModel node = (NodeModel) userObject;
        NodeStyleModel.setShape(node, value);
      }
    };
    reader.addAttributeHandler(NodeBuilder.XML_NODE, "STYLE", styleHandler);
    reader.addAttributeHandler(NodeBuilder.XML_STYLENODE, "STYLE", styleHandler);
    reader.addAttributeHandler("font", "SIZE", new IAttributeHandler() {
      public void setAttribute(final Object userObject, final String value) {
        final FontProperties fp = (FontProperties) userObject;
        fp.fontSize = Integer.parseInt(value.toString());
      }
    });
    reader.addAttributeHandler("font", "NAME", new IAttributeHandler() {
      public void setAttribute(final Object userObject, final String value) {
        final FontProperties fp = (FontProperties) userObject;
        fp.fontName = value;
      }
    });
    reader.addAttributeHandler("font", "BOLD", new IAttributeHandler() {
      public void setAttribute(final Object userObject, final String value) {
        final FontProperties fp = (FontProperties) userObject;
        fp.isBold = value.equals("true");
      }
    });
    reader.addAttributeHandler("font", "ITALIC", new IAttributeHandler() {
      public void setAttribute(final Object userObject, final String value) {
        final FontProperties fp = (FontProperties) userObject;
        fp.isItalic = value.equals("true");
      }
    });
    final IAttributeHandler nodenumberingHandler = new IAttributeHandler() {
      public void setAttribute(final Object userObject, final String value) {
        final NodeModel node = (NodeModel) userObject;
        NodeStyleModel.setNodeNumbering(node, value.equals("true"));
      }
    };
    reader.addAttributeHandler(NodeBuilder.XML_NODE, "NUMBERED", nodenumberingHandler);
    reader.addAttributeHandler(NodeBuilder.XML_STYLENODE, "NUMBERED", nodenumberingHandler);

    final IAttributeHandler formatHandler = new IAttributeHandler() {
      public void setAttribute(final Object userObject, final String value) {
        final NodeModel node = (NodeModel) userObject;
        NodeStyleModel.setNodeFormat(node, value);
      }
    };
    reader.addAttributeHandler(NodeBuilder.XML_NODE, "FORMAT", formatHandler);
    reader.addAttributeHandler(NodeBuilder.XML_STYLENODE, "FORMAT", formatHandler);
    if (FreeplaneVersion.getVersion().isOlderThan(new FreeplaneVersion(1, 3, 0))) {
      // compatibility for a view 1.2.X preview versions - remove after release 1.3
      reader.addAttributeHandler(NodeBuilder.XML_NODE, "TEMPLATE", formatHandler);
      reader.addAttributeHandler(NodeBuilder.XML_STYLENODE, "TEMPLATE", formatHandler);
    }

    final IAttributeHandler nodeMaxNodeWidthHandler = new IAttributeHandler() {
      public void setAttribute(final Object userObject, final String value) {
        final NodeModel node = (NodeModel) userObject;
        NodeSizeModel.setNodeMaxNodeWidth(node, Integer.valueOf(value));
      }
    };
    reader.addAttributeHandler(NodeBuilder.XML_NODE, "MAX_WIDTH", nodeMaxNodeWidthHandler);
    reader.addAttributeHandler(NodeBuilder.XML_STYLENODE, "MAX_WIDTH", nodeMaxNodeWidthHandler);

    final IAttributeHandler nodeMinWidthHandler = new IAttributeHandler() {
      public void setAttribute(final Object userObject, final String value) {
        final NodeModel node = (NodeModel) userObject;
        NodeSizeModel.setNodeMinWidth(node, Integer.valueOf(value));
      }
    };
View Full Code Here


      }
    }
  }

  private void registerAttributeHandlers(final ReadManager reader) {
    reader.addAttributeHandler("cloud", "STYLE", new IAttributeHandler() {
      public void setAttribute(final Object userObject, final String value) {
        //        final CloudModel cloud = (CloudModel) userObject;
        //        cloud.setStyle(value.toString());
      }
    });
    reader.addAttributeHandler("cloud", "COLOR", new IAttributeHandler() {
      public void setAttribute(final Object userObject, final String value) {
        final CloudModel cloud = (CloudModel) userObject;
        cloud.setColor(ColorUtils.stringToColor(value.toString()));
      }
    });
    reader.addAttributeHandler("cloud", "SHAPE", new IAttributeHandler() {
      public void setAttribute(final Object userObject, final String value) {
        final CloudModel cloud = (CloudModel) userObject;
        cloud.setShape(CloudModel.Shape.valueOf(value));
      }
    });
    reader.addAttributeHandler("cloud", "WIDTH", new IAttributeHandler() {
      public void setAttribute(final Object userObject, final String value) {
        //        final CloudModel cloud = (CloudModel) userObject;
        //        cloud.setWidth(Integer.parseInt(value.toString()));
      }
    });
View Full Code Here

      }
    });   
  }

  private void registerAttributeHandlers(ReadManager reader) {
    reader.addAttributeHandler(MAP_EXTENSION_XML_TAG, PROJECT_ID_XML_TAG, new IAttributeHandler() {
     
      public void setAttribute(Object map, String value) {
        final MapModel mapModel = (MapModel) map;
       
        WorkspaceMapModelExtension wmme = WorkspaceController.getMapModelExtension(mapModel);
        if(wmme.getProject() == null) {
          AWorkspaceProject prj = WorkspaceController.getCurrentModel().getProject(value);
          if(prj == null) {
            //WORKSPACE - todo: propagate exception
            LogUtils.warn("project with id="+value+" was not found");
            return;
          }
          wmme.setProject(prj);
        }
      }     
    });
   
    reader.addAttributeHandler(MAP_EXTENSION_XML_TAG, PROJECT_HOME_XML_TAG, new IAttributeHandler() {
     
      public void setAttribute(Object map, String value) {
        final MapModel mapModel = (MapModel) map;
       
        WorkspaceMapModelExtension wmme = WorkspaceController.getMapModelExtension(mapModel);
View Full Code Here

      return;
    }
  }

  private void registerAttributeHandlers(final ReadManager reader) {
    reader.addAttributeHandler("edge", "STYLE", new IAttributeHandler() {
      public void setAttribute(final Object userObject, final String value) {
        final EdgeModel edge = (EdgeModel) userObject;
        edge.setStyle(EdgeStyle.getStyle(value));
      }
    });
    reader.addAttributeHandler("edge", "HIDE", new IAttributeHandler() {
      public void setAttribute(final Object userObject, final String value) {
        final EdgeModel edge = (EdgeModel) userObject;
        edge.setStyle(EdgeStyle.EDGESTYLE_HIDDEN);
      }
    });
    reader.addAttributeHandler("edge", "COLOR", new IAttributeHandler() {
      public void setAttribute(final Object userObject, final String value) {
        final EdgeModel edge = (EdgeModel) userObject;
        edge.setColor(ColorUtils.stringToColor(value.toString()));
      }
    });
    reader.addAttributeHandler("edge", "WIDTH", new IAttributeHandler() {
      public void setAttribute(final Object userObject, final String value) {
        final EdgeModel edge = (EdgeModel) userObject;
        if (value.equals(EdgeModel.EDGEWIDTH_THIN)) {
          edge.setWidth(EdgeModel.WIDTH_THIN);
        }
View Full Code Here

  private void createBuilder() {
    ModeController modeController = Controller.getCurrentModeController();
    final MapController mapController = modeController.getMapController();
    final ReadManager readManager = mapController.getReadManager();
    readManager.addAttributeHandler(NodeBuilder.XML_NODE, "STYLE_REF", new IAttributeHandler() {
      public void setAttribute(final Object node, final String value) {
        final LogicalStyleModel extension = LogicalStyleModel.createExtension((NodeModel) node);
        extension.setStyle(StyleFactory.create(value));
      }
    });
    readManager.addAttributeHandler(NodeBuilder.XML_NODE, "LOCALIZED_STYLE_REF", new IAttributeHandler() {
      public void setAttribute(final Object node, final String value) {
        final LogicalStyleModel extension = LogicalStyleModel.createExtension((NodeModel) node);
        extension.setStyle(StyleFactory.create(NamedObject.format(value)));
      }
    });
View Full Code Here

    }
    arrowLinks.clear();
  }

  private void registerAttributeHandlers(final ReadManager reader) {
    reader.addAttributeHandler(NodeBuilder.XML_NODE, LINK, new IAttributeHandler() {
      public void setAttribute(final Object userObject, final String value) {
        final NodeModel node = (NodeModel) userObject;
        linkController.loadLink(node, value);
        final Collection<NodeLinkModel> links = NodeLinks.getLinks(node);
        arrowLinks.addAll(links);
      }
    });
   
    final IAttributeHandler hyperlinkHandler = new IAttributeHandler() {
      public void setAttribute(final Object userObject, final String value) {
        final NodeModel node = (NodeModel) userObject;
        linkController.loadLinkFormat(node, Boolean.parseBoolean(value));
      }
    };
    reader.addAttributeHandler(NodeBuilder.XML_NODE, FORMAT_AS_HYPERLINK, hyperlinkHandler);
    reader.addAttributeHandler(NodeBuilder.XML_STYLENODE, FORMAT_AS_HYPERLINK, hyperlinkHandler);
   
    reader.addAttributeHandler("arrowlink", "EDGE_LIKE", new IAttributeHandler() {
      public void setAttribute(final Object userObject, final String value) {
        final ConnectorModel arrowLink = (ConnectorModel) userObject;
        arrowLink.setShape(Shape.EDGE_LIKE);
      }
    });
    reader.addAttributeHandler("arrowlink", "SHAPE", new IAttributeHandler() {
      public void setAttribute(final Object userObject, final String value) {
        final ConnectorModel arrowLink = (ConnectorModel) userObject;
        arrowLink.setShape(Shape.valueOf(value));
      }
    });
    reader.addAttributeHandler("arrowlink", "DASH", new IAttributeHandler() {
      public void setAttribute(final Object userObject, final String value) {
        final ConnectorModel arrowLink = (ConnectorModel) userObject;
        final String[] split = value.split(" ");
        int[] dash = new int[split.length];
        int i = 0;
        for(String s : split){
          dash[i++] = Integer.parseInt(s);
        }
        arrowLink.setDash(dash);
      }
    });
    reader.addAttributeHandler("arrowlink", "DESTINATION", new IAttributeHandler() {
      public void setAttribute(final Object userObject, final String value) {
        final ConnectorModel arrowLink = (ConnectorModel) userObject;
        arrowLink.setTargetID(value);
        arrowLinks.add(arrowLink);
      }
    });
    reader.addAttributeHandler("arrowlink", "SOURCE_LABEL", new IAttributeHandler() {
      public void setAttribute(final Object userObject, final String value) {
        final ConnectorModel arrowLink = (ConnectorModel) userObject;
        arrowLink.setSourceLabel(value.toString());
      }
    });
    reader.addAttributeHandler("arrowlink", "MIDDLE_LABEL", new IAttributeHandler() {
      public void setAttribute(final Object userObject, final String value) {
        final ConnectorModel arrowLink = (ConnectorModel) userObject;
        arrowLink.setMiddleLabel(value.toString());
      }
    });
    reader.addAttributeHandler("arrowlink", "TARGET_LABEL", new IAttributeHandler() {
      public void setAttribute(final Object userObject, final String value) {
        final ConnectorModel arrowLink = (ConnectorModel) userObject;
        arrowLink.setTargetLabel(value.toString());
      }
    });
    reader.addAttributeHandler("arrowlink", "STARTINCLINATION", new IAttributeHandler() {
      public void setAttribute(final Object userObject, final String value) {
        final ConnectorModel arrowLink = (ConnectorModel) userObject;
        arrowLink.setStartInclination(TreeXmlReader.xmlToPoint(value.toString()));
      }
    });
    reader.addAttributeHandler("arrowlink", "ENDINCLINATION", new IAttributeHandler() {
      public void setAttribute(final Object userObject, final String value) {
        final ConnectorModel arrowLink = (ConnectorModel) userObject;
        arrowLink.setEndInclination(TreeXmlReader.xmlToPoint(value.toString()));
      }
    });
    reader.addAttributeHandler("arrowlink", "STARTARROW", new IAttributeHandler() {
      public void setAttribute(final Object userObject, final String value) {
        final ConnectorModel arrowLink = (ConnectorModel) userObject;
        arrowLink.setStartArrow(ArrowType.valueOf(value.toUpperCase()));
      }
    });
    reader.addAttributeHandler("arrowlink", "ENDARROW", new IAttributeHandler() {
      public void setAttribute(final Object userObject, final String value) {
        final ConnectorModel arrowLink = (ConnectorModel) userObject;
        arrowLink.setEndArrow(ArrowType.valueOf(value.toUpperCase()));
      }
    });
    reader.addAttributeHandler("arrowlink", "WIDTH", new IAttributeHandler() {
      public void setAttribute(final Object userObject, final String value) {
        final ConnectorModel arrowLink = (ConnectorModel) userObject;
        arrowLink.setWidth(Integer.parseInt(value.toString()));
      }
    });
   
    reader.addAttributeHandler("arrowlink", "FONT_FAMILY", new IAttributeHandler() {
      public void setAttribute(final Object userObject, final String value) {
        final ConnectorModel arrowLink = (ConnectorModel) userObject;
        arrowLink.setLabelFontFamily(value.toString());
      }
    });
    reader.addAttributeHandler("arrowlink", "FONT_SIZE", new IAttributeHandler() {
      public void setAttribute(final Object userObject, final String value) {
        final ConnectorModel arrowLink = (ConnectorModel) userObject;
        arrowLink.setLabelFontSize(Integer.parseInt(value.toString()));
      }
    });
View Full Code Here

    return mapReader.getCurrentNodeTreeCreator().getCreatedMap();
  }

  private void registerAttributeHandlers(final ReadManager reader) {
    reader.addAttributeHandler(AttributeBuilder.XML_NODE_REGISTERED_ATTRIBUTE_NAME, "NAME",
        new IAttributeHandler() {
          public void setAttribute(final Object userObject, final String value) {
            final RegisteredAttributeProperties rap = (RegisteredAttributeProperties) userObject;
            rap.attributeName = value;
            AttributeRegistry.getRegistry(getMap()).registry(value);
          }
        });
    reader.addAttributeHandler(AttributeBuilder.XML_NODE_REGISTERED_ATTRIBUTE_NAME, "VISIBLE",
        new IAttributeHandler() {
          public void setAttribute(final Object userObject, final String value) {
            final RegisteredAttributeProperties rap = (RegisteredAttributeProperties) userObject;
            rap.visible = true;
          }
        });
    reader.addAttributeHandler(AttributeBuilder.XML_NODE_REGISTERED_ATTRIBUTE_NAME, "RESTRICTED",
        new IAttributeHandler() {
          public void setAttribute(final Object userObject, final String value) {
            final RegisteredAttributeProperties rap = (RegisteredAttributeProperties) userObject;
            rap.restricted = true;
          }
        });
    reader.addAttributeHandler(AttributeBuilder.XML_NODE_REGISTERED_ATTRIBUTE_NAME, "MANUAL",
        new IAttributeHandler() {
          public void setAttribute(final Object userObject, final String value) {
            final RegisteredAttributeProperties rap = (RegisteredAttributeProperties) userObject;
            rap.manual = true;
          }
        });
    reader.addAttributeHandler(AttributeBuilder.XML_NODE_REGISTERED_ATTRIBUTE_VALUE, "VALUE",
        new IAttributeHandler() {
          public void setAttribute(final Object userObject, final String value) {
            final AttributeProperties ap = (AttributeProperties) userObject;
            ap.attributeValue = value;
          }
        });
    reader.addAttributeHandler(AttributeBuilder.XML_NODE_REGISTERED_ATTRIBUTE_VALUE, "OBJECT",
        new IAttributeHandler() {
          public void setAttribute(final Object userObject, final String value) {
            final AttributeProperties ap = (AttributeProperties) userObject;
            ap.attributeObject = value;
          }
        });
    reader.addElementHandler(XML_NODE_ATTRIBUTE_LAYOUT, new IElementHandler() {
      public Object createElement(final Object parent, final String tag, final XMLElement attributes) {
        return parent;
      }
    });
    reader.addAttributeHandler(AttributeBuilder.XML_NODE_ATTRIBUTE_LAYOUT, "NAME_WIDTH", new IAttributeHandler() {
      public void setAttribute(final Object userObject, final String value) {
        final NodeModel node = (NodeModel) userObject;
        attributeController.createAttributeTableModel(node);
        final AttributeTableLayoutModel layout = NodeAttributeTableModel.getModel(node).getLayout();
        layout.setColumnWidth(0, Integer.parseInt(value));;
      }
    });
    reader.addAttributeHandler(AttributeBuilder.XML_NODE_ATTRIBUTE_LAYOUT, "VALUE_WIDTH", new IAttributeHandler() {
      public void setAttribute(final Object userObject, final String value) {
        final NodeModel node = (NodeModel) userObject;
        attributeController.createAttributeTableModel(node);
        final AttributeTableLayoutModel layout = NodeAttributeTableModel.getModel(node).getLayout();
        layout.setColumnWidth(1, Integer.parseInt(value));;
      }
    });
    reader.addAttributeHandler(AttributeBuilder.XML_NODE_ATTRIBUTE, "NAME", new IAttributeHandler() {
      public void setAttribute(final Object userObject, final String value) {
        final AttributeProperties ap = (AttributeProperties) userObject;
        ap.attributeName = value;
      }
    });
    reader.addAttributeHandler(AttributeBuilder.XML_NODE_ATTRIBUTE, "VALUE", new IAttributeHandler() {
      public void setAttribute(final Object userObject, final String value) {
        final AttributeProperties ap = (AttributeProperties) userObject;
        ap.attributeValue = value;
      }
    });
    reader.addAttributeHandler(AttributeBuilder.XML_NODE_ATTRIBUTE, "OBJECT", new IAttributeHandler() {
      public void setAttribute(final Object userObject, final String value) {
        final AttributeProperties ap = (AttributeProperties) userObject;
        ap.attributeObject = value;
      }
    });
    reader.addAttributeHandler(AttributeBuilder.XML_NODE_ATTRIBUTE_REGISTRY, "RESTRICTED", new IAttributeHandler() {
      public void setAttribute(final Object userObject, final String value) {
        AttributeRegistry.getRegistry(getMap()).setRestricted(true);
      }
    });
    reader.addAttributeHandler(AttributeBuilder.XML_NODE_ATTRIBUTE_REGISTRY, "SHOW_ATTRIBUTES",
        new IAttributeHandler() {
          public void setAttribute(final Object userObject, final String value) {
          final AttributeRegistry attributes = AttributeRegistry.getRegistry(getMap());
          if(attributes != null)
            attributes.setAttributeViewType(value);
          }
        });
    reader.addAttributeHandler(AttributeBuilder.XML_NODE_ATTRIBUTE_REGISTRY, "FONT_SIZE", new IAttributeHandler() {
      public void setAttribute(final Object userObject, final String value) {
        final int size = Integer.parseInt(value.toString());
        AttributeRegistry.getRegistry(getMap()).setFontSize(size);
      }
    });
View Full Code Here

      return;
    }
  }

  private void registerAttributeHandlers(final ReadManager reader) {
    reader.addAttributeHandler("icon", "BUILTIN", new IAttributeHandler() {
      public void setAttribute(final Object userObject, final String value) {
        final IconProperties ip = (IconProperties) userObject;
        ip.iconName = value;
      }
    });
View Full Code Here

    this.parseManager = parseManager;
  }

  private boolean addAttribute(final String key, final String value) {
    if (saveAsXmlUntil == null && attributeHandlersForTag != null) {
      final IAttributeHandler attributeHandler = attributeHandlersForTag.get(key);
      if (attributeHandler != null) {
        attributeHandler.setAttribute(currentElement, value);
        return true;
      }
    }
    return false;
  }
View Full Code Here

* @author Dimitry Polivaev
* 06.12.2008
*/
class LocationBuilder implements IExtensionAttributeWriter {
  private void registerAttributeHandlers(final ReadManager reader) {
    reader.addAttributeHandler(NodeBuilder.XML_NODE, "VSHIFT", new IAttributeHandler() {
      public void setAttribute(final Object userObject, final String value) {
        final NodeModel node = (NodeModel) userObject;
        LocationModel.createLocationModel(node).setShiftY(Integer.parseInt(value));
      }
    });
    reader.addAttributeHandler(NodeBuilder.XML_NODE, "VGAP", new IAttributeHandler() {
      public void setAttribute(final Object userObject, final String value) {
        final NodeModel node = (NodeModel) userObject;
        LocationModel.createLocationModel(node).setVGap(Integer.parseInt(value));
      }
    });
    reader.addAttributeHandler(NodeBuilder.XML_NODE, "HGAP", new IAttributeHandler() {
      public void setAttribute(final Object userObject, final String value) {
        final NodeModel node = (NodeModel) userObject;
        LocationModel.createLocationModel(node).setHGap(Integer.parseInt(value));
      }
    });
View Full Code Here

TOP

Related Classes of org.freeplane.core.io.IAttributeHandler

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.