org.valkyriercp.command.config.ToolBarCommandButtonConfigurer Maven / Gradle / Ivy
package org.valkyriercp.command.config;
import org.valkyriercp.command.support.AbstractCommand;
import org.valkyriercp.image.ShadowedIcon;
import javax.swing.*;
import java.awt.*;
/**
* Custom CommandButtonConfigurer
for buttons on the toolbar.
*
* Configurable Properties:
*
* Property
* Default
* Purpose
*
*
* showText
* false
* determines whether text is shown
*
*
* textBelowIcon
* true
* indicates whether the text is shown below the icon (as is default in
* most applications)
*
*
* enableShadow
* false
* toggles shadow effect on rollover. If the icon already had a rollover
* icon attached, no shadow effect is applied
*
*
*
* @author Keith Donald
* @author Peter De Bruycker
*/
public class ToolBarCommandButtonConfigurer extends DefaultCommandButtonConfigurer {
private boolean showText = false;
private boolean textBelowIcon = true;
private boolean enableShadow = false;
public boolean isEnableShadow() {
return enableShadow;
}
public void setEnableShadow(boolean enableShadow) {
this.enableShadow = enableShadow;
}
public void setTextBelowIcon(boolean textBelowIcon) {
this.textBelowIcon = textBelowIcon;
}
public boolean isTextBelowIcon() {
return textBelowIcon;
}
public void setShowText(boolean showText) {
this.showText = showText;
}
public boolean isShowText() {
return showText;
}
public void configure(AbstractButton button, AbstractCommand command, CommandFaceDescriptor faceDescriptor) {
super.configure(button, command, faceDescriptor);
if (textBelowIcon) {
button.setHorizontalTextPosition(JButton.CENTER);
button.setVerticalTextPosition(JButton.BOTTOM);
}
if (!showText) {
if (button.getIcon() != null) {
button.setText(null);
}
}
if (enableShadow && button.getIcon() != null && button.getRolloverIcon() == null) {
button.setRolloverEnabled(true);
button.setRolloverIcon(new ShadowedIcon(button.getIcon()));
}
button.setMargin(new Insets(2, 5, 2, 5));
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy