Java-注解

定义

注解(Annotation),也叫元数据。一种代码级别的说明。它是JDK1.5及以后版本引入的一个特性,与类、接口、枚举是在同一个层次。
它可以声明在包、类、字段、方法、局部变量、方法参数等的前面,用来对这些元素进行说明、注释、标注。

作用

  • 编写文档:通过代码里标识的元数据生成文档【生成文档doc文档】
  • 反射解析:通过代码里标识的元数据对代码进行分析,跟踪代码中的依赖性【使用反射】
  • 编译检查:通过代码里标识的元数据让编译器能够实现基本的编译检查【Override】

分类

基本内置注解

@Override

它的作用是对覆盖超类中方法的方法进行标记,如果被标记的方法并没有实际覆盖超类中的方法,则编译器会发出错误警告。

package annotation;
 
public class Hero {
 
    String name;
    @Override
    public String toString(){
        return name;
    }
    @Override
    public String fromString(){
        return name;
    }
}

在fromString()方法上加上@Override 注解,就会提示错误警告。因为Hero类的父类Object,并没有fromString方法。

@Deprecated

它的作用是对不应该再使用的方法添加注解,当编程人员使用这些方法时,将会在编译时提示已经过时。

package annotation;
 
public class Hero {
 
    String name;
     
    @Deprecated
    public void hackMap(){
         
    }
    public static void main(String[] args) {
        new Hero().hackMap();
    }
 
}

方法hackMap被注解为过期,在调用的时候,就会提示已经过期警告。

@SuppressWarnings

Suppress英文的意思是抑制的意思,这个注解的用处是忽略警告信息。

参数有:

  • deprecation:使用了不赞成使用的类或方法时的警告(使用@Deprecated使得编译器产生的警告);
  • unchecked:执行了未检查的转换时的警告,例如当使用集合时没有用泛型 (Generics) 来指定集合保存的类型; 关闭编译器警告
  • fallthrough:当 Switch 程序块直接通往下一种情况而没有 Break 时的警告;
  • path:在类路径、源文件路径等中有不存在的路径时的警告;
  • serial:当在可序列化的类上缺少 serialVersionUID 定义时的警告;
  • finally:任何 finally 子句不能正常完成时的警告;
  • rawtypes 泛型类型未指明
  • unused 引用定义了,但是没有被使用
  • all:关于以上所有情况的警告。
package annotation;
 
import java.util.ArrayList;
import java.util.List;
 
public class Hero {
    String name;
    @SuppressWarnings({ "rawtypes", "unused" })
    public static void main(String[] args) {
        List heros = new ArrayList();
    }
 
}

加上 @SuppressWarnings({ “rawtypes”, “unused” })后,就对这些警告进行了抑制,即忽略掉这些警告信息。编译器将不会出现警告。

@FunctionalInterface

@FunctionalInterface这是Java1.8 新增的注解,用于约定函数式接口。
函数式接口概念: 如果接口中只有一个抽象方法(可以包含多个默认方法或多个static方法),该接口称为函数式接口。函数式接口其存在的意义,主要是配合Lambda 表达式 来使用。

package annotation;
 
@FunctionalInterface
public interface Inter1 {
    public void adAttack();
}

Inter1 只有一个抽象方法,可以被注解为@FunctionalInterface

package annotation;
 
@FunctionalInterface
public interface Inter2 {
    public void apAttack();
    public void apAttack2();
}

Inter1 有两个方法apAttack()和apAttack2(),那么就不能被注解为函数式接口。

元注解

讲解元注解概念之前,我们先建立元数据的概念。

元数据:为其他数据提供信息的数据。就是上面所说的注解。
元注解:用于注解 自定义注解注解

元注解有这么几种:

  • @Target
  • @Retention
  • @Inherited
  • @Documented
  • @Repeatable (java1.8 新增)
@Target

用于声明注解修饰范围。
例如:@Target({METHOD,TYPE}),表示他可以用在 方法和类型(类和接口)等上,但是不能放在属性等其他位置。
枚举值:

  • ElementType.TYPE:能修饰类、接口或枚举类型
  • ElementType.FIELD:能修饰成员变量
  • ElementType.METHOD:能修饰方法
  • ElementType.PARAMETER:能修饰参数
  • ElementType.CONSTRUCTOR:能修饰构造器
  • ElementType.LOCAL_VARIABLE:能修饰局部变量
  • ElementType.ANNOTATION_TYPE:能修饰注解
  • ElementType.PACKAGE:能修饰包
@Target({METHOD,TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Inherited
@Documented
public @interface JDBCConfig {
     String ip();
     int port() default 3306;
     String database();
     String encoding();
     String loginName();
     String password();
}

可以在类、方法使用

@JDBCConfig(ip = "192.168.1.103", database = "mysql", encoding = "utf-8", loginName = "dbuser", password = "111111")
public class AnnotationDemo {

    @JDBCConfig(ip = "192.168.1.103", database = "mysql", encoding = "utf-8", loginName = "dbuser", password = "111111")
    public void test(){
    }
}

但是不能在成员属性前使用

@JDBCConfig(ip = "192.168.1.103", database = "mysql", encoding = "utf-8", loginName = "dbuser", password = "111111")
public class AnnotationDemo {
    @JDBCConfig(ip = "192.168.1.103", database = "mysql", encoding = "utf-8", loginName = "dbuser", password = "111111")
    public void test(){}
    
    /* 编译报错 */
    @JDBCConfig(ip = "192.168.1.103", database = "mysql", encoding = "utf-8", loginName = "dbuser", password = "111111")
    public String ip;
}
@Retention

@Retention 表示生命周期。 @Retention可选的值有3个:

  • RetentionPolicy.SOURCE: 注解只在源代码中存在,编译成class之后,就没了。@Override 就是这种注解
  • RetentionPolicy.CLASS: 注解在java文件编程成.class文件后,依然存在,但是运行起来后就没了@Retention的默认值,即当没有显式指定@Retention的时候,就会是这种类型。
  • RetentionPolicy.RUNTIME: 注解在运行起来之后依然存在,程序可以通过反射获取这些信息,自定义注解@JDBCConfig 就是这样。
@Target({METHOD,TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Inherited
@Documented
 
public @interface JDBCConfig {
     String ip();
     int port() default 3306;
     String database();
     String encoding();
     String loginName();
     String password();
}
@Inherited

@Inherited 表示该注解具有继承性。使得子类可以反射获取父类注解信息

注解JDBCConfig 含有元注解@Inherited

@Target({METHOD,TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Inherited
@Documented
@interface JDBCConfig {
    String ip();
    int port() default 3306;
    String database();
    String encoding();
    String loginName();
    String password();
}

类DBUtil使用注解

@JDBCConfig(ip = "192.168.1.103", database = "mysql", encoding = "utf-8", loginName = "dbuser", password = "111111")
class DBUtil{

}

类ChildDBUtil继承DBUtil,并获取父类注解信息

class ChildDBUtil extends DBUtil{
    public static void test(){
        JDBCConfig annotation = ChildDBUtil.class.getAnnotation(JDBCConfig.class);
        String ip = annotation.ip();
        int port = annotation.port();
        String loginName = annotation.loginName();
        String password = annotation.password();

        System.out.println("ip="+ip+",port="+port+",loginName="+loginName+",password="+password);
    }
}

运行输出

public class AnnotationDemo {
    public static void main(String[] argv){
        ChildDBUtil.test();
    }
}

输出:
ip=192.168.1.103,port=3306,loginName=dbuser,password=111111

结果看出,子类可以通过反射获取父类的注解信息。

如果注解删除元注解@Inherited

@Target({METHOD,TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@interface JDBCConfig {
    String ip();
    int port() default 3306;
    String database();
    String encoding();
    String loginName();
    String password();
}

运行报错:

Exception in thread "main" java.lang.NullPointerException
	at 注解.ChildDBUtil.test(AnnotationDemo.java:17)
	at 注解.AnnotationDemo.main(AnnotationDemo.java:10)

子类不能通过反射获取父类的注解信息。

@Documented

在用javadoc命令生成API文档后,DBUtil的文档里会出现该注解说明。

@Repeatable

表示这个声明的注解是可重复的。@Repeatable的值是另一个注解,其可以通过这个另一个注解的值来包含这个可重复的注解。
很拗口,看例子
文件夹中有很多文件类型,比如:java, html, css, js等待。

FileType 注解

@Target(  METHOD )
@Retention( RetentionPolicy.RUNTIME )
@Repeatable( FileTypes.class )
public @interface FileType {
    String value();
};

FileTypes 注解

@Target( METHOD)
@Retention( RetentionPolicy.RUNTIME )
public @interface FileTypes {
    FileType[] value();
}

其中,@FileType注解上的元注解@Repeatable中的值使用了@FileTypes注解,@FileTypes 注解中包含的值类型是一个@FileType注解的数组。
这就解释了官方文档中@Repeatable中值的使用。

调用:

public class FindFiles {
    public static void main(String[] argv) throws NoSuchMethodException {
        FileType[] annotations = FindFiles.class.getMethod("test").getAnnotationsByType(FileType.class);

        for(FileType fileType : annotations){
            System.out.println(fileType.value());
        }
    }

    @FileType("java")
    @FileType("txt")
    @FileType("jsp")
    public static void test(){

    }
}

输出:
java
txt
jsp

public T[] getAnnotationsByType(Class annotationClass);可以获取注解集合

自定义注解

它类似于新创建一个接口文件,但为了区分,注解类型声明为 @interface
上述元注解讲解中JDBCConfig、FileType等就是自定义注解。
例子:获取一个连接数据库test的连接Connection实例

public class DBUtil {
    static String ip = "127.0.0.1";
    static int port = 3306;
    static String database = "test";
    static String encoding = "UTF-8";
    static String loginName = "root";
    static String password = "admin";
    static{
        try {
            Class.forName("com.mysql.jdbc.Driver");
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }
   
    public static Connection getConnection() throws SQLException {
        String url = String.format("jdbc:mysql://%s:%d/%s?characterEncoding=%s", ip, port, database, encoding);
        return DriverManager.getConnection(url, loginName, password);
    }
    
    public static void main(String[] args) throws SQLException {
        Connection c = getConnection();
        System.out.println(c);
    }
}

但是数据库相关信息写死在代码里,下面通过注解方式配置数据库信息。

1、自定义注解JDBCConfig

@Target({METHOD,TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Inherited
@Documented
public @interface JDBCConfig {
     String ip();
     int port() default 3306;
     String database();
     String encoding();
     String loginName();
     String password();
}

2、注解方式DBUtil
数据库相关配置信息本来是以属性的方式存放的,现在改为了以注解的方式,提供这些信息了。

@JDBCConfig(ip = "127.0.0.1", database = "test", encoding = "UTF-8", loginName = "root", password = "admin")
public class DBUtil {
    static {
        try {
            Class.forName("com.mysql.jdbc.Driver");
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }
 
}

3、解析注解
通过反射,获取这个DBUtil这个类上的注解对象。
public <A extends Annotation> A getAnnotation(Class<A> annotationClass)

@JDBCConfig(ip = "127.0.0.1", database = "test", encoding = "UTF-8", loginName = "root", password = "admin")
public class DBUtil {
    static {
        try {
            Class.forName("com.mysql.jdbc.Driver");
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }
 
    public static Connection getConnection() throws SQLException, NoSuchMethodException, SecurityException {
        /* 通过反射,获取这个DBUtil这个类上的注解对象 */
        JDBCConfig config = DBUtil.class.getAnnotation(JDBCConfig.class);
 
        /* 通过注解对象方法,获取各个注解元素的值 */
        String ip = config.ip();
        int port = config.port();
        String database = config.database();
        String encoding = config.encoding();
        String loginName = config.loginName();
        String password = config.password();
 
        String url = String.format("jdbc:mysql://%s:%d/%s?characterEncoding=%s", ip, port, database, encoding);
        return DriverManager.getConnection(url, loginName, password);
    }
     
    public static void main(String[] args) throws NoSuchMethodException, SecurityException, SQLException {
        Connection c = getConnection();
        System.out.println(c);
    }
}

仿hibernate

解决如下问题:

  1. 当前类是否实体类?
  2. 表名称?
  3. 主键对应哪个属性, 自增长策略是什么,对应字段名称是什么?
  4. 非主键属性对应字段名称是什么?

1、自定义hibernate注解
实体类注解

@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
public @interface MyEntity {
 
}

表注解

@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
public @interface MyTable {
 
    String name();
}

主键注解

@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface MyId {
 
}

自增注解

@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface MyGeneratedValue {
    String strategy();
}

字段注解

@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface MyColumn {
    String value();
}

2、运用在Hero对象

@MyEntity
@MyTable(name="hero_")
public class Hero {
    private int id;
    private String name;
    private int damage;
    private int armor;
     
    @MyId
    @MyGeneratedValue(strategy = "identity")
    @MyColumn("id_")
    public int getId() {
        return id;
    }
    
    public void setId(int id) {
        this.id = id;
    }
    
    @MyColumn("name_")
    public String getName() {
        return name;
    }
    
    public void setName(String name) {
        this.name = name;
    }
    
    @MyColumn("damage_")
    public int getDamage() {
        return damage;
    }
    
    public void setDamage(int damage) {
        this.damage = damage;
    }
    
    @MyColumn("armor_")
    public int getArmor() {
        return armor;
    }
    
    public void setArmor(int armor) {
        this.armor = armor;
    }
}

3、创建一个解析类ParseHibernateAnnotation ,获取Hero类上配置的注解信息
思路如下:

  1. 首先获取Hero.class类对象。Hero.class
  2. 判断本类是否进行了MyEntity注解。getAnnotation(MyEntity.class)
  3. 获取注解 MyTable。getAnnotation(MyTable.class)
  4. 遍历所有的方法,如果某个方法有MyId注解,那么就记录为主键方法primaryKeyMethod。getAnnotation(MyId.class)
  5. 把主键方法的自增长策略注解MyGeneratedValue和对应的字段注解MyColumn 取出来。getAnnotation(MyGeneratedValue.class)、getAnnotation(MyColumn.class)
  6. 遍历所有非主键方法,并且有MyColumn注解的方法,打印属性名称和字段名称的对应关系。getAnnotation(MyColumn.class)
public class ParseHibernateAnnotation {
 
    public static void main(String[] args) {
 
        /* 获取Hero.class类对象 */
        Class<Hero> clazz = Hero.class;
        
        /* 判断本类是否进行了MyEntity注解 */
        MyEntity myEntity = (MyEntity) clazz.getAnnotation(MyEntity.class);
        if (null == myEntity) {
            System.out.println("Hero类不是实体类");
        } else {
            System.out.println("Hero类是实体类");
            
            /* 获取注解 MyTable */
            MyTable myTable= (MyTable) clazz.getAnnotation(MyTable.class);
            String tableName = myTable.name();
            System.out.println("其对应的表名是:" + tableName);
            
            /* 遍历所有的方法 */
            Method[] methods =clazz.getMethods();
            Method primaryKeyMethod = null;
            for (Method m: methods) {
                /* 判断是否有MyId注解 */
                MyId myId = m.getAnnotation(MyId.class);
                if(null!=myId){
                    /* 获取主键方法 */
                    primaryKeyMethod = m;
                    break;
                }
            }
             
            if(null!=primaryKeyMethod){
                System.out.println("找到主键:" + method2attribute( primaryKeyMethod.getName() ));
                
                /* 获取主键自增属性 */
                MyGeneratedValue myGeneratedValue = primaryKeyMethod.getAnnotation(MyGeneratedValue.class);
                System.out.println("其自增长策略是:" +myGeneratedValue.strategy());
                
                /* 获取主键字段名 */
                MyColumn myColumn = primaryKeyMethod.getAnnotation(MyColumn.class);
                System.out.println("对应数据库中的字段是:" +myColumn.value());
            }
            System.out.println("其他非主键属性分别对应的数据库字段如下:");
            
            /* 遍历所有的方法,获取非主键方法*/
            for (Method m: methods) {
                if(m==primaryKeyMethod){
                    continue;
                }
                MyColumn myColumn = m.getAnnotation(MyColumn.class);
                if(null==myColumn)
                    continue;
                System.out.format("属性: %s\t对应的数据库字段是:%s%n",method2attribute(m.getName()),myColumn.value());
 
            }
        }
    }
 
    private static String method2attribute(String methodName) {
        String result = methodName; ;
        result = result.replaceFirst("get", "");
        result = result.replaceFirst("is", "");
        if(result.length()<=1){
            return result.toLowerCase();
        }
        else{
            return result.substring(0,1).toLowerCase() + result.substring(1,result.length());
        }
         
    }
}

目前,各种 Java 框架,如 Spring,Hibernate,Junit等均大量使用自定义的注解,用于登陆、权限拦截、日志处理等,内部都是通过运行时靠反射获取注解。

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
使用方法: 1、解压至C:\Program Files目录下(密码:xiaoqing); 2、双击导入注册表C:\Program Files\BCGSoft\BCGControlBarPro\bcgcontrolbarpro.12.00.reg; 3、运行向导C:\Program Files\BCGSoft\BCGControlBarPro\BCGCBProIntegrationWizard.exe。 与其它不同之处: 1、包含完整的源代码、帮助文件; 2、已经对 BCGPAppWizard2005 中的向导进行汉化,在 Visual Studio 2008(2010) 中可使用中文向导 BCGPAppWizard (参考 Visual Studio 2008 原有的中文向导,如果您想学习汉化向导,参考目录是:C:\Program Files\Microsoft Visual Studio 9.0\VC\VCWizards\AppWiz\MFC\Application\templates\2052) 关于静态链接: 1、首先必须在运行向导BCGCBProIntegrationWizard.exe时已经编译静态库; 2、在 Visual Studio 建立项目向导时,选择静态链接即可。 关于使用 Office2007、2010 风格: 如果您使用了这些新风格,必须在项目中包括这些资源,否则 debug 版本启动时会报错(缺少资源,release版本不会提示,但显示不正常),具体有二种方法: 1、直接在“解决方案资源管理器”-“资源文件”中点右键,“添加”-“现有项”,把C:\Program Files\BCGSoft\BCGControlBarPro\BCGCBPro\Styles中所有扩展名为 .rc 的资源包括进来即可。 2、直接在“资源视图”-“您的项目”上点右键,选择“资源包括”,在“资源包括”中的“编译时指令”中的#include "BCGCBPro.rc"后面添加以下代码: #include "C:\Program Files\BCGSoft\BCGControlBarPro\BCGCBPro\Styles\BCGPStyle2007Aqua.rc" #include "C:\Program Files\BCGSoft\BCGControlBarPro\BCGCBPro\Styles\BCGPStyle2007Luna.rc" #include "C:\Program Files\BCGSoft\BCGControlBarPro\BCGCBPro\Styles\BCGPStyle2007Obsidian.rc" #include "C:\Program Files\BCGSoft\BCGControlBarPro\BCGCBPro\Styles\BCGPStyle2007Silver.rc" #include "C:\Program Files\BCGSoft\BCGControlBarPro\BCGCBPro\Styles\BCGPStyle2010White.rc" #include "C:\Program Files\BCGSoft\BCGControlBarPro\BCGCBPro\Styles\BCGPStyleCarbon.rc" #include "C:\Program Files\BCGSoft\BCGControlBarPro\BCGCBPro\Styles\BCGPStyleScenic.rc" 3、如果使用动态库链接,请手工编译C:\Program Files\BCGSoft\BCGControlBarPro\BCGCBPro\Styles\Office2007_styles.sln或者build_all.dsp 仅为学习使用,下载后24小时内删除,请支持 BCGSoft 购买正版,本人不提供技术支持,不对任何负责。 尊重他人劳动成果,欢迎与大家分享成果。 官方更新说明: http://www.bcgsoft.com/bcgcontrolbarpro-versions.htm Version 12.0. Released 01/20/2010 New features CBCGPVisualManager2010 implements Microsoft Office 2010 Beta 1 color themes: Blue theme (see screenshot) Black theme (see screenshot) Silver theme (see screenshot) Just activate CBCGPVisualManager2010 to use these new themes in your application: CBCGPVisualManager::SetDefaultManager (RUNTIME_CLASS (CBCGPVisualManager2010)); Please run BCGPMSOffice2007Demo, DrawCli or BCGPOrganizer to see this feature in action. Added Microsoft Office 2010-style Ribbon Backstage View (see screenshot). The following new methods were added to CBCGPRibbonBar class: SetBackstageMode: enables/disables Backstage View mode. IsBackstageMode: returns TRUE if Backstage View mode is enabled. AddBackstageCategory: creates Backstage View category. GetBackstageCategory: returns Backstage View category. IsBackstageViewActive: returns TRUE if Backstage View is currently active. By default, the Ribbon Application button will be displayed with the default (blue) color, but developers can customize its appearance by calling visual manager's new method 'SetMainButtonColor' (see screenshot). CBCGPRibbonBar::AddBackstageCategory returns a pointer to the new class object - CBCGPRibbonBackstageViewPanel. Usually, you'll need to call the following class methods to create your backstage view: AddCommand: add a single command button such as "Save", "Save As" or "Exit". AddView: add a button with attached right-side form ("Print", "Recent Files" and so on). There are 2 new classes that should be used for implementing right-side views: CBCGPRibbonBackstageViewItemForm: a single page dialog CBCGPRibbonBackstageViewItemPropertySheet: multi-page Please note that our Application Wizards were updated and now, when you're creating a new, Ribbon-based application, you can choose "Backstage view" option (see screenshot) and initial backstage view code will be automatically generated for your pleasure!. The Ribbon bar Application ("main") Button can display a text label instead of icon in the "scenic" mode (usually "File" in English language UI). The following new methods were added to the CBCGPRibbonMainButton class: SetScenicText GetScenicText Implemented ability to add Ribbon Galleries to the dialogs (see screenshot). The new class CBCGPRibbonGalleryCtrl may be used for this purpose. Please take a look at BCGPMSOffice2007Demo example (Backstage view pages) to see this new control in action. Implemented Resizable Dialogs support (see screenshot1 and screenshot2): Added 2 new classes: CBCGPControlsLayout: implements the base class for all layout managers. CBCGPStaticLayout: implements "static" layout management based on anchors. To enable layout support, you've to call EnableLayout/GetLayout methods in the following classes: CBCGPDialog CBCGPDialogBar CBCGPropertyPage CBCGPFormView Please run ResizableForm new sample to see this feature in action. In addition, you can see this feature in the following examples and samples: BCGPMSOffice2007Demo: "Clipboard" Pane and Backstage view. BCGPOrganizer: resizable dialog bar. RibbonGadgets: backstage view. ToolBoxDemo: resizable form Significantly improved CBCGPVisualManagerVS2010 (see screenshot): The color scheme is identical to Visual Studio 2010 Beta 2. Added a new Smart Docking style (BCGP_SDT_VS2010). You can run BCGPVisualStudioGUIDemo example to examine this look. Added content scrolling support to CBCGPDockingControlBar-derived classes (see screenshot). By default, the scrolling is implemented in CBCGPDialogBar class only, but you can easily add this support to any CBCGPDockingControlBar-derived class (please take a look at BCGPGridExample example, COutputBar class). CBCGPDockingBarScrollButton class implements docking pane scroll button (vertical and horizontal) and its look depends on the currently activated visual manager. Calculator control has been significantly improved: All calculator buttons are drawn using built-in bitmaps and use visual manager appearance (see screenshot). Implemented extended commands. Using a new method CBCGPCalculator::SetExtendedCommands developers can add a lot of build-in calculator commands such as idCommandAdvSin, idCommandAdvCos, idCommandAdvTan and others. CBCGPRibbonComboBox allows to display a popup calculator window. Just call CBCGPRibbonComboBox::EnableCalculator method to assign a calculator to the ribbon combobox. Override a new 'OnCalculatorUserCommand' method to implement your calculator commands. Please take a look at BCGPControls example and RibbonGadgets/SkinnedDialog samples to see these new features in action. The following new methods were added to CBCGPVisualManager class: OnDrawDockingBarScrollButton OnDrawCaptionBarCloseButton GetHeaderCtrlTextColor OnFillPropSheetHeaderArea OnDrawDateTimeDropButton GetCalculatorButtonTextColor GetEditCtrlSelectionBkColor GetEditCtrlSelectionTextColor OnDrawDlgSizeBox OnFillRibbonBackstageForm OnDrawRibbonMinimizeButtonImage GetRibbonMinimizeButtonImageSize GetRibbonButtonsGroupHorzMargin IsDrawRibbonGroupSeparator OnDrawRibbonGroupSeparator GetRibbonBackstageTopLineHeight OnDrawRibbonBackstageTopLine SetMainButtonColor GetMainButtonColor IsOwnerDrawDlgSeparator OnDrawDlgSeparator CBCGPPropertySheet has a new mode: PropSheetLook_AeroWizard (see screenshot). In general, this mode has been designed and implemented for Vista/Windows 7 Aero, but you can use it in any OSs/modes (see screenshot). The glass (aero) area can be combined with a page header - we've added a new optional parameter 'bDrawHeaderOnAeroCaption' to EnablePageHeader method. Please take a look at PropSheetDemo sample to see this mode. Added support for the Internet Explorer-like new tab in CBCGPTabWnd class (see screenshot). Call EnableNewTab method to enable this feature. Please take a look BCGPIE7Demo example to see this feature in action. Grid and Report controls changes: Added option to select items by clicks on grid header: New header flag BCGP_GRID_HEADER_SELECT. Implemented color themes for the new visual managers such as CBCGPVisualManager2010 (Office 2010-like) and CBCGPVisualManagerVS2010 (Visual Studio 2010-like) (see screenshot). Improved grid printing support. The following new classes were added: CBCGPGridPage class: this class is used by the grid control to store print pages. A print page specifies which area of the grid is printed at the specified page. The grid counts in items in vertical direction. The grid counts in pixels in horizontal direction. CBCGPGridPageInfo class: This class is used by the grid control to store information about the printing range and the currently printing page. It is stored in CBCGPGridCtrl::m_PrintParams::m_pageInfo member and in CPrintInfo::m_lpUserData member of the CPrintInfo object used while printing at the current print session. Added an option to deselect items. To deselect an item please use SetCurSel with SM_INVERT_SEL flag. New functions were added: CBCGPGridCtrl::EnableInvertSelOnCtrl CBCGPGridCtrl::IsInvertSelOnCtrlEnabled Changes in header click events: New BCGM_GRID_COLUMN_CLICK message. Added CBCGPGridCtrl::OnHeaderColumnRClick. Modified CBCGPGridCtrl::OnHeaderColumnClick. Items align support: New CBCGPGridItem::GetAlign function. Item's alignment is specified by CBCGPGridCtrl::SetColumnAlign. Grid horizontal pagination support. Added CBCGPGridPage::m_nWidth - page width, CBCGPGridPageInfo::m_nPageWidth - width of currently printed page. See CBCGPGridPage class, CBCGPGridPageInfo class. Drag-and-Drop support (see new "Drag and Drop" tab in BCGPGridExample sample): New message BCGM_GRID_BEGINDRAG. Added methods EnableDragSelection, IsDragSelectionEnabled, EnableDragSelectionBorder, IsDragSelectionBorderEnabled, StartDragItems and HitTestSelectionBorder. Extended in-place edit customization support (see new "Easy Input" tab in BCGPGridExample sample): New messages BCGM_GRID_ITEM_BEGININPLACEEDIT, BCGM_GRID_ITEM_ENDINPLACEEDIT. New functions OnBeginInplaceEdit, OnEndInplaceEdit, CanBeginInplaceEditOnChar, CanEndInplaceEditOnChar, OnInplaceEditKeyDown, OnInplaceEditSetSel. New BCGPGRID_ITEM_INFO::dwResultCode member. See BCGPGRID_ITEM_INFO struct. New method SetClearInplaceEditOnEnter. Call SetClearInplaceEditOnEnter (FALSE) to disable grid from clearing content of the item on Enter. Added CBCGPGridCtrl::GoToNextItem method. CBCGPGridCtrl::EnsureVisible is now virtual. Added navigation by TAB (Shift+TAB) key. Added "Ctrl+Z" (Undo) handler for in-place edit of the grid item. Changes in CBCGPGridCtrl::SetCurSel for SM_SET_ACTIVE_ITEM style. Grid item with combo-box now supports F4 to open drop-down list. Added a new parameter CBCGPMDITabParams::m_bReuseRemovedTabGroups. If this flag is TRUE MDI tab groups which were marked as removed will be used for new groups. This reduces memory consumption for applications that frequently create and remove groups. Added OpenType font support for font combo boxes. Added keyboard and MS Active Accessibility support to CBCGPTasksPane class. CBCGPEditCtrl::ExportBuffer has a new optional parameter 'BOOL bForceAnsi'. Setting it to TRUE forces exporting editor's text in ANSI format. CBCGPRibbonStatusBarPane constructor and SetAnimationList method have a new optional parameter 'BOOL bDontScaleInHighDPIMode'. Set it to TRUE if you don't need to scale pane image in the High DPI mode. When user clicks on the glass area of CBCGPExplorerToolBar window, the application window is moved now. Added CBCGPCalendarBar::GetState method - returns the calendar style flags specified in SetState method. CBCGPRibbonEdit displays a drop-down window upon pressing F4 key. Added CBCGPShellManager::IsControlPanel method. Added new font 'fontCaption' to BCGPGLOBAL_DATA. This font will be useful for displaying caption texts. CBCGPStatic has a new member: m_clrText. You can set this member to colorize text labels (see SkinnedDialog sample). New method CBCGPDockManager::ShowFloatingBars shows/hides floating panes. CBCGPListBox control can work with left-side icons and item group headers now. The following new methods were added: SetImageList: set items image list SetItemImage: associate item with a specific icon AddCaption: add a group caption Changes in examples and samples: BCGPControls: "Calculator" page demonstrates new calculator features BCGPGridExample: added new visual managers and new 2 tabs: "Drag and Drop" and "Easy Input" BCGPIE7Demo: the tab control was fully redesigned and derived from the library MDI Tab control. BCGPMSOffice2007Demo: added MS Office 2010 Backstage view. "Clipboard" pane demonstrates a new layout manager. BCGPVisualStudioGUIDemo: Start Page view can be converted to docking control bar. DrawCli: added MS Office 2010 Backstage view and new visual managers. PropSheetDemo: added Aero Wizard demonstration. ResizableForm: new sample, demonstrates how to use a new layout manager along with dialogs, dialog bars, property sheets and form views. RibbonGadgets: added MS Office 2010 Backstage view and edit boxes with calculator. SkinnedDialog: added edit box with calculator and text labels with a custom colors. Changes in the Ribbon Designer: Added "Calculator" element. Support for three new styles introduced in Microsoft Office 2010 (blue, silver, black) Ribbon elements can be edited by double click. Image lists can be loaded from files. Implemented icon editing for Palette (Gallery) Buttons. Fixes: FireChangingActiveTab is called from CBCGPOutlookWnd::SetActiveTab now. Fixed resource leak in CBCGPUserTool::DrawToolIcon Fixed problem with a slider's thumb location in CBCGPRibbonSlider::SetThumbRect in the High DPI mode. Improved appearance of the calendar drop-down button in CBCGPDateTimeCtrl. Fixed problem with setting editbox auto-complete mode in Windows 9x/NT4 CBCGP***FrameWnd::WinHelp dwData parameter has DWORD_PTR type now. This fixes 64-bit compatibility issue with this virtual method. Fixed memory leak in CBCGPPngImage::LoadFromBuffer (VS.NET 2003 or higher, BCGP_EXCLUDE_GDI_PLUS is defined). CBCGPGroup is properly handles WM_SETTEXT message now. CBCGPCalendar always closes dropped-down month picker when the calendar is being destroyed. CBCGPRibbonEdit::OnDraw correctly draws edit box label in case of center/right-side control alignment. Fixed appearance of CBCGPExCheckList items in the high DPI mode (under VC++ 6.0). Fixed problem with displaying disabled check boxes (CBCGPButton class) when some visual managers are activated. Fixed problem with CBCGPHeaderCtrl items text color when some visual managers are activated. Fixed problem with vertical scrolling of elements in CBCGPRibbonPanel::OnKey. CBCGPEdit correctly draws a browse button image and text when control is located on the glass (aero) area. CBCGPEdit uses visual manager color them when control has ES_READONLY style. CBCGPStatic doesn't perform the custom drawing if it has a style like icon, rectangle or frame. CBCGPPropertySheet: fixed some problems with repositioning and redrawing navigation buttons. Fixed some visual problems in owner-draw frame/dialog captions. Ribbon Main Button scenic icon is correctly painted in high DPI mode now. Fixed problem with text alignment in grid columns. CBCGPGridCtrl::SetColumnAlign is working properly now. Fixed bug with using different horizontal color and vertical color for the grid lines. The m_clrVertLine setting did not work when m_bGridItemBorders flag was switched on. Fixed problem with clicking on CBCGPGridURLItem in read-write mode. Fixed a bug with automatic sizing of grid columns. The bug appeared when auto-sizing was enabled with EnableColumnAutoSize(TRUE). Fixed bug with "Ctrl+A" for in-place editing of grid items. "Ctrl+A" selects all text inside in-place editor during in-place editing, instead of the entire grid as before. Fixed memory leak in CBCGPGridCtrl::CopyHtmlToClipboardInternal. Ribbon Designer supports Visual Studio 2008 and Visual Studio 2010 Beta 2 projects.
New Features FormHttpMessageConverter should support non-String form values [SPR-17645] #22174 spring-jcl routes logging inefficiently against SLF4J with log4j-to-slf4j setup [SPR-17586] #22118 Allow java.time types for setting the Last-Modified header [SPR-17571] #22103 StringHttpMessageConverter should assume charset UTF-8 for application/json [SPR-17568] #22100 NettyDataBufferFactory.join should return original buffer as-is in case of a single element (for compatibility with Netty 4.1.32) [SPR-17560] #22092 Use Netty's optimized UTF-8 encoding if available [SPR-17558] #22090 Equals checks to MediaType.ALL should not be affected the presence of parameters [SPR-17550] #22082 Reactive HTTP header adapters don't print header values in toString [SPR-17546] #22078 Add ability to retrieve associated ClientRequest from WebClientResponseException [SPR-17087] #21624 beetle Bug Fixes HttpHeaders.EMPTY is not immutable [SPR-17633] #22164 UriComponentsBuilder.toUriString() is broken [SPR-17630] #22161 MethodParameter.isOptional() fails with ArrayIndexOutOfBoundsException [SPR-17629] #22160 MockMvcResultMatchers.forwardedUrl argument is not declared as nullable [SPR-17623] #22155 Cannot convert from Collection to RegularEnumSet [SPR-17619] #22151 TomcatHttpHandlerAdapter is not aware of Server[Request|Response]Wrapper [SPR-17611] #22143 ChannelSendOperator does not propagate cancel signal to the server [SPR-17609] #22141 @Value Optional<...> field injection fails in case of registered ConversionService [SPR-17607] #22139 @Profile mishandles "not" operand mixed with "&" [SPR-17606] #22138 SpEL, error parsing big InlineMap [SPR-17605] #22137 Composed RequestPredicates have invalid string representation [SPR-17594] #22126 Regression: IllegalStateException: Ambiguous handler methods is thrown for explicit HEAD mapping [SPR-17593] #22125 Exporting a lazily initialized bean (which implements SelfNaming and is annotated with ManagedResource annotation) gives IllegalStateException [SPR-17592] #22124 MockHttpServletRequest changes Accept-Language header values [SPR-17566] #22098 SpEL variable evaluation fails with NPE against ConcurrentHashMap [SPR-17565] #22097 WebClient logs "Only one connection receive subscriber allowed" when response status is an error [SPR-17564] #22096 Potential resource leak in DataSourceUtils.doGetConnection [SPR-17559] #22091 HibernateTransactionManager (unintentionally) bound to Hibernate 5.2 SharedSessionContractImplementor [SPR-17557] #22089 Spring JavaMailSenderImpl does not show proper message when recipient list is empty [SPR-17540] #22072 'default-lazy-init' attribute is not processed when XSD validation is disabled [SPR-8335] #12983

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

不会叫的狼

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值