From: Mark G. <mg...@us...> - 2003-04-22 18:57:30
|
Update of /cvsroot/gmod/apollo/src/java/apollo/gui/schemes In directory sc8-pr-cvs1:/tmp/cvs-serv14643/src/java/apollo/gui/schemes Modified Files: PropertyScheme.java TierProperty.java Log Message: Added isProtein as a tier property so one can tell apollo a tier is protein without having to stick "Protein" in the tier label. This gets away from the hard wiring of proteins. The problem came up for a user this morning and it was trivial to add so I did. This is added to the tier as "key=value:isProtein=true". So Ive introduced the idea of key-value pairs to the tiers. This gets away from the rigid ordering of arbitrary properties and its clearer since the key will say what the value is for. A tag was necasary for now ("key=value:") to distinguish it for parsing. New properties should use key-value, and it'll be pretty easy to convert the old ones at some point. This is a step towards making tiers more managable. Index: PropertyScheme.java =================================================================== RCS file: /cvsroot/gmod/apollo/src/java/apollo/gui/schemes/PropertyScheme.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** PropertyScheme.java 22 Apr 2003 17:07:29 -0000 1.7 --- PropertyScheme.java 22 Apr 2003 18:57:23 -0000 1.8 *************** *** 287,292 **** --- 287,294 ---- // End of line reached - do something with words else { + TierProperty tp=null; // Counting the line numbers as tokenizer.lineno() always returns 1. not sure why. ++line_number; + // Apparently the number of words has to be from 4 to 7 or 10 to 13(see below) if ((words.size() == 4 || words.size() == 5 || words.size() == 6 || words.size() == 7) && bracedSets.size() == 0 && *************** *** 310,315 **** labeled = new Boolean(false); } ! TierProperty tp = (TierProperty) ! tiersHash.get (tier_label.toLowerCase()); if (tp == null) { tp = new TierProperty(tier_label, --- 312,316 ---- labeled = new Boolean(false); } ! tp = (TierProperty)tiersHash.get (tier_label.toLowerCase()); if (tp == null) { tp = new TierProperty(tier_label, *************** *** 340,345 **** tier_label = (String) words.elementAt(1); type = (String) words.elementAt(2); ! TierProperty tp = (TierProperty) ! tiersHash.get (tier_label.toLowerCase()); if (tp == null) { tp = new TierProperty(tier_label, true, false); --- 341,345 ---- tier_label = (String) words.elementAt(1); type = (String) words.elementAt(2); ! tp = (TierProperty)tiersHash.get (tier_label.toLowerCase()); if (tp == null) { tp = new TierProperty(tier_label, true, false); *************** *** 423,430 **** } } // end of else words.removeAllElements(); bracedStrs = null; bracedSets.removeAllElements(); ! } // end of else statement } // end of try after while EOF catch (IOException e) { --- 423,433 ---- } } // end of else + + parseKeyValuePairs(words,tp); + // done going through all words words.removeAllElements(); bracedStrs = null; bracedSets.removeAllElements(); ! } // end of else statement for parsing words } // end of try after while EOF catch (IOException e) { *************** *** 441,444 **** --- 444,473 ---- } // System.out.println("Reading types group file: " + typeFile); + } + + /** Parse all words that begin with "key=value:". Presently this is just + isProtein. Evenutally all words could go this route. Then the type string wouldnt + have so strict about order, and it would be clearer. + */ + private void parseKeyValuePairs(Vector words,TierProperty tierProperty) { + if (tierProperty==null) return; + for (int i=0; i<words.size(); i++) { + String word = (String)words.get(i); + if (!isKeyValue(word)) continue; + String keyValue = word.substring(10); + int equalsIndex = keyValue.indexOf('='); + if (equalsIndex==-1) continue; + String key = keyValue.substring(0,equalsIndex); + String value = keyValue.substring(equalsIndex+1); + + if (key.equals("isProtein")) { + boolean isProtein = Boolean.valueOf(value).booleanValue(); // "true" -> true + tierProperty.setIsProtein(isProtein); + } + } + } + /** KeyValues start with "key=value:" */ + private boolean isKeyValue(String word) { + return word.startsWith("key=value:"); } Index: TierProperty.java =================================================================== RCS file: /cvsroot/gmod/apollo/src/java/apollo/gui/schemes/TierProperty.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** TierProperty.java 10 Sep 2002 15:02:04 -0000 1.4 --- TierProperty.java 22 Apr 2003 18:57:25 -0000 1.5 *************** *** 233,235 **** --- 233,242 ---- } + private boolean isProtein=false; + void setIsProtein(boolean isProtein) { + this.isProtein = isProtein; + } + /** Default is false */ + public boolean isProtein() { return isProtein; } + } |