/* * MediathekView * Copyright (C) 2008 W. Xaver * W.Xaver[at]googlemail.com * http://zdfmediathk.sourceforge.net/ * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ package mediathek.gui.dialog; import com.jidesoft.utils.SystemInfo; import mSearch.tool.Log; import mediathek.config.Icons; import mediathek.tool.EscBeenden; import mediathek.tool.GuiFunktionen; import javax.swing.*; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.File; @SuppressWarnings("serial") public class DialogZiel extends JDialog { public boolean ok = false; public String ziel; private final JFrame parent; public DialogZiel(JFrame pparent, boolean modal, String ziel, String titel) { super(pparent, modal); parent = pparent; initComponents(); jButtonZiel.setIcon(Icons.ICON_BUTTON_FILE_OPEN); setTitle(titel); jButtonOk.addActionListener(new OkBeobachter()); jButtonAbbrechen.addActionListener(new AbbrechenBeobachter()); jButtonZiel.addActionListener(new ZielBeobachter()); jTextFieldPfad.setText(ziel); this.ziel = ziel; if (pparent != null) { setLocationRelativeTo(pparent); } new EscBeenden(this) { @Override public void beenden_() { ok = false; beenden(); } }; } void check() { boolean ret = false; String pfad = jTextFieldPfad.getText(); if (!pfad.isEmpty()) { try { int ook; if (new File(pfad).exists()) { ook = JOptionPane.showConfirmDialog(parent, "Datei: " + '"' + pfad + '"' + " existiert bereits", "Überschreiben?", JOptionPane.YES_NO_OPTION); } else { ook = JOptionPane.OK_OPTION; } if (ook == JOptionPane.OK_OPTION) { ziel = pfad; ret = true; } } catch (Exception ignored) { } } ok = ret; } private void beenden() { this.dispose(); } /** This method is called from within the constructor to * initialize the form. * WARNING: Do NOT modify this code. The content of this method is * always regenerated by the Form Editor. */ // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents private void initComponents() { javax.swing.JPanel jPanel1 = new javax.swing.JPanel(); jButtonZiel = new javax.swing.JButton(); jTextFieldPfad = new javax.swing.JTextField(); javax.swing.JLabel jLabel1 = new javax.swing.JLabel(); jButtonAbbrechen = new javax.swing.JButton(); jButtonOk = new javax.swing.JButton(); setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); jPanel1.setBorder(javax.swing.BorderFactory.createEtchedBorder()); jButtonZiel.setIcon(new javax.swing.ImageIcon(getClass().getResource("/mediathek/res/muster/button-file-open.png"))); // NOI18N jButtonZiel.setToolTipText("Zielpfad auswählen"); jLabel1.setText("Zielpfad:"); javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1); jPanel1.setLayout(jPanel1Layout); jPanel1Layout.setHorizontalGroup( jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createSequentialGroup() .addContainerGap() .addComponent(jLabel1) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jTextFieldPfad, javax.swing.GroupLayout.DEFAULT_SIZE, 300, Short.MAX_VALUE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jButtonZiel) .addContainerGap()) ); jPanel1Layout.setVerticalGroup( jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createSequentialGroup() .addContainerGap() .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER) .addComponent(jLabel1) .addComponent(jTextFieldPfad, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jButtonZiel)) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) ); jPanel1Layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {jButtonZiel, jTextFieldPfad}); jButtonAbbrechen.setText("Abbrechen"); jButtonOk.setText("Ok"); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() .addComponent(jButtonOk) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jButtonAbbrechen))) .addContainerGap()) ); layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jButtonAbbrechen, jButtonOk}); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap() .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jButtonAbbrechen) .addComponent(jButtonOk)) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) ); pack(); }// </editor-fold>//GEN-END:initComponents // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton jButtonAbbrechen; private javax.swing.JButton jButtonOk; private javax.swing.JButton jButtonZiel; private javax.swing.JTextField jTextFieldPfad; // End of variables declaration//GEN-END:variables private class OkBeobachter implements ActionListener { @Override public void actionPerformed(ActionEvent e) { check(); beenden(); } } private class AbbrechenBeobachter implements ActionListener { @Override public void actionPerformed(ActionEvent e) { ok = false; beenden(); } } private class ZielBeobachter implements ActionListener { @Override public void actionPerformed(ActionEvent e) { //we can use native chooser on Mac... if (SystemInfo.isMacOSX()) { FileDialog chooser = new FileDialog(parent, "Logdatei speichern"); chooser.setMode(FileDialog.SAVE); chooser.setVisible(true); if (chooser.getFile() != null) { try { File destination = new File(chooser.getDirectory() + chooser.getFile()); jTextFieldPfad.setText(destination.getAbsolutePath()); ziel = jTextFieldPfad.getText(); } catch (Exception ex) { Log.errorLog(642109058, ex); } } } else { int returnVal; JFileChooser chooser = new JFileChooser(); if (!jTextFieldPfad.getText().isEmpty()) { chooser.setCurrentDirectory(new File(jTextFieldPfad.getText())); } else { chooser.setCurrentDirectory(new File(GuiFunktionen.getHomePath())); } chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); returnVal = chooser.showOpenDialog(null); if (returnVal == JFileChooser.APPROVE_OPTION) { try { jTextFieldPfad.setText(chooser.getSelectedFile().getAbsolutePath()); } catch (Exception ex) { Log.errorLog(642109058, ex); } } } } } }