| 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 |
|
| 27 |
package dr.app.beauti.priorspanel; |
| 28 |
|
| 29 |
import dr.app.beauti.util.PanelUtils; |
| 30 |
import dr.app.gui.components.RealNumberField; |
| 31 |
|
| 32 |
import javax.swing.*; |
| 33 |
import java.awt.*; |
| 34 |
import java.awt.event.ActionListener; |
| 35 |
import java.awt.event.ActionEvent; |
| 36 |
import java.text.NumberFormat; |
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
public class SpecialNumberPanel extends JPanel implements ActionListener { |
| 45 |
private final JButton b1, b2, b3, b4, b5; |
| 46 |
private final JLabel label; |
| 47 |
|
| 48 |
private RealNumberField selectedField = null; |
| 49 |
|
| 50 |
SpecialNumberPanel() { |
| 51 |
super(new BorderLayout()); |
| 52 |
|
| 53 |
label = new JLabel("Set a special value in the text fields above:"); |
| 54 |
JPanel panel = new JPanel(new FlowLayout(FlowLayout.LEFT)); |
| 55 |
panel.setOpaque(false); |
| 56 |
|
| 57 |
b1 = new JButton(NumberFormat.getNumberInstance().format(Double.POSITIVE_INFINITY)); |
| 58 |
PanelUtils.setupComponent(b1); |
| 59 |
b1.setFocusable(false); |
| 60 |
b1.setActionCommand(RealNumberField.POSITIVE_INFINITY); |
| 61 |
b1.addActionListener(this); |
| 62 |
|
| 63 |
b2 = new JButton(NumberFormat.getNumberInstance().format(Double.NEGATIVE_INFINITY)); |
| 64 |
PanelUtils.setupComponent(b2); |
| 65 |
b2.setFocusable(false); |
| 66 |
b2.setActionCommand(RealNumberField.NEGATIVE_INFINITY); |
| 67 |
b2.addActionListener(this); |
| 68 |
|
| 69 |
b3 = new JButton("MAX"); |
| 70 |
PanelUtils.setupComponent(b3); |
| 71 |
b3.setFocusable(false); |
| 72 |
b3.setActionCommand(RealNumberField.MAX_VALUE); |
| 73 |
b3.addActionListener(this); |
| 74 |
|
| 75 |
b4 = new JButton("MIN"); |
| 76 |
PanelUtils.setupComponent(b4); |
| 77 |
b4.setFocusable(false); |
| 78 |
b4.setActionCommand(RealNumberField.MIN_VALUE); |
| 79 |
b4.addActionListener(this); |
| 80 |
|
| 81 |
b5 = new JButton(RealNumberField.NaN); |
| 82 |
PanelUtils.setupComponent(b5); |
| 83 |
b5.setFocusable(false); |
| 84 |
b5.setActionCommand(RealNumberField.NaN); |
| 85 |
b5.addActionListener(this); |
| 86 |
|
| 87 |
b1.setToolTipText("Click to set 'Positive Infinity' in the selected text field."); |
| 88 |
b2.setToolTipText("Click to set 'Negative Infinity' in the selected text field."); |
| 89 |
b3.setToolTipText("Click to set the 'Maximum numerical value' in the selected text field."); |
| 90 |
b3.setToolTipText("Click to set the 'Minimum numerical value' in the selected text field."); |
| 91 |
b3.setToolTipText("Click to set 'Not a Number' in the selected text field."); |
| 92 |
|
| 93 |
|
| 94 |
panel.add(b1); |
| 95 |
panel.add(b2); |
| 96 |
panel.add(b3); |
| 97 |
panel.add(b4); |
| 98 |
panel.add(b5); |
| 99 |
|
| 100 |
add(label, BorderLayout.NORTH); |
| 101 |
add(panel, BorderLayout.CENTER); |
| 102 |
} |
| 103 |
|
| 104 |
public void setSelectedField(RealNumberField selectedField) { |
| 105 |
this.selectedField = selectedField; |
| 106 |
} |
| 107 |
|
| 108 |
@Override |
| 109 |
public void setEnabled(boolean enabled) { |
| 110 |
super.setEnabled(enabled); |
| 111 |
b1.setEnabled(enabled); |
| 112 |
b2.setEnabled(enabled); |
| 113 |
b3.setEnabled(enabled); |
| 114 |
b4.setEnabled(enabled); |
| 115 |
b5.setEnabled(enabled); |
| 116 |
label.setEnabled(enabled); |
| 117 |
} |
| 118 |
|
| 119 |
public void actionPerformed(ActionEvent e) { |
| 120 |
if (selectedField != null) { |
| 121 |
selectedField.setText(e.getActionCommand()); |
| 122 |
} |
| 123 |
} |
| 124 |
} |