private void reposition(int x, int y, int width, int height) {
   if (y == 0) {
     y = Y;
     x = X;
   }
   Rectangle constraints = new Rectangle(x, y, width, height);
   ((GraphicalEditPart) getParent()).setLayoutConstraint(this, getFigure(), constraints);
   FigureCanvas canvas = (FigureCanvas) getViewer().getControl();
   canvas.getViewport().repaint();
 }
Esempio n. 2
0
  public static void main(String[] args) {

    Display d = new Display();
    Shell shell = new Shell(d);
    shell.setLayout(new FillLayout());

    FigureCanvas canvas = new FigureCanvas(shell);
    canvas.setContents(new Label("Hello World"));

    shell.setText("draw2d");
    shell.open();
    while (!shell.isDisposed()) while (!d.readAndDispatch()) d.sleep();
  }
  /**
   * Perform the ruler layout.
   *
   * @since 3.6
   */
  public void doLayout() {
    if (left == null && top == null) {
      Rectangle area = getClientArea();
      if (!editor.getBounds().equals(area)) editor.setBounds(area);
      return;
    }

    int leftWidth = 0, topHeight = 0;
    Rectangle leftTrim = null, topTrim = null;
    if (left != null) {
      leftTrim = calculateRulerTrim((Canvas) left.getControl());
      // Adding the trim width here because FigureCanvas#computeSize()
      // does not
      leftWidth = left.getControl().computeSize(SWT.DEFAULT, SWT.DEFAULT).x + leftTrim.width;
    }
    if (top != null) {
      topTrim = calculateRulerTrim((Canvas) top.getControl());
      topHeight = top.getControl().computeSize(SWT.DEFAULT, SWT.DEFAULT).y + topTrim.height;
    }

    Rectangle editorSize = getClientArea();
    editorSize.x = leftWidth;
    editorSize.y = topHeight;
    editorSize.width -= leftWidth;
    editorSize.height -= topHeight;
    editor.setBounds(editorSize);

    /*
     * Fix for Bug# 67554 Take trim into account. Some platforms (such as
     * MacOS and Motif) leave some trimming around some canvasses.
     */
    Rectangle trim = calculateEditorTrim(editor);
    if (left != null) {
      // The - 1 and + 1 are to compensate for the RulerBorder
      left.getControl()
          .setBounds(
              0,
              topHeight - trim.x + leftTrim.x - 1,
              leftWidth,
              editorSize.height - trim.height + leftTrim.height + 1);
    }
    if (top != null) {
      top.getControl()
          .setBounds(
              leftWidth - trim.y + topTrim.y - 1,
              0,
              editorSize.width - trim.width + topTrim.width + 1,
              topHeight);
    }
  }
 public void notifyChanged(Notification notification) {
   super.notifyChanged(notification);
   if (notification.getFeature() instanceof EAttributeImpl) {
     if (notification.getNotifier() instanceof BoundsImpl) {
       reposition(
           ((BoundsImpl) notification.getNotifier()).getX(),
           ((BoundsImpl) notification.getNotifier()).getY(),
           ((BoundsImpl) notification.getNotifier()).getWidth(),
           ((BoundsImpl) notification.getNotifier()).getHeight());
       FigureCanvas canvas = (FigureCanvas) getViewer().getControl();
       canvas.getViewport().repaint();
     }
   }
 }
Esempio n. 5
0
 protected void configureControl(Control control) {
   if (control instanceof Scale) {
     Scale scale = (Scale) control;
     scale.setMinimum(0);
     scale.setMaximum(10000);
     scale.setSelection(0);
     return;
   } else if (control instanceof FigureCanvas) {
     FigureCanvas fc = (FigureCanvas) control;
     fc.setScrollBarVisibility(FigureCanvas.NEVER);
     fc.getLightweightSystem().setEventDispatcher(new SliderEventDispatcher());
     fc.setViewport(createViewport(fc));
     IFigure contents = createContents(fc);
     fc.setContents(contents);
     createSlotFigure(contents);
     createBlockFigure(contents);
   }
 }
 public RotationButtonComposite(
     Composite parent, int direction, String lblText, boolean ctrlPressRequired) {
   super(parent, SWT.None);
   this.direction = direction;
   this.lblText = lblText;
   this.ctrlPressRequired = ctrlPressRequired;
   GridLayout layout = new GridLayout();
   layout.marginHeight = 0;
   layout.marginWidth = 0;
   setLayout(layout);
   this.setBackground(ColorConstants.white);
   figCanvas = new FigureCanvas(this);
   figCanvas.setContents(getContents());
   figCanvas.getViewport().setContentsTracksHeight(true);
   figCanvas.getViewport().setContentsTracksWidth(true);
   figCanvas.setLayoutData(new GridData(GridData.FILL_BOTH));
   figCanvas.setBorder(new LineBorder(1));
 }
Esempio n. 7
0
 protected void refreshCanvas(FigureCanvas fc) {
   fc.getContents().revalidate();
   fc.getContents().repaint();
   String text = getSelectionText();
   if (text == null) {
     blockFigure.setToolTip(null);
   } else {
     blockFigure.setToolTip(new Label(text));
   }
 }
  private GraphicalViewer createRulerContainer(int orientation) {
    ScrollingGraphicalViewer viewer = new RulerViewer();
    final boolean isHorizontal =
        orientation == PositionConstants.NORTH || orientation == PositionConstants.SOUTH;

    // Finish initializing the viewer
    viewer.setRootEditPart(new RulerRootEditPart(isHorizontal));
    viewer.setEditPartFactory(new RulerEditPartFactory(diagramViewer));
    viewer.createControl(this);
    ((GraphicalEditPart) viewer.getRootEditPart())
        .getFigure()
        .setBorder(new RulerBorder(isHorizontal));
    viewer.setProperty(GraphicalViewer.class.toString(), diagramViewer);

    // Configure the viewer's control
    FigureCanvas canvas = (FigureCanvas) viewer.getControl();
    canvas.setScrollBarVisibility(FigureCanvas.NEVER);
    if (font == null) {
      FontData[] data = canvas.getFont().getFontData();
      for (int i = 0; i < data.length; i++) {
        data[i].setHeight(data[i].getHeight() - 1);
      }
      font = new Font(Display.getCurrent(), data);
    }
    canvas.setFont(font);
    if (isHorizontal) {
      canvas.getViewport().setHorizontalRangeModel(editor.getViewport().getHorizontalRangeModel());
    } else {
      canvas.getViewport().setVerticalRangeModel(editor.getViewport().getVerticalRangeModel());
    }

    // Add the viewer to the rulerEditDomain
    if (rulerEditDomain == null) {
      rulerEditDomain = new EditDomain();
      rulerEditDomain.setCommandStack(diagramViewer.getEditDomain().getCommandStack());
    }
    rulerEditDomain.addViewer(viewer);

    return viewer;
  }
Esempio n. 9
0
 protected void layoutFigures(FigureCanvas fc) {
   Rectangle r = new Rectangle(fc.getViewport().getClientArea());
   if (vertical) r.transpose();
   Dimension size = blockFigure.getPreferredSize();
   Rectangle b =
       new Rectangle(
           r.x + size.width / 2,
           r.y + (r.height - SLOT_HEIGHT) / 2,
           r.width - size.width,
           SLOT_HEIGHT);
   int x = (int) (b.x + b.width * selectionRatio);
   int y = b.y + b.height - b.height / 2;
   Rectangle b2 = new Rectangle(x - size.width / 2, y - size.height / 2, size.width, size.height);
   if (vertical) {
     b.transpose();
     b2.transpose();
   }
   slotFigure.setBounds(b);
   blockFigure.setBounds(b2);
 }
Esempio n. 10
0
  public void createPartControl(Composite parent) {
    GridLayout layout = new GridLayout(1, true);
    layout.marginHeight = 5;
    layout.marginWidth = 5;
    parent.setLayout(layout);
    parent.setBackground(ColorUtil.getInstance().getColor(SWT.COLOR_WHITE));
    parent.setBackgroundMode(SWT.INHERIT_FORCE);

    window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    man = getViewSite().getActionBars().getToolBarManager();

    man.add(
        new Action("Reload", ImageUtil.getImageDescriptor(Images.refresh)) {
          public void run() {
            yesterday = null;
            yesterdayDataProvider.clearTrace();
            traceDataProvider.clearTrace();
            thread.interrupt();
          }
        });

    canvas = new FigureCanvas(parent);
    canvas.setScrollBarVisibility(FigureCanvas.NEVER);
    canvas.setLayoutData(new GridData(GridData.FILL_BOTH));

    canvas.addControlListener(
        new ControlListener() {
          boolean lock = false;

          public void controlResized(ControlEvent e) {
            org.eclipse.swt.graphics.Rectangle r = canvas.getClientArea();
            if (!lock) {
              lock = true;
              if (ChartUtil.isShowDescriptionAllowSize(r.height)) {
                CounterTodayTotalView.this.setContentDescription(desc);
              } else {
                CounterTodayTotalView.this.setContentDescription("");
              }
              r = canvas.getClientArea();
              lock = false;
            }
            xyGraph.setSize(r.width, r.height);
          }

          public void controlMoved(ControlEvent e) {}
        });

    xyGraph = new XYGraph();
    xyGraph.setShowLegend(false);
    // xyGraph.setShowTitle(false);

    canvas.setContents(xyGraph);

    xyGraph.primaryXAxis.setDateEnabled(true);
    xyGraph.primaryXAxis.setShowMajorGrid(true);

    xyGraph.primaryYAxis.setAutoScale(true);
    xyGraph.primaryYAxis.setShowMajorGrid(true);

    xyGraph.primaryXAxis.setTitle("");
    xyGraph.primaryYAxis.setTitle("");

    ScouterUtil.addShowTotalValueListener(canvas, xyGraph);

    createDataProvider();
    createYesterdayProvider();

    canvas.addKeyListener(
        new KeyListener() {
          public void keyReleased(KeyEvent e) {}

          public void keyPressed(KeyEvent e) {
            if (e.keyCode == SWT.F5) {
              yesterday = null;
              yesterdayDataProvider.clearTrace();
              traceDataProvider.clearTrace();
              thread.interrupt();
            }
          }
        });

    String date = DateUtil.yyyymmdd(TimeUtil.getCurrentTime(serverId));

    Server server = ServerManager.getInstance().getServer(serverId);
    String svrName = "";
    String counterDisplay = "";
    String counterUnit = "";
    if (server != null) {
      svrName = server.getName();
      counterDisplay = server.getCounterEngine().getCounterDisplayName(objType, counter);
      counterUnit = server.getCounterEngine().getCounterUnit(objType, counter);
    }
    desc =
        "ⓢ"
            + svrName
            + " | (Today) ["
            + date.substring(0, 4)
            + "-"
            + date.substring(4, 6)
            + "-"
            + date.substring(6, 8)
            + "] Total "
            + counterDisplay
            + (!"".equals(counterUnit) ? " (" + counterUnit + ")" : "");
    try {
      setViewTab(objType, counter, serverId);
    } catch (Exception e1) {
      e1.printStackTrace();
    }

    thread = new RefreshThread(this, 10000);
    thread.setName(
        this.toString()
            + " - "
            + "objType:"
            + objType
            + ", counter:"
            + counter
            + ", serverId:"
            + serverId);
    thread.start();
  }
Esempio n. 11
0
  public void createPartControl(Composite parent) {
    window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    GridLayout layout = new GridLayout(1, true);
    layout.marginHeight = 5;
    layout.marginWidth = 5;
    parent.setLayout(layout);
    parent.setBackground(ColorUtil.getInstance().getColor(SWT.COLOR_WHITE));
    parent.setBackgroundMode(SWT.INHERIT_FORCE);
    canvas = new FigureCanvas(parent);
    canvas.setLayoutData(new GridData(GridData.FILL_BOTH));
    canvas.setScrollBarVisibility(FigureCanvas.NEVER);
    canvas.addControlListener(
        new ControlListener() {
          boolean lock = false;

          public void controlResized(ControlEvent e) {
            org.eclipse.swt.graphics.Rectangle r = canvas.getClientArea();
            if (!lock) {
              lock = true;
              if (ChartUtil.isShowDescriptionAllowSize(r.height)) {
                CounterLoadTimeView.this.setContentDescription(desc);
              } else {
                CounterLoadTimeView.this.setContentDescription("");
              }
              r = canvas.getClientArea();
              lock = false;
            }
            xyGraph.setSize(r.width, r.height);
          }

          public void controlMoved(ControlEvent e) {}
        });

    xyGraph = new XYGraph();
    xyGraph.setShowLegend(false);
    xyGraph.setShowTitle(false);

    canvas.setContents(xyGraph);

    xyGraph.primaryXAxis.setDateEnabled(true);
    xyGraph.primaryXAxis.setShowMajorGrid(true);

    xyGraph.primaryYAxis.setAutoScale(true);
    xyGraph.primaryYAxis.setShowMajorGrid(true);

    provider = new CircularBufferDataProvider(true);
    provider.setBufferSize(7200); // for 4-hour
    provider.setCurrentXDataArray(new double[] {});
    provider.setCurrentYDataArray(new double[] {});

    // create the trace
    trace = new Trace("TOTAL", xyGraph.primaryXAxis, xyGraph.primaryYAxis, provider);

    // set trace property
    trace.setPointStyle(PointStyle.NONE);
    trace.getXAxis().setFormatPattern("HH:mm");
    trace.getYAxis().setFormatPattern("#,##0");

    trace.setLineWidth(PManager.getInstance().getInt(PreferenceConstants.P_CHART_LINE_WIDTH));
    trace.setTraceType(TraceType.SOLID_LINE);
    trace.setTraceColor(ColorUtil.getInstance().getColor(SWT.COLOR_DARK_CYAN));

    xyGraph.primaryXAxis.setTitle("");
    xyGraph.primaryYAxis.setTitle("");

    xyGraph.addTrace(trace);

    restoreState();
  }
 /** Unhook outline viewer. */
 protected void unhookOutlineViewer() {
   editor.getSelectionSynchronizer().removeViewer(getViewer());
   FigureCanvas editor2 = editor.getEditor();
   if (disposeListener != null && editor2 != null && !editor2.isDisposed())
     editor2.removeDisposeListener(disposeListener);
 }
  /**
   * Creates rulers for the given graphical viewer.
   *
   * <p>The primaryViewer or its Control cannot be <code>null</code>. The primaryViewer's Control
   * should be a FigureCanvas and a child of this Composite. This method should only be invoked
   * once.
   *
   * <p>To create ruler(s), simply add the RulerProvider(s) (with the right key:
   * RulerProvider.PROPERTY_HORIZONTAL_RULER or RulerProvider.PROPERTY_VERTICAL_RULER) as a property
   * on the given viewer. It can be done after this method is invoked.
   * RulerProvider.PROPERTY_RULER_VISIBILITY can be used to show/hide the rulers.
   *
   * @param primaryViewer The graphical viewer for which the rulers have to be created
   */
  public void setGraphicalViewer(ScrollingGraphicalViewer primaryViewer) {
    // pre-conditions
    Assert.isNotNull(primaryViewer);
    Assert.isNotNull(primaryViewer.getControl());
    Assert.isTrue(diagramViewer == null);

    diagramViewer = primaryViewer;
    editor = (FigureCanvas) diagramViewer.getControl();

    // layout whenever the scrollbars are shown or hidden, and whenever the
    // RulerComposite
    // is resized
    layoutListener =
        new Listener() {
          public void handleEvent(Event event) {
            // @TODO:Pratik If you use Display.asyncExec(runnable) here,
            // some flashing
            // occurs. You can see it when the palette is in the editor, and
            // you hit
            // the button to show/hide it.
            layout(true);
          }
        };
    addListener(SWT.Resize, layoutListener);
    ScrollBar horizontalBar = editor.getHorizontalBar();
    if (horizontalBar != null) {
      horizontalBar.addListener(SWT.Show, layoutListener);
      horizontalBar.addListener(SWT.Hide, layoutListener);
    }
    ScrollBar verticalBar = editor.getVerticalBar();
    if (verticalBar != null) {
      verticalBar.addListener(SWT.Show, layoutListener);
      verticalBar.addListener(SWT.Hide, layoutListener);
    }

    propertyListener =
        new PropertyChangeListener() {
          public void propertyChange(PropertyChangeEvent evt) {
            String property = evt.getPropertyName();
            if (RulerProvider.PROPERTY_HORIZONTAL_RULER.equals(property)) {
              setRuler(
                  (RulerProvider)
                      diagramViewer.getProperty(RulerProvider.PROPERTY_HORIZONTAL_RULER),
                  PositionConstants.NORTH);
            } else if (RulerProvider.PROPERTY_VERTICAL_RULER.equals(property)) {
              setRuler(
                  (RulerProvider) diagramViewer.getProperty(RulerProvider.PROPERTY_VERTICAL_RULER),
                  PositionConstants.WEST);
            } else if (RulerProvider.PROPERTY_RULER_VISIBILITY.equals(property))
              setRulerVisibility(
                  ((Boolean) diagramViewer.getProperty(RulerProvider.PROPERTY_RULER_VISIBILITY))
                      .booleanValue());
          }
        };
    diagramViewer.addPropertyChangeListener(propertyListener);
    Boolean rulerVisibility =
        (Boolean) diagramViewer.getProperty(RulerProvider.PROPERTY_RULER_VISIBILITY);
    if (rulerVisibility != null) setRulerVisibility(rulerVisibility.booleanValue());
    setRuler(
        (RulerProvider) diagramViewer.getProperty(RulerProvider.PROPERTY_HORIZONTAL_RULER),
        PositionConstants.NORTH);
    setRuler(
        (RulerProvider) diagramViewer.getProperty(RulerProvider.PROPERTY_VERTICAL_RULER),
        PositionConstants.WEST);
  }
  public void createPartControl(Composite parent) {
    window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();

    Composite composite = new Composite(parent, SWT.NONE);
    GridLayout gLayout = new GridLayout(1, true);
    gLayout.horizontalSpacing = 0;
    gLayout.marginHeight = 0;
    gLayout.marginWidth = 0;
    composite.setLayout(gLayout);
    createUpperMenu(composite);

    Composite chartComposite = new Composite(composite, SWT.NONE);
    chartComposite.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, true));
    chartComposite.setLayout(UIUtil.formLayout(0, 0));
    this.marginTargetComposite = chartComposite;
    chartComposite.setBackground(ColorUtil.getInstance().getColor(SWT.COLOR_WHITE));

    canvas = new FigureCanvas(chartComposite);
    canvas.setScrollBarVisibility(FigureCanvas.NEVER);
    canvas.setBackground(ColorUtil.getInstance().getColor(SWT.COLOR_WHITE));

    canvas.setLayoutData(UIUtil.formData(0, leftMargin, 0, 0, 100, 0, 100, 0));

    canvas.addControlListener(
        new ControlListener() {
          boolean lock = false;

          public void controlResized(ControlEvent e) {
            org.eclipse.swt.graphics.Rectangle r = canvas.getClientArea();
            if (!lock) {
              lock = true;
              if (ChartUtil.isShowDescriptionAllowSize(r.height)) {
                CounterPastLongDateTotalView.this.setContentDescription(desc);
              } else {
                CounterPastLongDateTotalView.this.setContentDescription("");
              }
              r = canvas.getClientArea();
              lock = false;
            }
            xyGraph.setSize(r.width, r.height);
          }

          public void controlMoved(ControlEvent e) {}
        });
    xyGraph = new XYGraph();
    xyGraph.setShowLegend(false);

    canvas.setContents(xyGraph);

    xyGraph.primaryXAxis.setDateEnabled(true);
    xyGraph.primaryXAxis.setShowMajorGrid(true);

    xyGraph.primaryYAxis.setAutoScale(true);
    xyGraph.primaryYAxis.setShowMajorGrid(true);

    xyGraph.primaryXAxis.setTitle("");
    xyGraph.primaryYAxis.setTitle("");

    traceDataProvider = new CircularBufferDataProvider(true);
    //		traceDataProvider.setBufferSize(buffer);
    traceDataProvider.setCurrentXDataArray(new double[] {});
    traceDataProvider.setCurrentYDataArray(new double[] {});

    // create the trace
    trace = new Trace("TOTAL", xyGraph.primaryXAxis, xyGraph.primaryYAxis, traceDataProvider);

    // set trace property
    trace.setPointStyle(PointStyle.NONE);
    trace.getXAxis().setFormatPattern("yyyy-MM-dd\n  HH:mm:ss");
    trace.getYAxis().setFormatPattern("#,##0");

    trace.setLineWidth(PManager.getInstance().getInt(PreferenceConstants.P_CHART_LINE_WIDTH));
    trace.setTraceType(TraceType.AREA);
    trace.setTraceColor(ColorUtil.getInstance().TOTAL_CHART_COLOR);

    xyGraph.primaryXAxis.setTitle("");
    xyGraph.primaryYAxis.setTitle("");

    // add the trace to xyGraph
    xyGraph.addTrace(trace);
    ChartUtil.addSolidLine(xyGraph, traceDataProvider, ColorUtil.getInstance().TOTAL_CHART_COLOR);

    ScouterUtil.addShowTotalValueListener(canvas, xyGraph);

    man = getViewSite().getActionBars().getToolBarManager();

    canvas.addKeyListener(
        new KeyListener() {
          public void keyReleased(KeyEvent e) {}

          public void keyPressed(KeyEvent e) {
            if (e.keyCode == SWT.F5) {
              ExUtil.asyncRun(
                  new Runnable() {
                    public void run() {
                      try {
                        setInput(sDate, eDate, objType, counter, serverId);
                      } catch (Exception e) {
                        e.printStackTrace();
                      }
                    }
                  });
            }
          }
        });

    man.add(
        new Action("Reload", ImageUtil.getImageDescriptor(Images.refresh)) {
          public void run() {
            ExUtil.exec(
                new Runnable() {
                  public void run() {
                    try {
                      setInput(sDate, eDate, objType, counter, serverId);
                    } catch (Exception e) {
                      e.printStackTrace();
                    }
                  }
                });
          }
        });

    man.add(new Separator());
    man.add(
        new Action("Duplicate", ImageUtil.getImageDescriptor(Images.copy)) {
          public void run() {
            ExUtil.exec(
                new Runnable() {
                  public void run() {
                    duplicateView();
                  }
                });
          }
        });

    restoreState();
  }
Esempio n. 15
0
  public void createPartControl(Composite parent) {
    Server server = ServerManager.getInstance().getServer(serverId);
    this.setPartName("DB Activity[" + server.getName() + "]");
    GridLayout layout = new GridLayout(1, true);
    layout.marginHeight = 5;
    layout.marginWidth = 5;
    parent.setLayout(layout);
    parent.setBackground(ColorUtil.getInstance().getColor(SWT.COLOR_WHITE));
    parent.setBackgroundMode(SWT.INHERIT_FORCE);
    canvas = new FigureCanvas(parent);
    canvas.setLayoutData(new GridData(GridData.FILL_BOTH));
    canvas.setScrollBarVisibility(FigureCanvas.NEVER);
    canvas.addControlListener(
        new ControlListener() {
          public void controlMoved(ControlEvent arg0) {}

          public void controlResized(ControlEvent arg0) {
            Rectangle r = canvas.getClientArea();
            xyGraph.setSize(r.width, r.height);
          }
        });

    xyGraph = new XYGraph();
    xyGraph.setShowLegend(true);
    xyGraph.setShowTitle(false);
    canvas.setContents(xyGraph);

    xyGraph.primaryXAxis.setDateEnabled(true);
    xyGraph.primaryXAxis.setShowMajorGrid(true);
    xyGraph.primaryYAxis.setAutoScale(true);
    xyGraph.primaryYAxis.setShowMajorGrid(true);
    xyGraph.primaryXAxis.setFormatPattern("HH:mm:ss");
    xyGraph.primaryYAxis.setFormatPattern("#,##0");

    xyGraph.primaryXAxis.setTitle("");
    xyGraph.primaryYAxis.setTitle("");

    CircularBufferDataProvider callProvider = new CircularBufferDataProvider(true);
    callProvider.setBufferSize(BUFFER_SIZE);
    callProvider.setCurrentXDataArray(new double[] {});
    callProvider.setCurrentYDataArray(new double[] {});
    callTrace = new Trace("Call (SUM)", xyGraph.primaryXAxis, xyGraph.primaryYAxis, callProvider);
    callTrace.setPointStyle(PointStyle.NONE);
    callTrace.setTraceType(TraceType.AREA);
    callTrace.setLineWidth(PManager.getInstance().getInt(PreferenceConstants.P_CHART_LINE_WIDTH));
    callTrace.setAreaAlpha(255);
    callTrace.setTraceColor(ColorUtil.getInstance().getColor(SWT.COLOR_DARK_BLUE));
    xyGraph.addTrace(callTrace);

    CircularBufferDataProvider selectProvider = new CircularBufferDataProvider(true);
    selectProvider.setBufferSize(BUFFER_SIZE);
    selectProvider.setCurrentXDataArray(new double[] {});
    selectProvider.setCurrentYDataArray(new double[] {});
    selectTrace =
        new Trace("Select (SUM)", xyGraph.primaryXAxis, xyGraph.primaryYAxis, selectProvider);
    selectTrace.setPointStyle(PointStyle.NONE);
    selectTrace.setTraceType(TraceType.AREA);
    selectTrace.setLineWidth(PManager.getInstance().getInt(PreferenceConstants.P_CHART_LINE_WIDTH));
    selectTrace.setAreaAlpha(255);
    selectTrace.setTraceColor(ColorUtil.getInstance().getColor(SWT.COLOR_DARK_CYAN));
    xyGraph.addTrace(selectTrace);

    CircularBufferDataProvider insertProvider = new CircularBufferDataProvider(true);
    insertProvider.setBufferSize(BUFFER_SIZE);
    insertProvider.setCurrentXDataArray(new double[] {});
    insertProvider.setCurrentYDataArray(new double[] {});
    insertTrace =
        new Trace("Insert (SUM)", xyGraph.primaryXAxis, xyGraph.primaryYAxis, insertProvider);
    insertTrace.setPointStyle(PointStyle.NONE);
    insertTrace.setTraceType(TraceType.AREA);
    insertTrace.setLineWidth(PManager.getInstance().getInt(PreferenceConstants.P_CHART_LINE_WIDTH));
    insertTrace.setAreaAlpha(255);
    insertTrace.setTraceColor(ColorUtil.getInstance().getColor(SWT.COLOR_DARK_GRAY));
    xyGraph.addTrace(insertTrace);

    CircularBufferDataProvider updateProvider = new CircularBufferDataProvider(true);
    updateProvider.setBufferSize(BUFFER_SIZE);
    updateProvider.setCurrentXDataArray(new double[] {});
    updateProvider.setCurrentYDataArray(new double[] {});
    updateTrace =
        new Trace("Update (SUM)", xyGraph.primaryXAxis, xyGraph.primaryYAxis, updateProvider);
    updateTrace.setPointStyle(PointStyle.NONE);
    updateTrace.setTraceType(TraceType.AREA);
    updateTrace.setLineWidth(PManager.getInstance().getInt(PreferenceConstants.P_CHART_LINE_WIDTH));
    updateTrace.setAreaAlpha(255);
    updateTrace.setTraceColor(ColorUtil.getInstance().getColor(SWT.COLOR_DARK_GREEN));
    xyGraph.addTrace(updateTrace);

    CircularBufferDataProvider deleteProvider = new CircularBufferDataProvider(true);
    deleteProvider.setBufferSize(BUFFER_SIZE);
    deleteProvider.setCurrentXDataArray(new double[] {});
    deleteProvider.setCurrentYDataArray(new double[] {});
    deleteTrace =
        new Trace("Delete (SUM)", xyGraph.primaryXAxis, xyGraph.primaryYAxis, deleteProvider);
    deleteTrace.setPointStyle(PointStyle.NONE);
    deleteTrace.setTraceType(TraceType.AREA);
    deleteTrace.setLineWidth(PManager.getInstance().getInt(PreferenceConstants.P_CHART_LINE_WIDTH));
    deleteTrace.setAreaAlpha(255);
    deleteTrace.setTraceColor(ColorUtil.getInstance().getColor(SWT.COLOR_DARK_MAGENTA));
    xyGraph.addTrace(deleteTrace);

    ScouterUtil.addHorizontalRangeListener(
        xyGraph.getPlotArea(), new OpenDigestTableAction(serverId), true);

    IToolBarManager man = getViewSite().getActionBars().getToolBarManager();
    Action fixRangeAct =
        new Action("Pin Range", IAction.AS_CHECK_BOX) {
          public void run() {
            fixRange = isChecked();
          }
        };
    fixRangeAct.setImageDescriptor(ImageUtil.getImageDescriptor(Images.pin));
    man.add(fixRangeAct);

    thread = new RefreshThread(this, REFRESH_INTERVAL);
    thread.start();
  }
 public void redraw() {
   if (canvas != null && canvas.isDisposed() == false) {
     canvas.redraw();
     xyGraph.repaint();
   }
 }
Esempio n. 17
0
 public void setEnabled(boolean enabled) {
   super.setEnabled(enabled);
   redraw();
 }
  public void createPartControl(Composite parent) {
    String displayCounter =
        defaultServer.getCounterEngine().getCounterDisplayName(objType, counter);
    String objectDisplay = defaultServer.getCounterEngine().getDisplayNameObjectType(objType);
    setPartName(grpName + " - " + displayCounter);
    mode = CounterUtil.getTotalMode(objType, counter);
    desc = grpName + " | (Today) [" + objectDisplay + "] " + displayCounter;
    GridLayout layout = new GridLayout(1, true);
    layout.marginHeight = 5;
    layout.marginWidth = 5;
    parent.setLayout(layout);
    parent.setBackground(ColorUtil.getInstance().getColor(SWT.COLOR_WHITE));
    parent.setBackgroundMode(SWT.INHERIT_FORCE);
    canvas = new FigureCanvas(parent);
    canvas.setScrollBarVisibility(FigureCanvas.NEVER);
    canvas.setLayoutData(new GridData(GridData.FILL_BOTH));
    canvas.addControlListener(
        new ControlListener() {
          boolean lock = false;

          public void controlResized(ControlEvent e) {
            org.eclipse.swt.graphics.Rectangle r = canvas.getClientArea();
            if (!lock) {
              lock = true;
              if (ChartUtil.isShowDescriptionAllowSize(r.height)) {
                CounterTodayGroupCountView.this.setContentDescription(desc);
              } else {
                CounterTodayGroupCountView.this.setContentDescription("");
              }
              r = canvas.getClientArea();
              lock = false;
            }
            if (xyGraph == null) return;
            xyGraph.setSize(r.width, r.height);
            lineWidth = r.width / 30;
            trace.setLineWidth(lineWidth);
            xAxisUnitWidth =
                xyGraph.primaryXAxis.getValuePosition(1, false)
                    - xyGraph.primaryXAxis.getValuePosition(0, false);
          }

          public void controlMoved(ControlEvent e) {}
        });

    canvas.addMouseListener(
        new MouseListener() {
          public void mouseUp(MouseEvent e) {
            writedValueMode = false;
            canvas.redraw();
          }

          public void mouseDown(MouseEvent e) {
            writeValue(e.x);
          }

          public void mouseDoubleClick(MouseEvent e) {}
        });

    xyGraph = new XYGraph();
    xyGraph.setShowLegend(false);

    canvas.setContents(xyGraph);

    xyGraph.primaryXAxis.setDateEnabled(false);
    xyGraph.primaryXAxis.setShowMajorGrid(false);

    xyGraph.primaryYAxis.setAutoScale(true);
    xyGraph.primaryYAxis.setShowMajorGrid(true);

    xyGraph.primaryXAxis.setTitle("");
    xyGraph.primaryYAxis.setTitle("");

    traceDataProvider = new CircularBufferDataProvider(true);
    traceDataProvider.setBufferSize(24);
    traceDataProvider.setCurrentXDataArray(new double[] {});
    traceDataProvider.setCurrentYDataArray(new double[] {});

    this.xyGraph.primaryXAxis.setRange(0, 24);

    // create the trace
    trace = new Trace("TotalCount", xyGraph.primaryXAxis, xyGraph.primaryYAxis, traceDataProvider);

    // set trace property
    trace.setPointStyle(PointStyle.NONE);
    // trace.getXAxis().setFormatPattern("HH");
    trace.getYAxis().setFormatPattern("#,##0");

    trace.setLineWidth(15);
    trace.setTraceType(TraceType.BAR);
    trace.setAreaAlpha(200);
    trace.setTraceColor(ColorUtil.getInstance().TOTAL_CHART_COLOR);

    // add the trace to xyGraph
    xyGraph.addTrace(trace);

    thread = new RefreshThread(this, 5000);
    thread.start();
    thread.setName(
        this.toString()
            + " - "
            + "objType:"
            + objType
            + ", counter:"
            + counter
            + ", grpName:"
            + grpName);
  }
  static void refreshGrid() {
    if (styleGrid != null) {
      styleGrid.dispose();
      shell.pack();
    }

    styleGrid = new Group(shell, SWT.NONE);
    styleGrid.setText(xAxis.getName() + " vs. " + yAxis.getName());
    styleGrid.setLayout(new GridLayout(xAxis.getCount() + 1, false));
    styleGrid.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, true, true, 1, 1));

    // put blank label in top left corner
    Label label = new Label(styleGrid, SWT.NONE);

    // add x-axis labels
    for (int x = 0; x < xAxis.getCount(); x++) {
      label = new Label(styleGrid, SWT.NONE);
      label.setText(xAxis.getName() + " =\n" + xAxis.getAt(x).getName());
    }

    // iterate over the y-axis style settings
    for (int y = 1; y < yAxis.getCount() + 1; y++) {

      // add y-axis label for this row
      label = new Label(styleGrid, SWT.NONE);
      label.setText(yAxis.getName() + " =\n" + yAxis.getAt(y - 1).getName());

      // iterate over the x-axis style settings
      for (int x = 1; x < xAxis.getCount() + 1; x++) {

        // create a sample shape instance
        Shape shape;
        if (sampleShape == Polyline.class) {
          Polyline poly = new Polyline();
          poly.addPoint(new Point(20, 20));
          poly.addPoint(new Point(50, 80));
          poly.addPoint(new Point(10, 50));
          shape = poly;
        } else {
          try {
            shape = (Shape) sampleShape.getConstructor(null).newInstance(null);
          } catch (Exception e) {
            throw new RuntimeException(
                "Could not find a no args constructor for " + sampleShape.getName());
          }
          shape.setBounds(new Rectangle(0, 0, 100, 75));
        }

        // apply default style
        shape.setBackgroundColor(ColorConstants.orange());
        shape.setLineWidthFloat(defaultLineWidth);
        shape.setAntialias(SWT.ON);

        // apply styles imposed by each axis
        xAxis.applyTo(shape, x - 1);
        yAxis.applyTo(shape, y - 1);

        FigureCanvas figureBox = new FigureCanvas(styleGrid);
        figureBox.setContents(shape);
      }
    }
    shell.pack();
  }