📄 label.java
字号:
/**
* $Id:Label.java $
*
* Copyright 2004 ~ 2005 JingFei International Cooperation LTD. All rights reserved.
*
*/
package com.jfimagine.jfgraph.shape.base;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Color;
import java.awt.geom.Rectangle2D;
import java.awt.geom.AffineTransform;
import java.awt.Font;
import java.awt.font.FontRenderContext;
import java.awt.font.TextLayout;
import java.awt.BasicStroke;
import java.awt.image.BufferedImage;
import java.awt.RenderingHints;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import com.jfimagine.jfdom.Document;
import com.jfimagine.jfdom.Element;
import com.jfimagine.utils.commonutil.CommonUtil;
import com.jfimagine.utils.commonutil.Base64;
import com.jfimagine.jfgraph.shape.base.AbstractObject;
import com.jfimagine.jfgraph.shape.base.ShapeConst;
import com.jfimagine.jfgraph.shape.base.JFVersion;
import com.jfimagine.jfgraph.geom.GeomConst;
import com.jfimagine.jfgraph.geom.JFPoint;
import com.jfimagine.jfgraph.geom.Rect;
import com.jfimagine.jfgraph.shape.decorate.FontFormat;
/**
* Label Class. A label is to label the text of a shape.
*
* @author CookieMaker
*
* @version $Revision: 1.00 $
*/
public class Label extends AbstractObject {
/**
* A XML string tag represents a jflabel
*/
public static final String XML_LABEL ="Label";
/**
* A XML string tag represents the x coordinate offset of this label
*/
public static final String XML_XOFFSET ="xOffset";
/**
* A XML string tag represents the y coordinate offset of this label
*/
public static final String XML_YOFFSET ="yOffset";
/**
* A XML string tag represents the text of this label
*/
public static final String XML_TEXT ="text";
/**
* A XML string tag represents the if visible of this label
*/
public static final String XML_VISIBLE ="visible";
/**
* A XML string tag represents the if movable of this label
*/
public static final String XML_MOVABLE ="movable";
/**
* A point for x,y coordinates of the left-top corner of the label.
*/
protected JFPoint m_labelPoint =new JFPoint();
/**
* Label text.
*/
protected String m_text ="";
/**
* Label visible or invisible.
*/
protected boolean m_visible =true;
/**
* Label movable. e.g. Not movable in JFLabelLine.
*/
protected boolean m_movable =true;
/**
* A parent object of this label.
*/
protected AbstractObject m_parent;
/**
* A font format of this label.
*/
protected Font m_font =new Font(FontFormat.FONTNAME_DEFAULT, Font.PLAIN, FontFormat.FONTSIZE_DEFAULT);
/**
* Constructor for Label
*/
public Label(){
setObjectType(ShapeConst.SHAPETYPE_LABEL);
setXMLTag(XML_LABEL);
}
/**
* Constructor for Label
*/
public Label(double x,double y){
setObjectType(ShapeConst.SHAPETYPE_LABEL);
setXMLTag(XML_LABEL);
m_labelPoint.setX(x);
m_labelPoint.setY(y);
}
/**
* Constructor for Label
*/
public Label(JFPoint pnt){
setObjectType(ShapeConst.SHAPETYPE_LABEL);
setXMLTag(XML_LABEL);
m_labelPoint.setValue(pnt);
}
/**
* Get parent object of this label.
* @return parent object.
*/
public AbstractObject getParent(){
return m_parent;
}
/**
* Set parent object of this label.
* @param A new parent object.
*/
public void setParent(AbstractObject obj){
m_parent =obj;
}
/**
* Get the x offset of current label. <br>
*
* @return The x offset of current label.
*
*/
public double getXOffset(){
return m_labelPoint.getX();
}
/**
* Set the x offset of current label. <br>
*
* @param xOffset The x offset of current label.
*
* @return No return.
*
*/
public void setXOffset(double xOffset){
m_labelPoint.setX(xOffset);
}
/**
* Get the y offset of current label. <br>
*
* @return The y offset of current label.
*
*/
public double getYOffset(){
return m_labelPoint.getY();
}
/**
* Set the y offset of current label. <br>
*
* @param yOffset The y offset of current label.
*
*/
public void setYOffset(double yOffset){
m_labelPoint.setY(yOffset);
}
/**
* Get the actual draw point of this label.
*
* @param g A graphics context used to measure.
* @param useStrokeAndFill If use stroke and fill drawing format
* @return The actual draw point.
*
*/
public JFPoint getDrawPoint(Graphics g,boolean useStrokeAndFill){
if (m_text==null || m_text.length()==0)
return new JFPoint();
Rectangle2D bounds =getBounds2D(g);
double zoom =getZoomScale();
float x =(float)((m_labelPoint.getX() * zoom -bounds.getWidth()/2) );
float y =(float)((m_labelPoint.getY())* zoom);
if (useStrokeAndFill)
y = (float)(y-bounds.getHeight());
return new JFPoint(x,y);
}
/**
* Get the point of current label. <br>
*
* @return The position of current label.
*
*/
public JFPoint getLabelPoint(){
return m_labelPoint;
}
/**
* Set the point of current label. <br>
*
* @param pnt The point of current label.
*
*/
public void setLabelPoint(JFPoint pnt){
m_labelPoint.setValue(pnt);
}
/**
* Get if visible of current label. <br>
*
* @return True if visible, false otherwise.
*
*/
public boolean getVisible(){
return m_visible;
}
/**
* Set the visible of current label. <br>
*
* @param visible A new visible state of current label.
*
*/
public void setVisible(boolean visible){
m_visible =visible;
}
/**
* Get if movable of current label. <br>
*
* @return True if movable, false otherwise.
*
*/
public boolean getMovable(){
return m_movable;
}
/**
* Set the movable of current label. <br>
*
* @param movable A new movable state of current label.
*
*/
public void setMovable(boolean movable){
m_movable =movable;
}
/**
* Get the text of current label. <br>
*
* @return The text of current label.
*
*/
public String getText(){
return m_text;
}
/**
* Set the text of current label. <br>
*
* @param text The text of current label.
*
*/
public void setText(String text){
if (text==null) text="";
m_text =text;
}
/**
* Get the font of current label. <br>
*
* @return The font of current label.
*
*/
public Font getFont(){
return m_font;
}
/**
* Get a zoomed font of current label. <br>
*
* @return A new zoomed font of current label.
*
*/
public Font getZoomedFont(){
double zoom =getZoomScale();
if (zoom==1.0)
return m_font;
else
return new Font(m_font.getFontName(), m_font.getStyle(), (int)(m_font.getSize() * zoom));
}
/**
* Set the font of current label. <br>
*
* @param font The font of current label.
*
*/
public void setFont(Font aFont){
if (aFont==null)
m_font =new Font(FontFormat.FONTNAME_DEFAULT, Font.PLAIN, 12);
else
m_font =new Font(aFont.getFontName(), aFont.getStyle(), aFont.getSize());
}
/**
* Set the value of current label. <br>
*
* @param aLabel A new label value.
*
*/
public void setValue(Label aLabel){
if (aLabel!=null){
m_labelPoint.setValue(aLabel.m_labelPoint);
m_text =aLabel.m_text;
m_visible =aLabel.m_visible;
m_movable =aLabel.m_movable;
m_font =new Font(aLabel.m_font.getFontName(),aLabel.m_font.getStyle(),aLabel.m_font.getSize());
}
}
/**
* Get the bounds of this label.
*
* @return The bounds rectangle of this label.
*
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -