Package org.eclipse.swt.custom

Examples of org.eclipse.swt.custom.StyleRange


      public void paintObject(PaintObjectEvent event) {
        if(emoticons == null) {
          return;
        }
        GC gc = event.gc;
        StyleRange style = event.style;
        String text = styledTextHistory.getText(style.start,style.start + style.length);
        for(IconDef icon : emoticons.getIcons()) {
          for(String iconstr : icon.text) {
            if(iconstr.equals(text)) {
              gc.drawImage(icon.getImage(), event.x, event.y + event.ascent - style.metrics.ascent);
View Full Code Here


        }
       
        String historydate =  historyDateFormat.format(date == null ? new Date() : date) + " ";
       
        String prefixtext = (prefix == null ? "<" + jiddisplay + "> " : prefix + jiddisplay + " ");
        StyleRange dateRange = new StyleRange();
        dateRange.start = styledTextHistory.getText().length();
        dateRange.length = historydate.length();
        dateRange.fontStyle = SWT.BOLD;
       
        int msgStart = styledTextHistory.getText().length() + historydate.length();
        StyleRange range = new StyleRange();
        range.start = dateRange.start + dateRange.length;
        range.length = prefixtext.length();
        if(isMe(jid)) {
          range.foreground = styledTextHistory.getDisplay().getSystemColor(SWT.COLOR_RED);
        } else {
          range.foreground = styledTextHistory.getDisplay().getSystemColor(SWT.COLOR_BLUE);
        }
        range.fontStyle = SWT.BOLD;
        styledTextHistory.append(historydate + prefixtext);
        styledTextHistory.setStyleRange(dateRange);
        styledTextHistory.setStyleRange(range);
        if(usesXHTML) {
          SAXParserFactory fac = SAXParserFactory.newInstance();
          try {
            SAXParser parser = fac.newSAXParser();
           
            parser.parse(new InputSource(new StringReader("<body>"+msg+"</body>")),new ParseXHTMLForStyledText(styledTextHistory));
          } catch (ParserConfigurationException e) {
            e.printStackTrace();
          } catch (SAXException e) {
            e.printStackTrace();
          } catch (IOException e) {
            e.printStackTrace();
          }
         
        } else {
          styledTextHistory.append(msg);
        }
       
        String text = styledTextHistory.getText();
        text = text.substring(msgStart,text.length());

        if (emoticons != null) {
          for (IconDef def : emoticons.getIcons()) {
            for (String iconstr : def.text) {
              int index = text.indexOf(iconstr);
              if (index >= 0) {
                StyleRange iconRange = new StyleRange();
                iconRange.start = msgStart + index;
                iconRange.length = iconstr.length();
                Image image = def.getImage();
                Rectangle rect = image.getBounds();
                iconRange.metrics = new GlyphMetrics(rect.height,0,rect.width / iconstr.length());
View Full Code Here

  }


  private void makeInputSelectionBold() {
    Point range = chatInput.getSelectionRange();
    StyleRange style = new StyleRange();
    style.start = range.x;
    style.length = range.y;
    if (style.fontStyle == SWT.BOLD)
      style.fontStyle = SWT.NORMAL;
    else
View Full Code Here

    chatInput.setFocus();
  }

  private void makeInputSelectionUnderlined() {
    Point range = chatInput.getSelectionRange();
    StyleRange style = new StyleRange();
    style.start = range.x;
    style.length = range.y;
    style.underline = !style.underline;
    chatInput.setStyleRange(style);
    chatInput.setFocus();
View Full Code Here

    List<StyleRange> styleStack;
    private StyledText text;
    public ParseXHTMLForStyledText(StyledText text) {
      this.text = text;
      styleStack = new ArrayList<StyleRange>();
      styleStack.add(new StyleRange());
    }
View Full Code Here

    /* (non-Javadoc)
     * @see org.xml.sax.helpers.DefaultHandler#startElement(java.lang.String, java.lang.String, java.lang.String, org.xml.sax.Attributes)
     */
    @Override
    public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
      StyleRange range = styleStack.get(styleStack.size()-1);
      range = (StyleRange)range.clone();
      styleStack.add(range);
     
      String style = attributes.getValue("", "style");
      if(style != null) {
        String[] styles = style.split("\\s*;\\s*");
 
View Full Code Here

    /* (non-Javadoc)
     * @see org.xml.sax.helpers.DefaultHandler#characters(char[], int, int)
     */
    @Override
    public void characters(char[] ch, int start, int length) throws SAXException {
      StyleRange range = styleStack.get(styleStack.size()-1);
      int startPos = text.getText().length();
      text.append(new String(ch,start,length));
      StyleRange newRange = (StyleRange)range.clone();
      newRange.start = startPos;
      newRange.length = length;
      text.setStyleRange(newRange);
    }
View Full Code Here

    StyledText text = sourceViewer.getTextWidget();

    if (mCurrentStyleRange != null) {
      // reset current style range
      StyleRange resetedStyleRange = new StyleRange(mCurrentStyleRange.start,
              mCurrentStyleRange.length, null, null);

      text.setStyleRange(resetedStyleRange);
    }

    if (length != 0) {
      mCurrentStyleRange = new StyleRange(start, length, text.getSelectionForeground(), text
              .getSelectionBackground());

      text.setStyleRange(mCurrentStyleRange);
    }
  }
View Full Code Here

   * @param attr
   *          the attribute describing the style of the range to be styled
   */
  protected void addRange(TextPresentation presentation, int offset, int length, TextAttribute attr) {
    if (attr != null)
      presentation.addStyleRange(new StyleRange(offset, length, attr.getForeground(), attr
              .getBackground(), attr.getStyle()));
  }
View Full Code Here

    StyledText text = sourceViewer.getTextWidget();

    if (mCurrentStyleRange != null) {
      // reset current style range
      StyleRange resetedStyleRange = new StyleRange(mCurrentStyleRange.start,
              mCurrentStyleRange.length, null, null);

      text.setStyleRange(resetedStyleRange);
      mCurrentStyleRange = null;
    }

    if (length != 0) {
      mCurrentStyleRange = new StyleRange(start, length, text.getSelectionForeground(), text
              .getSelectionBackground());

      text.setStyleRange(mCurrentStyleRange);
    }
  }
View Full Code Here

TOP

Related Classes of org.eclipse.swt.custom.StyleRange

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.