Search in sources :

Example 1 with AlarmTableColumn

use of alma.acsplugins.alarmsystem.gui.table.AlarmTableModel.AlarmTableColumn in project ACS by ACS-Community.

the class AlarmTable method initGUI.

/**
	 * Init the GUI
	 */
private void initGUI() {
    setShowHorizontalLines(true);
    // Build and set the selection model
    selectionModel = new DefaultListSelectionModel();
    selectionModel.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    setSelectionModel(selectionModel);
    this.setOpaque(false);
    sorter = new TableRowSorter<AlarmTableModel>(model);
    this.setRowSorter(sorter);
    sorter.setMaxSortKeys(2);
    sorter.setSortsOnUpdates(true);
    // Initially sort by timestamp
    List<RowSorter.SortKey> sortKeys = new ArrayList<RowSorter.SortKey>();
    sortKeys.add(new RowSorter.SortKey(AlarmTableColumn.PRIORITY.ordinal(), SortOrder.ASCENDING));
    sortKeys.add(new RowSorter.SortKey(AlarmTableColumn.TIME.ordinal(), SortOrder.DESCENDING));
    sorter.setSortKeys(sortKeys);
    // Remove all the columns not visible at startup
    TableColumnModel colModel = getColumnModel();
    columns = new TableColumn[colModel.getColumnCount()];
    for (int t = 0; t < columns.length; t++) {
        columns[t] = colModel.getColumn(t);
        columns[t].setIdentifier(AlarmTableColumn.values()[t]);
        if (columns[t].getIdentifier() == AlarmTableColumn.ICON || columns[t].getIdentifier() == AlarmTableColumn.IS_CHILD || columns[t].getIdentifier() == AlarmTableColumn.IS_PARENT) {
            columns[t].setWidth(20);
            columns[t].setResizable(false);
            columns[t].setPreferredWidth(20);
            columns[t].setMaxWidth(20);
            columns[t].setMinWidth(20);
        } else if (columns[t].getIdentifier() == AlarmTableColumn.PRIORITY) {
            BufferedImage bImg = new BufferedImage(100, 100, BufferedImage.TYPE_INT_RGB);
            Graphics2D g2D = bImg.createGraphics();
            FontMetrics fm = g2D.getFontMetrics();
            int sz = fm.stringWidth(PriorityLabel.VERY_HIGH.description);
            columns[t].setPreferredWidth(sz + 6);
            columns[t].setMaxWidth(sz + 8);
        }
    }
    for (AlarmTableColumn col : AlarmTableColumn.values()) {
        if (!col.visibleAtStartup) {
            colModel.removeColumn(columns[col.ordinal()]);
        }
    }
    buildPopupMenu();
    addMouseListener(mouseAdapter);
    getTableHeader().addMouseListener(new AlarmHeaderMouseAdapter());
    // Set the tooltip
    ToolTipManager ttm = ToolTipManager.sharedInstance();
    ttm.setDismissDelay(Integer.MAX_VALUE);
    ttm.setLightWeightPopupEnabled(true);
}
Also used : UndocAlarmTableModel(alma.acsplugins.alarmsystem.gui.undocumented.table.UndocAlarmTableModel) RowSorter(javax.swing.RowSorter) TableRowSorter(javax.swing.table.TableRowSorter) ToolTipManager(javax.swing.ToolTipManager) ArrayList(java.util.ArrayList) TableColumnModel(javax.swing.table.TableColumnModel) DefaultListSelectionModel(javax.swing.DefaultListSelectionModel) Point(java.awt.Point) BufferedImage(java.awt.image.BufferedImage) Graphics2D(java.awt.Graphics2D) FontMetrics(java.awt.FontMetrics) AlarmTableColumn(alma.acsplugins.alarmsystem.gui.table.AlarmTableModel.AlarmTableColumn)

Aggregations

AlarmTableColumn (alma.acsplugins.alarmsystem.gui.table.AlarmTableModel.AlarmTableColumn)1 UndocAlarmTableModel (alma.acsplugins.alarmsystem.gui.undocumented.table.UndocAlarmTableModel)1 FontMetrics (java.awt.FontMetrics)1 Graphics2D (java.awt.Graphics2D)1 Point (java.awt.Point)1 BufferedImage (java.awt.image.BufferedImage)1 ArrayList (java.util.ArrayList)1 DefaultListSelectionModel (javax.swing.DefaultListSelectionModel)1 RowSorter (javax.swing.RowSorter)1 ToolTipManager (javax.swing.ToolTipManager)1 TableColumnModel (javax.swing.table.TableColumnModel)1 TableRowSorter (javax.swing.table.TableRowSorter)1