Archive for October, 2007

Java Swing - O Reilly See also properties from (Domain and web hosting)

Friday, October 26th, 2007

Java Swing - O Reilly See also properties from the AbstractDocument.AbstractElement class (Table 20.10) 20.1.13.2 Constructor public BranchElement(Element parent, AttributeSet a) Creates a new element with the specified parent and attributes. The element initially has no children. 20.1.13.3 Methods public Enumeration children() This method (from the TreeNode interface) returns an Enumeration of the element’s children. public int getElementIndex(int offset) Maps an absolute character offset to the child Element containing the given offset. It performs a binary search of the Element’s children, looking for a child that contains the given document offset. It returns the index of the closest Element it can find. If this branch does not contain the given offset, the index of either the first or last child is returned, depending on which side of this Element the given offset is located. If this element has no children, this method returns 0 (the same value returned if the input offset is found in the element’s first child). public Element positionToElement(int pos) Uses getElementIndex() to return the Element object at the given Document offset. If getElementIndex() returns the index of an Element that does not actually contain the given offset (which is possible, since it just returns the closest Element), null is returned. public void replace(int offset, int length, Element[] elems) Removes the requested number (length) of child Elements, starting at the specified offset, and replaces them with the input array of Elements. Note that the offset and lengthparameters specify the first child to remove and the number of children to remove. That is, they refer to the Element’s children, not Document characters. Note that this method performs as a delete operation if elems is empty, or to an insert operation if the length is zero. Also note that removed Elements may contain other Elements, which will also be removed. public String toString() Returns a String representation of the Element, formed by concatenating Branch Element, the Element’s name, and the Element’s start and end offsets. - 636
Visit our web design programs services for an affordable and reliable webhost to suit all your needs.

Java Swing - O Reilly leaf* boolean (Web hosting domains) true name*

Friday, October 26th, 2007

Java Swing - O Reilly leaf* boolean true name* String From attribute set, or ContentElementNameif null startOffset* int Property Data Type get is set bound Default Value See also properties from the AbstractDocument.AbstractElement class (Table 20.10) 20.1.12.2 Constructor public LeafElement(Element parent, AttributeSet a, int offs0, int offs1) Creates a new Element with the specified parent and attributes. The element covers the specified range of the Document. The offsets of this element are managed by two Position objects created in this constructor based on the offset values. 20.1.12.3 Methods public Enumeration children() This method (from TreeNode) returns null, since leaf elements have no children. public int getElementIndex(int pos) Since leaves have no children, this method always returns -1. public String toString() Returns a String representation of the Element. The value is formed by concatenating Leaf Element, the Element’s name, and its start and end positions. 20.1.13 The AbstractDocument.BranchElement Class This is a public inner class used to represent composite Elements, which contain other Elements. It is a concrete subclass of AbstractDocument.Abstract-Element. 20.1.13.1 Properties AbstractDocument.BranchElement defines the property values shown in Table 20.15. See the “Property” section of the Element interface for descriptions of these properties. The startOffset and endOffset values are maintained by Position objects created in the constructor. StartOffset always maps to the first character of element[0], while endOffset maps to the last character of the last child element. The leaf property is always false, and allowsChildren is always true. Table 20.15, AbstractDocument.BranchElement Properties Property Data Type get is set bound Default Value allowsChildren* boolean true element (indexed)* Element null elementCount* int 0 endOffset* int element[elementCount-1].endOffset leaf* boolean false name* String From attribute set, or ParagraphElementNameif null startOffset* int element[0].startOffset - 635
If you are in need for cheap and reliable webhost to host your website, we recommend http web server services.

Shared web hosting - Java Swing - O Reilly only be called while

Thursday, October 25th, 2007

Java Swing - O Reilly only be called while a write lock is held. If the write lock is currently held, these methods use the Document’s current AttributeContext to modify the attribute set to reflect the desired change. 20.1.11.5 TreeNode Methods In addition to the accessors for the TreeNode properties, the following methods from the TreeNode interface are defined: public abstract Enumeration children() Must be implemented to return an Enumeration of the Element’s children. public int getIndex(TreeNode node) Returns the index of the given node. If the given node is not a child of this element, -1 will be returned. 20.1.11.6 Other Methods public void dump(PrintStream out, int indentAmount) Dumps the Element hierarchy to the given stream for debugging purposes. public abstract int getElementIndex(int offset) Returns the Element that corresponds to the specified character offset in the Document. protected void finalize() throws Throwable This method, called when the Element is being garbage collected, notifies the AttributeContext that it may reclaim the Element’s attributes. 20.1.12 The AbstractDocument.LeafElement Class This is a public inner class used to refer to a block of text in the document. LeafElements do not contain child elements. This class is a concrete subclass of AbstractDocument.AbstractElement. 20.1.12.1 Properties AbstractDocument.LeafElement defines the property values in Table 20.14. See the “Property” section of the Element interface for descriptions of these elements. The startOffset and endOffset values are maintained by Position objects created in the constructor. The other default values listed here reflect the fact that LeafElements have no children. Table 20.14, AbstractDocument.LeafElement Properties Property Data Type get is set bound Default Value allowsChildren* boolean false element (indexed)* Element null elementCount* int 0 endOffset* int - 634
Check Tomcat Web Hosting services for best quality webspace to host your web application.

Web site development - Java Swing - O Reilly name* String from attribute

Thursday, October 25th, 2007

Java Swing - O Reilly name* String from attribute set parent* TreeNode same as parentElement parentElement* Element from constructor resolveParent* MutableAttributeSet from attribute set startOffset* int abstract Several of these properties may appear to be duplicates. This is because AbstractElement implements the TreeNode interface. The allowsChildren, childAt, childCount, and parentproperties come from this interface. 20.1.11.2 Constructors public AbstractElement(Element parent, AttributeSet a) Creates a new Element with the specified parent and attributes. The AttributeSet is stored and used in the methods defined in the AttributeSet and MutableAttributeSet interfaces. 20.1.11.3 AttributeSet Methods The following methods are defined in the AttributeSet interface. public boolean isDefined(String attrName) public boolean isEqual(AttributeSet attr) public boolean containsAttribute(String name, Object value) public boolean containsAttributes(AttributeSet attrs) Delegate to the Element’s AttributeSet. public AttributeSet copyAttributes() Returns the element’s AttributeSet. It does not actually copy anything. public Object getAttribute(String attrName) Delegates this call to its AttributeSet. If null is returned, it tries to retrieve the attribute value from its resolveParent. 20.1.11.4 MutableAttributeSet Methods These methods are defined in the MutableAttributeSet interface: public void addAttribute(String name, Object value) public void addAttributes(AttributeSet attr) public void removeAttribute(Object name) public void removeAttributes(Enumeration names) public void removeAttributes(AttributeSet attrs) The first thing each of these methods does is ensure that the current thread is actively holding the write lock on the document containing this Element. If not, a StateInvariantError (a non-public class in the text package) is thrown. Because of this check, you cannot call these methods directly on the Elements in a Document. They may - 633
In case you need quality webspace to host and run your web applications, try our personal web hosting services.

Java Swing - O Reilly be modified. This multiple (Web site designers)

Thursday, October 25th, 2007

Java Swing - O Reilly be modified. This multiple interface inheritance allows an AbstractElement to act both as an Element and as the AttributeSet that defines the Element’s properties. AbstractDocument also provides two concrete subclasses of AbstractElement called BranchElement and LeafElement (defined next). Figure 20.6 shows the inheritance hierarchy for these classes. Figure 20.6. AbstractDocument.AbstractElement class diagram Note that AbstractElement also implements the TreeNode interface from the javax.swing.treepackage. This makes it easy to represent the document structure visually using a JTree. 20.1.11.1 Properties Table 20.13 shows the properties defined by AbstractDocument.Abstract-Element. See the “Property” sections of the Element and MutableAttributeSet interfaces for descriptions of most of these properties. Most of the properties either are abstract (allowsChildren, element, elementCount, endOffset, leaf, and startOffset) or are obtained from the AttributeSet passed to the AbstractElement constructor. The resolveParent property is taken from the AttributeSet, but if this is null, the resolveParent will be the Element’s parent’s AttributeSet. Table 20.13, AbstractDocument.AbstractElement Properties Property Data Type get is set bound Default Value allowsChildren* boolean abstract attributeCount* int from attribute set attributeNames* Enumeration from attribute set attributes* AttributeSet this childAt (indexed)* TreeNode same as element childCount* int same as elementCount document* Document AbstractDocument.this element (indexed)* Element abstract elementCount* int abstract endOffset* int abstract leaf* boolean abstract - 632
In case you need affordable webhost to host your website, our recommendation is ecommerce web host services.

Java Swing (Web design careers) - O Reilly } catch (BadLocationException ex)

Wednesday, October 24th, 2007

Java Swing - O Reilly } catch (BadLocationException ex) {ex.printStackTrace();} } // Calls render() on the document in a new Thread. public void renderInThread(final long startTime) { this.startTime = startTime; // An anonymous inner class for a new Thread new Thread() { public void run() { System.out.println(rname + ” start rendering: ” + (System.currentTimeMillis() - startTime)); doc.render(DocRenderer.this); System.out.println(rname + ” done rendering: ” + (System.currentTimeMillis()-startTime)); } }.start(); // start the new thread } private Document doc; private String rname; private long startTime; } Here’s the output created by this program. The writing process, which contains no sleep() calls, was not able to complete until the rendering processes finished. One start rendering: 0One start renderer.run(): 0Two start rendering: 0Two start renderer.run(): 0Start writing: 990 // writer is blocked until readers are doneOne:Three blind mice One done rendering: 3030Two:Three blind mice Two done rendering: 3030Done writing: 3030 // only after readers release their locks can writer getin One start rendering: 3080One start renderer.run(): 3140One:Three blind mice, see how they run. One done rendering: 6100 The first four lines show that both readers start rendering at the same time. The next line shows the writer attempting to start after about one second. The next four lines shows the two readers finishing their rendering at about the same time, three seconds after they began. Only after these reads completed was the write able to get in. This is why we see the “Done writing” output after the reader output even though the write processing takes very little time (there is no sleep() call for the writer). The last four lines show the output of a single read after the document has been modified. 20.1.11 The AbstractDocument.AbstractElement Class AbstractElement is a public abstract inner class used to represent Elements of an AbstractDocument. It defines some default behavior useful for any Element implementation. In addition to implementing the Element interface, AbstractElement also implements MutableAttributeSet, which is an extension of the AttributeSet interface that allows the set to - 631
Check Tomcat Web Hosting services for best quality webspace to host your web application.

Web hosting colocation - Java Swing - O Reilly public static void main(String[]

Wednesday, October 24th, 2007

Java Swing - O Reilly public static void main(String[] args) { // Create a document with some initial text Document doc = new PlainDocument(); try { doc.insertString(0, “Three blind mice”, null); } catch (BadLocationException ex) {ex.printStackTrace();} // Create two “renderers” which will simulate painting the document DocRenderer r1 = new DocRenderer(”One”, doc); DocRenderer r2 = new DocRenderer(”Two”, doc); // Start the renderers in new threads. We’ll print out timing data to show // how things work. long startTime = System.currentTimeMillis(); r1.renderInThread(startTime); r2.renderInThread(startTime); // Wait one second before writing try { Thread.sleep(1000); } catch (InterruptedException ex) {} // Attempt to add some content to the document System.out.println(”Start writing: ” + (System.currentTimeMillis()-startTime)); try { doc.insertString(doc.getLength(), “, see how they run.”, null); } catch (BadLocationException ex) {ex.printStackTrace();} System.out.println(”Done writing: ” + (System.currentTimeMillis()-startTime)); // Render the modified documentr1.renderInThread(startTime); } } // A simple class that implements Runnable and provides a method to run itself // in a new Thread. class DocRenderer implements Runnable { // Create a new renderer for the given document. A name is provided to // distinguish the output of different renderers. public DocRenderer(String rname, Document doc) { this.rname = rname; this.doc = doc; } // This method is called by AbstractDocument.render(). It “renders” the// document by sleeping for 3 sec, then dumping the doc contents to stdout. public void run() { try { System.out.println(rname + ” start renderer.run(): ” + (System.currentTimeMillis()-startTime)); // Simulate a slow rendering process. Thread.sleep(3000); } catch (InterruptedException ex) {} // “render” by writing the text to stdouttry { System.out.println(rname + “:” + doc.getText(0, doc.getLength())); - 630
If you are in need for cheap and reliable webhost to host your website, we recommend http web server services.

Java Swing - O Reilly Returns a new BranchElement (Web server extensions)

Tuesday, October 23rd, 2007

Java Swing - O Reilly Returns a new BranchElement (described later) with the given parent and attribute set. protected Element createLeafElement(Element parent, AttributeSet a, int p0, int p1) Returns a new LeafElement (described later) with the given parent and attribute set, covering the specified range. protected final AbstractDocument.AttributeContext getAttributeContext() Returns the AttributeContext (described later) used for managing the document’s attributes. protected final AbstractDocument.Content getContent() Returns the Content (described later) object used to manage the actual contents of the document. protected void insertUpdate(AbstractDocument.DefaultDocumentEvent chng,AttributeSet attr) Called to indicate that text has been inserted into the document. The default implementation does nothing. protected void removeUpdate(AbstractDocument.DefaultDocumentEvent chng) Called to indicate that text has been removed from the document. The default implementation does nothing. 20.1.10.10 Document Locking Example This example shows that multiple Document renderers can read a Document simultaneously, but that this rendering process will block an attempted write operation. The code creates two DocRenderer objects, which it asks to render a simple document.[7] In this example, we “render” the document by just printing its contents to the screen. These rendering requests are made in separate threads, started at roughly the same time. The rendering method contains a three-second sleep() call to simulate a lengthy rendering process. After starting these two rendering threads, the main program sleeps for one second and then attempts to add text to the document. The output shows that this write attempt blocks until the two rendering threads have completed. Here’s the source code for this example: [7] We use a very simple subclass of AbstractDocument called PlainDocument in this example. This class will be defined later in this chapter. For now, there’s nothing special you need to know about this class. // LockingExample.java // import javax.swing.*; import javax.swing.text.*; // Sample program showing how AbstractDocument locking works. public class LockingExample { - 629
We recommend high quality webhost to host and run your jsp application: christian web host services.

Java Swing - O Reilly 20.1.10.7 Reading and Writing (Yahoo free web hosting)

Tuesday, October 23rd, 2007

Java Swing - O Reilly 20.1.10.7 Reading and Writing These methods read and write the underlying Document content. The methods that modify the content must obtain a write lock before proceeding. public String getText(int offset, int length) throws BadLocationException public void getText(int offset, int length, Segment txt) throws BadLocationException Returns the text starting at the specified offset, continuing for the specified length. The second version returns the requested text in the input Segment object. These methods do not obtain a read lock while accessing the Document’s content. public void insertString(int offs, String str, AttributeSet a) throws BadLocationException Inserts the specified string, with the given attributes, at the input offset in the Document. This method blocks until it is able to obtain the Document’s write lock. After making the requested insertion, it calls insertUpdate(), fireInsertUpdate() and, if this is an undoable edit, fireUndoableEditUpdate(). public void remove(int offs, int len) throws BadLocationException Removes text from the Document, starting at the specified offset and continuing for the given number of characters. Like insertString(), this method blocks until it is able to obtain a write lock. After removing the specified text, it calls removeUpdate(), fireRemoveUpdate() and, if this is an undoable edit, fireUndoableEditUpdate(). 20.1.10.8 Other Public Methods public synchronized Position createPosition(int offs) throws BadLocationException Returns a new Position object, capable of tracking change as the Document is modified. public void dump(PrintStream out) Dumps diagnostic information to the specified stream. This is done by calling dump() on the default root element, if it is an instance of AbstractElement. public Object getProperty(Object key) Returns the value of the requested property. Properties may have any arbitrary key and any arbitrary value. This method uses the Dictionary managed by the documentProperties property. public void putProperty(Object key, Object value) Sets an arbitrary property value for the document. Properties may have any arbitrary key and any arbitrary value. This method uses the Dictionary managed by the documentProperties property. 20.1.10.9 Other Protected Methods protected Element createBranchElement(Element parent, AttributeSet a) - 628
We recommend high quality webhost to host and run your jsp application: christian web host services.

Java Swing - O Reilly AbstractDocument (Web hosting support) implements a basic

Monday, October 22nd, 2007

Java Swing - O Reilly AbstractDocument implements a basic locking mechanism which ensures that at any given time, there is either a single writer of the document, or zero or more readers. That is, if no one is writing to the document, anyone is allowed to begin reading it or writing to it. Once someone begins writing, no one is able to read until the writer has finished. Certain methods that technically “read” the document (such as getText()) do not actually obtain a read lock to do so. The only method that obtains a read lock is the render() method, meaning that you are not guaranteed document stability during other access methods. This locking scheme is supported by the methods described next. It’s important to understand how this works if you decide to implement your own document type. If you decide to use the existing document types, it’s not too important to understand all the details. protected final synchronized Thread getCurrentWriter() Returns the thread currently holding the write lock (if there is one). If the document is not currently being updated, null is returned. protected final synchronized void readLock() Blocks until it is able to obtain a read lock. If another thread holds the write lock, this method waits until it is notified that the lock has been released before trying to obtain the lock again. protected final synchronized void readUnlock() Called to indicate that the current thread is no longer reading the document. If this was the only reader, writing may begin (threads waiting for the lock are notified). protected final synchronized void writeLock() Blocks until it is able to obtain the write lock. If the write lock is held by another thread, or there are any readers, this method will wait until it is notified that the state of the locks has changed before making an attempt to obtain the lock. Once the lock has been obtained, this method returns, and no other read or write locks can be obtained until the lock is released. protected final synchronized void writeUnlock() Releases the write lock, allowing waiting readers or writers to obtain locks. public void render(Runnable r) Called to render the Document visually. It obtains a read lock, ensuring that no changes will be made to the Document during the rendering process. It then calls the input Runnable’s run() [6] method. This method must not attempt to modify the Document, since deadlock will occur if it tries to obtain a write lock. When the run() method completes (either naturally or by throwing an exception), the read lock is released. Note that there is nothing in this method directly related to rendering the Document. It could technically be used to execute any arbitrary code while holding a read lock. [6] This method is called directly. The Runnable is not passed to a new Thread object. - 627
Check Tomcat Web Hosting services for best quality webspace to host your web application.