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 3d52b2beff..a2b8b05ba1 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 @@ -1,7 +1,6 @@ package com.fr.design.designer.creator.cardlayout; import com.fr.base.BaseUtils; -import com.fr.base.background.ColorBackground; import com.fr.design.designer.beans.AdapterBus; import com.fr.design.designer.beans.ComponentAdapter; import com.fr.design.designer.beans.models.SelectionModel; @@ -151,9 +150,7 @@ public class XCardAddButton extends XButton{ CardSwitchButton titleButton = new CardSwitchButton(index,cardLayoutName); //设置标题 titleButton.setText(getTabTitleName()); - titleButton.setInitialBackground(ColorBackground.getInstance(Color.WHITE)); XCardSwitchButton showButton = new XCardSwitchButton(titleButton, dimension, cardLayout, tagLayout); - titleButton.setCustomStyle(true); titleButton.setShowButton(true); showButton.setBackupParent(tagLayout); this.tagLayout.setCurrentCard(titleButton); 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 099cc4330d..bdc2f533f0 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 @@ -5,7 +5,6 @@ package com.fr.design.designer.creator.cardlayout; import com.fr.base.BaseUtils; import com.fr.base.GraphHelper; -import com.fr.base.background.ColorBackground; import com.fr.design.designer.beans.AdapterBus; import com.fr.design.designer.beans.ComponentAdapter; import com.fr.design.designer.beans.models.SelectionModel; @@ -34,9 +33,19 @@ import com.fr.general.Inter; import com.fr.general.cardtag.TemplateStyle; import com.fr.stable.unit.PT; -import javax.swing.*; +import javax.swing.Action; +import javax.swing.Icon; +import javax.swing.JComponent; +import javax.swing.JOptionPane; +import javax.swing.JPopupMenu; +import javax.swing.SwingUtilities; import javax.swing.plaf.basic.BasicLabelUI; -import java.awt.*; +import java.awt.Color; +import java.awt.Dimension; +import java.awt.FontMetrics; +import java.awt.Graphics; +import java.awt.Graphics2D; +import java.awt.Point; import java.awt.event.MouseEvent; import java.awt.geom.Rectangle2D; import java.util.ArrayList; @@ -62,11 +71,8 @@ public class XCardSwitchButton extends XButton { private static final int MIN_SIZE = 1; // 删除按钮识别区域偏移量 - private static final int RIGHT_OFFSET = 15; - private static final int TOP_OFFSET = 15; - - //这边先不计算button的高度,涉及到layout那边的整体高度,先用之前的固定高度 - private static final int DEFAULT_BUTTON_HEIGHT = 36; + private static final int CLOSE_ICON_RIGHT_OFFSET = 15; + private static final int CLOSE_ICON_TOP_OFFSET = 15; // tab按钮里的字体因为按钮内部的布局看起来比正常的要小,加个调整量 private static final int FONT_SIZE_ADJUST = 2; @@ -74,13 +80,12 @@ public class XCardSwitchButton extends XButton { //文字竖排时用来计算文字大小 private static final int RESLUTION = 120; - private static final int DOTSLINESPACE = 6; private XWCardLayout cardLayout; private XWCardTagLayout tagLayout; private Background selectBackground; - private boolean isCustomStyle; + private UILabel label; private Icon closeIcon = MOUSE_CLOSE; @@ -101,14 +106,6 @@ public class XCardSwitchButton extends XButton { this.cardLayout = cardLayout; } - public boolean isCustomStyle() { - return isCustomStyle; - } - - public void setCustomStyle(boolean customStyle) { - isCustomStyle = customStyle; - } - public Background getSelectBackground() { return selectBackground; } @@ -157,8 +154,7 @@ public class XCardSwitchButton extends XButton { } //获取当前tab的index - XCardSwitchButton button = this; - CardSwitchButton currentButton = (CardSwitchButton) button.toData(); + CardSwitchButton currentButton = (CardSwitchButton) this.toData(); int index = currentButton.getIndex(); int maxIndex = cardLayout.getComponentCount() - 1; @@ -169,14 +165,13 @@ public class XCardSwitchButton extends XButton { deleteTabLayout(selectionModel, designer); return; } - deleteCard(button,index); - this.tagLayout.adjustComponentWidth(); + deleteCard(this, index); designer.fireTargetModified(); LayoutUtils.layoutRootContainer(designer.getRootComponent()); FormHierarchyTreePane.getInstance().refreshRoot(); return; } - + //将当前tab按钮改为选中状态 changeButtonState(index); @@ -222,7 +217,7 @@ public class XCardSwitchButton extends XButton { } //删除card,同时修改其他switchbutton和tabfit的index - private void deleteCard(XCardSwitchButton button,int index){ + private void deleteCard(XCardSwitchButton button, int index){ String titleName = button.getContentLabel().getText(); int value = JOptionPane.showConfirmDialog(null, Inter.getLocText("FR-Designer_ConfirmDialog_Content") + "“" + titleName + "”", Inter.getLocText("FR-Designer_ConfirmDialog_Title"), JOptionPane.YES_NO_OPTION); @@ -292,18 +287,18 @@ public class XCardSwitchButton extends XButton { int width = button.getWidth(); // 鼠标进入按钮右侧删除图标区域 - double recX = position.getX() + titlePoint.getX() + (width - RIGHT_OFFSET); - double recY = position.getY() + titlePoint.getY() + TOP_OFFSET; + double recX = position.getX() + titlePoint.getX() + (width - CLOSE_ICON_RIGHT_OFFSET); + double recY = position.getY() + titlePoint.getY() + CLOSE_ICON_TOP_OFFSET; - return (recX < ex && ex < recX + RIGHT_OFFSET && ey < recY && ey > position.getY()); + return (recX < ex && ex < recX + CLOSE_ICON_RIGHT_OFFSET && ey < recY && ey > position.getY()); } //将当前switchButton改为选中状态 - private void changeButtonState(int index){ - for(int i=0;i height - textHeight && i < verticalTextList.size()-1) { - textY -= 10; - paintDots(g2d, textY, (width - fm.stringWidth(paint_str)) / 2); - break; - } - } - }else{ - super.paint(g, c); - } - } - - public void paintDots(Graphics2D g2d, int startY, int startX){ - for (int i = 0; i < 3; i++) { - String paint_str = "."; - GraphHelper.drawString(g2d, paint_str, startX, startY); - startY += DOTSLINESPACE;// - startY += PT.pt2pix(0, RESLUTION); - } - } + public class CardSwitchBtnLabelUI extends BasicLabelUI { + private static final int DOT_COUNT = 3; + private static final String DOT = "."; + private static final int DOTS_LINESPACE = 6; + private static final int DOTS_HEIGHT = 10; + + @Override + public void paint(Graphics g, JComponent c) { + WCardTagLayout wCardTagLayout = (WCardTagLayout) tagLayout.toData(); + if (ComparatorUtils.equals(wCardTagLayout.getTextDirection(), WTabTextDirection.TEXT_VER_DIRECTION)) { + //绘制文本竖排展示 + paintVerticalText(g); + } else { + super.paint(g, c); + } + } + + private void paintVerticalText(Graphics g) { + Graphics2D g2d = (Graphics2D) g; + int width = XCardSwitchButton.this.getWidth(); + int height = XCardSwitchButton.this.getHeight(); + CardSwitchButton button = (CardSwitchButton) XCardSwitchButton.this.toData(); + String titleText = button.getText(); + java.util.List verticalTextList = new ArrayList(); + StringBuilder titleStringBuf = new StringBuilder(); + WidgetTitle title = getWidgetTitle(); + FRFont font = title.getFrFont(); + FRFont newFont = FRFont.getInstance(font.getName(), font.getStyle(), font.getSize() + FONT_SIZE_ADJUST); + FontMetrics fm = GraphHelper.getFontMetrics(newFont); + for (int i = 0; i < titleText.length(); i++) { + titleStringBuf.append(titleText.charAt(i)); + verticalTextList.add(titleStringBuf.substring(0, titleStringBuf.length())); + titleStringBuf.delete(0, titleStringBuf.length()); + } + int textAscent = fm.getAscent(); + int textHeight = fm.getHeight(); + int textY = 0; + textY += textAscent; + for (int i = 0; i < verticalTextList.size(); i++) { + String paint_str = (String) verticalTextList.get(i); + + GraphHelper.drawString(g2d, paint_str, (width - fm.stringWidth(paint_str)) / 2, textY); + textY += textHeight; + textY += PT.pt2pix(0, RESLUTION); + if (textY > height - textHeight && i < verticalTextList.size() - 1) { + textY -= DOTS_HEIGHT; + paintDots(g2d, textY, (width - fm.stringWidth(paint_str)) / 2); + break; + } + } + } + + public void paintDots(Graphics2D g2d, int startY, int startX) { + for (int i = 0; i < DOT_COUNT; i++) { + GraphHelper.drawString(g2d, DOT, startX, startY); + startY += DOTS_LINESPACE; + startY += PT.pt2pix(0, RESLUTION); + } + } } } \ No newline at end of file diff --git a/designer_form/src/com/fr/design/designer/creator/cardlayout/XWCardLayout.java b/designer_form/src/com/fr/design/designer/creator/cardlayout/XWCardLayout.java index 4c1a957fc1..b1c9863b4f 100644 --- a/designer_form/src/com/fr/design/designer/creator/cardlayout/XWCardLayout.java +++ b/designer_form/src/com/fr/design/designer/creator/cardlayout/XWCardLayout.java @@ -31,7 +31,6 @@ import com.fr.form.ui.container.WLayout; import com.fr.form.ui.container.cardlayout.WCardMainBorderLayout; import com.fr.form.ui.container.cardlayout.WCardTagLayout; import com.fr.form.ui.container.cardlayout.WCardTitleLayout; -import com.fr.form.ui.container.cardlayout.WTabFitLayout; import com.fr.general.ComparatorUtils; import com.fr.general.Inter; import com.fr.stable.ArrayUtils; @@ -227,12 +226,9 @@ public class XWCardLayout extends XLayoutContainer { private XCardSwitchButton initFirstButton(String widgetName, XWCardTagLayout xTag){ CardSwitchButton firstBtn = new CardSwitchButton(widgetName); firstBtn.setText(Inter.getLocText("FR-Designer_Title") + 0); - firstBtn.setInitialBackground(ColorBackground.getInstance(Color.WHITE)); - firstBtn.setCustomStyle(true); xTag.setCurrentCard(firstBtn); XCardSwitchButton xFirstBtn = new XCardSwitchButton(firstBtn, new Dimension(CardSwitchButton.DEF_WIDTH, -1), this, xTag); xFirstBtn.setBackupParent(xTag); - return xFirstBtn; } 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 0b32232216..6a77c95de3 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 @@ -1,7 +1,6 @@ package com.fr.design.designer.creator.cardlayout; import com.fr.base.GraphHelper; -import com.fr.base.background.ColorBackground; import com.fr.design.designer.beans.LayoutAdapter; import com.fr.design.designer.beans.adapters.layout.FRTabFitLayoutAdapter; import com.fr.design.designer.beans.models.SelectionModel; @@ -22,7 +21,6 @@ import com.fr.form.ui.container.WAbsoluteLayout.BoundsWidget; import com.fr.form.ui.container.cardlayout.WCardTagLayout; import com.fr.form.ui.container.cardlayout.WTabFitLayout; import com.fr.general.Background; -import com.fr.general.FRLogger; import com.fr.general.Inter; import com.fr.stable.ArrayUtils; import com.fr.stable.core.PropertyChangeAdapter; @@ -213,40 +211,27 @@ public class XWTabFitLayout extends XWFitLayout { } private void checkButonType() { - if (this.xCardSwitchButton == null) { - //假如为空,默认获取第一个tab的cardBtn属性 - try { - xCardSwitchButton = (XCardSwitchButton) ((XWCardMainBorderLayout) this.getTopLayout()).getTitlePart().getTagPart().getComponent(0); - }catch (Exception e){ - FRLogger.getLogger().error(e.getMessage()); - } - return; - } - boolean isStyle = ((WTabFitLayout) data).isCustomStyle(); - Background bg; - bg = ColorBackground.getInstance(NORMAL_GRAL); + WTabFitLayout wTabFitLayout = ((WTabFitLayout) data); CardSwitchButton cardSwitchButton = (CardSwitchButton) this.xCardSwitchButton.toData(); + boolean isStyle = wTabFitLayout.isCustomStyle(); + Background initialBackground = wTabFitLayout.getInitialBackground(); + Background overBackground = wTabFitLayout.getOverBackground(); + Background clickBackground = wTabFitLayout.getClickBackground(); if (!isStyle) { - this.xCardSwitchButton.setCustomStyle(false); - this.xCardSwitchButton.setSelectBackground(bg); + cardSwitchButton.setCustomStyle(false); cardSwitchButton.setInitialBackground(null); cardSwitchButton.setClickBackground(null); cardSwitchButton.setOverBackground(null); } else { - Background initialBackground = cardSwitchButton.getInitialBackground(); - bg = initialBackground == null ? bg : initialBackground; - this.xCardSwitchButton.setSelectBackground(bg); - this.xCardSwitchButton.setCustomStyle(true); cardSwitchButton.setCustomStyle(true); - if (this.initialBackground != null){ - this.xCardSwitchButton.setSelectBackground(this.initialBackground); - cardSwitchButton.setInitialBackground(this.initialBackground); + if (initialBackground != null){ + cardSwitchButton.setInitialBackground(initialBackground); } - if (this.overBackground != null){ - cardSwitchButton.setOverBackground(this.overBackground); + if (overBackground != null){ + cardSwitchButton.setOverBackground(overBackground); } - if (this.clickBackground != null) { - cardSwitchButton.setClickBackground(this.clickBackground); + if (clickBackground != null) { + cardSwitchButton.setClickBackground(clickBackground); } } } @@ -601,30 +586,14 @@ public class XWTabFitLayout extends XWFitLayout { @Override public void firePropertyChange(){ - checkButonType(); //根据字体长度设置tab宽度 setCardSwitchBtnSize(); XWCardLayout cardLayout = (XWCardLayout) this.getBackupParent(); XWCardMainBorderLayout mainLayout = (XWCardMainBorderLayout) cardLayout.getBackupParent(); XWCardTitleLayout titleLayout = mainLayout.getTitlePart(); -// //放置tab按钮的tagLayout + //放置tab按钮的tagLayout XWCardTagLayout tagLayout = titleLayout.getTagPart(); tagLayout.setTabsAndAdjust(); - - initialBackground = ((WTabFitLayout) data).getInitialBackground(); - overBackground = ((WTabFitLayout) data).getOverBackground(); - clickBackground = ((WTabFitLayout)data).getClickBackground(); - CardSwitchButton cardSwitchButton = (CardSwitchButton) xCardSwitchButton.toData(); - if(initialBackground != null){ - xCardSwitchButton.setSelectBackground(initialBackground); - cardSwitchButton.setInitialBackground(initialBackground); - } - if(overBackground != null){ - cardSwitchButton.setOverBackground(overBackground); - } - if(clickBackground != null){ - cardSwitchButton.setClickBackground(clickBackground); - } } public void setCardSwitchBtnSize(){ diff --git a/designer_form/src/com/fr/design/widget/ui/designer/component/TabFitLayoutBackgroundPane.java b/designer_form/src/com/fr/design/widget/ui/designer/component/TabFitLayoutBackgroundPane.java index b2c79c9223..12a6e3c26a 100644 --- a/designer_form/src/com/fr/design/widget/ui/designer/component/TabFitLayoutBackgroundPane.java +++ b/designer_form/src/com/fr/design/widget/ui/designer/component/TabFitLayoutBackgroundPane.java @@ -2,6 +2,7 @@ package com.fr.design.widget.ui.designer.component; import com.fr.design.gui.ilable.UILabel; import com.fr.design.widget.component.BackgroundCompPane; +import com.fr.form.ui.CardSwitchButton; import com.fr.form.ui.container.cardlayout.WTabFitLayout; import com.fr.general.Background; import com.fr.general.Inter; @@ -15,33 +16,33 @@ public class TabFitLayoutBackgroundPane extends BackgroundCompPane UILabel fontLabel = new UILabel(Inter.getLocText("FR-Designer_Font")); fontLabel.setVerticalAlignment(SwingConstants.TOP); - frFontPane = new FRFontPane(){ + frFontPane = new FRFontPane() { protected JPanel createRightPane() { double p = TableLayout.PREFERRED; double f = TableLayout.FILL; @@ -73,7 +75,7 @@ public class WCardTagLayoutDefinePane extends AbstractDataModify } }; - displayPositionGroup = new UIButtonGroup(WTabDisplayPosition.getStringArray()){ + displayPositionGroup = new UIButtonGroup(WTabDisplayPosition.getStringArray()) { @Override public boolean shouldResponseNameListener() { return true; @@ -105,7 +107,7 @@ public class WCardTagLayoutDefinePane extends AbstractDataModify public void populateBean(WCardTagLayout ob) { //标题背景和字体属性设置在WCardLayout上做兼容 XLayoutContainer topLayout = creator.getTopLayout(); - LayoutBorderStyle layoutBorderStyle = ((XWCardMainBorderLayout)topLayout).getCardPart().toData().getBorderStyle(); + LayoutBorderStyle layoutBorderStyle = ((XWCardMainBorderLayout) topLayout).getCardPart().toData().getBorderStyle(); displayPositionGroup.setSelectedIndex(ob.getDisplayPosition().getType()); textDirectionGroup.setSelectedIndex(ob.getTextDirection().getType()); @@ -121,25 +123,41 @@ public class WCardTagLayoutDefinePane extends AbstractDataModify public WCardTagLayout updateBean() { //标题背景和字体属性设置在WCardLayout上做兼容 XLayoutContainer topLayout = creator.getTopLayout(); - LayoutBorderStyle layoutBorderStyle = ((XWCardMainBorderLayout)topLayout).getCardPart().toData().getBorderStyle(); + LayoutBorderStyle layoutBorderStyle = ((XWCardMainBorderLayout) topLayout).getCardPart().toData().getBorderStyle(); FRFont frFont = layoutBorderStyle.getTitle().getFrFont() == null ? FRFont.getInstance() : layoutBorderStyle.getTitle().getFrFont(); layoutBorderStyle.getTitle().setFrFont(frFontPane.update(frFont)); WCardTagLayout layout = (WCardTagLayout) creator.toData(); boolean isHori = displayPositionGroup.getSelectedIndex() == WTabDisplayPosition.TOP_POSITION.getType() || displayPositionGroup.getSelectedIndex() == WTabDisplayPosition.BOTTOM_POSITION.getType(); - if(ComparatorUtils.equals(getGlobalName(), Inter.getLocText("FR-Designer_Tab_Style_Template"))){ + if (ComparatorUtils.equals(getGlobalName(), Inter.getLocText("FR-Designer_Tab_Style_Template"))) { layout.setDisplayPosition(WTabDisplayPosition.parse(displayPositionGroup.getSelectedIndex())); - textDirectionGroup.setSelectedIndex(isHori? WTabTextDirection.TEXT_HORI_DERECTION.getType():WTabTextDirection.TEXT_VER_DIRECTION.getType()); + textDirectionGroup.setSelectedIndex(isHori ? WTabTextDirection.TEXT_HORI_DERECTION.getType() : WTabTextDirection.TEXT_VER_DIRECTION.getType()); + layout.setHgap(isHori ? WCardTagLayout.DESIGNER_DEFAULT_GAP : 0); + layout.setVgap(isHori ? 0 : WCardTagLayout.DESIGNER_DEFAULT_GAP); } layout.setTextDirection(WTabTextDirection.parse(textDirectionGroup.getSelectedIndex())); TemplateStyle templateStyle = (TemplateStyle) templateStyleEditor.getValue(); - if(!ComparatorUtils.equals(layout.getTemplateStyle(), templateStyle)){ + if (!ComparatorUtils.equals(layout.getTemplateStyle(), templateStyle)) { backgroundEditor.setValue(templateStyle.getDefaultBackground()); layoutBorderStyle.getTitle().setBackground(templateStyle.getDefaultBackground()); + //重置内部tab的默认背景 + resetTabBackground(layout, templateStyle); layout.setTemplateStyle(templateStyle); - }else{ + } else { layoutBorderStyle.getTitle().setBackground((Background) backgroundEditor.getValue()); } return layout; } + + private void resetTabBackground(WCardTagLayout layout, TemplateStyle templateStyle) { + for (int i = 0, len = layout.getWidgetCount(); i < len; i++) { + CardSwitchButton button = layout.getSwitchButton(i); + //兼容默认样式 + boolean defaultStyle = ComparatorUtils.equals(templateStyle.getStyle(), DefaultTemplateStyle.DEFAULT_TEMPLATE_STYLE); + button.setInitialBackground(defaultStyle ? null : templateStyle.getTabDefaultBackground()); + button.setOverBackground(null); + button.setClickBackground(null); + button.setCustomStyle(true); + } + } } diff --git a/designer_form/src/com/fr/design/widget/ui/designer/layout/WTabFitLayoutDefinePane.java b/designer_form/src/com/fr/design/widget/ui/designer/layout/WTabFitLayoutDefinePane.java index 77452e07b9..b9a2358695 100644 --- a/designer_form/src/com/fr/design/widget/ui/designer/layout/WTabFitLayoutDefinePane.java +++ b/designer_form/src/com/fr/design/widget/ui/designer/layout/WTabFitLayoutDefinePane.java @@ -78,7 +78,7 @@ public class WTabFitLayoutDefinePane extends AbstractDataModify { @Override public void populateBean(WTabFitLayout ob) { - borderStyle.populate(ob); + borderStyle.populate(ob.getCurrentCard()); paddingBoundPane.populate(ob); componentInterval.setValue(ob.getCompInterval()); if(ob.getCurrentCard() == null){ @@ -118,7 +118,7 @@ public class WTabFitLayoutDefinePane extends AbstractDataModify { @Override public WTabFitLayout updateBean() { WTabFitLayout layout = (WTabFitLayout) creator.toData(); - borderStyle.update(layout); + borderStyle.update(layout.getCurrentCard()); if (ComparatorUtils.equals(getGlobalName(), Inter.getLocText("FR-Designer_Layout-Padding"))) { paddingBoundPane.update(layout); }