1 package org.wcb.gui.forms;
2
3 import org.wcb.gui.component.JXTitlePanel;
4 import org.wcb.gui.component.WaveButton;
5 import org.wcb.gui.component.JMessageTextPane;
6 import org.wcb.gui.LogbookFrame;
7 import org.wcb.resources.MessageResourceRegister;
8 import org.wcb.resources.MessageKey;
9 import org.wcb.model.vo.hibernate.Logbook;
10 import org.wcb.model.bd.LogbookDelegate;
11 import org.jdesktop.swingx.border.DropShadowBorder;
12
13 import javax.swing.border.Border;
14 import javax.swing.border.CompoundBorder;
15 import javax.swing.*;
16 import java.awt.*;
17 import java.awt.event.ActionListener;
18 import java.awt.event.ActionEvent;
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46 public class LogbookEntryDisplay extends JXTitlePanel implements ActionListener {
47
48 private LogbookEntryForm logEntryForm;
49 private JButton jButtonClear;
50 private JButton jButtonSave;
51 private LogbookFrame frameRef;
52 private LogbookDelegate delegate;
53
54 public LogbookEntryDisplay(LogbookFrame parentFrame) {
55 super("Logbook New Entry", new Color(0x3779ff));
56 Border shadow = new DropShadowBorder(Color.BLACK, 2, 5, .3f, 10, false, true, true, true);
57 this.setBorder(new CompoundBorder(shadow, this.getBorder()));
58 this.delegate = new LogbookDelegate();
59 this.frameRef = parentFrame;
60 initComponents();
61 }
62
63 private void initComponents() {
64 setLayout(new BorderLayout());
65
66 logEntryForm = new LogbookEntryForm();
67
68 JScrollPane scroller = new JScrollPane(logEntryForm);
69 scroller.setViewportView(logEntryForm);
70 scroller.setPreferredSize(new Dimension(250,400));
71 scroller.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
72
73 jButtonClear = new WaveButton(MessageResourceRegister.getInstance().getValue(MessageKey.BUTTON_CLEAR));
74 jButtonClear.addActionListener(this);
75
76 jButtonSave = new WaveButton(MessageResourceRegister.getInstance().getValue(MessageKey.BUTTON_SAVE));
77 jButtonSave.addActionListener(this);
78
79 JPanel topPanel = new JPanel(new GridLayout(1,2));
80 topPanel.add(scroller);
81 topPanel.add(createTextPane());
82
83 JPanel buttonPanel = new JPanel(new GridBagLayout());
84 GridBagConstraints gridBagConstraints;
85
86 gridBagConstraints = new GridBagConstraints();
87 gridBagConstraints.gridx = 0;
88 gridBagConstraints.gridy = 1;
89 gridBagConstraints.anchor = GridBagConstraints.WEST;
90 buttonPanel.add(jButtonClear, gridBagConstraints);
91
92 gridBagConstraints = new GridBagConstraints();
93 gridBagConstraints.gridx = 1;
94 gridBagConstraints.gridy = 1;
95 gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
96 gridBagConstraints.anchor = GridBagConstraints.WEST;
97 buttonPanel.add(jButtonSave, gridBagConstraints);
98
99
100 add(topPanel, BorderLayout.CENTER);
101
102 add(buttonPanel, BorderLayout.SOUTH);
103 }
104
105 public Logbook getLogbookValue() {
106 return logEntryForm.getLogEntry();
107 }
108
109 public void setLogbookValue(Logbook entryValue) {
110 logEntryForm.setLogEntry(entryValue);
111 }
112
113 private JTextPane createTextPane() {
114 String[] initString =
115 { " " ,
116 "The idea is to make pilot logbook entry easy. ",
117 "We've designed the entry form to be easy to work",
118 "with, and assist in entering redundant information." ,
119 "This logbook software is only as good as the data",
120 "entered into it. It is your responsibility to ",
121 "ensure accuracy, and compliance with the FAR rules.",
122 " ",
123 "The hope is that this logbook software makes it",
124 "easier to track pilot time, and report that",
125 "information acurately. Though reports, and some",
126 "basic analysis of FAR regulations. Note: that",
127 "regulations change and as such it is important",
128 "to keep up with them."
129 };
130
131 JMessageTextPane messagePane = new JMessageTextPane(initString);
132 messagePane.setBackground(new Color(0x96bfdd));
133 return messagePane.getTextPane();
134 }
135
136 public void actionPerformed(ActionEvent event) {
137 Object source = event.getSource();
138 if (source.equals(jButtonSave))
139 {
140 if (delegate.validate(logEntryForm.getLogEntry()))
141 {
142 if((logEntryForm.getCrossCountry() > 0 && logEntryForm.isValidCrossCountry()) || logEntryForm.getCrossCountry() == 0) {
143 delegate.saveLogEntry(logEntryForm.getLogEntry());
144
145 this.frameRef.refreshLogbookView();
146 CardLayout cl = (CardLayout) frameRef.getCardPanel().getLayout();
147 cl.show(frameRef.getCardPanel(), LogbookFrame.LOGBOOK_VIEW);
148 } else {
149 JOptionPane.showMessageDialog(this, "There is a validation problem with cross country time.", "Validation Error", JOptionPane.ERROR_MESSAGE);
150 }
151 }
152 else
153 {
154 JOptionPane.showMessageDialog(this, "There is a possible validation problem", "Validation Error", JOptionPane.ERROR_MESSAGE);
155 }
156 }
157 if (source.equals(jButtonClear))
158 {
159 logEntryForm.reset();
160 }
161 }
162
163 }