1
2
3
4 package com.webstersmalley.mediacollection.ui;
5
6 import java.awt.event.ActionEvent;
7 import java.io.File;
8
9 import javax.swing.AbstractAction;
10 import javax.swing.Action;
11 import javax.swing.JFrame;
12 import javax.swing.JLabel;
13 import javax.swing.JTable;
14
15 import org.apache.log4j.Logger;
16 import org.apache.log4j.PropertyConfigurator;
17 import org.swixml.SwingEngine;
18
19 import ca.odell.glazedlists.BasicEventList;
20 import ca.odell.glazedlists.EventList;
21 import ca.odell.glazedlists.SortedList;
22 import ca.odell.glazedlists.swing.EventTableModel;
23 import ca.odell.glazedlists.swing.TableComparatorChooser;
24
25 import com.webstersmalley.mediacollection.controller.BrowserController;
26 import com.webstersmalley.mediacollection.model.SimpleMediaCollectionBeanComparator;
27 import com.webstersmalley.mediacollection.model.SimpleMediaCollectionTableFormat;
28 import com.webstersmalley.ui.SwiXMLFrame;
29
30 /**
31 */
32 public class BrowserFrame
33 {
34 private static Logger log = Logger.getLogger(BrowserFrame.class);
35 static
36 {
37 PropertyConfigurator.configure("log4j.properties");
38 }
39
40 public JTable mediatable;
41 public JFrame browserFrame;
42 public JLabel statusLabel;
43 private boolean initialised = false;
44
45 private void setInitialised() {
46 this.initialised = true;
47 }
48
49 public Action exitAction = new AbstractAction()
50 {
51 public void actionPerformed(ActionEvent e)
52 {
53 System.out.println("Exit");
54 System.exit(0);
55 }
56 };
57
58 public Action newAction = new AbstractAction()
59 {
60 public void actionPerformed(ActionEvent e)
61 {
62 try
63 {
64 if (initialised) {
65 controller.newDatabase();
66 }
67 }
68 catch (Exception ex)
69 {
70 log.error("Error creating new database", ex);
71 }
72 }
73 };
74
75 public Action openAction = new AbstractAction()
76 {
77 public void actionPerformed(ActionEvent e)
78 {
79 try
80 {
81 if (initialised) {
82 controller.openDatabase();
83 }
84 }
85 catch (Exception ex)
86 {
87 log.error("Error creating new database", ex);
88 }
89 }
90 };
91
92 public Action aboutAction = new AbstractAction()
93 {
94 public void actionPerformed(ActionEvent e)
95 {
96 SwiXMLFrame aboutFrame = new SwiXMLFrame("com.webstersmalley.mediacollection.ui.AboutFrame.xml");
97 System.out.println("About");
98 }
99 };
100
101 public Action importAction = new AbstractAction()
102 {
103 public void actionPerformed(ActionEvent e)
104 {
105 try
106 {
107 controller.importFileSystem();
108 }
109 catch (Exception ex)
110 {
111 log.error("Error parsing", ex);
112 }
113 }
114 };
115
116
117 private BrowserController controller;
118
119 private EventList list = new BasicEventList();
120
121 public EventList getEventList()
122 {
123 return list;
124 }
125
126 public BrowserFrame()
127 {
128 String filename = this.getClass().getName() + ".xml";
129 File uiFile = new File("xml" + File.separator + filename);
130
131 try
132 {
133 log.debug("Launching " + filename + " UI");
134 new SwingEngine(this).render(uiFile).setVisible(true);
135 log.debug("Launched");
136 }
137 catch (Exception e)
138 {
139 log.error("Error launching UI", e);
140 }
141
142 SortedList sortedList = new SortedList(list, new SimpleMediaCollectionBeanComparator(true, 0));
143 EventTableModel model = new EventTableModel(sortedList, new SimpleMediaCollectionTableFormat());
144 mediatable.setModel(model);
145 log.debug("Getting sorter");
146 TableComparatorChooser tableSorter = new TableComparatorChooser(mediatable, sortedList, true);
147 log.debug("done");
148 controller = new BrowserController(this, list);
149 this.setInitialised();
150 }
151
152 public void showMessage(String message)
153 {
154 statusLabel.setText(message);
155 }
156
157 public JFrame getJFrame()
158 {
159 return browserFrame;
160 }
161 }