GrxProcessManagerView.java
Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2008, AIST, the University of Tokyo and General Robotix Inc.
00003  * All rights reserved. This program is made available under the terms of the
00004  * Eclipse Public License v1.0 which accompanies this distribution, and is
00005  * available at http://www.eclipse.org/legal/epl-v10.html
00006  * Contributors:
00007  * General Robotix Inc.
00008  * National Institute of Advanced Industrial Science and Technology (AIST) 
00009  */
00010 /*
00011  *  GrxProcessManagerView.java
00012  *
00013  *  Copyright (C) 2007 GeneralRobotix, Inc.
00014  *  All Rights Reserved
00015  *
00016  *  @author Yuichiro Kawasumi (General Robotix, Inc.)
00017  */
00018 
00019 package com.generalrobotix.ui.view;
00020 
00021 import java.util.ArrayList;
00022 import java.util.Vector;
00023 
00024 import org.eclipse.jface.action.Action;
00025 import org.eclipse.jface.action.IMenuListener;
00026 import org.eclipse.jface.action.IMenuManager;
00027 import org.eclipse.jface.action.MenuManager;
00028 import org.eclipse.swt.SWT;
00029 import org.eclipse.swt.custom.LineStyleEvent;
00030 import org.eclipse.swt.custom.LineStyleListener;
00031 import org.eclipse.swt.custom.StyleRange;
00032 import org.eclipse.swt.custom.StyledText;
00033 import org.eclipse.swt.events.DisposeListener;
00034 import org.eclipse.swt.events.DisposeEvent;
00035 import org.eclipse.swt.graphics.Color;
00036 import org.eclipse.swt.widgets.Composite;
00037 
00038 import com.generalrobotix.ui.GrxBasePlugin;
00039 import com.generalrobotix.ui.GrxBaseView;
00040 import com.generalrobotix.ui.GrxBaseViewPart;
00041 import com.generalrobotix.ui.GrxPluginManager;
00042 import com.generalrobotix.ui.grxui.Activator;
00043 import com.generalrobotix.ui.util.GrxProcessManager;
00044 import com.generalrobotix.ui.util.MessageBundle;
00045 import com.generalrobotix.ui.util.GrxProcessManager.AProcess;
00046 
00047 @SuppressWarnings("serial")
00048 public class GrxProcessManagerView extends GrxBaseView
00049     implements DisposeListener {
00050     public static final String TITLE          = "Process Manager";
00051     private StyledText              outputArea_      = null;
00052     public GrxProcessManager   processManager_ = null;
00053 
00054     public GrxProcessManagerView(String name, GrxPluginManager manager,
00055             GrxBaseViewPart vp, Composite parent) {
00056         super(name, manager, vp, parent);
00057         
00058         initializeComposite();     
00059         composite_.addDisposeListener(this);
00060         processManager_ = (GrxProcessManager) manager.getItem("processManager");
00061         if(processManager_!=null){
00062                 outputArea_.setText("");
00063                 String[] processed = processManager_.getOutputBuffer().toString().split("\n", -1);
00064                 for (int i = 0; i < processed.length; i++) {
00065                         if(processed[i].startsWith("[")){
00066                                 String id=processed[i].substring(1, processed[i].indexOf(":"));
00067                                 AProcess p =processManager_.get(id);
00068                                 if(p.showOutput())
00069                                         outputArea_.append(processed[i] + "\n");
00070                         }
00071                 }
00072                 processManager_.clearBuffer();
00073         }
00074         isScrollable_ = false;
00075 
00076         if(processManager_!=null)
00077                 processManager_.addObserver(this);
00078         
00079     }
00080 
00081     public String[] getMenuPath() {
00082         return new String[] { "Tools" };
00083     }
00084     
00085     public void initializeComposite() {
00086         outputArea_ = new StyledText(composite_, SWT.MULTI | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
00087         outputArea_.setEditable(false);
00088         outputArea_.addLineStyleListener(new HilightListener());
00089         
00090         // 右クリックメニューを自動再生成させる
00091         MenuManager manager = new MenuManager();
00092         manager.setRemoveAllWhenShown(true);
00093         manager.addMenuListener(new IMenuListener() {
00094             public void menuAboutToShow(IMenuManager menu) {
00095                 for (Action action : getOutputMenu()) {
00096                     menu.add(action);
00097                 }
00098             }
00099         });
00100         outputArea_.setMenu(manager.createContextMenu(outputArea_));
00101     }
00102     
00103     private Vector<Action> getOutputMenu() {
00104         Vector<Action> vector = new Vector<Action>(size());
00105         for (int i = 0; i < processManager_.size(); i++) {
00106             final AProcess p = processManager_.get(i);
00107             Action action = new Action(p.pi_.id, Action.AS_CHECK_BOX) {
00108                 public void run() {
00109                     p.setShowOutput(isChecked());
00110                     String[] processed = processManager_.getOutputBuffer().toString().split("\n"); //$NON-NLS-1$
00111                     outputArea_.setText(""); //$NON-NLS-1$
00112                     for (int i = 0; i < processed.length; i++) {
00113                         for (int j = 0; j < processManager_.size(); j++) {
00114                             AProcess p2 = processManager_.get(j);
00115                             if (p2.showOutput() && processed[i].startsWith("[" + p2.pi_.id)) { //$NON-NLS-1$
00116                                 outputArea_.append(processed[i] + "\n"); //$NON-NLS-1$
00117                             }
00118 
00119                         }
00120                     }
00121                 }
00122             };
00123             action.setChecked(p.showOutput());
00124             vector.add(action);
00125         }
00126 
00127         Action actionClearAll = new Action(MessageBundle.get("GrxProcessManager.menu.clearAll1"), Action.AS_PUSH_BUTTON) { //$NON-NLS-1$
00128             public void run() {
00129                 outputArea_.setText(""); //$NON-NLS-1$
00130                 processManager_.setOutputBuffer(new StringBuffer());
00131             }
00132         };
00133         vector.add(actionClearAll);
00134         return vector;
00135 
00136     }
00137     
00138     public void update(GrxBasePlugin plugin, Object... arg) {
00139         if(processManager_!=plugin) return;
00140         if((String)arg[0]=="append"){
00141                 outputArea_.append((String)arg[1]);
00142         }else if((String)arg[0]=="setTopIndex"){
00143                 outputArea_.setTopIndex(outputArea_.getLineCount());
00144         }
00145     }
00146     
00147     public void shutdown() {
00148         if(processManager_!=null)
00149                 processManager_.deleteObserver(this);
00150     }
00151 
00152     public void widgetDisposed(DisposeEvent e){
00153         processManager_.stopType();
00154     }
00155   
00156         public static class HilightListener implements LineStyleListener {
00157                 public void lineGetStyle(LineStyleEvent event) {
00158                         String string = event.lineText;
00159                     StyleRange[] styles = new StyleRange[1];
00160                     styles[0] = new StyleRange();
00161                     if(string.startsWith("[")){
00162                         int i=string.indexOf(']');
00163                         if(i>0){
00164                                 char c = string.charAt(i-1);
00165                                 if(c=='E'){
00166                                         styles[0].start  = event.lineOffset;
00167                                         styles[0].length = string.length();
00168                                         styles[0].foreground = Activator.getDefault().getColor("red");
00169                                 }
00170                         }       
00171                 }
00172                     event.styles = styles;
00173                 }
00174         }
00175 }


openhrp3
Author(s): AIST, General Robotix Inc., Nakamura Lab of Dept. of Mechano Informatics at University of Tokyo
autogenerated on Sun Apr 2 2017 03:43:54