| 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.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 |
|
| 40 |
|
| 41 |
|
| 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 |
|
| 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 |
|
| 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 |
} |