package com.example.demo;
import javafx.embed.swing.SwingFXUtils;
import javafx.scene.SnapshotParameters;
import javafx.scene.canvas.Canvas;
import javafx.scene.canvas.GraphicsContext;
import javafx.scene.control.ColorPicker;
import javafx.scene.control.Menu;
import javafx.scene.control.MenuBar;
import javafx.scene.control.MenuItem;
import javafx.scene.image.WritableImage;
import javafx.scene.input.KeyCombination;
import javafx.scene.layout.StackPane;
import javafx.scene.paint.Color;
import javafx.stage.FileChooser;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
/**
* @author Gst
*/
public class GstMenuBar implements initProperty {
private GstCanvas gstCanvas;
private Canvas canvas;
private GraphicsContext gc;
private MenuBar menuBar ;
private StackPane anchorPane;
WritableImage snapshot;
public GstMenuBar(MenuBar menuBar, GstCanvas gstCanvas,StackPane anchorPane) {
this.menuBar = menuBar;
this.gstCanvas = gstCanvas;
canvas = gstCanvas.getCanvas();
gc = gstCanvas.getGc();
this.anchorPane=anchorPane;
}
public GstMenuBar(GstCanvas gstCanvas,StackPane anchorPane) {
this.anchorPane=anchorPane;
menuBar = new MenuBar();
this.gstCanvas = gstCanvas;
canvas = gstCanvas.getCanvas();
gc = gstCanvas.getGc();
Menu menu0 = new Menu("字体颜色");
Menu menu1 = new Menu("粗细");
Menu menu2 = new Menu("图形");
Menu menu3 = new Menu("快捷工具");
ColorPicker colorPicker = new ColorPicker(); // 创建一个颜色选择器
MenuItem menuItem = new MenuItem(); // 创建一个菜单项,将颜色选择器设置为图标
menuItem.setGraphic(colorPicker);
menu0.getItems().add(menuItem); // 将菜单项添加到菜单中
gstCanvas.setStrokeColor(Color.BLACK); //设置初始画笔颜色
colorPicker.setValue(Color.BLACK); //设置初始选择器颜色
colorPicker.setOnAction(event -> { // 获取
相关问题可以联系本人