brunomnsilva / JavaFXSmartGraph

Generic (Java FX) Graph Visualization Library

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

setStyleClass now cleares default classes

bahfheuv opened this issue · comments

From #10:

Umm, are you certain it doesn't clear the default classes now? (.vertex, .edge, .arrow)

Yeah I (Bertie2011, but now on a school account) finally got around to trying the new version (which you should probably increase the version number of instead of calling it 0.9 again) aaaaand it does seem to have the default classes missing after setting a custom class in the latest version. 🙃

So everything is as expected?

And yes, you're right about the version number. Just bumped it!

No... Setting a class clears the default vertex/edge class. Meaning I can't target a vertex with the .vertex CSS class anymore

Well, that's the expected behavior:

public interface SmartStylableNode {    
    
    /**
     * Applies cumulatively the <code>css</code> styles to the node.
     * 
     * Note that JavaFX styles are cumulative.
     * 
     * @param css styles
     */
    public void setStyle(String css);
    
    /**
     * Applies the CSS styling defined in class selector <code>cssClass</code>.
     * 
     * The <code>cssClass</code> string must not contain a preceding dot, e.g.,
     * "myClass" instead of ".myClass".
     * 
     * The CSS Class must be defined in <code>smartpgraph.css</code> file.
     * 
     * The expected behavior is to remove  all current styling before 
     * applying the class css.
     * 
     * @param cssClass name of the CSS class.
     */
    public void setStyleClass(String cssClass);
}

What do you propose? setStyle and addStyle maybe?

Ummm... Either keep track of the class name that's "native" and make sure you don't remove the "vertex" class in a vertex, same for edges. Or just expose all style class methods, so that users can add multiple classes and remove the right ones themselves.

The problem has nothing to do with setStyle(cssString), I'm talking about setStyleClass

The following behavior is now available on version 0.9.2 for vertices and edges:

public interface SmartStylableNode {    
    
    /**
     * Applies cumulatively the <code>css</code> inline styles to the node.
     * 
     * These inline JavaFX styles have higher priority and are not overwritten by
     * any css classes set by {@link SmartStylableNode#addStyleClass(java.lang.String) }.
     * But will be discarded if you use  {@link SmartStylableNode#setStyleClass(java.lang.String) }
     * 
     * If you need to clear any previously set inline styles, use 
     * <code>.setStyle(null)</code>
     * 
     * @param css styles
     */
    public void setStyle(String css);
    
    /**
     * Applies the CSS styling defined in class selector <code>cssClass</code>.
     * 
     * The <code>cssClass</code> string must not contain a preceding dot, e.g.,
     * "myClass" instead of ".myClass".
     * 
     * The CSS Class must be defined in <code>smartpgraph.css</code> file or
     * in the custom provided stylesheet.
     * 
     * The expected behavior is to remove all current styling before 
     * applying the class css.
     * 
     * @param cssClass name of the CSS class.
     */
    public void setStyleClass(String cssClass);
    
    /**
     * Applies cumulatively the CSS styling defined in class selector 
     * <code>cssClass</code>.
     * 
     * The CSS Class must be defined in <code>smartpgraph.css</code> file or
     * in the custom provided stylesheet.
     * 
     * The cumulative operation will overwrite any existing styling elements
     * previously defined for previous classes.
     * 
     * @param cssClass name of the CSS class.
     */
    public void addStyleClass(String cssClass);
    
    /**
     * Removes a previously <code>cssClass</code> existing CSS styling.
     * 
     * Given styles can be added sequentially, the removal of a css class
     * will be a removal that keeps the previous ordering of kept styles.
     * 
     * @param cssClass name of the CSS class.
     * 
     * @return true if successful; false if <code>cssClass</code> wasn't 
     * previously set.
     */
    public boolean removeStyleClass(String cssClass);
}

Ummm... Either keep track of the class name that's "native" and make sure you don't remove the "vertex" class in a vertex, same for edges. Or just expose all style class methods, so that users can add multiple classes and remove the right ones themselves.

The problem has nothing to do with setStyle(cssString), I'm talking about setStyleClass

For the intended usage, call addStyleClass and removeStyleClass. setStyleClass will reset all styling. Thanks for the improvement 😄

That's awesome!
(Again, I'm the same guy as bahfheuv, one is my school account)

The documentation is kinda odd though:

  • setStyleClass should probably clarify that the default classes (vertex and edge) and any applied styling is cleared. (A bit more obvious than saying "all styling is cleared")
  • add and remove StyleClass methods make it seem like the order of adding classes to the internal list matters, but it's the ordering inside the style sheet that matters (as far as I know). Classes defined later in the style sheets overwrite properties set in classes defined earlier, regardless of when those classes are added to the elements. Or in short: addStyleClass call order does not matter, it's the stylesheet order.

Nice to see the commit reference btw!