1 package org.wcb.gui;
2
3 import org.wcb.gui.forms.tabbed.LogbookTableDisplayForm;
4 import org.wcb.gui.forms.report.TotalFlightTimeByMonthReportForm;
5 import org.wcb.gui.forms.LogbookEntryDisplay;
6 import org.wcb.gui.component.*;
7 import org.wcb.gui.component.border.BookBorder;
8 import org.wcb.gui.component.border.LeftPageBookBorder;
9 import org.wcb.gui.event.ApplicationCloseListener;
10 import org.wcb.gui.event.FrameDialogListener;
11 import org.wcb.gui.util.UIHelper;
12 import org.wcb.gui.util.WindowStateSaver;
13 import org.wcb.gui.util.ApplicationPreferences;
14 import org.wcb.gui.dialog.JLoginDialog;
15 import org.wcb.resources.HSQLDatabaseInitializer;
16 import org.wcb.model.vo.hibernate.Logbook;
17 import org.jdesktop.swingx.border.DropShadowBorder;
18 import org.jdesktop.swingx.VerticalLayout;
19
20 import org.wcb.model.service.impl.RecencyExperianceValidationService;
21 import org.wcb.model.service.IServicesConstants;
22 import org.wcb.model.util.SpringUtil;
23 import org.wcb.model.bd.LogbookDelegate;
24 import org.wcb.gui.util.IPilotsLogApplicationPreferenceKeys;
25
26 import javax.swing.*;
27 import javax.swing.border.CompoundBorder;
28 import javax.swing.border.Border;
29 import java.awt.*;
30
31 import com.jgoodies.plaf.plastic.Plastic3DLookAndFeel;
32 import com.jgoodies.plaf.plastic.theme.SkyBlue;
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60 public class LogbookFrame extends JFrame {
61 private JPanel glass;
62 private JComponent sheet;
63 private JPanel eastPanel;
64 private TotalFlightTimeByMonthReportForm summaryReport;
65 private LogbookEntryDisplay logEntryform;
66 private LogbookTableDisplayForm logbookTableView;
67 public static final String LOGBOOK_VIEW = "Logbook";
68 public static final String LOGBOOK_ENTRY_VIEW = "Entry";
69 public static final String SUMMARY_REPORT_VIEW = "Summary";
70
71 public LogbookFrame() {
72 glass = (JPanel) getGlassPane();
73 setTitle("Pilots Log");
74 super.setIconImage(UIHelper.getIcon("org/wcb/resources/gui/wings.png").getImage());
75 this.showSplashScreen();
76 if (ApplicationPreferences.getInstance().getBoolean(IPilotsLogApplicationPreferenceKeys.SHOW_WARN_ON_START)) {
77 RecencyExperianceValidationService recencyValidator = (RecencyExperianceValidationService) SpringUtil.getApplicationContext().getBean(IServicesConstants.LOGBOOK_RECENCY_EXPERIANCE);
78 LogbookDelegate delegate = (LogbookDelegate) SpringUtil.getApplicationContext().getBean(IServicesConstants.LOGBOOK_DELEGATE);
79 recencyValidator.setObject(delegate.getAllLogbookEntries());
80 if(!recencyValidator.validate()) {
81 String messages = recencyValidator.getMessage();
82 JOptionPane.showMessageDialog(this, messages, "Warning" , JOptionPane.WARNING_MESSAGE);
83 }
84 }
85
86 }
87
88 public JPanel getCardPanel() {
89 return eastPanel;
90 }
91
92 private void setApplicationLookAndFeel() {
93
94 try
95 {
96 UIManager.setLookAndFeel(new Plastic3DLookAndFeel());
97 Plastic3DLookAndFeel.setMyCurrentTheme(new SkyBlue());
98 com.jgoodies.plaf.Options.setPopupDropShadowEnabled(true);
99 }
100 catch (Exception e)
101 {
102 e.printStackTrace();
103 }
104 }
105
106 private void showSplashScreen() {
107 SplashScreen splash = new SplashScreen(UIHelper.getIcon("org/wcb/resources/gui/safelog_cover_black_sm.jpg"));
108 try
109 {
110 splash.showStatus("JPilot Logbook V 1.0");
111 new HSQLDatabaseInitializer();
112 splash.showStatus("created by");
113 Thread.sleep(100);
114 this.initComponents();
115 this.setApplicationLookAndFeel();
116 pack();
117 splash.showStatus("Walter Bogaardt");
118 Thread.sleep(500);
119 setSize(800, 620);
120 Toolkit tk = Toolkit.getDefaultToolkit();
121 tk.addAWTEventListener(WindowStateSaver.getInstance(), AWTEvent.WINDOW_EVENT_MASK);
122 loginUser();
123 addWindowListener(new ApplicationCloseListener(this));
124 splash.close();
125 }
126 catch (InterruptedException err)
127 {
128 err.printStackTrace();
129 }
130 }
131
132
133
134
135
136
137
138 private void loginUser() {
139
140 if (ApplicationPreferences.getInstance().getBoolean(ApplicationPreferences.LOGON_ENABLE)) {
141 JLoginDialog dialog = new JLoginDialog(this, "JPilot Login", true);
142 dialog.setVisible(true);
143 }
144 else {
145
146 setVisible(true);
147 }
148 }
149
150 public void refreshSummaryReport() {
151 summaryReport.refresh();
152 }
153
154 public void setLogEntryForm(Logbook oValue) {
155 logEntryform.setLogbookValue(oValue);
156 }
157
158 public Logbook getLogEntryForm() {
159 return logEntryform.getLogbookValue();
160 }
161
162
163
164
165
166
167 public void refreshLogbookView() {
168 logbookTableView.refresh();
169 }
170
171 private void initComponents() {
172 setLayout(new BorderLayout());
173 setJMenuBar(new JPilotMenu(this));
174 ImageIcon titleIcon = UIHelper.getIcon("org/wcb/resources/gui/log_title.png");
175 JLabel titleLabel = new JLabel(titleIcon);
176 logbookTableView = new LogbookTableDisplayForm();
177
178 JPanel titlePanel = new JPanel();
179 titlePanel.setBackground(new Color(0x8a84ab));
180 titlePanel.setLayout(new BorderLayout());
181
182
183 eastPanel = new JPanel(new CardLayout());
184 eastPanel.setBorder(new CompoundBorder(new BookBorder(), eastPanel.getBorder()));
185 eastPanel.add(logbookTableView, LOGBOOK_VIEW);
186
187 JXTitlePanel summaryPanel = new JXTitlePanel("Summary of all Flights", new Color(0x3779ff));
188 Border shadow = new DropShadowBorder(Color.BLACK, 2, 5, .3f, 10, false, true, true, true);
189 summaryPanel.setBorder(new CompoundBorder(shadow, summaryPanel.getBorder()));
190 summaryReport = new TotalFlightTimeByMonthReportForm();
191 summaryPanel.add(summaryReport);
192 eastPanel.add(summaryPanel, SUMMARY_REPORT_VIEW);
193
194 logEntryform = new LogbookEntryDisplay(this);
195 eastPanel.add(logEntryform, LOGBOOK_ENTRY_VIEW);
196
197 JPanel westPanel = new JPanel();
198 westPanel.setLayout(new VerticalLayout(2));
199 westPanel.setBorder(new CompoundBorder(new LeftPageBookBorder(), westPanel.getBorder()));
200 JButton logbook = new WaveButton("Logbook");
201 JButton summary = new WaveButton("Summary");
202 JButton airport = new WaveButton("Airports");
203 JButton aircraft = new WaveButton("Aircraft");
204 logbook.addActionListener(new FrameDialogListener(this));
205 summary.addActionListener(new FrameDialogListener(this));
206 airport.addActionListener(new FrameDialogListener(this));
207 aircraft.addActionListener(new FrameDialogListener(this));
208 westPanel.add(logbook);
209 westPanel.add(aircraft);
210 westPanel.add(airport);
211 westPanel.add(summary);
212
213
214 JPanel mainPanel = new JPanel(new BorderLayout());
215 mainPanel.add(westPanel, BorderLayout.WEST);
216 mainPanel.add(eastPanel, BorderLayout.CENTER);
217
218
219 titlePanel.add(new JPilotIconMenu(this), BorderLayout.NORTH);
220 titlePanel.add(titleLabel, BorderLayout.WEST);
221 add(titlePanel, BorderLayout.NORTH);
222 add(mainPanel, BorderLayout.CENTER);
223 add(new JStatusBar(), BorderLayout.SOUTH);
224 }
225
226 public JComponent showJDialogAsSheet(JDialog dialog) {
227 sheet = (JComponent) dialog.getContentPane();
228 glass.setLayout(new GridBagLayout());
229
230 glass.removeAll();
231 GridBagConstraints gbc = new GridBagConstraints();
232 gbc.anchor = GridBagConstraints.NORTH;
233 glass.add(sheet, gbc);
234 gbc.gridy = 1;
235 gbc.weighty = Integer.MAX_VALUE;
236 glass.add(Box.createGlue(), gbc);
237 glass.setVisible(true);
238 return sheet;
239 }
240
241 public void hideSheet() {
242 glass.setVisible(false);
243 }
244
245 public static void main(String[] args) {
246 new LogbookFrame();
247 }
248 }