/src/mpv5/utils/ui/TextFieldUtils.java
Java | 121 lines | 67 code | 18 blank | 36 comment | 2 complexity | 50959b503749855f9687bb37daf5d38a MD5 | raw file
1 2/* 3 * This file is part of YaBS. 4 * 5 * YaBS is free software: you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License as published by 7 * the Free Software Foundation, either version 3 of the License, or 8 * (at your option) any later version. 9 * 10 * YaBS is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License 16 * along with YaBS. If not, see <http://www.gnu.org/licenses/>. 17 */ 18package mpv5.utils.ui; 19 20//~--- non-JDK imports -------------------------------------------------------- 21import mpv5.ui.beans.LabeledTextField; 22 23//~--- JDK imports ------------------------------------------------------------ 24 25import java.awt.Color; 26import java.awt.Component; 27 28import javax.swing.JComponent; 29import javax.swing.JTextField; 30import javax.swing.SwingWorker; 31import javax.swing.border.Border; 32import javax.swing.border.EtchedBorder; 33import javax.swing.border.LineBorder; 34 35/** 36 * 37 * 38 */ 39public class TextFieldUtils { 40 41 public static void blinkerGrey(LabeledTextField field) { 42 new blinker(field.getTextField(), 2, Color.GRAY).execute(); 43 } 44 45 /** 46 * Lets a text field blink 47 * @param field 48 */ 49 public static void blinkerRed(JTextField field) { 50 new blinker(field, 2, Color.RED).execute(); 51 } 52 53 /** 54 * Lets a text field blink 55 * @param lfield 56 */ 57 public static void blinkerRed(LabeledTextField lfield) { 58 new blinker(lfield.getTextField(), 2, Color.RED).execute(); 59 } 60 61 /** 62 * 63 * @param component 64 * @param color 65 */ 66 public static void blink(JComponent component, Color color) { 67 new blinker(component, 2, color).execute(); 68 } 69 70 public static void blinker(JTextField jTextField1, Color color) { 71 blink(jTextField1, color); 72 } 73 74 private static class blinker extends SwingWorker<Void, Void> { 75 76 private Color color; 77 private int count; 78 private JComponent fi; 79 80 private blinker(JComponent field, int i, Color col) { 81 fi = field; 82 count = i; 83 color = col; 84 } 85 86 @Override 87 protected Void doInBackground() throws Exception { 88 fi.setOpaque(true); 89 final Border oborder = fi.getBorder(); 90 final Color ocolor = fi.getBackground(); 91 boolean roundb = true; 92 int borderthickness = 1; 93 if (oborder instanceof LineBorder) { 94 roundb = ((LineBorder) oborder).getRoundedCorners(); 95 borderthickness = ((LineBorder) oborder).getThickness(); 96 } 97 98 for (int i = 0; i < count; i++) { 99 try { 100 Border etch = new LineBorder(color, borderthickness, roundb); 101 fi.setBorder(etch); 102 } catch (Exception e) { 103 fi.setBackground(color); 104 } 105 fi.validate(); 106 Thread.sleep(550); 107 fi.setBackground(ocolor); 108 try { 109 fi.setBorder(oborder); 110 } catch (Exception e) { 111 } 112 fi.validate(); 113 Thread.sleep(550); 114 } 115 116 return null; 117 } 118 } 119} 120//~ Formatted by Jindent --- http://www.jindent.com 121