Skip to content

Commit

Permalink
Möglicherweise vorläufige nicht fxml-basierte Menüanzeige hinzugefügt.
Browse files Browse the repository at this point in the history
  • Loading branch information
AntonJuliusRabe committed Jun 17, 2018
1 parent 7d49038 commit 34244e5
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 5 deletions.
78 changes: 78 additions & 0 deletions src/main/java/de/sbmltab/view/MenuController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package de.sbmltab.view;

import java.net.URL;
import java.util.ResourceBundle;

import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Menu;
import javafx.scene.control.MenuBar;
import javafx.scene.control.MenuItem;
import javafx.scene.input.InputEvent;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyCombination;
import javafx.scene.input.KeyEvent;


public class MenuController implements Initializable
{
public static MenuBar generateMenuBar (){

MenuBar menuBar = new MenuBar();

// Benötigte Menus
Menu fileMenu = new Menu("File");
Menu editMenu = new Menu("Edit");
Menu viewMenu = new Menu("View");
Menu helpMenu = new Menu("Help");

// Benötigte Menu-Items

This comment has been minimized.

Copy link
@draeger

draeger Jun 17, 2018

Member

Avoid German, in particular umlauts.

//file
MenuItem newItem = new MenuItem("New");
MenuItem openItem = new MenuItem("Open");
MenuItem saveItem = new MenuItem("Save");
MenuItem exitItem = new MenuItem("Exit");
MenuItem exportItem = new MenuItem("Export");
MenuItem importItem = new MenuItem("Import");
//edit
MenuItem copyItem = new MenuItem("Copy");
MenuItem cutItem = new MenuItem("Cut");
MenuItem pasteItem = new MenuItem("Paste");
MenuItem undoItem = new MenuItem("Undo");
MenuItem redoItem = new MenuItem("Redo");
//View
MenuItem columnsShownItem = new MenuItem("Columns shown");
MenuItem hideColumnsItem = new MenuItem("Hide Columns");
MenuItem showHiddenColumnsItem = new MenuItem("Show hidden columns");

// Richtige Reihenfolge in den Menus
fileMenu.getItems().addAll(newItem, openItem, importItem, exportItem, saveItem, exitItem );
editMenu.getItems().addAll(undoItem, redoItem, copyItem, cutItem, pasteItem);
viewMenu.getItems().addAll(columnsShownItem, hideColumnsItem, showHiddenColumnsItem);

// Add Menus to the MenuBar
menuBar.getMenus().addAll(fileMenu, editMenu, viewMenu, helpMenu);

//definiere Tastenkürzel

This comment has been minimized.

Copy link
@draeger

draeger Jun 17, 2018

Member

Avoid German, and umlauts in particular.

newItem.setAccelerator(KeyCombination.keyCombination("Ctrl+N"));

This comment has been minimized.

Copy link
@draeger

draeger Jun 17, 2018

Member

These keystrokes are typical for Linux and Windows, whereas in macOS one would use the command key instead of the control key. Therefore, it makes sense to create a method for this that generates the key strokes depending on the user's operating system.

openItem.setAccelerator(KeyCombination.keyCombination("Ctrl+O"));
saveItem.setAccelerator(KeyCombination.keyCombination("Ctrl+S"));
undoItem.setAccelerator(KeyCombination.keyCombination("Ctrl+Z"));
redoItem.setAccelerator(KeyCombination.keyCombination("Ctrl+Y"));
copyItem.setAccelerator(KeyCombination.keyCombination("Ctrl+C"));
cutItem.setAccelerator(KeyCombination.keyCombination("Ctrl+X"));
pasteItem.setAccelerator(KeyCombination.keyCombination("Ctrl+V"));

return menuBar;
}

@Override
public void initialize(URL arg0, ResourceBundle arg1) {
// TODO Auto-generated method stub

}



}
20 changes: 16 additions & 4 deletions src/main/java/de/sbmltab/view/SBMLTabMainView.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,31 @@
import java.io.IOException;

import javafx.application.Application;
import javafx.event.EventHandler;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
import javafx.scene.image.Image;
import javafx.scene.input.KeyCombination;
import javafx.scene.control.Menu;
import javafx.scene.control.MenuBar;
import javafx.scene.control.MenuItem;
import javafx.scene.layout.BorderPane;


public class SBMLTabMainView extends Application{
public class SBMLTabMainView extends Application {


public void start(Stage stage) throws Exception {
Parent root = FXMLLoader.load(getClass().getResource("TabModView.fxml"));


MenuBar menuBar = MenuController.generateMenuBar();
BorderPane root = new BorderPane();
root.setTop(menuBar);
//Parent root = FXMLLoader.load(getClass().getResource("TabModView.fxml"));
root.setTop(menuBar);
root.setCenter(FXMLLoader.load(getClass().getResource("TabModView.fxml")));
Scene scene = new Scene(root, 800, 600);

stage.getIcons().add (new Image("File:/Icons/Icon_small.png"));

This comment has been minimized.

Copy link
@draeger

draeger Jun 17, 2018

Member

Is there a specific reason for not using the loading mechanism via getClass().getResource() here as well?

stage.setTitle("TabMod v1.0");
stage.setScene(scene);
Expand All @@ -25,4 +36,5 @@ public void start(Stage stage) throws Exception {

}


}
2 changes: 1 addition & 1 deletion src/main/java/de/sbmltab/view/TabModView.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<?import javafx.scene.text.*?>

<GridPane xmlns:fx="http://javafx.com/fxml/1" hgap="10" vgap="10">
<padding><Insets top="25" right="25" bottom="10" left="25"/></padding>
<padding><Insets top="0" right="0" bottom="0" left="0"/></padding>

<gridLinesVisible>true</gridLinesVisible>
<!-- TODO Add Nodes -->
Expand Down

1 comment on commit 34244e5

@draeger
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The file src/main/java/de/sbmltab/view/TabModView.fxml is a resource file and should therefore not be located in the java directory. Please move to src/main/resources/ and create the identical package de.sbmltab.view there as well. The FXML file will then be placed in the same package upon building the project.

Please sign in to comment.