home *** CD-ROM | disk | FTP | other *** search
- package FontViewer.components;
-
- import FontViewer.filters.FontFileFilter;
- import FontViewer.util.QuickSort;
- import FontViewer.windows.MainWindow;
- import java.awt.BorderLayout;
- import java.awt.Dimension;
- import java.awt.Font;
- import java.awt.FontFormatException;
- import java.awt.event.ActionEvent;
- import java.awt.event.FocusEvent;
- import java.awt.event.KeyEvent;
- import java.awt.event.MouseEvent;
- import java.awt.event.WindowEvent;
- import java.io.File;
- import java.io.FileInputStream;
- import java.io.IOException;
- import java.lang.ref.WeakReference;
- import javax.swing.JButton;
- import javax.swing.JFileChooser;
- import javax.swing.JLabel;
- import javax.swing.JList;
- import javax.swing.JOptionPane;
- import javax.swing.JPanel;
- import javax.swing.JScrollPane;
- import javax.swing.JTextField;
- import javax.swing.border.Border;
-
- public class OtherFontsPanel extends JPanel implements ListPanel {
- private File currentDirectory;
- private String[] fnames;
- private String[] fontnames;
- // $FF: renamed from: mw FontViewer.windows.MainWindow
- private MainWindow field_0;
- private JButton browseButton;
- private JLabel locationLabel;
- private JPanel locationPanel;
- private JTextField locationTextField;
- private JList otherFontsList;
- private JScrollPane otherFontsScrollPane;
-
- public OtherFontsPanel(MainWindow mw) {
- this.field_0 = mw;
- this.initComponents();
- }
-
- public String[] getItem(int itemNumber) {
- String[] s = new String[3];
- if (itemNumber >= 0 && itemNumber < this.fnames.length) {
- s[0] = this.fnames[itemNumber];
- s[1] = this.currentDirectory.toString();
- s[2] = itemNumber + "";
- }
-
- return s;
- }
-
- public int getNumItems() {
- int items = 0;
- if (this.fnames != null) {
- items = this.fnames.length;
- }
-
- return items;
- }
-
- public String[] getCurrentItem() {
- String[] s = new String[3];
- int p = this.otherFontsList.getSelectedIndex();
- if (p >= 0) {
- s[0] = this.fnames[p];
- s[1] = this.currentDirectory.toString();
- s[2] = p + "";
- }
-
- return s;
- }
-
- public int getCurrentItemNum() {
- return this.otherFontsList.getSelectedIndex();
- }
-
- private void updateFontNames() {
- Font f = null;
- WeakReference wrf = null;
- String fontfile = "";
- this.fontnames = new String[this.fnames.length];
-
- for(int i = 0; i < this.fnames.length; ++i) {
- try {
- fontfile = this.currentDirectory.toString() + File.separator + this.fnames[i];
- System.out.println("FF: " + fontfile);
- f = Font.createFont(0, new FileInputStream(fontfile));
- wrf = new WeakReference(f);
- this.fontnames[i] = ((Font)wrf.get()).getName();
- } catch (IOException var6) {
- this.fontnames[i] = "Cannot load " + this.fnames[i] + " [IOException]";
- } catch (FontFormatException var7) {
- this.fontnames[i] = "Cannot load " + this.fnames[i] + " [FontFormatException]";
- }
- }
-
- }
-
- private void updateDisplay() {
- this.fnames = this.currentDirectory.list(new FontFileFilter());
- QuickSort.sort(this.fnames, true);
- if (this.fnames.length == 0) {
- String[] message = new String[]{"This folder does not contain any fonts."};
- this.otherFontsList.setListData(message);
- this.otherFontsList.setEnabled(false);
- } else {
- this.otherFontsList.setListData(this.fnames);
- this.otherFontsList.setEnabled(true);
- }
-
- this.field_0.updateDisplay();
- }
-
- public void selectItem(String name, String loc) {
- this.otherFontsList.setSelectedValue(name, true);
- int p = this.otherFontsList.getSelectedIndex();
- if (p >= 0) {
- this.field_0.setCurrentFont(this.fnames[p].toString(), this.currentDirectory.toString(), p);
- }
-
- }
-
- public void selectNext() {
- int i = this.otherFontsList.getSelectedIndex();
- if (i >= 0) {
- if (i + 1 < this.fnames.length) {
- ++i;
- }
-
- this.setCurrentItem(i, true);
- } else {
- this.setCurrentItem(0, true);
- }
-
- }
-
- public void selectPrev() {
- int i = this.otherFontsList.getSelectedIndex();
- if (i >= 0) {
- if (i - 1 >= 0) {
- --i;
- }
-
- this.setCurrentItem(i, true);
- } else {
- this.setCurrentItem(0, true);
- }
-
- }
-
- private void setCurrentItem(int p, boolean internal) {
- if (this.fnames != null) {
- if (internal) {
- this.otherFontsList.setSelectedIndex(p);
- int spos = p * (this.otherFontsScrollPane.getVerticalScrollBar().getMaximum() / this.fnames.length);
- spos -= this.otherFontsScrollPane.getSize().height / 2;
- this.otherFontsScrollPane.getVerticalScrollBar().setValue(spos);
- }
-
- if (p >= 0) {
- this.field_0.setCurrentFont(this.fnames[p].toString(), this.currentDirectory.toString(), p);
- }
- }
-
- }
-
- private void initComponents() {
- this.locationPanel = new JPanel();
- this.locationLabel = new JLabel();
- this.locationTextField = new JTextField();
- this.browseButton = new JButton();
- this.otherFontsScrollPane = new JScrollPane();
- this.otherFontsList = new JList();
- this.setLayout(new BorderLayout(2, 2));
- this.locationPanel.setLayout(new BorderLayout(4, 0));
- this.locationLabel.setText("Location:");
- this.locationPanel.add(this.locationLabel, "West");
- this.locationTextField.setToolTipText("Enter the location where fonts you wish to view are stored here");
- this.locationTextField.setPreferredSize(new Dimension(100, 20));
- this.locationTextField.addFocusListener(new 1(this));
- this.locationTextField.addKeyListener(new 2(this));
- this.locationPanel.add(this.locationTextField, "Center");
- this.browseButton.setText("Browse");
- this.browseButton.setToolTipText("Browse for font directory");
- this.browseButton.setPreferredSize(new Dimension(81, 20));
- this.browseButton.addActionListener(new 3(this));
- this.locationPanel.add(this.browseButton, "East");
- this.add(this.locationPanel, "North");
- this.otherFontsScrollPane.setBorder((Border)null);
- this.otherFontsList.addKeyListener(new 4(this));
- this.otherFontsList.addMouseListener(new 5(this));
- this.otherFontsScrollPane.setViewportView(this.otherFontsList);
- this.add(this.otherFontsScrollPane, "Center");
- }
-
- private void locationTextFieldFocusLost(FocusEvent evt) {
- this.field_0.setTyping(false);
- }
-
- private void locationTextFieldFocusGained(FocusEvent evt) {
- this.field_0.setTyping(true);
- }
-
- private void otherFontsListKeyReleased(KeyEvent evt) {
- this.setCurrentItem(this.otherFontsList.getSelectedIndex(), false);
- }
-
- private void browseButtonActionPerformed(ActionEvent evt) {
- JFileChooser fc = new JFileChooser(new File(""));
- fc.setFileSelectionMode(1);
- fc.showOpenDialog(this);
- if (fc.getSelectedFile() != null) {
- this.currentDirectory = fc.getSelectedFile();
- this.locationTextField.setText(this.currentDirectory.toString());
- this.updateDisplay();
- }
-
- }
-
- private void otherFontsListMouseClicked(MouseEvent evt) {
- this.setCurrentItem(this.otherFontsList.getSelectedIndex(), false);
- }
-
- private void locationTextFieldKeyReleased(KeyEvent evt) {
- if (evt.getKeyCode() == 10) {
- this.field_0.setTyping(false);
- File f = new File(this.locationTextField.getText());
- if (f.exists()) {
- if (f.isDirectory()) {
- this.currentDirectory = f;
- this.updateDisplay();
- } else {
- new JOptionPane();
- JOptionPane.showMessageDialog(this, "The location does not point to a directory.", "Error!", 0);
- }
- } else {
- new JOptionPane();
- JOptionPane.showMessageDialog(this, "Directory does not exist.", "Error!", 0);
- }
- }
-
- }
-
- private void exitForm(WindowEvent evt) {
- }
-
- // $FF: synthetic method
- static void access$000(OtherFontsPanel x0, FocusEvent x1) {
- x0.locationTextFieldFocusGained(x1);
- }
-
- // $FF: synthetic method
- static void access$100(OtherFontsPanel x0, FocusEvent x1) {
- x0.locationTextFieldFocusLost(x1);
- }
-
- // $FF: synthetic method
- static void access$200(OtherFontsPanel x0, KeyEvent x1) {
- x0.locationTextFieldKeyReleased(x1);
- }
-
- // $FF: synthetic method
- static void access$300(OtherFontsPanel x0, ActionEvent x1) {
- x0.browseButtonActionPerformed(x1);
- }
-
- // $FF: synthetic method
- static void access$400(OtherFontsPanel x0, KeyEvent x1) {
- x0.otherFontsListKeyReleased(x1);
- }
-
- // $FF: synthetic method
- static void access$500(OtherFontsPanel x0, MouseEvent x1) {
- x0.otherFontsListMouseClicked(x1);
- }
- }
-