incubator-adffaces-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Simon Lessard" <simon.lessar...@gmail.com>
Subject Re: PATCH: ServerSide buttons are back
Date Mon, 11 Dec 2006 22:19:54 GMT
Hello everyones,

I was among the people wanting to keep them for round edges, but now I find
them evil. The result is not always consistent and sometimes looks quite odd
with international characters, you can hardly add any mouseover or
mousepress interaction that most users are used to. As Adam suggested in one
reply of that old thread, we can get those round edge back with CSS 3 when
browsers support it, meaning in one year or so for most browser and never
for IE.


Regards,

~ Simon


On 12/11/06, Mark Robinson <mark.robinson@mizar.com> wrote:
>
> So I've cleaned up my patch.
>
> I've removed the dependence on trinidadinternal.ui and I've added some
> classes which I needed to implement server side buttons.
>
> Mark
>
> Mark Robinson wrote:
> > Hi,
> >
> > I've written up a patch which will enable the use of server generated
> > buttons in tr:commandButtons.  It follows the documentation in that
> > you must supply AFButtonStartIcon:alias, AFButtonEndIcon:alias,
> > AFButtonTopBackgroundIcon:alias  and
> > AFButtonBottomBackgroundIcon:alias in the skin definition file.  If it
> > can't find these definitions, it reverts to normal client-side buttons.
> >
> >
> > Mark
> > ------------------------------------------------------------------------
>
>
>
> Index:
> trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/CoreImageContext.java
> ===================================================================
> ---
> trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/CoreImageContext.java
> (revision 0)
> +++
> trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/CoreImageContext.java
> (revision 0)
> @@ -0,0 +1,149 @@
> +/*
> + * Copyright  2005,2006 The Apache Software Foundation.
> + *
> + * Licensed under the Apache License, Version 2.0 (the "License");
> + * you may not use this file except in compliance with the License.
> + * You may obtain a copy of the License at
> + *
> + *      http://www.apache.org/licenses/LICENSE-2.0
> + *
> + * Unless required by applicable law or agreed to in writing, software
> + * distributed under the License is distributed on an "AS IS" BASIS,
> + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
> implied.
> + * See the License for the specific language governing permissions and
> + * limitations under the License.
> + */
> +
> +package org.apache.myfaces.trinidadinternal.renderkit.core;
> +
> +import javax.faces.context.FacesContext;
> +
> +import org.apache.myfaces.trinidad.context.Agent;
> +import org.apache.myfaces.trinidad.context.LocaleContext;
> +import org.apache.myfaces.trinidad.context.RequestContext;
> +import org.apache.myfaces.trinidad.logging.TrinidadLogger;
> +import org.apache.myfaces.trinidadinternal.agent.TrinidadAgent;
> +import org.apache.myfaces.trinidadinternal.image.ImageConstants;
> +import org.apache.myfaces.trinidadinternal.image.ImageContext;
> +import org.apache.myfaces.trinidadinternal.image.ImageProvider;
> +import
> org.apache.myfaces.trinidadinternal.image.cache.FileSystemImageCache;
> +import org.apache.myfaces.trinidadinternal.share.config.Configuration;
> +import
> org.apache.myfaces.trinidadinternal.share.config.ContextBasedConfiguration
> ;
> +import org.apache.myfaces.trinidadinternal.share.util.NamespaceMap;
> +import org.apache.myfaces.trinidadinternal.style.StyleContext;
> +
> +public class CoreImageContext implements ImageContext {
> +    public CoreImageContext(TrinidadAgent agent, LocaleContext
> localeContext, StyleContext styleContext) {
> +        _agent = agent;
> +        _localeContext = localeContext;
> +        _styleContext = styleContext;
> +        _nameSpaceProperties = new NamespaceMap();
> +
> +        _initializeConfiguration(FacesContext.getCurrentInstance(),
> RequestContext.getCurrentInstance());
> +    }
> +
> +    public LocaleContext getLocaleContext() {
> +        return _localeContext;
> +    }
> +
> +    public TrinidadAgent getAgent() {
> +        return _agent;
> +    }
> +
> +    public Configuration getConfiguration() {
> +        return _config;
> +    }
> +
> +    public Object getProperty(String namespace, Object key) {
> +        Object o = _nameSpaceProperties.get(namespace, key);
> +
> +        if (o == null)
> +        {
> +          if (ImageConstants.TECATE_NAMESPACE == namespace)
> +          {
> +            if (ImageConstants.IMAGE_PROVIDER_PROPERTY == key)
> +            {
> +              ImageProvider imageProvider = _getDefaultImageProvider();
> +
> +              setProperty(ImageConstants.TECATE_NAMESPACE,
> +                          ImageConstants.IMAGE_PROVIDER_PROPERTY,
> +                          imageProvider);
> +
> +              o = imageProvider;
> +            }
> +          }
> +        }
> +
> +        return o;
> +    }
> +
> +    public void setProperty(String namespace, Object key, Object value) {
> +        _nameSpaceProperties.put(namespace, key, value);
> +    }
> +
> +    public StyleContext getStyleContext() {
> +        return _styleContext;
> +    }
> +
> +    // Creates a default Tecate's FileSystemImageCache.
> +    // Uses the web server root and base image uri to determine the
> +    // location of the default cache
> +    private ImageProvider _getDefaultImageProvider()
> +    {
> +      ImageProvider provider = null;
> +      //Configuration config = getConfiguration();
> +      try
> +      {
> +        // We explicitly avoid using the SHARED_CONTEXT_PATH for the
> +        // image cache.  That way, we can ensure that each application
> +        // creates its own local image cache.
> +        String contextPath = getStyleContext().getGeneratedFilesPath();
> +        String path = _getDefaultImageCacheDirectory();
> +
> +        provider = FileSystemImageCache.getSharedCache(contextPath +
> path);
> +      }
> +      catch (Exception e)
> +      {
> +        _LOG.severe("Could not get image cache", e);
> +      }
> +
> +      return provider;
> +    }
> +
> +    /**
> +     * Gets the default Image Cache directory
> +     *
> +     * @return relative Image Cache directory
> +     */
> +    private String _getDefaultImageCacheDirectory() {
> +      return _DEFAULT_BASE_DIRECTORY + _DEFAULT_IMAGES_SUBDIRECTORY +
> _DEFAULT_CACHE_SUBDIRECTORY;
> +    }
> +
> +    private void _initializeConfiguration(FacesContext fContext,
> +                                          RequestContext context)
> +    {
> +      _config = new ContextBasedConfiguration(fContext, context);
> +    }
> +
> +
> +
> +
> +    private static final String _DEFAULT_BASE_DIRECTORY   = "/adf/";
> +    private static final String _DEFAULT_IMAGES_SUBDIRECTORY = "images/";
> +    private static final String _DEFAULT_JSLIBS_SUBDIRECTORY = "jsLibs/";
> +    private static final String _DEFAULT_JSPS_SUBDIRECTORY   = "jsps/";
> +    private static final String _DEFAULT_STYLES_SUBDIRECTORY = "styles/";
> +    private static final String _DEFAULT_CACHE_SUBDIRECTORY  = "cache/";
> +
> +
> +
> +
> +    private TrinidadAgent _agent;
> +    private LocaleContext _localeContext;
> +    private StyleContext _styleContext;
> +    private NamespaceMap        _nameSpaceProperties;
> +    private Configuration _config;
> +
> +    static private final TrinidadLogger _LOG =
> +      TrinidadLogger.createTrinidadLogger(CoreImageContext.class);
> +}
> Index:
> trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/CoreRenderingContext.java
> ===================================================================
> ---
> trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/CoreRenderingContext.java
> (revision 483170)
> +++
> trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/CoreRenderingContext.java
> (working copy)
> @@ -45,7 +45,7 @@
> import org.apache.myfaces.trinidadinternal.agent.TrinidadAgentImpl;
> import org.apache.myfaces.trinidadinternal.agent.AgentUtil;
>
> -
> +import org.apache.myfaces.trinidadinternal.image.ImageContext;
> import org.apache.myfaces.trinidadinternal.skin.SkinNotAvailable;
>
> import org.apache.myfaces.trinidadinternal.style.StyleContext;
> @@ -64,6 +64,7 @@
>
>      _properties = new HashMap<Object, Object>();
>
> +
>      _outputMode = afContext.getOutputMode();
>      _agent = _initializeAgent(context,
>                                afContext.getAgent(),
> @@ -75,6 +76,8 @@
>      _initializePPR(context, afContext);
>      // Get and cache (since it can be EL-bound)
>      _accessibilityMode = afContext.getAccessibilityMode();
> +
> +    _imageContext = new CoreImageContext(getTrinidadAgent(),
> getLocaleContext(), getStyleContext());
>    }
>
>
> @@ -103,6 +106,10 @@
>      else
>        _linkStyleDisabledCount--;
>    }
> +
> +  public ImageContext getImageContext() {
> +      return _imageContext;
> +  }
>
>
>    /**
> @@ -526,8 +533,9 @@
>      localeContext.setDecimalFormatContext(mdfc);
>      _localeContext = localeContext;
>    }
> +
>
> -
> +  private ImageContext        _imageContext;
>    private Skin                _skin;
>    private FormData            _formData;
>    private TrinidadAgent       _agent;
> @@ -553,7 +561,7 @@
>
>    static private final Map<Object, Object> _EMAIL_CAPABILITIES =
>      new HashMap<Object, Object>();
> -
> +
>    static
>    {
>      _PRINTABLE_CAPABILITIES.put(TrinidadAgent.CAP_INTRINSIC_EVENTS,
> @@ -584,4 +592,7 @@
>
>    static private final TrinidadLogger _LOG =
>      TrinidadLogger.createTrinidadLogger(CoreRenderingContext.class);
> +
> +
> +
> }
> Index:
> trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/CommandButtonConstants.java
> ===================================================================
> ---
> trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/CommandButtonConstants.java
> (revision 0)
> +++
> trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/CommandButtonConstants.java
> (revision 0)
> @@ -0,0 +1,138 @@
> +/*
> + * Copyright  2005,2006 The Apache Software Foundation.
> + *
> + * Licensed under the Apache License, Version 2.0 (the "License");
> + * you may not use this file except in compliance with the License.
> + * You may obtain a copy of the License at
> + *
> + *      http://www.apache.org/licenses/LICENSE-2.0
> + *
> + * Unless required by applicable law or agreed to in writing, software
> + * distributed under the License is distributed on an "AS IS" BASIS,
> + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
> implied.
> + * See the License for the specific language governing permissions and
> + * limitations under the License.
> + */
> +
> +package org.apache.myfaces.trinidadinternal.renderkit.core.xhtml;
> +
> +public class CommandButtonConstants {
> +
> +
> +      // menuTabs Icons
> +      static final String AF_MENU_TABS_ENABLED_START_ICON_NAME =
> +        "af|menuTabs::enabled-start-icon";
> +      static final String AF_MENU_TABS_SELECTED_START_ICON_NAME =
> +        "af|menuTabs::selected-start-icon";
> +      static final String AF_MENU_TABS_ENABLED_END_ICON_NAME =
> +        "af|menuTabs::enabled-end-icon";
> +      static final String AF_MENU_TABS_SELECTED_END_ICON_NAME =
> +        "af|menuTabs::selected-end-icon";
> +      static final String AF_MENU_TABS_ENABLED_JOIN_ICON_NAME =
> +        "af|menuTabs::enabled-join-icon";
> +      static final String AF_MENU_TABS_SELECTED_ENABLED_JOIN_ICON_NAME =
> +        "af|menuTabs::selected-enabled-join-icon";
> +      static final String AF_MENU_TABS_ENABLED_SELECTED_JOIN_ICON_NAME =
> +        "af|menuTabs::enabled-selected-join-icon";
> +      static final String AF_MENU_TABS_ENABLED_BACKGROUND_ICON_NAME =
> +        "af|menuTabs::enabled-background-icon";
> +      static final String AF_MENU_TABS_SELECTED_BACKGROUND_ICON_NAME =
> +        "af|menuTabs::selected-background-icon";
> +
> +      // menuBar Icons
> +      static final String AF_MENU_BAR_START_ICON_NAME =
> +        "af|menuBar::start-icon";
> +      static final String AF_MENU_BAR_END_ICON_NAME =
> +        "af|menuBar::end-icon";
> +      static final String AF_MENU_BAR_LEADING_SEPARATOR_ICON_NAME =
> +        "af|menuBar::leading-separator-icon";
> +      static final String AF_MENU_BAR_TRAILING_SEPARATOR_ICON_NAME =
> +        "af|menuBar::trailing-separator-icon";
> +      static final String AF_MENU_BAR_BACKGROUND_ICON_NAME =
> +        "af|menuBar::background-icon";
> +
> +      // GlobalButtonBar Icons
> +      static final String AF_MENU_BUTTONS_SEPARATOR_ICON_NAME =
> +        "af|menuButtons::separator-icon";
> +
> +      // messages Icons
> +      static final String AF_MESSAGES_TOP_START_ICON_NAME =
> +        "af|messages::top-start-icon";
> +      static final String AF_MESSAGES_TOP_END_ICON_NAME =
> +        "af|messages::top-end-icon";
> +      static final String AF_MESSAGES_TOP_BACKGROUND_ICON_NAME =
> +        "af|messages::top-background-icon";
> +      static final String AF_MESSAGES_BOTTOM_START_ICON_NAME =
> +        "af|messages::bottom-start-icon";
> +      static final String AF_MESSAGES_BOTTOM_END_ICON_NAME =
> +        "af|messages::bottom-end-icon";
> +      static final String AF_MESSAGES_BOTTOM_BACKGROUND_ICON_NAME =
> +        "af|messages::bottom-background-icon";
> +      static final String AF_MESSAGES_START_BACKGROUND_ICON_NAME =
> +        "af|messages::start-background-icon";
> +      static final String AF_MESSAGES_END_BACKGROUND_ICON_NAME =
> +        "af|messages::end-background-icon";
> +
> +      // panelSideBar Icons
> +      static final String AF_PANEL_SIDE_BAR_TOP_START_ICON_NAME =
> +        "af|panelSideBar::top-start-icon";
> +      static final String AF_PANEL_SIDE_BAR_TOP_END_ICON_NAME =
> +        "af|panelSideBar::top-end-icon";
> +      static final String AF_PANEL_SIDE_BAR_TOP_BACKGROUND_ICON_NAME =
> +        "af|panelSideBar::top-background-icon";
> +      static final String AF_PANEL_SIDE_BAR_BOTTOM_START_ICON_NAME =
> +        "af|panelSideBar::bottom-start-icon";
> +      static final String AF_PANEL_SIDE_BAR_BOTTOM_END_ICON_NAME =
> +        "af|panelSideBar::bottom-end-icon";
> +      static final String AF_PANEL_SIDE_BAR_BOTTOM_BACKGROUND_ICON_NAME =
> +        "af|panelSideBar::bottom-background-icon";
> +      static final String AF_PANEL_SIDE_BAR_START_BACKGROUND_ICON_NAME =
> +        "af|panelSideBar::start-background-icon";
> +      static final String AF_PANEL_SIDE_BAR_END_BACKGROUND_ICON_NAME =
> +        "af|panelSideBar::end-background-icon";
> +
> +
> +      // Button Icons
> +      static final String BUTTON_START_ICON_NAME =
> +        "AFButtonStartIcon";
> +      static final String BUTTON_END_ICON_NAME =
> +        "AFButtonEndIcon";
> +      static final String BUTTON_TOP_BACKGROUND_ICON_NAME =
> +        "AFButtonTopBackgroundIcon";
> +      static final String BUTTON_BOTTOM_BACKGROUND_ICON_NAME =
> +        "AFButtonBottomBackgroundIcon";
> +
> +      static final String BUTTON_DISABLED_START_ICON_NAME =
> +        "AFButtonDisabledStartIcon";
> +      static final String BUTTON_DISABLED_END_ICON_NAME =
> +        "AFButtonDisabledEndIcon";
> +      static final String BUTTON_DISABLED_TOP_BACKGROUND_ICON_NAME =
> +        "AFButtonDisabledTopBackgroundIcon";
> +      static final String BUTTON_DISABLED_BOTTOM_BACKGROUND_ICON_NAME =
> +        "AFButtonDisabledBottomBackgroundIcon";
> +
> +      // Style classes
> +
> +      // menuBar style classes
> +      public static final String AF_MENU_BAR_EMPTY_STYLE_CLASS =
> +        "af|menuBar::empty";
> +      public static final String AF_MENU_BAR_BODY_STYLE_CLASS =
> +        "af|menuBar::body";
> +      public static final String AF_MENU_BAR_TITLE_STYLE_CLASS =
> +        "af|menuBar::title";
> +
> +
> +      // tr:messages style classes
> +      // when we combine base and simple renders, this will move up to
> +      // BaseDesktopConstants. In fact, all the styles in this class
> will.
> +
> +
> +      // style that is on the td that surrounds the entire message box
> +      public static final String AF_MESSAGES_BODY_STYLE_CLASS =
> +        "af|messages::body";
> +
> +
> +      // tr:panelSideBar style classes
> +      public static final String AF_PANEL_SIDE_BAR_BODY_STYLE_CLASS =
> +        "af|panelSideBar::body";
> +}
> Index:
> trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/CommandButtonRenderer.java
> ===================================================================
> ---
> trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/CommandButtonRenderer.java
   (revision
> 483170)
> +++
> trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/CommandButtonRenderer.java
   (working
> copy)
> @@ -15,19 +15,44 @@
>   */
> package org.apache.myfaces.trinidadinternal.renderkit.core.xhtml;
>
> +import java.awt.Color;
> +import java.awt.Font;
> +
> import java.io.IOException;
>
> +import java.util.Collection;
> import java.util.Collections;
> +import java.util.Iterator;
> import java.util.List;
>
> +import java.util.Map;
> +
> import javax.faces.component.UIComponent;
> +import javax.faces.context.ExternalContext;
> import javax.faces.context.FacesContext;
> import javax.faces.context.ResponseWriter;
>
> import org.apache.myfaces.trinidad.bean.FacesBean;
> import org.apache.myfaces.trinidad.bean.PropertyKey;
> +import org.apache.myfaces.trinidad.context.LocaleContext;
> +import org.apache.myfaces.trinidad.context.RenderingContext;
> +import org.apache.myfaces.trinidad.skin.Icon;
> +import org.apache.myfaces.trinidad.skin.Skin;
> +import org.apache.myfaces.trinidadinternal.agent.TrinidadAgent;
> +import org.apache.myfaces.trinidadinternal.image.ImageConstants;
> +import org.apache.myfaces.trinidadinternal.image.ImageProvider;
> +import org.apache.myfaces.trinidadinternal.image.ImageProviderResponse;
> +import org.apache.myfaces.trinidadinternal.image.cache.CompositeButtonKey
> ;
> +import
> org.apache.myfaces.trinidadinternal.image.cache.FileSystemImageCache;
> +import org.apache.myfaces.trinidadinternal.share.io.InputStreamProvider;
> +import org.apache.myfaces.trinidadinternal.share.io.NameResolver;
> +import org.apache.myfaces.trinidadinternal.skin.StyleSheetNameResolver;
> +import org.apache.myfaces.trinidadinternal.style.Style;
> +import org.apache.myfaces.trinidadinternal.style.StyleMap;
> +import org.apache.myfaces.trinidadinternal.style.util.FontProxy;
> import org.apache.myfaces.trinidad.component.core.nav.CoreCommandButton;
> -import org.apache.myfaces.trinidad.context.RenderingContext;
> +import
> org.apache.myfaces.trinidadinternal.renderkit.core.CoreImageContext;
> +import
> org.apache.myfaces.trinidadinternal.renderkit.core.CoreRenderingContext;
>
> public class CommandButtonRenderer extends CommandLinkRenderer
> {
> @@ -54,7 +79,220 @@
>    {
>      return true;
>    }
> +
> +
> +    // Key for Boolean Skin property which we use
> +    // to track whether buttons should be rendered as images.
> +    private static Object _IMAGE_BUTTON_KEY = new Object();
> +    private static Object _IMAGE_BUTTON_RTL_KEY = new Object();
> +
> +    // Tests whether button should be rendered as an image.
> +    // SLAF buttons are rendered using images if all three
> +    // button icons (start, end, background) specified.
> +    // Otherwise the button is rendered using the base.desktop
> +    // button implementation (browser buttons).
> +    static public boolean doRenderImageButton(
> +      )
> +    {
> +      // First, check the _IMAGE_BUTTON_KEY (or _IMAGE_BUTTON_RTL_KEY if
> rtl)
> +      // property on the Skin.
> +      //   This will be Boolean.TRUE if
> +      // we have all three icons, Boolean.FALSE if we
> +      // don't, or null if we haven't checked yet.
> +
> +      CoreRenderingContext coreRender =
> (CoreRenderingContext)RenderingContext.getCurrentInstance();
> +      boolean rtl = coreRender.isRightToLeft();
> +      Boolean value;
> +      Skin skin = coreRender.getSkin();
> +      if (rtl)
> +        value = (Boolean)skin.getProperty(_IMAGE_BUTTON_RTL_KEY);
> +      else
> +        value = (Boolean)skin.getProperty(_IMAGE_BUTTON_KEY);
>
> +      if (value != null)
> +        return (Boolean.TRUE == value);
> +
> +      // we fetch different icons if we are in the
> +      // right-to-left reading direction. context.getIcon takes care of
> +      // this, by adding the :rtl suffix to the icon name if the
> +      // reading direction is rtl.
> +      Icon startIcon = coreRender.getIcon(
> +
> CommandButtonConstants.BUTTON_START_ICON_NAME);
> +      Icon endIcon = coreRender.getIcon(
> +
> CommandButtonConstants.BUTTON_END_ICON_NAME);
> +      Icon topBackgroundIcon = coreRender.getIcon(
> +
> CommandButtonConstants.BUTTON_TOP_BACKGROUND_ICON_NAME);
> +      Icon bottomBackgroundIcon = coreRender.getIcon(
> +
> CommandButtonConstants.BUTTON_BOTTOM_BACKGROUND_ICON_NAME);
> +
> +      // If we are missing any of the icons, we don't render
> +      // the button image.
> +      if (startIcon == null || endIcon == null || topBackgroundIcon ==
> null || bottomBackgroundIcon == null)
> +      {
> +
> +        if (rtl)
> +          skin.setProperty(_IMAGE_BUTTON_RTL_KEY, Boolean.FALSE);
> +        else
> +          skin.setProperty(_IMAGE_BUTTON_KEY, Boolean.FALSE);
> +
> +        return false;
> +      }
> +      if (rtl)
> +        skin.setProperty(_IMAGE_BUTTON_RTL_KEY, Boolean.TRUE);
> +      else
> +        skin.setProperty(_IMAGE_BUTTON_KEY, Boolean.TRUE);
> +
> +      return true;
> +    }
> +
> +    protected Integer getFontSize(Style serverButtonStyle) {
> +        Integer serverFontSize =
> (Integer)serverButtonStyle.getParsedProperty(Style.FONT_SIZE_KEY);
> +        if(serverFontSize == null) {
> +            serverFontSize = new Integer(12);
> +        }
> +
> +        return serverFontSize;
> +    }
> +
> +    protected Integer getFontStyle(Style serverButtonStyle) {
> +        Integer serverFontStyle =
> (Integer)serverButtonStyle.getParsedProperty(Style.FONT_STYLE_KEY);
> +        if(serverFontStyle == null) {
> +            serverFontStyle = new Integer(0);
> +        }
> +
> +        return serverFontStyle;
> +    }
> +
> +    protected ImageProviderResponse getButtonImage(FacesContext context,
> UIComponent component, FacesBean bean) {
> +
> +        ImageProviderResponse response = null;
> +        try {
> +         //   UIXRenderingContext facesRender =
> FacesRenderingContext.getRenderingContext(context, component);
> +            RenderingContext renderingContext =
> RenderingContext.getCurrentInstance();
> +
> +            CoreRenderingContext coreContext =
> (CoreRenderingContext)renderingContext;
> +
> +            String generatedFiles =
> ((CoreRenderingContext)renderingContext).getStyleContext().getGeneratedFilesPath()+"/adf/images/cache";
> +
> +           // ImageProvider imageProvider =
> (ImageProvider)renderingContext.getProperties().get(
> ImageConstants.IMAGE_PROVIDER_PROPERTY);
> +            //imageProvider = FileSystemImageCache.getSharedCache
> (generatedFiles);
> +            ImageProvider imageProvider =
> (ImageProvider)coreContext.getImageContext().getProperty(
> ImageConstants.TECATE_NAMESPACE, ImageConstants.IMAGE_PROVIDER_PROPERTY);
> +
> +            ExternalContext externalContext = context.getExternalContext
> ();
> +            String contextPath = externalContext.getRequestContextPath();
> +
> +            StyleMap styleMap = coreContext.getStyleContext
> ().getStyleMap();
> +            Style serverButtonStyle = null;
> +
> +
> +            Icon startIcon = renderingContext.getIcon(
> +
> CommandButtonConstants.BUTTON_START_ICON_NAME);
> +             Icon endIcon = renderingContext.getIcon(
> +
> CommandButtonConstants.BUTTON_END_ICON_NAME);
> +             Icon topBackgroundIcon = renderingContext.getIcon(
> +
> CommandButtonConstants.BUTTON_TOP_BACKGROUND_ICON_NAME);
> +             Icon bottomBackgroundIcon = renderingContext.getIcon(
> +
> CommandButtonConstants.BUTTON_BOTTOM_BACKGROUND_ICON_NAME);
> +
> +            Icon startDisabledIcon = renderingContext.getIcon(
> +
> CommandButtonConstants.BUTTON_DISABLED_START_ICON_NAME);
> +             Icon endDisabledIcon = renderingContext.getIcon(
> +
> CommandButtonConstants.BUTTON_DISABLED_END_ICON_NAME);
> +             Icon topDisabledBackgroundIcon = renderingContext.getIcon(
> +
> CommandButtonConstants.BUTTON_DISABLED_TOP_BACKGROUND_ICON_NAME);
> +             Icon bottomDisabledBackgroundIcon = renderingContext.getIcon
> (
> +
> CommandButtonConstants.BUTTON_DISABLED_BOTTOM_BACKGROUND_ICON_NAME);
> +
> +            NameResolver nameResolver =
> StyleSheetNameResolver.createResolver(coreContext.getStyleContext());
> +
> +            InputStreamProvider startIsp;
> +            InputStreamProvider endIsp;
> +            InputStreamProvider borderBottonIsp;
> +            InputStreamProvider borderTopIsp;
> +
> +
> +            // Load up the icons used to generate the image
> +            if (getDisabled(bean)) {
> +                startIsp = nameResolver.getProvider
> (((String)startDisabledIcon.getImageURI(context,
> RenderingContext.getCurrentInstance())).replaceAll(contextPath, ""));
> +                endIsp = nameResolver.getProvider
> (((String)endDisabledIcon.getImageURI(context,
> RenderingContext.getCurrentInstance())).replaceAll(contextPath, ""));
> +                borderBottonIsp = nameResolver.getProvider
> (((String)topDisabledBackgroundIcon.getImageURI(context,
> RenderingContext.getCurrentInstance())).replaceAll(contextPath, ""));
> +                borderTopIsp = nameResolver.getProvider
> (((String)bottomDisabledBackgroundIcon.getImageURI(context,
> RenderingContext.getCurrentInstance())).replaceAll(contextPath, ""));
> +            } else {
> +                startIsp = nameResolver.getProvider
> (((String)startIcon.getImageURI(context,
> RenderingContext.getCurrentInstance())).replaceAll(contextPath, ""));
> +                endIsp = nameResolver.getProvider
> (((String)endIcon.getImageURI(context,RenderingContext.getCurrentInstance())).replaceAll(contextPath,
> ""));
> +                borderBottonIsp = nameResolver.getProvider
> (((String)topBackgroundIcon.getImageURI(context,
> RenderingContext.getCurrentInstance())).replaceAll(contextPath, ""));
> +                borderTopIsp = nameResolver.getProvider
> (((String)bottomBackgroundIcon.getImageURI(context,
> RenderingContext.getCurrentInstance())).replaceAll(contextPath, ""));
> +            }
> +
> +
> +
> +            if (getDisabled(bean)) {
> +               serverButtonStyle = styleMap.getStyleByName(
> coreContext.getStyleContext(),"AFButtonServerTextDisabled");
> +            } else {
> +               serverButtonStyle = styleMap.getStyleByName(
> coreContext.getStyleContext(),"AFButtonServerText");
> +            }
> +
> +            Integer serverFontSize = getFontSize(serverButtonStyle);
> +            Integer serverFontStyle = getFontStyle(serverButtonStyle);
> +
> +            Collection serverFont =
> (Collection)serverButtonStyle.getParsedProperty(Style.FONT_FAMILIES_KEY);
> +            String fontName = null;
> +            Font fontImpl = null;
> +            if(serverFont == null){
> +                fontName = "Dialog";
> +                fontImpl = new Font(fontName, serverFontStyle,
> serverFontSize);
> +            } else {
> +                Iterator fonts = serverFont.iterator();
> +                while(fonts.hasNext()) {
> +                    fontName = (String)fonts.next();
> +                    fontImpl = new Font(fontName, serverFontStyle,
> serverFontSize);
> +                    if(fontImpl != null)
> +                        break;
> +                }
> +            }
> +            FontProxy myFontProxy = new FontProxy(fontImpl);
> +
> +            String text = getText(bean);
> +
> +            char accessKey;
> +            if (supportsAccessKeys(coreContext))
> +            {
> +              accessKey = getAccessKey(bean);
> +            }
> +            else
> +            {
> +              accessKey = CHAR_UNDEFINED;
> +            }
> +
> +            Color textColor = (Color)serverButtonStyle.getParsedProperty(
> Style.FOREGROUND_KEY);
> +            Color bgColor = (Color)serverButtonStyle.getParsedProperty(
> Style.BACKGROUND_KEY);
> +
> +            if(textColor == null) {
> +                textColor = Color.black;
> +            }
> +
> +            if(bgColor == null) {
> +                bgColor = Color.WHITE;
> +            }
> +
> +            Boolean useAntiAlias =
> (Boolean)serverButtonStyle.getParsedProperty(Style.TEXT_ANTIALIAS_KEY);
> +            if(useAntiAlias == null) {
> +                useAntiAlias = new Boolean(true);
> +            }
> +
> +            CompositeButtonKey button = new CompositeButtonKey(
> coreContext.getImageContext(), "", text, text, textColor, bgColor, new
> Color(0,0,0,0), myFontProxy, getDisabled(bean), useAntiAlias, accessKey,
> +            startIsp,
> +            endIsp,
> +            borderBottonIsp,
> +            borderTopIsp);
> +
> +            response = imageProvider.getImage(coreContext.getImageContext(),
> button);
> +        } catch(Exception e) {
> +            e.printStackTrace();
> +        }
> +        return response;
> +    }
> +
>    @Override
>    protected void encodeAll(
>      FacesContext        context,
> @@ -71,74 +309,122 @@
>      // Make sure we don't have anything to save
>      assert(arc.getCurrentClientId() == null);
>      arc.setCurrentClientId(clientId);
> -
> -    boolean useButtonTag = useButtonTags(arc);
> -    String element = useButtonTag ? "button" : "input";
> -    ResponseWriter rw = context.getResponseWriter();
> -    rw.startElement(element, component);
> -    renderId(context, component);
> +
> +    if(doRenderImageButton()) {
> +    ////////////
> +        ResponseWriter rw = context.getResponseWriter();
> +        rw.startElement("a", component);
>
> -    // Write the text and access key
> -    String text = getText(bean);
> -    String icon = getIcon(bean);
> +        if (getDisabled(bean) || !supportsNavigation(arc))
> +        {
> +          renderId(context, component);
> +          renderStyleAttributes(context, arc, bean);
> +        }
> +        else
> +        {
> +          renderId(context, component);
> +          renderAllAttributes(context, arc, bean);
>
> -    if (useButtonTag)
> -      rw.writeAttribute("type", getButtonType(), null);
> -    else if (icon != null)
> -      rw.writeAttribute("type", "image", null);
> -    else
> -      rw.writeAttribute("type", getInputType(), null);
> +          // If we have an onclick handler, always provide a destination
> +          String destination = getDestination(bean);
> +          if ((destination == null) && hasOnclick(bean))
> +          {
> +            destination = "#";
> +          }
>
> -    if (getDisabled(bean))
> -    {
> -      rw.writeAttribute("disabled", Boolean.TRUE, "disabled");
> -      // Skip over event attributes when disabled
> -      renderStyleAttributes(context, arc, bean);
> -    }
> -    else
> -    {
> -      renderAllAttributes(context, arc, bean);
> -    }
> +          renderEncodedActionURI(context, "href", destination);
>
> -    char accessKey;
> -    if (supportsAccessKeys(arc))
> -    {
> -      accessKey = getAccessKey(bean);
> -      if (accessKey != CHAR_UNDEFINED)
> -      {
> -        rw.writeAttribute("accesskey",
> -                          new Character(accessKey),
> -                          "accessKey");
> -      }
> +          if (!Boolean.FALSE.equals(
> +                  arc.getAgent().getCapabilities().get(
> TrinidadAgent.CAP_TARGET)))
> +          {
> +            rw.writeAttribute("target", getTargetFrame(bean), null);
> +          }
> +        }
> +        ////
> +        ImageProviderResponse buttonImage = getButtonImage(context,
> component, bean);
> +        String buttonImageURI = buttonImage.getImageURI();
> +
> +        rw.startElement("img", component);
> +
> +        ExternalContext externalContext = context.getExternalContext();
> +        String contextPath = externalContext.getRequestContextPath();
> +        CoreRenderingContext coreRenderContext =
> (CoreRenderingContext)RenderingContext.getCurrentInstance();
> +        CoreImageContext imageContext =
> (CoreImageContext)coreRenderContext.getImageContext();
> +        rw.writeAttribute("src",
> contextPath+"/adf/images/cache/"+buttonImageURI, null);
> +        rw.endElement("img");
> +
> +        rw.endElement("a");
> +
> +      //  super.encodeEnd(context, arc, component, bean);
> +    } else {
> +        boolean useButtonTag = useButtonTags(arc);
> +        String element = useButtonTag ? "button" : "input";
> +        ResponseWriter rw = context.getResponseWriter();
> +        rw.startElement(element, component);
> +        renderId(context, component);
> +
> +        // Write the text and access key
> +        String text = getText(bean);
> +        String icon = getIcon(bean);
> +
> +        if (useButtonTag)
> +          rw.writeAttribute("type", getButtonType(), null);
> +        else if (icon != null)
> +          rw.writeAttribute("type", "image", null);
> +        else
> +          rw.writeAttribute("type", getInputType(), null);
> +
> +        if (getDisabled(bean))
> +        {
> +          rw.writeAttribute("disabled", Boolean.TRUE, "disabled");
> +          // Skip over event attributes when disabled
> +          renderStyleAttributes(context, arc, bean);
> +        }
> +        else
> +        {
> +          renderAllAttributes(context, arc, bean);
> +        }
> +
> +        char accessKey;
> +        if (supportsAccessKeys(arc))
> +        {
> +          accessKey = getAccessKey(bean);
> +          if (accessKey != CHAR_UNDEFINED)
> +          {
> +            rw.writeAttribute("accesskey",
> +                              new Character(accessKey),
> +                              "accessKey");
> +          }
> +        }
> +        else
> +        {
> +          accessKey = CHAR_UNDEFINED;
> +        }
> +
> +        if (useButtonTag)
> +        {
> +          AccessKeyUtils.renderAccessKeyText(context,
> +                                             text,
> +                                             accessKey,
> +
> SkinSelectors.AF_ACCESSKEY_STYLE_CLASS);
> +          if (icon != null)
> +            OutputUtils.renderImage(context, arc, icon, null, null, null,
> +                                    getShortDesc(bean));
> +        }
> +        else
> +        {
> +          if (icon != null)
> +          {
> +            renderEncodedResourceURI(context, "src", icon);
> +          }
> +          else
> +          {
> +            rw.writeAttribute("value", text, "text");
> +          }
> +        }
> +
> +        rw.endElement(element);
>      }
> -    else
> -    {
> -      accessKey = CHAR_UNDEFINED;
> -    }
> -
> -    if (useButtonTag)
> -    {
> -      AccessKeyUtils.renderAccessKeyText(context,
> -                                         text,
> -                                         accessKey,
> -
> SkinSelectors.AF_ACCESSKEY_STYLE_CLASS);
> -      if (icon != null)
> -        OutputUtils.renderImage(context, arc, icon, null, null, null,
> -                                getShortDesc(bean));
> -    }
> -    else
> -    {
> -      if (icon != null)
> -      {
> -        renderEncodedResourceURI(context, "src", icon);
> -      }
> -      else
> -      {
> -        rw.writeAttribute("value", text, "text");
> -      }
> -    }
> -
> -    rw.endElement(element);
>    }
>
>    protected String getButtonType()
> Index:
> trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/StyleSheetNameResolver.java
> ===================================================================
> ---
> trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/StyleSheetNameResolver.java
> (revision 483170)
> +++
> trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/StyleSheetNameResolver.java
> (working copy)
> @@ -47,7 +47,7 @@
>   * @version $Name:  $ ($Revision:
> adfrt/faces/adf-faces-impl/src/main/java/oracle/adfinternal/view/faces/skin/StyleSheetNameResolver.java#0
> $) $Date: 10-nov-2005.18:59:02 $
>   * @author The Oracle ADF Faces Team
>   */
> -class StyleSheetNameResolver implements NameResolver
> +public class StyleSheetNameResolver implements NameResolver
> {
>    /**
>     * Creates a NameResolver which can locate style sheets
>
>
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message