org.valkyriercp.component.MessagableTabbedPane Maven / Gradle / Ivy
package org.valkyriercp.component;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Configurable;
import org.valkyriercp.core.Message;
import org.valkyriercp.core.Severity;
import org.valkyriercp.image.IconSource;
import javax.swing.*;
import java.awt.*;
import java.util.*;
import java.util.List;
/**
* @author Jan Hoskens
* @author Geoffrey De Smet
*/
@Configurable
public class MessagableTabbedPane extends JTabbedPane implements MessagableTab {
private List tabMetaDatas = new ArrayList();
@Autowired
private IconSource iconSource;
public MessagableTabbedPane() {
super();
}
public MessagableTabbedPane(int tabPlacement) {
super(tabPlacement);
}
public MessagableTabbedPane(int tabPlacement, int tabPolicy) {
super(tabPlacement, tabPolicy);
}
@Override
public void insertTab(String title, Icon icon, Component component, String tip, int index) {
super.insertTab(title, icon, component, tip, index);
tabMetaDatas.add(index, new TabMetaData());
}
@Override
public void setIconAt(int index, Icon icon) {
// Hack to allow the error icon to overwrite the real icon
TabMetaData tabMetaData = tabMetaDatas.get(index);
tabMetaData.setIcon(icon);
if (!tabMetaData.hasErrors()) {
super.setIconAt(index, icon);
}
}
@Override
public void setToolTipTextAt(int index, String toolTipText) {
// Hack to allow the error toolTipText to overwrite the real toolTipText
TabMetaData tabMetaData = tabMetaDatas.get(index);
tabMetaData.setToolTipText(toolTipText);
if (!tabMetaData.hasErrors()) {
super.setToolTipTextAt(index, toolTipText);
}
}
public void setMessage(Object source, Message message, int index) {
TabMetaData tabMetaData = tabMetaDatas.get(index);
tabMetaData.put(source, message);
if (tabMetaData.hasErrors()) {
// Calling super to avoid the error icon/toolTipText overwrite hack
super.setIconAt(index, loadIcon(Severity.ERROR.getLabel()));
super.setToolTipTextAt(index, tabMetaData.getFirstErrorMessage());
} else {
// Calling super to avoid the error icon/toolTipText overwrite hack
super.setIconAt(index, tabMetaData.getIcon());
super.setToolTipTextAt(index, tabMetaData.getToolTipText());
}
}
private Icon loadIcon(String severityLabel) {
return iconSource.getIcon("severity." + severityLabel + ".overlay");
}
private static class TabMetaData {
private Map
© 2015 - 2025 Weber Informatics LLC | Privacy Policy