GraphPanel.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  */
16 package com.generalrobotix.ui.view.graph;
17 
18 import java.util.Enumeration;
19 import java.util.List;
20 
21 import org.eclipse.jface.dialogs.IDialogConstants;
22 import org.eclipse.jface.dialogs.MessageDialog;
23 import org.eclipse.jface.resource.StringConverter;
24 import org.eclipse.swt.SWT;
25 import org.eclipse.swt.custom.SashForm;
26 import org.eclipse.swt.custom.ScrolledComposite;
27 import org.eclipse.swt.events.PaintEvent;
28 import org.eclipse.swt.events.PaintListener;
29 import org.eclipse.swt.events.SelectionAdapter;
30 import org.eclipse.swt.events.SelectionEvent;
31 import org.eclipse.swt.graphics.Color;
32 import org.eclipse.swt.layout.GridData;
33 import org.eclipse.swt.layout.GridLayout;
34 import org.eclipse.swt.layout.RowLayout;
35 import org.eclipse.swt.widgets.Button;
36 import org.eclipse.swt.widgets.Composite;
37 import org.eclipse.swt.widgets.Label;
38 import org.eclipse.swt.widgets.Scale;
39 
45 
46 @SuppressWarnings("serial") //$NON-NLS-1$
47 public class GraphPanel extends Composite{
48  //--------------------------------------------------------------------
52  private List<GrxModelItem> currentModels_ = null;
53 
54  private static final Color normalColor_ = Activator.getDefault().getColor("black");
55  private static final Color focusedColor_ = Activator.getDefault().getColor( "focusedColor" ); //$NON-NLS-1$
56 
57  private SashForm graphElementBase_;
58 
59  private Button hRangeButton_;
60  private Button vRangeButton_;
61  private Button seriesButton_;
62  //private Button epsButton_;
63 
64  public void setEnabled(boolean b) {
65  hRangeButton_.setEnabled(b);
66  vRangeButton_.setEnabled(b);
67  seriesButton_.setEnabled(b);
68  //epsButton_.setEnabled(b);
69  }
70 
71  public void setEnabledRangeButton(boolean b) {
72  hRangeButton_.setEnabled(b);
73  vRangeButton_.setEnabled(b);
74  }
75 
79  //private EPSDialog epsDialog_;
80 
81  private ScrolledComposite graphScrollPane_;
82 
83  private int numGraph_;
86 
87  public GraphPanel(GrxPluginManager manager, TrendGraphModel trendGraphMgr, Composite comp) {
88  super(comp, SWT.NONE);
89  manager_ = manager;
90  trendGraphMgr_ = trendGraphMgr;
91 
92  setLayout(new GridLayout(1,true));
93  graphScrollPane_ = new ScrolledComposite(this, SWT.H_SCROLL | SWT.V_SCROLL| SWT.BORDER);
94  graphScrollPane_.setExpandHorizontal(true);
95  graphScrollPane_.setExpandVertical(true);
96  GridData gridData0 = new GridData();
97  gridData0.horizontalAlignment = GridData.FILL;
98  gridData0.grabExcessHorizontalSpace = true;
99  gridData0.verticalAlignment = GridData.FILL;
100  gridData0.grabExcessVerticalSpace = true;
101  graphScrollPane_.setLayoutData(gridData0);
102  Composite graphControlPanel = new Composite(this, SWT.NONE);
103  GridData gridData1 = new GridData();
104  gridData1.horizontalAlignment = GridData.FILL;
105  gridData1.grabExcessHorizontalSpace = true;
106  graphControlPanel.setLayoutData(gridData1);
107  graphControlPanel.setLayout(new RowLayout());
108  graphElementBase_ = new SashForm(graphScrollPane_, SWT.VERTICAL);
109  graphElementBase_.SASH_WIDTH = 6;
110  graphScrollPane_.setContent(graphElementBase_);
111 
112  numGraph_ = trendGraphMgr_.getNumGraph();
113  graphElement_ = new GraphElement[numGraph_];
114  for (int i = 0; i < numGraph_; i ++) {
115  graphElement_[i] =
116  new GraphElement(
117  this,
118  graphElementBase_,
119  trendGraphMgr_.getTrendGraph(i) );
120  }
121  graphScrollPane_.setMinSize(graphElementBase_.computeSize(SWT.DEFAULT, SWT.DEFAULT));
122 
123  currentGraph_ = graphElement_[0];
124  graphElement_[0].setBorderColor(focusedColor_);
125 
126  hRangeButton_ = new Button(graphControlPanel, SWT.PUSH);
127  hRangeButton_.setText(MessageBundle.get("GraphPanel.button.hrange")); //$NON-NLS-1$
128  hRangeDialog_ = new HRangeDialog(graphControlPanel.getShell());
129  hRangeButton_.addSelectionListener(new SelectionAdapter(){
130  public void widgetSelected(SelectionEvent e) {
131  GrxGraphItem graphItem = manager_.<GrxGraphItem>getSelectedItem(GrxGraphItem.class, null);
132  if (graphItem == null)
133  return;
134  hRangeDialog_.setMaxHRange(trendGraphMgr_.getTotalTime());
135  hRangeDialog_.setMinHRange(trendGraphMgr_.getStepTime() * 10);
136  double range = trendGraphMgr_.getTimeRange();
137  double pos = trendGraphMgr_.getMarkerPos();
138  hRangeDialog_.setHRange(range);
139  hRangeDialog_.setMarkerPos(pos);
140  if(hRangeDialog_.open() == IDialogConstants.OK_ID){
141  int flag = hRangeDialog_.getUpdateFlag();
142  if (flag != 0) {
143  TrendGraph tg = currentGraph_.getTrendGraph();
144  double hRange = hRangeDialog_.getHRange();
145  double mpos = hRangeDialog_.getMarkerPos();
146  if ((flag & HRangeDialog.RANGE_UPDATED) != 0
147  || (flag & HRangeDialog.POS_UPDATED) != 0) {
148  tg.setTimeRangeAndPos(hRange, mpos);
149  }
150  graphItem.setDblAry("timeRange", new double[]{hRange, mpos}); //$NON-NLS-1$
151  trendGraphMgr_.updateGraph();
152  }
153  }
154  }
155  });
156 
157  vRangeButton_ = new Button(graphControlPanel, SWT.PUSH);
158  vRangeButton_.setText(MessageBundle.get("GraphPanel.button.vrange")); //$NON-NLS-1$
159  vRangeDialog_ = new VRangeDialog(graphControlPanel.getShell());
160  vRangeButton_.addSelectionListener(new SelectionAdapter(){
161  public void widgetSelected(SelectionEvent e) {
162  TrendGraph tg = currentGraph_.getTrendGraph();
163  vRangeDialog_.setUnit(tg.getUnitLabel());
164  vRangeDialog_.setBase(tg.getBase());
165  vRangeDialog_.setExtent(tg.getExtent());
166  if(vRangeDialog_.open() == IDialogConstants.OK_ID){
167  double base = vRangeDialog_.getBase();
168  double extent = vRangeDialog_.getExtent();
169  tg.setRange(base, extent);
170  GrxGraphItem graphItem = manager_.<GrxGraphItem>getSelectedItem(GrxGraphItem.class, null);
171  if (graphItem == null)
172  return;
173  graphItem.setDblAry(currentGraph_.getTrendGraph().getNodeName()+".vRange", new double[]{base, extent}); //$NON-NLS-1$
174  redraw(getLocation().x,getLocation().y,getSize().x,getSize().y,true);
175  }
176  }
177  }
178  );
179 
180  seriesButton_ = new Button(graphControlPanel, SWT.PUSH);
181  seriesButton_.setText(MessageBundle.get("GraphPanel.button.series")); //$NON-NLS-1$
182 
183  seriesDialog_ = new SeriesDialog(currentGraph_, graphControlPanel.getShell());
184  seriesButton_.addSelectionListener(new SelectionAdapter(){
185  public void widgetSelected(SelectionEvent e) {
186  GrxGraphItem graphItem = manager_.<GrxGraphItem>getSelectedItem(GrxGraphItem.class, null);
187  if (graphItem == null)
188  {
189  if(MessageDialog.openQuestion(
190  null,
191  MessageBundle.get("GraphPanel.dialog.creategraph.title"),
192  MessageBundle.get("GraphPanel.dialog.creategraph.message")))
193  {
194  graphItem = (GrxGraphItem)manager_.createItem(GrxGraphItem.class, null);
195  manager_.itemChange(graphItem, GrxPluginManager.ADD_ITEM);
196  manager_.setSelectedItem(graphItem, true);
197  }
198  else
199  return;
200  }
201 
202  TrendGraph tg = currentGraph_.getTrendGraph();
203  seriesDialog_.setModelList(currentModels_);
204  seriesDialog_.setDataItemInfoList(tg.getDataItemInfoList());
205  if(seriesDialog_.open() == IDialogConstants.OK_ID){
206  DataItemInfo[] dii = seriesDialog_.getDataItemInfoList();
207  for (int i = 0; i < dii.length; i++) {
208  tg.setDataItemInfo(dii[i]);
209  }
210  dii = seriesDialog_.getRemovedList();
211  for (int i = 0; i < dii.length; i++) {
212  tg.removeDataItem(dii[i]);
213  }
214 
215  addedArray_ = seriesDialog_.getAddedList();
216  for (int i = 0; i < addedArray_.length; i++) {
217  tg.addDataItem(addedArray_[i]);
218  }
219 
220  String graphName = tg.getNodeName();
221  Enumeration<?> enume = graphItem.propertyNames();
222  while (enume.hasMoreElements()) {
223  String key = (String)enume.nextElement();
224  if (key.startsWith(graphName))
225  graphItem.remove(key);
226  }
227  String dataItems = ""; //$NON-NLS-1$
228  DataItemInfo[] list = tg.getDataItemInfoList();
229  for (int i = 0; i<list.length;i++) {
230  DataItem di = list[i].dataItem;
231  String header = tg._getDataItemNodeName(di);
232  if (i > 0)
233  dataItems += ","; //$NON-NLS-1$
234  dataItems += graphName+"_"+di.object+"_"+di.node+"_"+di.attribute; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
235  if (di.index >= 0)
236  dataItems += "_"+di.index; //$NON-NLS-1$
237  graphItem.setProperty(header+".object",di.object); //$NON-NLS-1$
238  graphItem.setProperty(header+".node",di.node); //$NON-NLS-1$
239  graphItem.setProperty(header+".attr",di.attribute); //$NON-NLS-1$
240  graphItem.setProperty(header+".index", String.valueOf(di.index)); //$NON-NLS-1$
241  graphItem.setProperty(header+".legend", list[i].legend); //$NON-NLS-1$
242  graphItem.setProperty(header+".color", StringConverter.asString(list[i].color)); //$NON-NLS-1$
243  }
244  graphItem.setProperty(graphName+".dataItems",dataItems); //$NON-NLS-1$
245  updateButtons();
246  trendGraphMgr_.updateGraph();
247  }
248  }
249  }
250  );
251  /*
252  epsButton_ = new Button(graphControlPanel, SWT.PUSH);
253  epsButton_.setText(MessageBundle.get("graph.eps"));
254 
255  epsDialog_ = new EPSDialog(owner_);
256  epsButton_.addActionListener(
257  new ActionListener() {
258  public void actionPerformed(ActionEvent evt) {
259  epsDialog_.setColorOutput(true);
260  epsDialog_.setGraphOutput(true);
261  epsDialog_.setLegendOutput(true);
262  epsDialog_.setLocationRelativeTo(GraphPanel.this);
263  epsDialog_.setVisible(true);
264  if (epsDialog_.isUpdated()) {
265  String path = epsDialog_.getPath();
266  boolean cout = epsDialog_.isColorOutput();
267  boolean gout = epsDialog_.isGraphOutput();
268  boolean lout = epsDialog_.isLegendOutput();
269  FileWriter fw = null;
270 
271  if (path.equals("")) {
272  new MessageDialog(
273  owner_,
274  MessageBundle.get("message.filenameempty"),
275  MessageBundle.get("messege.inputfilename")
276  ).showModalDialog();
277  return;
278  }
279 
280  try {
281  fw = new FileWriter(path);
282  } catch (IOException ex) {
283  //ex.printStackTrace();
284  //System.exit(0);
285  new MessageDialog(
286  owner_,
287  MessageBundle.get("messege.fileioerror"),
288  MessageBundle.get("messege.fileioerror")
289  ).showModalDialog();
290  return;
291  }
292  BufferedWriter bw = new BufferedWriter(fw);
293  DroppableXYGraph graph =
294  (DroppableXYGraph)currentGraph_.getGraph();
295  DroppableXYGraph.LegendPanel legend =
296  (DroppableXYGraph.LegendPanel)graph.getLegendPanel();
297  Dimension gsize = graph.getSize();
298  //Dimension lsize = legend.getSize();
299  Dimension lsize = legend.getMinimalSize();
300  int width = 0;
301  int height = 0;
302  int lyofs = 0;
303  if (gout && lout) {
304  width = gsize.width + lsize.width - GRAPH_RIGHT_MARGIN + 10;
305  if (gsize.height > lsize.height) {
306  height = gsize.height;
307  lyofs = (gsize.height - lsize.height) / 2;
308  } else {
309  height = lsize.height;
310  }
311  } else if (gout) {
312  width = gsize.width;
313  height = gsize.height;
314  } else if (lout) {
315  width = lsize.width;
316  height = lsize.height;
317  }
318  EPSGraphics eg = new EPSGraphics(bw, 0, 0, width, height, cout);
319  int xofs = 0;
320  if (gout) {
321  graph.setEPSMode(true);
322  graph.paint(eg);
323  graph.setEPSMode(false);
324  xofs += gsize.width - GRAPH_RIGHT_MARGIN + 10;
325  }
326  if (lout) {
327  eg.setXOffset(xofs);
328  eg.setYOffset(lyofs);
329  legend.paint(eg);
330  }
331  eg.finishOutput();
332  }
333  }
334  }
335  );
336  */
337  setEnabledRangeButton(false);
338  }
339 
340  public void setFocuse(GraphElement ge){
341  currentGraph_.setBorderColor(normalColor_);
342  currentGraph_ = ge;
343  currentGraph_.setBorderColor(focusedColor_);
344  redraw(getLocation().x,getLocation().y,getSize().x,getSize().y,true);
345  seriesDialog_.setCurrentGraph(currentGraph_);
346  updateButtons();
347  }
348  //--------------------------------------------------------------------
352  public void resetFocus() {
353  /*
354  SwingUtilities.invokeLater(
355  new Runnable() {
356  public void run() {
357  currentGraph_ = graphElement_[0];
358  for (int i = 0; i < numGraph_; i++) {
359  graphElement_[i].setBorderColor(normalColor_);
360  graphElement_[i].setLegendBackColor(normalColor_);
361  //graphElement_[i].getPreferredSize().height = INITIAL_GRAPH_HEIGHT;
362  }
363  graphElement_[0].setBorderColor(focusedColor_);
364  graphElement_[0].setLegendBackColor(focusedColor_);
365  //graphScrollPane_.getViewport().setViewPosition(new Point(0, 0));
366  //heightSlider_.setValue(INITIAL_GRAPH_HEIGHT);
367  graphElementBase_.setVisible(false);
368  graphElementBase_.setVisible(true);
369  updateButtons();
370  }
371  }
372  );
373  */
374  }
375 
376  //--------------------------------------------------------------------
380  private void updateButtons() {
381  boolean enabled = (currentGraph_.getTrendGraph().getNumDataItems() > 0);
382  vRangeButton_.setEnabled(enabled);
383  seriesButton_.setEnabled(true);
384  //epsButton_.setEnabled(enabled);
385 
386  GrxGraphItem p = manager_.<GrxGraphItem>getSelectedItem(GrxGraphItem.class, null);
387  setEnabledRangeButton(p != null);
388  }
389 
390 
391  /* public void setMode(int mode) {
392  mode_ = mode;
393  SwingUtilities.invokeLater(
394  new Runnable() {
395  public void run() {
396  boolean enabled =
397  (currentGraph_.getTrendGraph().getNumDataItems() > 0);
398  if (mode_ == GUIStatus.EDIT_MODE) {
399  hRangeButton_.setEnabled(true);
400  vRangeButton_.setEnabled(enabled);
401  seriesButton_.setEnabled(enabled);
402  epsButton_.setEnabled(enabled);
403  } else if (mode_ == GUIStatus.EXEC_MODE) {
404  hRangeButton_.setEnabled(false);
405  vRangeButton_.setEnabled(enabled);
406  seriesButton_.setEnabled(false);
407  epsButton_.setEnabled(false);
408  } else if (mode_ == GUIStatus.PLAYBACK_MODE) {
409  hRangeButton_.setEnabled(false);
410  vRangeButton_.setEnabled(enabled);
411  seriesButton_.setEnabled(false);
412  epsButton_.setEnabled(enabled);
413  }
414  }
415  }
416  );
417  }
418 
419  //--------------------------------------------------------------------
420  // Implementation of PlaybackStatusListener
421  public void playbackStatusChanged(int status) {
422  final int subMode = status;
423  SwingUtilities.invokeLater(
424  new Runnable() {
425  public void run() {
426  boolean enabled =
427  (currentGraph_.getTrendGraph().getNumDataItems() > 0);
428  switch (subMode) {
429  case PlaybackStatus.STOPPED:
430  hRangeButton_.setEnabled(true);
431  vRangeButton_.setEnabled(enabled);
432  seriesButton_.setEnabled(enabled);
433  epsButton_.setEnabled(enabled);
434  break;
435  case PlaybackStatus.PLAYING:
436  hRangeButton_.setEnabled(false);
437  vRangeButton_.setEnabled(enabled);
438  seriesButton_.setEnabled(false);
439  epsButton_.setEnabled(false);
440  break;
441  case PlaybackStatus.PAUSE:
442  hRangeButton_.setEnabled(true);
443  vRangeButton_.setEnabled(enabled);
444  seriesButton_.setEnabled(enabled);
445  epsButton_.setEnabled(enabled);
446  break;
447  case PlaybackStatus.RECORDING:
448  hRangeButton_.setEnabled(false);
449  vRangeButton_.setEnabled(enabled);
450  seriesButton_.setEnabled(false);
451  epsButton_.setEnabled(false);
452  break;
453  }
454  }
455  }
456  );
457  }*/
458 
459  //--------------------------------------------------------------------
460 
461  public void setModelList(List<GrxModelItem> list){
462  currentModels_ = list;
463  }
464 
465 }
GraphPanel(GrxPluginManager manager, TrendGraphModel trendGraphMgr, Composite comp)
Definition: GraphPanel.java:87
static final String get(String key)
void itemChange(GrxBaseItem item, int event)
* x
Definition: IceUtils.h:98
#define null
our own NULL pointer
Definition: IceTypes.h:57
GrxBaseItem createItem(Class<?extends GrxBaseItem > cls, String name)
アイテムの作成. 指定したアイテムプラグインに、指定したアイテム名で新しいアイテムを作る。 ...
item corresponds to a robot model
png_uint_32 i
Definition: png.h:2735
long b
Definition: jpegint.h:371
void removeDataItem(DataItemInfo dataItemInfo)
void setSelectedItem(GrxBaseItem item, boolean select)
select/unselect item
Object setProperty(String key, String value)
set property value associated with a keyword
プラグイン管理クラス GrxUIの核になるクラス。プラグインのロード等の、初期化を実行する。 プラグインとそ...
void setModelList(List< GrxModelItem > list)
void setTimeRangeAndPos(double timeRange, double markerPos)
void setModelList(List< GrxModelItem > list)
org
* y
Definition: IceUtils.h:97
void setRange(double base, double extent)
png_infop png_uint_32 flag
Definition: png.h:2159
final void setDblAry(String key, double[] value, int digits)
associate double array to key
void setCurrentGraph(GraphElement currentGraph)


openhrp3
Author(s): AIST, General Robotix Inc., Nakamura Lab of Dept. of Mechano Informatics at University of Tokyo
autogenerated on Sat Apr 13 2019 02:14:21