home *** CD-ROM | disk | FTP | other *** search
/ Symantec Visual Cafe for Java 2.5 / symantec-visual-cafe-2.5-database-dev-edition.iso / Extras / ODesign / SetupPSE.exe / data.z / TextSettings.java < prev    next >
Encoding:
Java Source  |  1997-01-24  |  1.9 KB  |  109 lines

  1. package COM.odi.demo.OSDraw;
  2.  
  3. /**
  4.  *      <H3>Copyright (C) Object Design Inc. 1996, 1997</H3>
  5.  */
  6.  
  7. import java.awt.*;
  8.  
  9. /*
  10.  * Class TextSettings defines settings of current text
  11.  * Settings are font name, style, size
  12.  */
  13.  
  14. public class TextSettings {
  15.  
  16.   // Choice of fonts
  17.  
  18.   public static final String fontNames[] = {
  19.     "Arial",
  20.     "Courier",
  21.     "Times Roman"
  22.   };
  23.  
  24.   // Info of current font settings
  25.  
  26.   private String name;
  27.   private int style;
  28.   private int size;
  29.  
  30.   public TextSettings() {
  31.     name = "Arial";
  32.     style = Font.PLAIN;
  33.     size = 16;
  34.   }
  35.  
  36.   // Methods to access private data
  37.  
  38.   public Font getFont() {
  39.     return new Font(name, style, size);
  40.   }
  41.  
  42.   public void setName(String name) {
  43.     this.name = name;
  44.     correctName();
  45.   }
  46.  
  47.   public void setName(int index) {
  48.     if (index < 0 || index >= fontNames.length) {
  49.       return;
  50.     }
  51.     name = fontNames[index];
  52.     correctName();
  53.   }
  54.  
  55.   public int getNameIndex() {
  56.     regularName();
  57.     boolean found = false;
  58.     int i = 0;
  59.     while (!found && i < fontNames.length) {
  60.       found = name.equals(fontNames[i]); 
  61.       if (!found) {
  62.         i++;
  63.       }
  64.     }
  65.     correctName();
  66.     if (found) {
  67.       return i;
  68.     }
  69.     return -1; // This should never happen
  70.   }
  71.  
  72.   public void setStyle(int index) {
  73.     if (index < 0 || index >= 4) {
  74.       return;
  75.     }
  76.     if (index == 3) {
  77.       style = Font.BOLD + Font.ITALIC;
  78.       return;
  79.     }
  80.     style = index;
  81.   }
  82.  
  83.   public int getStyleIndex() {
  84.     if (style < (Font.BOLD + Font.ITALIC)) {
  85.       return style;
  86.     }
  87.     return style - 1;
  88.   }
  89.  
  90.   public void setSize(int size) {
  91.     this.size = size;
  92.   }
  93.  
  94.   // Two methods to adjust discrepancy between common font name
  95.   // and its equivalent name for java.awt.Font
  96.  
  97.   private void correctName() {
  98.     if (name.equals("Times Roman")) {
  99.       name = "TimesRoman";
  100.     }
  101.   }
  102.  
  103.   private void regularName() {
  104.     if (name.equals("TimesRoman")) {
  105.       name = "Times Roman";
  106.     }
  107.   }
  108. }
  109.