Package

Source Code of CodeTermPanel

//
//  CodeTermPanel.java
//  VideoAnnotate
//
//  Created by Michael Fischer on 10/08/2005.
//  Copyright 2005 __MyCompanyName__. All rights reserved.
//
import java.awt.Panel;
import java.awt.List;
import java.awt.Label;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Dimension;

public class CodeTermPanel extends Panel {
  CodeTerm term=null;
  Label title=null;
  List codes=null;
 
  public CodeTermPanel() {
    setLayout(null);
    Font f = new Font("SansSerif",Font.BOLD,9);
    Font fl = new Font("SansSerif",Font.PLAIN,8);
    title = new Label();
    codes = new List();
    this.setVisible(false);
    add(title);
    add(codes);
    title.setFont(f);
    codes.setFont(fl);
    format();
    setVisible(true);
  }
 
  public CodeTermPanel(CodeTerm t) {
    this();
    setTerm(t);
  }
 
  int rows = 0;
  int maxWidth=20;
 
  public void setTerm(CodeTerm t) {
    term=t;
    setVisible(false);
    title.setText(t.getName());
    codes.removeAll();
    rows = term.getCategories().size()+term.getModifiers().size()+1;
    for (int i=0;i<term.getCategories().size();i++) {
      codes.add((String) term.getCategories().elementAt(i));
      int w = ((String) term.getCategories().elementAt(i)).length()*12;
      if (w > maxWidth) maxWidth = w;
    }
    codes.add("-----");
    for (int i=0;i<term.getModifiers().size();i++) {
      codes.add((String) term.getModifiers().elementAt(i));
      int w = ((String) term.getModifiers().elementAt(i)).length()*12;
      if (w > maxWidth) maxWidth = w;
    }
    codes.preferredSize(rows);
    format();
    setVisible(true);
  }
 
  public void format() {
    int lw = codes.getPreferredSize(rows).width;
    int lh = codes.getPreferredSize(rows).height;
    if (lw < 50) lw = 72; // maxWidth;
    if (lh < 30) lh = 100; // rows*16;
    Dimension s = title.getSize();
    s.width = lw;
    s.height= 14;
    title.setLocation(0,0);
    title.setSize(s);
    codes.setLocation(0,s.height);
    this.setSize(lw,lh+15);
    codes.setSize(lw,lh);
  }
 
  public int measureText(String text) {
    return measureText(text, getFont());
  }

  public int measureText(String text, Font f) {
    return getGraphics().getFontMetrics(f).stringWidth(text);
  }
}
TOP

Related Classes of CodeTermPanel

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.