[isidorus-cvs] r579 - in branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets: base container values

lgiessmann at common-lisp.net lgiessmann at common-lisp.net
Fri Jul 8 07:01:51 UTC 2011


Author: lgiessmann
Date: Fri Jul  8 00:01:50 2011
New Revision: 579

Log:
gdl-frontend: Widgets: implemented GdlList

Added:
   branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/values/ListStylePositionValue.java
   branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/values/ListStyleTypeValue.java
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/GdlVisibleObject.java
   branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/container/GdlList.java

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 Jul  7 09:29:24 2011	(r578)
+++ branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/base/GdlPsis.java	Fri Jul  8 00:01:50 2011	(r579)
@@ -129,7 +129,7 @@
 		public final static String gdlFloat = gdl + "float";
 		public final static String gdlBackgroundColor = gdl + "background-color";
 		public final static String gdlOrdered = gdl + "ordered";
-		public final static String gdlListstyleType = gdl + "list-style-type";
+		public final static String gdlListStyleType = gdl + "list-style-type";
 		public final static String gdlListStylePosition = gdl + "list-style-position";
 		public final static String gdlPositionStyle = gdl + "position-style";
 		public final static String gdlNthValue = gdl + "nth-value";

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	Thu Jul  7 09:29:24 2011	(r578)
+++ branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/base/GdlVisibleObject.java	Fri Jul  8 00:01:50 2011	(r579)
@@ -914,7 +914,7 @@
 			return null;
 		} else {
 			return new NumUnitValue(paddingOcc.getValue());
-		}		
+		}
 	}
 
 

Modified: branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/container/GdlList.java
==============================================================================
--- branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/container/GdlList.java	Thu Jul  7 09:29:24 2011	(r578)
+++ branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/container/GdlList.java	Fri Jul  8 00:01:50 2011	(r579)
@@ -1,49 +1,289 @@
 package us.isidor.gdl.anaToMia.Widgets.container;
 
+import java.util.ArrayList;
 import com.google.gwt.dom.client.Element;
 import com.google.gwt.user.client.DOM;
-
+import com.google.gwt.user.client.ui.Composite;
+import com.google.gwt.user.client.ui.SimplePanel;
+import com.google.gwt.user.client.ui.Widget;
+import com.google.gwt.dom.client.Node;
+import us.isidor.gdl.anaToMia.TopicMaps.TopicMapsModel.Occurrence;
 import us.isidor.gdl.anaToMia.TopicMaps.TopicMapsModel.Topic;
+import us.isidor.gdl.anaToMia.Widgets.base.GdlPsis;
 import us.isidor.gdl.anaToMia.Widgets.base.GdlVisibleObject;
-import us.isidor.gdl.anaToMia.Widgets.base.IGdlContainer;
 import us.isidor.gdl.anaToMia.Widgets.environment.ExecutionException;
 import us.isidor.gdl.anaToMia.Widgets.environment.InvalidGdlSchemaException;
+import us.isidor.gdl.anaToMia.Widgets.environment.Pair;
+import us.isidor.gdl.anaToMia.Widgets.values.ListStylePositionValue;
+import us.isidor.gdl.anaToMia.Widgets.values.ListStyleTypeValue;
 
-public class GdlList extends GdlVisibleObject implements IGdlContainer{
-	protected Element listElement = null;
+public class GdlList extends GdlVisibleObject{
+	
 	
 	// some constructors
-	protected GdlList(){
+	protected GdlList() throws InvalidGdlSchemaException{
 		super();
+		this.initList(this.getOrdered());
 	}
 	
 	
 	public GdlList(Topic tmRepresentative) throws InvalidGdlSchemaException, ExecutionException{
 		super(tmRepresentative);
+		this.initList(this.getOrdered());
 	}
 	
 	
-	public void initList(boolean ordered){
-		Element elem = DOM.createElement(ordered ? "ol" : "ul");
-		super.addToContainerPanel(elem);
+	// sets the list Element to either ol or ul depending on the gdl:ordered property
+	public void initList(boolean ordered) throws InvalidGdlSchemaException {
+		// this object is able to own only one sub-element
+		super.subElements.add(new ListWidget(this.getOrdered()));
 	}
 	
 	
-	public void createListItem(){
-		
+	// returns the property of a gdl:ordered occurrence, otherwise the default value if no occurrence is set
+	public boolean getOrdered() throws InvalidGdlSchemaException{
+		Occurrence orderedOcc = getNoneOrOneUnscopedOccurrence(GdlPsis.OccurrenceType.gdlOrdered);
+
+		if(orderedOcc != null){
+			String boolStr = orderedOcc.getValue().toUpperCase();
+			if(boolStr.equals("TRUE")){
+				return true;
+			} else if(boolStr.equals("FALSE")) {
+				return false;
+			} else {
+				throw new InvalidGdlSchemaException("The occurrence " + GdlPsis.OccurrenceType.gdlOrdered + " must be set to one of \"true\" or \"false\", but is \"" + orderedOcc.getValue() + "\"");
+			}
+		} else {
+			return false;
+		}
 	}
 	
 	
-	public boolean getOrdered(){
-		// TODO: implement
-		return false;
+	// returns a ListStyleTypeValeu instance that describes this instance's list style type property
+	public ListStyleTypeValue getListStyleType() throws InvalidGdlSchemaException {
+		Occurrence typeOcc = getNoneOrOneUnscopedOccurrence(GdlPsis.OccurrenceType.gdlListStyleType);
+
+		if(typeOcc != null){
+			try{
+				return ListStyleTypeValue.fromString(typeOcc.getValue());
+			}catch(IllegalArgumentException e){
+				String values = "deciaml, decimal-leading-zero, lower-greek, lower-roman, armenian, georgian, upper-roman, " +
+								"lower-alpha, upper-alpha, lower-latin, upper-latin, disc, circle, square or none";
+				throw new InvalidGdlSchemaException("The occurrence " + GdlPsis.OccurrenceType.gdlListStyleType + " must be set to one of " + values + " , but is \"" + typeOcc.getValue() + "\"");
+			}
+		} else if(this.getOrdered()){
+			return ListStyleTypeValue.DECIMAL;
+		} else {
+			return ListStyleTypeValue.CIRCLE;
+		}
 	}
 
+	
+	// returns a ListStylePositionValue instance that describes this instance's list style position property
+	public ListStylePositionValue getListStylePosition() throws InvalidGdlSchemaException {
+		Occurrence positionOcc = getNoneOrOneUnscopedOccurrence(GdlPsis.OccurrenceType.gdlListStylePosition);
 
+		if(positionOcc != null){
+			try{
+				return ListStylePositionValue.valueOf(positionOcc.getValue().toUpperCase());
+			}catch(IllegalArgumentException e){
+				throw new InvalidGdlSchemaException("The occurrence " + GdlPsis.OccurrenceType.gdlListStylePosition + " must be set to one of inside or outside, but is \"" + positionOcc.getValue() + "\"");
+			}
+		} else{
+			return ListStylePositionValue.OUTSIDE;
+		}
+		
+	}
+
+	
+	// sets the css property ordered
+	@Deprecated
+	public void setOrdered(Widget widget, boolean value) throws InvalidGdlSchemaException, ExecutionException {
+		// do nothing this property has to be set in the initList mehtod
+	}
+	
+	
+	// sets the css property list-style-type
+	public void setListStyleType(Widget widget, ListStyleTypeValue value) throws InvalidGdlSchemaException, ExecutionException {
+		this.setCssProperty(widget, null, "list-style-type", value.getCssValue());
+	}
+	
+	
+	// sets the css property list-style-position
+	public void setListStylePositionValue(Widget widget, ListStylePositionValue value) throws InvalidGdlSchemaException, ExecutionException {
+		this.setCssProperty(widget, null, "list-style-position", value.getCssValue());
+	}
+	
+	
+	// calls the super applies the GdlStyle for every TextArea item of this instance
+	@Override
+	protected void setGdlStyle() throws InvalidGdlSchemaException, ExecutionException{
+		if(this.subElements != null){
+			for (Widget item : this.subElements) {
+				this.setGdlStyle(item);
+			}
+		}
+	}
+	
+	
+	// sets the css properties, by calling the super class's method and the local
+	// method, which sets some specific properties for the GdlList instance
 	@Override
-	public void append(GdlVisibleObject ancestor, GdlVisibleObject descendant)
-			throws InvalidGdlSchemaException {
-		// TODO Auto-generated method stub
+	public void setGdlStyle(Widget widget) throws InvalidGdlSchemaException, ExecutionException {
+		super.setGdlStyle(widget);
+
+		this.setListStylePositionValue(widget, this.getListStylePosition());
+		this.setListStyleType(widget, this.getListStyleType());
+	}
+	
+	
+	// inserts the passed item on the given index
+	public void append(GdlVisibleObject item, int position){
+		if(this.subElements != null && this.subElements.size() != 0){
+			((ListWidget)this.subElements.get(0)).insertWidget(item, position);
+		}
+	}
+	
+	
+	// Wraps a ul an ol element as a widget based on a SimplePanel
+	protected class ListWidget extends Composite {
+		private SimplePanel basePanel = new SimplePanel();
+		private Element listElement = null;
+		// note: index is not the actual index of the item in the array list,
+		// it is the user's passed index when inserting this element
+		private ArrayList<Pair<ListItem, Integer>> itemsAndIndexes = new ArrayList<Pair<ListItem, Integer>>();
+		
+		public ListWidget(){
+			this.listElement = DOM.createElement("ul");
+			this.basePanel.getElement().insertFirst(this.listElement);
+		}
+		
+		public ListWidget(boolean ordered){
+			if(ordered) this.listElement = DOM.createElement("ol");
+			else this.listElement = DOM.createElement("ul");
+			this.basePanel.getElement().insertFirst(this.listElement);
+		}
+		
+		
+		// inserts the passed list item as the last child to this list element
+		public void appendListItem(ListItem item){
+			if(item == null) return;
+			item.appendToList(this.listElement);
+		}
+		
+		
+		// inserts the passed instance item to this list directly after the intance previous
+		public void appendListItem(ListItem item, ListItem previous){
+			if(item == null) return;
+			item.appendToList(this.listElement, previous);
+		}
+		
+		
+		// inserts the passed widget directly before the first item that
+		// has a greater position index
+		public void insertWidget(Widget widget, int position){
+			ListItem previosItem = this.getItemBeforeIndex(position);
+			ListItem item = new ListItem(this.listElement);
+			item.appendContentToListItem(widget.getElement());
+			this.appendListItem(item, previosItem);
+		}
+		
+		
+		// returns the first item that has a smaller position index 
+		public ListItem getItemBeforeIndex(int idx){
+			Pair<ListItem, Integer> result = null;
+			for (Pair<ListItem, Integer> item : this.itemsAndIndexes) {
+				if(item.getSecond() < idx && (result == null || result.getSecond() < item.getSecond()))result = item;
+			}
+		
+			if(result != null) result.getFirst();
+			return null;
+		}
+		
+		
+		// returns all ListItems
+		public ArrayList<ListItem> getItems(){
+			ArrayList<ListItem> items = new ArrayList<GdlList.ListItem>();
+			for (Pair<ListItem, Integer> pair : this.itemsAndIndexes) {
+				items.add(pair.getFirst());
+			}
+			return items;
+		}
+		
+		
+		// returns the position index of the item, that was psecified when
+		// inserting the passed ListItem
+		public int indexOfItem(ListItem item){
+			for (Pair<ListItem, Integer> pair : this.itemsAndIndexes) {
+				if(pair.getFirst().equals(item)) return pair.getSecond();
+			}
+			
+			return -1;
+		}
+	}
+	
+	
+	// this class wrapps a list item, i.e. a div element within a li element
+	protected class ListItem{
+		private Element liElement = null;
+		private Element divElement = null;
+		
+		public ListItem(){
+			this.liElement = DOM.createElement("li");
+			this.divElement = DOM.createElement("div");
+			this.liElement.insertFirst(this.divElement);
+		}
+		
+		public ListItem(Element parentList){
+			this();
+			this.appendToList(parentList);
+		}
+		
+		// inserts the this instance into the passed list element,
+		// if this instance is not bound yet
+		public void appendToList(Element parentList){
+			if(parentList != null && this.liElement.getParentNode() == null){
+				Node lastChild = parentList.getLastChild();
+				if(lastChild != null){
+					parentList.insertAfter(this.liElement, lastChild);
+				} else {
+					parentList.insertFirst(this.liElement);
+				}
+			}
+		}
+		
+		
+		// inserts the this instance into the passed list element
+		// after the passed ListItem, if this instance is not bound yet
+		public void appendToList(Element parentList, ListItem previous){
+			if(parentList == null) return;
+			
+			if(previous == null){
+				this.appendToList(parentList);
+			}else{
+				parentList.insertAfter(this.liElement, previous.liElement);
+			}
+		}
+		
+		
+		// removes this instance from the set list
+		public void removeFromList(){
+			this.liElement.removeFromParent();
+		}
+		
+		// appends the content element to the inner div item
+		public void appendContentToListItem(Element content){
+			if(content != null){
+				Node lastChild = this.divElement.getLastChild();
+				if(lastChild != null){
+					this.divElement.insertAfter(content, lastChild);
+				} else {
+					this.divElement.insertFirst(content);
+				}
+			}
+		}
+		
+		
 		
 	}
 }

Added: branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/values/ListStylePositionValue.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/ListStylePositionValue.java	Fri Jul  8 00:01:50 2011	(r579)
@@ -0,0 +1,13 @@
+package us.isidor.gdl.anaToMia.Widgets.values;
+
+public enum ListStylePositionValue implements CssValue {
+	INSIDE,
+	OUTSIDE;
+	
+
+	@Override
+	public String getCssValue() {
+		return this.toString().toLowerCase();
+	}
+
+}

Added: branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/values/ListStyleTypeValue.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/ListStyleTypeValue.java	Fri Jul  8 00:01:50 2011	(r579)
@@ -0,0 +1,47 @@
+package us.isidor.gdl.anaToMia.Widgets.values;
+
+public enum ListStyleTypeValue implements CssValue{
+	DECIMAL,
+	DECIMAL_LEADING_ZERO,
+	LOWER_GREEK,
+	LOWER_ROMAN,
+	ARMENIAN,
+	GEORGIAN,
+	UPPER_ROMAN,
+	LOWER_ALPHA,
+	UPPER_ALPHA,
+	LOWER_LATIN,
+	UPPER_LATIN,
+	DISC,
+	CIRCLE,
+	SQUARE,
+	NONE;
+
+	@Override
+	public String getCssValue() {
+		return this.toString().toLowerCase().replace("_", "-");
+	}
+	
+	
+	public static ListStyleTypeValue fromString(String str) throws IllegalArgumentException{
+		if(null == str) return null;
+		
+		String upperStr = str.toUpperCase();
+		if(upperStr.equals("DECIMAL")) return DECIMAL;
+		else if(upperStr.equals("DECIMAL-LEADING-ZERO")) return DECIMAL_LEADING_ZERO;
+		else if(upperStr.equals("LOWER-GREEK")) return LOWER_GREEK;
+		else if(upperStr.equals("LOWER-ROMAN")) return LOWER_ROMAN;
+		else if(upperStr.equals("ARMENIAN")) return ARMENIAN;
+		else if(upperStr.equals("GEORGIAN")) return GEORGIAN;
+		else if(upperStr.equals("UPPER-ROMAN")) return UPPER_ROMAN;
+		else if(upperStr.equals("LOWER-ALPHA")) return LOWER_ALPHA;
+		else if(upperStr.equals("UPPER-ALPHA")) return UPPER_ALPHA;
+		else if(upperStr.equals("LOWER-LATIN")) return LOWER_LATIN;
+		else if(upperStr.equals("UPPER-LATIN")) return UPPER_LATIN;
+		else if(upperStr.equals("DISC")) return DISC;
+		else if(upperStr.equals("CIRCLE")) return CIRCLE;
+		else if(upperStr.equals("SQUARE")) return SQUARE;
+		else if(upperStr.equals("NONE")) return NONE;
+		else throw new IllegalArgumentException("the value " + str + "is not a FontWeightValue value");
+	}
+}




More information about the Isidorus-cvs mailing list