diff --git a/designer_form/src/com/fr/design/designer/creator/XLayoutContainer.java b/designer_form/src/com/fr/design/designer/creator/XLayoutContainer.java index 47f4270a5e..381b16f87d 100644 --- a/designer_form/src/com/fr/design/designer/creator/XLayoutContainer.java +++ b/designer_form/src/com/fr/design/designer/creator/XLayoutContainer.java @@ -81,6 +81,27 @@ public abstract class XLayoutContainer extends XBorderStyleWidgetCreator impleme }; } + /** + * 控件名属性 + * @return + * @throws IntrospectionException + */ + public CRPropertyDescriptor createWidgetNameDescriptor() throws IntrospectionException { + return new CRPropertyDescriptor("widgetName", this.data.getClass()).setI18NName(Inter + .getLocText("FR-Designer_Form-Widget_Name")); + } + + /** + * 边距属性 + * @return + * @throws IntrospectionException + */ + public CRPropertyDescriptor createMarginDescriptor() throws IntrospectionException { + return new CRPropertyDescriptor("margin", this.data.getClass()).setEditorClass(PaddingMarginEditor.class) + .setI18NName(Inter.getLocText("FR-Designer_Layout-Padding")) + .putKeyValue(XCreatorConstants.PROPERTY_CATEGORY, "Advanced"); + } + /** * 返回对应的wlayout * @return wlayout控件 diff --git a/designer_form/src/com/fr/design/designer/creator/cardlayout/XCardAddButton.java b/designer_form/src/com/fr/design/designer/creator/cardlayout/XCardAddButton.java index c16d4de3f8..2c6a0036b5 100644 --- a/designer_form/src/com/fr/design/designer/creator/cardlayout/XCardAddButton.java +++ b/designer_form/src/com/fr/design/designer/creator/cardlayout/XCardAddButton.java @@ -31,7 +31,7 @@ public class XCardAddButton extends XButton{ private static final int START_INDEX = 3; private static final int INDEX = 0; - + private static final int DEFAULT_BUTTON_WIDTH = 80; private static Icon ADD_ICON = BaseUtils.readIcon("/com/fr/design/form/images/add.png"); private Icon addIcon = ADD_ICON; @@ -139,8 +139,7 @@ public class XCardAddButton extends XButton{ //新增tab private void addTab(int index){ Dimension dimension = new Dimension(); - XCardSwitchButton button = (XCardSwitchButton) this.tagLayout.getComponent(INDEX); - dimension.width = button.getWidth(); + dimension.width = DEFAULT_BUTTON_WIDTH; String cardLayoutName = cardLayout.toData().getWidgetName(); CardSwitchButton titleButton = new CardSwitchButton(index,cardLayoutName); diff --git a/designer_form/src/com/fr/design/designer/creator/cardlayout/XCardSwitchButton.java b/designer_form/src/com/fr/design/designer/creator/cardlayout/XCardSwitchButton.java index bcd38dbf2a..c95b2bbd33 100644 --- a/designer_form/src/com/fr/design/designer/creator/cardlayout/XCardSwitchButton.java +++ b/designer_form/src/com/fr/design/designer/creator/cardlayout/XCardSwitchButton.java @@ -3,13 +3,11 @@ */ package com.fr.design.designer.creator.cardlayout; -import java.awt.Color; -import java.awt.Dimension; -import java.awt.Graphics; -import java.awt.Graphics2D; -import java.awt.Point; +import java.awt.*; import java.awt.event.MouseEvent; import java.awt.geom.Rectangle2D; +import java.util.HashMap; +import java.util.Map; import javax.swing.*; @@ -34,6 +32,7 @@ import com.fr.form.ui.container.cardlayout.WTabFitLayout; import com.fr.general.Background; import com.fr.general.FRFont; import com.fr.general.Inter; +import sun.font.FontDesignMetrics; /** * @@ -338,4 +337,48 @@ public class XCardSwitchButton extends XButton { return this.getBackupParent().getTopLayout(); } -} \ No newline at end of file + public void setTabsAndAdjust() { + if (this.tagLayout == null) { + return; + } + int tabLength = this.tagLayout.getComponentCount(); + Map cardWidth = new HashMap<>(); + Map cardHeight = new HashMap<>(); + for (int i = 0; i < tabLength; i++) { + XCardSwitchButton temp = (XCardSwitchButton) this.tagLayout.getComponent(i); + CardSwitchButton tempCard = (CardSwitchButton) temp.toData(); + String tempText = tempCard.getText(); + Font f = ((CardSwitchButton)this.toData()).getFont(); + FontMetrics fm = FontDesignMetrics.getMetrics(f); + cardWidth.put(i,fm.stringWidth(tempText)); + cardHeight.put(i,fm.getHeight()); + } + adjustTabs(tabLength, cardWidth, cardHeight); + } + + public void adjustTabs(int tabLength, Map width, Map height) { + int tempX = 0; + for (int i = 0; i < tabLength; i++) { + Rectangle rectangle = this.tagLayout.getComponent(i).getBounds(); + Integer cardWidth = width.get(i) + SIDE_OFFSET; + Integer cardHeight = height.get(i) + HEIGHT_OFFSET; + rectangle.setSize(cardWidth, cardHeight); + rectangle.setBounds(tempX, 0, cardWidth, cardHeight); + tempX += cardWidth; + this.tagLayout.getComponent(i).setBounds(rectangle); + Dimension dimension = new Dimension(); + dimension.setSize(cardWidth, cardHeight); + this.getContentLabel().setSize(dimension); + this.setSize(dimension); + XCardSwitchButton temp = (XCardSwitchButton) this.tagLayout.getComponent(i); + CardSwitchButton tempCard = (CardSwitchButton) temp.toData(); + tempCard.setDefaultWidth(cardWidth); + } + } + + @Override + public void doLayout() { + super.doLayout(); + setTabsAndAdjust(); + } +} diff --git a/designer_form/src/com/fr/design/designer/creator/cardlayout/XWTabFitLayout.java b/designer_form/src/com/fr/design/designer/creator/cardlayout/XWTabFitLayout.java index 775d4c38c8..75816c9bbd 100644 --- a/designer_form/src/com/fr/design/designer/creator/cardlayout/XWTabFitLayout.java +++ b/designer_form/src/com/fr/design/designer/creator/cardlayout/XWTabFitLayout.java @@ -42,7 +42,6 @@ public class XWTabFitLayout extends XWFitLayout { // tab布局在拖拽导致的缩放里(含间隔时),如果拖拽宽高大于组件宽高,会导致调整的时候找不到原来的组件 // 这里先将拖拽之前的宽高先做备份 public static final Color NORMAL_GRAL = new Color(236,236,236); - public static final Color CHOOSED_GRAL = new Color(222,222,222); private Dimension referDim; private Background initialBackground; private Background overBackground; @@ -105,7 +104,7 @@ public class XWTabFitLayout extends XWFitLayout { public CRPropertyDescriptor[] supportedDescriptor() throws IntrospectionException { checkButonType(); CRPropertyDescriptor[] crp = ((WTabFitLayout) data).isCustomStyle() ? getisCustomStyle() : getisnotCustomStyle(); - return ArrayUtils.addAll(super.supportedDescriptor(), crp); + return ArrayUtils.addAll(defaultDescriptor(), crp); } protected CRPropertyDescriptor[] getisCustomStyle() throws IntrospectionException { @@ -195,6 +194,14 @@ public class XWTabFitLayout extends XWFitLayout { return crPropertyDescriptors[i]; } + protected CRPropertyDescriptor[] defaultDescriptor() throws IntrospectionException { + CRPropertyDescriptor[] crPropertyDescriptors = { + super.createWidgetNameDescriptor(), + super.createMarginDescriptor() + }; + return crPropertyDescriptors; + } + private void checkButonType() { if (this.xCardSwitchButton == null) { return;