1 19 20 package org.netbeans.modules.j2ee.persistence.util; 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 48 public class ProgressPanel extends javax.swing.JPanel { 49 50 private Dialog dialog; 51 52 public ProgressPanel() { 53 initComponents(); 54 } 55 56 public void open(JComponent progressComponent) { 57 holder.add(progressComponent, BorderLayout.CENTER); 58 59 DialogDescriptor dd = new DialogDescriptor( 60 this, 61 NbBundle.getMessage(ProgressPanel.class, "MSG_PleaseWait"), 62 true, 63 new Object [0], 64 DialogDescriptor.NO_OPTION, 65 DialogDescriptor.DEFAULT_ALIGN, 66 null, 67 null, 68 true); 69 dialog = DialogDisplayer.getDefault().createDialog(dd); 70 if (dialog instanceof JDialog ) { 71 JDialog jDialog = ((JDialog )dialog); 72 jDialog.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE); 73 JRootPane rootPane = jDialog.getRootPane(); 74 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) { 77 if (cancelButton.isEnabled()) { 78 cancelButton.doClick(); 79 } 80 } 81 }); 82 } 83 dialog.setResizable(false); 84 dialog.setVisible(true); 85 } 86 87 public void close() { 88 if (dialog != null) { 89 dialog.setVisible(false); 90 dialog.dispose(); 91 } 92 } 93 94 public boolean isOpen() { 95 return dialog != null && dialog.isVisible(); 96 } 97 98 public void setText(String text) { 99 info.setText(text); 100 } 101 102 105 String getText() { 106 return info.getText(); 107 } 108 109 public void setCancelVisible(boolean cancelVisible) { 110 cancelButton.setVisible(cancelVisible); 111 } 112 113 116 boolean isCancelVisible() { 117 return cancelButton.isVisible(); 118 } 119 120 public void setCancelEnabled(boolean cancelEnabled) { 121 cancelButton.setEnabled(cancelEnabled); 122 } 123 124 127 boolean isCancelEnabled() { 128 return cancelButton.isEnabled(); 129 } 130 131 public void addCancelActionListener(ActionListener listener) { 132 cancelButton.addActionListener(listener); 133 } 134 135 138 JButton getCancelButton() { 139 return cancelButton; 140 } 141 142 147 private void initComponents() { 149 java.awt.GridBagConstraints gridBagConstraints; 150 151 info = new javax.swing.JLabel (); 152 holder = new javax.swing.JPanel (); 153 cancelButton = new javax.swing.JButton (); 154 155 setLayout(new java.awt.GridBagLayout ()); 156 157 info.setText(" "); 158 gridBagConstraints = new java.awt.GridBagConstraints (); 159 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 160 gridBagConstraints.insets = new java.awt.Insets (12, 12, 11, 11); 161 add(info, gridBagConstraints); 162 163 holder.setLayout(new java.awt.BorderLayout ()); 164 165 gridBagConstraints = new java.awt.GridBagConstraints (); 166 gridBagConstraints.gridx = 0; 167 gridBagConstraints.gridy = 1; 168 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 169 gridBagConstraints.weightx = 1.0; 170 gridBagConstraints.weighty = 1.0; 171 gridBagConstraints.insets = new java.awt.Insets (0, 12, 11, 11); 172 add(holder, gridBagConstraints); 173 174 cancelButton.setText(org.openide.util.NbBundle.getMessage(ProgressPanel.class, "LBL_Cancel")); 175 gridBagConstraints = new java.awt.GridBagConstraints (); 176 gridBagConstraints.gridx = 0; 177 gridBagConstraints.gridy = 2; 178 gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST; 179 gridBagConstraints.insets = new java.awt.Insets (0, 12, 11, 11); 180 add(cancelButton, gridBagConstraints); 181 182 } 184 185 private javax.swing.JButton cancelButton; 187 private javax.swing.JPanel holder; 188 private javax.swing.JLabel info; 189 191 public Dimension getPreferredSize() { 192 Dimension orig = super.getPreferredSize(); 193 return new Dimension (500, orig.height); 194 } 195 196 } 197 | Popular Tags |