001/**
002 * Copyright (C) 2014  Universidade de Aveiro, DETI/IEETA, Bioinformatics Group - http://bioinformatics.ua.pt/
003 *
004 * This file is part of Dicoogle/dicoogle.
005 *
006 * Dicoogle/dicoogle 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 * Dicoogle/dicoogle 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 Dicoogle.  If not, see <http://www.gnu.org/licenses/>.
018 */
019
020
021/*
022 * 
023 * 
024 * TaskList.java
025 *
026 * Created on Jul 20, 2010, 10:21:21 AM
027 */
028
029package pt.ua.dicoogle.rGUI.client.windows;
030
031import java.awt.event.ActionEvent;
032import java.awt.event.ActionListener;
033import java.util.ArrayList;
034import javax.swing.JProgressBar;
035import javax.swing.Timer;
036import pt.ua.dicoogle.rGUI.interfaces.controllers.ITaskList;
037import pt.ua.dicoogle.rGUI.interfaces.signals.ITaskListSignal;
038import pt.ua.dicoogle.sdk.datastructs.Report;
039import pt.ua.dicoogle.sdk.task.Task;
040
041/**
042 *
043 * @author Luís A. Bastião Silva <bastiao@ua.pt>
044 */
045@Deprecated
046public final class TaskList extends javax.swing.JPanel {
047
048    private static ITaskList taskList;
049    private static ITaskListSignal tasksSignal;
050
051    class PairTaskProgress{
052        public Task task;
053        public JProgressBar bar;
054    }
055    private ArrayList<PairTaskProgress> tasks = new ArrayList<>();
056    
057    Timer timer;
058    
059    /** Creates new form TaskList */
060    public TaskList(){
061        initComponents();
062        
063        ActionListener updateTask = new ActionListener() {
064            @Override
065            public void actionPerformed(ActionEvent e) {
066                updateProgress();
067            }
068        };
069        
070        timer = new Timer(1000,updateTask);
071        timer.start();
072        
073        //registerRemoteObject();
074        //getTaskList();
075
076    }
077
078    public void updateProgress(){
079        ArrayList<PairTaskProgress> ntasks = new ArrayList<>();
080        for(PairTaskProgress task : tasks){
081            //otherwise updates it
082           task.bar.setValue((int)(task.task.getProgress()*100));
083            if(task.task.isDone()){
084                remove(task.bar);
085            }
086            else{
087                ntasks.add(task);
088            }
089        }
090        tasks = ntasks;
091        
092        revalidate();
093        repaint();
094    }
095    
096    public void add(Iterable<Task<Report>> tasks){
097                
098        for(Task<Report> task : tasks){
099            JProgressBar bar = new JProgressBar(0,100);
100            bar.setString(task.getName()+" -> "+task.getProgress());
101            bar.setValue((int)(task.getProgress()*100)+10);
102            
103            PairTaskProgress pair = new PairTaskProgress();
104            pair.task = task;
105            pair.bar = bar;
106            //scrollPanel.add(pair.bar);
107            this.tasks.add(pair);
108            add(bar);
109
110        }
111        updateProgress();
112    }
113    
114
115
116    /** This method is called from within the constructor to
117     * initialize the form.
118     * WARNING: Do NOT modify this code. The content of this method is
119     * always regenerated by the Form Editor.
120     */
121    @SuppressWarnings("unchecked")
122    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
123    private void initComponents() {
124
125        jLabel1 = new javax.swing.JLabel();
126        jSeparator1 = new javax.swing.JSeparator();
127
128        setLayout(new javax.swing.BoxLayout(this, javax.swing.BoxLayout.Y_AXIS));
129
130        jLabel1.setText("Task Progress");
131        add(jLabel1);
132        add(jSeparator1);
133    }// </editor-fold>//GEN-END:initComponents
134    // Variables declaration - do not modify//GEN-BEGIN:variables
135    private javax.swing.JLabel jLabel1;
136    private javax.swing.JSeparator jSeparator1;
137    // End of variables declaration//GEN-END:variables
138
139}