001 /*****************************************************************************
002
003 jBudget.
004 Copyright (C) Dmitri Petrov
005
006 This program is free software: you can redistribute it and/or modify
007 it under the terms of the GNU General Public License as published by
008 the Free Software Foundation, either version 3 of the License, or
009 (at your option) any later version.
010
011 This program is distributed in the hope that it will be useful,
012 but WITHOUT ANY WARRANTY; without even the implied warranty of
013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
014 GNU General Public License for more details.
015
016 You should have received a copy of the GNU General Public License
017 along with this program. If not, see <http://www.gnu.org/licenses/>.
018
019 *****************************************************************************/
020
021 package org.jbudget.gui;
022
023 import java.awt.AWTEvent;
024 import java.awt.BorderLayout;
025 import java.awt.Toolkit;
026 import java.util.ArrayList;
027 import java.util.Calendar;
028 import java.util.GregorianCalendar;
029 import java.util.LinkedList;
030 import java.util.List;
031 import javax.swing.ButtonGroup;
032 import javax.swing.JCheckBoxMenuItem;
033 import javax.swing.JComponent;
034 import javax.swing.JFrame;
035 import javax.swing.JMenu;
036 import javax.swing.JMenuBar;
037 import javax.swing.JMenuItem;
038 import javax.swing.JRadioButtonMenuItem;
039 import javax.swing.JSeparator;
040 import javax.swing.JTabbedPane;
041 import javax.swing.KeyStroke;
042 import org.jbudget.Core.Month;
043 import org.jbudget.gui.components.CombinedTabbedPane;
044 import org.jbudget.gui.month.DatesInfoTable;
045 import org.jbudget.gui.month.DatesInfoTableModel;
046 import org.jbudget.gui.month.ReportPanel;
047 import org.jbudget.gui.trans.AllocationListPanel;
048 import org.jbudget.gui.trans.TransactionFilterPanel;
049 import org.jbudget.gui.trans.TransactionListPanel;
050 import org.jbudget.gui.trans.TransactionSorterPanel;
051 import org.jbudget.Core.TransactionFilter;
052
053 /**
054 * This is a base class for the MainWindow class. Here the GUI components
055 * contained in the main window are assembled in a signal frame. Mostly this
056 * class is responsible for handing the transaction/allocation list components.
057 *
058 * @author petrov
059 */
060 public class MainWindowBase extends JFrame
061 {
062 //============================== DATA ===============================//
063
064 /** Main data window */
065 protected final JTabbedPane dataPane =
066 new JTabbedPane(JTabbedPane.BOTTOM, JTabbedPane.SCROLL_TAB_LAYOUT);
067
068 /** A list of displayed months */
069 protected final List<Month> displayedMonths = new LinkedList<Month>();
070
071 /** A calendar used for time tracking */
072 protected final Calendar calendar = new GregorianCalendar();
073
074 /** An object that describes what columns are shown in month panels. */
075 protected DatesInfoTableModel.State tableState =
076 new DatesInfoTableModel.State();
077
078 /** An object that controlls the rendering of the accunt/expense category
079 * table.
080 */
081 protected DatesInfoTable.RenderingState renderingState =
082 new DatesInfoTable.RenderingState();
083
084 /** An object that is used to store the colors used to represent accounts
085 * and expense categories.
086 */
087 protected DatesInfoTable.Colors colors = new DatesInfoTable.Colors();
088
089 /** List of Transactions (created on demand)*/
090 private final TransactionListPanel transactionsPanel =
091 new TransactionListPanel();
092
093 /** List of Allocations (created on demand)*/
094 private final AllocationListPanel allocationsPanel =
095 new AllocationListPanel();
096
097 /** Report panel. */
098 private final ReportPanel reportPanel = new ReportPanel();
099
100 /** A panel that is used to edit the filter. */
101 private final TransactionFilterPanel filterPanel =
102 new TransactionFilterPanel(new TransactionFilter());
103
104 /** GUI component that is used to change the sorting of the transactions
105 * and allocations in corresponding lists. */
106 private final TransactionSorterPanel sorterPanel =
107 new TransactionSorterPanel();
108
109
110 //============================================================================
111 //
112 // Constructing menu components.
113 //
114 //============================================================================
115
116 /** Main menu bar */
117 protected final JMenuBar menuBar = new JMenuBar();
118
119 //===== FILE MENU ====//
120
121 protected final JMenu fileMenu = new JMenu("File");
122 protected final JMenuItem openMonthBtn = new JMenuItem("Open Month");
123 protected final JMenuItem addMonthBtn = new JMenuItem("Add Month");
124 protected final JMenuItem saveAllBtn = new JMenuItem("Save All");
125 protected final JMenuItem closeAllBtn = new JMenuItem("Close All");
126 protected final JMenuItem exitBtn = new JMenuItem("Exit");
127
128 //===== VIEW MENU =======//
129
130 protected final JMenu viewMenu = new JMenu("View");
131 protected final JCheckBoxMenuItem collapseAccountsBtn =
132 new JCheckBoxMenuItem("Collapse Accounts");
133 protected final JCheckBoxMenuItem collapseCategoriesBtn =
134 new JCheckBoxMenuItem("Collapse Expneses");
135 protected final JCheckBoxMenuItem hideSubcategoriesBtn =
136 new JCheckBoxMenuItem("Hide Subcategories");
137 protected final JMenu hideMenu = new JMenu("Hide");
138 protected final JCheckBoxMenuItem hideEmptyAccountsBtn =
139 new JCheckBoxMenuItem("Empty Accounts");
140 protected final JCheckBoxMenuItem hideIdleAccountsBtn =
141 new JCheckBoxMenuItem("Idle Accounts");
142 protected final JCheckBoxMenuItem hideEmptyCategoriesBtn =
143 new JCheckBoxMenuItem("Empty Categories");
144 protected final JCheckBoxMenuItem hideIdleCategoriesBtn =
145 new JCheckBoxMenuItem("Idle Categories");
146 protected final JMenu renderersMenu = new JMenu("Renderer");
147 protected final JRadioButtonMenuItem detailedRendererBtn =
148 new JRadioButtonMenuItem("Detailed");
149 protected final JRadioButtonMenuItem activityRendererBtn =
150 new JRadioButtonMenuItem("Activity");
151 protected final JRadioButtonMenuItem balanceRendererBtn =
152 new JRadioButtonMenuItem("Balance");
153 protected final JRadioButtonMenuItem actAndBalRendererBtn =
154 new JRadioButtonMenuItem("Act. & Balance");
155 protected final JMenu backgroundMenu = new JMenu("Background");
156 protected final JRadioButtonMenuItem plainBackgrBtn =
157 new JRadioButtonMenuItem("Plain");
158 protected final JRadioButtonMenuItem stripedBackgrBtn =
159 new JRadioButtonMenuItem("Stripes");
160 protected final JRadioButtonMenuItem fullStructureBackgrBtn =
161 new JRadioButtonMenuItem("Structure: Full");
162 protected final JRadioButtonMenuItem simpleStructureBackgrBtn =
163 new JRadioButtonMenuItem("Structure: Simple");
164 protected final JRadioButtonMenuItem noStructureBackgrBtn =
165 new JRadioButtonMenuItem("Structure: Off");
166 protected final JMenu highlightMenu = new JMenu("Highlighting");
167 protected final JRadioButtonMenuItem highltOffBtn =
168 new JRadioButtonMenuItem("Off");
169 protected final JRadioButtonMenuItem highltUnderlBtn =
170 new JRadioButtonMenuItem("Underline");
171 protected final ButtonGroup renderersGroup = new ButtonGroup();
172 protected final ButtonGroup backgroundGroup1 = new ButtonGroup();
173 protected final ButtonGroup backgroundGroup2 = new ButtonGroup();
174 protected final ButtonGroup highlightGroup = new ButtonGroup();
175
176 //===== MONTH MENU =====//
177
178 protected final JMenu monthMenu = new JMenu("Month");
179 protected final JMenuItem saveMonthBtn = new JMenuItem("Save");
180 protected final JMenuItem closeMonthBtn = new JMenuItem("Close");
181 protected final JMenuItem showBudgetBtn = new JMenuItem("Show Budget");
182 protected final JMenuItem changeBudgetBtn = new JMenuItem("Change Budget");
183 protected final JMenuItem addAllocationBtn = new JMenuItem("Add Allocation");
184 protected final JMenuItem addTransactionBtn = new JMenuItem("Add Transaction");
185
186 //====== BUDGET MENU ====//
187
188 protected final JMenu budgetsMenu = new JMenu("Budgets");
189 protected final JMenuItem viewBudgetBtn = new JMenuItem("View Budget");
190 protected final JMenuItem newBudgetBtn = new JMenuItem("New Budget");
191 protected final JMenuItem budgetWisardBtn = new JMenuItem("Budget Wisard");
192 protected final JMenuItem removeBudgetBtn = new JMenuItem("Remove Budget");
193 protected final JMenuItem removeUnusedBudgetsBtn = new JMenuItem("Remove Unused");
194
195 //====== ACCOUNTS MENU ====//
196
197 protected final JMenu accountsMenu = new JMenu("Accounts");
198 protected final JMenuItem viewAccountBtn = new JMenuItem("View Account");
199 protected final JMenuItem editAccountBtn = new JMenuItem("Edit Account");
200 protected final JMenuItem newAccountBtn = new JMenuItem("New Account");
201 protected final JMenuItem removeAccountBtn = new JMenuItem("Remove Account");
202 protected final JMenuItem removeUnusedAccountsBtn = new JMenuItem("Remove Unused");
203
204 //===== TOOLS MENU =====//
205
206 protected final JMenu toolsMenu = new JMenu("Tools");
207 protected final JMenuItem analysisBtn = new JMenuItem("Analysis");
208 protected final JMenuItem preferencesBtn = new JMenuItem("Preferences");
209
210 //===== SYSTEM MENU ===//
211
212 protected final JMenu systemMenu = new JMenu("System");
213 protected final JMenuItem switchUserBtn = new JMenuItem("Switch User");
214 protected final JMenuItem newUserBtn = new JMenuItem("Add User");
215 protected final JMenuItem removeUserBtn = new JMenuItem("Remove User");
216 protected final JMenuItem dataDirBtn = new JMenuItem("Data Dir.");
217
218 //===== HELP MENU =====//
219
220 protected final JMenu helpMenu = new JMenu("Help");
221 protected final JMenuItem getStartedBtn = new JMenuItem("Get Started");
222 protected final JMenuItem aboutBtn = new JMenuItem("About");
223
224
225 //============================================================================
226 //
227 // CONSTRUCTOR[S]
228 //
229 //============================================================================
230
231 MainWindowBase()
232 {
233 super("jBudget");
234
235 List<JComponent> tabs = new ArrayList<JComponent>(5);
236 tabs.add(transactionsPanel);
237 tabs.add(allocationsPanel);
238 tabs.add(reportPanel);
239 tabs.add(filterPanel);
240 tabs.add(sorterPanel);
241
242 List<String> tabNames = new ArrayList<String>(5);
243 tabNames.add("TRANSACTIONS");
244 tabNames.add("ALLOCATIONS");
245 tabNames.add("REPORT");
246 tabNames.add("CHANGE FILTER");
247 tabNames.add("CHANGE ORDER");
248
249 sorterPanel.addListener(allocationsPanel.getModel());
250 sorterPanel.addListener(transactionsPanel.getModel());
251
252 CombinedTabbedPane mainPane =
253 new CombinedTabbedPane(dataPane, tabs, tabNames);
254
255 setLayout(new BorderLayout());
256 add(mainPane, BorderLayout.CENTER);
257
258 setJMenuBar(menuBar);
259
260 Toolkit.getDefaultToolkit().addAWTEventListener(
261 new EventListener(), AWTEvent.MOUSE_EVENT_MASK);
262 }
263
264 //============================================================================
265 //
266 // Accessors.
267 //
268 //============================================================================
269
270 /** Returns the TransactionListPanel object taht is used to display a list
271 * of transactoins. */
272 public TransactionListPanel getTransactionsPanel()
273 {
274 return transactionsPanel;
275 }
276
277 /** Returns the AllocationListPanel object taht is used to display a list
278 * of allocations. */
279 public AllocationListPanel getAllocationsPanel()
280 {
281 return allocationsPanel;
282 }
283
284 //============================================================================
285 //
286 // Initialization Methods.
287 //
288 //============================================================================
289
290
291 /** Puts all components in the menu bar. */
292 protected void arrangeMenus()
293 {
294 //====== File Menu =====//
295
296 openMonthBtn.setToolTipText("Open an existing month record");
297 addMonthBtn.setToolTipText("Create a new month record");
298 saveAllBtn.setToolTipText("Save all open month records");
299 closeAllBtn.setToolTipText("Save and Close all open month records");
300 exitBtn.setToolTipText("Save all open records and exit");
301
302 openMonthBtn.setMnemonic('o');
303 addMonthBtn.setMnemonic('a');
304 saveAllBtn.setMnemonic('s');
305 closeAllBtn.setMnemonic('c');
306 exitBtn.setMnemonic('x');
307
308 openMonthBtn.setAccelerator(KeyStroke.getKeyStroke("control O"));
309
310 addMonthBtn.setAccelerator(KeyStroke.getKeyStroke("control N"));
311 saveAllBtn.setAccelerator(KeyStroke.getKeyStroke("control S"));
312 exitBtn.setAccelerator(KeyStroke.getKeyStroke("control X"));
313
314 fileMenu.add(openMonthBtn);
315 fileMenu.add(addMonthBtn);
316 fileMenu.add(new JSeparator());
317 fileMenu.add(saveAllBtn);
318 fileMenu.add(closeAllBtn);
319 fileMenu.add(new JSeparator());
320 fileMenu.add(exitBtn);
321
322 menuBar.add(fileMenu);
323
324 //==== Veiw Menu =======//
325
326 collapseAccountsBtn.setToolTipText("Collapse all Accounts in one column");
327 collapseCategoriesBtn.setToolTipText(
328 "Collapse all Expense Categories in one column");
329
330 hideSubcategoriesBtn.setToolTipText("Show only root categories");
331 hideEmptyAccountsBtn.setToolTipText("Hide accounts with zero balance");
332 hideEmptyCategoriesBtn.setToolTipText("Hide categories with zero balance");
333 hideIdleAccountsBtn.setToolTipText("Hide accounts with no transactions");
334 hideIdleCategoriesBtn.setToolTipText("Hide expense categories with no transactions");
335
336 plainBackgrBtn.setToolTipText("Use plain background");
337 stripedBackgrBtn.setToolTipText("Use striped background");
338 fullStructureBackgrBtn.setToolTipText("Use colors associated with expense categories");
339 simpleStructureBackgrBtn.setToolTipText("Use colors associated with expense categories");
340 noStructureBackgrBtn.setToolTipText("Do not use colors associated with expense categories");
341
342 highltOffBtn.setToolTipText("No highlighting");
343 highltUnderlBtn.setToolTipText("Underline expenses and credits");
344
345 hideMenu.add(hideEmptyAccountsBtn);
346 hideMenu.add(hideIdleAccountsBtn);
347 hideMenu.addSeparator();
348 hideMenu.add(hideEmptyCategoriesBtn);
349 hideMenu.add(hideIdleCategoriesBtn);
350 hideMenu.add(hideSubcategoriesBtn);
351
352 renderersMenu.add(detailedRendererBtn);
353 renderersMenu.add(activityRendererBtn);
354 renderersMenu.add(balanceRendererBtn);
355 renderersMenu.add(actAndBalRendererBtn);
356
357 renderersGroup.add(detailedRendererBtn);
358 renderersGroup.add(activityRendererBtn);
359 renderersGroup.add(balanceRendererBtn);
360 renderersGroup.add(actAndBalRendererBtn);
361
362 backgroundMenu.add(plainBackgrBtn);
363 backgroundMenu.add(stripedBackgrBtn);
364 backgroundMenu.addSeparator();
365 backgroundMenu.add(fullStructureBackgrBtn);
366 backgroundMenu.add(simpleStructureBackgrBtn);
367 backgroundMenu.add(noStructureBackgrBtn);
368
369 backgroundGroup1.add(plainBackgrBtn);
370 backgroundGroup1.add(stripedBackgrBtn);
371 backgroundGroup2.add(fullStructureBackgrBtn);
372 backgroundGroup2.add(simpleStructureBackgrBtn);
373 backgroundGroup2.add(noStructureBackgrBtn);
374
375
376 highlightMenu.add(highltOffBtn);
377 highlightMenu.add(highltUnderlBtn);
378
379 highlightGroup.add(highltOffBtn);
380 highlightGroup.add(highltUnderlBtn);
381
382 viewMenu.add(collapseAccountsBtn);
383 viewMenu.add(collapseCategoriesBtn);
384 viewMenu.addSeparator();
385 viewMenu.add(hideMenu);
386 viewMenu.addSeparator();
387 viewMenu.add(renderersMenu);
388 viewMenu.add(backgroundMenu);
389 viewMenu.add(highlightMenu);
390
391 menuBar.add(viewMenu);
392
393 //==== Month Menu =======//
394
395 saveMonthBtn.setToolTipText("Save current month record");
396 closeMonthBtn.setToolTipText("Save and Close current month record");
397 showBudgetBtn.setToolTipText("Show budget used by this month");
398 changeBudgetBtn.setToolTipText("Chnage budget for the month");
399 addAllocationBtn.setToolTipText("Create a new expense allocation");
400 addTransactionBtn.setToolTipText("Create a new transaction record");
401
402 saveMonthBtn.setMnemonic('s');
403 closeMonthBtn.setMnemonic('c');
404 showBudgetBtn.setMnemonic('b');
405 addAllocationBtn.setMnemonic('a');
406 addTransactionBtn.setMnemonic('t');
407
408 closeMonthBtn.setAccelerator(KeyStroke.getKeyStroke("control W"));
409 addTransactionBtn.setAccelerator(KeyStroke.getKeyStroke("control T"));
410
411 monthMenu.add(closeMonthBtn);
412 monthMenu.add(saveMonthBtn);
413 monthMenu.add(new JSeparator());
414 monthMenu.add(showBudgetBtn);
415 monthMenu.add(changeBudgetBtn);
416 monthMenu.add(new JSeparator());
417 monthMenu.add(addAllocationBtn);
418 monthMenu.add(addTransactionBtn);
419
420 menuBar.add(monthMenu);
421
422 //=== Budgets Menu ===//
423
424 viewBudgetBtn.setToolTipText("Show a budget");
425 newBudgetBtn.setToolTipText(
426 "Create a new budget using Budget Editor (Advanced)");
427 budgetWisardBtn.setToolTipText(
428 "Create a new budget using Budget Wisard (Simple)");
429 removeBudgetBtn.setToolTipText("Remove an unused budget");
430 removeUnusedBudgetsBtn.setToolTipText("Remove all unused budgets");
431
432 viewBudgetBtn.setMnemonic('v');
433 newBudgetBtn.setMnemonic('n');
434 removeBudgetBtn.setMnemonic('r');
435 removeUnusedBudgetsBtn.setMnemonic('u');
436
437 budgetsMenu.add(viewBudgetBtn);
438 budgetsMenu.add(newBudgetBtn);
439 budgetsMenu.add(budgetWisardBtn);
440 budgetsMenu.add(new JSeparator());
441 budgetsMenu.add(removeBudgetBtn);
442 budgetsMenu.add(removeUnusedBudgetsBtn);
443
444 menuBar.add(budgetsMenu);
445
446 //=== Accounts Menu ===//
447
448 viewAccountBtn.setToolTipText("Display account record");
449 editAccountBtn.setToolTipText("Edit account record");
450 newAccountBtn.setToolTipText("Create a new account record");
451 removeAccountBtn.setToolTipText("Remove a record of an account");
452 removeUnusedAccountsBtn.setToolTipText("Remove all unused account records");
453
454 viewAccountBtn.setMnemonic('v');
455 editAccountBtn.setMnemonic('e');
456 newAccountBtn.setMnemonic('n');
457 removeAccountBtn.setMnemonic('r');
458 removeUnusedAccountsBtn.setMnemonic('u');
459
460 editAccountBtn.setEnabled(false);
461 newAccountBtn.setEnabled(false);
462 removeAccountBtn.setEnabled(false);
463 removeUnusedAccountsBtn.setEnabled(false);
464
465 accountsMenu.add(viewAccountBtn);
466 accountsMenu.add(new JSeparator());
467 accountsMenu.add(editAccountBtn);
468 accountsMenu.add(newAccountBtn);
469 accountsMenu.add(new JSeparator());
470 accountsMenu.add(removeAccountBtn);
471 accountsMenu.add(removeUnusedAccountsBtn);
472
473 menuBar.add(accountsMenu);
474
475 //=== Tools Menu ===//
476
477 analysisBtn.setToolTipText("Open data analysis window");
478 preferencesBtn.setToolTipText("Change preferences");
479
480 toolsMenu.add(analysisBtn);
481 toolsMenu.add(preferencesBtn);
482
483 menuBar.add(toolsMenu);
484
485 //=== System Menu ===//
486
487 switchUserBtn.setToolTipText("Change current user");
488 newUserBtn.setToolTipText("Add a new user");
489 removeUserBtn.setToolTipText("Remove a user");
490
491 switchUserBtn.setMnemonic('s');
492 newUserBtn.setMnemonic('a');
493 removeUserBtn.setMnemonic('r');
494
495 switchUserBtn.setAccelerator(KeyStroke.getKeyStroke("control U"));
496
497 newUserBtn.setEnabled(false);
498 removeUserBtn.setEnabled(false);
499
500 systemMenu.add(switchUserBtn);
501 systemMenu.addSeparator();
502 systemMenu.add(newUserBtn);
503 systemMenu.add(removeUserBtn);
504 systemMenu.add(dataDirBtn);
505
506 menuBar.add(systemMenu);
507
508 //=== Help Menu ===//
509
510 helpMenu.add(getStartedBtn);
511 helpMenu.add(aboutBtn);
512
513 menuBar.add(helpMenu);
514 }
515
516 }