[Ejtools-cvs] libraries/common/src/main/org/ejtools/util FileTools.java,NONE,1.1 package.html,NONE,1
Brought to you by:
letiemble
Update of /cvsroot/ejtools/libraries/common/src/main/org/ejtools/util In directory sc8-pr-cvs1:/tmp/cvs-serv18971/common/src/main/org/ejtools/util Modified Files: ClassTools.java KeyLimitedStack.java LimitedStack.java Platform.java Added Files: FileTools.java package.html Log Message: Add more javadocs. Add package.html files. --- NEW FILE: FileTools.java --- /* * EJTools, the Enterprise Java Tools * * Distributable under LGPL license. * See terms of license at www.gnu.org. */ package org.ejtools.util; import java.io.File; import java.text.MessageFormat; import java.util.ResourceBundle; import javax.swing.JFileChooser; import javax.swing.JOptionPane; import javax.swing.filechooser.FileFilter; /** * Helper class to make easy the file selection. Handles the overwrite in case of * save actions. * * @author Laurent Etiemble * @version $Revision: 1.1 $ */ public class FileTools { /** Resource bundle */ private static ResourceBundle resources = ResourceBundle.getBundle("org.ejtools.util.Resources"); /** Default constructor */ protected FileTools() { } /** * Select a file through a JFileChooser. * * @param title The title for the JFileChooser * @param approveText The text that appears on the approve button * @param type The type of operation * @param filter The FileFilter to use * @return The selected file otherwise null * @see javax.swing.JFileChooser#OPEN_DIALOG * @see javax.swing.JFileChooser#SAVE_DIALOG */ public static File selectFile(String title, String approveText, int type, FileFilter filter) { File selectedFile = null; // Fix for JFileChooser/SecurityManager bug (#4264750) SecurityManager s = System.getSecurityManager(); System.setSecurityManager(null); // Choose file JFileChooser chooser = new JFileChooser(System.getProperty("user.dir")); chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); chooser.setDialogTitle(title); chooser.setDialogType(type); chooser.setFileFilter(filter); int returnVal = chooser.showDialog(null, approveText); System.setSecurityManager(s); if (returnVal == JFileChooser.APPROVE_OPTION) { selectedFile = chooser.getSelectedFile(); } if ((selectedFile != null) && (type == JFileChooser.SAVE_DIALOG) && (selectedFile.exists())) { int ret = JOptionPane.showConfirmDialog(null, MessageFormat.format(resources.getString("file.dialog.overwrite.text"), new Object[]{selectedFile.getName()})); if (ret != JOptionPane.OK_OPTION) { selectedFile = null; } } return selectedFile; } /** * An helper class that simplifies the creation of a FileFilter. * * @author Laurent Etiemble * @version $Revision: 1.1 $ */ protected static class SimpleFileFilter extends FileFilter { private String description; private String extension; /** * Constructor for SimpleFileFilter class * * @param extension The file extension. Must start with a dot. * @param description The description that will appears in the JFileChooser */ public SimpleFileFilter(String extension, String description) { this.extension = extension; this.description = description; } /** * Check wheter or not the file ends with the right extension. * * @param file The file to test * @return True if the file is accepted */ public boolean accept(File file) { return file.getName().endsWith(this.extension); } /** * Returns the description string for displaying inside the JFileChooser * * @return The description */ public String getDescription() { return this.description; } } } --- NEW FILE: package.html --- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"> <!-- EJTools, the Enterprise Java Tools Distributable under LGPL license. See terms of license at www.gnu.org. $Revision: 1.1 $ --> <html> <head/> <body> </body> </html> Index: ClassTools.java =================================================================== RCS file: /cvsroot/ejtools/libraries/common/src/main/org/ejtools/util/ClassTools.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** ClassTools.java 15 Sep 2003 22:23:45 -0000 1.6 --- ClassTools.java 13 Dec 2003 21:27:49 -0000 1.7 *************** *** 1,189 **** ! /* ! * EJTools, the Enterprise Java Tools ! * ! * Distributable under LGPL license. ! * See terms of license at www.gnu.org. ! */ ! package org.ejtools.util; ! ! import java.util.ArrayList; ! ! ! /** ! * Utility class to handle Class realted stuff. ! * ! * @author Laurent Etiemble ! * @version $Revision$ ! */ ! public class ClassTools ! { ! /** Holds the numeric classes */ ! private static ArrayList numericClasses; ! ! ! /** ! * Pretty print a full qualified class name. Specially useful for object arrays. ! * ! * @param className The fully qualified class name ! * @return The pretty class name ! */ ! public static String classDisplay(String className) ! { ! String result = className; ! ! if (className == null) ! { ! return null; ! } ! ! if (className.startsWith("[Z")) ! { ! result = "boolean[]"; ! } ! if (className.startsWith("[C")) ! { ! result = "char[]"; ! } ! if (className.startsWith("[D")) ! { ! result = "double[]"; ! } ! if (className.startsWith("[F")) ! { ! result = "float[]"; ! } ! if (className.startsWith("[I")) ! { ! result = "int[]"; ! } ! if (className.startsWith("[S")) ! { ! result = "short[]"; ! } ! if (className.startsWith("[J")) ! { ! result = "long[]"; ! } ! if (className.startsWith("[B")) ! { ! result = "byte[]"; ! } ! if (className.startsWith("[L")) ! { ! result = className.substring(2, className.length() - 1) + "[]"; ! } ! ! return result; ! } ! ! ! /** ! * Get the class by its name. ! * ! * @param fullPathClassName The full qualified name of the class ! * @return The class if it is found, otherwise null ! */ ! public static Class getClass(String fullPathClassName) ! { ! // Check if the class is a primitive type ! if (fullPathClassName.equals("void")) ! { ! return Void.TYPE; ! } ! if (fullPathClassName.equals("int")) ! { ! return Integer.TYPE; ! } ! if (fullPathClassName.equals("short")) ! { ! return Short.TYPE; ! } ! if (fullPathClassName.equals("long")) ! { ! return Long.TYPE; ! } ! if (fullPathClassName.equals("byte")) ! { ! return Byte.TYPE; ! } ! if (fullPathClassName.equals("char")) ! { ! return Character.TYPE; ! } ! if (fullPathClassName.equals("float")) ! { ! return Float.TYPE; ! } ! if (fullPathClassName.equals("double")) ! { ! return Double.TYPE; ! } ! if (fullPathClassName.equals("boolean")) ! { ! return Boolean.TYPE; ! } ! ! // Try to load the class ! Class c = null; ! try ! { ! c = Class.forName(fullPathClassName); ! } ! catch (Throwable e) ! { ! // Ignore it ! } ! ! return c; ! } ! ! ! /** ! * Get the double value from a numeric class ! * ! * @param o Object to transform ! * @return The double value ! */ ! public static double getValue(Object o) ! { ! if (isNumeric(o.getClass())) ! { ! if (o instanceof Number) ! { ! return ((Number) o).doubleValue(); ! } ! return (new Double(o.toString())).doubleValue(); ! } ! return 0; ! } ! ! ! /** ! * Return whether or not a class is numeric ! * ! * @param clazz The class to test ! * @return true if the class is numeric ! */ ! public static boolean isNumeric(Class clazz) ! { ! return numericClasses.contains(clazz); ! } ! ! /** fill in with the numeric classes */ ! static ! { ! numericClasses = new ArrayList(); ! numericClasses.add(Byte.class); ! numericClasses.add(Double.class); ! numericClasses.add(Float.class); ! numericClasses.add(Integer.class); ! numericClasses.add(Long.class); ! numericClasses.add(Short.class); ! numericClasses.add(Byte.TYPE); ! numericClasses.add(Double.TYPE); ! numericClasses.add(Float.TYPE); ! numericClasses.add(Integer.TYPE); ! numericClasses.add(Long.TYPE); ! numericClasses.add(Short.TYPE); ! } ! } --- 1,189 ---- ! /* ! * EJTools, the Enterprise Java Tools ! * ! * Distributable under LGPL license. ! * See terms of license at www.gnu.org. ! */ ! package org.ejtools.util; ! ! import java.util.ArrayList; ! ! ! /** ! * Utility class to handle Class realted stuff. ! * ! * @author Laurent Etiemble ! * @version $Revision$ ! */ ! public class ClassTools ! { ! /** Holds the numeric classes */ ! private static ArrayList numericClasses; ! ! ! /** ! * Pretty print a full qualified class name. Specially useful for object arrays. ! * ! * @param className The fully qualified class name ! * @return The pretty class name ! */ ! public static String classDisplay(String className) ! { ! String result = className; ! ! if (className == null) ! { ! return null; ! } ! ! if (className.startsWith("[Z")) ! { ! result = "boolean[]"; ! } ! if (className.startsWith("[C")) ! { ! result = "char[]"; ! } ! if (className.startsWith("[D")) ! { ! result = "double[]"; ! } ! if (className.startsWith("[F")) ! { ! result = "float[]"; ! } ! if (className.startsWith("[I")) ! { ! result = "int[]"; ! } ! if (className.startsWith("[S")) ! { ! result = "short[]"; ! } ! if (className.startsWith("[J")) ! { ! result = "long[]"; ! } ! if (className.startsWith("[B")) ! { ! result = "byte[]"; ! } ! if (className.startsWith("[L")) ! { ! result = className.substring(2, className.length() - 1) + "[]"; ! } ! ! return result; ! } ! ! ! /** ! * Get the class by its name. ! * ! * @param fullPathClassName The full qualified name of the class ! * @return The class if it is found, otherwise null ! */ ! public static Class getClass(String fullPathClassName) ! { ! // Check if the class is a primitive type ! if (fullPathClassName.equals("void")) ! { ! return Void.TYPE; ! } ! if (fullPathClassName.equals("int")) ! { ! return Integer.TYPE; ! } ! if (fullPathClassName.equals("short")) ! { ! return Short.TYPE; ! } ! if (fullPathClassName.equals("long")) ! { ! return Long.TYPE; ! } ! if (fullPathClassName.equals("byte")) ! { ! return Byte.TYPE; ! } ! if (fullPathClassName.equals("char")) ! { ! return Character.TYPE; ! } ! if (fullPathClassName.equals("float")) ! { ! return Float.TYPE; ! } ! if (fullPathClassName.equals("double")) ! { ! return Double.TYPE; ! } ! if (fullPathClassName.equals("boolean")) ! { ! return Boolean.TYPE; ! } ! ! // Try to load the class ! Class c = null; ! try ! { ! c = Class.forName(fullPathClassName); ! } ! catch (Throwable e) ! { ! // Ignore it ! } ! ! return c; ! } ! ! ! /** ! * Get the double value from a numeric class ! * ! * @param o Object to transform ! * @return The double value ! */ ! public static double getValue(Object o) ! { ! if (isNumeric(o.getClass())) ! { ! if (o instanceof Number) ! { ! return ((Number) o).doubleValue(); ! } ! return (new Double(o.toString())).doubleValue(); ! } ! return 0; ! } ! ! ! /** ! * Return whether or not a class is numeric ! * ! * @param clazz The class to test ! * @return true if the class is numeric ! */ ! public static boolean isNumeric(Class clazz) ! { ! return numericClasses.contains(clazz); ! } ! ! /** fill in with the numeric classes */ ! static ! { ! numericClasses = new ArrayList(); ! numericClasses.add(Byte.class); ! numericClasses.add(Double.class); ! numericClasses.add(Float.class); ! numericClasses.add(Integer.class); ! numericClasses.add(Long.class); ! numericClasses.add(Short.class); ! numericClasses.add(Byte.TYPE); ! numericClasses.add(Double.TYPE); ! numericClasses.add(Float.TYPE); ! numericClasses.add(Integer.TYPE); ! numericClasses.add(Long.TYPE); ! numericClasses.add(Short.TYPE); ! } ! } Index: KeyLimitedStack.java =================================================================== RCS file: /cvsroot/ejtools/libraries/common/src/main/org/ejtools/util/KeyLimitedStack.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** KeyLimitedStack.java 15 Sep 2003 22:23:45 -0000 1.6 --- KeyLimitedStack.java 13 Dec 2003 21:27:49 -0000 1.7 *************** *** 1,61 **** ! /* ! * EJTools, the Enterprise Java Tools ! * ! * Distributable under LGPL license. ! * See terms of license at www.gnu.org. ! */ ! package org.ejtools.util; ! ! ! /** ! * Extension of the Limited Stack class, which doesn't allow duplicates. ! * ! * @author Laurent Etiemble ! * @version $Revision$ ! */ ! public class KeyLimitedStack extends LimitedStack ! { ! /** Constructor for KeyLimitedStack. */ ! public KeyLimitedStack() ! { ! super(); ! } ! ! ! /** ! * Constructor for KeyLimitedStack. ! * ! * @param size ! */ ! public KeyLimitedStack(int size) ! { ! super(size); ! } ! ! ! /** ! * Overrides the push method to limit the number of elements and skip duplicates. ! * ! * @param item Item to push onto the stack ! * @return The item pushed ! */ ! public Object push(Object item) ! { ! // Remove duplicate ! if (this.contains(item)) ! { ! this.remove(this.indexOf(item)); ! } ! else ! { ! // If size is exceeded, remove the first in ! if (this.size() >= this.maximumSize) ! { ! this.remove(0); ! } ! } ! ! // Push the item ! return super.push(item); ! } ! } --- 1,61 ---- ! /* ! * EJTools, the Enterprise Java Tools ! * ! * Distributable under LGPL license. ! * See terms of license at www.gnu.org. ! */ ! package org.ejtools.util; ! ! ! /** ! * Extension of the Limited Stack class, which doesn't allow duplicates. ! * ! * @author Laurent Etiemble ! * @version $Revision$ ! */ ! public class KeyLimitedStack extends LimitedStack ! { ! /** Constructor for KeyLimitedStack. */ ! public KeyLimitedStack() ! { ! super(); ! } ! ! ! /** ! * Constructor for KeyLimitedStack. ! * ! * @param size ! */ ! public KeyLimitedStack(int size) ! { ! super(size); ! } ! ! ! /** ! * Overrides the push method to limit the number of elements and skip duplicates. ! * ! * @param item Item to push onto the stack ! * @return The item pushed ! */ ! public Object push(Object item) ! { ! // Remove duplicate ! if (this.contains(item)) ! { ! this.remove(this.indexOf(item)); ! } ! else ! { ! // If size is exceeded, remove the first in ! if (this.size() >= this.maximumSize) ! { ! this.remove(0); ! } ! } ! ! // Push the item ! return super.push(item); ! } ! } Index: LimitedStack.java =================================================================== RCS file: /cvsroot/ejtools/libraries/common/src/main/org/ejtools/util/LimitedStack.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** LimitedStack.java 15 Sep 2003 22:23:45 -0000 1.6 --- LimitedStack.java 13 Dec 2003 21:27:49 -0000 1.7 *************** *** 1,59 **** ! /* ! * EJTools, the Enterprise Java Tools ! * ! * Distributable under LGPL license. ! * See terms of license at www.gnu.org. ! */ ! package org.ejtools.util; ! ! import java.util.Stack; ! ! /** ! * Extension of the Stack class, which has a limited depth (FIFO stack). This class doesn't allow duplicates. ! * ! * @author Laurent Etiemble ! * @version $Revision$ ! */ ! public class LimitedStack extends Stack ! { ! /** Maximum number elements allowed in the stack */ ! protected int maximumSize; ! ! ! /** Constructor for the LimitedStack object */ ! public LimitedStack() ! { ! this(10); ! } ! ! ! /** ! * Constructor for the LimitedStack object ! * ! * @param size Depth size of the stack ! */ ! public LimitedStack(int size) ! { ! this.maximumSize = size; ! } ! ! ! /** ! * Overrides the push method to limit the number of elements. ! * ! * @param item Item to push onto the stack ! * @return The item pushed ! */ ! public Object push(Object item) ! { ! // If size is exceeded, remove the first in ! if (this.size() >= this.maximumSize) ! { ! this.remove(0); ! } ! ! // Push the item ! return super.push(item); ! } ! } ! --- 1,59 ---- ! /* ! * EJTools, the Enterprise Java Tools ! * ! * Distributable under LGPL license. ! * See terms of license at www.gnu.org. ! */ ! package org.ejtools.util; ! ! import java.util.Stack; ! ! /** ! * Extension of the Stack class, which has a limited depth (FIFO stack). This class doesn't allow duplicates. ! * ! * @author Laurent Etiemble ! * @version $Revision$ ! */ ! public class LimitedStack extends Stack ! { ! /** Maximum number elements allowed in the stack */ ! protected int maximumSize; ! ! ! /** Constructor for the LimitedStack object */ ! public LimitedStack() ! { ! this(10); ! } ! ! ! /** ! * Constructor for the LimitedStack object ! * ! * @param size Depth size of the stack ! */ ! public LimitedStack(int size) ! { ! this.maximumSize = size; ! } ! ! ! /** ! * Overrides the push method to limit the number of elements. ! * ! * @param item Item to push onto the stack ! * @return The item pushed ! */ ! public Object push(Object item) ! { ! // If size is exceeded, remove the first in ! if (this.size() >= this.maximumSize) ! { ! this.remove(0); ! } ! ! // Push the item ! return super.push(item); ! } ! } ! Index: Platform.java =================================================================== RCS file: /cvsroot/ejtools/libraries/common/src/main/org/ejtools/util/Platform.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** Platform.java 15 Sep 2003 22:23:45 -0000 1.1 --- Platform.java 13 Dec 2003 21:27:49 -0000 1.2 *************** *** 1,91 **** ! /* ! * EJTools, the Enterprise Java Tools ! * ! * Distributable under LGPL license. ! * See terms of license at www.gnu.org. ! */ ! package org.ejtools.util; ! ! ! /** ! * Description of the Class ! * ! * @author Laurent Etiemble ! * @version $Revision$ ! */ ! public class Platform ! { ! /** Description of the Field */ ! private static String JAVA_VERSION; ! /** Description of the Field */ ! public final static boolean IS_JAVA_1_1 = Platform.getJavaVersionMatches(Platform.JAVA_1_1); ! /** Description of the Field */ ! public final static boolean IS_JAVA_1_2 = Platform.getJavaVersionMatches(Platform.JAVA_1_2); ! /** Description of the Field */ ! public final static boolean IS_JAVA_1_3 = Platform.getJavaVersionMatches(Platform.JAVA_1_3); ! /** Description of the Field */ ! public final static boolean IS_JAVA_1_4 = Platform.getJavaVersionMatches(Platform.JAVA_1_4); ! /** Description of the Field */ ! public final static boolean IS_JAVA_1_5 = Platform.getJavaVersionMatches(Platform.JAVA_1_5); ! /** Description of the Field */ ! public final static String JAVA_1_1 = "1.1"; ! /** Description of the Field */ ! public final static String JAVA_1_2 = "1.2"; ! /** Description of the Field */ ! public final static String JAVA_1_3 = "1.3"; ! /** Description of the Field */ ! public final static String JAVA_1_4 = "1.4"; ! /** Description of the Field */ ! public final static String JAVA_1_5 = "1.5"; ! ! ! /** Avoid instantiation */ ! private Platform() { } ! ! ! /** ! * Gets the javaVersion attribute of the Platform class ! * ! * @return The javaVersion value ! */ ! public static String getJavaVersion() ! { ! if (JAVA_VERSION == null) ! { ! JAVA_VERSION = System.getProperty("java.version"); ! } ! return JAVA_VERSION; ! } ! ! ! /** ! * Gets the javaVersionCompatible attribute of the Platform class ! * ! * @param version Description of the Parameter ! * @return The javaVersionCompatible value ! */ ! public static boolean isJavaVersionCompatible(String version) ! { ! if (getJavaVersion() == null) ! { ! return false; ! } ! return (JAVA_VERSION.compareTo(version) >= 0); ! } ! ! ! /** ! * Gets the javaVersionMatches attribute of the Platform class ! * ! * @param versionPrefix Description of the Parameter ! * @return The javaVersionMatches value ! */ ! private static boolean getJavaVersionMatches(String versionPrefix) ! { ! if (getJavaVersion() == null) ! { ! return false; ! } ! return JAVA_VERSION.startsWith(versionPrefix); ! } ! } --- 1,91 ---- ! /* ! * EJTools, the Enterprise Java Tools ! * ! * Distributable under LGPL license. ! * See terms of license at www.gnu.org. ! */ ! package org.ejtools.util; ! ! ! /** ! * Description of the Class ! * ! * @author Laurent Etiemble ! * @version $Revision$ ! */ ! public class Platform ! { ! /** Description of the Field */ ! private static String JAVA_VERSION; ! /** Description of the Field */ ! public final static boolean IS_JAVA_1_1 = Platform.getJavaVersionMatches(Platform.JAVA_1_1); ! /** Description of the Field */ ! public final static boolean IS_JAVA_1_2 = Platform.getJavaVersionMatches(Platform.JAVA_1_2); ! /** Description of the Field */ ! public final static boolean IS_JAVA_1_3 = Platform.getJavaVersionMatches(Platform.JAVA_1_3); ! /** Description of the Field */ ! public final static boolean IS_JAVA_1_4 = Platform.getJavaVersionMatches(Platform.JAVA_1_4); ! /** Description of the Field */ ! public final static boolean IS_JAVA_1_5 = Platform.getJavaVersionMatches(Platform.JAVA_1_5); ! /** Description of the Field */ ! public final static String JAVA_1_1 = "1.1"; ! /** Description of the Field */ ! public final static String JAVA_1_2 = "1.2"; ! /** Description of the Field */ ! public final static String JAVA_1_3 = "1.3"; ! /** Description of the Field */ ! public final static String JAVA_1_4 = "1.4"; ! /** Description of the Field */ ! public final static String JAVA_1_5 = "1.5"; ! ! ! /** Avoid instantiation */ ! private Platform() { } ! ! ! /** ! * Gets the javaVersion attribute of the Platform class ! * ! * @return The javaVersion value ! */ ! public static String getJavaVersion() ! { ! if (JAVA_VERSION == null) ! { ! JAVA_VERSION = System.getProperty("java.version"); ! } ! return JAVA_VERSION; ! } ! ! ! /** ! * Gets the javaVersionCompatible attribute of the Platform class ! * ! * @param version Description of the Parameter ! * @return The javaVersionCompatible value ! */ ! public static boolean isJavaVersionCompatible(String version) ! { ! if (getJavaVersion() == null) ! { ! return false; ! } ! return (JAVA_VERSION.compareTo(version) >= 0); ! } ! ! ! /** ! * Gets the javaVersionMatches attribute of the Platform class ! * ! * @param versionPrefix Description of the Parameter ! * @return The javaVersionMatches value ! */ ! private static boolean getJavaVersionMatches(String versionPrefix) ! { ! if (getJavaVersion() == null) ! { ! return false; ! } ! return JAVA_VERSION.startsWith(versionPrefix); ! } ! } |