Package org.eclipse.swt.graphics

Examples of org.eclipse.swt.graphics.Point


  }

  public Point getSize() {
    Rectangle bounds = getBounds();
    if(bounds == null)
      return new Point(0, 0);
    return new Point(bounds.width - (marginWidth * 2),
                     bounds.height - (marginHeight * 2));
  }
View Full Code Here


   * @return
   *
   * @since 3.0.4.3
   */
  private boolean _printString() {
    size = new Point(0, 0);

    if (string == null) {
      return false;
    }

    if (printArea == null || printArea.isEmpty()) {
      return false;
    }

    ArrayList lines = new ArrayList();
   
    while (string.indexOf('\t') >= 0) {
      string = string.replace('\t', ' ');
    }

    boolean fullLinesOnly = (printFlags & FLAG_FULLLINESONLY) > 0;
    boolean skipClip = (printFlags & FLAG_SKIPCLIP) > 0;
    boolean noDraw = (printFlags & FLAG_NODRAW) > 0;
    boolean wrap = (swtFlags & SWT.WRAP) > 0;

    if ((printFlags & FLAG_KEEP_URL_INFO) == 0) {
      Matcher htmlMatcher = patHREF.matcher(string);
      boolean hasURL = htmlMatcher.find();
      if (hasURL) {
        listUrlInfo = new ArrayList(1);

        while (hasURL) {
          URLInfo urlInfo = new URLInfo();

          // Store the full ahref string once, then use substring which doesn't
          // create real strings :)
          urlInfo.fullString = htmlMatcher.group();
          urlInfo.relStartPos = htmlMatcher.start(0);

          urlInfo.url = string.substring(htmlMatcher.start(1),
              htmlMatcher.end(1));
          urlInfo.text = string.substring(htmlMatcher.start(2),
              htmlMatcher.end(2));
          urlInfo.titleLength = urlInfo.text.length();

          Matcher matcherTitle = patAHREF_TITLE.matcher(urlInfo.fullString);
          if (matcherTitle.find()) {
            urlInfo.title = string.substring(urlInfo.relStartPos
                + matcherTitle.start(1), urlInfo.relStartPos
                + matcherTitle.end(1));
          }

          Matcher matcherTarget = patAHREF_TARGET.matcher(urlInfo.fullString);
          if (matcherTarget.find()) {
            urlInfo.target = string.substring(urlInfo.relStartPos
                + matcherTarget.start(1), urlInfo.relStartPos
                + matcherTarget.end(1));
          }

          //System.out.println("URLINFO! " + urlInfo.fullString
          //    + "\ntarget="
          //    + urlInfo.target + "\ntt=" + urlInfo.title + "\nurl="
          //    + urlInfo.url + "\ntext=" + urlInfo.text + "\n\n");

          string = htmlMatcher.replaceFirst(urlInfo.text.replaceAll("\\$",
              "\\\\\\$"));
         
          listUrlInfo.add(urlInfo);
          htmlMatcher = patHREF.matcher(string);
          hasURL = htmlMatcher.find(urlInfo.relStartPos);
        }
      }
    } else {
      Matcher htmlMatcher = patHREF.matcher(string);
      string = htmlMatcher.replaceAll("$2");
    }

    Rectangle rectDraw = new Rectangle(printArea.x, printArea.y,
        printArea.width, printArea.height);

    Rectangle oldClipping = null;
    try {
      if (!skipClip && !noDraw) {
        oldClipping = gc.getClipping();

        // Protect the GC from drawing outside the drawing area
        gc.setClipping(printArea);
      }

      // Process string line by line
      int iCurrentHeight = 0;
      int currentCharPos = 0;
     
      int pos1 = string.indexOf('\n');
      int pos2 = string.indexOf('\r');
      if (pos2 == -1) {
        pos2 = pos1;
      }
      int posNewLine = Math.min(pos1, pos2);
      if (posNewLine < 0) {
        posNewLine = string.length();
      }
      int posLastNewLine = 0;
      while (posNewLine >= 0 && posLastNewLine < string.length()) {
        String sLine = string.substring(posLastNewLine, posNewLine);

        do {
          LineInfo lineInfo = new LineInfo(sLine, currentCharPos);
          lineInfo = processLine(gc, lineInfo, printArea, wrap, fullLinesOnly,
              false);
          String sProcessedLine = (String) lineInfo.lineOutputed;

          if (sProcessedLine != null && sProcessedLine.length() > 0) {
            if (lineInfo.width == 0 || lineInfo.height == 0) {
              Point gcExtent = gc.stringExtent(sProcessedLine);
              if (lineInfo.width == 0) {
                lineInfo.width = gcExtent.x;
              }
              if (lineInfo.height == 0) {
                lineInfo.height = gcExtent.y;
              }
            }
            Point extent = new Point(lineInfo.width, lineInfo.height);
            iCurrentHeight += extent.y;
            boolean isOverY = iCurrentHeight > printArea.height;

            if (DEBUG) {
              System.out.println("Adding Line: [" + sProcessedLine + "]"
View Full Code Here

        if (imageScales != null && imageScales.length > imgIdx) {
          bounds.width = (int) (bounds.width * imageScales[imgIdx]);
          bounds.height = (int) (bounds.height * imageScales[imgIdx]);
        }
       
        Point spaceExtent = gc.stringExtent(space.toString());
        int newWidth = lineInfo.width + bounds.width + spaceExtent.x;


        if (newWidth > printArea.width) {
          if (bounds.width + spaceExtent.x < printArea.width || lineInfo.width > 0) {
            return 0;
          }
        }
       
        if (lineInfo.imageIndexes == null) {
          lineInfo.imageIndexes = new int[] { imgIdx };
        }
       
        lineInfo.width = newWidth;
        lineInfo.height = Math.max(bounds.height, lineInfo.height);

        outputLine.append(space);
        outputLine.append(word);
        if (space.length() > 0) {
          space.delete(0, space.length());
        }
        space.append(' ');
       
        return -1;
      }
    }

    Point ptWordSize = gc.stringExtent(word + " ");
    boolean bWordLargerThanWidth = ptWordSize.x > printArea.width;
    int targetWidth = lineInfo.width + ptWordSize.x;
    if (targetWidth > printArea.width) {
      // word is longer than space avail, split
      int endIndex = word.length();
View Full Code Here

  private void drawLine(GC gc, LineInfo lineInfo, int swtFlags,
      Rectangle printArea, boolean noDraw) {
    String text = lineInfo.lineOutputed;
    // TODO: ensure width and height have values
    if (lineInfo.width == 0 || lineInfo.height == 0) {
      Point gcExtent = gc.stringExtent(text);;
      if (lineInfo.width == 0) {
        lineInfo.width = gcExtent.x;
      }
      if (lineInfo.height == 0) {
        lineInfo.height = gcExtent.y;
      }
    }
    Point drawSize = new Point(lineInfo.width, lineInfo.height);
   
    int x0;
    if ((swtFlags & SWT.RIGHT) > 0) {
      x0 = printArea.x + printArea.width - drawSize.x;
    } else if ((swtFlags & SWT.CENTER) > 0) {
      x0 = printArea.x + (printArea.width - drawSize.x) / 2;
    } else {
      x0 = printArea.x;
    }

    int y0 = printArea.y;

    int lineInfoRelEndPos = lineInfo.relStartPos
        + lineInfo.lineOutputed.length();
    int relStartPos = lineInfo.relStartPos;
    int lineStartPos = 0;

    URLInfo urlInfo = null;
    boolean drawURL = hasHitUrl();

    if (drawURL) {
      URLInfo[] hitUrlInfo = getHitUrlInfo();
      int nextHitUrlInfoPos = 0;

      while (drawURL) {
        drawURL = false;
        for (int i = nextHitUrlInfoPos; i < hitUrlInfo.length; i++) {
          urlInfo = hitUrlInfo[i];

          drawURL = (urlInfo.relStartPos < lineInfoRelEndPos)
              && (urlInfo.relStartPos + urlInfo.titleLength > relStartPos)
              && (relStartPos >= lineInfo.relStartPos)
              && (relStartPos < lineInfoRelEndPos);
          if (drawURL) {
            nextHitUrlInfoPos = i + 1;
            break;
          }
        }

        if (!drawURL) {
          break;
        }

        //int numHitUrlsAlready = urlInfo.hitAreas == null ? 0 : urlInfo.hitAreas.size();

        // draw text before url
        int i = lineStartPos + urlInfo.relStartPos - relStartPos;
        //System.out.println("numHitUrlsAlready = " + numHitUrlsAlready + ";i=" + i);
        if (i > 0 && i > lineStartPos && i <= text.length()) {
          String s = text.substring(lineStartPos, i);
          //gc.setBackground(gc.getDevice().getSystemColor(SWT.COLOR_RED));
          x0 += drawText(gc, s, x0, y0, lineInfo.height, null, noDraw).x;

          relStartPos += (i - lineStartPos);
          lineStartPos += (i - lineStartPos);
          //System.out.println("|" + s + "|" + textExtent.x);
        }

        // draw url text
        int end = i + urlInfo.titleLength;
        if (i < 0) {
          i = 0;
        }
        //System.out.println("end=" + end + ";" + text.length() + ";titlelen=" + urlInfo.titleLength);
        if (end > text.length()) {
          end = text.length();
        }
        String s = text.substring(i, end);
        relStartPos += (end - i);
        lineStartPos += (end - i);
        Point pt = null;
        //System.out.println("|" + s + "|");
        Color fgColor = null;
        if (!noDraw) {
          fgColor = gc.getForeground();
          if (urlInfo.urlColor != null) {
View Full Code Here

    printArea.y += drawSize.y;
  }
 
  private Point drawText(GC gc, String s, int x, int y, int height,
      List hitAreas, boolean nodraw) {
    Point textExtent;

    if (images != null) {
      int pctPos = s.indexOf('%');
      int lastPos = 0;
      int w = 0;
      int h = 0;
      while (pctPos >= 0) {
        if (pctPos >= 0 && s.length() > pctPos + 1) {
          int imgIdx = s.charAt(pctPos + 1) - '0';
         
          if (imgIdx >= images.length || imgIdx < 0 || images[imgIdx] == null) {
            String sStart = s.substring(lastPos, pctPos + 1);
            textExtent = gc.textExtent(sStart);
            int centerY = y + (height / 2 - textExtent.y / 2);
            if (hitAreas != null) {
              hitAreas.add(new Rectangle(x, centerY, textExtent.x, textExtent.y));
            }
            if (!nodraw) {
              gc.drawText(sStart, x, centerY, true);
            }
            x += textExtent.x;
            w += textExtent.x;
            h = Math.max(h, textExtent.y);

            lastPos = pctPos + 1;
            pctPos = s.indexOf('%', pctPos + 1);
            continue;
          }
         
          String sStart = s.substring(lastPos, pctPos);
          textExtent = gc.textExtent(sStart);
          int centerY = y + (height / 2 - textExtent.y / 2);
          if (!nodraw) {
            gc.drawText(sStart, x, centerY, true);
          }
          x += textExtent.x;
          w += textExtent.x;
          h = Math.max(h, textExtent.y);
          if (hitAreas != null) {
            hitAreas.add(new Rectangle(x, centerY, textExtent.x, textExtent.y));
          }

          //System.out.println("drawimage: " + x + "x" + y + ";idx=" + imgIdx);
          Rectangle imgBounds = images[imgIdx].getBounds();
          float scale = 1.0f;
          if (imageScales != null && imageScales.length > imgIdx) {
            scale = imageScales[imgIdx];
          }
          int scaleImageWidth = (int) (imgBounds.width * scale);
          int scaleImageHeight = (int) (imgBounds.height * scale);

         
          centerY = y + (height / 2 - scaleImageHeight / 2);
          if (hitAreas != null) {
            hitAreas.add(new Rectangle(x, centerY, scaleImageWidth, scaleImageHeight));
          }
          if (!nodraw) {
            //gc.drawImage(images[imgIdx], x, centerY);
            gc.drawImage(images[imgIdx], 0, 0, imgBounds.width,
                imgBounds.height, x, centerY, scaleImageWidth, scaleImageHeight);
          }
          x += scaleImageWidth;
          w += scaleImageWidth;
         
          h = Math.max(h, scaleImageHeight);
        }
        lastPos = pctPos + 2;
        pctPos = s.indexOf('%', lastPos);
      }

      if (s.length() >= lastPos) {
        String sEnd = s.substring(lastPos);
        textExtent = gc.textExtent(sEnd);
        int centerY = y + (height / 2 - textExtent.y / 2);
        if (hitAreas != null) {
          hitAreas.add(new Rectangle(x, centerY, textExtent.x, textExtent.y));
        }
        if (!nodraw) {
          gc.drawText(sEnd, x, centerY, true);
        }
        x += textExtent.x;
        w += textExtent.x;
        h = Math.max(h, textExtent.y);
      }
      return new Point(w, h);
    }


    if (!nodraw) {
      gc.drawText(s, x, y, true);
View Full Code Here

    shell.setLayout(new FillLayout());
    final Display display = shell.getDisplay();

    composite = new Composite(shell, SWT.DOUBLE_BUFFERED);

    final Point firstMousePos = display.getCursorLocation();

    composite.addTraverseListener(new TraverseListener() {
      public void keyTraversed(TraverseEvent e) {
        if (e.detail == SWT.TRAVERSE_ESCAPE) {
          setCancelled(true);
          shell.dispose();
        } else if (e.detail == SWT.TRAVERSE_ARROW_NEXT) {
          setValue(value + 1);
        } else if (e.detail == SWT.TRAVERSE_ARROW_PREVIOUS) {
          setValue(value - 1);
        } else if (e.detail == SWT.TRAVERSE_PAGE_NEXT) {
          setValue(value + bigPageIncrement);
        } else if (e.detail == SWT.TRAVERSE_PAGE_PREVIOUS) {
          setValue(value - bigPageIncrement);
        } else if (e.detail == SWT.TRAVERSE_RETURN) {
          setCancelled(false);
          shell.dispose();
        }
      }
    });

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

      public void keyPressed(KeyEvent e) {
        if (e.keyCode == SWT.PAGE_DOWN && e.stateMask == 0) {
          setValue(value + pageIncrement);
        } else if (e.keyCode == SWT.PAGE_UP && e.stateMask == 0) {
          setValue(value - pageIncrement);
        } else if (e.keyCode == SWT.HOME) {
          setValue(minValue);
        } else if (e.keyCode == SWT.END) {
          if (maxValue != -1) {
            setValue(maxValue);
          }
        }
      }
    });

    composite.addMouseMoveListener(new MouseMoveListener() {
      public void mouseMove(MouseEvent e) {
        lastMoveHadMouseDown = false;
        boolean hasButtonDown = (e.stateMask & SWT.BUTTON_MASK) > 0
            || assumeInitiallyDown;
        if (hasButtonDown) {
          if (e.y > HEIGHT - SCALER_HEIGHT) {
            lastMoveHadMouseDown = true;
            setValue(getValueFromMousePos(e.x));
          }
          composite.redraw();
        } else {
          composite.redraw();
        }
      }
    });

    composite.addMouseTrackListener(new MouseTrackListener() {
      boolean mouseIsOut = false;

      private boolean exitCancelled = false;

      public void mouseHover(MouseEvent e) {
      }

      public void mouseExit(MouseEvent e) {
      if (!exitCancelled) {
            shell.dispose();
        } else {
        exitCancelled = false;
        }
     
      }

      public void mouseEnter(MouseEvent e) {
        if (mouseIsOut) {
          exitCancelled = true;
        }
        mouseIsOut = false;
      }
    });

    composite.addMouseListener(new MouseListener() {
      boolean bMouseDown = false;

      public void mouseUp(MouseEvent e) {
        if (assumeInitiallyDown) {
          assumeInitiallyDown = false;
        }
        if (MOUSE_ONLY_UP_EXITS) {
          if (lastMoveHadMouseDown) {
            Point mousePos = display.getCursorLocation();
            if (mousePos.equals(firstMousePos)) {
              lastMoveHadMouseDown = false;
              return;
            }
          }
          bMouseDown = true;
        }
        if (bMouseDown) {
          if (e.y > HEIGHT - SCALER_HEIGHT) {
            setValue(getValueFromMousePos(e.x));
            setCancelled(false);
            if (lastMoveHadMouseDown) {
              shell.dispose();
            }
          } else if (e.y > TEXT_HEIGHT) {
            int idx = (e.y - TEXT_HEIGHT) / OPTION_HEIGHT;
            Iterator iterator = mapOptions.keySet().iterator();
            long newValue;
            do {
              newValue = ((Long) iterator.next()).intValue();
              idx--;
            } while (idx >= 0);
            value = newValue; // ignore min/max
            setCancelled(false);
            setMenuChosen(true);
            shell.dispose();
          }
        }
      }

      public void mouseDown(MouseEvent e) {
        if (e.count > 1) {
          lastMoveHadMouseDown = true;
          return;
        }
        Point mousePos = display.getCursorLocation();
        if (e.y > HEIGHT - SCALER_HEIGHT) {
          bMouseDown = true;
          setValue(getValueFromMousePos(e.x));
        }
      }

      public void mouseDoubleClick(MouseEvent e) {
      }

    });

    composite.addPaintListener(new PaintListener() {
      public void paintControl(PaintEvent e) {
        int x = (int)(WIDTH_NO_PADDING * value / maxValue);
        if (x < 0) {
          x = 0;
        } else if (x > WIDTH_NO_PADDING) {
          x = WIDTH_NO_PADDING;
        }
        int startX = (int)(WIDTH_NO_PADDING * startValue / maxValue);
        if (startX < 0) {
          startX = 0;
        } else if (startX > WIDTH_NO_PADDING) {
          startX = WIDTH_NO_PADDING;
        }
        int baseLinePos = getBaselinePos();

        try {
          e.gc.setAdvanced(true);
          e.gc.setAntialias(SWT.ON);
        } catch (Exception ex) {
          // aw
        }

        e.gc.setForeground(display.getSystemColor(SWT.COLOR_WIDGET_NORMAL_SHADOW));
        // left
        e.gc.drawLine(PADDING_X0, baseLinePos - 6, PADDING_X0, baseLinePos + 6);
        // right
        e.gc.drawLine(PADDING_X0 + WIDTH_NO_PADDING, baseLinePos - 6,
            PADDING_X0 + WIDTH_NO_PADDING, baseLinePos + 6);
        // baseline
        e.gc.drawLine(PADDING_X0, baseLinePos, PADDING_X0 + WIDTH_NO_PADDING,
            baseLinePos);

        e.gc.setForeground(display.getSystemColor(SWT.COLOR_WIDGET_FOREGROUND));
        e.gc.setBackground(display.getSystemColor(SWT.COLOR_WIDGET_FOREGROUND));
        // start value marker
        e.gc.drawLine(PADDING_X0 + startX, baseLinePos - 5,
            PADDING_X0 + startX, baseLinePos + 5);
        // current value marker
        e.gc.fillRoundRectangle(PADDING_X0 + x - 2, baseLinePos - 5, 5, 10, 10,
            10);

        // Current Value Text
        e.gc.setForeground(display.getSystemColor(SWT.COLOR_INFO_FOREGROUND));
        e.gc.setBackground(display.getSystemColor(SWT.COLOR_INFO_BACKGROUND));

        e.gc.fillRectangle(0, 0, WIDTH, TEXT_HEIGHT);

        GCStringPrinter.printString(e.gc,title+"\n"+ _getStringValue(), new Rectangle(0,
            0, WIDTH, HEIGHT), true, false, SWT.CENTER | SWT.TOP | SWT.WRAP);

        e.gc.drawLine(0, TEXT_HEIGHT - 1, WIDTH, TEXT_HEIGHT - 1);

        // options list
        int y = TEXT_HEIGHT;
        Point mousePos = composite.toControl(display.getCursorLocation());
        for (Iterator iter = mapOptions.keySet().iterator(); iter.hasNext();) {
          long value = (Long) iter.next();
          String text = (String) mapOptions.get(value);

          Rectangle area = new Rectangle(0, y, WIDTH, OPTION_HEIGHT);
          Color bg;
          if (area.contains(mousePos)) {
            bg = display.getSystemColor(SWT.COLOR_LIST_SELECTION);
            e.gc.setBackground(bg);
            e.gc.setForeground(display.getSystemColor(SWT.COLOR_LIST_SELECTION_TEXT));
            e.gc.fillRectangle(area);
          } else {
            bg = display.getSystemColor(SWT.COLOR_LIST_BACKGROUND);
            e.gc.setBackground(bg);
            e.gc.setForeground(display.getSystemColor(SWT.COLOR_LIST_FOREGROUND));
          }

          int ovalSize = OPTION_HEIGHT - 6;
          if (getValue() == value) {
            Color saveColor = e.gc.getBackground();
            e.gc.setBackground(e.gc.getForeground());
            e.gc.fillOval(4, y + 5, ovalSize - 3, ovalSize - 3);
            e.gc.setBackground(saveColor);
          }
          if (JMConstants.isLinux) {
            // Hack: on linux, drawing oval seems to draw a line from last pos
            // to start of oval.. drawing a point (anywhere) seems to clear the
            // path
            Color saveColor = e.gc.getForeground();
            e.gc.setForeground(bg);
            e.gc.drawPoint(2, y + 3);
            e.gc.setForeground(saveColor);
          }
          e.gc.drawOval(2, y + 3, ovalSize, ovalSize);

          GCStringPrinter.printString(e.gc, text, new Rectangle(OPTION_HEIGHT,
              y, WIDTH - OPTION_HEIGHT, OPTION_HEIGHT), true, false, SWT.LEFT);
          y += OPTION_HEIGHT;
        }

        // typed value
        if (sValue.length() > 0) {
          Point extent = e.gc.textExtent(sValue);
          if (extent.x > WIDTH - 10) {
            extent.x = WIDTH - 10;
          }
          Rectangle rect = new Rectangle(WIDTH - 8 - extent.x, 14,
              extent.x + 5, extent.y + 4 + 14 > TEXT_HEIGHT ? TEXT_HEIGHT - 15
                  : extent.y + 4);
          e.gc.setBackground(display.getSystemColor(SWT.COLOR_INFO_BACKGROUND));
          e.gc.fillRectangle(rect);

          try {
            e.gc.setAlpha(TYPED_TEXT_ALPHA);
          } catch (Exception ex) {
          }
          e.gc.setBackground(display.getSystemColor(SWT.COLOR_LIST_BACKGROUND));
          e.gc.setForeground(display.getSystemColor(SWT.COLOR_LIST_FOREGROUND));
          //e.gc.drawRectangle(rect);

          GCStringPrinter.printString(e.gc, sValue , new Rectangle(rect.x + 2,
              rect.y + 2, WIDTH - 5, OPTION_HEIGHT), true, false, SWT.LEFT
              | SWT.BOTTOM);
        }
      }
    });

    Point location = display.getCursorLocation();

    location.y -= getBaselinePos();
    int x = (int) (WIDTH_NO_PADDING * (value > maxValue ? 1 : (double) value
        / maxValue));
    location.x -= PADDING_X0 + x;
View Full Code Here

  public Object getData(String key) {
    return object_list.get(key);
  }

  public boolean setHeight(int iHeight) {
    return setIconSize(new Point(1, iHeight));
  }
View Full Code Here

      if (gc == null) {
        return;
      }
    }

    Point srcStart = new Point(clipping.x - bounds.x, clipping.y - bounds.y);
    Rectangle dstRect = new Rectangle(clipping.x, clipping.y,
        imageBounds.width - srcStart.x, imageBounds.height - srcStart.y);

    Utils.drawImage(gc, image, srcStart, dstRect, clipping, 0, 0, false);
   
View Full Code Here

  }
 
  public static boolean drawImage(GC gc, Image image, Rectangle dstRect,
      Rectangle clipping, int hOffset, int vOffset, boolean clearArea)
  {
    return drawImage(gc, image, new Point(0, 0), dstRect, clipping, hOffset,
        vOffset, clearArea);
  }
View Full Code Here

  }

  public static boolean drawImage(GC gc, Image image, Rectangle dstRect,
      Rectangle clipping, int hOffset, int vOffset)
  {
    return drawImage(gc, image, new Point(0, 0), dstRect, clipping, hOffset,
        vOffset, false);
  }
View Full Code Here

TOP

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

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.