/*
 * InfoDialog.java
 *
 * Created on July 9, 2005, 10:26 PM
 */

package ch.randelshofer.multishow;

import ch.randelshofer.gui.*;
import java.awt.*;
import javax.swing.*;
import java.io.*;
import java.util.*;
/**
 *
 * @author  werni
 */
public class InfoDialog extends javax.swing.JDialog {
    
    /** Creates new form InfoDialog */
    public InfoDialog(Frame parent, File file, String info) {
        super(parent, false);
        initComponents();
        setFile(file);
        setInfo(info);
    }

    public void setInfo(String info) {
        infoPanel.removeAll();
        for (StringTokenizer tt = new StringTokenizer(info, "\n"); tt.hasMoreTokens(); ) {
            String line = tt.nextToken();
            JLabel lineLabel = new JLabel(line);
            separator.putClientProperty("Quaqua.Component.visualMargin", new Insets(3,0,3,0));
            lineLabel.putClientProperty("Quaqua.Component.visualMargin", new Insets(1,3,1,3));
            lineLabel.setFont(Fonts.getSmallDialogFont());
            infoPanel.add(lineLabel);
        }
        pack();
        infoPanel.repaint();
    }

    public void setFile(File file) {
        fileLabel.setText(file.getName());
    }
    
    /** 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() {
        java.awt.GridBagConstraints gridBagConstraints;

        fileLabel = new javax.swing.JLabel();
        separator = new javax.swing.JSeparator();
        infoPanel = new javax.swing.JPanel();

        FormListener formListener = new FormListener();

        setTitle("View Info");
        setResizable(false);
        addWindowListener(formListener);
        getContentPane().setLayout(new java.awt.GridBagLayout());

        fileLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.insets = new java.awt.Insets(12, 17, 9, 17);
        getContentPane().add(fileLabel, gridBagConstraints);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridy = 1;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.weightx = 1.0;
        getContentPane().add(separator, gridBagConstraints);

        infoPanel.setLayout(new javax.swing.BoxLayout(infoPanel, javax.swing.BoxLayout.Y_AXIS));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridy = 2;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.weighty = 1.0;
        gridBagConstraints.insets = new java.awt.Insets(12, 17, 17, 17);
        getContentPane().add(infoPanel, gridBagConstraints);

        pack();
    }

    // Code for dispatching events from components to event handlers.

    private class FormListener implements java.awt.event.WindowListener {
        FormListener() {}
        public void windowActivated(java.awt.event.WindowEvent evt) {
        }

        public void windowClosed(java.awt.event.WindowEvent evt) {
        }

        public void windowClosing(java.awt.event.WindowEvent evt) {
            if (evt.getSource() == InfoDialog.this) {
                InfoDialog.this.closeDialog(evt);
            }
        }

        public void windowDeactivated(java.awt.event.WindowEvent evt) {
        }

        public void windowDeiconified(java.awt.event.WindowEvent evt) {
        }

        public void windowIconified(java.awt.event.WindowEvent evt) {
        }

        public void windowOpened(java.awt.event.WindowEvent evt) {
        }
    }// </editor-fold>//GEN-END:initComponents
    
    /** Closes the dialog */
    private void closeDialog(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_closeDialog
        setVisible(false);
        dispose();
    }//GEN-LAST:event_closeDialog
    
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel fileLabel;
    private javax.swing.JPanel infoPanel;
    private javax.swing.JSeparator separator;
    // End of variables declaration//GEN-END:variables
    
}
