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

📄 doublearrayeditor.java

📁 java核心技术源代码
💻 JAVA
字号:
/**
   @version 1.20 2001-08-21
   @author Cay Horstmann
*/

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

/**
   A custom editor for an array of floating point numbers.
*/
public class DoubleArrayEditor extends PropertyEditorSupport
{  
   public Component getCustomEditor()
   {  
      return new DoubleArrayEditorPanel(this);
   }

   public boolean supportsCustomEditor()
   {  
      return true;
   }

   public boolean isPaintable()
   {  
      return true;
   }

   public void paintValue(Graphics g, Rectangle box)
   {  
      Graphics2D g2 = (Graphics2D)g;
      double[] values = (double[]) getValue();
      StringBuffer s = new StringBuffer();
      for (int i = 0; i < 3; i++)
      {  
         if (values.length > i) s.append(values[i]);
         if (values.length > i + 1) s.append(", ");
      }
      if (values.length > 3) s.append("...");

      g2.setColor(Color.white);
      g2.fill(box);
      g2.setColor(Color.black);
      FontRenderContext context = g2.getFontRenderContext();
      Rectangle2D stringBounds = g2.getFont().getStringBounds(
         s.toString(), 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.toString(), (float)x, (float)y);
   }

   public String getAsText()
   {  
      return null;
   }
}


⌨️ 快捷键说明

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