Java get tooltip info - java

Is it possible in java to get text from a tooltip in a gui that I didnt make. For example, I may be in a web browser or on a desktop application with my java program running in the background. I want to get any tooltip info that pops up (at anytime) and return it to the java program.
Just to clarify i'm not asking about how to create tooltips or get tooltip data in gui I make only tooltips that appear in other 3rd party software. Thanks.

The Tooltip Text has to be "somewhere" in the software. "Somewhere" can be a handful of different places, depending on how the software is built and distributed:
String literals in the sourcecode (and thus in the bytecode, too), this often happens to non-internationalized programs
resource bundles, i.e. the Strings are externalized from the source code into a separate file (usually one per supported UI-language)
If the software is distributed as *.jar-File, use your favorite unzip-software to decompress is (when in doubt, use 7zip).
Look around for *.properties-files, these may contain the resource bundles (= collection of UI-text-Strings) you are looking for.
If you can't find resource bundles, the Tooltip Text is probably hidden in String literals directly in the bytecode. Use something like strings(1) on *nix-ish platforms (no link for this one, seems I can only post 2 links) or Strings on Windows to extract the printable Strings from the *.class-files.
Note that you might find lots of printable Strings in there, so you might want to filter them using a suitable regular expression.

Related

Atom Processing having problems with folders with spaces

I have recently starting using the Java based language Processing.
I started off with using the standard processing editor that has been installed on my Windows machine, but didn't quite take to it. It's not very customizable and lacks things like highlighting variable and function names throughout the code.
So I decided to use Atom instead, and so far it's been great. Although with one problem:
I can't build sketches that have spaces in their directories.
If I want to build a sketch that has the path...
C:\Users\Sulu\Documents\Processing\Test Sketches\Test\test.pde
I get the message:
DPI detection failed, fallback to 96 dpi
C:\Users\Sulu\Documents\Processing\Test does not exist.
[Finished in 1.008s]
I'm sure this is down to the fact that there is a space in the path.
My question is this. Is there anyway that I can get Atom, or maybe it is the 'processing-java.exe' I need to modify, to ignore space names in the path?
To automatically add doublequotes?
I'd be really grateful to any help with this as I have a lot of sketches that have spaces in their path names and renaming them all would be tedious.
Thanks.
It is a part of Processing language, it is a rule, just like syntax which you have to follow and can't be modified, at least as far as I know.
This is what the official github wiki says -
Names of sketches cannot start with a number, or have spaces inside. This is mostly because of a restriction on the naming of Java classes. I suppose if lots of people find this upsetting, we could add some extra code to unhinge the resulting class name from the sketch name, but it adds complexity, and complexity == bugs. :)
So, I am afraid there is no solution to your problem other than renaming your sketches, at least not yet!
EDIT :
Seems like I misinterpreted the question a little bit, I would suppose your sketch works with processing editor but not in external editors because they use cli to compile your project, and the instructions do contain the file path, which can not have spaces when present in bash, if they do, they need to be enclosed within quotes or spaces need to be "escaped" with \, which is again, controlled by processing and I don't think you can somehow modify "processing" to add quotes to paths during "building" or escape spaces \ so the answer still remains the same.

Predefined JDialogs in Swing

I'm working on a library that will translate all the hard-coded strings in swing.
I have, with some help, managed to find all the strings related to it, so that's a start. However, I have noticed that upon trying to rename a file in JFileChooser to a name that was already taken, I get an error dialog saying that I can't do that.
Was this Java, or was it Windows (OS on which the program was ran)?
If it was Java, I'd like to know more about how to customize such a JDialog, and if it was Windows, there's not much I can do, especially since the program is supposed to be cross-platform.
You can find the source code of your JDK in the directory you installed it in.
In the openJDK-7 implementation the String you are looking for is defined in the
package com.sun.swing.internal.plaf.basic.resources and the file basic.java.
The other files in this directory correspond to the different translations:
basic_de.java, basic_es.java, ..., etc.
There are all the String constants that are used by the Swing classes.
Amongst them:
{ "FileChooser.renameErrorFileExists.textAndMnemonic",
"Cannot rename {0}: A file with the name you specified already exists. Specify a different file name." },
So you will have to find a way to override the Attribute FileChooser.renameErrorFileExists.textAndMnemonic to change this dialog.
If you want to translate these strings refer to this answer.
Different Java installations might have different Strings there since these Files are not part of the official Java API.
As far as I can tell these files are not contained in the src.zip that is distributed by Oracle.

How to execute console or GUI input as if it was actual Java code?

I want to be able to input java commands/code to execute during run-time (during the execution of a "persistent" program) in the same way, or as close as possible, to the same code would be executed if it was present on the source-code for the program (programmed as part of the software), using a GUI element, like jTextArea.
The following StackOverflow questions seem to be related, but, along with they'r answers, don't seem to be what i'm looking for.
How To Get Input From Console Class In Java?
Using GUI for console input and outputin java
I don't want to "be able to trigger actions from specific console inputs, and print the feedback into the console", as seems to be the case of console applications described in those question and answers.
What i want is to "be able to execute actual java code, that i cannot predict nor control, from console (or GUI) input".
NOTE: The "i cannot predict nor control" here refers to the "developer"...But of course i can predict and "control" it if i'm the one inputting the code, as the "user" would do.
Since java uses a virtual-machine environment, i think it might be possible for it to execute "run-time inputted code"...But i'm not sure such thing is even possible.
For example, i'd like the run-time input of for(int i=0; i<3; i++){System.out.println(i);} in the "GUI console" (jTextArea, for example) to, upon pressing the enter key or clicking a "Send" button, be ("compiled and "?) executed, and give the same output as if it was part of the original source-code, thus:
0
1
2
So i'd like to know the following:
Is it possible?
If yes, how can i do it? (OR, if no, what is the closest alternative?)
Use the JavaCompiler. It can compile code from a String.
For an E.G. see the STBC & especially the source code. It provides a GUI and can compile the code in the text area on button click.
But note the:
System Requirements
STBC will run on any computer with a version 1.6+ Java Plug-In* JDK (AKA SDK).
(*) The API that STBC uses is merely a public interface to the compiler in the tools.jar that is distributed only with JDKs (though the 'public JRE' of the JDK also seems to acquire a tools.jar). This leads to some unusual requirements in running either the native jar, or the web start app.
You can use JavaCompiler, as this question's answer states:
https://stackoverflow.com/a/935316/420001
Also, what you're wanting to do is evaluate a String of code:
It's not really recommended though.
There is a project called BeanShell
"In short, BeanShell is dynamically interpreted Java, plus a scripting language and flexible environment all rolled into one clean package. "
I know this is an old answer but for future Googlers:
I would recommend JavaREPL whose source is available here:
https://github.com/albertlatacz/java-repl
What AlmightyR is asking for is called Read-Eval-Print-Loop (REPL) for the Java language which is what JavaREPL provides.
JavaREPL has an online demo available here: http://www.javarepl.com/console.html
JavaREPL also has an Intellij plugin and a CLI version which are both linked to in the Github repository.
It looks sort of abandoned currently but perhaps it just doesn't need to be maintained?

Spy++ for Java Swing applications

Is there an equivalent for Spy++ for java swing applications?
I work with a third party application that contains a huge number of screens that get invoked via a reflection based mechanism.
Whenever an issue occurs the only way to locate the problem code is to search through the source (we have access to the source but cannot fix and deploy due to contractual obligations) for a specific string sequence that occurs on the window in question. eg if I see the string "XYZ" on the buggy window I have to search against the source for that string to locate the java file in which the bug exists.
Is there a tool that will let me, at runtime, point to a Swing screen and return the class from which the screen is generated?
Have you tried using Swing Explorer? It is more or less meant for similar tasks. I'm unaware of whether it will display the actual class that contains the component, but it certainly is capable of displaying the component hierarchy. You might want to check the ability to obtain the addition trace which contains the stack trace of the events leading to the component's addition to the tree.

Making a Windows Taskbar Jump-List in Java

I know the following things, and was wondering if they can be combined to make Java use jump-lists in Windows:
Windows displays Jump-Lists for supporting programs when a taskbar icon is right-clicked
C++, C#, F#, and VB support this natively (as shown here)
Java can import native capabilities using the JNA (as shown here)
Anybody have experience they can lend to help me create a jump-list for a Java app?
The J7Goodies library won't work, as it no longer exists.
The word "natively" is overstating the case a bit. WPF provides jump list support. That's not the same as C# providing it. (For Windows Forms people there's the Code Pack which is a set of managed wrappers.) And MFC provides jump list support which is also not the same as C++ providing it. Anyway, there are two things going on here. One is adding files you opened recently to that jumplist, which under some circumstances you can get for free. The other is adding arbitrary files (typically starting point templates etc) to the jumplist.
To add a file to the recent/frequent list, you call SHAddToRecentDocs, though you may not have to if, for example, you use the Common File Dialog control to open files, and/or the user double-clicks files to launch your app and open them (you have the file type registered.) Lots of folks suggest calling it anyway to be on the safe side. To add any old thing to the jumplist see http://msdn.microsoft.com/en-us/library/dd378402(v=VS.85).aspx.
How to call those from Java, I forget, but I hope they get you started.
There is a Java library providing the new Windows 7 features for Java. It's called J7Goodies by Strix Code. You can create your own jump lists with it.

Categories