I am trying to create a GUI tool to edit few property files, each property file contains large amount of lines. What's the best swing controls in Java should I use in order to load these property files.
Thanks,
You could present an editable JTable with two columns, one for property key, one for property value
http://zaval.org/products/jrc-editor/index.html
Take a look at this. It shows all keys in a tree like structure and let you edit them. Supports multiple locale dependent files and represent them accordingly.
Related
In my JavaFX project I am allowing users to set an accent color that will be used throughout the application. This accent color will be stored in a sqlite database.
Upon initialization, the database file will be read, and the accent color is applied. Currently this is done painfully by calling the .setStyle() method on every element that needs to be changed. This method is prone to mistakes and difficult to maintain. I am adding all elements that need the change applied to an array and looping through it, but it is easy to forget to add an element to the array every time I add a new button, etc. Not to mention different types of elements need different styles applied.
The only way I can think to accomplish this currently is to store the entire CSS element including accent color as a String, save the string to a .css file on the filesystem, and then load the external CSS. But this method is not graceful.
So I am aware of the following two ways to accomplish what I want, but both are not ideal.
Call .setStyle() on every element, adding all elements to an array and looping
Store my CSS in a String, save to the file system, load CSS, delete file from file system
Ideas like less, sass, and scss won't work because they require knowing what the color will be at build time, which I won't know. Having separate stylesheets prepared ahead of time won't work because there are millions of colors the user might choose.
An ideal answer would be some way to modify the add() method to accept css rules as a string (similar to how you pass them to .setStyle() method) instead of just a file path like this (example, does not work):
primaryStage.getScene().getStylesheets().add("-fx-background-color:" + getAccentColor() + ";");
Any ideas? Surely someone out there has provided user configurable accent colors before.
Thank you!
Storing all nodes in an array and looping over them is ridiculous. In the linked question the accepted answer leverages the styleProperty in the style of reactive programming.
Another solution is to use CSS classes and swap out the stylesheets, as you have mentioned. This would be more of a generative approach. You can download the DB data of the styling on app setup, set the style, which just defines colours for specific CSS classes and reload it if the user changes it at runtime.
As you would rewrite the file on startup anyway, you can use Files.createTempFile(). Or you change it only when the user decides to change, that way you can keep the file.
This is the answer that I found that works perfectly without implementing new classes or overwriting URL handlers or anything crazy like that.
How to override JavaFX css by code for complex objects
Thanks to #James_D!
I am using iReport version 5.6.
Right now we're analyzing the requirement for a new project where the requirement is as follows.
We have a report which is designed in jrxml with almost 20 fields where user has to scroll to the right to get all values and hence tedious for the user when result size is too large.
Suggested requirement is as to configure the jrxml in such a way that user can select the column name for which the report should be generated.
Related image
We have done study on this and found the only possible solution may be to create a jrxml for each possible combination which seems to be not efficient for our project.
Could you please suggest is there any possible way to handle this situation?
Instead of using a seperate .jrxml file for each "view" you could duplicate the bands and use printWhen expressions to determine which band to display. Not a lot better than having separate .jrxml files but at least all the logic will be in the same file.
Another idea is to use parameters like showColA,showColB etc. Use those parameters to determine the column headers and values of those columns (this could get a little messy though)
In shell script, I can use a loop to set new variables from a text file which contains variables and values. My text file looks like:
path1=/tmp/data
path2=/tmp/data2
myname=ABC
In java, is there any way to do like that?
Yes, it is possible and it is quite a common practice. Many server-based applications are designed in a way that they can fetch such variables from a file rather than a database.
These two links are all you'll need to get started:
https://docs.oracle.com/javase/7/docs/api/java/util/Properties.html
https://docs.oracle.com/javase/tutorial/essential/environment/properties.html
I am new to Natural Language Processing and GATE.Currently I'm learning to use GATE / ANNIE . ANNIE's default gazetteer lists are great, but obviously they don't provide lists for everything.
I need to create a list of characters in a story book.
Creating lists and adding entries to each and every list from GATE Gazetteer Editor (as mentioned in Gate manual 13.2.2) or using a text editor does not seem to be practicable .So anyone knows a method to create our own gazetteer lists other than,creating/editing directly through GATE or using a text editor?
As said in the GATE manual you can edit any of the existing lists in a text editor. Probably the most straight-forward way is to create these lists programatically. I.e. if you have them in a database, dump records in the gazetteer format (basically one word per line). If you have them in a csv or a web page, export them to the right format.
Another option is to use a more advanced gazetteer which uses an ontology or semantic repository. See the manual link above for different gazetteers and how to work with them.
I created a list using the contents of a column from a database table as suggested above. Simply saved it as a .lst file using Notepad++ in the same directory as all the other .lst files (I'm using the ANNIE gazetteer) and then added it using the gazetteer editor.
One problem that I ran into was not having it saved in the correct encoding (UTF-8). GATE didn't like it and it showed in the messages when loading. Once I figured that out and corrected it, it worked fine.
If you need to create a list of entities from text maybe you could look into the gazetteer list collector - http://gate.ac.uk/sale/tao/splitch13.html - 13.7
I'm working on this swing project and thought it would be a good idea to save user selections to a text file so whenever program is closed and opened again old selections still persist there. Mainly want to store things like checked checkboxes, radio buttons and some integer variables. Is this possible to do in just plain .txt file or will I have to use something like xml?
This should be done with intention to then grab info from txt file and use to set latest user selections in JFrame.
For this scenario, use the Java™ Preferences API, the page says it:
Applications require preference and configuration data to adapt to the
needs of different users and environments. The java.util.prefs package
provides a way for applications to store and retrieve user and system
preference and configuration data. The data is stored persistently in
an implementation-dependent backing store. There are two separate
trees of preference nodes, one for user preferences and one for system
preferences.
You could use Properties for this, although, creating an object to hold the information and store it in XML using JAXB is also nice and a little more flexible (in my opinion) since the XML structure allows for more of a tree-like structure, allowing for saving more complex information, and for keeping related stuff together. There's no automatic way to do this, and so you the programmer will have to write code for this. If your program is set up as an MVC, Model-View-Control, type program, you'll simply save the model, perhaps via JAXB as I've mentioned.
This is the exact use of property files.
Its just a matter of setting properties and saving to a property file and getting these properties at load time. Define the items you need saving in key value pairs when saving. You can retrieve from the key when reading.
For example for a radio button have the property write as ;
prop.setProperty("radioselected", "true"); //true or false based on the selection
When reading,
boolean radioSelected = Boolean.parseBoolean(prop.getProperty("radioselected"))
If this value is true, set the radio button checked state true when loading the UI. If not keep it unchecked.
Refer http://www.mkyong.com/java/java-properties-file-examples/ for more details.
You can use regular text files. It's only a matter of encoding the data from your program into text and decoding the text into the form when loading.
As the other answers suggest, you can also use properties to not reinvent the wheel.
Use properties file. To save it when window is closing use code like following:
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
saveProperties();
}
});