|
|
@ -44,6 +44,7 @@ import javax.swing.JSeparator; |
|
|
|
import javax.swing.MenuElement; |
|
|
|
import javax.swing.MenuElement; |
|
|
|
import javax.swing.SwingConstants; |
|
|
|
import javax.swing.SwingConstants; |
|
|
|
import javax.swing.SwingUtilities; |
|
|
|
import javax.swing.SwingUtilities; |
|
|
|
|
|
|
|
import javax.swing.ToolTipManager; |
|
|
|
import javax.swing.plaf.basic.BasicMenuItemUI; |
|
|
|
import javax.swing.plaf.basic.BasicMenuItemUI; |
|
|
|
import java.awt.AWTEvent; |
|
|
|
import java.awt.AWTEvent; |
|
|
|
import java.awt.AlphaComposite; |
|
|
|
import java.awt.AlphaComposite; |
|
|
@ -212,6 +213,35 @@ public class MultiTemplateTabPane extends JComponent { |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* 模板可以关闭的条件 |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
class CloseCondition { |
|
|
|
|
|
|
|
private CloseOption closeOption; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public CloseCondition(CloseOption closeOption) { |
|
|
|
|
|
|
|
this.closeOption = closeOption; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* 判断模板是否可以关闭,两个条件:1、是否满足CloseOption里面的条件(在左侧、在右侧等)2、是否和当前正在编辑模板属于同一种模板tab操作类型 |
|
|
|
|
|
|
|
* @param closeJTemplate |
|
|
|
|
|
|
|
* @param tplIndex |
|
|
|
|
|
|
|
* @param i |
|
|
|
|
|
|
|
* @return |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public boolean shouldClose(JTemplate closeJTemplate, int tplIndex, int i) { |
|
|
|
|
|
|
|
boolean matchOption = this.closeOption.shouldClose(tplIndex, i); |
|
|
|
|
|
|
|
JTemplate currentTemplate = HistoryTemplateListCache.getInstance().getCurrentEditingTemplate(); |
|
|
|
|
|
|
|
if (!JTemplate.isValid(currentTemplate)) { |
|
|
|
|
|
|
|
return matchOption; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return matchOption && ComparatorUtils.equals(closeJTemplate.getTemplateTabOperatorType(), |
|
|
|
|
|
|
|
currentTemplate.getTemplateTabOperatorType()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
enum CloseOption { |
|
|
|
enum CloseOption { |
|
|
|
Left(Toolkit.i18nText("Fine-Design_Close_templates_To_The_Left")) { |
|
|
|
Left(Toolkit.i18nText("Fine-Design_Close_templates_To_The_Left")) { |
|
|
|
@Override |
|
|
|
@Override |
|
|
@ -324,14 +354,15 @@ public class MultiTemplateTabPane extends JComponent { |
|
|
|
public void actionPerformed(ActionEvent e) { |
|
|
|
public void actionPerformed(ActionEvent e) { |
|
|
|
//只有关闭所有模板才需要判断当前模板,关闭左侧、右侧、其他都不需要
|
|
|
|
//只有关闭所有模板才需要判断当前模板,关闭左侧、右侧、其他都不需要
|
|
|
|
SaveSomeTemplatePane saveSomeTemplatePane = new SaveSomeTemplatePane(option == CloseOption.All); |
|
|
|
SaveSomeTemplatePane saveSomeTemplatePane = new SaveSomeTemplatePane(option == CloseOption.All); |
|
|
|
if (saveSomeTemplatePane.showSavePane(option, false)) { |
|
|
|
CloseCondition closeCondition = new CloseCondition(option); |
|
|
|
|
|
|
|
if (saveSomeTemplatePane.showSavePane(closeCondition, false)) { |
|
|
|
|
|
|
|
|
|
|
|
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); |
|
|
|
} |
|
|
|
} |
|
|
|
JTemplate<?, ?> currentTemplate = HistoryTemplateListCache.getInstance().getCurrentEditingTemplate(); |
|
|
|
JTemplate<?, ?> currentTemplate = HistoryTemplateListCache.getInstance().getCurrentEditingTemplate(); |
|
|
|
closeTemplate(templates, currentTemplate); |
|
|
|
closeTemplate(closeCondition, templates, currentTemplate); |
|
|
|
|
|
|
|
|
|
|
|
if (openedTemplate.size() == 0) { |
|
|
|
if (openedTemplate.size() == 0) { |
|
|
|
DesignerContext.getDesignerFrame().addAndActivateJTemplate(); |
|
|
|
DesignerContext.getDesignerFrame().addAndActivateJTemplate(); |
|
|
@ -346,10 +377,9 @@ public class MultiTemplateTabPane extends JComponent { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void closeTemplate(JTemplate<?, ?>[] templates, JTemplate<?, ?> currentTemplate) { |
|
|
|
private void closeTemplate(CloseCondition closeCondition, JTemplate<?, ?>[] templates, JTemplate<?, ?> currentTemplate) { |
|
|
|
String operator = currentTemplate.getTemplateTabOperatorType(); |
|
|
|
|
|
|
|
for (int i = 0; i < templates.length; i++) { |
|
|
|
for (int i = 0; i < templates.length; i++) { |
|
|
|
if (option.shouldClose(tplIndex, i) && ComparatorUtils.equals(operator, templates[i].getTemplateTabOperatorType())) { |
|
|
|
if (closeCondition.shouldClose(templates[i], 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]; |
|
|
@ -727,6 +757,58 @@ public class MultiTemplateTabPane extends JComponent { |
|
|
|
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; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -998,9 +1080,12 @@ public class MultiTemplateTabPane extends JComponent { |
|
|
|
// selectIndex 没有变化,但是对应的模板已经变成了前一张模板
|
|
|
|
// selectIndex 没有变化,但是对应的模板已经变成了前一张模板
|
|
|
|
if (closeIconIndex == selectedIndex || isCloseCurrent) { |
|
|
|
if (closeIconIndex == selectedIndex || isCloseCurrent) { |
|
|
|
// 如果当前关闭的模板在最右侧,那么预览上一个,防止数组越界
|
|
|
|
// 如果当前关闭的模板在最右侧,那么预览上一个,防止数组越界
|
|
|
|
|
|
|
|
// 关闭的模板是当前选中的模板时,需要重新计算下一个待展示的模板的index
|
|
|
|
if (selectedIndex >= maxPaintIndex) { |
|
|
|
if (selectedIndex >= maxPaintIndex) { |
|
|
|
// selectIndex 不会 <0 因为如果关闭的是打开的最后一个模板,那么关闭之后 openedTemplate.isEmpty() = true
|
|
|
|
// selectIndex 不会 <0 因为如果关闭的是打开的最后一个模板,那么关闭之后 openedTemplate.isEmpty() = true
|
|
|
|
selectedIndex = calNextShowJTemplateIndex(selectedIndex - 1); |
|
|
|
selectedIndex = calNextShowJTemplateIndex(selectedIndex - 1); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
selectedIndex = calNextShowJTemplateIndex(selectedIndex); |
|
|
|
} |
|
|
|
} |
|
|
|
isCloseCurrent = false; |
|
|
|
isCloseCurrent = false; |
|
|
|
} |
|
|
|
} |
|
|
@ -1121,6 +1206,7 @@ public class MultiTemplateTabPane extends JComponent { |
|
|
|
|
|
|
|
|
|
|
|
private class MultiTemplateTabMouseListener implements MouseListener { |
|
|
|
private class MultiTemplateTabMouseListener implements MouseListener { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private boolean oldLightWeightPopupEnabled; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 鼠标进入 |
|
|
|
* 鼠标进入 |
|
|
@ -1129,7 +1215,8 @@ public class MultiTemplateTabPane extends JComponent { |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void mouseEntered(MouseEvent e) { |
|
|
|
public void mouseEntered(MouseEvent e) { |
|
|
|
// do nothing
|
|
|
|
this.oldLightWeightPopupEnabled = ToolTipManager.sharedInstance().isLightWeightPopupEnabled(); |
|
|
|
|
|
|
|
ToolTipManager.sharedInstance().setLightWeightPopupEnabled(false); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
@ -1139,6 +1226,9 @@ public class MultiTemplateTabPane extends JComponent { |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void mouseExited(MouseEvent e) { |
|
|
|
public void mouseExited(MouseEvent e) { |
|
|
|
|
|
|
|
ToolTipManager.sharedInstance().setEnabled(false); |
|
|
|
|
|
|
|
ToolTipManager.sharedInstance().setEnabled(true); |
|
|
|
|
|
|
|
ToolTipManager.sharedInstance().setLightWeightPopupEnabled(this.oldLightWeightPopupEnabled); |
|
|
|
listDownMode = LIST_DOWN; |
|
|
|
listDownMode = LIST_DOWN; |
|
|
|
closeIconIndex = -1; |
|
|
|
closeIconIndex = -1; |
|
|
|
mouseOveredIndex = -1; |
|
|
|
mouseOveredIndex = -1; |
|
|
|