PageRenderTime 18ms CodeModel.GetById 12ms RepoModel.GetById 1ms app.codeStats 0ms

/src/mpv5/utils/renderer/TableCellRendererForProducts.java

http://mp-rechnungs-und-kundenverwaltung.googlecode.com/
Java | 82 lines | 45 code | 9 blank | 28 comment | 3 complexity | 2629aa225de4649be5586a832c31cb31 MD5 | raw file
Possible License(s): LGPL-3.0, Apache-2.0, GPL-3.0, GPL-2.0, AGPL-3.0, JSON, BSD-3-Clause
  1. /*
  2. *
  3. This file is part of YaBS.
  4. YaBS is free software: you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation, either version 3 of the License, or
  7. (at your option) any later version.
  8. YaBS is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with YaBS. If not, see <http://www.gnu.org/licenses/>.
  14. *
  15. */
  16. package mpv5.utils.renderer;
  17. import java.awt.Color;
  18. import java.awt.Component;
  19. import javax.swing.JFormattedTextField;
  20. import javax.swing.JTable;
  21. import javax.swing.table.DefaultTableCellRenderer;
  22. import javax.swing.table.TableColumn;
  23. import mpv5.db.objects.Product;
  24. public class TableCellRendererForProducts extends DefaultTableCellRenderer {
  25. private final DefaultTableCellRenderer adaptee = new DefaultTableCellRenderer();
  26. private final JTable t;
  27. /**
  28. *
  29. * @param t
  30. * @param color
  31. */
  32. public TableCellRendererForProducts(JTable t) {
  33. super();
  34. this.t = t;
  35. }
  36. /**
  37. * Set this renderer to the given column + editor
  38. * @param column
  39. */
  40. public void setRendererTo(int column) {
  41. TableColumn col = t.getColumnModel().getColumn(t.getColumnModel().getColumnIndex(t.getModel().getColumnName(column)));
  42. col.setCellEditor(new TableCellEditorForDezimal(new JFormattedTextField()));
  43. col.setCellRenderer(this);
  44. }
  45. @Override
  46. protected void setValue(Object value) {
  47. if (value instanceof Product) {
  48. value = ((Product)value).__getCnumber();
  49. }
  50. super.setValue(value);
  51. }
  52. @Override
  53. public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int col) {
  54. if (value instanceof Product) {
  55. value = ((Product)value).__getCnumber();
  56. }
  57. adaptee.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, col);
  58. setForeground(adaptee.getForeground());
  59. setBackground(adaptee.getBackground());
  60. setBorder(adaptee.getBorder());
  61. setFont(adaptee.getFont());
  62. setText(adaptee.getText());
  63. if (hasFocus) {
  64. setBackground(Color.BLUE);
  65. setForeground(Color.WHITE);
  66. }
  67. return this;
  68. }
  69. }