| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
package dr.app.beauti.tipdatepanel; |
| 27 |
|
| 28 |
import jam.panels.OptionsPanel; |
| 29 |
|
| 30 |
import javax.swing.*; |
| 31 |
import javax.swing.border.EmptyBorder; |
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
public class SetValueDialog { |
| 41 |
|
| 42 |
private JFrame frame; |
| 43 |
private final OptionsPanel optionPanel; |
| 44 |
private String title = "Set Values for Taxa"; |
| 45 |
|
| 46 |
JLabel descriptionText = new JLabel(); |
| 47 |
|
| 48 |
private final JTextField valueText = new JTextField(16); |
| 49 |
|
| 50 |
public SetValueDialog(JFrame frame, String title) { |
| 51 |
this.frame = frame; |
| 52 |
|
| 53 |
this.title = title; |
| 54 |
|
| 55 |
optionPanel = new OptionsPanel(12, 12); |
| 56 |
|
| 57 |
optionPanel.addSpanningComponent(descriptionText); |
| 58 |
optionPanel.addComponentWithLabel("Value: ", valueText); |
| 59 |
} |
| 60 |
|
| 61 |
public void setDescription(String description) { |
| 62 |
descriptionText.setText(description); |
| 63 |
} |
| 64 |
|
| 65 |
public void setTitle(String title) { |
| 66 |
this.title = title; |
| 67 |
} |
| 68 |
|
| 69 |
public int showDialog() { |
| 70 |
|
| 71 |
JOptionPane optionPane = new JOptionPane(optionPanel, |
| 72 |
JOptionPane.QUESTION_MESSAGE, |
| 73 |
JOptionPane.OK_CANCEL_OPTION, |
| 74 |
null, |
| 75 |
null, |
| 76 |
null); |
| 77 |
optionPane.setBorder(new EmptyBorder(12, 12, 12, 12)); |
| 78 |
|
| 79 |
final JDialog dialog = optionPane.createDialog(frame, title); |
| 80 |
dialog.pack(); |
| 81 |
|
| 82 |
dialog.setVisible(true); |
| 83 |
|
| 84 |
int result = JOptionPane.CANCEL_OPTION; |
| 85 |
Integer value = (Integer) optionPane.getValue(); |
| 86 |
if (value != null && value != -1) { |
| 87 |
result = value; |
| 88 |
} |
| 89 |
|
| 90 |
return result; |
| 91 |
} |
| 92 |
|
| 93 |
public String getValue() { |
| 94 |
return valueText.getText(); |
| 95 |
} |
| 96 |
} |