Debian Codegraph @

src/dr/app/beauti/priorspanel/SpecialNumberPanel.java

raw symbols SCIP
1 /*
2 * SpecialNumberPanel.java
3 *
4 * Copyright (c) 2002-2015 Alexei Drummond, Andrew Rambaut and Marc Suchard
5 *
6 * This file is part of BEAST.
7 * See the NOTICE file distributed with this work for additional
8 * information regarding copyright ownership and licensing.
9 *
10 * BEAST is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU Lesser General Public License as
12 * published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
14 *
15 * BEAST is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with BEAST; if not, write to the
22 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
23 * Boston, MA 02110-1301 USA
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 * @author Walter Xie
40 * @author Andrew Rambaut
41 * @author Alexei Drummond
42 * @version $Id: SpecialNumberPanel.java,v 1.4 2006/09/05 13:29:34 rambaut Exp $
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 //Add Components to this container, using the default FlowLayout.
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 }