All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.wings.SClickable Maven / Gradle / Ivy

The newest version!
/*
 * Copyright 2000,2005 wingS development team.
 *
 * This file is part of wingS (http://wingsframework.org).
 *
 * wingS 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 2.1
 * of the License, or (at your option) any later version.
 *
 * Please see COPYING for the complete licence.
 */
package org.wings;


/**
 * A basic icon-text compound
 * where you can set an event by hand or which could be
 * used as a base class to extend from.
 *
 * @author Armin Haaf
 */
public class SClickable
        extends SAbstractClickable {

    /**
     * if this is set (!=null) this event is rendered as anchor. If it is null,
     * the anchor in the AnchorRenderStack is rendered
     */
    private String event;

    /**
     * if this is set (!=null) this event is rendered as anchor. If it is null,
     * the anchor in the AnchorRenderStack is rendered
     */
    private LowLevelEventListener requestTarget;

    /**
     * Creates a new SClickable instance with the specified text
     * (left alligned) and no icon.
     *
     * @param text The text to be displayed by the label.
     */
    public SClickable(String text) {
        this(text, null, SConstants.LEFT);
    }

    /**
     * Creates a new SClickable instance with no text and no icon.
     */
    public SClickable() {
        this((String) null);
    }

    /**
     * Creates a new SClickable instance with the specified icon
     * (left alligned) and no text.
     *
     * @param icon The image to be displayed by the label.
     */
    public SClickable(SIcon icon) {
        this(icon, SConstants.LEFT);
    }

    /**
     * Creates a new SClickable instance with the specified icon
     * (alligned as specified) and no text.
     *
     * @param icon                The image to be displayed by the clickable.
     * @param horizontalAlignment One of the following constants defined in
     *                            SConstants:
     *                            LEFT, CENTER, RIGHT.
     * @see SConstants
     */
    public SClickable(SIcon icon, int horizontalAlignment) {
        this(null, icon, horizontalAlignment);
    }

    /**
     * Creates a new SClickable instance with the specified icon
     * and the specified text (left alligned).
     *
     * @param text The text to be displayed by the SClickable.
     * @param icon The image to be displayed by the SClickable.
     */
    public SClickable(String text, SIcon icon) {
        setText(text);
        setIcon(icon);
        setHorizontalAlignment(SConstants.LEFT);
    }

    /**
     * Creates a new SClickable instance with the specified icon
     * and the specified text (alligned as specified).
     *
     * @param text                The text to be displayed by the SClickable.
     * @param icon                The image to be displayed by the SClickable.
     * @param horizontalAlignment One of the following constants defined in
     *                            SConstants:
     *                            LEFT, CENTER, RIGHT.
     * @see SConstants
     */
    public SClickable(String text, SIcon icon, int horizontalAlignment) {
        setText(text);
        setIcon(icon);
        setHorizontalAlignment(horizontalAlignment);
    }

    /**
     * Creates a new SClickable instance with the specified text
     * (alligned as specified) and no icon.
     *
     * @param text                The text to be displayed by the SClickable.
     * @param horizontalAlignment One of the following constants defined in
     *                            SConstants:
     *                            LEFT, CENTER, RIGHT.
     * @see SConstants
     */
    public SClickable(String text, int horizontalAlignment) {
        this(text, null, horizontalAlignment);
    }

    @Override
    public boolean isEpochCheckEnabled() {
        return requestTarget == null || requestTarget.isEpochCheckEnabled();
    }

    /**
     * if this is set (!=null) this event is rendered as anchor. If it is null,
     * the anchor in the AnchorRenderStack is rendered
     */
    public final void setEvent(String event, LowLevelEventListener requestTarget) {
        setEvent(event);
        setEventTarget(requestTarget);
    }

    /**
     * if this is set (!=null) this event is rendered as anchor. If it is null,
     * the anchor in the AnchorRenderStack is rendered
     */
    public void setEvent(String e) {
        if (isDifferent(event, e)) {
            String oldVal = this.event;
            event = e;
            reload();
            propertyChangeSupport.firePropertyChange("event", oldVal, this.event);
        }
    }

    /**
     * if this is set (!=null) this event is rendered as anchor. If it is null,
     * the anchor in the AnchorRenderStack is rendered
     */
    public final String getEvent() {
        return event;
    }

    /**
     * sets the LowLevelEventListener for which to create a event.
     */
    public void setEventTarget(LowLevelEventListener t) {
        if (isDifferent(requestTarget, t)) {
            LowLevelEventListener oldVal = this.requestTarget;
            requestTarget = t;
            reload();
            propertyChangeSupport.firePropertyChange("eventTarget", oldVal, this.requestTarget);
        }
    }

    /**
     * if this is set (!=null) this event is rendered as anchor. If it is null,
     * the anchor in the AnchorRenderStack is rendered
     */
    public final LowLevelEventListener getEventTarget() {
        return requestTarget;
    }

    @Override
    public SimpleURL getURL() {
        if (event != null && requestTarget != null) {
            RequestURL u = getRequestURL();
            if (!isEpochCheckEnabled()) {
                u.setEventEpoch(null);
                u.setResource(null);
            }

            u.addParameter(requestTarget,
                    event);
            return u;
        } else {
            return null;
        }
    }


}






© 2015 - 2024 Weber Informatics LLC | Privacy Policy