GraphElement.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 package com.generalrobotix.ui.view.graph;
11 
12 //import java.awt.*;
13 //import java.awt.event.*;
14 
15 import org.eclipse.swt.SWT;
16 import org.eclipse.swt.custom.SashForm;
17 import org.eclipse.swt.events.MouseEvent;
18 import org.eclipse.swt.events.MouseListener;
19 import org.eclipse.swt.events.PaintEvent;
20 import org.eclipse.swt.events.PaintListener;
21 import org.eclipse.swt.events.SelectionListener;
22 import org.eclipse.swt.graphics.Color;
23 import org.eclipse.swt.graphics.Font;
24 import org.eclipse.swt.layout.GridData;
25 import org.eclipse.swt.layout.GridLayout;
26 import org.eclipse.swt.widgets.Composite;
29 
37 public class GraphElement extends Composite implements MouseListener
38  // implements MouseListener, ActionListener
39 {
40  SashForm graphPane_; // 分割ペイン
41  DroppableXYGraph graph_; // グラフ
42  LegendPanel legend_; // 凡例
43  TrendGraph tg_; // トレンドグラフ
44  GraphPanel gp_;
45 
46  SelectionListener actionListener_; // アクションリスナ列
47 
48  private static final int GRAPH_LEFT_MARGIN = 50;
49  private static final int GRAPH_RIGHT_MARGIN = 50;
50  private static final int GRAPH_TOP_MARGIN = 20;
51  private static final int GRAPH_BOTTOM_MARGIN = 30;
52 
53  private static final Color normalColor_ = Activator.getDefault().getColor("black");
54  private static final Font GRAPH_LEGEND_FONT = Activator.getDefault().getFont( "dialog12" );
55  // -----------------------------------------------------------------
56  // コンストラクタ
64  public GraphElement(
65  GraphPanel gp,
66  Composite parent,
67  TrendGraph tg
68  ) {
69  super(parent, SWT.NONE);
70 
71  // 参照保存
72  tg_ = tg; // トレンドグラフ
73  gp_ = gp;
74 
75  GridData gridData0 = new GridData();
76  gridData0.horizontalAlignment = GridData.FILL;
77  gridData0.grabExcessHorizontalSpace = true;
78  setLayoutData(gridData0);
79 
80  GridLayout layout=new GridLayout(1,true);
81  layout.marginHeight=0;
82  setLayout(layout);
83 
84  // スプリットペイン
85  graphPane_ = new SashForm( this, SWT.HORIZONTAL );
86  GridData gridData = new GridData();
87  gridData.horizontalAlignment = GridData.FILL;
88  gridData.grabExcessHorizontalSpace = true;
89  gridData.verticalAlignment = GridData.FILL;
90  gridData.grabExcessVerticalSpace = true;
91  graphPane_.setLayoutData(gridData);
92 
93  graph_ = new DroppableXYGraph(
94  graphPane_,
95  GRAPH_LEFT_MARGIN,
96  GRAPH_RIGHT_MARGIN,
97  GRAPH_TOP_MARGIN,
98  GRAPH_BOTTOM_MARGIN
99  );
100  legend_ = new LegendPanel(
101  graphPane_,
102  Activator.getDefault().getFont( "dialog10" ),
103  Activator.getDefault().getColor("black"),
104  Activator.getDefault().getColor("white")
105  );
106  graphPane_.setWeights(new int[] { 4,1});
107  graphPane_.SASH_WIDTH = 6;
108 
109  ((XYLineGraph)graph_).setBorderColor(normalColor_);
110  legend_.setBackColor(normalColor_);
111  legend_.setFont(GRAPH_LEGEND_FONT);
112 
113  tg.setGraph((XYLineGraph) graph_, legend_);
114 
115  // リスナ設定
116  // ((DroppableXYGraph)graph_).addActionListener(this); // ドロップアクションリスナ
117  graph_.addMouseListener(this);
118  legend_.addMouseListener(this);
119  // graphPane_.addMouseListener(this);
120  // addMouseListener(this);
121  }
122 
123  // -----------------------------------------------------------------
124  // メソッド
131  return tg_;
132  }
133 
140  return graph_;
141  }
142 
149  return legend_;
150  }
151 /*
152  // -----------------------------------------------------------------
153  // ActionListener登録および削除
154  public void addActionListener(ActionListener listener) {
155  actionListener_ = AWTEventMulticaster.add(actionListener_, listener);
156  }
157  public void removeActionListener(ActionListener listener) {
158  actionListener_ = AWTEventMulticaster.remove(actionListener_, listener);
159  }
160 
161  // -----------------------------------------------------------------
162  // MouseListenerの実装
163  public void mousePressed(MouseEvent evt) {
164  //System.out.println("Clicked");
165  raiseActionEvent();
166  }
167  public void mouseClicked(MouseEvent evt){}
168  public void mouseEntered(MouseEvent evt){}
169  public void mouseExited(MouseEvent evt) {}
170  public void mouseReleased(MouseEvent evt){}
171 
172  // -----------------------------------------------------------------
173  // ActionListenerの実装
174  public void actionPerformed(ActionEvent evt) {
175  /*
176  int result = tg_.addDataItem(
177  (AttributeInfo)(((DroppableXYGraph)graph_).getDroppedObject())
178  );
179  if (result == TrendGraph.SUCCEEDED) { // 成功?
180  ((DroppableXYGraph)graph_).setDropSucceeded(true);
181  raiseActionEvent();
182  repaint();
183  } else if (result == TrendGraph.NOT_MATCHED) { // データ種別不一致?
184  ((DroppableXYGraph)graph_).setDropSucceeded(false);
185  new ErrorDialog(
186  (Frame)null,
187  MessageBundle.get("dialog.graph.mismatch.title"),
188  MessageBundle.get("dialog.graph.mismatch.message")
189  ).showModalDialog();
190  } else { // データ種別非サポート
191  ((DroppableXYGraph)graph_).setDropSucceeded(false);
192  new ErrorDialog(
193  (Frame)null,
194  MessageBundle.get("dialog.graph.unsupported.title"),
195  MessageBundle.get("dialog.graph.unsupported.message")
196  ).showModalDialog();
197  }
198 
199  }
200 */
206  /*
207  private void raiseActionEvent() {
208  if(actionListener_ != null) {
209  actionListener_.actionPerformed(
210  new ActionEvent(
211  this,
212  ActionEvent.ACTION_PERFORMED,
213  CMD_CLICKED
214  )
215  );
216  }
217  }
218 */
219  public void setBorderColor(Color color) {
220  graph_.setBorderColor(color);
221  legend_.setBackColor(color);
222 
223  }
224 
225  public void mouseDoubleClick(MouseEvent e) {
226  // TODO 自動生成されたメソッド・スタブ
227 
228  }
229 
230  public void mouseDown(MouseEvent e) {
231  // TODO 自動生成されたメソッド・スタブ
232 
233  }
234 
235  public void mouseUp(MouseEvent e) {
236  gp_.setFocuse(this);
237  }
238 }
void setGraph(XYLineGraph graph, LegendPanel legend)
Definition: TrendGraph.java:90
GraphElement(GraphPanel gp, Composite parent, TrendGraph tg)
org


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