/* * @(#)PutDialog.java * * This file is part of webCDwriter - Network CD/DVD Writing. * * Copyright (C) 1999-2006 Jörg P. M. Haeger * * webCDwriter is free software. See CDcreator.java for details. */ import java.awt.*; import java.awt.event.*; import javax.swing.*; /** * A file transmission dialog. * * @version 20060410 * @author Jörg P. M. Haeger */ class PutDialog extends JPanel { private JLabel label1, label2; private String label1Buffer = "", label2Buffer = ""; protected JProgressBar bar; protected JCheckBox ignoreAllUnreadableBox, shortenAllBox; PutDialog(JButton cancelButton) { setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20)); setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); add(Box.createVerticalGlue()); label1 = new JLabel(CDcreator.i18n("titlePutFiles")); label1.setAlignmentX(CENTER_ALIGNMENT); add(label1); add(Box.createVerticalStrut(20)); JPanel hp = new JPanel(); // hp.setAlignmentX(LEFT_ALIGNMENT); hp.setLayout( new BoxLayout(hp, BoxLayout.X_AXIS)); hp.setBorder( BorderFactory.createCompoundBorder( BorderFactory.createTitledBorder( CDcreator.i18n("file")), BorderFactory.createEmptyBorder(5, 5, 5, 5))); label2 = new JLabel(label2Buffer); // label2.setEditable(false); hp.add(label2); hp.add(Box.createHorizontalGlue()); add(hp); add(Box.createRigidArea(new Dimension(500, 20))); bar = new JProgressBar(); bar.setStringPainted(true); add(bar); add(Box.createVerticalStrut(20)); hp = new JPanel(); hp.setLayout( new BoxLayout(hp, BoxLayout.X_AXIS)); hp.setBorder( BorderFactory.createCompoundBorder( BorderFactory.createTitledBorder( CDcreator.i18n("PutDialog.options")), BorderFactory.createEmptyBorder(5, 5, 5, 5))); ignoreAllUnreadableBox = new JCheckBox( CDcreator.i18n("PutDialog.ignoreAllUnreadable"), false); hp.add(ignoreAllUnreadableBox); hp.add(Box.createHorizontalStrut(20)); shortenAllBox = new JCheckBox( CDcreator.i18n("PutDialog.shortenAll"), false); hp.add(shortenAllBox); hp.add(Box.createHorizontalGlue()); add(hp); add(Box.createVerticalGlue()); JPanel buttons = new JPanel(); buttons.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); buttons.setLayout(new FlowLayout(FlowLayout.CENTER)); buttons.add(cancelButton); add(buttons); } public void setFileName(String str) { final int maxLength = 70; final int length = str.length(); if (length > maxLength) { final int p = str.lastIndexOf("/"); if (p < 0 || length - p > maxLength / 2) str = str.substring(length - maxLength); else str = str.substring(0, maxLength - 3 - (length - p)) + "..." + str.substring(p); } synchronized(label2) { boolean refresh = label2Buffer.length() == 0; label2Buffer = str; if (!refresh) return; } SwingUtilities.invokeLater(new Runnable() { public void run() { synchronized(label2) { label2.setText(label2Buffer); // label2.setCaretPosition(label2Buffer.length()); label2Buffer = ""; } } }); } public void setMessage(String str) { synchronized(label1) { boolean refresh = label1Buffer.length() == 0; label1Buffer = str; if (!refresh) return; } SwingUtilities.invokeLater(new Runnable() { public void run() { synchronized(label1) { label1.setText(label1Buffer); label1Buffer = ""; } } }); } public void setRange(final int a, final int b) { SwingUtilities.invokeLater(new Runnable() { public void run() { bar.setMinimum(a); bar.setMaximum(b); } }); } public void setProgress(final int n) { SwingUtilities.invokeLater(new Runnable() { public void run() { bar.setValue(n); CDcreator.setTitle((int) (100 * bar.getPercentComplete())); } }); } }