java - NullPointerException and MouseListener in a graph -


i trying use code change opacity of vertices connected vertex clicked in jgraphx, , when click somewhere outside vertices rechange opacity. when vertex clicked, value/string queried , objects connected added in new object list. process object list choose whats going highlighted , whats not. keep getting errors , cant fix it. dont have null object far have checked. if can help, appreciated.

the error refers line:

graph.getview().getstate(mycell).getstyle().put(mxconstants.style_opacity, opacity_hl); 

here code:

    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 " +                              " { 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);                             }                               ( 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);                     }                    }                 }             });         } 

the error:

exception in thread "awt-eventqueue-0" java.lang.nullpointerexception     @ guiquery$14.mousereleased(guiquery.java:1087)     @ java.awt.awteventmulticaster.mousereleased(unknown source)     @ java.awt.component.processmouseevent(unknown source)     @ javax.swing.jcomponent.processmouseevent(unknown source)     @ java.awt.component.processevent(unknown source)     @ java.awt.container.processevent(unknown source)     @ java.awt.component.dispatcheventimpl(unknown source)     @ java.awt.container.dispatcheventimpl(unknown source)     @ java.awt.component.dispatchevent(unknown source)     @ java.awt.lightweightdispatcher.retargetmouseevent(unknown source)     @ java.awt.lightweightdispatcher.processmouseevent(unknown source)     @ java.awt.lightweightdispatcher.dispatchevent(unknown source)     @ java.awt.container.dispatcheventimpl(unknown source)     @ java.awt.window.dispatcheventimpl(unknown source)     @ java.awt.component.dispatchevent(unknown source)     @ java.awt.eventqueue.dispatcheventimpl(unknown source)     @ java.awt.eventqueue.access$200(unknown source)     @ java.awt.eventqueue$3.run(unknown source)     @ java.awt.eventqueue$3.run(unknown source)     @ java.security.accesscontroller.doprivileged(native method)     @ java.security.protectiondomain$1.dointersectionprivilege(unknown source)     @ java.security.protectiondomain$1.dointersectionprivilege(unknown source)     @ java.awt.eventqueue$4.run(unknown source)     @ java.awt.eventqueue$4.run(unknown source)     @ java.security.accesscontroller.doprivileged(native method)     @ java.security.protectiondomain$1.dointersectionprivilege(unknown source)     @ java.awt.eventqueue.dispatchevent(unknown source)     @ java.awt.eventdispatchthread.pumponeeventforfilters(unknown source)     @ java.awt.eventdispatchthread.pumpeventsforfilter(unknown source)     @ java.awt.eventdispatchthread.pumpeventsforhierarchy(unknown source)     @ java.awt.eventdispatchthread.pumpevents(unknown source)     @ java.awt.eventdispatchthread.pumpevents(unknown source)     @ java.awt.eventdispatchthread.run(unknown source) 

when use code highlight children of parent vertex works properly. need expand more cells highlighted, depending on object list occurs query:

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);                 }             }            }             });          } 

i found solution. adding object , object list wasnt null, jgraphx doesnt recognise same objects. should have added vertices/cells objects immediately.


Comments

Popular posts from this blog

c++ - CryptStringToBinary API behavior -

c++ - Correct method for redrawing a layered window -

java.util.scanner - How to read and add only numbers to array from a text file -