VisClient/org/hfbk/util/FontDialog.java

Go to the documentation of this file.
00001 
00007 package org.hfbk.util;
00008 
00009 import java.awt.BorderLayout;
00010 import java.awt.Button;
00011 import java.awt.Dialog;
00012 import java.awt.Dimension;
00013 import java.awt.Font;
00014 import java.awt.Frame;
00015 import java.awt.GraphicsEnvironment;
00016 import java.awt.List;
00017 import java.awt.Panel;
00018 import java.awt.Point;
00019 import java.awt.event.ActionEvent;
00020 import java.awt.event.ActionListener;
00021 import java.awt.event.ItemEvent;
00022 import java.awt.event.ItemListener;
00023 
00024 import javax.swing.JLabel;
00025 
00026 public class FontDialog extends Dialog {
00027         public FontChooser font; 
00028         public Font SelectedFont;
00029 
00030         public FontDialog(Frame owner, String selected) {
00031                 super(owner, "Choose font..");
00032                 this.setLocation(new Point(100, 100));
00033                 this.setSize(new Dimension(360, 242));
00034 
00035                 font = new FontChooser(selected);
00036                 this.add(font);
00037                 
00038                 this.setModal(true);
00039                 UIUtils.blackify(this); // apply the classic vis look!
00040                 pack();
00041         }
00042 
00043         public Font chooseFont() {
00044                 this.setVisible(true);
00045                 return this.SelectedFont;
00046         }
00047 
00048         public class FontChooser extends Panel {
00049         
00050                 JLabel Preview;
00051                 List FontList;
00052                 Button OK_Button;
00053                 Button Cancel_Button;
00054                 
00055                 public FontChooser(String selected) {
00056                         super();
00057                         setLayout(new BorderLayout());
00058                         
00059                         this.Preview = new JLabel("ABCD abcd 0123", JLabel.CENTER){
00060                                 public Dimension getPreferredSize() {
00061                                         Dimension d=super.getPreferredSize();
00062                                         d.width*=1.2;
00063                                         d.height*=1.2;
00064                                         return d;
00065                                 }
00066                         };
00067 
00068                         this.FontList = new List();
00069                         this.FontList.addItemListener(new ItemListener() {
00070                                 public void itemStateChanged(ItemEvent arg0) {
00071                                         updatePreview();
00072                                 }
00073                         });
00074                         
00075                         fillFonts(selected);
00076                         
00077                         this.OK_Button = new Button("OK");
00078                         this.OK_Button.addActionListener(new ActionListener() {
00079                                 public void actionPerformed(ActionEvent e) {
00080                                         FontDialog.this.setVisible(false);
00081                                 }
00082                         });
00083 
00084                         this.Cancel_Button = new Button("CANCEL");
00085                         this.Cancel_Button.addActionListener(new ActionListener() {
00086                                 public void actionPerformed(ActionEvent e) {
00087                                         SelectedFont = null;
00088                                         FontDialog.this.setVisible(false);
00089                                 }
00090                         });
00091                         
00092                         updatePreview();
00093                         
00094                         add(Preview, BorderLayout.NORTH);
00095                         add(FontList, BorderLayout.CENTER);
00096                 
00097                         Panel p=new Panel();
00098                         p.add(OK_Button);
00099                         p.add(Cancel_Button);
00100                         add(p, BorderLayout.SOUTH);
00101                         
00102                         this.setLocation(new Point(100, 100));
00103                         pack();
00104                 
00105                 }
00106 
00107                 private void updatePreview() {
00108                 //      try {
00109                                 int size = 24;
00110                                 String name = this.FontList.getSelectedItem();
00111                                 
00112                                 SelectedFont = new Font(name, Font.PLAIN, size);
00113                                 this.Preview.setFont(SelectedFont);
00114                         /*} catch (Exception ex) {
00115                                 System.out.println(ex.getMessage());
00116                         }*/
00117                 }
00118                 
00119                 void fillFonts(String selected){
00120                         String[] fonts = GraphicsEnvironment.getLocalGraphicsEnvironment()
00121                         .getAvailableFontFamilyNames();
00122                         for (String f: fonts)
00123                                 this.FontList.add(f);
00124                         int i=0;
00125                         for (String f: fonts){
00126                                 if (f.equals(selected)){
00127                                         FontList.select(i);
00128                                         FontList.makeVisible(i);
00129                                         break;
00130                                 }
00131                                 i++;
00132                         }       
00133                 }
00134         }
00135 }

Generated on Tue Apr 7 17:57:20 2009 for visclient by  doxygen 1.5.1