Skip to content

Commit

Permalink
Fix width of result table columns, add icons for view menu, modify file
Browse files Browse the repository at this point in the history
validation error message
  • Loading branch information
CarstenWickner committed Sep 14, 2015
1 parent f2cd52f commit 6b5fceb
Show file tree
Hide file tree
Showing 9 changed files with 75 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ public String getColumnName(final int columnIndex) {

@Override
public Class<?> getColumnClass(final int columnIndex) {
if (columnIndex < 2) {
if (columnIndex == 0) {
return String.class;
}
return Long.class;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,11 @@
import javax.swing.JTable;
import javax.swing.ListSelectionModel;
import javax.swing.SwingConstants;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.TableCellRenderer;
import javax.swing.table.TableColumn;
import javax.swing.table.TableModel;

import org.hmx.scitos.ais.core.i18n.AisMessage;
Expand All @@ -55,6 +58,8 @@ public final class PatternAnalysisPanel extends JPanel {

/** The alternate row color, for easier readability in the result tables. */
static final Color ALTERNATE_ROW_COLOR = new Color(239, 239, 239);
/** The minimum width of a single table column. */
private static final int MIN_COLUMN_WIDTH = 40;

/** The associated view project, containing the interviews the displayed results are extracted from. */
final PatternAnalysisModel model;
Expand All @@ -72,9 +77,9 @@ public PatternAnalysisPanel(final ScitosClient client, final AisViewProject proj
this.model = new PatternAnalysisModel(project);
this.setBorder(null);
final JTabbedPane tabStack = new JTabbedPane(SwingConstants.TOP, JTabbedPane.WRAP_TAB_LAYOUT);
tabStack.add(AisMessage.ANALYSIS_SUMMARY.get(), this.createTableFromModel(this.model.getSummaryTableModel()));
tabStack.add(AisMessage.ANALYSIS_SEQUENCE.get(), this.createTableFromModel(this.model.getSequenceTableModel()));
tabStack.add(AisMessage.ANALYSIS_PATTERN.get(), this.createTableFromModel(this.model.getPatternTableModel()));
tabStack.add(AisMessage.ANALYSIS_SUMMARY.get(), this.createTableFromModel(this.model.getSummaryTableModel(), true));
tabStack.add(AisMessage.ANALYSIS_SEQUENCE.get(), this.createTableFromModel(this.model.getSequenceTableModel(), false));
tabStack.add(AisMessage.ANALYSIS_PATTERN.get(), this.createTableFromModel(this.model.getPatternTableModel(), true));
this.add(tabStack);
this.addHierarchyListener(new HierarchyListener() {

Expand Down Expand Up @@ -117,9 +122,11 @@ void refresh() {
*
* @param tableModel
* table model to display
* @param sortable
* if the columns should be sortable
* @return scrollable table taking up the whole view
*/
private JScrollPane createTableFromModel(final TableModel tableModel) {
private JScrollPane createTableFromModel(final TableModel tableModel, final boolean sortable) {
final JTable tableView = new JTable(tableModel) {

@Override
Expand All @@ -138,16 +145,31 @@ public void updateUI() {
final Font contentFont = UIManager.getFont("Table.font");
if (contentFont != null) {
this.setFont(new Font(contentFont.getAttributes()).deriveFont(contentFont.getSize2D() * scaleFactor));
this.setRowHeight(2 + Math.round(this.getFont().getSize2D() * scaleFactor));
this.setRowHeight(this.getRowMargin() + (int) Math.ceil(this.getFont().getSize2D() * scaleFactor));
}
PatternAnalysisPanel.this.adjustColumns(this);
}

@Override
public void createDefaultColumnsFromModel() {
super.createDefaultColumnsFromModel();
final JTable self = this;
SwingUtilities.invokeLater(new Runnable() {

@Override
public void run() {
PatternAnalysisPanel.this.adjustColumns(self);
}
});
}
};
tableView.setBorder(null);
tableView.setAutoCreateColumnsFromModel(true);
tableView.setAutoCreateRowSorter(true);
tableView.setAutoCreateRowSorter(sortable);
tableView.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
tableView.setRowSelectionAllowed(true);
tableView.setColumnSelectionAllowed(false);
tableView.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
tableView.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
final AlternateRowRenderer cellRenderer = new AlternateRowRenderer();
tableView.setDefaultRenderer(String.class, cellRenderer);
tableView.setDefaultRenderer(Long.class, cellRenderer);
Expand All @@ -157,6 +179,34 @@ public void updateUI() {
return scrollableTable;
}

/**
* Adjust the widths of all columns of the given table to fit the respective column's header and contents.
*
* @param table
* the table to adjust the columns for
*/
void adjustColumns(final JTable table) {
final int columnCount = table.getColumnCount();
final int rowCount = table.getRowCount();
for (int columnIndex = 0; columnIndex < columnCount; columnIndex++) {
final TableColumn column = table.getColumnModel().getColumn(columnIndex);
TableCellRenderer headerRenderer = column.getHeaderRenderer();
if (headerRenderer == null) {
headerRenderer = table.getTableHeader().getDefaultRenderer();
}
final Object headerValue = column.getHeaderValue();
final Component headerCell = headerRenderer.getTableCellRendererComponent(table, headerValue, false, false, -1, columnIndex);
int columnWidth = headerCell.getPreferredSize().width;
for (int rowIndex = 0; rowIndex < rowCount; rowIndex++) {
final TableCellRenderer cellRenderer = table.getCellRenderer(rowIndex, columnIndex);
columnWidth = Math.max(columnWidth, table.prepareRenderer(cellRenderer, rowIndex, columnIndex).getPreferredSize().width);
}
final int preferredWidth = Math.max(PatternAnalysisPanel.MIN_COLUMN_WIDTH, columnWidth) + 4 + 2 * table.getIntercellSpacing().width;
column.setMaxWidth(preferredWidth + PatternAnalysisPanel.MIN_COLUMN_WIDTH / 2);
column.setPreferredWidth(preferredWidth);
}
}

/** Cell renderer to apply alternating row background color in order to improve the table's readability. */
private static final class AlternateRowRenderer extends DefaultTableCellRenderer {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@

It might belong to a newer version. Please check if there is a newer version available.</entry>
<entry key="Client.MenuBar.File.Save">Save</entry>
<entry key="Client.MenuBar.File.Save.Failed">The produced File could not be validated and might be corrupted.</entry>
<entry key="Client.MenuBar.File.Save.Failed">The produced File could not be validated.
Please try to save it again (possibly at another Location?) or
Open the File in a Web Browser (e.g. Firefox) and compare it yourself.</entry>
<entry key="Client.MenuBar.File.SaveAs">Save As...</entry>
<entry key="Client.MenuBar.File.Types.AIS">AIS Project</entry>
<entry key="Client.MenuBar.Preferences">Preferences</entry>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Lade gegebenenfalls die aktuelle Version von SciToS herunter.</entry>
<entry key="Client.MenuBar.File.Save">Speichern</entry>
<entry key="Client.MenuBar.File.Save.Failed">Die gespeicherte Datei konnte nicht vollständig validiert werden.
Bitte versuche noch einmal es zu speichern (ggf. an einem anderen Ort?) oder
öffne die Datei in einem (modernen) Web Browser und kontrolliere es selbst.</entry>
öffne die Datei in einem Web Browser (z.B. Firefox) und vergleiche es selbst.</entry>
<entry key="Client.MenuBar.File.SaveAs">Speichern unter...</entry>
<entry key="Client.MenuBar.File.Types.AIS">AIS Projekt</entry>
<entry key="Client.MenuBar.Preferences">Einstellungen</entry>
Expand Down
12 changes: 9 additions & 3 deletions scitos.view/src/main/java/org/hmx/scitos/view/ScitosIcon.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,17 +63,23 @@ public enum ScitosIcon {
UNDO_EDIT("/icons/eclipse/undo_edit.png"),
/** Icon: redo entry in menu bar / tool bar. */
REDO_EDIT("/icons/eclipse/redo_edit.png"),
/** Icon: increase content (font) size entry in menu bar. */
ZOOM_IN("/icons/fatcow/magnifier_zoom_in.png"),
/** Icon: reduce content (font) size entry in menu bar. */
ZOOM_OUT("/icons/fatcow/magnifier_zoom_out.png"),
/** Icon: toggle icon for the main view's sidebar. */
SIDEBAR("/icons/fatcow/layouts_select_sidebar.png"),
/** Icon: vertical arrow pointing upwards for moving something up. */
ARROW_UP("/icons/eclipse/arrow_up.png"),
/** Icon: vertical arrow pointing downwards for moving something down. */
ARROW_DOWN("/icons/eclipse/arrow_down.png"),
/** Icon: config/preferences entry in menu bar. */
CONFIG("/icons/fatcow/cog.png"),
/** Icon: add entry e.g. in category tree table **/
/** Icon: add entry e.g. in category tree table. **/
ADD("/icons/fatcow/add.png"),
/** Icon: remove entry e.g. in category tree table **/
/** Icon: remove entry e.g. in category tree table. **/
DELETE("/icons/fatcow/cross.png"),
/** Icon: add entry e.g. in category tree table **/
/** Icon: model entry e.g. in category tree table. **/
CATEGORY("/icons/fatcow/clipboard_invoice.png");

/** Location of the represented icon in the classpath. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -341,9 +341,9 @@ public void actionPerformed(final ActionEvent event) {
*/
private JMenu createViewMenu() {
final JMenu viewMenu = new JMenu(Message.MENUBAR_VIEW.get());
final JMenuItem scaleUpFontItem = viewMenu.add(new JMenuItem(Message.MENUBAR_VIEW_FONT_SCALE_UP.get()));
final JMenuItem scaleUpFontItem = viewMenu.add(new JMenuItem(Message.MENUBAR_VIEW_FONT_SCALE_UP.get(), ScitosIcon.ZOOM_IN.create()));
scaleUpFontItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_P, ScitosClient.SHORTCUT_MASK | InputEvent.SHIFT_DOWN_MASK));
final JMenuItem scaleDownFontItem = viewMenu.add(new JMenuItem(Message.MENUBAR_VIEW_FONT_SCALE_DOWN.get()));
final JMenuItem scaleDownFontItem = viewMenu.add(new JMenuItem(Message.MENUBAR_VIEW_FONT_SCALE_DOWN.get(), ScitosIcon.ZOOM_OUT.create()));
scaleDownFontItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_M, ScitosClient.SHORTCUT_MASK | InputEvent.SHIFT_DOWN_MASK));
// allow the scaling only in the given range, with 10% change per step: 1.1^(-2 to +8)
final AtomicInteger range = new AtomicInteger(0);
Expand All @@ -365,7 +365,8 @@ public void actionPerformed(final ActionEvent event) {
ScitosClient.this.setContentScaleFactor((float) Math.pow(1.1, range.get()));
}
});
viewMenu.add(new JMenuItem(Message.MENUBAR_VIEW_TOGGLE_PROJECT_TREE.get())).addActionListener(new ActionListener() {
final JMenuItem toggleTreeItem = viewMenu.add(new JMenuItem(Message.MENUBAR_VIEW_TOGGLE_PROJECT_TREE.get(), ScitosIcon.SIDEBAR.create()));
toggleTreeItem.addActionListener(new ActionListener() {

@Override
public void actionPerformed(final ActionEvent event) {
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 6b5fceb

Please sign in to comment.