PageRenderTime 95ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/src/mpv5/utils/ui/TextFieldUtils.java

http://mp-rechnungs-und-kundenverwaltung.googlecode.com/
Java | 121 lines | 67 code | 18 blank | 36 comment | 2 complexity | 50959b503749855f9687bb37daf5d38a 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.ui;
  18. //~--- non-JDK imports --------------------------------------------------------
  19. import mpv5.ui.beans.LabeledTextField;
  20. //~--- JDK imports ------------------------------------------------------------
  21. import java.awt.Color;
  22. import java.awt.Component;
  23. import javax.swing.JComponent;
  24. import javax.swing.JTextField;
  25. import javax.swing.SwingWorker;
  26. import javax.swing.border.Border;
  27. import javax.swing.border.EtchedBorder;
  28. import javax.swing.border.LineBorder;
  29. /**
  30. *
  31. *
  32. */
  33. public class TextFieldUtils {
  34. public static void blinkerGrey(LabeledTextField field) {
  35. new blinker(field.getTextField(), 2, Color.GRAY).execute();
  36. }
  37. /**
  38. * Lets a text field blink
  39. * @param field
  40. */
  41. public static void blinkerRed(JTextField field) {
  42. new blinker(field, 2, Color.RED).execute();
  43. }
  44. /**
  45. * Lets a text field blink
  46. * @param lfield
  47. */
  48. public static void blinkerRed(LabeledTextField lfield) {
  49. new blinker(lfield.getTextField(), 2, Color.RED).execute();
  50. }
  51. /**
  52. *
  53. * @param component
  54. * @param color
  55. */
  56. public static void blink(JComponent component, Color color) {
  57. new blinker(component, 2, color).execute();
  58. }
  59. public static void blinker(JTextField jTextField1, Color color) {
  60. blink(jTextField1, color);
  61. }
  62. private static class blinker extends SwingWorker<Void, Void> {
  63. private Color color;
  64. private int count;
  65. private JComponent fi;
  66. private blinker(JComponent field, int i, Color col) {
  67. fi = field;
  68. count = i;
  69. color = col;
  70. }
  71. @Override
  72. protected Void doInBackground() throws Exception {
  73. fi.setOpaque(true);
  74. final Border oborder = fi.getBorder();
  75. final Color ocolor = fi.getBackground();
  76. boolean roundb = true;
  77. int borderthickness = 1;
  78. if (oborder instanceof LineBorder) {
  79. roundb = ((LineBorder) oborder).getRoundedCorners();
  80. borderthickness = ((LineBorder) oborder).getThickness();
  81. }
  82. for (int i = 0; i < count; i++) {
  83. try {
  84. Border etch = new LineBorder(color, borderthickness, roundb);
  85. fi.setBorder(etch);
  86. } catch (Exception e) {
  87. fi.setBackground(color);
  88. }
  89. fi.validate();
  90. Thread.sleep(550);
  91. fi.setBackground(ocolor);
  92. try {
  93. fi.setBorder(oborder);
  94. } catch (Exception e) {
  95. }
  96. fi.validate();
  97. Thread.sleep(550);
  98. }
  99. return null;
  100. }
  101. }
  102. }
  103. //~ Formatted by Jindent --- http://www.jindent.com