📄 font.java
字号:
/**
* Font.Object
*/
package HAB.object;
import HAB.HcBean.HalcyonAppletBeanInterface;
import HAB.HcBean.HpException;
import java.io.Serializable;
import java.lang.Cloneable;
public class font implements
Cloneable,
Serializable,
HAB.HcBean.HalcyonAppletBeanInterface
{
boolean bold = false;
boolean italic = false;
public String name = "MS Sans Serif";//you fei.
public float size = 11.0f;//you fei.
public short style = 0;
boolean strikethrough = false;
boolean underline = false;
public short weight = 400;
private java.awt.Component target;
private short charset;
public font() {}
public font(java.awt.Font f) {
this(f.getName(),(short)f.getStyle(),(float)f.getSize());
}
public font(String name, short style, float size) {
this(name,style,size,false,false);
}
public font(String name, short style, float size,boolean strikethru, boolean underline) {
this.name = name;
this.style = style;
this.size = size;
this.strikethrough = strikethru;
this.underline = underline;
}
public void setTarget(java.awt.Component comp) {
target = comp;
target.setFont(_getFont());//new java.awt.Font("Dialog", java.awt.Font.PLAIN, 11));
}
public java.awt.Font _getFont() {
String namefont = (name.substring(3)).trim();
if (namefont.equalsIgnoreCase("Abadi MT Condensed") || namefont.equalsIgnoreCase("Arial")
|| namefont.equalsIgnoreCase("News Gothic MT") || namefont.equalsIgnoreCase("Tahoma")
|| namefont.equalsIgnoreCase("Verdana") || namefont.equalsIgnoreCase("Arial Black")
|| namefont.equalsIgnoreCase("Century Gothic")) {
//Dialog 1.
//1 Abadi MT Condensed
//3 Arial
//4 Arial Black ()
//23 News Gothic MT
//28 Tahoma
//31 Verdana
//7 Century Gothic
return new java.awt.Font("Dialog",style,(int)size);
} else if (namefont.equalsIgnoreCase("Ms Sans Serif") || namefont.equalsIgnoreCase("Comic Sans Ms")
|| namefont.equalsIgnoreCase("Fixedsys") || namefont.equalsIgnoreCase("Terminal")) {
//SansSerif 2.
//Ms Sans Serif 21.
//Comic Sans Ms 8
//Fixedsys 13.
//Terminal 29.
return new java.awt.Font("SansSerif",style,(int)size);
} else if (namefont.equalsIgnoreCase("Ms Serif") ||namefont.equalsIgnoreCase("Book Antigua")
|| namefont.equalsIgnoreCase("Calisto Mt")) {
//Serif 3.
//Ms Serif 22.
//Book Antigua 5.
//Calisto Mt 6.
return new java.awt.Font("Serif",style,(int)size);
} else if (namefont.equalsIgnoreCase("Courier New") || namefont.equalsIgnoreCase("Lucida Sans Unicode")) {
//Monospacted 4.
//12 Courier New
//18 Lucida Sans Unicode
return new java.awt.Font("Monospacted",style,(int)size);
} else if (namefont.equalsIgnoreCase("Copperplate Gothic Bold") || namefont.equalsIgnoreCase("Copperplate Gothic Light")
|| namefont.equalsIgnoreCase("Impact")) {
//Helvetica 5.
//Copperplate Gothic Bold 9.
//Copperplate Gothic Light 10.
//Impact 14.
return new java.awt.Font("Helvetica",style,(int)size);
} else if (namefont.equalsIgnoreCase("Times New Roman") || namefont.equalsIgnoreCase("Lucida HandWriting")
|| namefont.equalsIgnoreCase("Lucida Sans") || namefont.equalsIgnoreCase("Modern")
|| namefont.equalsIgnoreCase("OCR A Extended") || namefont.equalsIgnoreCase("System")) {
//TimesRoman 6.
//Times New Roman 30.
//Lucida HandWriting 16.
//Lucida Sans 17.
//Modern 20.
//OCR A Extended 24.
//System 27.
return new java.awt.Font("TimersRoman",style,(int)size);
} else if (namefont.equalsIgnoreCase("Courier")) {
//Courier 7.
//Courier 11.
return new java.awt.Font("Courier",style,(int)size);
} else if (namefont.equalsIgnoreCase("Abadi MT Condensed Light")) {
//DialogInput 8./4.
//Abadi MT Condensed Light 2
return new java.awt.Font("DialogInput",style,(int)size);
} else if (namefont.equalsIgnoreCase("Webdings") || namefont.equalsIgnoreCase("Windings")
|| namefont.equalsIgnoreCase("Windings2") || namefont.equalsIgnoreCase("Windings3")
|| namefont.equalsIgnoreCase("Symbol") || namefont.equalsIgnoreCase("Marlett")
|| namefont.equalsIgnoreCase("Kingsoft Phonetic Plain")
|| namefont.equalsIgnoreCase("Small Fonts")) {
//Marlett 19.
//Symbol 26.
//Webdings 32.
//Windings 33
//Windings2 34
//Windings3 35
//Kingsoft Phonetic Plain 15.
//Small Fonts 25.
return new java.awt.Font("ZapfDingbats",style,(int)size);
}
//========================================================
/*if(name.trim().equalsIgnoreCase("T Timers New Roman")){
return new java.awt.Font("TimesRoman",style,(int)size);
}else if(name.trim().equalsIgnoreCase("Courier")){
return new java.awt.Font("Courier",style,(int)size);
}else if(name.trim().equalsIgnoreCase("T Symbol")){
return new java.awt.Font("Symbol",style,(int)size);
}else if(name.trim().equalsIgnoreCase("T Tahoma")){
return new java.awt.Font("Helvetica",style,(int)size);
}*/
return new java.awt.Font(name,style,(int)size);
}
public void _setStyle(short newStyle) {
style = newStyle;
switch(style) {
case 0:
bold = false;
italic = false;
weight = 400;
break;
case 1:
bold = true;
italic = false;
weight = 700;
break;
case 2:
bold = false;
italic = true;
weight = 400;
break;
case 3:
bold = true;
italic = true;
weight = 700;
break;
}
}
public short _getStyle() {
return style;
}
public void _setBold(boolean newbold)
{
if (bold) {
if(!newbold) style -= 1;
}else {
if(newbold) style += 1;
}
bold = newbold;
if (target != null)
{
target.setFont(_getFont());
target.repaint();
}
}
public boolean _getBold()
{
return bold;
}
public void _setItalic(boolean newitalic)
{
if (italic) {
if(!newitalic) style -= 2;
}else {
if (newitalic) style += 2;
}
italic = newitalic;
if (target != null)
{
target.setFont(_getFont());
target.repaint();
}
}
public boolean _getItalic() {
return italic;
}
/**
* Must check the newname is corret or not! HsuJijun
*/
public void _setName(String newname)
{
name = newname;
if (target != null)
{
target.setFont(_getFont());
target.repaint();
}
}
public String _getName()
{
return name;
}
public void _setDeft(String newdeft)
{
_setName(newdeft);
}
public String _getDeft()
{
return name;
}
public void _setSize(float newsize)
{
size = newsize+3;
if (target != null)
{
target.setFont(_getFont());
target.repaint();
}
}
public float _getSize()
{
return size-3;
}
public void _setStrikethrough(boolean newstrthr)
{
strikethrough = newstrthr;
if (target != null)
{
target.setFont(_getFont());
target.repaint();
}
}
public boolean _getStrikethrough()
{
return strikethrough;
}
public void _setUnderline(boolean newunderline)
{
underline = newunderline;
if (target != null)
{
target.setFont(_getFont());
target.repaint();
}
}
public boolean _getUnderline()
{
return underline;
}
public void _setWeight(short newweight)throws HpException
{
if(newweight<0 || newweight>1000)
throw new HpException(6,"Overflow");
weight = newweight;
switch(weight) {
case 400:
_setBold(false);
break;
case 700:
_setBold(true);
break;
}
if (target != null) target.repaint();
}
public short _getWeight()
{
return weight;
}
public void _setCharset( short value)
{
this.charset=value;
}
public short _getCharset()
{
return this.charset;
}
public final boolean equals( font second) {
if (second==null) return false;
return (second._getName().equals(name) && second._getSize() == _getSize()
&& second._getStyle()==style && second._getStrikethrough()==strikethrough
&& second._getUnderline()==underline && second._getWeight()==weight);
}
public final void copy( font second) {
this.name = second._getName();
this._setSize(second._getSize());
this.bold = second._getBold();
this.italic = second._getItalic();
this.strikethrough = second._getStrikethrough();
this.underline = second._getUnderline();
this.weight = second._getWeight();
this.style = second._getStyle();
this.charset=second._getCharset();
}
public synchronized Object clone() {
try {
font ft = (font) super.clone();
return ft;
}
catch (CloneNotSupportedException e)
{
throw new InternalError();
}
}
private static java.beans.BeanInfo bi = null;
public java.beans.BeanInfo getBeanInfo()
{
if (bi == null)
{
bi =(java.beans.BeanInfo) new HAB.object.fontBeanInfo() ;
}
return bi;
}
private void writeObject(java.io.ObjectOutputStream s)
throws java.io.IOException
{
s.defaultWriteObject();
}
private void readObject(java.io.ObjectInputStream s)
throws java.lang.ClassNotFoundException,
java.io.IOException
{
s.defaultReadObject();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -