home *** CD-ROM | disk | FTP | other *** search
- package FontViewer.components;
-
- import FontViewer.windows.MainWindow;
- import java.awt.BorderLayout;
- import java.awt.Dimension;
- import java.awt.Font;
- import java.awt.GridLayout;
- import java.awt.Insets;
- import java.awt.event.ActionEvent;
- import java.awt.event.ItemEvent;
- import java.awt.event.WindowEvent;
- import java.io.File;
- import java.io.FileInputStream;
- import java.lang.ref.WeakReference;
- import java.util.ResourceBundle;
- import java.util.Vector;
- import javax.swing.JButton;
- import javax.swing.JComboBox;
- import javax.swing.JLabel;
- import javax.swing.JOptionPane;
- import javax.swing.JPanel;
- import javax.swing.JScrollPane;
- import javax.swing.JTextPane;
- import javax.swing.JToggleButton;
- import javax.swing.border.Border;
- import javax.swing.border.TitledBorder;
- import javax.swing.text.Style;
- import javax.swing.text.StyleConstants;
-
- public class SampleTextPanel extends JPanel {
- private final int BOLD = 0;
- private final int ITALIC = 1;
- private final int UNDERLINE = 2;
- private Vector fontSizes;
- private String sampleText;
- private String fname;
- private String floc;
- private int fsize;
- private boolean[] fontProperties = new boolean[]{false, false, false};
- // $FF: renamed from: mw FontViewer.windows.MainWindow
- private MainWindow field_0;
- private JButton addFavouritesButton;
- private JToggleButton boldButton;
- private JPanel fontInfoPanel;
- private JLabel fontName;
- private JLabel fontNameLabel;
- private JPanel fontPropertiesPanel;
- private JComboBox fontSizeComboBox;
- private JLabel fontSizeLabel;
- private JPanel fontSizePanel;
- private JToggleButton italicsButton;
- private JPanel optionsPanel;
- private JTextPane previewTextPane;
- private JScrollPane previewTextPaneScollPane;
- private JPanel topPanel;
- private JToggleButton underlineButton;
-
- public SampleTextPanel(MainWindow mw, int[] sizes) {
- this.field_0 = mw;
- this.sampleText = ResourceBundle.getBundle("FontViewer.resources.Opcion").getString("defaultSampleText");
- this.initFontSizes(sizes);
- this.initComponents();
- this.fname = "Default";
- this.floc = "System Font";
- this.fontSizeComboBox.setSelectedItem(this.fontSizes.get(9));
- }
-
- private void initFontSizes(int[] sizes) {
- this.fontSizes = new Vector(sizes.length);
-
- for(int i = 0; i < sizes.length; ++i) {
- this.fontSizes.add(new Integer(sizes[i]));
- }
-
- }
-
- public void setSampleText(String s) {
- this.sampleText = s;
- this.previewTextPane.setText(this.sampleText);
- }
-
- public void setCurrentFont(String name, String loc) {
- this.fname = name;
- this.floc = loc;
- if (!loc.equals("System Font")) {
- try {
- Font chosenFont = Font.createFont(0, new FileInputStream(loc + File.separator + this.fname));
- WeakReference wrf = new WeakReference(chosenFont);
- this.fname = ((Font)wrf.get()).getName();
- } catch (Exception var5) {
- new JOptionPane();
- JOptionPane.showMessageDialog(this, "Error loading font.", "Error!", 0);
- }
- }
-
- this.updateDisplay();
- }
-
- public void setFavButtonAction(String action) {
- this.addFavouritesButton.setText(action);
- }
-
- private void updateDisplay() {
- this.fontName.setText(this.fname);
- this.fontName.setToolTipText(this.fname);
- Style s = this.previewTextPane.getStyle("default");
- StyleConstants.setFontFamily(s, this.fname);
- StyleConstants.setFontSize(s, this.fsize);
- StyleConstants.setBold(s, this.fontProperties[0]);
- StyleConstants.setItalic(s, this.fontProperties[1]);
- StyleConstants.setUnderline(s, this.fontProperties[2]);
- this.previewTextPane.setParagraphAttributes(s, true);
- }
-
- private void initComponents() {
- this.previewTextPaneScollPane = new JScrollPane();
- this.previewTextPane = new AATextPane();
- this.topPanel = new JPanel();
- this.optionsPanel = new JPanel();
- this.fontPropertiesPanel = new JPanel();
- this.boldButton = new JToggleButton();
- this.italicsButton = new JToggleButton();
- this.underlineButton = new JToggleButton();
- this.addFavouritesButton = new JButton();
- this.fontInfoPanel = new JPanel();
- this.fontSizePanel = new JPanel();
- this.fontSizeLabel = new JLabel();
- this.fontSizeComboBox = new JComboBox(this.fontSizes);
- this.fontName = new JLabel();
- this.fontNameLabel = new JLabel();
- this.setLayout(new BorderLayout(2, 2));
- this.setBorder(new TitledBorder(" Sample Text "));
- this.previewTextPaneScollPane.setBorder((Border)null);
- this.previewTextPane.setBorder((Border)null);
- this.previewTextPane.setEditable(false);
- this.previewTextPane.setText(this.sampleText);
- this.previewTextPaneScollPane.setViewportView(this.previewTextPane);
- this.add(this.previewTextPaneScollPane, "Center");
- this.topPanel.setLayout(new GridLayout(2, 0, 0, 2));
- this.topPanel.setPreferredSize(new Dimension(10, 42));
- this.optionsPanel.setLayout(new BorderLayout(2, 2));
- this.optionsPanel.setPreferredSize(new Dimension(10, 24));
- this.fontPropertiesPanel.setLayout(new GridLayout(1, 3, 2, 0));
- this.fontPropertiesPanel.setPreferredSize(new Dimension(64, 20));
- this.boldButton.setText("B");
- this.boldButton.setToolTipText("Bold");
- this.boldButton.setMargin(new Insets(2, 2, 2, 2));
- this.boldButton.addActionListener(new 1(this));
- this.fontPropertiesPanel.add(this.boldButton);
- this.italicsButton.setFont(new Font("Dialog", 3, 12));
- this.italicsButton.setText("I");
- this.italicsButton.setToolTipText("Italic");
- this.italicsButton.setMargin(new Insets(2, 2, 2, 2));
- this.italicsButton.setPreferredSize(new Dimension(20, 20));
- this.italicsButton.addActionListener(new 2(this));
- this.fontPropertiesPanel.add(this.italicsButton);
- this.underlineButton.setText("U");
- this.underlineButton.setToolTipText("Underline");
- this.underlineButton.setMargin(new Insets(2, 2, 2, 2));
- this.underlineButton.setPreferredSize(new Dimension(20, 20));
- this.underlineButton.addActionListener(new 3(this));
- this.fontPropertiesPanel.add(this.underlineButton);
- this.optionsPanel.add(this.fontPropertiesPanel, "West");
- this.addFavouritesButton.setText("Add to Favourites");
- this.addFavouritesButton.setMargin(new Insets(2, 2, 2, 2));
- this.addFavouritesButton.setPreferredSize(new Dimension(130, 20));
- this.addFavouritesButton.addActionListener(new 4(this));
- this.optionsPanel.add(this.addFavouritesButton, "East");
- this.topPanel.add(this.optionsPanel);
- this.fontInfoPanel.setLayout(new BorderLayout(2, 2));
- this.fontSizePanel.setLayout(new GridLayout(1, 2));
- this.fontSizePanel.setPreferredSize(new Dimension(112, 24));
- this.fontSizeLabel.setFont(new Font("Dialog", 0, 12));
- this.fontSizeLabel.setHorizontalAlignment(4);
- this.fontSizeLabel.setText("Font Size: ");
- this.fontSizePanel.add(this.fontSizeLabel);
- this.fontSizeComboBox.setFont(new Font("Dialog", 0, 12));
- this.fontSizeComboBox.setPreferredSize(new Dimension(31, 24));
- this.fontSizeComboBox.addItemListener(new 5(this));
- this.fontSizePanel.add(this.fontSizeComboBox);
- this.fontInfoPanel.add(this.fontSizePanel, "East");
- this.fontName.setFont(new Font("Dialog", 0, 12));
- this.fontName.setText("No font selected");
- this.fontInfoPanel.add(this.fontName, "Center");
- this.fontNameLabel.setFont(new Font("Dialog", 0, 12));
- this.fontNameLabel.setText("Font Name: ");
- this.fontInfoPanel.add(this.fontNameLabel, "West");
- this.topPanel.add(this.fontInfoPanel);
- this.add(this.topPanel, "North");
- }
-
- private void fontSizeComboBoxItemStateChanged(ItemEvent evt) {
- this.fsize = (Integer)this.fontSizes.get(this.fontSizeComboBox.getSelectedIndex());
- this.updateDisplay();
- this.field_0.setFontSize(this.fsize);
- }
-
- private void underlineButtonActionPerformed(ActionEvent evt) {
- this.fontProperties[2] = this.underlineButton.isSelected();
- this.updateDisplay();
- }
-
- private void italicsButtonActionPerformed(ActionEvent evt) {
- this.fontProperties[1] = this.italicsButton.isSelected();
- this.updateDisplay();
- }
-
- private void boldButtonActionPerformed(ActionEvent evt) {
- this.fontProperties[0] = this.boldButton.isSelected();
- this.updateDisplay();
- }
-
- private void addFavouritesButtonActionPerformed(ActionEvent evt) {
- if (this.addFavouritesButton.getText().charAt(0) == 'A') {
- this.field_0.addToFav();
- } else {
- this.field_0.removeFromFav();
- }
-
- }
-
- private void exitForm(WindowEvent evt) {
- }
-
- // $FF: synthetic method
- static void access$000(SampleTextPanel x0, ActionEvent x1) {
- x0.boldButtonActionPerformed(x1);
- }
-
- // $FF: synthetic method
- static void access$100(SampleTextPanel x0, ActionEvent x1) {
- x0.italicsButtonActionPerformed(x1);
- }
-
- // $FF: synthetic method
- static void access$200(SampleTextPanel x0, ActionEvent x1) {
- x0.underlineButtonActionPerformed(x1);
- }
-
- // $FF: synthetic method
- static void access$300(SampleTextPanel x0, ActionEvent x1) {
- x0.addFavouritesButtonActionPerformed(x1);
- }
-
- // $FF: synthetic method
- static void access$400(SampleTextPanel x0, ItemEvent x1) {
- x0.fontSizeComboBoxItemStateChanged(x1);
- }
- }
-