package hallenklettern;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Connection;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.ListModel;
import javax.swing.ListSelectionModel;
import start.Config;
import functions.CreateThonList;
import functions.UIAA_Skala;
import gui.GUIBuilder;
@SuppressWarnings("serial")
public class HALLE_GUI_CreateRoute extends JFrame implements ActionListener {
// implementieren der Configuration und der Datenbank-Verbindung
private static Config config = new Config();
public HALLE_DB db = new HALLE_DB();
private static Connection con;
private UIAA_Skala skala;
private static HALLE_GUI_CreateRoute instance = null;
private JPanel top_panel;
private JPanel main_panel;
private JPanel bottom_panel;
private JPanel list_panel;
private JPanel color_panel;
private JPanel gesamt_panel;
private JTextField f1 = new JTextField();
private JTextField f2 = new JTextField();
private JTextField f3 = new JTextField();
private JTextField f4 = new JTextField();
public JTextField f5 = new JTextField();
private JList list;
private int counter;
private int thonwert;
private String name;
private String farbe;
private String schwierigkeit;
private String FEHLER = "";
private int xL = 10; // xpos Label
private int xT = 140; // xpos Textfield
private int y1 = 40;
private int y2 = 70;
private int y3 = 110;
private int y4 = 140;
private int y5 = 170;
private int h = 20;
private int h2 = 30;
private JPanel panel1, panel2;
private Container cp;
private String textFarbe;
public static void main(String[] args) {
}
public HALLE_GUI_CreateRoute() {
super("Hallen Route anlegen");
setSize(500,560);
setLocation(627, 114);
}
public static HALLE_GUI_CreateRoute getInstance() {
if(instance == null) {
instance = new HALLE_GUI_CreateRoute();
}
return instance;
}
//---------------------------------------------------------------------------------------------------------
public void createRoute() {
db.connectToDatabase();
con=db.getConnection();
db.countEntries(con, "SELECT name FROM hallenrouten WHERE wall=\""+this.name+"\"");
this.counter = db.getMaxEntries();
this.counter++;
db.close();
f1.setText(this.name); f1.setBounds(xT,y1,250,h2);
f2.setText("Deutschland"); f2.setBounds(xT,y2,80 ,h2);
f3.setText(""); f3.setBounds(xT,y3,180,h2);
f4.setText(""); f4.setBounds(xT,y4,80,h2);
f5.setText(""); f5.setBounds(xT,y5,80,h2);
// Main Panel setzen
main_panel = new JPanel();
main_panel.setLayout(null);
Label l1 = new Label("Wand",Label.RIGHT); l1.setBounds(xL,y1,120,h);
Label l2 = new Label("Land",Label.RIGHT); l2.setBounds(xL,y2,120,h);
Label l3 = new Label("Routenname",Label.RIGHT); l3.setBounds(xL,y3,120,h);
Label l4 = new Label("Schwierigkeit",Label.RIGHT); l4.setBounds(xL,y4,120,h);
Label l5 = new Label("Farbe",Label.RIGHT); l5.setBounds(xL,y5,120,h);
// Label fehler = new Label(""+FEHLER,Label.RIGHT); fehler.setBounds(370,120,80 ,h2);
// Font font = new Font("Verdana",Font.PLAIN,14);
// fehler.setFont(font);
// fehler.setForeground(Color.RED);
main_panel.add(l1);
main_panel.add(l2);
main_panel.add(l3);
main_panel.add(l4);
main_panel.add(l5);
// main_panel.add(fehler);
main_panel.add(f1);
main_panel.add(f2);
main_panel.add(f3);
main_panel.add(f4);
main_panel.add(f5);
// List panel setzen
String[] farben = {"rot","blau","gelb","grün","weiß","pink","lila","schwarz","grau","sand","orange","meliert","rot-weiß","insert","schwarz-rot"};
list = new JList(farben);
list.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
list.setSelectedIndex(0);
list.setSize(100, 50);
list.setBackground(Color.white);
list.setFixedCellHeight(12); // Sets the height of every cell in the list.
list.setFixedCellWidth(140);
list.setLocation(0,0);
list_panel = new JPanel();
list_panel.add(list);
// Top Panel setzen
top_panel = new JPanel();
top_panel.setLayout(new FlowLayout(FlowLayout.LEFT,0,0));
ImageIcon ico1 = new ImageIcon();
Image logo = getToolkit().getImage("Media/Logo_Create_HallenRoute.jpg");
ico1.setImage(logo);
JLabel reload = new JLabel();
reload.setIcon(ico1);
top_panel.add(reload);
// Farben Panel setzen
color_panel = new JPanel();
instance = new HALLE_GUI_CreateRoute();
HALLE_ColorPanel2 colorpanel = new HALLE_ColorPanel2(this.name);
color_panel.add(colorpanel);
// Bottom Panel setzen
bottom_panel = new JPanel();
Icon icon1 = new ImageIcon("Media/buttonlabel_speichern.gif");
JButton but_anlegen = new JButton("Speichern",icon1);
but_anlegen.addActionListener(this);
bottom_panel.setBackground(Color.white);
bottom_panel.add(but_anlegen);
// Container zusammensetzen
gesamt_panel = new JPanel();
gesamt_panel.add(main_panel);
panel1 = new JPanel();
panel1.setLayout(new BorderLayout());
panel1.add(top_panel , BorderLayout.NORTH);
panel1.add(main_panel , BorderLayout.CENTER);
panel2 = new JPanel();
panel2.setLayout(new BorderLayout());
panel2.add(list_panel , BorderLayout.CENTER);
panel2.add(color_panel , BorderLayout.WEST);
panel2.add(bottom_panel , BorderLayout.SOUTH);
setLayout(new GridLayout(2,1));
add(panel1);
add(panel2);
setVisible(true);
}
//-------------------------------------------------------------------------------------------------------
// Das Speichern der Datensätze --
//-------------------------------------------------------------------------------------------------------
public void actionPerformed(ActionEvent event) {
String cmd = event.getActionCommand();
if (cmd.equals("Speichern")) {
skala = new UIAA_Skala();
if ((!f3.getText().equals("")) && (!f4.getText().equals(""))) {
// selected1 = group1.getSelection();
System.out.println("Eingegebner Wert des Grades "+f4.getText());
if (f2.getText().equals("Italien")) {
schwierigkeit = skala.France_to_UIAA(f4.getText());
System.out.println("------> France----> "+schwierigkeit);
CreateThonList thon = new CreateThonList();
thonwert = thon.getThon(schwierigkeit);
}
else if (f2.getText().equals("Deutschland")) {
schwierigkeit = f4.getText();
System.out.println("------> France----> "+schwierigkeit);
CreateThonList thon = new CreateThonList();
thonwert = thon.getThon(schwierigkeit);
}
else {
schwierigkeit = f4.getText();
CreateThonList thon = new CreateThonList();
thonwert = thon.getThon(schwierigkeit);
}
ListModel lm = list.getModel();
int[] sel = list.getSelectedIndices();
for (int i = 0; i < sel.length; ++i) {
farbe = (String)lm.getElementAt(sel[i]);
System.out.println("Die ausgesuchte farbe ist : " + farbe);
}
db.connectToDatabase();
con=db.getConnection();
//
System.out.println("\n der eigentliche neueeintrag\n");
db.createRoutes(con , "INSERT INTO hallenrouten(wall,nummer,name,bezeichnung,grad,tour,land,statusT,statusN,projektT,projektN,wert,thon) VALUES (\""
+f1.getText()+"\",\""
+this.counter+"\",\""
+f3.getText()+"\",\""
+"Entreprise Graue Wand"+"\",\""
+f4.getText()+"\",\""
+farbe+"\",\""
+f2.getText()+"\",\""
+"noch nicht"+"\",\""
+"noch nicht"+"\",\""
+"nicht"+"\",\""
+"nicht"+"\",\""
+"1"+"\",\""
+thonwert+"\")");
db.close();
GUIBuilder gui = GUIBuilder.getInstance();
gui.reload_Hallenklettern_Inhalt(name,"nummer", "alles");
setDefaultCloseOperation(javax.swing.JFrame.EXIT_ON_CLOSE);
setVisible(false); // verschwinden lassen
dispose(); // abräumen
}
}
}
//----------------------------------------------------------------------------------------------------
//-- Getter und Setter --
//----------------------------------------------------------------------------------------------------
public void setUpdateID(String name) {
this.name = name;
}
public void setTextFarbe(String textFarbe) {
System.out.println("Farbe angekommen");
this.textFarbe = textFarbe;
}
public String getTextFarbe() {
return textFarbe;
}
//''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''#
public void reloadPanel(String name, String farbe) {
System.out.println("bin in reload...");
gesamt_panel.remove(main_panel);
db.connectToDatabase();
con=db.getConnection();
db.countEntries(con, "SELECT name FROM hallenrouten WHERE wall=\""+this.name+"\"");
this.counter = db.getMaxEntries();
this.counter++;
db.close();
f1.setText(this.name); f1.setBounds(xT,y1,250,h2);
f2.setText("Deutschland"); f2.setBounds(xT,y2,80 ,h2);
f3.setText(""); f3.setBounds(xT,y3,180,h2);
f4.setText(""); f4.setBounds(xT,y4,80,h2);
f5.setText(farbe); f5.setBounds(xT,y5,80,h2);
// Main Panel setzen
main_panel = new JPanel();
main_panel.setLayout(null);
Label l1 = new Label("Wand",Label.RIGHT); l1.setBounds(xL,y1,120,h);
Label l2 = new Label("Land",Label.RIGHT); l2.setBounds(xL,y2,120,h);
Label l3 = new Label("Routenname",Label.RIGHT); l3.setBounds(xL,y3,120,h);
Label l4 = new Label("Schwierigkeit",Label.RIGHT); l4.setBounds(xL,y4,120,h);
Label l5 = new Label("Farbe",Label.RIGHT); l5.setBounds(xL,y5,120,h);
// Label fehler = new Label(""+FEHLER,Label.RIGHT); fehler.setBounds(370,120,80 ,h2);
// Font font = new Font("Verdana",Font.PLAIN,14);
// fehler.setFont(font);
// fehler.setForeground(Color.RED);
main_panel.add(l1);
main_panel.add(l2);
main_panel.add(l3);
main_panel.add(l4);
main_panel.add(l5);
// main_panel.add(fehler);
main_panel.add(f1);
main_panel.add(f2);
main_panel.add(f3);
main_panel.add(f4);
main_panel.add(f5);
gesamt_panel.add(main_panel);
}
} // end All