package jobaapp;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.net.URL;
import java.net.MalformedURLException;
import javax.swing.*;
/**
* JobaGui
*
* Die Klasse stellt eine dumme Gui.
*
* @author jay
* @version 0.2
*
*/
public class JobaGui implements ActionListener
{
/** Fenster der Gui */
private JFrame frame;
/** Menu Container */
private JMenuBar menuBar;
/**
* Panel der Hauptzeichenflächen, die dann die Container halten
* in denen wirklich geschrieben wird.
*/
private JPanel panelCenter;
private JPanel panelStart;
private JPanel panelRight;
private JPanel panelBottom;
private JPanel panelLeft;
/** Hauptbereich */
private JPanel centerPanel;
/** Headerbereich */
private JPanel headerPanel;
/** StatusPanel, also das Panel auf der rechten Seite */
private JPanel statusPanel;
private JLabel textStatusPanelLabel;
/** FooterPanel */
private JPanel footerPanel;
/** OptionPanel auf der linken Seite */
private JPanel optionPanel;
/** Textfelder zur Parameterübergabe, analog zu $_POST in PHP */
private JTextField dollarPostStringOne;
private JTextField dollarPostStringTwo;
/** Konstruktor ohne Parameter */
public JobaGui()
{
// Frame erzeugen
JFrame frame = new JFrame( "JobaApp" );
this.frame = frame;
frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
// Menu erzeugen
this.menuBar = new JMenuBar();
JMenu fileMenu = new JMenu( "Datei" );
JMenu editMenu = new JMenu( "Bearbeiten" );
JMenu actionMenu = new JMenu( "Anwendungen" );
JMenu extrasMenu = new JMenu( "Extras" );
JMenu helpMenu = new JMenu( "Hilfe" );
// Submenus anlegen
// Submenu File Menu
JMenuItem fileSubMenuOne = new JMenuItem( "Neu ..." ); // TODO
JMenuItem fileSubMenuTwo = new JMenuItem( "Speichern"); // TODO
JMenuItem fileSubMenuThree = new JMenuItem( "Speichern unter ..."); // TODO
JMenuItem fileSubMenuFour = new JMenuItem( "Beenden"); // TODO
fileMenu.add(fileSubMenuOne);
fileMenu.add(fileSubMenuTwo);
fileMenu.add(fileSubMenuThree);
fileMenu.add(fileSubMenuFour);
// Submenu editMenu
JMenuItem editSubMenuOne = new JMenuItem( "Rückgängig machen" ); // TODO
//bearbeitenSubMenuEins.addActionListener(this); // TODO
editMenu.add( editSubMenuOne );
// Submenu actionMenu with subSubMenu
JMenu actionSubMenuOne = new JMenu( "Bioinformatik" );
JMenu actionSubMenuTwo = new JMenu( "Gesundheit" );
JMenu actionSubMenuTwoPointFive = new JMenu( "Geometrie" );
JMenu actionSubMenuThree = new JMenu( "Kryptographie");
JMenu actionSubMenuFour = new JMenu( "Mathematik" );
JMenu actionSubSubMenuOne = new JMenu( "Algorithmen" );
JMenuItem actionSubSubMenuOneItemOne = new JMenuItem( "Dotplot" );
JMenuItem actionSubSubMenuOneItemOnePointFive = new JMenuItem("Levenshtein");
JMenuItem actionSubSubMenuOneItemTwo = new JMenuItem( "Needleman-Wunsch");
actionSubSubMenuOneItemOne.addActionListener(this);
actionSubSubMenuOneItemOnePointFive.addActionListener(this);
actionSubSubMenuOneItemTwo.addActionListener(this);
JMenu actionSubSubMenuTwo = new JMenu( "Algorithmen" );
JMenuItem actionSubSubMenuTwoItemOne = new JMenuItem( "Body-Mass-Index" );
JMenuItem actionSubSubMenuTwoItemTwo = new JMenuItem( "Broca-Index" );
actionSubSubMenuTwoItemOne.addActionListener( this );
actionSubSubMenuTwoItemTwo.addActionListener( this );
JMenu actionSubSubMenuTwoPointFive = new JMenu( "Algorithmen");
JMenuItem actionSubSubMenuTwoPointFiveItemOne = new JMenuItem( "Convex-Hull");
actionSubSubMenuTwoPointFiveItemOne.addActionListener( this );
JMenu actionSubSubMenuThree = new JMenu( "Algorithmen");
JMenuItem actionSubSubMenuThreeItemOne = new JMenuItem( "Cäsar-Chiffre" );
JMenuItem actionSubSubMenuThreeItemTwo = new JMenuItem( "ROT13");
actionSubSubMenuThreeItemOne.addActionListener(this);
actionSubSubMenuThreeItemTwo.addActionListener(this);
JMenu actionSubSubMenuFour = new JMenu ( "Algorithmen" );
JMenuItem actionSubSubMenuFourItemOne = new JMenuItem( "Fibonacci-Folge" );
actionSubSubMenuFourItemOne.addActionListener(this);
// Einhängeoperationen der Menus
actionSubSubMenuOne.add(actionSubSubMenuOneItemOne);
actionSubSubMenuOne.add(actionSubSubMenuOneItemOnePointFive);
actionSubSubMenuOne.add(actionSubSubMenuOneItemTwo);
actionSubMenuOne.add(actionSubSubMenuOne);
actionSubSubMenuTwo.add( actionSubSubMenuTwoItemOne );
actionSubSubMenuTwo.add( actionSubSubMenuTwoItemTwo );
actionSubMenuTwo.add( actionSubSubMenuTwo );
actionSubSubMenuTwoPointFive.add( actionSubSubMenuTwoPointFiveItemOne );
actionSubMenuTwoPointFive.add( actionSubSubMenuTwoPointFive );
actionSubSubMenuThree.add( actionSubSubMenuThreeItemOne);
actionSubSubMenuThree.add( actionSubSubMenuThreeItemTwo);
actionSubMenuThree.add( actionSubSubMenuThree );
actionSubSubMenuFour.add( actionSubSubMenuFourItemOne );
actionSubMenuFour.add( actionSubSubMenuFour );
actionMenu.add( actionSubMenuOne );
actionMenu.add( actionSubMenuTwo );
actionMenu.add( actionSubMenuTwoPointFive);
actionMenu.add( actionSubMenuThree);
actionMenu.add( actionSubMenuFour );
// Submenu extraMenu
JMenu extrasSubMenuOne = new JMenu( "Look and Feel wechseln" );
JMenuItem extrasSubSubMenuOne = new JMenuItem( "Standard-LAF");
JMenuItem extrasSubSubMenuTwo = new JMenuItem( "Metal-LAF");
//extrasSubSubMenuZwei.addActionListener(this); // Action
extrasSubMenuOne.add(extrasSubSubMenuOne);
extrasSubMenuOne.add(extrasSubSubMenuTwo);
extrasMenu.add( extrasSubMenuOne);
// submenu helpMenu
JMenuItem helpSubMenuOne = new JMenuItem( "Dokumentation" );
helpSubMenuOne.addActionListener(this);
helpMenu.add(helpSubMenuOne);
// add menus to MenuBar
this.menuBar.add(fileMenu);
this.menuBar.add(editMenu);
this.menuBar.add(actionMenu);
this.menuBar.add(extrasMenu);
this.menuBar.add(helpMenu);
frame.setJMenuBar(this.menuBar);
// Use BorderLayoutManager
frame.setLayout( new BorderLayout(5, 5));
// Set JavaLookAndFeel
JFrame.setDefaultLookAndFeelDecorated(false);
// Komponentenpanels
this.panelCenter = new JPanel();
this.panelStart = new JPanel();
this.panelLeft = new JPanel();
this.panelRight = new JPanel();
this.panelBottom = new JPanel();
// build CenterArea
this.centerPanel = this.buildCenterPanel();
// build StartArea
this.headerPanel = this.buildHeaderPanel();
// build RightArea
this.statusPanel = this.buildStatusPanel();
// build FooterArea
this.footerPanel = this.buildFooterPanel();
// build LeftArea
this.optionPanel = this.buildOptionPanel();
// bring ContentArea together
this.panelCenter.add(this.centerPanel);
this.panelStart.add(this.headerPanel);
this.panelLeft.add(this.optionPanel);
this.panelRight.add(this.statusPanel);
this.panelBottom.add(this.footerPanel);
// relate the frame to the borderLayout
frame.add( this.panelStart, BorderLayout.PAGE_START );
frame.add( this.panelLeft, BorderLayout.LINE_START );
frame.add( this.panelCenter );
frame.add( this.panelRight, BorderLayout.LINE_END );
frame.add( this.panelBottom, BorderLayout.PAGE_END );
frame.pack(); // get PreferredSize to start rendering
frame.setVisible( true );
}
/** erstelle und gebe das CenterPanel aus */
public JPanel buildCenterPanel()
{
this.centerPanel = new JPanel();
JPanel welcomeTextPanel = new JPanel();
// Use a JTextArea (FlowLayoutManager by default)
String welcomeText = new String(
" *** Überblick JobaApps *** \n" +
" Hier kannst du diverse interssante Sachen machen:\n" +
" * Unter Anwendungen findest du alle Programme.\n" +
" * Die anderen Menüs sind allgemeiner Natur.\n" +
" * Links im Panel ist eine Info zum Anwendungsablauf.\n" +
" * Rechts im Panel ist eine Statusübersicht.\n");
JTextArea welcomeTextArea = new JTextArea(welcomeText);
Dimension dimwta = new Dimension(500, 300);
welcomeTextArea.setSize(dimwta);
welcomeTextArea.setFont(new Font("Nimbus Mono L", Font.PLAIN, 14 ));
welcomeTextArea.setLineWrap(true);
welcomeTextArea.setWrapStyleWord(true);
welcomeTextArea.setEditable(false);
welcomeTextPanel.add(welcomeTextArea);
Dimension dim = new Dimension( 600, 600 );
this.centerPanel.setPreferredSize(dim);
this.centerPanel.setBackground(Color.white);
this.centerPanel.add(welcomeTextPanel);
return this.centerPanel;
}
/** HeaderPanel erstellen und ausgeben */
public JPanel buildHeaderPanel()
{
this.headerPanel = new JPanel();
String hps = new String("JobaApps");
JTextArea headerPanelTextArea = new JTextArea(hps);
headerPanelTextArea.setFont(new Font( "Nimbus Mono L", Font.BOLD, 26));
headerPanelTextArea.setEditable(false);
this.headerPanel.add(headerPanelTextArea);
return this.headerPanel;
}
/** StatusPanel erstellen und ausgeben */
public JPanel buildStatusPanel()
{
this.statusPanel = new JPanel();
this.statusPanel.setBorder(BorderFactory.createLineBorder(Color.white));
// replace statusPanel-Content
JTextArea jta = new JTextArea();
jta.setBorder(null);
jta.setEditable(false);
jta.setLineWrap(true);
jta.setWrapStyleWord(true);
Dimension dim = new Dimension(150, 590);
jta.setPreferredSize(dim);
jta.setText(
"Status:\n" +
"Ort - Startbildschirm"
);
this.statusPanel.add(jta);
//Dimension dim = new Dimension( 200, 600 );
//this.statusPanel.setPreferredSize(dim);
return this.statusPanel;
}
/** footer-Panel erstellen und ausgeben */
public JPanel buildFooterPanel()
{
this.footerPanel = new JPanel();
JLabel label = new JLabel("Bei Problemen und Fragen: [email]info@jochen-bauer.net[/email]");
this.footerPanel.add(label);
return this.footerPanel;
}
/** OptionPanel erstellen und ausgeben */
public JPanel buildOptionPanel()
{
this.optionPanel = new JPanel();
this.optionPanel.setBorder(BorderFactory.createLineBorder(Color.white));
JTextArea jta = new JTextArea();
jta.setBorder(null);
jta.setEditable(false);
jta.setLineWrap(true);
jta.setWrapStyleWord(true);
Dimension dim = new Dimension(150, 590);
jta.setPreferredSize(dim);
jta.setText(
"Bedienung: \n" +
"* Keine weiteren Infos."
);
this.optionPanel.add(jta);
//Dimension dim = new Dimension(200, 600);
//this.optionPanel.setPreferredSize(dim);
return this.optionPanel;
}
/**
* ActionHandler
*
* Die Actions werden nach dem Alphabet geordnet und zwar
* nach dem Menueintrag, darunter folgt die Antwortansicht
* und dann der nächste Eintrag. Am Anfang und am Ende sind
* zwei Dummy-Einträge - alles andere im 'else if'-Teil.
*/
public void actionPerformed(ActionEvent e)
{
if ( e.getActionCommand() == "LAF-Wechsel" )
{
// TODO
}
else if ( e.getActionCommand() == "Dotplot")
{
...
}
else if ( e.getActionCommand() == "Convex-Hull")
{
// replace statusPanel-Content
JTextArea jta = new JTextArea();
jta.setBorder(null);
jta.setEditable(false);
jta.setLineWrap(true);
jta.setWrapStyleWord(true);
Dimension dim = new Dimension(150, 590);
jta.setPreferredSize(dim);
jta.setText(
"Status:\n" +
"Ort - Geometrie | Convex-Hull"
);
this.statusPanel.removeAll();
this.statusPanel.add(jta);
this.statusPanel.revalidate();
this.statusPanel.repaint();
// replace centerPanel Content
this.centerPanel.removeAll();
JPanel convexHullPanel = new JPanel();
JLabel convexHullHeaderLabel = new JLabel( "Convex-Hull berechnen" );
JTextField convexHullInputField = new JTextField( "hier Punkte eintragen etwa 23,17;66,77;");
// die JTextFields ein die Transfercontainer uebergeben
this.dollarPostStringOne = convexHullInputField;
JButton convexHullButton = new JButton("Convex-Hull berechnen");
convexHullButton.addActionListener( this );
convexHullPanel.add( convexHullHeaderLabel );
convexHullPanel.add( convexHullInputField );
convexHullPanel.add( convexHullButton);
this.centerPanel.add( convexHullPanel );
this.centerPanel.revalidate();
this.centerPanel.repaint();
}
else if ( e.getActionCommand() == "Convex-Hull berechnen")
{
// replace centerPanel Content
this.centerPanel.removeAll();
// Kopf
JPanel convexHullPanel = new JPanel();
// Punkte in den Konstruktor einspeisen
// Array uebergeben - lafft
// TODO Array waere besser wenn es übernommen wird
int[][] points = {
{ 200, 200 },
{ 160, 320 },
{ 245, 40 },
{ 80, 220 },
{ 40, 180 },
{ 260, 175 },
{ 180, 50 },
{ 100, 160 }
};
// Objekt anlegen
JobaConvexHull jobaConvexHullObject = new JobaConvexHull(points); // Konstruktor startet dazu computeConvexHull()
// Punkt anfuegen
// Punkt verschieben
// Punkt loeschen
// Debugging-Anweisungen
// DebugFrame anzeigen, der JInternalFrame samt Inhalt kommt aus JobaConvexHull,
// JInternalFrames brauchen aber gewissen Umstände, etwa einen JFrame als Elternteil und
// ein JDesktopPane als Träger der JInternalFrames. Selbst wird das JDesktopPane am main-Frame
// eingehängt.
// Ausgangspunkte ausgeben
int[][] returnInputPunkteArray = jobaConvexHullObject.getPoints();
String debuggingStringFromJobaGuiToJobaConvexHull = new String("");
debuggingStringFromJobaGuiToJobaConvexHull += " +++++ Debugging String aus JobaGui +++++";
debuggingStringFromJobaGuiToJobaConvexHull += "\n Liste der Eingabepunkte: \n";
for ( int i = 0; i < returnInputPunkteArray.length; i++ ) // Laenge des Punktearray, also P1 bis Pn
{
debuggingStringFromJobaGuiToJobaConvexHull += "P" + (i+1) + " ( ";
for ( int j = 0; j < returnInputPunkteArray[i].length; j++ ) // Punktekoordinaten, einmal auf 0 der X-Wert, auf 1 der Y-Wert
{
debuggingStringFromJobaGuiToJobaConvexHull += returnInputPunkteArray[i][j] + " ; ";
}
debuggingStringFromJobaGuiToJobaConvexHull += " )\n";
}
// Punktearray anzeigen
int[][] convexHullPoints = jobaConvexHullObject.getConvexHullPoints();
String debuggingStringFromJobaConvexHullToJobaGui = new String("");
debuggingStringFromJobaConvexHullToJobaGui += " +++++ Debugging String aus JobaConvexHull +++++";
for ( int i = 0; i < convexHullPoints.length; i++ ) // Laenge des Punktearray, also P1 bis Pn
{
debuggingStringFromJobaConvexHullToJobaGui += "P" + (i+1) + " ( ";
for ( int j = 0; j < convexHullPoints[i].length; j++ ) // Punktekoordinaten, einmal auf 0 der X-Wert, auf 1 der Y-Wert
{
debuggingStringFromJobaConvexHullToJobaGui += convexHullPoints[i][j] + " ; ";
}
debuggingStringFromJobaConvexHullToJobaGui += " )\n";
}
String debugString = new String();
debugString = jobaConvexHullObject.getDebugString();
Container container = frame.getContentPane();
JDesktopPane desktop = new JDesktopPane();
container.add( desktop );
JInternalFrame debugFrame = new JInternalFrame(
"Debug-InternalFrame-Convex-Hull", // title
true, // resizeable
true, // closeable
true, // maximizeable
true // iconifiable, minimierbar
);
debugFrame.setSize(600, 200);
Font debugFrameFont = new Font("Nimbus Mono L", Font.PLAIN, 12 );
JTextArea debugFrameTextArea = new JTextArea();
JScrollPane debugFrameScrollPane = new JScrollPane( debugFrameTextArea ); // ScrollPane die TextArea geben
debugFrameTextArea.setFont(debugFrameFont);
debugFrameTextArea.setEditable(false);
debugFrameTextArea.setText(debugString + debuggingStringFromJobaGuiToJobaConvexHull + debuggingStringFromJobaConvexHullToJobaGui);
debugFrame.add(debugFrameScrollPane); // ScrollPane einhängen bei JIF
debugFrame.setVisible(true);
desktop.add( debugFrame );
this.centerPanel.add( convexHullPanel );
this.centerPanel.revalidate();
this.centerPanel.repaint();
}
else if ( e.getActionCommand() == "Dokumentation")
{
...
}
else if ( e.getActionCommand() == "Fibonacci-Folge" )
{
this.centerPanel.removeAll();
// replace statusPanel-Content
JTextArea jta = new JTextArea();
jta.setBorder(null);
jta.setEditable(false);
jta.setLineWrap(true);
jta.setWrapStyleWord(true);
Dimension dim = new Dimension(150, 590);
jta.setPreferredSize(dim);
jta.setText(
"Status: Ort - Mathematik | Fibonacci-Folge"
);
this.statusPanel.removeAll();
this.statusPanel.add(jta);
this.statusPanel.revalidate();
this.statusPanel.repaint();
JTextField fibonacciInputString = new JTextField( "10");
this.dollarPostStringOne = fibonacciInputString;
JButton fibonacciButton = new JButton("Fibonacci-Folge berechnen");
fibonacciButton.addActionListener(this);
this.centerPanel.add(fibonacciInputString);
this.centerPanel.add(fibonacciButton);
this.centerPanel.revalidate();
this.centerPanel.repaint();
}
else if ( e.getActionCommand() == "Fibonacci-Folge berechnen" )
{
this.centerPanel.removeAll();
// TODO es gibt bei der Eingabe 48 eine Absturz, wahrscheinlich ein Überlauf?!
// String als int parsen und Konstruktor aufrufen
int n = Integer.parseInt(this.dollarPostStringOne.getText());
JobaFibonacci jobaFibonacci = new JobaFibonacci(n);
JLabel jlf = new JLabel(""+jobaFibonacci.getFib());
this.centerPanel.add(jlf);
this.centerPanel.revalidate();
this.centerPanel.repaint();
}
else
{
// Dialogue if an actionListener is registrated but doesn't work
}
}
/** MouseActionHandler */
public void mouseClicked(MouseEvent me)
{
if ( me.getButton() == MouseEvent.BUTTON1 )
{
JOptionPane.showMessageDialog(null, "BUTTON 1 wurde geklickt.");
}
else
{
JOptionPane.showMessageDialog(null, "Oha so war das mit dem Mausklick nicht gemeint.");
}
}
public void mouseEntered(MouseEvent me){}
public void mouseExited(MouseEvent me){}
public void mousePressed(MouseEvent me){}
public void mouseReleased(MouseEvent me){}
/** main-Methode zum Programmeinstieg */
public static void main ( String[] args )
{
new JobaGui();
}
}