[isidorus-cvs] r588 - in branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets: base environment text values
lgiessmann at common-lisp.net
lgiessmann at common-lisp.net
Fri Jul 8 17:29:09 UTC 2011
Author: lgiessmann
Date: Fri Jul 8 10:29:08 2011
New Revision: 588
Log:
gdl-frontend: Widgets: implemented a GWT widget as a pendant to the java.util.Pattern for regular expressions
Added:
branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/environment/Pattern.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
branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/text/GdlTitle.java
branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/values/FontWeightValue.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/GdlVisibleObject.java Fri Jul 8 09:27:41 2011 (r587)
+++ branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/base/GdlVisibleObject.java Fri Jul 8 10:29:08 2011 (r588)
@@ -105,8 +105,11 @@
public static void replaceStyleProperty(Element elem, String styleName, String styleValue){
String oldStyle = elem.getAttribute("style");
+ //Window.alert(">> _" + oldStyle + "_<<" + " >> _" + styleName + "_<< => " + oldStyle.matches("(^| |;)" + styleName + " *:")); // TODO: remove
if(oldStyle.matches("(^| |;)" + styleName + " *:")){
- elem.setAttribute("style", oldStyle.replaceAll(styleName + ":.+;", styleName + ": " + styleValue + ";"));
+ Window.alert("!!!TEST!!!");
+
+ elem.setAttribute("style", oldStyle.replaceFirst(styleName + ":.+;", styleName + ": " + styleValue + ";"));
} else {
elem.setAttribute("style", oldStyle + " " + styleName + ": " + styleValue + ";");
}
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 Fri Jul 8 09:27:41 2011 (r587)
+++ branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/base/TestClass.java Fri Jul 8 10:29:08 2011 (r588)
@@ -1,12 +1,11 @@
package us.isidor.gdl.anaToMia.Widgets.base;
+
import us.isidor.gdl.anaToMia.TmEngine.jtmsBasedEngine.JtmsTmEngine;
import us.isidor.gdl.anaToMia.TopicMaps.TopicMapsModel.Occurrence;
import us.isidor.gdl.anaToMia.TopicMaps.TopicMapsModel.Topic;
-import us.isidor.gdl.anaToMia.Widgets.container.GdlList;
+import us.isidor.gdl.anaToMia.Widgets.environment.Pattern;
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.text.GdlTitle;
import us.isidor.gdl.anaToMia.Widgets.values.CursorValue;
import com.google.gwt.core.client.EntryPoint;
@@ -124,6 +123,20 @@
GdlTitle tmp = new GdlTitle(tmpRepresentative);
this.mainPanel.add(tmp);
+
+
+
+
+ String oldStyle = "margin: 0px; width: 300px; max-idth: auto; min-width: auto; height: 300px; max-height: auto; min-height: auto; color: #000000; direction: rtl; text-align: left; line-height: normal; text-decoration: underline; font-style: normal; font-size: 15pt; font-weight: NORMAL; letter-spacing: normal; word-spacing: normal; font-size: 25pt; font-size: 25pt; width: 300px; max-idth: auto; min-width: auto; height: 300px; max-height: auto; min-height: auto; color: #000000; direction: rtl; text-align: left; line-height: ... word-spacing: normal; font-size: 25pt; font-size: 25pt; font-size: 25pt; font-size: 25pt; font-size: 25pt; font-size: 25pt; font-size: 25pt; font-size: 25pt; font-size: 25pt; font-size: 25pt; font-size: 25pt; width: 300px; max-idth: auto; min-width: auto; height: 300px; max-height: auto; min-height: auto; color: #000000; direction: rtl; text-align: left; line-height: normal; text-decoration: underline; font-style: normal; font-size: 15pt; font-weight: NORMAL; letter-spacing: normal; word-spacing: normal;";
+
+ /*
+ String rex = "width";
+ Window.alert(" ==> " + oldStyle.matches("width"));
+ Window.alert(oldStyle.replaceAll(" width:[^;]*;", " WIDTH:xyz;"));
+ */
+
+ Pattern pattern = new Pattern("width");
+ Window.alert(">> " + pattern.matches(oldStyle));
}catch(Exception e){
e.printStackTrace();
Window.alert(">> e >> " + e.getClass() + " >> " + e.getMessage());
Added: branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/environment/Pattern.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/environment/Pattern.java Fri Jul 8 10:29:08 2011 (r588)
@@ -0,0 +1,182 @@
+package us.isidor.gdl.anaToMia.Widgets.environment;
+
+// source: http://www.java2s.com/Code/Java/GWT/ImplementjavautilregexPatternwithJavascriptRegExpobject.htm
+
+/*
+ * Copyright 2006 Robert Hanson <iamroberthanson AT gmail.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.util.ArrayList;
+import java.util.List;
+
+import com.google.gwt.core.client.JavaScriptObject;
+
+/**
+ * <p>
+ * Implementation of the {@link java.util.regex.Pattern} class with a
+ * wrapper aroung the Javascript <a href="http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Guide:Regular_Expressions">RegExp</a> object.
+ * As most of the methods delegate to the JavaScript RegExp object, certain differences in the
+ * declaration and behaviour of regular expressions must be expected.
+ * </p>
+ * <p>
+ * Please note that neither the {@link java.util.regex.Pattern#compile(String)} method nor
+ * {@link Matcher} instances are supported. For the later, consider using {@link Pattern#match(String)}.
+ * </p>
+ *
+ * @author George Georgovassilis
+ *
+ */
+public class Pattern {
+
+ /**
+ * Declares that regular expressions should be matched across line borders.
+ */
+ public final static int MULTILINE = 1;
+
+ /**
+ * Declares that characters are matched reglardless of case.
+ */
+ public final static int CASE_INSENSITIVE = 2;
+
+ private JavaScriptObject regExp;
+
+ private static JavaScriptObject createExpression(String pattern, int flags) {
+ String sFlags = "";
+ if ((flags & MULTILINE) != 0)
+ sFlags += "m";
+ if ((flags & CASE_INSENSITIVE) != 0)
+ sFlags += "i";
+ return _createExpression(pattern, sFlags);
+ }
+
+ private static native JavaScriptObject _createExpression(String pattern,
+ String flags)/*-{
+ return new RegExp(pattern, flags);
+ }-*/;
+
+ private native void _match(String text, @SuppressWarnings("rawtypes") List matches)/*-{
+ var regExp = this. at us.isidor.gdl.anaToMia.Widgets.environment.Pattern::regExp;
+ var result = text.match(regExp);
+ if (result == null) return;
+ for (var i=0;i<result.length;i++)
+ matches. at java.util.ArrayList::add(Ljava/lang/Object;)(result[i]);
+ }-*/;
+
+ /**
+ * Determines wether the specified regular expression is validated by the
+ * provided input.
+ * @param regex Regular expression
+ * @param input String to validate
+ * @return <code>true</code> if matched.
+ */
+ public static boolean matches(String regex, String input) {
+ return new Pattern(regex).matches(input);
+ }
+
+ /**
+ * Escape a provided string so that it will be interpreted as a literal
+ * in regular expressions.
+ * The current implementation does escape each character even if not neccessary,
+ * generating verbose literals.
+ * @param input
+ * @return
+ */
+ public static String quote(String input) {
+ String output = "";
+ for (int i = 0; i < input.length(); i++) {
+ output += "\\" + input.charAt(i);
+ }
+ return output;
+ }
+
+ /**
+ * Class constructor
+ * @param pattern Regular expression
+ */
+ public Pattern(String pattern) {
+ this(pattern, 0);
+ }
+
+ /**
+ * Class constructor
+ * @param pattern Regular expression
+ * @param flags
+ */
+ public Pattern(String pattern, int flags) {
+ regExp = createExpression(pattern, flags);
+ }
+
+ /**
+ * This method is borrowed from the JavaScript RegExp object.
+ * It parses a string and returns as an array any assignments to parenthesis groups
+ * in the pattern's regular expression
+ * @param text
+ * @return Array of strings following java's Pattern convention for groups:
+ * Group 0 is the entire input string and the remaining groups are the matched parenthesis.
+ * In case nothing was matched an empty array is returned.
+ */
+ public String[] match(String text) {
+ @SuppressWarnings("rawtypes")
+ List matches = new ArrayList();
+ _match(text, matches);
+ String arr[] = new String[matches.size()];
+ for (int i = 0; i < matches.size(); i++)
+ arr[i] = matches.get(i).toString();
+ return arr;
+ }
+
+ /**
+ * Determines wether a provided text matches the regular expression
+ * @param text
+ * @return
+ */
+ public native boolean matches(String text)/*-{
+ var regExp = this. at us.isidor.gdl.anaToMia.Widgets.environment.Pattern::regExp;
+ return regExp.test(text);
+ }-*/;
+
+ /**
+ * Returns the regular expression for this pattern
+ * @return
+ */
+ public native String pattern()/*-{
+ var regExp = this. at us.isidor.gdl.anaToMia.Widgets.environment.Pattern::regExp;
+ return regExp.source;
+ }-*/;
+
+ private native void _split(String input, @SuppressWarnings("rawtypes") List results)/*-{
+ var regExp = this. at us.isidor.gdl.anaToMia.Widgets.environment.Pattern::regExp;
+ var parts = input.split(regExp);
+ for (var i=0;i<parts.length;i++)
+ results. at java.util.ArrayList::add(Ljava/lang/Object;)(parts[i] );
+ }-*/;
+
+ /**
+ * Split an input string by the pattern's regular expression
+ * @param input
+ * @return Array of strings
+ */
+ public String[] split(String input){
+ @SuppressWarnings("rawtypes")
+ List results = new ArrayList();
+ _split(input, results);
+ String[] parts = new String[results.size()];
+ for (int i=0;i<results.size();i++)
+ parts[i] = (String)results.get(i);
+ return parts;
+ }
+
+}
+
Modified: branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/text/GdlTitle.java
==============================================================================
--- branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/text/GdlTitle.java Fri Jul 8 09:27:41 2011 (r587)
+++ branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/text/GdlTitle.java Fri Jul 8 10:29:08 2011 (r588)
@@ -278,10 +278,10 @@
public void setWidth(Widget widget, AutoNumUnitValue value, String styleClass) throws InvalidGdlSchemaException, ExecutionException {
if(value != null && widget.getClass().equals(TitleWidget.class)) {
if(styleClass == null){
- super.replaceStyleProperty(((TitleWidget)widget).getTitleElement(), "width", value.getCssValue());
+ super.replaceStyleProperty(((TitleWidget)widget).getTitleElement(), "width", value.getCssValue()); // TODO: fix
}
this.addStyleToStore(styleClass, "width", value.getCssValue());
- this.setCssProperty(widget, styleClass, "width", value.getCssValue());
+ super.setCssProperty(widget, styleClass, "width", value.getCssValue());
}
}
@@ -290,10 +290,10 @@
public void setMinWidth(Widget widget, AutoNumUnitValue value, String styleClass) throws InvalidGdlSchemaException, ExecutionException {
if(value != null && widget.getClass().equals(TitleWidget.class)) {
if(styleClass == null){
- super.replaceStyleProperty(((TitleWidget)widget).getTitleElement(), "minWidth", value.getCssValue());
+ super.replaceStyleProperty(((TitleWidget)widget).getTitleElement(), "min-width", value.getCssValue());
}
- this.addStyleToStore(styleClass, "minWidth", value.getCssValue());
- this.setCssProperty(widget, styleClass, "minWidth", value.getCssValue());
+ this.addStyleToStore(styleClass, "min-width", value.getCssValue());
+ super.setCssProperty(widget, styleClass, "minWidth", value.getCssValue());
}
}
@@ -302,10 +302,10 @@
public void setMaxWidth(Widget widget, AutoNumUnitValue value, String styleClass) throws InvalidGdlSchemaException, ExecutionException {
if(value != null && widget.getClass().equals(TitleWidget.class)) {
if(styleClass == null){
- super.replaceStyleProperty(((TitleWidget)widget).getTitleElement(), "maxWidth", value.getCssValue());
+ super.replaceStyleProperty(((TitleWidget)widget).getTitleElement(), "max-width", value.getCssValue());
}
- this.addStyleToStore(styleClass, "maxWidth", value.getCssValue());
- this.setCssProperty(widget, styleClass, "maxWidth", value.getCssValue());
+ this.addStyleToStore(styleClass, "max-width", value.getCssValue());
+ super.setCssProperty(widget, styleClass, "maxWidth", value.getCssValue());
}
}
@@ -317,7 +317,7 @@
super.replaceStyleProperty(((TitleWidget)widget).getTitleElement(), "height", value.getCssValue());
}
this.addStyleToStore(styleClass, "height", value.getCssValue());
- this.setCssProperty(widget, styleClass, "height", value.getCssValue());
+ super.setCssProperty(widget, styleClass, "height", value.getCssValue());
}
}
@@ -326,10 +326,10 @@
public void setMinHeight(Widget widget, AutoNumUnitValue value, String styleClass) throws InvalidGdlSchemaException, ExecutionException {
if(value != null && widget.getClass().equals(TitleWidget.class)) {
if(styleClass == null){
- super.replaceStyleProperty(((TitleWidget)widget).getTitleElement(), "minHeight", value.getCssValue());
+ super.replaceStyleProperty(((TitleWidget)widget).getTitleElement(), "min-height", value.getCssValue());
}
- this.addStyleToStore(styleClass, "minHeight", value.getCssValue());
- this.setCssProperty(widget, styleClass, "minHeight", value.getCssValue());
+ this.addStyleToStore(styleClass, "min-height", value.getCssValue());
+ super.setCssProperty(widget, styleClass, "minHeight", value.getCssValue());
}
}
@@ -338,10 +338,10 @@
public void setMaxHeight(Widget widget, AutoNumUnitValue value, String styleClass) throws InvalidGdlSchemaException, ExecutionException {
if(value != null && widget.getClass().equals(TitleWidget.class)) {
if(styleClass == null){
- super.replaceStyleProperty(((TitleWidget)widget).getTitleElement(), "maxHeight", value.getCssValue());
+ super.replaceStyleProperty(((TitleWidget)widget).getTitleElement(), "max-height", value.getCssValue());
}
- this.addStyleToStore(styleClass, "maxHeight", value.getCssValue());
- this.setCssProperty(widget, styleClass, "maxHeight", value.getCssValue());
+ this.addStyleToStore(styleClass, "max-height", value.getCssValue());
+ super.setCssProperty(widget, styleClass, "maxHeight", value.getCssValue());
}
}
Modified: branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/values/FontWeightValue.java
==============================================================================
--- branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/values/FontWeightValue.java Fri Jul 8 09:27:41 2011 (r587)
+++ branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/values/FontWeightValue.java Fri Jul 8 10:29:08 2011 (r588)
@@ -17,7 +17,7 @@
@Override
public String getCssValue() {
- String str = this.toString();
+ String str = this.toString().toLowerCase();
if(str.startsWith("_")) return str.substring(1);
else return str;
}
More information about the Isidorus-cvs
mailing list