Archive for November, 2007

Java Swing - O Reilly Removes the named Style (Web page design)

Friday, November 30th, 2007

Java Swing - O Reilly Removes the named Style from the context. 21.1.5.8 Font Management Methods These methods are used to manage Font objects. An Element’s Font is not typically stored as a single attribute, so it’s nice to have an easy way to obtain the Font and ensure that duplicate Font objects aren’t created unnecessarily. public Font getFont(AttributeSet attr) Checks for four attributes (Bold, Italic, FontFamily, and FontSize) in the given set, based on the constants defined in the StyleConstants class. From the values of these attributes, it returns a Font using the getFont() method. public Font getFont(String family, int style, int size) Searches an internal table for a Font matching the given font family, style, and size. If the Font is found, it is returned. If not, a new Font object is created, added to the table, and returned. The second parameter should be a logical “or” of the constants Font.PLAIN, Font.BOLD, and Font.ITALIC that defines the desired attributes. public FontMetrics getFontMetrics(Font f) Returns the FontMetrics object for the given Font using the default Toolkit. This method simply calls getFontMetrics() on the default Toolkit. 21.1.5.9 Color Accessor Methods public Color getForeground(AttributeSet attr) public Color getBackground(AttributeSet attr) Call StyleConstants.getForeground(attr) and StyleConstants.get- Background(attr). They could be overridden to take other attributes (brighter, darker, etc.) into account. 21.1.5.10 Serialization Methods The following static methods define a mechanism for reading and writing an AttributeSet to a stream. They are written so that the constant attribute keys defined in StyleConstants will be recognized when the stream is read, allowing references to the existing static objects to be used, instead of creating new ones. If these methods were not used, whenever a serialized AttributeSet was read in, new instances of the constants including StyleConstants.Bold, StyleConstants.Foreground, etc. were created. Each set would have its own “bold” attribute, rather than the shared StyleConstants.Boldinstance. These methods prevent this from happening by giving special treatment to registered attribute keys. public static void registerStaticAttributeKey(Object key) - 710
Searching for affordable and proven webhost to host and run your servlet applications? Go to Linux Web Hosting services and you will find it.

Web design rates - Java Swing - O Reilly Before looking at the

Friday, November 30th, 2007

Java Swing - O Reilly Before looking at the methods related to managing Style objects, we’ll take a quick detour to look at how the StyleContext manages Styles internally. Figure 21.3 shows an object structure for a StyleContext containing two Styles, each of which has a single “real” attribute, along with its name and resolving parent, stored as attributes of the Style (if they are non-null). There are two things to note about this structure. First, the StyleContext actually uses a Style object to manage Styles. The attribute keys in this special Style are the names of the real Styles. In our example, there are two Styles named style1 and style2 (the resolving parent of style2 is a third Style object that is not shown). The values for these keys are Style objects. Second, the NamedStyle inner class (described in a few pages) actually uses a SimpleAttributeSet to store attribute values. Figure 21.3. Inside a StyleContext 21.1.5.7 Style Management Methods The following methods are used to create new Styles and manage them using a StyleContext: public Style addStyle(String nm, Style parent) Creates a new, empty Style with the specified name and resolving parent. If no name is specified, the new Style will not be managed by the StyleContext, so the caller is responsible for keeping track of it. The second argument should be null if there is no parent for this Style (a common case). It is helpful to understand that this method returns a new StyleContext.NamedStyle (which implements Style). This inner class uses the attribute management methods defined in the last section to keep track of the attributes that define the Style. This means that attributes directly added to the Style object will automatically be incorporated into the StyleContext, without requiring an explicit call to StyleContent.addAttribute(). public Style getStyle(String nm) Returns a Style for the given name. If no Style has been added with the specified name, it returns null. public void removeStyle(String nm) - 709
We recommend cheap and reliable webhost to host and run your web applications: Coldfusion Web Hosting services.

Java Swing (Professional web hosting) - O Reilly // Add a 2nd

Thursday, November 29th, 2007

Java Swing - O Reilly // Add a 2nd attribute to both sets AttributeSet oneB = con.addAttribute(oneA, StyleConstants.Foreground, Color.blue); System.out.println(”Refs are same after adding a 2nd attribute ” + “to one set? ” + (oneB == twoA)); // prints false (of course) AttributeSet twoB = con.addAttribute(twoA, StyleConstants.Foreground, Color.blue); System.out.println(”Refs are same after adding ” + “2nd attribute to 2nd set? ” + (oneB == twoB)); // prints true // remove the second attribute so it matches the old set . . . AttributeSet oneC = con.removeAttribute(oneB, StyleConstants.Foreground); System.out.println(”Old set matches new set after removal? ” + (oneC == oneA)); // prints true // show that a threshold for reusing sets is reached . . . AttributeSet tooBig1 = new SimpleAttributeSet(); AttributeSet tooBig2 = new SimpleAttributeSet(); for (int i=0; i<10; i++) { tooBig1 = con.addAttribute(tooBig1, Integer.toString(i), new Integer(i)); tooBig2 = con.addAttribute(tooBig2, Integer.toString(i), new Integer(i)); System.out.print(tooBig1 == tooBig2); System.out.print(" "); } System.out.println(); System.exit(0); } } When executed, this program produces the following output: Refs are initially to the same object? falseRefs are same after setting the same value? trueRefs are same after adding a 2nd attribute to one set? falseRefs are same after adding 2nd attribute to 2nd set? trueOld set matches new set after removal? true true true true true true true true true true false Initially, we created two new sets and checked to see if they referred to the same object. Since both were created using new(), this of course returns false. Next, we add the same attribute (bold=true) to each set and compare the sets returned from the two addAttribute() calls. The StyleContext has returned the same instance in both cases, so a comparison of oneA and twoA returns true. We then add a second attribute (foreground=blue) to the first set. The returned value (oneB) is, as you'd expect, not the same as twoA. However, adding the second attribute to the second set as well results in another shared set. We then remove this attribute from the first set and confirm that the returned set is the same set we had before adding the second attribute. Finally, we show that this set reuse is only done on small sets. In this last portion of the example, we add some toy attributes to two sets and show that the sets returned by addAttribute() match until we exceed the threshold, when we get separate set objects, even though they still contain the same key/value pairs. 21.1.5.6 A Look Inside - 708
Visit our web design programs services for an affordable and reliable webhost to suit all your needs.

Java Swing - O Reilly set reaches a threshold (Top ten web hosting)

Thursday, November 29th, 2007

Java Swing - O Reilly set reaches a threshold (more than 9 attributes, by default), this method returns the original set (if it is mutable) with the specified attribute added. If the original set is immutable, a new mutable set (a SimpleAttributeSet) is returned. public synchronized AttributeSet addAttributes(AttributeSet old, AttributeSet attr) Adds the second set of attributes to the first and returns a new set. The same rules about returning new sets or reusing the original set apply, as for the previous method. public synchronized AttributeSet removeAttribute(AttributeSet old, Object name) Removes the specified attribute and returns a new set. public synchronized AttributeSet removeAttributes(AttributeSet old, AttributeSet attrs) Removes the second set of attributes from the first. public synchronized AttributeSet removeAttributes(AttributeSet old, Enumeration names) Removes the specified attributes from the given set. names should contain the keys for the attributes to be removed. public synchronized void reclaim(AttributeSet a) Tells the context that an attribute set is no longer being used, allowing it to be removed from the context. The following example shows how StyleContext can be used to share AttributeSets. Whenever the attributes in two small sets are equal, the same set is returned. Once the sets get too large, it is more efficient to use different sets, since matching all attributes in a large set would become too time consuming. // StyleContextExample.java// import javax.swing.text.*; import java.awt.*; public class StyleContextExample { public static void main(String[] args) { StyleContext con = new StyleContext(); // Create two different attribute sets . . . SimpleAttributeSet one = new SimpleAttributeSet(); SimpleAttributeSet two = new SimpleAttributeSet(); System.out.println(”Refs are initially to the same object? ” + (one == two)); // prints false // Add the same things to each set . . . AttributeSet oneA=con.addAttribute(one, StyleConstants.Bold, Boolean.TRUE); AttributeSet twoA=con.addAttribute(two, StyleConstants.Bold, Boolean.TRUE); System.out.println(”Refs are same after setting the ” + “same value? ” + (oneA == twoA)); // prints true - 707
In case you need affordable webhost to host your website, our recommendation is ecommerce web host services.

Java Swing - O Reilly Bold, and Italic). This (Web page design)

Thursday, November 29th, 2007

Java Swing - O Reilly Bold, and Italic). This class can be used to create and manage the actual Font objects generated from these attributes. 21.1.5.1 Properties Table 21.10 shows the properties defined by the StyleContext class. The emptySet property is initialized as a StyleContext.SmallAttribute (a package private inner class implementation of AttributeSet) object that contains no attributes. StyleNames provides access to the names of all Styles created by this StyleContext. Initially, a single Style named “default” is created. This Style does not contain any attributes. Table 21.10, StyleContext Properties Property Data Type get is set bound Default Value emptySet* AttributeSet StyleContext.SmallAttributeSet() styleNames Enumeration (String) { “default” } 21.1.5.2 Events Whenever a new Style is created or an existing Style is removed,[7] a ChangeEvent is fired. The following two methods are provided for managing ChangeListeners. [7] Note that to be notified of changes to the attributes within a Style, you must add a listener to the Style itself, not the StyleContext. public void addChangeListener(ChangeListener l) public void removeChangeListener(ChangeListener l) 21.1.5.3 Constants The StyleContext class defines the constant shown in Table 21.11. Table 21.11, StyleContext Constants Name Data Type Description DEFAULT_STYLE String The name of the default (initially empty) style (default) 21.1.5.4 Constructor public StyleContext() Creates a StyleContext containing only a default style. The default Style has no attributes. 21.1.5.5 AttributeContext Methods These methods (along with the accessor for the emptySet property) implement the AbstractDocument.AttributeContext interface. They can be used to add and remove attributes from AttributeSets, allowing equivalent sets to be shared within a document, or across documents sharing the same StyleContext. public synchronized AttributeSet addAttribute(AttributeSet old, Object name, Object value) Adds an attribute to the given set and returns a new attribute set. For small attribute sets, this implementation always returns a different object than the original one. Once the size of the - 706
We highly recommend you visit web and email hosting services if you need stable and cheap web hosting platform for your web applications.

Tomcat web server - Java Swing - O Reilly Property Data Type get

Wednesday, November 28th, 2007

Java Swing - O Reilly Property Data Type get is set bound Default Value tab (indexed) TabStop from constructor tabCount int from constructor 21.1.4.2 Constructor public TabSet(TabStop tabs[]) Creates a set containing the given array of TabStops. 21.1.4.3 Methods public TabStop getTabAfter(float location) Returns the first TabStop positioned after the given location. public int getTabIndex(TabStop tab) Returns the index of the given TabStop. public int getTabIndexAfter(float location) Returns the index of the first TabStop positioned after the input location. public String toString() Returns a string representation of the TabStops in the set. 21.1.5 The StyleContext Class Now back to style. StyleContext is a utility class that provides a variety of features used when working with AttributeSets and Styles. StyleContext implements the AbstractDocument.AttributeContext interface, providing mechanisms for sharing attributes that can greatly reduce the overhead involved in storing a large number of attributes, possibly spanning multiple documents. For large documents, a utility like StyleContext can quickly become critical. Consider a worst-case scenario in which we have a document containing 1000 characters that alternate between bold and italics (e.g., abcdefghij). Without the use of a StyleContext, we’d have 1000 AttributeSet objects, each containing an attribute/value pair. Using a StyleContext would reduce this number to two. This is clearly not a particularly realistic example, but it serves to illustrate the point that intelligent management of attributes is a good idea. In addition to providing an efficient implementation of the AbstractDocument.AttributeContext interface, StyleContext adds methods used to track a set of Styles and serves as a factory for new Style objects, using an inner class called NamedStyle. A third category of methods defined by StyleContext is methods used to retrieve Font objects from AttributeSets and manage the Fonts efficiently. The reason Fonts are given this special treatment is that they are typically stored using four different attributes (FontSize, FontFamily, - 705
In case you need affordable webhost to host your website, our recommendation is ecommerce web host services.

Java Swing - O Reilly Constant Description LEAD_DOTS Precede (Crystaltech web hosting)

Wednesday, November 28th, 2007

Java Swing - O Reilly Constant Description LEAD_DOTS Precede tab with a series of dots LEAD_EQUALS Precede tab with a series of equal signs LEAD_HYPHENS Precede tab with a series of hyphens LEAD_NONE Precede tab with blank space LEAD_THICKLINE Precede tab with a thick line LEAD_UNDERLINE Precede tab with a thin line 21.1.3.4 Constructors public TabStop(float pos) Creates a TabStop at the specified position, with alignment and leader set to ALIGN_LEFT and LEAD_NONE. public TabStop(float pos, int align, int leader) Creates a TabStop at the specified position, with the given alignment and leader values. 21.1.3.5 Object Methods The following methods, defined in Object, are implemented in this class: public boolean equals(Object other) Returns true if the given object is a TabStop with the same alignment, leader, and position. public int hashCode() This method just calls super.hashCode(). Note that this breaks the contract normally defined by this method, which states that objects that are equal (according to equals()) should return the same hashCode. This should be fixed in a future release. public String toString() Returns a string that describes the values of the object’s three properties. 21.1.4 The TabSet Class It is often useful to define a series of TabStops that should be applied to a given block of text. TabSet allows you to do this, and defines a few convenient methods for looking up the TabStops contained in the set. TabSets are immutable once the TabStops are defined (in the constructor), they cannot be added or removed. 21.1.4.1 Properties The TabSet class defines the properties shown in Table 21.9. The indexed tab property is used to access a given TabStop, while the tabCount property holds the current number of TabStops defined in the set. Table 21.9, TabSet Properties - 704
You want to have a cheap webhost for your apache application, then check apache web hosting services.

Java Swing - O Reilly doc.insertString(offset, “tCenteredn”, null); tabs (Web site counters)

Tuesday, November 27th, 2007

Java Swing - O Reilly doc.insertString(offset, “tCenteredn”, null); tabs = new TabSet(new TabStop[] {center}); StyleConstants.setTabSet(a, tabs); doc.setParagraphAttributes(offset, 1, a, false); offset = doc.getLength(); doc.insertString(doc.getLength(), “t1234.99n”, null); tabs = new TabSet(new TabStop[] {decimal}); StyleConstants.setTabSet(a, tabs); doc.setParagraphAttributes(offset, 1, a, false); offset = doc.getLength(); doc.insertString(doc.getLength(), “tLeftn”, null); tabs = new TabSet(new TabStop[] {left}); StyleConstants.setTabSet(a, tabs); doc.setParagraphAttributes(offset, 1, a, false); offset = doc.getLength(); doc.insertString(doc.getLength(), “tRightn”, null); tabs = new TabSet(new TabStop[] {right}); StyleConstants.setTabSet(a, tabs); doc.setParagraphAttributes(offset, 1, a, false); } catch (BadLocationException ex) {} // Display it JFrame f = new JFrame(); f.addWindowListener(new BasicWindowMonitor()); f.setSize(200, 110); f.setContentPane(tp); f.setVisible(true); } } In this example, we simply created five TabStop objects, one with each of the different alignment values. For each TabStop, we added a line of text, starting with a tab (”t”) and set its TabSet (described next) to a set containing the single TabStop. Figure 21.2 shows how these values are displayed. Figure 21.2. TabStop alignment 21.1.3.3 Leader Constants Table 21.8 shows constants that enumerate the possible ways the space before a tab should be filled. These constants are legal values for the leader property. Currently, changing this property’s value has no effect. Table 21.8, TabStop Leading Constants - 703
Looking for affordable and reliable webhost to host and run your business application? Then look no more and go to servlet web hosting services.

Unable to start debugging on the web server - Java Swing - O Reilly position float from constructor

Tuesday, November 27th, 2007

Java Swing - O Reilly position float from constructor 21.1.3.2 Alignment Constants Table 21.7 shows the constants used to enumerate the possible ways that text following a tab can be aligned. Table 21.7, TabStop Alignment Constants Name Data Type Description ALIGN_BAR int Text after the tab should start at the tab position (currently the same as ALIGN_LEFT) ALIGN_CENTER int Text after the tab should be centered over the tab’s position ALIGN_DECIMAL int Text after the tab should be aligned so that the next decimal, tab, or newline is located at the tab position ALIGN_LEFT int Text after the tab should start at the tab position ALIGN_RIGHT int Text after the tab should end at the tab position Here’s an example that shows the effect of each of these alignment values: // TabStopExample.java // import javax.swing.text.*; import javax.swing.*; // Show how the different TabStop alignment values work. public class TabStopExample { public static void main(String[] args) { // Create TabStops with the different alignments TabStop bar = new TabStop(100, TabStop.ALIGN_BAR, TabStop.LEAD_NONE); TabStop center = new TabStop(100, TabStop.ALIGN_CENTER, TabStop.LEAD_NONE); TabStop decimal= new TabStop(100, TabStop.ALIGN_DECIMAL, TabStop.LEAD_NONE); TabStop left = new TabStop(100, TabStop.ALIGN_LEFT, TabStop.LEAD_NONE); TabStop right = new TabStop(100, TabStop.ALIGN_RIGHT, TabStop.LEAD_NONE); // Create a JTextPane to show tabs in JTextPane tp = new JTextPane(); StyledDocument doc = tp.getStyledDocument(); SimpleAttributeSet a = new SimpleAttributeSet(); TabSet tabs; int offset; // Insert text with each TabStop value try { offset = doc.getLength(); doc.insertString(doc.getLength(), “tBarn”, null); tabs = new TabSet(new TabStop[] {bar}); StyleConstants.setTabSet(a, tabs); doc.setParagraphAttributes(offset, 1, a, false); offset = doc.getLength(); - 702
We highly recommend you visit web and email hosting services if you need stable and cheap web hosting platform for your web applications.

Java Swing - (Web host sites) O Reilly public static boolean isUnderline(AttributeSet

Monday, November 26th, 2007

Java Swing - O Reilly public static boolean isUnderline(AttributeSet a) These methods return the value found in the given set, if there is one. If the key is not found, the default values shown in Table 21.2 are returned. public static void setAlignment(MutableAttributeSet a, int align) public static void setBackground(MutableAttributeSet a, Color bg) public static void setBidiLevel(MutableAttributeSet a, int 0) public static void setBold(MutableAttributeSet a, boolean b) public static void setFirstLineIndent(MutableAttributeSet a, float i) public static void setFontFamily(MutableAttributeSet a, String fam) public static void setFontSize(MutableAttributeSet a, int s) public static void setForeground(MutableAttributeSet a, Color fg) public static void setItalic(MutableAttributeSet a, boolean b) public static void setLeftIndent(MutableAttributeSet a, float i) public static void setLineSpacing(MutableAttributeSet a, float i) public static void setRightIndent(MutableAttributeSet a, float i) public static void setSpaceAbove(MutableAttributeSet a, float i) public static void setSpaceBelow(MutableAttributeSet a, float i) public static void setTabSet(MutableAttributeSet a, TabSet tabs) public static void setUnderline(MutableAttributeSet a, boolean b) These methods add the appropriate attribute to the given set, replacing the existing value if there is one. The next two methods actually set two properties. In addition to setting ComponentAttribute or IconAttribute, they also set the AbstractDocument.Ele-mentNameAttribute. The values used for this property were shown back in Table 21.5. public static void setComponent(MutableAttributeSet a, Component c) public static void setIcon(MutableAttributeSet a, Icon c) 21.1.3 The TabStop Class In the last section, we came across TabSet and TabStop. Now, we’ll take quick detour from our discussion of style to examine them. TabStop, as you might guess, is used to describe a tab position. This information is used by the text view classes to correctly handle the display of tabs encountered in the document model. 21.1.3.1 Properties The TabStop class defines the properties listed in Table 21.6. The alignment property specifies how the text following a tab should be positioned relative to the tab position. The legal values for this property are shown in Table 21.7. The leader property describes what should be displayed leading up to the tab. Legal values for this property are shown in Table 21.6. Currently, none of the Swing text views use the leader property. The position property indicates where the tab should appear (in pixels). Table 21.6, TabStop Properties Property Data Type get is set bound Default Value alignment int ALIGN_LEFT leader int LEAD_NONE - 701
You need excellent and relaible webhost company to host your web applications? Then pay a visit to Inexpensive Web Hosting services.