001: /*
002: * Copyright Javelin Software, All rights reserved.
003: */
004:
005: package com.javelin.swinglets;
006:
007: import java.awt.*;
008: import java.util.*;
009: import java.io.*;
010:
011: /**
012: * A SCharacter will display a 'control' character, that would otherwise
013: * not be rendered correctly.
014: * <P>
015: * These characters are:-
016: *
017: <table BORDER COLS=1 >
018: <tr><td>NAME</td></tr>
019: <tr><td><font size=-1>SPACE</font></td></tr>
020: <tr><td><font size=-1>PARAGRAPH</font></td></tr>
021: <tr><td><font size=-1>BREAK</font></td></tr>
022: <tr><td><font size=-1>QUOTE</font></td></tr>
023: <tr><td><font size=-1>AMPERSAND</font></td></tr>
024: <tr><td><font size=-1>APOSTROPHE</font></td></tr>
025: <tr><td><font size=-1>GREATER_THAN</font></td>
026: </tr><tr><td><font size=-1>LESS_THAN</font></td></tr>
027: </table>
028:
029: * @author Robin Sharp
030: */
031:
032: import java.awt.*;
033: import java.io.*;
034: import java.util.*;
035:
036: public class SCharacter extends SComponent {
037: /**
038: * Specical Characters for Look And Feel
039: */
040: public final static int SPACE = 0;
041: public final static int PARAGRAPH = 1;
042: public final static int BREAK = 2;
043: public final static int QUOTE = 3;
044: public final static int AMPERSAND = 4;
045: public final static int APOSTROPHE = 5;
046: public final static int GREATER_THAN = 6;
047: public final static int LESS_THAN = 7;
048:
049: /**
050: * Creates a <code>SCharacter</code> instance with the following code.
051: */
052: public SCharacter(int character) {
053: if (character != 0)
054: setCharacter(character);
055: }
056:
057: /**
058: * Creates a <code>SCharacter</code> with a SPACE.
059: */
060: public SCharacter() {
061: }
062:
063: /**
064: * Returns the name of the L&F class that renders this component.
065: */
066: public Class getUIClass() {
067: return SCharacter.class;
068: }
069:
070: /**
071: * Returns the code for the character.
072: */
073: public int getCharacter() {
074: return character;
075: }
076:
077: /**
078: * Sets the code for the character..
079: */
080: public SCharacter setCharacter(int character) {
081: firePropertyChange("character", this .character,
082: this .character = character);
083: return this ;
084: }
085:
086: /**
087: * Returns the character as normal text.
088: */
089: public String getText() {
090: return text[character];
091: }
092:
093: /**
094: * Returns the character as special text.
095: */
096: public String getSpecialText() {
097: if (getUI() == null)
098: return null;
099:
100: return ((com.javelin.swinglets.plaf.SCharacterUI) getUI())
101: .getSpecialText(character);
102: }
103:
104: /**
105: * Is Character of this type.
106: */
107: public boolean equals(int character) {
108: return this .character == character;
109: }
110:
111: /**
112: * Do the two characters have the same character.
113: */
114: public boolean equals(Object object) {
115: if (object == null)
116: return false;
117: if (object == this )
118: return true;
119:
120: if (object instanceof SCharacter) {
121: if (((SCharacter) object).getCharacter() == character) {
122: return true;
123: }
124: }
125: return false;
126: }
127:
128: // PRIVATE ////////////////////////////////////////////////////
129:
130: private int character;
131: private static String[] text = new String[] { " ", "\n\n", "\n",
132: "\"", "&", "'", ">", "<" };
133:
134: }
|