View Javadoc
1   package info.mikethomas.fahview.v6project.panels;
2   
3   /*
4    * #%L
5    * This file is part of FAHView-v6project.
6    * %%
7    * Copyright (C) 2011 - 2017 Mike Thomas <mikepthomas@outlook.com>
8    * %%
9    * FAHView is free software: you can redistribute it and/or modify
10   * it under the terms of the GNU General Public License as published by
11   * the Free Software Foundation, either version 3 of the License, or
12   * (at your option) any later version.
13   * %
14   * FAHView is distributed in the hope that it will be useful,
15   * but WITHOUT ANY WARRANTY; without even the implied warranty of
16   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17   * GNU General Public License for more details.
18   * %
19   * You should have received a copy of the GNU General Public License
20   * along with FAHView.  If not, see <http://www.gnu.org/licenses/>.
21   * #L%
22   */
23  
24  import info.mikethomas.fahview.v6project.model.QueueImpl;
25  import info.mikethomas.fahview.v6project.utilities.ProgressCellRenderer;
26  import info.mikethomas.fahview.v6project.utilities.QueueReader;
27  import javax.swing.JTable;
28  import org.netbeans.api.settings.ConvertAsProperties;
29  import org.openide.awt.ActionID;
30  import org.openide.awt.ActionReference;
31  import org.openide.windows.TopComponent;
32  import org.openide.util.NbBundle.Messages;
33  
34  
35  /**
36   * Top component which displays something.
37   *
38   * @author <a href="mailto:mikepthomas@outlook.com">Michael Thomas</a>
39   * @version $Id: $Id
40   */
41  @ConvertAsProperties(
42      dtd="-//info.mikethomas.fahview.v6project.panels//Queue//EN",
43      autostore=false
44  )
45  @TopComponent.Description(
46      preferredID="QueueTopComponent",
47      iconBase="info/mikethomas/fahview/v6project/queue.png",
48      persistenceType=TopComponent.PERSISTENCE_ALWAYS
49  )
50  @TopComponent.Registration(mode = "editor", openAtStartup = false)
51  @ActionID(category = "Window", id = "info.mikethomas.fahview.v6project.panels.QueueTopComponent")
52  @ActionReference(path = "Menu/Window" /*, position = 333 */)
53  @TopComponent.OpenActionRegistration(
54      displayName = "#CTL_QueueAction",
55      preferredID="QueueTopComponent"
56  )
57  @Messages({
58      "CTL_QueueAction=Queue",
59      "CTL_QueueTopComponent=Queue Window",
60      "HINT_QueueTopComponent=This is a Queue window"
61  })
62  public final class QueueTopComponent extends TopComponent {
63      /**
64       * <p>Constructor for QueueTopComponent.</p>
65       */
66      public QueueTopComponent() {
67          initComponents();
68          setName(Bundle.CTL_QueueTopComponent());
69          setToolTipText(Bundle.HINT_QueueTopComponent());
70  
71          table.getColumn("Progress").setCellRenderer(new ProgressCellRenderer());
72      }
73  
74      /**
75       * This method is called from within the constructor to
76       * initialize the form.
77       * WARNING: Do NOT modify this code. The content of this method is
78       * always regenerated by the Form Editor.
79       */
80      // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
81      private void initComponents() {
82  
83          queueWindow = new javax.swing.JScrollPane();
84          table = new javax.swing.JTable();
85  
86          table.setModel(new javax.swing.table.DefaultTableModel(
87              new Object [][] {
88                  {"0", null, "0%", null},
89                  {"1", null, "0%", null},
90                  {"2", null, "0%", null},
91                  {"3", null, "0%", null},
92                  {"4", null, "0%", null},
93                  {"5", null, "0%", null},
94                  {"6", null, "0%", null},
95                  {"7", null, "0%", null},
96                  {"8", null, "0%", null},
97                  {"9", null, "0%", null}
98              },
99              new String [] {
100                 "Position", "Status", "Progress", "Project"
101             }
102         ) {
103             Class[] types = new Class [] {
104                 java.lang.String.class, java.lang.Integer.class, java.lang.String.class, java.lang.String.class
105             };
106             boolean[] canEdit = new boolean [] {
107                 true, false, true, false
108             };
109 
110             public Class getColumnClass(int columnIndex) {
111                 return types [columnIndex];
112             }
113 
114             public boolean isCellEditable(int rowIndex, int columnIndex) {
115                 return canEdit [columnIndex];
116             }
117         });
118         table.setDoubleBuffered(true);
119         queueWindow.setViewportView(table);
120 
121         org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
122         this.setLayout(layout);
123         layout.setHorizontalGroup(
124             layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
125             .add(layout.createSequentialGroup()
126                 .addContainerGap()
127                 .add(queueWindow, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 607, Short.MAX_VALUE)
128                 .addContainerGap())
129         );
130         layout.setVerticalGroup(
131             layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
132             .add(layout.createSequentialGroup()
133                 .addContainerGap()
134                 .add(queueWindow, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 181, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
135                 .addContainerGap(113, Short.MAX_VALUE))
136         );
137     }// </editor-fold>//GEN-END:initComponents
138 
139 
140     // Variables declaration - do not modify//GEN-BEGIN:variables
141     private javax.swing.JScrollPane queueWindow;
142     private javax.swing.JTable table;
143     // End of variables declaration//GEN-END:variables
144 
145     /** {@inheritDoc} */
146     @Override
147     public void componentOpened() {
148         // TODO add custom code on component opening
149         // create queue
150                 QueueImpl queue = new QueueImpl(new QueueReader("/Users/mike/SkyDrive/Documents/University/Year 3/Computing Project/FAH/Core1/queue.dat"));
151                 System.out.println(queue);
152 
153                 // select the current index in table
154                 int current = queue.getCurrent();
155                 getTable().getSelectionModel().setSelectionInterval(current, current);
156 
157                 // Fill the table
158                 for (int i = 0; i <= 9; i++) {
159                     int status = queue.getQueueIndex(i).getStat();
160                     String percentage = queue.getQueueIndex(i).getWuid().getPercentage();
161                     int proj = queue.getQueueIndex(i).getWuid().getProj();
162                     int run = queue.getQueueIndex(i).getWuid().getRun();
163                     int clone = queue.getQueueIndex(i).getWuid().getClone();
164                     int gen = queue.getQueueIndex(i).getWuid().getGen();
165                     String project =
166                             proj + " (Run "
167                             + run + ", Clone "
168                             + clone + ", Gen "
169                             + gen + ")";
170                     setStatus(i, status);
171                     setPercentage(i, percentage);
172                     setProject(i, project);
173                 }
174     }
175 
176     /** {@inheritDoc} */
177     @Override
178     public void componentClosed() {
179         // TODO add custom code on component closing
180     }
181 
182     /**
183      * <p>writeProperties.</p>
184      *
185      * @param p a {@link java.util.Properties} object.
186      */
187     void writeProperties(java.util.Properties p) {
188         // better to version settings since initial version as advocated at
189         // http://wiki.apidesign.org/wiki/PropertyFiles
190         p.setProperty("version", "1.0");
191         // TODO store your settings
192     }
193     /**
194      * <p>readProperties.</p>
195      *
196      * @param p a {@link java.util.Properties} object.
197      */
198     void readProperties(java.util.Properties p) {
199         String version = p.getProperty("version");
200         // TODO read your settings according to their version
201     }
202 
203     /**
204      * Get this QueuePanel table instance
205      *
206      * @return JTable table
207      */
208     public JTable getTable() {
209         return table;
210     }
211 
212     /**
213      * Set the Status value in the QueuePanel table to a specified value at the
214      * required position
215      *
216      * @param position location in the table to change value.
217      * @param value the value to change to
218      */
219     protected void setStatus(int position, int value) {
220         table.getModel().setValueAt(value, position, 1);
221     }
222 
223     /**
224      * Set the Percentage value in the QueuePanel table to a specified value at the
225      * required position
226      *
227      * @param position location in the table to change value.
228      * @param value the value to change to
229      */
230     protected void setPercentage(int position, String value) {
231         table.getModel().setValueAt(value, position, 2);
232     }
233 
234     /**
235      * Set the Project value in the QueuePanel table to a specified value at the
236      * required position
237      *
238      * @param position location in the table to change value.
239      * @param value the value to change to
240      */
241     protected void setProject(int position, String value) {
242         table.getModel().setValueAt(value, position, 3);
243     }
244 }