All Downloads are FREE. Search and download functionalities are using the official Maven repository.

cdc.perfs.ui.swing.SourcesPanel Maven / Gradle / Ivy

There is a newer version: 0.52.0
Show newest version
package cdc.perfs.ui.swing;

import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;

import javax.swing.Icon;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.ListSelectionModel;

import cdc.perfs.api.MeasureLevel;
import cdc.ui.swing.SwingUtil;
import cdc.ui.swing.cells.EnumUi;

/**
 * Panel dedicated to Sources related controls.
 *
 * @author Damien Carbonne
 *
 */
class SourcesPanel extends JPanel {
    private static final long serialVersionUID = 1L;
    private final JTable wTable;

    public SourcesPanel(SourcesTableModel model) {
        setLayout(new GridBagLayout());

        final JScrollPane wScrollPane = new JScrollPane();
        {
            final GridBagConstraints gbc = new GridBagConstraints();
            gbc.insets = new Insets(0, 0, 0, 0);
            gbc.fill = GridBagConstraints.BOTH;
            gbc.gridx = 0;
            gbc.gridy = 1;
            gbc.weightx = 1.0;
            gbc.weighty = 1.0;
            add(wScrollPane, gbc);
        }

        wTable = new JTable();

        wScrollPane.setViewportView(wTable);

        wTable.setModel(model);
        wTable.getColumnModel().getColumn(0).setPreferredWidth(100);
        wTable.getColumnModel().getColumn(1).setPreferredWidth(50);
        wTable.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN);
        wTable.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

        final EnumUi.Settings settings = new EnumUi.Settings() {
            final Icon info = SwingUtil.loadIcon("cdc/perfs/images/cdc-perfs-level-info.png");
            final Icon major = SwingUtil.loadIcon("cdc/perfs/images/cdc-perfs-level-major.png");
            final Icon minor = SwingUtil.loadIcon("cdc/perfs/images/cdc-perfs-level-minor.png");
            final Icon micro = SwingUtil.loadIcon("cdc/perfs/images/cdc-perfs-level-micro.png");
            final Icon debug = SwingUtil.loadIcon("cdc/perfs/images/cdc-perfs-level-debug.png");

            @Override
            public Icon getIcon(MeasureLevel value) {
                switch (value) {
                case DEBUG:
                    return debug;
                case INFO:
                    return info;
                case MAJOR:
                    return major;
                case MICRO:
                    return micro;
                case MINOR:
                    return minor;
                default:
                    return null;
                }
            }
        };
        // settings.setTrueIcon(new ImageIcon("data/cdc-perfs-visible.png"));
        // // settings.setFalseIcon(new ImageIcon("data/cdc-perfs-hidden.png"));
        // settings.setTrueText(null);
        // settings.setFalseText(null);
        wTable.setDefaultRenderer(MeasureLevel.class,
                                  new EnumUi.LabelCellRenderer<>(MeasureLevel.class, settings));
        wTable.setDefaultEditor(MeasureLevel.class,
                                new EnumUi.CellEditor2<>(MeasureLevel.class, settings));
        wTable.setAutoCreateRowSorter(true);
        // wTable.setDefaultRenderer(Context.class, new ContextCell.Renderer());
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy