Search in sources :

Example 6 with TableRowSorter

use of javax.swing.table.TableRowSorter 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)

Example 7 with TableRowSorter

use of javax.swing.table.TableRowSorter in project EnrichmentMapApp by BaderLab.

the class HeatMapMainPanel method createTableHeader.

private void createTableHeader(int expressionColumnWidth) {
    JTableHeader header = table.getTableHeader();
    header.setReorderingAllowed(false);
    HeatMapTableModel tableModel = (HeatMapTableModel) table.getModel();
    TableColumnModel columnModel = table.getColumnModel();
    TableCellRenderer vertRenderer = new ColumnHeaderVerticalRenderer();
    TableCellRenderer vertRendererPheno1 = new ColumnHeaderVerticalRenderer(EMStyleBuilder.Colors.LIGHTEST_PHENOTYPE_1);
    TableCellRenderer vertRendererPheno2 = new ColumnHeaderVerticalRenderer(EMStyleBuilder.Colors.LIGHTEST_PHENOTYPE_2);
    TableColumn rankColumn = columnModel.getColumn(HeatMapTableModel.RANK_COL);
    rankColumn.setHeaderRenderer(columnHeaderRankOptionRendererFactory.create(this, HeatMapTableModel.RANK_COL));
    rankColumn.setPreferredWidth(100);
    ((TableRowSorter<?>) table.getRowSorter()).setSortable(HeatMapTableModel.RANK_COL, false);
    int colCount = tableModel.getColumnCount();
    for (int col = HeatMapTableModel.DESC_COL_COUNT; col < colCount; col++) {
        EMDataSet dataset = tableModel.getDataSet(col);
        String pheno1 = dataset.getEnrichments().getPhenotype1();
        String pheno2 = dataset.getEnrichments().getPhenotype2();
        Optional<String> pheno = tableModel.getPhenotype(col);
        TableCellRenderer renderer;
        if (pheno.filter(p -> p.equals(pheno1)).isPresent())
            renderer = vertRendererPheno1;
        else if (pheno.filter(p -> p.equals(pheno2)).isPresent())
            renderer = vertRendererPheno2;
        else
            renderer = vertRenderer;
        TableColumn column = columnModel.getColumn(col);
        column.setHeaderRenderer(renderer);
        column.setPreferredWidth(expressionColumnWidth);
    }
}
Also used : Arrays(java.util.Arrays) Inject(com.google.inject.Inject) AfterInjection(org.baderlab.csplugins.enrichmentmap.AfterInjection) HeatMapTableModel(org.baderlab.csplugins.enrichmentmap.view.heatmap.table.HeatMapTableModel) Operator(org.baderlab.csplugins.enrichmentmap.view.heatmap.HeatMapParams.Operator) JTableHeader(javax.swing.table.JTableHeader) TableCellRenderer(javax.swing.table.TableCellRenderer) IconManager(org.cytoscape.util.swing.IconManager) Assisted(com.google.inject.assistedinject.Assisted) ComboItem(org.baderlab.csplugins.enrichmentmap.view.util.ComboItem) Map(java.util.Map) BorderLayout(java.awt.BorderLayout) JComboBox(javax.swing.JComboBox) DEFAULT_SIZE(javax.swing.GroupLayout.DEFAULT_SIZE) Set(java.util.Set) ColorAndValueRenderer(org.baderlab.csplugins.enrichmentmap.view.heatmap.table.ColorAndValueRenderer) Distance(org.baderlab.csplugins.enrichmentmap.view.heatmap.HeatMapParams.Distance) Component(java.awt.Component) Collectors(java.util.stream.Collectors) TableRowSorter(javax.swing.table.TableRowSorter) Sets(com.google.common.collect.Sets) PREFERRED_SIZE(javax.swing.GroupLayout.PREFERRED_SIZE) List(java.util.List) Alignment(javax.swing.GroupLayout.Alignment) EMDataSet(org.baderlab.csplugins.enrichmentmap.model.EMDataSet) LookAndFeelUtil(org.cytoscape.util.swing.LookAndFeelUtil) SwingUtil(org.baderlab.csplugins.enrichmentmap.view.util.SwingUtil) ColumnHeaderRankOptionRenderer(org.baderlab.csplugins.enrichmentmap.view.heatmap.table.ColumnHeaderRankOptionRenderer) JCheckBox(javax.swing.JCheckBox) Optional(java.util.Optional) JTable(javax.swing.JTable) ColumnHeaderVerticalRenderer(org.baderlab.csplugins.enrichmentmap.view.heatmap.table.ColumnHeaderVerticalRenderer) RankValue(org.baderlab.csplugins.enrichmentmap.view.heatmap.table.RankValue) JPanel(javax.swing.JPanel) ListSelectionModel(javax.swing.ListSelectionModel) ActionListener(java.awt.event.ActionListener) TableColumnModel(javax.swing.table.TableColumnModel) SortKey(javax.swing.RowSorter.SortKey) EnrichmentMap(org.baderlab.csplugins.enrichmentmap.model.EnrichmentMap) CompletableFuture(java.util.concurrent.CompletableFuture) GradientLegendPanel(org.baderlab.csplugins.enrichmentmap.view.heatmap.table.GradientLegendPanel) ArrayList(java.util.ArrayList) SwingUtilities(javax.swing.SwingUtilities) EMStyleBuilder(org.baderlab.csplugins.enrichmentmap.style.EMStyleBuilder) JButton(javax.swing.JButton) Transform(org.baderlab.csplugins.enrichmentmap.view.heatmap.HeatMapParams.Transform) TableColumn(javax.swing.table.TableColumn) JPopupMenu(javax.swing.JPopupMenu) ActionEvent(java.awt.event.ActionEvent) RankOptionErrorHeader(org.baderlab.csplugins.enrichmentmap.view.heatmap.table.RankOptionErrorHeader) RankValueRenderer(org.baderlab.csplugins.enrichmentmap.view.heatmap.table.RankValueRenderer) JScrollPane(javax.swing.JScrollPane) JLabel(javax.swing.JLabel) GroupLayout(javax.swing.GroupLayout) ColorRenderer(org.baderlab.csplugins.enrichmentmap.view.heatmap.table.ColorRenderer) Comparator(java.util.Comparator) TableCellRenderer(javax.swing.table.TableCellRenderer) HeatMapTableModel(org.baderlab.csplugins.enrichmentmap.view.heatmap.table.HeatMapTableModel) JTableHeader(javax.swing.table.JTableHeader) TableColumnModel(javax.swing.table.TableColumnModel) EMDataSet(org.baderlab.csplugins.enrichmentmap.model.EMDataSet) ColumnHeaderVerticalRenderer(org.baderlab.csplugins.enrichmentmap.view.heatmap.table.ColumnHeaderVerticalRenderer) TableColumn(javax.swing.table.TableColumn) TableRowSorter(javax.swing.table.TableRowSorter)

Example 8 with TableRowSorter

use of javax.swing.table.TableRowSorter in project JMRI by JMRI.

the class SignalGroupSubTableAction method editHead.

/**
     * Open an editor to set the details of a Signal Head as part of a Signal Group.
     * Called when user clicks the Edit button for a Head in the Add/Edit Signal Group pane.
     * @see SignalGroupTableAction#signalHeadEditPressed(int) SignalGroupTableAction.signalHeadEditPressed
     * @param g Parent Signal Head
     * @param headName System or User Name of this Signal Head
     */
void editHead(SignalGroup g, String headName) {
    curSignalGroup = g;
    curHeadName = headName;
    curSignalHead = jmri.InstanceManager.getDefault(jmri.SignalHeadManager.class).getSignalHead(curHeadName);
    // shows i18n strings from signal head definition
    _OnAppearance = new JComboBox<String>(curSignalHead.getValidStateNames());
    _OffAppearance = new JComboBox<String>(curSignalHead.getValidStateNames());
    _systemName = new JLabel(headName);
    _systemName.setVisible(true);
    jmri.TurnoutManager tm = InstanceManager.turnoutManagerInstance();
    List<String> systemNameList = tm.getSystemNameList();
    _turnoutList = new ArrayList<SignalGroupTurnout>(systemNameList.size());
    Iterator<String> iter = systemNameList.iterator();
    while (iter.hasNext()) {
        String systemName = iter.next();
        String userName = tm.getBySystemName(systemName).getUserName();
        _turnoutList.add(new SignalGroupTurnout(systemName, userName));
    }
    jmri.SensorManager sm = InstanceManager.sensorManagerInstance();
    systemNameList = sm.getSystemNameList();
    _sensorList = new ArrayList<SignalGroupSensor>(systemNameList.size());
    iter = systemNameList.iterator();
    while (iter.hasNext()) {
        String systemName = iter.next();
        Sensor sen = sm.getBySystemName(systemName);
        if (sen != null) {
            String userName = sen.getUserName();
            _sensorList.add(new SignalGroupSensor(systemName, userName));
        }
    }
    initializeIncludedList();
    // Set up sub panel for editing of a Signal Group Signal Head item
    if (addSubFrame == null) {
        // create one if not yet available
        addSubFrame = new JmriJFrame((Bundle.getMessage("EditSignalGroup") + " - " + Bundle.getMessage("BeanNameSignalHead")), false, true);
        addSubFrame.addHelpMenu("package.jmri.jmrit.beantable.SignalGroupAddEdit", true);
        addSubFrame.setLocation(100, 30);
        addSubFrame.getContentPane().setLayout(new BoxLayout(addSubFrame.getContentPane(), BoxLayout.Y_AXIS));
        Container contentPane = addSubFrame.getContentPane();
        // add system name label
        JPanel ps = new JPanel();
        ps.setLayout(new FlowLayout());
        ps.add(nameLabel);
        ps.add(_systemName);
        contentPane.add(ps);
        // add user name label
        JPanel pc = new JPanel();
        pc.setLayout(new FlowLayout());
        pc.add(signalOnStateLabel);
        // comboBox to set On Appearance
        pc.add(_OnAppearance);
        _OnAppearance.setToolTipText(Bundle.getMessage("StateWhenMetTooltip"));
        pc.add(spacer);
        pc.add(signalOffStateLabel);
        // comboBox to set On Appearance
        pc.add(_OffAppearance);
        _OffAppearance.setToolTipText(Bundle.getMessage("StateWhenNotMetTooltip"));
        contentPane.add(pc);
        JPanel p = new JPanel();
        p.setLayout(new FlowLayout());
        p.add(userLabel);
        contentPane.add(p);
        // fill in info for the Signal Head being configured
        if (curSignalHead.getClass().getName().contains("SingleTurnoutSignalHead")) {
            jmri.implementation.SingleTurnoutSignalHead stsh = (jmri.implementation.SingleTurnoutSignalHead) InstanceManager.getDefault(jmri.SignalHeadManager.class).getByUserName(curHeadName);
            // we may use a user name in the editing pane, so look for that first
            if (stsh == null) {
                stsh = (jmri.implementation.SingleTurnoutSignalHead) InstanceManager.getDefault(jmri.SignalHeadManager.class).getBySystemName(curHeadName);
            // when user name is empty, get by user name
            }
            if (stsh != null) {
                log.debug("SGsubTA #279 editHead: setting props for signal head {}", curHeadName);
                if ((g.getHeadOnState(curSignalHead) == 0x00) && (g.getHeadOffState(curSignalHead) == 0x00)) {
                    g.setHeadOnState(curSignalHead, stsh.getOnAppearance());
                    g.setHeadOffState(curSignalHead, stsh.getOffAppearance());
                }
            } else {
                // nothing found
                log.error("Failed to get signal head object named {}", curHeadName);
            }
        }
        setSignalHeadStateBox(g.getHeadOnState(curSignalHead), _OnAppearance);
        setSignalHeadStateBox(g.getHeadOffState(curSignalHead), _OffAppearance);
        // add Turnout Display Choice
        JPanel py = new JPanel();
        py.add(new JLabel(Bundle.getMessage("Show")));
        selGroup = new ButtonGroup();
        allButton = new JRadioButton(Bundle.getMessage("All"), true);
        selGroup.add(allButton);
        py.add(allButton);
        allButton.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                // Setup for display of all Turnouts, if needed
                if (!showAll) {
                    showAll = true;
                    _SignalGroupTurnoutModel.fireTableDataChanged();
                    _SignalGroupSensorModel.fireTableDataChanged();
                }
            }
        });
        includedButton = new JRadioButton(Bundle.getMessage("Included"), false);
        selGroup.add(includedButton);
        py.add(includedButton);
        includedButton.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                // Setup for display of included Turnouts only, if needed
                if (showAll) {
                    showAll = false;
                    initializeIncludedList();
                    _SignalGroupTurnoutModel.fireTableDataChanged();
                    _SignalGroupSensorModel.fireTableDataChanged();
                }
            }
        });
        py.add(new JLabel("  " + Bundle.getMessage("_and_", Bundle.getMessage("Turnouts"), Bundle.getMessage("Sensors"))));
        contentPane.add(py);
        // add turnout table
        p2xt = new JPanel();
        JPanel p2xtSpace = new JPanel();
        p2xtSpace.setLayout(new BoxLayout(p2xtSpace, BoxLayout.Y_AXIS));
        p2xtSpace.add(new JLabel("XXX"));
        p2xt.add(p2xtSpace);
        JPanel p21t = new JPanel();
        p21t.setLayout(new BoxLayout(p21t, BoxLayout.Y_AXIS));
        p21t.add(new JLabel(Bundle.getMessage("SelectInGroup", Bundle.getMessage("Turnouts"))));
        p2xt.add(p21t);
        _SignalGroupTurnoutModel = new SignalGroupTurnoutModel();
        JTable SignalGroupTurnoutTable = new JTable(_SignalGroupTurnoutModel);
        TableRowSorter<SignalGroupTurnoutModel> sgtSorter = new TableRowSorter<>(_SignalGroupTurnoutModel);
        sgtSorter.setComparator(SignalGroupTurnoutModel.SNAME_COLUMN, new SystemNameComparator());
        RowSorterUtil.setSortOrder(sgtSorter, SignalGroupTurnoutModel.SNAME_COLUMN, SortOrder.ASCENDING);
        SignalGroupTurnoutTable.setRowSorter(sgtSorter);
        SignalGroupTurnoutTable.setRowSelectionAllowed(false);
        SignalGroupTurnoutTable.setPreferredScrollableViewportSize(new java.awt.Dimension(480, 80));
        ROW_HEIGHT = SignalGroupTurnoutTable.getRowHeight();
        JComboBox<String> stateTCombo = new JComboBox<String>();
        stateTCombo.addItem(SET_TO_CLOSED);
        stateTCombo.addItem(SET_TO_THROWN);
        TableColumnModel SignalGroupTurnoutColumnModel = SignalGroupTurnoutTable.getColumnModel();
        TableColumn includeColumnT = SignalGroupTurnoutColumnModel.getColumn(SignalGroupTurnoutModel.INCLUDE_COLUMN);
        includeColumnT.setResizable(false);
        includeColumnT.setMinWidth(50);
        includeColumnT.setMaxWidth(60);
        TableColumn sNameColumnT = SignalGroupTurnoutColumnModel.getColumn(SignalGroupTurnoutModel.SNAME_COLUMN);
        sNameColumnT.setResizable(true);
        sNameColumnT.setMinWidth(75);
        sNameColumnT.setMaxWidth(95);
        TableColumn uNameColumnT = SignalGroupTurnoutColumnModel.getColumn(SignalGroupTurnoutModel.UNAME_COLUMN);
        uNameColumnT.setResizable(true);
        uNameColumnT.setMinWidth(210);
        uNameColumnT.setMaxWidth(260);
        TableColumn stateColumnT = SignalGroupTurnoutColumnModel.getColumn(SignalGroupTurnoutModel.STATE_COLUMN);
        stateColumnT.setCellEditor(new DefaultCellEditor(stateTCombo));
        stateColumnT.setResizable(false);
        stateColumnT.setMinWidth(90);
        stateColumnT.setMaxWidth(100);
        _SignalGroupTurnoutScrollPane = new JScrollPane(SignalGroupTurnoutTable);
        p2xt.add(_SignalGroupTurnoutScrollPane, BorderLayout.CENTER);
        contentPane.add(p2xt);
        p2xt.setVisible(true);
        JPanel po = new JPanel();
        po.setLayout(new FlowLayout());
        JLabel operLabel = new JLabel(Bundle.getMessage("ChooseOrAnd"));
        po.add(operLabel);
        po.add(_SensorTurnoutOper);
        contentPane.add(po);
        // add sensor table
        p2xs = new JPanel();
        JPanel p2xsSpace = new JPanel();
        p2xsSpace.setLayout(new BoxLayout(p2xsSpace, BoxLayout.Y_AXIS));
        p2xsSpace.add(new JLabel("XXX"));
        p2xs.add(p2xsSpace);
        JPanel p21s = new JPanel();
        p21s.setLayout(new BoxLayout(p21s, BoxLayout.Y_AXIS));
        p21s.add(new JLabel(Bundle.getMessage("SelectInGroup", Bundle.getMessage("Sensors"))));
        p2xs.add(p21s);
        _SignalGroupSensorModel = new SignalGroupSensorModel();
        JTable SignalGroupSensorTable = new JTable(_SignalGroupSensorModel);
        TableRowSorter<SignalGroupSensorModel> sgsSorter = new TableRowSorter<>(_SignalGroupSensorModel);
        sgsSorter.setComparator(SignalGroupSensorModel.SNAME_COLUMN, new SystemNameComparator());
        RowSorterUtil.setSortOrder(sgsSorter, SignalGroupSensorModel.SNAME_COLUMN, SortOrder.ASCENDING);
        SignalGroupSensorTable.setRowSorter(sgsSorter);
        SignalGroupSensorTable.setRowSelectionAllowed(false);
        SignalGroupSensorTable.setPreferredScrollableViewportSize(new java.awt.Dimension(480, 80));
        JComboBox<String> stateSCombo = new JComboBox<String>();
        stateSCombo.addItem(SET_TO_ACTIVE);
        stateSCombo.addItem(SET_TO_INACTIVE);
        TableColumnModel SignalGroupSensorColumnModel = SignalGroupSensorTable.getColumnModel();
        TableColumn includeColumnS = SignalGroupSensorColumnModel.getColumn(SignalGroupSensorModel.INCLUDE_COLUMN);
        includeColumnS.setResizable(false);
        includeColumnS.setMinWidth(50);
        includeColumnS.setMaxWidth(60);
        TableColumn sNameColumnS = SignalGroupSensorColumnModel.getColumn(SignalGroupSensorModel.SNAME_COLUMN);
        sNameColumnS.setResizable(true);
        sNameColumnS.setMinWidth(75);
        sNameColumnS.setMaxWidth(95);
        TableColumn uNameColumnS = SignalGroupSensorColumnModel.getColumn(SignalGroupSensorModel.UNAME_COLUMN);
        uNameColumnS.setResizable(true);
        uNameColumnS.setMinWidth(210);
        uNameColumnS.setMaxWidth(260);
        TableColumn stateColumnS = SignalGroupSensorColumnModel.getColumn(SignalGroupSensorModel.STATE_COLUMN);
        stateColumnS.setCellEditor(new DefaultCellEditor(stateSCombo));
        stateColumnS.setResizable(false);
        stateColumnS.setMinWidth(90);
        stateColumnS.setMaxWidth(100);
        _SignalGroupSensorScrollPane = new JScrollPane(SignalGroupSensorTable);
        p2xs.add(_SignalGroupSensorScrollPane, BorderLayout.CENTER);
        contentPane.add(p2xs);
        p2xs.setVisible(true);
        // add notes panel
        JPanel pa = new JPanel();
        pa.setLayout(new BoxLayout(pa, BoxLayout.Y_AXIS));
        JPanel p1 = new JPanel();
        p1.setLayout(new FlowLayout());
        p1.add(status1);
        pa.add(p1);
        Border pBorder = BorderFactory.createEtchedBorder();
        pa.setBorder(pBorder);
        contentPane.add(pa);
        // add buttons - Add SignalGroup button
        JPanel pb = new JPanel();
        pb.setLayout(new FlowLayout(FlowLayout.TRAILING));
        // add Cancel button
        pb.add(cancelButton);
        cancelButton.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                cancelSubPressed(e);
            }
        });
        // add Update SignalGroup button
        pb.add(updateSubButton);
        updateSubButton.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                updateSubPressed(e, false);
            }
        });
        updateSubButton.setToolTipText(Bundle.getMessage("TooltipUpdate"));
        p2xtSpace.setVisible(false);
        p2xsSpace.setVisible(false);
        updateSubButton.setVisible(true);
        contentPane.add(pb);
        addSubFrame.pack();
    }
    // set listener for window closing
    addSubFrame.addWindowListener(new java.awt.event.WindowAdapter() {

        @Override
        public void windowClosing(java.awt.event.WindowEvent e) {
            addSubFrame.setVisible(false);
            cancelSubEdit();
            _SignalGroupSensorModel.dispose();
            _SignalGroupTurnoutModel.dispose();
        }
    });
    addSubFrame.setVisible(true);
    // add AND/OR choice box
    setoperBox(curSignalGroup.getSensorTurnoutOper(curSignalHead), _SensorTurnoutOper);
    setSignalHeadStateBox(curSignalGroup.getHeadOnState(curSignalHead), _OnAppearance);
    setSignalHeadStateBox(curSignalGroup.getHeadOffState(curSignalHead), _OffAppearance);
    int setRow = 0;
    for (int i = _turnoutList.size() - 1; i >= 0; i--) {
        SignalGroupTurnout turnout = _turnoutList.get(i);
        Turnout tTurnout = turnout.getTurnout();
        if (curSignalGroup.isTurnoutIncluded(curSignalHead, tTurnout)) {
            turnout.setIncluded(true);
            turnout.setState(curSignalGroup.getTurnoutState(curSignalHead, tTurnout));
            setRow = i;
        } else {
            turnout.setIncluded(false);
            turnout.setState(Turnout.CLOSED);
        }
    }
    setRow -= 1;
    if (setRow < 0) {
        setRow = 0;
    }
    _SignalGroupTurnoutScrollPane.getVerticalScrollBar().setValue(setRow * ROW_HEIGHT);
    _SignalGroupTurnoutModel.fireTableDataChanged();
    for (int i = _sensorList.size() - 1; i >= 0; i--) {
        SignalGroupSensor sensor = _sensorList.get(i);
        Sensor tSensor = sensor.getSensor();
        if (curSignalGroup.isSensorIncluded(curSignalHead, tSensor)) {
            sensor.setIncluded(true);
            sensor.setState(curSignalGroup.getSensorState(curSignalHead, tSensor));
            setRow = i;
        } else {
            sensor.setIncluded(false);
            sensor.setState(Sensor.INACTIVE);
        }
    }
    status1.setText(updateInst);
    updateSubButton.setVisible(true);
}
Also used : JPanel(javax.swing.JPanel) FlowLayout(java.awt.FlowLayout) JRadioButton(javax.swing.JRadioButton) ActionEvent(java.awt.event.ActionEvent) BoxLayout(javax.swing.BoxLayout) TableColumnModel(javax.swing.table.TableColumnModel) Container(java.awt.Container) TableRowSorter(javax.swing.table.TableRowSorter) JScrollPane(javax.swing.JScrollPane) JComboBox(javax.swing.JComboBox) JLabel(javax.swing.JLabel) TableColumn(javax.swing.table.TableColumn) DefaultCellEditor(javax.swing.DefaultCellEditor) ActionListener(java.awt.event.ActionListener) JmriJFrame(jmri.util.JmriJFrame) ButtonGroup(javax.swing.ButtonGroup) JTable(javax.swing.JTable) SystemNameComparator(jmri.util.SystemNameComparator) Border(javax.swing.border.Border) Turnout(jmri.Turnout) Sensor(jmri.Sensor)

Example 9 with TableRowSorter

use of javax.swing.table.TableRowSorter in project JMRI by JMRI.

the class TableFrames method makeSignalFrame.

/*
     * ********************* SignalFrame *****************************
     */
protected JInternalFrame makeSignalFrame() {
    JInternalFrame frame = new JInternalFrame(Bundle.getMessage("TitleSignalTable"), true, false, false, true);
    _signalModel = new SignalTableModel(this);
    _signalModel.init();
    _signalTable = new JTable(_signalModel);
    TableRowSorter<SignalTableModel> sorter = new TableRowSorter<>(_signalModel);
    _signalTable.setRowSorter(sorter);
    _signalTable.setTransferHandler(new jmri.util.DnDTableImportExportHandler(new int[] { SignalTableModel.UNITSCOL, SignalTableModel.DELETE_COL }));
    _signalTable.setDragEnabled(true);
    _signalTable.getColumnModel().getColumn(SignalTableModel.UNITSCOL).setCellRenderer(new MyBooleanRenderer(Bundle.getMessage("cm"), Bundle.getMessage("in")));
    _signalTable.getColumnModel().getColumn(SignalTableModel.DELETE_COL).setCellEditor(new ButtonEditor(new JButton()));
    _signalTable.getColumnModel().getColumn(SignalTableModel.DELETE_COL).setCellRenderer(new ButtonRenderer());
    for (int i = 0; i < _signalModel.getColumnCount(); i++) {
        int width = SignalTableModel.getPreferredWidth(i);
        _signalTable.getColumnModel().getColumn(i).setPreferredWidth(width);
    }
    _signalTable.sizeColumnsToFit(-1);
    int tableWidth = _signalTable.getPreferredSize().width;
    _signalTable.setPreferredScrollableViewportSize(new java.awt.Dimension(tableWidth, ROW_HEIGHT * 8));
    _signalTablePane = new JScrollPane(_signalTable);
    JPanel contentPane = new JPanel();
    contentPane.setLayout(new BorderLayout(5, 5));
    JLabel prompt = new JLabel(Bundle.getMessage("AddSignalPrompt"));
    contentPane.add(prompt, BorderLayout.NORTH);
    contentPane.add(_signalTablePane, BorderLayout.CENTER);
    frame.setContentPane(contentPane);
    frame.setLocation(200, 350);
    frame.pack();
    return frame;
}
Also used : JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) ButtonEditor(jmri.util.table.ButtonEditor) JButton(javax.swing.JButton) JLabel(javax.swing.JLabel) Point(java.awt.Point) Dimension(java.awt.Dimension) BorderLayout(java.awt.BorderLayout) JTable(javax.swing.JTable) JInternalFrame(javax.swing.JInternalFrame) TableRowSorter(javax.swing.table.TableRowSorter) ButtonRenderer(jmri.util.table.ButtonRenderer)

Example 10 with TableRowSorter

use of javax.swing.table.TableRowSorter in project JMRI by JMRI.

the class OperationsPanel method loadTableDetails.

/**
     * Load the table width, position, and sorting status from the user
     * preferences file.
     *
     * @param table The table to be adjusted.
     * @return true if a default instance of the
     *         {@link jmri.swing.JTablePersistenceManager} is available; false
     *         otherwise
     */
public boolean loadTableDetails(JTable table) {
    if (table.getRowSorter() == null) {
        TableRowSorter<? extends TableModel> sorter = new TableRowSorter<>(table.getModel());
        table.setRowSorter(sorter);
        // only sort on columns that are String or Integer
        for (int i = 0; i < table.getColumnCount(); i++) {
            if (table.getColumnClass(i) == String.class || table.getColumnClass(i) == Integer.class) {
                // allow sorting
                continue;
            }
            sorter.setSortable(i, false);
        }
    }
    // set row height
    table.setRowHeight(new JComboBox<>().getPreferredSize().height);
    // have to shut off autoResizeMode to get horizontal scroll to work (JavaSwing p 541)
    table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
    // give each cell a bit of space between the vertical lines and text
    table.setIntercellSpacing(new Dimension(3, 1));
    // table must have a name
    // NOI18N
    table.setName(getWindowFrameRef() + ":table");
    Optional<JTablePersistenceManager> manager = InstanceManager.getOptionalDefault(JTablePersistenceManager.class);
    if (manager.isPresent()) {
        manager.get().resetState(table);
        manager.get().persist(table);
        return true;
    }
    return false;
}
Also used : Dimension(java.awt.Dimension) JTablePersistenceManager(jmri.swing.JTablePersistenceManager) TableRowSorter(javax.swing.table.TableRowSorter)

Aggregations

TableRowSorter (javax.swing.table.TableRowSorter)32 JTable (javax.swing.JTable)23 JScrollPane (javax.swing.JScrollPane)22 JPanel (javax.swing.JPanel)17 JLabel (javax.swing.JLabel)15 BoxLayout (javax.swing.BoxLayout)13 JButton (javax.swing.JButton)13 TableColumnModel (javax.swing.table.TableColumnModel)10 Dimension (java.awt.Dimension)9 ActionEvent (java.awt.event.ActionEvent)9 SystemNameComparator (jmri.util.SystemNameComparator)9 ActionListener (java.awt.event.ActionListener)8 TableColumn (javax.swing.table.TableColumn)8 TableModel (javax.swing.table.TableModel)7 ButtonEditor (jmri.util.table.ButtonEditor)6 ButtonRenderer (jmri.util.table.ButtonRenderer)6 BorderLayout (java.awt.BorderLayout)5 FlowLayout (java.awt.FlowLayout)5 Point (java.awt.Point)5 JComboBox (javax.swing.JComboBox)5