User-defined strings for cross-program copy / paste - java

I'm trying to build a program that supplements and replaces Windows shortcuts with those defined by the user. Currently, I'm working on building a copy/paste function, but can't figure out how to move the copied object into a program other than mine. I tried using the Robot class to simulate keypresses depending on the value at a specific index in a string, but that won't allow me to pass variables other than the VKEY constants.
What would be needed in a method to copy and paste text between programs?

If you would consider using JavaFX: There is a Clipboard class, which claims to get the system clipboard, but I haven't tried if it works accross (non-JavaFX) applications:
http://docs.oracle.com/javafx/2/api/javafx/scene/input/Clipboard.html
Edit:
There is also an AWT-based Clipboard: http://docs.oracle.com/javase/7/docs/api/java/awt/datatransfer/Clipboard.html

Related

CaptainCasa framework: DOF export not working

We have a DOF grid defined programmatically where the export doesn't work for some reason.
Clipboard export works fine, but CSV, XML and PDF show the right number of rows/columns but empty data inside.
I debugged far enough to get to
org.eclnt.jsfserver.util.ExpressionManagerV#getValueForExpressionString(javax.faces.context.FacesContext, java.lang.String)
For some reason it returns empty string for all values in the broken scenarios, and returns the proper values for the clipboard export.
The expressionString passed is the same both times. It seems that the dispatcher cannot be resolved properly in the broken scenarios.
The export functionality works find across the rest of the DOF grids in our project.
Very difficult to guess for the reason, based on the current information. All the exports are using method "List<List> exportToStringListWholeGrid()" (class FIXGRIDBinding, inner class Exporter), so this is both used by Clipboard export and by other exports as well. - Could you maybe debug inside this method once for the clipboard export and once for the csv export and then check if you recognize any difference?
Ok, so my issue was that i had an expression like this:
d.d_3.SomePageUI.dofGrid.puis['whatever'].value
this expression would resolve the value of column "whatever" in the grid.
We had extra logic in the getter of dofGrid (don't ask why...), this extra logic would only crash when using CSV, PDF or XML exports (my guess it because a new window is opened and context changes somehow ?!)
Now the bad thing is that i didn't get an error "exception happened in getter dofGrid"
I got an error "dofGrid is NULL" :/

Can I modify element values (colors) of a CSS file JavaFX programatically?

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!

How to invoke applications on BlackBerry

I'm new on this world of BlackBerry and the thing is that i have a byte array of certain file that can be anything (picture, pdf, txt ...) and need to be shown. How can i execute applications related with the specific extention? In other words how can i invoke an application and give it the byte array to be displayed as the original file?
I also have the extention or file type.
I have tried to open the file using browsers but it always return timeout and that's not the idea.
Here is something like my question but it has not a final response. I'm developing for BlackBerry Curve.
I have never used it, but I think the appropriate API for this is the Content Handler API, most commonly referred to as CHAPI I think. Look for documentation of javax.microedition.content. Here is a link that will take you to the ContentHandler class.
I suggest that you look for the chapidemo sample for more information. It should have come with your tooling, if not, here it is on github: chapidemo sample.

Update objects written to a text files in java

Writing Java objects or a List into a text file is ok. But I want to know how I can update or rewrite a object which was written previously without writing objects again. For example, let s assume there is a java.util.List has a set of Objects. and then that list is written to a text file. Then later that file will be read again and get all objects from list and then change one object's value at run time by a java application. Then I don't need to write entire list back to the text file. Instead only the updated object in the list is required to be rewritten or updated in the text file without rewriting the whole list again. Any suggestion, or helpful source with sample codes please.
Take a look at RandomAccessFile. This will let you seek to the place in the file you want, and only update the part that you want to update.
Also take a look at this question on stackoverflow.
Without some fairly complex logic, you won't usually be able to update an object without rewriting the entire file. For example, if one of the objects on your list contains a string "shortstring", and you need to update it with string "muchmuchlongerstring", there will be no space in the file for the longer string without rewriting all the following content in the file.
If you want to persist large object trees to a file and still have the ability to update them, your code will be less buggy and life will be simplified by using one of the many file-based DBs out there, like:
SQLite (see Java and SQLite)
Derby
H2 (disk-based tables)

editing a string using BufferedReader in Java [duplicate]

Say I allow the user to edit something, like the phone number in an Address Book (actually, that's exactly what I'm doing). Is there something that I can add to println that will allow me to insert a variable to display as fully editable text? The assignment that I'm doing this for doesn't actually call for this, but I think it would be cool to have. I'm looking on Google but can't find anything, then again I don't really know what I'm looking for and whether or not I have the correct terms in mind ...
No, not using only what Java provides in the framework. Editing some text would require to
act on key press, which is not possible as in Java the input is buffered (i.e., wait for Enter to be pressed)
to move around in the text you output, which is also not possible
This could be done using some native code (ncurse on linux, ...), using JNI or JNA, but not that easily.
Note that there are some projects that aim to add those functionalities, so if you can use something outside of the core libraries, you could give them a tries... for instance http://code.google.com/p/java-console-api/
There are various options for this, in order of simplicity and portability to features and complexity:
Simply prompt for the information, reading a complete (return-terminated) line of response, and allow the normal terminal input facilities to be used for basic editing.
Use something like the gnu readline library to allow more advanced editing. You still won't have widgets (text input boxes at specific places on screen) as such though. There's a java implementation here: http://java-readline.sourceforge.net/
Use something like ncurses to specifically position the cursor, print text labels, handle keypresses, and implement your own text input box. Not fun.
Use a textual user interface library (TUI), like this one: http://www.bmsi.com/tuipeer/
If you opened a window that looks like the console window, and could react to keypress events, then you could do what you are asking, but, otherwise, if you are just running a program, the program will have ceased executing and returned control to your console, so it can't do anything else.
But, if you use a scriptable version of java you could write your own shell, and then you could do what you are asking, as the shell would not cease executing.
But, that will probably be beyond your course.

Categories