use of javax.swing.table.JTableHeader in project mafscaling by vimsh.
the class LogView method loadLogFile.
private void loadLogFile() {
// close log player
if (logPlayWindow != null)
disposeLogView();
// process log file
File file = fileChooser.getSelectedFile();
Properties prop = new Properties();
prop.put("delimiter", ",");
prop.put("firstRowHasColumnNames", "true");
setCursor(new Cursor(Cursor.WAIT_CURSOR));
logDataTable.filter(null);
filterText.setText("");
Column col;
String colName;
String lcColName;
String val;
try {
for (int i = 0; i < logDataTable.getColumnCount(); ++i) {
try {
CheckboxHeaderRenderer cbr = (CheckboxHeaderRenderer) logDataTable.getColumn(i).getHeaderRenderer();
logDataTable.getTableHeader().removeMouseListener(cbr.getMouseListener());
} catch (Exception e) {
}
}
BufferedReader br = null;
try {
br = new BufferedReader(new InputStreamReader(new FileInputStream(file.getAbsoluteFile()), Config.getEncoding()));
String line = null;
br.mark(1024);
while ((line = br.readLine()) != null && !line.contains(",")) {
br.mark(1024);
continue;
}
br.reset();
logDataTable.refresh(br, prop);
// Below is a hack code to check and convert time column hh:mm:ss.sss to msec number
convertTimeToMsec();
// Below is a hack code to check and convert column(s) with on/off values to number
convertOnOffToNumMsec();
} catch (Exception e) {
JOptionPane.showMessageDialog(null, e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
return;
} finally {
if (br != null) {
try {
br.close();
} catch (IOException e) {
logger.error(e);
}
}
}
CheckboxHeaderRenderer renderer;
Component comp;
XYSeries series;
selectionCombo.removeAllItems();
listModel.removeAllElements();
xAxisColumn.removeAllItems();
yAxisColumn.removeAllItems();
plotsColumn.removeAllItems();
xAxisColumn.addItem("");
yAxisColumn.addItem("");
plotsColumn.setText("");
plot3d.removeAllPlots();
rpmDataset.removeAllSeries();
dataset.removeAllSeries();
xMarker.clearLabels(true);
rpmCol = -1;
displCount = 0;
JTableHeader tableHeader = logDataTable.getTableHeader();
TreeSet<String> sortedColumns = new TreeSet<String>();
for (int i = 0; i < logDataTable.getColumnCount(); ++i) {
col = logDataTable.getColumn(i);
renderer = new CheckboxHeaderRenderer(i + 1, tableHeader);
col.setHeaderRenderer(renderer);
colName = col.getHeaderValue().toString();
sortedColumns.add(colName);
comp = renderer.getTableCellRendererComponent(logDataTable.getTable(), colName, false, false, 0, 0);
col.setPreferredWidth(comp.getPreferredSize().width + 4);
series = new XYSeries(colName);
series.setDescription(colName);
lcColName = colName.toLowerCase();
dataset.addSeries(series);
plotRenderer.setSeriesShapesVisible(i, false);
plotRenderer.setSeriesVisible(i, false);
if (rpmDataset.getSeriesCount() == 0 && (lcColName.matches(rpmMatchString) || lcColName.matches(engineSpeedMatchString))) {
rpmDataset.addSeries(series);
rpmPlotRenderer.setSeriesShapesVisible(0, false);
rpmPlotRenderer.setSeriesVisible(0, false);
rpmCol = i;
}
for (int j = 0; j < logDataTable.getRowCount(); ++j) {
try {
val = (String) logDataTable.getValueAt(j, i);
series.add(j, Double.valueOf(val), false);
} catch (Exception e) {
JOptionPane.showMessageDialog(null, "Invalid numeric value in column " + colName + ", row " + (j + 1), "Invalid value", JOptionPane.ERROR_MESSAGE);
if (br != null)
br.close();
return;
}
}
series.fireSeriesChanged();
}
for (String s : sortedColumns) {
xAxisColumn.addItem(s);
yAxisColumn.addItem(s);
plotsColumn.addItem(s);
selectionCombo.addItem(s);
renderer = (CheckboxHeaderRenderer) logDataTable.getColumnByHeaderName(s).getHeaderRenderer();
listModel.addElement(new JLabel(s, renderer.getCheckIcon(), JLabel.LEFT));
}
if (logDataTable.getControlPanel().getComponentCount() > tableControlPanelNumComponents)
logDataTable.getControlPanel().remove(tableControlPanelNumComponents);
logDataTable.getControlPanel().add(new JLabel(" [" + file.getName() + "]"));
initColors();
} catch (Exception ex) {
ex.printStackTrace();
logger.error(ex);
} finally {
setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
}
}
use of javax.swing.table.JTableHeader in project mafscaling by vimsh.
the class LogView method createLogViewPanel.
private void createLogViewPanel() {
logViewPanel = new JPanel();
GridBagLayout gbl_logViewPanel = new GridBagLayout();
gbl_logViewPanel.columnWidths = new int[] { 0 };
gbl_logViewPanel.rowHeights = new int[] { 0, 0 };
gbl_logViewPanel.columnWeights = new double[] { 1.0 };
gbl_logViewPanel.rowWeights = new double[] { 1.0, 0.0 };
logViewPanel.setLayout(gbl_logViewPanel);
try {
logDataTable = new DBTable();
logDataTable.copyColumnHeaderNames = true;
logDataTable.defaultClickCountToStartEditor = 2;
logDataTable.doNotUseDatabaseSort = true;
logDataTable.listenKeyPressEventsWholeWindow = true;
logDataTable.createControlPanel(DBTable.READ_NAVIGATION);
logDataTable.enableExcelCopyPaste();
logDataTable.setSortEnabled(false);
logDataTable.setSkin(new TableSkin());
logDataTable.refresh(new String[1][25]);
logDataTable.setComparator(new DoubleComparator());
logDataTable.getTable().setCellSelectionEnabled(true);
logDataTable.getTable().setColumnSelectionAllowed(true);
logDataTable.getTable().setRowSelectionAllowed(true);
logDataTable.getTable().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
JTextField rowTextField = ((JTextField) logDataTable.getControlPanel().getComponent(tableRowTextFieldComponentIdx));
rowTextField.setPreferredSize(null);
rowTextField.setColumns(tableRowTextFieldSize);
GridBagConstraints gbc_logDataTable = new GridBagConstraints();
gbc_logDataTable.insets = insets0;
gbc_logDataTable.anchor = GridBagConstraints.PAGE_START;
gbc_logDataTable.fill = GridBagConstraints.BOTH;
gbc_logDataTable.gridx = 0;
gbc_logDataTable.gridy = 0;
logViewPanel.add(logDataTable, gbc_logDataTable);
listModel = new DefaultListModel<JLabel>();
selectionCombo.removeAllItems();
TreeSet<String> sortedCols = new TreeSet<String>();
JTableHeader tableHeader = logDataTable.getTableHeader();
for (int i = 0; i < logDataTable.getColumnCount(); ++i) {
Column col = logDataTable.getColumn(i);
col.setNullable(true);
col.setHeaderRenderer(new CheckboxHeaderRenderer(i + 1, tableHeader));
sortedCols.add(col.getHeaderValue().toString());
}
for (String s : sortedCols) {
selectionCombo.addItem(s);
listModel.addElement(new JLabel(s, new CheckBoxIcon(), JLabel.LEFT));
}
JList<JLabel> menuList = new JList<JLabel>(listModel);
menuList.setOpaque(false);
menuList.setCellRenderer(new ImageListCellRenderer());
menuList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
menuList.setLayoutOrientation(JList.VERTICAL_WRAP);
menuList.setFixedCellHeight(25);
menuList.setVisibleRowCount(-1);
menuList.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
try {
if (e.getClickCount() == 1 && colors.size() > 0) {
JList<?> list = (JList<?>) e.getSource();
int index = list.locationToIndex(e.getPoint());
if (index >= 0) {
JLabel label = (JLabel) list.getModel().getElementAt(index);
Column col = logDataTable.getColumnByHeaderName(label.getText());
if (col.getHeaderRenderer() instanceof CheckboxHeaderRenderer) {
CheckboxHeaderRenderer renderer = (CheckboxHeaderRenderer) col.getHeaderRenderer();
CheckBoxIcon checkIcon = (CheckBoxIcon) label.getIcon();
checkIcon.setChecked(!checkIcon.isChecked());
if (checkIcon.isChecked()) {
checkIcon.setColor(colors.pop());
JTable table = logDataTable.getTable();
TableModel model = table.getModel();
addXYSeries(model, col.getModelIndex() - 1, col.getHeaderValue().toString(), checkIcon.getColor());
} else {
colors.push(checkIcon.getColor());
checkIcon.setColor(renderer.getDefaultColor());
removeXYSeries(col.getModelIndex() - 1);
}
list.repaint();
}
}
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
});
headerScrollPane = new JScrollPane(menuList);
GridBagConstraints gbc_headersTree = new GridBagConstraints();
gbc_headersTree.insets = insets0;
gbc_headersTree.anchor = GridBagConstraints.PAGE_START;
gbc_headersTree.fill = GridBagConstraints.BOTH;
gbc_headersTree.gridx = 0;
gbc_headersTree.gridy = 1;
logViewPanel.add(headerScrollPane, gbc_headersTree);
headerScrollPane.setVisible(false);
} catch (Exception e) {
e.printStackTrace();
logger.error(e);
}
}
use of javax.swing.table.JTableHeader in project com.revolsys.open by revolsys.
the class SingleRecordTableModel method newTable.
public static BaseJTable newTable(final Record object, final boolean editable) {
final SingleRecordTableModel model = new SingleRecordTableModel(object, editable);
final BaseJTable table = newTable(model);
final JTableHeader tableHeader = table.getTableHeader();
tableHeader.setReorderingAllowed(false);
return table;
}
use of javax.swing.table.JTableHeader in project com.revolsys.open by revolsys.
the class JTableUtil method sizeColumnsToFit.
public static void sizeColumnsToFit(final JTable table) {
Invoke.later(() -> {
final JTableHeader tableHeader = table.getTableHeader();
final TableColumnModel columnModel = table.getColumnModel();
for (int columnIndex = 0; columnIndex < table.getColumnCount(); columnIndex++) {
final TableColumn column = columnModel.getColumn(columnIndex);
final String columnName = table.getColumnName(columnIndex);
final TableCellRenderer headerRenderer = tableHeader.getDefaultRenderer();
final int headerWidth = headerRenderer.getTableCellRendererComponent(table, columnName, false, false, 0, 0).getPreferredSize().width;
int maxwidth = headerWidth + 20;
for (int rowIndex = 0; rowIndex < table.getRowCount(); rowIndex++) {
final TableCellRenderer cellRenderer = table.getCellRenderer(rowIndex, columnIndex);
final Object value = table.getValueAt(rowIndex, columnIndex);
final Component component = cellRenderer.getTableCellRendererComponent(table, value, false, false, rowIndex, columnIndex);
maxwidth = Math.max(component.getPreferredSize().width, maxwidth);
}
column.setPreferredWidth(maxwidth + 5);
}
});
}
use of javax.swing.table.JTableHeader in project com.revolsys.open by revolsys.
the class SortableTableCellHeaderRenderer method getTableCellRendererComponent.
@Override
public Component getTableCellRendererComponent(final JTable table, final Object value, final boolean isSelected, final boolean hasFocus, final int row, final int column) {
Icon icon = (Icon) UIManager.get("Table.naturalSortIcon");
boolean isPrint = false;
if (table != null) {
final JTableHeader header = table.getTableHeader();
if (header != null) {
Color foreground = null;
Color background = null;
if (hasFocus) {
foreground = (Color) UIManager.get("TableHeader.focusCellForeground");
background = (Color) UIManager.get("TableHeader.focusCellBackground");
}
if (foreground == null) {
foreground = header.getForeground();
}
if (background == null) {
background = header.getBackground();
}
setForeground(foreground);
setBackground(background);
setFont(header.getFont());
isPrint = header.isPaintingForPrint();
}
if (!isPrint) {
if (!this.horizontalTextPositionSet) {
setHorizontalTextPosition(10);
}
final SortOrder sortorder = getColumnSortOrder(table, column);
if (sortorder != null) {
switch(sortorder) {
case ASCENDING:
icon = (Icon) UIManager.get("Table.ascendingSortIcon");
break;
case DESCENDING:
icon = (Icon) UIManager.get("Table.descendingSortIcon");
break;
case UNSORTED:
icon = (Icon) UIManager.get("Table.naturalSortIcon");
break;
}
}
}
}
final String text = DataTypes.toString(value);
setText(text);
setIcon(icon);
this.sortArrow = icon;
Border border = null;
if (hasFocus) {
border = (Border) UIManager.get("TableHeader.focusCellBorder");
}
if (border == null) {
border = (Border) UIManager.get("TableHeader.cellBorder");
}
setBorder(border);
return this;
}
Aggregations