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

fr.techad.edc.popover.internal.swing.builder.ContextualComponentBuilderImpl Maven / Gradle / Ivy

There is a newer version: 3.0.0
Show newest version
package fr.techad.edc.popover.internal.swing.builder;

import fr.techad.edc.popover.builder.ContextualComponentBuilder;
import fr.techad.edc.popover.injector.provider.HelpListenerProvider;
import fr.techad.edc.popover.internal.swing.components.IconButton;
import fr.techad.edc.popover.internal.swing.tools.ImageIconCreator;
import fr.techad.edc.popover.swing.HelpListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.inject.Inject;
import javax.swing.*;
import java.net.URL;

/**
 * Implementation of {@link ContextualComponentBuilder} in case of swing.
 */
public class ContextualComponentBuilderImpl implements ContextualComponentBuilder {
    private static final Logger LOGGER = LoggerFactory.getLogger(ContextualComponentBuilderImpl.class);
    private final HelpListenerProvider helpListenerProvider;

    private String mainKey;
    private String subKey;
    private String languageCode;
    private String label = null;
    private String iconPath;

    @Inject
    public ContextualComponentBuilderImpl(HelpListenerProvider helpListenerProvider) {
        this.helpListenerProvider = helpListenerProvider;
    }

    @Override
    public ContextualComponentBuilder setKeys(String mainKey, String subKey, String languageCode) {
        this.mainKey = mainKey;
        this.subKey = subKey;
        this.languageCode=languageCode;
        return this;
    }

    @Override
    public ContextualComponentBuilder setIconPath(String iconPath) {
        this.iconPath = iconPath;
        return this;
    }

    @Override
    public ContextualComponentBuilder setLabel(String label) {
        this.label = label;
        return this;
    }

    @Override
    public JComponent build() {
        ImageIcon imageIcon = ImageIconCreator.createImageIcon(iconPath);
        IconButton iconButton = new IconButton(label, imageIcon);
        HelpListener helpListener = helpListenerProvider.get();
        helpListener.setKeysAndLanguageCode(mainKey, subKey, languageCode);
        iconButton.addMouseListener(helpListener);
        return iconButton;
    }


}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy