home *** CD-ROM | disk | FTP | other *** search
- package netscape.application;
-
- public class FontChooser implements Target {
- ListView _nameList;
- Popup _sizePopup;
- Popup _stylePopup;
- TextField _sizeTextField;
- TextField _messageTextField;
- Button _setButton;
- Font _currentFont;
- private ContainerView contentView;
- private Window window;
-
- public FontChooser() {
- String[] var8 = new String[4];
- int[] var9 = new int[4];
- int[] var12 = new int[6];
- this.contentView = new ContainerView(0, 0, 178, 120);
- this.contentView.setBackgroundColor(Color.lightGray);
- this.contentView.setBorder((Border)null);
- this.contentView.setHorizResizeInstruction(2);
- this.contentView.setVertResizeInstruction(16);
- ScrollGroup var3 = new ScrollGroup(4, 19, 90, 61);
- var3.setHasVertScrollBar(true);
- var3.setBorder(BezelBorder.loweredBezel());
- ((View)var3).setHorizResizeInstruction(2);
- ((View)var3).setVertResizeInstruction(16);
- Rect var7 = var3.scrollView().bounds;
- this._nameList = new ListView(0, 0, var7.width, var7.width);
- this._nameList.setHorizResizeInstruction(2);
- this._nameList.setPrototypeItem(new FontItem());
- this._nameList.prototypeItem().setFont(Font.fontNamed("Default"));
- this._loadNameList();
- var3.setContentView(this._nameList);
- this.contentView.addSubview(var3);
- TextField var2 = new TextField(28, 1, 70, 18);
- var2.setEditable(false);
- var2.setTextColor(Color.black);
- var2.setFont(Font.fontNamed("Helvetica", 1, 12));
- var2.setBackgroundColor(Color.lightGray);
- var2.setStringValue("Name");
- var2.setJustification(0);
- var2.setBorder((Border)null);
- ((View)var2).setHorizResizeInstruction(0);
- ((View)var2).setVertResizeInstruction(4);
- this.contentView.addSubview(var2);
- this._sizePopup = new Popup(99, 19, 45, 20);
- FontItem var6 = new FontItem();
- ((PopupItem)var6).setPopup(this._sizePopup);
- ((ListItem)var6).setFont(Font.fontNamed("Default"));
- this._sizePopup.setPrototypeItem(var6);
- var12[0] = 8;
- var12[1] = 10;
- var12[2] = 12;
- var12[3] = 14;
- var12[4] = 24;
- var12[5] = 36;
- int var11 = var12.length;
- ListView var1 = this._sizePopup.popupList();
-
- for(int var10 = 0; var10 < var11; ++var10) {
- FontItem var5 = (FontItem)var1.addItem();
- ((ListItem)var5).setTitle(Integer.toString(var12[var10]));
- var5.setTag(var12[var10]);
- }
-
- FontItem var16 = (FontItem)var1.addItem();
- ((ListItem)var16).setTitle("Other");
- var16.setTag(-1);
- this._sizePopup.setTarget(this);
- this._sizePopup.setHorizResizeInstruction(1);
- this._sizePopup.setVertResizeInstruction(4);
- this.contentView.addSubview(this._sizePopup);
- this._sizeTextField = new TextField(146, 19, 25, 20);
- this._sizeTextField.setEditable(true);
- this._sizeTextField.setContentsChangedCommandAndTarget("", this);
- this._sizeTextField.setHorizResizeInstruction(1);
- this._sizeTextField.setVertResizeInstruction(4);
- this.contentView.addSubview(this._sizeTextField);
- var2 = new TextField(100, 1, 30, 18);
- var2.setEditable(false);
- var2.setTextColor(Color.black);
- var2.setBackgroundColor(Color.lightGray);
- var2.setFont(Font.fontNamed("Helvetica", 1, 12));
- var2.setStringValue("Size");
- var2.setJustification(0);
- var2.setBorder((Border)null);
- ((View)var2).setHorizResizeInstruction(1);
- ((View)var2).setVertResizeInstruction(4);
- this.contentView.addSubview(var2);
- this._stylePopup = new Popup(99, 61, 75, 21);
- var6 = new FontItem();
- ((PopupItem)var6).setPopup(this._stylePopup);
- ((ListItem)var6).setFont(Font.fontNamed("Default"));
- this._stylePopup.setPrototypeItem(var6);
- var8[0] = "Plain";
- var8[1] = "Bold";
- var8[2] = "Italic";
- var8[3] = "Bold Italic";
- var9[0] = 0;
- var9[1] = 1;
- var9[2] = 2;
- var9[3] = 3;
- var11 = var8.length;
- var1 = this._stylePopup.popupList();
-
- for(int var19 = 0; var19 < var11; ++var19) {
- var16 = (FontItem)var1.addItem();
- ((ListItem)var16).setTitle(var8[var19]);
- var16.setTag(var9[var19]);
- }
-
- this._stylePopup.setHorizResizeInstruction(1);
- this._stylePopup.setVertResizeInstruction(4);
- this.contentView.addSubview(this._stylePopup);
- var2 = new TextField(100, 43, 30, 18);
- var2.setEditable(false);
- var2.setTextColor(Color.black);
- var2.setBackgroundColor(Color.lightGray);
- var2.setFont(Font.fontNamed("Helvetica", 1, 12));
- var2.setStringValue("Style");
- var2.setJustification(0);
- var2.setBorder((Border)null);
- ((View)var2).setHorizResizeInstruction(1);
- ((View)var2).setVertResizeInstruction(4);
- this.contentView.addSubview(var2);
- ContainerView var4 = new ContainerView(-2, 87, 184, 2);
- ((View)var4).setHorizResizeInstruction(2);
- ((View)var4).setVertResizeInstruction(8);
- this.contentView.addSubview(var4);
- this._setButton = new Button(124, 95, 50, 21);
- this._setButton.setTitle("Set");
- this._setButton.setHorizResizeInstruction(1);
- this._setButton.setVertResizeInstruction(8);
- this._setButton.setCommand("setFont");
- this._setButton.setTarget(this);
- this.contentView.addSubview(this._setButton);
- this._messageTextField = new TextField(4, 95, 100, 21);
- this._messageTextField.setEditable(false);
- this._messageTextField.setBorder((Border)null);
- this._messageTextField.setTextColor(Color.gray);
- this._messageTextField.setBackgroundColor(Color.lightGray);
- this._messageTextField.setFont(Font.fontNamed("Helvetica", 0, 10));
- this._messageTextField.setHorizResizeInstruction(0);
- this._messageTextField.setVertResizeInstruction(8);
- this.contentView.addSubview(this._messageTextField);
- this.setFont(Font.defaultFont());
- }
-
- private void _loadNameList() {
- String[] var2 = new String[6];
- String[] var3 = new String[6];
- var2[0] = "Courier";
- var2[1] = "Dialog";
- var2[2] = "Dialog Input";
- var2[3] = "Helvetica";
- var2[4] = "Times Roman";
- var2[5] = "Zapf Dingbats";
- var3[0] = "Courier";
- var3[1] = "Dialog";
- var3[2] = "DialogInput";
- var3[3] = "Helvetica";
- var3[4] = "TimesRoman";
- var3[5] = "ZapfDingbats";
- int var5 = var2.length;
-
- for(int var4 = 0; var4 < var5; ++var4) {
- FontItem var1 = (FontItem)this._nameList.addItem();
- ((ListItem)var1).setTitle(var2[var4]);
- var1.setFontName(var3[var4]);
- }
-
- this._nameList.setRowHeight(this._nameList.minItemHeight());
- this._nameList.sizeToMinSize();
- }
-
- public void show() {
- if (this.window != null) {
- this.window.show();
- }
-
- }
-
- public void hide() {
- if (this.window != null) {
- this.window.hide();
- }
-
- }
-
- private void _setSizePopupToSize(int var1) {
- int var3 = this._sizePopup.count();
-
- while(var3-- > 0) {
- FontItem var2 = (FontItem)this._sizePopup.popupList().itemAt(var3);
- if (var2.tag() == var1) {
- this._sizePopup.selectItemAt(var3);
- return;
- }
- }
-
- if (var3 == -1) {
- this._sizePopup.selectItemAt(this._sizePopup.count() - 1);
- }
-
- }
-
- public void setFont(Font var1) {
- if (var1 != null) {
- this._currentFont = var1;
- int var3 = this._nameList.count();
-
- while(var3-- > 0) {
- FontItem var2 = (FontItem)this._nameList.itemAt(var3);
- if (var2.hasFontName(var1.family())) {
- this._nameList.selectItemAt(var3);
- this._nameList.scrollItemAtToVisible(var3);
- break;
- }
- }
-
- if (var3 == -1) {
- this._nameList.selectItemAt(0);
- }
-
- if (var1.isBold()) {
- if (var1.isItalic()) {
- this._stylePopup.selectItemAt(3);
- } else {
- this._stylePopup.selectItemAt(1);
- }
- } else if (var1.isItalic()) {
- this._stylePopup.selectItemAt(2);
- } else {
- this._stylePopup.selectItemAt(0);
- }
-
- this._setSizePopupToSize(var1.size());
- this._sizeTextField.setIntValue(var1.size());
- }
- }
-
- public Font font() {
- String var3;
- if (this._nameList.selectedItem() == null) {
- var3 = "";
- } else {
- FontItem var2 = (FontItem)this._nameList.selectedItem();
- var3 = var2.fontName();
- }
-
- Font var1 = Font.fontNamed(var3, ((FontItem)this._stylePopup.selectedItem()).tag(), this._sizeTextField.intValue());
- return var1;
- }
-
- public void performCommand(String var1, Object var2) {
- if (var2 == this._sizeTextField) {
- int var5 = this._sizeTextField.intValue();
- if (var5 > 0) {
- this._setSizePopupToSize(var5);
- } else {
- this._setSizePopupToSize(8);
- this._sizeTextField.setIntValue(8);
- }
- } else {
- if (var2 == this._sizePopup) {
- int var3 = ((FontItem)this._sizePopup.selectedItem()).tag();
- if (var3 > 0) {
- this._sizeTextField.setIntValue(var3);
- return;
- }
- } else if (var2 == this._setButton) {
- TargetChain var4 = TargetChain.applicationChain();
- var4.performCommand(var1, this.font());
- }
-
- }
- }
-
- public void setWindow(Window var1) {
- this.window = var1;
- Size var2 = this.window.windowSizeForContentSize(this.contentView.width(), this.contentView.height());
- this.window.sizeTo(var2.width, var2.height);
- this.window.addSubview(this.contentView);
- this.window.setTitle("Font Chooser");
- Rect var3 = this.window.bounds();
- this.window.setMinSize(var3.width, var3.width);
- if (this.window instanceof InternalWindow) {
- InternalWindow var4 = (InternalWindow)this.window;
- var4.setCloseable(true);
- ((View)var4).setBuffered(true);
- }
-
- this.window.setContainsDocument(false);
- }
-
- public Window window() {
- return this.window;
- }
-
- public View contentView() {
- return this.contentView;
- }
- }
-