/[svn]/jsampler/trunk/src/org/jsampler/task/UpdateChannels.java
ViewVC logotype

Diff of /jsampler/trunk/src/org/jsampler/task/UpdateChannels.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1143 by iliev, Mon Apr 2 21:18:31 2007 UTC revision 1737 by iliev, Thu May 8 17:26:19 2008 UTC
# Line 22  Line 22 
22    
23  package org.jsampler.task;  package org.jsampler.task;
24    
25    import java.util.Vector;
26  import java.util.logging.Level;  import java.util.logging.Level;
27    
28  import org.jsampler.CC;  import org.jsampler.CC;
# Line 29  import org.jsampler.HF; Line 30  import org.jsampler.HF;
30  import org.jsampler.SamplerChannelModel;  import org.jsampler.SamplerChannelModel;
31  import org.jsampler.SamplerModel;  import org.jsampler.SamplerModel;
32    
33    import org.linuxsampler.lscp.SamplerChannel;
34    
35    import net.sf.juife.Task;
36    
37  import static org.jsampler.JSI18n.i18n;  import static org.jsampler.JSI18n.i18n;
38    
39    
# Line 52  public class UpdateChannels extends Enha Line 57  public class UpdateChannels extends Enha
57                          Integer[] chnIDs = CC.getClient().getSamplerChannelIDs();                          Integer[] chnIDs = CC.getClient().getSamplerChannelIDs();
58                                                    
59                          boolean found = false;                          boolean found = false;
60                                                            
61                          for(SamplerChannelModel m : sm.getChannelModels()) {                          boolean oldValue = CC.getSamplerModel().getChannelListIsAdjusting();
62                            
63                            javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
64                                    public void
65                                    run() {
66                                            CC.getSamplerModel().setChannelListIsAdjusting(true);
67                                            CC.getMainFrame().setAutoUpdateChannelListUI(false);
68                                    }
69                            });
70                            
71                            for(SamplerChannelModel m : sm.getChannels()) {
72                                  for(int i = 0; i < chnIDs.length; i++) {                                  for(int i = 0; i < chnIDs.length; i++) {
73                                          if(m.getChannelId() == chnIDs[i]) {                                          if(m.getChannelId() == chnIDs[i]) {
74                                                  chnIDs[i] = -1;                                                  chnIDs[i] = -1;
# Line 61  public class UpdateChannels extends Enha Line 76  public class UpdateChannels extends Enha
76                                          }                                          }
77                                  }                                  }
78                                                                    
79                                  if(!found) sm.removeChannel(m.getChannelId());                                  if(!found) sm.removeChannelById(m.getChannelId());
80                                  found = false;                                  found = false;
81                          }                          }
82                                                    
83                            Vector<SamplerChannel> v = new Vector<SamplerChannel>();
84                          for(int id : chnIDs) {                          for(int id : chnIDs) {
85                                  if(id >= 0) sm.addChannel(CC.getClient().getSamplerChannelInfo(id));                                  if(id >= 0) v.add(CC.getClient().getSamplerChannelInfo(id));
86                            }
87                            
88                            for(int i = 0; i < v.size() - 1; i++) sm.addChannel(v.elementAt(i));
89                            
90                            manageAutoUpdate(false);
91                            
92                            if(v.size() > 0) sm.addChannel(v.elementAt(v.size() - 1));
93                            else if(!CC.getSamplerModel().getChannelListIsAdjusting()) {
94                                    if(oldValue) sm.addChannel(null);
95                          }                          }
96                  } catch(Exception x) {                  } catch(Exception x) {
97                          setErrorMessage(getDescription() + ": " + HF.getErrorMessage(x));                          setErrorMessage(getDescription() + ": " + HF.getErrorMessage(x));
98                          CC.getLogger().log(Level.FINE, getErrorMessage(), x);                          CC.getLogger().log(Level.FINE, getErrorMessage(), x);
99                            manageAutoUpdate(true);
100                    }
101            }
102            
103            private void
104            manageAutoUpdate(boolean force) {
105                    if(!force) {
106                            Task[] tasks = CC.getTaskQueue().getPendingTasks();
107                            for(Task t : tasks) if(t.equals(this)) return;
108                  }                  }
109                    
110                    javax.swing.SwingUtilities.invokeLater(new Runnable() {
111                            public void
112                            run() {
113                                    CC.getSamplerModel().setChannelListIsAdjusting(false);
114                                    CC.getMainFrame().setAutoUpdateChannelListUI(true);
115                                    CC.getMainFrame().updateChannelListUI();
116                            }
117                    });
118            }
119                    
120            /**
121             * Used to decrease the traffic. All task in the queue
122             * equal to this are removed if added using {@link org.jsampler.CC#scheduleTask}.
123             * @see org.jsampler.CC#addTask
124             */
125            public boolean
126            equals(Object obj) {
127                    if(obj == null) return false;
128                    if(!(obj instanceof UpdateChannels)) return false;
129                    
130                    return true;
131          }          }
132  }  }

Legend:
Removed from v.1143  
changed lines
  Added in v.1737

  ViewVC Help
Powered by ViewVC