GraphElement.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 package com.generalrobotix.ui.view.graph;
00011 
00012 //import java.awt.*;
00013 //import java.awt.event.*;
00014 
00015 import org.eclipse.swt.SWT;
00016 import org.eclipse.swt.custom.SashForm;
00017 import org.eclipse.swt.events.MouseEvent;
00018 import org.eclipse.swt.events.MouseListener;
00019 import org.eclipse.swt.events.PaintEvent;
00020 import org.eclipse.swt.events.PaintListener;
00021 import org.eclipse.swt.events.SelectionListener;
00022 import org.eclipse.swt.graphics.Color;
00023 import org.eclipse.swt.graphics.Font;
00024 import org.eclipse.swt.layout.GridData;
00025 import org.eclipse.swt.layout.GridLayout;
00026 import org.eclipse.swt.widgets.Composite;
00027 import com.generalrobotix.ui.grxui.Activator;
00028 import com.generalrobotix.ui.view.graph.LegendPanel;
00029 
00037 public class GraphElement extends Composite implements MouseListener
00038  //   implements MouseListener, ActionListener
00039 {
00040         SashForm graphPane_;  // 分割ペイン
00041         DroppableXYGraph graph_;      // グラフ
00042         LegendPanel legend_;     // 凡例
00043     TrendGraph tg_;         // トレンドグラフ
00044     GraphPanel gp_;
00045 
00046     SelectionListener actionListener_; // アクションリスナ列
00047 
00048     private static final int GRAPH_LEFT_MARGIN = 50;
00049     private static final int GRAPH_RIGHT_MARGIN = 50;
00050     private static final int GRAPH_TOP_MARGIN = 20;
00051     private static final int GRAPH_BOTTOM_MARGIN = 30;
00052 
00053     private static final Color normalColor_ = Activator.getDefault().getColor("black");
00054     private static final Font GRAPH_LEGEND_FONT = Activator.getDefault().getFont( "dialog12" );
00055     // -----------------------------------------------------------------
00056     // コンストラクタ
00064     public GraphElement(
00065         GraphPanel gp,
00066         Composite parent,
00067         TrendGraph tg
00068     ) {
00069         super(parent, SWT.NONE);
00070 
00071         // 参照保存
00072         tg_ = tg;   // トレンドグラフ
00073         gp_ = gp;
00074         
00075         GridData gridData0 = new GridData();
00076                 gridData0.horizontalAlignment = GridData.FILL;
00077                 gridData0.grabExcessHorizontalSpace = true;
00078                 setLayoutData(gridData0);
00079         
00080                 GridLayout layout=new GridLayout(1,true);
00081                 layout.marginHeight=0;
00082                 setLayout(layout);
00083          
00084         // スプリットペイン
00085         graphPane_ = new SashForm( this, SWT.HORIZONTAL  );
00086         GridData gridData = new GridData();
00087                 gridData.horizontalAlignment = GridData.FILL;
00088                 gridData.grabExcessHorizontalSpace = true;
00089                 gridData.verticalAlignment = GridData.FILL;
00090                 gridData.grabExcessVerticalSpace = true;
00091                 graphPane_.setLayoutData(gridData);
00092                 
00093         graph_ = new DroppableXYGraph(
00094                         graphPane_, 
00095                 GRAPH_LEFT_MARGIN,
00096                 GRAPH_RIGHT_MARGIN,
00097                 GRAPH_TOP_MARGIN,
00098                 GRAPH_BOTTOM_MARGIN
00099             );
00100         legend_ = new LegendPanel(
00101                         graphPane_,
00102                         Activator.getDefault().getFont( "dialog10" ),
00103                         Activator.getDefault().getColor("black"),
00104                         Activator.getDefault().getColor("white")
00105             );
00106         graphPane_.setWeights(new int[] { 4,1});
00107         graphPane_.SASH_WIDTH = 6;
00108         
00109         ((XYLineGraph)graph_).setBorderColor(normalColor_);
00110         legend_.setBackColor(normalColor_);
00111         legend_.setFont(GRAPH_LEGEND_FONT);
00112 
00113         tg.setGraph((XYLineGraph) graph_, legend_);
00114 
00115         // リスナ設定
00116        // ((DroppableXYGraph)graph_).addActionListener(this); // ドロップアクションリスナ
00117         graph_.addMouseListener(this);
00118         legend_.addMouseListener(this);
00119        // graphPane_.addMouseListener(this);
00120        // addMouseListener(this);
00121     }
00122 
00123     // -----------------------------------------------------------------
00124     // メソッド
00130     public TrendGraph getTrendGraph() {
00131         return tg_;
00132     }
00133 
00139     public DroppableXYGraph getGraph() {
00140         return graph_;
00141     }
00142 
00148     public LegendPanel getLegend() {
00149         return legend_;
00150     }
00151 /*
00152     // -----------------------------------------------------------------
00153     // ActionListener登録および削除
00154     public void addActionListener(ActionListener listener) {
00155         actionListener_ = AWTEventMulticaster.add(actionListener_, listener);
00156     }
00157     public void removeActionListener(ActionListener listener) {
00158         actionListener_ = AWTEventMulticaster.remove(actionListener_, listener);
00159     }
00160 
00161     // -----------------------------------------------------------------
00162     // MouseListenerの実装
00163     public void mousePressed(MouseEvent evt) {
00164         //System.out.println("Clicked");
00165         raiseActionEvent();
00166     }
00167     public void mouseClicked(MouseEvent evt){}
00168     public void mouseEntered(MouseEvent evt){}
00169     public void mouseExited(MouseEvent evt) {}
00170     public void mouseReleased(MouseEvent evt){}
00171 
00172     // -----------------------------------------------------------------
00173     // ActionListenerの実装
00174     public void actionPerformed(ActionEvent evt) {
00175         /*
00176         int result = tg_.addDataItem(
00177             (AttributeInfo)(((DroppableXYGraph)graph_).getDroppedObject())
00178         );
00179         if (result == TrendGraph.SUCCEEDED) {   // 成功?
00180             ((DroppableXYGraph)graph_).setDropSucceeded(true);
00181             raiseActionEvent();
00182             repaint();
00183         } else if (result == TrendGraph.NOT_MATCHED) {  // データ種別不一致?
00184             ((DroppableXYGraph)graph_).setDropSucceeded(false);
00185             new ErrorDialog(
00186                 (Frame)null,
00187                 MessageBundle.get("dialog.graph.mismatch.title"),
00188                 MessageBundle.get("dialog.graph.mismatch.message")
00189             ).showModalDialog();
00190         } else {    // データ種別非サポート
00191             ((DroppableXYGraph)graph_).setDropSucceeded(false);
00192             new ErrorDialog(
00193                 (Frame)null,
00194                 MessageBundle.get("dialog.graph.unsupported.title"),
00195                 MessageBundle.get("dialog.graph.unsupported.message")
00196             ).showModalDialog();
00197         }
00198         
00199     }
00200 */
00206     /*
00207     private void raiseActionEvent() {
00208         if(actionListener_ != null) {
00209             actionListener_.actionPerformed(
00210                 new ActionEvent(
00211                     this,
00212                     ActionEvent.ACTION_PERFORMED,
00213                     CMD_CLICKED
00214                 )
00215             );
00216         }
00217     }
00218 */
00219         public void setBorderColor(Color color) {
00220                 graph_.setBorderColor(color);
00221                 legend_.setBackColor(color);
00222                 
00223         }
00224 
00225         public void mouseDoubleClick(MouseEvent e) {
00226                 // TODO 自動生成されたメソッド・スタブ
00227                 
00228         }
00229         
00230         public void mouseDown(MouseEvent e) {
00231                 // TODO 自動生成されたメソッド・スタブ
00232                 
00233         }
00234         
00235         public void mouseUp(MouseEvent e) {
00236                 gp_.setFocuse(this);
00237         }
00238 }


openhrp3
Author(s): AIST, General Robotix Inc., Nakamura Lab of Dept. of Mechano Informatics at University of Tokyo
autogenerated on Thu Apr 11 2019 03:30:16