Gridarta Editor
TextComponentUtils.java
Go to the documentation of this file.
1 /*
2  * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games.
3  * Copyright (C) 2000-2015 The Gridarta Developers.
4  *
5  * This program 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 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program 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 along
16  * with this program; if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  */
19 
20 package net.sf.gridarta.gui.utils;
21 
22 import java.awt.Component;
23 import java.awt.event.ActionEvent;
24 import java.awt.event.ActionListener;
25 import java.awt.event.FocusEvent;
26 import java.awt.event.FocusListener;
27 import javax.swing.JTextField;
28 import javax.swing.text.JTextComponent;
29 import org.jetbrains.annotations.NotNull;
30 
35 public class TextComponentUtils {
36 
40  private TextComponentUtils() {
41  }
42 
48  public static void setAutoSelectOnFocus(@NotNull final JTextComponent textComponent) {
49  final FocusListener focusListener = new FocusListener() {
50 
51  @Override
52  public void focusGained(@NotNull final FocusEvent e) {
53  textComponent.selectAll();
54  }
55 
56  @Override
57  public void focusLost(@NotNull final FocusEvent e) {
58  // ignore
59  }
60 
61  };
62  textComponent.addFocusListener(focusListener);
63  }
64 
70  public static void setActionNextFocus(@NotNull final JTextField textField, @NotNull final Component nextComponent) {
71  final ActionListener actionListener = new ActionListener() {
72 
73  @Override
74  public void actionPerformed(@NotNull final ActionEvent e) {
75  nextComponent.requestFocusInWindow();
76  }
77 
78  };
79  textField.addActionListener(actionListener);
80  }
81 
82 }
net.sf.gridarta.gui.utils.TextComponentUtils.TextComponentUtils
TextComponentUtils()
Definition: TextComponentUtils.java:40
net.sf.gridarta.gui.utils.TextComponentUtils.setActionNextFocus
static void setActionNextFocus(@NotNull final JTextField textField, @NotNull final Component nextComponent)
Definition: TextComponentUtils.java:70
net.sf.gridarta.gui.utils.TextComponentUtils.setAutoSelectOnFocus
static void setAutoSelectOnFocus(@NotNull final JTextComponent textComponent)
Definition: TextComponentUtils.java:48
net.sf.gridarta.gui.utils.TextComponentUtils
Definition: TextComponentUtils.java:35