import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import java.lang.*;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.DefaultTableColumnModel;
import javax.swing.table.TableColumn;
import java.io.*;
import java.util.Arrays;
public class test extends JFrame {
private JFileChooser jfco = new JFileChooser();
private JFileChooser jfco2 = new JFileChooser();
private JButton jButton1 = new JButton();
private JTextField jTextField1 = new JTextField();
private JButton jButton2 = new JButton();
private JButton jButton3 = new JButton();
private JRadioButton jRadioButton1 = new JRadioButton();
private JRadioButton jRadioButton2 = new JRadioButton();
private ButtonGroup jButtonGroup1 = new ButtonGroup();
private JTextField jTextField4 = new JTextField();
private JMenuBar jmb = new JMenuBar();
private JMenu jmu1 = new JMenu("Datei");
private JMenu jmu2 = new JMenu("Hilfe");
private JTable jTable1 = new JTable(0,4);
private DefaultTableModel model = (DefaultTableModel) jTable1.getModel();
private JLabel jLabel1 = new JLabel("Pfad zur Konfigurationsdatei");
private JButton jButton4 = new JButton();
public test(String title) {
super("Konfigurationstool für DelOld - ");
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
int frameWidth = 744;
int frameHeight = 569;
setSize(frameWidth, frameHeight);
Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
int x = (d.width - getSize().width) / 2;
int y = (d.height - getSize().height) / 2;
setLocation(x, y);
Container cp = getContentPane();
cp.setLayout(new BorderLayout());
jTable1.setModel(model);
jTextField1.setBounds(8, 40, 713, 24);
jTextField1.setText("");
jTextField1.setEditable(false);
cp.add(jTextField1);
jTextField4.setBounds(616, 8, 97, 24);
jTextField4.setText("");
jTextField4.setVisible(false);
cp.add(jTextField4);
jButton1.setBounds(8, 80, 187, 25);
jButton1.setText("Config auswählen");
jButton1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
jButton1_ActionPerformed(evt);
}
});
cp.add(jButton1);
jButton3.setBounds(8, 496, 715, 25);
jButton3.setText("Speichern");
jButton3.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
jButton3_ActionPerformed(evt);
}
});
cp.add(jButton3);
setJMenuBar(jmb);
jmb.add(jmu1);
jmb.add(jmu2);
Action openingAction = new AbstractAction( "Öffnen" ) {
public void actionPerformed( ActionEvent e ){
String configVerzeichnis = jfco2OpenFilename();
try {
configOpen(configVerzeichnis,model);
} catch (IOException d) {
JOptionPane.showMessageDialog( null, "Es ist ein Fehler aufgetreten, bitte den Administrator benachrichtigen" );
}
}
};
jmu1.add( openingAction );
Action savingAction = new AbstractAction( "Konfigurationsdatei Speichern" ) {
public void actionPerformed( ActionEvent e ) {
int max = jTable1.getRowCount();
int j = 0;
String Inhalt = "";
String path = jTextField1.getText();
for(int i = 0;i<max;i++){
j = 0;
Object Hauptordner = jTable1.getValueAt(i,j);
j++;
Object Anzahl = jTable1.getValueAt(i,j);
j++;
Object Art = jTable1.getValueAt(i,j);
j++;
Object Methode = jTable1.getValueAt(i,j);
if(Hauptordner.equals("") || Anzahl.equals("") || Art.equals("") || Methode.equals("")) {
System.out.println(Hauptordner);
}else {
Inhalt = Inhalt + (Hauptordner+";;;"+Anzahl+";;;"+Art+";;;"+Methode+"\r\n");
}
}
speichern(path,Inhalt);
}
};
jmu1.add( savingAction );
Action exitAction = new AbstractAction( "Programm Beenden" ) {
public void actionPerformed( ActionEvent e ) {
System.exit( 0 );
}
};
jmu1.add( exitAction );
Action infoAction = new AbstractAction( "Info" ) {
public void actionPerformed( ActionEvent e ) {
JOptionPane.showMessageDialog( null, "<html><head></head><body>Text</body></html>" );
}
};
jmu2.add( infoAction );
jTable1.setBounds(8, 112, 713, 369);
jTable1.setFont(new Font("Arial", Font.PLAIN, 17));
jTable1.setForeground(Color.BLACK);
TableColumn col = jTable1.getColumnModel().getColumn(0);
col.setPreferredWidth(320);
TableColumn col1 = jTable1.getColumnModel().getColumn(1);
col1.setPreferredWidth(50);
TableColumn col2 = jTable1.getColumnModel().getColumn(2);
col2.setPreferredWidth(130);
TableColumn col3 = jTable1.getColumnModel().getColumn(3);
col3.setPreferredWidth(130);
JScrollPane scroll = new JScrollPane(jTable1);
scroll.setVerticalScrollBarPolicy(scroll.VERTICAL_SCROLLBAR_ALWAYS);
jTable1.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
jTable1.setRowHeight(18);
jTable1.setVisible(true);
cp.add(scroll);
jLabel1.setBounds(8, 16, 194, 16);
jLabel1.setText("Pfad zur Konfigurationsdatei");
jLabel1.setFont(new Font("MS Sans Serif", Font.BOLD, 13));
cp.add(jLabel1);
jButton4.setBounds(576, 80, 147, 25);
jButton4.setText("Neuer Datensatz");
jButton4.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
jButton4_ActionPerformed(evt);
}
});
jButton4.setVisible(false);
cp.add(jButton4);
setResizable(false);
setVisible(true);
}
public String jfcoOpenFilename() {
jfco.setDialogTitle("Öffne Verzeichnis");
jfco.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
if (jfco.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
return jfco.getSelectedFile().getPath();
} else {
return null;
}
}
public String jfco2OpenFilename() {
jfco2.setDialogTitle("Öffne Datei");
jfco2.setFileSelectionMode(JFileChooser.FILES_ONLY);
if (jfco2.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
return jfco2.getSelectedFile().getPath();
} else {
return null;
}
}
public void jButton1_ActionPerformed(ActionEvent evt) {
String configVerzeichnis = jfco2OpenFilename();
try {
configOpen(configVerzeichnis, model);
} catch (IOException d) {
JOptionPane.showMessageDialog( null, "Es ist ein Fehler aufgetreten, bitte den Administrator benachrichtigen" );
}
}
public void jButton3_ActionPerformed(ActionEvent evt) {
int max = jTable1.getRowCount();
int j = 0;
String Inhalt = "";
String path = jTextField1.getText();
for(int i = 0;i<max;i++){
j = 0;
Object Hauptordner = jTable1.getValueAt(i,j);
j++;
Object Anzahl = jTable1.getValueAt(i,j);
j++;
Object Art = jTable1.getValueAt(i,j);
j++;
Object Methode = jTable1.getValueAt(i,j);
Inhalt = Inhalt + (Hauptordner+";;;"+Anzahl+";;;"+Art+";;;"+Methode+"\r\n");
}
speichern(path,Inhalt);
}
public String getSelectedRadioButton(ButtonGroup bg) {
for (java.util.Enumeration<AbstractButton> e = bg.getElements(); e.hasMoreElements();) {
AbstractButton b = e.nextElement();
if (b.isSelected()) return b.getText();
}
return null;
}
public void jButton4_ActionPerformed(ActionEvent evt) {
final JTextField PfadFeld = new JTextField();
PfadFeld.setEditable(false);
JTextField AnzahlFeld = new JTextField();
final JCheckBox MethodeFeld = new JCheckBox();
jButton2.setText("Ordner auswählen");
jButton2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
String Pfad = jfcoOpenFilename();
PfadFeld.setText(Pfad);
}
});
jRadioButton1.setText("Löschen");
jRadioButton1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
jTextField4.setText("del");
}
});
jButtonGroup1.add(jRadioButton1);
jRadioButton2.setText("Archivieren");
jRadioButton2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
jTextField4.setText("a");
}
});
jButtonGroup1.add(jRadioButton2);
MethodeFeld.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
}
});
Object[] message = {
"Pfad:", PfadFeld,
"", jButton2,
"Anzahl zu behaltende Dateien:", AnzahlFeld,
"Art:", jRadioButton1,
"Art:", jRadioButton2,
"Unterverzeichnisse einschließen:", MethodeFeld
};
JOptionPane pane = new JOptionPane(message, JOptionPane.PLAIN_MESSAGE, JOptionPane.OK_CANCEL_OPTION);
pane.createDialog(null,"Neuer Datensatz").setVisible(true);
}
public static void main(String[] args) {
new test("test");
}
public void speichern(String path, String Inhalt){
try {
BufferedWriter out = new BufferedWriter(new FileWriter(path));
out.write(Inhalt);
out.close();
JOptionPane.showMessageDialog( null, "Die Eingegebene Konfiguration wurde erfolgreich gespeichert" );
} catch (IOException e) {
JOptionPane.showMessageDialog( null, "Es ist ein Fehler aufgetreten, bitte den Administrator benachrichtigen" );
}
}
public void configOpen(String Path, DefaultTableModel model) throws IOException {
File fpath = new File(Path);
BufferedReader meinReader = new BufferedReader(new FileReader(fpath));
String configString = "";
int rowCountNow = jTable1.getRowCount();
System.out.println(rowCountNow);
if(rowCountNow > 0) {
for(int i = rowCountNow-1;i>=0;i--){
model.removeRow(i);
}
}
int rowCount = 0;
int i = 0;
int j = 0;
while((configString = meinReader.readLine())!= null) {
rowCount = rowCount + 1;
Object[] valuess = {};
model.addRow(valuess);
j = 0;
String[] split = configString.split(";;;");
String Pfad = split[0];
String Anzahlstr = split[1];
String Art = split[2];
String Methode = split[3];
jTable1.setValueAt(Pfad,i,j);
j++;
jTable1.setValueAt(Anzahlstr,i,j);
j++;
jTable1.setValueAt(Art,i,j);
j++;
jTable1.setValueAt(Methode,i,j);
jTable1.setVisible(true);
jButton4.setVisible(true);
jTextField1.setText(Path);
int Anzahl = Integer.parseInt(Anzahlstr);
i++;
}
}
}