home *** CD-ROM | disk | FTP | other *** search
Java Source | 1997-01-24 | 1.9 KB | 109 lines |
- package COM.odi.demo.OSDraw;
-
- /**
- * <H3>Copyright (C) Object Design Inc. 1996, 1997</H3>
- */
-
- import java.awt.*;
-
- /*
- * Class TextSettings defines settings of current text
- * Settings are font name, style, size
- */
-
- public class TextSettings {
-
- // Choice of fonts
-
- public static final String fontNames[] = {
- "Arial",
- "Courier",
- "Times Roman"
- };
-
- // Info of current font settings
-
- private String name;
- private int style;
- private int size;
-
- public TextSettings() {
- name = "Arial";
- style = Font.PLAIN;
- size = 16;
- }
-
- // Methods to access private data
-
- public Font getFont() {
- return new Font(name, style, size);
- }
-
- public void setName(String name) {
- this.name = name;
- correctName();
- }
-
- public void setName(int index) {
- if (index < 0 || index >= fontNames.length) {
- return;
- }
- name = fontNames[index];
- correctName();
- }
-
- public int getNameIndex() {
- regularName();
- boolean found = false;
- int i = 0;
- while (!found && i < fontNames.length) {
- found = name.equals(fontNames[i]);
- if (!found) {
- i++;
- }
- }
- correctName();
- if (found) {
- return i;
- }
- return -1; // This should never happen
- }
-
- public void setStyle(int index) {
- if (index < 0 || index >= 4) {
- return;
- }
- if (index == 3) {
- style = Font.BOLD + Font.ITALIC;
- return;
- }
- style = index;
- }
-
- public int getStyleIndex() {
- if (style < (Font.BOLD + Font.ITALIC)) {
- return style;
- }
- return style - 1;
- }
-
- public void setSize(int size) {
- this.size = size;
- }
-
- // Two methods to adjust discrepancy between common font name
- // and its equivalent name for java.awt.Font
-
- private void correctName() {
- if (name.equals("Times Roman")) {
- name = "TimesRoman";
- }
- }
-
- private void regularName() {
- if (name.equals("TimesRoman")) {
- name = "Times Roman";
- }
- }
- }
-