All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.datacleaner.widgets.DCLabel Maven / Gradle / Ivy

There is a newer version: 6.0.0
Show newest version
/**
 * DataCleaner (community edition)
 * Copyright (C) 2014 Neopost - Customer Information Management
 *
 * This copyrighted material is made available to anyone wishing to use, modify,
 * copy, or redistribute it subject to the terms and conditions of the GNU
 * Lesser General Public License, as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License
 * for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this distribution; if not, write to:
 * Free Software Foundation, Inc.
 * 51 Franklin Street, Fifth Floor
 * Boston, MA  02110-1301  USA
 */
package org.datacleaner.widgets;

import java.awt.Color;

import javax.swing.Icon;
import javax.swing.JLabel;
import javax.swing.SwingConstants;

import org.datacleaner.util.WidgetUtils;

/**
 * A convenient, decorated {@link JLabel} which supports multiple lines and more.
 */
public class DCLabel extends JLabel {

    private static final long serialVersionUID = 1L;

    private final boolean _multiline;

    public DCLabel(final boolean multiline, final String text, final Color textColor, final Icon icon) {
        super();
        _multiline = multiline;
        if (text != null) {
            setText(text);
        }
        if (textColor != null) {
            setForeground(textColor);
        }
        if (icon != null) {
            setIcon(icon);
        }
        setVerticalAlignment(SwingConstants.TOP);
    }

    public static DCLabel bright(final String text) {
        return new DCLabel(false, text, WidgetUtils.BG_COLOR_BRIGHTEST, null);
    }

    public static DCLabel dark(final String text) {
        return new DCLabel(false, text, WidgetUtils.BG_COLOR_DARKEST, null);
    }

    public static DCLabel brightMultiLine(final String text) {
        return new DCLabel(true, text, WidgetUtils.BG_COLOR_BRIGHTEST, null);
    }

    public static DCLabel darkMultiLine(final String text) {
        return new DCLabel(true, text, WidgetUtils.BG_COLOR_DARKEST, null);
    }

    @Override
    public void setText(String text) {
        if (text == null) {
            text = "";
        }
        if (_multiline) {
            if (text.indexOf("

") == -1) { text = "

" + text + "

"; } if (text.indexOf("") == -1) { text = "" + text + ""; } if (text.indexOf(""); } } super.setText(text); } public void setMaximumWidth(final int width) { String text = getText(); if (text.startsWith("") && text.endsWith("")) { // remove tags since that will be added below also text = text.substring(6, text.length() - 7); } super.setText( "
" + text + "
"); } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy