去除UI库: jfoenix,使用自定义组件

This commit is contained in:
yang 2022-10-12 10:06:16 +08:00
parent 6904b50e2e
commit 7b3fb90865
18 changed files with 99 additions and 111 deletions

View File

@ -34,7 +34,6 @@ javafx {
}
dependencies {
implementation('com.jfoenix:jfoenix:9.0.10')
implementation("com.google.code.gson:gson:2.9.1")
implementation('net.java.dev.jna:jna:5.12.1')
implementation('net.java.dev.jna:jna-platform:5.12.1')
@ -58,20 +57,10 @@ jlink {
imageZip = project.file("${buildDir}/distributions/app-${javafx.platform.classifier}.zip") as RegularFile
options = ['--strip-debug', '--compress', '2', '--no-header-files', '--no-man-pages']
launcher {
name = 'Roomit'
name = 'RoomIt'
}
}
jlinkZip {
group = 'distribution'
}
//
sourceSets {
main {
// resources静态资源文件夹里面的文件
resources {
exclude 'org/rococy/roomit/config.json'
}
}
}

View File

@ -15,7 +15,7 @@
}
},
"keyboard": {
"brush": "CTRL+G",
"brush": "CTRL+SHIFT+K",
"rectangle": "CTRL+R",
"ellipse": "CTRL+Q",
"tools": "CTRL+F",

View File

@ -1 +1 @@
rootProject.name = "roomIt"
rootProject.name = "RoomIt"

View File

@ -2,7 +2,6 @@ module org.rococy.roomit {
requires javafx.controls;
requires javafx.fxml;
requires java.desktop;
requires com.jfoenix;
requires com.google.gson;
requires com.sun.jna;
requires com.sun.jna.platform;

View File

@ -61,7 +61,7 @@ public class MainWindow extends Application {
FXMLLoader fxmlLoader = new FXMLLoader(ResourceUtils.getResource("fxml/mainWindow.fxml"));
Scene scene = new Scene(fxmlLoader.load(), ScreenUtils.getScreenWidth(), ScreenUtils.getScreenHeight());
// 场景背景透明
scene.setFill(Paint.valueOf("#00000000"));
scene.setFill(Paint.valueOf(GlobalConsts.TRANSPARENT_COLOR));
// 设置场景
stage.setScene(scene);

View File

@ -38,7 +38,7 @@ public class SettingWindow extends Application {
FXMLLoader fxmlLoader = new FXMLLoader(ResourceUtils.getResource("fxml/settingWindow.fxml"));
Scene scene = new Scene(fxmlLoader.load());
// 场景填充透明背景
scene.setFill(Paint.valueOf("#00000000"));
scene.setFill(Paint.valueOf(GlobalConsts.TRANSPARENT_COLOR));
// 设置场景
stage.setScene(scene);
// 设置图标

View File

@ -39,7 +39,7 @@ public class ToolsWindow extends Application {
FXMLLoader fxmlLoader = new FXMLLoader(ResourceUtils.getResource("fxml/toolsWindow.fxml"));
Scene scene = new Scene(fxmlLoader.load());
// 透明背景
scene.setFill(Paint.valueOf("#00000000"));
scene.setFill(Paint.valueOf(GlobalConsts.TRANSPARENT_COLOR));
// 设置场景
stage.setScene(scene);
// 设置标题

View File

@ -7,6 +7,7 @@ import javafx.scene.paint.Paint;
import javafx.stage.Screen;
import javafx.stage.Stage;
import javafx.stage.StageStyle;
import org.rococy.roomit.constant.GlobalConsts;
import org.rococy.roomit.util.ResourceUtils;
import java.io.IOException;
@ -30,7 +31,7 @@ public class TrayWindow extends Application {
// 设置场景
stage.setScene(scene);
// 场景填充透明背景
scene.setFill(Paint.valueOf("#00000000"));
scene.setFill(Paint.valueOf(GlobalConsts.TRANSPARENT_COLOR));
// 置顶
stage.setAlwaysOnTop(true);
// 取消任务栏

View File

@ -8,7 +8,6 @@ import org.rococy.roomit.constant.GlobalConsts;
import org.rococy.roomit.domain.*;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.HashMap;
@ -23,10 +22,11 @@ public class ConfigurationManager {
private static ShapeConfiguration shapeConfiguration;
private static KeyBoardConfiguration keyBoardConfiguration;
private static final Path CONFIGURATION_FILE_PATH = Path.of(GlobalConsts.CONFIGURATION_FILE_PATH);
static {
initConfiguration(readConfigFileContent());
try {
initConfiguration(Files.readString(CONFIGURATION_FILE_PATH));
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
Gson gson = new GsonBuilder().setPrettyPrinting().create();
@ -35,11 +35,14 @@ public class ConfigurationManager {
configMap.put("keyboard", keyBoardConfiguration.getKeyBoardMap());
try {
Files.writeString(Path.of(GlobalConsts.CONFIGURATION_FILE_URL), gson.toJson(configMap));
Files.writeString(CONFIGURATION_FILE_PATH, gson.toJson(configMap));
} catch (IOException e) {
e.printStackTrace();
}
}));
} catch (IOException e) {
e.printStackTrace();
}
}
public static BrushConfiguration getBrushConfiguration() {
@ -77,13 +80,4 @@ public class ConfigurationManager {
keyBoardConfiguration = new KeyBoardConfiguration(gson.fromJson(rootObject.get("keyboard"), Map.class));
}
private static String readConfigFileContent() {
try {
return Files.readString(Path.of(GlobalConsts.CONFIGURATION_FILE_URL), StandardCharsets.UTF_8);
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
}

View File

@ -11,6 +11,11 @@ public class GlobalConsts {
*/
public static final String THEME_COLOR = "linear-gradient(to bottom, #f64f59, #c471ed, #12c2e9)";
/**
* 透明色
*/
public static final String TRANSPARENT_COLOR = "#00000000";
/**
* logo图标路径
*/
@ -18,8 +23,7 @@ public class GlobalConsts {
/**
* 配置文件路径
* TODO 完成配置文件路径 打包进image文件夹与bin目录同级
*/
public static final String CONFIGURATION_FILE_URL = "D:\\background\\IdeaProject\\RoomIt\\src\\main\\resources\\org\\rococy\\roomit\\config.json";
public static final String CONFIGURATION_FILE_PATH = System.getProperty("user.dir") + "\\config.json";
}

View File

@ -170,10 +170,9 @@ public class ResizableEllipseWrapper extends Resizer {
* 配置项
*/
private final EllipseConfiguration ellipseConfiguration = ConfigurationManager.getEllipseConfiguration();
private static final String FILL_COLOR = "#00000000";
public InnerEllipse() {
styleMap.addStyle("-fx-fill", FILL_COLOR);
styleMap.addStyle("-fx-fill", GlobalConsts.TRANSPARENT_COLOR);
styleMap.addStyle("-fx-stroke", ellipseConfiguration.getBorderColor());
styleMap.addReactStyle("-fx-stroke-width", ellipseConfiguration.getBorderWidth());
}

View File

@ -2,6 +2,7 @@ package org.rococy.roomit.control;
import javafx.scene.Parent;
import org.rococy.roomit.config.ConfigurationManager;
import org.rococy.roomit.constant.GlobalConsts;
import org.rococy.roomit.control.base.Resizer;
import org.rococy.roomit.domain.RectangleConfiguration;
import org.rococy.roomit.util.ReactStyleMap;
@ -38,7 +39,7 @@ public class ResizableRectangle extends Resizer {
rectangleConfiguration = ConfigurationManager.getRectangleConfiguration();
// 填充颜色边框颜色边框宽度圆角
styleMap.addStyle("-fx-fill", "#00000000");
styleMap.addStyle("-fx-fill", GlobalConsts.TRANSPARENT_COLOR);
styleMap.addStyle("-fx-border-color", rectangleConfiguration.getBorderColor());
styleMap.addStyle("-fx-border-width", rectangleConfiguration.getBorderWidth());
styleMap.addStyle("-fx-border-style", "solid");

View File

@ -0,0 +1,26 @@
package org.rococy.roomit.control;
import javafx.scene.control.Slider;
/**
* 滑动条
*
* @author Rococy
* @date 2022/10/12
*/
public class RoomItSlider extends Slider {
public RoomItSlider() {
// 显示刻度值
this.setShowTickLabels(true);
// 刻度之间的单位距离
this.setMajorTickUnit(1);
this.initEvents();
}
private void initEvents() {
this.setOnMouseReleased(e -> this.setValue(Math.round(this.getValue())));
}
}

View File

@ -1,10 +1,9 @@
package org.rococy.roomit.controller;
import com.jfoenix.controls.JFXSlider;
import com.jfoenix.controls.JFXTextField;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.ScrollPane;
import javafx.scene.control.TextField;
import javafx.scene.control.*;
import javafx.scene.input.KeyEvent;
import javafx.scene.input.MouseEvent;
@ -14,6 +13,7 @@ import javafx.scene.text.Text;
import org.rococy.roomit.config.ConfigurationManager;
import org.rococy.roomit.constant.GlobalConsts;
import org.rococy.roomit.constant.KeyBoardConsts;
import org.rococy.roomit.control.RoomItSlider;
import org.rococy.roomit.domain.BrushConfiguration;
import org.rococy.roomit.domain.EllipseConfiguration;
import org.rococy.roomit.domain.RectangleConfiguration;
@ -61,7 +61,7 @@ public class SettingWindowController {
@FXML
private ColorPicker brushStrokeColorPicker;
@FXML
private JFXSlider brushLineWidthSlider;
private RoomItSlider brushLineWidthSlider;
/**
* 矩形
@ -69,7 +69,7 @@ public class SettingWindowController {
@FXML
private ColorPicker rectangleBorderColorPicker;
@FXML
private JFXSlider rectangleBorderWidthSlider;
private RoomItSlider rectangleBorderWidthSlider;
/**
* 椭圆
@ -77,7 +77,7 @@ public class SettingWindowController {
@FXML
private ColorPicker ellipseBorderColorPicker;
@FXML
private JFXSlider ellipseBorderWidthSlider;
private RoomItSlider ellipseBorderWidthSlider;
@FXML
private RadioButton transparentRadioBtn;
@ -88,23 +88,23 @@ public class SettingWindowController {
* 快捷键
*/
@FXML
private JFXTextField brushKeyboard;
private TextField brushKeyboard;
@FXML
private JFXTextField rectangleKeyboard;
private TextField rectangleKeyboard;
@FXML
private JFXTextField ellipseKeyboard;
private TextField ellipseKeyboard;
@FXML
private JFXTextField toolsKeyboard;
private TextField toolsKeyboard;
@FXML
private JFXTextField colorPickerKeyboard;
private TextField colorPickerKeyboard;
@FXML
private JFXTextField expendMouseKeyboard;
private TextField expendMouseKeyboard;
@FXML
private JFXTextField clearKeyboard;
private TextField clearKeyboard;
@FXML
private JFXTextField screenshotAndCopyKeyboard;
private TextField screenshotAndCopyKeyboard;
@FXML
private JFXTextField openOrCloseKeyboard;
private TextField openOrCloseKeyboard;
@FXML
public void switchSideButtons(MouseEvent event) {
@ -133,7 +133,7 @@ public class SettingWindowController {
@FXML
public void keyboardTextFieldMouseClick(MouseEvent e) {
((JFXTextField) e.getSource()).selectAll();
((TextField) e.getSource()).selectAll();
}
@FXML
@ -142,7 +142,7 @@ public class SettingWindowController {
return;
}
JFXTextField textField = (JFXTextField) e.getSource();
TextField textField = (TextField) e.getSource();
String key = (String) textField.getUserData();
StringJoiner keyBoardJoiner = new StringJoiner("+");
@ -217,20 +217,20 @@ public class SettingWindowController {
}
// 线条颜色
String strokeColor = brushConfiguration.getStrokeColor();
brushStrokeColorPicker.setValue(Color.valueOf(strokeColor.equals(GlobalConsts.THEME_COLOR) ? "#00000000" : strokeColor));
brushStrokeColorPicker.setValue(Color.valueOf(strokeColor.equals(GlobalConsts.THEME_COLOR) ? GlobalConsts.TRANSPARENT_COLOR : strokeColor));
// 线条粗细
brushLineWidthSlider.setValue(brushConfiguration.getLineWidth());
}
private void initRectangleConfiguration() {
String borderColor = rectangleConfiguration.getBorderColor();
rectangleBorderColorPicker.setValue(Color.valueOf(borderColor.equals(GlobalConsts.THEME_COLOR) ? "#00000000" : borderColor));
rectangleBorderColorPicker.setValue(Color.valueOf(borderColor.equals(GlobalConsts.THEME_COLOR) ? GlobalConsts.TRANSPARENT_COLOR : borderColor));
rectangleBorderWidthSlider.setValue(rectangleConfiguration.getBorderWidth());
}
private void initEllipseConfiguration() {
String borderColor = ellipseConfiguration.getBorderColor();
ellipseBorderColorPicker.setValue(Color.valueOf(borderColor.equals(GlobalConsts.THEME_COLOR) ? "#00000000" : borderColor));
ellipseBorderColorPicker.setValue(Color.valueOf(borderColor.equals(GlobalConsts.THEME_COLOR) ? GlobalConsts.TRANSPARENT_COLOR : borderColor));
ellipseBorderWidthSlider.setValue(ellipseConfiguration.getBorderWidth());
}

View File

@ -18,11 +18,6 @@ import java.util.Map;
*/
public class RoomItCursor extends SVGPath {
/**
* 配置项
*/
private static final String FILL_COLOR = GlobalConsts.THEME_COLOR;
/**
* 存储鼠标尺寸的对应关系
*/
@ -51,7 +46,7 @@ public class RoomItCursor extends SVGPath {
this.setRotate(-15);
// 设置渐变色
this.setStyle("-fx-fill: " + FILL_COLOR);
this.setStyle("-fx-fill: " + GlobalConsts.THEME_COLOR);
// small -> 0
LogoPosition smallLogo = new LogoPosition(28, 8, 27, 10, 32, 13);
@ -95,7 +90,7 @@ public class RoomItCursor extends SVGPath {
public void hide() {
this.setOpacity(0);
this.mouseSymbol.fillColor("#00000000");
this.mouseSymbol.fillColor(GlobalConsts.TRANSPARENT_COLOR);
}
public void setCursorLogo(MouseSymbol mouseSymbol) {

View File

@ -65,7 +65,7 @@
}
.keyboard-wrapper .label {
-fx-padding: 6px 5px 0 0;
-fx-padding: 0px 5px 3px 0;
-fx-font-size: 14px;
}
@ -74,27 +74,6 @@
}
/* 滑动条轨道 */
.jfx-slider {
-fx-padding: 1px 0 0;
-jfx-default-thumb: #dfdfdf;
-jfx-default-track: rgba(229, 229, 229, 0.53);
}
.jfx-slider .track {
-fx-pref-height: 8px;
}
.jfx-slider .slider-value {
-fx-stroke: #545151;
-fx-font-size: 10.0;
}
.jfx-text-field {
-fx-pref-width: 200px;
-fx-text-fill: #525252;
-fx-font-size: 13px;
-fx-prompt-text-fill: #ccc;
-jfx-unfocus-color: #525252;
-jfx-focus-color: #525252;
.text-field {
-fx-alignment: center;
}

View File

@ -1,9 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import com.jfoenix.controls.JFXSlider?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import com.jfoenix.controls.JFXTextField?>
<?import org.rococy.roomit.control.RoomItSlider?>
<HBox xmlns:fx="http://javafx.com/fxml"
fx:controller="org.rococy.roomit.controller.SettingWindowController"
stylesheets="@../css/setting.css"
@ -48,7 +48,7 @@
<HBox style="-fx-spacing: 10px">
<Label style="-fx-padding: 0px 0">线条粗细:</Label>
<JFXSlider fx:id="brushLineWidthSlider" styleClass="jfx-slider" min="1" max="10"
<RoomItSlider fx:id="brushLineWidthSlider" styleClass="jfx-slider" min="1" max="10"
blockIncrement="1"/>
</HBox>
</VBox>
@ -64,7 +64,7 @@
<HBox style="-fx-spacing: 10px">
<Label style="-fx-padding: 0px 0">边框粗细:</Label>
<JFXSlider fx:id="rectangleBorderWidthSlider" styleClass="jfx-slider" min="1" max="10"
<RoomItSlider fx:id="rectangleBorderWidthSlider" styleClass="jfx-slider" min="1" max="10"
blockIncrement="1"/>
</HBox>
</VBox>
@ -80,7 +80,7 @@
<HBox style="-fx-spacing: 10px">
<Label style="-fx-padding: 0px 0">边框粗细:</Label>
<JFXSlider fx:id="ellipseBorderWidthSlider" styleClass="jfx-slider" min="1" max="10"
<RoomItSlider fx:id="ellipseBorderWidthSlider" styleClass="jfx-slider" min="1" max="10"
blockIncrement="1"/>
</HBox>
</VBox>
@ -109,55 +109,55 @@
</rowConstraints>
<Label styleClass="label" GridPane.rowIndex="1" GridPane.columnIndex="1">切换为画笔:</Label>
<JFXTextField fx:id="brushKeyboard" userData="brush" editable="false"
<TextField fx:id="brushKeyboard" userData="brush" editable="false"
onKeyPressed="#keyboardTextFieldKeyPress"
onMouseClicked="#keyboardTextFieldMouseClick"
styleClass="jfx-text-field" GridPane.rowIndex="1" GridPane.columnIndex="2"/>
<Label styleClass="label" GridPane.rowIndex="2" GridPane.columnIndex="1">切换为矩形:</Label>
<JFXTextField fx:id="rectangleKeyboard" userData="rectangle" editable="false"
<TextField fx:id="rectangleKeyboard" userData="rectangle" editable="false"
onKeyPressed="#keyboardTextFieldKeyPress"
onMouseClicked="#keyboardTextFieldMouseClick" GridPane.rowIndex="2"
GridPane.columnIndex="2"/>
<Label styleClass="label" GridPane.rowIndex="3" GridPane.columnIndex="1">切换为椭圆:</Label>
<JFXTextField fx:id="ellipseKeyboard" userData="ellipse" editable="false"
<TextField fx:id="ellipseKeyboard" userData="ellipse" editable="false"
onKeyPressed="#keyboardTextFieldKeyPress"
onMouseClicked="#keyboardTextFieldMouseClick" GridPane.rowIndex="3"
GridPane.columnIndex="2"/>
<Label styleClass="label" GridPane.rowIndex="4" GridPane.columnIndex="1">弹出工具箱:</Label>
<JFXTextField fx:id="toolsKeyboard" userData="tools" editable="false"
<TextField fx:id="toolsKeyboard" userData="tools" editable="false"
onKeyPressed="#keyboardTextFieldKeyPress"
onMouseClicked="#keyboardTextFieldMouseClick" GridPane.rowIndex="4"
GridPane.columnIndex="2"/>
<Label styleClass="label" GridPane.rowIndex="5" GridPane.columnIndex="1">弹出颜色框:</Label>
<JFXTextField fx:id="colorPickerKeyboard" userData="colorPicker" editable="false"
<TextField fx:id="colorPickerKeyboard" userData="colorPicker" editable="false"
onKeyPressed="#keyboardTextFieldKeyPress"
onMouseClicked="#keyboardTextFieldMouseClick" GridPane.rowIndex="5"
GridPane.columnIndex="2"/>
<Label styleClass="label" GridPane.rowIndex="6" GridPane.columnIndex="1">放大鼠标:</Label>
<JFXTextField fx:id="expendMouseKeyboard" userData="expendMouse" editable="false"
<TextField fx:id="expendMouseKeyboard" userData="expendMouse" editable="false"
onKeyPressed="#keyboardTextFieldKeyPress"
onMouseClicked="#keyboardTextFieldMouseClick" GridPane.rowIndex="6"
GridPane.columnIndex="2"/>
<Label styleClass="label" GridPane.rowIndex="7" GridPane.columnIndex="1">清空画板:</Label>
<JFXTextField fx:id="clearKeyboard" userData="clear" editable="false"
<TextField fx:id="clearKeyboard" userData="clear" editable="false"
onKeyPressed="#keyboardTextFieldKeyPress"
onMouseClicked="#keyboardTextFieldMouseClick" GridPane.rowIndex="7"
GridPane.columnIndex="2"/>
<Label styleClass="label" GridPane.rowIndex="8" GridPane.columnIndex="1">截图并复制:</Label>
<JFXTextField fx:id="screenshotAndCopyKeyboard" userData="screenshotAndCopy" editable="false"
<TextField fx:id="screenshotAndCopyKeyboard" userData="screenshotAndCopy" editable="false"
onKeyPressed="#keyboardTextFieldKeyPress"
onMouseClicked="#keyboardTextFieldMouseClick"
GridPane.rowIndex="8" GridPane.columnIndex="2"/>
<Label styleClass="label" GridPane.rowIndex="9" GridPane.columnIndex="1">启动或关闭:</Label>
<JFXTextField fx:id="openOrCloseKeyboard" userData="openOrClose" editable="false"
<TextField fx:id="openOrCloseKeyboard" userData="openOrClose" editable="false"
onKeyPressed="#keyboardTextFieldKeyPress"
onMouseClicked="#keyboardTextFieldMouseClick" GridPane.rowIndex="9"
GridPane.columnIndex="2"/>

View File

@ -4,6 +4,7 @@
<?import javafx.scene.image.ImageView?>
<?import javafx.scene.layout.TilePane?>
<?import javafx.scene.layout.VBox?>
<TilePane xmlns="http://javafx.com/javafx"
xmlns:fx="http://javafx.com/fxml"
fx:id="container"