السلام عليكم و رحمة الله و بركاته
أنا بصدد إنجاز مشروع "Graph Editor " بواسطة المكتبة الخارجية JGraph و من ضمن الوظائف المطلوبة إدخال عقدة (vertices) إدخال سهم (edge) t) في JGraph و إزالة سهم إزالة عقدة
إستطعت فعل هذا بحمد الله وحده و لكن بقيت مشكلة ألا و هي أنه مطلوب مني إزالة كل الأسهم المربوطة بهذه العقدة التي نريد إزالتها
ها هو البرنامج
class supprimeAction implements ActionListener{
public void actionPerformed(ActionEvent e){
//supression du graph
final int i =onglet.getSelectedIndex();
Object[] t=myGraphs.get(i).selection;
//t = myGraphs.get(i).getGraph().getDescendants(t);
if( myGraphs.get(i).whatIs.equals("Une cellule ou groupe")){
for (Object obj : t)
{
if (obj == null)
continue;
String key = ((DefaultGraphCell) obj).getUserObject().toString();
myGraphs.get(i).liste.supprimer(key);
myGraphs.get(i).getGraph().getGraphLayoutCache().remove(new Object[] { obj });
}
}}
if(myGraphs.get(i).whatIs.equals("Un Lien")){
myGraphs.get(i).getGraph().getGraphLayoutCache().remove(t);فقط لمزيد توضيح البرنامج فإن المتغير (whatIs"( variable "هو متغير في "the class graph" التي في برنامجي و هي تمكننا من التمييز بين السهم و العقدة عند "the selection in the jgraph " عملية selection هي إختيار شيء ما بالفأرة و قد برمجت هذا المتغير في GraphSelectionListener و ها هو برنامجها لمزيد التوضيح فقط لكن ليس فيه أي مشكل و الحمد لله
المشكل في البرنامج الأول كما سبق التوضيح ينقصه كيف أزيل كل الأسهم المربوطة بالعقدة التي نريد إزالتها
graph.addGraphSelectionListener(new GraphSelectionListener() { public void valueChanged(GraphSelectionEvent C) { selection = graph.getSelectionCells(); for (int i = 0; i < selection.length; i++) { if (selection instanceof DefaultEdge) { whatIs="Un Lien"; System.out.println("lien"); } else if (selection instanceof DefaultGraphCell) { whatIs="Une cellule ou groupe"; System.out.println("cellule"); } }}});و جازاكم الله عنا كل خير