reordered pages
[debian/openrocket] / src / net / sf / openrocket / gui / print / OpenRocketPrintable.java
1 /*
2  * OpenRocketPrintable.java
3  */
4 package net.sf.openrocket.gui.print;
5
6 import java.util.ArrayList;
7 import java.util.List;
8
9 import net.sf.openrocket.l10n.Translator;
10 import net.sf.openrocket.startup.Application;
11
12 /**
13  * This enumeration identifies the various types of information that may be printed.
14  */
15
16 public enum OpenRocketPrintable {
17         // Design Report
18         DESIGN_REPORT("OpenRocketPrintable.DesignReport", false, 1),
19         // Parts detail
20         PARTS_DETAIL("OpenRocketPrintable.Partsdetail", true, 2),
21         // Nose Cone Templates
22         NOSE_CONE_TEMPLATE("OpenRocketPrintable.Noseconetemplates", false, 3),
23         // Transition Templates
24         TRANSITION_TEMPLATE("OpenRocketPrintable.Transitiontemplates", false, 4),
25         // Finset shape
26         FIN_TEMPLATE("OpenRocketPrintable.Fintemplates", true, 5),
27         // Fin marking guide.
28         FIN_MARKING_GUIDE("OpenRocketPrintable.Finmarkingguide", false, 6);
29         
30
31         private static final Translator trans = Application.getTranslator();
32         
33         /**
34          * The description - will be displayed in the JTree.
35          */
36         private String description;
37         
38         /**
39          * Flag that indicates if the enum value is different depending upon stage.
40          */
41         private boolean stageSpecific;
42         
43         /**
44          * The order of the item as it appears in the printed document.
45          */
46         private int order;
47         
48         /**
49          * Constructor.
50          *
51          * @param s      the displayable description
52          * @param staged indicates if the printable is stage dependent
53          * @param idx    the relative print order
54          */
55         OpenRocketPrintable(String s, boolean staged, int idx) {
56                 description = s;
57                 stageSpecific = staged;
58                 order = idx;
59         }
60         
61         /**
62          * Get the description of this printable.
63          *
64          * @return a displayable string
65          */
66         public String getDescription() {
67                 return trans.get(description);
68         }
69         
70         /**
71          * Answers if this enum value has different meaning depending upon the stage.
72          *
73          * @return true if the printable is stage dependent
74          */
75         public boolean isStageSpecific() {
76                 return stageSpecific;
77         }
78         
79         /**
80          * Answer the print order.  This is relative to other enum values.  No two enum values will have the same print
81          * order value.
82          *
83          * @return a 0 based order (0 being first, or highest)
84          */
85         public int getPrintOrder() {
86                 return order;
87         }
88         
89         /**
90          * Look up an enum value based on the description.
91          *
92          * @param target the description
93          *
94          * @return an instance of this enum class or null if not found
95          */
96         public static OpenRocketPrintable findByDescription(String target) {
97                 OpenRocketPrintable[] values = values();
98                 for (OpenRocketPrintable value : values) {
99                         if (value.getDescription().equalsIgnoreCase(target)) {
100                                 return value;
101                         }
102                 }
103                 return null;
104         }
105         
106         /**
107          * Get a list of ordered enum values that do not have stage affinity.
108          *
109          * @return a list of OpenRocketPrintable
110          */
111         public static List<OpenRocketPrintable> getUnstaged() {
112                 List<OpenRocketPrintable> unstaged = new ArrayList<OpenRocketPrintable>();
113                 OpenRocketPrintable[] values = values();
114                 for (OpenRocketPrintable value : values) {
115                         if (!value.isStageSpecific()) {
116                                 unstaged.add(value);
117                         }
118                 }
119                 return unstaged;
120         }
121 }