Sikuli issue - capturing an area - java

What I am trying to accomplish is to select an area on the screen with the mouse (outside of the may frame) and get the resulting region coordinates using Sikuli.
The code that should do this looks is below:
Screen screen = Screen.getPrimaryScreen();
Region region = screen.selectRegion("Select the area.");
What happens is that the cursor turns into a selector cross (the ones you usually see when you expect this function), but I can't select the area and actually the only way I can get back from the application is by killing it. Not too many examples I have found so I am asking for help here.
How can I make this work?
Also one other question:
I have downloaded the following script version:
Sikuli-IDE-1.0.0-Win64.zip
This means if I want to create a crossplatform solution I have to include like 6 jars? I have found a more universal Java API it seems (that is what it is called actually):
https://code.google.com/p/sikuli-api/
With all required supported OS but I can't find a single example on what I am trying to do that is similar to the little code snippet I pasted here. The sikuli script I am using now and this Sikuli API (apparently not the same) seems to be just different enough to amke this difficult.
Any suggestions? Thanks a lot in advance.

As it turns out, this only happens if I put this functionality on a Swing button's actionhandler. I have reported the bug to Sikuli and it will be probably fixed in the next release.

Related

Link two diffenrent windows with JNA

My issue is that I need to use Java code and Python code, each generating a window, Java still being the main process.
What I need is to link those two windows together. When I resize one, it resize the other, and same behavior when moving one, minimizing,...
I tried looking at the documentation or other solution on the Internet but I found nothing near my issue.
Will I need to implement a whole solution for it (listeners on both window to get size and resize the other, or position,...) or is there something I have been missing ?

Remove Unexpected border of JTabbedPane

I am trying to add tabs in a JTabbedPane. It is displaying the below mentioned white borderline which I am not expecting here as Every color is already set to Black except the white color for the text colors. What I might be missing.
I am trying to change this class from jitsi project
Here is what I've tried so far.
OS: Ubuntu 19.10: Java Version: 1.8.0_242
Windows 10 Pro: Java Version: 1.8.0_241
I am using default look and feel for this Frame whereas, for my manually created design, it is Nimbus.
The answer for the question heavily depends on the Look and Feel you're using for your application. I can't tell which one you're using by just looking at the screenshot because you modified it a lot and you've left out part of the code in your question that installs it. In case you aren't installing any specific one - you're running the default Look and Feel, which might also be different depending on the OS/JDK versions, if I'm not wrong.
So as #sleepToken already said in the comment - do not post random parts of your code or all of the code, instead post an SSCCE. While sometimes you might think it is unnecessary and/or unrelated - in many cases it is not, and it does help whoever will read and try to answer your question to run the code & debug the issue if necessary.
That being said - I can give a general answer to your question: All component are painted by their respective UI implementation (TabbedPaneUI in this particular case) and in some cases parts of the painting code might not be configurable, for instance some colors or other options might be hard-coded. You can simply look into the source code of the particular UI implementation that your application uses, find the painting code that you want to configure and see if it is actually configurable in the first place.
In case your application uses MetalLookAndFeel - the implementation is MetalTabbedPaneUI. From what I can tell by looking at it's code - it uses colors from TabbedPane.highlight, TabbedPane.borderHightlightColor and TabbedPane.darkShadow UI defaults for the border. Adding custom color for TabbedPane.highlight might fix the issue for you since you didn't mention that you modified that one in your question.
In case it doesn't - I once again recommend posting an SSCCE along with your OS type/version in case you're using a native Look and Feel. Native Look and Feel differs between different JDK versions for different OS version and often uses a highly customized UI implementation that might not be as configurable.

UI components of java programs appearing as blank boxes

As I run Java programs (like DbVisualizer and OpenProj) on my computer, some UI components like buttons, images, check boxes, scrollbars, etc. show as blank boxes. Not rarely some of these components first appear normally when you open the program and then go blank as you mouse over them.
I have already updated JRE and video drivers and also tweaked JAVA_OPTS with -Dsun.java2d.noddraw=true;-Dsun.java2d.d3d=false;, as recommended in Java forums, but none of these proposed solutions have worked so far.
I don't believe this is an OS specific issue, since I checked some other PCs with the exact same configuration of OS (Windows Vista) and hardware and many of them don't present that problem.
A screenshot of this situation can be seen here:
Any ideas?
Those JAVA_OPTS must be separated by spaces and not semi-colons!
Connect to the application with jVisualVM and verify that the "JVM Arguments" section contains all your desired options.
While using windows basic theme I would often find numerous graphical glitches. Moving a window would create a trail behind itself over background windows and UI controls at times would not appear until moused over.
As already suggested, try using the windows aero theme and just turn off transparency if you don't like the aero look.
This does seem more like a graphics driver issue. Note how things that are missing are images (icons, checkboxes) which are drawn by transferring the bitmap data directly to the graphic card. The sun.java2d.noddraw=false and sun.java2d.d3d=false are more of a hacks in this case, really.
What I would do is:
check if I am using the latest version of Java (wouldn't hurt to switch to a 64-bit java if you are using a 64-bit system)
check your graphics drivers, make sure they are the latest version
check Windows service packs
Also try using changing the Look and feel; maybe this will help.
I suspect that disabling DirectDraw will fix this and your attempt to disable it was unsuccessful.
As noted by Ryan, the options appear to be formatted incorrectly. Remove the semicolons and put a space between, or better still, only use sun.java2d.d3d=false. The sun.java2d.noddraw flag was obsoleted Java SE6u10 and setting to true now has the same effect as setting sun.java2d.d3d=false. There is no need to set both.
The effect of the incorrect formatting can be seen in the code below:
public class WrongArgs {
public static void main(String[] args) {
System.out.println("sun.java2d.noddraw: " + System.getProperty("sun.java2d.noddraw"));
System.out.println("sun.java2d.d3d: " + System.getProperty("sun.java2d.d3d"));
}
}
Running this code with args: "-Dsun.java2d.noddraw=true;-Dsun.java2d.d3d=false;" produces:
sun.java2d.noddraw: true;-Dsun.java2d.d3d=false;
sun.java2d.d3d: null
Running with args "-Dsun.java2d.noddraw=true -Dsun.java2d.d3d=false"
sun.java2d.noddraw: true
sun.java2d.d3d: false

Problem with FOP Image scaling in Java

Okay, so here's my problem:
We use FOP for creating "pretty" report output. We use the pdf option if the user wants a file, AWT for previewing, and the -print option for printing them. We are using FOP 0.25.x, which I fully recognize is not the newest version, but upgrading to 0.95 appears to be a non-trivial task that I don't necessarily want to undertake.
Anyway, it was noticed by one of our users that when printing ID cards (generated via FOP -print option) to the id card printer, the images on the cards (pictures of the employees) had some corruption in them...sort of like like green and reds dots and lines. We also discovered that if we sent the exact same print request to one of our HP color laserjets, it printed fine. To add to the strangeness, if we use FOP to create a PDF of the ID card and then print it via acrobat reader on the card printer, it prints fine.
I eventually discovered that it had something to do with the scaling of the images...we were scaling 600px high images down to something like 120px. If I presized the images down, even just halfing them, the corruption went down noticeably. Similarly, when I upsized the images, the corruption went up.
So my question: anybody have ANY idea what is going on here? Or has ever run into such a thing?
Since I don't know why this is happening, I don't know how to fix the root cause, but I've been working through some various workarounds:
1) Use FOP to create a pdf of the image and then print that via Java. This seems like an obvious answer, but some Googling around showed that printing a PDF via Java is not trivial. I've seen the PDF Renderer project on java.net, but seems pretty bulky for a single very specific application.
2) Try to resize the images before giving it to FOP. This also seemed pretty straightforward, however our various users can setup stylesheets for these id cards however they want and using "pt" and "in" sizing in them seems to be pretty common...I don't know of any good way to map that to a pixel resizing.
If anybody has any insight into the root cause, ways to make these work arounds work, and/or another idea, you'd be in my debt.
Most certain explanation:
image corruption? it's a bug.
Why not use 0.95? Sooner or later you have to upgrade, Apache consortium won't
fix bugs in 0.25.x versions.
You can't hope to find workarounds for every bugs which might occur in future.
I ended up doing the second thing I mention in the original question...i.e. resizing it before giving it to FOP. I found that I could retrieve the dpi of the printer I was printing to and do some math on it to get pixel sizing. Seems to work perfectly in all my testing...not a real solution but an adequate workaround.

fonts on org.eclipse.swt.widgets.Composite are messed up on Linux

I extend org.eclipse.swt.widgets.Composite and create many widgets on it, (labels, table, text etc). The problem I am facing is that the labels' text is getting truncated on linux while it appears fine on windows. When I change the linux's font to gothic the truncation is little less but still there. Is there way to homogenize the windows and linux display. What could be the best font to use in linux in such a case.
More likely it is related to this eclipse bug which I just lobbied to have re-opened: https://bugs.eclipse.org/bugs/show_bug.cgi?id=151322
It sounds like you are using absolute positioning instead of dynamic layouts. (If this isn't the case, perhaps you could post code demonstrating the problem). Using a dynamic layout should ensure that controls are resized to accommodate their contents. (They're also great if you ever translate a product, because then you don't have to rejig every dialog for every language.)
To complete McDowel's answer, there is also a bug related to the way Linux check for wrapping label:
It is fixed since 3.4M7.
Even though it may not be related to your case, it would be useful to know which version of eclipse you are using and if you can reproduce your bug with the latest ones (like a 3.5M6)

Categories