|
From: <fb...@us...> - 2003-07-14 21:02:33
|
Update of /cvsroot/jgb/jgb/src/java/core/jgb/handlers/swing
In directory sc8-pr-cvs1:/tmp/cvs-serv31851/src/java/core/jgb/handlers/swing
Modified Files:
AbstractControlTagHandler.java ConstraintsTagHandler.java
Log Message:
* src/java/tests/jgb/handlers/swing/TestConstraintsTagHandler.java:
Started implementing new constraints-handling code. Started making
constraints be saved in a Map instead of last defined. The map is
associative with the current object. So constraints are attached to
their parent objects, but are used for children of said parent.
* src/java/core/jgb/handlers/swing/ConstraintsTagHandler.java:
Implemented tests.
* src/java/core/jgb/handlers/swing/AbstractControlTagHandler.java,
src/java/tests/jgb/handlers/swing/TestAbstractControlTagHandler.java,
src/java/tests/jgb/handlers/swing/TestControlTagHandler.java,
src/java/tests/jgb/handlers/swing/TestGlueTagHandler.java,
src/java/tests/jgb/handlers/swing/TestStrutTagHandler.java:
Had to modify tests to take into account new Constraints object
and way of doing things.
* src/examples/webbrowser.xml:
Works, but not exactly right. Problem with constraints that are not
properly associated. All controls are so small as to be useless...
Added a "Dump" menu item to use XMLEncoder to dump the frame.
* src/java/examples/jgb/examples/WebBrowserEventManager.java:
Modified to implement the dump() method required by the register
call of the dump menu item.
* src/java/core/jgb/builder/utils/Constraints.java:
Created implementation that is a data holder for two pieces of
information: value and class. No tests for such a simple class.
Index: AbstractControlTagHandler.java
===================================================================
RCS file: /cvsroot/jgb/jgb/src/java/core/jgb/handlers/swing/AbstractControlTagHandler.java,v
retrieving revision 1.13
retrieving revision 1.14
diff -C2 -d -r1.13 -r1.14
*** AbstractControlTagHandler.java 27 Jun 2003 16:45:48 -0000 1.13
--- AbstractControlTagHandler.java 14 Jul 2003 21:02:30 -0000 1.14
***************
*** 21,27 ****
--- 21,29 ----
import jgb.builder.TagHandler;
+ import jgb.builder.utils.Constraints;
import java.awt.*;
import java.util.EmptyStackException;
+ import java.util.Map;
/**
***************
*** 92,103 ****
}
! Container parent = (Container)getCurrentControl();
Object constraints = getCurrentConstraints();
if (parent.getLayout() instanceof GridBagLayout) {
! GridBagLayout layout = (GridBagLayout)parent.getLayout();
! layout.setConstraints(component, (GridBagConstraints)constraints);
parent.add(component);
! } else {
parent.add(component, constraints);
}
--- 94,110 ----
}
! Container parent = (Container) getCurrentControl();
Object constraints = getCurrentConstraints();
if (parent.getLayout() instanceof GridBagLayout) {
! if (null != constraints) {
! GridBagLayout layout = (GridBagLayout) parent.getLayout();
! layout.setConstraints(component, (GridBagConstraints) constraints);
! }
!
parent.add(component);
! } else if (null != constraints) {
parent.add(component, constraints);
+ } else {
+ parent.add(component);
}
***************
*** 118,122 ****
*/
protected Component getCurrentControl() {
! return (Component)super.getCurrentObject();
}
--- 125,129 ----
*/
protected Component getCurrentControl() {
! return (Component) super.getCurrentObject();
}
***************
*** 143,147 ****
*/
protected Object getCurrentConstraints() {
! return tagContext.get(TagHandler.CURRENT_CONSTRAINTS_KEY);
}
--- 150,161 ----
*/
protected Object getCurrentConstraints() {
! Map constraintsMap = (Map) tagContext.get(TagHandler.CURRENT_CONSTRAINTS_KEY);
! if (null == constraintsMap) {
! return null;
! } else if (constraintsMap.containsKey(getCurrentObject())) {
! return ((Constraints) constraintsMap.get(getCurrentObject())).getValue();
! } else {
! return null;
! }
}
Index: ConstraintsTagHandler.java
===================================================================
RCS file: /cvsroot/jgb/jgb/src/java/core/jgb/handlers/swing/ConstraintsTagHandler.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -C2 -d -r1.9 -r1.10
*** ConstraintsTagHandler.java 27 Jun 2003 16:45:49 -0000 1.9
--- ConstraintsTagHandler.java 14 Jul 2003 21:02:30 -0000 1.10
***************
*** 21,26 ****
--- 21,28 ----
import jgb.builder.TagHandler;
+ import jgb.builder.utils.Constraints;
import org.xml.sax.SAXException;
+ import java.util.HashMap;
import java.util.Map;
***************
*** 39,43 ****
protected void enterElement(Map atts) throws SAXException {
if (atts.containsKey(ATTR_RESET)) {
! tagContext.remove(TagHandler.CURRENT_CONSTRAINTS_KEY);
tagContext.put(EMPTY_KEY, "true");
}
--- 41,46 ----
protected void enterElement(Map atts) throws SAXException {
if (atts.containsKey(ATTR_RESET)) {
! final Map constraintsMap = getCurrentConstraints();
! constraintsMap.remove(getCurrentObject());
tagContext.put(EMPTY_KEY, "true");
}
***************
*** 45,57 ****
public void exitElement() throws SAXException {
if (tagContext.containsKey(EMPTY_KEY)) {
tagContext.remove(EMPTY_KEY);
} else {
! tagContext.put(TagHandler.CURRENT_CONSTRAINTS_KEY,
! tagContext.get(TagHandler.PARAMETER_VALUE_KEY));
}
tagContext.remove(TagHandler.PARAMETER_CLASS_KEY);
tagContext.remove(TagHandler.PARAMETER_VALUE_KEY);
}
}
--- 48,83 ----
public void exitElement() throws SAXException {
+ if (null == getCurrentObject()) {
+ throwParsingException("Parent object is null ! Cannot set constraints...");
+ }
+
+ final Map constraintsMap = getCurrentConstraints();
+
if (tagContext.containsKey(EMPTY_KEY)) {
+ constraintsMap.remove(getCurrentObject());
tagContext.remove(EMPTY_KEY);
} else {
! constraintsMap.put(getCurrentObject(), new Constraints(
! tagContext.get(TagHandler.PARAMETER_VALUE_KEY),
! (Class) tagContext.get(TagHandler.PARAMETER_CLASS_KEY)));
}
tagContext.remove(TagHandler.PARAMETER_CLASS_KEY);
tagContext.remove(TagHandler.PARAMETER_VALUE_KEY);
+ }
+
+ private Map getCurrentConstraints() throws SAXException {
+ final Map constraintsMap;
+ if (tagContext.containsKey(TagHandler.CURRENT_CONSTRAINTS_KEY)) {
+ constraintsMap = (Map) tagContext.get(TagHandler.CURRENT_CONSTRAINTS_KEY);
+ if (null == constraintsMap) {
+ throwParsingException("CURRENT_CONSTRAINTS_KEY was null ! " +
+ "Cannot continue setting constraints.");
+ }
+ } else {
+ constraintsMap = new HashMap();
+ tagContext.put(TagHandler.CURRENT_CONSTRAINTS_KEY, constraintsMap);
+ }
+ return constraintsMap;
}
}
|