import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Image;
import java.awt.Insets;
import java.awt.Toolkit;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTabbedPane;
import javax.swing.ScrollPaneConstants;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import de.diplom.controller.Button_Menu_WorkspaceController;
import de.diplom.controller.MainFrameController;
import de.diplom.controller.WorkspacePaneController;
import de.diplom.exception.Button_MenuControllerException;
import de.diplom.exception.FrameMenuException;
import de.diplom.exception.MainFrameException;
import de.diplom.model.BaseComponent;
import de.diplom.model.BaseVertex;
import de.diplom.model.Cause;
import de.diplom.model.Edge;
import de.diplom.model.Effect;
import de.diplom.model.Graph;
import de.diplom.model.ObjectFactory;
import de.diplom.model.Precise;
import de.diplom.model.Project;
import de.diplom.model.SystemOutSchemaOutput;
/**
* Die Klasse <code>MainFrame</code> prässentiert die gesamte Elemente der
* Überfläsche (GUI).
*
* @see de.diplom.view.SymbolButton#setMainFrame(MainFrame frame)
* @see de.diplom.view.MenuFrame#setMainFrame(MainFrame frame)
* @see de.diplom.view.SymbolButton#s
*
*/
public class MainFrame extends JFrame {
/**
*
*/
private static final long serialVersionUID = 1L;
/**
* contentPane
*/
private JPanel contentPane;
private String myFunction;
// private Project project;
private Dimension dem = new Dimension(500, 500);
/*
* logo des Gesamt Projekt
*/
Image logo = Toolkit.getDefaultToolkit().getImage(
"src/de/diplom/icons/logo.gif");
/**
* Steuerung element für die Frame
*/
private MainFrameController mainFrameController;
/**
* Steuerung Element für das Menü
*/
private WorkspacePaneController WorkspaceController;
private Button_Menu_WorkspaceController button_Menu_WorkspaceController;
/**
* Menü der Frame
*/
private MenuFrame menuFrame;
/**
* Buttons
*/
private SymbolButton symbolButton;
/**
* Panel als arbeitsplatz
*/
private WorkspacePane workspacePane;
private JPanel symbolPane;
/**
* scrollPane als Container Field
*/
private JScrollPane scrollPane;
/**
*/
public JTabbedPane tabbedPane = null;
/**
* index des tabbedPane
*/
private int tabbedIndex;
/**
* bgColor Background Color for alle Panels
*/
Color backGround = new Color(230, 220, 240);
private ObjectFactory factory;
private Project project;
private Graph graph;
/**
* in der Knostruktur der Klasse Wird folgende erzeugt 1- die Steuerung
* Element für Menü und Buttons. 2- Menü 3- initialize() aufgerufen wo alle
* Element der Frame initialisert. 4- Steuerung Element des Frame eingesetzt
* 5- neue TabbedPane
*
* @param controller
* @throws FrameMenuException
*/
public MainFrame(MainFrameController controller) throws MainFrameException,
FrameMenuException {
this.myFunction = "MainFrame(MainFrameController controller)";
if (controller == null)
throw new MainFrameException("In der Klasse : "
+ this.getClass().getName() + ", Konstruktur : " + ""
+ this.myFunction + ", das Field : controller == null");
this.mainFrameController = controller;
/**
* add die Controller an Das Fenster
*/
this.addWindowListener(controller);
try {
/**
* neue Button_MenuController gestellt wenn nicht geklappt wird eine
* MainFrameException eingelosst
*/
this.button_Menu_WorkspaceController = new Button_Menu_WorkspaceController();
if (this.button_Menu_WorkspaceController == null)
throw new MainFrameException(
"In der Klasse : "
+ this.getClass().getName()
+ ", Konstruktur : "
+ ""
+ this.myFunction
+ ", das Field : "
+ "button_Menu_WorkspaceController könnte nicht erzeugt werden...");
/**
* schauen Sie die Methode setFrameMenu
*/
this.setFrameMenu(new MenuFrame(
this.button_Menu_WorkspaceController));
this.button_Menu_WorkspaceController.setMainFrame(this);
} catch (Button_MenuControllerException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
/**
* neue TabbedPane erzeugt wurde
*/
this.tabbedPane = new JTabbedPane();
if (this.tabbedPane == null)
throw new MainFrameException("In der Klasse : "
+ this.getClass().getName() + ", Konstruktur : " + ""
+ this.myFunction + ", das Field : tabbedPane == null");
/**
* Regesterien von der TabbedPane an mainFrameController
*/
//this.mainFrameController.setTabbedPane(this.tabbedPane);
/**
* tabbedPane wird automatische gescrollt.
*/
this.tabbedPane.setAutoscrolls(true);
/**
* addieren die Steuerungselemente an der TabbedPane
*/
this.tabbedPane.addChangeListener(this.mainFrameController);
this.tabbedPane.addMouseListener(this.mainFrameController);
this.tabbedPane.addMouseMotionListener(this.mainFrameController);
/**
* see Methode initialize()
*/
initialize();
}
/**
* @return the projectList
*/
public void newProject() {
if(this.project == null){
this.project = this.factory.createProject();
System.out.println("Project wurde erstellt...");
}
}
Project getProject(){
if(this.project == null){
this.newProject();
}
return this.project;
}
/**
* Die Methode initialize() setzt die grosse des Fenster, die Position,
* Title, Logo und die Die Inhalt des Fenster ein.
*/
private void initialize() {
this.myFunction = "initialize()";
try {
this.setSize(760, 400);
this.setLocation(20, 20);
this.setTitle("Hanaii");
this.setIconImage(logo);
this.setResizable(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setJMenuBar(this.getFrameMenu());
this.setContentPane(getcontentPane());
this.setVisible(true);
} catch (MainFrameException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
/**
* @return the menuFrame
* @throws MainFrameException
*/
public MenuFrame getFrameMenu() throws MainFrameException {
this.myFunction = "getFrameMenu()";
if (this.menuFrame == null)
throw new MainFrameException("In der Klasse : "
+ this.getClass().getName() + ", Methode : " + ""
+ this.myFunction + ", das Field : menuFrame == null");
return menuFrame;
}
/**
* @param menuFrame
* the menuFrame to set
* @throws MainFrameException
*/
public void setFrameMenu(MenuFrame menuFrame) throws MainFrameException {
this.myFunction = "setFrameMenu(MenuFrame menuFrame)";
if (menuFrame == null)
throw new MainFrameException("In der Klasse : "
+ this.getClass().getName() + ", Methode : " + ""
+ this.myFunction + ", das Field : menuFrame == null");
this.menuFrame = menuFrame;
this.menuFrame.setMainFrame(this);
}
/**
* Die gesamt Container wird folgende erzeugt 1- eine neue Panel 2- Layout
* des Panel als BorderLayout 3- SymbolPane wird im Norden eingesetzt. 4-
* die TabbedPane an die mitte lokalisiert 4- eine new Tab an der TabbedPane
* addiert 5- die BagGround eingesetzt
*
* @return contentPane
* @throws MainFrameException
*/
/**
* @return
* @throws MainFrameException
*/
/**
* @return
* @throws MainFrameException
*/
/**
* @return
* @throws MainFrameException
*/
/**
* @return
* @throws MainFrameException
*/
private JPanel getcontentPane() throws MainFrameException {
this.myFunction = "getcontentPane()";
if (this.contentPane == null) {
this.contentPane = new JPanel();
if (this.contentPane == null)
throw new MainFrameException("In der Klasse : "
+ this.getClass().getName() + ", Methode : " + ""
+ this.myFunction
+ ", contentPane könnte nicht erzeugt werden....");
this.contentPane.setLayout(new BorderLayout());
this.contentPane.add(this.getSymbolPane(), BorderLayout.NORTH);
/*
* hier eine Begrüssung fenster auf bauen and die addTabbedPane nach
* hier auf rufen
*/
//addTabbedPane();
this.contentPane.setBackground(this.backGround);
this.contentPane.add(this.tabbedPane, BorderLayout.CENTER);
this.contentPane.setOpaque(true);
}
return this.contentPane;
}
/**
* im getSymbolPane() Methode wird folgende gemacht:- 1- ein neue Panel wird
* erzeugt 2- grosse des Panel eingesetzt 3- new SymbolButton objekt 4-
* anmeden die SymboleButton objekte an Ihre Steuerungselement 5- Die
* Methode setMainFrame von SymbolButton aufgeruft und die gesamt fenster
* als Param gegeben 6- Farbe des Hintergrund 7- neue GridBagLayout für die
* panel. 8- und jeder einselnen element zu einem Bestimmte Position
* lokalisiert . Ersten wird symbolButton an die buttoncontroller
* registeriet, dann die die Kontroller,
*
* @return symbolPane
*/
private JPanel getSymbolPane() throws MainFrameException {
this.myFunction = "getSymbolPane()";
if (symbolPane == null) {
try {
this.symbolPane = new JPanel();
if (this.symbolPane == null)
throw new MainFrameException("In der Klasse : "
+ this.getClass().getName() + ", Methode : " + ""
+ this.myFunction
+ ", symbolePane könnte nicht erzeugt werden....");
this.symbolPane.setSize(dem);
this.symbolButton = new SymbolButton();
if (this.symbolButton == null)
throw new MainFrameException("In der Klasse : "
+ this.getClass().getName() + ", Methode : " + ""
+ this.myFunction
+ ", symboleButton könnte nicht erzeugt werden....");
this.symbolButton
.setButtonController(this.button_Menu_WorkspaceController);
this.button_Menu_WorkspaceController
.setSymbolButton(this.symbolButton);
this.symbolButton.setMainFrame(this);
this.symbolPane.setBackground(this.backGround);
this.symbolPane.setLayout(new GridBagLayout());
GridBagConstraints c = new GridBagConstraints();
c.insets = new Insets(0, 0, 0, 0);
c.fill = GridBagConstraints.VERTICAL;
c.gridwidth = 1;
c.gridx = 1;
c.gridy = 0;
c.weightx = 0.0;
c.ipady = 5;
symbolPane.add(symbolButton.getNewGraph(), c);
c.gridx = 2;
c.gridy = 0;
c.ipady = 5;
symbolPane.add(symbolButton.getOpen(), c);
c.gridx = 3;
c.gridy = 0;
c.ipady = 5;
symbolPane.add(symbolButton.getSave(), c);
c.gridx = 4;
c.gridy = 0;
c.ipady = 5;
symbolPane.add(symbolButton.getPrint(), c);
c.gridx = 1;
c.gridy = 1;
c.ipady = 5;
symbolPane.add(symbolButton.getUndo(), c);
c.gridx = 2;
c.gridy = 1;
c.ipady = 5;
symbolPane.add(symbolButton.getCut(), c);
c.gridx = 3;
c.gridy = 1;
c.ipady = 5;
symbolPane.add(symbolButton.getCopy(), c);
c.gridx = 4;
c.gridy = 1;
c.ipady = 5;
symbolPane.add(symbolButton.getPaste(), c);
c.insets = new Insets(2, 2, 2, 2);
c.gridy = 0;
c.gridx = 15;
c.ipady = 2;
c.weightx = 0.1;
symbolPane.add(symbolButton.getCauseButton(), c);
c.insets = new Insets(2, 2, 2, 2);
c.gridx = 16;
c.gridy = 0;
symbolPane.add(symbolButton.getB_EffectButton(), c);
c.gridx = 17;
c.gridy = 0;
symbolPane.add(symbolButton.getE_EffectButton(), c);
c.gridx = 14;
c.gridy = 0;
this.symbolPane.add(this.symbolButton.getWait(), c);
c.gridx = 10;
c.gridy = 1;
c.weightx = 0.5;
c.insets = new Insets(2, 150, 2, 0);
symbolPane.add(symbolButton.getAndButton(), c);
c.gridx = 11;
c.gridy = 1;
c.insets = new Insets(0, 0, 0, 150);
symbolPane.add(symbolButton.getOrButton(), c);
c.insets = new Insets(0, 0, 0, 0);
c.gridx = 13;
c.gridy = 1;
symbolPane.add(symbolButton.getConnectorButton(), c);
c.insets = new Insets(0, 0, 0, 0);
c.gridx = 14;
c.gridy = 1;
symbolPane.add(symbolButton.getConvertButton(), c);
c.gridx = 15;
c.gridy = 1;
symbolPane.add(symbolButton.getExclusive(), c);
c.gridx = 16;
c.gridy = 1;
symbolPane.add(symbolButton.getInclusive(), c);
c.gridx = 17;
c.gridy = 1;
symbolPane.add(symbolButton.getOnlyOne(), c);
c.gridx = 19;
c.gridy = 0;
c.anchor = GridBagConstraints.EAST;
symbolPane.add(symbolButton.getCheckGraphButton(), c);
c.gridx = 19;
c.gridy = 1;
symbolPane.add(symbolButton.getTestGeneratorButton(), c);
} catch (java.lang.Throwable e) {
System.out.println("getSymbolPane()");
}
}
return symbolPane;
}
int i = 0;
public void newGraph(){
if(this.project != null){
try {
this.graph = this.factory.createGraph();
this.graph.setId("G"+ ++i);
this.addTabbedPane();
this.project.addGraphToList(this.graph);
} catch (MainFrameException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}else{
System.out.println("Project soll ersten erstellt werden...!");
}
}
/**/
public void saveProject(){
int i = 0;
System.out.println("SaveMethode im MainFrame");
for(Graph graph : this.getProject().getGraph()){
System.out.println("Graph : " + ++i);
for(BaseComponent comp : graph.getComponentList()){
System.out.println(comp.toString());
}
}
try {
JAXBContext ctx = JAXBContext.newInstance(new Class[]{Project.class, Graph.class,
Edge.class, BaseVertex.class, Effect.class,
BaseComponent.class, Cause.class, Precise.class});
// ctx.generateSchema(new SystemOutSchemaOutput());
Marshaller marshaller = ctx.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
marshaller.marshal(this.getProject(), System.out);
} catch (JAXBException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// ctx.createMarshaller().marshal(elem, System.out);
}
public void openProject(){
System.out.println("Open Methode im MainFrame");
}
public void saveProjectAs(){
System.out.println("SaveAsMethode im MainFrame");
}
/**
* @return the graph
*/
public Graph getGraph() {
return graph;
}
/**
* @param graph the graph to set
*/
public void setGraph(Graph graph) {
this.graph = graph;
}
/**
* Methode addTabbedPane wird folgende erledigt 1- eine neue Workspace
* erzeugt 2- index des Tabbs erzeugt um die Bennenung des Tab benutzt 3-
* Title des Tabe 4- Beschreibung des Tab (toolTip) 5- new JScrollpane 6-
* die scrollPolice eingesetzt 7- workspace an die ScrollPane eingesetzt 8-
* new Tabb mit Beschreibung und Title an der tabbedPane eingefügt
*/
public void addTabbedPane() throws MainFrameException {
int index = this.tabbedPane.getTabCount() + 1;
String title = "Graphik " + index;
String toolTip = "Darstellung Ursache-Wirkung-Graph " + index;
JPanel pane = this.getWorkspacePane();
// pane.setOpaque(true);
System.out.println("MainFrame Graph ID " +this.getGraph().getId());
((WorkspacePane) pane).setGraph(this.getGraph());
//pane.setFocusable(true);
// this.workspacePane.setPreferredSize();
// pane.setPreferredSize(new Dimension(200,200));
this.scrollPane = new JScrollPane(pane);
this.scrollPane.setPreferredSize(new Dimension(200, 200));
this.scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
this.scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
this.tabbedPane.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
this.tabbedPane.addTab(title, null, this.scrollPane, toolTip);
}
/**
* lösch allen TabbedPane Bevor schliessen soll ein OptionPane scheint um
* die Daten die auf die alle Überfläschen befindet gespeichert werden soll.
*
*/
public void removeAllTabbedPane() {
this.tabbedPane.removeAll();
}
/**
* lösch eine bestimmte TabbedPane Bevor schliessen soll ein OptionPane
* scheint um die Daten die auf die Überfläsche befindet gespeichert werden
* soll
*/
public void removeTabbedPaneAt(int index) {
this.tabbedPane.removeTabAt(index);
}
/**
* @return the tabbedPane
*/
public JTabbedPane getTabbedPane() {
return tabbedPane;
}
/**
* @param tabbedPane the tabbedPane to set
*/
public void setTabbedPane(JTabbedPane tabbedPane) {
this.tabbedPane = tabbedPane;
}
/**
* @return the tabbedIndex
*/
public int getTabbedIndex() {
return tabbedIndex;
}
/**
* @param tabbedIndex
* the tabbedIndex to set
*/
public void setTabbedIndex(int tabbedIndex) {
this.tabbedIndex = tabbedIndex;
}
/**
* @return the workspacePane10
* @throws MainFrameException
*/
private WorkspacePane getWorkspacePane() throws MainFrameException {
this.myFunction = "getWorkspacePane()";
this.WorkspaceController = new WorkspacePaneController();
if (this.WorkspaceController == null)
throw new MainFrameException("In der Klasse : "
+ this.getClass().getName() + ", Methode : " + ""
+ this.myFunction
+ ", WorkspaceController könnte nicht erzeugt werden....");
this.workspacePane = new WorkspacePane(this.WorkspaceController, this.getGraph());
if (this.workspacePane == null)
throw new MainFrameException("In der Klasse : "
+ this.getClass().getName() + ", Methode : " + ""
+ this.myFunction
+ ", workspacePane10 könnte nicht erzeugt werden....");
this.WorkspaceController.setView(this.workspacePane);
this.button_Menu_WorkspaceController
.setWorkspacePane(this.workspacePane);
return this.workspacePane;
}
/**
* @return the menuFrame
*/
public MenuFrame getMenuFrame() {
return menuFrame;
}
/**
* @param menuFrame
* the menuFrame to set
*/
public void setMenuFrame(MenuFrame menuFrame) {
this.menuFrame = menuFrame;
}
/**
* @return the symbolButton
*/
public SymbolButton getSymbolButton() {
return symbolButton;
}
/**
* @param symbolButton
* the symbolButton to set
*/
public void setSymbolButton(SymbolButton symbolButton) {
this.symbolButton = symbolButton;
}
/**
* @param workspacePane
* the workspacePane10 to set
*/
public void setWorkspacePane(WorkspacePane workspacePane) {
this.workspacePane = workspacePane;
}
public void releaseMainFrameController() {
// TODO Auto-generated method stub
}
public void setFactory(ObjectFactory factory) {
// TODO Auto-generated method stub
this.factory = factory;
}
}