Skip to content
This repository has been archived by the owner on Jul 10, 2018. It is now read-only.

Commit

Permalink
More builder work
Browse files Browse the repository at this point in the history
Move RibbonCommand to common package as FlamingoCommand
Refactor RichTooltip to be based on the builder pattern
  • Loading branch information
kirill-grouchnikov committed May 12, 2018
1 parent 5064caf commit f2aa462
Show file tree
Hide file tree
Showing 26 changed files with 2,610 additions and 479 deletions.
Binary file modified drop/6.0.00-dev/flamingo-6.0.00-dev.jar
Binary file not shown.
Binary file modified lib/trident-1.5.00.jar
Binary file not shown.
Expand Up @@ -27,28 +27,23 @@
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.pushingpixels.flamingo.api.ribbon;
package org.pushingpixels.flamingo.api.common;

import java.awt.event.ActionListener;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;

import org.pushingpixels.flamingo.api.common.AbstractCommandButton;
import org.pushingpixels.flamingo.api.common.CommandToggleButtonGroup;
import org.pushingpixels.flamingo.api.common.JCommandButton;
import org.pushingpixels.flamingo.api.common.JCommandButton.CommandButtonKind;
import org.pushingpixels.flamingo.api.common.JCommandMenuButton;
import org.pushingpixels.flamingo.api.common.JCommandToggleButton;
import org.pushingpixels.flamingo.api.common.JCommandToggleMenuButton;
import org.pushingpixels.flamingo.api.common.RichTooltip;
import org.pushingpixels.flamingo.api.common.JCommandButton.CommandButtonPopupOrientationKind;
import org.pushingpixels.flamingo.api.common.icon.ResizableIcon;
import org.pushingpixels.flamingo.api.common.popup.PopupPanelCallback;
import org.pushingpixels.flamingo.api.ribbon.JRibbon;
import org.pushingpixels.flamingo.api.ribbon.JRibbonBand;

/**
* Encapsulates metadata associated with a single ribbon command. Use a new instance of
* {@link RibbonCommandBuilder} to configure a new command, and {@link RibbonCommandBuilder#build()}
* to build a command.
* Encapsulates metadata associated with a single command. Use a new instance of
* {@link FlamingoCommandBuilder} to configure a new command, and
* {@link FlamingoCommandBuilder#build()} to build a command.
*
* Note that while {@link #buildButton()} can be used to directly build the visual representation of
* a command, commands represented by this class are passed to various APIs on the {@link JRibbon}
Expand All @@ -58,7 +53,7 @@
*
* @author Kirill Grouchnikov
*/
public class RibbonCommand {
public class FlamingoCommand {
private String title;
private ResizableIcon icon;
private ResizableIcon disabledIcon;
Expand All @@ -68,25 +63,23 @@ public class RibbonCommand {
private String actionKeyTip;
private PopupPanelCallback popupCallback;
private RichTooltip popupRichTooltip;
private CommandButtonPopupOrientationKind popupOrientationKind;
private String popupKeyTip;
private boolean isTitleClickAction;
private boolean isTitleClickPopup;
private boolean isEnabled;
private boolean isToggle;
private boolean isToggleSelected;
private RibbonCommandToggleGroup toggleGroup;
private FlamingoCommandToggleGroup toggleGroup;
private boolean isAutoRepeatAction;
private boolean hasAutoRepeatIntervalsSet;
private int autoRepeatInitialInterval;
private int autoRepeatSubsequentInterval;
private boolean isFireActionOnRollover;

private final PropertyChangeSupport pcs = new PropertyChangeSupport(this);

public void addPropertyChangeListener(PropertyChangeListener listener) {
this.pcs.addPropertyChangeListener(listener);
}

public void removePropertyChangeListener(PropertyChangeListener listener) {
this.pcs.removePropertyChangeListener(listener);
}

RibbonCommand() {
protected FlamingoCommand() {
}

protected void checkConsistency() {
Expand Down Expand Up @@ -189,6 +182,10 @@ public String getPopupKeyTip() {
return this.popupKeyTip;
}

public CommandButtonPopupOrientationKind getPopupOrientationKind() {
return this.popupOrientationKind;
}

public boolean isTitleClickAction() {
return this.isTitleClickAction;
}
Expand Down Expand Up @@ -216,26 +213,42 @@ public boolean isToggleSelected() {
return this.isToggleSelected;
}

public RibbonCommandToggleGroup getToggleGroup() {
public FlamingoCommandToggleGroup getToggleGroup() {
return this.toggleGroup;
}

public boolean isAutoRepeatAction() {
return this.isAutoRepeatAction;
}

public int getAutoRepeatInitialInterval() {
return this.hasAutoRepeatIntervalsSet ? this.autoRepeatInitialInterval : -1;
}

public int getAutoRepeatSubsequentInterval() {
return this.hasAutoRepeatIntervalsSet ? this.autoRepeatSubsequentInterval : -1;
}

public boolean isFireActionOnRollover() {
return this.isFireActionOnRollover;
}

private AbstractCommandButton createButton(boolean isMenu) {
return isMenu
? (this.isToggle() ? new JCommandToggleMenuButton(this.title, this.icon)
: new JCommandMenuButton(this.title, this.icon))
: (this.isToggle() ? new JCommandToggleButton(this.title, this.icon)
: new JCommandButton(this.title, this.icon));
}

protected boolean hasAction() {
return (this.getAction() != null);
}

protected boolean hasPopup() {
return (this.getPopupCallback() != null);
}

private void populateButton(AbstractCommandButton button) {
if (this.getDisabledIcon() != null) {
button.setDisabledIcon(this.getDisabledIcon());
Expand All @@ -258,6 +271,7 @@ private void populateButton(AbstractCommandButton button) {
jcb.setPopupCallback(this.getPopupCallback());
jcb.setPopupRichTooltip(this.getPopupRichTooltip());
jcb.setPopupKeyTip(this.getPopupKeyTip());
jcb.setPopupOrientationKind(this.getPopupOrientationKind());
}

if (hasAction && hasPopup) {
Expand All @@ -269,6 +283,16 @@ private void populateButton(AbstractCommandButton button) {
} else {
jcb.setCommandButtonKind(CommandButtonKind.POPUP_ONLY);
}

if (this.isAutoRepeatAction()) {
jcb.setAutoRepeatAction(true);
if (this.hasAutoRepeatIntervalsSet) {
jcb.setAutoRepeatActionIntervals(this.getAutoRepeatInitialInterval(),
this.getAutoRepeatSubsequentInterval());
}
}

jcb.setFireActionOnRollover(this.isFireActionOnRollover());
}

button.setEnabled(this.isEnabled());
Expand All @@ -281,7 +305,7 @@ private void populateButton(AbstractCommandButton button) {
button.getActionModel().setSelected(true);
}

this.addPropertyChangeListener((PropertyChangeEvent evt) -> {
this.pcs.addPropertyChangeListener((PropertyChangeEvent evt) -> {
if ("enabled".equals(evt.getPropertyName())) {
button.setEnabled((Boolean) evt.getNewValue());
}
Expand All @@ -300,11 +324,11 @@ public AbstractCommandButton buildMenuButton() {
return result;
}

public static class RibbonCommandToggleGroup {
public static class FlamingoCommandToggleGroup {
private CommandToggleButtonGroup toggleButtonGroup = new CommandToggleButtonGroup();
}

protected abstract static class BaseRibbonCommandBuilder<T extends RibbonCommand, B extends BaseRibbonCommandBuilder> {
protected abstract static class BaseFlamingoCommandBuilder<T extends FlamingoCommand, B extends BaseFlamingoCommandBuilder> {
protected String title;
protected ResizableIcon icon;
protected ResizableIcon disabledIcon;
Expand All @@ -315,14 +339,20 @@ protected abstract static class BaseRibbonCommandBuilder<T extends RibbonCommand
protected PopupPanelCallback popupCallback;
protected RichTooltip popupRichTooltip;
protected String popupKeyTip;
protected CommandButtonPopupOrientationKind popupOrientationKind;
protected boolean isTitleClickAction;
protected boolean isTitleClickPopup;
protected boolean isEnabled = true;
protected boolean isToggle;
protected boolean isToggleSelected;
protected RibbonCommandToggleGroup toggleGroup;

protected void configureBaseRibbonCommand(RibbonCommand command) {
protected FlamingoCommandToggleGroup toggleGroup;
protected boolean isAutoRepeatAction;
protected boolean hasAutoRepeatIntervalsSet;
protected int autoRepeatInitialInterval;
protected int autoRepeatSubsequentInterval;
protected boolean isFireActionOnRollover;

protected void configureBaseCommand(FlamingoCommand command) {
command.title = this.title;
command.icon = this.icon;
command.disabledIcon = this.disabledIcon;
Expand All @@ -333,12 +363,18 @@ protected void configureBaseRibbonCommand(RibbonCommand command) {
command.popupCallback = this.popupCallback;
command.popupRichTooltip = this.popupRichTooltip;
command.popupKeyTip = this.popupKeyTip;
command.popupOrientationKind = popupOrientationKind;
command.isTitleClickAction = this.isTitleClickAction;
command.isTitleClickPopup = this.isTitleClickPopup;
command.isEnabled = this.isEnabled;
command.isToggle = this.isToggle;
command.isToggleSelected = this.isToggleSelected;
command.toggleGroup = this.toggleGroup;
command.isAutoRepeatAction = this.isAutoRepeatAction;
command.hasAutoRepeatIntervalsSet = this.hasAutoRepeatIntervalsSet;
command.autoRepeatInitialInterval = this.autoRepeatInitialInterval;
command.autoRepeatSubsequentInterval = this.autoRepeatSubsequentInterval;
command.isFireActionOnRollover = this.isFireActionOnRollover;
}

public B setTitle(String title) {
Expand Down Expand Up @@ -391,6 +427,11 @@ public B setPopupKeyTip(String popupKeyTip) {
return (B) this;
}

public B setPopupOrientationKind(CommandButtonPopupOrientationKind popupOrientationKind) {
this.popupOrientationKind = popupOrientationKind;
return (B) this;
}

public B setTitleClickAction() {
this.isTitleClickAction = true;
return (B) this;
Expand All @@ -417,20 +458,36 @@ public B setToggleSelected(boolean toggleSelected) {
return (B) this;
}

public B inToggleGroup(RibbonCommandToggleGroup toggleGroup) {
public B inToggleGroup(FlamingoCommandToggleGroup toggleGroup) {
this.toggleGroup = toggleGroup;
return (B) this;
}


public B setAutoRepeatAction(boolean isAutoRepeatAction) {
this.isAutoRepeatAction = isAutoRepeatAction;
return (B) this;
}

public B setAutoRepeatActionIntervals(int initial, int subsequent) {
this.hasAutoRepeatIntervalsSet = true;
this.autoRepeatInitialInterval = initial;
this.autoRepeatSubsequentInterval = subsequent;
return (B) this;
}

public B setFireActionOnRollover(boolean isFireActionOnRollover) {
this.isFireActionOnRollover = isFireActionOnRollover;
return (B) this;
}
}

public static class RibbonCommandBuilder
extends BaseRibbonCommandBuilder<RibbonCommand, RibbonCommandBuilder> {
public static class FlamingoCommandBuilder
extends BaseFlamingoCommandBuilder<FlamingoCommand, FlamingoCommandBuilder> {

public RibbonCommand build() {
RibbonCommand command = new RibbonCommand();
public FlamingoCommand build() {
FlamingoCommand command = new FlamingoCommand();

this.configureBaseRibbonCommand(command);
this.configureBaseCommand(command);

command.checkConsistency();

Expand Down
9 changes: 6 additions & 3 deletions src/org/pushingpixels/flamingo/api/common/JCommandButton.java
Expand Up @@ -61,7 +61,10 @@ public class JCommandButton extends AbstractCommandButton {
* The UI class ID string.
*/
public static final String uiClassID = "CommandButtonUI";


public static final int DEFAULT_AUTO_REPEAT_INITIAL_INTERVAL_MS = 500;
public static final int DEFAULT_AUTO_REPEAT_SUBSEQUENT_INTERVAL_MS = 100;

/**
* Associated popup callback. May be <code>null</code>.
*
Expand Down Expand Up @@ -431,8 +434,8 @@ public JCommandButton(String title, ResizableIcon icon) {
this.popupOrientationKind = CommandButtonPopupOrientationKind.DOWNWARD;
// this.displayState = CommandButtonDisplayState.CUSTOM;
this.isAutoRepeatAction = false;
this.autoRepeatInitialInterval = 500;
this.autoRepeatSubsequentInterval = 100;
this.autoRepeatInitialInterval = DEFAULT_AUTO_REPEAT_INITIAL_INTERVAL_MS;
this.autoRepeatSubsequentInterval = DEFAULT_AUTO_REPEAT_SUBSEQUENT_INTERVAL_MS;

this.updateUI();
}
Expand Down

0 comments on commit f2aa462

Please sign in to comment.