PageRenderTime 33ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/src/mpv5/utils/renderer/LazyCellEditor.java

http://mp-rechnungs-und-kundenverwaltung.googlecode.com/
Java | 76 lines | 47 code | 10 blank | 19 comment | 5 complexity | 5a4219d43acd3e4dd0c7be04eaa1f361 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. * This file is part of YaBS.
  3. *
  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. *
  9. * YaBS is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with YaBS. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. package mpv5.utils.renderer;
  18. import java.awt.event.MouseEvent;
  19. import java.util.EventObject;
  20. import javax.swing.DefaultCellEditor;
  21. import javax.swing.JComboBox;
  22. import javax.swing.JTextField;
  23. import javax.swing.SwingUtilities;
  24. /**
  25. *
  26. */
  27. public class LazyCellEditor extends DefaultCellEditor {
  28. public LazyCellEditor(JComboBox c) {
  29. super(c);
  30. }
  31. public LazyCellEditor(final JTextField tf) {
  32. super(tf);
  33. super.setClickCountToStart(1);
  34. delegate = new EditorDelegate() {
  35. boolean isMousePressed = false;
  36. @Override
  37. public void setValue(Object value) {
  38. if(isMousePressed && value != null){
  39. SwingUtilities.invokeLater(new Runnable() {
  40. public void run() {
  41. tf.selectAll();
  42. }
  43. });
  44. tf.setText(value.toString());
  45. } else {
  46. tf.setText(""); }
  47. }
  48. @Override
  49. public Object getCellEditorValue() {
  50. return tf.getText();
  51. }
  52. @Override
  53. public boolean isCellEditable(EventObject anEvent) {
  54. if (anEvent instanceof MouseEvent) {
  55. isMousePressed = true;
  56. return ((MouseEvent) anEvent).getClickCount() >= clickCountToStart;
  57. }
  58. isMousePressed = false;
  59. return true;
  60. }
  61. };
  62. }
  63. public boolean stopCellEditingSilent() {
  64. return true;
  65. }
  66. }