Package org.eclipse.swt.graphics

Examples of org.eclipse.swt.graphics.GC


      return;
    }
    Image image = new Image(SWTThread.getInstance().getDisplay(), newWidth,
        newHeight);
    Color color;
    GC gcImage = new GC(image);
    gcImage.setForeground(Colors.grey);
    gcImage.drawRectangle(0, 0, x1 + 1, y1 + 1);
    int blocksPerPixel = 0;
    int iPixelsPerBlock = 0;
    int pxRes = 0;
    long pxBlockStep = 0;
    int factor = 4;

    while (iPixelsPerBlock <= 0) {
      blocksPerPixel++;
      iPixelsPerBlock = (int) ((x1 + 1) / (lNumBlocks / blocksPerPixel));
    }

    pxRes = (int) (x1 - ((lNumBlocks / blocksPerPixel) * iPixelsPerBlock)); // kolik mi zbyde
    if (pxRes <= 0)
      pxRes = 1;
    pxBlockStep = (lNumBlocks * factor) / pxRes; // kolikaty blok na +1 k sirce
    long addBlocks = (lNumBlocks * factor) / pxBlockStep;
    if ((addBlocks * iPixelsPerBlock) > pxRes)
      pxBlockStep += 1;

    /*      String msg = "iPixelsPerBlock = "+iPixelsPerBlock + ", blocksPerPixel = " + blocksPerPixel;
          msg += ", pxRes = " + pxRes + ", pxBlockStep = " + pxBlockStep + ", addBlocks = " + addBlocks + ", x1 = " + x1;
          Debug.out(msg);*/

    TOTorrent torrent = pePiece.getManager().getDiskManager().getTorrent();

    boolean[] written = pePiece.getDMPiece().getWritten();
    boolean piece_written = pePiece.isWritten();
    int drawnWidth = 0;
    int blockStep = 0;

    int pieceNumber = pePiece.getPieceNumber();
    long[] offsets = new long[(int) lNumBlocks];
    long[] lengths = (long[]) offsets.clone();
    Arrays.fill(offsets,
        (long) pePiece.getManager().getDiskManager().getPieceLength()
            * (long) pieceNumber);
    for (int i = 0; i < lNumBlocks; lengths[i] = pePiece.getBlockSize(i), offsets[i] += DiskManager.BLOCK_SIZE * i, i++)
      ;

    boolean[] isCached = cacheStats == null ? null
        : cacheStats.getBytesInCache(torrent, offsets, lengths);

    for (int i = 0; i < lNumBlocks; i += blocksPerPixel) {
      int nextWidth = iPixelsPerBlock;

      blockStep += blocksPerPixel * factor;
      if (blockStep >= pxBlockStep) { // pokud jsem prelezl dany pocet bloku, zvys tomuhle sirku
        nextWidth += (int) (blockStep / pxBlockStep);
        blockStep -= pxBlockStep;
      }

      if (i >= lNumBlocks - blocksPerPixel) { // pokud je posledni, at zasahuje az na konec
        nextWidth = x1 - drawnWidth;
      }
      color = Colors.white;

      if ((written == null && piece_written) || (written != null && written[i])) {

        color = colors[COLOR_WRITTEN];

      } else if (pePiece.isDownloaded(i)) {

        color = colors[COLOR_DOWNLOADED];

      } else if (pePiece.isRequested(i)) {

        color = colors[COLOR_REQUESTED];
      }

      gcImage.setBackground(color);
      gcImage.fillRectangle(drawnWidth + 1, 1, nextWidth, y1);

      if (isCached[i]) {
        gcImage.setBackground(colors[COLOR_INCACHE]);
        gcImage.fillRectangle(drawnWidth + 1, 1, nextWidth, 3);

      }

      drawnWidth += nextWidth;

    }
    gcImage.dispose();
   
    Image oldImage = null;
    Graphic graphic = cell.getGraphic();
    if (graphic instanceof UISWTGraphic) {
      oldImage = ((UISWTGraphic)graphic).getImage();
    }

    if (cell instanceof TableCellSWT) {
      ((TableCellSWT) cell).setGraphic(image);
    } else {
      cell.setGraphic(new UISWTGraphicImpl(image));
    }
    if (oldImage != null && !oldImage.isDisposed())
      oldImage.dispose();

    gcImage.dispose();
  }
View Full Code Here


      if(bufferScale != null && ! bufferScale.isDisposed())
        bufferScale.dispose();
     
      bufferScale = new Image(drawCanvas.getDisplay(),bounds);
     
      GC gcBuffer = new GC(bufferScale);
      try {
      gcBuffer.drawImage(bufferBackground,0,0);
      gcBuffer.setForeground(Colors.black);
      //gcImage.setBackground(null);
      scale.setNbPixels(bounds.height - 16);
      int[] levels = scale.getScaleValues();
      for(int i = 0 ; i < levels.length ; i++) {
        int height = bounds.height - scale.getScaledValue(levels[i]) - 2;
        gcBuffer.drawLine(1,height,bounds.width - 70 ,height);
        gcBuffer.drawText(formater.format(levels[i]),bounds.width - 65,height - 12,true);
      }
      if (this.update_divider_width > 0) {
        for (int i=bounds.width - 70; i > 0; i-=this.update_divider_width) {
          gcBuffer.setForeground(Colors.grey);
          gcBuffer.drawLine(i, 0, i, bounds.height);
        }
      }
      } catch (Exception e) {
        Debug.out(e);
      } finally {
        gcBuffer.dispose();
      }
    }
  }  
View Full Code Here

   
    if(internalLoop == 0 || sizeChanged) {
      drawChart(sizeChanged);
    }
   
    GC gc = new GC(drawCanvas);
    gc.drawImage(bufferImage,bounds.x,bounds.y);
    gc.dispose();   
  }
View Full Code Here

      if(bufferImage != null && ! bufferImage.isDisposed())
        bufferImage.dispose();
     
      bufferImage = new Image(drawCanvas.getDisplay(),bounds);
     
      GC gcImage = new GC(bufferImage);
     
      gcImage.drawImage(bufferScale,0,0);
     
      int oldAverage = 0;  
      int[] oldTargetValues = new int[all_values.length];
      int[] maxs = new int[all_values.length];
      for(int x = 0 ; x < bounds.width - 71 ; x++) {
        int position = currentPosition - x -1;
        if(position < 0)
          position+= 2000;
        for (int z=0;z<all_values.length;z++){
          int value = all_values[z][position];
          if(value > maxs[z]){
            maxs[z] = value;
          }
        }
      }
      int  max = 0;
      for (int i=0;i<maxs.length;i++){
        if(maxs[i] > max) {
          max = maxs[i];
        }
      }
     
      scale.setMax(max);
      int maxHeight = scale.getScaledValue(max);
      for(int x = 0 ; x < bounds.width - 71 ; x++) {
        int position = currentPosition - x -1;
        if(position < 0)
          position+= 2000;
       
        int xDraw = bounds.width - 71 - x;
        gcImage.setLineWidth(1);
        for (int z=0;z<all_values.length;z++){
          int targetValue   = all_values[z][position];
          int oldTargetValue   = oldTargetValues[z];
         
          if ( x > 1 ){           
              int h1 = bounds.height - scale.getScaledValue(targetValue) - 2;
              int h2 = bounds.height - scale.getScaledValue(oldTargetValue) - 2;
              gcImage.setForeground( z <= 2 ? colors[z+1] : colors[3]);
              gcImage.drawLine(xDraw,h1,xDraw+1, h2);           
          }
         
          oldTargetValues[z] = all_values[z][position];
        }
       
        int average = computeAverage(position);
        if(x > 6) {
          int h1 = bounds.height - scale.getScaledValue(average) - 2;
          int h2 = bounds.height - scale.getScaledValue(oldAverage) - 2;
          gcImage.setForeground(colors[COLOR_AVERAGE]);
          gcImage.setLineWidth(2);
          gcImage.drawLine(xDraw,h1,xDraw+1, h2);
        }
        oldAverage = average;
     
     
      if(nbValues > 0) {
        int height = bounds.height - scale.getScaledValue(computeAverage(currentPosition-6)) - 2;
        gcImage.setForeground(colors[COLOR_AVERAGE]);
        gcImage.drawText(formater.format(computeAverage(currentPosition-6)),bounds.width - 65,height - 12,true);
      }   
     
      gcImage.dispose();

    }finally{
     
      this_mon.exit();
    }
View Full Code Here

      Color colors[] = new Color[4];
      colors[0] = colorWhite;
      colors[1] = lightGrey;
      colors[2] = lightGrey2;
      colors[3] = lightGrey;
      GC gcBuffer = new GC(bufferBackground);
      for(int i = 0 ; i < bounds.height - 2 ; i++) {
        gcBuffer.setForeground(colors[i%4]);
        gcBuffer.drawLine(1,i+1,bounds.width-1,i+1);
      }      
      gcBuffer.setForeground(Colors.black);
      gcBuffer.drawLine(bounds.width-70,0,bounds.width-70,bounds.height-1);   
     
      gcBuffer.drawRectangle(0,0,bounds.width-1,bounds.height-1);
      gcBuffer.dispose();
    }
  }
View Full Code Here

        tableColumn = (TableColumnCore) row.getDataSource();

        if (event.image != null && !Constants.isLinux) {
          try {
            GC gc = new GC(event.image);
            try {
              Rectangle bounds = event.image.getBounds();
              gc.fillRectangle(bounds);
              String title = MessageText.getString(
                  tableColumn.getTitleLanguageKey(), tableColumn.getName());
              String s = title
                  + " Column will be placed at the location you drop it, shifting other columns down";
              GCStringPrinter sp = new GCStringPrinter(gc, s, bounds, false, false,
                  SWT.CENTER | SWT.WRAP);
              sp.calculateMetrics();
              if (sp.isCutoff()) {
                GCStringPrinter.printString(gc, title, bounds, false, false,
                    SWT.CENTER | SWT.WRAP);
              } else {
                sp.printString();
              }
            } finally {
              gc.dispose();
            }
          } catch (Throwable t) {
            //ignore
          }
        }
View Full Code Here

 
  private void updateButtonColor(final Display display, final int rV, final int gV, final int bV) {
    Image oldImg = img;
    Color color = ColorCache.getColor(display, rV, gV, bV);
    img = new Image(display,25,10);
    GC gc = new GC(img);
    gc.setBackground(color);
    gc.fillRectangle(0,0,25,10);
    gc.dispose();
    colorChooser.setImage(img);
    if(oldImg != null && ! oldImg.isDisposed())
      oldImg.dispose();
  }
View Full Code Here

    if (internalLoop == 0 || sizeChanged ){
     
      drawPlot();
    }

    GC gc = new GC(canvas);
   
    gc.drawImage(bufferImage,bounds.x,bounds.y);
   
    gc.dispose();  
  }
View Full Code Here

        bufferImage.dispose();
      }
     
      bufferImage = new Image( canvas.getDisplay(), bounds );

      GC image = new GC( bufferImage );

      int  max_x = 0;
      int  max_y = 0;
      int  max_z = 0;
     
      for (int i=0;i<values.length;i++){
       
        int[]  entry = (int[])values[i];
       
        if ( entry[0] > max_x ){
         
          max_x = entry[0];
        }
        if ( entry[1] > max_y ){
         
          max_y = entry[1];
        }
        if ( entry[2] > max_z ){
       
          max_z = entry[2];
        }
      }
     
     
      int usable_width   = bounds.width - PAD_LEFT - PAD_RIGHT;
      int usable_height  = bounds.height - PAD_TOP - PAD_BOTTOM;
     
      try {
        image.setAntialias( SWT.ON );
      } catch (Exception e) {
        // Ignore ERROR_NO_GRAPHICS_LIBRARY error or any others
      }
     
      double  x_ratio = ((float)usable_width-((usable_height/2)/ANGLE_TAN)) / max_x;
      double  y_ratio = ((float)usable_height/2) / max_y;
      double  z_ratio = ((float)usable_height/2) / max_z;
     
        // grid
     
      int x_axis_left_x = PAD_LEFT;
      int x_axis_left_y = usable_height + PAD_TOP;
      int x_axis_right_x = PAD_LEFT + usable_width;
      int x_axis_right_y  = usable_height + PAD_TOP;
     

      int y_axis_left_x = PAD_LEFT;
      int y_axis_left_y = usable_height + PAD_TOP;     
      int y_axis_right_x = PAD_LEFT + (int)((usable_height/2) / ANGLE_TAN );
      int y_axis_right_y = usable_height / 2;
     
      int z_axis_bottom_x = PAD_LEFT;
      int z_axis_bottom_y = usable_height + PAD_TOP;
      int z_axis_top_x  = PAD_LEFT;
      int z_axis_top_y  = PAD_TOP + usable_height / 2;
     
      Rectangle old_clip = image.getClipping();

      image.setClipping( new Rectangle( PAD_LEFT, PAD_RIGHT, usable_width, usable_height ));
     
      image.setForeground( Colors.light_grey );

      int  x_lines = 10;
     
      for (int i=1;i<x_lines;i++){
       
        int  x1 = x_axis_left_x + (( y_axis_right_x - y_axis_left_x )*i/x_lines);
        int  y1 = x_axis_left_y - (( y_axis_left_y - y_axis_right_y )*i/x_lines);
       
        int x2 = x_axis_right_x;
        int y2 = y1;
       
        image.drawLine( x1, y1, x2, y2 );
      }
     
      int  y_lines = 10;

      for (int i=1;i<y_lines;i++){
       
        int  x1 = y_axis_left_x + (( x_axis_right_x - x_axis_left_x )*i/x_lines);
        int  y1 = y_axis_left_y;
       
        int x2 = y_axis_right_x + (( x_axis_right_x - x_axis_left_x )*i/x_lines);
        int y2 = y_axis_right_y;
       
        image.drawLine( x1, y1, x2, y2 );
      }
     
      image.setClipping( old_clip );
     
      int  z_lines = 10;

      for (int i=1;i<z_lines;i++){

        int  z = z_axis_bottom_y + ( z_axis_top_y - z_axis_bottom_y )*i/z_lines;

        image.drawLine( z_axis_bottom_x, z, z_axis_bottom_x-4, z );
      }
     
        // now values
     
      for (int i=0;i<values.length;i++){
       
        int[]  entry = (int[])values[i];
       
        int  draw_x = (int)( x_ratio * entry[0] );
        int  draw_y = (int)( y_ratio * entry[1] );
        int  draw_z = (int)( z_ratio * entry[2] );
       
        draw_x += draw_y / ANGLE_TAN;
       
        image.setForeground( colours[(int)(((float)entry[2]/max_z)*(colours.length-1))]);
     
        image.drawLine(
            PAD_LEFT + draw_x,
            PAD_TOP + usable_height - draw_y,
            PAD_LEFT + draw_x,
            PAD_TOP + usable_height - ( draw_y + draw_z ));
      }
       
      image.setForeground( Colors.black );
     
      image.drawRectangle( bounds.x, bounds.y, bounds.width-1, bounds.height-1 );
     
      int  font_height = image.getFontMetrics().getHeight();
      int char_width  = image.getFontMetrics().getAverageCharWidth();
     
        // x axis
     
      image.drawLine( x_axis_left_x, x_axis_left_y, x_axis_right_x, x_axis_right_y );
      image.drawLine( usable_width, x_axis_right_y - 4, x_axis_right_x, x_axis_right_y );
      image.drawLine( usable_width, x_axis_right_y + 4, x_axis_right_x, x_axis_right_y );

      String x_text = labels[0] + " - " + formatters[0].format( max_x );
     
      image.drawText(
          x_text,
          x_axis_right_x - 20 - x_text.length()*char_width,
          x_axis_right_y - font_height - 2,
          SWT.DRAW_TRANSPARENT );
     
        // z axis
     
      String z_text = labels[2] + " - " + formatters[2].format( max_z );
     
      image.drawText( z_text, z_axis_top_x + 4, z_axis_top_y + 10, SWT.DRAW_TRANSPARENT );
     
      image.drawLine( z_axis_bottom_x, z_axis_bottom_y, z_axis_top_x, z_axis_top_y );
      image.drawLine( z_axis_top_x-4, z_axis_top_y + 10, z_axis_top_x, z_axis_top_y );
      image.drawLine( z_axis_top_x+4, z_axis_top_y + 10, z_axis_top_x, z_axis_top_y );

        // y axis
     
      image.drawLine( y_axis_left_x, y_axis_left_y, y_axis_right_x, y_axis_right_y );     
      image.drawLine( y_axis_right_x-6, y_axis_right_y,  y_axis_right_x, y_axis_right_y );     
      image.drawLine( y_axis_right_x, y_axis_right_y + 6, y_axis_right_x, y_axis_right_y );
     
      String  y_text = labels[1] + " - " + formatters[1].format( max_y );
     
      image.drawText(
          y_text,
          y_axis_right_x - (y_text.length() * char_width),
          y_axis_right_y - font_height - 2,
          SWT.DRAW_TRANSPARENT );


      image.drawText( title, ( bounds.width - title.length()*char_width )/2, 1, SWT.DRAW_TRANSPARENT );

      image.dispose();

    }finally{

      this_mon.exit();
    }
View Full Code Here

      imageBuffer = new int[drawWidth];
      bImageBufferValid = false;
    }

    Image image = (Image) infoObj.getUserData("PiecesImage");
    GC gcImage;
    boolean bImageChanged;
    Rectangle imageBounds;
    if (image == null || image.isDisposed()) {
      bImageChanged = true;
    } else {
      imageBounds = image.getBounds();
      bImageChanged = imageBounds.width != newWidth
          || imageBounds.height != newHeight;
    }
    if (bImageChanged) {
      if (image != null && !image.isDisposed()) {
        image.dispose();
      }
      image = new Image(SWTThread.getInstance().getDisplay(), newWidth,
          newHeight);
      imageBounds = image.getBounds();
      bImageBufferValid = false;

      // draw border
      gcImage = new GC(image);
      gcImage.setForeground(Colors.grey);
      if (borderHorizontalSize > 0) {
        if (borderVerticalSize > 0) {
          gcImage.drawRectangle(0, 0, newWidth - 1, newHeight - 1);
        } else {
          gcImage.drawLine(0, 0, newWidth - 1, 0);
          gcImage.drawLine(0, newHeight - 1, newWidth - 1, newHeight - 1);
        }
      } else if (borderVerticalSize > 0) {
        gcImage.drawLine(0, 0, 0, newHeight - 1);
        gcImage.drawLine(newWidth - 1, 0, newWidth - 1, newHeight - 1);
      }

      if (borderSplit > 0) {
        gcImage.setForeground(Colors.white);
        gcImage.drawLine(x0, completionHeight + borderHorizontalSize, x1,
            completionHeight + borderHorizontalSize);
      }
    } else {
      gcImage = new GC(image);
    }

    DiskManager disk_manager = infoObj.getDiskManager();

    DiskManagerPiece[] pieces = disk_manager == null ? null
        : disk_manager.getPieces();

    int nbPieces = infoObj.getNbPieces();

    try {

      int nbComplete = 0;
      int a0;
      int a1 = 0;
      for (int i = 0; i < drawWidth; i++) {
        if (i == 0) {
          // always start out with one piece
          a0 = 0;
          a1 = nbPieces / drawWidth;
          if (a1 == 0)
            a1 = 1;
        } else {
          // the last iteration, a1 will be nbPieces
          a0 = a1;
          a1 = ((i + 1) * nbPieces) / (drawWidth);
        }

        int index;

        if (a1 <= a0) {
          index = imageBuffer[i - 1];
        } else {
          int nbAvailable = 0;
          for (int j = a0; j < a1; j++)
            if (pieces != null && pieces[j].isDone())
              nbAvailable++;
          nbComplete += nbAvailable;
          index = (nbAvailable * Colors.BLUES_DARKEST) / (a1 - a0);
          //System.out.println("i="+i+";nbAvailable="+nbAvailable+";nbComplete="+nbComplete+";nbPieces="+nbPieces+";a0="+a0+";a1="+a1);
        }

        if (!bImageBufferValid || imageBuffer[i] != index) {
          imageBuffer[i] = index;
          bImageChanged = true;
          gcImage.setForeground(index == INDEX_COLOR_NONEAVAIL ? Colors.red
              : Colors.blues[index]);
          gcImage.drawLine(i + x0, y0, i + x0, y1);
        }
      }

      // pieces can sometimes be 0 due to timing or bad torrent (well, there's a bug with a /0 error
      // so it can happen somehow :)

      int limit = nbPieces == 0 ? 0 : ((drawWidth * nbComplete) / nbPieces);

      if (limit < drawWidth) {
        gcImage.setBackground(Colors.blues[Colors.BLUES_LIGHTEST]);
        gcImage.fillRectangle(limit + x0, borderHorizontalSize, x1 - limit,
            completionHeight);
      }

      gcImage.setBackground(Colors.colorProgressBar);
      gcImage.fillRectangle(x0, borderHorizontalSize, limit, completionHeight);
    } catch (Exception e) {
      System.out.println("Error Drawing PiecesItem");
      Debug.printStackTrace(e);
    }
    gcImage.dispose();

    Image oldImage = null;
    Graphic graphic = cell.getGraphic();
    if (graphic instanceof UISWTGraphic) {
      oldImage = ((UISWTGraphic) graphic).getImage();
View Full Code Here

TOP

Related Classes of org.eclipse.swt.graphics.GC

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.