242 return output;
243 }
244
245 // Localization
246
247 /**
248 * Returns an array of <code>Locale</code>s that may be used to
249 * localize warning listeners and compression settings. A return
250 * value of <code>null</code> indicates that localization is not
251 * supported.
252 *
253 * <p> The default implementation returns a clone of the
254 * <code>availableLocales</code> instance variable if it is
255 * non-<code>null</code>, or else returns <code>null</code>.
256 *
257 * @return an array of <code>Locale</code>s that may be used as
258 * arguments to <code>setLocale</code>, or <code>null</code>.
259 */
260 public Locale[] getAvailableLocales() {
261 return (availableLocales == null) ?
262 null : (Locale[])availableLocales.clone();
263 }
264
265 /**
266 * Sets the current <code>Locale</code> of this
267 * <code>ImageWriter</code> to the given value. A value of
268 * <code>null</code> removes any previous setting, and indicates
269 * that the writer should localize as it sees fit.
270 *
271 * <p> The default implementation checks <code>locale</code>
272 * against the values returned by
273 * <code>getAvailableLocales</code>, and sets the
274 * <code>locale</code> instance variable if it is found. If
275 * <code>locale</code> is <code>null</code>, the instance variable
276 * is set to <code>null</code> without any checking.
277 *
278 * @param locale the desired <code>Locale</code>, or
279 * <code>null</code>.
280 *
281 * @exception IllegalArgumentException if <code>locale</code> is
282 * non-<code>null</code> but is not one of the values returned by
1738 * <code>null</code>.
1739 */
1740 public void removeAllIIOWriteProgressListeners() {
1741 this.progressListeners = null;
1742 }
1743
1744 /**
1745 * Broadcasts the start of an image write to all registered
1746 * <code>IIOWriteProgressListener</code>s by calling their
1747 * <code>imageStarted</code> method. Subclasses may use this
1748 * method as a convenience.
1749 *
1750 * @param imageIndex the index of the image about to be written.
1751 */
1752 protected void processImageStarted(int imageIndex) {
1753 if (progressListeners == null) {
1754 return;
1755 }
1756 int numListeners = progressListeners.size();
1757 for (int i = 0; i < numListeners; i++) {
1758 IIOWriteProgressListener listener =
1759 (IIOWriteProgressListener)progressListeners.get(i);
1760 listener.imageStarted(this, imageIndex);
1761 }
1762 }
1763
1764 /**
1765 * Broadcasts the current percentage of image completion to all
1766 * registered <code>IIOWriteProgressListener</code>s by calling
1767 * their <code>imageProgress</code> method. Subclasses may use
1768 * this method as a convenience.
1769 *
1770 * @param percentageDone the current percentage of completion,
1771 * as a <code>float</code>.
1772 */
1773 protected void processImageProgress(float percentageDone) {
1774 if (progressListeners == null) {
1775 return;
1776 }
1777 int numListeners = progressListeners.size();
1778 for (int i = 0; i < numListeners; i++) {
1779 IIOWriteProgressListener listener =
1780 (IIOWriteProgressListener)progressListeners.get(i);
1781 listener.imageProgress(this, percentageDone);
1782 }
1783 }
1784
1785 /**
1786 * Broadcasts the completion of an image write to all registered
1787 * <code>IIOWriteProgressListener</code>s by calling their
1788 * <code>imageComplete</code> method. Subclasses may use this
1789 * method as a convenience.
1790 */
1791 protected void processImageComplete() {
1792 if (progressListeners == null) {
1793 return;
1794 }
1795 int numListeners = progressListeners.size();
1796 for (int i = 0; i < numListeners; i++) {
1797 IIOWriteProgressListener listener =
1798 (IIOWriteProgressListener)progressListeners.get(i);
1799 listener.imageComplete(this);
1800 }
1801 }
1802
1803 /**
1804 * Broadcasts the start of a thumbnail write to all registered
1805 * <code>IIOWriteProgressListener</code>s by calling their
1806 * <code>thumbnailStarted</code> method. Subclasses may use this
1807 * method as a convenience.
1808 *
1809 * @param imageIndex the index of the image associated with the
1810 * thumbnail.
1811 * @param thumbnailIndex the index of the thumbnail.
1812 */
1813 protected void processThumbnailStarted(int imageIndex,
1814 int thumbnailIndex) {
1815 if (progressListeners == null) {
1816 return;
1817 }
1818 int numListeners = progressListeners.size();
1819 for (int i = 0; i < numListeners; i++) {
1820 IIOWriteProgressListener listener =
1821 (IIOWriteProgressListener)progressListeners.get(i);
1822 listener.thumbnailStarted(this, imageIndex, thumbnailIndex);
1823 }
1824 }
1825
1826 /**
1827 * Broadcasts the current percentage of thumbnail completion to
1828 * all registered <code>IIOWriteProgressListener</code>s by calling
1829 * their <code>thumbnailProgress</code> method. Subclasses may
1830 * use this method as a convenience.
1831 *
1832 * @param percentageDone the current percentage of completion,
1833 * as a <code>float</code>.
1834 */
1835 protected void processThumbnailProgress(float percentageDone) {
1836 if (progressListeners == null) {
1837 return;
1838 }
1839 int numListeners = progressListeners.size();
1840 for (int i = 0; i < numListeners; i++) {
1841 IIOWriteProgressListener listener =
1842 (IIOWriteProgressListener)progressListeners.get(i);
1843 listener.thumbnailProgress(this, percentageDone);
1844 }
1845 }
1846
1847 /**
1848 * Broadcasts the completion of a thumbnail write to all registered
1849 * <code>IIOWriteProgressListener</code>s by calling their
1850 * <code>thumbnailComplete</code> method. Subclasses may use this
1851 * method as a convenience.
1852 */
1853 protected void processThumbnailComplete() {
1854 if (progressListeners == null) {
1855 return;
1856 }
1857 int numListeners = progressListeners.size();
1858 for (int i = 0; i < numListeners; i++) {
1859 IIOWriteProgressListener listener =
1860 (IIOWriteProgressListener)progressListeners.get(i);
1861 listener.thumbnailComplete(this);
1862 }
1863 }
1864
1865 /**
1866 * Broadcasts that the write has been aborted to all registered
1867 * <code>IIOWriteProgressListener</code>s by calling their
1868 * <code>writeAborted</code> method. Subclasses may use this
1869 * method as a convenience.
1870 */
1871 protected void processWriteAborted() {
1872 if (progressListeners == null) {
1873 return;
1874 }
1875 int numListeners = progressListeners.size();
1876 for (int i = 0; i < numListeners; i++) {
1877 IIOWriteProgressListener listener =
1878 (IIOWriteProgressListener)progressListeners.get(i);
1879 listener.writeAborted(this);
1880 }
1881 }
1882
1883 /**
1884 * Broadcasts a warning message to all registered
1885 * <code>IIOWriteWarningListener</code>s by calling their
1886 * <code>warningOccurred</code> method. Subclasses may use this
1887 * method as a convenience.
1888 *
1889 * @param imageIndex the index of the image on which the warning
1890 * occurred.
1891 * @param warning the warning message.
1892 *
1893 * @exception IllegalArgumentException if <code>warning</code>
1894 * is <code>null</code>.
1895 */
1896 protected void processWarningOccurred(int imageIndex,
1897 String warning) {
1898 if (warningListeners == null) {
1899 return;
1900 }
1901 if (warning == null) {
1902 throw new IllegalArgumentException("warning == null!");
1903 }
1904 int numListeners = warningListeners.size();
1905 for (int i = 0; i < numListeners; i++) {
1906 IIOWriteWarningListener listener =
1907 (IIOWriteWarningListener)warningListeners.get(i);
1908
1909 listener.warningOccurred(this, imageIndex, warning);
1910 }
1911 }
1912
1913 /**
1914 * Broadcasts a localized warning message to all registered
1915 * <code>IIOWriteWarningListener</code>s by calling their
1916 * <code>warningOccurred</code> method with a string taken
1917 * from a <code>ResourceBundle</code>. Subclasses may use this
1918 * method as a convenience.
1919 *
1920 * @param imageIndex the index of the image on which the warning
1921 * occurred.
1922 * @param baseName the base name of a set of
1923 * <code>ResourceBundle</code>s containing localized warning
1924 * messages.
1925 * @param keyword the keyword used to index the warning message
1926 * within the set of <code>ResourceBundle</code>s.
1927 *
1934 * @exception IllegalArgumentException if the named resource is
1935 * not found in the located <code>ResourceBundle</code>.
1936 * @exception IllegalArgumentException if the object retrieved
1937 * from the <code>ResourceBundle</code> is not a
1938 * <code>String</code>.
1939 */
1940 protected void processWarningOccurred(int imageIndex,
1941 String baseName,
1942 String keyword) {
1943 if (warningListeners == null) {
1944 return;
1945 }
1946 if (baseName == null) {
1947 throw new IllegalArgumentException("baseName == null!");
1948 }
1949 if (keyword == null) {
1950 throw new IllegalArgumentException("keyword == null!");
1951 }
1952 int numListeners = warningListeners.size();
1953 for (int i = 0; i < numListeners; i++) {
1954 IIOWriteWarningListener listener =
1955 (IIOWriteWarningListener)warningListeners.get(i);
1956 Locale locale = (Locale)warningLocales.get(i);
1957 if (locale == null) {
1958 locale = Locale.getDefault();
1959 }
1960
1961 /**
1962 * If an applet supplies an implementation of ImageWriter and
1963 * resource bundles, then the resource bundle will need to be
1964 * accessed via the applet class loader. So first try the context
1965 * class loader to locate the resource bundle.
1966 * If that throws MissingResourceException, then try the
1967 * system class loader.
1968 */
1969 ClassLoader loader = (ClassLoader)
1970 java.security.AccessController.doPrivileged(
1971 new java.security.PrivilegedAction() {
1972 public Object run() {
1973 return Thread.currentThread().getContextClassLoader();
1974 }
1975 });
1976
|
242 return output;
243 }
244
245 // Localization
246
247 /**
248 * Returns an array of <code>Locale</code>s that may be used to
249 * localize warning listeners and compression settings. A return
250 * value of <code>null</code> indicates that localization is not
251 * supported.
252 *
253 * <p> The default implementation returns a clone of the
254 * <code>availableLocales</code> instance variable if it is
255 * non-<code>null</code>, or else returns <code>null</code>.
256 *
257 * @return an array of <code>Locale</code>s that may be used as
258 * arguments to <code>setLocale</code>, or <code>null</code>.
259 */
260 public Locale[] getAvailableLocales() {
261 return (availableLocales == null) ?
262 null : availableLocales.clone();
263 }
264
265 /**
266 * Sets the current <code>Locale</code> of this
267 * <code>ImageWriter</code> to the given value. A value of
268 * <code>null</code> removes any previous setting, and indicates
269 * that the writer should localize as it sees fit.
270 *
271 * <p> The default implementation checks <code>locale</code>
272 * against the values returned by
273 * <code>getAvailableLocales</code>, and sets the
274 * <code>locale</code> instance variable if it is found. If
275 * <code>locale</code> is <code>null</code>, the instance variable
276 * is set to <code>null</code> without any checking.
277 *
278 * @param locale the desired <code>Locale</code>, or
279 * <code>null</code>.
280 *
281 * @exception IllegalArgumentException if <code>locale</code> is
282 * non-<code>null</code> but is not one of the values returned by
1738 * <code>null</code>.
1739 */
1740 public void removeAllIIOWriteProgressListeners() {
1741 this.progressListeners = null;
1742 }
1743
1744 /**
1745 * Broadcasts the start of an image write to all registered
1746 * <code>IIOWriteProgressListener</code>s by calling their
1747 * <code>imageStarted</code> method. Subclasses may use this
1748 * method as a convenience.
1749 *
1750 * @param imageIndex the index of the image about to be written.
1751 */
1752 protected void processImageStarted(int imageIndex) {
1753 if (progressListeners == null) {
1754 return;
1755 }
1756 int numListeners = progressListeners.size();
1757 for (int i = 0; i < numListeners; i++) {
1758 IIOWriteProgressListener listener = progressListeners.get(i);
1759 listener.imageStarted(this, imageIndex);
1760 }
1761 }
1762
1763 /**
1764 * Broadcasts the current percentage of image completion to all
1765 * registered <code>IIOWriteProgressListener</code>s by calling
1766 * their <code>imageProgress</code> method. Subclasses may use
1767 * this method as a convenience.
1768 *
1769 * @param percentageDone the current percentage of completion,
1770 * as a <code>float</code>.
1771 */
1772 protected void processImageProgress(float percentageDone) {
1773 if (progressListeners == null) {
1774 return;
1775 }
1776 int numListeners = progressListeners.size();
1777 for (int i = 0; i < numListeners; i++) {
1778 IIOWriteProgressListener listener = progressListeners.get(i);
1779 listener.imageProgress(this, percentageDone);
1780 }
1781 }
1782
1783 /**
1784 * Broadcasts the completion of an image write to all registered
1785 * <code>IIOWriteProgressListener</code>s by calling their
1786 * <code>imageComplete</code> method. Subclasses may use this
1787 * method as a convenience.
1788 */
1789 protected void processImageComplete() {
1790 if (progressListeners == null) {
1791 return;
1792 }
1793 int numListeners = progressListeners.size();
1794 for (int i = 0; i < numListeners; i++) {
1795 IIOWriteProgressListener listener = progressListeners.get(i);
1796 listener.imageComplete(this);
1797 }
1798 }
1799
1800 /**
1801 * Broadcasts the start of a thumbnail write to all registered
1802 * <code>IIOWriteProgressListener</code>s by calling their
1803 * <code>thumbnailStarted</code> method. Subclasses may use this
1804 * method as a convenience.
1805 *
1806 * @param imageIndex the index of the image associated with the
1807 * thumbnail.
1808 * @param thumbnailIndex the index of the thumbnail.
1809 */
1810 protected void processThumbnailStarted(int imageIndex,
1811 int thumbnailIndex) {
1812 if (progressListeners == null) {
1813 return;
1814 }
1815 int numListeners = progressListeners.size();
1816 for (int i = 0; i < numListeners; i++) {
1817 IIOWriteProgressListener listener = progressListeners.get(i);
1818 listener.thumbnailStarted(this, imageIndex, thumbnailIndex);
1819 }
1820 }
1821
1822 /**
1823 * Broadcasts the current percentage of thumbnail completion to
1824 * all registered <code>IIOWriteProgressListener</code>s by calling
1825 * their <code>thumbnailProgress</code> method. Subclasses may
1826 * use this method as a convenience.
1827 *
1828 * @param percentageDone the current percentage of completion,
1829 * as a <code>float</code>.
1830 */
1831 protected void processThumbnailProgress(float percentageDone) {
1832 if (progressListeners == null) {
1833 return;
1834 }
1835 int numListeners = progressListeners.size();
1836 for (int i = 0; i < numListeners; i++) {
1837 IIOWriteProgressListener listener = progressListeners.get(i);
1838 listener.thumbnailProgress(this, percentageDone);
1839 }
1840 }
1841
1842 /**
1843 * Broadcasts the completion of a thumbnail write to all registered
1844 * <code>IIOWriteProgressListener</code>s by calling their
1845 * <code>thumbnailComplete</code> method. Subclasses may use this
1846 * method as a convenience.
1847 */
1848 protected void processThumbnailComplete() {
1849 if (progressListeners == null) {
1850 return;
1851 }
1852 int numListeners = progressListeners.size();
1853 for (int i = 0; i < numListeners; i++) {
1854 IIOWriteProgressListener listener = progressListeners.get(i);
1855 listener.thumbnailComplete(this);
1856 }
1857 }
1858
1859 /**
1860 * Broadcasts that the write has been aborted to all registered
1861 * <code>IIOWriteProgressListener</code>s by calling their
1862 * <code>writeAborted</code> method. Subclasses may use this
1863 * method as a convenience.
1864 */
1865 protected void processWriteAborted() {
1866 if (progressListeners == null) {
1867 return;
1868 }
1869 int numListeners = progressListeners.size();
1870 for (int i = 0; i < numListeners; i++) {
1871 IIOWriteProgressListener listener = progressListeners.get(i);
1872 listener.writeAborted(this);
1873 }
1874 }
1875
1876 /**
1877 * Broadcasts a warning message to all registered
1878 * <code>IIOWriteWarningListener</code>s by calling their
1879 * <code>warningOccurred</code> method. Subclasses may use this
1880 * method as a convenience.
1881 *
1882 * @param imageIndex the index of the image on which the warning
1883 * occurred.
1884 * @param warning the warning message.
1885 *
1886 * @exception IllegalArgumentException if <code>warning</code>
1887 * is <code>null</code>.
1888 */
1889 protected void processWarningOccurred(int imageIndex,
1890 String warning) {
1891 if (warningListeners == null) {
1892 return;
1893 }
1894 if (warning == null) {
1895 throw new IllegalArgumentException("warning == null!");
1896 }
1897 int numListeners = warningListeners.size();
1898 for (int i = 0; i < numListeners; i++) {
1899 IIOWriteWarningListener listener = warningListeners.get(i);
1900
1901 listener.warningOccurred(this, imageIndex, warning);
1902 }
1903 }
1904
1905 /**
1906 * Broadcasts a localized warning message to all registered
1907 * <code>IIOWriteWarningListener</code>s by calling their
1908 * <code>warningOccurred</code> method with a string taken
1909 * from a <code>ResourceBundle</code>. Subclasses may use this
1910 * method as a convenience.
1911 *
1912 * @param imageIndex the index of the image on which the warning
1913 * occurred.
1914 * @param baseName the base name of a set of
1915 * <code>ResourceBundle</code>s containing localized warning
1916 * messages.
1917 * @param keyword the keyword used to index the warning message
1918 * within the set of <code>ResourceBundle</code>s.
1919 *
1926 * @exception IllegalArgumentException if the named resource is
1927 * not found in the located <code>ResourceBundle</code>.
1928 * @exception IllegalArgumentException if the object retrieved
1929 * from the <code>ResourceBundle</code> is not a
1930 * <code>String</code>.
1931 */
1932 protected void processWarningOccurred(int imageIndex,
1933 String baseName,
1934 String keyword) {
1935 if (warningListeners == null) {
1936 return;
1937 }
1938 if (baseName == null) {
1939 throw new IllegalArgumentException("baseName == null!");
1940 }
1941 if (keyword == null) {
1942 throw new IllegalArgumentException("keyword == null!");
1943 }
1944 int numListeners = warningListeners.size();
1945 for (int i = 0; i < numListeners; i++) {
1946 IIOWriteWarningListener listener = warningListeners.get(i);
1947 Locale locale = warningLocales.get(i);
1948 if (locale == null) {
1949 locale = Locale.getDefault();
1950 }
1951
1952 /**
1953 * If an applet supplies an implementation of ImageWriter and
1954 * resource bundles, then the resource bundle will need to be
1955 * accessed via the applet class loader. So first try the context
1956 * class loader to locate the resource bundle.
1957 * If that throws MissingResourceException, then try the
1958 * system class loader.
1959 */
1960 ClassLoader loader = (ClassLoader)
1961 java.security.AccessController.doPrivileged(
1962 new java.security.PrivilegedAction() {
1963 public Object run() {
1964 return Thread.currentThread().getContextClassLoader();
1965 }
1966 });
1967
|