public class mskMaFr extends JFrame {
private JPanel jContentPane = null;
private JMenuBar jJMenuBar = null;
private JMenu fileMenu = null;
private JMenu editMenu = null;
private JMenu helpMenu = null;
private JMenuItem exitMenuItem = null;
private JMenuItem aboutMenuItem = null;
private JMenuItem cutMenuItem = null;
private JMenuItem copyMenuItem = null;
private JMenuItem pasteMenuItem = null;
private JMenuItem saveMenuItem = null;
private JMenuItem openMenuItem = null;
private JMenuItem openFMenuItem = null;
private JMenuItem searMenuItem = null;
private JMenuItem newMenuItem = null;
private JScrollPane jScrollPane = null;
private JDialog searDial = null;
private JPanel diaCo = null;
private JTable mscTab = null;
private String[] col = new String[] {"Name","Liste"};
private String[] [] row = new String[] [] {{"",""}};
private Object tdat;
private JList nList = null;
private JButton newListBtn = null;
private JButton remListBtn = null;
private JTextField nTex = null;
private JButton nOkBtn = null;
private JButton nCaBtn = null;
private JButton sOkBtn = null;
/**
* This is the default constructor
*/
public mskMaFr() {
super();
initialize();
}
/**
* This method initializes this
*
* @return void
*/
private void initialize() {
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setJMenuBar(getJJMenuBar());
this.setSize(455, 355);
this.setContentPane(getJContentPane());
this.setTitle("Application");
this.nOkBtn.setVisible(false);
this.nCaBtn.setVisible(false);
this.nTex.setVisible(false);
this.sOkBtn.setVisible(false);
}
/**
* This method initializes jContentPane
*
* @return javax.swing.JPanel
*/
private JPanel getJContentPane() {
if (jContentPane == null) {
jContentPane = new JPanel();
jContentPane.setLayout(null);
jContentPane.add(getJScrollPane(), null);
jContentPane.add(getNList(), null);
jContentPane.add(getNewListBtn(), null);
jContentPane.add(getRemListBtn(), null);
jContentPane.add(getNTex(), null);
jContentPane.add(getNOkBtn(), null);
jContentPane.add(getNCaBtn(), null);
jContentPane.add(getSOkBtn(), null);
}
return jContentPane;
}
/**
* This method initializes jJMenuBar
*
* @return javax.swing.JMenuBar
*/
private JMenuBar getJJMenuBar() {
if (jJMenuBar == null) {
jJMenuBar = new JMenuBar();
jJMenuBar.add(getFileMenu());
jJMenuBar.add(getEditMenu());
jJMenuBar.add(getHelpMenu());
}
return jJMenuBar;
}
/**
* This method initializes jMenu
*
* @return javax.swing.JMenu
*/
private JMenu getFileMenu() {
if (fileMenu == null) {
fileMenu = new JMenu();
fileMenu.setText("Datei");
fileMenu.add(getNewMenuItem());
fileMenu.add(getOpenMenuItem());
fileMenu.add(getOpenFMenuItem());
fileMenu.add(getSaveMenuItem());
fileMenu.add(getExitMenuItem());
}
return fileMenu;
}
/**
* This method initializes jMenu
*
* @return javax.swing.JMenu
*/
private JMenu getEditMenu() {
if (editMenu == null) {
editMenu = new JMenu();
editMenu.setText("Bearbeiten");
editMenu.add(getSearMenuItem());
editMenu.add(getCutMenuItem());
editMenu.add(getCopyMenuItem());
editMenu.add(getPasteMenuItem());
}
return editMenu;
}
/**
* This method initializes jMenu
*
* @return javax.swing.JMenu
*/
private JMenu getHelpMenu() {
if (helpMenu == null) {
helpMenu = new JMenu();
helpMenu.setText("Hilfe");
helpMenu.add(getAboutMenuItem());
}
return helpMenu;
}
/**
* This method initializes jMenuItem
*
* @return javax.swing.JMenuItem
*/
private JMenuItem getExitMenuItem() {
if (exitMenuItem == null) {
exitMenuItem = new JMenuItem();
exitMenuItem.setText("Exit");
exitMenuItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.exit(0);
}
});
}
return exitMenuItem;
}
/**
* This method initializes jMenuItem
*
* @return javax.swing.JMenuItem
*/
private JMenuItem getAboutMenuItem() {
if (aboutMenuItem == null) {
aboutMenuItem = new JMenuItem();
aboutMenuItem.setText("About");
aboutMenuItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JDialog over = new JDialog();
over.setSize(240,120);
JTextArea otex = new JTextArea();
otex.setText("Entwickelt wurde diese Programm von ... zum Archivieren...");
over.add(otex);
over.setVisible(true);
}
});
}
return aboutMenuItem;
}
/**
* This method initializes jMenuItem
*
* @return javax.swing.JMenuItem
*/
private JMenuItem getCutMenuItem() {
if (cutMenuItem == null) {
cutMenuItem = new JMenuItem();
cutMenuItem.setText("Cut");
cutMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X,
Event.CTRL_MASK, true));
}
return cutMenuItem;
}
/**
* This method initializes jMenuItem
*
* @return javax.swing.JMenuItem
*/
private JMenuItem getCopyMenuItem() {
if (copyMenuItem == null) {
copyMenuItem = new JMenuItem();
copyMenuItem.setText("Copy");
copyMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C,
Event.CTRL_MASK, true));
}
return copyMenuItem;
}
/**
* This method initializes jMenuItem
*
* @return javax.swing.JMenuItem
*/
private JMenuItem getPasteMenuItem() {
if (pasteMenuItem == null) {
pasteMenuItem = new JMenuItem();
pasteMenuItem.setText("Paste");
pasteMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_V,
Event.CTRL_MASK, true));
}
return pasteMenuItem;
}
//Neue Liste erstellen
private JMenuItem getNewMenuItem(){
if (newMenuItem == null){
newMenuItem = new JMenuItem();
newMenuItem.setText("Neue Liste");
newMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N,
Event.CTRL_MASK, true));
newMenuItem.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
nOkBtn.setVisible(false);
nCaBtn.setVisible(false);
nTex.setText("");
nTex.setVisible(false);
nOkBtn.setVisible(true);
nCaBtn.setVisible(true);
nTex.setVisible(true);
}
});
}
return newMenuItem;
}
//Die Suche
private JMenuItem getSearMenuItem(){
if (searMenuItem == null){
searMenuItem = new JMenuItem();
searMenuItem.setText("Suche");
searMenuItem.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
nOkBtn.setVisible(false);
nCaBtn.setVisible(false);
nTex.setText("");
nTex.setVisible(false);
sOkBtn.setVisible(true);
nTex.setVisible(true);
nCaBtn.setVisible(true);
}});
}
return searMenuItem;
}
//gespeicherte Datei wieder öffnen
private JMenuItem getOpenFMenuItem(){
if (openFMenuItem == null){
openFMenuItem = new JMenuItem();
openFMenuItem.setText("Öffnen");
openFMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O,
Event.CTRL_MASK, true));
openFMenuItem.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
JFileChooser chooser = new JFileChooser(System.getProperty("home.dir"));
int ret = chooser.showOpenDialog(null);
if (ret == JFileChooser.APPROVE_OPTION){
File file = chooser.getSelectedFile();
BufferedReader reader = null;
try {
reader = new BufferedReader(new FileReader(file));
String strLine;
while ( (strLine = reader.readLine()) != null )
{
DefaultTableModel model = (DefaultTableModel)mscTab.getModel();
String[] items = strLine.split(";");
model.addRow(items);
}
DefaultTableModel model = (DefaultTableModel)mscTab.getModel();
model.fireTableDataChanged();
}
catch(FileNotFoundException ex) {}
catch(IOException exx) {}
catch (Exception ie) {
System.out.println(ie.getMessage());
} finally {
try {
reader.close();
} catch (Exception ex) {
}
}
}
}
});
}
return openFMenuItem;
}
/**
* This method initializes jMenuItem
*
* @return javax.swing.JMenuItem
*/
private JMenuItem getSaveMenuItem() {
if (saveMenuItem == null) {
saveMenuItem = new JMenuItem();
saveMenuItem.setText("Speichern");
saveMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S,
Event.CTRL_MASK, true));
saveMenuItem.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
JFileChooser chooser = new JFileChooser(System.getProperty("home.dir"));
int ret = chooser.showSaveDialog(null);
if (ret == JFileChooser.APPROVE_OPTION){
System.out.println(mscTab.getColumnCount());
System.out.println(mscTab.getRowCount());
File file = chooser.getSelectedFile();
BufferedWriter writer = null;
try{
writer = new BufferedWriter(new FileWriter(file));
/* for (int i=0;i<colm;i++){
for(int k=1;k<rowm;k++){
writer.write(mscTab.getValueAt(i,k).toString());
}
}*/
int colm = mscTab.getColumnCount();
int rowm = mscTab.getRowCount();
for ( int i = 1; i < colm; i++){
for (int k = 1; k < rowm; k++){
System.out.println(mscTab.getValueAt(i,k));
writer.write(mscTab.getValueAt(i,k).toString());
writer.newLine();
}
}
}
catch (IOException ioex){
System.err.println(ioex);
}
finally{
try {
writer.close();
} catch (IOException iex) {
}
}
}
}
});
}
return saveMenuItem;
}
//openMenuItem
private JMenuItem getOpenMenuItem(){
if (openMenuItem == null){
openMenuItem = new JMenuItem();
openMenuItem.setText("Dateien hinzufügen");
openMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F,
Event.CTRL_MASK, true));
openMenuItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
//neuer FileChooser
JFileChooser chooser = new JFileChooser(System.getProperty("home.dir"));
chooser.setFileFilter(new FileFilter() {
public boolean accept(File f) {
return f.isDirectory()
|| f.getName().toLowerCase().endsWith(".mp3")
|| f.getName().toLowerCase().endsWith(".mp4")
|| f.getName().toLowerCase().endsWith(".wma");
}
public String getDescription() {
return ".mp3 .mp4 .wma";
}});
chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
int ret = chooser.showOpenDialog(null);
if(ret == JFileChooser.APPROVE_OPTION) {
//Einzelne Dateien zufügen
String path = chooser.getSelectedFile().toString();
File dir = new File(path);
if(path.toLowerCase().endsWith(".mp3") || path.toLowerCase().endsWith(".mp4") || path.toLowerCase().endsWith(".wma")){
for(int i=0; i < row.length; i++){
Object row[] []= {{dir.getName(),nList.getSelectedValue()}};
DefaultTableModel model = (DefaultTableModel)mscTab.getModel();
model.addRow(row[i]);
}
}
else {
String[] file = dir.list();
Object[][] files = {{dir.list(),nList.getSelectedValue()}};
for(int i=0;i<=file.length;i++) {
if(file[i].toLowerCase().endsWith(".mp3") || file[i].toLowerCase().endsWith(".mp4") || file[i].toLowerCase().endsWith(".wma")) {
System.out.println(dir.getAbsolutePath() + "\\" + file[i]);
Object rows[] []= {{file[i],nList.getSelectedValue()}};
for (int k = 0;k<rows.length; k++){
DefaultTableModel model = (DefaultTableModel)mscTab.getModel();
model.addRow(rows[k]);
}
}
}}}}});
}
return openMenuItem;
}
/**
* This method initializes jScrollPane
*
* @return javax.swing.JScrollPane
*/
private JScrollPane getJScrollPane() {
if (jScrollPane == null) {
jScrollPane = new JScrollPane();
jScrollPane.setBounds(new java.awt.Rectangle(0,1,331,253));
jScrollPane.setViewportView(getMscTab());
}
return jScrollPane;
}
/**
* This method initializes jTable
*
* @return javax.swing.JTable
*/
private JTable getMscTab() {
if (mscTab == null) {
mscTab = new JTable();
mscTab.setShowHorizontalLines(false);
mscTab.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
mscTab.setColumnSelectionAllowed(true);
DefaultTableModel model = new DefaultTableModel(row, col);
mscTab.setModel(model);
}
return mscTab;
}
/**
* This method initializes jList
*
* @return javax.swing.JList
*/
private JList getNList() {
if (nList == null) {
nList = new JList();
nList.setBounds(new java.awt.Rectangle(330,0,117,253));
DefaultListModel lmod = new DefaultListModel();
nList.setModel(lmod);
}
return nList;
}
/**
* This method initializes jButton
*
* @return javax.swing.JButton
*/
private JButton getNewListBtn() {
if (newListBtn == null) {
newListBtn = new JButton();
newListBtn.setBounds(new java.awt.Rectangle(5,257,72,15));
newListBtn.setToolTipText("Neue Liste hinzufügen.");
newListBtn.setText("Neu");
newListBtn.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
nOkBtn.setVisible(false);
nCaBtn.setVisible(false);
nTex.setText("");
nTex.setVisible(false);
nOkBtn.setVisible(true);
nCaBtn.setVisible(true);
nTex.setVisible(true);
}
});
}
return newListBtn;
}
/**
* This method initializes jButton
*
* @return javax.swing.JButton
*/
private JButton getRemListBtn() {
if (remListBtn == null) {
remListBtn = new JButton();
remListBtn.setBounds(new java.awt.Rectangle(84,257,72,15));
remListBtn.setToolTipText("Liste löschen.");
remListBtn.setText("Ent");
remListBtn.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
int colm = mscTab.getColumnCount();
int rowm = mscTab.getRowCount();
for ( int i = 0; i < colm; i++){
for (int k = 0; k < rowm; k++){
System.out.println(mscTab.getValueAt(i,k));
}
}
}
});
}
return remListBtn;
}
/**
* This method initializes jTextField
*
* @return javax.swing.JTextField
*/
private JTextField getNTex() {
if (nTex == null) {
nTex = new JTextField();
nTex.setBounds(new java.awt.Rectangle(41,278,174,18));
}
return nTex;
}
/**
* This method initializes jButton
*
* @return javax.swing.JButton
*/
private JButton getNOkBtn() {
if (nOkBtn == null) {
nOkBtn = new JButton();
nOkBtn.setText("OK");
nOkBtn.setBounds(new java.awt.Rectangle(226,279,81,15));
nOkBtn.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
String text = nTex.getText();
Object[] data = {text};
DefaultListModel model = (DefaultListModel)nList.getModel();
for(int i=0; i < data.length; i++){
model.addElement(data[i]);
}
nOkBtn.setVisible(false);
nCaBtn.setVisible(false);
nTex.setText("");
nTex.setVisible(false);
}
});
}
return nOkBtn;
}
private JButton getSOkBtn() {
if (sOkBtn == null) {
sOkBtn = new JButton();
sOkBtn.setText("Suche");
sOkBtn.setBounds(new java.awt.Rectangle(226,279,81,15));
sOkBtn.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
// System.out.println(nTex.getText());
Object[] [] sDat = {{nTex.getText(),nTex.getText()}};
int colm = mscTab.getColumnCount();
int rowm = mscTab.getRowCount();
for ( int i = 0; i < colm; i++){
for (int k = 0; k < rowm; k++){
if (sDat == mscTab.getValueAt(i,k)){
System.out.println(mscTab.getValueAt(i,k).toString());
}
}
}
String text = "*"+nTex.getText()+"*";
for ( int j = 0; j < colm; j++){
for (int h = 0; h < rowm; h++){
if (text == mscTab.getValueAt(j,h)){
System.out.println(mscTab.getValueAt(j,h));
}
}
}
sOkBtn.setVisible(false);
nCaBtn.setVisible(false);
nTex.setText("");
nTex.setVisible(false);
}
});
}
return sOkBtn;
}
/**
* This method initializes jButton1
*
* @return javax.swing.JButton
*/
private JButton getNCaBtn() {
if (nCaBtn == null) {
nCaBtn = new JButton();
nCaBtn.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
nCaBtn.setBounds(new java.awt.Rectangle(315,279,78,15));
nCaBtn.setText("Cancel");
nCaBtn.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
nOkBtn.setVisible(false);
nCaBtn.setVisible(false);
nTex.setText("");
nTex.setVisible(false);
sOkBtn.setVisible(false);
}
});
}
return nCaBtn;
}
/**
* Launches this application
*/
public static void main(String[] args) {
mskMaFr application = new mskMaFr();
application.show();
}
} // @jve:decl-index=0:visual-constraint="10,10"