From e4a68daca93273f2e86c2024321252387067074b Mon Sep 17 00:00:00 2001 From: PanLi320 <854954082@qq.com> Date: Fri, 6 Jan 2017 17:51:29 +0800 Subject: [PATCH] =?UTF-8?q?REPORT-576=20tab=20button=E8=BE=93=E5=85=A5?= =?UTF-8?q?=E6=A0=87=E9=A2=98=E5=86=85=E5=AE=B9=E8=87=AA=E5=8A=A8=E5=8F=98?= =?UTF-8?q?=E5=AE=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../creator/cardlayout/XCardAddButton.java | 4 +- .../creator/cardlayout/XCardSwitchButton.java | 63 ++++++++++++++++--- 2 files changed, 56 insertions(+), 11 deletions(-) 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 83427316a5..441b56575f 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,6 +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"); @@ -139,8 +140,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..ca4f7f1f10 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; /** * @@ -62,6 +61,9 @@ public class XCardSwitchButton extends XButton { // tab按钮里的字体因为按钮内部的布局看起来比正常的要小,加个调整量 private static final int FONT_SIZE_ADJUST = 2; + private static final int SIDE_OFFSET = 57; + private static final int HEIGHT_OFFSET = 25; + private XWCardLayout cardLayout; private XWCardTagLayout tagLayout; @@ -155,19 +157,18 @@ public class XCardSwitchButton extends XButton { //将当前tab按钮改为选中状态 changeButtonState(index); - + // 切换到当前tab按钮对应的tabFitLayout XWTabFitLayout tabFitLayout = (XWTabFitLayout) cardLayout.getComponent(index); tabFitLayout.setxCardSwitchButton(this); selectionModel.setSelectedCreator(tabFitLayout); - + if (editingMouseListener.stopEditing()) { ComponentAdapter adapter = AdapterBus.getComponentAdapter(designer, this); editingMouseListener.startEditing(this, adapter.getDesignerEditor(), adapter); } - } //删除card,同时修改其他switchbutton和tabfit的index @@ -337,5 +338,49 @@ public class XCardSwitchButton extends XButton { public XLayoutContainer getTopLayout() { return this.getBackupParent().getTopLayout(); } - + + 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(); + } } \ No newline at end of file