1 19 20 package org.netbeans.modules.j2ee.common; 21 22 import java.awt.BorderLayout ; 23 import java.awt.Dialog ; 24 import java.awt.Dimension ; 25 import java.awt.event.ActionEvent ; 26 import java.awt.event.ActionListener ; 27 import java.awt.event.KeyEvent ; 28 import javax.swing.AbstractAction ; 29 import javax.swing.JButton ; 30 import javax.swing.JComponent ; 31 import javax.swing.JDialog ; 32 import javax.swing.JRootPane ; 33 import javax.swing.KeyStroke ; 34 import org.openide.DialogDescriptor; 35 import org.openide.DialogDisplayer; 36 import org.openide.util.NbBundle; 37 38 42 public class ProgressPanel extends javax.swing.JPanel { 43 44 private Dialog dialog; 45 46 public ProgressPanel() { 47 initComponents(); 48 } 49 50 public void open(JComponent progressComponent) { 51 holder.add(progressComponent, BorderLayout.CENTER); 52 53 DialogDescriptor dd = new DialogDescriptor( 54 this, 55 NbBundle.getMessage(ProgressPanel.class, "MSG_PleaseWait"), 56 true, 57 new Object [0], 58 DialogDescriptor.NO_OPTION, 59 DialogDescriptor.DEFAULT_ALIGN, 60 null, 61 null, 62 true); 63 dialog = DialogDisplayer.getDefault().createDialog(dd); 64 if (dialog instanceof JDialog ) { 65 JDialog jDialog = ((JDialog )dialog); 66 jDialog.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE); 67 JRootPane rootPane = jDialog.getRootPane(); 68 rootPane.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), "cancel"); rootPane.getActionMap().put("cancel", new AbstractAction () { public void actionPerformed(ActionEvent event) { 71 if (cancelButton.isEnabled()) { 72 cancelButton.doClick(); 73 } 74 } 75 }); 76 } 77 dialog.setResizable(false); 78 dialog.setVisible(true); 79 } 80 81 public void close() { 82 if (dialog != null) { 83 dialog.setVisible(false); 84 dialog.dispose(); 85 } 86 } 87 88 public boolean isOpen() { 89 return dialog != null && dialog.isVisible(); 90 } 91 92 public void setText(String text) { 93 info.setText(text); 94 } 95 96 99 String getText() { 100 return info.getText(); 101 } 102 103 public void setCancelVisible(boolean cancelVisible) { 104 cancelButton.setVisible(cancelVisible); 105 } 106 107 110 boolean isCancelVisible() { 111 return cancelButton.isVisible(); 112 } 113 114 public void setCancelEnabled(boolean cancelEnabled) { 115 cancelButton.setEnabled(cancelEnabled); 116 } 117 118 121 boolean isCancelEnabled() { 122 return cancelButton.isEnabled(); 123 } 124 125 public void addCancelActionListener(ActionListener listener) { 126 cancelButton.addActionListener(listener); 127 } 128 129 132 JButton getCancelButton() { 133 return cancelButton; 134 } 135 136 141 private void initComponents() { 143 java.awt.GridBagConstraints gridBagConstraints; 144 145 info = new javax.swing.JLabel (); 146 holder = new javax.swing.JPanel (); 147 cancelButton = new javax.swing.JButton (); 148 149 setLayout(new java.awt.GridBagLayout ()); 150 151 info.setText(" "); 152 gridBagConstraints = new java.awt.GridBagConstraints (); 153 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 154 gridBagConstraints.insets = new java.awt.Insets (12, 12, 11, 11); 155 add(info, gridBagConstraints); 156 157 holder.setLayout(new java.awt.BorderLayout ()); 158 159 gridBagConstraints = new java.awt.GridBagConstraints (); 160 gridBagConstraints.gridx = 0; 161 gridBagConstraints.gridy = 1; 162 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 163 gridBagConstraints.weightx = 1.0; 164 gridBagConstraints.weighty = 1.0; 165 gridBagConstraints.insets = new java.awt.Insets (0, 12, 11, 11); 166 add(holder, gridBagConstraints); 167 168 cancelButton.setText(org.openide.util.NbBundle.getMessage(ProgressPanel.class, "LBL_Cancel")); 169 gridBagConstraints = new java.awt.GridBagConstraints (); 170 gridBagConstraints.gridx = 0; 171 gridBagConstraints.gridy = 2; 172 gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST; 173 gridBagConstraints.insets = new java.awt.Insets (0, 12, 11, 11); 174 add(cancelButton, gridBagConstraints); 175 176 } 178 179 private javax.swing.JButton cancelButton; 181 private javax.swing.JPanel holder; 182 private javax.swing.JLabel info; 183 185 public Dimension getPreferredSize() { 186 Dimension orig = super.getPreferredSize(); 187 return new Dimension (500, orig.height); 188 } 189 190 } 191 | Popular Tags |