このコードを使用して、jgraphx でクリックされた頂点に接続されているいくつかの頂点の不透明度を変更しようとしています。頂点の外側のどこかをクリックすると、不透明度が再変更されます。頂点をクリックすると、その値/文字列が照会され、それに接続されているすべてのオブジェクトが新しいオブジェクト リストに追加されます。次に、このオブジェクト リストを処理して、ハイライトするものとハイライトしないものを選択します。ただし、エラーが発生し続け、修正できません。私が確認した限り、null オブジェクトはありません。誰かが助けてくれれば、本当にありがたいです。
エラーは次の行を参照しています。
graph.getView().getState(myCell).getStyle().put(mxConstants.STYLE_OPACITY, OPACITY_HL);
コードは次のとおりです。
public void MassCellHighlight() {
int OPACITY_PALE = 15;
int OPACITY_HL = 100;
graphComponent.getGraphControl().addMouseListener(new MouseAdapter() {
public void mouseReleased (MouseEvent e1) {
if (e1.getButton() == 1 && e1.getClickCount() == 1) {
long x = e1.getX();
long y = e1.getY();
Object cell = graphComponent.getCellAt((int) x, (int)y);
String usecell = graph.convertValueToString(cell);
PropertyConfigurator.configure("\\jena-log4j.properties");
OntModel model = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
FileManager.get().readModel( model, "file" );
String queryString =
"PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> " +
"PREFIX owl: <http://www.w3.org/2002/07/owl#> " +
"PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> " +
"PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> " +
"PREFIX bi: <#> " +
" SELECT ?Path " +
" WHERE { bi:"+usecell+" bi:can_lead_to ?Path } " ;
Query query = QueryFactory.create(queryString);
QueryExecution qe= QueryExecutionFactory.create(query, model);
ResultSet resultset = qe.execSelect();
ResultSet results = ResultSetFactory.copyResults(resultset);
List<Object> values = new ArrayList<Object>();
while ( results.hasNext() ) {
values.add( results.next().get( "Path" ));
}
String s = values.toString();
Pattern p = Pattern.compile("(?<=#)([^,]*)(?=(,|\\]))");
Matcher m = p.matcher(s);
List<String> listhl = new ArrayList<String>() ;
while (m.find()) {
listhl.add(m.group(1));
}
listhl.add(usecell);
List<Object> objectlist = new ArrayList<Object>(listhl);
System.out.println(objectlist);
Object[] allCells = mxGraphModel.getChildren(graph.getModel(), graph.getDefaultParent());
if (cell != null) {
if (graph.getModel().isVertex(cell)) {
for( Object myCell : objectlist) {
graph.getView().getState(myCell).getStyle().put(mxConstants.STYLE_OPACITY, OPACITY_HL);
graph.getView().getState(myCell).getStyle().put(mxConstants.STYLE_TEXT_OPACITY, OPACITY_HL);
}
for ( Object myCell: allCells) {
graph.getView().getState(myCell).getStyle().put(mxConstants.STYLE_OPACITY, OPACITY_PALE);
graph.getView().getState(myCell).getStyle().put(mxConstants.STYLE_TEXT_OPACITY, OPACITY_PALE);
}
}else {
for( Object myCell: allCells) {
graph.getView().getState(myCell).getStyle().put(mxConstants.STYLE_OPACITY, OPACITY_HL);
graph.getView().getState(myCell).getStyle().put(mxConstants.STYLE_TEXT_OPACITY, OPACITY_HL);
}
}
mxRectangle bounds = graph.getBoundsForCells(allCells, true, true, true);
graph.repaint( bounds);
}
}
}
});
}
エラー:
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at GUIquery$14.mouseReleased(GUIquery.java:1087)
at java.awt.AWTEventMulticaster.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$200(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
親頂点の子のみを強調表示するこのコードを使用すると、正しく機能します。クエリから発生するオブジェクト リストに応じて、より多くのセルが強調表示されるように展開する必要があります。
public void CellHighlight() {
graphComponent.getGraphControl().addMouseListener(new MouseAdapter() {
public void mouseReleased (MouseEvent e1) {
if (e1.getButton() == 1 && e1.getClickCount() == 2) {
final Object selectedCell = graphComponent.getCellAt(e1.getX(), e1.getY());
Object[] allCells = mxGraphModel.getChildren(graph.getModel(), graph.getDefaultParent());
if (selectedCell != null) {
if (graph.getModel().isVertex( selectedCell)) {
for( Object myCell: allCells) {
graph.getView().getState(myCell).getStyle().put(mxConstants.STYLE_OPACITY, OPACITY_PALE);
graph.getView().getState(myCell).getStyle().put(mxConstants.STYLE_TEXT_OPACITY, OPACITY_PALE);
}
List<Object> cellList = new ArrayList<Object>();
cellList.add(selectedCell);
Object[] outgoingEdges = mxGraphModel.getOutgoingEdges( graph.getModel(), selectedCell);
for( Object edge: outgoingEdges) {
cellList.add( graph.getModel().getTerminal( edge, false));
}
cellList.addAll( Arrays.asList(outgoingEdges));
for( Object myCell: cellList) {
graph.getView().getState(myCell).getStyle().put(mxConstants.STYLE_OPACITY, OPACITY_HL);
graph.getView().getState(myCell).getStyle().put(mxConstants.STYLE_TEXT_OPACITY, OPACITY_HL);
}
} else {
for( Object myCell: allCells) {
graph.getView().getState(myCell).getStyle().put(mxConstants.STYLE_OPACITY, OPACITY_HL);
graph.getView().getState(myCell).getStyle().put(mxConstants.STYLE_TEXT_OPACITY, OPACITY_HL);
}
}
mxRectangle bounds = graph.getBoundsForCells(allCells, true, true, true);
graph.repaint( bounds);
}
}
}
});
}