Debian Codegraph @

src/dr/app/coalgen/InputsPanel.java

raw symbols SCIP
1 /*
2 * InputsPanel.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 package dr.app.coalgen;
27
28 import jam.framework.Exportable;
29 import jam.panels.OptionsPanel;
30
31 import javax.swing.*;
32 import java.awt.*;
33 import java.awt.event.ActionEvent;
34 import java.awt.event.ActionListener;
35 import java.io.File;
36 import java.io.IOException;
37
38 /**
39 * @author Andrew Rambaut
40 * @author Alexei Drummond
41 * @version $Id$
42 */
43 public class InputsPanel extends JPanel implements Exportable {
44
45 private final CoalGenFrame frame;
46 private final CoalGenData data;
47
48 private OptionsPanel optionPanel;
49
50 private final JButton logFileButton = new JButton("Choose File...");
51 private final JTextField logFileNameText = new JTextField("not selected", 16);
52
53 private final JButton treesFileButton = new JButton("Choose File...");
54 private final JTextField treesFileNameText = new JTextField("not selected", 16);
55
56
57 public InputsPanel(final CoalGenFrame frame, final CoalGenData data) {
58
59 super();
60
61 this.frame = frame;
62 this.data = data;
63
64 setOpaque(false);
65 setLayout(new BorderLayout());
66
67 optionPanel = new OptionsPanel(12, 12, SwingConstants.CENTER);
68 add(optionPanel, BorderLayout.NORTH);
69
70 logFileButton.addActionListener(new ActionListener() {
71 public void actionPerformed(ActionEvent ae) {
72 FileDialog dialog = new FileDialog(frame,
73 "Select input log file...",
74 FileDialog.LOAD);
75
76 dialog.setVisible(true);
77 if (dialog.getFile() == null) {
78 // the dialog was cancelled...
79 return;
80 }
81
82 logFileButton.setEnabled(false);
83
84 File file = new File(dialog.getDirectory(), dialog.getFile());
85 try {
86 frame.readFromFile(file);
87 } catch (IOException e) {
88 e.printStackTrace();
89 }
90 }
91 });
92 logFileNameText.setEditable(false);
93
94 treesFileButton.addActionListener(new ActionListener() {
95 public void actionPerformed(ActionEvent ae) {
96 FileDialog dialog = new FileDialog(frame,
97 "Select input trees file...",
98 FileDialog.LOAD);
99
100 dialog.setVisible(true);
101 if (dialog.getFile() == null) {
102 // the dialog was cancelled...
103 return;
104 }
105
106 data.treesFile = new File(dialog.getDirectory(), dialog.getFile());
107 treesFileNameText.setText(data.treesFile.getName());
108
109 frame.fireTracesChanged();
110 }
111 });
112 treesFileNameText.setEditable(false);
113
114 JPanel panel1 = new JPanel(new BorderLayout(0, 0));
115 panel1.setOpaque(false);
116 panel1.add(logFileNameText, BorderLayout.CENTER);
117 panel1.add(logFileButton, BorderLayout.EAST);
118 optionPanel.addComponentWithLabel("Log File: ", panel1);
119
120 JPanel panel2 = new JPanel(new BorderLayout(0, 0));
121 panel2.setOpaque(false);
122 panel2.add(treesFileNameText, BorderLayout.CENTER);
123 panel2.add(treesFileButton, BorderLayout.EAST);
124 optionPanel.addComponentWithLabel("Input Trees File: ", panel2);
125 }
126
127 public final void tracesChanged() {
128 logFileButton.setEnabled(true);
129 if (data.logFile != null) {
130 logFileNameText.setText(data.logFile.getName());
131 }
132 }
133
134 public void collectSettings() {
135
136 }
137
138 public JComponent getExportableComponent() {
139 return this;
140 }
141 }