/* * @(#)BurnDialog.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.*; /** * BurnDialog * * @version 20060412 * @author Jörg P. M. Haeger */ class BurnDialog extends javax.swing.JPanel { Command parent; JLabel label; JProgressBar bar, bufferBar = null; JTable table = null; private JButton detailsButton; private JPanel buttons; // private JPanel hideBar; // private JPanel showBar; private boolean areDetailsVisible = false; BurnDialog(Command aParent) { parent = aParent; setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20)); setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); label = new JLabel(); label.setAlignmentX(CENTER_ALIGNMENT); bar = new JProgressBar(); bar.setStringPainted(true); areDetailsVisible = Config.getBool(Config.SHOW_DETAILS); if (areDetailsVisible) { prepareDetails(); detailsButton = new JButton("<< " + i18n("details")); } else detailsButton = new JButton(i18n("details") + " >>"); detailsButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { areDetailsVisible = !areDetailsVisible; Config.set(Config.SHOW_DETAILS, areDetailsVisible); prepareDetails(); removeAll(); add(Box.createVerticalGlue()); addMain(); if (areDetailsVisible) detailsButton.setText("<< " + i18n("details")); else detailsButton.setText(i18n("details") + " >>"); add(Box.createVerticalStrut(15)); add(buttons); parent.validate(); } }); buttons = new JPanel(); // buttons.setBackground(new Color(0, 255, 255)); buttons.setLayout(new FlowLayout()); buttons.setOpaque(true); buttons.add(detailsButton); add(Box.createVerticalGlue()); addMain(); add(Box.createVerticalStrut(15)); add(buttons); } void addButton(JButton button) { buttons.add(button); remove(buttons); add(buttons); parent.validate(); } private void addMain() { add(label); add(Box.createVerticalStrut(10)); if (table == null) { add(bar); if (bufferBar != null) { add(Box.createVerticalStrut(10)); add(bufferBar); } } else { JScrollPane scroller = new JScrollPane(table); scroller.setAlignmentX(JPanel.CENTER_ALIGNMENT); add(scroller); } if (areDetailsVisible) { add(Box.createVerticalStrut(15)); add(Log.getView()); } } static String i18n(String key) { if (key.startsWith(".")) key = "BurnDialog" + key; return CDcreator.i18n(key); } void prepareDetails() { /* JButton hide = new JButton(MainWin.getIcon("up.png")); hide.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { removeAll(); addMain(); add(showBar); parent.validate(); parent.pack(); } }); hide.setPreferredSize(new Dimension(25, 25)); hideBar = new JPanel(); hideBar.setLayout( new BoxLayout(hideBar, BoxLayout.X_AXIS)); hideBar.add(Box.createHorizontalGlue()); hideBar.add(hide); */ Log.getView().setAlignmentX(JPanel.CENTER_ALIGNMENT); Log.getView().setPreferredSize(new Dimension(400, 1600)); /* JButton show = new JButton(MainWin.getIcon("down.png")); show.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { removeAll(); addMain(); add(hideBar); add(Log.getView()); parent.validate(); parent.pack(); } }); show.setPreferredSize(new Dimension(25, 25)); showBar = new JPanel(); showBar.setLayout( new BoxLayout(showBar, BoxLayout.X_AXIS)); showBar.add(Box.createHorizontalGlue()); showBar.add(show); */ } public void setBuffer(final int percent) { if (bufferBar == null) { bufferBar = new JProgressBar(0, 100); bufferBar.setString(i18n(".buffer")); bufferBar.setStringPainted(true); removeAll(); add(Box.createVerticalGlue()); addMain(); add(Box.createVerticalStrut(15)); add(buttons); parent.validate(); } bufferBar.setValue(percent); } public void setIndeterminate(final boolean newValue) { bar.setIndeterminate(newValue); bar.setStringPainted(!newValue); } public void setMessage(final String str) { label.setText(str); if (bufferBar != null) { remove(bufferBar); bufferBar = null; parent.validate(); } } public void setRange(int a, int b) { bar.setMinimum(a); bar.setMaximum(b); } public void setProgress(final int n) { bar.setValue(n); if (bufferBar != null) { if (n == bar.getMaximum()) bufferBar.setValue(0); } CDcreator.setTitle((int) (100 * bar.getPercentComplete())); } public void setTable(JTable aTable) { table = aTable; table.setAlignmentX(JPanel.CENTER_ALIGNMENT); removeAll(); add(Box.createVerticalGlue()); addMain(); add(Box.createVerticalStrut(15)); add(buttons); } }