⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 propertysheetpage.java

📁 JGraph扩展应用。自定义Renderer,自定义视图View实现自定义工作流控件
💻 JAVA
字号:
/**
 * @PROJECT.FULLNAME@ @VERSION@ License.
 *
 * Copyright @YEAR@ L2FProd.com
 *
 * 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 com.l2fprod.common.demo;

import com.l2fprod.common.beans.BaseBeanInfo;
import com.l2fprod.common.beans.editor.ComboBoxPropertyEditor;
import com.l2fprod.common.propertysheet.PropertySheet;
import com.l2fprod.common.propertysheet.PropertySheetPanel;
import com.l2fprod.common.swing.LookAndFeelTweaks;

import java.awt.Color;
import java.awt.Font;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyVetoException;
import java.io.File;
import java.util.Arrays;
import java.util.ListResourceBundle;

import javax.swing.Icon;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.UIManager;

/**
 * PropertySheetPage. <br>
 *  
 */
public class PropertySheetPage extends JPanel {

  public PropertySheetPage() {
    setLayout(LookAndFeelTweaks.createVerticalPercentLayout());

	/*
    JTextArea message = new JTextArea();
    message.setText(PropertySheetMain.RESOURCE.getString("Main.sheet1.message"));
    LookAndFeelTweaks.makeMultilineLabel(message);
    add(message);
    */
	
    final Bean data = new Bean();
    data.setName("John Smith");
    data.setText("Any text here");
    data.setColor(Color.BLUE);
    data.setPath(new File("."));
    data.setVisible(true);
    data.setTime(System.currentTimeMillis());
	data.setFrontColor(Color.ORANGE);
	data.setCurrentPath(new File(System.getProperty("user.dir")));
	data.setFont(new Font("宋体", Font.BOLD, 12));

    final PropertySheetPanel sheet = new PropertySheetPanel();
    sheet.setMode(PropertySheet.VIEW_AS_CATEGORIES);
    sheet.setDescriptionVisible(true);
    sheet.setSortingCategories(true);
    sheet.setSortingProperties(true);
    sheet.setRestoreToggleStates(true);
    //add(sheet, "*");
	add(sheet);
    // everytime a property change, update the sheet with it
    new BeanBinder(data, sheet);    
  }

  public static class Bean {
	  private Color frontColor = Color.LIGHT_GRAY;
	  public void setFrontColor(Color color){
		  frontColor = color;
	  }
	  
	  public Color getFrontColor(){
		  return frontColor;
	  }
	  
	  private File currentPath;
	  public void setCurrentPath(File file){
		  currentPath = file;
	  }
	  public File getCurrentPath(){
		  return currentPath;
	  }
	  
	  private Font font;
	  public void setFont(Font font){
		  this.font = font;
	  }
	  public Font getFont(){
		  return font;
	  }
	  

    private String name;

    public String getName() {
      return name;
    }

    public void setName(String name) {
      this.name = name;
    }

    private String text;

    public String getText() {
      return text;
    }

    public void setText(String text) {
      this.text = text;
    }

    private long time;

    public long getTime() {
      return time;
    }

    public void setTime(long time) {
      this.time = time;
    }

    public String getVersion() {
      return "1.0";
    }

    private boolean visible;

    public boolean isVisible() {
      return visible;
    }

    public void setVisible(boolean visible) {
      this.visible = visible;
    }

    private int id;

    public int getId() {
      return id;
    }

    public void setId(int id) {
      this.id = id;
    }

    private File path;

    public File getPath() {
      return path;
    }

    public void setPath(File path) {
      this.path = path;
    }

    private Color color = Color.blue;

    public Color getColor() {
      return color;
    }

    public void setColor(Color color) {
      this.color = color;
    }

    private double doubleValue = 121210.4343543;

    public void setADouble(double d) {
      this.doubleValue = d;
    }

    public double getADouble() {
      return doubleValue;
    }

    private String season;
    
    public void setSeason(String s) {
      season = s;
    }
    
    public String getSeason() {
      return season;
    }
    
    private String constrained;
    
    public String getConstrained() {
      return constrained;
    }

    public void setConstrained(String constrained) throws PropertyVetoException {
      if ("blah".equals(constrained)) {
        throw new PropertyVetoException("e",
        new PropertyChangeEvent(this, "constrained", this.constrained,
          constrained));
      }
      this.constrained = constrained;
    }
    
    public String toString() {
      return "[name=" + getName() + ",text=" + getText() + ",time=" + getTime()
          + ",version=" + getVersion() + ",visible=" + isVisible() + ",id="
          + getId() + ",path=" + getPath() + ",aDouble=" + getADouble() +
          ",season=" + getSeason() + "]";
    }

  }

  public static class BeanBeanInfo extends BaseBeanInfo {

    public BeanBeanInfo() {
      super(Bean.class);
	  addProperty("frontColor").setCategory("Kuangzy");
	  addProperty("currentPath").setCategory("Kuangzy");
	  addProperty("font").setCategory("Kuangzy");
	  
      addProperty("id").setCategory("General");
      addProperty("name").setCategory("General");
      addProperty("text").setCategory("General");
      addProperty("visible").setCategory("General");
      
      // the File attribute will not be shown if running in Java Web
      // Start, otherwise it will lead to exception when rendering the
      // value
      if (System.getProperty("javawebstart.version") == null) {
        addProperty("path").setCategory("Details");
      }
      
      addProperty("time").setCategory("Details");
      addProperty("color").setCategory("Details");
      addProperty("season").setCategory("Details").setPropertyEditorClass(SeasonEditor.class);
      // a readonly property
      addProperty("version");
      // a constrained property
      addProperty("constrained");
      addProperty("aDouble").setCategory("Numbers");
    }
  }
  
	public static class SeasonEditor extends ComboBoxPropertyEditor {
	  public SeasonEditor() {
	    super();	    
	    setAvailableValues(new String[]{"Spring","Summer","Fall","Winter",});
	    Icon[] icons = new Icon[4];
	    Arrays.fill(icons, UIManager.getIcon("Tree.openIcon"));
	    setAvailableIcons(icons);
	  }
	}
	
	/*
  public static class BeanRB extends ListResourceBundle {

    protected Object[][] getContents() {
      return new Object[][] { {"name", "Name"},
          {"name.shortDescription", "The name of this object<br>Here I'm using multple lines<br>for the property<br>so scrollbars will get enabled"},
          {"text", "Text"}, {"time", "Time"}, {"color", "Background"},
          {"aDouble", "a double"},
          {"season", "Season"},
          {
          "constrained.shortDescription",
          "This property is constrained. Try using <b>blah</b> as the value, the previous value will be restored"}};
    }
  }*/

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -