I have the following problem. I need to get an UI properties:
UIManager.getString("OptionPane.okButtonText")
that returns the string "OK", and it works. However, if I iterate through the UIDefaults keyset, I never get the key "OptionPane.okButtonText". Does anyone know why it happens? I get the UIDefaults in three different way (UIManager.getDefaults(), UIManager.getLookAndFeel().getDefaults() and UIManager.getLookAndFeelDefaults()), but no one of these work.
Edit: I also find this list of properties of the class JFileChooser, that contains some properties that do not appear int the UIDefaults keyset. The problem is: how programmatically get all this properties?
Edit: Example of code:
UIDefaults defaults = UIManager.getDefaults();
String thekey = "OptionPane.okButtonText";
System.out.println(thekey + ": " + UIManager.getString(thekey));
for (Enumeration e = defaults.keys(); e.hasMoreElements();) {
Object key = e.nextElement();
System.out.println(key + ": " + defaults.get(key));
}
this code return print these properties. The key "OptionPane.okButtonText" dont appear in the output.
This could be a problem with resourceBundles: the optionPane (as well as f.i. fileChooser and other) text properties are loaded from localized bundles. They are (used to be, not entirely sure if that's still the case) internal classes under com.sun.swing.internal.plaf. Maybe something's going wrong there ...
here's the snippet that worksforme:
String ok = "OptionPane.okButtonText";
String text = "";
text += " LAF: " + UIManager.getLookAndFeelDefaults().get(ok);
text += " lookup: " + UIManager.get(ok);
text += " default: " + UIManager.getDefaults().get(ok);
System.out.println(text);
// output, whereever I add that:
LAF: OK lookup: OK default: OK
independent of which LAF is currently installed. My system is win/vista, my default locale de
Edit: just to clarify - the localized resources are not necessarily direct entries in the keys()/entrySet(), these are methods in Hashtable which are not overridden in UIDefaults. So while the lookup as in my snippet should always work querying the enums is wrong - the entries are not there but in some cached maps which are fed by resourceBundles.
Edit2: added the def of ok (thought that would be ... obvious after talking for several hours about that key :-)
Edit3: for further experiments, we should probably lookup a value which differs more than "OK" across Locales, f.i. cancelButtonText
Edit 4 (the very last before a major break, promised :-) - as to "how-to find all localized values" is not possible without resorting to dirty means (aka: implementation details). The only way I can think of is to look into the resourceBundles which are - assumedly - loaded, like
import com.sun.swing.internal.plaf.basic.resources.basic;
String cancel = "OptionPane.cancelButtonText";
ListResourceBundle bundle = new basic();
for (String key : bundle.keySet()) {
if(cancel.equals(key)) {
System.out.println(key
+ ": " + bundle.getString(key));
}
}
It appears that OptionPane.okButtonText is a feature unique to Aqua available in all L&Fs, as shown using this approach that includes localized values not seen when iterating over the entrySet().
import javax.swing.UIDefaults;
import javax.swing.UIManager;
/** #see https://stackoverflow.com/questions/5729306 */
public class OptionPaneDefaults {
public static void main(String[] args) throws Exception {
UIManager.LookAndFeelInfo[] lfa =
UIManager.getInstalledLookAndFeels();
for (UIManager.LookAndFeelInfo lf : lfa) {
UIManager.setLookAndFeel(lf.getClassName());
UIDefaults uid = UIManager.getLookAndFeelDefaults();
System.out.println("***"
+ " " + lf.getName()
+ " " + lf.getClassName()
+ " " + uid.size() + " entries");
String ok = "OptionPane.okButtonText";
String text = "";
text += " LAF: " + UIManager.getLookAndFeelDefaults().get(ok);
text += " lookup: " + UIManager.get(ok);
text += " default: " + UIManager.getDefaults().get(ok);
System.out.println(text);
}
}
}
Console, Mac OS X:
*** Metal javax.swing.plaf.metal.MetalLookAndFeel 636 entries
LAF: OK lookup: OK default: OK
*** Nimbus com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel 1054 entries
LAF: OK lookup: OK default: OK
*** CDE/Motif com.sun.java.swing.plaf.motif.MotifLookAndFeel 550 entries
LAF: OK lookup: OK default: OK
*** Mac OS X com.apple.laf.AquaLookAndFeel 711 entries
LAF: OK lookup: OK default: OK
Console, Windows 7:
*** Metal javax.swing.plaf.metal.MetalLookAndFeel 636 entries
LAF: OK lookup: OK default: OK
*** Nimbus com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel 1049 entries
LAF: OK lookup: OK default: OK
*** CDE/Motif com.sun.java.swing.plaf.motif.MotifLookAndFeel 550 entries
LAF: OK lookup: OK default: OK
*** Windows com.sun.java.swing.plaf.windows.WindowsLookAndFeel 637 entries
LAF: OK lookup: OK default: OK
*** Windows Classic com.sun.java.swing.plaf.windows.WindowsClassicLookAndFeel 637 entries
LAF: OK lookup: OK default: OK
Related
I wanted to loop through a folder containig .mp3 files and changing their album names (if they don't have one) to their title (e.g. Remix.mp3 with Title "Remix" gets the Album "Remix") using mp3agic.
This is my code so far:
if (mp3file.hasId3v1Tag()) {
ID3v1 id3v1Tag = mp3file.getId3v1Tag();
try {
if (id3v1Tag.getAlbum().equals("")) {
id3v1Tag.setAlbum(id3v1Tag.getTitle());
mp3file.save(SAVE_DIR + "\\" + child.getName());
System.out.println(SAVE_DIR + "/" + child.getName());
} else {
mp3file.save(SAVE_DIR + "/" + child.getName());
}
} catch (Exception e) {
mp3file.save(SAVE_DIR + "/" + child.getName());
}
}
I get the following error:
Exception in thread "main" com.mpatric.mp3agic.NotSupportedException: Packing Obselete frames is not supported
at com.mpatric.mp3agic.ID3v2ObseleteFrame.packFrame(ID3v2ObseleteFrame.java:32)
at com.mpatric.mp3agic.ID3v2Frame.toBytes(ID3v2Frame.java:83)
at com.mpatric.mp3agic.AbstractID3v2Tag.packSpecifiedFrames(AbstractID3v2Tag.java:275)
at com.mpatric.mp3agic.AbstractID3v2Tag.packFrames(AbstractID3v2Tag.java:261)
at com.mpatric.mp3agic.AbstractID3v2Tag.packTag(AbstractID3v2Tag.java:227)
at com.mpatric.mp3agic.AbstractID3v2Tag.toBytes(AbstractID3v2Tag.java:218)
at com.mpatric.mp3agic.Mp3File.save(Mp3File.java:450)
at de.thejetstream.main.Iterator.(Iterator.java:57)
at de.thejetstream.main.Main.main(Main.java:12)
at this file:
name: Feel Good in Black and Yellow.mp3
title: Feel Good in Black and Yellow (feat. Gorillaz & De La Soul)
album: Black and Yellow - Single
It crashes at line 57, which equals to the last save (in the catch).
What is the problem with this code? Is it just because the file uses an old kind of codec or something like this?
I found the solution:
The problem was that these files used ip3v2 tags instead of ip3v1. Simply checking which on it is and adjusting the code accordingly solved everything.
In SAS Open Metadata reference (page 126), it says:
The UpdateMetadata method enables you to update the properties of existing metadata objects. It returns an error if the metadata object to be updated does not exist, unless the OMI_IGNORE_NOTFOUND (134217728) flag is set.
Here is my problem, if I specify the flag or I don't specify the flag, I still get the same error: ("SASLibrary : A5X8AHW1.B40000SQ cannot be found in the wlibrary container in the Foundation repository.")
Here is a snippet that reproduces the error:
import com.sas.meta.SASOMI.IOMI;
import com.sas.metadata.MetadataUtil;
import org.omg.CORBA.StringHolder;
IOMI iOMI = ... // an instance of IOMI connection
StringHolder outputMeta = new StringHolder();
String request = ""
+ "<UpdateMetadata>"
+ " <Metadata>"
+ " <SASLibrary Id=\"A5X8AHW1.B40000SQ\"/>"
+ " </Metadata>"
+ " <NS>SAS</NS>"
+ " <Flags>" + (MetadataUtil.OMI_IGNORE_NOTFOUND | MetadataUtil.OMI_TRUSTED_CLIENT | MetadataUtil.OMI_RETURN_LIST) + "</Flags>"
+ " <Options/>"
+ "</UpdateMetadata>"
;
iOMI.DoRequest(request, outputMeta);
Any ideas what is going wrong?
Contrary to what that document states, I have only seen OMI_IGNORE_NOTFOUND flag work with the DeleteMetadata method.
The javadoc also seems to support this by stating
OMI_IGNORE_NOTFOUND (134217728) This flag is for DeleteMetadata to tell it to ignore objects not found so that it will not return on error.
com.sas.metadata.remote.MdOMIUtil Interface Field Summery
Fairly new to Play trying to change the language dynamically.
route
GET /language/:lang controllers.Index.setLanguage(lang: String)
Tried so far (but none of them work)
Lang.apply(language);
Lang.change(language); // <-- doesn't even compile
Lang.apply(language);
ctx().changeLang(language);
view
#import play.i18n.Messages
...
#Messages.get("message")
#messages.at("message")
...
Both not working..
application.config
messages
Method with some logging
public Result setLanguage(String language) {
Http.Context context = Http.Context.current();
String langFromHttpContext = context.lang().language();
String langFromCtx = ctx().lang().language();
String playLangCookieVal = request().cookies().get("PLAY_LANG").value();
boolean changed = ctx().changeLang(language);
Logger.info("Request param: " + language);
Logger.info("Http context language: " + langFromHttpContext);
Logger.info("ctx language: " + langFromHttpContext);
Logger.info("PLAY_LANG cookie value: " + langFromCtx);
Logger.info("Changed: " + changed);
return ok(index.render("Index"));
}
Result
application - Request param: en
application - Http context language: nl
application - ctx language: nl
application - PLAY_LANG cookie value: nl
application - Changed: false
You need to delete the application.langs="nl" from the configuration. It's deprecated and replaced by the play.i18n.langs.
You must leave only play.i18n.langs=["en","nl"]
You code does not work because Play reads the application.langs="nl" and ignore play.i18n.langs=["en","nl"] (because langs already read from the application.langs), so it suggest your application use only "nl" language and, of course could not set it to "en", so ctx().changeLang(language) method return false
Try this:
ctx().changeLang(language);
My program currently gets a list of drives plugged into the computer with File.listRoots(). But, when I plug a camera or an MP3 player into the computer directly (instead of inserting the memory card), it's not listed, nor does it have a drive letter in Windows Explorer. For example, here's the location of my camera:
Computer\Canon PowerShot SD750\Removable storage
How can I also list cameras/other devices that do not have a drive letter? I assume this will require a JNI library of some sort, but I don't know for sure obviously.
Thanks!
P.S. Out of desperation, I did try to list the contents of Computer\; it didn't work of course.
Update: I found this question here: Portable Device Path on Windows ; that's exactly the problem I'm having, but there is no solution laid out there.
Java 7 has some promising looking classes in this area, like this one:
http://download.java.net/jdk7/docs/api/java/nio/file/FileSystem.html
Assuming that you need it to work on Java 6 as well, I would suggest running a shell script and parsing its output.
On Windows you could run mountvol, on Unix/MacOS X mount etc. Of course parsing the output would be somewhat tedious and you would have to worry about every OS your app runs on, but hey, at least... not sure what.... it works?
Here is some sample code which seems helpful on Windows:
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_Volume")
For Each objItem In colItems
WScript.Echo "Automount: " & objItem.Automount
WScript.Echo "Block Size: " & objItem.BlockSize
WScript.Echo "Capacity: " & objItem.Capacity
WScript.Echo "Caption: " & objItem.Caption
WScript.Echo "Compressed: " & objItem.Compressed
WScript.Echo "Device ID: " & objItem.DeviceID
WScript.Echo "Dirty Bit Set: " & objItem.DirtyBitSet
WScript.Echo "Drive Letter: " & objItem.DriveLetter
WScript.Echo "Drive Type: " & objItem.DriveType
WScript.Echo "File System: " & objItem.FileSystem
WScript.Echo "Free Space: " & objItem.FreeSpace
WScript.Echo "Indexing Enabled: " & objItem.IndexingEnabled
WScript.Echo "Label: " & objItem.Label
WScript.Echo "Maximum File Name Length: " & objItem.MaximumFileNameLength
WScript.Echo "Name: " & objItem.Name
WScript.Echo "Quotas Enabled: " & objItem.QuotasEnabled
WScript.Echo "Quotas Incomplete: " & objItem.QuotasIncomplete
WScript.Echo "Quotas Rebuilding: " & objItem.QuotasRebuilding
WScript.Echo "Serial Number: " & objItem.SerialNumber
WScript.Echo "Supports Disk Quotas: " & objItem.SupportsDiskQuotas
WScript.Echo "Supports File-Based Compression: " & _
objItem.SupportsFileBasedCompression
WScript.Echo
Next
Here is the output I got for my ebook reader:
Automount: True
Block Size: 4096
Capacity: 999120896
Caption: G:\
Compressed:
Device ID: \\?\Volume{8e3b4ce5-a124-11e0-9d2b-e30c5839642d}\
Dirty Bit Set: False
Drive Letter: G:
Drive Type: 2
File System: FAT32
Free Space: 663683072
Indexing Enabled:
Label: PocketBook9
Maximum File Name Length: 255
Name: G:\
Quotas Enabled:
Quotas Incomplete:
Quotas Rebuilding:
Serial Number: 1276177233
Supports Disk Quotas: False
Supports File-Based Compression: False
The solution to above problem using JMTP library on
http://code.google.com/p/jmtp/
Here is my code
package jmtp;
import be.derycke.pieter.com.COMException;
import be.derycke.pieter.com.Guid;
import java.io.*;
import java.math.BigInteger;
import jmtp.PortableDevice;
import jmtp.*;
public class Jmtp {
public static void main(String[] args) {
PortableDeviceManager manager = new PortableDeviceManager();
PortableDevice device = manager.getDevices()[0];
// Connect to my mp3-player
device.open();
System.out.println(device.getModel());
System.out.println("---------------");
// Iterate over deviceObjects
for (PortableDeviceObject object : device.getRootObjects()) {
// If the object is a storage object
if (object instanceof PortableDeviceStorageObject) {
PortableDeviceStorageObject storage = (PortableDeviceStorageObject) object;
for (PortableDeviceObject o2 : storage.getChildObjects()) {
//
// BigInteger bigInteger1 = new BigInteger("123456789");
// File file = new File("c:/JavaAppletSigningGuide.pdf");
// try {
// storage.addAudioObject(file, "jj", "jj", bigInteger1);
// } catch (Exception e) {
// //System.out.println("Exception e = " + e);
// }
//
System.out.println(o2.getOriginalFileName());
}
}
}
manager.getDevices()[0].close();
}
}
Donot forget add jmtp.dll files (that comes up with jmtp download) as a native library for more info see my answer on
http://stackoverflow.com/questions/12798530/including-native-library-in-netbeans
This may not be the answer you're looking for, but is assigning them to a drive letter not an option? You can usually manually do this with USB devices on Windows using My Computer > right-click > Manage > Storage.
It's possible that CaptureDeviceManager in JMF (java media framework) could help you but I kind of doubt it.
Maybe you can take a look at Morena Framework http://www.gnome.sk/Twain/jtp.htmlv (seems to be open source, but a little expensive; though there is a free evaluation version), it is for TWAIN compatible scanners/cameras (Windows/MAC) or SANE compatible (Linux or other unix flavor), to get a list of connected devices, you can do this:
import SK.gnome.morena.*;
import SK.gnome.twain.*;
public class Test
{
public static void main(String[] args) throws Exception
{
TwainSource[] sources=TwainManager.listSources();
if(sources == null) return;
for(int i = 0; i < sources.length; i++)
{
System.out.println("Twain source is: " + ts.toString());
}
}
}
Maybe that could help,if not I think maybe JMF is a possible solution.
I got my inv finally working! :D But, you know... now... it's dumb. I want it to say "Use Item 1" or whatever when I Right-click so I do this:
if (actItemx == "Item 1") {
popup.add(dropMenuItem + " " + actItemx); // should print "Use Item 1"
popup.add(cancelMenuItem);
}
Looks fine to me... but... when I compile, it's fine. When I run it, it's fine... but when I DO IT:
I would have sworn that because it's displayed correctly in CMD that it would display correctly on JMenu... weird.
popup.add(dropMenuItem + " " + actItemx);
That command is adding the toString() representaion of the dropMenuItem Swing component, plus a space, the the String value of actItemx.
I would guess you want:
popup.add(dropMenuItem.getText() + " " + actItemx);