コード例 #1
0
ファイル: XLogCallView.java プロジェクト: daisyleenr/scouter
 public Color getColor(Object rel) {
   if (rel instanceof XLogConnection) {
     XLogConnection conn = (XLogConnection) rel;
     if (conn.error || conn.elapsed > 8000) {
       return ColorUtil.getInstance().getColor(SWT.COLOR_DARK_RED);
     }
   }
   return ColorUtil.getInstance().getColor(SWT.COLOR_DARK_GRAY);
 }
コード例 #2
0
  private void createDataProvider() {
    traceDataProvider = new CircularBufferDataProvider(true);
    traceDataProvider.setBufferSize(288);
    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("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);

    // add the trace to xyGraph
    xyGraph.addTrace(trace);
    ChartUtil.addSolidLine(xyGraph, traceDataProvider, ColorUtil.getInstance().TOTAL_CHART_COLOR);
  }
コード例 #3
0
  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);
  }
コード例 #4
0
  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();
  }
コード例 #5
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();
  }
コード例 #6
0
ファイル: EQCommonView.java プロジェクト: hwiba/scouter
  public void createPartControl(final Composite parent) {
    parent.setBackground(ColorUtil.getInstance().getColor(SWT.COLOR_WHITE));
    parent.setBackgroundMode(SWT.INHERIT_FORCE);
    parent.setLayout(UIUtil.formLayout(0, 0));
    GridLayout layout = new GridLayout(1, true);
    layout.marginHeight = MARGIN;
    layout.marginWidth = MARGIN;
    scroll = new ScrolledComposite(parent, SWT.H_SCROLL | SWT.V_SCROLL);
    scroll.setLayoutData(UIUtil.formData(0, 0, 0, 0, 100, 0, 100, 0));
    canvas = new Canvas(scroll, SWT.DOUBLE_BUFFERED);
    canvas.setLayout(layout);
    canvas.addPaintListener(
        new PaintListener() {
          public void paintControl(PaintEvent e) {
            try {
              area = canvas.getClientArea();
              winYSize = parent.getSize().y;
              drawEQImage(e.gc);
            } catch (Throwable t) {
            }
          }
        });
    canvas.addMouseListener(
        new MouseAdapter() {
          public void mouseDoubleClick(MouseEvent e) {
            if (unitHeight == 0 || datas == null) {
              return;
            }
            if (e.y <= AXIS_PADDING) {
              return;
            }
            int index = (e.y - AXIS_PADDING) / unitHeight;
            if (datas.length < index + 1 || datas[index].isAlive == false) {
              return;
            }
            AgentObject agent = AgentModelThread.getInstance().getAgentObject(datas[index].objHash);
            new OpenCxtmenuActiveServiceListAction(
                    getSite().getWorkbenchWindow(),
                    MenuStr.ACTIVE_SERVICE_LIST,
                    datas[index].objHash,
                    agent.getObjType(),
                    agent.getServerId())
                .run();
          }
        });

    scroll.setContent(canvas);
    scroll.setExpandVertical(true);
    scroll.setExpandHorizontal(true);

    scroll.addListener(
        SWT.MouseWheel,
        new Listener() {
          public void handleEvent(Event event) {
            Point origin = scroll.getOrigin();
            origin.y += (event.count * -1) * 10;
            scroll.setOrigin(origin);
          }
        });

    // canvas.setToolTipText("Double click to list active services");
    thread = new RefreshThread(this, REFRESH_INTERVAL);
    thread.start();
  }
コード例 #7
0
ファイル: EQCommonView.java プロジェクト: hwiba/scouter
public abstract class EQCommonView extends ViewPart implements RefreshThread.Refreshable {
  private static final int MARGIN = 10;
  private static final int BAR_WIDTH = 7;
  private static final int BAR_PADDING_HEIGHT = 2;
  private static final int AXIS_PADDING = 16;
  private static final int REFRESH_INTERVAL = 200;
  private static final int FETCH_INTERVAL = 2000;
  public static double CYCLE_INTERVAL = 1000;
  private static int MINIMUM_UNIT_HEIGHT = 20;

  protected RefreshThread thread;

  protected Canvas canvas;
  private long lastFetchedTime;
  protected Set<EqData> valueSet = new TreeSet<EqData>(new EqDataComparator());
  private int unitHeight;

  private Image ibuffer;

  private ScrolledComposite scroll;
  int winYSize;
  Rectangle area;

  public void createPartControl(final Composite parent) {
    parent.setBackground(ColorUtil.getInstance().getColor(SWT.COLOR_WHITE));
    parent.setBackgroundMode(SWT.INHERIT_FORCE);
    parent.setLayout(UIUtil.formLayout(0, 0));
    GridLayout layout = new GridLayout(1, true);
    layout.marginHeight = MARGIN;
    layout.marginWidth = MARGIN;
    scroll = new ScrolledComposite(parent, SWT.H_SCROLL | SWT.V_SCROLL);
    scroll.setLayoutData(UIUtil.formData(0, 0, 0, 0, 100, 0, 100, 0));
    canvas = new Canvas(scroll, SWT.DOUBLE_BUFFERED);
    canvas.setLayout(layout);
    canvas.addPaintListener(
        new PaintListener() {
          public void paintControl(PaintEvent e) {
            try {
              area = canvas.getClientArea();
              winYSize = parent.getSize().y;
              drawEQImage(e.gc);
            } catch (Throwable t) {
            }
          }
        });
    canvas.addMouseListener(
        new MouseAdapter() {
          public void mouseDoubleClick(MouseEvent e) {
            if (unitHeight == 0 || datas == null) {
              return;
            }
            if (e.y <= AXIS_PADDING) {
              return;
            }
            int index = (e.y - AXIS_PADDING) / unitHeight;
            if (datas.length < index + 1 || datas[index].isAlive == false) {
              return;
            }
            AgentObject agent = AgentModelThread.getInstance().getAgentObject(datas[index].objHash);
            new OpenCxtmenuActiveServiceListAction(
                    getSite().getWorkbenchWindow(),
                    MenuStr.ACTIVE_SERVICE_LIST,
                    datas[index].objHash,
                    agent.getObjType(),
                    agent.getServerId())
                .run();
          }
        });

    scroll.setContent(canvas);
    scroll.setExpandVertical(true);
    scroll.setExpandHorizontal(true);

    scroll.addListener(
        SWT.MouseWheel,
        new Listener() {
          public void handleEvent(Event event) {
            Point origin = scroll.getOrigin();
            origin.y += (event.count * -1) * 10;
            scroll.setOrigin(origin);
          }
        });

    // canvas.setToolTipText("Double click to list active services");
    thread = new RefreshThread(this, REFRESH_INTERVAL);
    thread.start();
  }

  static Font verdana12Bold = new Font(null, "Verdana", 12, SWT.BOLD);
  static Font verdana10Bold = new Font(null, "Verdana", 10, SWT.NORMAL);
  static Font verdana10Italic = new Font(null, "Verdana", 10, SWT.ITALIC);
  static Font verdana7 = new Font(null, "Verdana", 7, SWT.NORMAL);

  long lastDrawTime;

  private void drawEQImage(GC gc) {
    if (ibuffer != null) {
      synchronized (ibuffer) {
        if (AXIS_PADDING + (MINIMUM_UNIT_HEIGHT * size) > winYSize) {
          scroll.setMinSize(
              canvas.computeSize(SWT.DEFAULT, AXIS_PADDING + (MINIMUM_UNIT_HEIGHT * size)));
        } else {
          scroll.setMinSize(canvas.computeSize(SWT.DEFAULT, winYSize));
        }
        if (ibuffer.isDisposed() == false) {
          gc.drawImage(ibuffer, 0, 0);
        }
      }
    }
  }

  boolean onGoing = false;
  int size;
  EqData[] datas;

  ObjectSelectManager objSelMgr = ObjectSelectManager.getInstance();

  static Color black = ColorUtil.getInstance().getColor(SWT.COLOR_BLACK);
  static Color red = ColorUtil.getInstance().getColor(SWT.COLOR_RED);
  static Color dark_gary = ColorUtil.getInstance().getColor(SWT.COLOR_GRAY);

  protected void buildBars() {
    long now = TimeUtil.getCurrentTime();
    if ((now - lastDrawTime) < REFRESH_INTERVAL || area == null) {
      return;
    }
    if (onGoing) return;
    onGoing = true;
    int width = area.width > 100 ? area.width : 100;
    int height = area.height > 50 ? area.height : 50;
    Image img = new Image(null, width, height);
    GC gc = new GC(img);
    try {
      lastDrawTime = now;
      double maxValue = 0;
      ArrayList<EqData> list = new ArrayList<EqData>();
      synchronized (valueSet) {
        for (EqData e : valueSet) {
          if (objSelMgr.isUnselectedObject(e.objHash)) {
            continue;
          }
          double max = ChartUtil.getEqMaxValue(e.asd.act1 + e.asd.act2 + e.asd.act3);
          if (max > maxValue) {
            maxValue = max;
          }
          list.add(e);
        }
      }
      size = list.size();
      if (size < 1) {
        datas = new EqData[0];
        return;
      }
      datas = list.toArray(new EqData[size]);
      unitHeight = (height - AXIS_PADDING) / size;

      if (unitHeight < MINIMUM_UNIT_HEIGHT) {
        unitHeight = MINIMUM_UNIT_HEIGHT;
      }

      // draw horizontal line
      gc.setForeground(XLogViewPainter.color_grid_narrow);
      gc.setLineStyle(SWT.LINE_DOT);
      for (int i = AXIS_PADDING + unitHeight; i <= height - unitHeight; i = i + unitHeight) {
        gc.drawLine(0, i, width, i);
      }

      // draw axis line
      gc.setForeground(black);
      gc.setLineStyle(SWT.LINE_SOLID);
      int verticalLineX = 6;
      gc.drawLine(verticalLineX, AXIS_PADDING, verticalLineX, height);
      gc.drawLine(verticalLineX, AXIS_PADDING, width, AXIS_PADDING);

      int groundWidth = area.width - verticalLineX;
      int barSpace = width - verticalLineX - (3 * BAR_WIDTH);
      int imgHeight = unitHeight - (BAR_PADDING_HEIGHT * 2);
      int mod = (int) (TimeUtil.getCurrentTime() % CYCLE_INTERVAL);
      for (int i = 0; i < datas.length; i++) {
        // draw objName
        String objName = datas[i].displayName;
        gc.setForeground(dark_gary);
        gc.setFont(verdana10Italic);
        int strWidth = gc.stringExtent(objName).x;
        while (groundWidth <= (strWidth + 5)) {
          objName = objName.substring(1);
          strWidth = gc.stringExtent(objName).x;
        }
        int x1 = width - strWidth - 5;
        int y1 =
            AXIS_PADDING + (unitHeight * i) + ((unitHeight - (gc.stringExtent(objName).y + 2)));
        gc.drawString(objName, x1, y1, true);
        if (datas[i].isAlive == false) {
          gc.setForeground(dark_gary);
          gc.setLineWidth(2);
          gc.drawLine(
              x1 - 1,
              y1 + (gc.stringExtent(objName).y / 2),
              x1 + gc.stringExtent(objName).x + 1,
              y1 + (gc.stringExtent(objName).y / 2));
        }
        gc.setLineWidth(1);
        ActiveSpeedData asd = datas[i].asd;
        long total = asd.act1 + asd.act2 + asd.act3;
        double reach = barSpace * (total / maxValue);
        int barX = verticalLineX + 1;
        if (total > 0) {
          try {
            // distribute bars to 3 types
            int noOfBars = (int) reach / BAR_WIDTH;
            int noOfAct1 = (int) (noOfBars * ((double) asd.act1 / total));
            int noOfAct2 = (int) (noOfBars * ((double) asd.act2 / total));
            int noOfAct3 = (int) (noOfBars * ((double) asd.act3 / total));
            int sediments = noOfBars - (noOfAct1 + noOfAct2 + noOfAct3);
            while (sediments > 0) {
              if (asd.act3 > 0) {
                noOfAct3++;
                sediments--;
              }
              if (sediments > 0 && asd.act2 > 0) {
                noOfAct2++;
                sediments--;
              }
              if (sediments > 0 && asd.act1 > 0) {
                noOfAct1++;
                sediments--;
              }
            }
            int barY = AXIS_PADDING + ((unitHeight * i) + BAR_PADDING_HEIGHT);
            Color lastColor = null;

            for (int j = 0; j < noOfAct3; j++) {
              // draw red bar
              drawNemo(
                  gc,
                  ColorUtil.getInstance().ac3,
                  barX + 1,
                  barY + 1,
                  BAR_WIDTH - 2,
                  imgHeight - 2);
              barX += BAR_WIDTH;
              lastColor = ColorUtil.getInstance().ac3;
            }
            for (int j = 0; j < noOfAct2; j++) {
              // draw yellow bar
              drawNemo(
                  gc,
                  ColorUtil.getInstance().ac2,
                  barX + 1,
                  barY + 1,
                  BAR_WIDTH - 2,
                  imgHeight - 2);
              barX += BAR_WIDTH;
              lastColor = ColorUtil.getInstance().ac2;
            }
            for (int j = 0; j < noOfAct1; j++) {
              // draw blue bar
              drawNemo(
                  gc,
                  ColorUtil.getInstance().ac1,
                  barX + 1,
                  barY + 1,
                  BAR_WIDTH - 2,
                  imgHeight - 2);
              barX += BAR_WIDTH;
              lastColor = ColorUtil.getInstance().ac1;
            }

            // draw tong-tong bar
            if (lastColor != null) {
              drawNemo(
                  gc,
                  lastColor,
                  barX + 1 + (int) calculateReach(mod, BAR_WIDTH * 0.7d),
                  barY + 1,
                  BAR_WIDTH - 2,
                  imgHeight - 2);
            }
          } catch (Throwable th) {
            th.printStackTrace();
          }
        }

        // draw count text
        if (datas[i].isAlive) {
          gc.setFont(verdana10Bold);
          gc.setForeground(black);
          String v = Long.toString(total);
          gc.drawString(
              v,
              barX + (BAR_WIDTH * 2),
              AXIS_PADDING + (unitHeight * i) + ((unitHeight - gc.stringExtent(v).y) / 2),
              true);
        }
      }

      // draw scale text
      gc.setForeground(black);
      gc.setFont(verdana7);
      int max = (int) maxValue;
      String v = Integer.toString(max);
      String v2 = Integer.toString(max / 2);
      gc.drawString(v, width - gc.stringExtent(v).x - 2, 2, true);
      gc.drawString(
          v2, verticalLineX + ((width - verticalLineX) / 2) - gc.stringExtent(v2).x, 2, true);
      gc.drawString("0", verticalLineX, 2, true);
    } catch (Throwable th) {
      th.printStackTrace();
    } finally {
      gc.dispose();
      Image old = ibuffer;
      ibuffer = img;
      if (old != null) {
        old.dispose();
      }
      onGoing = false;
    }
  }

  private void drawNemo(GC gc, Color background, int x, int y, int width, int height) {
    gc.setBackground(background);
    gc.fillRectangle(x, y, width, height);
    gc.setForeground(black);
    gc.drawRectangle(x, y, width, height);
  }

  public void setFocus() {
    scroll.setFocus();
  }

  private double calculateReach(int mod, double weight) {
    return (Math.cos(mod * (Math.PI / (CYCLE_INTERVAL / 2.0)) + Math.PI) + 1) / 2 * weight;
  }

  public void refresh() {
    buildBars();
    long now = TimeUtil.getCurrentTime();
    if (now >= lastFetchedTime + FETCH_INTERVAL) {
      lastFetchedTime = now;
      valueSet.clear();
      fetch();
    }
    ExUtil.exec(
        canvas,
        new Runnable() {
          public void run() {
            canvas.redraw();
          }
        });
  }

  public abstract void fetch();

  public void dispose() {
    super.dispose();
    if (ibuffer != null && ibuffer.isDisposed() == false) {
      ibuffer.dispose();
    }
    if (this.thread != null) {
      this.thread.shutdown();
    }
  }

  public static class ActiveSpeedData {
    public int act1;
    public int act2;
    public int act3;
  }

  public static class EqData {
    public int objHash;
    public boolean isAlive;
    public String displayName;
    public ActiveSpeedData asd;

    public int hashCode() {
      final int prime = 31;
      int result = 1;
      result = prime * result + objHash;
      return result;
    }

    public boolean equals(Object obj) {
      if (this == obj) return true;
      if (obj == null) return false;
      if (getClass() != obj.getClass()) return false;
      EqData other = (EqData) obj;
      if (objHash != other.objHash) return false;
      return true;
    }

    public String toString() {
      return "EqData [objHash=" + objHash + ", displayName=" + displayName + "]";
    }
  }

  public class EqDataComparator implements Comparator<EqData> {
    public int compare(EqData o1, EqData o2) {
      int comp = o1.displayName.compareTo(o2.displayName);
      if (comp == 0) {
        return o1.objHash - o2.objHash;
      }
      return comp;
    }
  }
}
コード例 #8
0
ファイル: EQCommonView.java プロジェクト: hwiba/scouter
  protected void buildBars() {
    long now = TimeUtil.getCurrentTime();
    if ((now - lastDrawTime) < REFRESH_INTERVAL || area == null) {
      return;
    }
    if (onGoing) return;
    onGoing = true;
    int width = area.width > 100 ? area.width : 100;
    int height = area.height > 50 ? area.height : 50;
    Image img = new Image(null, width, height);
    GC gc = new GC(img);
    try {
      lastDrawTime = now;
      double maxValue = 0;
      ArrayList<EqData> list = new ArrayList<EqData>();
      synchronized (valueSet) {
        for (EqData e : valueSet) {
          if (objSelMgr.isUnselectedObject(e.objHash)) {
            continue;
          }
          double max = ChartUtil.getEqMaxValue(e.asd.act1 + e.asd.act2 + e.asd.act3);
          if (max > maxValue) {
            maxValue = max;
          }
          list.add(e);
        }
      }
      size = list.size();
      if (size < 1) {
        datas = new EqData[0];
        return;
      }
      datas = list.toArray(new EqData[size]);
      unitHeight = (height - AXIS_PADDING) / size;

      if (unitHeight < MINIMUM_UNIT_HEIGHT) {
        unitHeight = MINIMUM_UNIT_HEIGHT;
      }

      // draw horizontal line
      gc.setForeground(XLogViewPainter.color_grid_narrow);
      gc.setLineStyle(SWT.LINE_DOT);
      for (int i = AXIS_PADDING + unitHeight; i <= height - unitHeight; i = i + unitHeight) {
        gc.drawLine(0, i, width, i);
      }

      // draw axis line
      gc.setForeground(black);
      gc.setLineStyle(SWT.LINE_SOLID);
      int verticalLineX = 6;
      gc.drawLine(verticalLineX, AXIS_PADDING, verticalLineX, height);
      gc.drawLine(verticalLineX, AXIS_PADDING, width, AXIS_PADDING);

      int groundWidth = area.width - verticalLineX;
      int barSpace = width - verticalLineX - (3 * BAR_WIDTH);
      int imgHeight = unitHeight - (BAR_PADDING_HEIGHT * 2);
      int mod = (int) (TimeUtil.getCurrentTime() % CYCLE_INTERVAL);
      for (int i = 0; i < datas.length; i++) {
        // draw objName
        String objName = datas[i].displayName;
        gc.setForeground(dark_gary);
        gc.setFont(verdana10Italic);
        int strWidth = gc.stringExtent(objName).x;
        while (groundWidth <= (strWidth + 5)) {
          objName = objName.substring(1);
          strWidth = gc.stringExtent(objName).x;
        }
        int x1 = width - strWidth - 5;
        int y1 =
            AXIS_PADDING + (unitHeight * i) + ((unitHeight - (gc.stringExtent(objName).y + 2)));
        gc.drawString(objName, x1, y1, true);
        if (datas[i].isAlive == false) {
          gc.setForeground(dark_gary);
          gc.setLineWidth(2);
          gc.drawLine(
              x1 - 1,
              y1 + (gc.stringExtent(objName).y / 2),
              x1 + gc.stringExtent(objName).x + 1,
              y1 + (gc.stringExtent(objName).y / 2));
        }
        gc.setLineWidth(1);
        ActiveSpeedData asd = datas[i].asd;
        long total = asd.act1 + asd.act2 + asd.act3;
        double reach = barSpace * (total / maxValue);
        int barX = verticalLineX + 1;
        if (total > 0) {
          try {
            // distribute bars to 3 types
            int noOfBars = (int) reach / BAR_WIDTH;
            int noOfAct1 = (int) (noOfBars * ((double) asd.act1 / total));
            int noOfAct2 = (int) (noOfBars * ((double) asd.act2 / total));
            int noOfAct3 = (int) (noOfBars * ((double) asd.act3 / total));
            int sediments = noOfBars - (noOfAct1 + noOfAct2 + noOfAct3);
            while (sediments > 0) {
              if (asd.act3 > 0) {
                noOfAct3++;
                sediments--;
              }
              if (sediments > 0 && asd.act2 > 0) {
                noOfAct2++;
                sediments--;
              }
              if (sediments > 0 && asd.act1 > 0) {
                noOfAct1++;
                sediments--;
              }
            }
            int barY = AXIS_PADDING + ((unitHeight * i) + BAR_PADDING_HEIGHT);
            Color lastColor = null;

            for (int j = 0; j < noOfAct3; j++) {
              // draw red bar
              drawNemo(
                  gc,
                  ColorUtil.getInstance().ac3,
                  barX + 1,
                  barY + 1,
                  BAR_WIDTH - 2,
                  imgHeight - 2);
              barX += BAR_WIDTH;
              lastColor = ColorUtil.getInstance().ac3;
            }
            for (int j = 0; j < noOfAct2; j++) {
              // draw yellow bar
              drawNemo(
                  gc,
                  ColorUtil.getInstance().ac2,
                  barX + 1,
                  barY + 1,
                  BAR_WIDTH - 2,
                  imgHeight - 2);
              barX += BAR_WIDTH;
              lastColor = ColorUtil.getInstance().ac2;
            }
            for (int j = 0; j < noOfAct1; j++) {
              // draw blue bar
              drawNemo(
                  gc,
                  ColorUtil.getInstance().ac1,
                  barX + 1,
                  barY + 1,
                  BAR_WIDTH - 2,
                  imgHeight - 2);
              barX += BAR_WIDTH;
              lastColor = ColorUtil.getInstance().ac1;
            }

            // draw tong-tong bar
            if (lastColor != null) {
              drawNemo(
                  gc,
                  lastColor,
                  barX + 1 + (int) calculateReach(mod, BAR_WIDTH * 0.7d),
                  barY + 1,
                  BAR_WIDTH - 2,
                  imgHeight - 2);
            }
          } catch (Throwable th) {
            th.printStackTrace();
          }
        }

        // draw count text
        if (datas[i].isAlive) {
          gc.setFont(verdana10Bold);
          gc.setForeground(black);
          String v = Long.toString(total);
          gc.drawString(
              v,
              barX + (BAR_WIDTH * 2),
              AXIS_PADDING + (unitHeight * i) + ((unitHeight - gc.stringExtent(v).y) / 2),
              true);
        }
      }

      // draw scale text
      gc.setForeground(black);
      gc.setFont(verdana7);
      int max = (int) maxValue;
      String v = Integer.toString(max);
      String v2 = Integer.toString(max / 2);
      gc.drawString(v, width - gc.stringExtent(v).x - 2, 2, true);
      gc.drawString(
          v2, verticalLineX + ((width - verticalLineX) / 2) - gc.stringExtent(v2).x, 2, true);
      gc.drawString("0", verticalLineX, 2, true);
    } catch (Throwable th) {
      th.printStackTrace();
    } finally {
      gc.dispose();
      Image old = ibuffer;
      ibuffer = img;
      if (old != null) {
        old.dispose();
      }
      onGoing = false;
    }
  }
コード例 #9
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();
  }
コード例 #10
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();
  }