use of menus.ExportImageTool in project DistributedFractalNetwork by Budder21.
the class FractalEditor method initialize.
/**
* Initializes the menus and fractal
*
* @author David
*
* @throws FileNotFoundException
* @throws AWTException
*/
@SuppressWarnings({ "rawtypes", "unchecked", "static-access" })
public void initialize() throws FileNotFoundException, AWTException {
// initializing stuff
Layer.initializeFractalRegistry();
File fractalDirectory = new File(Constants.FRACTAL_FILEPATH);
if (!fractalDirectory.exists()) {
fractalDirectory.mkdirs();
try {
fractalDirectory.createNewFile();
} catch (IOException e1) {
e1.printStackTrace();
}
}
fractal = new RenderManager();
MenuBar menu = new MenuBar();
SwingNode fractalEditor = new SwingNode();
TreeView parameters = new TreeView();
layers = new TreeView();
VBox trees = new VBox();
trees.minHeightProperty().bind(bp.minHeightProperty().subtract(menu.minHeightProperty()));
trees.minWidthProperty().bind(bp.minWidthProperty().divide(6));
Button render = new Button("Update");
render.minWidthProperty().bind(trees.minWidthProperty());
render.minHeightProperty().bind(trees.minHeightProperty().divide(6));
fractalView = new ImageView();
fractalView.setOnMouseClicked(e -> {
Point p = new Point(e.getScreenX(), e.getScreenY() - 52);
double screenDistX = fractalView.getFitWidth() / 2 - p.x;
double screenDistY = fractalView.getFitHeight() / 2 - p.y;
double realDistX = -screenDistX * fractal.getRealResolution().x / fractal.getScreenResolution().width;
double realDistY = screenDistY * fractal.getRealResolution().y / fractal.getScreenResolution().height;
fractal.setLocation(new Point(fractal.getLocation().x + realDistX * 2, fractal.getLocation().y + realDistY * 2));
this.updateFractalImage();
});
fractalView.setOnMouseEntered(e -> {
zoom = true;
});
fractalView.setOnMouseExited(e -> {
zoom = false;
});
this.setOnKeyPressed(e -> {
if (zoom)
if (e.getCode() == KeyCode.COMMA) {
this.fractal.setZoom(this.fractal.getZoom() * 1.5);
updateFractalImage();
} else if (e.getCode() == KeyCode.PERIOD) {
this.fractal.setZoom(this.fractal.getZoom() / 1.5);
updateFractalImage();
}
});
fractalView.setOnScroll(e -> {
double zoom = e.getDeltaY() > 0 ? 1 / .9 : .9;
this.fractal.setZoom(this.fractal.getZoom() * zoom);
this.updateFractalImage();
});
this.fractal = new RenderManager();
render.setOnAction(e -> {
updateFractalImage();
});
// Fitting the image to the screen
fractalView.fitWidthProperty().bind(bp.minWidthProperty().subtract(trees.minWidthProperty()));
fractalView.fitHeightProperty().bind(bp.heightProperty().subtract(menu.minHeightProperty()).subtract(220));
{
// Fitting gradientEditor to full screen
Dimension p = new Dimension((int) (Toolkit.getDefaultToolkit().getScreenSize().width * 0.75), 200);
System.out.println("Gradient Dimensions: " + p);
gradient = new Window(p, 50, this.fractal.getLayers().get(0));
}
{
// Tree Stuff
parameters.setRoot(new TreeItem("params"));
parameters.getRoot().setExpanded(true);
TreeItem xPos = new TreeItem();
parameters.getRoot().getChildren().addAll(xPos);
layers.setRoot(new TreeItem());
layers.getRoot().setExpanded(true);
layers.setShowRoot(false);
layers.setEditable(true);
/**
* layers.setCellFactory(new Callback<TreeView,CheckBoxTreeCell>(){
*
* @Override public CheckBoxTreeCell call(TreeView p) { return new
* CheckBoxTreeCell(); } });
*/
// Use a custom callback to determine the style of the tree item
layers.setCellFactory(new Callback<TreeView, TreeCell>() {
@Override
public TreeCell call(TreeView param) {
return new CheckBoxTreeCell() {
@Override
public void updateItem(Object item, boolean empty) {
super.updateItem(item, empty);
// empty
if (empty) {
setGraphic(null);
setText(null);
// Otherwise if it's not representation as an
// item of the tree
// is not a CheckBoxTreeItem, remove the
// checkbox item
} else if (!(getTreeItem() instanceof CheckBoxTreeItem)) {
BufferedImage image;
try {
image = ImageIO.read(new File("textures\\plusButton.png"));
Image plusImage = SwingFXUtils.toFXImage(image, null);
ImageView plusView = new ImageView(plusImage);
plusView.setFitHeight(16);
plusView.setFitWidth(16);
setGraphic(plusView);
} catch (IOException e) {
e.printStackTrace();
}
}
}
};
}
});
TreeItem add = new TreeItem();
/**
* try{ BufferedImage image = ImageIO.read(new
* File("textures\\plusButton.jpg")); Image plusImage =
* SwingFXUtils.toFXImage(image, null); ImageView plusView = new
* ImageView(plusImage); plusView.setFitWidth(16);
* plusView.setFitHeight(16); add.setGraphic(plusView);
* }catch(Exception e){ e.printStackTrace(); }
*/
layerIndex = 1;
CheckBoxTreeItem item = getNewTreeItem();
/**
* add.addEventHandler(CheckBoxTreeItem.checkBoxSelectionChangedEvent(),
* e -> { if(((CheckBoxTreeItem)(e.getSource())).isSelected()){
* ((CheckBoxTreeItem)(e.getSource())).getParent().getChildren().add(0,
* new CheckBoxTreeItem(new
* MetaLayer("Layer"+incrementLayers(),null)));
* ((CheckBoxTreeItem)(e.getSource())).setSelected(false); }});
*/
layers.setOnMouseClicked(new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent mouseEvent) {
if (mouseEvent.getClickCount() == 2) {
if (layers.getSelectionModel().getSelectedItem() == add) {
CheckBoxTreeItem i = getNewTreeItem();
layers.getRoot().getChildren().add(0, i);
fractal.addLayer("HistogramLayer");
} else {
((TreeItem) layers.getSelectionModel().getSelectedItem()).setValue(LayerBox.display((TreeItem<MetaLayer>) layers.getSelectionModel().getSelectedItem()));
MetaLayer meta = ((MetaLayer) ((TreeItem) layers.getSelectionModel().getSelectedItem()).getValue());
int index = layers.getRoot().getChildren().size() - 2 - layers.getRoot().getChildren().indexOf(layers.getSelectionModel().getSelectedItem());
Layer l = fractal.getLayers().get(index);
if (meta.getType() != l.getClass().getSimpleName()) {
Layer newLayer = Layer.getLayerByType(meta.getType());
newLayer.init(new Palette(), index + 1);
fractal.getLayers().set(index, newLayer);
fractal.update();
}
fractal.getLayers().get(index).setName(meta.getName());
updateFractalImage();
}
} else if (mouseEvent.getClickCount() == 1 && layers.getSelectionModel().getSelectedItem() != add) {
int index = layers.getRoot().getChildren().size() - 2 - layers.getRoot().getChildren().indexOf(layers.getSelectionModel().getSelectedItem());
Layer l = fractal.getLayers().get(index);
gradient.updateLayer(l);
}
}
});
layers.getRoot().getChildren().addAll(item, add);
{
// TODO I DONT KNOW WHY THIS ISNT WORKING IUEAWBIUBFAI
/**
* layers.getRoot().addEventHandler(layers.getRoot().childrenModificationEvent(),e
* -> { for(Object i :((TreeItem)e.getSource()).getChildren()){
* if(i!=add)
* if(((MetaLayer)((TreeItem)(i)).getValue()).isDelete()){
* layers.getSelectionModel().select(i);
* layers.getSelectionModel().clearSelection(); } } });
*/
}
}
// Trying to get this to work
fractalEditor.setOnMouseEntered(e -> gradient.repaint());
{
// This is the menu stuff
Menu network = new Menu("Network");
Menu fractal = new Menu("Fractal");
Menu system = new Menu("System");
MenuItem newNet = new MenuItem("Create New Network");
MenuItem viewNetLog = new MenuItem("View Network Log");
MenuItem viewNet = new MenuItem("View Network");
MenuItem endNet = new MenuItem("Close Network");
newNet.setOnAction(e -> {
NetworkCreationTool createNet = new NetworkCreationTool();
if (createNet.createNetwork()) {
this.network = createNet.getServer();
this.network.init(log);
Alert alert = new Alert(AlertType.INFORMATION);
alert.setTitle("Network Message");
alert.setHeaderText(null);
alert.setContentText("Network succesfully created.");
viewNet.setDisable(false);
endNet.setDisable(false);
newNet.setDisable(true);
viewNetLog.setDisable(false);
alert.showAndWait();
}
});
viewNet.setDisable(true);
endNet.setDisable(true);
viewNetLog.setDisable(true);
viewNet.setOnAction(e -> {
Display display = new Display(this.network);
this.network.setDisplay(display);
display.updateNetworkView(this.network.getChildren(), this.network.getUncompletedJobs());
});
endNet.setOnAction(e -> {
this.network.kill();
viewNet.setDisable(true);
endNet.setDisable(true);
viewNetLog.setDisable(true);
newNet.setDisable(false);
});
viewNetLog.setOnAction(e -> {
Alert alert = new Alert(AlertType.INFORMATION);
alert.setTitle("Network Log");
alert.setHeaderText(null);
alert.setContentText(this.network.getLog().getLog());
alert.showAndWait();
});
network.getItems().addAll(newNet, viewNet, viewNetLog, endNet);
MenuItem newFract = new MenuItem("New Fractal");
newFract.setOnAction(e -> {
this.fractal = new RenderManager();
gradient.updateLayer(this.fractal.getLayers().get(0));
this.updateFractalImage();
});
MenuItem openFract = new MenuItem("Open Fractal");
openFract.setOnAction(e -> {
FileChooser chooser = new FileChooser();
chooser.setTitle("Open Fractal");
chooser.setInitialDirectory(new File("fractals"));
FileChooser.ExtensionFilter filter = new FileChooser.ExtensionFilter("Fractals (*.fractal)", "*.fractal");
chooser.getExtensionFilters().add(filter);
File f = chooser.showOpenDialog(null);
this.fractal = new RenderManager(f);
gradient.updateLayer(this.fractal.getLayers().get(0));
this.updateFractalImage();
});
MenuItem saveFract = new MenuItem("Save Fractal");
saveFract.setOnAction(e -> {
this.fractal.saveFractal();
});
MenuItem saveFractAs = new MenuItem("Save Fractal As");
saveFractAs.setOnAction(e -> {
this.fractal.saveFractalAs();
});
MenuItem exportFract = new MenuItem("Export Fractal");
exportFract.setOnAction(e -> {
ExportImageTool export = new ExportImageTool();
export.exportImage(this.fractal);
});
fractal.getItems().addAll(newFract, openFract, saveFract, saveFractAs, exportFract);
MenuItem newLayer = new MenuItem("New Layer Type");
newLayer.setOnAction(e -> {
RegisterLayerTool register = new RegisterLayerTool();
register.registerLayer();
Layer.registerLayer(register.getFile());
});
MenuItem changeLog = new MenuItem("Edit Log Options");
changeLog.setOnAction(e -> {
});
system.getItems().addAll(newLayer, changeLog);
menu.getMenus().addAll(fractal);
menu.getMenus().addAll(network);
menu.getMenus().addAll(system);
}
VBox center = new VBox();
center.getChildren().addAll(fractalView, fractalEditor);
trees.getChildren().addAll(parameters, layers, render);
bp.setCenter(center);
bp.setRight(trees);
// This is where the menu is located on the border pane
bp.setTop(menu);
bp.minWidthProperty().bind(this.widthProperty());
bp.minHeightProperty().bind(this.heightProperty());
fractalEditor.setContent(gradient);
fractalEditor.minHeight(200);
}
Aggregations