de.fhg.iais.asc.ui.i18n.LocalizedUI.java Source code

Java tutorial

Introduction

Here is the source code for de.fhg.iais.asc.ui.i18n.LocalizedUI.java

Source

package de.fhg.iais.asc.ui.i18n;

/******************************************************************************
 * Copyright 2011 (c) Fraunhofer IAIS Netmedia  http://www.iais.fraunhofer.de *
 * ************************************************************************** *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may    *
 * not use this file except in compliance with the License.                   *
 * You may obtain a copy of the License at                                    *
 * http://www.apache.org/licenses/LICENSE-2.0                                 *
 * Unless required by applicable law or agreed to in writing,                 *
 * software distributed under the License is distributed on an "AS IS" BASIS, *
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   *
 * See the License for the specific language governing permissions and        *
 * limitations under the License.                                             *
 ******************************************************************************/

import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JLabel;
import javax.swing.JRadioButton;

import org.apache.commons.lang.StringUtils;

public final class LocalizedUI {
    private LocalizedUI() {
    }

    public static JButton createButton(String key, ActionListener listener) {
        key = "Button." + key;
        String tooltipText = Messages.getString("Tooltip." + key, "");

        JButton button = new JButton(Messages.getString(key));
        if (!StringUtils.isEmpty(tooltipText)) {
            button.setToolTipText(tooltipText);
        }

        if (listener != null) {
            button.addActionListener(listener);
        }

        return button;
    }

    public static JLabel createLabel(String key) {
        key = "Label." + key;
        String tooltipText = Messages.getString("Tooltip." + key, "");

        JLabel label = new JLabel(Messages.getString(key));
        if (!StringUtils.isEmpty(tooltipText)) {
            label.setToolTipText(tooltipText);
        }

        return label;
    }

    public static JCheckBox createCheckbox(String key, ActionListener listener) {
        key = "Checkbox." + key;
        String tooltipText = Messages.getString("Tooltip." + key, "");

        JCheckBox checkBox = new JCheckBox(Messages.getString(key));
        if (!StringUtils.isEmpty(tooltipText)) {
            checkBox.setToolTipText(tooltipText);
        }

        if (listener != null) {
            checkBox.addActionListener(listener);
        }

        return checkBox;
    }

    public static JRadioButton createRadioButton(String key) {
        key = "Radiobutton." + key;
        String tooltipText = Messages.getString("Tooltip." + key, "");

        JRadioButton radioButton = new JRadioButton(Messages.getString(key));
        if (!StringUtils.isEmpty(tooltipText)) {
            radioButton.setToolTipText(tooltipText);
        }

        return radioButton;
    }

}