`
nlslzf
  • 浏览: 1027908 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

PropertyEditor

    博客分类:
  • java
阅读更多

http://read.pudn.com/downloads37/sourcecode/windows/control/117440/PropertyProj/src/propertyproj/PropertyEditor.java__.htm

 

package propertyproj;   
   
import javax.swing.*;   
import javax.swing.table.*;   
import java.util.Hashtable;   
import java.awt.Component;   
import java.awt.*;   
import javax.swing.event.*;   
import java.awt.event.*;   
import java.util.*;   
import java.beans.*;   
   
public class PropertyEditor   
    extends JTable {   
  protected DefaultCellEditor dlgCellEditor;   
  protected DefaultCellEditor booleanCellEditor;   
  protected TableCellRenderer booleanRender;   
  protected DefaultCellEditor longEditor;   
  protected DefaultTableCellRenderer longRender;   
  protected Hashtable propertyEditors = new Hashtable(10);   
  protected Hashtable propertyRender = new Hashtable(10);   
  protected Hashtable propertyEditable = new Hashtable(10);   
  public PropertyEditorModel ptm = new PropertyEditorModel();   
   
  public PropertyEditor(PropertyEditorModel ptm) {   
    super(ptm);   
    this.ptm = ptm;   
  }   
   
  public PropertyEditor() {   
   
  }   
   
  public class PropertyEditorModel   
      extends DefaultTableModel {   
    PropertyEditorModel() {   
      super(0, 2);   
    }   
   
    /**  
     * Returns the name of the column at <code>columnIndex</code>.  
     *  
     * @param columnIndex the index of the column  
     * @return the name of the column  
     * @todo Implement this javax.swing.table.TableModel method  
     */   
    public String getColumnName(int columnIndex) {   
      if (columnIndex == 0) {   
        return "属性";   
      }   
      else {   
        return "值";   
      }   
    }   
   
    /**  
     * Returns true if the cell at <code>rowIndex</code> and  
     * <code>columnIndex</code> is editable.  
     *  
     * @param rowIndex the row whose value to be queried  
     * @param columnIndex the column whose value to be queried  
     * @return true if the cell is editable  
     * @todo Implement this javax.swing.table.TableModel method  
     */   
    public boolean isCellEditable(int rowIndex, int columnIndex) {   
      if (columnIndex == 0) {   
        return false;   
      }   
      else {   
        return true;   
   
      }   
    }   
   
  }   
   
  /**  
   * Returns an appropriate editor for the cell specified by <code>row</code> and  
   * <code>column</code>.  
   *  
   * @param row the row of the cell to edit, where 0 is the first row  
   * @param column the column of the cell to edit, where 0 is the first column  
   * @return the editor for this cell; if <code>null</code> return the default  
   *   editor for this type of cell  
   * @todo Implement this javax.swing.JTable method  
   */   
  public TableCellEditor getCellEditor(int row, int column) {   
    TableCellEditor editor = null;   
    if (column == 1) {   
      editor = (TableCellEditor) propertyEditors.get(this.getValueAt(row, 0));   
    }   
    if (editor == null) {   
      editor = super.getCellEditor(row, column);   
    }   
   
    return editor;   
   
  }   
   
  /**  
   * Returns an appropriate renderer for the cell specified by this row and  
   * column.  
   *  
   * @param row the row of the cell to render, where 0 is the first row  
   * @param column the column of the cell to render, where 0 is the first column  
   * @return the assigned renderer; if <code>null</code> returns the default  
   *   renderer for this type of object  
   * @todo Implement this javax.swing.JTable method  
   */   
  public TableCellRenderer getCellRenderer(int row, int column) {   
    TableCellRenderer render = null;   
    if (column == 1) {   
      render = (TableCellRenderer) propertyRender.get(this.getValueAt(row, 0));   
    }   
    if (render == null) {   
      render = super.getCellRenderer(row, column);   
    }   
    return render;   
  }   
   
  public void addProperty(String propertyName, Long longNumObj) {   
    if (propertyName == null) {   
      throw new RuntimeException("属性名称不能为空");   
    }   
    Object[] row = new Object[2];   
    row[0] = propertyName;   
    row[1] = longNumObj;   
    this.appenRow(row);   
    propertyEditors.put(propertyName, longEditor);   
    this.propertyRender.put(propertyName, longRender);   
    this.propertyEditable.put(propertyName, new Boolean(true));   
   
  }   
   
  public void addProperty(String propertyName, Boolean booleanObj) {   
    if (propertyName == null) {   
      throw new RuntimeException("属性名称不能为空");   
    }   
    Object[] row = new Object[2];   
    row[0] = propertyName;   
    row[1] = booleanObj;   
    this.appenRow(row);   
    propertyEditors.put(propertyName, this.booleanCellEditor);   
    this.propertyRender.put(propertyName, this.booleanRender);   
    this.propertyEditable.put(propertyName, new Boolean(true));   
   
  }   
   
  public Object getPropertyValue(String propertyName) {   
    Object retValue = null;   
    for (int i = 0; i  ptm.getRowCount(); i++) {   
      if (ptm.getValueAt(i, 0).equals(propertyName)) {   
        retValue = ptm.getValueAt(i, 1);   
        break;   
      }   
    }   
    return retValue;   
  }   
   
  public void setPropertyValue(String propertyName, Object newValue) {   
    for (int i = 0; i  ptm.getRowCount(); i++) {   
      if (ptm.getValueAt(i, 0).equals(propertyName)) {   
        ptm.setValueAt(newValue, i, 1);   
        break;   
      }   
    }   
   
  }   
   
  public void appenRow(Object[] row) {   
    ptm.addRow(row);   
   
  }   
   
  public void createLongEditorRenderer() {   
    final PanelInputText longTextField = new PanelInputText();   
    longEditor = new DefaultCellEditor(new JTextField()) {   
      Component editor;   
      private Object previsousValue = null;   
      public Object getCellEditorValue() {   
        if (editor instanceof PanelInputText) {   
   
          if ( ( (PanelInputText) editor).getText().equals("")) {   
            return (Long)null;   
          }   
          else {   
            System.out.println("getCellEditorValue   " +   
                               ( (PanelInputText) editor).getText());   
   
            return new Long( ( (PanelInputText) editor).getText());   
   
          }   
        }   
        else {   
          return (Long)null;   
        }   
      }   
   
      public Component getTableCellEditorComponent(JTable table, Object value,   
          boolean isSelected, int row, int column) {   
        editor = null;   
   
        if (value != null) {   
          longTextField.setText(value.toString());   
   
        }   
        else {   
          longTextField.setText("");   
        }   
        previsousValue = value;   
        System.out.println("getTableCellEditorCompontOldValue:   " + value);   
        editor = longTextField;   
        System.out.println("getTableCellEditorCompont");   
        return editor;   
      }   
   
      public boolean stopCellEditing() {   
        Long lv = null;   
        if (! ( (PanelInputText) editor).getText().equals("")) {   
          try {   
            System.out.println("stopCellEditing");   
            lv = new Long( ( (PanelInputText) editor).getText());   
          }   
          catch (Exception e) {   
            this.cancelCellEditing();   
            return true;   
          }   
   
        }   
        if ( (previsousValue == null) ? (previsousValue == lv) :   
            this.previsousValue.equals(lv)) {   
          System.out.println("stopCellEditing");   
          this.cancelCellEditing();   
          return true;   
        }   
        System.out.println("DefaultstopEditing");   
        return super.stopCellEditing();   
   
      }   
   
    };   
    longTextField.addFocusListener(new FocusAdapter() {   
      public void focusLost(FocusEvent e) {   
        System.out.println("FocusLost");   
        longEditor.stopCellEditing();   
   
      }   
    }   
    );   
   
    longEditor.setClickCountToStart(2);   
    this.longRender = new DefaultTableCellRenderer() {   
      public Component getTableCellRendererComponent(JTable table,   
          Object value,   
          boolean isSelected,   
          boolean hasFocus,   
          int row,   
          int column) {   
        JLabel jLabel;   
        jLabel = (JLabel)super.getTableCellRendererComponent(table, value,   
            isSelected,   
            hasFocus, row, column);   
        if (value == null) {   
          jLabel.setText("");   
        }   
        else   
        if ( ( (Long) value).toString().equals("11")) {   
          jLabel.setText("测试代码名称转换");   
        }   
        else {   
          jLabel.setText( ( (Long) value).toString());   
   
        }   
   
        if (! (value == null)) {   
          System.out.println("getRender" + value.getClass().getName());   
        }   
        return jLabel;   
   
      }   
   
    }   
   
    ;   
    longRender.setHorizontalAlignment(JLabel.LEFT);   
    longRender.setBackground(Color.pink);   
  }   
   
  public void createBooleanEditorRender() {   
    JCheckBox jcb = new JCheckBox("");   
   
    this.booleanCellEditor = new DefaultCellEditor(jcb);   
   
    booleanCellEditor.setClickCountToStart(1);   
   
    this.booleanRender = new TableCellRenderer() {   
   
      public Component getTableCellRendererComponent(JTable table, Object value,   
          boolean isSelected, boolean hasFocus,   
          int row, int column) {   
   
        BooleanRender booleanRender = new BooleanRender();   
        if (value != null) {   
          if ( ( (Boolean) value).booleanValue()) {   
            booleanRender.selJCheckBox(new Boolean(true));   
          }   
          else {   
            booleanRender.selJCheckBox(new Boolean(false));   
   
          }   
        }   
        else {   
          booleanRender.selJCheckBox(new Boolean(false));   
        }   
        return booleanRender;   
      }   
   
    };   
   
  }   
}  
 
分享到:
评论

相关推荐

    学习Spring必学的Java基础知识(3)—PropertyEditor

    NULL 博文链接:https://bijian1013.iteye.com/blog/2164121

    SpringMVC之DataBinding和Validation--Validator,PropertyEditor,Converter,Formatter

    NULL 博文链接:https://b-l-east.iteye.com/blog/1705872

    Property Editor

    properties Editor for eclipse,解压后丢到eclipse安装目录的drops下重启eclipse即可,亲测有效。

    Delphi7~Delphi2010 JSON 读写组件(源码)

    Delphi7~Delphi2010 JSON 读写组件(源码)

    superobjectv1.2.4.zip_DELPHI JSON格式解析_JSON_json delphi_superobje

    DELPHI JSON 解析字符串,封装

    matlab GUI设计命令大全

    (3)对象属性编辑器(PropertyEditor):可查看每个对象的属性 值,也可修改、设置对象的属性值;(4)位置调整工具(Alignment Too1):用来调整图形窗1:1中各个图形对象的位置的工具. (5)对象浏览编辑器(Object Browser...

    数学建模算法的matlab代码

    figurepalette pan plotbrowser plotedit plottools propertyeditor rotate3d showplottool zoom 显示或隐藏图形窗口的调色板 交互式移动图像以多方向浏览 显示或隐藏窗口的图形浏览器 交互式编辑和标注图形 显示或...

    Spring MVC 3.0实战指南.ppt

    PropertyEditor依然有效 强大的ConversionService,让很多梦想成真 基于ConversionService体系,定义自定义的类型转换器 格式化:带格式字符串内部对象 相互转换 使用支持格式化的转换器 数据校验框架 JSR 303 ...

    LambdaProbe 中文包下载

    LambdaProbe 1.7b 发布了,原作者网站不... 如果没有合适的工具, 推荐下载本站开发的 Java 属性文件编辑器: PropertyEditor.jar 47KB PropertyEditor_src.zip 36KB 截屏: PropertyEditor_screenshotV2-1_1.png (位于...

    Spring3MVC注解教程.ppt

    PropertyEditor依然有效 强大的ConversionService,让很多梦想成真 基于ConversionService体系,定义自定义的类型转换器 格式化:带格式字符串内部对象 相互转换 使用支持格式化的转换器 数据校验框架 JSR...

    spring.net中文手册在线版

    Spring.NET是一个应用程序框架,其目的是协助开发人员创建企业级的.NET应用程序。...32.3.PropertyEditor和TypeConverter 32.4.ResourceBundle和ResourceManager 32.5.异常 32.6.应用程序配置 32.7.AOP框架

    Spring-Reference_zh_CN(Spring中文参考手册)

    5.4.2. 内建的PropertyEditor实现 5.4.2.1. 注册用户自定义的PropertyEditor 6. 使用Spring进行面向切面编程(AOP) 6.1. 简介 6.1.1. AOP概念 6.1.2. Spring AOP的功能和目标 6.1.3. Spring的AOP代理 6.2. @AspectJ...

    开源框架 Spring Gossip

    实作 Validator 使用 PropertyEditor 档案上传 &lt;br&gt; &lt;br&gt;View层方案、Web框架整合 当使用JSP作为View层技术时,您可以结合JSTL以及Spring提供的标签,而除了JSP技术作为View层之外,Spring还...

    spring-framework-reference4.1.4

    Not Using Commons Logging ................................................................... 12 Using SLF4J ..............................................................................................

    FreeCAD开发指南(FreeCAD_Mod_Dev_Guide__20170101-1)

    3.5.1 Naming of property and PropertyEditor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29 3.5.2 src/App/PropertyStandard.h . . . . . . . . . . . . . . . . . . . . . ....

    spring chm文档

    5.4.2. 内建的PropertyEditor实现 6. 使用Spring进行面向切面编程(AOP) 6.1. 简介 6.1.1. AOP概念 6.1.2. Spring AOP的功能和目标 6.1.3. Spring的AOP代理 6.2. @AspectJ支持 6.2.1. 启用@AspectJ支持 ...

    Spring中文帮助文档

    5.4.2. 内建的PropertyEditor实现 6. 使用Spring进行面向切面编程(AOP) 6.1. 简介 6.1.1. AOP概念 6.1.2. Spring AOP的功能和目标 6.1.3. AOP代理 6.2. @AspectJ支持 6.2.1. 启用@AspectJ支持 6.2.2. 声明...

    Spring 2.0 开发参考手册

    5.4.2. 内建的PropertyEditor实现 6. 使用Spring进行面向切面编程(AOP) 6.1. 简介 6.1.1. AOP概念 6.1.2. Spring AOP的功能和目标 6.1.3. Spring的AOP代理 6.2. @AspectJ支持 6.2.1. 启用@AspectJ支持 ...

    Spring API

    5.4.2. 内建的PropertyEditor实现 6. 使用Spring进行面向切面编程(AOP) 6.1. 简介 6.1.1. AOP概念 6.1.2. Spring AOP的功能和目标 6.1.3. AOP代理 6.2. @AspectJ支持 6.2.1. 启用@AspectJ支持 6.2.2. 声明...

Global site tag (gtag.js) - Google Analytics