Skip to content

Commit

Permalink
Made the table for "More Options".
Browse files Browse the repository at this point in the history
  • Loading branch information
carsonalh committed Jun 12, 2019
1 parent 91b6d55 commit 59a04ee
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/gui/continuous/MoreOptionsFrame.java
Expand Up @@ -22,7 +22,7 @@ public MoreOptionsFrame() {
super();

// Creation
table = new JTable();
table = new MoreOptionsTable();
tableContainer = new JScrollPane(table);
submitButton = new JButton("Save");
cancelButton = new JButton("Cancel");
Expand Down
78 changes: 78 additions & 0 deletions src/gui/continuous/MoreOptionsTable.java
@@ -0,0 +1,78 @@
package gui.continuous;

import javax.swing.*;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableCellEditor;
import javax.swing.table.TableCellRenderer;

public class MoreOptionsTable extends JTable {

private static final String[] COLUMNS = new String[]{"Field", "Value"};
private static final Object[][] DATA = {
{"Function", "x^2", String.class},
{"Start", 0.0, Double.class},
{"Count", 0, Integer.class},
{"Stride", 0.0, Double.class},
{"SigmaX", 0.0, Double.class},
{"SigmaY", 0.0, Double.class},
{"Outliers", false, Boolean.class},
{"One Every", 0, Integer.class},
{"Scale", 0.0, Double.class},
};
private Class editingClass = null;

public MoreOptionsTable() {
super(new MoreOptionsTableModel(getDisplayData(), COLUMNS));

getTableHeader().setReorderingAllowed(false);
setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
}

private static Object[][] getDisplayData() {
Object[][] displayData = new Object[DATA.length][2];

for (int i = 0; i < DATA.length; i++) {
displayData[i][0] = DATA[i][0];
displayData[i][1] = DATA[i][1];
}

return displayData;
}

@Override
public TableCellRenderer getCellRenderer(int row, int column) {
editingClass = null;

Class cellClass = getModel().getValueAt(row, column).getClass();
return getDefaultRenderer(cellClass);
}

@Override
public TableCellEditor getCellEditor(int row, int column) {
editingClass = null;

if (getModel().isCellEditable(row, column)) {
editingClass = getModel().getValueAt(row, column).getClass();
return getDefaultEditor(editingClass);
} else {
return super.getCellEditor(row, column);
}
}

@Override
public Class<?> getColumnClass(int column) {
return editingClass != null ? editingClass : super.getColumnClass(column);
}

private static class MoreOptionsTableModel extends DefaultTableModel {
public MoreOptionsTableModel(Object[][] data, Object[] columnNames) {
super(data, columnNames);
}

@Override
public boolean isCellEditable(int row, int column) {
return column == 1;
}
}

}

0 comments on commit 59a04ee

Please sign in to comment.