1 package org.neuclear.commons.swing;
2
3 import com.jgoodies.forms.builder.ButtonBarBuilder;
4 import com.jgoodies.forms.builder.PanelBuilder;
5 import com.jgoodies.forms.layout.CellConstraints;
6 import com.jgoodies.forms.layout.FormLayout;
7 import com.l2fprod.common.swing.BannerPanel;
8 import org.neuclear.commons.crypto.passphraseagents.UserCancellationException;
9 import org.neuclear.commons.crypto.passphraseagents.icons.IconTools;
10 import org.neuclear.commons.crypto.passphraseagents.swing.MessageLabel;
11
12 import javax.swing.*;
13 import java.awt.*;
14
15 /*
16 * The NeuClear Project and it's libraries are
17 * (c) 2002-2004 Antilles Software Ventures SA
18 * For more information see: http://neuclear.org
19 *
20 * This library is free software; you can redistribute it and/or
21 * modify it under the terms of the GNU Lesser General Public
22 * License as published by the Free Software Foundation; either
23 * version 2.1 of the License, or (at your option) any later version.
24 *
25 * This library is distributed in the hope that it will be useful,
26 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
28 * Lesser General Public License for more details.
29 *
30 * You should have received a copy of the GNU Lesser General Public
31 * License along with this library; if not, write to the Free Software
32 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
33 */
34
35 /***
36 * User: pelleb
37 * Date: May 18, 2004
38 * Time: 12:24:07 PM
39 */
40 public abstract class ProcessDialog extends NeuClearDialog {
41 public ProcessDialog(Frame frame, String id) {
42 this(frame, id, IconTools.getOK());
43 }
44
45 public ProcessDialog(Frame frame, String id, Icon okIcon) throws HeadlessException {
46 super(frame, id, okIcon);
47 busyPanel = buildProcessPanel();
48 }
49
50 private JPanel buildProcessPanel() {
51
52 FormLayout layout = new FormLayout("right:pref, 3dlu, 100dlu:grow ",
53 "pref,3dlu,pref,3dlu,pref, 7dlu, pref");
54 PanelBuilder builder = new PanelBuilder(layout);
55 CellConstraints cc = new CellConstraints();
56
57 builder.setDefaultDialogBorder();
58
59 BannerPanel banner = new BannerPanel();
60 banner.setTitle(Messages.getProcessTitle(id));
61 banner.setSubtitle(Messages.getProcessDescription(id));
62 builder.add(banner, cc.xyw(1, 1, 3));
63 processMessage = new MessageLabel();
64 builder.add(processMessage, cc.xyw(1, 3, 3));
65 progress = new JProgressBar(0, 100);
66 progress.setIndeterminate(true);
67 progress.setVisible(true);
68
69 builder.add(progress, cc.xyw(1, 5, 3));
70 ButtonBarBuilder bb = new ButtonBarBuilder();
71 bb.addGlue();
72 bb.addUnrelatedGap();
73 // bb.addGridded(ok);
74 cancel = new JButton(Messages.getText("cancel"));
75 bb.addGridded(cancel);
76 cancel.addActionListener(closeAction);
77 builder.add(bb.getPanel(), cc.xyw(1, 7, 3));
78
79 return builder.getPanel();
80
81 }
82
83 protected Object openAndWait(LongChildProcess process) throws UserCancellationException {
84 final Object waiter = openAndWait(new ProcessRunner(this, process));
85 clear();
86 hide();
87 return waiter;
88 }
89
90 private void switchToProcess() {
91 getContentPane().removeAll();
92 getContentPane().add(busyPanel);
93 pack();
94 }
95
96 private class ProcessRunner extends AbstractDialogRunner {
97 public ProcessRunner(ProcessDialog dia, Runnable process) {
98 super(dia);
99 this.process = process;
100 if (process instanceof LongChildProcess)
101 ((LongChildProcess) process).setParent(this);
102 }
103
104 private Runnable process;
105
106 public void execute() {
107 switchToProcess();
108 new Thread(process).start();
109
110 }
111
112
113 }
114
115 public void processInfo(String info) {
116 processMessage.info(info);
117 }
118
119 private final JPanel busyPanel;
120 private JProgressBar progress;
121 private MessageLabel processMessage;
122 private JButton cancel;
123 }
This page was automatically generated by Maven