优化细节,删除无效代码。

This commit is contained in:
javas 2018-01-12 14:13:23 +08:00
parent f991436ccf
commit 54c72df3d9
3 changed files with 10 additions and 285 deletions

View File

@ -28,7 +28,7 @@ public abstract class AbstractGroupPanel<T extends AbstractGroup<T,E>, E extends
String currGroupName;
protected Map<String, T> group;
Map<String, T> group;
AbstractGroupPanel(Map<String, T> group, String selectGroupName) {
itemGroupPanel.setLayout(new VerticalFlowLayout());
@ -237,39 +237,39 @@ public abstract class AbstractGroupPanel<T extends AbstractGroup<T,E>, E extends
protected abstract E createItem(String name);
//所有元素Get方法
public JPanel getMainPanel() {
JPanel getMainPanel() {
return mainPanel;
}
public JComboBox getGroupComboBox() {
JComboBox getGroupComboBox() {
return groupComboBox;
}
public JButton getCopyGroupButton() {
JButton getCopyGroupButton() {
return copyGroupButton;
}
public JButton getDeleteGroupButton() {
JButton getDeleteGroupButton() {
return deleteGroupButton;
}
public JButton getAddItemButton() {
JButton getAddItemButton() {
return addItemButton;
}
public JButton getDeleteItemButton() {
JButton getDeleteItemButton() {
return deleteItemButton;
}
public JButton getCopyItemButton() {
JButton getCopyItemButton() {
return copyItemButton;
}
public JPanel getItemGroupPanel() {
JPanel getItemGroupPanel() {
return itemGroupPanel;
}
public JPanel getItemPanel() {
JPanel getItemPanel() {
return itemPanel;
}
}

View File

@ -1,100 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.sjhy.plugin.ui.TemplateSetting">
<grid id="27dc6" binding="mainPanel" layout-manager="GridLayoutManager" row-count="3" column-count="6" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<xy x="20" y="33" width="586" height="454"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<tabbedpane id="272b3" binding="templateTabbedPane">
<constraints>
<grid row="1" column="0" row-span="2" col-span="5" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false">
<preferred-size width="200" height="200"/>
</grid>
</constraints>
<properties/>
<border type="none"/>
<children/>
</tabbedpane>
<component id="ffaa3" class="javax.swing.JLabel">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<labelFor value="e5431"/>
<text resource-bundle="string" key="label.template.group"/>
</properties>
</component>
<component id="e5431" class="javax.swing.JComboBox" binding="groupButton">
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="8" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="150" height="-1"/>
</grid>
</constraints>
<properties/>
</component>
<grid id="e30b5" layout-manager="GridLayoutManager" row-count="3" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="2" column="5" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="eedcb" class="javax.swing.JButton" binding="removeButton">
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<icon value="actions/delete.png"/>
</properties>
</component>
<vspacer id="1da1">
<constraints>
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
</constraints>
</vspacer>
<component id="ee190" class="javax.swing.JButton" binding="addButton">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<icon value="general/add.png"/>
</properties>
</component>
</children>
</grid>
<component id="9d5e2" class="javax.swing.JButton" binding="deleteButton">
<constraints>
<grid row="0" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<icon value="actions/delete.png"/>
</properties>
</component>
<component id="96a1b" class="javax.swing.JButton" binding="copyGroupButton">
<constraints>
<grid row="0" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<icon value="actions/copy.png"/>
</properties>
</component>
<hspacer id="2b805">
<constraints>
<grid row="0" column="4" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
</hspacer>
<component id="76ed0" class="javax.swing.JLabel">
<constraints>
<grid row="1" column="5" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text resource-bundle="string" key="label.operate"/>
</properties>
</component>
</children>
</grid>
</form>

View File

@ -1,175 +0,0 @@
package com.sjhy.plugin.ui;
import com.intellij.openapi.options.Configurable;
import com.sjhy.plugin.entity.Template;
import com.sjhy.plugin.entity.TemplateGroup;
import com.sjhy.plugin.service.ConfigService;
import org.jetbrains.annotations.Nls;
import org.jetbrains.annotations.Nullable;
import javax.swing.*;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
public class TemplateSetting implements Configurable {
private JPanel mainPanel;
private JButton copyGroupButton;
private JButton deleteButton;
private JTabbedPane templateTabbedPane;
private JComboBox groupButton;
private JButton addButton;
private JButton removeButton;
private List<EditTemplatePanel> editTemplatePanelList = new ArrayList<>();
private Map<String, TemplateGroup> templateGroupMap;
private String currGroupName;
private ConfigService configService;
private Boolean init = false;
private TemplateGroup getTemplateGroup() {
return this.templateGroupMap.get(currGroupName);
}
TemplateSetting(ConfigService configService) {
this.configService = configService;
//新增选项卡
addButton.addActionListener(e -> {
String value = JOptionPane.showInputDialog(null, "Input Tab Name:", "Demo");
if (value==null) {
return;
}
if (value.trim().length()==0){
JOptionPane.showMessageDialog(null, "Tab Name Can't Is Empty!");
return;
}
for (Template template : getTemplateGroup().getElementList()) {
if (template.getName().equals(value)){
JOptionPane.showMessageDialog(null, "Tab Name Already exist!");
return;
}
}
getTemplateGroup().getElementList().add(new Template(value, ""));
refresh();
});
//删除选项卡
removeButton.addActionListener(e -> {
getTemplateGroup().getElementList().remove(templateTabbedPane.getSelectedIndex());
refresh();
});
//切换分组
this.groupButton.addActionListener(e -> {
if (!init) {
return;
}
String val = (String) groupButton.getSelectedItem();
if (val==null) {
return;
}
if (val.equals(currGroupName)){
return;
}
currGroupName = val;
refresh();
});
//复制分组
copyGroupButton.addActionListener(e -> {
String value = JOptionPane.showInputDialog(null, "Input Group Name:", currGroupName+" Copy");
if (value==null) {
return;
}
if (value.trim().length()==0){
JOptionPane.showMessageDialog(null, "Group Name Can't Is Empty!");
return;
}
if (templateGroupMap.containsKey(value)){
JOptionPane.showMessageDialog(null, "Group Name Already exist!");
return;
}
TemplateGroup templateGroup = templateGroupMap.get(currGroupName).clone();
templateGroup.setName(value);
templateGroupMap.put(value, templateGroup);
currGroupName = value;
refresh();
});
//删除分组
deleteButton.addActionListener(e -> {
int result = JOptionPane.showConfirmDialog(null, "Confirm Delete Group "+currGroupName+"?", "温馨提示", JOptionPane.OK_CANCEL_OPTION);
if (result==0){
if(ConfigService.DEFAULT_NAME.equals(currGroupName)){
JOptionPane.showMessageDialog(null, "Can't Delete Default Group!");
return;
}
templateGroupMap.remove(currGroupName);
currGroupName = ConfigService.DEFAULT_NAME;
refresh();
}
});
init();
}
private void init() {
//复制一份
this.templateGroupMap = new LinkedHashMap<>();
configService.getTemplateGroupMap().forEach((s, templateGroup) -> this.templateGroupMap.put(s, templateGroup.clone()));
this.currGroupName = configService.getCurrTemplateGroupName();
refresh();
}
@SuppressWarnings("unchecked")
private void refresh() {
this.init = false;
//初始化分组
this.groupButton.removeAllItems();
this.templateGroupMap.keySet().forEach(this.groupButton::addItem);
this.groupButton.setSelectedItem(this.currGroupName);
//初始化选项卡
editTemplatePanelList.clear();
int count = this.templateTabbedPane.getTabCount();
if (count>0) {
for (int i = 0; i < count; i++) {
this.templateTabbedPane.removeTabAt(0);
}
}
getTemplateGroup().getElementList().forEach(template -> {
EditTemplatePanel editTemplatePanel = new EditTemplatePanel(template);
editTemplatePanelList.add(editTemplatePanel);
this.templateTabbedPane.addTab(template.getName(), editTemplatePanel.getMainPanel());
});
this.init = true;
}
@Nls
@Override
public String getDisplayName() {
return "Template Setting";
}
@Nullable
@Override
public JComponent createComponent() {
return this.mainPanel;
}
@Override
public boolean isModified() {
editTemplatePanelList.forEach(EditTemplatePanel::refresh);
return !configService.getTemplateGroupMap().equals(this.templateGroupMap);
}
@Override
public void apply() {
this.configService.setCurrTemplateGroupName(currGroupName);
this.configService.setTemplateGroupMap(templateGroupMap);
}
@Override
public void reset() {
init();
}
}