If you work with javax.print and want to know which parameters are sent to the printing device use following VM parameter to enable some debug information on standard out:
-Dsun.print.ippdebug=true
Friday, January 9, 2015
Saturday, January 3, 2015
Quick Dependency resolving with Grape
Most of the time i use Groovy with the GroovyShell or as a Groovy-Shell Script (remember my Blog-Post in October). Doing it that way you can achieve a lot with some lines of Groovy Script and the Groovy Standard Library Classes. But what if you need some classes from some third party libraries?
If you run your Groovy Script inside the GroovyShell you can simply modify the file groovy-starter.conf (resides in the conf folder of your GroovyShell installation). Add the classpath to the required library and you are done.
But this can get quite difficult if the library has further dependencies and you did not have these ones. Or you have these dependencies but only as maven dependencies, living in a gigantic maven repo on your local harddrive.
To get around this issue Groovy provides a Maven like mechanism called Grape. Grape does all the dependency resolving for you by doing lookups in well known Maven Repositories. So for example, if you like to have the FTPClient class from org.apache.commons.net in your Groovy Script, add the following Grape Statement:
@Grapes(
@Grab(group='commons-net', module='commons-net', version='3.2')
)
Then add the import statement for the FTPClient class and you are done! The full script with its overwhelming functionality ;-):
@Grapes(
@Grab(group='commons-net', module='commons-net', version='3.2')
)
import org.apache.commons.net.ftp.*;
FTPClient ftpClient = new FTPClient();
If the required dependency does not exist in the repositories known by Grape you can tell Grape where to go to find it. Simply add this statement:
@GrabResolver(name='myrepo', root='http://mymavenrepo.org/')
Grape is "supported" by mvnrepository.com. If you look for a dependency mvnrepository.com tells you the grape-code for instant usage!
If you run your Groovy Script inside the GroovyShell you can simply modify the file groovy-starter.conf (resides in the conf folder of your GroovyShell installation). Add the classpath to the required library and you are done.
But this can get quite difficult if the library has further dependencies and you did not have these ones. Or you have these dependencies but only as maven dependencies, living in a gigantic maven repo on your local harddrive.
To get around this issue Groovy provides a Maven like mechanism called Grape. Grape does all the dependency resolving for you by doing lookups in well known Maven Repositories. So for example, if you like to have the FTPClient class from org.apache.commons.net in your Groovy Script, add the following Grape Statement:
@Grapes(
@Grab(group='commons-net', module='commons-net', version='3.2')
)
Then add the import statement for the FTPClient class and you are done! The full script with its overwhelming functionality ;-):
@Grapes(
@Grab(group='commons-net', module='commons-net', version='3.2')
)
import org.apache.commons.net.ftp.*;
FTPClient ftpClient = new FTPClient();
If the required dependency does not exist in the repositories known by Grape you can tell Grape where to go to find it. Simply add this statement:
@GrabResolver(name='myrepo', root='http://mymavenrepo.org/')
Grape is "supported" by mvnrepository.com. If you look for a dependency mvnrepository.com tells you the grape-code for instant usage!
Sunday, December 14, 2014
Collada Unmarshaller
Hey everybody! I just pushed my Collada Unmarshaller to github. It simply does unmarshalling with jaxb. Not more!
You find the sources here: https://github.com/laubfall/collada-loader
You find the sources here: https://github.com/laubfall/collada-loader
Wednesday, December 10, 2014
Stackoverflow in JavaFX ChangeListeners
JavaFXs ChangeListeners are an easy way to monitor changes on JavaFX Properties and do some work if a change happened. But as easy as that is you easily can run into a stackoverflow because you'd changed the monitored property inside the ChangeListener.
Imagine you like to sort a Collection every time it is modified. Do sorting inside the ChangeListener raises a Stackoverflow because the sort itself raises a change event. So, how can we prevent that? The answer is simple: remove the ChangeListener before the code that modifies the property and then add it again!
public void onChanged(javafx.collections.ListChangeListener.Change<? extends Pair<String, L>> change){
change.getList().removeListener(this);
Collections.sort(change.getList(), comparator());
change.getList().addListener(this);
}
In this example we monitor a list and sort it when its content changes.
Imagine you like to sort a Collection every time it is modified. Do sorting inside the ChangeListener raises a Stackoverflow because the sort itself raises a change event. So, how can we prevent that? The answer is simple: remove the ChangeListener before the code that modifies the property and then add it again!
public void onChanged(javafx.collections.ListChangeListener.Change<? extends Pair<String, L>> change){
change.getList().removeListener(this);
Collections.sort(change.getList(), comparator());
change.getList().addListener(this);
}
In this example we monitor a list and sort it when its content changes.
Saturday, November 15, 2014
JavaFX TabPane and Tab change
At the moment i am working with JavaFX building a little Application that has a lot of configurable parameters. For the reason of not getting lost on a dialog with thousand of different checkboxes, textfields and so on, the parameter controls should be grouped with the JavaFX control TabPane. A TabPane was quickly done but soon i realized that it is not so easy to prevent the user from changing the current tab if the parameters grouped in this tab have invalid values. Instead of switching to the selected tab i rather like to show a validation error message. So i did some reading on the JavaFX API but there is no way out of the box to achieve this behavior. You can do some work if the tab has changed but not before it is changed. If you have a similar issue with the TabPane maybe my solution will work for you :-)
class StateAwareChangeListener implements ChangeListener<Tab>
{
/**
* go to previous tab if validation fails and this flag is true.
*/
private boolean roleback;
/**
* If validation is ok change the tab.
*
* {@inheritDoc}
*
*/
@Override
public void changed(ObservableValue<? extends Tab> arg0, Tab arg1, Tab arg2)
{
if (roleback) {
roleback = false;
return;
}
boolean validateConfig = validateIfChangeIsPossible();
if (validateConfig == false) {
roleback = true;
tabPane.getSelectionModel().select(arg1);
}
}
}
This listener calls the method validateIfChangeIsPossible that you have to implement by yourself. If changing the tab is possible return true. If false the old tab is selected again. You can also parse the new tab as a parameter into validateIfChangeIsPossible, if you need the information.
Finally add this class as a ChangeListener to the selectedItemProperty of the TabPane:
tabPane.getSelectionModel().selectedItemProperty().addListener(new StateAwareChangeListener());
class StateAwareChangeListener implements ChangeListener<Tab>
{
/**
* go to previous tab if validation fails and this flag is true.
*/
private boolean roleback;
/**
* If validation is ok change the tab.
*
* {@inheritDoc}
*
*/
@Override
public void changed(ObservableValue<? extends Tab> arg0, Tab arg1, Tab arg2)
{
if (roleback) {
roleback = false;
return;
}
boolean validateConfig = validateIfChangeIsPossible();
if (validateConfig == false) {
roleback = true;
tabPane.getSelectionModel().select(arg1);
}
}
}
This listener calls the method validateIfChangeIsPossible that you have to implement by yourself. If changing the tab is possible return true. If false the old tab is selected again. You can also parse the new tab as a parameter into validateIfChangeIsPossible, if you need the information.
Finally add this class as a ChangeListener to the selectedItemProperty of the TabPane:
tabPane.getSelectionModel().selectedItemProperty().addListener(new StateAwareChangeListener());
Friday, October 31, 2014
Execute Groovy as a Shell-Script
A colleague of me told me today that it is possible to run Scala Scripts directly in a shell. Because i am more familiar with Groovy i started some research if it is possible to do this with Groovy as well. To do it short: Yes we can :-) Take a look: http://groovy.codehaus.org/Running
Tuesday, October 28, 2014
JavaFX SceneBuilder or how to add more Cols and Rows to a GridPane
Yeah, i know it sounds simple: add some additional columns and / or rows to a GridPane with the SceneBuilder. Minute over minute i looked at the Properties-View of the GridPane but no way to add columns or rows.
Solution: right click on the GridPane in the hierachy view and simply select what you want to do ;-)
Solution: right click on the GridPane in the hierachy view and simply select what you want to do ;-)
Subscribe to:
Posts (Atom)
