create changelog entry
[debian/openrocket] / core / 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         // Centering Ring Templates
26         CENTERING_RING_TEMPLATE("OpenRocketPrintable.Centeringringtemplates", false, 5),
27         // Finset shape
28         FIN_TEMPLATE("OpenRocketPrintable.Fintemplates", true, 6),
29         // Fin marking guide.
30         FIN_MARKING_GUIDE("OpenRocketPrintable.Finmarkingguide", false, 7);
31
32
33         private static final Translator trans = Application.getTranslator();
34
35         /**
36          * The description - will be displayed in the JTree.
37          */
38         private String description;
39
40         /**
41          * Flag that indicates if the enum value is different depending upon stage.
42          */
43         private boolean stageSpecific;
44
45         /**
46          * The order of the item as it appears in the printed document.
47          */
48         private int order;
49
50         /**
51          * Constructor.
52          *
53          * @param s      the displayable description
54          * @param staged indicates if the printable is stage dependent
55          * @param idx    the relative print order
56          */
57         OpenRocketPrintable(String s, boolean staged, int idx) {
58                 description = s;
59                 stageSpecific = staged;
60                 order = idx;
61         }
62
63         /**
64          * Get the description of this printable.
65          *
66          * @return a displayable string
67          */
68         public String getDescription() {
69                 return trans.get(description);
70         }
71
72         /**
73          * Answers if this enum value has different meaning depending upon the stage.
74          *
75          * @return true if the printable is stage dependent
76          */
77         public boolean isStageSpecific() {
78                 return stageSpecific;
79         }
80
81         /**
82          * Answer the print order.  This is relative to other enum values.  No two enum values will have the same print
83          * order value.
84          *
85          * @return a 0 based order (0 being first, or highest)
86          */
87         public int getPrintOrder() {
88                 return order;
89         }
90
91         /**
92          * Look up an enum value based on the description.
93          *
94          * @param target the description
95          *
96          * @return an instance of this enum class or null if not found
97          */
98         public static OpenRocketPrintable findByDescription(String target) {
99                 OpenRocketPrintable[] values = values();
100                 for (OpenRocketPrintable value : values) {
101                         if (value.getDescription().equalsIgnoreCase(target)) {
102                                 return value;
103                         }
104                 }
105                 return null;
106         }
107
108         /**
109          * Get a list of ordered enum values that do not have stage affinity.
110          *
111          * @return a list of OpenRocketPrintable
112          */
113         public static List<OpenRocketPrintable> getUnstaged() {
114                 List<OpenRocketPrintable> unstaged = new ArrayList<OpenRocketPrintable>();
115                 OpenRocketPrintable[] values = values();
116                 for (OpenRocketPrintable value : values) {
117                         if (!value.isStageSpecific()) {
118                                 unstaged.add(value);
119                         }
120                 }
121                 return unstaged;
122         }
123 }