예제 #1
0
  @Override
  public void setCustomBounds(double min, double max) {
    if (model != null) {
      if (model.getCustomMin() != min || model.getCustomMax() != max) {
        if (min >= max) {
          throw new IllegalArgumentException("min should be less than max");
        }
        if (min < model.getMin() || max > model.getMax()) {
          throw new IllegalArgumentException("Min and max should be in the bounds");
        }

        // Interval
        if (model.getIntervalStart() < min || model.getIntervalEnd() > max) {
          dynamicController.setVisibleInterval(min, max);
        }

        // Custom bounds
        double[] val = new double[] {min, max};
        model.setCustomMin(min);
        model.setCustomMax(max);
        fireTimelineModelEvent(
            new TimelineModelEvent(TimelineModelEvent.EventType.CUSTOM_BOUNDS, model, val));
      }
    }
  }
예제 #2
0
  public TimelineControllerImpl() {
    listeners = new ArrayList<TimelineModelListener>();

    // Workspace events
    ProjectController pc = Lookup.getDefault().lookup(ProjectController.class);
    dynamicController = Lookup.getDefault().lookup(DynamicController.class);

    pc.addWorkspaceListener(
        new WorkspaceListener() {

          @Override
          public void initialize(Workspace workspace) {}

          @Override
          public void select(Workspace workspace) {
            model = workspace.getLookup().lookup(TimelineModelImpl.class);
            if (model == null) {
              model = new TimelineModelImpl(dynamicController.getModel(workspace));
              workspace.add(model);
            }
            attributeModel =
                Lookup.getDefault().lookup(AttributeController.class).getModel(workspace);
            setup();
          }

          @Override
          public void unselect(Workspace workspace) {
            unsetup();
          }

          @Override
          public void close(Workspace workspace) {}

          @Override
          public void disable() {
            model = null;
            attributeModel = null;
            fireTimelineModelEvent(
                new TimelineModelEvent(TimelineModelEvent.EventType.MODEL, null, null));
          }
        });

    if (pc.getCurrentWorkspace() != null) {
      model = pc.getCurrentWorkspace().getLookup().lookup(TimelineModelImpl.class);
      if (model == null) {
        model = new TimelineModelImpl(dynamicController.getModel(pc.getCurrentWorkspace()));
        pc.getCurrentWorkspace().add(model);
      }
      attributeModel =
          Lookup.getDefault().lookup(AttributeController.class).getModel(pc.getCurrentWorkspace());
      setup();
    }
  }
예제 #3
0
 @Override
 public void setInterval(double from, double to) {
   if (model != null) {
     if (model.getIntervalStart() != from || model.getIntervalEnd() != to) {
       if (from >= to) {
         throw new IllegalArgumentException("from should be less than to");
       }
       if (from < model.getCustomMin() || to > model.getCustomMax()) {
         throw new IllegalArgumentException("From and to should be in the bounds");
       }
       dynamicController.setVisibleInterval(from, to);
     }
   }
 }
예제 #4
0
 @Override
 public void setEnabled(boolean enabled) {
   if (model != null) {
     if (enabled != model.isEnabled() && model.hasValidBounds()) {
       model.setEnabled(enabled);
       fireTimelineModelEvent(
           new TimelineModelEvent(TimelineModelEvent.EventType.ENABLED, model, enabled));
     }
     if (!enabled) {
       // Disable filtering
       dynamicController.setVisibleInterval(new TimeInterval());
     }
   }
 }
예제 #5
0
 private void unsetup() {
   dynamicController.removeModelListener(this);
 }
예제 #6
0
  private void setup() {
    fireTimelineModelEvent(new TimelineModelEvent(TimelineModelEvent.EventType.MODEL, model, null));

    dynamicController.addModelListener(this);
  }
  public void updateWorld() {
    // System.out.println("update world");
    cacheMarker++;

    GraphModel graphModel = controller.getModel();
    if (graphModel == null) {
      engine.worldUpdated(cacheMarker);
      return;
    }
    if (gm != null && gm != graphModel) {
      reset();
    }
    gm = graphModel;
    HierarchicalGraph graph;
    if (graphModel.isDirected()) {
      undirected = false;
      graph = graphModel.getHierarchicalDirectedGraphVisible();
    } else if (graphModel.isUndirected()) {
      undirected = true;
      graph = graphModel.getHierarchicalUndirectedGraphVisible();
    } else if (graphModel.isMixed()) {
      undirected = false;
      graph = graphModel.getHierarchicalMixedGraphVisible();
    } else {
      undirected = false;
      graph = graphModel.getHierarchicalDirectedGraphVisible();
    }

    if (dynamicModel == null) {
      DynamicController dynamicController = Lookup.getDefault().lookup(DynamicController.class);
      dynamicModel = dynamicController.getModel();
    }

    graphView = graph.getView().getViewId();

    ModelClass[] object3dClasses = engine.getModelClasses();

    graph.readLock();

    ModelClass nodeClass = object3dClasses[AbstractEngine.CLASS_NODE];
    if (nodeClass.isEnabled()
        && (graph.getNodeVersion() > nodeVersion || modeManager.requireModeChange())) {
      updateNodes(graph);
      nodeClass.setCacheMarker(cacheMarker);
    }

    ModelClass edgeClass = object3dClasses[AbstractEngine.CLASS_EDGE];
    if (edgeClass.isEnabled()
        && (graph.getEdgeVersion() > edgeVersion || modeManager.requireModeChange())) {
      updateEdges(graph);
      updateMetaEdges(graph);
      edgeClass.setCacheMarker(cacheMarker);
      if (!undirected && vizConfig.isShowArrows()) {
        object3dClasses[AbstractEngine.CLASS_ARROW].setCacheMarker(cacheMarker);
      }
    }

    ModelClass potatoClass = object3dClasses[AbstractEngine.CLASS_POTATO];
    if (potatoClass.isEnabled()
        && (graph.getNodeVersion() > nodeVersion || modeManager.requireModeChange())) {
      updatePotatoes(graph);
      potatoClass.setCacheMarker(cacheMarker);
    }

    nodeVersion = graph.getNodeVersion();
    edgeVersion = graph.getEdgeVersion();

    graph.readUnlock();

    engine.worldUpdated(cacheMarker);
  }
  public boolean execute() {
    attributeModel = workspace.getLookup().lookup(AttributeModel.class);
    graphModel = workspace.getLookup().lookup(GraphModel.class);
    HierarchicalGraph graph = null;
    if (exportVisible) {
      graph = graphModel.getHierarchicalGraphVisible();
    } else {
      graph = graphModel.getHierarchicalGraph();
    }
    Progress.start(progress);
    graph.readLock();

    // Options
    if (normalize) {
      calculateMinMax(graph);
    }

    // Calculate progress units count
    int max = 0;
    if (exportHierarchy) {
      for (Node n : graph.getNodesTree()) {
        max++;
      }
      for (Edge e : graph.getEdgesTree()) {
        max++;
      }
    } else {
      max = graph.getNodeCount();
      for (Edge e : graph.getEdgesAndMetaEdges()) {
        max++;
      }
    }
    Progress.switchToDeterminate(progress, max);

    try {
      XMLOutputFactory outputFactory = XMLOutputFactory.newInstance();
      outputFactory.setProperty("javax.xml.stream.isRepairingNamespaces", Boolean.FALSE);

      XMLStreamWriter xmlWriter = outputFactory.createXMLStreamWriter(writer);
      xmlWriter = new IndentingXMLStreamWriter(xmlWriter);

      xmlWriter.writeStartDocument("UTF-8", "1.0");
      xmlWriter.setPrefix("", GEXF_NAMESPACE);
      xmlWriter.writeStartElement(GEXF_NAMESPACE, GEXF);
      xmlWriter.writeNamespace("", GEXF_NAMESPACE);
      xmlWriter.writeAttribute(GEXF_VERSION, "1.1");

      if (exportColors || exportPosition || exportSize) {
        xmlWriter.writeNamespace(VIZ, VIZ_NAMESPACE);
      }
      xmlWriter.writeAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
      xmlWriter.writeAttribute("xsi:schemaLocation", GEXF_NAMESPACE_LOCATION);

      if (exportDynamic) {
        DynamicController dynamicController = Lookup.getDefault().lookup(DynamicController.class);
        dynamicModel = dynamicController != null ? dynamicController.getModel(workspace) : null;
        visibleInterval =
            dynamicModel == null
                ? null
                : exportVisible
                    ? dynamicModel.getVisibleInterval()
                    : new TimeInterval(Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY);
      }

      writeMeta(xmlWriter);
      writeGraph(xmlWriter, graph);

      xmlWriter.writeEndElement();
      xmlWriter.writeEndDocument();
      xmlWriter.close();

    } catch (Exception e) {
      graph.readUnlockAll();
      if (e instanceof RuntimeException) {
        throw (RuntimeException) e;
      }
      throw new RuntimeException(e);
    }

    graph.readUnlock();

    Progress.finish(progress);
    return !cancel;
  }
예제 #9
0
  public void process() {
    // Workspace
    ProjectController pc = Lookup.getDefault().lookup(ProjectController.class);
    if (workspace == null) {
      workspace = pc.newWorkspace(pc.getCurrentProject());
      pc.openWorkspace(workspace);
    }
    if (container.getSource() != null) {
      pc.setSource(workspace, container.getSource());
    }

    // Architecture
    GraphModel graphModel = Lookup.getDefault().lookup(GraphController.class).getModel(workspace);

    HierarchicalGraph graph = null;
    switch (container.getEdgeDefault()) {
      case DIRECTED:
        graph = graphModel.getHierarchicalDirectedGraph();
        break;
      case UNDIRECTED:
        graph = graphModel.getHierarchicalUndirectedGraph();
        break;
      case MIXED:
        graph = graphModel.getHierarchicalMixedGraph();
        break;
      default:
        graph = graphModel.getHierarchicalMixedGraph();
        break;
    }
    GraphFactory factory = graphModel.factory();

    // Attributes - Creates columns for properties
    attributeModel = Lookup.getDefault().lookup(AttributeController.class).getModel(workspace);
    attributeModel.mergeModel(container.getAttributeModel());

    // Dynamic
    if (container.getTimeFormat() != null) {
      DynamicController dynamicController = Lookup.getDefault().lookup(DynamicController.class);
      if (dynamicController != null) {
        dynamicController.setTimeFormat(container.getTimeFormat());
      }
    }

    int nodeCount = 0;
    // Create all nodes
    for (NodeDraftGetter draftNode : container.getNodes()) {
      Node n = factory.newNode(draftNode.isAutoId() ? null : draftNode.getId());
      flushToNode(draftNode, n);
      draftNode.setNode(n);
      nodeCount++;
    }

    // Push nodes in data structure
    for (NodeDraftGetter draftNode : container.getNodes()) {
      Node n = draftNode.getNode();
      NodeDraftGetter[] parents = draftNode.getParents();
      if (parents != null) {
        for (int i = 0; i < parents.length; i++) {
          Node parent = parents[i].getNode();
          graph.addNode(n, parent);
        }
      } else {
        graph.addNode(n);
      }
    }

    // Create all edges and push to data structure
    int edgeCount = 0;
    for (EdgeDraftGetter edge : container.getEdges()) {
      Node source = edge.getSource().getNode();
      Node target = edge.getTarget().getNode();
      Edge e = null;
      switch (container.getEdgeDefault()) {
        case DIRECTED:
          e =
              factory.newEdge(
                  edge.isAutoId() ? null : edge.getId(), source, target, edge.getWeight(), true);
          break;
        case UNDIRECTED:
          e =
              factory.newEdge(
                  edge.isAutoId() ? null : edge.getId(), source, target, edge.getWeight(), false);
          break;
        case MIXED:
          e =
              factory.newEdge(
                  edge.isAutoId() ? null : edge.getId(),
                  source,
                  target,
                  edge.getWeight(),
                  edge.getType().equals(EdgeType.UNDIRECTED) ? false : true);
          break;
      }

      flushToEdge(edge, e);
      edgeCount++;
      graph.addEdge(e);
    }
    workspace = null;
  }
  public void initArchitecture() {
    model = VizController.getInstance().getVizModel().getTextModel();
    vizConfig = VizController.getInstance().getVizConfig();
    drawable = VizController.getInstance().getDrawable();
    initRenderer();

    // Init sizemodes
    for (SizeMode s : sizeModes) {
      s.init();
    }

    // Model listening
    model.addChangeListener(
        new ChangeListener() {

          public void stateChanged(ChangeEvent e) {
            if (!nodeRenderer.getFont().equals(model.getNodeFont())) {
              nodeRenderer.setFont(model.getNodeFont());
            }
            if (!edgeRenderer.getFont().equals(model.getEdgeFont())) {
              edgeRenderer.setFont(model.getEdgeFont());
            }
            nodeRefresh = true;
            edgeRefresh = true;
          }
        });

    // Model change
    VizController.getInstance()
        .getVizModel()
        .addPropertyChangeListener(
            new PropertyChangeListener() {

              public void propertyChange(PropertyChangeEvent evt) {
                if (evt.getPropertyName().equals("init")) {
                  TextManager.this.model = VizController.getInstance().getVizModel().getTextModel();

                  // Initialize columns if needed
                  if (model.getNodeTextColumns() == null
                      || model.getNodeTextColumns().length == 0) {
                    AttributeController attributeController =
                        Lookup.getDefault().lookup(AttributeController.class);
                    if (attributeController != null && attributeController.getModel() != null) {
                      AttributeModel attributeModel = attributeController.getModel();
                      AttributeColumn[] nodeCols =
                          new AttributeColumn[] {
                            attributeModel
                                .getNodeTable()
                                .getColumn(PropertiesColumn.NODE_LABEL.getIndex())
                          };
                      AttributeColumn[] edgeCols =
                          new AttributeColumn[] {
                            attributeModel
                                .getEdgeTable()
                                .getColumn(PropertiesColumn.EDGE_LABEL.getIndex())
                          };
                      model.setTextColumns(nodeCols, edgeCols);
                    }
                  }

                  DynamicModel dynamicModel = dynamicController.getModel();
                  if (dynamicModel != null) {
                    currentTimeInterval = dynamicModel.getVisibleInterval();
                    builder.setDefaultEstimator(dynamicModel.getEstimator());
                    builder.setNumberEstimator(dynamicModel.getNumberEstimator());
                  } else {
                    currentTimeInterval = null;
                  }
                }
              }
            });

    // Settings
    antialised = vizConfig.isLabelAntialiased();
    mipmap = vizConfig.isLabelMipMap();
    fractionalMetrics = vizConfig.isLabelFractionalMetrics();
    renderer3d = false;

    // Dynamic change
    dynamicController = Lookup.getDefault().lookup(DynamicController.class);
    dynamicController.addModelListener(
        new DynamicModelListener() {

          public void dynamicModelChanged(DynamicModelEvent event) {
            if (event.getEventType().equals(DynamicModelEvent.EventType.VISIBLE_INTERVAL)) {
              currentTimeInterval = (TimeInterval) event.getData();
            }
          }
        });
  }