GrxProcessManagerView.java
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2008, AIST, the University of Tokyo and General Robotix Inc.
3  * All rights reserved. This program is made available under the terms of the
4  * Eclipse Public License v1.0 which accompanies this distribution, and is
5  * available at http://www.eclipse.org/legal/epl-v10.html
6  * Contributors:
7  * General Robotix Inc.
8  * National Institute of Advanced Industrial Science and Technology (AIST)
9  */
10 /*
11  * GrxProcessManagerView.java
12  *
13  * Copyright (C) 2007 GeneralRobotix, Inc.
14  * All Rights Reserved
15  *
16  * @author Yuichiro Kawasumi (General Robotix, Inc.)
17  */
18 
19 package com.generalrobotix.ui.view;
20 
21 import java.util.ArrayList;
22 import java.util.Vector;
23 
24 import org.eclipse.jface.action.Action;
25 import org.eclipse.jface.action.IMenuListener;
26 import org.eclipse.jface.action.IMenuManager;
27 import org.eclipse.jface.action.MenuManager;
28 import org.eclipse.swt.SWT;
29 import org.eclipse.swt.custom.LineStyleEvent;
30 import org.eclipse.swt.custom.LineStyleListener;
31 import org.eclipse.swt.custom.StyleRange;
32 import org.eclipse.swt.custom.StyledText;
33 import org.eclipse.swt.events.DisposeListener;
34 import org.eclipse.swt.events.DisposeEvent;
35 import org.eclipse.swt.graphics.Color;
36 import org.eclipse.swt.widgets.Composite;
37 
46 
47 @SuppressWarnings("serial")
48 public class GrxProcessManagerView extends GrxBaseView
49  implements DisposeListener {
50  public static final String TITLE = "Process Manager";
51  private StyledText outputArea_ = null;
52  public GrxProcessManager processManager_ = null;
53 
55  GrxBaseViewPart vp, Composite parent) {
56  super(name, manager, vp, parent);
57 
58  initializeComposite();
59  composite_.addDisposeListener(this);
60  processManager_ = (GrxProcessManager) manager.getItem("processManager");
61  if(processManager_!=null){
62  outputArea_.setText("");
63  String[] processed = processManager_.getOutputBuffer().toString().split("\n", -1);
64  for (int i = 0; i < processed.length; i++) {
65  if(processed[i].startsWith("[")){
66  String id=processed[i].substring(1, processed[i].indexOf(":"));
67  AProcess p =processManager_.get(id);
68  if(p.showOutput())
69  outputArea_.append(processed[i] + "\n");
70  }
71  }
72  processManager_.clearBuffer();
73  }
74  isScrollable_ = false;
75 
76  if(processManager_!=null)
77  processManager_.addObserver(this);
78 
79  }
80 
81  public String[] getMenuPath() {
82  return new String[] { "Tools" };
83  }
84 
85  public void initializeComposite() {
86  outputArea_ = new StyledText(composite_, SWT.MULTI | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
87  outputArea_.setEditable(false);
88  outputArea_.addLineStyleListener(new HilightListener());
89 
90  // 右クリックメニューを自動再生成させる
91  MenuManager manager = new MenuManager();
92  manager.setRemoveAllWhenShown(true);
93  manager.addMenuListener(new IMenuListener() {
94  public void menuAboutToShow(IMenuManager menu) {
95  for (Action action : getOutputMenu()) {
96  menu.add(action);
97  }
98  }
99  });
100  outputArea_.setMenu(manager.createContextMenu(outputArea_));
101  }
102 
103  private Vector<Action> getOutputMenu() {
104  Vector<Action> vector = new Vector<Action>(size());
105  for (int i = 0; i < processManager_.size(); i++) {
106  final AProcess p = processManager_.get(i);
107  Action action = new Action(p.pi_.id, Action.AS_CHECK_BOX) {
108  public void run() {
109  p.setShowOutput(isChecked());
110  String[] processed = processManager_.getOutputBuffer().toString().split("\n"); //$NON-NLS-1$
111  outputArea_.setText(""); //$NON-NLS-1$
112  for (int i = 0; i < processed.length; i++) {
113  for (int j = 0; j < processManager_.size(); j++) {
114  AProcess p2 = processManager_.get(j);
115  if (p2.showOutput() && processed[i].startsWith("[" + p2.pi_.id)) { //$NON-NLS-1$
116  outputArea_.append(processed[i] + "\n"); //$NON-NLS-1$
117  }
118 
119  }
120  }
121  }
122  };
123  action.setChecked(p.showOutput());
124  vector.add(action);
125  }
126 
127  Action actionClearAll = new Action(MessageBundle.get("GrxProcessManager.menu.clearAll1"), Action.AS_PUSH_BUTTON) { //$NON-NLS-1$
128  public void run() {
129  outputArea_.setText(""); //$NON-NLS-1$
130  processManager_.setOutputBuffer(new StringBuffer());
131  }
132  };
133  vector.add(actionClearAll);
134  return vector;
135 
136  }
137 
138  public void update(GrxBasePlugin plugin, Object... arg) {
139  if(processManager_!=plugin) return;
140  if((String)arg[0]=="append"){
141  outputArea_.append((String)arg[1]);
142  }else if((String)arg[0]=="setTopIndex"){
143  outputArea_.setTopIndex(outputArea_.getLineCount());
144  }
145  }
146 
147  public void shutdown() {
148  if(processManager_!=null)
149  processManager_.deleteObserver(this);
150  }
151 
152  public void widgetDisposed(DisposeEvent e){
153  processManager_.stopType();
154  }
155 
156  public static class HilightListener implements LineStyleListener {
157  public void lineGetStyle(LineStyleEvent event) {
158  String string = event.lineText;
159  StyleRange[] styles = new StyleRange[1];
160  styles[0] = new StyleRange();
161  if(string.startsWith("[")){
162  int i=string.indexOf(']');
163  if(i>0){
164  char c = string.charAt(i-1);
165  if(c=='E'){
166  styles[0].start = event.lineOffset;
167  styles[0].length = string.length();
168  styles[0].foreground = Activator.getDefault().getColor("red");
169  }
170  }
171  }
172  event.styles = styles;
173  }
174  }
175 }
void update(GrxBasePlugin plugin, Object... arg)
static final String get(String key)
int c
Definition: autoplay.py:16
#define null
our own NULL pointer
Definition: IceTypes.h:57
png_uint_32 size
Definition: png.h:1521
png_infop png_charpp name
Definition: png.h:2382
manager
png_uint_32 i
Definition: png.h:2735
GrxProcessManagerView(String name, GrxPluginManager manager, GrxBaseViewPart vp, Composite parent)
def run(tree, args)
GrxBaseItem getItem(Class<? extends GrxBaseItem > cls, String name)
プラグイン管理クラス GrxUIの核になるクラス。プラグインのロード等の、初期化を実行する。 プラグインとそ...
org
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 Thu Sep 8 2022 02:24:03