Author: lgiessmann Date: Mon Jul 4 08:29:44 2011 New Revision: 556
Log: gdl-frontend: Widgets: added the class GdlTextObject, derived from GdlVisibleObject
Added: branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/base/GdlTextObject.java branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/values/DirectionValue.java branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/values/NormalNumUnitValue.java branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/values/TextAlignValue.java branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/values/TextDecorationValue.java Modified: 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/TestClass.java
Added: branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/base/GdlTextObject.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/base/GdlTextObject.java Mon Jul 4 08:29:44 2011 (r556) @@ -0,0 +1,150 @@ +package us.isidor.gdl.anaToMia.Widgets.base; + + +import us.isidor.gdl.anaToMia.TopicMaps.TopicMapsModel.Occurrence; +import us.isidor.gdl.anaToMia.TopicMaps.TopicMapsModel.Topic; +import us.isidor.gdl.anaToMia.Widgets.environment.ExecutionException; +import us.isidor.gdl.anaToMia.Widgets.environment.InvalidGdlSchemaException; +import us.isidor.gdl.anaToMia.Widgets.values.DirectionValue; +import us.isidor.gdl.anaToMia.Widgets.values.NormalNumUnitValue; +import us.isidor.gdl.anaToMia.Widgets.values.TextAlignValue; +import us.isidor.gdl.anaToMia.Widgets.values.TextDecorationValue; + +public abstract class GdlTextObject extends GdlVisibleObject { + + // some constructors + protected GdlTextObject(){ + super(); + } + + + public GdlTextObject(Topic tmRepresentative) throws InvalidGdlSchemaException, ExecutionException{ + super(tmRepresentative); + } + + + // returns a DirectionValue instance that represents the text direction of this element. + // If a styleClass is set, only the corresponding value of the scoped occurrence is returned + // or null. + public DirectionValue getDirection(String styleClass) throws InvalidGdlSchemaException { + Occurrence directionOcc = null; + if(styleClass != null){ + directionOcc = super.getNoneOrOneScopedOccurrence(GdlPsis.OccurrenceType.gdlDirection, styleClass); + } else { + directionOcc = super.getNoneOrOneUnscopedOccurrence(GdlPsis.OccurrenceType.gdlDirection); + } + + if(directionOcc == null && styleClass != null){ + return null; + } else if(directionOcc == null) { + return DirectionValue.LTR; + } else { + try{ + return DirectionValue.valueOf(directionOcc.getValue().toUpperCase()); + }catch(IllegalArgumentException e){ + throw new InvalidGdlSchemaException("The occurrence " + GdlPsis.OccurrenceType.gdlDirection + " must be set to one of "ltr" or "rtl", but is "" + directionOcc.getValue() + """); + } + } + } + + + // returns a TextAlingvalue instance that represents the text-align of this element. + // If a styleClass is set, only the corresponding value of the scoped occurrence is returned + // or null. + public TextAlignValue getTextAlign(String styleClass) throws InvalidGdlSchemaException { + Occurrence textAlignOcc = null; + if(styleClass != null){ + textAlignOcc = super.getNoneOrOneScopedOccurrence(GdlPsis.OccurrenceType.gdlDirection, styleClass); + } else { + textAlignOcc = super.getNoneOrOneUnscopedOccurrence(GdlPsis.OccurrenceType.gdlDirection); + } + + if(textAlignOcc == null && styleClass != null){ + return null; + } else if(textAlignOcc == null) { + return TextAlignValue.LEFT; + } else { + try{ + return TextAlignValue.valueOf(textAlignOcc.getValue().toUpperCase()); + }catch(IllegalArgumentException e){ + throw new InvalidGdlSchemaException("The occurrence " + GdlPsis.OccurrenceType.gdlTextAlign + " must be set to one of "left", "right", "center" or "justify", but is "" + textAlignOcc.getValue() + """); + } + } + } + + + // returns a NormalNumUnitValue instance that represents the line-height of this element. + // If a styleClass is set, only the corresponding value of the scoped occurrence is returned + // or null. + public NormalNumUnitValue getLineHeight(String styleClass) throws InvalidGdlSchemaException { + Occurrence lineHeightOcc = null; + if(styleClass != null){ + lineHeightOcc = super.getNoneOrOneScopedOccurrence(GdlPsis.OccurrenceType.gdlDirection, styleClass); + } else { + lineHeightOcc = super.getNoneOrOneUnscopedOccurrence(GdlPsis.OccurrenceType.gdlDirection); + } + + if(lineHeightOcc == null && styleClass != null){ + return null; + } else if(lineHeightOcc == null) { + return new NormalNumUnitValue(); + } else { + return new NormalNumUnitValue(lineHeightOcc.getValue()); + } + } + + + // returns a TextDecoarionValue instance that represents the text-decoration of this element. + // If a styleClass is set, only the corresponding value of the scoped occurrence is returned + // or null. + public TextDecorationValue getGdlTextDecoration(String styleClass) throws InvalidGdlSchemaException { + Occurrence decorationOcc = null; + if(styleClass != null){ + decorationOcc = super.getNoneOrOneScopedOccurrence(GdlPsis.OccurrenceType.gdlTextDecoration, styleClass); + } else { + decorationOcc = super.getNoneOrOneUnscopedOccurrence(GdlPsis.OccurrenceType.gdlTextDecoration); + } + + if(decorationOcc == null && styleClass != null){ + return null; + } else if(decorationOcc == null) { + return TextDecorationValue.NONE; + } else { + try{ + return TextDecorationValue.valueOf(decorationOcc.getValue().toUpperCase()); + }catch(IllegalArgumentException e){ + throw new InvalidGdlSchemaException("The occurrence " + GdlPsis.OccurrenceType.gdlTextDecoration + " must be set to one of "underline", "overline", "line-through", "blink" or "none", but is "" + decorationOcc.getValue() + """); + } + } + } + + + // calls the super class's setGdlStyle and additionally calls local statements + // to fulfill the style settings + @Override + protected void setGdlStyle() throws InvalidGdlSchemaException, ExecutionException{ + super.setGdlStyle(); + + // TODO: implement + + // direction [hover | active | focus] + // text-align [hover | active | focus] + // line-height [hover | active | focus] + // text-decoration [hover | active | focus] + // color [hover | active | focus] + // font-family [hover | active | focus] + // font-style [hover | active | focus] + // font-size [hover | active | focus] + // font-weight [hover | active | focus] + // letter-spacing [hover | active | focus] + // word-spacing [hover | active | focus] + + + // TODO: implement + // css pseudo class handlers => register additional handlers for this class ??? + } + + + // shall return the objects textual value + public abstract String getText(); +}
Modified: 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 Mon Jul 4 07:26:24 2011 (r555) +++ branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/base/GdlVisibleObject.java Mon Jul 4 08:29:44 2011 (r556) @@ -33,6 +33,7 @@ import com.google.gwt.event.dom.client.HasMouseOutHandlers; import com.google.gwt.event.dom.client.HasMouseOverHandlers; import com.google.gwt.event.dom.client.HasMouseUpHandlers; +import com.google.gwt.event.dom.client.HasScrollHandlers; import com.google.gwt.event.dom.client.MouseDownEvent; import com.google.gwt.event.dom.client.MouseDownHandler; import com.google.gwt.event.dom.client.MouseOutEvent; @@ -41,13 +42,15 @@ import com.google.gwt.event.dom.client.MouseOverHandler; import com.google.gwt.event.dom.client.MouseUpEvent; import com.google.gwt.event.dom.client.MouseUpHandler; +import com.google.gwt.event.dom.client.ScrollEvent; +import com.google.gwt.event.dom.client.ScrollHandler; import com.google.gwt.event.shared.HandlerRegistration; import com.google.gwt.user.client.DOM; import com.google.gwt.user.client.ui.AbsolutePanel; import com.google.gwt.user.client.ui.Composite;
-public abstract class GdlVisibleObject extends Composite implements GdlDescriptor, HasClickHandlers, HasMouseOutHandlers, HasMouseOverHandlers, HasFocusHandlers, HasMouseDownHandlers, HasMouseUpHandlers, HasBlurHandlers{ +public abstract class GdlVisibleObject extends Composite implements GdlDescriptor, HasClickHandlers, HasMouseOutHandlers, HasMouseOverHandlers, HasFocusHandlers, HasMouseDownHandlers, HasMouseUpHandlers, HasBlurHandlers, HasScrollHandlers{ protected AbsolutePanel mainPanel = new AbsolutePanel(); protected Topic tmRepresentative = null; protected TopicMap tm = null; @@ -59,7 +62,8 @@ protected boolean isHovered = false;
- private GdlVisibleObject() { + // some constructors + protected GdlVisibleObject() { initWidget(this.mainPanel); }
@@ -81,7 +85,7 @@
// a helper method that returns all occurrences of the type bound to the passed PSI - private JsArray<Occurrence> getOccurrences(String occurrenceType){ + protected JsArray<Occurrence> getOccurrences(String occurrenceType){ Topic occType = tm.getTopicBySubjectIdentifier(tm.createLocator(occurrenceType)); if(occType == null) return null; else return tmRepresentative.getOccurrences(occType); @@ -91,7 +95,7 @@ // 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 getNoneOrOneUnscopedOccurrence(String occurrenceType) throws InvalidGdlSchemaException{ + protected Occurrence getNoneOrOneUnscopedOccurrence(String occurrenceType) throws InvalidGdlSchemaException{ JsArray<Occurrence> occs = getOccurrences(occurrenceType); ArrayList<Occurrence> unscopedOccs = new ArrayList<Occurrence>(); for(int i = 0; i != occs.length(); ++i){ @@ -110,7 +114,7 @@
// 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{ + protected Occurrence getNoneOrOneScopedOccurrence(String occurrenceType, String theme) throws InvalidGdlSchemaException{ Topic themeTopic = tm.getTopicBySubjectIdentifier(tm.createLocator(theme)); if(themeTopic == null){ return null; @@ -1390,7 +1394,7 @@
// sets all GDL styles that are defined by the topic map representative - public void setGdlStyle() throws InvalidGdlSchemaException, ExecutionException { + protected void setGdlStyle() throws InvalidGdlSchemaException, ExecutionException { this.setDisplay(this.getDisplay()); this.setZindex(this.getZindex()); this.setFloat(this.getFloat()); @@ -1485,6 +1489,13 @@ } + // registers a scroll handler on this element + @Override + public HandlerRegistration addScrollHandler(ScrollHandler handler) { + return this.addDomHandler(handler, ScrollEvent.getType()); + } + + // registers a mouse down handler on this element @Override public HandlerRegistration addMouseUpHandler(MouseUpHandler handler) {
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 Mon Jul 4 07:26:24 2011 (r555) +++ branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/base/TestClass.java Mon Jul 4 08:29:44 2011 (r556) @@ -100,7 +100,11 @@ bgcFocus.addTheme(gdlFocus); - GdlVisibleObject tmp = new GdlVisibleObject(tmpRepresentative){}; + GdlTextObject tmp = new GdlTextObject(tmpRepresentative){ + @Override + public String getText() { + return "tmp"; + }}; this.mainPanel.add(tmp); }catch(Exception e){ e.printStackTrace();
Added: branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/values/DirectionValue.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/DirectionValue.java Mon Jul 4 08:29:44 2011 (r556) @@ -0,0 +1,11 @@ +package us.isidor.gdl.anaToMia.Widgets.values; + +public enum DirectionValue implements CssValue { + LTR, + RTL; + + + public String getCssValue(){ + return this.toString().toLowerCase(); + } +}
Added: branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/values/NormalNumUnitValue.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/NormalNumUnitValue.java Mon Jul 4 08:29:44 2011 (r556) @@ -0,0 +1,46 @@ +package us.isidor.gdl.anaToMia.Widgets.values; + +import us.isidor.gdl.anaToMia.Widgets.environment.InvalidGdlSchemaException; + +public class NormalNumUnitValue extends NumUnitValue{ + public NormalNumUnitValue(){ + super.unit = null; // if unit is null, the default value is normal + super.value = 0f; + } + + + public NormalNumUnitValue(String value) throws InvalidGdlSchemaException{ + String upperString = value.trim().toUpperCase(); + if(upperString.equals("NORMAL")){ + super.unit = null; // if unit is null, the default value is normal + super.value = 0f; + }else if(upperString.endsWith("PX")){ + this.value = makeFloat(upperString, 2); + this.unit = CssUnit.PIXEL; + }else if (upperString.endsWith("PT")){ + this.value = makeFloat(upperString, 2); + this.unit = CssUnit.POINT; + } else if(upperString.endsWith("%")){ + this.value = makeFloat(upperString, 1); + this.unit = CssUnit.PERCENTAGE; + } else { + throw new InvalidGdlSchemaException("normal numeric values supported by the GDL containing a unit definition must be of the form <numeric-value>(pt|px|%)|normal, but found: " + value); + } + } + + + @Override + public String getCssValue() { + if(super.unit == null){ + return "normal"; + } else { + return super.getCssValue(); + } + } + + + // this method returns true, if the value must be treated as "auto" + public boolean isNormal(){ + return super.unit == null; + } +} \ No newline at end of file
Added: branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/values/TextAlignValue.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/TextAlignValue.java Mon Jul 4 08:29:44 2011 (r556) @@ -0,0 +1,14 @@ +package us.isidor.gdl.anaToMia.Widgets.values; + +public enum TextAlignValue implements CssValue{ + LEFT, + RIGHT, + CENTER, + JUSTIFY; + + + @Override + public String getCssValue() { + return this.toString().toLowerCase(); + } +}
Added: branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/values/TextDecorationValue.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/TextDecorationValue.java Mon Jul 4 08:29:44 2011 (r556) @@ -0,0 +1,15 @@ +package us.isidor.gdl.anaToMia.Widgets.values; + +public enum TextDecorationValue implements CssValue { + UNDERLINE, + OVERLINE, + LINE_THROUGH, + BLINK, + NONE; + + + @Override + public String getCssValue() { + return this.toString().toLowerCase().replace("_", "-"); + } +}