Example usage for javax.swing JTable getColumn

List of usage examples for javax.swing JTable getColumn

Introduction

In this page you can find the example usage for javax.swing JTable getColumn.

Prototype

public TableColumn getColumn(Object identifier) 

Source Link

Document

Returns the TableColumn object for the column in the table whose identifier is equal to identifier, when compared using equals.

Usage

From source file:org.openconcerto.erp.core.finance.accounting.ui.GrandLivrePanel.java

/**
 * Cree un JTable contenant les ecritures du compte pass en argument
 * /*from  w w w.ja va  2  s.  c  o m*/
 * @param compte
 * @return null si aucune ecriture
 */
private JTable createJTableCompte(Compte compte) {

    // on cree la JTable
    final JTable tableTmp = creerJTable(compte);

    if (tableTmp != null) {

        // On met en place le renderer
        EcritureGrandLivreRenderer ecritureRenderer = new EcritureGrandLivreRenderer(
                ((TableSorter) tableTmp.getModel()));

        for (int j = 0; j < tableTmp.getColumnCount(); j++) {
            tableTmp.getColumnModel().getColumn(j).setCellRenderer(ecritureRenderer);
        }

        // Gestion de la souris sur la JTable
        tableTmp.addMouseListener(new MouseAdapter() {

            public void mousePressed(final MouseEvent mE) {

                if (mE.getButton() == MouseEvent.BUTTON3) {
                    JPopupMenu menuDroit = new JPopupMenu();

                    menuDroit.add(new AbstractAction("Voir la source") {

                        public void actionPerformed(ActionEvent e) {
                            int row = tableTmp.rowAtPoint(mE.getPoint());

                            TableSorter s = (TableSorter) tableTmp.getModel();

                            int modelIndex = s.modelIndex(row);
                            ConsultCompteModel consultCompteModel = ((ConsultCompteModel) s.getTableModel());
                            Ecriture ecriture = consultCompteModel.getEcritures().get(modelIndex);

                            MouvementSQLElement.showSource(ecriture.getIdMvt());

                        }
                    });
                    menuDroit.show(mE.getComponent(), mE.getX(), mE.getY());
                }
            }
        });

    }
    return tableTmp;
}

From source file:org.openconcerto.erp.core.finance.accounting.ui.PlanComptableGPanel.java

public JTable creerJTable(ClasseCompte ccTmp) { // NO_UCD

    final PlanComptableGModel model;
    if (this.radioCompteDeveloppe.isSelected()) {
        model = new PlanComptableGModel(ccTmp, 3);
    } else if (this.radioCompteAbrege.isSelected()) {
        model = new PlanComptableGModel(ccTmp, 2);
    } else {//from  w w w .jav  a2s  . c  o m
        model = new PlanComptableGModel(ccTmp, 1);
    }

    final JTable table = new JTable(model) {
        public JToolTip createToolTip() {
            JMultiLineToolTip t = new JMultiLineToolTip();
            t.setFixedWidth(500);
            return t;
        }
    };

    table.getColumnModel().getColumn(0).setCellRenderer(new PlanComptableCellRenderer(0));
    table.getColumnModel().getColumn(1).setCellRenderer(new PlanComptableCellRenderer(0));

    // TODO calcul de la taille de la colone numero de compte
    table.getColumnModel().getColumn(0).setMaxWidth(90);

    table.getTableHeader().setReorderingAllowed(false);

    table.addMouseMotionListener(new MouseMotionAdapter() {
        int lastRow = -1;

        public void mouseMoved(final MouseEvent e) {

            final Point p = new Point(e.getX(), e.getY());

            SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    final int row = table.rowAtPoint(p);
                    if (lastRow != row) {
                        lastRow = row;
                        String strTmp = ((Compte) (model.getComptes().get(lastRow))).getInfos();

                        if (strTmp.length() != 0) {
                            table.setToolTipText(strTmp);
                        } else {
                            table.setToolTipText(null);
                        }

                    }
                }
            });

        }
    });

    if (this.actionClickDroit != null) {
        // System.out.println("Ajout menu droit");
        table.addMouseListener(new MouseAdapter() {

            public void mousePressed(MouseEvent e) {

                if (e.getButton() == MouseEvent.BUTTON3) {
                    actionDroitTable(e, table);
                }
            }
        });
    }

    // Enable row selection (default)
    /**
     * table.setColumnSelectionAllowed(false); table.setRowSelectionAllowed(true);
     * 
     * table.setSelectionMode(table.getSelectionModel().MULTIPLE_INTERVAL_SELECTION);
     */

    table.getSelectionModel().addListSelectionListener(new ListSelectionListener() {

        public void valueChanged(ListSelectionEvent e) {
            int selectedRow = table.getSelectedRow();
            if (selectedRow < 0) {
                // Pas de selection
                textInfos.setText("Pas de compte slctionn");
            } else {
                textInfos.setText(((Compte) (model.getComptes().get(selectedRow))).getInfos());
            }
        }
    });

    return table;
}

From source file:org.openstreetmap.josm.gui.preferences.imagery.CacheContentsPanel.java

private static JTable getTableForCache(final CacheAccess<String, BufferedImageCacheEntry> cache,
        final TableModel tableModel) {
    final JTable ret = new JTable(tableModel);

    ButtonColumn buttonColumn = new ButtonColumn(new AbstractAction() {
        @Override// w w  w .j  a  va  2s  .co  m
        public void actionPerformed(ActionEvent e) {
            int row = ret.convertRowIndexToModel(ret.getEditingRow());
            tableModel.setValueAt("0", row, 1);
            cache.remove(ret.getValueAt(row, 0).toString() + ':');
        }
    });
    TableColumn tableColumn = ret.getColumnModel().getColumn(2);
    tableColumn.setCellRenderer(buttonColumn);
    tableColumn.setCellEditor(buttonColumn);
    return ret;
}

From source file:org.processmining.analysis.performance.dottedchart.ui.MetricsPanel.java

/**
 * Displays the performance metrics of each pattern on the east side of the
 * plug-in window.//from w  w  w.  j av a2s.c o m
 * 
 * @param sortedArray
 *            int[]
 */

public void displayPerformanceMetrics() {
    String type = dcPanel.getTimeOption();
    ArrayList<DescriptiveStatistics> aList = dcModel.getTimeStatistics();
    ArrayList<String> aTitles = dcModel.getDescriptiveStatisticsTitles();

    ArrayList<String> sortedTitleList = dcModel.getSortedKeySetList();

    this.removeAll();
    this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
    // add time option menu
    this.add(Box.createRigidArea(new Dimension(5, 10)));
    JPanel menuPanel = new JPanel(new BorderLayout());
    menuPanel.setPreferredSize(new Dimension(160, 45));
    menuPanel.setMaximumSize(new Dimension(180, 45));
    timeSortLabel.setAlignmentX(LEFT_ALIGNMENT);
    menuPanel.add(timeSortLabel, BorderLayout.NORTH);
    timeBox.setMaximumSize(new Dimension(160, 20));
    timeBox.setAlignmentX(LEFT_ALIGNMENT);
    menuPanel.add(Box.createRigidArea(new Dimension(5, 0)));
    menuPanel.add(timeBox, BorderLayout.CENTER);
    this.add(menuPanel);
    this.add(Box.createRigidArea(new Dimension(5, 10)));

    // for each frequency get the set of patterns that have that frequency
    // (run from high frequency to low)
    int size = 0;
    for (int i = 0; i < aList.size(); i++) {
        try {
            String key;
            DescriptiveStatistics currentDS = null;
            if (i != 0)
                key = sortedTitleList.get(i - 1);
            else {
                key = aTitles.get(0);
                currentDS = aList.get(i);
            }

            if (i > 0 && dcModel.getTypeHashMap().equals(DottedChartPanel.ST_INST)
                    && !dcModel.getInstanceTypeToKeep().contains(key))
                continue;
            size++;

            if (i > 0) {
                for (int j = 1; j < aTitles.size(); j++) {
                    if (aTitles.get(j).equals(key))
                        currentDS = aList.get(j);
                }
            }
            AbstractTableModel otm;
            // create labels that contains information about the pattern
            if (i == 0)
                otm = new OverallMetricTableModel();
            else
                otm = new OneMetricTableModel();
            DefaultTableCellRenderer dtcr = new DefaultTableCellRenderer();
            dtcr.setBackground(new Color(235, 235, 235));
            JTable table = new JTable(otm);
            table.setPreferredSize(new Dimension(200, 55));
            table.setMaximumSize(new Dimension(200, 55));
            table.getColumnModel().getColumn(0).setPreferredWidth(70);
            table.getColumnModel().getColumn(0).setMaxWidth(100);
            table.getTableHeader().setFont(new Font("SansSerif", Font.PLAIN, 12));
            table.getColumnModel().getColumn(0).setCellRenderer(dtcr);
            table.setBorder(BorderFactory.createEtchedBorder());

            // place throughput times in table
            if (type.equals(DottedChartPanel.TIME_ACTUAL)) {
                if (i == 0) {
                    table.setValueAt(DateFormat.getInstance().format(dcModel.getLogBoundaryLeft()), 0, 1);
                    table.setValueAt(DateFormat.getInstance().format(dcModel.getLogBoundaryRight()), 1, 1);
                } else {
                    table.setValueAt(DateFormat.getInstance().format(dcModel.getStartDateofLogUniList(key)), 0,
                            1);
                    table.setValueAt(DateFormat.getInstance().format(dcModel.getEndDateofLogUniList(key)), 1,
                            1);
                }
                table.setValueAt(formatString(currentDS.getMean() / timeDivider, 5), 2, 1);
                table.setValueAt(formatString(currentDS.getMin() / timeDivider, 5), 3, 1);
                table.setValueAt(formatString(currentDS.getMax() / timeDivider, 5), 4, 1);
            } else if (type.equals(DottedChartPanel.TIME_RELATIVE_TIME)) {
                if (i == 0) {
                    table.setValueAt(formatDate(dcModel.getLogBoundaryLeft()), 0, 1);
                    table.setValueAt(formatDate(dcModel.getLogBoundaryRight()), 1, 1);
                } else {
                    table.setValueAt(formatDate(dcModel.getStartDateofLogUniList(key)), 0, 1);
                    table.setValueAt(formatDate(dcModel.getEndDateofLogUniList(key)), 1, 1);
                }
                table.setValueAt(formatString(currentDS.getMean() / timeDivider, 5), 2, 1);
                table.setValueAt(formatString(currentDS.getMin() / timeDivider, 5), 3, 1);
                table.setValueAt(formatString(currentDS.getMax() / timeDivider, 5), 4, 1);
            } else if (type.equals(DottedChartPanel.TIME_RELATIVE_RATIO)) {
                if (i == 0) {
                    table.setValueAt(formatRatio(dcModel.getLogBoundaryLeft()), 0, 1);
                    table.setValueAt(formatRatio(dcModel.getLogBoundaryRight()), 1, 1);
                } else {
                    table.setValueAt(formatRatio(dcModel.getStartDateofLogUniList(key)), 0, 1);
                    table.setValueAt(formatRatio(dcModel.getEndDateofLogUniList(key)), 1, 1);
                }
                table.setValueAt(formatString(currentDS.getMean() / 100, 5), 2, 1);
                table.setValueAt(formatString(currentDS.getMin() / 100, 5), 3, 1);
                table.setValueAt(formatString(currentDS.getMax() / 100, 5), 4, 1);
            } else if (type.equals(DottedChartPanel.TIME_LOGICAL)
                    || type.equals(DottedChartPanel.TIME_LOGICAL_RELATIVE)) {
                if (i == 0) {
                    table.setValueAt(formatString(dcModel.getLogBoundaryLeft().getTime(), 5), 0, 1);
                    table.setValueAt(formatString(dcModel.getLogBoundaryRight().getTime(), 5), 1, 1);
                } else {
                    table.setValueAt(formatString((dcModel.getStartDateofLogUniList(key)).getTime(), 5), 0, 1);
                    table.setValueAt(formatString((dcModel.getEndDateofLogUniList(key)).getTime(), 5), 1, 1);
                }
                table.setValueAt(formatString(currentDS.getMean(), 5), 2, 1);
                table.setValueAt(formatString(currentDS.getMin(), 5), 3, 1);
                table.setValueAt(formatString(currentDS.getMax(), 5), 4, 1);
            }

            JPanel tempPanel = new JPanel(new BorderLayout());
            table.setAlignmentX(CENTER_ALIGNMENT);
            tempPanel.setPreferredSize(new Dimension(160, 98));
            tempPanel.setMaximumSize(new Dimension(180, 98));
            tempPanel.add(table.getTableHeader(), BorderLayout.NORTH);
            tempPanel.add(table, BorderLayout.CENTER);
            JPanel tempPanel2 = new JPanel(new BorderLayout());
            JLabel patternLabel = new JLabel("Component " + key + ":");
            patternLabel.setAlignmentX(LEFT_ALIGNMENT);

            JLabel frequencyLabel = null;
            if (i == 0)
                frequencyLabel = new JLabel("# of components: " + currentDS.getN());
            else
                frequencyLabel = new JLabel("# of dots: " + dcModel.getNumberOfLogUnits(key));

            frequencyLabel.setAlignmentX(LEFT_ALIGNMENT);
            frequencyLabel.setFont(new Font("SansSerif", Font.PLAIN, 12));
            tempPanel2.add(patternLabel, BorderLayout.NORTH);
            tempPanel2.add(frequencyLabel, BorderLayout.CENTER);
            tempPanel2.add(tempPanel, BorderLayout.SOUTH);
            this.add(tempPanel2);
            this.add(Box.createRigidArea(new Dimension(5, 10)));
        } catch (NullPointerException ex) {
            // can occur when patternMap does not contain a pattern with
            // this frequency
            size--;
        }
    }
    // make sure the pattern performance information is displayed properly
    this.setPreferredSize(new Dimension(200, 140 * (size + 1)));
    this.revalidate();
    this.repaint();

}

From source file:org.prom5.analysis.performance.dottedchart.ui.MetricsPanel.java

/**
 * Displays the performance metrics of each pattern on the east side of the
 * plug-in window.//ww w  . j  ava 2s .co  m
 * @param sortedArray int[]
 */

public void displayPerformanceMetrics() {
    String type = dcPanel.getTimeOption();
    ArrayList<DescriptiveStatistics> aList = dcModel.getTimeStatistics();
    ArrayList<String> aTitles = dcModel.getDescriptiveStatisticsTitles();

    ArrayList<String> sortedTitleList = dcModel.getSortedKeySetList();

    this.removeAll();
    this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
    //add time option menu
    this.add(Box.createRigidArea(new Dimension(5, 10)));
    JPanel menuPanel = new JPanel(new BorderLayout());
    menuPanel.setPreferredSize(new Dimension(160, 45));
    menuPanel.setMaximumSize(new Dimension(180, 45));
    timeSortLabel.setAlignmentX(LEFT_ALIGNMENT);
    menuPanel.add(timeSortLabel, BorderLayout.NORTH);
    timeBox.setMaximumSize(new Dimension(160, 20));
    timeBox.setAlignmentX(LEFT_ALIGNMENT);
    menuPanel.add(Box.createRigidArea(new Dimension(5, 0)));
    menuPanel.add(timeBox, BorderLayout.CENTER);
    this.add(menuPanel);
    this.add(Box.createRigidArea(new Dimension(5, 10)));

    //for each frequency get the set of patterns that have that frequency
    //(run from high frequency to low)
    int size = 0;
    for (int i = 0; i < aList.size(); i++) {
        try {
            String key;
            DescriptiveStatistics currentDS = null;
            if (i != 0)
                key = sortedTitleList.get(i - 1);
            else {
                key = aTitles.get(0);
                currentDS = aList.get(i);
            }

            if (i > 0 && dcModel.getTypeHashMap().equals(DottedChartPanel.ST_INST)
                    && !dcModel.getInstanceTypeToKeep().contains(key))
                continue;
            size++;

            if (i > 0) {
                for (int j = 1; j < aTitles.size(); j++) {
                    if (aTitles.get(j).equals(key))
                        currentDS = aList.get(j);
                }
            }
            AbstractTableModel otm;
            //create labels that contains information about the pattern
            if (i == 0)
                otm = new OverallMetricTableModel();
            else
                otm = new OneMetricTableModel();
            DefaultTableCellRenderer dtcr = new DefaultTableCellRenderer();
            dtcr.setBackground(new Color(235, 235, 235));
            JTable table = new JTable(otm);
            table.setPreferredSize(new Dimension(200, 55));
            table.setMaximumSize(new Dimension(200, 55));
            table.getColumnModel().getColumn(0).setPreferredWidth(70);
            table.getColumnModel().getColumn(0).setMaxWidth(100);
            table.getTableHeader().setFont(new Font("SansSerif", Font.PLAIN, 12));
            table.getColumnModel().getColumn(0).setCellRenderer(dtcr);
            table.setBorder(BorderFactory.createEtchedBorder());

            //place throughput times in table
            if (type.equals(DottedChartPanel.TIME_ACTUAL)) {
                if (i == 0) {
                    table.setValueAt(DateFormat.getInstance().format(dcModel.getLogBoundaryLeft()), 0, 1);
                    table.setValueAt(DateFormat.getInstance().format(dcModel.getLogBoundaryRight()), 1, 1);
                } else {
                    table.setValueAt(DateFormat.getInstance().format(dcModel.getStartDateofLogUniList(key)), 0,
                            1);
                    table.setValueAt(DateFormat.getInstance().format(dcModel.getEndDateofLogUniList(key)), 1,
                            1);
                }
                table.setValueAt(formatString(currentDS.getMean() / timeDivider, 5), 2, 1);
                table.setValueAt(formatString(currentDS.getMin() / timeDivider, 5), 3, 1);
                table.setValueAt(formatString(currentDS.getMax() / timeDivider, 5), 4, 1);
            } else if (type.equals(DottedChartPanel.TIME_RELATIVE_TIME)) {
                if (i == 0) {
                    table.setValueAt(formatDate(dcModel.getLogBoundaryLeft()), 0, 1);
                    table.setValueAt(formatDate(dcModel.getLogBoundaryRight()), 1, 1);
                } else {
                    table.setValueAt(formatDate(dcModel.getStartDateofLogUniList(key)), 0, 1);
                    table.setValueAt(formatDate(dcModel.getEndDateofLogUniList(key)), 1, 1);
                }
                table.setValueAt(formatString(currentDS.getMean() / timeDivider, 5), 2, 1);
                table.setValueAt(formatString(currentDS.getMin() / timeDivider, 5), 3, 1);
                table.setValueAt(formatString(currentDS.getMax() / timeDivider, 5), 4, 1);
            } else if (type.equals(DottedChartPanel.TIME_RELATIVE_RATIO)) {
                if (i == 0) {
                    table.setValueAt(formatRatio(dcModel.getLogBoundaryLeft()), 0, 1);
                    table.setValueAt(formatRatio(dcModel.getLogBoundaryRight()), 1, 1);
                } else {
                    table.setValueAt(formatRatio(dcModel.getStartDateofLogUniList(key)), 0, 1);
                    table.setValueAt(formatRatio(dcModel.getEndDateofLogUniList(key)), 1, 1);
                }
                table.setValueAt(formatString(currentDS.getMean() / 100, 5), 2, 1);
                table.setValueAt(formatString(currentDS.getMin() / 100, 5), 3, 1);
                table.setValueAt(formatString(currentDS.getMax() / 100, 5), 4, 1);
            } else if (type.equals(DottedChartPanel.TIME_LOGICAL)
                    || type.equals(DottedChartPanel.TIME_LOGICAL_RELATIVE)) {
                if (i == 0) {
                    table.setValueAt(formatString(dcModel.getLogBoundaryLeft().getTime(), 5), 0, 1);
                    table.setValueAt(formatString(dcModel.getLogBoundaryRight().getTime(), 5), 1, 1);
                } else {
                    table.setValueAt(formatString((dcModel.getStartDateofLogUniList(key)).getTime(), 5), 0, 1);
                    table.setValueAt(formatString((dcModel.getEndDateofLogUniList(key)).getTime(), 5), 1, 1);
                }
                table.setValueAt(formatString(currentDS.getMean(), 5), 2, 1);
                table.setValueAt(formatString(currentDS.getMin(), 5), 3, 1);
                table.setValueAt(formatString(currentDS.getMax(), 5), 4, 1);
            }

            JPanel tempPanel = new JPanel(new BorderLayout());
            table.setAlignmentX(CENTER_ALIGNMENT);
            tempPanel.setPreferredSize(new Dimension(160, 98));
            tempPanel.setMaximumSize(new Dimension(180, 98));
            tempPanel.add(table.getTableHeader(), BorderLayout.NORTH);
            tempPanel.add(table, BorderLayout.CENTER);
            JPanel tempPanel2 = new JPanel(new BorderLayout());
            JLabel patternLabel = new JLabel("Component " + key + ":");
            patternLabel.setAlignmentX(LEFT_ALIGNMENT);

            JLabel frequencyLabel = null;
            if (i == 0)
                frequencyLabel = new JLabel("# of components: " + currentDS.getN());
            else
                frequencyLabel = new JLabel("# of dots: " + dcModel.getNumberOfLogUnits(key));

            frequencyLabel.setAlignmentX(LEFT_ALIGNMENT);
            frequencyLabel.setFont(new Font("SansSerif", Font.PLAIN, 12));
            tempPanel2.add(patternLabel, BorderLayout.NORTH);
            tempPanel2.add(frequencyLabel, BorderLayout.CENTER);
            tempPanel2.add(tempPanel, BorderLayout.SOUTH);
            this.add(tempPanel2);
            this.add(Box.createRigidArea(new Dimension(5, 10)));
        } catch (NullPointerException ex) {
            //can occur when patternMap does not contain a pattern with this frequency
            size--;
        }
    }
    //make sure the pattern performance information is displayed properly
    this.setPreferredSize(new Dimension(200, 140 * (size + 1)));
    this.revalidate();
    this.repaint();

}

From source file:org.rdv.datapanel.DigitalTabularDataPanel.java

private void addColumn() {
    if (columnGroupCount == MAX_COLUMN_GROUP_COUNT) {
        return;//from  w w  w.ja  v a  2  s.c om
    }

    if (columnGroupCount != 0) {
        panelBox.add(Box.createHorizontalStrut(7));
    }

    final int tableIndex = columnGroupCount;

    final DataTableModel tableModel = new DataTableModel();
    final JTable table = new JTable(tableModel);

    table.setDragEnabled(true);
    table.setName(DigitalTabularDataPanel.class.getName() + " JTable #" + Integer.toString(columnGroupCount));

    if (showThresholdCheckBoxGroup.isSelected()) {
        tableModel.setThresholdVisible(true);
    }

    if (showMinMaxCheckBoxGroup.isSelected()) {
        tableModel.setMaxMinVisible(true);

        table.getColumn("Min").setCellRenderer(doubleCellRenderer);
        table.getColumn("Max").setCellRenderer(doubleCellRenderer);
    }

    table.getColumn("Value").setCellRenderer(dataCellRenderer);

    tables.add(table);
    tableModels.add(tableModel);

    JScrollPane tableScrollPane = new JScrollPane(table);
    panelBox.add(tableScrollPane);

    // popup menu for panel
    JPopupMenu popupMenu = new JPopupMenu();

    final JMenuItem copyMenuItem = new JMenuItem("Copy");
    copyMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            TransferHandler.getCopyAction().actionPerformed(
                    new ActionEvent(table, ae.getID(), ae.getActionCommand(), ae.getWhen(), ae.getModifiers()));
        }
    });
    popupMenu.add(copyMenuItem);

    popupMenu.addSeparator();

    JMenuItem printMenuItem = new JMenuItem("Print...");
    printMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            try {
                table.print(JTable.PrintMode.FIT_WIDTH);
            } catch (PrinterException pe) {
            }
        }
    });
    popupMenu.add(printMenuItem);
    popupMenu.addSeparator();

    final JCheckBoxMenuItem showMaxMinMenuItem = new JCheckBoxMenuItem("Show min/max columns", false);
    showMaxMinMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            setMaxMinVisible(showMaxMinMenuItem.isSelected());
        }
    });
    showMinMaxCheckBoxGroup.addCheckBox(showMaxMinMenuItem);
    popupMenu.add(showMaxMinMenuItem);

    final JCheckBoxMenuItem showThresholdMenuItem = new JCheckBoxMenuItem("Show threshold columns", false);
    showThresholdMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            setThresholdVisible(showThresholdMenuItem.isSelected());
        }
    });
    showThresholdCheckBoxGroup.addCheckBox(showThresholdMenuItem);
    popupMenu.add(showThresholdMenuItem);

    popupMenu.addSeparator();

    JMenuItem blankRowMenuItem = new JMenuItem("Insert blank row");
    blankRowMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            tableModel.addBlankRow();
        }
    });
    popupMenu.add(blankRowMenuItem);

    final JMenuItem removeSelectedRowsMenuItem = new JMenuItem("Remove selected rows");
    removeSelectedRowsMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            removeSelectedRows(tableIndex);
        }
    });
    popupMenu.add(removeSelectedRowsMenuItem);

    popupMenu.addSeparator();

    JMenu numberOfColumnsMenu = new JMenu("Number of columns");
    numberOfColumnsMenu.addMenuListener(new MenuListener() {
        public void menuSelected(MenuEvent me) {
            JMenu menu = (JMenu) me.getSource();
            for (int j = 0; j < MAX_COLUMN_GROUP_COUNT; j++) {
                JMenuItem menuItem = menu.getItem(j);
                boolean selected = (j == (columnGroupCount - 1));
                menuItem.setSelected(selected);
            }
        }

        public void menuDeselected(MenuEvent me) {
        }

        public void menuCanceled(MenuEvent me) {
        }
    });

    for (int i = 0; i < MAX_COLUMN_GROUP_COUNT; i++) {
        final int number = i + 1;
        JRadioButtonMenuItem item = new JRadioButtonMenuItem(Integer.toString(number));
        item.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent ae) {
                setNumberOfColumns(number);
            }
        });
        numberOfColumnsMenu.add(item);
    }
    popupMenu.add(numberOfColumnsMenu);

    popupMenu.addPopupMenuListener(new PopupMenuListener() {
        public void popupMenuWillBecomeVisible(PopupMenuEvent arg0) {
            boolean anyRowsSelected = table.getSelectedRowCount() > 0;
            copyMenuItem.setEnabled(anyRowsSelected);
            removeSelectedRowsMenuItem.setEnabled(anyRowsSelected);
        }

        public void popupMenuWillBecomeInvisible(PopupMenuEvent arg0) {
        }

        public void popupMenuCanceled(PopupMenuEvent arg0) {
        }
    });

    // set component popup and mouselistener to trigger it
    table.setComponentPopupMenu(popupMenu);
    tableScrollPane.setComponentPopupMenu(popupMenu);

    panelBox.revalidate();

    columnGroupCount++;

    properties.setProperty("numberOfColumns", Integer.toString(columnGroupCount));
}

From source file:org.rdv.datapanel.DigitalTabularDataPanel.java

private void setMaxMinVisible(boolean maxMinVisible) {
    if (showMinMaxCheckBoxGroup.isSelected() != maxMinVisible) {
        for (int i = 0; i < this.columnGroupCount; i++) {
            DataTableModel tableModel = tableModels.get(i);
            JTable table = tables.get(i);

            tableModel.setMaxMinVisible(maxMinVisible);

            table.getColumn("Value").setCellRenderer(dataCellRenderer);

            if (maxMinVisible) {
                table.getColumn("Min").setCellRenderer(doubleCellRenderer);
                table.getColumn("Max").setCellRenderer(doubleCellRenderer);
            }//from   ww w .ja va 2 s.c o m

            if (showThresholdCheckBoxGroup.isSelected()) {
                table.getColumn("Min Thresh").setCellRenderer(doubleCellRenderer);
                table.getColumn("Max Thresh").setCellRenderer(doubleCellRenderer);
            }
        }

        showMinMaxCheckBoxGroup.setSelected(maxMinVisible);

        if (maxMinVisible) {
            properties.setProperty("maxMinVisible", "true");
        } else {
            properties.remove("maxMinVisible");
        }
    }
}

From source file:org.rdv.datapanel.DigitalTabularDataPanel.java

private void setThresholdVisible(boolean thresholdVisible) {
    if (showThresholdCheckBoxGroup.isSelected() != thresholdVisible) {
        for (int i = 0; i < columnGroupCount; i++) {
            DataTableModel tableModel = tableModels.get(i);
            JTable table = tables.get(i);

            tableModel.setThresholdVisible(thresholdVisible);

            table.getColumn("Value").setCellRenderer(dataCellRenderer);

            if (showMinMaxCheckBoxGroup.isSelected()) {
                table.getColumn("Min").setCellRenderer(doubleCellRenderer);
                table.getColumn("Max").setCellRenderer(doubleCellRenderer);
            }/*www  .  ja v  a 2  s.  co m*/

            if (thresholdVisible) {
                table.getColumn("Min Thresh").setCellRenderer(doubleCellRenderer);
                table.getColumn("Max Thresh").setCellRenderer(doubleCellRenderer);
            }
        }

        showThresholdCheckBoxGroup.setSelected(thresholdVisible);

        if (thresholdVisible) {
            properties.setProperty("thresholdVisible", "true");
        } else {
            properties.remove("thresholdVisible");
        }
    }
}

From source file:org.yccheok.jstock.gui.JTableUtilities.java

public static void setJTableOptions(JTable jTable, GUIOptions.JTableOptions jTableOptions) {
    if (jTableOptions.getColumnSize() <= 0) {
        // A bug introduced in version 1.0.5p. Due to incorrect
        // implementation of Utils.toXML, we may get a table option with 0
        // column turned on. To avoid all columns being turned off, we will
        // return early.
        return;/*from ww  w. jav  a2  s . co  m*/
    }

    final Locale locale = jTableOptions.getLocale();
    // HACKING!
    boolean first_column_hacking_required = false;

    // Remove unwanted column. MUST BE DONE FIRST!
    for (int i = 0; i < jTable.getColumnCount(); i++) {
        final String name = jTable.getColumnName(i);

        // In to avoid the following situation.
        // 1. GUIOptions is being saved when we are in Chinese locale.
        // 2. Application is restarted in English locale.
        // 3. We are trying to compare English wording with Chinese wording.
        //
        // Before performing comparison, we shall convert name, to the locale
        // of table options.
        final java.util.List<String> keys = getKeys(name, Locale.getDefault());

        // Ensure correct resource file is being loaded.
        // When ResourceBundle.getBundle(..., locale) is being called, the
        // system will try to search in the following sequence.
        // 1. gui_<locale>.properties.
        // 2. gui_<default_locale>.properties.
        // 3. gui.properties.
        final Locale oldLocale = Locale.getDefault();
        Locale.setDefault(locale);
        try {
            final ResourceBundle bundle = ResourceBundle.getBundle("org.yccheok.jstock.data.gui", locale);
            Locale.setDefault(oldLocale);

            // Try all the keys.
            boolean found = false;
            for (String key : keys) {
                final String translated_name = bundle.getString(key);
                if (jTableOptions.contains(translated_name)) {
                    found = true;
                    break;
                }
            }

            /* Remove any unwanted columns. */
            if (found == false) {
                // HACKING!
                // Some customers complain their first column of Watchlist,
                // or Portfolio are being hidden. I'm not sure why that
                // happen. YES! I have really no idea why that happen!
                // This is a hacking way "if (i > 0)" to prevent such 
                // problem. Shh...
                if (i > 0) {
                    removeTableColumn(jTable, name);
                    i--;
                } else {
                    first_column_hacking_required = true;
                }
            }
        } finally {
            Locale.setDefault(oldLocale);
        }
    }

    final int optionsCount = jTableOptions.getColumnSize();
    final int tableCount = jTable.getColumnCount();

    // HACKING!
    // jTableOptions doesn't have first column information if first_column_hacking_required
    // is true. When perform column moving, we will start from 2nd column if
    // first_column_hacking_required is true. Assume first column will always
    // stay in first column.
    int target = first_column_hacking_required ? 1 : 0;

    /* Sort the columns according to user preference. */
    for (int i = 0; i < optionsCount; i++) {
        final String name = jTableOptions.getColumnName(i);
        final java.util.List<String> keys = getKeys(name, locale);
        assert (keys != null);

        int index = -1;
        for (int j = 0; j < tableCount; j++) {
            // Try all the keys.
            boolean found = false;
            String translated_name = null;
            for (String key : keys) {
                translated_name = GUIBundle.getString(key);
                if (jTable.getColumnName(j).equals(translated_name)) {
                    found = true;
                    break;
                }
            }

            if (found) {
                /* Restore width. */
                jTable.getColumn(translated_name).setPreferredWidth(jTableOptions.getColumnWidth(i));

                index = j;
                break;
            }
        }

        if (index >= 0) {
            jTable.moveColumn(index, target++);
        }
    }
}

From source file:org.yccheok.jstock.gui.JTableUtilities.java

public static void removeTableColumn(JTable jTable, Object identifier) {
    TableColumn tableColumn = null;
    // If we try to getColumn which its identifier doesn't exist, 
    // IllegalArgumentException will be thrown.        
    try {/*from w  w  w . j  a  va  2s  . co m*/
        tableColumn = jTable.getColumn(identifier);
    } catch (IllegalArgumentException ex) {
        log.error(null, ex);
    }

    if (tableColumn != null) {
        jTable.removeColumn(tableColumn);
    }
}