org.nuiton.jaxx.runtime.swing.TabInfo Maven / Gradle / Ivy
/*
* #%L
* JAXX :: Runtime
* %%
* Copyright (C) 2008 - 2023 Code Lutin, Ultreia.io
* %%
* This program 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.
*
* 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 General Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* .
* #L%
*/
package org.nuiton.jaxx.runtime.swing;
import io.ultreia.java4all.bean.AbstractJavaBean;
import io.ultreia.java4all.bean.spi.GenerateJavaBeanDefinition;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import javax.swing.Icon;
import javax.swing.JComponent;
import javax.swing.JTabbedPane;
import java.awt.Color;
import java.util.Objects;
import java.util.Set;
@GenerateJavaBeanDefinition
public class TabInfo extends AbstractJavaBean {
private static final Logger log = LogManager.getLogger(TabInfo.class);
public static final String BACKGROUND_PROPERTY = "background";
public static final String TAB_COMPONENT_PROPERTY = "tabComponent";
public static final String TAB_COMPONENT_STR_PROPERTY = "tabComponentStr";
public static final String DISABLED_ICON_PROPERTY = "disabledIcon";
public static final String DISPLAYED_MNEMONIC_INDEX_PROPERTY = "displayedMnemonicIndex";
public static final String ENABLED_PROPERTY = "enabled";
public static final String FOREGROUND_PROPERTY = "foreground";
public static final String ICON_PROPERTY = "icon";
public static final String MNEMONIC_PROPERTY = "mnemonic";
public static final String TITLE_PROPERTY = "title";
public static final String TOOL_TIP_TEXT_PROPERTY = "toolTipText";
public static final String VALID_PROPERTY = "valid";
private String id;
private String containerId;
private Color background;
private Icon disabledIcon;
private int displayedMnemonicIndex = -1;
private boolean enabled = true;
private Color foreground;
private Icon icon;
private int mnemonic = -1;
private String title;
private String toolTipText;
private JComponent tabComponent;
private String tabComponentStr;
private int tabIndex;
private Set properties;
private boolean valid;
public TabInfo() {
}
public TabInfo(String id) {
this.id = id;
}
public String getId() {
return id;
}
public void install(JTabbedPane parent, int index) {
setContainerId(parent.getName());
setTabIndex(index);
TabInfoPropertyChangeListener listener = new TabInfoPropertyChangeListener(parent, index);
addPropertyChangeListener(listener);
listener.install(this);
}
public Color getBackground() {
return background;
}
public void setBackground(Color background) {
Color oldValue = this.background;
this.background = background;
firePropertyChange(BACKGROUND_PROPERTY, oldValue, background);
}
public Icon getDisabledIcon() {
return disabledIcon;
}
public void setDisabledIcon(Icon disabledIcon) {
Icon oldValue = this.disabledIcon;
this.disabledIcon = disabledIcon;
firePropertyChange(DISABLED_ICON_PROPERTY, oldValue, disabledIcon);
}
public int getDisplayedMnemonicIndex() {
return displayedMnemonicIndex;
}
public void setDisplayedMnemonicIndex(int displayedMnemonicIndex) {
int oldValue = this.displayedMnemonicIndex;
this.displayedMnemonicIndex = displayedMnemonicIndex;
firePropertyChange(DISPLAYED_MNEMONIC_INDEX_PROPERTY, oldValue, displayedMnemonicIndex);
}
public boolean isEnabled() {
return enabled;
}
public void setEnabled(boolean enabled) {
boolean oldValue = this.enabled;
this.enabled = enabled;
firePropertyChange(ENABLED_PROPERTY, oldValue, enabled);
}
public Color getForeground() {
return foreground;
}
public void setForeground(Color foreground) {
Color oldValue = this.foreground;
this.foreground = foreground;
firePropertyChange(FOREGROUND_PROPERTY, oldValue, foreground);
}
public Icon getIcon() {
return icon;
}
public void setIcon(Icon icon) {
Icon oldValue = this.icon;
this.icon = icon;
firePropertyChange(ICON_PROPERTY, oldValue, icon);
}
public int getMnemonic() {
return mnemonic;
}
public void setMnemonic(int mnemonic) {
int oldValue = this.mnemonic;
this.mnemonic = mnemonic;
firePropertyChange(MNEMONIC_PROPERTY, oldValue, mnemonic);
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
String oldValue = this.title;
this.title = title;
firePropertyChange(TITLE_PROPERTY, oldValue, title);
}
public String getToolTipText() {
return toolTipText;
}
public void setToolTipText(String toolTipText) {
String oldValue = this.toolTipText;
this.toolTipText = toolTipText;
firePropertyChange(TOOL_TIP_TEXT_PROPERTY, oldValue, toolTipText);
}
public JComponent getTabComponent() {
return tabComponent;
}
public void setTabComponent(JComponent tabComponent) {
JComponent oldValue = this.tabComponent;
this.tabComponent = tabComponent;
if (oldValue!=null) {
firePropertyChange(TAB_COMPONENT_PROPERTY, oldValue, tabComponent);
}
}
public String getTabComponentStr() {
return tabComponentStr;
}
public void setTabComponentStr(String tabComponentStr) {
String oldValue = this.tabComponentStr;
this.tabComponentStr = tabComponentStr;
firePropertyChange(TAB_COMPONENT_STR_PROPERTY, oldValue, tabComponent);
}
public String getContainerId() {
return containerId;
}
public void setContainerId(String containerId) {
String oldValue = getContainerId();
this.containerId = containerId;
firePropertyChange("containerId", oldValue, containerId);
}
public Set getProperties() {
return properties;
}
public void setProperties(Set properties) {
this.properties = properties;
}
public boolean isValid() {
return valid;
}
public void setValid(boolean valid) {
this.valid = valid;
firePropertyChange(VALID_PROPERTY, null, valid);
}
public int getTabIndex() {
return tabIndex;
}
public void setTabIndex(int tabIndex) {
this.tabIndex = tabIndex;
}
public void firePropertyIfNotNull(String propertyName) {
Object value = get(Objects.requireNonNull(propertyName));
if (value != null) {
log.info(String.format("Fire tab not null property: %s → %s", propertyName, value));
firePropertyChange(propertyName, null, value);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy