Skip to content

Commit 2952604

Browse files
author
xuanxuqaq
committed
支持设置小数边框厚度
1 parent 1edcd44 commit 2952604

File tree

7 files changed

+39
-21
lines changed

7 files changed

+39
-21
lines changed

src/main/java/file/engine/MainClass.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,8 @@ private static void checkVersion() {
169169
* -DFile_Engine_Preview=true
170170
*/
171171
private static void setSystemProperties() {
172+
System.setProperty("awt.useSystemAAFontSettings", "on");
173+
System.setProperty("swing.aatext", "true");
172174
System.setProperty("File_Engine_Preview", "false");
173175
System.setProperty("file.encoding", "UTF-8");
174176
System.setProperty("sun.java2d.noddraw", "true");

src/main/java/file/engine/configs/AllConfigs.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,8 @@ private void readSearchBarFontColor(Map<String, Object> settingsInJson) {
430430
}
431431

432432
private void readBorderThickness(Map<String, Object> settingsInJson) {
433-
configEntity.setBorderThickness(getFromJson(settingsInJson, "borderThickness", 1));
433+
Object borderThickness = getFromJson(settingsInJson, "borderThickness", 1);
434+
configEntity.setBorderThickness(Float.parseFloat(String.valueOf(borderThickness)));
434435
}
435436

436437
private void readLanguage(Map<String, Object> settingsInJson) {

src/main/java/file/engine/configs/ConfigEntity.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public class ConfigEntity {
9999
private String borderType;
100100

101101
@SerializedName("borderThickness")
102-
private int borderThickness;
102+
private float borderThickness;
103103

104104
@SerializedName("roundRadius")
105105
private double roundRadius;

src/main/java/file/engine/event/handler/impl/frame/searchBar/PreviewSearchBarEvent.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public class PreviewSearchBarEvent extends Event {
1212
public final int unchosenLabelFontColor;
1313
public final int defaultBackgroundColor;
1414
public final Constants.Enums.BorderType borderType;
15-
public final int borderThickness;
15+
public final float borderThickness;
1616

1717
public PreviewSearchBarEvent(String borderColor,
1818
String searchBarColor,
@@ -31,7 +31,7 @@ public PreviewSearchBarEvent(String borderColor,
3131
this.chosenLabelFontColor = Integer.parseInt(chosenLabelFontColor, 16);
3232
this.unchosenLabelFontColor = Integer.parseInt(unchosenLabelFontColor, 16);
3333
this.defaultBackgroundColor = Integer.parseInt(defaultBackgroundColor, 16);
34-
this.borderThickness = Integer.parseInt(borderThickness);
34+
this.borderThickness = Float.parseFloat(borderThickness);
3535
this.borderType = borderType;
3636
}
3737
}

src/main/java/file/engine/frames/SearchBar.java

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -188,18 +188,16 @@ private SearchBar() {
188188
* @param positionY Y坐标
189189
* @param searchBarWidth 宽度
190190
* @param searchBarHeight 高度
191-
* @param transparentColor 透明的背景颜色
192-
* @param contentPanel 内容面板
193191
*/
194-
private void initFrame(int positionX, int positionY, int searchBarWidth, int searchBarHeight, Color transparentColor, JPanel contentPanel) {
192+
private void initFrame(int positionX, int positionY, int searchBarWidth, int searchBarHeight) {
195193
//frame
196194
searchBar.setBounds(positionX, positionY, searchBarWidth, searchBarHeight);
197195
searchBar.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
198196
searchBar.setUndecorated(true);
199197
searchBar.getRootPane().setWindowDecorationStyle(JRootPane.NONE);
200-
searchBar.setBackground(transparentColor);
198+
searchBar.setBackground(new Color(0, 0, 0, 0));
201199
searchBar.setOpacity(AllConfigs.getInstance().getConfigEntity().getTransparency());
202-
searchBar.setContentPane(contentPanel);
200+
searchBar.setContentPane(searchBarContentPane);
203201
searchBar.setType(JFrame.Type.UTILITY);
204202
searchBar.setAlwaysOnTop(true);
205203
//用于C++判断是否点击了当前窗口
@@ -224,7 +222,7 @@ private void initGUI() {
224222
labelFontColor = new Color(configs.getFontColor());
225223
initBorder(allConfigs.getBorderType(), new Color(configs.getBorderColor()), configs.getBorderThickness());
226224

227-
initFrame(positionX, positionY, searchBarWidth, searchBarHeight, transparentColor, searchBarContentPane);
225+
initFrame(positionX, positionY, searchBarWidth, searchBarHeight);
228226

229227
int labelHeight = searchBarHeight / 9;
230228
int textFieldHeight = (int) (labelHeight * TEXT_FIELD_HEIGHT_RATIO);
@@ -263,6 +261,7 @@ private void initGUI() {
263261
searchBar.setIconImage(image);
264262
}
265263
//panel
264+
searchBarContentPane.setDoubleBuffered(true);
266265
searchBarContentPane.setBounds(0, 0, searchBarWidth, searchBarHeight);
267266
searchBarContentPane.setLayout(null);
268267
searchBarContentPane.setBackground(transparentColor);
@@ -413,8 +412,9 @@ private void initMenuItems() {
413412
* @param borderColor 边框颜色
414413
* @param borderThickness 边框厚度
415414
*/
416-
private void initBorder(Constants.Enums.BorderType borderType, Color borderColor, int borderThickness) {
415+
private void initBorder(Constants.Enums.BorderType borderType, Color borderColor, float borderThickness) {
417416
double roundRadius = AllConfigs.getInstance().getConfigEntity().getRoundRadius();
417+
int borderThickNessInt = (int) borderThickness;
418418
RoundBorder topRound = new RoundBorder(borderColor,
419419
borderThickness,
420420
(int) roundRadius,
@@ -432,7 +432,7 @@ private void initBorder(Constants.Enums.BorderType borderType, Color borderColor
432432
RoundBorder.ShowLines.ALL);
433433
if (Constants.Enums.BorderType.AROUND == borderType) {
434434
topBorder = topRound;
435-
middleBorder = BorderFactory.createMatteBorder(0, borderThickness, 0, borderThickness, borderColor);
435+
middleBorder = BorderFactory.createMatteBorder(0, borderThickNessInt, 0, borderThickNessInt, borderColor);
436436
bottomBorder = bottomRound;
437437
fullBorder = fullRound;
438438
} else if (Constants.Enums.BorderType.EMPTY == borderType) {
@@ -444,9 +444,9 @@ private void initBorder(Constants.Enums.BorderType borderType, Color borderColor
444444
} else if (borderType == Constants.Enums.BorderType.FULL) {
445445
Border lineBorder = BorderFactory.createMatteBorder(
446446
0,
447-
borderThickness,
448-
borderThickness,
449-
borderThickness,
447+
borderThickNessInt,
448+
borderThickNessInt,
449+
borderThickNessInt,
450450
borderColor);
451451
topBorder = topRound;
452452
middleBorder = lineBorder;
@@ -2588,6 +2588,9 @@ private void addSearchWaiter(AtomicBoolean isWaiting) {
25882588
}
25892589

25902590
private void setSearchBarRadius(int x, int y, double radius, int width, int height) {
2591+
Graphics g = searchBar.getGraphics();
2592+
Graphics2D graphics2d = (Graphics2D) g;
2593+
graphics2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
25912594
searchBar.setShape(new RoundRectangle2D.Double(x, y, width, height, radius, radius));
25922595
}
25932596

@@ -4397,7 +4400,7 @@ private void setSearchBarFontColor(int colorNum) {
43974400
textField.setForeground(new Color(colorNum));
43984401
}
43994402

4400-
private void setBorderColor(Constants.Enums.BorderType borderType, int colorNum, int borderThickness) {
4403+
private void setBorderColor(Constants.Enums.BorderType borderType, int colorNum, float borderThickness) {
44014404
initBorder(borderType, new Color(colorNum), borderThickness);
44024405
}
44034406
}

src/main/java/file/engine/frames/SettingsFrame.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -758,6 +758,19 @@ private boolean canParseInteger(String str, int min, int max) {
758758
}
759759
}
760760

761+
@SuppressWarnings("SameParameterValue")
762+
private boolean canParseFloat(String str, float min, float max) {
763+
try {
764+
float v = Float.parseFloat(str);
765+
if (min <= v && v <= max) {
766+
return true;
767+
}
768+
throw new Exception("parse failed");
769+
} catch (Exception e) {
770+
return false;
771+
}
772+
}
773+
761774
@SuppressWarnings("SameParameterValue")
762775
private boolean canParseDouble(String str, double min, double max) {
763776
try {
@@ -3221,7 +3234,7 @@ private void checkRoundRadius(StringBuilder stringBuilder) {
32213234
}
32223235

32233236
private void checkBorderThickness(StringBuilder stringBuilder) {
3224-
if (!canParseInteger(textFieldBorderThickness.getText(), 1, 4)) {
3237+
if (!canParseFloat(textFieldBorderThickness.getText(), 0, 4)) {
32253238
stringBuilder.append(translateService.getTranslation("Border thickness is too large, please change"));
32263239
}
32273240
}
@@ -3340,7 +3353,7 @@ private ConfigEntity getConfigEntity(boolean isContinuousUpdate) {
33403353
configEntity.setProxyType(Constants.Enums.ProxyType.PROXY_DIRECT);
33413354
}
33423355
configEntity.setUpdateAddress((String) chooseUpdateAddress.getSelectedItem());
3343-
configEntity.setBorderThickness(Integer.parseInt(textFieldBorderThickness.getText()));
3356+
configEntity.setBorderThickness(Float.parseFloat(textFieldBorderThickness.getText()));
33443357
if (borderType == null) {
33453358
borderType = Constants.Enums.BorderType.AROUND;
33463359
}

src/main/java/file/engine/frames/components/RoundBorder.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
public class RoundBorder implements Border {
88
private final Color color;
9-
private final int thickness;
9+
private final float thickness;
1010
private final int borderRadius;
1111
private final int roundedCorners;
1212
private final int showLines;
@@ -84,7 +84,7 @@ private RoundShape(double width, double height, double radius, int roundedCorner
8484
}
8585

8686

87-
public RoundBorder(Color color, int thickness, int roundRadius, int roundedCorners, int showLines) {
87+
public RoundBorder(Color color, float thickness, int roundRadius, int roundedCorners, int showLines) {
8888
// 有参数的构造方法
8989
this.color = color;
9090
this.thickness = thickness;
@@ -104,7 +104,6 @@ public void paintBorder(Component c, Graphics g, int x, int y, int width, int he
104104
graphics2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
105105
graphics2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_GASP);
106106
graphics2d.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY);
107-
graphics2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
108107
graphics2d.setRenderingHint(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_QUALITY);
109108
graphics2d.setRenderingHint(RenderingHints.KEY_DITHERING, RenderingHints.VALUE_DITHER_ENABLE);
110109
graphics2d.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON);

0 commit comments

Comments
 (0)