Gridarta Editor
ActionBuilderUtils.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.utils;
21 
22 import java.util.MissingResourceException;
23 import javax.swing.JLabel;
24 import net.sf.japi.swing.action.ActionBuilder;
25 import org.jetbrains.annotations.NotNull;
26 
31 public class ActionBuilderUtils {
32 
36  private ActionBuilderUtils() {
37  }
38 
46  public static boolean getBoolean(@NotNull final ActionBuilder actionBuilder, @NotNull final String key) {
47  final String value = actionBuilder.getString(key);
48  return value != null && Boolean.parseBoolean(value);
49  }
50 
59  public static int getInt(@NotNull final ActionBuilder actionBuilder, @NotNull final String key, final int defaultValue) {
60  final String value = actionBuilder.getString(key);
61  if (value == null) {
62  return defaultValue;
63  }
64 
65  return NumberUtils.parseInt(value, defaultValue);
66  }
67 
75  @NotNull
76  public static String getString(@NotNull final ActionBuilder actionBuilder, @NotNull final String key, @NotNull final String defaultValue) {
77  final String value = actionBuilder.getString(key);
78  return value == null ? defaultValue : value;
79  }
80 
88  @NotNull
89  public static String getString(@NotNull final ActionBuilder actionBuilder, @NotNull final String key) {
90  final String value = actionBuilder.getString(key);
91  if (value == null) {
92  throw new MissingResourceException("missing resource key: " + key, ActionBuilderUtils.class.getName(), key);
93  }
94  return value;
95  }
96 
105  @NotNull
106  public static String format(@NotNull final ActionBuilder actionBuilder, @NotNull final String key, @NotNull final Object... args) {
107  final String value = actionBuilder.format(key, args);
108  if (value == null) {
109  throw new MissingResourceException("missing resource key: " + key, ActionBuilderUtils.class.getName(), key);
110  }
111  return value;
112  }
113 
122  @NotNull
123  public static JLabel newLabel(@NotNull final ActionBuilder actionBuilder, @NotNull final String key) {
124  final JLabel label = new JLabel(getString(actionBuilder, key));
125  label.setToolTipText(actionBuilder.getString(key + ".shortdescription"));
126  return label;
127  }
128 
129 }
static int getInt(@NotNull final ActionBuilder actionBuilder, @NotNull final String key, final int defaultValue)
Returns the value of a key as an.
Utility class for parsing strings into numbers.
static String getString(@NotNull final ActionBuilder actionBuilder, @NotNull final String key, @NotNull final String defaultValue)
Returns the value of a key.
static int parseInt(@NotNull final String s)
Parses an integer string.
ActionBuilderUtils()
Private constructor to prevent instantiation.
static String getString(@NotNull final ActionBuilder actionBuilder, @NotNull final String key)
Returns the value of a key.
Utility class for ActionBuilder related functions.
static boolean getBoolean(@NotNull final ActionBuilder actionBuilder, @NotNull final String key)
Returns the value of a key as a.
static JLabel newLabel(@NotNull final ActionBuilder actionBuilder, @NotNull final String key)
Creates a new JLabel from a resource key.
static String format(@NotNull final ActionBuilder actionBuilder, @NotNull final String key, @NotNull final Object... args)
Returns the value of a key.