You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
149 lines
6.4 KiB
149 lines
6.4 KiB
/* |
|
* Copyright(c) 2001-2010, FineReport Inc, All Rights Reserved. |
|
*/ |
|
package com.fr.design.designer.creator; |
|
|
|
import com.fr.base.BaseUtils; |
|
import com.fr.base.Style; |
|
import com.fr.base.background.ImageBackground; |
|
import com.fr.design.border.UIRoundedBorder; |
|
import com.fr.design.form.util.FontTransformUtil; |
|
import com.fr.design.form.util.XCreatorConstants; |
|
import com.fr.design.gui.ilable.UILabel; |
|
import com.fr.design.mainframe.widget.editors.FontEditor; |
|
import com.fr.design.mainframe.widget.editors.ItemCellEditor; |
|
import com.fr.design.mainframe.widget.editors.WidgetValueEditor; |
|
import com.fr.design.mainframe.widget.renderer.FontCellRenderer; |
|
import com.fr.design.mainframe.widget.renderer.LabelHorizontalAlignmentRenderer; |
|
import com.fr.form.ui.Label; |
|
import com.fr.form.ui.container.WParameterLayout; |
|
|
|
import com.fr.general.Background; |
|
import com.fr.stable.ArrayUtils; |
|
import com.fr.stable.Constants; |
|
import com.fr.stable.core.PropertyChangeAdapter; |
|
|
|
import javax.swing.*; |
|
import java.awt.*; |
|
import java.awt.geom.Rectangle2D; |
|
import java.beans.IntrospectionException; |
|
|
|
/** |
|
* @author richer |
|
* @since 6.5.3 |
|
*/ |
|
public class XLabel extends XWidgetCreator { |
|
|
|
private int cornerSize = 15; |
|
private boolean enabledBackgroundPainting = true; |
|
|
|
public XLabel(Label widget, Dimension initSize) { |
|
super(widget, initSize); |
|
} |
|
|
|
public void setEnabledBackgroundPainting(boolean enable) { |
|
this.enabledBackgroundPainting = enable; |
|
} |
|
|
|
/** |
|
* 生成creator对应的控件widget |
|
* |
|
* @return 控件widget |
|
*/ |
|
public Label toData() { |
|
return (Label) data; |
|
} |
|
|
|
/** |
|
* 返回组件属性值 |
|
* |
|
* @return 返回组件属性值 |
|
* @throws IntrospectionException 异常 |
|
*/ |
|
@Override |
|
public CRPropertyDescriptor[] supportedDescriptor() throws IntrospectionException { |
|
return (CRPropertyDescriptor[]) ArrayUtils.addAll(super.supportedDescriptor(), |
|
new CRPropertyDescriptor[]{ |
|
new CRPropertyDescriptor("widgetValue", this.data.getClass()).setI18NName( |
|
com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Widget_Value")).setEditorClass( |
|
WidgetValueEditor.class).putKeyValue(XCreatorConstants.PROPERTY_CATEGORY, "Fine-Design_Basic_Advanced") |
|
.setPropertyChangeListener(new PropertyChangeAdapter() { |
|
|
|
@Override |
|
public void propertyChange() { |
|
XCreator parent = (XCreator) XLabel.this.getParent(); |
|
((WParameterLayout) parent.toData()).refreshTagList(); |
|
} |
|
}), |
|
new CRPropertyDescriptor("wrap", this.data.getClass()).setI18NName( |
|
com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_StyleAlignment_Wrap_Text")).putKeyValue( |
|
XCreatorConstants.PROPERTY_CATEGORY, "Fine-Design_Basic_Advanced"), |
|
new CRPropertyDescriptor("verticalCenter", this.data.getClass()).setI18NName( |
|
com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Page_Setup_Vertically")).putKeyValue( |
|
XCreatorConstants.PROPERTY_CATEGORY, "Fine-Design_Basic_Advanced"), |
|
new CRPropertyDescriptor("textalign", this.data.getClass()).setI18NName( |
|
com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Alignment-Style")).setEditorClass(ItemCellEditor.class) |
|
.setRendererClass(LabelHorizontalAlignmentRenderer.class).putKeyValue( |
|
XCreatorConstants.PROPERTY_CATEGORY, "Fine-Design_Basic_Advanced"), |
|
new CRPropertyDescriptor("font", this.data.getClass()).setI18NName(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Font")) |
|
.setEditorClass(FontEditor.class).setRendererClass(FontCellRenderer.class).putKeyValue( |
|
XCreatorConstants.PROPERTY_CATEGORY, "Fine-Design_Basic_Advanced")}); |
|
} |
|
|
|
@Override |
|
public void paintComponent(Graphics g) { |
|
super.paintComponent(g); |
|
Label label = (Label) data; |
|
Dimension size = this.getSize(); |
|
//先画背景,再画标题 |
|
Background background = label.getBackground(); |
|
if (background != null && enabledBackgroundPainting) { |
|
Graphics2D g2d = (Graphics2D) g; |
|
Composite oldComposite = g2d.getComposite(); |
|
g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, label.getBackgroundOpacity())); |
|
background.paint(g, new Rectangle2D.Double(0, 0, size.getWidth(), size.getHeight())); |
|
g2d.setComposite(oldComposite); |
|
} |
|
if (label.getWidgetValue() != null) { |
|
Graphics2D g2d = (Graphics2D) g.create(); |
|
|
|
Background inset = label.getInsetImage(); |
|
Image insetImage = inset instanceof ImageBackground ? ((ImageBackground) inset).getImage() : null; |
|
|
|
BaseUtils.drawStringStyleInRotation(g2d, |
|
this.getWidth(), this.getHeight(), |
|
label.getWidgetValue().toString(), |
|
Style.getInstance(label.getFont()) |
|
.deriveHorizontalAlignment(label.getTextalign()) |
|
.deriveVerticalAlignment(label.isVerticalCenter() ? SwingConstants.CENTER : SwingConstants.TOP) |
|
.deriveTextStyle(label.isWrap() ? Style.TEXTSTYLE_WRAPTEXT : Style.TEXTSTYLE_SINGLELINE), |
|
insetImage, label.getInsetImagePadding(), label.isInsetRelativeTextLeft(), label.isInsetRelativeTextRight(), |
|
FontTransformUtil.getDesignerFontResolution()); |
|
|
|
} |
|
} |
|
|
|
@Override |
|
protected JComponent initEditor() { |
|
if (editor == null) { |
|
editor = new UILabel(); |
|
} |
|
return editor; |
|
} |
|
|
|
@Override |
|
protected void initXCreatorProperties() { |
|
super.initXCreatorProperties(); |
|
if (toData().getBorder() != Constants.LINE_NONE) { |
|
this.setBorder(new UIRoundedBorder(toData().getBorder(), toData().getColor(), toData().isCorner() ? cornerSize : 0)); |
|
} else { |
|
this.setBorder(DEFALUTBORDER); |
|
} |
|
} |
|
|
|
@Override |
|
protected String getIconName() { |
|
return "label_16.png"; |
|
} |
|
|
|
}
|
|
|