001    /*
002     * jiuawt
003     * 
004     * Copyright (c) 2000, 2001, 2002, 2003 Marco Schmidt.
005     * All rights reserved.
006     */
007    
008    package net.sourceforge.jiu.apps;
009    
010    import net.sourceforge.jiu.apps.EditorState;
011    import net.sourceforge.jiu.gui.awt.JiuAwtFrame;
012    import net.sourceforge.jiu.util.SystemInfo;
013    
014    /**
015     * Graphical user interface application based on the AWT (Abstract
016     * Windowing Toolkit, part of Java's standard runtime library since 1.0) 
017     * that demonstrates features of JIU.
018     * <p>
019     * <h3>Memory shortage</h3>
020     * One of the errors experienced most frequently with jiuawt is the 
021     * 'out of memory' error.
022     * Note that only whoever starts jiuawt can give it more memory by
023     * giving more memory to the Java virtual machine.
024     * Example:
025     * <pre>java -mx300m jiu.jar</pre>
026     * starts jiuawt and provides it with 300 MB of memory.
027     *
028     * <h3>Command line switches</h3>
029     * <dl>
030     * <dt><code>--dir DIRECTORY</code>
031     * <dd>set working directory to <code>DIRECTORY</code>
032     * <dt><code>--help</code>
033     * <dd>print help screen to standard output and exit
034     * <dt><code>--lang LANGUAGE</code>
035     * <dd>set language to <code>LANGUAGE</code>, where <code>en</code> is English, <code>de</code> is German and <code>es</code> is Spanish
036     * <dt><code>--system</code>
037     * <dd>print system information to standard output and exit
038     * <dt><code>--version</code>
039     * <dd>print version information to standard output and exit
040     * </dl>
041     * @author Marco Schmidt
042     */
043    public class jiuawt
044    {
045            private jiuawt()
046            {
047            }
048    
049            /**
050             * Creates a {@link JiuAwtFrame} object.
051             * @param args program arguments, call jiuawt with <code>--help</code> as single argument to get a help screen
052             */
053            public static void main(String[] args)
054            {
055                    EditorState state = new EditorState();
056                    int index = 0;
057                    while (index < args.length)
058                    {
059                            String s = args[index++];
060                            if ("--dir".equals(s))
061                            {
062                                    if (index == args.length)
063                                    {
064                                            throw new IllegalArgumentException("Directory switch must be followed by a directory name.");
065                                    }
066                                    state.setCurrentDirectory(args[index++]);
067                            }
068                            else
069                            if ("--help".equals(s))
070                            {
071                                    printVersion();
072                                    System.out.println();
073                                    System.out.println("Usage: jiuawt [OPTIONS] [FILE]");
074                                    System.out.println("\tFILE is the name of an image file to be loaded after start-up");
075                                    System.out.println("\t--dir  DIRECTORY  set working directory to DIRECTORY");
076                                    System.out.println("\t--help            print this help screen and exit");
077                                    System.out.println("\t--lang LANGCODE   set language to LANGCODE (de=German, en=English, es=Spanish)");
078                                    System.out.println("\t--system          print system info and exit");
079                                    System.out.println("\t--version         print version information and exit");
080                                    System.exit(0);
081                            }
082                            else
083                            if ("--lang".equals(s))
084                            {
085                                    if (index == args.length)
086                                    {
087                                            throw new IllegalArgumentException("Language switch must be followed by language code.");
088                                    }
089                                    state.setStrings(args[index++]);
090                            }
091                            else
092                            if ("--system".equals(s))
093                            {
094                                    String info = SystemInfo.getSystemInfo(state.getStrings());
095                                    System.out.println(info);
096                                    System.exit(0);
097                            }
098                            else
099                            if ("--version".equals(s))
100                            {
101                                    printVersion();
102                                    System.exit(0);
103                            }
104                            else
105                            {
106                                    if (s.startsWith("-"))
107                                    {
108                                            throw new IllegalArgumentException("Unknown switch: " + s);
109                                    }
110                                    else
111                                    {
112                                            state.setStartupImageName(s);
113                                    }
114                            }
115                    }
116                    state.ensureStringsAvailable();
117                    new JiuAwtFrame(state);
118            }
119    
120            private static void printVersion()
121            {
122                    System.out.println("jiuawt " + JiuInfo.JIU_VERSION);
123                    System.out.println("An image editing program as a demo for the JIU image processing library.");
124                    System.out.println("Written by Marco Schmidt.");
125                    System.out.println("Visit the JIU website at <" + JiuInfo.JIU_HOMEPAGE + ">.");
126            }
127    }