Logo Search packages:      
Sourcecode: javamorph version File versions  Download package

CStrings.java

package javamorph;

import java.io.*;
import javax.swing.*;

/**
 * @version 1.1
 * <br/>
 * @author claus.erhard.wimmer@googlemail.com
 * <br/>
 * Program: JavaMorph V 1.1.
 * <br/>
 * Class: CStrings.
 * <br/>
 * License: GPLv2.
 * <br/>
 * Description: Collection of directory names.
 * <br/>
 * Hint: Defines the working directory at the desktop & its subdirectories.
 */
00021 public class CStrings {
    /** File separator depending on OS. */
00023     public static final String SEP = System.getProperty("file.separator");
    /** User's home. */
00025     public static final String HOME = System.getProperty("user.home") + SEP;
    /** Dir from which this application has been started. */
00027     public static final String DIR = System.getProperty("user.dir");
    /** Location of the .jar distribution file. */
00029     public static final String JAR = DIR + SEP + "JavaMorph_2009_01_19.jar";
    /** Program name. */
00031     public static final String PROG = "JavaMorph";
    /** Program version. */
00033     public static final String VERSION = "V 1.1";
    /** Author of the program. */
00035     public static final String AUTHOR = "claus.erhard.wimmer@googlemail.com";
    /** License description. */
00037     public static final String LICENSE = "GPLv2";
    /** Working directory name. */
00039     public static final String APPDIR = "Desktop" + SEP + PROG + SEP;
    /** Working directory path. */
00041     public static final String WORKDIR = HOME + APPDIR;
    /** Input directory path. */
00043     public static final String INPUTDIR = HOME + APPDIR + "input" + SEP;
    /** Debug directory path. */
00045     public static final String DEBUGDIR = HOME + APPDIR + "debug" + SEP;
    /** Help directory path. */
00047     public static final String HELPDIR = HOME + APPDIR + "help" + SEP;
    /** Polygon data directory path. */
00049     public static final String POLYGONDIR = HOME + APPDIR + "polygon" + SEP;
    /** Mesh data directory path. */
00051     public static final String MESHDIR = HOME + APPDIR + "mesh" + SEP;
    /** Output directory path. */
00053     public static final String OUTPUTDIR = WORKDIR + "output" + SEP;
    /** Property file name & path. */
00055     public static final String PROPS = WORKDIR + "properties.props";
    /** Left input picture file name & path. */
00057     public static final String LEFT_INPUT = INPUTDIR + "left.jpg";
    /** Right input picture file name & path. */
00059     public static final String RIGHT_INPUT = INPUTDIR + "right.jpg";
    /** Left mesh data file name & path. */
00061     public static final String LEFT_MESH = MESHDIR + "left.msh";
    /** Right mesh data file name & path. */
00063     public static final String RIGHT_MESH = MESHDIR + "right.msh";
    /** Left polygon data file name & path. */
00065     public static final String LEFT_POLYGON = POLYGONDIR + "left.pol";
    /** Right polygon data file name & path. */
00067     public static final String RIGHT_POLYGON = POLYGONDIR + "right.pol";
    /** Left clip matrix file name & path. */
00069     public static final String LEFT_DEBUG = DEBUGDIR + "left_debug.png";
    /** Right clip matrix file name & path. */
00071     public static final String RIGHT_DEBUG = DEBUGDIR + "right_debug.png";
    /** Help file name & path. */
00073     public static final String HELP = HELPDIR + "JavaMorph.pdf";
    /** File to store the triangulation of the left mesh to. */
00075     public static final String LEFT_TRI = DEBUGDIR + "t_left_triangles.png";
    /** File to store the triangulation of the right mesh to. */
00077     public static final String RIGHT_TRI = DEBUGDIR + "t_right_triangles.png";
    /** File to store the triangulation of the 50% merged mesh to. */
00079     public static final String MIDDLE_TRI = DEBUGDIR + "t_middle_triangles.png";
    /** Left file name prefix. */
00081     public static final String LEFT_PREFIX = "left";
    /** Right file name prefix. */
00083     public static final String RIGHT_PREFIX = "right";
    
    /**
     * Compose the name of one result output file.
     * @param n Number of the morph step.
     * @return Filename consisting of 3 numerical digits + extension.
     */
00090     public static String getOutput(int n){
        String str_n = "" + n;
        while(3 > str_n.length()){
           str_n = "0" + str_n;
        }
        return OUTPUTDIR + str_n + ".jpg";
    }
    /**
     * Called if the application is called for the first time on one PC.
     * Try to copy the sample data from the .jar distribution file into the 
     * working directory. Create sub directories therefore.
     * @return <code>true</code>if the copy process has been successful.
     */
00103     public static boolean initialize(){
        try{
            File 
                work = new File(WORKDIR),
                input = new File(INPUTDIR),
                output = new File(OUTPUTDIR),
                polygon = new File(POLYGONDIR),
                mesh = new File(MESHDIR),
                help = new File(HELPDIR),
                debug = new File(DEBUGDIR);
            if(!work.exists()){
                if(JOptionPane.YES_OPTION ==
                        JOptionPane.showConfirmDialog(null, 
                        "Workdir = " + WORKDIR + " doesn't exist, create?")){
                    work.mkdir();
                    input.mkdir();
                    output.mkdir();
                    mesh.mkdir();
                    polygon.mkdir();
                    help.mkdir();
                    debug.mkdir();
                    extractFiles();
                    JOptionPane.showMessageDialog(null,
                    "Please handle app's files within the following workdir = " 
                    + WORKDIR + '!');
                    return true;
                }else{
                    JOptionPane.showMessageDialog(null, 
                            "Don't create workdir = " + WORKDIR + ", exit now");
                    return false;
                }
            }else{
                return true;
            }
        }catch(Exception e){
            System.err.println(e.getMessage());
            e.printStackTrace();
            JOptionPane.showMessageDialog(null,
            "Can't create workdir (" + WORKDIR + "), see console output!");
            return false;
        }
    }
    /**
     * Extract files from the .jar distribution into the generated
     * sub directories of the working directory.
     */
00149     public static void extractFiles(){
        copyFile("help/JavaMorph.pdf", HELP);
        copyFile("input/left.jpg", LEFT_INPUT);
        copyFile("input/right.jpg", RIGHT_INPUT);
        copyFile("mesh/left.msh", LEFT_MESH);
        copyFile("mesh/right.msh", RIGHT_MESH);
        copyFile("polygon/left.pol", LEFT_POLYGON);
        copyFile("polygon/right.pol", RIGHT_POLYGON);
    }
    /**
     * Copy one single file from the .jar distribution into the sub directory
     * of the working directory.
     * @param in Location of the .jar file entry.
     * @param out Target path & name of the file to copy the content to.
     */
00164     public static void copyFile(String in, String out){
        try{
            ClassLoader loader = ClassLoader.getSystemClassLoader();
            InputStream raw = loader.getResourceAsStream(in);
            BufferedInputStream bin = new BufferedInputStream(raw);
            BufferedOutputStream bout = 
                new BufferedOutputStream(new FileOutputStream(out));
            int i;
            while(-1 != (i = bin.read()))bout.write(i);
            bin.close();
            bout.close();
        }catch(Exception e){
            System.out.println("in = " + in + '.');
            System.out.println("out = " + out + '.');
            System.err.println(e.getMessage());
            System.out.println("in = " + in + '.');
            System.out.println("out = " + out + '.');
            e.printStackTrace();
            JOptionPane.showMessageDialog(null,
            "Can't copy file (" + out + "), see console output!");
        }           
    }
}

Generated by  Doxygen 1.6.0   Back to index