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

  1. package FontViewer.components;
  2.  
  3. import FontViewer.windows.MainWindow;
  4. import java.awt.BorderLayout;
  5. import java.awt.event.KeyEvent;
  6. import java.awt.event.MouseEvent;
  7. import java.awt.event.WindowEvent;
  8. import java.util.Collections;
  9. import java.util.Vector;
  10. import javax.swing.JPanel;
  11. import javax.swing.JScrollPane;
  12. import javax.swing.JTable;
  13. import javax.swing.border.Border;
  14. import javax.swing.table.DefaultTableModel;
  15.  
  16. public class FavouriteFontsPanel extends JPanel implements ListPanel {
  17.    private final int NOT_FOUND = -1;
  18.    private final int COL_FONTNAME = 0;
  19.    private final int COL_FONTLOC = 1;
  20.    // $FF: renamed from: mw FontViewer.windows.MainWindow
  21.    private MainWindow field_0;
  22.    // $FF: renamed from: tm javax.swing.table.DefaultTableModel
  23.    private DefaultTableModel field_1;
  24.    private int sortCol;
  25.    private boolean sortAsend;
  26.    private JScrollPane favouritesScrollPane;
  27.    private JTable favouritesTable;
  28.  
  29.    public FavouriteFontsPanel(MainWindow mw) {
  30.       this.initComponents();
  31.       this.field_0 = mw;
  32.       this.field_1 = (DefaultTableModel)this.favouritesTable.getModel();
  33.       this.sortCol = 0;
  34.       this.sortAsend = true;
  35.       this.favouritesTable.setAutoCreateColumnsFromModel(false);
  36.    }
  37.  
  38.    public boolean addToFav(String name, String loc) {
  39.       boolean found = true;
  40.       if (this.getItemNumber(name, loc) == -1) {
  41.          found = false;
  42.          this.field_1.addRow(new Object[]{name, loc});
  43.       }
  44.  
  45.       return !found;
  46.    }
  47.  
  48.    public boolean removeFromFav(String name, String loc) {
  49.       boolean removed = false;
  50.       int p = this.getItemNumber(name, loc);
  51.       if (p != -1) {
  52.          this.field_1.removeRow(p);
  53.          removed = true;
  54.       }
  55.  
  56.       if (p >= this.field_1.getRowCount()) {
  57.          this.favouritesTable.changeSelection(this.field_1.getRowCount() - 1, 0, false, false);
  58.          this.setCurrentItem(this.field_1.getRowCount() - 1);
  59.       } else {
  60.          this.favouritesTable.changeSelection(p, 0, false, false);
  61.          this.setCurrentItem(p);
  62.       }
  63.  
  64.       this.field_0.updateDisplay();
  65.       return removed;
  66.    }
  67.  
  68.    public int getItemNumber(String name, String loc) {
  69.       int itemNum = -1;
  70.       Object[] data = this.field_1.getDataVector().toArray();
  71.       String font = "[" + name + ", " + loc + "]";
  72.  
  73.       for(int i = 0; i < data.length; ++i) {
  74.          if (data[i].toString().equals(font)) {
  75.             itemNum = i;
  76.             i += data.length;
  77.          }
  78.       }
  79.  
  80.       return itemNum;
  81.    }
  82.  
  83.    public String[] getItem(int itemNumber) {
  84.       String[] s = new String[3];
  85.       if (itemNumber >= 0 && itemNumber < this.field_1.getRowCount()) {
  86.          s[0] = this.field_1.getValueAt(itemNumber, 0).toString();
  87.          s[1] = this.field_1.getValueAt(itemNumber, 1).toString();
  88.          s[2] = itemNumber + "";
  89.       }
  90.  
  91.       return s;
  92.    }
  93.  
  94.    public int getNumItems() {
  95.       return this.field_1.getRowCount();
  96.    }
  97.  
  98.    public String[] getCurrentItem() {
  99.       int p = this.favouritesTable.getSelectedRow();
  100.       String[] s = this.getItem(p);
  101.       this.sortAllRowsBy(this.sortCol, this.sortAsend);
  102.       this.favouritesTable.changeSelection(this.getItemNumber(s[0], s[1]), 0, false, false);
  103.       return s;
  104.    }
  105.  
  106.    public int getCurrentItemNum() {
  107.       return this.favouritesTable.getSelectedRow();
  108.    }
  109.  
  110.    private void setCurrentItem(int p) {
  111.       String[] s = this.getCurrentItem();
  112.  
  113.       try {
  114.          if (p >= 0) {
  115.             this.field_0.setCurrentFont(s[0], s[1], Integer.parseInt(s[2]));
  116.          }
  117.       } catch (Exception var4) {
  118.       }
  119.  
  120.    }
  121.  
  122.    public void selectItem(String name, String loc) {
  123.       this.setCurrentItem(this.getItemNumber(name, loc));
  124.    }
  125.  
  126.    public void selectNext() {
  127.       int i = this.favouritesTable.getSelectedRow();
  128.       if (i >= 0) {
  129.          if (i + 1 < this.favouritesTable.getRowCount()) {
  130.             ++i;
  131.          }
  132.  
  133.          this.favouritesTable.changeSelection(i, 0, false, false);
  134.          this.setCurrentItem(i);
  135.       } else {
  136.          this.favouritesTable.changeSelection(0, 0, false, false);
  137.          this.setCurrentItem(0);
  138.       }
  139.  
  140.    }
  141.  
  142.    public void selectPrev() {
  143.       int i = this.favouritesTable.getSelectedRow();
  144.       if (i >= 0) {
  145.          if (i - 1 >= 0) {
  146.             --i;
  147.          }
  148.  
  149.          this.favouritesTable.changeSelection(i, 0, false, false);
  150.          this.setCurrentItem(i);
  151.       } else {
  152.          this.favouritesTable.changeSelection(0, 0, false, false);
  153.          this.setCurrentItem(0);
  154.       }
  155.  
  156.    }
  157.  
  158.    public void sortAllRowsBy(int colIndex, boolean ascending) {
  159.       Vector data = this.field_1.getDataVector();
  160.       Collections.sort(data, new ColumnSorter(this, colIndex, ascending));
  161.       this.field_1.fireTableStructureChanged();
  162.    }
  163.  
  164.    private void initComponents() {
  165.       this.favouritesScrollPane = new JScrollPane();
  166.       this.favouritesTable = new JTable();
  167.       this.setLayout(new BorderLayout());
  168.       this.favouritesScrollPane.setBorder((Border)null);
  169.       this.favouritesTable.setModel(new 1(this, new Object[0][], new String[]{"Font Name", "Location"}));
  170.       this.favouritesTable.setDoubleBuffered(true);
  171.       this.favouritesTable.addKeyListener(new 2(this));
  172.       this.favouritesTable.addMouseListener(new 3(this));
  173.       this.favouritesScrollPane.setViewportView(this.favouritesTable);
  174.       this.add(this.favouritesScrollPane, "Center");
  175.    }
  176.  
  177.    private void favouritesTableMouseClicked(MouseEvent evt) {
  178.       this.setCurrentItem(this.favouritesTable.getSelectedRow());
  179.    }
  180.  
  181.    private void favouritesTableKeyReleased(KeyEvent evt) {
  182.       this.setCurrentItem(this.favouritesTable.getSelectedRow());
  183.    }
  184.  
  185.    private void exitForm(WindowEvent evt) {
  186.    }
  187.  
  188.    // $FF: synthetic method
  189.    static void access$000(FavouriteFontsPanel x0, KeyEvent x1) {
  190.       x0.favouritesTableKeyReleased(x1);
  191.    }
  192.  
  193.    // $FF: synthetic method
  194.    static void access$100(FavouriteFontsPanel x0, MouseEvent x1) {
  195.       x0.favouritesTableMouseClicked(x1);
  196.    }
  197. }
  198.