Skip to content

Commit 93e3ea8

Browse files
committed
optimize Setting
1 parent 1e1c6b1 commit 93e3ea8

File tree

8 files changed

+595
-166
lines changed

8 files changed

+595
-166
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package com.shuzijun.leetcode.plugin.listener;
2+
3+
import com.intellij.ui.ColorPicker;
4+
5+
import javax.swing.*;
6+
import java.awt.*;
7+
import java.awt.event.MouseAdapter;
8+
import java.awt.event.MouseEvent;
9+
10+
/**
11+
* @author shuzijun
12+
*/
13+
public class ColorListener extends MouseAdapter {
14+
private JLabel label;
15+
private JPanel mainPanel;
16+
17+
public ColorListener(JPanel mainPanel,JLabel label) {
18+
this.mainPanel = mainPanel;
19+
this.label = label;
20+
}
21+
22+
@Override
23+
public void mouseClicked(MouseEvent e) {
24+
Color newColor = ColorPicker.showDialog(mainPanel, label.getText()+" Color", label.getForeground(), true, null, true);
25+
if(newColor!=null){
26+
label.setForeground(newColor);
27+
}
28+
}
29+
30+
31+
}

src/main/java/com/shuzijun/leetcode/plugin/model/Config.java

Lines changed: 75 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.intellij.util.xmlb.annotations.Transient;
44

5+
import java.awt.*;
56
import java.util.ArrayList;
67
import java.util.HashMap;
78
import java.util.List;
@@ -82,7 +83,7 @@ public class Config {
8283
/**
8384
* 题目颜色
8485
*/
85-
private String levelColour = "#5CB85C;#F0AD4E;#D9534F";
86+
private String levelColour = Constant.LEVEL_COLOUR;
8687

8788
private List<String> favoriteList;
8889

@@ -232,8 +233,57 @@ public String getCookie(String user) {
232233
public String getLevelColour() {
233234
return levelColour;
234235
}
236+
@Transient
237+
public Color[] getFormatLevelColour() {
238+
Color[] formatColors = new Color[3];
239+
formatColors[0] = new Color(92, 184, 92);
240+
formatColors[1] = new Color(240, 173, 78);
241+
formatColors[2] = new Color(217, 83, 79);
242+
String[] colors = getLevelColour().split(";");
243+
if (colors.length > 0) {
244+
try {
245+
formatColors[0] = new Color(Integer.parseInt(colors[0].replace("#", ""), 16));
246+
} catch (Exception ignore) {
247+
}
248+
}
249+
if (colors.length > 1) {
250+
try {
251+
formatColors[1] = new Color(Integer.parseInt(colors[1].replace("#", ""), 16));
252+
} catch (Exception ignore) {
253+
}
254+
}
255+
if (colors.length > 2) {
256+
try {
257+
formatColors[2] = new Color(Integer.parseInt(colors[2].replace("#", ""), 16));
258+
} catch (Exception ignore) {
259+
}
260+
}
261+
return formatColors;
262+
}
235263

236264
public void setLevelColour(String levelColour) {
265+
if(levelColour ==null || levelColour.isEmpty()){
266+
this.levelColour = Constant.LEVEL_COLOUR;
267+
}else {
268+
this.levelColour = levelColour;
269+
}
270+
}
271+
272+
@Transient
273+
public void setFormatLevelColour(Color... colors) {
274+
String levelColour = "";
275+
if (colors != null && colors.length > 0) {
276+
for (Color color : colors) {
277+
String R = Integer.toHexString(color.getRed());
278+
R = R.length() < 2 ? ('0' + R) : R;
279+
String G = Integer.toHexString(color.getGreen());
280+
G = G.length() < 2 ? ('0' + G) : G;
281+
String B = Integer.toHexString(color.getBlue());
282+
B = B.length() < 2 ? ('0' + B) : B;
283+
284+
levelColour = levelColour + '#' + R + G + B + ";";
285+
}
286+
}
237287
this.levelColour = levelColour;
238288
}
239289

@@ -244,4 +294,28 @@ public Boolean getEnglishContent() {
244294
public void setEnglishContent(Boolean englishContent) {
245295
this.englishContent = englishContent;
246296
}
297+
298+
299+
public boolean isModified(Config config){
300+
if(config ==null){
301+
return false;
302+
}
303+
if (version != null ? !version.equals(config.version) : config.version != null) return false;
304+
if (loginName != null ? !loginName.equals(config.loginName) : config.loginName != null) return false;
305+
if (filePath != null ? !filePath.equals(config.filePath) : config.filePath != null) return false;
306+
if (codeType != null ? !codeType.equals(config.codeType) : config.codeType != null) return false;
307+
if (url != null ? !url.equals(config.url) : config.url != null) return false;
308+
if (update != null ? !update.equals(config.update) : config.update != null) return false;
309+
if (proxy != null ? !proxy.equals(config.proxy) : config.proxy != null) return false;
310+
if (customCode != null ? !customCode.equals(config.customCode) : config.customCode != null) return false;
311+
if (englishContent != null ? !englishContent.equals(config.englishContent) : config.englishContent != null)
312+
return false;
313+
if (customFileName != null ? !customFileName.equals(config.customFileName) : config.customFileName != null)
314+
return false;
315+
if (customTemplate != null ? !customTemplate.equals(config.customTemplate) : config.customTemplate != null)
316+
return false;
317+
return levelColour != null ? levelColour.equals(config.levelColour) : config.levelColour == null;
318+
}
319+
320+
247321
}

src/main/java/com/shuzijun/leetcode/plugin/model/Constant.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,4 +72,9 @@ public class Constant {
7272
public static final Integer PLUGIN_CONFIG_VERSION_1 = 1;
7373
//第二版本,不兼容之前的临时目录,从此版本开始更换新临时目录
7474
public static final Integer PLUGIN_CONFIG_VERSION_2 = 2;
75+
76+
/**
77+
* 默认题目颜色
78+
*/
79+
public static final String LEVEL_COLOUR = "#5CB85C;#F0AD4E;#D9534F";
7580
}

src/main/java/com/shuzijun/leetcode/plugin/renderer/CustomTreeCellRenderer.java

Lines changed: 11 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import com.shuzijun.leetcode.plugin.model.Config;
66
import com.shuzijun.leetcode.plugin.model.Question;
77
import com.shuzijun.leetcode.plugin.setting.PersistentConfig;
8-
import org.apache.commons.lang.StringUtils;
98

109
import javax.imageio.ImageIO;
1110
import javax.swing.*;
@@ -19,36 +18,22 @@
1918
*/
2019
public class CustomTreeCellRenderer extends NodeRenderer {
2120

22-
private Color Level1 = new Color(92, 184, 92);
23-
private Color Level2 = new Color(240, 173, 78);
24-
private Color Level3 = new Color(217, 83, 79);
21+
private static Color Level1 = new Color(92, 184, 92);
22+
private static Color Level2 = new Color(240, 173, 78);
23+
private static Color Level3 = new Color(217, 83, 79);
2524

2625
public CustomTreeCellRenderer() {
26+
loaColor();
27+
}
28+
29+
public static void loaColor(){
2730
Config config = PersistentConfig.getInstance().getInitConfig();
2831
if (config != null) {
29-
if (StringUtils.isNotBlank(config.getLevelColour())) {
30-
String[] colors = config.getLevelColour().split(";");
31-
if (colors.length > 0) {
32-
try {
33-
Level1 = new Color(Integer.parseInt(colors[0].replace("#",""), 16));
34-
} catch (Exception ignore) {
35-
}
36-
}
37-
if (colors.length > 1) {
38-
try {
39-
Level2 = new Color(Integer.parseInt(colors[1].replace("#",""), 16));
40-
} catch (Exception ignore) {
41-
}
42-
}
43-
if (colors.length > 2) {
44-
try {
45-
Level3 = new Color(Integer.parseInt(colors[2].replace("#",""), 16));
46-
} catch (Exception ignore) {
47-
}
48-
}
49-
}
32+
Color[] colors = config.getFormatLevelColour();
33+
Level1 = colors[0];
34+
Level2 = colors[1];
35+
Level3 = colors[2];
5036
}
51-
5237
}
5338

5439
public static BufferedImage getResourceBufferedImage(String filePath) {
@@ -71,7 +56,6 @@ public void customizeCellRenderer(JTree tree, Object value, boolean selected, bo
7156
DefaultMutableTreeNode node = (DefaultMutableTreeNode) value;
7257
Question question = (Question) node.getUserObject();
7358

74-
7559
if (question.getLevel() == null) {
7660

7761
} else if (question.getLevel() == 1) {

src/main/java/com/shuzijun/leetcode/plugin/setting/SettingConfigurable.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ public Runnable enableSearch(String option) {
4545
@Override
4646
public JComponent createComponent() {
4747
mainPanel = new SettingUI();
48-
mainPanel.createUI();
4948
return mainPanel.getContentPane();
5049
}
5150

@@ -69,4 +68,5 @@ public void disposeUIResources() {
6968
mainPanel.disposeUIResources();
7069
mainPanel = null;
7170
}
71+
7272
}

0 commit comments

Comments
 (0)