Skip to content
Snippets Groups Projects
Commit 63eb33b4 authored by Erik Diers's avatar Erik Diers
Browse files

Fixed bugs

parent 93e6e462
No related branches found
No related tags found
No related merge requests found
No preview for this file type
......@@ -19,7 +19,7 @@ import utils.SFB_Util;
public class Main {
private static final String XLSX_SESSION_PREFIX = "SessionDate";
private static final String SFB_SUBJID = "subjectID";
private static final String SFB_SUBJID = "Subject ID";
private static final String SFB_RECORD_DATE = "Record Date";
private static int xlsx_subjIdHeaderIndex = -1;
......@@ -43,6 +43,23 @@ public class Main {
FileChooserPanel xlsxImportFile = new FileChooserPanel("Excel import file").switchToFileSelect(".xlsx");
ConditionedPanel importFromXlsx = new ConditionedPanel("Import from Excel", false, baseMetaJson, xlsxImportFile);
importFromXlsx.addActionListener( (ActionEvent e) -> {
boolean notState = !importFromXlsx.getOutput();
numberOfConsecutiveSubjects.setEnabled(notState);
if (!notState)
useCustomSubjectCodes.setValue(notState);
sessionAmount.setEnabled(notState);
});
useCustomSubjectCodes.addActionListener( (ActionEvent e) -> {
numberOfConsecutiveSubjects.setEnabled(true);
if (useCustomSubjectCodes.getOutput())
importFromXlsx.setValue(false);
sessionAmount.setEnabled(true);
});
ButtonPanel submit = new ButtonPanel("Create", new ActionListener() {
@Override
......@@ -82,11 +99,13 @@ public class Main {
xlsxReader = CSV_Reader.fromXLSX(xlsxImportFile.getOutput(), null);
for (int i = 0; i < sessions; i++) {
if (xlsxReader.getColumn(XLSX_SESSION_PREFIX + " " + i) == -1) {
SimpleFrame.promt("Excel file has not specifed Session date " + i + " [" + XLSX_SESSION_PREFIX + " " + i + "]");
return;
}
sessions = 0;
while(xlsxReader.getColumn(XLSX_SESSION_PREFIX + " " + (sessions + 1)) != -1)
sessions++;
if (sessions == 0) {
SimpleFrame.promt("Please specify session dates in excel file: " + XLSX_SESSION_PREFIX + " 0");
return;
}
......@@ -197,11 +216,17 @@ public class Main {
for(int i = 0; i < currentRow.length; i++) {
String header = xlsxReader.getColumnHead(i);
if (header.startsWith(XLSX_SESSION_PREFIX)) {
if (header.endsWith("" + currentSession)) //Identifies the current session. This breaks in case of more than 9 sessions. But this wont happen.
if (header.endsWith("" + currentSession)) { //Identifies the current session. This breaks in case of more than 9 sessions. But this wont happen.
obj.put("DataCite-Date", currentRow[i]);
obj.put("DublinCore-Date", currentRow[i]);
header = SFB_RECORD_DATE;
else
}else
continue;
}
if (header.trim().equals("") || currentRow[i].equals(""))
continue;
obj.put(header, currentRow[i]);
}
......
......@@ -5,7 +5,7 @@ import java.awt.FlowLayout;
import javax.swing.JCheckBox;
import javax.swing.JPanel;
public class CheckboxPanel extends JPanel implements IOutput<Boolean>{
public class CheckboxPanel extends JPanel implements IOutput<Boolean, CheckboxPanel>{
private static final long serialVersionUID = 186566928368140438L;
private JCheckBox checkBox;
......@@ -29,4 +29,10 @@ public class CheckboxPanel extends JPanel implements IOutput<Boolean>{
return checkBox.isSelected();
}
@Override
public CheckboxPanel setValue(Boolean val) {
this.checkBox.setSelected(val);
return this;
}
}
......@@ -6,7 +6,7 @@ import java.awt.FlowLayout;
import javax.swing.JLabel;
import javax.swing.JPanel;
public class ComboSelectionPanel extends JPanel implements IOutput<String[]>{
public class ComboSelectionPanel extends JPanel implements IOutput<String[], ComboSelectionPanel>{
private static final long serialVersionUID = -2030551269354521325L;
public static final String[] SFB_MODALITIES = new String[] {"Behavorial", "Calcium Imaging", "ECG|Pulse", "EDA", "EEG", "Eyetracking", "Histology", "Hormone measurements", "LFP", "MRI", "Questionaires", "Respiration", "Single cell recording", "TMS"};
......@@ -31,5 +31,10 @@ public class ComboSelectionPanel extends JPanel implements IOutput<String[]>{
public String[] getOutput() {
return comboSel.GetSelectedStrings();
}
@Override
public ComboSelectionPanel setValue(String[] val) {
throw new RuntimeException("Not jet implemented!");
}
}
......@@ -19,7 +19,7 @@ import javax.swing.JSpinner;
import javax.swing.SpinnerNumberModel;
import javax.swing.border.EmptyBorder;
public class ConditionedPanel extends JPanel implements ActionListener, IOutput<Boolean>{
public class ConditionedPanel extends JPanel implements ActionListener, IOutput<Boolean, ConditionedPanel>{
private static final long serialVersionUID = 9148401845646235697L;
private JCheckBox checkBox;
......@@ -58,13 +58,17 @@ public class ConditionedPanel extends JPanel implements ActionListener, IOutput<
actionPerformed(null);
}
public void addActionListener(ActionListener listener) {
checkBox.addActionListener(listener);
}
private Component leftJustify( JComponent panel ) {
Box b = Box.createHorizontalBox();
b.add( panel );
b.add( Box.createHorizontalGlue() );
return b;
}
@Override
public Boolean getOutput() {
return checkBox.isSelected();
......@@ -81,14 +85,14 @@ public class ConditionedPanel extends JPanel implements ActionListener, IOutput<
@SuppressWarnings("unchecked")
public <T> T getInternalOutput() {
return ((IOutput<T>)interalPanels[0]).getOutput();
return ((IOutput<T,?>)interalPanels[0]).getOutput();
}
@SuppressWarnings("unchecked")
public <T> LinkedList<T> getInternalOutputs() {
LinkedList<T> list = new LinkedList<T>();
for(int i = 0; i < interalPanels.length; i++) {
list.add(((IOutput<T>)interalPanels[0]).getOutput());
list.add(((IOutput<T,?>)interalPanels[0]).getOutput());
}
return list;
......@@ -111,4 +115,12 @@ public class ConditionedPanel extends JPanel implements ActionListener, IOutput<
}
}
@Override
public ConditionedPanel setValue(Boolean val) {
if (checkBox.isSelected() != val) {
checkBox.doClick();
}
return this;
}
}
......@@ -11,7 +11,7 @@ import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.filechooser.FileFilter;
public class FileChooserPanel extends JPanel implements IOutput<File>, ActionListener{
public class FileChooserPanel extends JPanel implements IOutput<File, FileChooserPanel>, ActionListener{
private static final long serialVersionUID = 3136641561102977065L;
private JButton button;
private JLabel text;
......@@ -104,5 +104,14 @@ public class FileChooserPanel extends JPanel implements IOutput<File>, ActionLis
return filesOut;
}
@Override
public FileChooserPanel setValue(File val) {
out = val;
text.setText(out.getAbsolutePath().substring(
(int)Math.max(0, out.getAbsolutePath().length() - maxFilenameCharactersShown)));
return this;
}
}
package uiutils;
public interface IOutput<T> {
public interface IOutput<T, THIS> {
T getOutput();
THIS setValue(T val);
}
......@@ -14,7 +14,7 @@ import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.text.Document;
public class InputFieldPanel extends JPanel implements IOutput<String>{
public class InputFieldPanel extends JPanel implements IOutput<String, InputFieldPanel>{
private PlaceholderTextField txtField;
......@@ -94,4 +94,10 @@ public class InputFieldPanel extends JPanel implements IOutput<String>{
}
}
@Override
public InputFieldPanel setValue(String val) {
txtField.setText(val);
return this;
}
}
......@@ -24,7 +24,7 @@ public class ReportABugWindow extends SimpleFrame{
private static final long serialVersionUID = -9110093488807819801L;
private HashMap<String, IOutput<?>> nameToFieldTable;
private HashMap<String, IOutput<?, ?>> nameToFieldTable;
private CheckboxPanel includeLogData;
private String applicationName;
......@@ -84,11 +84,11 @@ public class ReportABugWindow extends SimpleFrame{
}
public void AddElement(String jsonName, JPanel ioutputPanel) {
if (!(ioutputPanel instanceof IOutput<?>)) {
if (!(ioutputPanel instanceof IOutput<?, ?>)) {
throw new RuntimeException("Only IOutput panels can be added!");
}
nameToFieldTable.put(jsonName, (IOutput<?>)ioutputPanel);
nameToFieldTable.put(jsonName, (IOutput<?, ?>)ioutputPanel);
super.addCenter(ioutputPanel);
}
......@@ -97,7 +97,7 @@ public class ReportABugWindow extends SimpleFrame{
public JSONObject createJSON() {
JSONObject json = new JSONObject();
for(Entry<String, IOutput<?>> entry : nameToFieldTable.entrySet()) {
for(Entry<String, IOutput<?, ?>> entry : nameToFieldTable.entrySet()) {
json.put(entry.getKey(), entry.getValue().getOutput().toString());
}
......
......@@ -9,7 +9,7 @@ import javax.swing.JSpinner;import javax.swing.SpinnerModel;
import javax.swing.SpinnerNumberModel;
import javax.swing.event.ChangeListener;
public class SpinnerINTPanel extends JPanel implements IOutput<Integer>{
public class SpinnerINTPanel extends JPanel implements IOutput<Integer, SpinnerINTPanel>{
private static final long serialVersionUID = -2030532269354521325L;
private JSpinner spinner;
......@@ -34,6 +34,18 @@ public class SpinnerINTPanel extends JPanel implements IOutput<Integer>{
public Integer getOutput() {
return (int)spinner.getValue();
}
@Override
public void setEnabled(boolean enabled) {
spinner.setEnabled(enabled);
super.setEnabled(enabled);
}
@Override
public SpinnerINTPanel setValue(Integer val) {
spinner.setValue(val);
return this;
}
......
......@@ -11,7 +11,7 @@ import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
public class TextAreaPanel extends JPanel implements IOutput<String> {
public class TextAreaPanel extends JPanel implements IOutput<String, TextAreaPanel> {
private static final long serialVersionUID = 5857892221079489896L;
public JTextArea textArea;
......@@ -59,4 +59,10 @@ public class TextAreaPanel extends JPanel implements IOutput<String> {
public String getOutput() {
return textArea.getText();
}
@Override
public TextAreaPanel setValue(String val) {
textArea.setText(val);
return this;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment