Jgraph

Fermé
aline - 19 mars 2008 à 20:25
 aline - 17 janv. 2009 à 21:03
Bonjour,
J'utilise jgraph.Je veux savoir comment je peux dessiner avec jgraph des formes autre que le rectancle tel que losange,cercle...
Merci pour votre aide

8 réponses

papillon2000 Messages postés 106 Date d'inscription samedi 13 décembre 2008 Statut Membre Dernière intervention 12 janvier 2010 15
13 déc. 2008 à 20:48
bonsoir,est ce qu'il ya parmis vous ceux qui ont réussi à exécuter le programme HelloWorld pour l'API jgraph,parsque j'arrive pas à avoir le résultat de ce code. et je veux vraiment l'exécuter pour l'utiliser après dans mon projet.
merci.
0
Salut,
Netbeans est un éditeur de code java comme éclipse ou jcreater ou jbuilderX .
Je ne sais pas pas comment ajouter l'api jgraph à l'éditeur que vous utiliser.
Cherchez sur le net ou télécharger netbeans et ajoute jgraph à netbeans.
Bon courage.
0
papillon2000 Messages postés 106 Date d'inscription samedi 13 décembre 2008 Statut Membre Dernière intervention 12 janvier 2010 15
15 déc. 2008 à 12:43
merci, j'ai réglé mon probléme,sayé sa marche avec jbuilder.
mon probléme maintenant et comment dessiner mon graphe c'est une sorte de workflow (ensemble de taches et le flux d'ordonnancement entre alles)
et aussi je veux dessiner sur le graphe des forme de réstagles avec des arcs empointillé (restangle empointillé).
merci.
0
papillon2000 Messages postés 106 Date d'inscription samedi 13 décembre 2008 Statut Membre Dernière intervention 12 janvier 2010 15
16 déc. 2008 à 16:32
bonjour, j'ai utilisé jgraph et sa marche,mais mon probléme (puisque il ya tjrs des problémes dans la programmation) j'arrive pas à dessiner une forme ovale (Ellipse), j'arrive pas a trouver le composant EllipseD2 pour dessiner la forme ovale.
pouvez vous m'aider c'est urgent.
merci.
0
Salut.
Désolé pour le retard.
Pour dessiner une forme autre le carré et le rectangle il te faut 3 classes:

1)L apremière classe:
import java.awt.Dimension;
import java.awt.geom.Rectangle2D; 
import java.util.Hashtable;
import java.util.Map;
import javax.swing.BorderFactory; 
import javax.swing.SwingConstants;
import org.jgraph.graph.DefaultGraphCell; 
import org.jgraph.graph.GraphConstants; 

public class MyCell extends DefaultGraphCell {
    public int code;
    public MyCell(Object userObject) { 
   
  }

    MyCell() {
            }
   public Map createCellAttributes(int x,int y,int h,int w) { 
     Map map = new Hashtable(); 
     GraphConstants.setResize(map,false); 
     
     GraphConstants.setSize(map,new Dimension(20,20) );
     // Add a Bounds Attribute to the Map 
     GraphConstants.setBounds(map, new Rectangle2D.Double(x, y,w,h)); 
     GraphConstants.setVerticalTextPosition(map, SwingConstants.CENTER); 
     GraphConstants.setLineWidth(map, 2.0f); 
     GraphConstants.setOpaque(map,true); 
     GraphConstants.setBorder(map, BorderFactory.createTitledBorder("smAA")); 
     return map; 
    }
 public void setCode(int i){code=i;}
 public int getCode(){return code;}
}



2)La deuxième classe classe:
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.GradientPaint;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;

import org.jgraph.graph.CellViewRenderer;
import org.jgraph.graph.EdgeView;
import org.jgraph.graph.VertexRenderer;
import org.jgraph.graph.VertexView;


public class JGraphEllipseView extends VertexView{
    /**
	 */
	public static transient JGraphEllipseRenderer renderer = new JGraphEllipseRenderer();

	/**
	 */
	public JGraphEllipseView() {
		super();
	}

	/**
	 */
	public JGraphEllipseView(Object cell) {
		super(cell);
	}

	/**
	 * Returns the intersection of the bounding rectangle and the
	 * straight line between the source and the specified point p.
	 * The specified point is expected not to intersect the bounds.
	 */
	public Point2D getPerimeterPoint(EdgeView edge, Point2D source, Point2D p) {
		Rectangle2D r = getBounds();

		double x = r.getX();
		double y = r.getY();
		double a = (r.getWidth() + 1) / 2;
		double b = (r.getHeight() + 1) / 2;

		// x0,y0 - center of ellipse
		double x0 = x + a;
		double y0 = y + b;

		// x1, y1 - point
		double x1 = p.getX();
		double y1 = p.getY();

		// calculate straight line equation through point and ellipse center
		// y = d * x + h
		double dx = x1 - x0;
		double dy = y1 - y0;

		if (dx == 0)
			return new Point((int) x0, (int) (y0 + b * dy / Math.abs(dy)));

		double d = dy / dx;
		double h = y0 - d * x0;

		// calculate intersection
		double e = a * a * d * d + b * b;
		double f = -2 * x0 * e;
		double g = a * a * d * d * x0 * x0 + b * b * x0 * x0 - a * a * b * b;

		double det = Math.sqrt(f * f - 4 * e * g);

		// two solutions (perimeter points)
		double xout1 = (-f + det) / (2 * e);
		double xout2 = (-f - det) / (2 * e);
		double yout1 = d * xout1 + h;
		double yout2 = d * xout2 + h;

		double dist1Squared = Math.pow((xout1 - x1), 2)
				+ Math.pow((yout1 - y1), 2);
		double dist2Squared = Math.pow((xout2 - x1), 2)
				+ Math.pow((yout2 - y1), 2);

		// correct solution
		double xout, yout;

		if (dist1Squared < dist2Squared) {
			xout = xout1;
			yout = yout1;
		} else {
			xout = xout2;
			yout = yout2;
		}

		return getAttributes().createPoint(xout, yout);
	}

	/**
	 */
        
	public CellViewRenderer getRenderer() {
		return renderer;
	}

	/**
	 */
	public static class JGraphEllipseRenderer extends VertexRenderer {

		/**
		 * Return a slightly larger preferred size than for a rectangle.
		 */
		public Dimension getPreferredSize() {
			Dimension d = super.getPreferredSize();
			d.width += d.width / 8;
			d.height += d.height / 2;
			return d;
		}

		/**
		 */
		public void paint(Graphics g) {
			int b = borderWidth;
			Graphics2D g2 = (Graphics2D) g;
			Dimension d = getSize();
			boolean tmp = selected;
			if (super.isOpaque()) {
				g.setColor(super.getBackground());
				if (gradientColor != null && !preview) {
					setOpaque(false);
					g2.setPaint(new GradientPaint(0, 0, getBackground(),
							getWidth(), getHeight(), gradientColor, true));
				}
				g.fillOval(b - 1, b - 1, d.width - b, d.height - b);
			}
			try {
				setBorder(null);
				setOpaque(false);
				selected = false;
				super.paint(g);
			} finally {
				selected = tmp;
			}
			if (bordercolor != null) {
				g.setColor(bordercolor);
				g2.setStroke(new BasicStroke(b));
				g.drawOval(b - 1, b - 1, d.width - b, d.height - b);
                                
			}
			
				
				g.setColor(highlightColor);
                                g.setColor(Color.black);
				g.drawOval(b - 1, b - 1, d.width - b, d.height - b);
                                g.fillOval(b - 1, b - 1, d.width - b, d.height - b); /*c'est l'instruction qui permet de préciser la fome du coprs à dessiner.Donc pour changer la fome géometrique à dessiner il suffit de changer cette instruction */
                                
		}
	
	}

}


3/la 3ème claase: qui contient le main



import javax.swing.JFrame;
import javax.swing.JScrollPane;
import org.jgraph.JGraph;
import org.jgraph.graph.DefaultCellViewFactory;
import org.jgraph.graph.DefaultGraphModel;

import org.jgraph.graph.GraphLayoutCache;
import org.jgraph.graph.GraphModel;
import org.jgraph.graph.VertexView;

public class test {
    public static void main(String[] args) {
GraphModel model = new DefaultGraphModel();
GraphLayoutCache view = new GraphLayoutCache(model,
new
DefaultCellViewFactory());
JGraph graph = new JGraph(model, view);
graph.getGraphLayoutCache().setFactory(new DefaultCellViewFactory() { 
      // CellViews for each type of cell 
      protected VertexView createVertexView(Object cell) { 
   if (cell instanceof MyCell) 
     return new JGraphEllipseView(cell); 
   return new VertexView(cell); 
      } 
 }); 
graph.getGraphLayoutCache().insert(new MyCell(new JGraphEllipseView()));
JFrame frame = new JFrame();
frame.getContentPane().add(new JScrollPane(graph));
frame.pack();
frame.setVisible(true);
}

}






0
ALINE > ALINE
18 déc. 2008 à 16:26
j'ai oublié de te dire.tu peux faire déplacer la cercle avec la souris, tu peux la redimmentionner.tu peux écrire dedans en double cliquant sur la cercle.
bon travail.
si l a solution que je t'ai donnée marche dit moi SVP;
0
papillon2000 Messages postés 106 Date d'inscription samedi 13 décembre 2008 Statut Membre Dernière intervention 12 janvier 2010 15
18 déc. 2008 à 21:01
oui sa marche. mais je ne sais pas si je peux le faire reliéer avec les réctangles pour dessiner une sorte de réseau de pétri ou un workflow.Merci beaucoup.
je pense que vous travaillez avec jgraph,il ya aussi la bibliothéque Jlow pour les workflow.

avec JDK1.4 quant j'utilise le package cds.clein.jgraph.Jlow je reçoi un message d'erreur qui me dis que j'utilise une classe (classe Jlow) ancienne qu'il faux changée ou supprimer.
j'arrive pas à trouvé une autre bibliothéque Jlow pour changer cette classe.
est ce que le probléme est dans la bibliothéque Jlow ou dans la vesion de JDK que j'utilise.
0
oui tu peux dessiner sur le meme graphe différents fomres.Je vais te chercher le code exacte et je te l'envoie .
Pour la bibliothèque JLow je ne la connait pas.
Bon travail.
0
aline > aline
20 déc. 2008 à 16:47
Salut.

Pour faire dessiner plusieurs formes au meme temps tu dois procéder ainsi:

tu dois remplacer le corps de La méthode createVertexView de la class main par le code suivant:
if (cell instanceof MyCell ) 
     return new JGraphEllipseView(cell); 

   
   else if (cell instanceof MyCell4)
       return new JgraphLosangeView(cell);
   
   else if (cell instanceof MyCell5)
       return new JgraphDataView(cell);
   
     
        
   return new VertexView(cell); 



MyCell4 et MyCell4 sont deux classes dont leurs codes et le meme que MyCell.
Il reste maintenant à définir les classes JgraphLosangeView et JgraphDataView

import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.GradientPaint;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Point;
import org.jgraph.graph.VertexView;
import org.jgraph.graph.CellViewRenderer;
import org.jgraph.graph.VertexRenderer;
import org.jgraph.graph.VertexView;
import org.jgraph.graph.CellViewRenderer;
import org.jgraph.graph.VertexRenderer;

public class JgraphLosangeView extends VertexView {
     public static transient ActivityRenderer renderer = new ActivityRenderer();

	public JgraphLosangeView() {
		super();
	}

	public JgraphLosangeView(Object cell) {
		super(cell);
	}

		public static int getArcSize(int width, int height) {
		int arcSize;

		
		if (width <= height) {
			arcSize = height / 5;
			if (arcSize > (width / 2)) {
				arcSize = width / 2;
			}
		} else {
			arcSize = width / 5;
			if (arcSize > (height / 2)) {
				arcSize = height / 2;
			}
		}

		return arcSize;
	}

	public CellViewRenderer getRenderer() {
		return renderer;
	}


<code>
import java.awt.Color;
import java.awt.Dimension;
import java.awt.GradientPaint;
import java.awt.Graphics;
import java.awt.Graphics2D;
import org.jgraph.graph.VertexView;
import org.jgraph.graph.CellViewRenderer;
import org.jgraph.graph.VertexRenderer;
import org.jgraph.graph.VertexView;
import org.jgraph.graph.CellViewRenderer;
import org.jgraph.graph.VertexRenderer;
/**
 * 
 * 
 * @author AMMOUNA
 */
public class JgraphDataView extends VertexView {
 public static transient ActivityRenderer renderer = new ActivityRenderer();

	public JgraphDataView() {
		super();
	}

	public JgraphDataView(Object cell) {
		super(cell);
	}

	/**
	 * Returns the intersection of the bounding rectangle and the straight line
	 * between the source and the specified point p. The specified point is
	 * expected not to intersect the bounds.
	 */
	// todo public Point2D getPerimeterPoint(Point source, Point p) {
	/**
	 * getArcSize calculates an appropriate arc for the corners of the rectangle
	 * for boundary size cases of width and height
	 */
	public static int getArcSize(int width, int height) {
		int arcSize;

		// The arc width of a activity rectangle is 1/5th of the larger
		// of the two of the dimensions passed in, but at most 1/2
		// of the smaller of the two. 1/5 because it looks nice and 1/2
		// so the arc can complete in the given dimension

		if (width <= height) {
			arcSize = height / 5;
			if (arcSize > (width / 2)) {
				arcSize = width / 2;
			}
		} else {
			arcSize = width / 5;
			if (arcSize > (height / 2)) {
				arcSize = height / 2;
			}
		}

		return arcSize;
	}

	public CellViewRenderer getRenderer() {
		return renderer;
	}

	public static class ActivityRenderer extends VertexRenderer {

		/**
		 * Return a slightly larger preferred size than for a rectangle.
		 */
		public Dimension getPreferredSize() {
			Dimension d = super.getPreferredSize();
			d.width += d.height / 5;
			return d;
		}

		public void paint(Graphics g) {
			int b = borderWidth;
			Graphics2D g2 = (Graphics2D) g;
			Dimension d = getSize();
			boolean tmp = selected;
			int roundRectArc = JGraphRoundRectView.getArcSize(d.width - b,
					d.height - b);
			if (super.isOpaque()) {
				g.setColor(super.getBackground());
				if (gradientColor != null && !preview) {
					setOpaque(false);
					g2.setPaint(new GradientPaint(0, 0, getBackground(),
							getWidth(), getHeight(), gradientColor, true));
				}
				
                                
			}
			try {
				setBorder(null);
				setOpaque(false);
				selected = false;
				super.paint(g);
			} finally {
				selected = tmp;
			}
			if (bordercolor != null) {
				g.setColor(bordercolor);
				
                              
			}
			
				g.setColor(Color.black);
				
                                g.drawRect(b - 1, b - 1, d.width - b, d.height - b);
                              
		}
                
                
                
                
                
                
	}

}



public static class ActivityRenderer extends VertexRenderer {

/**
* Return a slightly larger preferred size than for a rectangle.
*/
public Dimension getPreferredSize() {
Dimension d = super.getPreferredSize();
d.width += d.height / 5;
return d;
}

public void paint(Graphics g) {
int b = borderWidth;
Graphics2D g2 = (Graphics2D) g;
Dimension d = getSize();
boolean tmp = selected;
int roundRectArc = JGraphRoundRectView.getArcSize(d.width - b,
d.height - b);
if (super.isOpaque()) {
g.setColor(super.getBackground());
if (gradientColor != null && !preview) {
setOpaque(false);
g2.setPaint(new GradientPaint(0, 0, getBackground(),
getWidth(), getHeight(), gradientColor, true));
}

}
try {
setBorder(null);
setOpaque(false);
selected = false;
super.paint(g);
} finally {
selected = tmp;
}
if (bordercolor != null) {
g.setColor(bordercolor);
g2.setStroke(new BasicStroke(b));
int x[]={40,30,20,30};
int Y[]={40,30,40,50};
g.drawPolygon(x,Y,4);
}

Dimension size = this.getSize();
int x = size.width / 2;
int y = size.height / 2;
Point[] p = new Point[] { new Point(x, 0), new Point(0, y), new Point(x, size.height - 1), new Point(size.width - 1, y)};
int[] xp = new int[] { x, 0, x, size.width - 1 };
int[] yp = new int[] { 0, y, size.height - 1, y };
g.drawPolygon(xp, yp, 4);
}
}

}

</code>



La classe test devient ainsi



import javax.swing.JFrame;
import javax.swing.JScrollPane;
import org.jgraph.JGraph;
import org.jgraph.graph.DefaultCellViewFactory;
import org.jgraph.graph.DefaultGraphModel;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
import org.jgraph.graph.GraphLayoutCache;
import org.jgraph.graph.GraphModel;
import org.jgraph.graph.VertexView;

public class test {
    public static void main(String[] args) {
GraphModel model = new DefaultGraphModel();
GraphLayoutCache view = new GraphLayoutCache(model,
new
DefaultCellViewFactory());
JGraph graph = new JGraph(model, view);
graph.getGraphLayoutCache().setFactory(new DefaultCellViewFactory() { 
      // CellViews for each type of cell 
     /* protected VertexView createVertexView(Object cell) { 
   if (cell instanceof MyCell) 
     return new JGraphEllipseView(cell); 
   return new VertexView(cell); 
      } */
    protected VertexView createVertexView(Object cell) { 
  if (cell instanceof MyCell ) 
     return new JGraphEllipseView(cell); 
   
   else if (cell instanceof MyCell1)
       return new JGraphRoundRectView(cell);
   
   else if (cell instanceof MyCell2)
       return new JgraphLoopView(cell);
   
   else if (cell instanceof MyCell3)
       return new JgraphFinal(cell);
   
   else if (cell instanceof MyCell4)
       return new JgraphLosangeView(cell);
   
   else if (cell instanceof MyCell5)
       return new JgraphDataView(cell);
   
    else if (cell instanceof MyCell6)
       return new JgraphJoinView(cell);
   
      else if (cell instanceof MyCell7)
       return new JgraphForkView(cell);
   
   return new VertexView(cell); 
      } 
    
 }); 
graph.getGraphLayoutCache().insert(new MyCell(new JGraphEllipseView()));

graph.getGraphLayoutCache().insert(new MyCell5(new JgraphDataView()));

graph.getGraphLayoutCache().insert(new MyCell4(new JgraphLosangeView()));
JFrame frame = new JFrame();
frame.getContentPane().add(new JScrollPane(graph));
frame.pack();
frame.setVisible(true);
}

}




Dans l'exécution, les trois formes géométriques seront superposées.
essaie ce code et dit moi est ce que ça marche ou nom?
Bon travail.
0

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
papillon2000 Messages postés 106 Date d'inscription samedi 13 décembre 2008 Statut Membre Dernière intervention 12 janvier 2010 15
22 déc. 2008 à 14:06
merci aline mais le programme ne marche pas,j'arrive pas à trouver dans jgraph le package
import org.jgraph.cellview.JGraphRoundRectView;
peut etre c'est l'api jgraph que j'ai téléchargé;
0
salut.
je ne comprends pas pourquoi tu cherche le package import org.jgraph.cellview.JGraphRoundRectView;
si le code ne marche pas dit moi quel est le message d'erreur exacte.
0
papillon2000 Messages postés 106 Date d'inscription samedi 13 décembre 2008 Statut Membre Dernière intervention 12 janvier 2010 15
23 déc. 2008 à 12:24
bonjour,je t'envoie aline le message d'erreur:

- "JgraphDataView.java": cannot resolve symbol: variable JGraphRoundRectView in class application_dession.JgraphDataView.ActivityRenderer at line 93, column 44
- "ActivityRenderer.java": package org.jgraph.cellview does not exist at line 25, column 28
- "ActivityRenderer.java": cannot resolve symbol: variable JGraphRoundRectView in class application_dession.ActivityRenderer at line 47, column 20

je t'informe que je travaille avec jbuilder (jdk1.4).
tu peux m'envoyé aline la bibliothéque jgraph que tu utilise peut etre c'est la version de jgraph que l'utilise.
si t'es d'accord je t'envoie mon adresse la prochaine fois.
0
salut.
J e suis OK pour l'envoie.
Si tu ne veux pas envoyer ton @ ici pour que ça ne soit pas visible à tous le monde , je te dis que je suis la meme persoone que je t'ai répondu sur le forum de www.javafr.com. Mon pseudonom là est monpseudonom.Tu peut m'envoyé ton @ dans un email sur ce forum.
a+
0
med issam Messages postés 1 Date d'inscription lundi 14 janvier 2008 Statut Membre Dernière intervention 15 janvier 2009 > aline
15 janv. 2009 à 17:44
slt Aline
d'après ma recherche sur Jgraph j'ai trouver que normalement tu peus me répondre a des question consernons Jgraph.
SVP aide moi c urgent
SVP ,
mon travail consiste a tracer un graphe qui se compose des carraeu et des cercle qui sont lier avec des flèches.
Ce graphe dynamique, l'utilisateur entre le nombre des carreaux et des cercles.
jai arriver a tracer les carreaux mais les cecles non.
jai trouver des codes qui se compose de 3 classe pour tracer une cercle qui je ne peu pas modifier sa taille ni son emplacement.
ce que je veux que tu m'aide a tracer ce graphe et surtou les cercle.
SVP, aide moi
j'attend ta réponse
et merci d'avance.
0
aline > med issam Messages postés 1 Date d'inscription lundi 14 janvier 2008 Statut Membre Dernière intervention 15 janvier 2009
17 janv. 2009 à 20:59
Bonjour,

essaie ce code:
première classe

package bi2;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.geom.Rectangle2D;
import java.util.Hashtable;
import java.util.Map;
import javax.swing.BorderFactory;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.SwingConstants;
import org.jgraph.JGraph;
import org.jgraph.graph.DefaultCellViewFactory;
import org.jgraph.graph.DefaultGraphModel;
import org.jgraph.graph.GraphConstants;
import org.jgraph.graph.GraphLayoutCache;
import org.jgraph.graph.GraphModel;
import org.jgraph.graph.VertexView;


public class test {
    public static void main(String[] args) {
GraphModel model = new DefaultGraphModel();
GraphLayoutCache view = new GraphLayoutCache(model,
new
DefaultCellViewFactory());
JGraph graph = new JGraph(model, view);
graph.getGraphLayoutCache().setFactory(new DefaultCellViewFactory() { 
      // CellViews for each type of cell 
     /* protected VertexView createVertexView(Object cell) { 
   if (cell instanceof MyCell) 
     return new JGraphEllipseView(cell); 
   return new VertexView(cell); 
      } */
    protected VertexView createVertexView(Object cell) { 
  if (cell instanceof MyCell ) 
     return new JGraphEllipseView(cell); 
   
     
  
   else if (cell instanceof MyCell5)
       return new JgraphDataView(cell);
   
      
   return new VertexView(cell); 
      } 
    
 }); 
       
       JGraphEllipseView activity = new JGraphEllipseView();
       MyCell cellAct = new  MyCell(activity);
       
       Map map = new Hashtable(); 
       GraphConstants.setResize(map,false); 
       GraphConstants.setSize(map,new Dimension(20,20) );
       GraphConstants.setBounds(map, new Rectangle2D.Double(400,50,85,85)); 
       GraphConstants.setVerticalTextPosition(map, SwingConstants.CENTER);
       GraphConstants.setLineWidth(map, 2.0f); 
       GraphConstants.setOpaque(map,true); 
       GraphConstants.setBorder(map, BorderFactory.createTitledBorder("smAA"));
       
       cellAct.getAttributes().applyMap(map); 
       
      
       GraphConstants.setEditable(cellAct.getAttributes(),false);
       GraphConstants.setBackground(cellAct.getAttributes(),Color.white); 
       graph.getGraphLayoutCache().insert(cellAct);



graph.getGraphLayoutCache().insert(new MyCell5(new JgraphDataView()));

//graph.getGraphLayoutCache().insert(new MyCell4(new JgraphLosangeView()));
JFrame frame = new JFrame();
frame.getContentPane().add(new JScrollPane(graph));
frame.pack();
frame.setVisible(true);
}

}



deuxième classe
package bi2;

import java.awt.Dimension;

import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D; 
import java.util.Hashtable;
import java.util.Map;
import javax.swing.BorderFactory; 

import javax.swing.SwingConstants;
import org.jgraph.graph.DefaultGraphCell; 
import org.jgraph.graph.GraphConstants; 

public class MyCell5 extends DefaultGraphCell {
    public int code;
     String name=""; 
      String stereo="unknown";
      String desc="";
    public MyCell5(Object userObject) { 
  
   
  } 
    public MyCell5() { 
     
  } 
   public Map createCellAttributes(int x,int y,int h,int w) { 
     Map map = new Hashtable(); 
     GraphConstants.setResize(map,false); 
     
     GraphConstants.setSize(map,new Dimension(90,90) );
     // Add a Bounds Attribute to the Map 
      GraphConstants.setBounds(map, new Rectangle2D.Double(x, y,w,h));  
     GraphConstants.setVerticalTextPosition(map, SwingConstants.CENTER); 
     GraphConstants.setLineWidth(map, 2.0f); 
     GraphConstants.setOpaque(map,true); 
     GraphConstants.setBorder(map, BorderFactory.createTitledBorder("smAA")); 
     return map; 
    }
 public void setCode(int i){code=i;}
 public int getCode(){return code;}
}
 



troisième classe


/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package bi2;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.GradientPaint;
import java.awt.Graphics;
import java.awt.Graphics2D;
import org.jgraph.graph.VertexView;
import org.jgraph.graph.CellViewRenderer;
import org.jgraph.graph.VertexRenderer;
import org.jgraph.graph.VertexView;
import org.jgraph.graph.CellViewRenderer;
import org.jgraph.graph.VertexRenderer;

public class JGraphRoundRectView extends VertexView{
    public static transient ActivityRenderer renderer = new ActivityRenderer();

	public JGraphRoundRectView() {
		super();
	}

	public JGraphRoundRectView(Object cell) {
		super(cell);
	}

	/**
	 * Returns the intersection of the bounding rectangle and the straight line
	 * between the source and the specified point p. The specified point is
	 * expected not to intersect the bounds.
	 */
	// todo public Point2D getPerimeterPoint(Point source, Point p) {
	/**
	 * getArcSize calculates an appropriate arc for the corners of the rectangle
	 * for boundary size cases of width and height
	 */
	public static int getArcSize(int width, int height) {
		int arcSize;

		// The arc width of a activity rectangle is 1/5th of the larger
		// of the two of the dimensions passed in, but at most 1/2
		// of the smaller of the two. 1/5 because it looks nice and 1/2
		// so the arc can complete in the given dimension

		if (width <= height) {
			arcSize = height / 5;
			if (arcSize > (width / 2)) {
				arcSize = width / 2;
			}
		} else {
			arcSize = width / 5;
			if (arcSize > (height / 2)) {
				arcSize = height / 2;
			}
		}

		return arcSize;
	}

	public CellViewRenderer getRenderer() {
		return renderer;
	}

	public static class ActivityRenderer extends VertexRenderer {

		/**
		 * Return a slightly larger preferred size than for a rectangle.
		 */
		public Dimension getPreferredSize() {
			Dimension d = super.getPreferredSize();
			d.width += d.height / 5;
			return d;
		}

		public void paint(Graphics g) {
			int b = borderWidth;
			Graphics2D g2 = (Graphics2D) g;
			Dimension d = getSize();
			boolean tmp = selected;
			int roundRectArc = JGraphRoundRectView.getArcSize(d.width - b,
					d.height - b);
			if (super.isOpaque()) {
				g.setColor(super.getBackground());
				if (gradientColor != null && !preview) {
					setOpaque(false);
					g2.setPaint(new GradientPaint(0, 0, getBackground(),
							getWidth(), getHeight(), gradientColor, true));
				}
				g.fillRoundRect(b / 2, b / 2, d.width - (int) (b * 1.5),
						d.height - (int) (b * 1.5), roundRectArc, roundRectArc);
			}
			try {
				setBorder(null);
				setOpaque(false);
				selected = false;
				super.paint(g);
			} finally {
				selected = tmp;
			}
			if (bordercolor != null) {
				g.setColor(bordercolor);
				//g2.setStroke(new BasicStroke(b));
				g.drawRoundRect(b / 2, b / 2, d.width - (int) (b * 1.5),
						d.height - (int) (b * 1.5), roundRectArc, roundRectArc);
			}
			//if (selected) {
				//g2.setStroke(GraphConstants.SELECTION_STROKE);
				g.setColor(Color.black);
				g.drawRoundRect(b / 2, b / 2, d.width - (int) (b * 1.5),
						d.height - (int) (b * 1.5), roundRectArc, roundRectArc);
			//}
		}
	}


}





quatrième classe

package bi2;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.GradientPaint;
import java.awt.Graphics;
import java.awt.Graphics2D;
import org.jgraph.graph.VertexView;
import org.jgraph.graph.CellViewRenderer;
import org.jgraph.graph.VertexRenderer;
import org.jgraph.graph.VertexView;
import org.jgraph.graph.CellViewRenderer;
import org.jgraph.graph.VertexRenderer;
/**
 * 
 * 
 * @author AMMOUNA
 */
public class JgraphDataView extends VertexView {
 public static transient ActivityRenderer renderer = new ActivityRenderer();

	public JgraphDataView() {
		super();
	}

	public JgraphDataView(Object cell) {
		super(cell);
	}

	/**
	 * Returns the intersection of the bounding rectangle and the straight line
	 * between the source and the specified point p. The specified point is
	 * expected not to intersect the bounds.
	 */
	// todo public Point2D getPerimeterPoint(Point source, Point p) {
	/**
	 * getArcSize calculates an appropriate arc for the corners of the rectangle
	 * for boundary size cases of width and height
	 */
	public static int getArcSize(int width, int height) {
		int arcSize;

		// The arc width of a activity rectangle is 1/5th of the larger
		// of the two of the dimensions passed in, but at most 1/2
		// of the smaller of the two. 1/5 because it looks nice and 1/2
		// so the arc can complete in the given dimension

		if (width <= height) {
			arcSize = height / 5;
			if (arcSize > (width / 2)) {
				arcSize = width / 2;
			}
		} else {
			arcSize = width / 5;
			if (arcSize > (height / 2)) {
				arcSize = height / 2;
			}
		}

		return arcSize;
	}

	public CellViewRenderer getRenderer() {
		return renderer;
	}

	public static class ActivityRenderer extends VertexRenderer {

		/**
		 * Return a slightly larger preferred size than for a rectangle.
		 */
		public Dimension getPreferredSize() {
			Dimension d = super.getPreferredSize();
			d.width += d.height / 5;
			return d;
		}

		public void paint(Graphics g) {
			int b = borderWidth;
			Graphics2D g2 = (Graphics2D) g;
			Dimension d = getSize();
			boolean tmp = selected;
	int roundRectArc = JGraphRoundRectView.getArcSize(d.width - b,
					d.height - b);
			if (super.isOpaque()) {
				g.setColor(super.getBackground());
				if (gradientColor != null && !preview) {
					setOpaque(false);
					g2.setPaint(new GradientPaint(0, 0, getBackground(),
							getWidth(), getHeight(), gradientColor, true));
				}
				
                                
			}
			try {
				setBorder(null);
				setOpaque(false);
				selected = false;
				super.paint(g);
			} finally {
				selected = tmp;
			}
			if (bordercolor != null) {
				g.setColor(bordercolor);
				
                              
			}
			
				g.setColor(Color.red);
				
                                g.drawRect(b - 1, b - 1, d.width - b, d.height - b);
                              
		}
                
                
                
                
                
                
	}

}



cinquième classe


package bi2;

import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.GradientPaint;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;

import org.jgraph.graph.CellViewRenderer;
import org.jgraph.graph.EdgeView;
import org.jgraph.graph.VertexRenderer;
import org.jgraph.graph.VertexView;


public class JGraphEllipseView extends VertexView{
    /**
	 */
	public static transient JGraphEllipseRenderer renderer = new JGraphEllipseRenderer();

	/**
	 */
	public JGraphEllipseView() {
		super();
	}

	/**
	 */
	public JGraphEllipseView(Object cell) {
		super(cell);
	}

	/**
	 * Returns the intersection of the bounding rectangle and the
	 * straight line between the source and the specified point p.
	 * The specified point is expected not to intersect the bounds.
	 */
	public Point2D getPerimeterPoint(EdgeView edge, Point2D source, Point2D p) {
		Rectangle2D r = getBounds();

		double x = r.getX();
		double y = r.getY();
		double a = (r.getWidth() + 1) / 2;
		double b = (r.getHeight() + 1) / 2;

		// x0,y0 - center of ellipse
		double x0 = x + a;
		double y0 = y + b;

		// x1, y1 - point
		double x1 = p.getX();
		double y1 = p.getY();

		// calculate straight line equation through point and ellipse center
		// y = d * x + h
		double dx = x1 - x0;
		double dy = y1 - y0;

		if (dx == 0)
			return new Point((int) x0, (int) (y0 + b * dy / Math.abs(dy)));

		double d = dy / dx;
		double h = y0 - d * x0;

		// calculate intersection
		double e = a * a * d * d + b * b;
		double f = -2 * x0 * e;
		double g = a * a * d * d * x0 * x0 + b * b * x0 * x0 - a * a * b * b;

		double det = Math.sqrt(f * f - 4 * e * g);

		// two solutions (perimeter points)
		double xout1 = (-f + det) / (2 * e);
		double xout2 = (-f - det) / (2 * e);
		double yout1 = d * xout1 + h;
		double yout2 = d * xout2 + h;

		double dist1Squared = Math.pow((xout1 - x1), 2)
				+ Math.pow((yout1 - y1), 2);
		double dist2Squared = Math.pow((xout2 - x1), 2)
				+ Math.pow((yout2 - y1), 2);

		// correct solution
		double xout, yout;

		if (dist1Squared < dist2Squared) {
			xout = xout1;
			yout = yout1;
		} else {
			xout = xout2;
			yout = yout2;
		}

		return getAttributes().createPoint(xout, yout);
	}

	/**
	 */
        
	public CellViewRenderer getRenderer() {
		return renderer;
	}

	/**
	 */
	public static class JGraphEllipseRenderer extends VertexRenderer {

		/**
		 * Return a slightly larger preferred size than for a rectangle.
		 */
		public Dimension getPreferredSize() {
			Dimension d = super.getPreferredSize();
			d.width += d.width / 8;
			d.height += d.height / 2;
			return d;
		}

		/**
		 */
		public void paint(Graphics g) {
			int b = borderWidth;
			Graphics2D g2 = (Graphics2D) g;
			Dimension d = getSize();
			boolean tmp = selected;
			if (super.isOpaque()) {
				g.setColor(super.getBackground());
				if (gradientColor != null && !preview) {
					setOpaque(false);
					g2.setPaint(new GradientPaint(0, 0, getBackground(),
							getWidth(), getHeight(), gradientColor, true));
				}
				g.fillOval(b - 1, b - 1, d.width - b, d.height - b);
			}
			try {
				setBorder(null);
				setOpaque(false);
				selected = false;
				super.paint(g);
			} finally {
				selected = tmp;
			}
			if (bordercolor != null) {
				g.setColor(bordercolor);
				g2.setStroke(new BasicStroke(b));
				g.drawOval(b - 1, b - 1, d.width - b, d.height - b);
                                
			}
			
				
				g.setColor(highlightColor);
                                g.setColor(Color.black);
				g.drawOval(b - 1, b - 1, d.width - b, d.height - b);
                                g.fillOval(b - 1, b - 1, d.width - b, d.height - b);
                                
		}
	
	}

}


sixième classe


package bi2;

import java.awt.geom.Rectangle2D;
import java.util.Hashtable;
import java.util.Map;
import javax.swing.BorderFactory;
import javax.swing.SwingConstants;
import org.jgraph.graph.DefaultGraphCell;
import org.jgraph.graph.GraphConstants;
public class MyCell4 extends DefaultGraphCell{
      public int code;
    public MyCell4(Object userObject) { 
    super(userObject); 
   
  }

    MyCell4() {
        
    }
   public Map createCellAttributes(int x,int y,int h,int w) { 
     Map map = new Hashtable(); 
     GraphConstants.setResize(map,false); 
     GraphConstants.setAutoSize(map,false); 
     // Add a Bounds Attribute to the Map 
      GraphConstants.setBounds(map, new Rectangle2D.Double(x, y,w,h)); 
     GraphConstants.setVerticalTextPosition(map, SwingConstants.TOP); 
     GraphConstants.setLineWidth(map, 9.0f); 
     GraphConstants.setOpaque(map,false); 
     GraphConstants.setBorder(map, BorderFactory.createTitledBorder("smAA")); 
     return map; 
    }
public void setCode(int i){code=i;}
   public int getCode(){return code;}
}



septième classe
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package bi2;

import java.awt.Dimension;

import java.awt.geom.Rectangle2D; 
import java.util.Hashtable;
import java.util.Map;
import javax.swing.BorderFactory; 

import javax.swing.SwingConstants;
import org.jgraph.graph.DefaultGraphCell; 
import org.jgraph.graph.GraphConstants; 

public class MyCell extends DefaultGraphCell {
    public int code;
    public MyCell(Object userObject) { 
   
  }

    MyCell() {
            }
   public Map createCellAttributes(int x,int y,int h,int w) { 
     Map map = new Hashtable(); 
     GraphConstants.setResize(map,false); 
     
     GraphConstants.setSize(map,new Dimension(20,20) );
     // Add a Bounds Attribute to the Map 
     GraphConstants.setBounds(map, new Rectangle2D.Double(x, y,w,h)); 
     GraphConstants.setVerticalTextPosition(map, SwingConstants.CENTER); 
     GraphConstants.setLineWidth(map, 2.0f); 
     GraphConstants.setOpaque(map,true); 
     GraphConstants.setBorder(map, BorderFactory.createTitledBorder("smAA")); 
     return map; 
    }
 public void setCode(int i){code=i;}
 public int getCode(){return code;}
}





l'instruction qui s'occupe de l'emplacement de l'objet ainsi les dimensions est l'instruction suivante du classe test:
GraphConstants.setBounds(map, new Rectangle2D.Double(400,50,85,85));

400 : c'est la valeur du x
50: valeur du y
85: valeur de la longeur
85: valeur largeur

donc il suffit de cahnger ces paramètres.
essaie ce code et dit moi est ce que tu obtient le resultat souhauté ou nom.
0
aline > aline
17 janv. 2009 à 21:03
j'ai oublié de dire que cette instruction se trouve dans la classe test.
bon travail
0
papillon2000 Messages postés 106 Date d'inscription samedi 13 décembre 2008 Statut Membre Dernière intervention 12 janvier 2010 15
23 déc. 2008 à 14:03
ok aline.merci
0
vedoca Messages postés 9 Date d'inscription mercredi 19 mars 2008 Statut Membre Dernière intervention 14 avril 2008
20 mars 2008 à 16:50
bonjour je te propose cette doc

http://mbaron.ftp-developpez.com/javase/javavisu.pdf

mais j'ai un problème avec JGraph j'arrive pas à installé correctement SVP aider mois j'ai vraiment pas le temps ,j'utilise crimson iditor et j'ai téléchargé "jgraph-latest_lgpl-src" de taille 3380Ko comment faire aide mois SVP c'est urgent
voila ce que j'ai fait j'ai installer jgraph.jar dans la partie C et j'ai ajouter le chemin d'accès au fichier jgraph.jar à la variable d'environnement système mais quand j'ai exécute un exemple que j'ai télécharger il m'affiche c'est erreurs

C:\Documents and Settings\bonbino\Bureau>javac HelloWorld.java
HelloWorld.java:9: package org.jgraph does not exist
import org.jgraph.JGraph;
^
HelloWorld.java:10: package org.jgraph.graph does not exist
import org.jgraph.graph.DefaultEdge;
^
HelloWorld.java:11: package org.jgraph.graph does not exist
import org.jgraph.graph.DefaultGraphCell;
^
HelloWorld.java:12: package org.jgraph.graph does not exist
import org.jgraph.graph.DefaultGraphModel;
^
HelloWorld.java:13: package org.jgraph.graph does not exist
import org.jgraph.graph.DefaultPort;
^
HelloWorld.java:14: package org.jgraph.graph does not exist
import org.jgraph.graph.GraphConstants;
^
HelloWorld.java:15: package org.jgraph.graph does not exist
import org.jgraph.graph.GraphModel;
^
HelloWorld.java:66: cannot find symbol
symbol : class DefaultGraphCell


******************voila l'exemple*********************



import java.awt.Color;
import java.awt.geom.Rectangle2D;

import javax.swing.BorderFactory;
import javax.swing.JFrame;
import javax.swing.JScrollPane;

import org.jgraph.JGraph;
import org.jgraph.graph.DefaultEdge;
import org.jgraph.graph.DefaultGraphCell;
import org.jgraph.graph.DefaultGraphModel;
import org.jgraph.graph.DefaultPort;
import org.jgraph.graph.GraphConstants;
import org.jgraph.graph.GraphModel;

public class HelloWorld {

public static void main(String[] args) {

// Construct Model and Graph
GraphModel model = new DefaultGraphModel();
JGraph graph = new JGraph(model);

// Control-drag should clone selection
graph.setCloneable(false);

// Enable edit without final RETURN keystroke
graph.setInvokesStopCellEditing(true);

// When over a cell, jump to its default port (we only have one, anyway)
graph.setJumpToDefaultPort(true);

// Insert all three cells in one call, so we need an array to store them
DefaultGraphCell[] cells = new DefaultGraphCell[3];

// Create Hello Vertex
cells[0] = createVertex("Hello", 20, 20, 40, 20, Color.BLUE, false);

// Create World Vertex
cells[1] = createVertex("World", 140, 140, 40, 20, Color.ORANGE, true);

// Create Edge
DefaultEdge edge = new DefaultEdge();
// Fetch the ports from the new vertices, and connect them with the edge
edge.setSource(cells[0].getChildAt(0));
edge.setTarget(cells[1].getChildAt(0));
cells[2] = edge;

// Set Arrow Style for edge
int arrow = GraphConstants.ARROW_CLASSIC;
GraphConstants.setLineEnd(edge.getAttributes(), arrow);
GraphConstants.setEndFill(edge.getAttributes(), true);

// Insert the cells via the cache, so they get selected
graph.getGraphLayoutCache().insert(cells);

// Show in Frame
JFrame frame = new JFrame();
frame.getContentPane().add(new JScrollPane(graph));
//frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setVisible(true);
}

public static DefaultGraphCell createVertex(String name, double x,
double y, double w, double h, Color bg, boolean raised) {

// Create vertex with the given name
DefaultGraphCell cell = new DefaultGraphCell(name);

// Set bounds
GraphConstants.setBounds(cell.getAttributes(), new Rectangle2D.Double(
x, y, w, h));



// Set fill color
if (bg != null) {
GraphConstants.setGradientColor(cell.getAttributes(), Color.orange);
GraphConstants.setOpaque(cell.getAttributes(), true);
}

// Set raised border
if (raised)
GraphConstants.setBorder(cell.getAttributes(), BorderFactory
.createRaisedBevelBorder());
else
// Set black border
GraphConstants.setBorderColor(cell.getAttributes(), Color.black);

// Add a Port
DefaultPort port = new DefaultPort();
cell.add(port);
port.setParent(cell);

return cell;
}
}
-1
ahhhhhhhhhh,ba moi aussi g deja passé 12h a cherché sur ce sujet et pas de solution encore,courage,cherchons encore
0
vedoca Messages postés 9 Date d'inscription mercredi 19 mars 2008 Statut Membre Dernière intervention 14 avril 2008 > aissa
21 mars 2008 à 19:49
bonsoir aissa

j'ai pas passé tous ce temps!!!!! , je crois que tu es déconnecté dans ta recherche je te propose de voir ce lien si tu n'est pas désespérerai

https://github.com/jgraph
0
Bonjour
Merci pour ta reponse.
Mais moi j'utilise netbeans et je ne sais pas ce crimson.
Mais je vais te dire comment j'ai ajouté jgraph à netbeans peut etre cela t'aide.
il faut savoir que Jgraph est une bibliothèque externe donc, il faut la télécharger, puis prendre le jar " jgraph.jar" qui se trouve dans le dossier "lib" de ton " zip ou jar " que tu as téléchargé
ensuiste il faut intégré ce jar dans ton projet dans NetBeans en suivant ce lien https://java.developpez.com/faq/netbe...ojetsStandards

Bon courage
0
papillon2000 Messages postés 106 Date d'inscription samedi 13 décembre 2008 Statut Membre Dernière intervention 12 janvier 2010 15 > aline
14 déc. 2008 à 13:45
bonjour,j'ai téléchargé jgraph mais je rencontre des defficultés dans son utilisation.
sa marche pas l'exemple de code HelloWorld.
je travaille avec jcreater ou jbuilderX avec JDK 1.5
je ne comprend pas ce que vous dite pas netbean.
est ce que je veux avoir plus d'information et orientation SVP, afin de pouvoir utiliser la JGRAPH c'est très important pour moi.
merci.
0
papillon2000 Messages postés 106 Date d'inscription samedi 13 décembre 2008 Statut Membre Dernière intervention 12 janvier 2010 15
13 déc. 2008 à 21:47
bonsoir à tous,moi aussi j'ai le méme probléme.j'arrive pas à utiliser l'API jgraph,pouvez vous m'envoyé les instruction exacte pour son inctalation pour pouvoir l'utiliser.
je travaille avec jbuilder,est ce qu'il me faux un autre logiciel pour que sa marche?

SVP c'est très urgent.merci.
0