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 / SampleTextPanel.class (.txt) < prev    next >
Encoding:
Java Class File  |  2004-04-25  |  9.1 KB  |  250 lines

  1. package FontViewer.components;
  2.  
  3. import FontViewer.windows.MainWindow;
  4. import java.awt.BorderLayout;
  5. import java.awt.Dimension;
  6. import java.awt.Font;
  7. import java.awt.GridLayout;
  8. import java.awt.Insets;
  9. import java.awt.event.ActionEvent;
  10. import java.awt.event.ItemEvent;
  11. import java.awt.event.WindowEvent;
  12. import java.io.File;
  13. import java.io.FileInputStream;
  14. import java.lang.ref.WeakReference;
  15. import java.util.ResourceBundle;
  16. import java.util.Vector;
  17. import javax.swing.JButton;
  18. import javax.swing.JComboBox;
  19. import javax.swing.JLabel;
  20. import javax.swing.JOptionPane;
  21. import javax.swing.JPanel;
  22. import javax.swing.JScrollPane;
  23. import javax.swing.JTextPane;
  24. import javax.swing.JToggleButton;
  25. import javax.swing.border.Border;
  26. import javax.swing.border.TitledBorder;
  27. import javax.swing.text.Style;
  28. import javax.swing.text.StyleConstants;
  29.  
  30. public class SampleTextPanel extends JPanel {
  31.    private final int BOLD = 0;
  32.    private final int ITALIC = 1;
  33.    private final int UNDERLINE = 2;
  34.    private Vector fontSizes;
  35.    private String sampleText;
  36.    private String fname;
  37.    private String floc;
  38.    private int fsize;
  39.    private boolean[] fontProperties = new boolean[]{false, false, false};
  40.    // $FF: renamed from: mw FontViewer.windows.MainWindow
  41.    private MainWindow field_0;
  42.    private JButton addFavouritesButton;
  43.    private JToggleButton boldButton;
  44.    private JPanel fontInfoPanel;
  45.    private JLabel fontName;
  46.    private JLabel fontNameLabel;
  47.    private JPanel fontPropertiesPanel;
  48.    private JComboBox fontSizeComboBox;
  49.    private JLabel fontSizeLabel;
  50.    private JPanel fontSizePanel;
  51.    private JToggleButton italicsButton;
  52.    private JPanel optionsPanel;
  53.    private JTextPane previewTextPane;
  54.    private JScrollPane previewTextPaneScollPane;
  55.    private JPanel topPanel;
  56.    private JToggleButton underlineButton;
  57.  
  58.    public SampleTextPanel(MainWindow mw, int[] sizes) {
  59.       this.field_0 = mw;
  60.       this.sampleText = ResourceBundle.getBundle("FontViewer.resources.Opcion").getString("defaultSampleText");
  61.       this.initFontSizes(sizes);
  62.       this.initComponents();
  63.       this.fname = "Default";
  64.       this.floc = "System Font";
  65.       this.fontSizeComboBox.setSelectedItem(this.fontSizes.get(9));
  66.    }
  67.  
  68.    private void initFontSizes(int[] sizes) {
  69.       this.fontSizes = new Vector(sizes.length);
  70.  
  71.       for(int i = 0; i < sizes.length; ++i) {
  72.          this.fontSizes.add(new Integer(sizes[i]));
  73.       }
  74.  
  75.    }
  76.  
  77.    public void setSampleText(String s) {
  78.       this.sampleText = s;
  79.       this.previewTextPane.setText(this.sampleText);
  80.    }
  81.  
  82.    public void setCurrentFont(String name, String loc) {
  83.       this.fname = name;
  84.       this.floc = loc;
  85.       if (!loc.equals("System Font")) {
  86.          try {
  87.             Font chosenFont = Font.createFont(0, new FileInputStream(loc + File.separator + this.fname));
  88.             WeakReference wrf = new WeakReference(chosenFont);
  89.             this.fname = ((Font)wrf.get()).getName();
  90.          } catch (Exception var5) {
  91.             new JOptionPane();
  92.             JOptionPane.showMessageDialog(this, "Error loading font.", "Error!", 0);
  93.          }
  94.       }
  95.  
  96.       this.updateDisplay();
  97.    }
  98.  
  99.    public void setFavButtonAction(String action) {
  100.       this.addFavouritesButton.setText(action);
  101.    }
  102.  
  103.    private void updateDisplay() {
  104.       this.fontName.setText(this.fname);
  105.       this.fontName.setToolTipText(this.fname);
  106.       Style s = this.previewTextPane.getStyle("default");
  107.       StyleConstants.setFontFamily(s, this.fname);
  108.       StyleConstants.setFontSize(s, this.fsize);
  109.       StyleConstants.setBold(s, this.fontProperties[0]);
  110.       StyleConstants.setItalic(s, this.fontProperties[1]);
  111.       StyleConstants.setUnderline(s, this.fontProperties[2]);
  112.       this.previewTextPane.setParagraphAttributes(s, true);
  113.    }
  114.  
  115.    private void initComponents() {
  116.       this.previewTextPaneScollPane = new JScrollPane();
  117.       this.previewTextPane = new AATextPane();
  118.       this.topPanel = new JPanel();
  119.       this.optionsPanel = new JPanel();
  120.       this.fontPropertiesPanel = new JPanel();
  121.       this.boldButton = new JToggleButton();
  122.       this.italicsButton = new JToggleButton();
  123.       this.underlineButton = new JToggleButton();
  124.       this.addFavouritesButton = new JButton();
  125.       this.fontInfoPanel = new JPanel();
  126.       this.fontSizePanel = new JPanel();
  127.       this.fontSizeLabel = new JLabel();
  128.       this.fontSizeComboBox = new JComboBox(this.fontSizes);
  129.       this.fontName = new JLabel();
  130.       this.fontNameLabel = new JLabel();
  131.       this.setLayout(new BorderLayout(2, 2));
  132.       this.setBorder(new TitledBorder(" Sample Text "));
  133.       this.previewTextPaneScollPane.setBorder((Border)null);
  134.       this.previewTextPane.setBorder((Border)null);
  135.       this.previewTextPane.setEditable(false);
  136.       this.previewTextPane.setText(this.sampleText);
  137.       this.previewTextPaneScollPane.setViewportView(this.previewTextPane);
  138.       this.add(this.previewTextPaneScollPane, "Center");
  139.       this.topPanel.setLayout(new GridLayout(2, 0, 0, 2));
  140.       this.topPanel.setPreferredSize(new Dimension(10, 42));
  141.       this.optionsPanel.setLayout(new BorderLayout(2, 2));
  142.       this.optionsPanel.setPreferredSize(new Dimension(10, 24));
  143.       this.fontPropertiesPanel.setLayout(new GridLayout(1, 3, 2, 0));
  144.       this.fontPropertiesPanel.setPreferredSize(new Dimension(64, 20));
  145.       this.boldButton.setText("B");
  146.       this.boldButton.setToolTipText("Bold");
  147.       this.boldButton.setMargin(new Insets(2, 2, 2, 2));
  148.       this.boldButton.addActionListener(new 1(this));
  149.       this.fontPropertiesPanel.add(this.boldButton);
  150.       this.italicsButton.setFont(new Font("Dialog", 3, 12));
  151.       this.italicsButton.setText("I");
  152.       this.italicsButton.setToolTipText("Italic");
  153.       this.italicsButton.setMargin(new Insets(2, 2, 2, 2));
  154.       this.italicsButton.setPreferredSize(new Dimension(20, 20));
  155.       this.italicsButton.addActionListener(new 2(this));
  156.       this.fontPropertiesPanel.add(this.italicsButton);
  157.       this.underlineButton.setText("U");
  158.       this.underlineButton.setToolTipText("Underline");
  159.       this.underlineButton.setMargin(new Insets(2, 2, 2, 2));
  160.       this.underlineButton.setPreferredSize(new Dimension(20, 20));
  161.       this.underlineButton.addActionListener(new 3(this));
  162.       this.fontPropertiesPanel.add(this.underlineButton);
  163.       this.optionsPanel.add(this.fontPropertiesPanel, "West");
  164.       this.addFavouritesButton.setText("Add to Favourites");
  165.       this.addFavouritesButton.setMargin(new Insets(2, 2, 2, 2));
  166.       this.addFavouritesButton.setPreferredSize(new Dimension(130, 20));
  167.       this.addFavouritesButton.addActionListener(new 4(this));
  168.       this.optionsPanel.add(this.addFavouritesButton, "East");
  169.       this.topPanel.add(this.optionsPanel);
  170.       this.fontInfoPanel.setLayout(new BorderLayout(2, 2));
  171.       this.fontSizePanel.setLayout(new GridLayout(1, 2));
  172.       this.fontSizePanel.setPreferredSize(new Dimension(112, 24));
  173.       this.fontSizeLabel.setFont(new Font("Dialog", 0, 12));
  174.       this.fontSizeLabel.setHorizontalAlignment(4);
  175.       this.fontSizeLabel.setText("Font Size: ");
  176.       this.fontSizePanel.add(this.fontSizeLabel);
  177.       this.fontSizeComboBox.setFont(new Font("Dialog", 0, 12));
  178.       this.fontSizeComboBox.setPreferredSize(new Dimension(31, 24));
  179.       this.fontSizeComboBox.addItemListener(new 5(this));
  180.       this.fontSizePanel.add(this.fontSizeComboBox);
  181.       this.fontInfoPanel.add(this.fontSizePanel, "East");
  182.       this.fontName.setFont(new Font("Dialog", 0, 12));
  183.       this.fontName.setText("No font selected");
  184.       this.fontInfoPanel.add(this.fontName, "Center");
  185.       this.fontNameLabel.setFont(new Font("Dialog", 0, 12));
  186.       this.fontNameLabel.setText("Font Name: ");
  187.       this.fontInfoPanel.add(this.fontNameLabel, "West");
  188.       this.topPanel.add(this.fontInfoPanel);
  189.       this.add(this.topPanel, "North");
  190.    }
  191.  
  192.    private void fontSizeComboBoxItemStateChanged(ItemEvent evt) {
  193.       this.fsize = (Integer)this.fontSizes.get(this.fontSizeComboBox.getSelectedIndex());
  194.       this.updateDisplay();
  195.       this.field_0.setFontSize(this.fsize);
  196.    }
  197.  
  198.    private void underlineButtonActionPerformed(ActionEvent evt) {
  199.       this.fontProperties[2] = this.underlineButton.isSelected();
  200.       this.updateDisplay();
  201.    }
  202.  
  203.    private void italicsButtonActionPerformed(ActionEvent evt) {
  204.       this.fontProperties[1] = this.italicsButton.isSelected();
  205.       this.updateDisplay();
  206.    }
  207.  
  208.    private void boldButtonActionPerformed(ActionEvent evt) {
  209.       this.fontProperties[0] = this.boldButton.isSelected();
  210.       this.updateDisplay();
  211.    }
  212.  
  213.    private void addFavouritesButtonActionPerformed(ActionEvent evt) {
  214.       if (this.addFavouritesButton.getText().charAt(0) == 'A') {
  215.          this.field_0.addToFav();
  216.       } else {
  217.          this.field_0.removeFromFav();
  218.       }
  219.  
  220.    }
  221.  
  222.    private void exitForm(WindowEvent evt) {
  223.    }
  224.  
  225.    // $FF: synthetic method
  226.    static void access$000(SampleTextPanel x0, ActionEvent x1) {
  227.       x0.boldButtonActionPerformed(x1);
  228.    }
  229.  
  230.    // $FF: synthetic method
  231.    static void access$100(SampleTextPanel x0, ActionEvent x1) {
  232.       x0.italicsButtonActionPerformed(x1);
  233.    }
  234.  
  235.    // $FF: synthetic method
  236.    static void access$200(SampleTextPanel x0, ActionEvent x1) {
  237.       x0.underlineButtonActionPerformed(x1);
  238.    }
  239.  
  240.    // $FF: synthetic method
  241.    static void access$300(SampleTextPanel x0, ActionEvent x1) {
  242.       x0.addFavouritesButtonActionPerformed(x1);
  243.    }
  244.  
  245.    // $FF: synthetic method
  246.    static void access$400(SampleTextPanel x0, ItemEvent x1) {
  247.       x0.fontSizeComboBoxItemStateChanged(x1);
  248.    }
  249. }
  250.