home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2005 February / PCpro_2005_02.ISO / files / opensource / Opcion_1.1.1 / Opcion_v1.1.1.exe / FontViewer / components / SystemFontsPanel.class (.txt) < prev    next >
Encoding:
Java Class File  |  2004-04-25  |  4.7 KB  |  154 lines

  1. package FontViewer.components;
  2.  
  3. import FontViewer.windows.MainWindow;
  4. import java.awt.BorderLayout;
  5. import java.awt.GraphicsEnvironment;
  6. import java.awt.event.KeyEvent;
  7. import java.awt.event.MouseEvent;
  8. import java.awt.event.WindowEvent;
  9. import javax.swing.JList;
  10. import javax.swing.JPanel;
  11. import javax.swing.JScrollPane;
  12. import javax.swing.border.Border;
  13.  
  14. public class SystemFontsPanel extends JPanel implements ListPanel {
  15.    // $FF: renamed from: mw FontViewer.windows.MainWindow
  16.    private MainWindow field_0;
  17.    private String[] names;
  18.    private String location;
  19.    private JList systemFontsList;
  20.    private JScrollPane systemFontsScrollPane;
  21.  
  22.    public SystemFontsPanel(MainWindow mw) {
  23.       this.field_0 = mw;
  24.       this.initComponents();
  25.       this.initSystemFonts();
  26.    }
  27.  
  28.    private void initSystemFonts() {
  29.       this.names = GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames();
  30.       this.location = "System Font";
  31.       this.systemFontsList.setListData(this.names);
  32.    }
  33.  
  34.    public String[] getItem(int itemNumber) {
  35.       String[] s = new String[3];
  36.       if (itemNumber >= 0 && itemNumber < this.names.length) {
  37.          s[0] = this.names[itemNumber];
  38.          s[1] = this.location;
  39.          s[2] = itemNumber + "";
  40.       }
  41.  
  42.       return s;
  43.    }
  44.  
  45.    public int getNumItems() {
  46.       int items = 0;
  47.       if (this.names != null) {
  48.          items = this.names.length;
  49.       }
  50.  
  51.       return items;
  52.    }
  53.  
  54.    public String[] getCurrentItem() {
  55.       String[] s = new String[3];
  56.       int p = this.systemFontsList.getSelectedIndex();
  57.       if (p >= 0) {
  58.          s[0] = this.names[p];
  59.          s[1] = this.location;
  60.          s[2] = p + "";
  61.       }
  62.  
  63.       return s;
  64.    }
  65.  
  66.    public int getCurrentItemNum() {
  67.       return this.systemFontsList.getSelectedIndex();
  68.    }
  69.  
  70.    public void selectItem(String name, String loc) {
  71.       this.systemFontsList.setSelectedValue(name, true);
  72.       int p = this.systemFontsList.getSelectedIndex();
  73.       if (p >= 0) {
  74.          this.field_0.setCurrentFont(this.names[p], this.location, p);
  75.       }
  76.  
  77.    }
  78.  
  79.    public void selectNext() {
  80.       int i = this.systemFontsList.getSelectedIndex();
  81.       if (i >= 0) {
  82.          if (i + 1 < this.names.length) {
  83.             ++i;
  84.          }
  85.  
  86.          this.setCurrentItem(i, true);
  87.       } else {
  88.          this.setCurrentItem(0, true);
  89.       }
  90.  
  91.    }
  92.  
  93.    public void selectPrev() {
  94.       int i = this.systemFontsList.getSelectedIndex();
  95.       if (i >= 0) {
  96.          if (i - 1 >= 0) {
  97.             --i;
  98.          }
  99.  
  100.          this.setCurrentItem(i, true);
  101.       } else {
  102.          this.setCurrentItem(0, true);
  103.       }
  104.  
  105.    }
  106.  
  107.    private void setCurrentItem(int p, boolean internal) {
  108.       if (internal) {
  109.          this.systemFontsList.setSelectedIndex(p);
  110.          int spos = p * (this.systemFontsScrollPane.getVerticalScrollBar().getMaximum() / this.names.length);
  111.          spos -= this.systemFontsScrollPane.getSize().height / 2;
  112.          this.systemFontsScrollPane.getVerticalScrollBar().setValue(spos);
  113.       }
  114.  
  115.       if (p >= 0) {
  116.          this.field_0.setCurrentFont(this.names[p], this.location, p);
  117.       }
  118.  
  119.    }
  120.  
  121.    private void initComponents() {
  122.       this.systemFontsScrollPane = new JScrollPane();
  123.       this.systemFontsList = new JList();
  124.       this.setLayout(new BorderLayout());
  125.       this.systemFontsScrollPane.setBorder((Border)null);
  126.       this.systemFontsList.setSelectionMode(0);
  127.       this.systemFontsList.addKeyListener(new 1(this));
  128.       this.systemFontsList.addMouseListener(new 2(this));
  129.       this.systemFontsScrollPane.setViewportView(this.systemFontsList);
  130.       this.add(this.systemFontsScrollPane, "Center");
  131.    }
  132.  
  133.    private void systemFontsListKeyReleased(KeyEvent evt) {
  134.       this.setCurrentItem(this.systemFontsList.getSelectedIndex(), false);
  135.    }
  136.  
  137.    private void systemFontsListMouseClicked(MouseEvent evt) {
  138.       this.setCurrentItem(this.systemFontsList.getSelectedIndex(), false);
  139.    }
  140.  
  141.    private void exitForm(WindowEvent evt) {
  142.    }
  143.  
  144.    // $FF: synthetic method
  145.    static void access$000(SystemFontsPanel x0, KeyEvent x1) {
  146.       x0.systemFontsListKeyReleased(x1);
  147.    }
  148.  
  149.    // $FF: synthetic method
  150.    static void access$100(SystemFontsPanel x0, MouseEvent x1) {
  151.       x0.systemFontsListMouseClicked(x1);
  152.    }
  153. }
  154.