001 /*
002 * Copyright 2002-2007 the original author or authors.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of 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,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016 package org.springframework.richclient.command.config;
017
018 import java.awt.Insets;
019
020 import javax.swing.AbstractButton;
021 import javax.swing.JButton;
022
023 import org.springframework.richclient.command.AbstractCommand;
024 import org.springframework.richclient.image.ShadowedIcon;
025
026 /**
027 * Custom <code>CommandButtonConfigurer</code> for buttons on the toolbar.
028 * <p>
029 * Configurable Properties: <table border="1">
030 * <tr>
031 * <td><b>Property</b></td>
032 * <td><b>Default</b></td>
033 * <td><b>Purpose</b></td>
034 * </tr>
035 * <tr>
036 * <td><code>showText</code></td>
037 * <td>false</td>
038 * <td>determines whether text is shown</td>
039 * </tr>
040 * <tr>
041 * <td><code>textBelowIcon</code></td>
042 * <td>true</td>
043 * <td>indicates whether the text is shown below the icon (as is default in
044 * most applications)</td>
045 * </tr>
046 * <tr>
047 * <td><code>enableShadow</code></td>
048 * <td>false</td>
049 * <td>toggles shadow effect on rollover. If the icon already had a rollover
050 * icon attached, no shadow effect is applied</td>
051 * </tr>
052 * </table>
053 *
054 * @author Keith Donald
055 * @author Peter De Bruycker
056 */
057 public class ToolBarCommandButtonConfigurer extends DefaultCommandButtonConfigurer {
058 private boolean showText = false;
059
060 private boolean textBelowIcon = true;
061
062 private boolean enableShadow = false;
063
064 public boolean isEnableShadow() {
065 return enableShadow;
066 }
067
068 public void setEnableShadow(boolean enableShadow) {
069 this.enableShadow = enableShadow;
070 }
071
072 public void setTextBelowIcon(boolean textBelowIcon) {
073 this.textBelowIcon = textBelowIcon;
074 }
075
076 public boolean isTextBelowIcon() {
077 return textBelowIcon;
078 }
079
080 public void setShowText(boolean showText) {
081 this.showText = showText;
082 }
083
084 public boolean isShowText() {
085 return showText;
086 }
087
088 public void configure(AbstractButton button, AbstractCommand command, CommandFaceDescriptor faceDescriptor) {
089 super.configure(button, command, faceDescriptor);
090
091 if (textBelowIcon) {
092 button.setHorizontalTextPosition(JButton.CENTER);
093 button.setVerticalTextPosition(JButton.BOTTOM);
094 }
095
096 if (!showText) {
097 if (button.getIcon() != null) {
098 button.setText(null);
099 }
100 }
101
102 if (enableShadow && button.getIcon() != null && button.getRolloverIcon() == null) {
103 button.setRolloverEnabled(true);
104 button.setRolloverIcon(new ShadowedIcon(button.getIcon()));
105 }
106
107 button.setMargin(new Insets(2, 5, 2, 5));
108 }
109 }