1515 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1616 GNU General Public License for more details.
1717
18- You should have received a copy of the GNU General Public License along
18+ You should have received a copy of the GNU General Public License along
1919 with this program; if not, write to the Free Software Foundation, Inc.
2020 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
2121*/
3030
3131abstract public class Contribution {
3232 static final String SPECIAL_CATEGORY_NAME = "Starred" ;
33- static final List validCategories =
34- Arrays .asList ("3D" , "Animation" , "Data" , "Geometry" , "GUI" , "Hardware" ,
35- "I/O" , "Math" , "Simulation" , "Sound" , SPECIAL_CATEGORY_NAME , "Typography" ,
33+ static final List validCategories =
34+ Arrays .asList ("3D" , "Animation" , "Data" , "Geometry" , "GUI" , "Hardware" ,
35+ "I/O" , "Math" , "Simulation" , "Sound" , SPECIAL_CATEGORY_NAME , "Typography" ,
3636 "Utilities" , "Video & Vision" , "Other" );
3737
3838 //protected String category; // "Sound"
@@ -48,20 +48,20 @@ abstract public class Contribution {
4848 protected int minRevision ; // 0
4949 protected int maxRevision ; // 227
5050 protected List <String > specifiedImports ; // pdf.export.*,pdf.convert.common.*
51-
52-
51+
52+
5353 // "Sound"
5454// public String getCategory() {
5555// return category;
5656// }
5757
58-
58+
5959 // "Sound", "Utilities"... see valid list in ContributionListing
6060 protected List <String > getCategories () {
6161 return categories ;
6262 }
63-
64-
63+
64+
6565 protected String getCategoryStr () {
6666 StringBuilder sb = new StringBuilder ();
6767 for (String category : categories ) {
@@ -71,8 +71,8 @@ protected String getCategoryStr() {
7171 sb .deleteCharAt (sb .length ()-1 ); // delete last comma
7272 return sb .toString ();
7373 }
74-
75-
74+
75+
7676 protected boolean hasCategory (String category ) {
7777 if (category != null ) {
7878 for (String c : categories ) {
@@ -82,15 +82,15 @@ protected boolean hasCategory(String category) {
8282 }
8383 }
8484 return false ;
85- }
86-
87-
85+ }
86+
87+
8888 // pdf.export.*,pdf.convert.common.*
8989 protected List <String > getImports () {
9090 return specifiedImports ;
9191 }
92-
93-
92+
93+
9494 protected String getImportStr () {
9595 if (specifiedImports == null || specifiedImports .isEmpty ()) {
9696 return "" ;
@@ -156,7 +156,7 @@ public int getVersion() {
156156 public String getPrettyVersion () {
157157 return prettyVersion ;
158158 }
159-
159+
160160 // 1402805757
161161 public long getLastUpdated () {
162162 return lastUpdated ;
@@ -179,36 +179,36 @@ public boolean isCompatible(int versionNum) {
179179
180180
181181 abstract public ContributionType getType ();
182-
183-
182+
183+
184184 public String getTypeName () {
185185 return getType ().toString ();
186186 }
187-
188-
187+
188+
189189 abstract public boolean isInstalled ();
190-
191-
192- // /**
190+
191+
192+ // /**
193193// * Returns true if the type of contribution requires the PDE to restart
194- // * when being added or removed.
194+ // * when being added or removed.
195195// */
196196// public boolean requiresRestart() {
197197// return getType() == ContributionType.TOOL || getType() == ContributionType.MODE;
198198// }
199-
199+
200200
201201 boolean isRestartFlagged () {
202202 return false ;
203203 }
204-
205-
204+
205+
206206 /** Overridden by LocalContribution. */
207207 boolean isDeletionFlagged () {
208208 return false ;
209209 }
210210
211-
211+
212212 boolean isUpdateFlagged () {
213213 return false ;
214214 }
@@ -217,36 +217,36 @@ boolean isUpdateFlagged() {
217217 /**
218218 * Returns true if the contribution is a starred/recommended contribution, or
219219 * is by the Processing Foundation.
220- *
220+ *
221221 * @return
222222 */
223223 boolean isSpecial () {
224224 try {
225- return (authorList .indexOf ("The Processing Foundation" ) != -1 ||
225+ return (authorList .indexOf ("The Processing Foundation" ) != -1 ||
226226 categories .contains (SPECIAL_CATEGORY_NAME ));
227227 } catch (NullPointerException npe ) {
228228 return false ;
229229 }
230230 }
231231
232232
233- /**
233+ /**
234234 * @return a single element list with "Unknown" as the category.
235235 */
236236 static List <String > defaultCategory () {
237237 List <String > outgoing = new ArrayList <String >();
238238 outgoing .add ("Unknown" );
239239 return outgoing ;
240240 }
241-
242-
241+
242+
243243 /**
244244 * @return the list of categories that this contribution is part of
245245 * (e.g. "Typography / Geometry"). "Unknown" if the category null.
246246 */
247247 static List <String > parseCategories (String categoryStr ) {
248248 List <String > outgoing = new ArrayList <String >();
249-
249+
250250 if (categoryStr != null ) {
251251 String [] listing = PApplet .trim (PApplet .split (categoryStr , ',' ));
252252 for (String category : listing ) {
@@ -261,8 +261,8 @@ static List<String> parseCategories(String categoryStr) {
261261 }
262262 return outgoing ;
263263 }
264-
265-
264+
265+
266266 /**
267267 * @return the list of imports that this contribution (library) contains.
268268 */
@@ -278,54 +278,10 @@ static List<String> parseImports(String importStr) {
278278 return (outgoing .size () > 0 ) ? outgoing : null ;
279279 }
280280
281+
281282 static private String translateCategory (String cat ) {
282- String translated = "" ;
283-
284- switch (cat ) {
285- case "3D" :
286- translated = Language .text ("contrib.category.3d" );
287- break ;
288- case "Animation" :
289- translated = Language .text ("contrib.category.animation" );
290- break ;
291- case "Data" :
292- translated = Language .text ("contrib.category.data" );
293- break ;
294- case "Geometry" :
295- translated = Language .text ("contrib.category.geometry" );
296- break ;
297- case "GUI" :
298- translated = Language .text ("contrib.category.gui" );
299- break ;
300- case "Hardware" :
301- translated = Language .text ("contrib.category.hardware" );
302- break ;
303- case "I/O" :
304- translated = Language .text ("contrib.category.io" );
305- break ;
306- case "Math" :
307- translated = Language .text ("contrib.category.math" );
308- break ;
309- case "Simulation" :
310- translated = Language .text ("contrib.category.simulation" );
311- break ;
312- case "Sound" :
313- translated = Language .text ("contrib.category.sound" );
314- break ;
315- case "Typography" :
316- translated = Language .text ("contrib.category.typography" );
317- break ;
318- case "Utilities" :
319- translated = Language .text ("contrib.category.utilities" );
320- break ;
321- case "Video & Vision" :
322- translated = Language .text ("contrib.category.video_vision" );
323- break ;
324- case "Other" :
325- translated = Language .text ("contrib.category.other" );
326- break ;
327- }
328- return translated ;
283+ // Converts Other to other, I/O to i_o, Video & Vision to video_vision
284+ String cleaned = cat .replaceAll ("[\\ W]+" , "_" ).toLowerCase ();
285+ return Language .text ("contrib.category." + cleaned );
329286 }
330-
331287}
0 commit comments