Examples of GC


Examples of org.eclipse.swt.graphics.GC

        cell.setGraphic(null);
        return;
      }
     
      piecesImage = new Image(SWTThread.getInstance().getDisplay(), newWidth, newHeight);
      final GC gcImage = new GC(piecesImage);
     
      // dm may be null if this is a skeleton file view
      DownloadManager download_manager = fileInfo.getDownloadManager();
      PEPeerManager peer_manager = download_manager == null ? null : download_manager.getPeerManager();
      PEPiece[] pe_pieces = peer_manager == null ? null : peer_manager.getPieces();
      final long now = SystemTime.getCurrentTime();
     
      if (fileInfo != null && manager != null)
      {
        if (percentDone == 1000)
        {
          gcImage.setForeground(Colors.blues[Colors.BLUES_DARKEST]);
          gcImage.setBackground(Colors.blues[Colors.BLUES_DARKEST]);
          gcImage.fillRectangle(1, 1, newWidth - 2, newHeight - 2);
        } else
        {
          final int firstPiece = fileInfo.getFirstPieceNumber();
          final int nbPieces = fileInfo.getNbPieces();
          final DiskManagerPiece[] dm_pieces = manager.getPieces();
          bNoRed = true;
          for (int i = 0; i < newWidth; i++)
          {
            final int a0 = (i * nbPieces) / newWidth;
            int a1 = ((i + 1) * nbPieces) / newWidth;
            if (a1 == a0)
              a1++;
            if (a1 > nbPieces && nbPieces != 0)
              a1 = nbPieces;
            int nbAvailable = 0;
            boolean written = false;
            boolean partially_written = false;
            if (firstPiece >= 0)
              for (int j = a0; j < a1; j++)
              {
                final int this_index = j + firstPiece;
                final DiskManagerPiece dm_piece = dm_pieces[this_index];
                if (dm_piece.isDone())
                  nbAvailable++;
                if (written)
                  continue;
                if (pe_pieces != null)
                {
                  PEPiece pe_piece = pe_pieces[this_index];
                  if (pe_piece != null)
                    written = written || (pe_piece.getLastDownloadTime(now) + 500) > last_draw_time;
                }
                if ((!written) && (!partially_written))
                {
                  final boolean[] blocks = dm_piece.getWritten();
                  if (blocks != null)
                    for (int k = 0; k < blocks.length; k++)
                      if (blocks[k])
                      {
                        partially_written = true;
                        break;
                      }
                }
              } // for j
            else
              nbAvailable = 1;
            gcImage.setBackground(written ? Colors.red : partially_written ? Colors.grey : Colors.blues[(nbAvailable * Colors.BLUES_DARKEST) / (a1 - a0)]);
            gcImage.fillRectangle(i, 1, 1, newHeight - 2);
            if (written)
              bNoRed = false;
          }
          gcImage.setForeground(Colors.grey);
        }
      } else
        gcImage.setForeground(Colors.grey);
     
      if (manager != null)
        gcImage.drawRectangle(0, 0, newWidth - 1, newHeight - 1);
      gcImage.dispose();
     
      last_draw_time = now;
     
      if (cell instanceof TableCellSWT)
        ((TableCellSWT) cell).setGraphic(piecesImage);
View Full Code Here

Examples of org.eclipse.swt.graphics.GC

      Rectangle bounds = super.getBounds();
     
      int wInside = bounds.width - (marginWidth * 2);
      int hInside = bounds.height - (marginHeight * 2);
      Image imageCellBG = new Image(Display.getDefault(), wInside, hInside);
      GC gc = new GC(imageCellBG);
      gc.drawImage(imageRowBG, bounds.x + marginWidth, 0 + marginHeight,
          wInside, hInside, 0, 0, wInside, hInside);
      gc.dispose();
     
      return imageCellBG;
    }
   
    TableOrTreeSWT table = row.getTable();
   
    Rectangle bounds = super.getBounds();
   
    if (bounds.isEmpty()) {
      return null;
    }
   
    Image image = new Image(Display.getDefault(), bounds.width
        - (marginWidth * 2), bounds.height - (marginHeight * 2));
   
    GC gc = new GC(image);
    gc.setForeground(getBackground());
    gc.setBackground(getBackground());
    gc.fillRectangle(0, 0, bounds.width, bounds.height);
    gc.dispose();
   
    return image;
  }
View Full Code Here

Examples of org.eclipse.swt.graphics.GC

    consoleText.setLayoutData(gd);

    // XXX This doesn't work well, but it's better than nothing
    consoleText.addListener(SWT.Resize, new Listener() {
      public void handleEvent(Event event) {
        GC gc = new GC(consoleText);
        int charWidth = gc.getFontMetrics().getAverageCharWidth();
        gc.dispose();

        int areaWidth = consoleText.getBounds().width;
        consoleText.setTabs(areaWidth / 6 / charWidth);
      }
    });
View Full Code Here

Examples of org.eclipse.swt.graphics.GC

    private Image createGradientImage(int height, Display display) {
        int width= 50;

        Image result= new Image(display, width, height);

        GC gc= new GC(result);

        Color colorC= createColor(SWT.COLOR_WIDGET_BACKGROUND, SWT.COLOR_LIST_BACKGROUND, 35, display);
        Color colorD= createColor(SWT.COLOR_WIDGET_BACKGROUND, SWT.COLOR_LIST_BACKGROUND, 45, display);
        Color colorE= createColor(SWT.COLOR_WIDGET_BACKGROUND, SWT.COLOR_LIST_BACKGROUND, 80, display);
        Color colorF= createColor(SWT.COLOR_WIDGET_BACKGROUND, SWT.COLOR_LIST_BACKGROUND, 70, display);
        Color colorG= createColor(SWT.COLOR_WIDGET_BACKGROUND, SWT.COLOR_WHITE, 45, display);
        Color colorH= createColor(SWT.COLOR_WIDGET_NORMAL_SHADOW, SWT.COLOR_LIST_BACKGROUND, 35, display);

        try {
            drawLine(width, 0, colorC, gc);
            drawLine(width, 1, colorC, gc);

            gc.setForeground(colorD);
            gc.setBackground(colorE);
            gc.fillGradientRectangle(0, 2, width, 2 + 8, true);

            gc.setBackground(colorE);
            gc.fillRectangle(0, 2 + 9, width, height - 4);

            drawLine(width, height - 3, colorF, gc);
            drawLine(width, height - 2, colorG, gc);
            drawLine(width, height - 1, colorH, gc);

        } finally {
            gc.dispose();

            colorC.dispose();
            colorD.dispose();
            colorE.dispose();
            colorF.dispose();
View Full Code Here

Examples of org.eclipse.swt.graphics.GC

*/
public class PieUtils {

  private static Image computePie(Display display,int width,int height,int percent) {
    Image image = new Image(display,width,height);
    GC gcImage = new GC(image);
    gcImage.setForeground(Colors.blue);
    int angle = (percent * 360) / 100;
    gcImage.setBackground(Colors.blues[Colors.BLUES_MIDDARK]);
    gcImage.fillArc(0,0,width,height,90-angle,angle);
    gcImage.drawOval(0 , 0 , width-1, height-1);
    gcImage.dispose();
    return image;
  }
View Full Code Here

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

Examples of org.eclipse.swt.graphics.GC

      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

Examples of org.eclipse.swt.graphics.GC

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

Examples of org.eclipse.swt.graphics.GC

      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

Examples of org.eclipse.swt.graphics.GC

      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
TOP
Copyright © 2018 www.massapi.com. 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.