use of javax.imageio.event.IIOWriteWarningListener in project jdk8u_jdk by JetBrains.
the class ImageWriter method processWarningOccurred.
/**
* Broadcasts a localized warning message to all registered
* <code>IIOWriteWarningListener</code>s by calling their
* <code>warningOccurred</code> method with a string taken
* from a <code>ResourceBundle</code>. Subclasses may use this
* method as a convenience.
*
* @param imageIndex the index of the image on which the warning
* occurred.
* @param baseName the base name of a set of
* <code>ResourceBundle</code>s containing localized warning
* messages.
* @param keyword the keyword used to index the warning message
* within the set of <code>ResourceBundle</code>s.
*
* @exception IllegalArgumentException if <code>baseName</code>
* is <code>null</code>.
* @exception IllegalArgumentException if <code>keyword</code>
* is <code>null</code>.
* @exception IllegalArgumentException if no appropriate
* <code>ResourceBundle</code> may be located.
* @exception IllegalArgumentException if the named resource is
* not found in the located <code>ResourceBundle</code>.
* @exception IllegalArgumentException if the object retrieved
* from the <code>ResourceBundle</code> is not a
* <code>String</code>.
*/
protected void processWarningOccurred(int imageIndex, String baseName, String keyword) {
if (warningListeners == null) {
return;
}
if (baseName == null) {
throw new IllegalArgumentException("baseName == null!");
}
if (keyword == null) {
throw new IllegalArgumentException("keyword == null!");
}
int numListeners = warningListeners.size();
for (int i = 0; i < numListeners; i++) {
IIOWriteWarningListener listener = (IIOWriteWarningListener) warningListeners.get(i);
Locale locale = (Locale) warningLocales.get(i);
if (locale == null) {
locale = Locale.getDefault();
}
/**
* If an applet supplies an implementation of ImageWriter and
* resource bundles, then the resource bundle will need to be
* accessed via the applet class loader. So first try the context
* class loader to locate the resource bundle.
* If that throws MissingResourceException, then try the
* system class loader.
*/
ClassLoader loader = (ClassLoader) java.security.AccessController.doPrivileged(new java.security.PrivilegedAction() {
public Object run() {
return Thread.currentThread().getContextClassLoader();
}
});
ResourceBundle bundle = null;
try {
bundle = ResourceBundle.getBundle(baseName, locale, loader);
} catch (MissingResourceException mre) {
try {
bundle = ResourceBundle.getBundle(baseName, locale);
} catch (MissingResourceException mre1) {
throw new IllegalArgumentException("Bundle not found!");
}
}
String warning = null;
try {
warning = bundle.getString(keyword);
} catch (ClassCastException cce) {
throw new IllegalArgumentException("Resource is not a String!");
} catch (MissingResourceException mre) {
throw new IllegalArgumentException("Resource is missing!");
}
listener.warningOccurred(this, imageIndex, warning);
}
}
use of javax.imageio.event.IIOWriteWarningListener in project jdk8u_jdk by JetBrains.
the class BMPImageWriter method writeEmbedded.
private void writeEmbedded(IIOImage image, ImageWriteParam bmpParam) throws IOException {
String format = compressionType == BI_JPEG ? "jpeg" : "png";
Iterator iterator = ImageIO.getImageWritersByFormatName(format);
ImageWriter writer = null;
if (iterator.hasNext())
writer = (ImageWriter) iterator.next();
if (writer != null) {
if (embedded_stream == null) {
throw new RuntimeException("No stream for writing embedded image!");
}
writer.addIIOWriteProgressListener(new IIOWriteProgressAdapter() {
public void imageProgress(ImageWriter source, float percentageDone) {
processImageProgress(percentageDone);
}
});
writer.addIIOWriteWarningListener(new IIOWriteWarningListener() {
public void warningOccurred(ImageWriter source, int imageIndex, String warning) {
processWarningOccurred(imageIndex, warning);
}
});
writer.setOutput(ImageIO.createImageOutputStream(embedded_stream));
ImageWriteParam param = writer.getDefaultWriteParam();
//param.setDestinationBands(bmpParam.getDestinationBands());
param.setDestinationOffset(bmpParam.getDestinationOffset());
param.setSourceBands(bmpParam.getSourceBands());
param.setSourceRegion(bmpParam.getSourceRegion());
param.setSourceSubsampling(bmpParam.getSourceXSubsampling(), bmpParam.getSourceYSubsampling(), bmpParam.getSubsamplingXOffset(), bmpParam.getSubsamplingYOffset());
writer.write(null, image, param);
} else
throw new RuntimeException(I18N.getString("BMPImageWrite5") + " " + format);
}
Aggregations