Gephi Toolkitを使用してグラフ アプレットを作成し、それを JavaEE Web サイトに統合しようとしています。しかし問題は、Gephi Toolkit (Preview API) が対話型機能をほとんどサポートしていないことです。
Gephi フォーラムのこのトピックによると、マウス リスナーを実装して、ノードのクリックなどのマウス イベントを処理する必要があります。しかし、私はそれを理解していませんでした.誰かがこれについて私を助けることができますか?
コード: ランダム グラフを表示するクラスを作成し (これは問題ありません)、 PreviewMouseListenerを実装する新しいクラスを追加し、ノードがクリックされたときにメッセージを出力します。
/*
Copyright 2008-2010 Gephi
Authors : Mathieu Bastian <mathieu.bastian@gephi.org>
Website : http://www.gephi.org
This file is part of Gephi.
Gephi is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
Gephi is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with Gephi. If not, see <http://www.gnu.org/licenses/>.
*/
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.io.File;
import javax.swing.JFrame;
import org.gephi.graph.api.GraphController;
import org.gephi.graph.api.GraphModel;
import org.gephi.graph.api.NodeIterator;
import org.gephi.io.generator.plugin.RandomGraph;
import org.gephi.io.importer.api.Container;
import org.gephi.io.importer.api.ContainerFactory;
import org.gephi.io.importer.api.ImportController;
import org.gephi.io.processor.plugin.DefaultProcessor;
import org.gephi.layout.plugin.random.Random;
import org.gephi.layout.plugin.random.RandomLayout;
import org.gephi.preview.api.PreviewController;
import org.gephi.preview.api.PreviewModel;
import org.gephi.preview.api.PreviewProperty;
import org.gephi.preview.api.ProcessingTarget;
import org.gephi.preview.api.RenderTarget;
import org.gephi.preview.types.DependantOriginalColor;
import org.gephi.project.api.ProjectController;
import org.gephi.project.api.Workspace;
import org.openide.util.Lookup;
import processing.core.PApplet;
/**
*
* @author Mathieu Bastian
*/
public class PreviewJFrame {
public void script() {
//Init a project - and therefore a workspace
ProjectController pc = Lookup.getDefault().lookup(ProjectController.class);
pc.newProject();
Workspace workspace = pc.getCurrentWorkspace();
//Generate a random graph
Container container = Lookup.getDefault().lookup(ContainerFactory.class).newContainer();
RandomGraph randomGraph = new RandomGraph();
randomGraph.setNumberOfNodes(50);
randomGraph.setWiringProbability(0.005);
randomGraph.generate(container.getLoader());
//Append imported data to GraphAPI
ImportController importController = Lookup.getDefault().lookup(ImportController.class);
importController.process(container, new DefaultProcessor(), workspace);
GraphModel graphModel = Lookup.getDefault().lookup(GraphController.class).getModel();
//Preview configuration
PreviewController previewController = Lookup.getDefault().lookup(PreviewController.class);
PreviewModel previewModel = previewController.getModel();
previewModel.getProperties().putValue(PreviewProperty.SHOW_NODE_LABELS, Boolean.TRUE);
previewModel.getProperties().putValue(PreviewProperty.NODE_LABEL_COLOR, new DependantOriginalColor(Color.WHITE));
previewModel.getProperties().putValue(PreviewProperty.EDGE_CURVED, Boolean.TRUE);
previewModel.getProperties().putValue(PreviewProperty.EDGE_OPACITY, 50);
previewModel.getProperties().putValue(PreviewProperty.EDGE_RADIUS, 10f);
previewModel.getProperties().putValue(PreviewProperty.BACKGROUND_COLOR, Color.BLACK);
previewController.refreshPreview();
//New Processing target, get the PApplet
ProcessingTarget target = (ProcessingTarget) previewController.
getRenderTarget(RenderTarget.PROCESSING_TARGET);
PApplet applet = target.getApplet();
applet.init();
//Refresh the preview and reset the zoom
previewController.render(target);
RandomLayout layout = new RandomLayout(new Random(),1500);
layout.setGraphModel(graphModel);
layout.initAlgo();
layout.goAlgo();
layout.endAlgo();
//Add the applet to a JFrame and display--------------------------------------
JFrame frame = new JFrame("Test Preview");
frame.setLayout(new BorderLayout());
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.add(applet, BorderLayout.CENTER);
frame.pack();
frame.setVisible(true);
target.refresh();
target.resetZoom();
}
public static void main(String[] args) {
PreviewJFrame previewJFrame = new PreviewJFrame();
previewJFrame.script();
}
}
マウスリスナー:
import org.gephi.preview.api.PreviewMouseEvent;
import org.gephi.preview.api.PreviewProperties;
import org.gephi.preview.spi.MouseResponsiveRenderer;
import org.gephi.preview.spi.PreviewMouseListener;
import org.gephi.project.api.Workspace;
import org.openide.util.lookup.ServiceProvider;
@ServiceProvider(service = PreviewMouseListener.class)
public class AtosPreviewMouseListener implements PreviewMouseListener{
@Override
public void mouseClicked(PreviewMouseEvent event,
PreviewProperties properties, Workspace workspace) {
System.out.println("I'm clicked!!");
}
@Override
public void mousePressed(PreviewMouseEvent event,
PreviewProperties properties, Workspace workspace) {}
@Override
public void mouseDragged(PreviewMouseEvent event,
PreviewProperties properties, Workspace workspace) {}
@Override
public void mouseReleased(PreviewMouseEvent event,
PreviewProperties properties, Workspace workspace) {}
}
どうもありがとう!
PS: そのトピックに返信しようとしましたが、何日も前に登録したにも関わらず、私のアカウントはまだアクティブ化されていません...