Changeset 2319 in josm for trunk/src/org/openstreetmap/josm/gui/PleaseWaitDialog.java
- Timestamp:
- 2009-10-25T18:22:28+01:00 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/PleaseWaitDialog.java
r2050 r2319 2 2 package org.openstreetmap.josm.gui; 3 3 4 import java.awt.Dialog; 5 import java.awt.Frame; 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 6 import java.awt.Component; 7 import java.awt.GridBagConstraints; 6 8 import java.awt.GridBagLayout; 9 import java.awt.event.ActionListener; 7 10 import java.awt.event.ComponentEvent; 8 11 import java.awt.event.ComponentListener; … … 13 16 import javax.swing.JDialog; 14 17 import javax.swing.JLabel; 18 import javax.swing.JOptionPane; 15 19 import javax.swing.JPanel; 16 20 import javax.swing.JProgressBar; 21 import javax.swing.JScrollPane; 22 import javax.swing.JTextArea; 17 23 import javax.swing.UIManager; 18 24 19 25 import org.openstreetmap.josm.Main; 20 26 import org.openstreetmap.josm.tools.GBC; 21 import org.openstreetmap.josm.tools.I 18n;27 import org.openstreetmap.josm.tools.ImageProvider; 22 28 23 29 public class PleaseWaitDialog extends JDialog { … … 28 34 private final JLabel customText = new JLabel(""); 29 35 public final BoundedRangeModel progress = progressBar.getModel(); 30 public final JButton cancel = new JButton(I18n.tr("Cancel")); 36 private JButton btnCancel; 37 /** the text area and the scroll pane for the log */ 38 private JTextArea taLog = new JTextArea(5,50); 39 private JScrollPane spLog; 31 40 32 41 private void initDialog() { … … 37 46 pane.add(customText, GBC.eol().fill(GBC.HORIZONTAL)); 38 47 pane.add(progressBar, GBC.eop().fill(GBC.HORIZONTAL)); 39 pane.add(cancel, GBC.eol().anchor(GBC.CENTER)); 48 btnCancel = new JButton(tr("Cancel")); 49 btnCancel.setIcon(ImageProvider.get("cancel")); 50 btnCancel.setToolTipText(tr("Click to cancel the current operation")); 51 pane.add(btnCancel, GBC.eol().anchor(GBC.CENTER)); 52 GridBagConstraints gc = GBC.eol().fill(GBC.BOTH); 53 gc.weighty = 1.0; 54 gc.weightx = 1.0; 55 pane.add(spLog = new JScrollPane(taLog), gc); 56 spLog.setVisible(false); 40 57 setContentPane(pane); 41 58 //setSize(Main.pref.getInteger("progressdialog.size",600),100); 42 59 setCustomText(""); 43 setLocationRelativeTo( Main.parent);60 setLocationRelativeTo(getParent()); 44 61 addComponentListener(new ComponentListener() { 45 62 public void componentHidden(ComponentEvent e) {} … … 55 72 } 56 73 57 public PleaseWaitDialog(Frame parent) { 58 super(parent, true); 59 initDialog(); 60 } 61 62 public PleaseWaitDialog(Dialog parent) { 63 super(parent, true); 74 public PleaseWaitDialog(Component parent) { 75 super(JOptionPane.getFrameForComponent(parent), true); 64 76 initDialog(); 65 77 } … … 70 82 } 71 83 84 protected void adjustLayout() { 85 invalidate(); 86 pack(); 87 setSize(Main.pref.getInteger("progressdialog.size", 600), getSize().height); 88 } 89 72 90 /** 73 91 * Sets a custom text line below currentAction. Can be used to display additional information … … 75 93 */ 76 94 public void setCustomText(String text) { 77 if(text .length() == 0) {95 if(text == null || text.trim().length() == 0) { 78 96 customText.setVisible(false); 79 setSize(Main.pref.getInteger("progressdialog.size", 600), 100);97 adjustLayout(); 80 98 return; 81 99 } 100 if (!customText.isVisible()) { 101 customText.setVisible(true); 102 adjustLayout(); 103 } 104 customText.setText(text); 105 } 82 106 83 customText.setVisible(true); 84 customText.setText(text); 85 setSize(Main.pref.getInteger("progressdialog.size", 600), 120); 107 /** 108 * Appends a log message to the progress dialog. If the log area isn't visible yet 109 * it becomes visible. The height of the progress dialog is slightly increased too. 110 * 111 * @param message the message to append to the log. Ignore if null or white space only. 112 */ 113 public void appendLogMessage(String message) { 114 if (message == null || message.trim().length() ==0 ) 115 return; 116 if (!spLog.isVisible()) { 117 spLog.setVisible(true); 118 taLog.setVisible(true); 119 adjustLayout(); 120 } 121 taLog.append(message); 122 taLog.append("\n"); 123 spLog.getVerticalScrollBar().setValue(spLog.getVerticalScrollBar().getMaximum()); 124 } 125 126 /** 127 * Sets whether the cancel button is enabled or not 128 * 129 * @param enabled true, if the cancel button is enabled; false otherwise 130 */ 131 public void setCancelEnabled(boolean enabled) { 132 btnCancel.setEnabled(enabled); 133 } 134 135 /** 136 * Installs a callback for the cancel button. If callback is null, all action listeners 137 * are removed from the cancel button. 138 * 139 * @param callback the cancel callback 140 */ 141 public void setCancelCallback(ActionListener callback) { 142 if (callback == null) { 143 ActionListener[] listeners = btnCancel.getActionListeners(); 144 for (ActionListener l: listeners) { 145 btnCancel.removeActionListener(l); 146 } 147 } else { 148 btnCancel.addActionListener(callback); 149 } 86 150 } 87 151 }
Note:
See TracChangeset
for help on using the changeset viewer.