java-org.hwo.ui/src/org/hwo/ui/ProgressDialog.java

184 lines
5.6 KiB
Java

package org.hwo.ui;
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import java.awt.GridBagLayout;
import javax.swing.JLabel;
import java.awt.GridBagConstraints;
import java.awt.Insets;
import java.awt.Font;
import javax.swing.JProgressBar;
import javax.swing.border.TitledBorder;
import javax.swing.JTextArea;
import org.hwo.thread.ThreadedOperation;
import org.hwo.thread.ThreadedOperationUpdateArgs;
import org.hwo.thread.ThreadedOperationUpdateListener;
import java.awt.Dialog.ModalExclusionType;
import java.awt.Dialog.ModalityType;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
public class ProgressDialog extends JDialog implements ThreadedOperationUpdateListener{
private final JPanel contentPanel = new JPanel();
private JProgressBar pSchritt;
private JProgressBar pGesamt;
private JTextArea taStatus;
private JLabel lblSchritt;
private int operationResult;
private boolean operationFinished;
public static int executeOperation(ThreadedOperation operation)
{
ProgressDialog dialog = new ProgressDialog();
operation.addThreadedOperationUpdateListener(dialog);
dialog.setTitle(operation.getName());
operation.start();
dialog.setVisible(true);
operation.removeThreadedOperationUpdateListener(dialog);
return dialog.getOperationResult();
}
/**
* Create the dialog.
*/
protected ProgressDialog() {
addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent arg0) {
if (!operationFinished)
setVisible(true);
}
@Override
public void windowOpened(WindowEvent e) {
}
});
setModalityType(ModalityType.APPLICATION_MODAL);
setModalExclusionType(ModalExclusionType.APPLICATION_EXCLUDE);
setBounds(100, 100, 691, 270);
getContentPane().setLayout(new BorderLayout());
contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
getContentPane().add(contentPanel, BorderLayout.CENTER);
GridBagLayout gbl_contentPanel = new GridBagLayout();
gbl_contentPanel.columnWidths = new int[] {0};
gbl_contentPanel.rowHeights = new int[]{0, 0, 0, 0, 0, 0, 0};
gbl_contentPanel.columnWeights = new double[]{1.0};
gbl_contentPanel.rowWeights = new double[]{0.0, 0.0, 0.0, 0.0, 0.0, 1.0, Double.MIN_VALUE};
contentPanel.setLayout(gbl_contentPanel);
{
JLabel lblBitteWarten = new JLabel("Bitte warten...");
lblBitteWarten.setFont(new Font("Lucida Grande", Font.PLAIN, 32));
GridBagConstraints gbc_lblBitteWarten = new GridBagConstraints();
gbc_lblBitteWarten.insets = new Insets(0, 0, 5, 0);
gbc_lblBitteWarten.gridx = 0;
gbc_lblBitteWarten.gridy = 0;
contentPanel.add(lblBitteWarten, gbc_lblBitteWarten);
}
{
JLabel lblGesamtfortschritt = new JLabel("Gesamtfortschritt:");
GridBagConstraints gbc_lblGesamtfortschritt = new GridBagConstraints();
gbc_lblGesamtfortschritt.insets = new Insets(0, 0, 5, 0);
gbc_lblGesamtfortschritt.gridx = 0;
gbc_lblGesamtfortschritt.gridy = 1;
contentPanel.add(lblGesamtfortschritt, gbc_lblGesamtfortschritt);
}
{
pGesamt = new JProgressBar();
GridBagConstraints gbc_pGesamt = new GridBagConstraints();
gbc_pGesamt.insets = new Insets(0, 0, 5, 0);
gbc_pGesamt.fill = GridBagConstraints.HORIZONTAL;
gbc_pGesamt.gridx = 0;
gbc_pGesamt.gridy = 2;
contentPanel.add(pGesamt, gbc_pGesamt);
}
{
lblSchritt = new JLabel("Arbeitsschritt:");
GridBagConstraints gbc_lblSchritt = new GridBagConstraints();
gbc_lblSchritt.insets = new Insets(0, 0, 5, 0);
gbc_lblSchritt.gridx = 0;
gbc_lblSchritt.gridy = 3;
contentPanel.add(lblSchritt, gbc_lblSchritt);
}
{
pSchritt = new JProgressBar();
GridBagConstraints gbc_pSchritt = new GridBagConstraints();
gbc_pSchritt.insets = new Insets(0, 0, 5, 0);
gbc_pSchritt.fill = GridBagConstraints.HORIZONTAL;
gbc_pSchritt.gridx = 0;
gbc_pSchritt.gridy = 4;
contentPanel.add(pSchritt, gbc_pSchritt);
}
{
JPanel panel = new JPanel();
panel.setBorder(new TitledBorder(null, "Status", TitledBorder.LEADING, TitledBorder.TOP, null, null));
GridBagConstraints gbc_panel = new GridBagConstraints();
gbc_panel.fill = GridBagConstraints.BOTH;
gbc_panel.gridx = 0;
gbc_panel.gridy = 5;
contentPanel.add(panel, gbc_panel);
GridBagLayout gbl_panel = new GridBagLayout();
gbl_panel.columnWidths = new int[]{0, 0};
gbl_panel.rowHeights = new int[]{0, 0};
gbl_panel.columnWeights = new double[]{1.0, Double.MIN_VALUE};
gbl_panel.rowWeights = new double[]{1.0, Double.MIN_VALUE};
panel.setLayout(gbl_panel);
{
taStatus = new JTextArea();
GridBagConstraints gbc_taStatus = new GridBagConstraints();
gbc_taStatus.fill = GridBagConstraints.BOTH;
gbc_taStatus.gridx = 0;
gbc_taStatus.gridy = 0;
panel.add(taStatus, gbc_taStatus);
}
}
}
public int getOperationResult() {
return operationResult;
}
public void setOperationResult(int operationResult) {
this.operationResult = operationResult;
}
@Override
public void threadedOperationUpdate(ThreadedOperationUpdateArgs args) {
if (args.getProgressOperation()!=null)
pGesamt.setValue(args.getProgressOperation());
if (args.getProgressStep()!=null)
pSchritt.setValue(args.getProgressStep());
if (args.getStepLabel()!=null)
lblSchritt.setText(args.getStepLabel());
if (args.getStatusText()!=null)
taStatus.setText(args.getStatusText());
if (args.getTitleText()!=null)
setTitle(args.getTitleText());
}
@Override
public void threadedOperationFinished(int result) {
operationResult = result;
operationFinished = true;
setVisible(false);
}
}