Search in sources :

Example 1 with DBTable

use of quick.dbtable.DBTable in project mafscaling by vimsh.

the class LogView method createLogViewPanel.

private void createLogViewPanel() {
    logViewPanel = new JPanel();
    GridBagLayout gbl_logViewPanel = new GridBagLayout();
    gbl_logViewPanel.columnWidths = new int[] { 0 };
    gbl_logViewPanel.rowHeights = new int[] { 0, 0 };
    gbl_logViewPanel.columnWeights = new double[] { 1.0 };
    gbl_logViewPanel.rowWeights = new double[] { 1.0, 0.0 };
    logViewPanel.setLayout(gbl_logViewPanel);
    try {
        logDataTable = new DBTable();
        logDataTable.copyColumnHeaderNames = true;
        logDataTable.defaultClickCountToStartEditor = 2;
        logDataTable.doNotUseDatabaseSort = true;
        logDataTable.listenKeyPressEventsWholeWindow = true;
        logDataTable.createControlPanel(DBTable.READ_NAVIGATION);
        logDataTable.enableExcelCopyPaste();
        logDataTable.setSortEnabled(false);
        logDataTable.setSkin(new TableSkin());
        logDataTable.refresh(new String[1][25]);
        logDataTable.setComparator(new DoubleComparator());
        logDataTable.getTable().setCellSelectionEnabled(true);
        logDataTable.getTable().setColumnSelectionAllowed(true);
        logDataTable.getTable().setRowSelectionAllowed(true);
        logDataTable.getTable().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        JTextField rowTextField = ((JTextField) logDataTable.getControlPanel().getComponent(tableRowTextFieldComponentIdx));
        rowTextField.setPreferredSize(null);
        rowTextField.setColumns(tableRowTextFieldSize);
        GridBagConstraints gbc_logDataTable = new GridBagConstraints();
        gbc_logDataTable.insets = insets0;
        gbc_logDataTable.anchor = GridBagConstraints.PAGE_START;
        gbc_logDataTable.fill = GridBagConstraints.BOTH;
        gbc_logDataTable.gridx = 0;
        gbc_logDataTable.gridy = 0;
        logViewPanel.add(logDataTable, gbc_logDataTable);
        listModel = new DefaultListModel<JLabel>();
        selectionCombo.removeAllItems();
        TreeSet<String> sortedCols = new TreeSet<String>();
        JTableHeader tableHeader = logDataTable.getTableHeader();
        for (int i = 0; i < logDataTable.getColumnCount(); ++i) {
            Column col = logDataTable.getColumn(i);
            col.setNullable(true);
            col.setHeaderRenderer(new CheckboxHeaderRenderer(i + 1, tableHeader));
            sortedCols.add(col.getHeaderValue().toString());
        }
        for (String s : sortedCols) {
            selectionCombo.addItem(s);
            listModel.addElement(new JLabel(s, new CheckBoxIcon(), JLabel.LEFT));
        }
        JList<JLabel> menuList = new JList<JLabel>(listModel);
        menuList.setOpaque(false);
        menuList.setCellRenderer(new ImageListCellRenderer());
        menuList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        menuList.setLayoutOrientation(JList.VERTICAL_WRAP);
        menuList.setFixedCellHeight(25);
        menuList.setVisibleRowCount(-1);
        menuList.addMouseListener(new MouseAdapter() {

            @Override
            public void mouseClicked(MouseEvent e) {
                try {
                    if (e.getClickCount() == 1 && colors.size() > 0) {
                        JList<?> list = (JList<?>) e.getSource();
                        int index = list.locationToIndex(e.getPoint());
                        if (index >= 0) {
                            JLabel label = (JLabel) list.getModel().getElementAt(index);
                            Column col = logDataTable.getColumnByHeaderName(label.getText());
                            if (col.getHeaderRenderer() instanceof CheckboxHeaderRenderer) {
                                CheckboxHeaderRenderer renderer = (CheckboxHeaderRenderer) col.getHeaderRenderer();
                                CheckBoxIcon checkIcon = (CheckBoxIcon) label.getIcon();
                                checkIcon.setChecked(!checkIcon.isChecked());
                                if (checkIcon.isChecked()) {
                                    checkIcon.setColor(colors.pop());
                                    JTable table = logDataTable.getTable();
                                    TableModel model = table.getModel();
                                    addXYSeries(model, col.getModelIndex() - 1, col.getHeaderValue().toString(), checkIcon.getColor());
                                } else {
                                    colors.push(checkIcon.getColor());
                                    checkIcon.setColor(renderer.getDefaultColor());
                                    removeXYSeries(col.getModelIndex() - 1);
                                }
                                list.repaint();
                            }
                        }
                    }
                } catch (Exception ex) {
                    ex.printStackTrace();
                }
            }
        });
        headerScrollPane = new JScrollPane(menuList);
        GridBagConstraints gbc_headersTree = new GridBagConstraints();
        gbc_headersTree.insets = insets0;
        gbc_headersTree.anchor = GridBagConstraints.PAGE_START;
        gbc_headersTree.fill = GridBagConstraints.BOTH;
        gbc_headersTree.gridx = 0;
        gbc_headersTree.gridy = 1;
        logViewPanel.add(headerScrollPane, gbc_headersTree);
        headerScrollPane.setVisible(false);
    } catch (Exception e) {
        e.printStackTrace();
        logger.error(e);
    }
}
Also used : JPanel(javax.swing.JPanel) GridBagConstraints(java.awt.GridBagConstraints) GridBagLayout(java.awt.GridBagLayout) JTableHeader(javax.swing.table.JTableHeader) JTextField(javax.swing.JTextField) Column(quick.dbtable.Column) TreeSet(java.util.TreeSet) JScrollPane(javax.swing.JScrollPane) ChartMouseEvent(org.jfree.chart.ChartMouseEvent) MouseEvent(java.awt.event.MouseEvent) DBTable(quick.dbtable.DBTable) MouseAdapter(java.awt.event.MouseAdapter) JLabel(javax.swing.JLabel) Paint(java.awt.Paint) IOException(java.io.IOException) JTable(javax.swing.JTable) JList(javax.swing.JList) TableModel(javax.swing.table.TableModel)

Aggregations

GridBagConstraints (java.awt.GridBagConstraints)1 GridBagLayout (java.awt.GridBagLayout)1 Paint (java.awt.Paint)1 MouseAdapter (java.awt.event.MouseAdapter)1 MouseEvent (java.awt.event.MouseEvent)1 IOException (java.io.IOException)1 TreeSet (java.util.TreeSet)1 JLabel (javax.swing.JLabel)1 JList (javax.swing.JList)1 JPanel (javax.swing.JPanel)1 JScrollPane (javax.swing.JScrollPane)1 JTable (javax.swing.JTable)1 JTextField (javax.swing.JTextField)1 JTableHeader (javax.swing.table.JTableHeader)1 TableModel (javax.swing.table.TableModel)1 ChartMouseEvent (org.jfree.chart.ChartMouseEvent)1 Column (quick.dbtable.Column)1 DBTable (quick.dbtable.DBTable)1