Now it's time to write some code. You'll create a
BasicEventList
and populate it with issues. Next,
create an EventListModel
and a corresponding
JList
. Finally you can place it all in a
JFrame
and show that on screen.
import java.util.*; import java.io.*; import javax.swing.*; import java.awt.GridBagLayout; import java.awt.GridBagConstraints; import java.awt.Insets; // a simple issues library import ca.odell.issuezilla.*; // glazed lists import ca.odell.glazedlists.*; import ca.odell.glazedlists.swing.*; /** * An IssueBrowser is a program for finding and viewing issues. * * @author <href="mailto:jesse@odel.on.ca">Jesse Wilson</a> */ public class IssuesBrowser { /** event list that hosts the issues */ private EventList issuesEventList = new BasicEventList(); /** * Create an IssueBrowser for the specified issues. */ public IssuesBrowser(Collection issues) { issuesEventList.addAll(issues); } /** * Display a frame for browsing issues. */ public void display() { // create a panel with a table JPanel panel = new JPanel(); panel.setLayout(new GridBagLayout()); EventListModel issuesListModel = new EventListModel(issuesEventList); JList issuesJList = new JList(issuesListModel); JScrollPane issuesListScrollPane = new JScrollPane(issuesJList); panel.add(issuesListScrollPane, new GridBagConstraints(...)); // create a frame with that panel JFrame frame = new JFrame("Issues"); frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); frame.setSize(540, 380); frame.getContentPane().add(panel); frame.show(); } /** * Launch the IssuesBrowser from the commandline. */ public static void main(String[] args) { if(args.length != 1) { System.out.println("Usage: IssuesBrowser <file>"); return; } // load some issues Collection issues = null; try { IssuezillaXMLParser parser = new IssuezillaXMLParser(); InputStream issuesInStream = new FileInputStream(args[0]); issues = parser.loadIssues(issuesInStream, null); issuesInStream.close(); } catch(IOException e) { e.printStackTrace(); return; } // create the browser IssuesBrowser browser = new IssuesBrowser(issues); browser.display(); } }