/*
* FileReplacePane.java
*
* Created on March 3, 2005, 12:18 PM
*/
package kiyut.swing.shell.util;
import java.io.*;
import java.util.Date;
import java.text.DateFormat;
import javax.swing.JOptionPane;
import javax.swing.filechooser.FileSystemView;
/**
*
* @author Kiyut
*/
public class FileReplacePane extends javax.swing.JPanel {
/** Creates new FileReplacePane */
public FileReplacePane() {
this(null,null,null);
}
public FileReplacePane(FileSystemView fsv, File file1, File file2) {
initComponents();
if (fsv != null && file1 != null && file2 != null) {
setInfo(fsv,file1,file2);
}
}
/** 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.
*/
private void initComponents() {//GEN-BEGIN:initComponents
java.awt.GridBagConstraints gridBagConstraints;
jLabel2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
jPanel1 = new javax.swing.JPanel();
icon1Label = new javax.swing.JLabel();
size1Label = new javax.swing.JLabel();
modified1Label = new javax.swing.JLabel();
jPanel2 = new javax.swing.JPanel();
icon2Label = new javax.swing.JLabel();
size2Label = new javax.swing.JLabel();
modified2Label = new javax.swing.JLabel();
jPanel3 = new javax.swing.JPanel();
jLabel1 = new javax.swing.JLabel();
nameLabel = new javax.swing.JLabel();
setLayout(new java.awt.GridBagLayout());
jLabel2.setText("Would you like to replace the existing file");
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 1;
gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
gridBagConstraints.insets = new java.awt.Insets(15, 0, 0, 0);
add(jLabel2, gridBagConstraints);
jLabel3.setText("with this one?");
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 3;
gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
add(jLabel3, gridBagConstraints);
jPanel1.setLayout(new java.awt.GridBagLayout());
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 0;
gridBagConstraints.gridheight = 2;
gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH;
gridBagConstraints.insets = new java.awt.Insets(0, 0, 0, 10);
jPanel1.add(icon1Label, gridBagConstraints);
size1Label.setText("0 KB");
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 1;
gridBagConstraints.gridy = 0;
gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
jPanel1.add(size1Label, gridBagConstraints);
modified1Label.setText("modified on YYYY-MMM-DD, HH:MM:SS AM");
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 1;
gridBagConstraints.gridy = 1;
gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
jPanel1.add(modified1Label, gridBagConstraints);
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 2;
gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
gridBagConstraints.insets = new java.awt.Insets(15, 15, 15, 0);
add(jPanel1, gridBagConstraints);
jPanel2.setLayout(new java.awt.GridBagLayout());
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 0;
gridBagConstraints.gridheight = 2;
gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH;
gridBagConstraints.insets = new java.awt.Insets(0, 0, 0, 10);
jPanel2.add(icon2Label, gridBagConstraints);
size2Label.setText("0 KB");
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 1;
gridBagConstraints.gridy = 0;
gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
jPanel2.add(size2Label, gridBagConstraints);
modified2Label.setText("modified on YYYY-MMM-DD, HH:MM:SS AM");
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 1;
gridBagConstraints.gridy = 1;
gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
jPanel2.add(modified2Label, gridBagConstraints);
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 4;
gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
gridBagConstraints.insets = new java.awt.Insets(15, 15, 15, 0);
add(jPanel2, gridBagConstraints);
jPanel3.setLayout(new java.awt.GridBagLayout());
jLabel1.setText("This folder already contains\n ");
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 0;
gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
jPanel3.add(jLabel1, gridBagConstraints);
nameLabel.setText("a file named 'something.ext'.");
jPanel3.add(nameLabel, new java.awt.GridBagConstraints());
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 0;
gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
add(jPanel3, gridBagConstraints);
}//GEN-END:initComponents
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JLabel icon1Label;
private javax.swing.JLabel icon2Label;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JPanel jPanel1;
private javax.swing.JPanel jPanel2;
private javax.swing.JPanel jPanel3;
private javax.swing.JLabel modified1Label;
private javax.swing.JLabel modified2Label;
private javax.swing.JLabel nameLabel;
private javax.swing.JLabel size1Label;
private javax.swing.JLabel size2Label;
// End of variables declaration//GEN-END:variables
public void setInfo(FileSystemView fsv, File file1, File file2) {
String type;
if (file1.isDirectory()) {
type = "a folder named ";
} else {
type = "a file named ";
}
nameLabel.setText(type + "'" + fsv.getSystemDisplayName(file1) + "'.");
size1Label.setText(ShellUtilities.sizeToString(file1.length()));
size2Label.setText(ShellUtilities.sizeToString(file2.length()));
icon1Label.setIcon(fsv.getSystemIcon(file1));
icon2Label.setIcon(fsv.getSystemIcon(file2));
DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.LONG,DateFormat.LONG);
modified1Label.setText(dateFormat.format(new Date(file1.lastModified())));
modified1Label.setText(dateFormat.format(new Date(file2.lastModified())));
}
/** Convenience method to show as Dialog. This method delegates to JOptionPane
*/
public static int showDialog(java.awt.Component parentComponent, FileSystemView fsv, File file1, File file2) {
FileReplacePane optionPane = new FileReplacePane(fsv,file1,file2);
int choice = choice = JOptionPane.showConfirmDialog(parentComponent,optionPane,"File Replace",JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE);
return choice;
}
}