com.anrisoftware.prefdialog.csvimportdialog.panelproperties.advancedproperties.LineEndRenderer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of prefdialog-csvimportdialog Show documentation
Show all versions of prefdialog-csvimportdialog Show documentation
Dialog to import formatted text data in a comma separated format. The comma can also be a tab, space, semicolon or any other character.
/*
* Copyright 2013-2016 Erwin Müller
*
* This file is part of prefdialog-csvimportdialog.
*
* prefdialog-csvimportdialog is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or (at your
* option) any later version.
*
* prefdialog-csvimportdialog 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 General Public License for more
* details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with prefdialog-csvimportdialog. If not, see .
*/
package com.anrisoftware.prefdialog.csvimportdialog.panelproperties.advancedproperties;
import static java.lang.String.format;
import java.awt.Component;
import java.util.MissingResourceException;
import javax.inject.Inject;
import javax.swing.DefaultListCellRenderer;
import javax.swing.JList;
import com.anrisoftware.resources.texts.api.Texts;
import com.anrisoftware.resources.texts.api.TextsFactory;
/**
* Renders line end symbols.
*
* @author Erwin Mueller, [email protected]
* @since 3.0
*/
@SuppressWarnings("serial")
public class LineEndRenderer extends DefaultListCellRenderer {
private final Texts texts;
/**
* Injects the texts resources factory.
*
* @param textsFactory
* the {@link TextsFactory}.
*/
@Inject
LineEndRenderer(TextsFactory textsFactory) {
this.texts = textsFactory.create(getClass().getSimpleName());
}
@Override
public Component getListCellRendererComponent(JList> list, Object value,
int index, boolean isSelected, boolean cellHasFocus) {
super.getListCellRendererComponent(list, value, index, isSelected,
cellHasFocus);
if (value instanceof LineEnd) {
setupLineEnd((LineEnd) value);
}
return this;
}
private void setupLineEnd(LineEnd value) {
try {
String name = format("symbols_%s", value.name().toLowerCase());
String title = texts.getResource(name).getText();
setText(title);
} catch (MissingResourceException e) {
setText(value.toString());
}
}
}