[Spedit-commits] CVS: prototype/Sources/net/sourceforge/spedit/core XMLDocument.java,1.5,1.6 XMLElem
Status: Planning
Brought to you by:
krunte
|
From: S?bastien P. <kaz...@us...> - 2001-12-04 16:37:32
|
Update of /cvsroot/spedit/prototype/Sources/net/sourceforge/spedit/core
In directory usw-pr-cvs1:/tmp/cvs-serv21181/net/sourceforge/spedit/core
Modified Files:
XMLDocument.java XMLElement.java XMLElementWrapper.java
XMLInformation.java XMLViewFactory.java
Log Message:
New element menu, add element bug fix.
Index: XMLDocument.java
===================================================================
RCS file: /cvsroot/spedit/prototype/Sources/net/sourceforge/spedit/core/XMLDocument.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** XMLDocument.java 2001/11/28 13:14:37 1.5
--- XMLDocument.java 2001/12/04 16:37:29 1.6
***************
*** 349,353 ****
if ( factory!=null )
{
! info = factory.getElementInformation(((XMLElement)element).getWrapper());
}
--- 349,355 ----
if ( factory!=null )
{
! //info = factory.getElementInformation(((XMLElement)element).getWrapper());
! info = ((XMLElement)element).getWrapper().getInformation();
! //info.setNewlyCreated(false);
}
***************
*** 467,473 ****
Element e = root.getWrapper().getElementAt(offset);
if ( e.isLeaf() )
! return e.getParentElement();
else
! return e;
}
--- 469,475 ----
Element e = root.getWrapper().getElementAt(offset);
if ( e.isLeaf() )
! { return e.getParentElement(); }
else
! { return e; }
}
***************
*** 911,914 ****
--- 913,919 ----
else if ( pos.offset>offset-length )
{ pos.offset += length; }
+ /*else
+ {System.out.println("Oh my god!!:pos.offset="+pos.offset+
+ " offset:"+offset+" -length:"+(-length));}*/
}
}
***************
*** 1021,1031 ****
! // PRIVATE___________________________________________________________
! private int offset;
! private int length;
! private ElementEdit edit;
! private DocumentEvent.EventType type;
! private XMLDocument doc;
! private String value;
// CONSTRUCTORS______________________________________________________
--- 1026,1038 ----
! // PROTECTED__________________________________________________________
! protected int offset;
! protected int length;
! protected ElementEdit edit;
! protected DocumentEvent.EventType type;
! protected XMLDocument doc;
! protected String value;
!
! protected javax.swing.text.Position.Bias bias = javax.swing.text.Position.Bias.Forward;
// CONSTRUCTORS______________________________________________________
***************
*** 1062,1065 ****
--- 1069,1086 ----
/**
+ * Sets the bias of the current event.
+ * @param The new bias for this event
+ */
+ public void setBias(javax.swing.text.Position.Bias bias)
+ { this.bias = bias; }
+
+ /**
+ * Gets the bias of the current event.
+ * @return The bias of the current event
+ */
+ public javax.swing.text.Position.Bias getBias()
+ { return this.bias; }
+
+ /**
* This actually not adds an edit but <em>sets</em> the
* <code>ElementEdit</code>. Because a document event occurs at a
***************
*** 1110,1124 ****
if ( doc !=null && type==DocumentEvent.EventType.INSERT )
{
doc.updatePositions(offset, length);
try
{ doc.content.insertString(offset, value); }
catch (BadLocationException e)
{ e.printStackTrace(); }
- //System.out.println("Insertion of string:"+value+"\n at:"+offset);
}
//TODO: When it is a CHANGE
else if( doc !=null && type==DocumentEvent.EventType.REMOVE )
{
!
doc.updatePositions(offset, -length);
--- 1131,1156 ----
if ( doc !=null && type==DocumentEvent.EventType.INSERT )
{
+ if ( bias==javax.swing.text.Position.Bias.Forward)
+ {
+ System.out.println("Insert forward, old offset:"+offset);
+ offset = Math.min(offset+1,doc.content.length()-1);
+ //offset = Math.max(offset,0);
+ }
+
doc.updatePositions(offset, length);
+ System.out.println("Insertion of string:"+value+"\n at:"+offset+"/"+doc.content.length());
try
{ doc.content.insertString(offset, value); }
catch (BadLocationException e)
{ e.printStackTrace(); }
}
//TODO: When it is a CHANGE
else if( doc !=null && type==DocumentEvent.EventType.REMOVE )
{
! System.out.println("Removal from:"+offset+" to:"+(offset+length));
! try
! { except(); }
! catch (Exception e)
! { e.printStackTrace(); }
doc.updatePositions(offset, -length);
***************
*** 1127,1132 ****
String old = doc.content.getString(offset, length);
doc.content.remove(offset, length);
- System.out.println("Removal of from:"+offset+" to:"+(offset+length));
- System.out.println(" was:"+old);
}
catch (BadLocationException e)
--- 1159,1162 ----
***************
*** 1141,1146 ****
}
}
-
//------------------------------------------------------------------------
//
--- 1171,1177 ----
}
+ public void except() throws Exception
+ { throw new Exception(); }
}
//------------------------------------------------------------------------
//
Index: XMLElement.java
===================================================================
RCS file: /cvsroot/spedit/prototype/Sources/net/sourceforge/spedit/core/XMLElement.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** XMLElement.java 2001/11/01 15:41:43 1.1
--- XMLElement.java 2001/12/04 16:37:29 1.2
***************
*** 76,81 ****
// PROTECTED______________________________________________________________
! protected int contentLength;
! protected int startOffset;
protected XMLElementWrapper wrapper;
protected XMLAttributes xmlAttributes;
--- 76,81 ----
// PROTECTED______________________________________________________________
! protected int contentLength;
! protected int startOffset;
protected XMLElementWrapper wrapper;
protected XMLAttributes xmlAttributes;
***************
*** 132,138 ****
}
protected void init()
{
! this.content = new ArrayList(5);
this.wrapper = new XMLElementWrapper(this);
xmlAttributes = new XMLAttributes(getAttributes());
--- 132,142 ----
}
+ /**
+ * Initializes the <code>XMLElement</code> with a new content, with a
+ * new wrapper and a new set of attributes.
+ */
protected void init()
{
! this.content = new ArrayList(1);
this.wrapper = new XMLElementWrapper(this);
xmlAttributes = new XMLAttributes(getAttributes());
***************
*** 179,183 ****
}
-
public org.jdom.Element setAttribute(java.lang.String name,
java.lang.String value, org.jdom.Namespace ns)
--- 183,186 ----
***************
*** 188,192 ****
}
-
public org.jdom.Element setAttributes(java.util.List attributes)
{
--- 191,194 ----
***************
*** 346,349 ****
--- 348,352 ----
{
Object o=it.next();
+ //If it is an element we simply use the parent AddContent method
if ( o instanceof org.jdom.Element )
{ super.addContent((org.jdom.Element)o); }
***************
*** 352,357 ****
else
{
! System.err.println("Class "+o.getClass()+
! " not supported by XMLElement.setNewContent");
}
}
--- 355,359 ----
else
{
! notSupported(o.getClass().getName());
}
}
Index: XMLElementWrapper.java
===================================================================
RCS file: /cvsroot/spedit/prototype/Sources/net/sourceforge/spedit/core/XMLElementWrapper.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** XMLElementWrapper.java 2001/11/15 10:49:43 1.2
--- XMLElementWrapper.java 2001/12/04 16:37:29 1.3
***************
*** 2,9 ****
// Project : SPEdit-Prototypes
// ClassName : XMLElementWrapper
! // Version : 0.93c
// Type :
//
! // ThreadSafe : Nope
// Description : Subclass of JDOM Element, plus a Wrapper to make the
// JDOM element visible as a Swing Element.
--- 2,9 ----
// Project : SPEdit-Prototypes
// ClassName : XMLElementWrapper
! // Version : 0.95
// Type :
//
! // ThreadSafe : More or less ;)
// Description : Subclass of JDOM Element, plus a Wrapper to make the
// JDOM element visible as a Swing Element.
***************
*** 13,18 ****
// ----------------------------------------------------------------------------
// Creation date : 17-Sep-2001
! // Last mod. : 01-Nov-2001
// History :
// 01-Nov-2001 Fixed nasty bug in the insert method.(sp)
// 26-Oct-2001 Added some Javadoc. (sp)
--- 13,20 ----
// ----------------------------------------------------------------------------
// Creation date : 17-Sep-2001
! // Last mod. : 28-Nov-2001
// History :
+ // 28-Nov-2001 Improved TreeNode interface JavaDoc,
+ // added siblings access methods.(sp)
// 01-Nov-2001 Fixed nasty bug in the insert method.(sp)
// 26-Oct-2001 Added some Javadoc. (sp)
***************
*** 40,43 ****
--- 42,47 ----
// parent.getContent().size()... should test the
// difference between variable and method calls.
+ // - Wait for next JDom release to use MutableList and then
+ // optimize this class to the max.
package net.sourceforge.spedit.core;
***************
*** 122,125 ****
--- 126,130 ----
protected Position startPosition = null;
protected Position endPosition = null;
+ public boolean isNewlyCreated = false;
// CONSTRUCTORS___________________________________________________________
***************
*** 132,136 ****
{
this.element = element;
! information = null;
}
--- 137,141 ----
{
this.element = element;
! information = new net.sourceforge.spedit.core.XMLInformation(this.getName());
}
***************
*** 184,187 ****
--- 189,198 ----
//------------------------------------------------------------------------
+ /**
+ * Returns a list containing the children of the wrappeet. The
+ * only children that will be added to the list are XMLElemenWrapper and
+ * XMLTextWrapper instances.
+ * @return An enumeration on the children.
+ */
public synchronized Enumeration children()
{
***************
*** 194,207 ****
{ result.add(((XMLElement)o).getWrapper()); }
else if ( o instanceof XMLText )
! { result.add(((XMLElement)o).getWrapper()); }
}
return result.elements();
}
public boolean getAllowsChildren()
{
! return true;
}
public synchronized TreeNode getChildAt(int childIndex)
{
--- 205,235 ----
{ result.add(((XMLElement)o).getWrapper()); }
else if ( o instanceof XMLText )
! { result.add(((XMLText)o).getWrapper()); }
}
return result.elements();
}
+ /**
+ * Tells if the current element allows children. This is actually completely
+ * disjoined from the XMLInformation that the wrapper has.
+ * @return Returns <code>true</code> when the element has more than one child,
+ * otherwise returns <code>false</code>.
+ */
public boolean getAllowsChildren()
{
! if ( getChildCount()==0 )
! { return false; }
! else
! { return true; }
}
+ /**
+ * Return the child which has the given index. Basically a wrapper around
+ * the <code>getElement</code> method.
+ * @param childIndex the index of the child
+ * @return the designated children (which is a wrapper around a JDOM object),
+ * or <code>null</code>.
+ * @see #getElement
+ */
public synchronized TreeNode getChildAt(int childIndex)
{
***************
*** 209,212 ****
--- 237,245 ----
}
+ /**
+ * Returns the number of child elements of this wrapper.
+ * @return Same value as <code>getElementCount</code>
+ * @see #getElementCount
+ */
public int getChildCount()
{
***************
*** 214,217 ****
--- 247,257 ----
}
+ /**
+ * Returns the index of the given node if it is a child of the current
+ * element.
+ * @param node The node that we want to know the index.
+ * @return the index of the node if it is a child, otherwise returns
+ * <code>-1</code>.
+ */
public int getIndex(TreeNode node)
{
***************
*** 229,232 ****
--- 269,276 ----
}
+ /**
+ * Returns the parrent of the wrapper. Of course the parent is also an
+ * <code>XMLElementWrapper</code> so you can cast safely.
+ */
public TreeNode getParent()
{
***************
*** 403,406 ****
--- 447,505 ----
//------------------------------------------------------------------------
//
+ // Siblings
+ //
+ //------------------------------------------------------------------------
+
+ /**
+ * Returns the next <code>XMLElementWrapper</code> sibling
+ */
+ public XMLElementWrapper getNextSibling()
+ {
+ XMLElementWrapper parent = (XMLElementWrapper)getParentElement();
+ if ( parent==null ) { return null; }
+ int index = parent.getIndex(this);
+ if ( index<parent.getElementCount()-1 )
+ {
+ Object sibling = null;
+
+ for ( sibling = parent.getElement(++index) ;
+ !(sibling instanceof XMLElementWrapper) && index<parent.getElementCount() ;
+ sibling=parent.getElement(++index) );
+
+ if ( sibling instanceof XMLElementWrapper )
+ { return (XMLElementWrapper)sibling; }
+ else
+ { return null; }
+ }
+ else
+ { return null; }
+ }
+
+ /**
+ * Returns the previous <code>XMLElementWrapper</code> sibling
+ */
+ public XMLElementWrapper getPreviousSibling()
+ {
+ XMLElementWrapper parent = (XMLElementWrapper)getParentElement();
+ if ( parent==null ) { return null; }
+ int index = parent.getIndex(this);
+ if ( index>1 )
+ {
+ Object sibling = null;
+
+ for ( sibling = parent.getElement(--index) ;
+ !(sibling instanceof XMLElementWrapper) && index>0 ;
+ sibling=parent.getElement(--index) );
+
+ if ( sibling instanceof XMLElementWrapper )
+ { return (XMLElementWrapper)sibling; }
+ else
+ { return null; }
+ }
+ else
+ { return null; }
+ }
+ //------------------------------------------------------------------------
+ //
// Offsets
//
***************
*** 831,835 ****
XMLText new_text=new XMLText(st.substring(str_split,st.length()));
new_content.add(new_text);
- //We fire a new Document event
event = new XMLDocument.DocumentEvent(doc, offset,
inserted);
--- 930,933 ----
***************
*** 838,842 ****
event.addEdit(edit);
event.fire();
- System.out.println("Event fire-1");
}
//Or do we append it?
--- 936,939 ----
***************
*** 860,871 ****
new_content.add(new_text);
}
! //We fire a new Document event
! event = new XMLDocument.DocumentEvent(doc, offset,
! inserted);
edit = new XMLDocument.ElementEdit(this);
edit.addAddedElement(elt.getWrapper());
event.addEdit(edit);
event.fire();
! System.out.println("Event fire-2");
}
}
--- 957,966 ----
new_content.add(new_text);
}
! event = new XMLDocument.DocumentEvent(doc, offset, inserted);
edit = new XMLDocument.ElementEdit(this);
edit.addAddedElement(elt.getWrapper());
event.addEdit(edit);
event.fire();
! event = null;
}
}
***************
*** 880,885 ****
{
new_content.add(elt);
- //We create the DocumentEvent associated with the change and fire
- //it to the containing document.
event = new XMLDocument.DocumentEvent(doc, offset, inserted);
edit = new XMLDocument.ElementEdit(this);
--- 975,978 ----
***************
*** 887,891 ****
event.addEdit(edit);
event.fire();
- System.out.println("Event fire-3");
}
--- 980,983 ----
***************
*** 949,952 ****
--- 1041,1047 ----
*/
public Vector remove(int start, int end)
+ { return remove(start,end,true); }
+
+ protected Vector remove(int start, int end, boolean fireEvent)
{
//We make sure that the offsets are within the element bounds.
***************
*** 955,960 ****
//We adjust the end
! if ( end>=getEndOffset() )
! { end = getEndOffset(); }
ArrayList new_content = new ArrayList(element.getContent().size()-1);
--- 1050,1055 ----
//We adjust the end
! start = Math.max(start, getStartOffset());
! end = Math.min(end , getEndOffset());
ArrayList new_content = new ArrayList(element.getContent().size()-1);
***************
*** 964,967 ****
--- 1059,1063 ----
//We prepare the event
XMLDocument doc = (XMLDocument)element.getDocument();
+
XMLDocument.DocumentEvent event=new XMLDocument.DocumentEvent(doc, start,
end-start);
***************
*** 983,987 ****
case CUT_INSIDE:
//In these case we do not have to notify anything
! wrp.remove(start, end);
case LEAVE:
new_content.add(wrp.element);
--- 1079,1083 ----
case CUT_INSIDE:
//In these case we do not have to notify anything
! wrp.remove(start, end, false);
case LEAVE:
new_content.add(wrp.element);
***************
*** 992,997 ****
//node.
edit = new XMLDocument.ElementEdit(this);
! edit.addAddedElement(wrp);
! event.fire();
to_be_detached.add(wrp.element);
result.add(wrp.element);
--- 1088,1092 ----
//node.
edit = new XMLDocument.ElementEdit(this);
! edit.addRemovedElement(wrp);
to_be_detached.add(wrp.element);
result.add(wrp.element);
***************
*** 1019,1023 ****
//We fire the event
! //event.fire();
//Now we detach the nodes
for (Enumeration e=to_be_detached.elements();e.hasMoreElements();)
--- 1114,1119 ----
//We fire the event
! if ( fireEvent ) { event.fire(); }
! System.out.println("Removal in "+getName());
//Now we detach the nodes
for (Enumeration e=to_be_detached.elements();e.hasMoreElements();)
Index: XMLInformation.java
===================================================================
RCS file: /cvsroot/spedit/prototype/Sources/net/sourceforge/spedit/core/XMLInformation.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** XMLInformation.java 2001/11/27 10:31:41 1.3
--- XMLInformation.java 2001/12/04 16:37:29 1.4
***************
*** 63,67 ****
* @version 0.30
*/
! public class XMLInformation
{
// PROTECTED_______________________________________________________________
--- 63,67 ----
* @version 0.30
*/
! public class XMLInformation implements Cloneable
{
// PROTECTED_______________________________________________________________
***************
*** 84,88 ****
protected boolean strip=true;
- protected boolean newlyCreated=false;
// CONSTRUCTORS____________________________________________________________
--- 84,87 ----
***************
*** 110,114 ****
attachedViewParameters = new Hashtable();
}
!
//------------------------------------------------------------------------
//
--- 109,113 ----
attachedViewParameters = new Hashtable();
}
!
//------------------------------------------------------------------------
//
***************
*** 276,303 ****
//------------------------------------------------------------------------
//
- // Element state meta information
- //
- //------------------------------------------------------------------------
-
- /**
- * Tells if the element is a newly created element. For example elements
- * that have just been inserted may need some editing by the user, in
- * this case the WrapperView will activate a special display mode that
- * will graphically tell the user that he should edit the element.
- * @return Tells if the elment is a newly created one.
- */
- public boolean isNewlyCreated()
- { return newlyCreated; }
-
- /**
- * Sets or unsets the <code>newlyCreated</code> flag for this element.
- * @param nc The flag is set if <code>nc</code> is <code>true</code>.
- * @see #isNewlyCreated
- */
- public void setNewlyCreated(boolean nc)
- { newlyCreated = nc; }
-
- //------------------------------------------------------------------------
- //
// Textual content processing attributes
//
--- 275,278 ----
***************
*** 331,336 ****
return result.toString();
}
-
-
}
--- 306,309 ----
Index: XMLViewFactory.java
===================================================================
RCS file: /cvsroot/spedit/prototype/Sources/net/sourceforge/spedit/core/XMLViewFactory.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** XMLViewFactory.java 2001/11/28 13:14:37 1.6
--- XMLViewFactory.java 2001/12/04 16:37:29 1.7
***************
*** 95,99 ****
* @param elt The element that the view will display.
* @return A new wrapped and registered view.
! * @see #getElementView
*/
public View create(javax.swing.text.Element elt)
--- 95,99 ----
* @param elt The element that the view will display.
* @return A new wrapped and registered view.
! * @see #getElementView
*/
public View create(javax.swing.text.Element elt)
***************
*** 121,138 ****
}
}
! //Otherwise there is only one info, and we still check that
//the current element has the right ancestors.
else
{
! info = ((XMLInformation)ob);
if ( info!=null && hasAncestors((XMLElementWrapper)elt, info) )
! {
! ((XMLNode)elt).setInformation(info);
! }
else
! {
! info=null;
! }
}
//We instanciate the view
--- 121,137 ----
}
}
! //Otherwise there is only one info, and we also check that
//the current element has the right ancestors.
else
{
! info = (XMLInformation)((XMLInformation)ob);
if ( info!=null && hasAncestors((XMLElementWrapper)elt, info) )
! { info = (XMLInformation)((XMLInformation)ob); }
else
! { info=null; }
}
+
+ if ( info!=null )
+ { ((XMLNode)elt).setInformation(info); }
//We instanciate the view
|