Example usage for javax.swing JTable setDefaultRenderer

List of usage examples for javax.swing JTable setDefaultRenderer

Introduction

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

Prototype

public void setDefaultRenderer(Class<?> columnClass, TableCellRenderer renderer) 

Source Link

Document

Sets a default cell renderer to be used if no renderer has been set in a TableColumn.

Usage

From source file:org.drugis.addis.gui.renderer.EntityCellRenderer.java

public static void insertEntityRenderer(JTable table) {
    final TableCellRenderer defaultRenderer = table.getDefaultRenderer(Object.class);
    EntityCellRenderer renderer = new EntityCellRenderer(defaultRenderer);
    table.setDefaultRenderer(Object.class, renderer);
    // Entity is an interface, and if something returns a sub-interface of Entity, that is not a sub-type of Object
    // Hence, we have to attach the renderer to Entity.class as well.
    table.setDefaultRenderer(Entity.class, renderer);
}

From source file:org.eclim.installer.step.EclipsePluginsStep.java

@Override
public void displayed() {
    setBusy(true);//ww  w.  j  a v  a 2  s . c om
    setPreviousEnabled(false);

    try {
        overallLabel.setText("");
        overallProgress.setValue(0);
        taskLabel.setText("");
        taskProgress.setValue(0);
        taskProgress.setIndeterminate(true);

        // handle step re-entry.
        if (featuresPanel != null) {
            stepPanel.remove(featuresPanel);
        }

        EclipseInfo info = (EclipseInfo) Installer.getContext().getValue("eclipse.info");

        // find chosen features dependencies which need to be installed/upgraded.
        dependencies = unsatisfiedDependencies(info);

        if (dependencies.size() == 0) {
            overallProgress.setMaximum(1);
            overallProgress.setValue(1);
            overallLabel.setText("All third party plugins are up to date.");
            taskProgress.setMaximum(1);
            taskProgress.setValue(1);
            taskLabel.setText("");
        } else {
            tableModel = new DefaultTableModel();
            tableModel.addColumn("Feature");
            tableModel.addColumn("Version");
            tableModel.addColumn("Install / Upgrade");
            JTable table = new JTable(tableModel);
            table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
            table.setDefaultRenderer(Object.class, new DependencyCellRenderer());
            table.getSelectionModel().addListSelectionListener(new DependencySelectionListener());

            featuresPanel = new JPanel(new BorderLayout());
            featuresPanel.setAlignmentX(0.0f);

            JPanel container = new JPanel(new BorderLayout());
            container.add(table, BorderLayout.CENTER);

            JScrollPane scrollPane = new JScrollPane(container);
            scrollPane.setAlignmentX(0.0f);

            availableFeatures = loadAvailableFeatures();
            for (Dependency dependency : dependencies) {
                String version = availableFeatures.get(dependency.getId());
                String manual = "";
                if (version == null) {
                    manual = " (Manual)";
                    version = dependency.getRequiredVersion();
                }
                tableModel.addRow(new Object[] { dependency.getId(), version,
                        (dependency.isUpgrade() ? "Upgrade" : "Install") + manual, });
            }

            JPanel buttons = new JPanel(new FlowLayout(FlowLayout.RIGHT, 0, 0));
            buttons.setAlignmentX(0.0f);

            JButton skipButton = new JButton(new SkipPluginsAction());
            JButton installButton = new JButton(new InstallPluginsAction(skipButton));

            buttons.add(installButton);
            buttons.add(skipButton);

            featuresPanel.add(scrollPane, BorderLayout.CENTER);
            featuresPanel.add(buttons, BorderLayout.SOUTH);

            stepPanel.add(featuresPanel);
            overallProgress.setValue(0);
            overallLabel.setText("");
            taskProgress.setValue(0);
            taskLabel.setText("");
        }
    } catch (Exception e) {
        setError(e);
    } finally {
        setValid(dependencies != null && dependencies.size() == 0);
        setBusy(false);
        setPreviousEnabled(true);
        taskProgress.setIndeterminate(false);
    }
}

From source file:org.formic.wizard.step.gui.FeatureListStep.java

/**
 * {@inheritDoc}//from w w w  . j a  v  a 2s . c  o  m
 * @see org.formic.wizard.step.GuiStep#init()
 */
public Component init() {
    featureInfo = new JEditorPane("text/html", StringUtils.EMPTY);
    featureInfo.setEditable(false);
    featureInfo.addHyperlinkListener(new HyperlinkListener());

    Feature[] features = provider.getFeatures();
    JTable table = new JTable(features.length, 1) {
        private static final long serialVersionUID = 1L;

        public Class getColumnClass(int column) {
            return getValueAt(0, column).getClass();
        }

        public boolean isCellEditable(int row, int column) {
            return false;
        }
    };
    table.setBackground(new javax.swing.JList().getBackground());

    GuiForm form = createForm();

    for (int ii = 0; ii < features.length; ii++) {
        final Feature feature = (Feature) features[ii];
        final JCheckBox box = new JCheckBox();

        String name = getName() + '.' + feature.getKey();
        form.bind(name, box);

        box.putClientProperty("feature", feature);
        featureMap.put(feature.getKey(), box);

        if (feature.getInfo() == null) {
            feature.setInfo(Installer.getString(getName() + "." + feature.getKey() + ".html"));
        }
        feature.addPropertyChangeListener(new PropertyChangeListener() {
            public void propertyChange(PropertyChangeEvent event) {
                if (Feature.ENABLED_PROPERTY.equals(event.getPropertyName())) {
                    if (box.isSelected() != feature.isEnabled()) {
                        box.setSelected(feature.isEnabled());
                    }
                }
            }
        });

        box.setText(Installer.getString(name));
        box.setBackground(table.getBackground());
        if (!feature.isAvailable()) {
            box.setSelected(false);
            box.setEnabled(false);
        }
        table.setValueAt(box, ii, 0);
    }

    FeatureListMouseListener mouseListener = new FeatureListMouseListener();
    for (int ii = 0; ii < features.length; ii++) {
        Feature feature = (Feature) features[ii];
        if (feature.isEnabled() && feature.isAvailable()) {
            JCheckBox box = (JCheckBox) featureMap.get(feature.getKey());
            box.setSelected(true);
            mouseListener.processDependencies(feature);
            mouseListener.processExclusives(feature);
        }
    }

    table.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN);
    table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    table.setShowHorizontalLines(false);
    table.setShowVerticalLines(false);
    table.setDefaultRenderer(JCheckBox.class, new ComponentTableCellRenderer());

    table.addKeyListener(new FeatureListKeyListener());
    table.addMouseListener(mouseListener);
    table.getSelectionModel().addListSelectionListener(new FeatureListSelectionListener(table));

    table.setRowSelectionInterval(0, 0);

    JPanel panel = new JPanel();
    panel.setLayout(new BorderLayout());
    JPanel container = new JPanel(new BorderLayout());
    container.add(table, BorderLayout.CENTER);
    panel.add(new JScrollPane(container), BorderLayout.CENTER);
    JScrollPane infoScroll = new JScrollPane(featureInfo);
    infoScroll.setMinimumSize(new Dimension(0, 50));
    infoScroll.setMaximumSize(new Dimension(0, 50));
    infoScroll.setPreferredSize(new Dimension(0, 50));
    panel.add(infoScroll, BorderLayout.SOUTH);

    return panel;
}

From source file:org.isatools.isacreator.gui.formelements.SubForm.java

public void changeTableRenderer(JTable table, TableCellRenderer renderer) {
    try {/*ww w.  j a v  a 2 s . com*/
        TableCellRenderer rendererToUse = renderer;
        if (rendererToUse == null) {
            if (table == scrollTable) {
                rendererToUse = DEFAULT_SCROLL_TABLE_RENDERER;
            } else {
                rendererToUse = DEFAULT_LOCKED_TABLE_RENDERER;
            }
        }
        table.setDefaultRenderer(Class.forName("java.lang.Object"), rendererToUse);
    } catch (ClassNotFoundException e) {
        log.error("Problem occurred when changing TableRenderer : " + e.getMessage());
    }
}

From source file:org.isatools.isacreator.spreadsheet.Spreadsheet.java

/**
 * Setup the JTable with its desired characteristics
 *///w  ww . j a v a 2  s  .c o m
private void setupTable() {
    table = new CustomTable(spreadsheetModel);
    table.setShowGrid(true);
    table.setGridColor(Color.BLACK);
    table.setShowVerticalLines(true);
    table.setShowHorizontalLines(true);
    table.setGridColor(UIHelper.LIGHT_GREEN_COLOR);
    table.setRowSelectionAllowed(true);
    table.setColumnSelectionAllowed(true);
    table.setAutoCreateColumnsFromModel(false);
    table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
    table.getSelectionModel().addListSelectionListener(this);
    table.getColumnModel().getSelectionModel().addListSelectionListener(this);
    table.getTableHeader().setReorderingAllowed(true);
    table.getColumnModel().addColumnModelListener(this);
    try {
        table.setDefaultRenderer(Class.forName("java.lang.Object"), new SpreadsheetCellRenderer());
    } catch (ClassNotFoundException e) {
        // ignore this error
    }

    table.addMouseListener(this);
    table.getTableHeader().addMouseMotionListener(new MouseMotionListener() {
        public void mouseDragged(MouseEvent event) {
        }

        public void mouseMoved(MouseEvent event) {
            // display a tooltip when user hovers over a column. tooltip is derived
            // from the description of a field from the TableReferenceObject.
            JTable table = ((JTableHeader) event.getSource()).getTable();
            TableColumnModel colModel = table.getColumnModel();
            int colIndex = colModel.getColumnIndexAtX(event.getX());

            // greater than 1 to account for the row no. being the first col
            if (colIndex >= 1) {
                TableColumn tc = colModel.getColumn(colIndex);
                if (tc != null) {
                    try {
                        table.getTableHeader().setToolTipText(getFieldDescription(tc));
                    } catch (Exception e) {
                        // ignore this error
                    }
                }
            }
        }
    });

    //table.getColumnModel().addColumnModelListener(this);
    InputMap im = table.getInputMap(JTable.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    KeyStroke tab = KeyStroke.getKeyStroke(KeyEvent.VK_TAB, 0);

    //  Override the default tab behaviour
    //  Tab to the next editable cell. When no editable cells goto next cell.
    final Action previousTabAction = table.getActionMap().get(im.get(tab));
    Action newTabAction = new AbstractAction() {
        public void actionPerformed(ActionEvent e) {
            // maintain previous tab action procedure
            previousTabAction.actionPerformed(e);

            JTable table = (JTable) e.getSource();
            int row = table.getSelectedRow();
            int originalRow = row;
            int column = table.getSelectedColumn();
            int originalColumn = column;

            while (!table.isCellEditable(row, column)) {
                previousTabAction.actionPerformed(e);
                row = table.getSelectedRow();
                column = table.getSelectedColumn();

                //  Back to where we started, get out.
                if ((row == originalRow) && (column == originalColumn)) {
                    break;
                }
            }

            if (table.editCellAt(row, column)) {
                table.getEditorComponent().requestFocusInWindow();
            }
        }
    };

    table.getActionMap().put(im.get(tab), newTabAction);
    TableColumnModel model = table.getColumnModel();

    String previousColumnName = null;
    for (int columnIndex = 0; columnIndex < tableReferenceObject.getHeaders().size(); columnIndex++) {
        if (!model.getColumn(columnIndex).getHeaderValue().toString()
                .equals(TableReferenceObject.ROW_NO_TEXT)) {
            model.getColumn(columnIndex).setHeaderRenderer(columnRenderer);
            model.getColumn(columnIndex).setPreferredWidth(spreadsheetFunctions
                    .calcColWidths(model.getColumn(columnIndex).getHeaderValue().toString()));
            // add appropriate cell editor for cell.
            spreadsheetFunctions.addCellEditor(model.getColumn(columnIndex), previousColumnName);
            previousColumnName = model.getColumn(columnIndex).getHeaderValue().toString();
        } else {
            model.getColumn(columnIndex).setHeaderRenderer(new RowNumberCellRenderer());
        }
    }

    JTableHeader header = table.getTableHeader();
    header.setBackground(UIHelper.BG_COLOR);
    header.addMouseListener(new HeaderListener(header, columnRenderer));

    table.addNotify();
}

From source file:org.o3project.optsdn.don.frame.NeFrame.java

/**
 * Create a pane that displays Information Model ID list.
 * //from   w ww .  ja  v  a 2 s. c o m
 * @param portList Ports
 * @return The pane that displays Information Model ID list
 */
private JScrollPane createInformationModelIdListPane(List<Port> portList) {
    Collections.sort(portList, new PortComparator());

    Object[] columnNames = INFORMATION_MODEL_ID_COLNAME_LIST.toArray();
    DefaultTableModel tableModel = new DefaultTableModel(columnNames, 0);
    for (Port port : portList) {
        Port[] column = { port, port };
        tableModel.addRow(column);
    }

    JTable informationModeldTable = new JTable(tableModel);
    informationModeldTable.getTableHeader().setBackground(Color.WHITE);

    DefaultTableCellRenderer renderer = new InformationModelIdRenderer();
    renderer.setHorizontalAlignment(SwingConstants.CENTER);
    informationModeldTable.setDefaultRenderer(Object.class, renderer);

    JScrollPane informationModelIdPane = new JScrollPane();
    informationModelIdPane.getViewport().setView(informationModeldTable);
    informationModelIdPane
            .setPreferredSize(new Dimension(informationModelIdPane.getPreferredSize().width, TABLE_HEIGHT));

    return informationModelIdPane;
}

From source file:org.openconcerto.erp.core.humanresources.payroll.element.FichePayeSQLElement.java

public SQLComponent createComponent() {
    return new BaseSQLComponent(this) {

        private FichePayeModel model;
        private ElementComboBox comboSelProfil, selSalCombo;
        private EditFrame edit = null;
        private ElementComboBox selMois;
        private int dernMois, dernAnnee;
        private JTextField textAnnee;
        JDate dateDu, dateAu;/*ww  w. ja  va 2s  .co m*/
        private JScrollPane paneTreeLeft;
        private JPanel pDate;
        private JButton buttonValider, buttonGenCompta;

        public void addViews() {

            this.dernMois = 0;
            this.dernAnnee = 0;

            this.setLayout(new GridBagLayout());

            final GridBagConstraints c = new DefaultGridBagConstraints();

            // Tree elt Fiche de Paye On the left
            c.fill = GridBagConstraints.BOTH;
            c.weightx = 1;
            c.weighty = 1;
            c.gridheight = GridBagConstraints.REMAINDER;
            final RubriquePayeTree tree = new RubriquePayeTree();
            tree.expandRow(0);
            this.paneTreeLeft = new JScrollPane(tree);
            // this.add(this.paneTreeLeft, c);

            // Panel Fiche paye on the right
            // Salarie
            JPanel panelRight = new JPanel();
            panelRight.setLayout(new GridBagLayout());
            c.fill = GridBagConstraints.HORIZONTAL;
            c.weightx = 1;
            c.weighty = 0;
            c.gridheight = 1;
            c.gridwidth = 2;
            this.selSalCombo = new ElementComboBox();
            // c.gridx++;
            panelRight.add(this.selSalCombo, c);

            // Mois
            c.gridy++;
            // c.gridx++;
            c.fill = GridBagConstraints.HORIZONTAL;
            c.weightx = 1;
            c.weighty = 0;
            c.gridheight = 1;
            c.gridwidth = 3;
            JLabel labelMois = new JLabel("Fiche de paye du mois de");
            this.selMois = new ElementComboBox(true, 20);
            // this.selMois.setEditable(true);
            // /this.selMois.setEnabled(true);

            JLabel labelDu = new JLabel("Du");
            JLabel labelAu = new JLabel("Au");
            this.dateDu = new JDate();
            this.dateAu = new JDate();

            // JTextField textMois = new JTextField();
            JLabel labelAnnee = new JLabel("Anne");
            this.textAnnee = new JTextField();
            {
                this.pDate = new JPanel();
                this.pDate.setOpaque(false);
                this.pDate.add(labelMois);
                this.pDate.add(this.selMois);
                this.pDate.add(labelAnnee);
                this.pDate.add(this.textAnnee);
                this.pDate.add(labelDu);
                this.pDate.add(this.dateDu);
                this.pDate.add(labelAu);
                this.pDate.add(this.dateAu);
                panelRight.add(this.pDate, c);
            }
            c.gridx += 2;
            c.weightx = 1;
            c.gridwidth = 1;
            c.fill = GridBagConstraints.HORIZONTAL;
            panelRight.add(new JPanel(), c);

            // Action Button
            c.gridx++;
            c.fill = GridBagConstraints.HORIZONTAL;
            c.weightx = 0;
            c.weighty = 0;

            JPanel pButtons = new JPanel();
            pButtons.setOpaque(false);
            JButton buttonUp = new JNiceButton(IListFrame.class.getResource("fleche_haut.png"));
            JButton buttonDown = new JNiceButton(IListFrame.class.getResource("fleche_bas.png"));
            JButton buttonRemove = new JNiceButton(SQLComponent.class.getResource("delete.png"));
            {
                pButtons.add(buttonUp);
                pButtons.add(buttonDown);
                pButtons.add(buttonRemove);
            }
            panelRight.add(pButtons, c);

            // Table
            c.fill = GridBagConstraints.BOTH;
            c.weightx = 1;
            c.weighty = 1;
            c.gridx = 1;
            c.gridy++;
            c.gridwidth = GridBagConstraints.REMAINDER;
            this.model = new FichePayeModel(1);
            final JTable table = new JTable(this.model);
            panelRight.add(new JScrollPane(table), c);
            FichePayeRenderer rend = new FichePayeRenderer();
            table.setDefaultRenderer(String.class, rend);
            table.setDefaultRenderer(Float.class, rend);

            // Import profil
            c.gridx = 1;
            c.gridy++;
            c.weightx = 0;
            c.weighty = 0;
            c.gridwidth = 1;
            c.fill = GridBagConstraints.HORIZONTAL;
            JLabel labelProfil = new JLabel("Importer depuis un profil prdfini");
            panelRight.add(labelProfil, c);
            c.gridwidth = 1;

            this.comboSelProfil = new ElementComboBox();
            // this.comboSelProfil = new ElementComboBox();
            this.comboSelProfil.setListIconVisible(false);
            c.gridx++;
            c.gridwidth = 1;

            // this.comboSelProfil.init(eltProfil.getTable().getField("NOM"), null);
            panelRight.add(this.comboSelProfil, c);

            JButton buttonImportProfil = new JButton("Importer");
            c.gridx++;
            panelRight.add(buttonImportProfil, c);

            // Total Periode
            JPanel panelTotal = new JPanel();
            panelTotal.setBorder(BorderFactory.createTitledBorder("Total priode"));
            panelTotal.setLayout(new GridBagLayout());
            GridBagConstraints cPanel = new DefaultGridBagConstraints();

            // Salaire brut
            JLabel labelBrut = new JLabel(getLabelFor("SAL_BRUT"));
            panelTotal.add(labelBrut, cPanel);
            JTextField textSalBrut = new JTextField(10);
            cPanel.gridx++;
            cPanel.weightx = 0;
            panelTotal.add(textSalBrut, cPanel);
            textSalBrut.setEditable(false);
            textSalBrut.setEnabled(false);

            // acompte
            cPanel.gridx++;
            JLabel labelAcompte = new JLabel(getLabelFor("ACOMPTE"));
            panelTotal.add(labelAcompte, cPanel);
            JTextField textAcompte = new JTextField(10);
            cPanel.gridx++;
            panelTotal.add(textAcompte, cPanel);
            // textAcompte.setEditable(false);
            // textAcompte.setEnabled(false);

            // Conges Acquis
            cPanel.gridx++;
            JLabel labelCongesAcquis = new JLabel(getLabelFor("CONGES_ACQUIS"));
            panelTotal.add(labelCongesAcquis, cPanel);
            JTextField textCongesAcquis = new JTextField(10);
            cPanel.gridx++;
            panelTotal.add(textCongesAcquis, cPanel);

            // cotisation salariale
            cPanel.gridx = 0;
            cPanel.gridy++;
            JLabel labelCotSal = new JLabel(getLabelFor("COT_SAL"));
            panelTotal.add(labelCotSal, cPanel);
            JTextField textCotSal = new JTextField(10);
            cPanel.gridx++;
            panelTotal.add(textCotSal, cPanel);
            textCotSal.setEditable(false);
            textCotSal.setEnabled(false);

            // cotisation patronale
            cPanel.gridx++;
            JLabel labelCotPat = new JLabel(getLabelFor("COT_PAT"));
            panelTotal.add(labelCotPat, cPanel);
            JTextField textCotPat = new JTextField(10);
            cPanel.gridx++;
            panelTotal.add(textCotPat, cPanel);
            textCotPat.setEditable(false);
            textCotPat.setEnabled(false);

            JLabel labelCSG = new JLabel(getLabelFor("CSG"));
            cPanel.gridx++;
            panelTotal.add(labelCSG, cPanel);
            JTextField textCSG = new JTextField(10);
            cPanel.gridx++;
            panelTotal.add(textCSG, cPanel);
            textCSG.setEditable(false);
            textCSG.setEnabled(false);

            // net imposable
            cPanel.gridx = 0;
            cPanel.gridy++;
            JLabel labelNetImp = new JLabel(getLabelFor("NET_IMP"));
            panelTotal.add(labelNetImp, cPanel);
            JTextField textNetImp = new JTextField(10);
            cPanel.gridx++;
            panelTotal.add(textNetImp, cPanel);
            textNetImp.setEditable(false);
            textNetImp.setEnabled(false);

            cPanel.gridx++;
            JLabel labelNetAPayer = new JLabel(getLabelFor("NET_A_PAYER"));
            panelTotal.add(labelNetAPayer, cPanel);
            JTextField textNetAPayer = new JTextField(10);
            cPanel.gridx++;
            panelTotal.add(textNetAPayer, cPanel);
            textNetAPayer.setEditable(false);
            textNetAPayer.setEnabled(false);

            c.gridx = 1;
            c.gridy++;
            c.gridwidth = GridBagConstraints.REMAINDER;
            panelRight.add(panelTotal, c);

            // Cumuls

            c.gridx = 1;
            c.gridy++;
            c.gridwidth = 1;
            c.fill = GridBagConstraints.NONE;
            this.buttonValider = new JButton("Valider");
            // panelRight.add(buttonValider, c);

            c.gridx++;
            c.gridwidth = 1;
            this.buttonGenCompta = new JButton("Generer la comptabilit");
            // panelRight.add(buttonGenCompta, c);

            c.gridx = 0;
            c.gridy = 0;
            c.gridwidth = 1;
            c.gridheight = 1;
            c.fill = GridBagConstraints.BOTH;
            c.weightx = 1;
            c.weighty = 1;
            this.add(new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, this.paneTreeLeft, panelRight), c);

            // Listeners
            this.buttonGenCompta.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    int[] i = new int[1];
                    i[0] = getSelectedID();

                    SQLRow rowMois = getTable().getBase().getTable("MOIS").getRow(selMois.getSelectedId());

                    new GenerationMvtFichePaye(i, rowMois.getString("NOM"), textAnnee.getText());
                }
            });

            this.buttonValider.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    System.err.println("Validation de la fiche de paye");
                    validationFiche();
                }
            });

            buttonUp.addActionListener(new ActionListener() {

                public void actionPerformed(ActionEvent e) {
                    int newRowSelected = model.upRow(table.getSelectedRow());
                    if (newRowSelected >= 0) {
                        table.setRowSelectionInterval(newRowSelected, newRowSelected);
                    }
                }
            });

            buttonDown.addActionListener(new ActionListener() {

                public void actionPerformed(ActionEvent e) {
                    int newRowSelected = model.downRow(table.getSelectedRow());
                    if (newRowSelected >= 0) {
                        table.setRowSelectionInterval(newRowSelected, newRowSelected);
                    }
                }
            });

            buttonRemove.addActionListener(new ActionListener() {

                public void actionPerformed(ActionEvent e) {
                    model.removeRow(table.getSelectedRow());
                }
            });

            tree.addMouseListener(new MouseAdapter() {

                public void mousePressed(MouseEvent mE) {

                    TreePath path = tree.getClosestPathForLocation(mE.getPoint().x, mE.getPoint().y);

                    final Object obj = path.getLastPathComponent();

                    if (obj == null) {
                        return;
                    }

                    if (mE.getClickCount() == 2 && mE.getButton() == MouseEvent.BUTTON1) {

                        if (obj instanceof VariableRowTreeNode) {
                            model.addRowAt(((VariableRowTreeNode) obj).getRow(), table.getSelectedRow());
                        }
                    } else {

                        if (mE.getButton() == 3) {

                            if (obj instanceof VariableRowTreeNode) {

                                final SQLRow row = ((VariableRowTreeNode) obj).getRow();

                                JPopupMenu menuDroit = new JPopupMenu();

                                menuDroit.add(new AbstractAction("Editer") {
                                    public void actionPerformed(ActionEvent e) {

                                        if (edit != null) {
                                            edit.dispose();
                                        }
                                        edit = new EditFrame(Configuration.getInstance().getDirectory()
                                                .getElement(row.getTable()), EditFrame.MODIFICATION);
                                        edit.selectionId(row.getID(), 0);
                                        edit.pack();
                                        edit.setVisible(true);
                                    }
                                });

                                menuDroit.add(new AbstractAction("Nouvelle rubrique") {
                                    public void actionPerformed(ActionEvent e) {

                                        if (edit != null) {
                                            edit.dispose();
                                        }
                                        edit = new EditFrame(Configuration.getInstance().getDirectory()
                                                .getElement(row.getTable()));
                                        edit.pack();
                                        edit.setVisible(true);
                                    }
                                });

                                menuDroit.show(mE.getComponent(), mE.getPoint().x, mE.getPoint().y);

                            }
                        }
                    }
                }
            });

            this.dateDu.addValueListener(new PropertyChangeListener() {
                public void propertyChange(PropertyChangeEvent evt) {
                    if (!dateDu.isEmpty()) {
                        Date d = dateDu.getValue();

                        if (d != null) {
                            Calendar cal = Calendar.getInstance();
                            cal.setTime(d);
                            if (selMois.getSelectedId() > 1
                                    && cal.get(Calendar.MONTH) + 2 != selMois.getSelectedId()) {

                                cal.set(Calendar.DAY_OF_MONTH, 1);
                                cal.set(Calendar.MONTH, selMois.getSelectedId() - 2);
                                System.err.println("Du " + cal.getTime());
                                dateDu.setValue(cal.getTime());
                            }
                        }
                    }
                }
            });

            this.dateAu.addValueListener(new PropertyChangeListener() {
                public void propertyChange(PropertyChangeEvent evt) {
                    if (!dateAu.isEmpty()) {
                        Date d = dateAu.getValue();
                        if (d != null) {
                            Calendar cal = Calendar.getInstance();
                            cal.setTime(d);
                            if (selMois.getSelectedId() > 1
                                    && cal.get(Calendar.MONTH) + 2 != selMois.getSelectedId()) {

                                // TODO checker l'annee
                                // TODO ajouter dans le isValidated du au compris dans le mois
                                // selectionne

                                // Calendar.getInstance().set(Calendar.DAY_OF_MONTH, maxDay);
                                cal.set(Calendar.DAY_OF_MONTH, 1);
                                cal.set(Calendar.MONTH, selMois.getSelectedId() - 2);
                                cal.set(Calendar.DAY_OF_MONTH, cal.getActualMaximum(Calendar.DAY_OF_MONTH));
                                System.err.println("Au " + cal.getTime());
                                dateAu.setValue(cal.getTime());
                            }
                        }
                    }
                }
            });

            this.addRequiredSQLObject(this.textAnnee, "ANNEE");
            this.addRequiredSQLObject(this.selMois, "ID_MOIS");
            this.addSQLObject(this.comboSelProfil, "ID_PROFIL_PAYE");

            this.addSQLObject(textCongesAcquis, "CONGES_ACQUIS");
            this.addSQLObject(textCotPat, "COT_PAT");
            this.addSQLObject(textCotSal, "COT_SAL");
            this.addSQLObject(textCSG, "CSG");
            this.addSQLObject(textNetAPayer, "NET_A_PAYER");
            this.addSQLObject(textNetImp, "NET_IMP");
            this.addSQLObject(textSalBrut, "SAL_BRUT");
            this.addSQLObject(textAcompte, "ACOMPTE");
            this.addSQLObject(this.selSalCombo, "ID_SALARIE");

            this.addRequiredSQLObject(this.dateDu, "DU");
            this.addRequiredSQLObject(this.dateAu, "AU");

            this.selSalCombo.setEditable(false);
            this.selSalCombo.setEnabled(false);
            this.selSalCombo.setButtonsVisible(false);
            // this.selSalCombo.setVisible(false);

            buttonImportProfil.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {

                    model.loadFromProfil(comboSelProfil.getSelectedId());
                }
            });
        }

        private boolean isDateValid() {

            String yearS = this.textAnnee.getText().trim();
            int annee = (yearS.length() == 0) ? 0 : Integer.parseInt(yearS);

            int mois = this.selMois.getSelectedId();
            // System.err.println("anne " + annee + " dernAnnee " + this.dernAnnee + " mois " +
            // mois + " dernMois " + this.dernMois);

            return ((this.dernAnnee == 0) ? true : annee > this.dernAnnee)
                    || ((this.dernMois == 0 || this.dernMois == 13) ? true : mois > this.dernMois);
        }

        @Override
        public synchronized ValidState getValidState() {
            // FIXME add fireValidChange()
            return super.getValidState().and(ValidState.createCached(isDateValid(), "Date invalide"));
        }

        public int insert(SQLRow order) {

            int id = super.insert(order);
            this.model.updateFields(id);
            return id;
        }

        @Override
        public void update() {
            super.update();
            this.model.updateFields(this.getSelectedID());
        }

        @Override
        public void select(SQLRowAccessor r) {

            // System.err.println("SELECT FICHE ID -> " + r.getID());
            super.select(r);

            if (r != null && r.getID() > 1) {
                this.model.setFicheID(r.getID());

                SQLTable tableSal = getTable().getBase().getTable("SALARIE");
                SQLRow rowSal = tableSal.getRow(r.getInt("ID_SALARIE"));

                this.dernMois = rowSal.getInt("DERNIER_MOIS");
                this.dernAnnee = rowSal.getInt("DERNIERE_ANNEE");

                this.selSalCombo.setVisible(((Boolean) r.getObject("VALIDE")).booleanValue());
                this.paneTreeLeft.setVisible(!((Boolean) r.getObject("VALIDE")).booleanValue());
                this.buttonValider.setVisible(!((Boolean) r.getObject("VALIDE")).booleanValue());
                setpDateEnabled(!((Boolean) r.getObject("VALIDE")).booleanValue());
            }
            this.selSalCombo.setEditable(false);
            this.selSalCombo.setEnabled(false);
            this.selMois.setButtonsVisible(false);
            this.selSalCombo.setButtonsVisible(false);
        }

        private void setpDateEnabled(boolean b) {

            // System.err.println("Set date enable --> " + b);
            this.selMois.setEditable(b);
            // this.selMois.setEnabled(b);

            this.textAnnee.setEditable(b);
            this.textAnnee.setEnabled(b);

            this.dateDu.setEditable(b);
            this.dateDu.setEnabled(b);

            this.dateAu.setEditable(b);
            this.dateAu.setEnabled(b);
        }

        private void validationFiche() {

            this.update();
            FichePayeSQLElement.validationFiche(this.getSelectedID());
        }

        protected SQLRowValues createDefaults() {

            System.err.println("**********Set Defaults on FichePaye.date");
            SQLRowValues rowVals = new SQLRowValues(getTable());
            Calendar cal = Calendar.getInstance();
            rowVals.put("ID_MOIS", cal.get(Calendar.MONTH) + 2);
            rowVals.put("ANNEE", cal.get(Calendar.YEAR));

            cal.set(Calendar.DAY_OF_MONTH, 1);
            rowVals.put("DU", new java.sql.Date(cal.getTime().getTime()));

            cal.set(Calendar.DAY_OF_MONTH, cal.getActualMaximum(Calendar.DAY_OF_MONTH));
            rowVals.put("AU", new java.sql.Date(cal.getTime().getTime()));
            return rowVals;
        }

    };
}

From source file:org.pentaho.reporting.engine.classic.demo.ancient.demo.swingicons.SwingIconsDemoPanel.java

/**
 * Constructs the demo application./*from w  ww . j a v  a 2 s. c  o  m*/
 */
public SwingIconsDemoPanel() {
    data = new SwingIconsDemoTableModel();

    setLayout(new BorderLayout());
    setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4));
    final JTable table = new JTable(data);
    table.setDefaultRenderer(Image.class, new ImageCellRenderer());
    table.setRowHeight(26);
    final JScrollPane scrollPane = new JScrollPane(table);
    add(scrollPane, BorderLayout.CENTER);

    final JPanel buttonPanel = new JPanel();
    buttonPanel.setLayout(new FlowLayout(FlowLayout.TRAILING));
    buttonPanel.add(new JButton(new SelectRepositoryFileAction()));
    add(buttonPanel, BorderLayout.SOUTH);

    loadData(findDataFile());
}

From source file:org.tellervo.desktop.tridasv2.ui.ComponentViewer.java

private void setupTable() {
    tableModel = new ElementListTableModel();
    table = new JXTable(tableModel);

    tableSorter = new ElementListTableSorter(tableModel, table);
    table.getTableHeader().addMouseListener(tableSorter); // add sorter & header renderer
    table.setColumnSelectionAllowed(false);
    table.setRowSelectionAllowed(true);/*from  www  .jav  a2s  . c o m*/

    // set our column widths
    ElementListTableModel.setupColumnWidths(table);

    table.setDefaultRenderer(Object.class, new ElementListCellRenderer(this, false));
    table.setDefaultRenderer(Boolean.class, new BooleanCellRenderer(this, false));

    // hide irrelevent columns
    TableColumnModelExt colmodel = (TableColumnModelExt) table.getColumnModel();
    table.setColumnControlVisible(true);
    colmodel.getColumnExt(I18n.getText("hidden.MostRecentVersion")).setVisible(false);
    colmodel.getColumnExt(I18n.getText("dbbrowser.n")).setVisible(false);
    colmodel.getColumnExt(I18n.getText("dbbrowser.rec")).setVisible(false);
    colmodel.getColumnExt(I18n.getText("dbbrowser.hash")).setVisible(false);

    // popup menu
    table.addMouseListener(new PopupListener() {
        @Override
        public void showPopup(MouseEvent e) {
            // only clicks on tables
            if (!(e.getSource() instanceof JTable))
                return;

            JTable table = (JTable) e.getSource();
            ElementListTableModel model = (ElementListTableModel) table.getModel();

            // get the row and sanity check
            int row = table.rowAtPoint(e.getPoint());
            if (row < 0 || row >= model.getRowCount())
                return;

            // select it?
            table.setRowSelectionInterval(row, row);

            // get the element
            Element element = model.getElementAt(row);

            // create and show the menu
            JPopupMenu popup = new ElementListPopupMenu(element, ComponentViewer.this);
            popup.show(table, e.getX(), e.getY());
        }
    });
}

From source file:org.tellervo.desktop.tridasv2.ui.ComponentViewerOld.java

private void setupTable() {
    tableModel = new ElementListTableModel();
    table = new JXTable(tableModel);

    tableSorter = new ElementListTableSorter(tableModel, table);
    table.getTableHeader().addMouseListener(tableSorter); // add sorter & header renderer
    table.setColumnSelectionAllowed(false);
    table.setRowSelectionAllowed(true);/*ww  w. j ava2s.  c  o m*/

    // set our column widths
    ElementListTableModel.setupColumnWidths(table);

    table.setDefaultRenderer(Object.class, new ElementListCellRenderer(this, false));
    table.setDefaultRenderer(Boolean.class, new BooleanCellRenderer(this, false));

    // hide irrelevent columns
    TableColumnModelExt colmodel = (TableColumnModelExt) table.getColumnModel();
    table.setColumnControlVisible(true);
    colmodel.getColumnExt(I18n.getText("hidden.MostRecentVersion")).setVisible(false);
    colmodel.getColumnExt(I18n.getText("dbbrowser.n")).setVisible(false);
    colmodel.getColumnExt(I18n.getText("dbbrowser.rec")).setVisible(false);
    colmodel.getColumnExt(I18n.getText("dbbrowser.hash")).setVisible(false);

    // popup menu
    table.addMouseListener(new PopupListener() {
        @Override
        public void showPopup(MouseEvent e) {
            // only clicks on tables
            if (!(e.getSource() instanceof JTable))
                return;

            JTable table = (JTable) e.getSource();
            ElementListTableModel model = (ElementListTableModel) table.getModel();

            // get the row and sanity check
            int row = table.rowAtPoint(e.getPoint());
            if (row < 0 || row >= model.getRowCount())
                return;

            // select it?
            table.setRowSelectionInterval(row, row);

            // get the element
            Element element = model.getElementAt(row);

            // create and show the menu
            JPopupMenu popup = new ElementListPopupMenu(element, ComponentViewerOld.this);
            popup.show(table, e.getX(), e.getY());
        }
    });
}