|
|
@ -3,17 +3,15 @@ |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
package com.fr.design.designer.creator.cardlayout; |
|
|
|
package com.fr.design.designer.creator.cardlayout; |
|
|
|
|
|
|
|
|
|
|
|
import java.awt.Color; |
|
|
|
import java.awt.*; |
|
|
|
import java.awt.Dimension; |
|
|
|
|
|
|
|
import java.awt.Graphics; |
|
|
|
|
|
|
|
import java.awt.Graphics2D; |
|
|
|
|
|
|
|
import java.awt.Point; |
|
|
|
|
|
|
|
import java.awt.event.MouseEvent; |
|
|
|
import java.awt.event.MouseEvent; |
|
|
|
import java.awt.geom.Rectangle2D; |
|
|
|
import java.awt.geom.Rectangle2D; |
|
|
|
|
|
|
|
import java.util.*; |
|
|
|
|
|
|
|
|
|
|
|
import javax.swing.Icon; |
|
|
|
import javax.swing.*; |
|
|
|
|
|
|
|
|
|
|
|
import com.fr.base.BaseUtils; |
|
|
|
import com.fr.base.BaseUtils; |
|
|
|
|
|
|
|
import com.fr.base.GraphHelper; |
|
|
|
import com.fr.base.background.ColorBackground; |
|
|
|
import com.fr.base.background.ColorBackground; |
|
|
|
import com.fr.design.designer.beans.AdapterBus; |
|
|
|
import com.fr.design.designer.beans.AdapterBus; |
|
|
|
import com.fr.design.designer.beans.ComponentAdapter; |
|
|
|
import com.fr.design.designer.beans.ComponentAdapter; |
|
|
@ -33,6 +31,7 @@ import com.fr.form.ui.WidgetTitle; |
|
|
|
import com.fr.form.ui.container.cardlayout.WTabFitLayout; |
|
|
|
import com.fr.form.ui.container.cardlayout.WTabFitLayout; |
|
|
|
import com.fr.general.Background; |
|
|
|
import com.fr.general.Background; |
|
|
|
import com.fr.general.FRFont; |
|
|
|
import com.fr.general.FRFont; |
|
|
|
|
|
|
|
import com.fr.general.Inter; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* |
|
|
|
* |
|
|
@ -41,10 +40,14 @@ import com.fr.general.FRFont; |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public class XCardSwitchButton extends XButton { |
|
|
|
public class XCardSwitchButton extends XButton { |
|
|
|
|
|
|
|
|
|
|
|
private XWCardLayout cardLayout; |
|
|
|
|
|
|
|
private XWCardTagLayout tagLayout; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static final int LEFT_GAP = 16; |
|
|
|
private static final int LEFT_GAP = 16; |
|
|
|
|
|
|
|
private static Icon MOUSE_COLSE = BaseUtils.readIcon("/com/fr/design/images/buttonicon/close_icon.png"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//设置的图片类型
|
|
|
|
|
|
|
|
private static final String COLORBACKGROUNDTYPE = "ColorBackground"; |
|
|
|
|
|
|
|
private static final String DEFAULTTYPE = "default"; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//默认颜色
|
|
|
|
public static final Color NORMAL_GRAL = new Color(236,236,236); |
|
|
|
public static final Color NORMAL_GRAL = new Color(236,236,236); |
|
|
|
public static final Color CHOOSED_GRAL = new Color(222,222,222); |
|
|
|
public static final Color CHOOSED_GRAL = new Color(222,222,222); |
|
|
|
|
|
|
|
|
|
|
@ -54,12 +57,21 @@ public class XCardSwitchButton extends XButton { |
|
|
|
private static final int RIGHT_OFFSET = 15; |
|
|
|
private static final int RIGHT_OFFSET = 15; |
|
|
|
private static final int TOP_OFFSET = 25; |
|
|
|
private static final int TOP_OFFSET = 25; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//这边先不计算button的高度,涉及到layout那边的整体高度,先用之前的固定高度
|
|
|
|
|
|
|
|
private static final int DEFAULT_BUTTON_HEIGHT = 36; |
|
|
|
|
|
|
|
|
|
|
|
// tab按钮里的字体因为按钮内部的布局看起来比正常的要小,加个调整量
|
|
|
|
// tab按钮里的字体因为按钮内部的布局看起来比正常的要小,加个调整量
|
|
|
|
private static final int FONT_SIZE_ADJUST = 2; |
|
|
|
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; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private Background selectBackground; |
|
|
|
|
|
|
|
private boolean isCustomStyle; |
|
|
|
|
|
|
|
|
|
|
|
private static Icon MOUSE_COLSE = BaseUtils.readIcon("/com/fr/design/images/buttonicon/close_icon.png"); |
|
|
|
|
|
|
|
private Icon closeIcon = MOUSE_COLSE; |
|
|
|
private Icon closeIcon = MOUSE_COLSE; |
|
|
|
|
|
|
|
|
|
|
|
public XWCardTagLayout getTagLayout() { |
|
|
|
public XWCardTagLayout getTagLayout() { |
|
|
@ -78,6 +90,22 @@ public class XCardSwitchButton extends XButton { |
|
|
|
this.cardLayout = cardLayout; |
|
|
|
this.cardLayout = cardLayout; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public boolean isCustomStyle() { |
|
|
|
|
|
|
|
return isCustomStyle; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void setCustomStyle(boolean customStyle) { |
|
|
|
|
|
|
|
isCustomStyle = customStyle; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public Background getSelectBackground() { |
|
|
|
|
|
|
|
return selectBackground; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void setSelectBackground(Background selectBackground) { |
|
|
|
|
|
|
|
this.selectBackground = selectBackground; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public XCardSwitchButton(CardSwitchButton widget, Dimension initSize) { |
|
|
|
public XCardSwitchButton(CardSwitchButton widget, Dimension initSize) { |
|
|
|
super(widget, initSize); |
|
|
|
super(widget, initSize); |
|
|
|
} |
|
|
|
} |
|
|
@ -133,6 +161,7 @@ public class XCardSwitchButton extends XButton { |
|
|
|
|
|
|
|
|
|
|
|
// 切换到当前tab按钮对应的tabFitLayout
|
|
|
|
// 切换到当前tab按钮对应的tabFitLayout
|
|
|
|
XWTabFitLayout tabFitLayout = (XWTabFitLayout) cardLayout.getComponent(index); |
|
|
|
XWTabFitLayout tabFitLayout = (XWTabFitLayout) cardLayout.getComponent(index); |
|
|
|
|
|
|
|
tabFitLayout.setxCardSwitchButton(this); |
|
|
|
selectionModel.setSelectedCreator(tabFitLayout); |
|
|
|
selectionModel.setSelectedCreator(tabFitLayout); |
|
|
|
|
|
|
|
|
|
|
|
if (editingMouseListener.stopEditing()) { |
|
|
|
if (editingMouseListener.stopEditing()) { |
|
|
@ -141,11 +170,17 @@ public class XCardSwitchButton extends XButton { |
|
|
|
editingMouseListener.startEditing(this, |
|
|
|
editingMouseListener.startEditing(this, |
|
|
|
adapter.getDesignerEditor(), adapter); |
|
|
|
adapter.getDesignerEditor(), adapter); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
setTabsAndAdjust(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//删除card,同时修改其他switchbutton和tabfit的index
|
|
|
|
//删除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); |
|
|
|
|
|
|
|
if (value != JOptionPane.OK_OPTION) { |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
tagLayout.remove(button); |
|
|
|
tagLayout.remove(button); |
|
|
|
// 先清除该tab内部组件,否在再显示上有样式的残留
|
|
|
|
// 先清除该tab内部组件,否在再显示上有样式的残留
|
|
|
|
XWTabFitLayout tabLayout = (XWTabFitLayout)cardLayout.getComponent(index); |
|
|
|
XWTabFitLayout tabLayout = (XWTabFitLayout)cardLayout.getComponent(index); |
|
|
@ -225,6 +260,7 @@ public class XCardSwitchButton extends XButton { |
|
|
|
|
|
|
|
|
|
|
|
public void paintComponent(Graphics g) { |
|
|
|
public void paintComponent(Graphics g) { |
|
|
|
super.paintComponent(g); |
|
|
|
super.paintComponent(g); |
|
|
|
|
|
|
|
setTabsAndAdjust(); |
|
|
|
Graphics2D g2d = (Graphics2D) g; |
|
|
|
Graphics2D g2d = (Graphics2D) g; |
|
|
|
drawBackgorund(); |
|
|
|
drawBackgorund(); |
|
|
|
drawTitle(); |
|
|
|
drawTitle(); |
|
|
@ -241,16 +277,22 @@ public class XCardSwitchButton extends XButton { |
|
|
|
//画背景
|
|
|
|
//画背景
|
|
|
|
private void drawBackgorund(){ |
|
|
|
private void drawBackgorund(){ |
|
|
|
CardSwitchButton button = (CardSwitchButton)this.toData(); |
|
|
|
CardSwitchButton button = (CardSwitchButton)this.toData(); |
|
|
|
ColorBackground background; |
|
|
|
Background currentBackground; |
|
|
|
if(button.isShowButton()){ |
|
|
|
currentBackground = this.getSelectBackground(); |
|
|
|
this.rebuid(); |
|
|
|
//这边就是button的背景图片,图片的是image,默认的是color,所以不应该是针对null的判断
|
|
|
|
background = ColorBackground.getInstance(CHOOSED_GRAL); |
|
|
|
String type = currentBackground != null? currentBackground.getBackgroundType() : DEFAULTTYPE; |
|
|
|
this.setContentBackground(background); |
|
|
|
if (type.equals(COLORBACKGROUNDTYPE) || type.equals(DEFAULTTYPE)) { |
|
|
|
}else{ |
|
|
|
ColorBackground background; |
|
|
|
this.rebuid(); |
|
|
|
if(button.isShowButton()){ |
|
|
|
background = ColorBackground.getInstance(NORMAL_GRAL); |
|
|
|
this.rebuid(); |
|
|
|
this.setContentBackground(background); |
|
|
|
background = ColorBackground.getInstance(CHOOSED_GRAL); |
|
|
|
} |
|
|
|
this.setContentBackground(background); |
|
|
|
|
|
|
|
}else{ |
|
|
|
|
|
|
|
this.rebuid(); |
|
|
|
|
|
|
|
background = ColorBackground.getInstance(NORMAL_GRAL); |
|
|
|
|
|
|
|
this.setContentBackground(background); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//画标题
|
|
|
|
//画标题
|
|
|
@ -272,10 +314,12 @@ public class XCardSwitchButton extends XButton { |
|
|
|
label.setForeground(font.getForeground()); |
|
|
|
label.setForeground(font.getForeground()); |
|
|
|
Background background = title.getBackground(); |
|
|
|
Background background = title.getBackground(); |
|
|
|
if (background != null) { |
|
|
|
if (background != null) { |
|
|
|
if(button.isShowButton()){ |
|
|
|
if(button.isShowButton() && selectBackground != null){ |
|
|
|
background = ColorBackground.getInstance(CHOOSED_GRAL); |
|
|
|
this.setContentBackground(selectBackground); |
|
|
|
this.setContentBackground(background); |
|
|
|
}else if (button.isShowButton() && selectBackground == null){ |
|
|
|
}else{ |
|
|
|
background = ColorBackground.getInstance(CHOOSED_GRAL); |
|
|
|
|
|
|
|
this.setContentBackground(background); |
|
|
|
|
|
|
|
} else { |
|
|
|
this.setContentBackground(background); |
|
|
|
this.setContentBackground(background); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -298,4 +342,53 @@ public class XCardSwitchButton extends XButton { |
|
|
|
return this.getBackupParent().getTopLayout(); |
|
|
|
return this.getBackupParent().getTopLayout(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void setTabsAndAdjust() { |
|
|
|
|
|
|
|
if (this.tagLayout == null) { |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
int tabLength = this.tagLayout.getComponentCount(); |
|
|
|
|
|
|
|
Map<Integer, Integer> cardWidth = new HashMap<>(); |
|
|
|
|
|
|
|
Map<Integer, Integer> 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 = GraphHelper.getFontMetrics(f); |
|
|
|
|
|
|
|
cardWidth.put(i,fm.stringWidth(tempText)); |
|
|
|
|
|
|
|
cardHeight.put(i,fm.getHeight()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
adjustTabs(tabLength, cardWidth, cardHeight); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void adjustTabs(int tabLength, Map<Integer, Integer> width, Map<Integer, Integer> height) { |
|
|
|
|
|
|
|
if (width == null) { |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
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 = DEFAULT_BUTTON_HEIGHT; |
|
|
|
|
|
|
|
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); |
|
|
|
|
|
|
|
XCardSwitchButton temp = (XCardSwitchButton) this.tagLayout.getComponent(i); |
|
|
|
|
|
|
|
UILabel label = temp.getContentLabel(); |
|
|
|
|
|
|
|
label.setSize(dimension); |
|
|
|
|
|
|
|
temp.setContentLabel(label); |
|
|
|
|
|
|
|
temp.setSize(dimension); |
|
|
|
|
|
|
|
temp.setPreferredSize(new Dimension(cardWidth, cardHeight)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public void doLayout() { |
|
|
|
|
|
|
|
super.doLayout(); |
|
|
|
|
|
|
|
setTabsAndAdjust(); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |