public static void main(String[] args) throws Exception { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); final JFrame f = new JFrame(); f.setLayout(new BorderLayout()); try { System.out.println(UserManager.instance().login("Scott", "test")); // FinanceManager.instance().getAccountManager().retrieve(); FinanceManager.instance().getJournalManager().createJournal("General Journal"); FinanceManager.instance().getAccountManager().importAccts("TestAccts.xml"); FinanceManager.instance().turnOffInitializationPhase(); JournalEntry je = new JournalEntry("Test", null); Account cash = FinanceManager.instance().getAccountManager().getAccount("Cash"); Account a_r = FinanceManager.instance().getAccountManager().getAccount("Accounts Receivable"); je.addLineItem( new JournalEntryLineItem( cash, new AcctAmount(22, TransactionType.DEBIT), "test", cash.getAllCategories().toArray(new AcctActionCategory[0])[0])); je.addLineItem( new JournalEntryLineItem(a_r, new AcctAmount(22, TransactionType.CREDIT), "test", null)); JournalEntryPanel jep = new JournalEntryPanel(je); f.add(jep); } catch (Exception e) { e.printStackTrace(); UserManager.instance().logout(); } f.pack(); f.setVisible(true); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); }
/** * This panel will handle the GUI interactions for JournalEntry objects. If <code>je</code> is not * null it will be displayed, and if possible it will be editable. If <code>je</code> is null then * a new JournalEntry object can be created and registered with the financial engine. * * @param je */ public JournalEntryPanel(JournalEntry je) { super(JSplitPane.VERTICAL_SPLIT); this.setPreferredSize(new Dimension(500, -1)); occurred_ = new DateField(null); description_ = new JTextField(); this.listeners_ = new ArrayList<SaveListener<JournalEntry>>(); JButton add_entry = new JButton("Add Entry"); add_entry.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { updateDescriptionPanel(null); } }); JButton del_entry = new JButton("Remove Entry"); del_entry.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { int row = entry_table_.getSelectedRow(); JournalEntryTableModel m = (JournalEntryTableModel) entry_table_.getModel(); m.removeLineItem(row); } }); journals_combo_ = new JComboBox(); try { Collection<Journal> journals = FinanceManager.instance().getJournalManager().getJournals().values(); for (Journal j : journals) { journals_combo_.addItem(j); } } catch (DatabaseException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } catch (SQLException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } JButton save_to_journal = new JButton("Save to Journal"); save_to_journal.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { JournalEntryTableModel m = (JournalEntryTableModel) entry_table_.getModel(); JournalEntry je = m.getJournalEntry(); je.setDescription(description_.getText()); je.setOccurredTime(occurred_.getDate()); if (je.getLineItems().size() > 0) { Journal selected_journal = (Journal) journals_combo_.getSelectedItem(); if (selected_journal != null) { try { Integer journal_key = FinanceManager.instance() .getJournalManager() .addJournalEntry(selected_journal, je); System.out.println("Entry id in journal: " + journal_key); if (journal_key != null) { makeGUIReadOnly(); fireJournalEntrySave(je); } } catch (FinanceException e1) { // TODO Auto-generated catch block JOptionPane.showMessageDialog(JournalEntryPanel.this, e1.getMessage()); e1.printStackTrace(); } catch (DatabaseException e1) { // TODO Auto-generated catch block JOptionPane.showMessageDialog(JournalEntryPanel.this, e1.getMessage()); e1.printStackTrace(); } catch (SQLException e1) { // TODO Auto-generated catch block JOptionPane.showMessageDialog(JournalEntryPanel.this, e1.getMessage()); e1.printStackTrace(); } } } } }); options_ = new JPanel(); options_.setLayout(new FlowLayout(FlowLayout.LEFT)); options_.add(add_entry); options_.add(del_entry); options_.add(new JLabel("Journal")); options_.add(journals_combo_); options_.add(save_to_journal); JournalEntryTableModel m = (je == null) ? new JournalEntryTableModel() : new JournalEntryTableModel(je); entry_table_ = new JournalEntryTable(m); if (this.isReadOnly()) { this.makeGUIReadOnly(); } entry_table_ .getSelectionModel() .addListSelectionListener( new ListSelectionListener() { public void valueChanged(ListSelectionEvent e) { if (e.getValueIsAdjusting()) { return; } int row = entry_table_.getSelectedRow(); JournalEntryTableModel m = (JournalEntryTableModel) entry_table_.getModel(); updateDescriptionPanel(m.getLineItem(row)); } }); entry_table_.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); entry_table_.setPreferredSize(new Dimension(-1, 400)); entry_table_.setAutoCreateRowSorter(true); entry_table_.setRowHeight(25); JScrollPane entry_view = new JScrollPane( entry_table_, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); JPanel entry_details = new JPanel(); description_.setPreferredSize(new Dimension(300, 20)); if (je != null) { occurred_.setDate(je.getOccurredTime()); description_.setText(je.getDescription()); } entry_details.setLayout(new FlowLayout(FlowLayout.LEFT)); entry_details.add(new JLabel("Occurred")); entry_details.add(occurred_); entry_details.add(new JLabel("Description")); entry_details.add(description_); JPanel top_wrap = new JPanel(new BorderLayout()); top_wrap.add(options_, BorderLayout.NORTH); top_wrap.add(entry_details, BorderLayout.SOUTH); JPanel wrap = new JPanel(new BorderLayout()); wrap.add(top_wrap, BorderLayout.NORTH); wrap.add(entry_view, BorderLayout.CENTER); this.setTopComponent(wrap); this.setDefaultBottom(); }