Archive for September, 2007

Java Swing - O Reilly focusAccelerator char (Freelance web design) ‘0′ focusTraversable*

Sunday, September 30th, 2007

Java Swing - O Reilly focusAccelerator char ‘0′ focusTraversable* boolean true highlighter Highlighter null keymap Keymap null layout* LayoutManager null margin Insets TextUI.getDefaultMargin() opaque* boolean false preferredScrollableViewportSize* Dimension Preferred size of component scrollableTracksViewportHeight* boolean see below scrollableTracksViewportWidth* boolean see below selectedText String From document selectedTextColor Color null selectionColor Color null selectionEnd int From caret selectionStart int From caret text String From document See also properties from the JComponent class (Table 3.5). accessibleContext refers to an instance of the inner class AccessibleJTextComponent which implements the AccessibleText interface, described in Chapter 25. The actions property specifies the Actions (see Chapter 25, for an introduction to Swing’s new Action interface) available for the component. These actions might include things such as cut, paste, or change-font. The supported actions are defined by the component’s EditorKit, which we’ll cover in detail in Chapter 24. caret represents the location at which data will be inserted into the document. We’ll discuss the Caret interface in Chapter 22. caretColor , disabledTextColor, selectionColor , and selectedTextColor simply specify the color used to render the caret, disabled text, selection background, and selected text, respectively.[2] CaretPosition provides quick access to the Caret’s current position. [2] The regular text color is stored in the inherited foreground property. The editable property indicates whether or not the document can be edited. If this property is set to false, characters typed into the component will not be inserted the component will be used only for displaying text. We list the enabled property here only because JTextComponent overrides setEnabled() to explicitly call repaint(). Next, the focusAccelerator property specifies the key that can be used to give focus to the text component. focusTraversable is true by default, because the implementation of isFocusTraversable() is overridden to return true if the component is editable and enabled. The highlighter property is a reference to the object responsible for making highlights in the text. Like Caret, the Highlighter interface will be introduced in Chapter 22. Yet another new interface we’ll get to later in that chapter is Keymap, which is used to define the keymap property. This is an important property that allows you to specify, for example, what keys will cause text to be cut (e.g., CTRL-X) or paste (e.g, CTRL-V). The inherited layout property defaults to null, because the layout of text components is handled by the view hierarchy (see Chapter 23). The margin property specifies the distance between the component’s text and its border (using Insets, an AWT class). - 580
We recommend cheap and reliable webhost to host and run your web applications: Coldfusion Web Hosting services.

Java Swing - (How to cite a web site) O Reilly 19.1 The Swing Text

Sunday, September 30th, 2007

Java Swing - O Reilly 19.1 The Swing Text Components The five concrete Swing text component classes all have quite a bit in common. Consequently, they share a common base class, JTextComponent. Figure 19.2 shows the class hierarchy for the Swing text components. As you can see, JTextComponent is the only one of these classes defined in the text package; the rest can be found in javax.swing [1] with the rest of the Swing component classes. [1] All of the other text-related classes (discussed in the subsequent chapters) are part of the javax.swing.text package. Figure 19.2. The Swing text components 19.1.1 The JTextComponent Class JTextComponent is an abstract class that serves as the base class for all text-based Swing components. It defines a large number of properties and methods that apply to its subclasses. In this introductory chapter, we’ll pass quickly over many of these properties, as they require an understanding of the underlying model and view aspects of the text framework. 19.1.1.1 Properties JTextComponent defines the properties and default values shown in Table 19.1. document is a reference to the Document model for the component. This is where the component’s data is stored. We’ll get into a lot of detail on the Document interface and its implementations in the next chapter. The UI property for all text components is a TextUI. Table 19.1, JTextComponent Properties Property Data Type get is set bound Default Value document Document null UI TextUI from L&F accessibleContext* AccessibleContext AccessibleJTextComponent actions Action[] From the UI’s EditorKit caret Caret null caretColor Color null caretPosition int From caret disabledTextColor Color null editable boolean true enabled* boolean true - 579
If you are searching for cheap webhost for your web application, please visit MySQL5 Web Hosting services.

Java Swing - O Reilly Chapter 19. (Hosting web) Text 101

Sunday, September 30th, 2007

Java Swing - O Reilly Chapter 19. Text 101 Swing provides an extensive collection of classes for working with text in user interfaces. In fact, there’s so much provided for working with text, Swing’s creators placed most of it into its own package: javax.swing.text . This package’s dozens of interfaces and classes (plus the five concrete component classes in javax.swing) provide a rich (and complex!) set of text-based models and components. Over the course of the next six chapters, we’ll cover each of these classes and interfaces in detail. Figure 19.1 shows a very high-level view of the structure of the Swing text components. The arrows in the figure can be read as “knows about,” or “uses.” Figure 19.1. High-level view of the Swing text framework The text content for any component is stored in a model object called a Document. Chapter 20, and Chapter 21, cover the complex Swing document model in considerable detail. This model allows you to represent highly structured text supporting multiple fonts and colors, and even embedded Icons and Components. Swing text components allow you to customize certain aspects of the look-and-feel without much work. This includes the creation of custom carets (cursor) and custom highlighting, as well as the definition of custom key bindings, allowing you to associate Actions with special key combinations. These features are covered in Chapter 22. As usual, each text component delegates its painting tasks to a UI delegate. Unlike the other Swing UI delegates, the TextUI relies heavily on a large number of additional classes that extend a common base class called View. These classes are responsible for the details of layout, including issues such as alignment and text wrapping. We’ll cover all of these classes in detail in Chapter 23. Finally, all of this is tied together by something called an EditorKit. EditorKits allow you to define how your documents will be input and output via streams, what view objects should be used in which situations, and what special actions your editor will support. EditorKits (and TextActions) are covered in Chapter 24. This may all seem a bit overwhelming. The good news is that despite all the complexity and power Swing’s text components provide, it’s still pretty simple to do most things. That is the focus of this chapter. Here, we’ll look at JTextComponent, the base class for all of the text components, and its five subclasses: JTextField, JPasswordField, JTextArea, JEditorPane, and JTextPane. We won’t cover the complex text model and view classes until later, but we’ll occasionally reference things you may want to investigate further in the upcoming chapters. In the case of JTextPane, we won’t cover the properties and methods of this class in this chapter, because they rely pretty heavily on the document model. Instead, we’ll just provide a brief overview and an example that shows how to do a few basic things that would be particularly difficult to do with the AWT text components. - 578
Check Tomcat Web Hosting services for best quality webspace to host your web application.

Java Swing (Web site layout) O Reilly } private ExtendedUndoableEditSupport support

Saturday, September 29th, 2007

Java Swing O Reilly } private ExtendedUndoableEditSupport support = new ExtendedUndoableEditSupport(); private Object source; // the source of the last edit // A simple extension of UndoableEditSupport that lets us specify the event // source each time we post an edit. class ExtendedUndoableEditSupport extends UndoableEditSupport { // Post an edit to added listeners. public synchronized void postEdit(UndoableEdit ue) { realSource = source; // from our enclosing manager object super.postEdit(ue); } } } The first method here is a customized implementation of addEdit(). For the most part, we leave this method to the superclass. The only thing we’ve added is a call to UndoableEditSupport.postEdit(). Any time an edit is added to the undo manager, we’ll notify its listeners. The idea is that a single listener, probably responsible for updating an Undo menu, will be added to the undo manager. The next method is the undoableEditHappened() method from the UndoableEditListener interface. This is the method called each time any edit-generating component in the application fires an UndoableEdit. In this method, we first store the source of the event (we’ll see how we use this shortly) and then call addEdit(). The next two methods simply use UndoableEditSupport to manage interested listeners. Finally, we define a small inner class called ExtendedUndoableEditSupport. This is an extension of UndoableEditSupport that we will use to set the correct event source each time the ExtendedUndoManager fires an UndoableEditEvent. Rather than declaring the undo manager as the source of the event, we use the real source of the event that was passed to the undo manager’s undoableEditHappened() method. Note that realSource, which is a protected field in UndoableEditSupport, becomes the source object in the fired UndoableEdit-Event. - 577 -
Note: If you are looking for cheap and reliable webhost to host and run your mysql application check mysql web server services.

Java Swing O Reilly int size = edits.size(); (Christian web host)

Saturday, September 29th, 2007

Java Swing O Reilly int size = edits.size(); Vector v = new Vector(size); for (int i=size-1;i>=0;i–) { UndoableEdit u = (UndoableEdit)edits.elementAt(i); if (u.canUndo() && u.isSignificant()) v.addElement(u); } UndoableEdit[] array = new UndoableEdit[v.size()]; v.copyInto(array); return array; } // Return all currently significant redoable edits. The first edit will be the // next one to be redone. public synchronized UndoableEdit[] getRedoableEdits() { int size = edits.size(); Vector v = new Vector(size); for (int i=0; iVisit our web design programs services for an affordable and reliable webhost to suit all your needs.

Java Swing O Reilly 18.1.11 The CannotUndoException Class (Web server info)

Friday, September 28th, 2007

Java Swing O Reilly 18.1.11 The CannotUndoException Class This class is an extension of RuntimeException thrown when an attempt is made to undo an UndoableEdit that cannot be undone (typically because it has already been undone, or because it has been “killed”). There are no properties, constructors (other than the implicit default), or methods defined in this class. 18.1.12 Extending UndoManager Now that we’ve looked at all of the classes and interfaces in the undo framework, we’ll look at a few ideas for extending the functionality it provides. In this example, we’ll extend UndoManager to add a few extra features. The first thing we’ll add is the ability to get a list of the edits stored in the manager. This is a simple task of returning the contents of the edits vector inherited from CompoundEdit. We also provide access to an array of significant undoable edits and an array of significant redoable edits. These might be useful in a game like chess in which we want to provide a list of past moves. The next major feature we’ll add in this extended UndoManager is support for listeners. At the time of this writing, the current UndoManager did not have any way of notifying you when it received edits. As we saw in an earlier example, this means that you have to listen to each edit-generating component if you want to update the user interface to reflect new undoable or redoable edits as they occur. In our manager, we simply add the ability to add and remove undoable edit listeners to the undo manager itself. Each time an edit is added, the undo manager fires an UndoableEditEvent to any registered listeners. This way, we can just add the undo manager as a listener to each edit- generating component and then add a single listener to the undo manager to update the UI. The methods of our new undo manager can be divided into two groups, each supporting one of the two features we’re adding. We’ll split the source code listing along these lines so we can talk about each set of methods independently. Here’s the first half. // ExtendedUndoManager.java // import javax.swing.event.*; import javax.swing.undo.*; import java.util.Enumeration; import java.util.Vector; // An extension of UndoManager that provides two additional features: // (1) The ability to add & remove listeners and (2) the ability to gain more // extensive access to the edits being managed. public class ExtendedUndoManager extends UndoManager implements UndoableEditListener { // Return the complete list of edits in an array. public synchronized UndoableEdit[] getEdits() { UndoableEdit[] array = new UndoableEdit[edits.size()]; edits.copyInto(array); return array; } // Return all currently significant undoable edits. The first edit will be the // next one to be undone. public synchronized UndoableEdit[] getUndoableEdits() { - 575 -
Searching for affordable and proven webhost to host and run your servlet applications? Go to Linux Web Hosting services and you will find it.

Java Swing O Reilly implementation of the same (Web server hosting)

Friday, September 28th, 2007

Java Swing O Reilly implementation of the same class), we’ll show how easily we can use UndoableEditSupport to allow multiple listeners to be added and notified. Differences from our earlier implementation are highlighted. import java.awt.event.*; import javax.swing.*; import javax.swing.event.*; import javax.swing.undo.*; // Sample undoable toggle button class using UndoableEditSupport. public class UndoableJToggleButton2 extends JToggleButton { // For this example, we’ll just provide one constructor. public UndoableJToggleButton2(String txt) { super(txt); support = new UndoableEditSupport(this); } // Add an UndoableEditListener using our support object. public void addUndoableEditListener(UndoableEditListener l) { support.addUndoableEditListener(l); } // Remove an UndoableEditListener using our support object. public void removeUndoableEditListener(UndoableEditListener l) { support.addUndoableEditListener(l); } // Override this method to call the super implementation first (to fire the // action event) and then fire a new UndoableEditEvent to our listeners using // our support object. protected void fireActionPerformed(ActionEvent ev) { // Fire the ActionEvent as usual super.fireActionPerformed(ev); support.postEdit(new UndoableToggleEdit(this)); } private UndoableEditSupport support; } 18.1.10 The CannotRedoException Class This class is an extension of RuntimeException thrown when an attempt is made to redo an UndoableEdit that cannot be redone (typically because it has not yet been undone, or because it has been “killed”). There are no properties, constructors (other than the implicit default), or methods defined in this class. - 574 -
If you are searching for cheap webhost for your web application, please visit MySQL5 Web Hosting services.

Java Swing (Web site template) O Reilly Decrements updateLevel. If updateLevel

Thursday, September 27th, 2007

Java Swing O Reilly Decrements updateLevel. If updateLevel is now 0, it calls end() on the CompoundEditand then calls _postEdit() to deliver the edit to the support object’s listeners. protected CompoundEdit createCompoundEdit() Returns a new CompoundEdit. A subclass could override this method to return a different CompoundEdit implementation if desired. Figure 18.11 shows how to use beginUpdate() and endUpdate(). We add a total of four edits to the support object. Notice that the first endUpdate() call does nothing but decrement the current level. The next endUpdate(), which brings the level to zero, causes the composite edit containing the four added edits to be fired. Figure 18.11. Using beginUpdate() and endUpdate() 18.1.9.6 Other Methods public String toString() Returns a String representation of the support object including the current updateLevel, and String representations of the listener vector and CompoundEdit. 18.1.9.7 Using Undoable Edit Support Earlier in this chapter, we created a simple undoable toggle button class. To keep that example simple, we allowed only a single listener to be added to the button. In this example (just a new - 573 -
Please visit Domain Name Hosting services for high quality webhost to host and run your jsp applications.

Java Swing O Reilly Creates a (Web hosting ecommerce) new support

Thursday, September 27th, 2007

Java Swing O Reilly Creates a new support object, which will use the given object as the source for any events it fires. 18.1.9.4 UndoableEditEvent/Listener Support Methods The following methods allow an undo-capable object to use an UndoableEditSupport object to manage event listeners. public synchronized void addUndoableEditListener(UndoableEditListener l) Adds the given listener to a list of listeners to be notified of new UndoableEdits. public synchronized void removeUndoableEditListener(UndoableEditListener l) Removes the specified listener. public synchronized void postEdit(UndoableEdit e) If updateLevel is 0, this method uses _postEdit() to send an UndoableEditEvent to all added listeners. If updateLevel is not 0, this method adds the input edit to a CompoundEditto be fired later. See the beginUpdate() and endUpdate() methods for more details on the use of the CompoundEdit. protected void _postEdit(UndoableEdit e) This protected method is used by postEdit() and endUpdate(). It creates a new UndoableEditEvent containing the input edit and sends it to all registered listeners by calling undoableEditHappened() on each. 18.1.9.5 Nested Edit Support The following methods allow the UndoableEditSupport class to consolidate multiple edits into a single CompoundEdit, to be fired after a series of edits have been added. To use these methods, the object using the support object first calls beginUpdate(). Each subsequent postEdit() call will cause the input edit to be added to a single CompoundEdit. When endUpdate() is called, an UndoableEditEvent containing the CompoundEdit is fired. If multiple beginUpdate() calls are made, the support object keeps track of the level of nesting using the updateLevel property. Only when the number of endUpdate() calls matches the number of beginUpdate() calls is the CompoundEdit finally fired. Regardless of how many times beginUpdate() is called, only a single CompoundEdit is created. public synchronized void beginUpdate() Indicates that subsequent postEdit() calls should result in the input edit being added to a CompoundEdit. This method increments updateLevel and, if the updateLevel is 0, creates a new Compound-Edit. public synchronized void endUpdate() - 572 -
Note: In case you are looking for affordable and reliable webhost to host and run your j2ee application check Vision J2ee Web Hosting services.

Java Swing O Reilly 18.1.9 The UndoableEditSupport Class (Graphic web design)

Wednesday, September 26th, 2007

Java Swing O Reilly 18.1.9 The UndoableEditSupport Class UndoableEditSupport is a simple utility class for classes that need to support undo.[9] It provides methods for adding and removing UndoableEditListeners, as well as a postEdit() method used to send an UndoableEditEvent to the added listeners. Additionally, it allows multiple edits to be added to it and then fired as a single CompoundEdit. [9] Presently, none of the Swing classes that support undo actually use this class. Instead, they manage their edits and listeners themselves. 18.1.9.1 Property UndoableEditSupport is a direct subclass of Object and defines the updateLevel property shown in Table 18.8. updateLevel reflects the current level of nesting of beginUpdate() calls. See the discussion of Section 18.1.9.5 for more information on this property. Table 18.8, UndoableEditSupport Property Property Data Type get (get) is set (set) bound Default Value updateLevel int 0 18.1.9.2 Protected Fields The following fields are available to subclasses of UndoableEditSupport. protected CompoundEdit compoundEdit This is the edit used to group together multiple edits that are added between beginUpdate() and endUpdate() calls. See the discussion of Section 18.1.9.5 later in this section. protected Vector listeners This is where the list of listeners is stored. protected Object realSource Holds the event source used for all events fired by this object. If the source is set when the UndoableEditSupport is created, that object will be sent as the source of all events. Otherwise, the UndoableEditSupport itself will become the source. protected int updateLevel This is where the updateLevel property is stored. 18.1.9.3 Constructors public UndoableEditSupport() Creates a new support object, which will use itself as the source object for any events it fires. public UndoableEditSupport(Object r) - 571 -
Searching for affordable and reliable webhost to host and run your web applications? Go to our java web server services and you will be pleased.