@ -50,8 +50,6 @@ import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionAdapter ;
import java.awt.event.MouseMotionAdapter ;
import java.util.Collections ;
import java.util.Collections ;
import java.util.List ;
import java.util.List ;
import java.util.Map ;
import java.util.stream.Collectors ;
import static com.fine.theme.utils.FineClientProperties.BUTTON_TYPE_TOOLBAR_BUTTON ;
import static com.fine.theme.utils.FineClientProperties.BUTTON_TYPE_TOOLBAR_BUTTON ;
import static com.fine.theme.utils.FineUIScale.scale ;
import static com.fine.theme.utils.FineUIScale.scale ;
@ -75,6 +73,7 @@ public class MultiTemplateTabPane extends Row {
private static final String UI_CLASS_ID = "TemplateTabPaneUI" ;
private static final String UI_CLASS_ID = "TemplateTabPaneUI" ;
private static final int GAP = 6 ;
private static final int GAP = 6 ;
private static final int SMALLGAP = 4 ;
private static final int SMALLGAP = 4 ;
private static final int DOUBLE_CLICK = 2 ;
/ * *
/ * *
* 尾部动作区宽度
* 尾部动作区宽度
@ -124,6 +123,8 @@ public class MultiTemplateTabPane extends Row {
// 模板时,模板B会自动关闭
// 模板时,模板B会自动关闭
private JTemplate < ? , ? > temTemplate = null ;
private JTemplate < ? , ? > temTemplate = null ;
private ActionListener newTemplateAction ;
@Override
@Override
public String getUIClassID ( ) {
public String getUIClassID ( ) {
return UI_CLASS_ID ;
return UI_CLASS_ID ;
@ -205,8 +206,9 @@ public class MultiTemplateTabPane extends Row {
* @param l 监听器
* @param l 监听器
* /
* /
public void addLeadingAction ( ActionListener l ) {
public void addLeadingAction ( ActionListener l ) {
leadingActionButton . removeActionListener ( l ) ;
newTemplateAction = l ;
leadingActionButton . addActionListener ( l ) ;
leadingActionButton . removeActionListener ( newTemplateAction ) ;
leadingActionButton . addActionListener ( newTemplateAction ) ;
}
}
public void setLeadingActionEnable ( boolean enable ) {
public void setLeadingActionEnable ( boolean enable ) {
@ -227,19 +229,17 @@ public class MultiTemplateTabPane extends Row {
/ * *
/ * *
* 判断模板是否可以关闭 , 两个条件 : 1 、 是否满足CloseOption里面的条件 ( 在左侧 、 在右侧等 ) 2 、 是否和当前正在编辑模板属于同一种模板tab操作类型
* 判断模板是否可以关闭 , 两个条件 : 1 、 是否满足CloseOption里面的条件 ( 在左侧 、 在右侧等 ) 2 、 是否和当前正在编辑模板属于同一种模板tab操作类型
*
*
* @param closeJTemplate
* @param tplIndex
* @param tplIndex
* @param i
* @param i
* @return
* @return
* /
* /
public boolean shouldClose ( JTemplate closeJTemplate , int tplIndex , int i ) {
public boolean shouldClose ( int tplIndex , int i ) {
boolean matchOption = this . closeOption . shouldClose ( tplIndex , i ) ;
boolean matchOption = this . closeOption . shouldClose ( tplIndex , i ) ;
JTemplate currentTemplate = HistoryTemplateListCache . getInstance ( ) . getCurrentEditingTemplate ( ) ;
JTemplate currentTemplate = HistoryTemplateListCache . getInstance ( ) . getCurrentEditingTemplate ( ) ;
if ( ! JTemplate . isValid ( currentTemplate ) ) {
if ( ! JTemplate . isValid ( currentTemplate ) ) {
return matchOption ;
return matchOption ;
}
}
return matchOption & & ComparatorUtils . equals ( closeJTemplate . getTemplateTabOperatorType ( ) ,
return matchOption ;
currentTemplate . getTemplateTabOperatorType ( ) ) ;
}
}
}
}
@ -326,12 +326,7 @@ public class MultiTemplateTabPane extends Row {
if ( OK_OPTION = = selVal ) {
if ( OK_OPTION = = selVal ) {
CallbackSaveWorker worker = template . saveAs ( ) ;
CallbackSaveWorker worker = template . saveAs ( ) ;
worker . start ( template . getRuntimeId ( ) ) ;
worker . start ( template . getRuntimeId ( ) ) ;
worker . addSuccessCallback ( new Runnable ( ) {
worker . addSuccessCallback ( ( ) - > gotoEditingTemplateLeaf ( template . getPath ( ) ) ) ;
@Override
public void run ( ) {
gotoEditingTemplateLeaf ( template . getPath ( ) ) ;
}
} ) ;
}
}
} else {
} else {
gotoEditingTemplateLeaf ( template . getPath ( ) ) ;
gotoEditingTemplateLeaf ( template . getPath ( ) ) ;
@ -365,7 +360,7 @@ public class MultiTemplateTabPane extends Row {
JTemplate < ? , ? > currentTemplate = HistoryTemplateListCache . getInstance ( ) . getCurrentEditingTemplate ( ) ;
JTemplate < ? , ? > currentTemplate = HistoryTemplateListCache . getInstance ( ) . getCurrentEditingTemplate ( ) ;
closeTemplate ( closeCondition , templates , currentTemplate ) ;
closeTemplate ( closeCondition , templates , currentTemplate ) ;
if ( openedTemplate . size ( ) = = 0 ) {
if ( openedTemplate . isEmpty ( ) ) {
DesignerContext . getDesignerFrame ( ) . addAndActivateJTemplate ( ) ;
DesignerContext . getDesignerFrame ( ) . addAndActivateJTemplate ( ) ;
} else if ( option = = CloseOption . All ) {
} else if ( option = = CloseOption . All ) {
//openedTemplate(0)是JVirtualTemplate时需重新打开
//openedTemplate(0)是JVirtualTemplate时需重新打开
@ -380,7 +375,7 @@ public class MultiTemplateTabPane extends Row {
private void closeTemplate ( CloseCondition closeCondition , JTemplate < ? , ? > [ ] templates , JTemplate < ? , ? > currentTemplate ) {
private void closeTemplate ( CloseCondition closeCondition , JTemplate < ? , ? > [ ] templates , JTemplate < ? , ? > currentTemplate ) {
for ( int i = 0 ; i < templates . length ; i + + ) {
for ( int i = 0 ; i < templates . length ; i + + ) {
if ( closeCondition . shouldClose ( templates [ i ] , t plIndex , i ) ) {
if ( closeCondition . shouldClose ( tplIndex , i ) ) {
JTemplate < ? , ? > jTemplate = templates [ i ] ;
JTemplate < ? , ? > jTemplate = templates [ i ] ;
if ( jTemplate = = currentTemplate ) {
if ( jTemplate = = currentTemplate ) {
currentTemplate = option = = CloseOption . All ? null : templates [ tplIndex ] ;
currentTemplate = option = = CloseOption . All ? null : templates [ tplIndex ] ;
@ -415,20 +410,18 @@ public class MultiTemplateTabPane extends Row {
/ * *
/ * *
* 关闭所有指定模板tab操作类型的模板
* 关闭所有指定模板tab操作类型的模板
*
* @param operatorType
* /
* /
public void closeOtherByOperatorType ( String operatorType ) {
public void closeOther ( ) {
JTemplate < ? , ? > currentEditingTemplate = HistoryTemplateListCache . getInstance ( ) . getCurrentEditingTemplate ( ) ;
JTemplate < ? , ? > currentEditingTemplate = HistoryTemplateListCache . getInstance ( ) . getCurrentEditingTemplate ( ) ;
SaveSomeTemplatePane saveSomeTempa ltePane = new SaveSomeTemplatePane ( false ) ;
SaveSomeTemplatePane saveSomeTempla tePane = new SaveSomeTemplatePane ( false ) ;
if ( saveSomeTempa ltePane . showSavePane ( null , false , true ) ) {
if ( saveSomeTempla tePane . showSavePane ( null , false , true ) ) {
List < JTemplate < ? , ? > > openedTemplate = HistoryTemplateListCache . getInstance ( ) . getHistoryList ( ) ;
List < JTemplate < ? , ? > > openedTemplate = HistoryTemplateListCache . getInstance ( ) . getHistoryList ( ) ;
JTemplate < ? , ? > [ ] templates = new JTemplate < ? , ? > [ openedTemplate . size ( ) ] ;
JTemplate < ? , ? > [ ] templates = new JTemplate < ? , ? > [ openedTemplate . size ( ) ] ;
for ( int i = 0 ; i < openedTemplate . size ( ) ; i + + ) {
for ( int i = 0 ; i < openedTemplate . size ( ) ; i + + ) {
templates [ i ] = openedTemplate . get ( i ) ;
templates [ i ] = openedTemplate . get ( i ) ;
}
}
closeTemplate ( templates , currentEditingTemplate , operatorType ) ;
closeTemplate ( templates , currentEditingTemplate ) ;
DesignerContext . getDesignerFrame ( ) . activateJTemplate ( currentEditingTemplate ) ;
DesignerContext . getDesignerFrame ( ) . activateJTemplate ( currentEditingTemplate ) ;
MultiTemplateTabPane . getInstance ( ) . repaint ( ) ;
MultiTemplateTabPane . getInstance ( ) . repaint ( ) ;
@ -439,14 +432,10 @@ public class MultiTemplateTabPane extends Row {
* 关闭指定的非当前编辑模板
* 关闭指定的非当前编辑模板
*
*
* @param templates
* @param templates
* @param operatorType
* /
* /
private static void closeTemplate ( JTemplate < ? , ? > [ ] templates , JTemplate < ? , ? > currentEditingTemplate , String operatorType ) {
private static void closeTemplate ( JTemplate < ? , ? > [ ] templates , JTemplate < ? , ? > currentEditingTemplate ) {
for ( int i = 0 ; i < templates . length ; i + + ) {
for ( JTemplate < ? , ? > jTemplate : templates ) {
JTemplate < ? , ? > jTemplate = templates [ i ] ;
if ( jTemplate = = currentEditingTemplate ) {
boolean needClose = ComparatorUtils . equals ( operatorType , jTemplate . getTemplateTabOperatorType ( ) )
& & jTemplate ! = currentEditingTemplate ;
if ( ! needClose ) {
continue ;
continue ;
}
}
MultiTemplateTabPane . getInstance ( ) . closeFormat ( jTemplate ) ;
MultiTemplateTabPane . getInstance ( ) . closeFormat ( jTemplate ) ;
@ -471,11 +460,6 @@ public class MultiTemplateTabPane extends Row {
}
}
private String tempalteShowName ( JTemplate < ? , ? > template ) {
return template . getTabShowName ( template ) ;
}
public String getTemplateShowNameByIndex ( int index ) {
public String getTemplateShowNameByIndex ( int index ) {
JTemplate template = openedTemplate . get ( index ) ;
JTemplate template = openedTemplate . get ( index ) ;
return template . getTabShowName ( template ) ;
return template . getTabShowName ( template ) ;
@ -566,67 +550,14 @@ public class MultiTemplateTabPane extends Row {
minPaintIndex = 0 ;
minPaintIndex = 0 ;
maxPaintIndex = openedTemplate . size ( ) - 1 ;
maxPaintIndex = openedTemplate . size ( ) - 1 ;
}
}
//需要根据每个tab的宽度重新check下实际的maxPaintIndex和minPaintIndex
checkActualPaintIndex ( ) ;
}
/ * *
* 先计算出需要补充的tab个数
*
* @return
* /
private int calTabCountComplemented ( ) {
int a = 0 ;
for ( int i = minPaintIndex ; i < = maxPaintIndex ; i + + ) {
JTemplate template = openedTemplate . get ( i ) ;
if ( ! showJTemplateTab ( template ) ) {
a + + ;
}
}
return a ;
}
}
/ * *
/ * *
* 由于可能存在宽度为0的tab , 所以这边需要重新check下 , 先往后补 , 再往前补
* 个数小于最多能容纳的个数的情况下 , 看看宽度每个要画多少
* /
* /
private void checkActualPaintIndex ( ) {
int tabCount = calTabCountComplemented ( ) ;
if ( tabCount = = 0 ) {
return ;
}
if ( maxPaintIndex < openedTemplate . size ( ) - 1 ) {
for ( int i = maxPaintIndex + 1 ; i < openedTemplate . size ( ) ; i + + ) {
JTemplate template = openedTemplate . get ( i ) ;
if ( showJTemplateTab ( template ) ) {
tabCount - - ;
}
maxPaintIndex + + ;
if ( tabCount = = 0 ) {
return ;
}
}
}
if ( minPaintIndex > 0 ) {
for ( int i = minPaintIndex - 1 ; i > = 0 ; i - - ) {
JTemplate template = openedTemplate . get ( i ) ;
if ( showJTemplateTab ( template ) ) {
tabCount - - ;
}
minPaintIndex - - ;
if ( tabCount = = 0 ) {
return ;
}
}
}
}
//个数小于最多能容纳的个数的情况下,看看宽度每个要画多少
private void calculateRealAverageWidth ( double maxwidth , int templateNum ) {
private void calculateRealAverageWidth ( double maxwidth , int templateNum ) {
JTemplate jTemplate = HistoryTemplateListCache . getInstance ( ) . getCurrentEditingTemplate ( ) ;
List < JTemplate < ? , ? > > showTemplates = getOpenedJTemplates ( ) ;
List < JTemplate < ? , ? > > showTemplates = getOpenedJTemplatesByOperator ( jTemplate . getTemplateTabOperatorType ( ) ) ;
int num = Math . min ( showTemplates . size ( ) , templateNum ) ;
int num = Math . min ( showTemplates . size ( ) , templateNum ) ;
tabWidth = ( int ) ( maxwidth / ( num ) ) ;
tabWidth = ( int ) ( maxwidth / ( num ) ) ;
if ( tabWidth > scale ( MAXWIDTH ) ) {
if ( tabWidth > scale ( MAXWIDTH ) ) {
@ -639,7 +570,6 @@ public class MultiTemplateTabPane extends Row {
public void setIsCloseCurrent ( boolean isCloseCurrent ) {
public void setIsCloseCurrent ( boolean isCloseCurrent ) {
this . isCloseCurrent = isCloseCurrent ;
this . isCloseCurrent = isCloseCurrent ;
}
}
/ * *
/ * *
@ -658,12 +588,9 @@ public class MultiTemplateTabPane extends Row {
Toolkit . i18nText ( "Fine-Design_Basic_Dialog_Prompt" ) , JOptionPane . YES_NO_CANCEL_OPTION , JOptionPane . QUESTION_MESSAGE ) ;
Toolkit . i18nText ( "Fine-Design_Basic_Dialog_Prompt" ) , JOptionPane . YES_NO_CANCEL_OPTION , JOptionPane . QUESTION_MESSAGE ) ;
if ( returnVal = = JOptionPane . YES_OPTION ) {
if ( returnVal = = JOptionPane . YES_OPTION ) {
CallbackSaveWorker worker = specifiedTemplate . save ( ) ;
CallbackSaveWorker worker = specifiedTemplate . save ( ) ;
worker . addSuccessCallback ( new Runnable ( ) {
worker . addSuccessCallback ( ( ) - > {
@Override
FineLoggerFactory . getLogger ( ) . info ( Toolkit . i18nText ( "Fine-Design_Basic_Template_Already_Saved" , specifiedTemplate . getEditingFILE ( ) . getName ( ) ) ) ;
public void run ( ) {
closeTpl ( specifiedTemplate ) ;
FineLoggerFactory . getLogger ( ) . info ( Toolkit . i18nText ( "Fine-Design_Basic_Template_Already_Saved" , specifiedTemplate . getEditingFILE ( ) . getName ( ) ) ) ;
closeTpl ( specifiedTemplate ) ;
}
} ) ;
} ) ;
worker . start ( specifiedTemplate . getRuntimeId ( ) ) ;
worker . start ( specifiedTemplate . getRuntimeId ( ) ) ;
} else if ( returnVal = = JOptionPane . NO_OPTION ) {
} else if ( returnVal = = JOptionPane . NO_OPTION ) {
@ -738,9 +665,7 @@ public class MultiTemplateTabPane extends Row {
// 关闭的模板是当前选中的模板时,需要重新计算下一个待展示的模板的index
// 关闭的模板是当前选中的模板时,需要重新计算下一个待展示的模板的index
if ( selectedIndex > = maxPaintIndex ) {
if ( selectedIndex > = maxPaintIndex ) {
// selectIndex 不会 <0 因为如果关闭的是打开的最后一个模板,那么关闭之后 openedTemplate.isEmpty() = true
// selectIndex 不会 <0 因为如果关闭的是打开的最后一个模板,那么关闭之后 openedTemplate.isEmpty() = true
selectedIndex = calNextShowJTemplateIndex ( selectedIndex - 1 ) ;
selectedIndex - - ;
} else {
selectedIndex = calNextShowJTemplateIndex ( selectedIndex ) ;
}
}
isCloseCurrent = false ;
isCloseCurrent = false ;
}
}
@ -757,23 +682,11 @@ public class MultiTemplateTabPane extends Row {
}
}
}
}
/ * *
* 计算下一个可以展示的模板index
*
* @param currentIndex
* @return
* /
public int calNextShowJTemplateIndex ( int currentIndex ) {
JTemplate jTemplate = HistoryTemplateListCache . getInstance ( ) . getCurrentEditingTemplate ( ) ;
return MultiTemplateTabUtils . calShowTemplateIndex ( currentIndex , openedTemplate , jTemplate . getTemplateTabOperatorType ( ) ) ;
}
private boolean isOverCloseIcon ( int evtX ) {
private boolean isOverCloseIcon ( int evtX ) {
boolean isOverCloseIcon = false ;
boolean isOverCloseIcon = false ;
// todo
for ( int x : startX ) {
for ( int i = 0 ; i < startX . length ; i + + ) {
if ( evtX > = x & & evtX < = x + clodeIcon . getIconWidth ( ) ) {
if ( evtX > = startX [ i ] & & evtX < = startX [ i ] + clodeIcon . getIconWidth ( ) ) {
isOverCloseIcon = true ;
isOverCloseIcon = true ;
break ;
break ;
}
}
@ -787,11 +700,23 @@ public class MultiTemplateTabPane extends Row {
return evtX > = ( maxWidth + SMALLGAP ) & & evtX < = ( getWidth ( ) - SMALLGAP ) ;
return evtX > = ( maxWidth + SMALLGAP ) & & evtX < = ( getWidth ( ) - SMALLGAP ) ;
}
}
/ * *
* 判断是否在tab栏空白区
*
* @param evtX x坐标
* @return 是否在tab栏空白区
* /
private boolean isOverBlank ( int evtX ) {
int tabWidths = ( maxPaintIndex - minPaintIndex + 1 ) * tabWidth ;
int leftX = tabWidths + scale ( LEADING_WIDTH ) ;
return evtX > = leftX & & evtX < = getWidth ( ) - scale ( TRAILING_WIDTH ) ;
}
private int getTemplateIndex ( int evtX ) {
private int getTemplateIndex ( int evtX ) {
int textX = scale ( LEADING_WIDTH ) ;
int textX = scale ( LEADING_WIDTH ) ;
for ( int i = minPaintIndex ; i < = maxPaintIndex ; i + + ) {
for ( int i = minPaintIndex ; i < = maxPaintIndex ; i + + ) {
int textWidth = showJTemplateTab ( openedTemplate . get ( i ) ) ? tabWidth : 0 ;
int textWidth = tabWidth ;
if ( evtX > = textX & & evtX < textX + textWidth ) {
if ( evtX > = textX & & evtX < textX + textWidth ) {
return i ;
return i ;
}
}
@ -854,6 +779,15 @@ public class MultiTemplateTabPane extends Row {
MultiTemplateTabPane . this . repaint ( ) ;
MultiTemplateTabPane . this . repaint ( ) ;
}
}
@Override
public void mouseClicked ( MouseEvent e ) {
// 双击添加模板
if ( e . getClickCount ( ) = = DOUBLE_CLICK
& & isOverBlank ( e . getX ( ) ) ) {
newTemplateAction . actionPerformed ( null ) ;
}
}
/ * *
/ * *
* 按下
* 按下
*
*
@ -971,28 +905,6 @@ public class MultiTemplateTabPane extends Row {
}
}
}
}
/ * *
* 判断是否显示在tab栏上
*
* @param jTemplate
* @return
* /
private boolean showJTemplateTab ( JTemplate jTemplate ) {
JTemplate current = HistoryTemplateListCache . getInstance ( ) . getCurrentEditingTemplate ( ) ;
return ComparatorUtils . equals ( current . getTemplateTabOperatorType ( ) , jTemplate . getTemplateTabOperatorType ( ) ) ;
}
/ * *
* 获取tab操作类型的模板
*
* @param operator
* @return
* /
public List < JTemplate < ? , ? > > getOpenedJTemplatesByOperator ( String operator ) {
return openedTemplate . stream ( ) . filter ( ( jTemplate ) - > ComparatorUtils . equals ( jTemplate . getTemplateTabOperatorType ( ) , operator ) )
. collect ( Collectors . toList ( ) ) ;
}
/ * *
/ * *
* 获取所有模板
* 获取所有模板
*
*
@ -1002,16 +914,6 @@ public class MultiTemplateTabPane extends Row {
return Collections . unmodifiableList ( openedTemplate ) ;
return Collections . unmodifiableList ( openedTemplate ) ;
}
}
/ * *
* 根据tab操作类型进行分类
*
* @return
* /
public Map < String , List < JTemplate < ? , ? > > > getOpenedJTemplatesByCategory ( ) {
return openedTemplate . stream ( )
. collect ( Collectors . groupingBy ( JTemplate : : getTemplateTabOperatorType ) ) ;
}
/ * *
/ * *
* 返回当前tab数量
* 返回当前tab数量
*
*