1 31 32 package org.antlr.xjlib.appkit.utils; 33 34 import org.antlr.xjlib.appkit.frame.XJDialog; 35 import org.antlr.xjlib.appkit.frame.XJFrameInterface; 36 37 import javax.swing.*; 38 import java.awt.*; 39 import java.awt.event.ActionEvent ; 40 import java.awt.event.ActionListener ; 41 42 public class XJDialogProgress extends XJDialog { 43 44 protected XJDialogProgressDelegate delegate; 45 46 protected JLabel infoLabel; 47 protected JProgressBar progressBar; 48 protected JButton cancelButton; 49 50 public XJDialogProgress(XJFrameInterface owner, boolean modal) { 51 super(owner==null?null:owner.getJavaContainer(), modal); 52 init(); 53 } 54 55 public XJDialogProgress(XJFrameInterface owner) { 56 super(owner==null?null:owner.getJavaContainer(), false); 57 init(); 58 } 59 60 public XJDialogProgress(Container owner, boolean modal) { 61 super(owner, modal); 62 init(); 63 } 64 65 public XJDialogProgress(Container owner) { 66 super(owner, false); 67 init(); 68 } 69 70 public void init() { 71 setResizable(false); 72 setSize(400, 90); 73 74 initComponents(); 75 76 cancelButton.addActionListener(new ActionListener () { 77 public void actionPerformed(ActionEvent event) { 78 if(delegate != null) { 79 setInfo("Cancelling..."); 80 delegate.dialogDidCancel(); 81 } 82 } 83 }); 84 } 85 86 public void setCancellable(boolean flag) { 87 cancelButton.setEnabled(flag); 88 } 89 90 public void setIndeterminate(boolean flag) { 91 if(flag) { 92 setProgress(0); 93 setProgressMax(0); 94 } 95 progressBar.setIndeterminate(flag); 96 } 97 98 public void setDelegate(XJDialogProgressDelegate delegate) { 99 this.delegate = delegate; 100 } 101 102 public void setInfo(String info) { 103 infoLabel.setText(info); 104 } 105 106 public void setProgress(float value) { 107 setProgress((int)value); 108 } 109 110 public void setProgress(int value) { 111 progressBar.setValue(value); 112 } 113 114 public void setProgressMax(int value) { 115 progressBar.setMaximum(value); 116 } 117 118 private void initComponents() { 119 Container contentPane = getContentPane(); 120 contentPane.setLayout(new GridBagLayout()); 121 122 infoLabel = new JLabel(); 123 progressBar = new JProgressBar(); 124 cancelButton = new JButton("Cancel"); 125 126 setTitle("Operation in progress"); 127 128 GridBagConstraints gbc = new GridBagConstraints(); 129 130 gbc.gridx = 0; 131 gbc.gridy = 0; 132 gbc.gridwidth = 2; 133 gbc.anchor = GridBagConstraints.WEST; 134 gbc.fill = GridBagConstraints.HORIZONTAL; 135 gbc.weightx = 1; 136 gbc.insets = new Insets(20, 20, 0, 0); 137 contentPane.add(infoLabel, gbc); 138 139 gbc.gridx = 0; 140 gbc.gridy = 1; 141 gbc.gridwidth = 1; 142 gbc.insets = new Insets(0, 20, 20, 10); 143 contentPane.add(progressBar, gbc); 144 145 gbc.gridx = 1; 146 gbc.anchor = GridBagConstraints.CENTER; 147 gbc.fill = GridBagConstraints.NONE; 148 gbc.weightx = 0; 149 gbc.insets = new Insets(0, 0, 20, 20); 150 contentPane.add(cancelButton, gbc); 151 } 152 153 } 154 | Popular Tags |