Java: How to get the scrolling method in OS X Lion? - java

Since OS X supports the "natural scrolling", my applications works wrong. The natural scrolling is made for scroll panes, which I really like. But, when I want to zoom in/out, it works wrong. So, what I want to do is check the scroll method for OS X.
If it is "natural" I'll take the opposite of the scroll values from MouseWheelEvent.getWheelRotation() to make my zoom in/out behavior feel correct.
So, in short: How to know if OS X uses natural scrolling or not?

Found a solution.
First, you need a library to read .plist files. I used this one.
Than you can easily read in the GlobalPreferneces.plist (checked with fseventer which file is changed when changing the scroll option) to find out which kind of scrolling is enabled like this:
try {
File globalPref = new File(System.getProperty("user.home") + "/Library/Preferences/.GlobalPreferences.plist");
NSDictionary dict = (NSDictionary)PropertyListParser.parse(globalPref);
NSNumber pref = (NSNumber)dict.objectForKey("com.apple.swipescrolldirection");
if(pref.boolValue()) {
//natural scrolling is enabled
}
} catch (Exception ex) {
System.out.println("Faild to parse plist: " + ex.getMessage());
}

Take a look at Mike Swingler's answer on the java-dev mailing list. There is a whole thread about it.

As Apple has dropped Java, I don't think that there is built in method to detect if natural scrolling is enabled. However, you could read in in the .plist files for configuring mouse/touchpad behaviour (which is a basic xml file) and look for the property to enable natural scrolling is set to true or false.
You can find the required .plist files here:
User/Library/Preferences/ <- This folder is hidden in Lion!
com.apple.driver.AppleBluetoothMultitouch.mouse.plist
com.apple.driver.AppleHIDMouse.plist
Edit:
You can't read in a plist file with the standard Java Framework, as since Mac OS 10.4 all .plists are saved in binary format. See my other answer for a correct solution.

Related

Custom fonts PaxA920 and PaxA910

There is a application working with PAX A920 and PAX A910 devices. There is a change request to change the print slip more attractive way. Is there a way to use custom fonts?
I have tried by did not works for me.
try {
printerTester.setFontPath("font/calibri_regular.ttf");
}catch (Exception e){
e.printStackTrace();
}
Existing application font sizes changed by
printerTester.fontSet(EFontTypeAscii.FONT_8_16, EFontTypeExtCode.FONT_16_16);
Appreciate any help
Printing on these devices is usually done using only the fonts that the printer has. And most printers only support one type of font.
This is because performance can be ensured and resources can be saved.
If you want to decorate the printed content, create a graphic image of the content yourself and print it.
Maybe, your device specs or SDK has information to help you do that.
Please examine these materials carefully.
Even if you don't have that information, most of them should have the ability to print graphics, so try to create your own based on those specifications.

Android ImageSpans in Codename One TextFields

I am porting my Android app to iOS and I am using Codename One for that.
In my app an EditText can contain icons mixed with text. It is accomplished with instructions like these:
MyImageSpan iconSpan=new MyImageSpan(activity, R.drawable.icon);
editText.getText().insert(caretPosition,CHAR);
editText.getText().setSpan(iconSpan,caretPosition,caretPosition+1,Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
then in other parts, spans have to be detected, if present, and it is performed like this:
Editable editable = editText.getText();
for (int i = 0; i < editable.length(); i = next) {
// find the next span transition
next = editable.nextSpanTransition(i, editable.length(), MyImageSpan.class);
// get all spans in this range
MImageSpan[] tempSpans = editable.getSpans(i, next, MyImageSpan.class);
...
...
//In my app that becomes really complex
...
...
...
...
}
I tried to use this online tool:
http://fontello.com/
to manage icons like font glyphs, as it seems to be adviced by Codename One documentation.
In fact I do not understand if it is possible to have spans with different fonts in an TextField in Codename One, and I do not know if I could find and manage them inside the TextField.
But the most important thing is that the online tool to create fonts out of svg files did not work for me because some icons are reverted, others are broken or confused, others are tiny, depending on the saving format (eventually I saved in pure SVG format to avoid issues but it's the same).
What I am asking is how to handle the spans in the TextField in Codename One.
It has not to be the same "way" but the result has to be the same.
This won't work. Rich text edit is something that's just too different between platforms and isn't universally available. Since the edit component is implemented using native widgets it's very hard to consistently abstract something like this and effectively impossible.
However, web tools solved that problem already and include some cross platform rich edit tools that work. You can just use one of those tools and embed a BrowserComponent in your app. Then perform the rich editing within the browser component.
Back in the day we did it with CK editor, but this library is pretty out of date by now so I'm not sure how well it works. It should be relatively easy to create something like this though.

find name of icons in control panel

Is there a way to obtain the name of the icons in the Windows Control Panel, and find out their coordinates?
One more question - if I have an application running and that contains buttons, is there a possible way to obtain the name of the button, as in string?
http://msdn.microsoft.com/en-us/library/ee330741(v=VS.85).aspx lists the "canonical names" of each control panel item. For example, Microsoft.DateAndTime for the one that sets your date and time. http://msdn.microsoft.com/en-us/library/cc144191(v=VS.85).aspx shows how to use WinExec (which you may or may not be able to use from Java, I don't know) to launch an item given it's canonical name, for example
WinExec("%systemroot%\system32\control.exe /name Microsoft.WindowsUpdate", SW_NORMAL);
There is quite a lot of community content on that page, indicating that perhaps it's a bit trickier than the documentation suggests. I suspect that getting your code to work smoothly on XP, Vista, and 7 may be frustrating.
The Mail icon is missing from MS's list.
This source indicates that it's canonical name is "Mail".
Check out: http://msdn.microsoft.com/en-us/library/bb776778(v=VS.85).aspx

How to change display settings programically with java?

Is it possible to alter (change/update) display settings (configuration) in Windows XP using Java programming language?
I would like to do something like this:
Display[] displays = WindowsXPSystem.getDisplays(); //get all available displays (monitors). assume there are currently two monitors connected
Display d0 = displays[0]; // the first is 24" and is positioned on the left
d0.setPrimary(true); // and it should be primary, so all new windows open on it.
d0.setSize(new Dimension(1920,1080)); //update screen size (resolution)
d0.setPossition(0,0); //and position it on the left
Display d1 = displays[1]; //second monitor is also present
d1.setSize(new Dimension(1440,768)); // and it's 14.1" laptop's display
d1.setPossition(1920,332); //it's positioned on the right
Any ideas/suggestions/APIs how to update display settings with Java?
I think this is not possible with plain Java. Have a look at this question here:
Detect and Change display resolution permanently using java
as stated there, it's maybe possible to use any native Libraries through JNI (Java Native Interface) which kind of wraps native Libraries. But you will loose your platform independency then.
There is no plain Java solution to your problem. The function is way to specific for a generic implementation.
You could however, if you really need to implement this use a JNI library, that wraps the Windows functionality of adjusting the screen resolution.

PJL command to set orientation

I have tried setting the number of copies using PJL and got it working. However I could not get the #PJL SET ORIENTATION=LANDSCAPE working. It always prints in Portrait. I am also looking for options to print particular page range say from page 2 to 5. Can this be achieved using PJL? I am using the printer HP LaserJet 5000 Series PCL6.
I am able to achieve page range using the command, #PJL JOB NAME="TestPage" START=2 END=5. It works. Modfying the orientation does not work.
This most likely cannot be done with PJL in your case. The datastream probably contains a command for orientation. PJL is designed to provide access to features that are not native to the datastream used, provides a solution for explicit language selection, allows for feedback from the printer and other job related items.
Your best solution is to parse the output and make the change inline. You might be able to do this with a 3rd party solution like Ghostscript by splitting the document into sections for portrait and landscape, having it rotate for you, and then piece the file back together again.
Other options might include using a language such as PCL5 where it might be easier to modify the data inline.
Your postscript code likely has the orientation command which is overriding your PJL command. In your postscript code, look for something like this, as it's the thing that will rotate the page to landscape:
90 rotate
For example, I'm using this code to go landscape in postscript:
% get pagesize from device or default to letter
/pageSize {
currentpagedevice /PageSize known {
currentpagedevice /PageSize get
} {
612 792 2 array astore
} ifelse
} def
% go landscape
90 rotate 0 pageSize aload pop pop neg translate

Categories

Resources