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

📄 inverseeditor.java

📁 JAVA2核心技术第2卷.基础知识7th原书光盘附赠的源代码
💻 JAVA
字号:
/**
   @version 1.21 2004-08-30
   @author Cay Horstmann
*/

package com.horstmann.corejava;

import java.awt.*;
import java.awt.font.*;
import java.awt.geom.*;
import java.beans.*;

/**
   The property editor for the inverse property of the ChartBean.
   The inverse property toggles between colored graph bars
   and colored background.
*/
public class InverseEditor extends PropertyEditorSupport
{  
   public Component getCustomEditor() { return new InverseEditorPanel(this); }
   public boolean supportsCustomEditor() { return true; }
   public boolean isPaintable() { return true; }
   public String getAsText() { return null; }
   public String getJavaInitializationString() { return "" + getValue(); }

   public void paintValue(Graphics g, Rectangle box)
   {  
      Graphics2D g2 = (Graphics2D) g;
      boolean isInverse = (Boolean) getValue();
      String s = isInverse ? "Inverse" : "Normal";
      g2.setPaint(isInverse ? Color.black : Color.white);
      g2.fill(box);
      g2.setPaint(isInverse ? Color.white : Color.black);
      FontRenderContext context = g2.getFontRenderContext();
      Rectangle2D stringBounds = g2.getFont().getStringBounds(s, context);
      double w = stringBounds.getWidth();
      double x = box.x;
      if (w < box.width) x += (box.width - w) / 2;
      double ascent = -stringBounds.getY();
      double y = box.y + (box.height - stringBounds.getHeight()) / 2 + ascent;
      g2.drawString(s, (float) x, (float) y);
   }
}


⌨️ 快捷键说明

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