Archive for November, 2007

Web hosting plans - Java Swing - O Reilly 21.1.2.4 Alignment Value Constants

Monday, November 26th, 2007

Java Swing - O Reilly 21.1.2.4 Alignment Value Constants StyleConstants also defines four attribute values for the Alignment attribute, shown in Table 21.4. Table 21.4, StyleConstants.Alignment Attribute Value Constants Name Data Type Description ALIGN_CENTER int Align text to the center with equal whitespace on the left and right. ALIGN_JUSTIFIED int Align text such that all whitespace is spread out, leaving text aligned on both the left and right margins. The last line should have left alignment. ALIGN_LEFT int Align text to the left with whitespace on the right. ALIGN_RIGHT int Align text to the right with whitespace on the left. 21.1.2.5 Element Name Constants AbstractDocument defines a constant called ElementNameAttribute , used as a key to store the name of an Element in its AttributeSet (see Table 21.5). StyleConstants defines two possible values for this attribute, used when the Element does not contain textual data. This attribute is not limited to these two values; these are just constants for special case Element names. Table 21.5, AbstractDocument.ElementNameAttribute Value Constants Name Data Type Description ComponentElementName String Used when the Elementcontains a Componentinstead of text. IconElementName String Used when the Element contains an Icon instead of text. 21.1.2.6 Lookup and Update Methods StyleConstants defines static methods to access and set each of the attributes for which it defines constant keys. Each accessor method takes an AttributeSet, while the update methods require a MutableAttributeSet as input. These methods handle the conversions between Java primitive types and the wrapper classes Float, Integer, and Boolean (remember, all attribute values are of type Object, so primitive attribute values must be wrapped in objects), so that all interfaces are able to use the primitive types. public static int getAlignment(AttributeSet a) public static Color getBackground(AttributeSet a) public static int getBidiLevel(AttribuetSet a) public static boolean isBold(AttributeSet a) public static Component getComponent(AttributeSet a) public static float getFirstLineIndent(AttributeSet a) public static String getFontFamily(AttributeSet a) public static int getFontSize(AttributeSet a) public static Color getForeground(AttributeSet a) public static Icon getIcon(AttributeSet a) public static boolean isItalic(AttributeSet a) public static float getLeftIndent(AttributeSet a) public static float getLineSpacing(AttributeSet a) public static float getRightIndent(AttributeSet a) public static float getSpaceAbove(AttributeSet a) public static float getSpaceBelow(AttributeSet a) public static TabSet getTabSet(AttributeSet a) - 700
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.

Photo web hosting - Java Swing - O Reilly Constant Category Value Type

Sunday, November 25th, 2007

Java Swing - O Reilly Constant Category Value Type Default Description Alignment Paragraph Integer ALIGN_LEFT Alignment for a paragraph (see Table 21.4 for valid values) Background Char, Color Color Color.black Background color BidiLevel Character Integer 0 Bidirectional level according to the Unicode bidi algorithm Bold Char, Font Boolean false Bold text ComponentAttribute[4] Character Component null Allows an Element to represent a Component, instead of text FirstLineIndent Paragraph Float 0 Number of points to indent first line FontFamily Char, Font String “Monospaced” Name of the font family FontSize Char, Font Integer 12 Size of the font Foreground Char, Color Color black Foreground color IconAttribute Character Icon null Used to allow an Element to represent a Icon, instead of text Italic Char, Font Boolean false Italic text LeftIndent Paragraph Float 0 Number of points to indent from the left margin LineSpacing Paragraph Float 0 Number of points between lines Orientation[5] Paragraph undefined undefined Orientation of the paragraph RightIndent Paragraph Float 0 Number of points to indent from the right margin SpaceAbove Paragraph Float 0 Number of points above each line SpaceBelow Paragraph Float 0 Number of points below each line TabSet Paragraph TabSet[6] null Set of TabStops Underline Character Boolean false Underlined text [3] The attribute names FontFamily and FontSize are shortened to Family and Size within the FontConstants inner class. All other attribute names are the same within their respective inner classes. [4] The ComponentAttribute and IconAttribute constants can be used to indicate that an element should be displayed as a component or icon rather than as text. For more information, see the example later in the chapter. There is no additional significance to the “Attribute” suffix of these constants. [5] As of JDK 1.2 beta 4, no static convenience methods are defined for this constant. [6] The TabSet and TabStop classes are described after this section. 21.1.2.3 Other Attribute Constants Table 21.3 shows constants used to store special information in an AttributeSet. The first constant shown here, ComposedTextAttribute , is intended to be used to hold an AttributedString (a new JDK 1.2 class defined in the java.text package). This constant is currently unused. The last two constants in the table are used as attribute keys to define the set’s name (used for named Styles) and the set’s resolving parent. Table 21.3, StyleConstants Special Attribute Key Constants Name Data Type Value Type Description ComposedTextAttribute Object java.text.At- tributedString An attributed string describing the set’s attributes (JDK 1.2 only) NameAttribute Object String The name of the attribute set ResolveAttribute Object AttributeSet Attribute set’s resolving parent - 699
Please visit our professional web hosting services to find out about cheap and reliable webhost service that will surely answer all your demands.

Java Swing - O Reilly 21.1.2.1 StyleConstants Inner Classes (Web servers)

Saturday, November 24th, 2007

Java Swing - O Reilly 21.1.2.1 StyleConstants Inner Classes StyleConstants groups its constants using the four inner classes described next. Note the different (empty) interfaces from AttributeSet implemented by each class. These allow you to determine the type of an attribute using the instanceof operator. For example: if (someAttr instanceof AttributeSet.ParagraphAttribute) doSomething(); Here are the definitions of the different inner classes. public static class CharacterConstants implements AttributeSet.CharacterAttribute Defines constants for attributes typically applied to character content, including those defined in FontConstants and ColorConstants. public static class ColorConstants implements AttributeSet.ColorAttribute, AttributeSet.CharacterAttribute Defines constants for foreground and background color. public static class FontConstants implements AttributeSet.FontAttribute, AttributeSet.CharacterAttribute Defines constants related to font definition. public static class ParagraphConstants implements AttributeSet.ParagraphAttribute Defines constants used to describe an entire paragraph, such as alignment and spacing. You don’t need to worry about these inner classes, because all of the constants defined in them are also defined in the outer class, StyleConstants. This means that, for example, all of the following are valid (and equivalent): StyleConstants.FontSizeStyleConstants.CharacterConstants.SizeStyleConstants.FontConstants.Size Consistently using the first of these formats will make your code simpler to understand. 21.1.2.2 Attribute Constants Table 21.2 shows all of the attribute constants defined by StyleConstants. Regardless of their actual type, which is always one of the StyleConstants inner classes, all of these constants are defined as type Object. The Value Type column indicates the type of value that should be associated with each attribute key, and the Default column shows the value that will be returned by the static accessor methods (described later) if the attribute is not found in a set.[2] [2] This is fairly important. When you create a new JTextPane, for example, it is these default values that define what the text will look like if you don’t specify attributes for the text. This is because a default Style is in use that contains no attributes, so these defaults will be returned when the Styleis examined using the static StyleConstants methods. Table 21.2, StyleConstants Attribute Name Constants[3] - 698
Visit our web design programs services for an affordable and reliable webhost to suit all your needs.

Web hosting provider - Java Swing - O Reilly 21.1.1 The Style Interface

Saturday, November 24th, 2007

Java Swing - O Reilly 21.1.1 The Style Interface The Style interface is a simple extension of MutableAttributeSet, which allows a set of attributes to be given a name. This just defines a common identifier for the Style, allowing it to be easily referenced (e.g., by StyledDocument’s getStyle() method, which takes a single Stringand returns the matching Style). This name is also typically used to populate a menu in the user interface, allowing the user to select a named Style for some portion of text. In addition, Style adds support for registering change listeners to be notified whenever the attributes that define a Style are modified. 21.1.1.1 Property Table 21.1 shows the property defined by the Style interface. The only property added by Style is the name property. It is valid for a Style to be unnamed, in which case the accessor should simply return null. Table 21.1, Style Property Property Data Type get is set bound Default Value name String See also properties from the MutableAttributeSet interface (Table 20.9). 21.1.1.2 Events When a change is made to the attributes that make up a Style, listeners registered for change events will be notified. The style interface specifies the following standard methods for registering change listeners: public void addChangeListener(ChangeListener l) public void removeChangeListener(ChangeListener l) 21.1.2 The StyleConstants Class Many of the attributes used to describe text are very common. If each program had to choose a key (i.e., a name or symbolic constant) to represent each of these attributes, there would be little hope for consistency. In defining a key for the “bold” attribute, one developer might use the String”bold”, another might use the String “BoldText”, and yet another might use an Integer object that maps to some globally defined constant. For many common attributes, this confusion can be avoided by using the StyleConstants class. This class defines a large number of type-safe constant values, intended to be used as attribute keys. This allows us to refer to the “bold” attribute as simply StyleConstants.Bold. In addition to defining constants, StyleConstants also defines static methods that allow you to set the value for certain attributes. Using these methods allows you to replace a call like this: myMutableAttrSet.addAttribute(StyleConstants.Bold, new Boolean(true)); with a call like this: StyleConstants.setBold(myMutableAttrSet, true); - 697
We recommend high quality webhost to host and run your jsp application: christian web host services.

Java Swing - O Reilly This implementation of AbstractDocument.AttributeContext

Saturday, November 24th, 2007

Java Swing - O Reilly This implementation of AbstractDocument.AttributeContext provides an efficient mechanism for managing attributes and Styles shared by multiple Elements or Documents. It actually stores the Styles it manages as attributes in an instance of an inner class called NamedStyle. In addition, this class is responsible for the creation of new Style objects, which are always created as new NamedStyle objects. StyleContext.NamedStyle This public inner class implements the Style interface using its enclosing StyleContext for efficient management of attributes. Its resolving parent is always another Style. StyleConstants This class contains definitions for a wide variety of pre-defined attributes used to define Styles. It also contains many convenient static methods to extract specific attributes from a given AttributeSet, e.g., isBold() is a static method that takes an AttributeSet, checks to see if the StyleConstants.Bold key is in the set, and returns its value (or false if it’s not in the set). DefaultStyledDocument This is the class used by text components like JTextPane that want to show text using a variety of textual styles. It uses a StyleContext to manage its Styles. It also uses several inner classes, defined below. DefaultStyledDocument.ElementBuffer This public inner class is used to manage changes to the Element structure of a DefaultStyledDocument. DefaultStyledDocument.ElementSpec This public inner class is used to provide a specification of an Element to be created. ElementSpecs are created by DefaultStyledDocument (e.g., in insertUpdate()) and passed to an ElementBuffer, which uses them to determine how the Element structure needs to be updated.[1] [1] Note that a containment relation should be shown from DefaultStyledDocument.ElementSpecto AttributeSet (one of the things that makes up an ElementSpec is a set of attributes), but was omitted to keep the diagram as readable as possible. DefaultStyledDocument.SectionElement This protected inner class is an extension of AbstractDocument. BranchElement, used to provide an additional level of nesting in the DefaultStyledDocument Element structure. An instance of this class serves as the document’s root Element. In the next part of this chapter, we’ll take a closer look at each of these new classes and interfaces. Once they’ve all been covered, we’ll look at a detailed example that shows how to use Styles to create a Style-based text editor. - 696
Check Tomcat Web Hosting services for best quality webspace to host your web application.

Java Swing - O Reilly described in the last (Web page design)

Friday, November 23rd, 2007

Java Swing - O Reilly described in the last chapter to provide a powerful range of support for working with text styles. The new classes and interfaces involved in providing style capabilities (along with some of the ones from the last chapter that are directly related) are shown in Figure 21.1. Figure 21.1. Style class diagram Over the next few pages, we’ll give a brief overview of the new classes and interfaces shown in this diagram, as well as an explanation of the relationships between them. Style This interface, an extension of MutableAttributeSet, adds two things not provided by its super-interface. The first is a name every Style may (optionally) be given a name. The second is the ability to add and remove ChangeListeners. These listeners should be notified when changes are made to the definition of a Style. StyledDocument This interface, an extension of Document, adds a variety of methods for working with Styles and defines methods to provide access to the set of Style objects that describe the Document. New methods include setLogicalStyle(), to define the Style for the paragraph containing a given offset, addStyle(), to create a new Style, and many more. StyleContext - 695
You need excellent and relaible webhost company to host your web applications? Then pay a visit to Inexpensive Web Hosting services.

Java Swing (Java web server) - O Reilly } } Figure 21.7.

Friday, November 23rd, 2007

Java Swing - O Reilly } } Figure 21.7. JTextPane containing JButtons and ImageIcons 21.1.12.6 Other Public Method public void replaceSelection(String content) Inserts, removes, or replaces text. If there is any currently selected text, it is removed. Then, any new text is inserted in its place. If no text is passed in, this is essentially a remove operation. If no text is selected, the given text will be inserted at the current cursor position. Any new text will have the attributes currently defined for new given text (inputAttributes). 21.1.12.7 Protected Methods The following protected methods are defined in JTextPane: protected final StyledEditorKit getStyledEditorKit() Casts the result of getEditorKit() to a StyledEditorKit. protected EditorKit createDefaultEditorKit() Returns a new StyledEditorKit. This is the method called by JEditorPane.getEditorKit(), if it is called before a kit has been set for the pane. 21.1 Style If you’ve ever worked with a reasonably powerful word processor, you’re probably already familiar with the concept of a style. A style is basically just a collection of attributes that describes how something should look. For example, as I sit here writing this book, the text I’m entering into my word processor looks a certain way because of the paragraph style (Body) and character style (Default) I have selected. To produce the heading just before this paragraph, I could have typed “Style,” selected the text, changed the font to Bodoni BT, changed the font size to 18, and toggled on the italics button. Thankfully (believe me!), I didn’t have to do all that. All I had to do was click somewhere within the text and use a menu to select the HeadA style, which encapsulates all of the properties described above (not to mention more interesting things, like the fact that the next paragraph should be a Body paragraph). Providing this type of functionality in your own programs would be a lot of work if you had to do it all yourself. Fortunately, you don’t. The Swing text package builds on the document model - 694
If you are searching for cheap webhost for your web application, please visit MySQL5 Web Hosting services.

Web hosting comparison - Java Swing - O Reilly Inserts an Icon into

Thursday, November 22nd, 2007

Java Swing - O Reilly Inserts an Icon into the document, replacing anything currently selected. If there is no selection, the icon is inserted at the current cursor position. Inserting an Icon results in a single blank space being inserted into the document. This space is represented by a single Element, with attributes set to indicate that the space represents the given Icon. Here’s a short example showing how these methods work. In it, we create a JTextPane and two buttons: one inserts an Icon, and the second inserts a JButton. Figure 21.7 shows a display after playing with the editor a little bit. // IconAndComp.java // import javax.swing.*; import javax.swing.text.*; import java.awt.*; import java.awt.event.*; // Shows that Icons and Components can be added to a JTextPanepublic class IconAndComp { public static void main(String[] args) { final JTextPane pane = new JTextPane(); // Add an icon button final ImageIcon icon = new ImageIcon(”images/bluepaw.gif”); JButton iconButton = new JButton(icon); iconButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { pane.insertIcon(icon); } }); // Add a “Button” button JButton buttonButton = new JButton(”Insert Button”); buttonButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { pane.insertComponent(new Button(”Click Me”)); } }); // Lay out . . . JPanel buttons = new JPanel(); buttons.add(iconButton); buttons.add(buttonButton); JFrame frame = new JFrame(); frame.addWindowListener(new BasicWindowMonitor()); frame.setSize(300,200); Container c = frame.getContentPane(); c.setLayout(new BorderLayout()); c.add(pane, BorderLayout.CENTER); c.add(buttons, BorderLayout.SOUTH); frame.setVisible(true); - 693
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 (Make web site) the character attributes

Thursday, November 22nd, 2007

Java Swing - O Reilly Returns the character attributes that apply to the text at the current cursor location. Only the current cursor position is used; any selected text is irrelevant. If the current cursor position is just after the last character in the document, this method returns an empty set, because the leaf Element containing the text up to the end of the document does not contain the position after the end of the text; there’s actually an extra, empty Element there. public Style getLogicalStyle() Delegates to the pane’s document, passing in the current cursor location. Only the current cursor position is used, any selected text is irrelevant. public AttributeSet getParagraphAttributes() Returns the paragraph attributes that apply to the text at the current cursor location. Only the current cursor position is used; any selected text is irrelevant. public void setCharacterAttributes(AttributeSet attr, boolean replace) Applies the given attributes to the selected portion of the document. If there is no selection, the attributes will be applied to any new text inserted (by updating inputAttributes) into the document. The replace argument specifies whether or not the current attributes should be removed before applying the given attributes. public void setLogicalStyle(Style s) Delegates to the pane’s document, passing in the given Style and the current cursor location. The change is only applied to the paragraph at the current cursor location (unlike the other two set methods); any selected text is irrelevant. public void setParagraphAttributes(AttributeSet attr, boolean replace) Applies the given attributes to any paragraphs that intersect the selected portion of the document. If there is no selection, the attributes are applied to the paragraph at the current cursor position. The replace argument specifies whether or not the current attributes should be removed before applying the given attributes. 21.1.12.5 Adding Non-Text Content In addition to displaying text, JTextPane can be used to display Icons and arbitrary Components. This flexibility makes it possible to display documents with embedded images, or interactive documents such as HTML forms. public void insertComponent(Component c) Inserts a Component into the document, replacing anything currently selected. If there is no selection, the component is inserted at the current cursor position. Inserting a Componentresults in a single blank space being inserted into the document. This space is represented by a single Element with attributes set to indicate that the space represents the given Component. public void insertIcon(Icon c) - 692
If you are looking for cheap and quality webhost to host and run your website check Jboss Web Hosting services.

Java Swing - O Reilly See also properties from (Web design online)

Wednesday, November 21st, 2007

Java Swing - O Reilly See also properties from the JEditorPane class (Table 20.7). The characterAttributes , logicalStyle, and paragraphAttributes properties are described in the “Section 21.1.12.4″ section below. We handle them this way because the get() and set() methods are more complicated than basic property accessors and mutators. The default values for these properties come from the document. The inputAttributes property defines the AttributeSet to be used for newly inserted text. This property is managed by the editorKit. Newly inserted text will have the same attributes as the text before the cursor position. The editorKit property reflects the StyledEditorKit used by this class (EditorKits will be covered in detail in Chapter 24). Attempting to set editorKit to a kit that is not a StyledEditorKit (or a subclass) results in an IllegalArgumentException. The scrollableTracksViewportWidth property (from the Scrollable interface) is returned as true by this class, meaning that the pane should be confined to the width of the viewport it is placed in (when used with a JScrollPane, for example). This allows text to be properly wrapped when the end of a line is reached. 21.1.12.2 Constructors public JTextPane() Creates an empty text pane. It creates a new StyledEditorKit and gets its document model from this kit. public JTextPane(StyledDocument doc) Creates a text pane displaying the given document. 21.1.12.3 StyledDocument Delegation Methods The following methods do nothing more than delegate to the pane’s model. For a detailed explanation of Style manipulation, see the description of DefaultStyledDocument presented earlier in this chapter. public Style addStyle(String nm, Style parent) public Style getStyle(String nm) public void removeStyle(String nm) 21.1.12.4 Attribute and Style Methods These methods manipulate the attributes associated with either the current selection or the current cursor position. Pay close attention to which methods take the current selection into account, and which do not. Recall from the discussion of the StyledDocument interface that character attributes are applied to leaf elements, and paragraph attributes are applied to a leaf’s containing element. Styles are also applied at the paragraph level, typically serving as reusable sets of well-known attributes. public AttributeSet getCharacterAttributes() - 691
We recommend you use shared web hosting services, because many users agree that it is cheap, reliable and customer-satisfying webhost.