JFrame in all spaces on Mac OS X - java

I am trying to make a window in a Java application (a JFrame) follow the user between all Spaces in Mac OS X 10.5 and above, and I cannot seem to find how to do it. I found how to do it Objective-C, but there has to be some way to do this in Java!
How to do it in Objective-C:
http://www.cocoabuilder.com/archive/cocoa/192813-floating-window-across-all-spaces.html

Since it's very platform specific, it sounds like you'll have to write some kind of JNI/JNA to do it. Fortunately, someone might have already done this for you - check out http://code.google.com/p/rococoa/
This thread has a little bit of info on the API to get the NSWindow.

Related

How to catch the standard video output in Java

I want to catch the system's standard output, that is all that we can see at the monitor, from 0,0 coordinates to x,y. I've tried to make 50 screen capture per second with the Robot.createScreenCapture(Rectangle rectangle)) method, but it use a lot of memory and CPU. Instead, If I could catch the standard output and reproduce it in a video player (for example) I think that it should use less memory and cpu. Can anyone point me in the direction?
Recording the screen is a very OS environment specific task. On Linux one would, for example, do screen capture by talking to the X server directly using XLib or similar library.
If you are lucky someone has created a library in Java which abstracts this work (Like the Robot class), but if you can't find such a library then you will have to do the implementation for each platform yourself.
Unfortunately you would probably have to do some work in another language than Java since there might not exist Java bindings for the OS specific calls that you would have to make.
A good starting point would be to look at an existing project. For Linux this could be RecordMyDesktop:
http://recordmydesktop.sourceforge.net/development.php
For Windows you could look at: http://taksi.sourceforge.net/
So to sum things up: Java might not be right "hammer" for the task in question.

Java IDE for working over Remote Desktop

I have recently found out that anything Swing(NetBeans, IDEA) is excruciatingly slow to paint the UI over Remote Desktop(RDP).
Can you guys give me any suggestion for something that will work properly over RDP?
Actually, contrary to everything I've seen - mostly the "Dsun.java2d.noddraw=true", which is mentioned in a number of places, it is actually setting it to false that fixed the drawing issues(for me at least). Go figure.
RDP is optimized for native Windows apps and, regrettably, newer versions of RCP (like Vista/Win7's default RDP) is even more hostile to non-native apps than older (XP/Server 2003) versions. Here's a good link:
http://devnet.jetbrains.net/thread/280673
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4204845
One workaround is to get a screaming fast CPU/graphics board, tons and tons of memory and a super high-speed network connection :)
Another is to:
Select "32-bit true color" in your Terminal Services settings
Select "Modem"
Reduce screen resolution (heck, use 1024x768 if possible)
Here are some additional tips:
http://www.codinghorror.com/blog/2006/04/remote-desktop-tips-and-tricks.html
Try setting "Dsun.java2d.noddraw=true"
http://ubuntuforums.org/archive/index.php/t-1129187.html
http://www.mindfiresolutions.com/Solving-DIRECT-DRAW-ddraw-problems-in-Java-Swing-730.php
I am launching a java swing application from Linux, and display it as a Windows frame thanks to MobaXterm.
If you haven't done it already, please have a look at the following documentation :
https://docs.oracle.com/javase/8/docs/technotes/guides/2d/flags.html
Using -Dsun.java2d.noddraw=true did not fixed my issue, but setting xrender to true did.
So here's the code I used on Linux :
export _JAVA_OPTIONS='-Dsun.java2d.xrender=true'
java -jar my_java_application.jar
Maybe it's not only Swing that paints slow over Remote Desktop. However, Eclipse is based on SWT, based on native widgets, so it is not Swing.
You should give JavaWIDE a try. It is an IDE designed for access to a JDK without it installed on a system, with a built-in storage system so you just need access to the internet. It's not exactly a program for accessing everything on the computer but it will do a good job with your programming. It may take a while however, as the compiling is done on a separate server.

Mac OS X native printing from a Java desktop application

I would like to implement Mac OS X native printing in my Java desktop application.
That is, this print dialog when the user chooses to print:
which then expands to a dialog such as this:
As I understand it, native Mac OS X applications can customise the 2nd dialog by adding an option in the lower drop-down ("TextEdit" in the screenshot) which when selected displays options specific to the application.
How is the best way to go about achieving this in my Java application? I presume I will need to write some Objective C to do what I need, then use JNA/JNI to call it? Are they are pre-existing libraries that can help me?
You are correct in think you need to go down the JNI route.
Apple has a tech note on developing JNI routines here: http://developer.apple.com/library/mac/#technotes/tn2147/_index.html

Swing tweaks for Mac OS X

I remember having once seen a list of properties that could be set on Swing components to make them look more native on Mac OS X.
This included ways to mark "dirty" documents with the "dot" in the window close button, open dialogs as sheets (not sure about that, but sure would be nice) etc.
I know Apple has let Java down as a "primary" programming language, but as they recently updated Java and even offer Java 6, I wonder if there is a comprehensive and current list - ideally with examples - on what you can do to make Swing apps look better without much effort on the Mac.
After receiving some answers, I put this into community wiki mode and started the following list to be expanded if need be:
Technical Notes: Java - User Experience: Overview page on Apple's developer connection reference library (index page).
New Control Styles available within J2SE 5.0 on Mac OS X 10.5: Examples for Button styles etc. specific to Mac OS X 10.5 Leopard.
Java Runtime System Properties: Information on System properties that help you enable the Apple-style menubar at the top of the screen, give rendering hints for text anti-aliasing etc.
Mac OS X Integration for Java: Information on Menubar and Application menu, context menus, keyboard shortcuts and AppleScript
PDF "Java 1.3.1 Development for Mac OS X (Legacy)": 80 pages of information on various topics such as packaging applications. This is somewhat outdated.
The Quaqua site may be interesting as well. From the site:
"The Quaqua Look and Feel (Quaqua) is a user interface library for Java applications which wish to closely adhere to the Apple Human Interface Guidelines for Mac OS X. ... It runs on top of Apple's Aqua Look and Feel, and provides fixes and enhancements for it."
It has a fairly good user guide with examples as well.
The Java Development Guide for Mac OS X has a Mac OS X Integration for Java section that is probably what you're looking for.
You can check this PDF at Apple, but it's marked as legacy.
On some applications, I'm still using com.apple.macos.useScreenMenuBar to have the Java application use the Mac OS X menu bar, and it still works in Leopard.
My personal link collection:
From developer.apple.com:
Java Runtime Properties for Mac OS X (don't get scared by the "not recommended" popup, some of the information is still useful)
Apple Java Extensions
OS X Runtime Configuration Guidelines (not directly related to Java, but an interesting read anyway)
From Sun:
Bringing your Java Application to Mac OS X Part Three
same page at another location with working images: http://192.9.162.55/developer/technicalArticles/JavaLP/JavaToMac/
When clicking on some old links I'd been redirected to Java Design Guidelines and Java Guides, seems as though I have to update my links...

Enumerating attached DVD drives in Linux / Java / Scala

In my Scala (runs on top of Java) Application I would like to get a list of all drives that contain DVD media, e.g. something like this:
/dev/scd0 Star Trek DS9 DVD1
/dev/scd0 The 4400 DVD1
Not sure if it's possible to get the name of the disc, but the path is the important thing for me anyway.
I would prefer a pure Java / Scala solution (using file.io stuff). If that's not possible, accessing the right Linux files is fine, too (like /proc/something).
Thanks in advance!
I think you're out of luck with java.io.* but if you don't mind making calls out to Linux commands, you could assemble the data by:
Calling "mount" and capturing the first column of output.
Calling "volname" on each value you captured from step 1.
According to the man page for volname, it only returns data for ISO-9660 filesystems (e.g. DVDs), so any device path that returns empty can be ignored.
There is one (untested) possibility to get your drives with pure Java code. At least on Windows.
Its a little bit hacky and doesn't work under linux (because linux gets not as much integration love from sun I believe).
import javax.swing._
import javax.swing.filechooser._
val chooser = new JFileChooser()
val view = chooser.getFileSystemView()
The FileSystemView clas provides a few features such as asking the possible roots if they
are a drive (isDrive()). Swing uses this to present the file chooser with the right icons to
you so it should work under windows because IIRC it shows the correct symbols there. Under
Linux it unfortunately does only show the "/" root.
One of the reasons this doesn't work under linux could be, that the linux developers constantly change their preferred way of presenting such information to the user space. at the moment it is IIRC hal and dbus. Maybe SUN didn't want to publish a new java version each time this changes.
If pure java doesn't cut it maybe you could use a little bit of jni (which is not so hard to use anymore if you're using tools like JNA or such) to access the linux apis directly. I haven't done that but could try if you're interested.

Categories