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

📄 formattednumbereditor_fw.java

📁 一个用java写的地震分析软件(无源码)-used to write a seismic analysis software (without source)
💻 JAVA
字号:
package org.trinet.util.graphics.table;
import java.text.*;
import java.awt.*;
import java.awt.event.*;
import java.util.EventObject;
import javax.swing.*;
import org.trinet.util.graphics.text.*;

public class FormattedNumberEditor_FW extends AbstractCellEditor {
  protected NumberTextFieldFixed numberField;
  protected DecimalFormat df;
  protected int fontSize=12;
  protected Font font;

  public FormattedNumberEditor_FW() {
    NumberFormat nf = NumberFormat.getNumberInstance();
    if (nf instanceof DecimalFormat) {
      df = (DecimalFormat) nf;
      df.setGroupingUsed(false);
      df.setDecimalSeparatorAlwaysShown(false);
    }
    df.applyPattern("#0.");
    numberField  = new NumberTextFieldFixed(0, 12, df);
    numberField.setHorizontalAlignment(NumberTextFieldFixed.RIGHT);
    font = new Font("Monospaced", Font.PLAIN, fontSize);
    numberField.setFont(font);
    numberField.addActionListener(this);
  }

  public FormattedNumberEditor_FW(String pattern) {
    NumberFormat nf = NumberFormat.getNumberInstance();
    if (nf instanceof DecimalFormat) {
      df = (DecimalFormat) nf;
      df.setGroupingUsed(false);
      df.setDecimalSeparatorAlwaysShown(false);
    }
    if (pattern == null || pattern.length() == 0) pattern = "#0."; 
    df.applyPattern(pattern);
    numberField  = new NumberTextFieldFixed(0, 12, df);
    numberField.setHorizontalAlignment(NumberTextFieldFixed.RIGHT);
    font = new Font("Monospaced", Font.PLAIN, fontSize);
    numberField.setFont(font);
    numberField.addActionListener(this);
  }

  public FormattedNumberEditor_FW(String pattern, int columns) {
    NumberFormat nf = NumberFormat.getNumberInstance();
    if (nf instanceof DecimalFormat) {
      df = (DecimalFormat) nf;
      df.setGroupingUsed(false);
      df.setDecimalSeparatorAlwaysShown(false);
    }
    if (pattern == null || pattern.length() == 0) pattern = "#0."; 
    df.applyPattern(pattern);
//	Debug.println("FNE_FW pattern, columns:" + pattern + " " + columns);
    if (columns >= 0) numberField  = new NumberTextFieldFixed(0, columns, df);
    else numberField  = new NumberTextFieldFixed(0, 1, df);
    numberField.setHorizontalAlignment(NumberTextFieldFixed.RIGHT);
    font = new Font("Monospaced", Font.PLAIN, fontSize);
    numberField.setFont(font);
    numberField.addActionListener(this);
  }

  public int getFontSize() {
    return fontSize;
  }

  public void setFontSize(int fontSize) {
    if (fontSize > 0) this.fontSize = fontSize;
    font = font.deriveFont((float) fontSize);
    numberField.setFont(font);
  }

  public void setFont(Font font) {
    if (font != null) this.font = font;
    numberField.setFont(font);
  }

//Override AbstractCellEditor methods

  public boolean startCellEditing(EventObject anEvent) {
    if(anEvent == null) numberField.requestFocus();
    else if (anEvent instanceof MouseEvent) {
      if (((MouseEvent)anEvent).getClickCount() < clickCountToStart)
        return false;
    }
    return true;
  }

  public Component getComponent() {
    return numberField;
  }

  public void setCellEditorValue(Object value) {
    if (value != null) {
//      if (value.getClass() isInstanceOf Object)
        numberField.setValue(value);
    }
    else numberField.setText("");
    this.value = value;
  }
 
//Override getCellEditorValue method to return a number, not a String:
  public Object getCellEditorValue() {
    switch (numberField.getDataType()) {
      case NumberTextFieldFixed.INT_TYPE :
	return new Integer(numberField.getIntValue()) ;
      case NumberTextFieldFixed.LONG_TYPE :
	return new Long(numberField.getLongValue()) ;
      case NumberTextFieldFixed.FLOAT_TYPE :
	return new Float(numberField.getFloatValue()) ;
      case NumberTextFieldFixed.DOUBLE_TYPE :
	return new Double(numberField.getDoubleValue()) ;
      default:
        return numberField.getValue();
    } 
  }

  public Component getTableCellEditorComponent( JTable table, Object value, boolean isSelected, int row, int column) {
//    numberField.setText(value.toString());
    setCellEditorValue(value);
    return (Component) numberField; 
  }
}

⌨️ 快捷键说明

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