src.com.ibm.as400.util.html.HTMLText Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jt400-jdk8 Show documentation
Show all versions of jt400-jdk8 Show documentation
The Open Source version of the IBM Toolbox for Java
///////////////////////////////////////////////////////////////////////////////
//
// JTOpen (IBM Toolbox for Java - OSS version)
//
// Filename: HTMLText.java
//
// The source code contained herein is licensed under the IBM Public License
// Version 1.0, which has been approved by the Open Source Initiative.
// Copyright (C) 1997-2001 International Business Machines Corporation and
// others. All rights reserved.
//
///////////////////////////////////////////////////////////////////////////////
package com.ibm.as400.util.html;
import com.ibm.as400.access.ExtendedIllegalArgumentException;
import com.ibm.as400.access.ExtendedIllegalStateException;
import com.ibm.as400.access.Trace;
import java.awt.Color;
import java.beans.PropertyChangeSupport;
import java.beans.PropertyChangeListener;
import java.beans.PropertyVetoException;
import java.beans.VetoableChangeSupport;
import java.beans.VetoableChangeListener;
import java.io.Serializable;
/**
* The HTMLText class encapsulates HTML text attributes.
*
* This example creates an HTMLText object and sets its attributes.
*
*
* HTMLText text = new HTMLText("IBM");
* text.setBold(true);
* text.setSize(3);
* System.out.println(text.getTag());
*
*
* Here is the output of the tag:
*
* <font size="3"><b>IBM</b></font>
*
*
* Here is the output of calling getFOTag():
*
* <fo:block font-size='9pt' font-weight='bold'>IBM</fo:block>
*
*
* HTMLText objects generate the following events:
*
* - PropertyChangeEvent
*
- VetoableChangeEvent
*
**/
public class HTMLText extends HTMLTagAttributes implements HTMLConstants, Serializable // @Z1C
{
private static final String copyright = "Copyright (C) 1997-2001 International Business Machines Corporation and others.";
static final long serialVersionUID = 8640694441108878894L;
private String text_; // The text to tag.
private String alignment_; // The horizontal alignment. "left", "center", "right" or "justify".
private Color color_; // The font color attribute.
private int size_ = 0; // The font size attribute.
private boolean bold_ = false; // The bold style attribute.
private boolean fixed_ = false; // The fixed pitch style attribute.
private boolean italic_ = false; // The italic style attribute.
private boolean underscore_ = false; // The underline style attribute.
private String lang_; // The primary language used to display the tags contents. //$B1A
private String dir_; // The direction of the text interpretation. //$B1A
private boolean useFO_; // Indicates if XSL-FO tags are outputted. //@D1A
transient private VetoableChangeSupport vetos_; //@CRS
/**
* Constructs a default HTMLText object.
**/
public HTMLText()
{
super();
}
/**
* Constructs an HTMLText object with the specified text.
* @param text The text.
**/
public HTMLText(String text)
{
this();
try
{
setText(text);
}
catch (PropertyVetoException e)
{ /* do nothing */
}
}
/**
* Adds the VetoableChangeListener. The specified VetoableChangeListener's vetoableChange
* method is called each time the value of any constrained property is changed.
* @see #removeVetoableChangeListener
* @param listener The VetoableChangeListener.
**/
public void addVetoableChangeListener(VetoableChangeListener listener)
{
if (listener == null)
throw new NullPointerException("listener");
if (vetos_ == null) vetos_ = new VetoableChangeSupport(this); //@CRS
vetos_.addVetoableChangeListener(listener);
}
/**
* Returns the horizontal alignment.
* @return The horizontal alignment. One of the following constants
* defined in HTMLConstants: LEFT, CENTER, RIGHT, or JUSTIFY.
* @see com.ibm.as400.util.html.HTMLConstants
**/
public String getAlignment()
{
return alignment_;
}
/**
* Returns the color used to paint the text.
* @return The Color object representing the text color.
**/
public Color getColor() // @A1
{
return color_;
}
/**
* Returns the direction of the text interpretation.
* @return The direction of the text.
**/
public String getDirection() //$B1A
{
return dir_;
}
/**
* Returns the direction attribute tag.
* @return The direction tag.
**/
String getDirectionAttributeTag() //$B1A
{
if(useFO_ ) //@D1A
{ //@D1A
if((dir_ != null) && (dir_.length()>0)) //@D1A
{ //@D1A
if(dir_.equals(HTMLConstants.RTL)) //@D1A
return " writing-mode='rl'"; //@D1A
else //@D1A
return " writing-mode='lr'"; //@D1A
} //@D1A
else //@D1A
return ""; //@D1A
} //@D1A
else //@D1A
{ //@D1A
//@C1D
if ((dir_ != null) && (dir_.length() > 0))
return " dir=\"" + dir_ + "\"";
else
return "";
} //@D1A
}
/**
* Returns the end text alignment tag.
* @return The end text alignment tag or an empty String
* if the alignment is not set.
**/
String getEndTextAlignmentTag()
{
if (alignment_ != null)
return("