home *** CD-ROM | disk | FTP | other *** search
- package FontViewer.components;
-
- import FontViewer.windows.MainWindow;
- import java.awt.BorderLayout;
- import java.awt.event.KeyEvent;
- import java.awt.event.MouseEvent;
- import java.awt.event.WindowEvent;
- import java.util.Collections;
- import java.util.Vector;
- import javax.swing.JPanel;
- import javax.swing.JScrollPane;
- import javax.swing.JTable;
- import javax.swing.border.Border;
- import javax.swing.table.DefaultTableModel;
-
- public class FavouriteFontsPanel extends JPanel implements ListPanel {
- private final int NOT_FOUND = -1;
- private final int COL_FONTNAME = 0;
- private final int COL_FONTLOC = 1;
- // $FF: renamed from: mw FontViewer.windows.MainWindow
- private MainWindow field_0;
- // $FF: renamed from: tm javax.swing.table.DefaultTableModel
- private DefaultTableModel field_1;
- private int sortCol;
- private boolean sortAsend;
- private JScrollPane favouritesScrollPane;
- private JTable favouritesTable;
-
- public FavouriteFontsPanel(MainWindow mw) {
- this.initComponents();
- this.field_0 = mw;
- this.field_1 = (DefaultTableModel)this.favouritesTable.getModel();
- this.sortCol = 0;
- this.sortAsend = true;
- this.favouritesTable.setAutoCreateColumnsFromModel(false);
- }
-
- public boolean addToFav(String name, String loc) {
- boolean found = true;
- if (this.getItemNumber(name, loc) == -1) {
- found = false;
- this.field_1.addRow(new Object[]{name, loc});
- }
-
- return !found;
- }
-
- public boolean removeFromFav(String name, String loc) {
- boolean removed = false;
- int p = this.getItemNumber(name, loc);
- if (p != -1) {
- this.field_1.removeRow(p);
- removed = true;
- }
-
- if (p >= this.field_1.getRowCount()) {
- this.favouritesTable.changeSelection(this.field_1.getRowCount() - 1, 0, false, false);
- this.setCurrentItem(this.field_1.getRowCount() - 1);
- } else {
- this.favouritesTable.changeSelection(p, 0, false, false);
- this.setCurrentItem(p);
- }
-
- this.field_0.updateDisplay();
- return removed;
- }
-
- public int getItemNumber(String name, String loc) {
- int itemNum = -1;
- Object[] data = this.field_1.getDataVector().toArray();
- String font = "[" + name + ", " + loc + "]";
-
- for(int i = 0; i < data.length; ++i) {
- if (data[i].toString().equals(font)) {
- itemNum = i;
- i += data.length;
- }
- }
-
- return itemNum;
- }
-
- public String[] getItem(int itemNumber) {
- String[] s = new String[3];
- if (itemNumber >= 0 && itemNumber < this.field_1.getRowCount()) {
- s[0] = this.field_1.getValueAt(itemNumber, 0).toString();
- s[1] = this.field_1.getValueAt(itemNumber, 1).toString();
- s[2] = itemNumber + "";
- }
-
- return s;
- }
-
- public int getNumItems() {
- return this.field_1.getRowCount();
- }
-
- public String[] getCurrentItem() {
- int p = this.favouritesTable.getSelectedRow();
- String[] s = this.getItem(p);
- this.sortAllRowsBy(this.sortCol, this.sortAsend);
- this.favouritesTable.changeSelection(this.getItemNumber(s[0], s[1]), 0, false, false);
- return s;
- }
-
- public int getCurrentItemNum() {
- return this.favouritesTable.getSelectedRow();
- }
-
- private void setCurrentItem(int p) {
- String[] s = this.getCurrentItem();
-
- try {
- if (p >= 0) {
- this.field_0.setCurrentFont(s[0], s[1], Integer.parseInt(s[2]));
- }
- } catch (Exception var4) {
- }
-
- }
-
- public void selectItem(String name, String loc) {
- this.setCurrentItem(this.getItemNumber(name, loc));
- }
-
- public void selectNext() {
- int i = this.favouritesTable.getSelectedRow();
- if (i >= 0) {
- if (i + 1 < this.favouritesTable.getRowCount()) {
- ++i;
- }
-
- this.favouritesTable.changeSelection(i, 0, false, false);
- this.setCurrentItem(i);
- } else {
- this.favouritesTable.changeSelection(0, 0, false, false);
- this.setCurrentItem(0);
- }
-
- }
-
- public void selectPrev() {
- int i = this.favouritesTable.getSelectedRow();
- if (i >= 0) {
- if (i - 1 >= 0) {
- --i;
- }
-
- this.favouritesTable.changeSelection(i, 0, false, false);
- this.setCurrentItem(i);
- } else {
- this.favouritesTable.changeSelection(0, 0, false, false);
- this.setCurrentItem(0);
- }
-
- }
-
- public void sortAllRowsBy(int colIndex, boolean ascending) {
- Vector data = this.field_1.getDataVector();
- Collections.sort(data, new ColumnSorter(this, colIndex, ascending));
- this.field_1.fireTableStructureChanged();
- }
-
- private void initComponents() {
- this.favouritesScrollPane = new JScrollPane();
- this.favouritesTable = new JTable();
- this.setLayout(new BorderLayout());
- this.favouritesScrollPane.setBorder((Border)null);
- this.favouritesTable.setModel(new 1(this, new Object[0][], new String[]{"Font Name", "Location"}));
- this.favouritesTable.setDoubleBuffered(true);
- this.favouritesTable.addKeyListener(new 2(this));
- this.favouritesTable.addMouseListener(new 3(this));
- this.favouritesScrollPane.setViewportView(this.favouritesTable);
- this.add(this.favouritesScrollPane, "Center");
- }
-
- private void favouritesTableMouseClicked(MouseEvent evt) {
- this.setCurrentItem(this.favouritesTable.getSelectedRow());
- }
-
- private void favouritesTableKeyReleased(KeyEvent evt) {
- this.setCurrentItem(this.favouritesTable.getSelectedRow());
- }
-
- private void exitForm(WindowEvent evt) {
- }
-
- // $FF: synthetic method
- static void access$000(FavouriteFontsPanel x0, KeyEvent x1) {
- x0.favouritesTableKeyReleased(x1);
- }
-
- // $FF: synthetic method
- static void access$100(FavouriteFontsPanel x0, MouseEvent x1) {
- x0.favouritesTableMouseClicked(x1);
- }
- }
-