[isidorus-cvs] r540 - in branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets: . base values
lgiessmann at common-lisp.net
lgiessmann at common-lisp.net
Thu Jun 30 15:35:52 UTC 2011
Author: lgiessmann
Date: Thu Jun 30 08:35:50 2011
New Revision: 540
Log:
gdl-frontend: Widgets: implemented some methods for getting GDL attributes from occurrences
Added:
branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/values/
branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/values/AutoNumValue.java
branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/values/ClearValue.java
Replaced:
branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/base/GdlVisibleObject.java
- copied, changed from r539, branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/base/GdlVisibleObject.java
Modified:
branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/GDL_Widgets.gwt.xml
branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/base/GdlPsis.java
branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/base/TestClass.java
Modified: branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/GDL_Widgets.gwt.xml
==============================================================================
--- branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/GDL_Widgets.gwt.xml Thu Jun 30 05:35:16 2011 (r539)
+++ branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/GDL_Widgets.gwt.xml Thu Jun 30 08:35:50 2011 (r540)
@@ -22,6 +22,7 @@
<source path="base"/>
<source path="views"/>
<source path="environment"/>
+ <source path="values"/>
<source path="isidorus"/>
<!-- Reference the javascript file that is necessary for tmjs -->
Modified: branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/base/GdlPsis.java
==============================================================================
--- branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/base/GdlPsis.java Thu Jun 30 05:35:16 2011 (r539)
+++ branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/base/GdlPsis.java Thu Jun 30 08:35:50 2011 (r540)
@@ -1,5 +1,7 @@
package us.isidor.gdl.anaToMia.Widgets.base;
+import us.isidor.gdl.anaToMia.TopicMaps.TopicMapsModel.Topic;
+
public class GdlPsis {
public final static String gdl = "http://psi.isidor.us/gdl/";
@@ -222,4 +224,18 @@
public final static String gdlFocus = gdl + "focus";
public final static String gdlActive = gdl + "active";
}
+
+
+ // a helper method to return any identifier string of the topic
+ public static String getAnyIdOfTopic(Topic topic){
+ if(topic.getSubjectIdentifiers().length() != 0){
+ return topic.getSubjectIdentifiers().get(0).getReference();
+ }else if(topic.getSubjectLocators().length() != 0) {
+ return topic.getSubjectLocators().get(0).getReference();
+ }if(topic.getItemIdentifiers().length() != 0){
+ return topic.getItemIdentifiers().get(0).getReference();
+ } else {
+ return null;
+ }
+ }
}
Copied and modified: branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/base/GdlVisibleObject.java (from r539, branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/base/GdlVisibleObject.java)
==============================================================================
--- branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/base/GdlVisibleObject.java Thu Jun 30 05:35:16 2011 (r539, copy source)
+++ branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/base/GdlVisibleObject.java Thu Jun 30 08:35:50 2011 (r540)
@@ -1,14 +1,21 @@
package us.isidor.gdl.anaToMia.Widgets.base;
+import java.util.ArrayList;
+
import us.isidor.gdl.anaToMia.TopicMaps.TopicMapsModel.Occurrence;
import us.isidor.gdl.anaToMia.TopicMaps.TopicMapsModel.Topic;
import us.isidor.gdl.anaToMia.TopicMaps.TopicMapsModel.TopicMap;
import us.isidor.gdl.anaToMia.Widgets.environment.InvalidGdlSchemaException;
-
+import us.isidor.gdl.anaToMia.Widgets.values.AutoNumValue;
+import us.isidor.gdl.anaToMia.Widgets.values.ClearValue;
import com.google.gwt.core.client.JsArray;
+import com.google.gwt.dom.client.Style.Display;
+import com.google.gwt.dom.client.Style.Float;
+import com.google.gwt.dom.client.Style.VerticalAlign;
import com.google.gwt.user.client.ui.AbsolutePanel;
import com.google.gwt.user.client.ui.Composite;
+
public abstract class GdlVisibleObject extends Composite implements GdlDescriptor {
protected AbsolutePanel mainPanel = new AbsolutePanel();
protected Topic tmRepresentative = null;
@@ -32,61 +39,222 @@
}
+ // a helper method that returns all occurrences of the type bound to the passed PSI
+ private JsArray<Occurrence> getOccurrences(String occurrenceType){
+ return tmRepresentative.getOccurrences(tm.getTopicBySubjectIdentifier(tm.createLocator(occurrenceType)));
+ }
+
+
+ // a helper method that returns one occurrence of the type bound to the passed PSI.
+ // If more than one occurrence is available an InvalidGdlSchemaException is thrown.
+ // If nor occurrence is available the return value is null
+ private Occurrence getNoneOrOneOccurrence(String occurrenceType) throws InvalidGdlSchemaException{
+ JsArray<Occurrence> occs = getOccurrences(occurrenceType);
+
+ if(occs.length() > 1){
+ throw new InvalidGdlSchemaException("The topic " + GdlPsis.getAnyIdOfTopic(this.tmRepresentative) + "must be bound to none or one occurrence of the type " + occurrenceType + "but is bound " + occs.length() + " times to it");
+ } else if(occs.length() == 1){
+ return occs.get(0);
+ } else {
+ return null;
+ }
+ }
+
+
+ // a helper method that returns one occurrence of the type bound to the passed PSI and scoped
+ // by the theme bound to the passed PSI. If no such occurrence exist, the default value is null
+ private Occurrence getNoneOrOneScopedOccurrence(String occurrenceType, String theme) throws InvalidGdlSchemaException{
+ Topic themeTopic = tm.getTopicBySubjectIdentifier(tm.createLocator(theme));
+ if(themeTopic == null){
+ return null;
+ } else {
+ JsArray<Occurrence> occurrences = getOccurrences(occurrenceType);
+ ArrayList<Occurrence> matchedOccurrences = new ArrayList<Occurrence>();
+ for(int i = 0; i != occurrences.length(); ++i){
+ for(int j = 0; j != occurrences.get(i).getScope().length(); ++j){
+ if(occurrences.get(i).getScope().get(j).equals(themeTopic)){
+ matchedOccurrences.add(occurrences.get(i));
+ break;
+ }
+ }
+ }
+
+ if(matchedOccurrences.size() > 1){
+ throw new InvalidGdlSchemaException("The topic " + GdlPsis.getAnyIdOfTopic(this.tmRepresentative) + "must be bound to none or one occurrence of the type " + occurrenceType + " and the scope " + theme + " but is bound " + matchedOccurrences.size() + " times to it");
+ } else if(matchedOccurrences.size() == 1){
+ return matchedOccurrences.get(0);
+ } else {
+ return null;
+ }
+ }
+ }
+
+
+ // returns the string value of a gdl:id occurrence
public String getId() throws InvalidGdlSchemaException {
- JsArray<Occurrence> idOccs = tmRepresentative.getOccurrences(tm.getTopicBySubjectIdentifier(tm.createLocator(GdlPsis.OccurrenceType.gdlId)));
+ JsArray<Occurrence> idOccs = getOccurrences(GdlPsis.OccurrenceType.gdlId);
if(idOccs.length() != 1){
- throw new InvalidGdlSchemaException("The topic " + "" + "must be bound to exactly one occurrence of the type " + GdlPsis.OccurrenceType.gdlId + "but is bound " + idOccs.length() + " times to it");
+ throw new InvalidGdlSchemaException("The topic " + GdlPsis.getAnyIdOfTopic(this.tmRepresentative) + "must be bound to exactly one occurrence of the type " + GdlPsis.OccurrenceType.gdlId + "but is bound " + idOccs.length() + " times to it");
} else {
return idOccs.get(0).getValue();
}
}
+ // returns a Display instance of a gdl:display occurrence.
+ // If no gdl:display occurrence is set, the default value is returned
+ public Display getDisplay() throws InvalidGdlSchemaException {
+ Occurrence displayOcc = getNoneOrOneOccurrence(GdlPsis.OccurrenceType.gdlId);
+
+ if(displayOcc != null){
+ String value = displayOcc.getValue().toLowerCase();
+ if(value.equals("none")){
+ return Display.NONE;
+ } else if (value.equals("inline")){
+ return Display.INLINE;
+ } else if (value.equals("inline-block")){
+ return Display.INLINE_BLOCK;
+ } else if(value.equals("block")){
+ return Display.BLOCK;
+ } else {
+ throw new InvalidGdlSchemaException("The occurrence " + GdlPsis.OccurrenceType.gdlDisplay + " must be set to one of \"none\", \"inline\", \"inline-block\" or \"block\", but is \"" + displayOcc.getValue() + "\"");
+ }
+ } else {
+ return Display.INLINE_BLOCK;
+ }
+ }
+
+
+ // returns an AutoNumValue instance of a gdl:z-index occurrence.
+ // If no gdl:z-index occurrence is set, the default value is returned
+ public AutoNumValue getZindex() throws InvalidGdlSchemaException {
+ Occurrence zOcc = getNoneOrOneOccurrence(GdlPsis.OccurrenceType.gdlZindex);
+ if(zOcc != null){
+ return new AutoNumValue(zOcc.getValue());
+ } else {
+ return new AutoNumValue();
+ }
+ }
- // TODO: StyleClass scope
- // gdlVerticalAlign
- // gdlDisplay
- // gdlMargin
- // gdlMarginTop
- // gdlMarginRight
- // gdlMarginBottom
- // gdlMarginLeft
- // gdlBorderColor
- // gdlBorderColorTop
- // gdlBorderColorRight
- // gdlBorderColorBottom
- // gdlBorderColorLeft
- // gdlBorderStyle
- // gdlBorderStyleTop
- // gdlBorderStyleRight
- // gdlBorderStyleBottom
- // gdlBorderStyleLeft
- // gdlBorderWidth
- // gdlBorderWidthTop
- // gdlBorderWidthRight
- // gdlBorderWidthBottom
- // gdlBorderWidthLeft
- // gdlBorderRadius
- // gdlBorderTopRightRadius
- // gdlBorderTopLeftRadius
- // gdlBorderBottomRightRadius
- // gdlBorderBottomLeftRadius
- // gdlCursor
- // gdlZindex
- // gdlWidth
- // gdlMinWidth
- // gdlMaxWidth
- // gdlHeight
- // gdlMaxHeight
- // gdlMinHeight
- // gdlPadding
- // gdlPaddingTop
- // gdlPaddingRight
- // gdlPaddingBottom
- // gdlPaddingLeft
- // gdlFloat
- // gdlClear
- // gdlBackgroundColor
- // gdlOverflow
+ // returns a Float instance of a gdl:float occurrence or the default value for
+ // this property if no gdl:float occurrence is available
+ public Float getFloat() throws InvalidGdlSchemaException {
+ Occurrence floatOcc = getNoneOrOneOccurrence(GdlPsis.OccurrenceType.gdlFloat);
+
+ if(floatOcc != null){
+ String value = floatOcc.getValue().toLowerCase();
+ if(value.equals("none")){
+ return Float.NONE;
+ } else if (value.equals("left")){
+ return Float.LEFT;
+ } else if (value.equals("right")){
+ return Float.RIGHT;
+ } else {
+ throw new InvalidGdlSchemaException("The occurrence " + GdlPsis.OccurrenceType.gdlFloat + " must be set to one of \"none\", \"left\" or \"right\", but is \"" + floatOcc.getValue() + "\"");
+ }
+ } else {
+ return Float.NONE;
+ }
+ }
+
+
+ // returns a ClearValue instance of a gdl:clear occurrence or the default value for
+ // this property if no gdl:clear occurrence is available
+ public ClearValue getClear() throws InvalidGdlSchemaException {
+ Occurrence clearOcc = getNoneOrOneOccurrence(GdlPsis.OccurrenceType.gdlFloat);
+
+ if(clearOcc != null){
+ try{
+ return ClearValue.valueOf(clearOcc.getValue().toLowerCase());
+ }catch(IllegalArgumentException e){
+ throw new InvalidGdlSchemaException("The occurrence " + GdlPsis.OccurrenceType.gdlFloat + " must be set to one of \"none\", \"left\", \"right\" or \"both\", but is \"" + clearOcc.getValue() + "\"");
+ }
+ } else {
+ return ClearValue.none;
+ }
+ }
+
+
+ // returns a VerticalAlign instance of a gdl:vertical-align occurrence
+ // or the default value for this property if no gdl:vertical-align occurrence
+ // is available. The styleClass attribute is used as scope for expressing
+ // a css pseudo-class, if styleClass is null the occurrence must be unscoped
+ public VerticalAlign getVerticalAlign(String styleClass) throws InvalidGdlSchemaException {
+ Occurrence vaOcc = null;
+ if(styleClass != null){
+ vaOcc = getNoneOrOneScopedOccurrence(GdlPsis.OccurrenceType.gdlVerticalAlign, styleClass);
+ } else {
+ vaOcc = getNoneOrOneOccurrence(GdlPsis.OccurrenceType.gdlVerticalAlign);
+ }
+
+ if(vaOcc == null && styleClass != null){
+ return null;
+ } else if(vaOcc == null) {
+ return VerticalAlign.BASELINE;
+ }else {
+ String value = vaOcc.getValue().toLowerCase();
+ if(value.equals("baseline")){
+ return VerticalAlign.BASELINE;
+ } else if(value.equals("sub")){
+ return VerticalAlign.SUB;
+ } else if(value.equals("super")) {
+ return VerticalAlign.SUPER;
+ } else if(value.equals("top")) {
+ return VerticalAlign.TOP;
+ }else if(value.equals("text-top")) {
+ return VerticalAlign.TEXT_TOP;
+ }else if(value.equals("middle")) {
+ return VerticalAlign.MIDDLE;
+ }else if(value.equals("bottom")) {
+ return VerticalAlign.BOTTOM;
+ }else if(value.equals("text-bottom")) {
+ return VerticalAlign.TEXT_BOTTOM;
+ } else {
+ throw new InvalidGdlSchemaException("The occurrence " + GdlPsis.OccurrenceType.gdlVerticalAlign + " must be set to one of \"baseline\", \"sub\", \"super\", \"top\", \"text-top\", \"middle\", \"bottom\" or \"text-bottom\", but is \"" + vaOcc.getValue() + "\"");
+ }
+ }
+ }
+
+
+
+ // gdlMargin [gdl:hover | gdl:focus | gdl:active]
+ // gdlMarginTop [gdl:hover | gdl:focus | gdl:active]
+ // gdlMarginRight [gdl:hover | gdl:focus | gdl:active]
+ // gdlMarginBottom [gdl:hover | gdl:focus | gdl:active]
+ // gdlMarginLeft [gdl:hover | gdl:focus | gdl:active]
+ // gdlBorderColor [gdl:hover | gdl:focus | gdl:active]
+ // gdlBorderColorTop [gdl:hover | gdl:focus | gdl:active]
+ // gdlBorderColorRight [gdl:hover | gdl:focus | gdl:active]
+ // gdlBorderColorBottom [gdl:hover | gdl:focus | gdl:active]
+ // gdlBorderColorLeft [gdl:hover | gdl:focus | gdl:active]
+ // gdlBorderStyle [gdl:hover | gdl:focus | gdl:active]
+ // gdlBorderStyleTop [gdl:hover | gdl:focus | gdl:active]
+ // gdlBorderStyleRight [gdl:hover | gdl:focus | gdl:active]
+ // gdlBorderStyleBottom [gdl:hover | gdl:focus | gdl:active]
+ // gdlBorderStyleLeft [gdl:hover | gdl:focus | gdl:active]
+ // gdlBorderWidth [gdl:hover | gdl:focus | gdl:active]
+ // gdlBorderWidthTop [gdl:hover | gdl:focus | gdl:active]
+ // gdlBorderWidthRight [gdl:hover | gdl:focus | gdl:active]
+ // gdlBorderWidthBottom [gdl:hover | gdl:focus | gdl:active]
+ // gdlBorderWidthLeft [gdl:hover | gdl:focus | gdl:active]
+ // gdlBorderRadius [gdl:hover | gdl:focus | gdl:active]
+ // gdlBorderTopRightRadius [gdl:hover | gdl:focus | gdl:active]
+ // gdlBorderTopLeftRadius [gdl:hover | gdl:focus | gdl:active]
+ // gdlBorderBottomRightRadius [gdl:hover | gdl:focus | gdl:active]
+ // gdlBorderBottomLeftRadius [gdl:hover | gdl:focus | gdl:active]
+ // gdlCursor [gdl:hover | gdl:focus | gdl:active]
+ // gdlWidth [gdl:hover | gdl:focus | gdl:active]
+ // gdlMinWidth [gdl:hover | gdl:focus | gdl:active]
+ // gdlMaxWidth [gdl:hover | gdl:focus | gdl:active]
+ // gdlHeight [gdl:hover | gdl:focus | gdl:active]
+ // gdlMaxHeight [gdl:hover | gdl:focus | gdl:active]
+ // gdlMinHeight [gdl:hover | gdl:focus | gdl:active]
+ // gdlPadding [gdl:hover | gdl:focus | gdl:active]
+ // gdlPaddingTop [gdl:hover | gdl:focus | gdl:active]
+ // gdlPaddingRight [gdl:hover | gdl:focus | gdl:active]
+ // gdlPaddingBottom [gdl:hover | gdl:focus | gdl:active]
+ // gdlPaddingLeft [gdl:hover | gdl:focus | gdl:active]
+ // gdlBackgroundColor [gdl:hover | gdl:focus | gdl:active]
+ // gdlOverflow [gdl:hover | gdl:focus | gdl:active]
}
Modified: branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/base/TestClass.java
==============================================================================
--- branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/base/TestClass.java Thu Jun 30 05:35:16 2011 (r539)
+++ branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/base/TestClass.java Thu Jun 30 08:35:50 2011 (r540)
@@ -2,7 +2,6 @@
import us.isidor.gdl.anaToMia.TmEngine.jtmsBasedEngine.JtmsTmEngine;
import us.isidor.gdl.anaToMia.Widgets.isidorus.LoadSchemaCallback;
-
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
@@ -44,5 +43,6 @@
});
mainPanel.add(requestButton);
+
}
}
Added: branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/values/AutoNumValue.java
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/values/AutoNumValue.java Thu Jun 30 08:35:50 2011 (r540)
@@ -0,0 +1,51 @@
+package us.isidor.gdl.anaToMia.Widgets.values;
+
+import us.isidor.gdl.anaToMia.Widgets.environment.InvalidGdlSchemaException;
+
+
+public class AutoNumValue {
+ private Integer intValue = null;
+
+
+ public AutoNumValue()throws InvalidGdlSchemaException{
+ this("auto");
+ }
+
+
+ public AutoNumValue(String value) throws InvalidGdlSchemaException{
+ String val = value.toLowerCase();
+ if(val.equals("auto")){
+ // do nothing, a null reference of intValue is handled as the value "autho"
+ } else {
+ try{
+ intValue = Integer.valueOf(value);
+ }catch(NumberFormatException e){
+ throw new InvalidGdlSchemaException("An HTML auto-numeric value must bei either \"auto\" or an integer");
+ }
+ }
+ }
+
+
+ // return a string that contains either an integer as a string value
+ // or the string auto
+ public String getStringValue(){
+ if(intValue == null){
+ return "auto";
+ }else {
+ return String.valueOf(intValue);
+ }
+ }
+
+
+ // returns an integer value or null. If null is returned, the value must be treated
+ // as auto
+ public Integer getIntegerValue(){
+ return intValue;
+ }
+
+
+ // this method returns true, if the value must be treated as "auto"
+ public boolean isAuto(){
+ return intValue == null;
+ }
+}
Added: branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/values/ClearValue.java
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/values/ClearValue.java Thu Jun 30 08:35:50 2011 (r540)
@@ -0,0 +1,8 @@
+package us.isidor.gdl.anaToMia.Widgets.values;
+
+public enum ClearValue {
+ none,
+ left,
+ right,
+ both
+}
More information about the Isidorus-cvs
mailing list