Browse Source

无 JIRA 任务,处理圈复杂度的问题

feature/x
Harrison 2 years ago
parent
commit
d896eaca45
  1. 59
      designer-base/src/main/java/com/fr/start/BaseDesigner.java
  2. 28
      designer-base/src/main/java/com/fr/startup/ui/StartupPageModel.java
  3. 9
      designer-base/src/main/java/com/fr/startup/ui/StartupPageWorkspacePanel.java

59
designer-base/src/main/java/com/fr/start/BaseDesigner.java

@ -169,6 +169,19 @@ public abstract class BaseDesigner extends ToolBarMenuDock {
}
private void openTemplate0(DesignerFrame df, AtomicBoolean isException, FILE file) {
file = getExtraFILE(isException, file);
if (file != null && file.exists() && !isException.get()) {
df.openTemplate(file);
} else {
df.addAndActivateJTemplate();
// 如果没有模板,则需要确认一下
MutilTempalteTabPane.getInstance().setTemTemplate(HistoryTemplateListPane.getInstance().getCurrentEditingTemplate());
}
}
private FILE getExtraFILE(AtomicBoolean isException, FILE file) {
//启动时打开指定文件的接口
DesignerStartOpenFileProcessor processor = ExtraDesignClassManager.getInstance().getSingle(DesignerStartOpenFileProcessor.XML_TAG);
@ -184,14 +197,7 @@ public abstract class BaseDesigner extends ToolBarMenuDock {
isException.set(true);//此时有文件nullpointer异常,执行打开空文件
}
}
if (file != null && file.exists() && !isException.get()) {
df.openTemplate(file);
} else {
df.addAndActivateJTemplate();
// 如果没有模板,则需要确认一下
MutilTempalteTabPane.getInstance().setTemTemplate(HistoryTemplateListPane.getInstance().getCurrentEditingTemplate());
}
return file;
}
private boolean openTemplateOnStartup(DesignerFrame df, AtomicBoolean isException, FILE file) {
@ -200,25 +206,40 @@ public abstract class BaseDesigner extends ToolBarMenuDock {
if (onStartup) {
DesignerStartupContext context = DesignerStartupContext.getInstance();
if (context.isCreateNew()) {
df.addAndActivateJTemplate();
// 如果没有模板,则需要确认一下
MutilTempalteTabPane.getInstance().setTemTemplate(HistoryTemplateListPane.getInstance().getCurrentEditingTemplate());
return true;
return createNewTemplate(df);
}
if (context.isOpenLastFile()) {
if (file != null && file.exists() && !isException.get()) {
df.openTemplate(file);
return true;
}
if (isOpenTemplate(isException, file, context)) {
return openTemplate(df, file);
}
if (context.isOpenEmpty()) {
df.showEmptyJTemplate();
return true;
return openEmpty(df);
}
}
return false;
}
private boolean isOpenTemplate(AtomicBoolean isException, FILE file, DesignerStartupContext context) {
return context.isOpenLastFile() && file != null && file.exists() && !isException.get();
}
private boolean openEmpty(DesignerFrame df) {
df.showEmptyJTemplate();
return true;
}
private boolean openTemplate(DesignerFrame df, FILE file) {
df.openTemplate(file);
return true;
}
private boolean createNewTemplate(DesignerFrame df) {
df.addAndActivateJTemplate();
// 如果没有模板,则需要确认一下
MutilTempalteTabPane.getInstance().setTemTemplate(HistoryTemplateListPane.getInstance().getCurrentEditingTemplate());
return true;
}
private void enableFullScreenMode(Window window) {
String className = "com.apple.eawt.FullScreenUtilities";
String methodName = "setWindowCanFullScreen";

28
designer-base/src/main/java/com/fr/startup/ui/StartupPageModel.java

@ -37,6 +37,8 @@ public class StartupPageModel {
DesignerEnvManager envManager = DesignerEnvManager.getEnvManager();
String curEnvName = envManager.getCurEnvName();
Iterator<String> envNameIterator = envManager.getEnvNameIterator();
Comparator<StartupWorkspaceBean> startupWorkspaceBeanComparator = convertComparator(curEnvName);
List<StartupWorkspaceBean> infos = Lists.newArrayList(envNameIterator)
.stream()
.map((e) -> {
@ -48,18 +50,7 @@ public class StartupPageModel {
return new StartupWorkspaceBean(e, workspaceInfo.getPath(), workspaceInfo.getType());
}
})
.sorted(new Comparator<StartupWorkspaceBean>() {
@Override
public int compare(StartupWorkspaceBean o1, StartupWorkspaceBean o2) {
if (StringUtils.equals(curEnvName, o1.getName())) {
return -1;
}
if (StringUtils.equals(curEnvName, o2.getName())) {
return 1;
}
return 0;
}
})
.sorted(startupWorkspaceBeanComparator)
.collect(Collectors.toList());
Map<String, List<String>> recentFileMap = new HashMap<>();
for (StartupWorkspaceBean info : infos) {
@ -123,4 +114,17 @@ public class StartupPageModel {
public void setOpenEmptyTemplateRunnable(Runnable openEmptyTemplateRunnable) {
this.openEmptyTemplateRunnable = openEmptyTemplateRunnable;
}
private static Comparator<StartupWorkspaceBean> convertComparator(String curEnvName) {
return (o1, o2) -> {
if (StringUtils.equals(curEnvName, o1.getName())) {
return -1;
}
if (StringUtils.equals(curEnvName, o2.getName())) {
return 1;
}
return 0;
};
}
}

9
designer-base/src/main/java/com/fr/startup/ui/StartupPageWorkspacePanel.java

@ -63,7 +63,10 @@ public class StartupPageWorkspacePanel extends JPanel {
private static final Dimension PATH_DIMENSION = new Dimension(100, 20);
private static final Dimension SELECT_WORKSPACE_DIMENSION = new Dimension(210, 72);
private static final Dimension SELECT_CREATE_DIMENSION = new Dimension(60, 72);
public static final int COLUMN_LIMIT = 3;
private static final int COLUMN_LIMIT = 3;
private static final int DOUBLE_CLICK_COUNT = 2;
public static final int PARTITION_LIMIT = 2;
/* model */
@ -95,7 +98,7 @@ public class StartupPageWorkspacePanel extends JPanel {
this.contentPanel = generateLimitContentPanel(partitions);
this.add(contentPanel, BorderLayout.NORTH);
if (partitions.size() > 2) {
if (partitions.size() > PARTITION_LIMIT) {
this.tailPanel = generateTailPanel();
this.add(tailPanel, BorderLayout.SOUTH);
}
@ -378,7 +381,7 @@ public class StartupPageWorkspacePanel extends JPanel {
public void mousePressed(MouseEvent e) {
int clickCount = e.getClickCount();
if (clickCount == 2) {
if (clickCount == DOUBLE_CLICK_COUNT) {
pageModel.setSelectWorkspaceInfo(workspaceInfo);
openEmptyTemplateRunnable.run();
return;

Loading…
Cancel
Save