home *** CD-ROM | disk | FTP | other *** search
/ Computer Shopper 139 / dpcs0999.iso / Web / CFserver / data1.cab / Java / netscape / application / FontChooser.class (.txt) < prev    next >
Encoding:
Java Class File  |  1999-04-12  |  7.8 KB  |  305 lines

  1. package netscape.application;
  2.  
  3. public class FontChooser implements Target {
  4.    ListView _nameList;
  5.    Popup _sizePopup;
  6.    Popup _stylePopup;
  7.    TextField _sizeTextField;
  8.    TextField _messageTextField;
  9.    Button _setButton;
  10.    Font _currentFont;
  11.    private ContainerView contentView;
  12.    private Window window;
  13.  
  14.    public FontChooser() {
  15.       String[] var8 = new String[4];
  16.       int[] var9 = new int[4];
  17.       int[] var12 = new int[6];
  18.       this.contentView = new ContainerView(0, 0, 178, 120);
  19.       this.contentView.setBackgroundColor(Color.lightGray);
  20.       this.contentView.setBorder((Border)null);
  21.       this.contentView.setHorizResizeInstruction(2);
  22.       this.contentView.setVertResizeInstruction(16);
  23.       ScrollGroup var3 = new ScrollGroup(4, 19, 90, 61);
  24.       var3.setHasVertScrollBar(true);
  25.       var3.setBorder(BezelBorder.loweredBezel());
  26.       ((View)var3).setHorizResizeInstruction(2);
  27.       ((View)var3).setVertResizeInstruction(16);
  28.       Rect var7 = var3.scrollView().bounds;
  29.       this._nameList = new ListView(0, 0, var7.width, var7.width);
  30.       this._nameList.setHorizResizeInstruction(2);
  31.       this._nameList.setPrototypeItem(new FontItem());
  32.       this._nameList.prototypeItem().setFont(Font.fontNamed("Default"));
  33.       this._loadNameList();
  34.       var3.setContentView(this._nameList);
  35.       this.contentView.addSubview(var3);
  36.       TextField var2 = new TextField(28, 1, 70, 18);
  37.       var2.setEditable(false);
  38.       var2.setTextColor(Color.black);
  39.       var2.setFont(Font.fontNamed("Helvetica", 1, 12));
  40.       var2.setBackgroundColor(Color.lightGray);
  41.       var2.setStringValue("Name");
  42.       var2.setJustification(0);
  43.       var2.setBorder((Border)null);
  44.       ((View)var2).setHorizResizeInstruction(0);
  45.       ((View)var2).setVertResizeInstruction(4);
  46.       this.contentView.addSubview(var2);
  47.       this._sizePopup = new Popup(99, 19, 45, 20);
  48.       FontItem var6 = new FontItem();
  49.       ((PopupItem)var6).setPopup(this._sizePopup);
  50.       ((ListItem)var6).setFont(Font.fontNamed("Default"));
  51.       this._sizePopup.setPrototypeItem(var6);
  52.       var12[0] = 8;
  53.       var12[1] = 10;
  54.       var12[2] = 12;
  55.       var12[3] = 14;
  56.       var12[4] = 24;
  57.       var12[5] = 36;
  58.       int var11 = var12.length;
  59.       ListView var1 = this._sizePopup.popupList();
  60.  
  61.       for(int var10 = 0; var10 < var11; ++var10) {
  62.          FontItem var5 = (FontItem)var1.addItem();
  63.          ((ListItem)var5).setTitle(Integer.toString(var12[var10]));
  64.          var5.setTag(var12[var10]);
  65.       }
  66.  
  67.       FontItem var16 = (FontItem)var1.addItem();
  68.       ((ListItem)var16).setTitle("Other");
  69.       var16.setTag(-1);
  70.       this._sizePopup.setTarget(this);
  71.       this._sizePopup.setHorizResizeInstruction(1);
  72.       this._sizePopup.setVertResizeInstruction(4);
  73.       this.contentView.addSubview(this._sizePopup);
  74.       this._sizeTextField = new TextField(146, 19, 25, 20);
  75.       this._sizeTextField.setEditable(true);
  76.       this._sizeTextField.setContentsChangedCommandAndTarget("", this);
  77.       this._sizeTextField.setHorizResizeInstruction(1);
  78.       this._sizeTextField.setVertResizeInstruction(4);
  79.       this.contentView.addSubview(this._sizeTextField);
  80.       var2 = new TextField(100, 1, 30, 18);
  81.       var2.setEditable(false);
  82.       var2.setTextColor(Color.black);
  83.       var2.setBackgroundColor(Color.lightGray);
  84.       var2.setFont(Font.fontNamed("Helvetica", 1, 12));
  85.       var2.setStringValue("Size");
  86.       var2.setJustification(0);
  87.       var2.setBorder((Border)null);
  88.       ((View)var2).setHorizResizeInstruction(1);
  89.       ((View)var2).setVertResizeInstruction(4);
  90.       this.contentView.addSubview(var2);
  91.       this._stylePopup = new Popup(99, 61, 75, 21);
  92.       var6 = new FontItem();
  93.       ((PopupItem)var6).setPopup(this._stylePopup);
  94.       ((ListItem)var6).setFont(Font.fontNamed("Default"));
  95.       this._stylePopup.setPrototypeItem(var6);
  96.       var8[0] = "Plain";
  97.       var8[1] = "Bold";
  98.       var8[2] = "Italic";
  99.       var8[3] = "Bold Italic";
  100.       var9[0] = 0;
  101.       var9[1] = 1;
  102.       var9[2] = 2;
  103.       var9[3] = 3;
  104.       var11 = var8.length;
  105.       var1 = this._stylePopup.popupList();
  106.  
  107.       for(int var19 = 0; var19 < var11; ++var19) {
  108.          var16 = (FontItem)var1.addItem();
  109.          ((ListItem)var16).setTitle(var8[var19]);
  110.          var16.setTag(var9[var19]);
  111.       }
  112.  
  113.       this._stylePopup.setHorizResizeInstruction(1);
  114.       this._stylePopup.setVertResizeInstruction(4);
  115.       this.contentView.addSubview(this._stylePopup);
  116.       var2 = new TextField(100, 43, 30, 18);
  117.       var2.setEditable(false);
  118.       var2.setTextColor(Color.black);
  119.       var2.setBackgroundColor(Color.lightGray);
  120.       var2.setFont(Font.fontNamed("Helvetica", 1, 12));
  121.       var2.setStringValue("Style");
  122.       var2.setJustification(0);
  123.       var2.setBorder((Border)null);
  124.       ((View)var2).setHorizResizeInstruction(1);
  125.       ((View)var2).setVertResizeInstruction(4);
  126.       this.contentView.addSubview(var2);
  127.       ContainerView var4 = new ContainerView(-2, 87, 184, 2);
  128.       ((View)var4).setHorizResizeInstruction(2);
  129.       ((View)var4).setVertResizeInstruction(8);
  130.       this.contentView.addSubview(var4);
  131.       this._setButton = new Button(124, 95, 50, 21);
  132.       this._setButton.setTitle("Set");
  133.       this._setButton.setHorizResizeInstruction(1);
  134.       this._setButton.setVertResizeInstruction(8);
  135.       this._setButton.setCommand("setFont");
  136.       this._setButton.setTarget(this);
  137.       this.contentView.addSubview(this._setButton);
  138.       this._messageTextField = new TextField(4, 95, 100, 21);
  139.       this._messageTextField.setEditable(false);
  140.       this._messageTextField.setBorder((Border)null);
  141.       this._messageTextField.setTextColor(Color.gray);
  142.       this._messageTextField.setBackgroundColor(Color.lightGray);
  143.       this._messageTextField.setFont(Font.fontNamed("Helvetica", 0, 10));
  144.       this._messageTextField.setHorizResizeInstruction(0);
  145.       this._messageTextField.setVertResizeInstruction(8);
  146.       this.contentView.addSubview(this._messageTextField);
  147.       this.setFont(Font.defaultFont());
  148.    }
  149.  
  150.    private void _loadNameList() {
  151.       String[] var2 = new String[6];
  152.       String[] var3 = new String[6];
  153.       var2[0] = "Courier";
  154.       var2[1] = "Dialog";
  155.       var2[2] = "Dialog Input";
  156.       var2[3] = "Helvetica";
  157.       var2[4] = "Times Roman";
  158.       var2[5] = "Zapf Dingbats";
  159.       var3[0] = "Courier";
  160.       var3[1] = "Dialog";
  161.       var3[2] = "DialogInput";
  162.       var3[3] = "Helvetica";
  163.       var3[4] = "TimesRoman";
  164.       var3[5] = "ZapfDingbats";
  165.       int var5 = var2.length;
  166.  
  167.       for(int var4 = 0; var4 < var5; ++var4) {
  168.          FontItem var1 = (FontItem)this._nameList.addItem();
  169.          ((ListItem)var1).setTitle(var2[var4]);
  170.          var1.setFontName(var3[var4]);
  171.       }
  172.  
  173.       this._nameList.setRowHeight(this._nameList.minItemHeight());
  174.       this._nameList.sizeToMinSize();
  175.    }
  176.  
  177.    public void show() {
  178.       if (this.window != null) {
  179.          this.window.show();
  180.       }
  181.  
  182.    }
  183.  
  184.    public void hide() {
  185.       if (this.window != null) {
  186.          this.window.hide();
  187.       }
  188.  
  189.    }
  190.  
  191.    private void _setSizePopupToSize(int var1) {
  192.       int var3 = this._sizePopup.count();
  193.  
  194.       while(var3-- > 0) {
  195.          FontItem var2 = (FontItem)this._sizePopup.popupList().itemAt(var3);
  196.          if (var2.tag() == var1) {
  197.             this._sizePopup.selectItemAt(var3);
  198.             return;
  199.          }
  200.       }
  201.  
  202.       if (var3 == -1) {
  203.          this._sizePopup.selectItemAt(this._sizePopup.count() - 1);
  204.       }
  205.  
  206.    }
  207.  
  208.    public void setFont(Font var1) {
  209.       if (var1 != null) {
  210.          this._currentFont = var1;
  211.          int var3 = this._nameList.count();
  212.  
  213.          while(var3-- > 0) {
  214.             FontItem var2 = (FontItem)this._nameList.itemAt(var3);
  215.             if (var2.hasFontName(var1.family())) {
  216.                this._nameList.selectItemAt(var3);
  217.                this._nameList.scrollItemAtToVisible(var3);
  218.                break;
  219.             }
  220.          }
  221.  
  222.          if (var3 == -1) {
  223.             this._nameList.selectItemAt(0);
  224.          }
  225.  
  226.          if (var1.isBold()) {
  227.             if (var1.isItalic()) {
  228.                this._stylePopup.selectItemAt(3);
  229.             } else {
  230.                this._stylePopup.selectItemAt(1);
  231.             }
  232.          } else if (var1.isItalic()) {
  233.             this._stylePopup.selectItemAt(2);
  234.          } else {
  235.             this._stylePopup.selectItemAt(0);
  236.          }
  237.  
  238.          this._setSizePopupToSize(var1.size());
  239.          this._sizeTextField.setIntValue(var1.size());
  240.       }
  241.    }
  242.  
  243.    public Font font() {
  244.       String var3;
  245.       if (this._nameList.selectedItem() == null) {
  246.          var3 = "";
  247.       } else {
  248.          FontItem var2 = (FontItem)this._nameList.selectedItem();
  249.          var3 = var2.fontName();
  250.       }
  251.  
  252.       Font var1 = Font.fontNamed(var3, ((FontItem)this._stylePopup.selectedItem()).tag(), this._sizeTextField.intValue());
  253.       return var1;
  254.    }
  255.  
  256.    public void performCommand(String var1, Object var2) {
  257.       if (var2 == this._sizeTextField) {
  258.          int var5 = this._sizeTextField.intValue();
  259.          if (var5 > 0) {
  260.             this._setSizePopupToSize(var5);
  261.          } else {
  262.             this._setSizePopupToSize(8);
  263.             this._sizeTextField.setIntValue(8);
  264.          }
  265.       } else {
  266.          if (var2 == this._sizePopup) {
  267.             int var3 = ((FontItem)this._sizePopup.selectedItem()).tag();
  268.             if (var3 > 0) {
  269.                this._sizeTextField.setIntValue(var3);
  270.                return;
  271.             }
  272.          } else if (var2 == this._setButton) {
  273.             TargetChain var4 = TargetChain.applicationChain();
  274.             var4.performCommand(var1, this.font());
  275.          }
  276.  
  277.       }
  278.    }
  279.  
  280.    public void setWindow(Window var1) {
  281.       this.window = var1;
  282.       Size var2 = this.window.windowSizeForContentSize(this.contentView.width(), this.contentView.height());
  283.       this.window.sizeTo(var2.width, var2.height);
  284.       this.window.addSubview(this.contentView);
  285.       this.window.setTitle("Font Chooser");
  286.       Rect var3 = this.window.bounds();
  287.       this.window.setMinSize(var3.width, var3.width);
  288.       if (this.window instanceof InternalWindow) {
  289.          InternalWindow var4 = (InternalWindow)this.window;
  290.          var4.setCloseable(true);
  291.          ((View)var4).setBuffered(true);
  292.       }
  293.  
  294.       this.window.setContainsDocument(false);
  295.    }
  296.  
  297.    public Window window() {
  298.       return this.window;
  299.    }
  300.  
  301.    public View contentView() {
  302.       return this.contentView;
  303.    }
  304. }
  305.