GrxLoggerView.java
Go to the documentation of this file.
1 // -*- indent-tabs-mode: nil; tab-width: 4; -*-
2 /*
3  * Copyright (c) 2008, AIST, the University of Tokyo and General Robotix Inc.
4  * All rights reserved. This program is made available under the terms of the
5  * Eclipse Public License v1.0 which accompanies this distribution, and is
6  * available at http://www.eclipse.org/legal/epl-v10.html
7  * Contributors:
8  * General Robotix Inc.
9  * National Institute of Advanced Industrial Science and Technology (AIST)
10  */
11 /*
12  * GrxLoggerView.java
13  *
14  * Copyright (C) 2007 GeneralRobotix, Inc.
15  * All Rights Reserved
16  *
17  * @author Yuichiro Kawasumi (General Robotix, Inc.)
18  */
19 
20 package com.generalrobotix.ui.view;
21 
22 import java.text.DecimalFormat;
23 
24 import org.eclipse.swt.SWT;
25 import org.eclipse.swt.events.KeyEvent;
26 import org.eclipse.swt.events.KeyListener;
27 import org.eclipse.swt.events.SelectionAdapter;
28 import org.eclipse.swt.events.SelectionEvent;
29 import org.eclipse.swt.events.MouseEvent;
30 import org.eclipse.swt.events.MouseListener;
31 import org.eclipse.swt.events.MouseTrackListener;
32 import org.eclipse.swt.events.MouseMoveListener;
33 import org.eclipse.swt.layout.GridData;
34 import org.eclipse.swt.layout.GridLayout;
35 import org.eclipse.swt.widgets.Button;
36 import org.eclipse.swt.widgets.Composite;
37 import org.eclipse.swt.widgets.Display;
38 import org.eclipse.swt.widgets.Label;
39 import org.eclipse.swt.widgets.Scale;
40 import org.eclipse.swt.widgets.Text;
41 import org.eclipse.ui.IActionBars;
42 import org.eclipse.jface.action.Action;
43 
54 
55 @SuppressWarnings("serial") //$NON-NLS-1$
59 public class GrxLoggerView extends GrxBaseView {
60  public static final String TITLE = "Logger"; //$NON-NLS-1$
61 
62  private GrxWorldStateItem currentItem_=null;
63  private GrxSimulationItem simItem_=null;
64 
65  private int current_ = 0; // current position
66  private double playRate_ = 1.0; // playback rate
67  private int frameRate_ = defaultFrameRate_;
68  private boolean isPlaying_ = false;
69  private boolean isControlDisabled_ = false;
70  private boolean inSimulation_ = false;
71  private boolean buttonClick_ = false;
72 
73  // widgets
74  private Scale sliderFrameRate_;
75  private Label lblFrameRate_;
76  private Scale sliderTime_;
77 
78 
79  private Button btnFrameF_;
80  private Button btnFrameR_;
81  private Button[] btns_ = new Button[2];
82 
83  private String[] btnToolTips = new String[] {
84  MessageBundle.get("GrxLoggerView.text.oneRwd"), MessageBundle.get("GrxLoggerView.text.onePlay") //$NON-NLS-1$ //$NON-NLS-2$
85  };
86 
87  private final static String[] icons_ = { "icon_frame-.png", "icon_frame+.png" };//$NON-NLS-1$ //$NON-NLS-2$
88 
89  private Text tFldTime_;
90 
91  private Action[] toolActs_ = new Action[6];
92  private String[] actToolTips_ = new String[] {
93  MessageBundle.get("GrxLoggerView.text.fastRwd"),MessageBundle.get("GrxLoggerView.text.slowRwd"), //$NON-NLS-1$ //$NON-NLS-2$
94  MessageBundle.get("GrxLoggerView.text.pause"), MessageBundle.get("GrxLoggerView.text.play"), //$NON-NLS-1$ //$NON-NLS-2$
95  MessageBundle.get("GrxLoggerView.text.slowFwd"), MessageBundle.get("GrxLoggerView.text.fastFwd") //$NON-NLS-1$ //$NON-NLS-2$
96  };
97  private final static String[] actIcons_ = {
98  "icon_fastrwd.png", //$NON-NLS-1$
99  "icon_slowrwd.png", //$NON-NLS-1$
100  "icon_pause.png", //$NON-NLS-1$
101  "icon_playback.png", //$NON-NLS-1$
102  "icon_slowfwd.png", //$NON-NLS-1$
103  "icon_fastfwd.png" }; //$NON-NLS-1$
104  private final static String[] actDIcons_ = {
105  "icond_fastrwd.png", //$NON-NLS-1$
106  "icond_slowrwd.png", //$NON-NLS-1$
107  "icond_pause.png", //$NON-NLS-1$
108  "icond_playback.png", //$NON-NLS-1$
109  "icond_slowfwd.png", //$NON-NLS-1$
110  "icond_fastfwd.png" }; //$NON-NLS-1$
111 
112  private final static int maxFrameRate_ = 50;
113  private final static int defaultFrameRate_ = 10;
114  private Label lblPlayRate_;
115 
116  private static DecimalFormat FORMAT_FAST = new DecimalFormat("Play x ##;Play x-##"); //$NON-NLS-1$
117  private static DecimalFormat FORMAT_SLOW = new DecimalFormat("Play x 1/##;Play x-1/##"); //$NON-NLS-1$
118  private static String timeFormat = "%8.3f"; //"###0.000" //$NON-NLS-1$
119 
120  //private static final Font MONO_PLAIN_12 = new Font("Monospaced", Font.PLAIN, 12);
121 
122  private int mouseBtnActionNum = 0;
123  private int mouseBtnRepeat_ = 200;
124  private int mouseBtnAccelNeed_ = 5;
125  private int mouseBtnAccelRepeat_ = 30;
126  private boolean isMouseOverBtnR_ = false;
127  private boolean isMouseOverBtnF_ = false;
128  private Runnable backPosRun_;
129  private Runnable forwardPosRun_;
130 
132  // ログ1コマ毎の間隔
133  double logTimeStepMs_;
134  // 前回描画時刻
135  long prevDispNs_;
136  // 次回タイマー起動時刻
137  long nextTimerNs_;
138  final long mills2nano = 1000 * 1000;
139 
147  public GrxLoggerView(String name, GrxPluginManager manager, GrxBaseViewPart vp, Composite parent) {
148  super(name, manager, vp, parent);
149 
150  GridLayout gl = new GridLayout(6,false);
151  gl.marginHeight = 0;
152  composite_.setLayout( gl );
153 
154  // playback rate label
155  lblPlayRate_ = new Label( composite_, SWT.NONE);
156  lblPlayRate_.setText(MessageBundle.get("GrxLoggerView.label.pause")); //$NON-NLS-1$
157  GridData lblGridData = new GridData();
158  lblGridData.widthHint = 80;
159  lblPlayRate_.setLayoutData(lblGridData);
160 
161 
162  // playback controller
163  Composite btnComp = new Composite ( composite_, SWT.NONE);
164  GridLayout buttonLayout = new GridLayout(2,false);
165  buttonLayout.marginHeight = 0;
166  buttonLayout.marginWidth = 0;
167  btnComp.setLayout( buttonLayout );
168 
169  btnFrameR_ = new Button( btnComp, SWT.NONE );
170 
171  btnFrameR_.addMouseTrackListener(new MouseTrackListener(){
172  public void mouseEnter(MouseEvent e){
173  isMouseOverBtnR_ = true;
174  }
175  public void mouseExit(MouseEvent e){
176  isMouseOverBtnR_ = false;
177  }
178  public void mouseHover(MouseEvent e){
179  }
180  });
181 
182  btnFrameR_.addMouseMoveListener(new MouseMoveListener(){
183  public void mouseMove(MouseEvent e){
184  isMouseOverBtnR_ = (0 <= e.x && e.x < btnFrameR_.getSize().x && 0 <= e.y && e.y < btnFrameR_.getSize().y);
185  }
186  });
187  btnFrameR_.addMouseListener(new MouseListener(){
188  public void mouseDoubleClick(MouseEvent e){
189  }
190  public void mouseDown(MouseEvent e) {
191  if(e.button == 1){
192  backPosition();
193  startBackPosTimer();
194  }
195  }
196  public void mouseUp(MouseEvent e) {
197  if(e.button == 1){
198  stopBackPosTimer();
199  }
200  }
201  });
202 
203  btnFrameF_ = new Button( btnComp, SWT.NONE );
204 
205  btnFrameF_.addMouseTrackListener(new MouseTrackListener(){
206  public void mouseEnter(MouseEvent e){
207  isMouseOverBtnF_ = true;
208  }
209  public void mouseExit(MouseEvent e){
210  isMouseOverBtnF_ = false;
211  }
212  public void mouseHover(MouseEvent e){
213  }
214  });
215 
216  btnFrameF_.addMouseMoveListener(new MouseMoveListener(){
217  public void mouseMove(MouseEvent e){
218  isMouseOverBtnF_ = (0 <= e.x && e.x < btnFrameF_.getSize().x && 0 <= e.y && e.y < btnFrameF_.getSize().y);
219  }
220  });
221  btnFrameF_.addMouseListener(new MouseListener(){
222  public void mouseDoubleClick(MouseEvent e){
223  }
224  public void mouseDown(MouseEvent e) {
225  if(e.button == 1){
226  forwardPosition();
227  startForwardPosTimer();
228  }
229  }
230  public void mouseUp(MouseEvent e) {
231  if(e.button == 1){
232  stopForwardPosTimer();
233  }
234  }
235  });
236 
237  btns_[0] = btnFrameR_;
238  btns_[1] = btnFrameF_;
239 
240  for(int i=0; i<btns_.length; i++) {
241  btns_[i].setImage( Activator.getDefault().getImage( icons_[i] ) );
242  btns_[i].setToolTipText( btnToolTips[i] );
243  }
244 
245  // text field to display current time
246  tFldTime_ = new Text(composite_, SWT.SINGLE|SWT.BORDER);
247  tFldTime_.setText(MessageBundle.get("GrxLoggerView.text.noData")); //$NON-NLS-1$
248  GridData textGridData = new GridData();
249  textGridData.widthHint = 60;
250  tFldTime_.setLayoutData(textGridData);
251  tFldTime_.addKeyListener(new KeyListener(){
252  public void keyPressed(KeyEvent e) {}
253  public void keyReleased(KeyEvent e) {
254  if (e.character == SWT.CR) {
255  String str = tFldTime_.getText();
256  try{
257  double tm = Double.parseDouble(str);
258  int newpos = currentItem_.getPositionAt(tm);
259  if (newpos >= 0){
260  currentItem_.setPosition(newpos);
261  }
262  }catch(Exception ex){
263 
264  }
265  }
266  }
267  });
268 
269  //時間変更スライダ
270  sliderTime_ = new Scale( composite_, SWT.NONE );
271  sliderTime_.addSelectionListener(new SelectionAdapter(){
272  public void widgetSelected(SelectionEvent e){
273  currentItem_.setPosition(sliderTime_.getSelection());
274  buttonClick_ = true;
275  }
276  } );
277  sliderTime_.addKeyListener(new KeyListener(){
278  public void keyPressed(KeyEvent e) {
279  if (e.keyCode == SWT.ARROW_LEFT || e.keyCode == SWT.ARROW_DOWN){
280  if (isPlaying_)
281  pause();
282  currentItem_.setPosition(sliderTime_.getSelection());
283  }else if (e.keyCode == SWT.ARROW_RIGHT || e.keyCode == SWT.ARROW_UP){
284  if (isPlaying_)
285  pause();
286  currentItem_.setPosition(sliderTime_.getSelection());
287  }
288  }
289  public void keyReleased(KeyEvent e) {
290  }
291  });
292  GridData gd = new GridData(SWT.HORIZONTAL|SWT.FILL|GridData.FILL_HORIZONTAL);
293  sliderTime_.setLayoutData(gd);
294 
295  // frame rate
296  lblFrameRate_ = new Label(composite_, SWT.NONE);
297  lblFrameRate_.setText(MessageBundle.get("GrxLoggerView.label.FPS")+defaultFrameRate_); //$NON-NLS-1$
298 
299  // フレームレート変更スライダ
300  sliderFrameRate_ = new Scale( composite_, SWT.HORIZONTAL );
301  //sliderFrameRate_.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
302  sliderFrameRate_.setSize(80, 27);
303  sliderFrameRate_.setMaximum(maxFrameRate_);
304  sliderFrameRate_.setMinimum(1);
305  sliderFrameRate_.setSelection(defaultFrameRate_);
306  sliderFrameRate_.addSelectionListener(new SelectionAdapter(){
307  public void widgetSelected(SelectionEvent e){
308  frameRate_ = sliderFrameRate_.getSelection();
309  lblFrameRate_.setText( MessageBundle.get("GrxLoggerView.label.FPS")+String.valueOf(frameRate_) ); //$NON-NLS-1$
310  }
311  } );
312 
313  Action actFRwd_ = new Action(){
314  public void run(){
315  if (!isPlaying_)
316  playRate_ = -2.0;
317  else if (playRate_ > 0)
318  playRate_ *= -1;
319  else if (playRate_ > -64)
320  playRate_ *= 2.0;
321  buttonClick_ = true;
322  play();
323  }
324  };
325 
326  Action actSRwd_ = new Action(){
327  public void run(){
328  if (!isPlaying_)
329  playRate_ = -1.0/8.0;
330  else if (playRate_ > 0)
331  playRate_ *= -1;
332  else if (1/playRate_ > -64)
333  playRate_ *= 0.5;
334  buttonClick_ = true;
335  play();
336  }
337  };
338  Action actPause_ = new Action(){
339  public void run(){
340  pause();
341  }
342  };
343 
344  Action actPlay_ = new Action(){
345  public void run(){
346  playRate_ = 1.0;
347  buttonClick_ = true;
348  play();
349  }
350  };
351 
352  Action actSFwd_ = new Action(){
353  public void run(){
354  if (!isPlaying_)
355  playRate_ = 1.0/8.0;
356  else if (playRate_ < 0)
357  playRate_ *= -1;
358  else if (1/playRate_ < 64)
359  playRate_ *= 0.5;
360  buttonClick_ = true;
361  play();
362  }
363  };
364 
365  Action actFFwd_ = new Action(){
366  public void run(){
367  if (!isPlaying_)
368  playRate_ = 2.0;
369  else if (playRate_ < 0)
370  playRate_ *= -1;
371  else if (playRate_ < 64)
372  playRate_ *= 2.0;
373  buttonClick_ = true;
374  play();
375  }
376  };
377 
378  toolActs_[0] = actFRwd_;
379  toolActs_[1] = actSRwd_;
380  toolActs_[2] = actPause_;
381  toolActs_[3] = actPlay_;
382  toolActs_[4] = actSFwd_;
383  toolActs_[5] = actFFwd_;
384  IActionBars bars = vp.getViewSite().getActionBars();
385  for(int i = 0; i < toolActs_.length; i++) {
386  toolActs_[i].setImageDescriptor( Activator.getDefault().getDescriptor(actIcons_[i]) );
387  toolActs_[i].setDisabledImageDescriptor(Activator.getDefault().getDescriptor(actDIcons_[i]));
388  toolActs_[i].setToolTipText( actToolTips_[i] );
389  bars.getToolBarManager().add(toolActs_[i]);
390  }
391 
392 
393  backPosRun_ = new Runnable() {
394  public void run() {
395  Display display = btnFrameR_.getDisplay();
396  if (!display.isDisposed())
397  {
398  if(isMouseOverBtnR_)
399  {
400  mouseBtnActionNum += 1;
401  backPosition();
402  }
403  display.timerExec((mouseBtnActionNum < mouseBtnAccelNeed_ ? mouseBtnRepeat_ : mouseBtnAccelRepeat_), this);
404  }
405  }
406  };
407  forwardPosRun_ = new Runnable() {
408  public void run() {
409  Display display = btnFrameF_.getDisplay();
410  if (!display.isDisposed())
411  {
412  if(isMouseOverBtnF_)
413  {
414  mouseBtnActionNum += 1;
415  forwardPosition();
416  }
417  display.timerExec((mouseBtnActionNum < mouseBtnAccelNeed_ ? mouseBtnRepeat_ : mouseBtnAccelRepeat_), this);
418  }
419  }
420  };
421 
422  setScrollMinSize(SWT.DEFAULT,SWT.DEFAULT);
423 
424  setUp();
425  manager_.registerItemChangeListener(this, GrxWorldStateItem.class);
426  manager_.registerItemChangeListener(this, GrxSimulationItem.class);
427  }
428 
429  public void setUp(){
430  if(currentItem_ != null){
431  currentItem_.deleteObserver(this);
432  currentItem_.deletePosObserver(this);
433  }
434  currentItem_ = manager_.<GrxWorldStateItem>getSelectedItem(GrxWorldStateItem.class, null);
435  if(currentItem_!=null){
436  _setTimeSeriesItem(currentItem_);
437  currentItem_.addObserver(this);
438  currentItem_.addPosObserver(this);
439  updatePosition(currentItem_, currentItem_.getPosition());
440  }else
441  _setTimeSeriesItem(null);
442  if(simItem_ != null)
443  simItem_.deleteObserver(this);
444  simItem_ = manager_.<GrxSimulationItem>getSelectedItem(GrxSimulationItem.class, null);
445  if(simItem_!=null){
446  simItem_.addObserver(this);
447  }
448  }
449 
450  private boolean _isAtTheEndAfterPlayback(){
451  if (current_ == currentItem_.getLogSize()-1 && playRate_ > 0){
452  return true;
453  }else{
454  return false;
455  }
456  }
457 
458 
459  private void play() {
460  if(currentItem_ == null) return;
461  if (!isPlaying_) {
462  if (_isAtTheEndAfterPlayback()) currentItem_.setPosition(0);
463 
464  if(inSimulation_){
465  logTimeStepMs_ = currentItem_.getDbl("logTimeStep", 0.001)*1000; //$NON-NLS-1$
466  }
467  else{
468  // ログの時間間隔は一定として最初の1区間の間隔を読み込む。
469  if(currentItem_.getLogSize() < 2){
470  logTimeStepMs_ = currentItem_.getDbl("logTimeStep", 0.001)*1000;
471  }else{
472  logTimeStepMs_ = (currentItem_.getTime(1) - currentItem_.getTime(0))*1000;
473  }
474  }
475 
476  Runnable playRun_ = new Runnable() {
477  public void run() {
478  if(!isPlaying_) return;
479 
480  long nowNs = System.nanoTime();
481  boolean _continue = true;
482 
483  int diffpos = (int)((nowNs - prevDispNs_) / (logTimeStepMs_ * mills2nano) * playRate_);
484  int sliderMax = currentItem_.getLogSize()-1;
485  int newpos;
486  if(inSimulation_ && !buttonClick_)
487  newpos = sliderMax;
488  else
489  newpos = current_ + diffpos;
490  if (sliderMax < newpos) {
491  newpos = sliderMax;
492  if(!inSimulation_)
493  _continue = false;
494  } else if (newpos < 0) {
495  newpos = 0;
496  if(!inSimulation_)
497  _continue = false;
498  }
499 
500  if(newpos != current_){
501  //GrxDebugUtil.println(String.format("nowNs : %15d, pos : %d, logtime : %12.3f",
502  // (long)(nowNs/mills2nano), newpos, currentItem_.getTime(newpos)));
503  diffpos = newpos - current_;
504  currentItem_.setPosition(newpos);
505  prevDispNs_ += (long)((logTimeStepMs_ * mills2nano) * diffpos / playRate_);
506  }
507 
508  if(_continue){
509  nowNs = System.nanoTime();
510  int sleepTime = (int)((1000.0d/frameRate_) - ((nowNs - nextTimerNs_) / mills2nano));
511  //GrxDebugUtil.println(String.format("nowNs : %15d, next : %15d, sleep: %6d",
512  // (long)(nowNs/mills2nano), (long)(nextTimerNs_/mills2nano), sleepTime));
513  if(sleepTime < 1) sleepTime = 1;
514  nextTimerNs_ = nowNs + (sleepTime * mills2nano);
515  Display display = composite_.getDisplay();
516  if (!display.isDisposed())
517  display.timerExec(sleepTime, this);
518  }else{
519  pause();
520  }
521  }
522  };
523 
524  isPlaying_ = true;
525  long nowNs = System.nanoTime();
526  prevDispNs_ = nowNs;
527  int sleepTime = (int)(1000.0d/frameRate_);
528  nextTimerNs_ = nowNs + (sleepTime * mills2nano);
529  Display display = composite_.getDisplay();
530  if (!display.isDisposed())
531  display.timerExec(sleepTime, playRun_);
532  }
533  if (Math.abs(playRate_)<1.0)
534  lblPlayRate_.setText(FORMAT_SLOW.format(1/playRate_));
535  else
536  lblPlayRate_.setText(FORMAT_FAST.format(playRate_));
537  }
538 
542  public void pause() {
543  isPlaying_ = false;
544  lblPlayRate_.setText(MessageBundle.get("GrxLoggerView.label.pause")); //$NON-NLS-1$
545  }
546 
551  public boolean isPlaying() {
552  return isPlaying_;
553  }
554 
558  public void restoreProperties() {
559  super.restoreProperties();
560 
561  timeFormat = getStr("timeFormat", "%8.3f"); //$NON-NLS-1$ //$NON-NLS-2$
562  GrxDebugUtil.println("LoggerView: timeFormat = \""+timeFormat+"\"\n"); //$NON-NLS-1$ //$NON-NLS-2$
563  }
564 
566  current_ = 0;
567  sliderTime_.setSelection(0);
568  if (item != null){
569  _updateTimeField(item);
570  int size = item.getLogSize();
571  if(size > 0){
572  sliderTimeSetMaximam(item.getLogSize());
573  setEnabled(true);
574  }else{
575  sliderTimeSetMaximam(1);
576  setEnabled(false);
577  }
578  }else{
579  sliderTimeSetMaximam(1);
580  setEnabled(false);
581  }
582  }
583 
584  public void registerItemChange(GrxBaseItem item, int event){
585  if(item instanceof GrxWorldStateItem){
586  GrxWorldStateItem worldStateItem = (GrxWorldStateItem) item;
587  switch(event){
589  if(currentItem_!=worldStateItem){
590  _setTimeSeriesItem(worldStateItem);
591  currentItem_ = worldStateItem;
592  currentItem_.addObserver(this);
593  currentItem_.addPosObserver(this);
594  updatePosition(currentItem_, currentItem_.getPosition());
595  }
596  break;
599  if(currentItem_==worldStateItem){
600  currentItem_.deleteObserver(this);
601  currentItem_.deletePosObserver(this);
602  _setTimeSeriesItem(null);
603  currentItem_ = null;
604  }
605  break;
606  default:
607  break;
608  }
609  }else if(item instanceof GrxSimulationItem){
610  GrxSimulationItem simItem = (GrxSimulationItem) item;
611  switch(event){
613  if(simItem_!=simItem){
614  simItem_ = simItem;
615  simItem_.addObserver(this);
616  }
617  break;
620  if(simItem_==simItem){
621  simItem_.deleteObserver(this);
622  simItem_ = null;
623  }
624  break;
625  default:
626  break;
627  }
628  }
629  }
630 
635  Double t = item.getTime();
636  if (t != null) {
637  tFldTime_.setText(String.format(timeFormat, t));
638  setEnabled(true);
639  } else if (item.getLogSize() == 0){
640  tFldTime_.setText(MessageBundle.get("GrxLoggerView.text.noData")); //$NON-NLS-1$
641  setEnabled(false);
642  }
643  }
644 
649  public int getMaximum() {
650  return sliderTime_.getMaximum();
651  }
652 
657  public int getCurrentPos() {
658  return current_;
659  }
660 
661  public void update(GrxBasePlugin plugin, Object... arg) {
662  if(simItem_==plugin){
663  if((String)arg[0]=="StartSimulation"){ //$NON-NLS-1$
664  inSimulation_ = true;
665  buttonClick_ = false;
666  lblPlayRate_.setText(MessageBundle.get("GrxLoggerView.label.live")); //$NON-NLS-1$
667  if((Boolean)arg[1])
668  disableControl();
669  else{
670  playRate_ = 1;
671  play();
672  }
673  }else if((String)arg[0]=="StopSimulation"){ //$NON-NLS-1$
674  inSimulation_ = false;
675  lblPlayRate_.setText(MessageBundle.get("GrxLoggerView.label.pause")); //$NON-NLS-1$
676  enableControl();
677  pause();
678  }
679  }else if(currentItem_==plugin) {
680  if((String)arg[0]=="ClearLog"){ //$NON-NLS-1$
681  if(isPlaying())
682  pause();
683  _setTimeSeriesItem(currentItem_);
684  }else if((String)arg[0]=="LoadLog"){
685  _setTimeSeriesItem(currentItem_ );
686  updatePosition(currentItem_, currentItem_.getPosition());
687  }
688  }
689  }
690 
691  public void updatePosition(GrxBasePlugin plugin, Integer arg_pos){
692  if(currentItem_ != plugin)
693  return;
694 
695  int pos = arg_pos.intValue();
696  int logSize = currentItem_.getLogSize();
697  if ( pos < 0 || logSize < pos){
698  return;
699  }
700  current_ = pos;
701  sliderTimeSetMaximam(logSize-1);
702  sliderTime_.setSelection(pos);
703  _updateTimeField(currentItem_);
704  }
705 
710  public double getPlayRate() {
711  return playRate_;
712  }
713 
714  private void setEnabled(boolean b) {
715  if (isControlDisabled_) return;
716  sliderTime_.setEnabled(b);
717  tFldTime_.setEnabled(b);
718  lblPlayRate_.setEnabled(b);
719  for (int i=0; i<btns_.length; i++)
720  btns_[i].setEnabled(b);
721 
722  for (int i=0; i<toolActs_.length; i++)
723  toolActs_[i].setEnabled(b);
724 
725  }
726 
727  public void disableControl() {
728  setEnabled(false);
729  isControlDisabled_ = true;
730  }
731 
732  public void enableControl() {
733  isControlDisabled_ = false;
734  setEnabled(true);
735  }
736 
737  public void shutdown() {
738  manager_.removeItemChangeListener(this, GrxWorldStateItem.class);
739  if(currentItem_!=null)
740  {
741  currentItem_.deleteObserver(this);
742  currentItem_.deletePosObserver(this);
743  }
744  if(simItem_!=null)
745  simItem_.deleteObserver(this);
746  manager_.removeItemChangeListener(this, GrxSimulationItem.class);
747  }
748 
749  private void sliderTimeSetMaximam(int value)
750  {
751  sliderTime_.setMaximum(value);
752 
753  if(value < 150)
754  sliderTime_.setPageIncrement(5);
755  if(value < 1500)
756  sliderTime_.setPageIncrement(50);
757  else
758  sliderTime_.setPageIncrement(500);
759  }
760 
761  private void backPosition(){
762  if (isPlaying_)
763  pause();
764  currentItem_.setPosition(sliderTime_.getSelection()-1);
765  }
766  private void forwardPosition(){
767  if (isPlaying_)
768  pause();
769  currentItem_.setPosition(sliderTime_.getSelection()+1);
770  }
771  private void startBackPosTimer(){
772  mouseBtnActionNum = 0;
773 
774  Display display = btnFrameR_.getDisplay();
775  if (!display.isDisposed())
776  {
777  display.timerExec(mouseBtnRepeat_, backPosRun_);
778  }
779  }
780  private void stopBackPosTimer(){
781  mouseBtnActionNum = 0;
782 
783  Display display = btnFrameR_.getDisplay();
784  if (!display.isDisposed())
785  {
786  display.timerExec(-1, backPosRun_);
787  }
788  }
789  private void startForwardPosTimer(){
790  mouseBtnActionNum = 0;
791 
792  Display display = btnFrameF_.getDisplay();
793  if (!display.isDisposed())
794  {
795  display.timerExec(mouseBtnRepeat_, forwardPosRun_);
796  }
797  }
798  private void stopForwardPosTimer(){
799  mouseBtnActionNum = 0;
800 
801  Display display = btnFrameF_.getDisplay();
802  if (!display.isDisposed())
803  {
804  display.timerExec(-1, forwardPosRun_);
805  }
806  }
807 }
void registerItemChange(GrxBaseItem item, int event)
static final String get(String key)
#define null
our own NULL pointer
Definition: IceTypes.h:57
GrxLoggerView(String name, GrxPluginManager manager, GrxBaseViewPart vp, Composite parent)
png_uint_32 size
Definition: png.h:1521
png_infop png_charpp name
Definition: png.h:2382
png_voidp int value
Definition: png.h:2113
void _setTimeSeriesItem(GrxWorldStateItem item)
png_uint_32 i
Definition: png.h:2735
long b
Definition: jpegint.h:371
void update(GrxBasePlugin plugin, Object...arg)
def run(tree, args)
void updatePosition(GrxBasePlugin plugin, Integer arg_pos)
t
final Double getDbl(String key, Double defaultVal)
get double value associated to key
typedef int
Definition: png.h:1113
プラグイン管理クラス GrxUIの核になるクラス。プラグインのロード等の、初期化を実行する。 プラグインとそ...
boolean isPlaying()
check where playing now or not
org
void _updateTimeField(GrxWorldStateItem item)
char * arg
Definition: cdjpeg.h:136


openhrp3
Author(s): AIST, General Robotix Inc., Nakamura Lab of Dept. of Mechano Informatics at University of Tokyo
autogenerated on Sat May 8 2021 02:42:38