JAL-1492 formatting and squash NPEs
[jalview.git] / doc / i18n.html
index d2a7420..0be5673 100644 (file)
 <p>To use it within your code, you only have to invoke MessageManager with the text key in Messages_xx.properties:</p>\r
 <p>JButton ok = new JButton(MessageManager.getString("button.ok"));</p>\r
 <p>This will set JButton text to the one included at button.ok key. In English JButton text will be OK, while in Spanish will be Aceptar. This is the big thing of i18n. :)</p>\r
+<h1>Don't rely comparisons on labels</h1>\r
+<p>Don't use this type of coding:\r
+    threshold.addItem("No Threshold");<br>\r
+    threshold.addItem("Above Threshold");<br>\r
+    threshold.addItem("Below Threshold");<br>\r
+    [...]<br>\r
+    if (threshold.getSelectedItem().equals("Above Threshold"))<br>\r
+    {</br>\r
+      aboveThreshold = AnnotationColourGradient.ABOVE_THRESHOLD;<br>\r
+    }<br>\r
+    else if (threshold.getSelectedItem().equals("Below Threshold"))<br>\r
+    {<br>\r
+      aboveThreshold = AnnotationColourGradient.BELOW_THRESHOLD;<br>\r
+    }<br>\r
+</p>\r
+<p>Once text has been translated, these equals will fail as the label won't be the English ones. It should be used getSelectedIndex() instead of getSelectedItem(). If you do the proper way, the code will look like this:<br>\r
+    threshold.addItem(MessageManager.getString("label.threshold_feature_no_thereshold"));<br>\r
+    threshold.addItem(MessageManager.getString("label.threshold_feature_above_thereshold"));<br>\r
+    threshold.addItem(MessageManager.getString("label.threshold_feature_below_thereshold"));<br>\r
+    [...]<br>\r
+    if (threshold.getSelectedIndex()==1)<br>\r
+    {<br>\r
+      aboveThreshold = AnnotationColourGradient.ABOVE_THRESHOLD;<br>\r
+    }<br>\r
+    else if (threshold.getSelectedIndex()==2)<br>\r
+    {<br>\r
+      aboveThreshold = AnnotationColourGradient.BELOW_THRESHOLD;<br>\r
+    }<br>    \r
+</p>\r
 <h1>How to translate Jalview</h1>\r
 <p>Anyone interested in localizing/translating Jalview is strongly encouraged to join the <a href="mailto:jalview-dev@jalview.org">Jalview Development List</a> list. We would recommend that you read this entire page before proceeding.</p>\r
 <p>If you are planning on working on a Jalview translation, please send us an email (<a href="mailto:jalview-dev@jalview.org">Jalview Development List</a>). There may be someone else already working on translating Jalview to your target language.</p>\r