Skip to content

Commit

Permalink
Merge pull request #60 from marc-outins/issue_42
Browse files Browse the repository at this point in the history
Added field descriptions
  • Loading branch information
schuemie committed May 11, 2015
2 parents 128c23e + 564ea72 commit 8878f86
Show file tree
Hide file tree
Showing 7 changed files with 496 additions and 318 deletions.
130 changes: 113 additions & 17 deletions src/org/ohdsi/rabbitInAHat/DetailsPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import java.awt.BorderLayout;
import java.awt.CardLayout;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.GridLayout;
Expand All @@ -33,8 +34,12 @@
import javax.swing.JTable;
import javax.swing.JTextArea;
import javax.swing.UIManager;
import javax.swing.event.ChangeEvent;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.TableColumnModelEvent;
import javax.swing.event.TableColumnModelListener;
import javax.swing.event.TableModelEvent;
import javax.swing.event.TableModelListener;
import javax.swing.table.TableModel;
Expand All @@ -43,6 +48,7 @@
import org.ohdsi.rabbitInAHat.dataModel.ItemToItemMap;
import org.ohdsi.rabbitInAHat.dataModel.Table;
import org.ohdsi.utilities.StringUtilities;
import org.ohdsi.rabbitInAHat.dataModel.TableCellLongTextRenderer;

public class DetailsPanel extends JPanel implements DetailsListener {

Expand Down Expand Up @@ -80,6 +86,7 @@ public void showDetails(Object object) {
this.object = object;
if (object instanceof Table) {
tablePanel.showTable((Table) object);
tablePanel.updateRowHeights();
cardLayout.show(this, Table.class.getName());
} else if (object instanceof Field) {
fieldPanel.showField((Field) object);
Expand All @@ -101,8 +108,10 @@ private class TablePanel extends JPanel implements DocumentListener {
private Table table;
private JLabel nameLabel = new JLabel("");
private JLabel rowCountLabel = new JLabel("");
private SimpleTableModel fieldTable = new SimpleTableModel("Field", "Type");
private SimpleTableModel fieldTable = new SimpleTableModel("Field", "Type","Description");
private JTextArea commentsArea = new JTextArea();
private JTable displayTable = new JTable(fieldTable);


public TablePanel() {
setLayout(new BorderLayout());
Expand All @@ -118,13 +127,54 @@ public TablePanel() {
generalInfoPanel.add(rowCountLabel);
add(generalInfoPanel, BorderLayout.NORTH);

JTable table = new JTable(fieldTable);
JScrollPane fieldListPanel = new JScrollPane(table);
table.setFont(font);
table.setRowHeight(24);

JScrollPane fieldListPanel = new JScrollPane(displayTable);

// Updates row heights when column widths change
displayTable.getColumnModel().addColumnModelListener(new TableColumnModelListener(){

@Override
public void columnMarginChanged(ChangeEvent e) {
updateRowHeights();

}

@Override
public void columnMoved(TableColumnModelEvent e){

}

@Override
public void columnAdded(TableColumnModelEvent e) {
// TODO Auto-generated method stub

}

@Override
public void columnRemoved(TableColumnModelEvent e) {
// TODO Auto-generated method stub

}



@Override
public void columnSelectionChanged(ListSelectionEvent e) {
// TODO Auto-generated method stub

}
});

displayTable.setFont(font);

// Set cell renderer that wraps content
for (int c = 0; c < displayTable.getColumnCount(); c++){
displayTable.getColumnModel().getColumn(c).setCellRenderer(new TableCellLongTextRenderer());
}

fieldListPanel.setBorder(BorderFactory.createTitledBorder("Fields"));
add(fieldListPanel, BorderLayout.CENTER);

// JScrollPane commentsPanel = new JScrollPane(commentsArea);
// commentsArea.setFont(font);
// commentsArea.getDocument().addDocumentListener(this);
Expand All @@ -136,16 +186,40 @@ public TablePanel() {
// add(commentsPanel, BorderLayout.SOUTH);

}


private void updateRowHeights() {

/*
* Auto adjust the height of rows in a JTable.
* The only way to know the row height for sure is to render each cell
* to determine the rendered height. After your table is populated with
* data you can do:
*
*/
for (int row = 0; row < displayTable.getRowCount(); row++) {
int rowHeight = displayTable.getRowHeight();
for (int column = 0; column < displayTable.getColumnCount(); column++)
{
Component comp = displayTable.prepareRenderer(displayTable.getCellRenderer(row, column), row, column);

rowHeight = Math.max(rowHeight, comp.getPreferredSize().height);

}
displayTable.setRowHeight(row, rowHeight);
}
}

public void showTable(Table table) {
this.table = table;
nameLabel.setText(table.getName());
DecimalFormat formatter = new DecimalFormat("#,###");
rowCountLabel.setText(formatter.format(table.getRowCount()));
fieldTable.clear();
fieldTable.clear();

for (Field field : table.getFields()){
fieldTable.add(field.outputName(), field.getType());
fieldTable.add(field.outputName(), field.getType(),field.getDescription());
}

commentsArea.setText(table.getComment());
}

Expand All @@ -170,6 +244,7 @@ private class FieldPanel extends JPanel implements DocumentListener {
private static final long serialVersionUID = -4393026616049677944L;
private JLabel nameLabel = new JLabel("");
private JLabel rowCountLabel = new JLabel("");
private RiaH_JTextArea description = new RiaH_JTextArea ("");
private SimpleTableModel valueTable = new SimpleTableModel("Value", "Frequency", "Percent of Total (%)");
private JTextArea commentsArea = new JTextArea();
private Field field;
Expand All @@ -178,15 +253,29 @@ public FieldPanel() {
setLayout(new BorderLayout());

JPanel generalInfoPanel = new JPanel();
generalInfoPanel.setLayout(new GridLayout(0, 2));

generalInfoPanel.setLayout(new BorderLayout(5,5));

generalInfoPanel.setBorder(BorderFactory.createTitledBorder("General information"));

generalInfoPanel.add(new JLabel("Field name: "));
generalInfoPanel.add(nameLabel);

generalInfoPanel.add(new JLabel("Field type: "));
generalInfoPanel.add(rowCountLabel);


JPanel fieldInfo = new JPanel();
fieldInfo.setLayout(new GridLayout(0,2));

fieldInfo.add(new JLabel("Field name: "));
fieldInfo.add(nameLabel);

fieldInfo.add(new JLabel("Field type: "));
fieldInfo.add(rowCountLabel);

generalInfoPanel.add(fieldInfo,BorderLayout.NORTH);

JPanel descriptionInfo = new JPanel();
descriptionInfo.setLayout(new GridLayout(0,2));
descriptionInfo.add(new JLabel("Description: "));
descriptionInfo.add(description);

generalInfoPanel.add(descriptionInfo,BorderLayout.SOUTH);

add(generalInfoPanel, BorderLayout.NORTH);

JTable table = new JTable(valueTable);
Expand All @@ -210,9 +299,16 @@ public FieldPanel() {

public void showField(Field field) {
this.field = field;

nameLabel.setText(field.getName());
rowCountLabel.setText(field.getType());
description.setText(field.getDescription());

// Hide description if it's empty
description.getParent().setVisible(!description.getText().isEmpty());

valueTable.clear();

if (field.getValueCounts() != null) {
double valueCountTotal = 0.0;
for (String[] total : field.getValueCounts()) {
Expand Down
7 changes: 5 additions & 2 deletions src/org/ohdsi/rabbitInAHat/MappingPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -206,10 +206,13 @@ public void setSize(int width, int height) {
public void paint(Graphics g) {
Image offscreen = createVolatileImage(getWidth(), getHeight());
Graphics2D g2d;
if (offscreen == null)

if (offscreen == null){
g2d = (Graphics2D) g;
else
}else{
g2d = (Graphics2D) offscreen.getGraphics();
}

g2d.setBackground(Color.WHITE);
g2d.clearRect(0, 0, getWidth(), getHeight());

Expand Down
26 changes: 26 additions & 0 deletions src/org/ohdsi/rabbitInAHat/RiaH_JTextArea.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package org.ohdsi.rabbitInAHat;

import javax.swing.JTextArea;
import javax.swing.UIManager;

public class RiaH_JTextArea extends JTextArea {
/**
*
*/
private static final long serialVersionUID = -3065135241375027552L;

public RiaH_JTextArea(String text){
super(text);

setWrapStyleWord(true);
setLineWrap(true);
setOpaque(false);
setEditable(false);
setFocusable(false);
setBackground(UIManager.getColor("Label.background"));
setFont(UIManager.getFont("Label.font"));
setBorder(UIManager.getBorder("Label.border"));
}


}
Loading

0 comments on commit 8878f86

Please sign in to comment.