完成工具箱功能
|
@ -71,12 +71,12 @@ public class MainWindow extends Application {
|
|||
stage.setFullScreenExitHint("");
|
||||
// 置顶
|
||||
stage.setAlwaysOnTop(true);
|
||||
// 禁止缩小
|
||||
stage.setResizable(false);
|
||||
// 设置窗口透明
|
||||
stage.initStyle(StageStyle.TRANSPARENT);
|
||||
// 将窗口显示出来
|
||||
// stage.show();
|
||||
|
||||
new ToolsWindow().show();
|
||||
stage.show();
|
||||
} catch (
|
||||
IOException e) {
|
||||
e.printStackTrace();
|
||||
|
|
|
@ -1,10 +1,13 @@
|
|||
package org.rococy.roomit;
|
||||
|
||||
import javafx.application.Application;
|
||||
import javafx.event.EventHandler;
|
||||
import javafx.fxml.FXMLLoader;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.paint.Paint;
|
||||
import javafx.stage.Modality;
|
||||
import javafx.stage.Stage;
|
||||
import javafx.stage.WindowEvent;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
|
@ -18,7 +21,24 @@ public class ToolsWindow extends Application {
|
|||
|
||||
private final Stage stage = new Stage();
|
||||
|
||||
private static final ToolsWindow TOOLS_WINDOW = new ToolsWindow();
|
||||
|
||||
private ToolsWindow() {
|
||||
}
|
||||
|
||||
public static ToolsWindow getInstance() {
|
||||
return TOOLS_WINDOW;
|
||||
}
|
||||
|
||||
{
|
||||
try {
|
||||
// 加载FXML文件
|
||||
FXMLLoader fxmlLoader = new FXMLLoader(SettingWindow.class.getResource("fxml/toolsWindow.fxml"));
|
||||
Scene scene = new Scene(fxmlLoader.load());
|
||||
// 透明背景
|
||||
scene.setFill(Paint.valueOf("#00000000"));
|
||||
// 设置场景
|
||||
stage.setScene(scene);
|
||||
// 设置标题
|
||||
stage.setTitle("Roomit-工具箱");
|
||||
// 居中
|
||||
|
@ -28,15 +48,16 @@ public class ToolsWindow extends Application {
|
|||
stage.initModality(Modality.APPLICATION_MODAL);
|
||||
// 置顶
|
||||
stage.setAlwaysOnTop(true);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start(Stage stage) throws IOException {
|
||||
// 加载FXML文件
|
||||
FXMLLoader fxmlLoader = new FXMLLoader(SettingWindow.class.getResource("fxml/toolsWindow.fxml"));
|
||||
Scene scene = new Scene(fxmlLoader.load());
|
||||
// 设置场景
|
||||
stage.setScene(scene);
|
||||
if (stage.isShowing()) {
|
||||
return;
|
||||
}
|
||||
// 将窗口显示出来
|
||||
stage.show();
|
||||
}
|
||||
|
@ -49,4 +70,16 @@ public class ToolsWindow extends Application {
|
|||
}
|
||||
}
|
||||
|
||||
public boolean isShowing() {
|
||||
return stage.isShowing();
|
||||
}
|
||||
|
||||
public void setOnHidden(EventHandler<WindowEvent> value) {
|
||||
stage.setOnHidden(value);
|
||||
}
|
||||
|
||||
public void hide() {
|
||||
stage.hide();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -3,10 +3,12 @@ package org.rococy.roomit.control;
|
|||
import javafx.scene.Node;
|
||||
import javafx.scene.canvas.Canvas;
|
||||
import javafx.scene.canvas.GraphicsContext;
|
||||
import javafx.scene.paint.Color;
|
||||
import javafx.scene.paint.Paint;
|
||||
import javafx.scene.shape.StrokeLineCap;
|
||||
import javafx.scene.shape.StrokeLineJoin;
|
||||
import org.rococy.roomit.config.ConfigurationManager;
|
||||
import org.rococy.roomit.constant.GlobalConsts;
|
||||
import org.rococy.roomit.domain.BrushConfiguration;
|
||||
import org.rococy.roomit.domain.CanvasPoint;
|
||||
import org.rococy.roomit.util.ScreenUtils;
|
||||
|
@ -136,7 +138,8 @@ public class RoomItCanvas extends Canvas {
|
|||
private void initGraphics() {
|
||||
gc = this.getGraphicsContext2D();
|
||||
// 画笔颜色
|
||||
gc.setStroke(Paint.valueOf(configuration.getStrokeColor()));
|
||||
String strokeColor = configuration.getStrokeColor();
|
||||
gc.setStroke(Paint.valueOf(strokeColor.equals(GlobalConsts.THEME_COLOR) ? Color.RED.toString() : strokeColor));
|
||||
// 线条宽度
|
||||
gc.setLineWidth(configuration.getLineWidth());
|
||||
// 让线变得圆滑
|
||||
|
|
|
@ -10,10 +10,12 @@ import javafx.scene.input.MouseEvent;
|
|||
import javafx.scene.layout.Background;
|
||||
import javafx.scene.shape.Shape;
|
||||
import javafx.stage.Stage;
|
||||
import org.rococy.roomit.ToolsWindow;
|
||||
import org.rococy.roomit.config.ConfigurationManager;
|
||||
import org.rococy.roomit.constant.KeyBoardConsts;
|
||||
import org.rococy.roomit.control.Container;
|
||||
import org.rococy.roomit.control.*;
|
||||
import org.rococy.roomit.controller.base.BaseController;
|
||||
import org.rococy.roomit.cursor.RoomItCursor;
|
||||
import org.rococy.roomit.domain.KeyBoardConfiguration;
|
||||
import org.rococy.roomit.event.RoomItCursorEvent;
|
||||
|
@ -37,7 +39,7 @@ import java.util.ResourceBundle;
|
|||
* @author Rococy
|
||||
* @date 2022/9/8
|
||||
*/
|
||||
public class MainWindowController implements Initializable {
|
||||
public class MainWindowController extends BaseController implements Initializable {
|
||||
|
||||
@FXML
|
||||
private Container container;
|
||||
|
@ -91,59 +93,7 @@ public class MainWindowController implements Initializable {
|
|||
|
||||
@FXML
|
||||
public void windowKeyPressed(KeyEvent event) {
|
||||
String keyBoardText = KeyBoardUtils.parse(event);
|
||||
|
||||
switch (keyBoardConfiguration.getType(keyBoardText)) {
|
||||
// 切换为画笔
|
||||
case KeyBoardConsts.BRUSH: {
|
||||
changeState(BRUSH_SYMBOL);
|
||||
break;
|
||||
}
|
||||
|
||||
// 切换为绘制矩形状态
|
||||
case KeyBoardConsts.RECTANGLE: {
|
||||
changeState(RECTANGLE_SYMBOL);
|
||||
shapePane.switchToDrawRectangle();
|
||||
break;
|
||||
}
|
||||
|
||||
// 切换为绘制椭圆状态
|
||||
case KeyBoardConsts.ELLIPSE: {
|
||||
changeState(ELLIPSE_SYMBOL);
|
||||
shapePane.switchToDrawEllipse();
|
||||
break;
|
||||
}
|
||||
|
||||
// 弹出颜色框 picker
|
||||
case KeyBoardConsts.COLOR_PICKER: {
|
||||
ejectColorPicker();
|
||||
break;
|
||||
}
|
||||
|
||||
// 鼠标放大操作 expand
|
||||
case KeyBoardConsts.EXPEND_MOUSE: {
|
||||
cursor.expand(globalMouseX, globalMouseY);
|
||||
break;
|
||||
}
|
||||
|
||||
// 清空操作 clear
|
||||
case KeyBoardConsts.CLEAR: {
|
||||
this.clear();
|
||||
break;
|
||||
}
|
||||
|
||||
// 回退操作
|
||||
case KeyBoardConsts.BACK: {
|
||||
canvasGroup.undo();
|
||||
break;
|
||||
}
|
||||
|
||||
// 将截图放入剪切板操作
|
||||
case KeyBoardConsts.SCREENSHOT_AND_COPY: {
|
||||
this.captureToClipBoard();
|
||||
break;
|
||||
}
|
||||
}
|
||||
this.triggerKeyboard(KeyBoardUtils.parse(event));
|
||||
}
|
||||
|
||||
@FXML
|
||||
|
@ -169,6 +119,60 @@ public class MainWindowController implements Initializable {
|
|||
initDrawingBoard();
|
||||
}
|
||||
|
||||
public void triggerKeyboard(String keyBoardText) {
|
||||
switch (keyBoardConfiguration.getType(keyBoardText)) {
|
||||
// 切换为画笔
|
||||
case KeyBoardConsts.BRUSH -> changeState(BRUSH_SYMBOL);
|
||||
|
||||
// 切换为绘制矩形状态
|
||||
case KeyBoardConsts.RECTANGLE -> {
|
||||
changeState(RECTANGLE_SYMBOL);
|
||||
shapePane.switchToDrawRectangle();
|
||||
}
|
||||
|
||||
// 切换为绘制椭圆状态
|
||||
case KeyBoardConsts.ELLIPSE -> {
|
||||
changeState(ELLIPSE_SYMBOL);
|
||||
shapePane.switchToDrawEllipse();
|
||||
}
|
||||
|
||||
case KeyBoardConsts.TOOLS -> ejectToolsWindow();
|
||||
|
||||
// 弹出颜色框 picker
|
||||
case KeyBoardConsts.COLOR_PICKER -> ejectColorPicker();
|
||||
|
||||
// 鼠标放大操作 expand
|
||||
case KeyBoardConsts.EXPEND_MOUSE -> cursor.expand(globalMouseX, globalMouseY);
|
||||
|
||||
// 清空操作 clear
|
||||
case KeyBoardConsts.CLEAR -> this.clear();
|
||||
|
||||
// 回退操作
|
||||
case KeyBoardConsts.BACK -> canvasGroup.undo();
|
||||
|
||||
// 将截图放入剪切板操作
|
||||
case KeyBoardConsts.SCREENSHOT_AND_COPY -> {
|
||||
ToolsWindow toolsWindow = ToolsWindow.getInstance();
|
||||
if (toolsWindow.isShowing()) {
|
||||
toolsWindow.setOnHidden(e -> {
|
||||
try {
|
||||
Thread.sleep(500);
|
||||
this.captureToClipBoard();
|
||||
} catch (InterruptedException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
});
|
||||
toolsWindow.hide();
|
||||
} else {
|
||||
this.captureToClipBoard();
|
||||
}
|
||||
}
|
||||
|
||||
case KeyBoardConsts.OPEN_OR_CLOSE -> container.getScene().getWindow().hide();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 初始化最外层的pane
|
||||
*/
|
||||
|
@ -301,6 +305,13 @@ public class MainWindowController implements Initializable {
|
|||
colorPicker.show();
|
||||
}
|
||||
|
||||
/**
|
||||
* 弹出工具箱
|
||||
*/
|
||||
private void ejectToolsWindow() {
|
||||
ToolsWindow.getInstance().show();
|
||||
}
|
||||
|
||||
/**
|
||||
* 截屏并粘贴至剪切板
|
||||
*/
|
||||
|
@ -323,7 +334,12 @@ public class MainWindowController implements Initializable {
|
|||
container.setCursor(Cursor.DEFAULT);
|
||||
});
|
||||
|
||||
toast.setOnTransparentReleased(() -> ((Stage) container.getScene().getWindow()).close());
|
||||
toast.setOnTransparentReleased(() -> {
|
||||
Stage stage = ((Stage) container.getScene().getWindow());
|
||||
if (stage != null) {
|
||||
stage.close();
|
||||
}
|
||||
});
|
||||
|
||||
container.addChildren(toast);
|
||||
} catch (AWTException e) {
|
||||
|
|
|
@ -1,9 +1,77 @@
|
|||
package org.rococy.roomit.controller;
|
||||
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.fxml.Initializable;
|
||||
import javafx.scene.control.Tooltip;
|
||||
import javafx.scene.input.MouseEvent;
|
||||
import javafx.scene.layout.TilePane;
|
||||
import javafx.scene.layout.VBox;
|
||||
import org.rococy.roomit.config.ConfigurationManager;
|
||||
import org.rococy.roomit.controller.context.ControllerContext;
|
||||
import org.rococy.roomit.domain.KeyBoardConfiguration;
|
||||
|
||||
import java.net.URL;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
/**
|
||||
* @author Rococy
|
||||
* @date 2022/10/6
|
||||
*/
|
||||
public class ToolsWindowController {
|
||||
public class ToolsWindowController implements Initializable {
|
||||
|
||||
@FXML
|
||||
private TilePane container;
|
||||
|
||||
@FXML
|
||||
private VBox brushImageWrapper;
|
||||
|
||||
@FXML
|
||||
private VBox rectangleImageWrapper;
|
||||
|
||||
@FXML
|
||||
private VBox ellipseImageWrapper;
|
||||
|
||||
@FXML
|
||||
private VBox colorPickerImageWrapper;
|
||||
|
||||
@FXML
|
||||
private VBox expendMouseImageWrapper;
|
||||
|
||||
@FXML
|
||||
private VBox clearImageWrapper;
|
||||
|
||||
@FXML
|
||||
private VBox screenshotAndCopyImageWrapper;
|
||||
|
||||
@FXML
|
||||
private VBox openOrCloseImageWrapper;
|
||||
|
||||
private final KeyBoardConfiguration keyBoardConfiguration = ConfigurationManager.getKeyboardConfiguration();
|
||||
|
||||
@Override
|
||||
public void initialize(URL location, ResourceBundle resources) {
|
||||
Tooltip.install(brushImageWrapper, new Tooltip("画笔"));
|
||||
Tooltip.install(rectangleImageWrapper, new Tooltip("矩形"));
|
||||
Tooltip.install(ellipseImageWrapper, new Tooltip("椭圆"));
|
||||
Tooltip.install(colorPickerImageWrapper, new Tooltip("颜色选择器"));
|
||||
Tooltip.install(expendMouseImageWrapper, new Tooltip("鼠标放大"));
|
||||
Tooltip.install(clearImageWrapper, new Tooltip("清空画板"));
|
||||
Tooltip.install(screenshotAndCopyImageWrapper, new Tooltip("截屏并复制"));
|
||||
Tooltip.install(openOrCloseImageWrapper, new Tooltip("打开或关闭画板"));
|
||||
}
|
||||
|
||||
@FXML
|
||||
public void vBoxMouseClicked(MouseEvent event) {
|
||||
String keyboardType = (String) ((VBox) event.getSource()).getUserData();
|
||||
String keyBoardText = keyBoardConfiguration.getKeyBoardMap().get(keyboardType);
|
||||
MainWindowController mainWindowController = this.getMainController();
|
||||
mainWindowController.triggerKeyboard(keyBoardText);
|
||||
|
||||
// 隐藏当前窗口
|
||||
container.getScene().getWindow().hide();
|
||||
}
|
||||
|
||||
private MainWindowController getMainController() {
|
||||
return (MainWindowController) ControllerContext.getControllerByType(MainWindowController.class);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
package org.rococy.roomit.controller.base;
|
||||
|
||||
import org.rococy.roomit.controller.context.ControllerContext;
|
||||
|
||||
/**
|
||||
* @author Rococy
|
||||
* @date 2022/10/7
|
||||
*/
|
||||
public abstract class BaseController {
|
||||
|
||||
public BaseController() {
|
||||
ControllerContext.addController(this);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
package org.rococy.roomit.controller.context;
|
||||
|
||||
import org.rococy.roomit.controller.base.BaseController;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author Rococy
|
||||
* @date 2022/10/7
|
||||
*/
|
||||
public class ControllerContext {
|
||||
|
||||
private static final Map<String, BaseController> CONTROLLER_MAP = new HashMap<>(4);
|
||||
|
||||
public static void addController(BaseController baseController) {
|
||||
CONTROLLER_MAP.put(baseController.getClass().getSimpleName(), baseController);
|
||||
}
|
||||
|
||||
public static BaseController getControllerByType(Class<?> type) {
|
||||
for (BaseController controller : CONTROLLER_MAP.values()) {
|
||||
if (controller.getClass() == type) {
|
||||
return controller;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
#container {
|
||||
-fx-background-radius: 5px;
|
||||
-fx-pref-width: 480px;
|
||||
-fx-pref-height: 200px;
|
||||
}
|
||||
|
||||
.vbox {
|
||||
-fx-pref-width: 120px;
|
||||
-fx-pref-height: 100px;
|
||||
-fx-background-color: #00000000;
|
||||
-fx-cursor: hand;
|
||||
-fx-alignment: center;
|
||||
}
|
||||
|
||||
.vbox:hover {
|
||||
-fx-background-color: #ececec;
|
||||
}
|
||||
|
||||
.tooltip {
|
||||
-fx-background-color: #fff;
|
||||
-fx-text-fill: #000;
|
||||
-fx-font-size: 12px;
|
||||
}
|
|
@ -10,7 +10,6 @@
|
|||
id="container"
|
||||
onMouseEntered="#windowMouseEntered"
|
||||
onKeyPressed="#windowKeyPressed">
|
||||
|
||||
</Container>
|
||||
|
||||
|
||||
|
|
|
@ -1,21 +1,55 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<?import javafx.scene.layout.*?>
|
||||
|
||||
<AnchorPane xmlns="http://javafx.com/javafx"
|
||||
<?import javafx.scene.image.Image?>
|
||||
<?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"
|
||||
id="container"
|
||||
stylesheets="@../css/tools.css"
|
||||
fx:controller="org.rococy.roomit.controller.ToolsWindowController">
|
||||
|
||||
<!--
|
||||
brush
|
||||
rectangle
|
||||
ellipse
|
||||
tools
|
||||
colorPicker
|
||||
expendMouse
|
||||
clear
|
||||
screenshotAndCopy
|
||||
openOrClose
|
||||
-->
|
||||
<VBox styleClass="vbox" fx:id="brushImageWrapper" userData="brush" onMouseClicked="#vBoxMouseClicked">
|
||||
<ImageView fitWidth="50" fitHeight="50" preserveRatio="true">
|
||||
<Image url="@../img/brush-logo.png"/>
|
||||
</ImageView>
|
||||
</VBox>
|
||||
<VBox styleClass="vbox" fx:id="rectangleImageWrapper" userData="rectangle" onMouseClicked="#vBoxMouseClicked">
|
||||
<ImageView fitWidth="50" fitHeight="50" preserveRatio="true">
|
||||
<Image url="@../img/rectangle-logo.png"/>
|
||||
</ImageView>
|
||||
</VBox>
|
||||
<VBox styleClass="vbox" fx:id="ellipseImageWrapper" userData="ellipse" onMouseClicked="#vBoxMouseClicked">
|
||||
<ImageView fitWidth="50" fitHeight="50" preserveRatio="true">
|
||||
<Image url="@../img/ellipse-logo.png"/>
|
||||
</ImageView>
|
||||
</VBox>
|
||||
<VBox styleClass="vbox" fx:id="colorPickerImageWrapper" userData="colorPicker" onMouseClicked="#vBoxMouseClicked">
|
||||
<ImageView fitWidth="50" fitHeight="50" preserveRatio="true">
|
||||
<Image url="@../img/color-picker-logo.png"/>
|
||||
</ImageView>
|
||||
</VBox>
|
||||
<VBox styleClass="vbox" fx:id="expendMouseImageWrapper" userData="expendMouse" onMouseClicked="#vBoxMouseClicked">
|
||||
<ImageView fitWidth="50" fitHeight="50" preserveRatio="true">
|
||||
<Image url="@../img/mouse-logo.png"/>
|
||||
</ImageView>
|
||||
</VBox>
|
||||
<VBox styleClass="vbox" fx:id="clearImageWrapper" userData="clear" onMouseClicked="#vBoxMouseClicked">
|
||||
<ImageView fitWidth="50" fitHeight="50" preserveRatio="true">
|
||||
<Image url="@../img/clear-logo.png"/>
|
||||
</ImageView>
|
||||
</VBox>
|
||||
<VBox styleClass="vbox" fx:id="screenshotAndCopyImageWrapper" userData="screenshotAndCopy" onMouseClicked="#vBoxMouseClicked">
|
||||
<ImageView fitWidth="50" fitHeight="50" preserveRatio="true">
|
||||
<Image url="@../img/screenshot-logo.png"/>
|
||||
</ImageView>
|
||||
</VBox>
|
||||
<VBox styleClass="vbox" fx:id="openOrCloseImageWrapper" userData="openOrClose" onMouseClicked="#vBoxMouseClicked">
|
||||
<ImageView fitWidth="50" fitHeight="50" preserveRatio="true">
|
||||
<Image url="@../img/open-or-close-logo.png"/>
|
||||
</ImageView>
|
||||
</VBox>
|
||||
|
||||
</AnchorPane>
|
||||
</TilePane>
|
||||
|
|
After Width: | Height: | Size: 20 KiB |
After Width: | Height: | Size: 3.8 KiB |
After Width: | Height: | Size: 5.8 KiB |
After Width: | Height: | Size: 12 KiB |
After Width: | Height: | Size: 3.7 KiB |
After Width: | Height: | Size: 4.0 KiB |
After Width: | Height: | Size: 4.7 KiB |
After Width: | Height: | Size: 3.6 KiB |