use of java.awt.event.FocusListener in project triplea by triplea-game.
the class MapCreator method createPart1Panel.
private void createPart1Panel() {
panel1.removeAll();
panel1.setLayout(new BoxLayout(panel1, BoxLayout.PAGE_AXIS));
panel1.add(Box.createVerticalStrut(30));
final JTextArea text = new JTextArea(12, 10);
text.setWrapStyleWord(true);
text.setLineWrap(true);
text.setText("Welcome to Veqryn's map creator program for TripleA." + "\r\nThis program just runs utilities inside the triplea.jar file for you, and you could easily " + "run them yourself from the command line by reading the docs/developer_documentation.html" + "\r\n\r\nBefore you begin, go create a folder in your directory: Users\\yourname\\triplea\\maps" + "\r\nName the folder with a short name of your map, do not use any special characters in the name." + "\r\nNext, create 5 folders inside your map folder, with these names: " + "flags, units, baseTiles, reliefTiles, games" + "\r\nThen, create a text file and rename it \"map.properties\" or use one created by this utility." + "\r\n\r\nTo start the Map Utilities, have a png image of your map with just the territory borders " + "and nothing else. The borders must be in black (hex: 000000) and there should not be any " + "anti-aliasing (smoothing) of the lines or edges that stick out." + "\r\nCreate a small image of the map (approx 250 pixels wide) and name it \"smallMap.jpeg\"." + "\r\nPut these in the map's root folder. You can now start the map maker by clicking and filling " + "in the details below, before moving on to 'Step 2' and running the map utilities.");
final JScrollPane scrollText = new JScrollPane(text);
panel1.add(scrollText);
panel1.add(Box.createVerticalStrut(30));
panel1.add(new JLabel("Click button open up the readme file on how to make maps:"));
final JButton helpButton = new JButton("Start Tutorial / Show Help Document");
helpButton.addActionListener(e -> OpenFileUtility.openUrl(UrlConstants.MAP_MAKER_HELP.toString()));
panel1.add(helpButton);
panel1.add(Box.createVerticalStrut(30));
panel1.add(new JLabel("Click button to select where your map folder is:"));
final JButton mapFolderButton = new JButton("Select Map Folder");
mapFolderButton.addActionListener(SwingAction.of("Select Map Folder", e -> {
final String path = new FileSave("Where is your map's folder?", null, mapFolderLocation).getPathString();
if (path != null) {
final File mapFolder = new File(path);
if (mapFolder.exists()) {
mapFolderLocation = mapFolder;
System.setProperty(ToolArguments.MAP_FOLDER, mapFolderLocation.getPath());
}
}
}));
panel1.add(mapFolderButton);
panel1.add(Box.createVerticalStrut(30));
panel1.add(new JLabel("Set the unit scaling (unit image zoom): "));
panel1.add(new JLabel("Choose one of: 1.25, 1, 0.875, 0.8333, 0.75, 0.6666, 0.5625, 0.5"));
final JTextField unitZoomText = new JTextField("" + unitZoom);
unitZoomText.setMaximumSize(new Dimension(100, 20));
unitZoomText.addFocusListener(new FocusListener() {
@Override
public void focusGained(final FocusEvent e) {
}
@Override
public void focusLost(final FocusEvent e) {
try {
unitZoom = Math.min(4.0, Math.max(0.1, Double.parseDouble(unitZoomText.getText())));
System.setProperty(ToolArguments.UNIT_ZOOM, "" + unitZoom);
} catch (final Exception ex) {
// ignore malformed input
}
unitZoomText.setText("" + unitZoom);
}
});
panel1.add(unitZoomText);
panel1.add(Box.createVerticalStrut(30));
panel1.add(new JLabel("Set the width of the unit images: "));
final JTextField unitWidthText = new JTextField("" + unitWidth);
unitWidthText.setMaximumSize(new Dimension(100, 20));
unitWidthText.addFocusListener(new FocusListener() {
@Override
public void focusGained(final FocusEvent e) {
}
@Override
public void focusLost(final FocusEvent e) {
try {
unitWidth = Math.min(400, Math.max(1, Integer.parseInt(unitWidthText.getText())));
System.setProperty(ToolArguments.UNIT_WIDTH, "" + unitWidth);
} catch (final Exception ex) {
// ignore malformed input
}
unitWidthText.setText("" + unitWidth);
}
});
panel1.add(unitWidthText);
panel1.add(Box.createVerticalStrut(30));
panel1.add(new JLabel("Set the height of the unit images: "));
final JTextField unitHeightText = new JTextField("" + unitHeight);
unitHeightText.setMaximumSize(new Dimension(100, 20));
unitHeightText.addFocusListener(new FocusListener() {
@Override
public void focusGained(final FocusEvent e) {
}
@Override
public void focusLost(final FocusEvent e) {
try {
unitHeight = Math.min(400, Math.max(1, Integer.parseInt(unitHeightText.getText())));
System.setProperty(ToolArguments.UNIT_HEIGHT, "" + unitHeight);
} catch (final Exception ex) {
// ignore malformed input
}
unitHeightText.setText("" + unitHeight);
}
});
panel1.add(unitHeightText);
panel1.add(Box.createVerticalStrut(30));
panel1.add(new JLabel("<html>Here you can set the 'max memory' that utilities like the Polygon Grabber will use.<br>" + "This is useful is you have a very large map, or ever get any Java Heap Space errors.</html>"));
panel1.add(new JLabel("Set the amount of memory to use when running new processes (in megabytes [mb]):"));
final JTextField memoryText = new JTextField("" + (memoryInBytes / (1024 * 1024)));
memoryText.setMaximumSize(new Dimension(100, 20));
memoryText.addFocusListener(new FocusListener() {
@Override
public void focusGained(final FocusEvent e) {
}
@Override
public void focusLost(final FocusEvent e) {
try {
memoryInBytes = (long) 1024 * 1024 * Math.min(4096, Math.max(256, Integer.parseInt(memoryText.getText())));
} catch (final Exception ex) {
// ignore malformed input
}
memoryText.setText("" + (memoryInBytes / (1024 * 1024)));
}
});
panel1.add(memoryText);
panel1.add(Box.createVerticalStrut(30));
panel1.validate();
}
use of java.awt.event.FocusListener in project jmulticard by ctt-gob-es.
the class CustomDialogSmartcard method createAccessibilityButtonsPanel.
/**
* Se crea el panel de botones de accesibilidad.
*/
private void createAccessibilityButtonsPanel() {
this.accessibilityButtonsPanel = new JPanel(new GridBagLayout());
// Para el tooltip
final JWindow tip = new JWindow();
final JLabel tipText = new JLabel();
// Panel que va a contener los botones de accesibilidad
final JPanel panel = new JPanel(new GridBagLayout());
// Restricciones para los botones
final GridBagConstraints consButtons = new GridBagConstraints();
consButtons.fill = GridBagConstraints.BOTH;
consButtons.gridx = 0;
consButtons.gridy = 0;
consButtons.weightx = 1.0;
consButtons.weighty = 1.0;
// right padding
consButtons.insets = new Insets(0, 0, 0, 0);
// Restore button
final JPanel restorePanel = new JPanel();
// $NON-NLS-1$
final ImageIcon imageIconRestore = new ImageIcon(CustomDialogSmartcard.class.getResource("/images/restore.png"));
this.restoreButton = new JButton(imageIconRestore);
this.restoreButton.setMnemonic(KeyEvent.VK_R);
// $NON-NLS-1$
this.restoreButton.setToolTipText(Messages.getString("Wizard.restaurar.description"));
this.restoreButton.getAccessibleContext().setAccessibleName(this.restoreButton.getToolTipText());
this.restoreButton.addFocusListener(new FocusListener() {
/**
* Evento que se produce cuando el componente pierde el foco.
*/
@Override
public void focusLost(final FocusEvent e) {
Utils.showToolTip(false, tip, CustomDialogSmartcard.this.getRestoreButton(), tipText);
}
/**
* Evento que se produce cuando el componente tiene el foco.
*/
@Override
public void focusGained(final FocusEvent e) {
Utils.showToolTip(true, tip, CustomDialogSmartcard.this.getRestoreButton(), tipText);
}
});
final Dimension dimension = new Dimension(20, 20);
this.restoreButton.setPreferredSize(dimension);
this.restoreButton.addKeyListener(new KeyListener() {
@Override
public void keyTyped(final KeyEvent arg0) {
/* No necesario */
}
@Override
public void keyReleased(final KeyEvent arg0) {
/* No necesario */
}
@Override
public void keyPressed(final KeyEvent ke) {
if (10 == ke.getKeyCode()) {
getRestoreButton().doClick();
}
}
});
// $NON-NLS-1$
this.restoreButton.setName("restaurar");
restorePanel.add(this.restoreButton);
this.restoreButton.addActionListener(new ActionListener() {
/**
* Accion del boton.
*/
@Override
public void actionPerformed(final ActionEvent e) {
restaurarActionPerformed();
}
});
Utils.remarcar(this.restoreButton);
panel.add(restorePanel, consButtons);
consButtons.gridx = 1;
// right padding
consButtons.insets = new Insets(0, 0, 0, 0);
// Maximize button
final JPanel maximizePanel = new JPanel();
// $NON-NLS-1$
final ImageIcon imageIconMaximize = new ImageIcon(CustomDialogSmartcard.class.getResource("/images/maximize.png"));
this.maximizeButton = new JButton(imageIconMaximize);
this.maximizeButton.setMnemonic(KeyEvent.VK_M);
// $NON-NLS-1$
this.maximizeButton.setToolTipText(Messages.getString("Wizard.maximizar.description"));
this.maximizeButton.getAccessibleContext().setAccessibleName(this.maximizeButton.getToolTipText());
this.maximizeButton.addKeyListener(new KeyListener() {
@Override
public void keyTyped(final KeyEvent arg0) {
/* No necesario */
}
@Override
public void keyReleased(final KeyEvent arg0) {
/* No necesario */
}
@Override
public void keyPressed(final KeyEvent ke) {
if (10 == ke.getKeyCode()) {
getMaximizeButton().doClick();
}
}
});
// $NON-NLS-1$
this.maximizeButton.setName("maximizar");
// Se asigna una dimension por defecto
this.maximizeButton.setPreferredSize(dimension);
Utils.remarcar(this.maximizeButton);
maximizePanel.add(this.maximizeButton);
this.maximizeButton.addFocusListener(new FocusListener() {
/**
* Evento que se produce cuando el componente pierde el foco.
*/
@Override
public void focusLost(final FocusEvent e) {
Utils.showToolTip(false, tip, CustomDialogSmartcard.this.getMaximizeButton(), tipText);
}
/**
* Evento que se produce cuando el componente tiene el foco.
*/
@Override
public void focusGained(final FocusEvent e) {
Utils.showToolTip(true, tip, CustomDialogSmartcard.this.getMaximizeButton(), tipText);
}
});
this.maximizeButton.addActionListener(new ActionListener() {
/**
* Accion del boton.
*/
@Override
public void actionPerformed(final ActionEvent e) {
maximizarActionPerformed();
}
});
panel.add(maximizePanel, consButtons);
// Se anade al panel general
// Restricciones para el panel de botones
final GridBagConstraints c = new GridBagConstraints();
c.fill = GridBagConstraints.NONE;
c.gridx = 0;
c.gridy = 0;
c.weightx = 1.0;
c.weighty = 1.0;
c.insets = new Insets(0, 0, 0, 0);
c.anchor = GridBagConstraints.SOUTH;
this.accessibilityButtonsPanel.add(panel, c);
// Habilitado/Deshabilitado de botones restaurar/maximizar
if (GeneralConfig.isMaximized()) {
// Se deshabilita el boton de maximizado
this.maximizeButton.setEnabled(false);
// Se habilita el boton de restaurar
this.restoreButton.setEnabled(true);
} else {
// Se habilita el boton de maximizado
this.maximizeButton.setEnabled(true);
// Se deshabilita el boton de restaurar
this.restoreButton.setEnabled(false);
}
}
use of java.awt.event.FocusListener in project runelite by runelite.
the class ConfigPanel method openGroupConfigPanel.
private void openGroupConfigPanel(Config config, ConfigDescriptor cd, ConfigManager configManager) {
scrollBarPosition = getScrollPane().getVerticalScrollBar().getValue();
removeAll();
String name = cd.getGroup().name() + " Configuration";
JLabel title = new JLabel(name);
title.setToolTipText(cd.getGroup().description());
add(title, SwingConstants.CENTER);
for (ConfigItemDescriptor cid : cd.getItems()) {
if (cid.getItem().hidden()) {
continue;
}
JPanel item = new JPanel();
item.setLayout(new BorderLayout());
name = cid.getItem().name();
JLabel configEntryName = new JLabel(name);
configEntryName.setToolTipText("<html>" + name + ":<br>" + cid.getItem().description() + "</html>");
item.add(configEntryName, BorderLayout.CENTER);
if (cid.getType() == boolean.class) {
JCheckBox checkbox = new JCheckBox();
checkbox.setSelected(Boolean.parseBoolean(configManager.getConfiguration(cd.getGroup().keyName(), cid.getItem().keyName())));
checkbox.addActionListener(ae -> changeConfiguration(checkbox, cd, cid));
item.add(checkbox, BorderLayout.EAST);
}
if (cid.getType() == int.class) {
int value = Integer.parseInt(configManager.getConfiguration(cd.getGroup().keyName(), cid.getItem().keyName()));
SpinnerModel model = new SpinnerNumberModel(value, 0, Integer.MAX_VALUE, 1);
JSpinner spinner = new JSpinner(model);
Component editor = spinner.getEditor();
JFormattedTextField spinnerTextField = ((JSpinner.DefaultEditor) editor).getTextField();
spinnerTextField.setColumns(SPINNER_FIELD_WIDTH);
spinner.addChangeListener(ce -> changeConfiguration(spinner, cd, cid));
item.add(spinner, BorderLayout.EAST);
}
if (cid.getType() == String.class) {
JTextField textField = new JTextField("", TEXT_FIELD_WIDTH);
textField.setText(configManager.getConfiguration(cd.getGroup().keyName(), cid.getItem().keyName()));
textField.addFocusListener(new FocusListener() {
@Override
public void focusGained(FocusEvent e) {
}
@Override
public void focusLost(FocusEvent e) {
changeConfiguration(textField, cd, cid);
textField.setToolTipText(textField.getText());
}
});
textField.setToolTipText(textField.getText());
item.add(textField, BorderLayout.EAST);
}
if (cid.getType() == Color.class) {
JButton colorPicker = new JButton("Pick a color");
colorPicker.setFocusable(false);
colorPicker.setBackground(Color.decode(configManager.getConfiguration(cd.getGroup().keyName(), cid.getItem().keyName())));
colorPicker.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
final JFrame parent = new JFrame();
JColorChooser jColorChooser = new JColorChooser(Color.decode(configManager.getConfiguration(cd.getGroup().keyName(), cid.getItem().keyName())));
jColorChooser.getSelectionModel().addChangeListener(e1 -> colorPicker.setBackground(jColorChooser.getColor()));
parent.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
changeConfiguration(jColorChooser, cd, cid);
}
});
parent.add(jColorChooser);
parent.pack();
parent.setVisible(true);
}
});
item.add(colorPicker, BorderLayout.EAST);
}
if (cid.getType() == Dimension.class) {
JPanel dimensionPanel = new JPanel();
dimensionPanel.setLayout(new BorderLayout());
String str = configManager.getConfiguration(cd.getGroup().keyName(), cid.getItem().keyName());
String[] splitStr = str.split("x");
int width = Integer.parseInt(splitStr[0]);
int height = Integer.parseInt(splitStr[1]);
SpinnerModel widthModel = new SpinnerNumberModel(width, 0, Integer.MAX_VALUE, 1);
JSpinner widthSpinner = new JSpinner(widthModel);
Component widthEditor = widthSpinner.getEditor();
JFormattedTextField widthSpinnerTextField = ((JSpinner.DefaultEditor) widthEditor).getTextField();
widthSpinnerTextField.setColumns(4);
SpinnerModel heightModel = new SpinnerNumberModel(height, 0, Integer.MAX_VALUE, 1);
JSpinner heightSpinner = new JSpinner(heightModel);
Component heightEditor = heightSpinner.getEditor();
JFormattedTextField heightSpinnerTextField = ((JSpinner.DefaultEditor) heightEditor).getTextField();
heightSpinnerTextField.setColumns(4);
ChangeListener listener = e -> configManager.setConfiguration(cd.getGroup().keyName(), cid.getItem().keyName(), widthSpinner.getValue() + "x" + heightSpinner.getValue());
widthSpinner.addChangeListener(listener);
heightSpinner.addChangeListener(listener);
dimensionPanel.add(widthSpinner, BorderLayout.WEST);
dimensionPanel.add(new JLabel(" x "), BorderLayout.CENTER);
dimensionPanel.add(heightSpinner, BorderLayout.EAST);
item.add(dimensionPanel, BorderLayout.EAST);
}
if (cid.getType().isEnum()) {
Class<? extends Enum> type = (Class<? extends Enum>) cid.getType();
JComboBox box = new JComboBox(type.getEnumConstants());
box.setFocusable(false);
// sorry but this is the way to keep the size of the combobox in check.
box.setPrototypeDisplayValue("XXXXXXXX");
try {
Enum selectedItem = Enum.valueOf(type, configManager.getConfiguration(cd.getGroup().keyName(), cid.getItem().keyName()));
box.setSelectedItem(selectedItem);
box.setToolTipText(selectedItem.toString());
} catch (IllegalArgumentException ex) {
log.debug("invalid seleced item", ex);
}
box.addItemListener(e -> {
if (e.getStateChange() == ItemEvent.SELECTED) {
changeConfiguration(box, cd, cid);
box.setToolTipText(box.getSelectedItem().toString());
}
});
item.add(box, BorderLayout.EAST);
}
add(item);
}
JButton resetButton = new JButton("Reset");
resetButton.addActionListener((e) -> {
configManager.setDefaultConfiguration(config, true);
// Reload configuration panel
openGroupConfigPanel(config, cd, configManager);
});
add(resetButton);
JButton backButton = new JButton("Back");
backButton.addActionListener(e -> openConfigList());
add(backButton);
revalidate();
getScrollPane().getVerticalScrollBar().setValue(0);
}
use of java.awt.event.FocusListener in project browsermator by pcalkins.
the class ActionView method AddSetVarFocusListeners.
public void AddSetVarFocusListeners(SeleniumTestTool STAppFrame, SeleniumTestToolData STAppData, Procedure newbug, Action action) {
addJTextPasswordFocusListener(new FocusListener() {
@Override
public void focusGained(FocusEvent e) {
}
@Override
public void focusLost(FocusEvent e) {
}
});
addJTextFieldFocusListener(new FocusListener() {
@Override
public void focusGained(FocusEvent e) {
STAppFrame.ShowPlaceStoredVariableButton(true, newbug.index, action.index, 1);
}
@Override
public void focusLost(FocusEvent e) {
STAppFrame.ShowPlaceStoredVariableButton(false, newbug.index, action.index, 1);
}
});
addJTextField2FocusListener(new FocusListener() {
@Override
public void focusGained(FocusEvent e) {
STAppFrame.ShowPlaceStoredVariableButton(true, newbug.index, action.index, 2);
}
@Override
public void focusLost(FocusEvent e) {
STAppFrame.ShowPlaceStoredVariableButton(false, newbug.index, action.index, 2);
}
});
}
use of java.awt.event.FocusListener in project i2p.i2p by i2p.
the class TrayManager method getSwingTrayIcon.
private TrayIcon getSwingTrayIcon(String tooltip) throws AWTException {
// A JPopupMenu by itself is hard to get rid of,
// so we hang it off a zero-size, undecorated JFrame.
// http://stackoverflow.com/questions/1498789/jpopupmenu-behavior
// http://stackoverflow.com/questions/2581314/how-do-you-hide-a-swing-popup-when-you-click-somewhere-else
final JFrame frame = new JFrame();
// http://stackoverflow.com/questions/2011601/jframe-without-frame-border-maximum-button-minimum-button-and-frame-icon
frame.setUndecorated(true);
frame.setMinimumSize(new Dimension(0, 0));
frame.setSize(0, 0);
final JPopupMenu menu = getSwingMainMenu();
menu.setFocusable(true);
frame.add(menu);
TrayIcon ti = new TrayIcon(getTrayImage(), tooltip, null);
ti.addMouseListener(new MouseListener() {
public void mouseClicked(MouseEvent e) {
}
public void mouseEntered(MouseEvent e) {
}
public void mouseExited(MouseEvent e) {
}
public void mousePressed(MouseEvent e) {
handle(e);
}
public void mouseReleased(MouseEvent e) {
handle(e);
}
private void handle(MouseEvent e) {
// menu visible check is never true
if (!frame.isVisible()) /* || !menu.isVisible() */
{
frame.setLocation(e.getX(), e.getY());
frame.setVisible(true);
menu.show(frame, 0, 0);
}
updateMenu();
}
});
menu.addPopupMenuListener(new PopupMenuListener() {
public void popupMenuCanceled(PopupMenuEvent e) {
/* frame.setVisible(false); */
}
public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {
frame.setVisible(false);
}
public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
}
});
// this is to make it go away when we click elsewhere
// doesn't do anything
menu.addFocusListener(new FocusListener() {
public void focusGained(FocusEvent e) {
}
public void focusLost(FocusEvent e) {
frame.setVisible(false);
}
});
// this is to make it go away when we hit escape
// doesn't do anything
menu.addMenuKeyListener(new MenuKeyListener() {
public void menuKeyPressed(MenuKeyEvent e) {
}
public void menuKeyReleased(MenuKeyEvent e) {
}
public void menuKeyTyped(MenuKeyEvent e) {
if (e.getKeyChar() == (char) 0x1b)
frame.setVisible(false);
}
});
return ti;
}
Aggregations