View Javadoc
1   package fr.ifremer.tutti.ui.swing.content.protocol.rtp;
2   
3   /*
4    * #%L
5    * Tutti :: UI
6    * $Id:$
7    * $HeadURL:$
8    * %%
9    * Copyright (C) 2012 - 2016 Ifremer
10   * %%
11   * This program is free software: you can redistribute it and/or modify
12   * it under the terms of the GNU General Public License as
13   * published by the Free Software Foundation, either version 3 of the
14   * License, or (at your option) any later version.
15   * 
16   * This program is distributed in the hope that it will be useful,
17   * but WITHOUT ANY WARRANTY; without even the implied warranty of
18   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19   * GNU General Public License for more details.
20   * 
21   * You should have received a copy of the GNU General Public
22   * License along with this program.  If not, see
23   * <http://www.gnu.org/licenses/gpl-3.0.html>.
24   * #L%
25   */
26  
27  import fr.ifremer.tutti.ui.swing.content.protocol.EditProtocolSpeciesTableModel;
28  import fr.ifremer.tutti.ui.swing.content.protocol.EditProtocolUI;
29  
30  import javax.swing.AbstractCellEditor;
31  import javax.swing.JTable;
32  import javax.swing.border.LineBorder;
33  import javax.swing.event.CellEditorListener;
34  import javax.swing.event.ChangeEvent;
35  import javax.swing.table.TableCellEditor;
36  import java.awt.Color;
37  import java.awt.Component;
38  import java.util.EventObject;
39  
40  /**
41   * Created on 14/01/16.
42   *
43   * @author Tony Chemit - chemit@codelutin.com
44   * @since 4.4
45   */
46  public class RtpCellEditor extends AbstractCellEditor implements TableCellEditor {
47  
48      private static final long serialVersionUID = 1L;
49  
50      public static TableCellEditor newEditor(EditProtocolUI ui) {
51          return new RtpCellEditor(ui);
52      }
53  
54      protected final RtpButton editorButton;
55  
56      public RtpCellEditor(EditProtocolUI context) {
57  
58          editorButton = new RtpButton(context);
59          editorButton.setBorder(new LineBorder(Color.BLACK));
60          addCellEditorListener(new CellEditorListener() {
61              @Override
62              public void editingStopped(ChangeEvent e) {
63                  editorButton.setSelected(false);
64              }
65  
66              @Override
67              public void editingCanceled(ChangeEvent e) {
68                  editorButton.setSelected(false);
69              }
70          });
71      }
72  
73      @Override
74      public Component getTableCellEditorComponent(JTable table,
75                                                   Object value,
76                                                   boolean isSelected,
77                                                   int row,
78                                                   int column) {
79  
80          EditProtocolSpeciesTableModel tableModel = (EditProtocolSpeciesTableModel) table.getModel();
81          editorButton.init(tableModel, table.getRowSorter(), row);
82          return editorButton;
83  
84      }
85  
86      @Override
87      public boolean shouldSelectCell(EventObject anEvent) {
88          return false;
89      }
90  
91      @Override
92      public Object getCellEditorValue() {
93  
94          return true;
95      }
96  
97  }