Пример #1
0
  protected void setRenderContextEdgeTransformers(
      RenderContext<CallGraphNode, CallGraphLink> renderContext) {
    setEdgeLabeler(renderContext);
    renderContext.setEdgeDrawPaintTransformer(
        MapTransformer.<CallGraphLink, Paint>getInstance(edgePaints));
    renderContext.setEdgeStrokeTransformer(
        new Transformer<CallGraphLink, Stroke>() {
          protected final Stroke THIN = new BasicStroke(1);
          protected final Stroke THICK = new BasicStroke(2);

          public Stroke transform(CallGraphLink e) {
            Paint c = edgePaints.get(e);
            if (c == Color.LIGHT_GRAY) return THIN;
            else return THICK;
          }
        });
  }
  public SetupGraphPane() {

    // create a simple graph for the demo
    graph = new SparseMultigraph<Number, Number>();

    this.layout = new StaticLayout<Number, Number>(graph, new Dimension(600, 600));

    vv = new VisualizationViewer<Number, Number>(layout);
    vv.setBackground(Color.white);

    vv.getRenderContext()
        .setVertexLabelTransformer(
            MapTransformer.<Number, String>getInstance(
                LazyMap.<Number, String>decorate(
                    new HashMap<Number, String>(), new ToStringLabeller<Number>())));

    vv.getRenderContext()
        .setEdgeLabelTransformer(
            MapTransformer.<Number, String>getInstance(
                LazyMap.<Number, String>decorate(
                    new HashMap<Number, String>(), new ToStringLabeller<Number>())));

    vv.setVertexToolTipTransformer(vv.getRenderContext().getVertexLabelTransformer());

    final GraphZoomScrollPane panel = new GraphZoomScrollPane(vv);
    add(panel);
    Factory<Number> vertexFactory = new VertexFactory();
    Factory<Number> edgeFactory = new EdgeFactory();

    final EditingModalGraphMouse<Number, Number> graphMouse =
        new EditingModalGraphMouse<Number, Number>(
            vv.getRenderContext(), vertexFactory, edgeFactory);

    // the EditingGraphMouse will pass mouse event coordinates to the
    // vertexLocations function to set the locations of the vertices as
    // they are created
    //        graphMouse.setVertexLocations(vertexLocations);
    vv.setGraphMouse(graphMouse);
    vv.addKeyListener(graphMouse.getModeKeyListener());

    graphMouse.setMode(ModalGraphMouse.Mode.EDITING);

    final ScalingControl scaler = new CrossoverScalingControl();
    JButton plus = new JButton("+");
    plus.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            scaler.scale(vv, 1.1f, vv.getCenter());
          }
        });
    JButton minus = new JButton("-");
    minus.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            scaler.scale(vv, 1 / 1.1f, vv.getCenter());
          }
        });

    //        JButton help = new JButton("Help");
    //        help.addActionListener(new ActionListener() {
    //
    //            public void actionPerformed(ActionEvent e) {
    //                JOptionPane.showMessageDialog(vv, instructions);
    //            }});

    AnnotationControls<Number, Number> annotationControls =
        new AnnotationControls<Number, Number>(graphMouse.getAnnotatingPlugin());
    JPanel controls = new JPanel();
    controls.add(plus);
    controls.add(minus);
    JComboBox modeBox = graphMouse.getModeComboBox();
    controls.add(modeBox);
    controls.add(annotationControls.getAnnotationsToolBar());
    // controls.add(help);
    add(controls, BorderLayout.SOUTH);
  }
  public GraphEditorDemo() {

    // create a simple graph for the demo
    graph = new SparseMultigraph<Sommet, Number>();

    Transformer<Sommet, Paint> vertexPaint =
        new Transformer<Sommet, Paint>() {
          private final Color vert = Color.GREEN;
          private final Color bleu = Color.BLUE;
          private final Color rouge = Color.RED;

          public Paint transform(Sommet s) {
            if (s.isColoriee()) {
              return rouge;
            } else {
              if (s.proprietaire == 0) {

                return vert;
              } else {
                return bleu;
              }
            }
          }
        };

    this.layout = new StaticLayout<Sommet, Number>(graph, new Dimension(600, 600));

    vv = new VisualizationViewer<Sommet, Number>(layout);
    vv.setBackground(Color.white);

    vv.getRenderContext()
        .setVertexLabelTransformer(
            MapTransformer.<Sommet, String>getInstance(
                LazyMap.<Sommet, String>decorate(
                    new HashMap<Sommet, String>(), new ToStringLabeller<Sommet>())));

    vv.getRenderContext()
        .setEdgeLabelTransformer(
            MapTransformer.<Number, String>getInstance(
                LazyMap.<Number, String>decorate(
                    new HashMap<Number, String>(), new ToStringLabeller<Number>())));

    vv.setVertexToolTipTransformer(vv.getRenderContext().getVertexLabelTransformer());

    vv.getRenderContext().setVertexFillPaintTransformer(vertexPaint);

    Container content = getContentPane();
    final GraphZoomScrollPane panel = new GraphZoomScrollPane(vv);
    content.add(panel);
    Factory<Sommet> vertexFactory = new VertexFactory();
    Factory<Number> edgeFactory = new EdgeFactory();

    final EditingModalGraphMouse<Sommet, Number> graphMouse =
        new EditingModalGraphMouse<Sommet, Number>(
            vv.getRenderContext(), vertexFactory, edgeFactory);

    // the EditingGraphMouse will pass mouse event coordinates to the
    // vertexLocations function to set the locations of the vertices as
    // they are created
    //        graphMouse.setVertexLocations(vertexLocations);
    vv.setGraphMouse(graphMouse);
    vv.addKeyListener(graphMouse.getModeKeyListener());

    graphMouse.setMode(ModalGraphMouse.Mode.CREATION);

    final ScalingControl scaler = new CrossoverScalingControl();

    JButton plus = new JButton("+");
    plus.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            scaler.scale(vv, 1.1f, vv.getCenter());
          }
        });
    JButton minus = new JButton("-");
    minus.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            scaler.scale(vv, 1 / 1.1f, vv.getCenter());
          }
        });

    JToggleButton jtb = new JToggleButton("Joueur 1");
    jtb.addItemListener(
        new ItemListener() {
          public void itemStateChanged(ItemEvent ev) {
            if (ev.getStateChange() == ItemEvent.SELECTED) {
              joueurcourant = 1;

            } else if (ev.getStateChange() == ItemEvent.DESELECTED) {
              joueurcourant = 0;
            }
          }
        });

    JToggleButton jtf = new JToggleButton("Final");
    jtf.addItemListener(
        new ItemListener() {
          public void itemStateChanged(ItemEvent ev) {
            if (ev.getStateChange() == ItemEvent.SELECTED) {
              etatfinal = true;

            } else if (ev.getStateChange() == ItemEvent.DESELECTED) {
              etatfinal = false;
            }
          }
        });

    JButton att = new JButton("Attracteur Accessibilité");
    minus.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            ArrayList<Sommet> vertices = (ArrayList<Sommet>) graph.getVertices();
            ArrayList<Sommet> finaux = new ArrayList<Sommet>();
            for (Sommet s : vertices) {
              if (s.isFinal) finaux.add(s);
            }
            colorierAttracteur(finaux, graph.getVertexCount());
          }
        });

    AnnotationControls<Sommet, Number> annotationControls =
        new AnnotationControls<Sommet, Number>(graphMouse.getAnnotatingPlugin());
    JPanel controls = new JPanel();
    controls.add(plus);
    controls.add(minus);
    JComboBox modeBox = graphMouse.getModeComboBox();
    controls.add(modeBox);
    controls.add(jtb);
    controls.add(jtf);
    controls.add(att);
    // controls.add(annotationControls.getAnnotationsToolBar());
    content.add(controls, BorderLayout.SOUTH);
  }