001 /* 002 * Copyright 2002-2007 the original author or authors. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); you may not 005 * use this file except in compliance with the License. You may obtain a copy of 006 * the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 012 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 013 * License for the specific language governing permissions and limitations under 014 * the License. 015 */ 016 package org.springframework.richclient.dialog.control; 017 018 import java.beans.PropertyChangeListener; 019 import java.beans.PropertyChangeSupport; 020 021 import javax.swing.Icon; 022 import javax.swing.JComponent; 023 024 /** 025 * Represents a single tab in a tabbed pane. 026 * <p> 027 * TODO: move this to another package? 028 * 029 * @author Peter De Bruycker 030 */ 031 public class Tab { 032 public static final String TITLE_PROPERTY = "title"; 033 public static final String ICON_PROPERTY = "icon"; 034 public static final String TOOLTIP_PROPERTY = "tooltip"; 035 public static final String COMPONENT_PROPERTY = "component"; 036 public static final String VISIBLE_PROPERTY = "visible"; 037 public static final String MNEMONIC_PROPERTY = "mnemonic"; 038 public static final String ENABLED_PROPERTY = "enabled"; 039 040 private String title; 041 private Icon icon; 042 private String tooltip; 043 private JComponent component; 044 private boolean visible = true; 045 private int mnemonic; 046 private boolean enabled = true; 047 048 private PropertyChangeSupport propertyChangeSupport = new PropertyChangeSupport(this); 049 050 public Tab(String title, JComponent component) { 051 this.title = title; 052 this.component = component; 053 } 054 055 public Tab() { 056 057 } 058 059 public boolean isVisible() { 060 return visible; 061 } 062 063 public void setVisible(boolean visible) { 064 boolean old = this.visible; 065 this.visible = visible; 066 if (old != visible) { 067 propertyChangeSupport.firePropertyChange(VISIBLE_PROPERTY, old, visible); 068 } 069 } 070 071 public JComponent getComponent() { 072 return component; 073 } 074 075 public void setComponent(JComponent component) { 076 JComponent old = this.component; 077 this.component = component; 078 if (old != component) { 079 propertyChangeSupport.firePropertyChange(COMPONENT_PROPERTY, old, component); 080 } 081 } 082 083 public Icon getIcon() { 084 return icon; 085 } 086 087 public void setIcon(Icon icon) { 088 Icon old = this.icon; 089 this.icon = icon; 090 if (old != icon) { 091 propertyChangeSupport.firePropertyChange(ICON_PROPERTY, old, icon); 092 } 093 } 094 095 public String getTitle() { 096 return title; 097 } 098 099 public void setTitle(String title) { 100 String old = this.title; 101 this.title = title; 102 if(old != null && !old.equals(title) || title != null) { 103 propertyChangeSupport.firePropertyChange(TITLE_PROPERTY, old, title); 104 } 105 } 106 107 public String getTooltip() { 108 return tooltip; 109 } 110 111 public void setTooltip(String tooltip) { 112 String old = this.tooltip; 113 this.tooltip = tooltip; 114 if(old != null && !old.equals(tooltip) || tooltip != null) { 115 propertyChangeSupport.firePropertyChange(TOOLTIP_PROPERTY, old, tooltip); 116 } 117 } 118 119 public void addPropertyChangeListener(PropertyChangeListener l) { 120 propertyChangeSupport.addPropertyChangeListener(l); 121 } 122 123 public void addPropertyChangeListener(String propertyName, PropertyChangeListener l) { 124 propertyChangeSupport.addPropertyChangeListener(propertyName, l); 125 } 126 127 public void removePropertyChangeListener(PropertyChangeListener l) { 128 propertyChangeSupport.addPropertyChangeListener(l); 129 } 130 131 public void removePropertyChangeListener(String propertyName, PropertyChangeListener l) { 132 propertyChangeSupport.addPropertyChangeListener(propertyName, l); 133 } 134 135 public void setMnemonic(int mnemonic) { 136 int old = this.mnemonic; 137 this.mnemonic = mnemonic; 138 if(mnemonic != old) { 139 propertyChangeSupport.firePropertyChange(MNEMONIC_PROPERTY, old, mnemonic); 140 } 141 } 142 143 public int getMnemonic() { 144 return mnemonic; 145 } 146 147 public boolean isEnabled() { 148 return enabled; 149 } 150 151 public void setEnabled(boolean enabled) { 152 boolean old = this.enabled; 153 this.enabled = enabled; 154 if(enabled != old) { 155 propertyChangeSupport.firePropertyChange(ENABLED_PROPERTY, old, enabled); 156 } 157 } 158 }