krysalis-jplugin/src/java/org/krysalis/swingx/concerns RenderingHintsConcern.java,NONE,1.1

[email protected]
Newsgroups gmane.comp.krysalis.metamorphosis.cvs
Message-ID <[email protected]>
Update of /cvsroot/metamorphosis/krysalis-jplugin/src/java/org/krysalis/swingx/concerns
In directory sc8-pr-cvs1:/tmp/cvs-serv32290/src/java/org/krysalis/swingx/concerns

Added Files:
	RenderingHintsConcern.java 
Log Message:
Rename to a new more generic name.

--- NEW FILE: RenderingHintsConcern.java ---
/*****************************************************************************
 * Copyright (C) The Krysalis project. All rights reserved.                  *
 * ------------------------------------------------------------------------- *
 * This software is published under the terms of the Krysalis Software       *
 * License version 1.1_01, a copy of which has been included  with this      *
 * distribution in the LICENSE file.                                         *
 *****************************************************************************/
package org.krysalis.swingx.concerns;

import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;

import net.sf.cglib.BeforeAfterInterceptor;
import net.sf.cglib.Enhancer;

/**
 * 
 * Decorates components with antialiasing and keeps track of
 * antialiasing status.
 * 
 * Example:
 * JTextArea jTextArea = (JTextArea)RenderingHintsConcern.newInstance( javax.swing.JTextArea.class );
 * 
 *@author     <a href="mailto:[email protected]">Nicola Ken Barozzi</a>
 *@created    June 20, 2001
 *@version    1.0
 */
public class RenderingHintsConcern extends BeforeAfterInterceptor {

  static RenderingHintsConcern callback = new RenderingHintsConcern();
  
    private static boolean enabled = true;
    private static final Map antialiasingHints= new HashMap();
    private static Map hints= new HashMap();
          
          
  private RenderingHintsConcern() {
    antialiasingHints.put(RenderingHints.KEY_ANTIALIASING,
            RenderingHints.VALUE_ANTIALIAS_ON);
    antialiasingHints.put(RenderingHints.KEY_RENDERING,
            RenderingHints.VALUE_RENDER_QUALITY);
    antialiasingHints.put(RenderingHints.KEY_TEXT_ANTIALIASING,
            RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
    antialiasingHints.put(RenderingHints.KEY_FRACTIONALMETRICS,
            RenderingHints.VALUE_FRACTIONALMETRICS_ON);
            
    hints = antialiasingHints;
    
  }

  
      public static  Object newInstance( Class clazz ){
        try{  
            return Enhancer.enhance(clazz, null, callback);
        }catch( Throwable e ){
           e.printStackTrace(); 
           throw new Error(e.getMessage());
        }  
    
      }

    
      /** this method is invoked after execution
       * @param obj this
       * @param method Method
       * @param args Arg array
       * @param retValFromBefore value returned from beforeInvoke
       * @param invokedSuper value returned from invoke super
       * @param retValFromSuper value returner from super
       * @param e Exception thrown by super
       * @throws Throwable any exeption
       * @return value to return from generated method
       */
      public Object afterReturn(Object obj,
                                 Method method, 
                                 Object[] args, 
                                 boolean invokedSuper, 
                                 Object retValFromSuper, 
                                 Throwable e) throws java.lang.Throwable {
       
           if(e != null){
             throw e.fillInStackTrace();
           }

           //do nothing, as the real method has to do any necessary 
           //hint resetting nad our settings are default                  
        
          return retValFromSuper;
      }
    
      /** Generated code calls this method before invoking super
       * @param obj this
       * @param method Method
       * @param args Arg array
       * @param retValFromBefore value returned from beforeInvoke
       * @throws Throwable any exeption to stop execution
       * @return true if need to invoke super
       */
      public boolean invokeSuper(Object obj, java.lang.reflect.Method method, Object[] args) throws java.lang.Throwable {
        
        if(method.getName().equals("paint")){
          if (enabled) {
              Graphics2D g = (Graphics2D) args[0] ;
              g.setRenderingHints(hints);

          }

        }    
          return true;
      }
    
    public static boolean isEnabled() {
      return enabled;
    }

    public static void setEnabled(boolean enabled) {
      RenderingHintsConcern.enabled = enabled;
    }

    public static Map getHints() {
      return hints;
    }

    public static void setHints(Map hints) {
      RenderingHintsConcern.hints = hints;
    }

    public static Map getAntialiasingHints() {
      return antialiasingHints;
    }

}







-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.