# HG changeset patch # User Jacob Carlborg # Date 1219415508 -7200 # Node ID 34bfdb096054cd203993e305237354b69c381547 # Parent a329f9c3d66dc67fef29ad3a53304c96795e2920 Ported dwt.internal.Compatibility diff -r a329f9c3d66d -r 34bfdb096054 dwt/dwthelper/utils.d --- a/dwt/dwthelper/utils.d Fri Aug 22 15:39:51 2008 +0200 +++ b/dwt/dwthelper/utils.d Fri Aug 22 16:31:48 2008 +0200 @@ -507,6 +507,23 @@ bool CharacterIsLetter( dchar c ){ return tango.text.Unicode.isLetter( c ); } + +bool CharacterIsLetterOrDigit( dchar c ){ + return tango.text.Unicode.isLetterOrDigit(c); +} + +bool CharacterIsSpaceChar( dchar c ){ + return tango.text.Unicode.isSpace(c); +} + +struct Character +{ + static alias CharacterIsLetter isLetter; + static alias CharacterIsLetterOrDigit isLetterOrDigit; + static alias CharacterIsSpaceChar isSpaceChar; + static alias CharacterIsWhitespace isWhitespace; +} + public String toUpperCase( String str ){ return tango.text.Unicode.toUpper( str ); } diff -r a329f9c3d66d -r 34bfdb096054 dwt/internal/CloneableCompatibility.d --- a/dwt/internal/CloneableCompatibility.d Fri Aug 22 15:39:51 2008 +0200 +++ b/dwt/internal/CloneableCompatibility.d Fri Aug 22 16:31:48 2008 +0200 @@ -27,6 +27,5 @@ * Note: java.lang.Cloneable is not part of CLDC. *

*/ -public interface CloneableCompatibility : Cloneable -{ +public interface CloneableCompatibility : Cloneable { } diff -r a329f9c3d66d -r 34bfdb096054 dwt/internal/Compatibility.d --- a/dwt/internal/Compatibility.d Fri Aug 22 15:39:51 2008 +0200 +++ b/dwt/internal/Compatibility.d Fri Aug 22 16:31:48 2008 +0200 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2006 IBM Corporation and others. + * Copyright (c) 2000, 2007 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -8,30 +8,31 @@ * Contributors: * IBM Corporation - initial API and implementation * - * Port to the D Programming language: + * Port to the D programming language: + * Frank Benoit * Jacob Carlborg *******************************************************************************/ module dwt.internal.Compatibility; -import Math = tango.math.Math; -import Character = tango.text.Unicode; +import tango.core.Thread; +import tango.sys.Process; import dwt.DWT; - import dwt.dwthelper.BufferedInputStream; -import dwt.dwthelper.File; -import dwt.dwthelper.FileInputStream; -import dwt.dwthelper.FileOutputStream; -import dwt.dwthelper.InputStream; -import dwt.dwthelper.OutputStream; -import java.text.MessageFormat; -import dwt.dwthelper.MissingResourceException; +public import dwt.dwthelper.FileInputStream; +public import dwt.dwthelper.FileOutputStream; +public import dwt.dwthelper.InflaterInputStream; import dwt.dwthelper.ResourceBundle; import dwt.dwthelper.utils; + +/+ +import java.io.File; +import java.text.MessageFormat; +import java.util.MissingResourceException; +import java.util.ResourceBundle; import java.util.zip.DeflaterOutputStream; import java.util.zip.InflaterInputStream; - - ++/ /** * This class is a placeholder for utility methods commonly @@ -43,376 +44,334 @@ *

*

* IMPORTANT: some of the methods have been modified from their - * J2SE parents. Refer to the description of each method for + * J2SE parents. Refer to the description of each method for * specific changes. *

*
    - *
  • Exceptions thrown may differ since J2ME's set of + *
  • Exceptions thrown may differ since J2ME's set of * exceptions is a subset of J2SE's one. *
  • *
  • The range of the mathematic functions is subject to * change. - *
  • + * + *
+ */ +public final class Compatibility { + +/** + * Returns the PI constant as a double. + */ +public static const real PI = Math.PI; + +static const real toRadians = PI / 180; + +/** + * Answers the length of the side adjacent to the given angle + * of a right triangle. In other words, it returns the integer + * conversion of length * cos (angle). + *

+ * IMPORTANT: the j2me version has an additional restriction on + * the argument. length must be between -32767 and 32767 (inclusive). + *

+ * + * @param angle the angle in degrees + * @param length the length of the triangle's hypotenuse + * @return the integer conversion of length * cos (angle) + */ +public static int cos(int angle, int length) { + return cast(int)(Math.cos(angle * toRadians) * length); +} + +/** + * Answers the length of the side opposite to the given angle + * of a right triangle. In other words, it returns the integer + * conversion of length * sin (angle). + *

+ * IMPORTANT: the j2me version has an additional restriction on + * the argument. length must be between -32767 and 32767 (inclusive). + *

+ * + * @param angle the angle in degrees + * @param length the length of the triangle's hypotenuse + * @return the integer conversion of length * sin (angle) + */ +public static int sin(int angle, int length) { + return cast(int)(Math.sin(angle * toRadians) * length); +} + +/** + * Answers the most negative (i.e. closest to negative infinity) + * integer value which is greater than the number obtained by dividing + * the first argument p by the second argument q. + * + * @param p numerator + * @param q denominator (must be different from zero) + * @return the ceiling of the rational number p / q. + */ +public static int ceil(int p, int q) { + return cast(int)Math.ceil(cast(float)p / q); +} + +/** + * Answers whether the indicated file exists or not. + * + * @param parent the file's parent directory + * @param child the file's name + * @return true if the file exists + */ +public static bool fileExists(String parent, String child) { + return (new File (parent, child)).exists(); +} + +/** + * Answers the most positive (i.e. closest to positive infinity) + * integer value which is less than the number obtained by dividing + * the first argument p by the second argument q. + * + * @param p numerator + * @param q denominator (must be different from zero) + * @return the floor of the rational number p / q. + */ +public static int floor(int p, int q) { + return cast(int)Math.floor(cast(double)p / q); +} + +/** + * Answers the result of rounding to the closest integer the number obtained + * by dividing the first argument p by the second argument q. + *

+ * IMPORTANT: the j2me version has an additional restriction on + * the arguments. p must be within the range 0 - 32767 (inclusive). + * q must be within the range 1 - 32767 (inclusive). + *

+ * + * @param p numerator + * @param q denominator (must be different from zero) + * @return the closest integer to the rational number p / q + */ +public static int round(int p, int q) { + return cast(int)Math.round(cast(float)p / q); +} + +/** + * Returns 2 raised to the power of the argument. + * + * @param n an int value between 0 and 30 (inclusive) + * @return 2 raised to the power of the argument + * + * @exception IllegalArgumentException
    + *
  • ERROR_INVALID_RANGE - if the argument is not between 0 and 30 (inclusive)
  • *
*/ -public final class Compatibility -{ - - /** - * Returns the PI constant as a double. - */ - public static double PI = Math.PI; - - static double toRadians = PI / 180; - - /** - * Answers the length of the side adjacent to the given angle - * of a right triangle. In other words, it returns the integer - * conversion of length * cos (angle). - *

- * IMPORTANT: the j2me version has an additional restriction on - * the argument. length must be between -32767 and 32767 (inclusive). - *

- * - * @param angle the angle in degrees - * @param length the length of the triangle's hypotenuse - * @return the integer conversion of length * cos (angle) - */ - public static int cos (int angle, int length) - { - return cast(int) (Math.cos(angle * toRadians) * length); +public static int pow2(int n) { + if (n >= 1 && n <= 30) + return 2 << (n - 1); + else if (n != 0) { + DWT.error(DWT.ERROR_INVALID_RANGE); } + return 1; +} - /** - * Answers the length of the side opposite to the given angle - * of a right triangle. In other words, it returns the integer - * conversion of length * sin (angle). - *

- * IMPORTANT: the j2me version has an additional restriction on - * the argument. length must be between -32767 and 32767 (inclusive). - *

- * - * @param angle the angle in degrees - * @param length the length of the triangle's hypotenuse - * @return the integer conversion of length * sin (angle) - */ - public static int sin (int angle, int length) - { - return cast(int) (Math.sin(angle * toRadians) * length); - } +/** + * Create an DeflaterOutputStream if such things are supported. + * + * @param stream the output stream + * @return a deflater stream or null + * @exception IOException + * + * @since 3.4 + */ +public static OutputStream newDeflaterOutputStream(OutputStream stream) { + implMissing(__FILE__,__LINE__); + return null; + //DWT_TODO return new DeflaterOutputStream(stream); +} - /** - * Answers the most negative (i.e. closest to negative infinity) - * integer value which is greater than the number obtained by dividing - * the first argument p by the second argument q. - * - * @param p numerator - * @param q denominator (must be different from zero) - * @return the ceiling of the rational number p / q. - */ - public static int ceil (int p, int q) - { - return cast(int) Math.ceil(cast(float) p / q); - } +/** + * Open a file if such things are supported. + * + * @param filename the name of the file to open + * @return a stream on the file if it could be opened. + * @exception IOException + */ +public static InputStream newFileInputStream(String filename) { + return new FileInputStream(filename); +} - /** - * Answers whether the indicated file exists or not. - * - * @param parent the file's parent directory - * @param child the file's name - * @return true if the file exists - */ - public static bool fileExists (String parent, String child) - { - return (new File(parent, child)).exists(); - } - - /** - * Answers the most positive (i.e. closest to positive infinity) - * integer value which is less than the number obtained by dividing - * the first argument p by the second argument q. - * - * @param p numerator - * @param q denominator (must be different from zero) - * @return the floor of the rational number p / q. - */ - public static int floor (int p, int q) - { - return cast(int) Math.floor(cast(double) p / q); - } +/** + * Open a file if such things are supported. + * + * @param filename the name of the file to open + * @return a stream on the file if it could be opened. + * @exception IOException + */ +public static OutputStream newFileOutputStream(String filename) { + return new FileOutputStream(filename); +} - /** - * Answers the result of rounding to the closest integer the number obtained - * by dividing the first argument p by the second argument q. - *

- * IMPORTANT: the j2me version has an additional restriction on - * the arguments. p must be within the range 0 - 32767 (inclusive). - * q must be within the range 1 - 32767 (inclusive). - *

- * - * @param p numerator - * @param q denominator (must be different from zero) - * @return the closest integer to the rational number p / q - */ - public static int round (int p, int q) - { - return Math.round(cast(float) p / q); - } +/** + * Create an InflaterInputStream if such things are supported. + * + * @param stream the input stream + * @return a inflater stream or null + * @exception IOException + * + * @since 3.3 + */ +public static InflaterInputStream newInflaterInputStream(InputStream stream) { + return new InflaterInputStream(stream); +} - /** - * Returns 2 raised to the power of the argument. - * - * @param n an int value between 0 and 30 (inclusive) - * @return 2 raised to the power of the argument - * - * @exception IllegalArgumentException
    - *
  • ERROR_INVALID_RANGE - if the argument is not between 0 and 30 (inclusive)
  • - *
- */ - public static int pow2 (int n) - { - if (n >= 1 && n <= 30) - return 2 << (n - 1); - else if (n !is 0) - { - DWT.error(DWT.ERROR_INVALID_RANGE); - } - return 1; - } +/** + * Answers whether the character is a letter. + * + * @param c the character + * @return true when the character is a letter + */ +public static bool isLetter(dchar c) { + return Character.isLetter(c); +} - /** - * Create an DeflaterOutputStream if such things are supported. - * - * @param stream the output stream - * @return a deflater stream or null - * @exception IOException - * - * @since 3.4 - */ - public static OutputStream newDeflaterOutputStream (OutputStream stream) - { - return new DeflaterOutputStream(stream); - } - - /** - * Open a file if such things are supported. - * - * @param filename the name of the file to open - * @return a stream on the file if it could be opened. - * @exception IOException - */ - public static InputStream newFileInputStream (String filename) - { - return new FileInputStream(filename); - } +/** + * Answers whether the character is a letter or a digit. + * + * @param c the character + * @return true when the character is a letter or a digit + */ +public static bool isLetterOrDigit(dchar c) { + return Character.isLetterOrDigit(c); +} - /** - * Open a file if such things are supported. - * - * @param filename the name of the file to open - * @return a stream on the file if it could be opened. - * @exception IOException - */ - public static OutputStream newFileOutputStream (String filename) - { - return new FileOutputStream(filename); - } +/** + * Answers whether the character is a Unicode space character. + * + * @param c the character + * @return true when the character is a Unicode space character + */ +public static bool isSpaceChar(dchar c) { + return Character.isSpaceChar(c); +} - /** - * Create an InflaterInputStream if such things are supported. - * - * @param stream the input stream - * @return a inflater stream or null - * @exception IOException - * - * @since 3.3 - */ - public static InputStream newInflaterInputStream (InputStream stream) - { - return new BufferedInputStream(new InflaterInputStream(stream)); - } +/** + * Answers whether the character is a whitespace character. + * + * @param c the character to test + * @return true if the character is whitespace + */ +public static bool isWhitespace(dchar c) { + return Character.isWhitespace(c); +} - /** - * Answers whether the character is a letter. - * - * @param c the character - * @return true when the character is a letter - */ - public static bool isLetter (char c) - { - return Character.isLetter(c); - } - - /** - * Answers whether the character is a letter or a digit. - * - * @param c the character - * @return true when the character is a letter or a digit - */ - public static bool isLetterOrDigit (char c) - { - return Character.isLetterOrDigit(c); - } - - /** - * Answers whether the character is a Unicode space character. - * - * @param c the character - * @return true when the character is a Unicode space character - */ - public static bool isSpaceChar (char c) - { - return Character.isSpace(c); - } +/** + * Execute a program in a separate platform process if the + * underlying platform support this. + *

+ * The new process inherits the environment of the caller. + *

+ * + * @param prog the name of the program to execute + * + * @exception ProcessException + * if the program cannot be executed + */ +public static void exec(String prog) { + auto proc = new Process( prog ); + proc.execute; +} - /** - * Answers whether the character is a whitespace character. - * - * @param c the character to test - * @return true if the character is whitespace - */ - public static bool isWhitespace (char c) - { - return Character.isWhitespace(c); - } +/** + * Execute progArray[0] in a separate platform process if the + * underlying platform support this. + *

+ * The new process inherits the environment of the caller. + *

+ * + * @param progArray array containing the program to execute and its arguments + * + * @exception ProcessException + * if the program cannot be executed + */ +public static void exec(String[] progArray) { + auto proc = new Process( progArray ); + proc.execute; +} - /** - * Execute a program in a separate platform process if the - * underlying platform support this. - *

- * The new process inherits the environment of the caller. - *

- * - * @param prog the name of the program to execute - * - * @exception IOException - * if the program cannot be executed - * @exception SecurityException - * if the current SecurityManager disallows program execution - */ - public static void exec (String prog) - { - //Runtime.getRuntime().exec(prog); - } +private static ResourceBundle msgs = null; - /** - * Execute progArray[0] in a separate platform process if the - * underlying platform support this. - *

- * The new process inherits the environment of the caller. - *

- * - * @param progArray array containing the program to execute and its arguments - * - * @exception IOException - * if the program cannot be executed - * @exception SecurityException - * if the current SecurityManager disallows program execution - */ - public static void exec (String[] progArray) - { - Runtime.getRuntime().exec(progArray); - } - - private static ResourceBundle msgs = null; +/** + * Returns the NLS'ed message for the given argument. This is only being + * called from DWT. + * + * @param key the key to look up + * @return the message for the given key + * + * @see DWT#getMessage(String) + */ +public static String getMessage(String key) { + String answer = key; - /** - * Returns the NLS'ed message for the given argument. This is only being - * called from DWT. - * - * @param key the key to look up - * @return the message for the given key - * - * @see DWT#getMessage(String) - */ - public static String getMessage (String key) - { - String answer = key; - - if (key is null) - { - DWT.error(DWT.ERROR_NULL_ARGUMENT); + /*if (key is null) { + DWT.error (DWT.ERROR_NULL_ARGUMENT); + }*/ + if (msgs is null) { + try { + msgs = ResourceBundle.getBundle("dwt.internal.SWTMessages"); //$NON-NLS-1$ + } catch (IOException ex) { + answer = key ~ " (no resource bundle)"; //$NON-NLS-1$ } - if (msgs is null) - { - try - { - msgs = ResourceBundle.getBundle("dwt.internal.SWTMessages"); //$NON-NLS-1$ - } - catch (MissingResourceException ex) - { - answer = key + " (no resource bundle)"; //$NON-NLS-1$ - } - } - if (msgs !is null) - { - try - { - answer = msgs.getString(key); - } - catch (MissingResourceException ex2) - { - } - } - return answer; + } + if (msgs !is null) { + try { + answer = msgs.getString(key); + } catch (MissingResourceException ex2) {} } + return answer; +} +/++ PORTING_LEFT +public static String getMessage(String key, Object[] args) { + String answer = key; - public static String getMessage (String key, Object[] args) - { - String answer = key; - - if (key is null || args is null) - { - DWT.error(DWT.ERROR_NULL_ARGUMENT); + if (/*key == null ||*/ args is null) { + DWT.error (DWT.ERROR_NULL_ARGUMENT); + } + if (msgs is null) { + try { + msgs = ResourceBundle.getBundle("dwt.internal.SWTMessages"); //$NON-NLS-1$ + } catch (IOException ex) { + answer = key + " (no resource bundle)"; //$NON-NLS-1$ } - if (msgs is null) - { - try - { - msgs = ResourceBundle.getBundle("dwt.internal.SWTMessages"); //$NON-NLS-1$ - } - catch (MissingResourceException ex) - { - answer = key + " (no resource bundle)"; //$NON-NLS-1$ - } - } - if (msgs !is null) - { - try - { - MessageFormat formatter = new MessageFormat(""); - formatter.applyPattern(msgs.getString(key)); - answer = formatter.format(args); - } - catch (MissingResourceException ex2) - { - } - } - return answer; + } + if (msgs !is null) { + try { + MessageFormat formatter = new MessageFormat(""); + formatter.applyPattern(msgs.getString(key)); + answer = formatter.format(args); + } catch (MissingResourceException ex2) {} } - - /** - * Interrupt the current thread. - *

- * Note that this is not available on CLDC. - *

- */ - public static void interrupt () - { - Thread.currentThread().interrupt(); - } + return answer; +} ++/ +/** + * Interrupt the current thread. + *

+ * Note that this is not available on CLDC. + *

+ */ +public static void interrupt() { + //PORTING_FIXME: how to implement?? + //Thread.currentThread().interrupt(); +} - /** - * Compares two instances of class String ignoring the case of the - * characters and answers if they are equal. - * - * @param s1 string - * @param s2 string - * @return true if the two instances of class String are equal - */ - public static bool equalsIgnoreCase (String s1, String s2) - { - return s1.equalsIgnoreCase(s2); - } +/** + * Compares two instances of class String ignoring the case of the + * characters and answers if they are equal. + * + * @param s1 string + * @param s2 string + * @return true if the two instances of class String are equal + */ +public static bool equalsIgnoreCase(String s1, String s2) { + return s1.equalsIgnoreCase(s2); +} }