Skip to content

Commit 5d34493

Browse files
committed
Adds org.xml.sax
1 parent b61b90d commit 5d34493

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+11574
-0
lines changed

sources/net.sf.j2s.java.core/src/javax/swing/undo/UndoManager.java

Lines changed: 629 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 177 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
1+
/*
2+
* Copyright (c) 1997, 2004, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation. Oracle designates this
8+
* particular file as subject to the "Classpath" exception as provided
9+
* by Oracle in the LICENSE file that accompanied this code.
10+
*
11+
* This code is distributed in the hope that it will be useful, but WITHOUT
12+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14+
* version 2 for more details (a copy is included in the LICENSE file that
15+
* accompanied this code).
16+
*
17+
* You should have received a copy of the GNU General Public License version
18+
* 2 along with this work; if not, write to the Free Software Foundation,
19+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20+
*
21+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22+
* or visit www.oracle.com if you need additional information or have any
23+
* questions.
24+
*/
25+
26+
package javax.swing.undo;
27+
28+
import javax.swing.event.*;
29+
import java.util.*;
30+
31+
/**
32+
* A support class used for managing <code>UndoableEdit</code> listeners.
33+
*
34+
* @author Ray Ryan
35+
*/
36+
public class UndoableEditSupport {
37+
protected int updateLevel;
38+
protected CompoundEdit compoundEdit;
39+
protected Vector<UndoableEditListener> listeners;
40+
protected Object realSource;
41+
42+
/**
43+
* Constructs an <code>UndoableEditSupport</code> object.
44+
*/
45+
public UndoableEditSupport() {
46+
this(null);
47+
}
48+
49+
/**
50+
* Constructs an <code>UndoableEditSupport</code> object.
51+
*
52+
* @param r an <code>Object</code>
53+
*/
54+
public UndoableEditSupport(Object r) {
55+
realSource = r == null ? this : r;
56+
updateLevel = 0;
57+
compoundEdit = null;
58+
listeners = new Vector<UndoableEditListener>();
59+
}
60+
61+
/**
62+
* Registers an <code>UndoableEditListener</code>.
63+
* The listener is notified whenever an edit occurs which can be undone.
64+
*
65+
* @param l an <code>UndoableEditListener</code> object
66+
* @see #removeUndoableEditListener
67+
*/
68+
public synchronized void addUndoableEditListener(UndoableEditListener l) {
69+
listeners.addElement(l);
70+
}
71+
72+
/**
73+
* Removes an <code>UndoableEditListener</code>.
74+
*
75+
* @param l the <code>UndoableEditListener</code> object to be removed
76+
* @see #addUndoableEditListener
77+
*/
78+
public synchronized void removeUndoableEditListener(UndoableEditListener l)
79+
{
80+
listeners.removeElement(l);
81+
}
82+
83+
/**
84+
* Returns an array of all the <code>UndoableEditListener</code>s added
85+
* to this UndoableEditSupport with addUndoableEditListener().
86+
*
87+
* @return all of the <code>UndoableEditListener</code>s added or an empty
88+
* array if no listeners have been added
89+
* @since 1.4
90+
*/
91+
public synchronized UndoableEditListener[] getUndoableEditListeners() {
92+
return (UndoableEditListener[])(listeners.toArray(
93+
new UndoableEditListener[0]));
94+
}
95+
96+
/**
97+
* Called only from <code>postEdit</code> and <code>endUpdate</code>. Calls
98+
* <code>undoableEditHappened</code> in all listeners. No synchronization
99+
* is performed here, since the two calling methods are synchronized.
100+
*/
101+
protected void _postEdit(UndoableEdit e) {
102+
UndoableEditEvent ev = new UndoableEditEvent(realSource, e);
103+
Enumeration cursor = ((Vector)listeners.clone()).elements();
104+
while (cursor.hasMoreElements()) {
105+
((UndoableEditListener)cursor.nextElement()).
106+
undoableEditHappened(ev);
107+
}
108+
}
109+
110+
/**
111+
* DEADLOCK WARNING: Calling this method may call
112+
* <code>undoableEditHappened</code> in all listeners.
113+
* It is unwise to call this method from one of its listeners.
114+
*/
115+
public synchronized void postEdit(UndoableEdit e) {
116+
if (updateLevel == 0) {
117+
_postEdit(e);
118+
} else {
119+
// PENDING(rjrjr) Throw an exception if this fails?
120+
compoundEdit.addEdit(e);
121+
}
122+
}
123+
124+
/**
125+
* Returns the update level value.
126+
*
127+
* @return an integer representing the update level
128+
*/
129+
public int getUpdateLevel() {
130+
return updateLevel;
131+
}
132+
133+
/**
134+
*
135+
*/
136+
public synchronized void beginUpdate() {
137+
if (updateLevel == 0) {
138+
compoundEdit = createCompoundEdit();
139+
}
140+
updateLevel++;
141+
}
142+
143+
/**
144+
* Called only from <code>beginUpdate</code>.
145+
* Exposed here for subclasses' use.
146+
*/
147+
protected CompoundEdit createCompoundEdit() {
148+
return new CompoundEdit();
149+
}
150+
151+
/**
152+
* DEADLOCK WARNING: Calling this method may call
153+
* <code>undoableEditHappened</code> in all listeners.
154+
* It is unwise to call this method from one of its listeners.
155+
*/
156+
public synchronized void endUpdate() {
157+
updateLevel--;
158+
if (updateLevel == 0) {
159+
compoundEdit.end();
160+
_postEdit(compoundEdit);
161+
compoundEdit = null;
162+
}
163+
}
164+
165+
/**
166+
* Returns a string that displays and identifies this
167+
* object's properties.
168+
*
169+
* @return a <code>String</code> representation of this object
170+
*/
171+
public String toString() {
172+
return super.toString() +
173+
" updateLevel: " + updateLevel +
174+
" listeners: " + listeners +
175+
" compoundEdit: " + compoundEdit;
176+
}
177+
}
Lines changed: 193 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,193 @@
1+
// SAX Attribute List Interface.
2+
// http://www.saxproject.org
3+
// No warranty; no copyright -- use this as you will.
4+
// $Id: AttributeList.java,v 1.7 2004/04/26 17:34:34 dmegginson Exp $
5+
6+
package org.xml.sax;
7+
8+
/**
9+
* Interface for an element's attribute specifications.
10+
*
11+
* <blockquote>
12+
* <em>This module, both source code and documentation, is in the
13+
* Public Domain, and comes with <strong>NO WARRANTY</strong>.</em>
14+
* See <a href='http://www.saxproject.org'>http://www.saxproject.org</a>
15+
* for further information.
16+
* </blockquote>
17+
*
18+
* <p>This is the original SAX1 interface for reporting an element's
19+
* attributes. Unlike the new {@link org.xml.sax.Attributes Attributes}
20+
* interface, it does not support Namespace-related information.</p>
21+
*
22+
* <p>When an attribute list is supplied as part of a
23+
* {@link org.xml.sax.DocumentHandler#startElement startElement}
24+
* event, the list will return valid results only during the
25+
* scope of the event; once the event handler returns control
26+
* to the parser, the attribute list is invalid. To save a
27+
* persistent copy of the attribute list, use the SAX1
28+
* {@link org.xml.sax.helpers.AttributeListImpl AttributeListImpl}
29+
* helper class.</p>
30+
*
31+
* <p>An attribute list includes only attributes that have been
32+
* specified or defaulted: #IMPLIED attributes will not be included.</p>
33+
*
34+
* <p>There are two ways for the SAX application to obtain information
35+
* from the AttributeList. First, it can iterate through the entire
36+
* list:</p>
37+
*
38+
* <pre>
39+
* public void startElement (String name, AttributeList atts) {
40+
* for (int i = 0; i < atts.getLength(); i++) {
41+
* String name = atts.getName(i);
42+
* String type = atts.getType(i);
43+
* String value = atts.getValue(i);
44+
* [...]
45+
* }
46+
* }
47+
* </pre>
48+
*
49+
* <p>(Note that the result of getLength() will be zero if there
50+
* are no attributes.)
51+
*
52+
* <p>As an alternative, the application can request the value or
53+
* type of specific attributes:</p>
54+
*
55+
* <pre>
56+
* public void startElement (String name, AttributeList atts) {
57+
* String identifier = atts.getValue("id");
58+
* String label = atts.getValue("label");
59+
* [...]
60+
* }
61+
* </pre>
62+
*
63+
* @deprecated This interface has been replaced by the SAX2
64+
* {@link org.xml.sax.Attributes Attributes}
65+
* interface, which includes Namespace support.
66+
* @since SAX 1.0
67+
* @author David Megginson
68+
* @version 2.0.1 (sax2r2)
69+
* @see org.xml.sax.DocumentHandler#startElement startElement
70+
* @see org.xml.sax.helpers.AttributeListImpl AttributeListImpl
71+
*/
72+
public interface AttributeList {
73+
74+
75+
////////////////////////////////////////////////////////////////////
76+
// Iteration methods.
77+
////////////////////////////////////////////////////////////////////
78+
79+
80+
/**
81+
* Return the number of attributes in this list.
82+
*
83+
* <p>The SAX parser may provide attributes in any
84+
* arbitrary order, regardless of the order in which they were
85+
* declared or specified. The number of attributes may be
86+
* zero.</p>
87+
*
88+
* @return The number of attributes in the list.
89+
*/
90+
public abstract int getLength ();
91+
92+
93+
/**
94+
* Return the name of an attribute in this list (by position).
95+
*
96+
* <p>The names must be unique: the SAX parser shall not include the
97+
* same attribute twice. Attributes without values (those declared
98+
* #IMPLIED without a value specified in the start tag) will be
99+
* omitted from the list.</p>
100+
*
101+
* <p>If the attribute name has a namespace prefix, the prefix
102+
* will still be attached.</p>
103+
*
104+
* @param i The index of the attribute in the list (starting at 0).
105+
* @return The name of the indexed attribute, or null
106+
* if the index is out of range.
107+
* @see #getLength
108+
*/
109+
public abstract String getName (int i);
110+
111+
112+
/**
113+
* Return the type of an attribute in the list (by position).
114+
*
115+
* <p>The attribute type is one of the strings "CDATA", "ID",
116+
* "IDREF", "IDREFS", "NMTOKEN", "NMTOKENS", "ENTITY", "ENTITIES",
117+
* or "NOTATION" (always in upper case).</p>
118+
*
119+
* <p>If the parser has not read a declaration for the attribute,
120+
* or if the parser does not report attribute types, then it must
121+
* return the value "CDATA" as stated in the XML 1.0 Recommentation
122+
* (clause 3.3.3, "Attribute-Value Normalization").</p>
123+
*
124+
* <p>For an enumerated attribute that is not a notation, the
125+
* parser will report the type as "NMTOKEN".</p>
126+
*
127+
* @param i The index of the attribute in the list (starting at 0).
128+
* @return The attribute type as a string, or
129+
* null if the index is out of range.
130+
* @see #getLength
131+
* @see #getType(java.lang.String)
132+
*/
133+
public abstract String getType (int i);
134+
135+
136+
/**
137+
* Return the value of an attribute in the list (by position).
138+
*
139+
* <p>If the attribute value is a list of tokens (IDREFS,
140+
* ENTITIES, or NMTOKENS), the tokens will be concatenated
141+
* into a single string separated by whitespace.</p>
142+
*
143+
* @param i The index of the attribute in the list (starting at 0).
144+
* @return The attribute value as a string, or
145+
* null if the index is out of range.
146+
* @see #getLength
147+
* @see #getValue(java.lang.String)
148+
*/
149+
public abstract String getValue (int i);
150+
151+
152+
153+
////////////////////////////////////////////////////////////////////
154+
// Lookup methods.
155+
////////////////////////////////////////////////////////////////////
156+
157+
158+
/**
159+
* Return the type of an attribute in the list (by name).
160+
*
161+
* <p>The return value is the same as the return value for
162+
* getType(int).</p>
163+
*
164+
* <p>If the attribute name has a namespace prefix in the document,
165+
* the application must include the prefix here.</p>
166+
*
167+
* @param name The name of the attribute.
168+
* @return The attribute type as a string, or null if no
169+
* such attribute exists.
170+
* @see #getType(int)
171+
*/
172+
public abstract String getType (String name);
173+
174+
175+
/**
176+
* Return the value of an attribute in the list (by name).
177+
*
178+
* <p>The return value is the same as the return value for
179+
* getValue(int).</p>
180+
*
181+
* <p>If the attribute name has a namespace prefix in the document,
182+
* the application must include the prefix here.</p>
183+
*
184+
* @param name the name of the attribute to return
185+
* @return The attribute value as a string, or null if
186+
* no such attribute exists.
187+
* @see #getValue(int)
188+
*/
189+
public abstract String getValue (String name);
190+
191+
}
192+
193+
// end of AttributeList.java

0 commit comments

Comments
 (0)