Author: lgiessmann Date: Thu Jul 7 08:49:40 2011 New Revision: 577
Log: gdl-frontend: Widgets: implemented GdlListBox (GDL:one-per-group is currently not implemented)
Added: branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/text/GdlListBox.java 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/text/GdlText.java branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/text/GdlTextObject.java
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 Jul 7 07:44:51 2011 (r576) +++ branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/base/TestClass.java Thu Jul 7 08:49:40 2011 (r577) @@ -4,6 +4,7 @@ import us.isidor.gdl.anaToMia.TopicMaps.TopicMapsModel.Occurrence; import us.isidor.gdl.anaToMia.TopicMaps.TopicMapsModel.Topic; import us.isidor.gdl.anaToMia.Widgets.isidorus.LoadSchemaCallback; +import us.isidor.gdl.anaToMia.Widgets.text.GdlListBox; import us.isidor.gdl.anaToMia.Widgets.text.GdlText; import us.isidor.gdl.anaToMia.Widgets.values.CursorValue; import com.google.gwt.core.client.EntryPoint; @@ -114,7 +115,7 @@ fsHover.addTheme(gdlHover); - GdlText tmp = new GdlText(tmpRepresentative){}; + GdlListBox tmp = new GdlListBox(tmpRepresentative){}; this.mainPanel.add(tmp); }catch(Exception e){ e.printStackTrace();
Added: branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/text/GdlListBox.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/text/GdlListBox.java Thu Jul 7 08:49:40 2011 (r577) @@ -0,0 +1,198 @@ +package us.isidor.gdl.anaToMia.Widgets.text; + +import java.util.ArrayList; + +import com.google.gwt.event.shared.EventHandler; +import com.google.gwt.i18n.client.HasDirection.Direction; +import com.google.gwt.user.client.DOM; +import com.google.gwt.user.client.ui.ListBox; +import com.google.gwt.user.client.ui.Widget; + +import us.isidor.gdl.anaToMia.TopicMaps.TopicMapsModel.Occurrence; +import us.isidor.gdl.anaToMia.TopicMaps.TopicMapsModel.Topic; +import us.isidor.gdl.anaToMia.TopicMaps.TopicMapsModel.TopicMapsTypes; +import us.isidor.gdl.anaToMia.Widgets.base.GdlPsis; +import us.isidor.gdl.anaToMia.Widgets.base.IGdlHasValue; +import us.isidor.gdl.anaToMia.Widgets.environment.ActiveStyleHandler; +import us.isidor.gdl.anaToMia.Widgets.environment.ExecutionException; +import us.isidor.gdl.anaToMia.Widgets.environment.FocusStyleHandler; +import us.isidor.gdl.anaToMia.Widgets.environment.HoverStyleHandler; +import us.isidor.gdl.anaToMia.Widgets.environment.InvalidGdlSchemaException; +import us.isidor.gdl.anaToMia.Widgets.environment.Pair; + +public class GdlListBox extends GdlTextObject implements IGdlHasValue{ + // some constructors + protected GdlListBox() throws InvalidGdlSchemaException, ExecutionException { + super(); + } + + + public GdlListBox(Topic tmRepresentative) throws InvalidGdlSchemaException, ExecutionException{ + super(tmRepresentative); + // TODO: create a ListBox element for each TM-elem + ListBox lb = this.createNewListBox(); // TODO: remove only for debugging + lb.addItem("value-1", Direction.LTR); + lb.addItem("value-2", Direction.LTR); + lb.addItem("value-3", Direction.LTR); + lb.addItem("value-4", Direction.LTR); + lb.addItem("value-5", Direction.LTR); + lb.addItem("value-6", Direction.LTR); + lb.addItem("value-1", Direction.LTR); + lb.addItem("value-2", Direction.LTR); + lb.addItem("value-3", Direction.LTR); + lb.addItem("value-4", Direction.LTR); + lb.addItem("value-5", Direction.LTR); + lb.addItem("value-6", Direction.LTR); + lb = this.createNewListBox(); // TODO: remove only for debugging + lb.addItem("value-1", Direction.LTR); + lb.addItem("value-2", Direction.LTR); + lb.addItem("value-3", Direction.LTR); + } + + + // creates a new ListBox item, adds it to the subElements array, + // and applies the styles on it + protected ListBox createNewListBox() throws InvalidGdlSchemaException, ExecutionException { + ListBox elem = new ListBox(this.getMultiple()); + DOM.setElementAttribute(elem.getElement(), "id", this.getId() + "__GDL_" + this.subElements.size()); + this.setGdlStyle(elem); + ActiveStyleHandler asHandler = new ActiveStyleHandler(this); + FocusStyleHandler fsHandler = new FocusStyleHandler(this); + HoverStyleHandler hsHandler = new HoverStyleHandler(this); + elem.addMouseDownHandler(asHandler); + elem.addMouseUpHandler(asHandler); + elem.addMouseOverHandler(hsHandler); + elem.addMouseOutHandler(hsHandler); + elem.addFocusHandler(fsHandler); + elem.addBlurHandler(fsHandler); + this.subElements.add(elem); + super.addToContainerPanel(elem); + return elem; + } + + + // removes the passed element and all its handlers from the outer element + protected void removeListbox(ListBox elem) throws InvalidGdlSchemaException, ExecutionException{ + for (Pair<Widget, ArrayList<EventHandler>> item : this.eventHandlers) { + if(item.getFirst().equals(elem)){ + this.eventHandlers.remove(item); + break; + } + } + this.subElements.remove(elem); + elem.removeFromParent(); + } + + + // returns the gdl:multiple property - if no value is set the default value is returned + public boolean getMultiple() throws InvalidGdlSchemaException { + Occurrence multipleOcc = getNoneOrOneUnscopedOccurrence(GdlPsis.OccurrenceType.gdlMultiple); + + if(multipleOcc != null){ + String boolStr = multipleOcc.getValue().toUpperCase(); + if(boolStr.equals("TRUE")){ + return true; + } else if(boolStr.equals("FALSE")) { + return false; + } else { + throw new InvalidGdlSchemaException("The occurrence " + GdlPsis.OccurrenceType.gdlMargin + " must be set to one of "true" or "false", but is "" + multipleOcc.getValue() + """); + } + } else { + return false; + } + } + + + // returns the gdl:one-per-group property - if no value is set the default value is returned + public boolean getOnePerGroup() throws InvalidGdlSchemaException { + Occurrence onePerGroupOcc = getNoneOrOneUnscopedOccurrence(GdlPsis.OccurrenceType.gdlOnePerGroup); + + if(onePerGroupOcc != null){ + String boolStr = onePerGroupOcc.getValue().toUpperCase(); + if(boolStr.equals("TRUE")){ + return true; + } else if(boolStr.equals("FALSE")) { + return false; + } else { + throw new InvalidGdlSchemaException("The occurrence " + GdlPsis.OccurrenceType.gdlOnePerGroup + " must be set to one of "true" or "false", but is "" + onePerGroupOcc.getValue() + """); + } + } else { + return false; + } + } + + + // returns an int instance of a gdl:size occurrence. + // If no gdl:size occurrence is set, the default value is returned + public int getSize() throws InvalidGdlSchemaException { + Occurrence rowsOcc = getNoneOrOneUnscopedOccurrence(GdlPsis.OccurrenceType.gdlSize); + + if(rowsOcc != null){ + try{ + int value = Integer.valueOf(rowsOcc.getValue()); + if(value < 0) throw new InvalidGdlSchemaException("The occurrence " + GdlPsis.OccurrenceType.gdlSize + " must be set to a positive integer, but is "" + rowsOcc.getValue() + """); + else return value; + }catch(NumberFormatException e){ + throw new InvalidGdlSchemaException("The occurrence " + GdlPsis.OccurrenceType.gdlSize + " must be set to a positive integer, but is "" + rowsOcc.getValue() + """); + } + } else { + return 1; + } + } + + + // sets the size property of this element by using the GWT DOM class + public void setSize(Widget widget, int value){ + ((ListBox)widget).setVisibleItemCount(value); + } + + + // this method has not effect, it is defined only for consistency reasons + @Deprecated + public void setMultiple(Widget widget, boolean value){ + // Do nothing the gdl:multiple property is set in the createListBox method + // directly when calling the ListBox constructor + } + + + public void setOnePerGroup(Widget widget, boolean value){ + // TODO: implement => http://code.google.com/p/gwt-traction/source/browse/src/com/tractionsoftware... + } + + + // sets the css properties, by calling the super class's method and the local + // method, which sets some specific properties for the GdlText instance + @Override + public void setGdlStyle(Widget widget) throws InvalidGdlSchemaException, ExecutionException { + super.setGdlStyle(widget); + + this.setSize(widget, this.getSize()); + this.setOnePerGroup(widget, this.getOnePerGroup()); + } + + + // returns an ArrayList of string that contains all selected values + @Override + public ArrayList<String> getStringValue() { + ArrayList<String> results = new ArrayList<String>(); + for (Widget elem : super.subElements) { + ListBox lb = ((ListBox)elem); + if(lb.getSelectedIndex() != -1) results.add(lb.getValue(lb.getSelectedIndex())); + } + return results; + } + + + @Override + public ArrayList<Pair<TopicMapsTypes, Object>> getTmValue() { + // TODO Auto-generated method stub + return null; + } + + + @Override + public boolean validate() { + // TODO Auto-generated method stub + return false; + } +} \ No newline at end of file
Modified: branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/text/GdlText.java ============================================================================== --- branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/text/GdlText.java Thu Jul 7 07:44:51 2011 (r576) +++ branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/text/GdlText.java Thu Jul 7 08:49:40 2011 (r577) @@ -52,12 +52,12 @@ } - // creates a new TextArea item, adds it to the textElements array, + // creates a new TextArea item, adds it to the subElements array, // and applies the styles on it protected TextArea createNewTextArea() throws InvalidGdlSchemaException, ExecutionException { TextArea elem = new TextArea(); DOM.setElementAttribute(elem.getElement(), "id", this.getId() + "__GDL_" + this.subElements.size()); - this.setGdlStyle((Widget)elem); + this.setGdlStyle(elem); ActiveStyleHandler asHandler = new ActiveStyleHandler(this); FocusStyleHandler fsHandler = new FocusStyleHandler(this); HoverStyleHandler hsHandler = new HoverStyleHandler(this); @@ -448,7 +448,7 @@ } - // returns a boolean instance of a gdl:rows occurrence. + // returns an int instance of a gdl:rows occurrence. // If no gdl:rows occurrence is set, the default value is returned public int getRows() throws InvalidGdlSchemaException { Occurrence rowsOcc = getNoneOrOneUnscopedOccurrence(GdlPsis.OccurrenceType.gdlRows);
Modified: branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/text/GdlTextObject.java ============================================================================== --- branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/text/GdlTextObject.java Thu Jul 7 07:44:51 2011 (r576) +++ branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/text/GdlTextObject.java Thu Jul 7 08:49:40 2011 (r577) @@ -1,10 +1,7 @@ package us.isidor.gdl.anaToMia.Widgets.text;
- import com.google.gwt.dom.client.Style.FontStyle; -import com.google.gwt.user.client.ui.TextArea; import com.google.gwt.user.client.ui.Widget; - import us.isidor.gdl.anaToMia.TopicMaps.TopicMapsModel.Occurrence; import us.isidor.gdl.anaToMia.TopicMaps.TopicMapsModel.Topic; import us.isidor.gdl.anaToMia.Widgets.base.GdlPsis; @@ -283,66 +280,66 @@
// sets the direction style property of this element by using the GWT DOM class public void setDirection(Widget widget, DirectionValue value, String styleClass) throws InvalidGdlSchemaException, ExecutionException { - if(value != null) this.setCssProperty((TextArea)widget, styleClass, "direction", value.getCssValue()); + if(value != null) this.setCssProperty(widget, styleClass, "direction", value.getCssValue()); } // sets the text-align style property of this element by using the GWT DOM class public void setTextAlign(Widget widget, TextAlignValue value, String styleClass) throws InvalidGdlSchemaException, ExecutionException { - if(value != null) this.setCssProperty((TextArea)widget, styleClass, "textAlign", value.getCssValue()); + if(value != null) this.setCssProperty(widget, styleClass, "textAlign", value.getCssValue()); } // sets the line-height style property of this element by using the GWT DOM class public void setLineHeight(Widget widget, NormalNumUnitValue value, String styleClass) throws InvalidGdlSchemaException, ExecutionException { - if(value != null) this.setCssProperty((TextArea)widget, styleClass, "lineHeight", value.getCssValue()); + if(value != null) this.setCssProperty(widget, styleClass, "lineHeight", value.getCssValue()); } // sets the text-decoration style property of this element by using the GWT DOM class public void setTextDecoration(Widget widget, TextDecorationValue value, String styleClass) throws InvalidGdlSchemaException, ExecutionException { - if(value != null) this.setCssProperty((TextArea)widget, styleClass, "textDecoration", value.getCssValue()); + if(value != null) this.setCssProperty(widget, styleClass, "textDecoration", value.getCssValue()); } // sets the color style property of this element by using the GWT DOM class public void setColor(Widget widget, ColorValue value, String styleClass) throws InvalidGdlSchemaException, ExecutionException { - if(value != null) this.setCssProperty((TextArea)widget, styleClass, "color", value.getCssValue()); + if(value != null) this.setCssProperty(widget, styleClass, "color", value.getCssValue()); } // sets the font-family style property of this element by using the GWT DOM class public void setFontFamily(Widget widget, String value, String styleClass) throws InvalidGdlSchemaException, ExecutionException { - if(value != null) this.setCssProperty((TextArea)widget, styleClass, "fontFamily", value); + if(value != null) this.setCssProperty(widget, styleClass, "fontFamily", value); } // sets the font-style style property of this element by using the GWT DOM class public void setFontStyle(Widget widget, FontStyle value, String styleClass) throws InvalidGdlSchemaException, ExecutionException { - if(value != null) this.setCssProperty((TextArea)widget, styleClass, "fontStyle", value.getCssName()); + if(value != null) this.setCssProperty(widget, styleClass, "fontStyle", value.getCssName()); } // sets the font-size style property of this element by using the GWT DOM class public void setFontSize(Widget widget, PositiveNumUnitValue value, String styleClass) throws InvalidGdlSchemaException, ExecutionException { - if(value != null) this.setCssProperty((TextArea)widget, styleClass, "fontSize", value.getCssValue()); + if(value != null) this.setCssProperty(widget, styleClass, "fontSize", value.getCssValue()); } // sets the font-weight style property of this element by using the GWT DOM class public void setFontWeight(Widget widget, FontWeightValue value, String styleClass) throws InvalidGdlSchemaException, ExecutionException { - if(value != null) this.setCssProperty((TextArea)widget, styleClass, "fontWeight", value.getCssValue()); + if(value != null) this.setCssProperty(widget, styleClass, "fontWeight", value.getCssValue()); } // sets the letter-spacing style property of this element by using the GWT DOM class public void setLetterSpacing(Widget widget, NormalNumUnitValue value, String styleClass) throws InvalidGdlSchemaException, ExecutionException { - if(value != null) this.setCssProperty((TextArea)widget, styleClass, "letterSpacing", value.getCssValue()); + if(value != null) this.setCssProperty(widget, styleClass, "letterSpacing", value.getCssValue()); } // sets the word-spacing style property of this element by using the GWT DOM class public void setWordSpacing(Widget widget, NormalNumUnitValue value, String styleClass) throws InvalidGdlSchemaException, ExecutionException { - if(value != null) this.setCssProperty((TextArea)widget, styleClass, "wordSpacing", value.getCssValue()); + if(value != null) this.setCssProperty(widget, styleClass, "wordSpacing", value.getCssValue()); }