import java.awt.BorderLayout;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JFrame;
import java.awt.Dimension;
import java.awt.GridBagLayout;
import java.awt.GridLayout;
import javax.swing.JButton;
import java.awt.Rectangle;
import java.io.File;
import javax.swing.JTextField;
import javax.swing.JTextPane;
import java.awt.SystemColor;
import java.awt.Font;
import javax.swing.JPasswordField;
public class FileHandling extends JFrame {
private static final long serialVersionUID = 1L;
private JPanel jContentPane = null;
private JPanel jPanelNorth = null;
private JPanel jPanelCenter = null;
private JPanel jPanelSouth = null;
private JButton jButtonInputFile = null;
private JButton jButtonRCFFile = null;
private JButton jButtonOutputFile = null;
private JTextField jTextFieldInputFile = null;
private JTextField jTextFieldRFCFile = null;
private JTextField jTextFieldOutputFile = null;
private JButton jButtonWeiter = null;
ConvertToXML cXML = new ConvertToXML();
JFileChooser fc = new JFileChooser(); // @jve:decl-index=0:visual-constraint="14,469"
AnalysisNumber analysis; // @jve:decl-index=0:visual-constraint="794,32"
private JTextPane jTextPane = null;
private JTextPane jTextPaneAusgabe = null;
/**
* This is the default constructor
*/
public FileHandling() {
super();
initialize();
}
/**
* This method initializes this
*
* @return void
*/
private void initialize() {
fc.setSize(new Dimension(512, 335));
this.setSize(646, 416);
this.setContentPane(getJContentPane());
this.setMinimumSize(this.getSize());
this.setTitle("JFrame");
this.setVisible(true);
}
/**
* This method initializes jContentPane
*
* @return javax.swing.JPanel
*/
private JPanel getJContentPane() {
if (jContentPane == null) {
jContentPane = new JPanel();
jContentPane.setLayout(new GridLayout(3, 1));
jContentPane.add(getJPanelNorth(), null);
jContentPane.add(getJPanelCenter(), null);
jContentPane.add(getJPanelSouth(), null);
}
return jContentPane;
}
/**
* This method initializes jPanelNorth
*
* @return javax.swing.JPanel
*/
private JPanel getJPanelNorth() {
if (jPanelNorth == null) {
jPanelNorth = new JPanel();
jPanelNorth.setLayout(null);
jPanelNorth.setFont(new Font("Dialog", Font.BOLD, 18));
jPanelNorth.setBackground(SystemColor.control);
jPanelNorth.add(getJButtonInputFile(), null);
jPanelNorth.add(getJTextFieldInputFile(), null);
jPanelNorth.add(getJTextPane(), null);
}
return jPanelNorth;
}
/**
* This method initializes jPanelCenter
*
* @return javax.swing.JPanel
*/
private JPanel getJPanelCenter() {
if (jPanelCenter == null) {
jPanelCenter = new JPanel();
jPanelCenter.setLayout(null);
jPanelCenter.setBackground(SystemColor.control);
jPanelCenter.add(getJButtonRCFFile(), null);
jPanelCenter.add(getJTextFieldRFCFile(), null);
}
return jPanelCenter;
}
/**
* This method initializes jPanelSouth
*
* @return javax.swing.JPanel
*/
private JPanel getJPanelSouth() {
if (jPanelSouth == null) {
jPanelSouth = new JPanel();
jPanelSouth.setLayout(null);
jPanelSouth.setBackground(SystemColor.control);
jPanelSouth.add(getJButtonOutputFile(), null);
jPanelSouth.add(getJTextFieldOutputFile(), null);
jPanelSouth.add(getJButtonWeiter(), null);
jPanelSouth.add(getJTextPaneAusgabe(), null);
}
return jPanelSouth;
}
/**
* This method initializes jButtonInputFile
*
* @return javax.swing.JButton
*/
private JButton getJButtonInputFile() {
if (jButtonInputFile == null) {
jButtonInputFile = new JButton();
jButtonInputFile.setBounds(new Rectangle(30, 59, 122, 43));
jButtonInputFile.setText("CSV File");
jButtonInputFile.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
fc.setCurrentDirectory(new File("D:/GPS Translator/Daten/Bearbeitete Daten"));
if (e.getSource() == jButtonInputFile) {
int returnVal = fc.showOpenDialog(FileHandling.this);
if (returnVal == JFileChooser.APPROVE_OPTION) {
File file = fc.getSelectedFile();
jTextFieldInputFile.setText(file.getAbsolutePath());
}
}
}
});
}
return jButtonInputFile;
}
/**
* This method initializes jButtonRCFFile
*
* @return javax.swing.JButton
*/
private JButton getJButtonRCFFile() {
if (jButtonRCFFile == null) {
jButtonRCFFile = new JButton();
jButtonRCFFile.setBounds(new Rectangle(32, 35, 127, 43));
jButtonRCFFile.setText("RCF File");
jButtonRCFFile.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
fc.setCurrentDirectory(new File("D:/GPS Translator/Daten/Releasecauses"));
if (e.getSource() == jButtonRCFFile) {
int returnVal = fc.showOpenDialog(FileHandling.this);
if (returnVal == JFileChooser.APPROVE_OPTION) {
File file = fc.getSelectedFile();
jTextFieldRFCFile.setText(file.getAbsolutePath());
}
}
}
});
}
return jButtonRCFFile;
}
private void initAuswertung(){
analysis = new AnalysisNumber(this);
}
/**
* This method initializes jButtonOutputFile
*
* @return javax.swing.JButton
*/
private JButton getJButtonOutputFile() {
if (jButtonOutputFile == null) {
jButtonOutputFile = new JButton();
jButtonOutputFile.setBounds(new Rectangle(31, 39, 128, 43));
jButtonOutputFile.setText("Output File");
jButtonOutputFile.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
fc.setCurrentDirectory(new File("D:/GPS Translator"));
if (e.getSource() == jButtonOutputFile) {
int returnVal = fc.showOpenDialog(FileHandling.this);
if (returnVal == JFileChooser.APPROVE_OPTION) {
File file = fc.getSelectedFile();
jTextFieldOutputFile.setText(file.getAbsolutePath());
}
}
}
});
}
return jButtonOutputFile;
}
/**
* This method initializes jTextFieldInputFile
*
* @return javax.swing.JTextField
*/
private JTextField getJTextFieldInputFile() {
if (jTextFieldInputFile == null) {
jTextFieldInputFile = new JTextField();
jTextFieldInputFile.setBounds(new Rectangle(185, 61, 399, 43));
jTextFieldInputFile.setText("Bitte wählen sie eine Standortdatei aus");
}
return jTextFieldInputFile;
}
/**
* This method initializes jTextFieldRFCFile
*
* @return javax.swing.JTextField
*/
private JTextField getJTextFieldRFCFile() {
if (jTextFieldRFCFile == null) {
jTextFieldRFCFile = new JTextField();
jTextFieldRFCFile.setBounds(new Rectangle(187, 37, 399, 43));
jTextFieldRFCFile.setText("Bitte wählen sie eine Releasecausedatei aus");
}
return jTextFieldRFCFile;
}
/**
* This method initializes jTextFieldOutputFile
*
* @return javax.swing.JTextField
*/
private JTextField getJTextFieldOutputFile() {
if (jTextFieldOutputFile == null) {
jTextFieldOutputFile = new JTextField();
jTextFieldOutputFile.setBounds(new Rectangle(186, 41, 399, 43));
jTextFieldOutputFile.setToolTipText("Bitte nur in Verbindung mit Dateistrukturveränderungen ändern");
jTextFieldOutputFile.setText("D:/GPS Translator/data.xml");
}
return jTextFieldOutputFile;
}
/**
* This method initializes jButtonWeiter
*
* @return javax.swing.JButton
*/
private JButton getJButtonWeiter() {
if (jButtonWeiter == null) {
jButtonWeiter = new JButton();
jButtonWeiter.setBounds(new Rectangle(508, 89, 110, 29));
jButtonWeiter.setText("Weiter");
jButtonWeiter.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
cXML.getMerge().getEinlesen().setInputFilename(getJTextFieldInputFile().getText());
cXML.getMerge().getEinlesen().setRFCFilename(getJTextFieldRFCFile().getText());
cXML.setOutputFilename(getJTextFieldOutputFile().getText());
if (cXML.getMerge().getEinlesen().getInputFilename().endsWith("csv") && cXML.getOutputFilename().endsWith("gpx")|| cXML.getOutputFilename().endsWith("xml") && cXML.getMerge().getEinlesen().getRFCFilename().endsWith("csv")){
cXML.getMerge().merge();
JOptionPane.showMessageDialog(null, "Umwandlung erfolgreich abgeschlossen!", "GPS Translator", JOptionPane.OK_CANCEL_OPTION);
initAuswertung();
}else{
JOptionPane.showMessageDialog(null, "Bitte Eingaben kontrollieren und auf Dateiendung achten", "GPS Translator", JOptionPane.OK_CANCEL_OPTION);
}
}
});
}
return jButtonWeiter;
}
/**
* This method initializes jTextPane
*
* @return javax.swing.JTextPane
*/
private JTextPane getJTextPane() {
if (jTextPane == null) {
jTextPane = new JTextPane();
jTextPane.setBounds(new Rectangle(178, 3, 234, 50));
jTextPane.setFont(new Font("Dialog", Font.BOLD, 18));
jTextPane.setEditable(false);
jTextPane.setBackground(SystemColor.control);
jTextPane.setText("GPS Translator");
}
return jTextPane;
}
/**
* This method initializes jTextPaneAusgabe
*
* @return javax.swing.JTextPane
*/
private JTextPane getJTextPaneAusgabe() {
if (jTextPaneAusgabe == null) {
jTextPaneAusgabe = new JTextPane();
jTextPaneAusgabe.setBounds(new Rectangle(238, -4, 126, 30));
jTextPaneAusgabe.setBackground(SystemColor.control);
jTextPaneAusgabe.setEditable(false);
jTextPaneAusgabe.setFont(new Font("Dialog", Font.BOLD, 18));
jTextPaneAusgabe.setText("Ausgabedatei");
}
return jTextPaneAusgabe;
}
} // @jve:decl-index=0:visual-constraint="137,9"
import java.awt.BorderLayout;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JPanel;
import javax.swing.JFrame;
import javax.swing.JTextPane;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.Rectangle;
import java.awt.SystemColor;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.LinkedList;
import javax.swing.JTextField;
public class AnalysisNumber extends JFrame implements WindowListener
{
private static final long serialVersionUID = 1L;
private JPanel jContentPane = null;
private JPanel jPaneRCF = null;
private JPanel jPaneFreq = null;
private JPanel jPaneGenerate = null;
private JComboBox jComboBoxRCFauswahl = null;
private JTextPane jTextPaneRCF = null;
private JTextPane jTextPaneFreq = null;
private LinkedList<Releasecause> listeDerRC = new LinkedList<Releasecause>(); // @jve:decl-index=0:
private FileHandling fc;
private JButton jButtonGenerate = null;
private JButton jButtonAuswertung = null;
private String allRCF= "Alle Releasecauses";
File data = new File("C:/Users/T-OPC/GPS Translator/data.xml"); // @jve:decl-index=0:
private JTextField haeufigkeit = null;
/**
* This is the default constructor
*/
public AnalysisNumber(FileHandling file) {
super();
initialize();
this.fc = file;
}
/**
* This method initializes this
*
* @return void
*/
private void initialize() {
this.setSize(546, 324);
this.setContentPane(getJContentPane());
this.setMinimumSize(this.getSize());
this.setTitle("JFrame");
this.setVisible(true);
}
public LinkedList<Releasecause> readfile(){
FileReader myFile = null;
BufferedReader buff = null;
try {
myFile = new FileReader("C:/Users/T-OPC/GPS Translator/RCF.csv");
buff = new BufferedReader(myFile);
String line;
while ((line = buff.readLine()) != null) {
line = line.replaceAll(",", ".");
String[] splitted = line.split(";");
Releasecause rc = new Releasecause(splitted[0], splitted[1]);
listeDerRC.add(rc);
}
} catch (IOException e) {
System.err.println("Error2 :" + e);
} finally {
try {
buff.close();
myFile.close();
} catch (IOException e) {
System.err.println("Error2 :" + e);
}
}
return listeDerRC;
}
/**
* This method initializes jContentPane
*
* @return javax.swing.JPanel
*/
private JPanel getJContentPane() {
if (jContentPane == null) {
jContentPane = new JPanel(new GridLayout(3,1));
jContentPane.add(getJPaneRCF(), null);
jContentPane.add(getJPaneFreq(), null);
jContentPane.add(getJPaneGenerate(), null);
}
return jContentPane;
}
private JPanel getJPaneRCF() {
if (jPaneRCF == null) {
jPaneRCF = new JPanel();
jPaneRCF.setLayout(null);
jPaneRCF.setFont(new Font("Dialog", Font.BOLD, 18));
jPaneRCF.setBackground(SystemColor.control);
jPaneRCF.add(getJTextPaneRCF(), null);
jPaneRCF.add(getJComboBoxRCFauswahl(), null);
}
return jPaneRCF;
}
private JComboBox getJComboBoxRCFauswahl() {
readfile();
if (jComboBoxRCFauswahl == null) {
jComboBoxRCFauswahl = new JComboBox();
jComboBoxRCFauswahl.setBounds(new Rectangle(17, 43, 417, 43));
}
jComboBoxRCFauswahl.addItem(allRCF);
Releasecause[] rcf = new Releasecause[listeDerRC.size()];
listeDerRC.toArray(rcf);
for(int i = 0; i<listeDerRC.size(); i++){
jComboBoxRCFauswahl.addItem(rcf[i].getReleasecause()+ " "+ rcf[i].getBeschreibung());
}
return jComboBoxRCFauswahl;
}
private JTextPane getJTextPaneRCF() {
if (jTextPaneRCF == null) {
jTextPaneRCF = new JTextPane();
jTextPaneRCF.setBounds(new Rectangle(18, 11, 139, 30));
jTextPaneRCF.setEditable(false);
jTextPaneRCF.setBackground(SystemColor.control);
jTextPaneRCF.setFont(new Font("Dialog", Font.BOLD, 18));
jTextPaneRCF.setText("Releasecauses");
}
return jTextPaneRCF;
}
/**
* This method initializes jPanelCenter
*
* @return javax.swing.JPanel
*/
private JPanel getJPaneFreq() {
if (jPaneFreq == null) {
jPaneFreq = new JPanel();
jPaneFreq.setLayout(null);
jPaneFreq.setBackground(SystemColor.control);
jPaneFreq.add(getJTextPaneFreq(), null);
jPaneFreq.add(getHaeufigkeit(), null);
}
return jPaneFreq;
}
private JTextPane getJTextPaneFreq() {
if (jTextPaneFreq == null) {
jTextPaneFreq = new JTextPane();
jTextPaneFreq.setBounds(new Rectangle(22, 10, 94, 30));
jTextPaneFreq.setEditable(false);
jTextPaneFreq.setFont(new Font("Dialog", Font.BOLD, 18));
jTextPaneFreq.setBackground(SystemColor.control);
jTextPaneFreq.setBounds(new Rectangle(26, 5, 94, 30));
jTextPaneFreq.setText("Häufigkeit");
}
return jTextPaneFreq;
}
/**
* This method initializes jPanelSouth
*
* @return javax.swing.JPanel
*/
private JPanel getJPaneGenerate() {
if (jPaneGenerate == null) {
jPaneGenerate = new JPanel();
jPaneGenerate.setLayout(null);
jPaneGenerate.setBackground(SystemColor.control);
jPaneGenerate.add(getJButtonAuswertung(), null);
}
return jPaneGenerate;
}
public void FensterÖffnen() throws IOException{
String url = "D:/GPS Translator/karte.htm";
new ProcessBuilder( "rundll32", "url.dll,FileProtocolHandler", url ).start();
}
/**
* This method initializes jButtonAuswertung
*
* @return javax.swing.JButton
*/
private JButton getJButtonAuswertung() {
if (jButtonAuswertung == null) {
jButtonAuswertung = new JButton();
jButtonAuswertung.setBounds(new Rectangle(358, 35, 162, 45));
jButtonAuswertung.setText("Auswertung");
jButtonAuswertung.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
int freq = Integer.parseInt(haeufigkeit.getText());
if(jComboBoxRCFauswahl.getSelectedItem().equals(allRCF)){
fc.cXML.getMerge().setAuswertungFreq(freq);
fc.cXML.getMerge().auswertungAll();
fc.cXML.translate();
try {
FensterÖffnen();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}else{
String rcgesamt = jComboBoxRCFauswahl.getSelectedItem().toString();
String[] rc = rcgesamt.split(" ");
for(int i = 0; i<rc.length;){
fc.cXML.getMerge().setAuswertungRC(rc[0]);
break;
}
fc.cXML.getMerge().setAuswertungFreq(freq);
fc.cXML.getMerge().auswertung();
fc.cXML.translate();
try {
FensterÖffnen();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
data.deleteOnExit();
}
}
});
}
return jButtonAuswertung;
}
/**
* This method initializes haeufigkeit
*
* @return javax.swing.JTextField
*/
private JTextField getHaeufigkeit() {
if (haeufigkeit == null) {
haeufigkeit = new JTextField();
haeufigkeit.setBounds(new Rectangle(22, 58, 69, 26));
}
return haeufigkeit;
}
@Override
public void windowActivated(WindowEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void windowClosed(WindowEvent arg0) {
arg0.getWindow().dispose();
}
@Override
public void windowClosing(WindowEvent e) {
System.exit(0);
}
@Override
public void windowDeactivated(WindowEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void windowDeiconified(WindowEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void windowIconified(WindowEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void windowOpened(WindowEvent arg0) {
// TODO Auto-generated method stub
}
} // @jve:decl-index=0:visual-constraint="10,10"