View Javadoc
1   /*
2    * DesktopApplication1View.java
3    */
4   package net.sf.openv4j.swingui;
5   
6   import java.awt.event.ActionEvent;
7   import java.awt.event.ActionListener;
8   
9   import javax.swing.Icon;
10  import javax.swing.JDialog;
11  import javax.swing.JFrame;
12  import javax.swing.Timer;
13  
14  import org.jdesktop.application.Action;
15  import org.jdesktop.application.FrameView;
16  import org.jdesktop.application.ResourceMap;
17  import org.jdesktop.application.SingleFrameApplication;
18  import org.jdesktop.application.TaskMonitor;
19  
20  /**
21   * The application's main frame.
22   */
23  public class DesktopApplication1View extends FrameView {
24      // Variables declaration - do not modify//GEN-BEGIN:variables
25      private javax.swing.JPanel jPanel1;
26      private javax.swing.JPanel jPanel2;
27      private javax.swing.JTabbedPane jTabbedPane1;
28      private javax.swing.JPanel mainPanel;
29      private javax.swing.JMenuBar menuBar;
30      private javax.swing.JProgressBar progressBar;
31      private javax.swing.JLabel segmentSizeLabel;
32      private javax.swing.JComboBox segmetSizeComboBox;
33      private javax.swing.JComboBox serialPortComboBox;
34      private javax.swing.JLabel serialPortLabel;
35      private javax.swing.JLabel statusAnimationLabel;
36      private javax.swing.JLabel statusMessageLabel;
37      private javax.swing.JPanel statusPanel;
38      private final Icon idleIcon;
39      private final Timer busyIconTimer;
40  
41      // End of variables declaration//GEN-END:variables
42      private final Timer messageTimer;
43      private final Icon[] busyIcons = new Icon[15];
44      private JDialog aboutBox;
45      private int busyIconIndex = 0;
46  
47      /**
48       * Creates a new DesktopApplication1View object.
49       *
50       * @param app DOCUMENT ME!
51       */
52      public DesktopApplication1View(SingleFrameApplication app) {
53          super(app);
54  
55          initComponents();
56  
57          // status bar initialization - message timeout, idle icon and busy animation, etc
58          ResourceMap resourceMap = getResourceMap();
59          int messageTimeout = resourceMap.getInteger("StatusBar.messageTimeout");
60          messageTimer =
61              new Timer(messageTimeout, new ActionListener() {
62                      public void actionPerformed(ActionEvent e) {
63                          statusMessageLabel.setText("");
64                      }
65                  });
66          messageTimer.setRepeats(false);
67  
68          int busyAnimationRate = resourceMap.getInteger("StatusBar.busyAnimationRate");
69  
70          for (int i = 0; i < busyIcons.length; i++) {
71              busyIcons[i] = resourceMap.getIcon("StatusBar.busyIcons[" + i + "]");
72          }
73  
74          busyIconTimer =
75              new Timer(busyAnimationRate, new ActionListener() {
76                      public void actionPerformed(ActionEvent e) {
77                          busyIconIndex = (busyIconIndex + 1) % busyIcons.length;
78                          statusAnimationLabel.setIcon(busyIcons[busyIconIndex]);
79                      }
80                  });
81          idleIcon = resourceMap.getIcon("StatusBar.idleIcon");
82          statusAnimationLabel.setIcon(idleIcon);
83          progressBar.setVisible(false);
84  
85          // connecting action tasks to status bar via TaskMonitor
86          TaskMonitor taskMonitor = new TaskMonitor(getApplication().getContext());
87          taskMonitor.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
88                  public void propertyChange(java.beans.PropertyChangeEvent evt) {
89                      String propertyName = evt.getPropertyName();
90  
91                      if ("started".equals(propertyName)) {
92                          if (!busyIconTimer.isRunning()) {
93                              statusAnimationLabel.setIcon(busyIcons[0]);
94                              busyIconIndex = 0;
95                              busyIconTimer.start();
96                          }
97  
98                          progressBar.setVisible(true);
99                          progressBar.setIndeterminate(true);
100                     } else if ("done".equals(propertyName)) {
101                         busyIconTimer.stop();
102                         statusAnimationLabel.setIcon(idleIcon);
103                         progressBar.setVisible(false);
104                         progressBar.setValue(0);
105                     } else if ("message".equals(propertyName)) {
106                         String text = (String) (evt.getNewValue());
107                         statusMessageLabel.setText((text == null) ? "" : text);
108                         messageTimer.restart();
109                     } else if ("progress".equals(propertyName)) {
110                         int value = (Integer) (evt.getNewValue());
111                         progressBar.setVisible(true);
112                         progressBar.setIndeterminate(false);
113                         progressBar.setValue(value);
114                     }
115                 }
116             });
117     }
118 
119     /**
120      * DOCUMENT ME!
121      */
122     @Action
123     public void showAboutBox() {
124         if (aboutBox == null) {
125             JFrame mainFrame = DesktopApplication1.getApplication().getMainFrame();
126             aboutBox = new DesktopApplication1AboutBox(mainFrame);
127             aboutBox.setLocationRelativeTo(mainFrame);
128         }
129 
130         DesktopApplication1.getApplication().show(aboutBox);
131     }
132 
133     /**
134      * This method is called from within the constructor to initialize the form. WARNING: Do NOT modify this code. The content of this method is always regenerated by the Form Editor.
135      */
136     @SuppressWarnings("unchecked")
137     private void initComponents() {
138         mainPanel = new javax.swing.JPanel();
139         jTabbedPane1 = new javax.swing.JTabbedPane();
140         jPanel1 = new javax.swing.JPanel();
141         serialPortComboBox = new javax.swing.JComboBox();
142         serialPortLabel = new javax.swing.JLabel();
143         segmentSizeLabel = new javax.swing.JLabel();
144         segmetSizeComboBox = new javax.swing.JComboBox();
145         jPanel2 = new javax.swing.JPanel();
146         menuBar = new javax.swing.JMenuBar();
147 
148         javax.swing.JMenu fileMenu = new javax.swing.JMenu();
149         javax.swing.JMenuItem exitMenuItem = new javax.swing.JMenuItem();
150         javax.swing.JMenu helpMenu = new javax.swing.JMenu();
151         javax.swing.JMenuItem aboutMenuItem = new javax.swing.JMenuItem();
152         statusPanel = new javax.swing.JPanel();
153 
154         javax.swing.JSeparator statusPanelSeparator = new javax.swing.JSeparator();
155         statusMessageLabel = new javax.swing.JLabel();
156         statusAnimationLabel = new javax.swing.JLabel();
157         progressBar = new javax.swing.JProgressBar();
158 
159         mainPanel.setName("mainPanel"); // NOI18N
160 
161         jTabbedPane1.setName("jTabbedPane1"); // NOI18N
162 
163         jPanel1.setName("jPanel1"); // NOI18N
164 
165         serialPortComboBox.setName("serialPortComboBox"); // NOI18N
166 
167         serialPortLabel.setLabelFor(serialPortComboBox);
168 
169         org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance().getContext().getResourceMap(DesktopApplication1View.class);
170         serialPortLabel.setText(resourceMap.getString("serialPortLabel.text")); // NOI18N
171         serialPortLabel.setName("serialPortLabel"); // NOI18N
172 
173         segmentSizeLabel.setText(resourceMap.getString("segmetSizeLabel.text")); // NOI18N
174         segmentSizeLabel.setName("segmetSizeLabel"); // NOI18N
175 
176         segmetSizeComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "1", "2", "4", "8", "16", "32", "48", "64", "128" }));
177         segmetSizeComboBox.setSelectedIndex(5);
178         segmetSizeComboBox.setName("segmetSizeComboBox"); // NOI18N
179 
180         javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
181         jPanel1.setLayout(jPanel1Layout);
182         jPanel1Layout.setHorizontalGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(jPanel1Layout.createSequentialGroup().addContainerGap().addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addComponent(serialPortLabel).addComponent(segmentSizeLabel)).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addComponent(segmetSizeComboBox, 0, 97, Short.MAX_VALUE).addComponent(serialPortComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, 97, javax.swing.GroupLayout.PREFERRED_SIZE)).addContainerGap(521, javax.swing.GroupLayout.PREFERRED_SIZE)));
183         jPanel1Layout.setVerticalGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(jPanel1Layout.createSequentialGroup().addContainerGap().addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE).addComponent(serialPortLabel).addComponent(serialPortComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE).addComponent(segmentSizeLabel).addComponent(segmetSizeComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)).addContainerGap(334, Short.MAX_VALUE)));
184 
185         jTabbedPane1.addTab(resourceMap.getString("jPanel1.TabConstraints.tabTitle"), jPanel1); // NOI18N
186 
187         jPanel2.setName("jPanel2"); // NOI18N
188 
189         javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
190         jPanel2.setLayout(jPanel2Layout);
191         jPanel2Layout.setHorizontalGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 713, Short.MAX_VALUE));
192         jPanel2Layout.setVerticalGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 400, Short.MAX_VALUE));
193 
194         jTabbedPane1.addTab(resourceMap.getString("jPanel2.TabConstraints.tabTitle"), jPanel2); // NOI18N
195 
196         javax.swing.GroupLayout mainPanelLayout = new javax.swing.GroupLayout(mainPanel);
197         mainPanel.setLayout(mainPanelLayout);
198         mainPanelLayout.setHorizontalGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addComponent(jTabbedPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 725, Short.MAX_VALUE));
199         mainPanelLayout.setVerticalGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addComponent(jTabbedPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 440, Short.MAX_VALUE));
200 
201         jTabbedPane1.getAccessibleContext().setAccessibleName(resourceMap.getString("jTabbedPane1.AccessibleContext.accessibleName")); // NOI18N
202 
203         menuBar.setName("menuBar"); // NOI18N
204 
205         fileMenu.setText(resourceMap.getString("fileMenu.text")); // NOI18N
206         fileMenu.setName("fileMenu"); // NOI18N
207 
208         javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance().getContext().getActionMap(DesktopApplication1View.class, this);
209         exitMenuItem.setAction(actionMap.get("quit")); // NOI18N
210         exitMenuItem.setName("exitMenuItem"); // NOI18N
211         fileMenu.add(exitMenuItem);
212 
213         menuBar.add(fileMenu);
214 
215         helpMenu.setText(resourceMap.getString("helpMenu.text")); // NOI18N
216         helpMenu.setName("helpMenu"); // NOI18N
217 
218         aboutMenuItem.setAction(actionMap.get("showAboutBox")); // NOI18N
219         aboutMenuItem.setName("aboutMenuItem"); // NOI18N
220         helpMenu.add(aboutMenuItem);
221 
222         menuBar.add(helpMenu);
223 
224         statusPanel.setName("statusPanel"); // NOI18N
225 
226         statusPanelSeparator.setName("statusPanelSeparator"); // NOI18N
227 
228         statusMessageLabel.setName("statusMessageLabel"); // NOI18N
229 
230         statusAnimationLabel.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
231         statusAnimationLabel.setName("statusAnimationLabel"); // NOI18N
232 
233         progressBar.setName("progressBar"); // NOI18N
234 
235         javax.swing.GroupLayout statusPanelLayout = new javax.swing.GroupLayout(statusPanel);
236         statusPanel.setLayout(statusPanelLayout);
237         statusPanelLayout.setHorizontalGroup(statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addComponent(statusPanelSeparator, javax.swing.GroupLayout.DEFAULT_SIZE, 725, Short.MAX_VALUE).addGroup(statusPanelLayout.createSequentialGroup().addContainerGap().addComponent(statusMessageLabel).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 543, Short.MAX_VALUE).addComponent(progressBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(statusAnimationLabel).addContainerGap()));
238         statusPanelLayout.setVerticalGroup(statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(statusPanelLayout.createSequentialGroup().addComponent(statusPanelSeparator, javax.swing.GroupLayout.PREFERRED_SIZE, 2, javax.swing.GroupLayout.PREFERRED_SIZE).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE).addGroup(statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE).addComponent(statusMessageLabel).addComponent(statusAnimationLabel).addComponent(progressBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)).addGap(3, 3, 3)));
239 
240         setComponent(mainPanel);
241         setMenuBar(menuBar);
242         setStatusBar(statusPanel);
243     } // </editor-fold>//GEN-END:initComponents
244 }