1   /**
2    * Distribution License:
3    * JSword is free software; you can redistribute it and/or modify it under
4    * the terms of the GNU Lesser General Public License, version 2.1 as published by
5    * the Free Software Foundation. This program is distributed in the hope
6    * that it will be useful, but WITHOUT ANY WARRANTY; without even the
7    * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
8    * See the GNU Lesser General Public License for more details.
9    *
10   * The License is available on the internet at:
11   *       http://www.gnu.org/copyleft/lgpl.html
12   * or by writing to:
13   *      Free Software Foundation, Inc.
14   *      59 Temple Place - Suite 330
15   *      Boston, MA 02111-1307, USA
16   *
17   * Copyright: 2005
18   *     The copyright to this program is held by it's authors.
19   *
20   * ID: $Id: LayoutType.java 2088 2011-03-05 20:36:55Z dmsmith $
21   */
22  package org.crosswire.common.swing.desktop;
23  
24  import org.crosswire.common.swing.CWMsg;
25  
26  
27  /**
28   * Types of ViewLayouts. Currently there are two types of desktop layouts:
29   * <ul>
30   * <li>TDI - tabbed document interface.</li>
31   * <li>MDI - multiple document interface (sub-windows)</li>
32   * </ul>
33   * 
34   * @see gnu.lgpl.License for license details.<br>
35   *      The copyright to this program is held by it's authors.
36   * @author Joe Walker [joe at eireneh dot com]
37   * @author DM Smith [dmsmith555 at yahoo dot com]
38   */
39  public enum LayoutType {
40      /**
41       * Tabbed View
42       */
43      TDI {
44          @Override
45          public AbstractViewLayout createLayout() {
46              return new TDIViewLayout();
47          }
48  
49          @Override
50          public String toString() {
51              // TRANSLATOR: This is the name of one of two different ways to present Bible Views.
52              // These show up in Options/Preferences.
53              return CWMsg.gettext("Tabbed Document Interface");
54          }
55      },
56  
57      /**
58       * Multiple Document View
59       */
60      MDI {
61          @Override
62          public AbstractViewLayout createLayout() {
63              return new MDIViewLayout();
64          }
65  
66          @Override
67          public String toString() {
68              // TRANSLATOR: This is the name of one of two different ways to present Bible Views.
69              // These show up in Options/Preferences.
70              return CWMsg.gettext("Multiple Document Interface");
71          }
72      };
73  
74      /**
75       * Return the layout
76       * 
77       * @return the layout
78       */
79      public AbstractViewLayout getLayout() {
80          // In order to get the proper LAF it needs to be created after the LAF
81          // is set
82          // So we delay it until it is actually needed.
83          if (layout == null) {
84              layout = createLayout();
85          }
86          return layout;
87      }
88  
89      /**
90       * Create the appropriate kind of view layout
91       * 
92       * @return the created view layout
93       */
94      public abstract AbstractViewLayout createLayout();
95  
96      /**
97       * Get an integer representation for this LayoutType
98       */
99      public int toInteger() {
100         return ordinal();
101     }
102 
103     /**
104      * Lookup method to convert from a String
105      */
106     public static LayoutType fromString(String name) {
107         for (LayoutType v : values()) {
108             if (v.name().equalsIgnoreCase(name)) {
109                 return v;
110             }
111         }
112 
113         // cannot get here
114         assert false;
115         return null;
116     }
117 
118     /**
119      * Lookup method by ordinal value
120      */
121     public static LayoutType fromInteger(int ordinal) {
122         for (LayoutType v : values()) {
123             if (v.ordinal() == ordinal) {
124                 return v;
125             }
126         }
127 
128         // cannot get here
129         assert false;
130         return null;
131     }
132 
133     /**
134      * The actual layout
135      */
136     private transient AbstractViewLayout layout;
137 }
138