org.eclipse.swt.custom.LineStyleEvent Java Examples

The following examples show how to use org.eclipse.swt.custom.LineStyleEvent. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: XdsConsoleViewer.java    From xds-ide with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void lineGetStyle(LineStyleEvent event) {
    // Overrided to don't show hyperlinks as original console do it 
    IDocument document = getDocument();
    if (document != null && document.getLength() > 0) {
        ArrayList<StyleRange> ranges = new ArrayList<StyleRange>();
        int offset = event.lineOffset;
        int length = event.lineText.length();

        StyleRange[] partitionerStyles = ((IConsoleDocumentPartitioner) document.getDocumentPartitioner()).getStyleRanges(event.lineOffset, event.lineText.length());
        if (partitionerStyles != null) {
            for (int i = 0; i < partitionerStyles.length; i++) {
                ranges.add(partitionerStyles[i]);
            }
        } else {
            ranges.add(new StyleRange(offset, length, null, null));
        }

        if (ranges.size() > 0) {
            event.styles = (StyleRange[]) ranges.toArray(new StyleRange[ranges.size()]);
        }
    }
}
 
Example #2
Source File: LogLineStyleListener.java    From AndroidRobot with Apache License 2.0 5 votes vote down vote up
@Override
public void lineGetStyle(LineStyleEvent event) {
	List<StyleRange> styles = new ArrayList<StyleRange>();
	String line = event.lineText;
	if(line == null || line.trim().equals(""))
		return;
	if(line.startsWith(keywords[0])){
		//[���Կ�ʼ]
		styles.add(new StyleRange(event.lineOffset, line.length(), colorBlue, null, SWT.NORMAL));
	}else if(line.startsWith(keywords[1])){
		//[���Խ��]
		if(line.contains(keywords[2]))
			styles.add(new StyleRange(event.lineOffset, line.length(), colorRed, null, SWT.NORMAL));
		else if(line.contains(keywords[3]))
			styles.add(new StyleRange(event.lineOffset, line.length(), colorGreen, null, SWT.NORMAL));
	}else if(line.startsWith(keywords[4])){
		//[��Ϣ]
		styles.add(new StyleRange(0, line.length(), colorRed, null, SWT.BOLD));
	}else if(line.startsWith(keywords[5])){
		//[��ѯ]
		if(line.contains(keywords[2]))
			styles.add(new StyleRange(event.lineOffset, line.length(), colorRed, null, SWT.NORMAL));
		else if(line.contains(keywords[6]))
			styles.add(new StyleRange(event.lineOffset, line.length(), colorGreen, null, SWT.NORMAL));
	}
	
	event.styles = (StyleRange[]) styles.toArray(new StyleRange[0]);
}
 
Example #3
Source File: SyntaxHighlighter.java    From RepDev with GNU General Public License v3.0 5 votes vote down vote up
public void lineGetStyle(LineStyleEvent event) {
	ArrayList<Token> ltokens = parser.getLtokens();
	ArrayList<StyleRange> ranges = new ArrayList<StyleRange>();

	int line = txt.getLineAtOffset(event.lineOffset);

	int ftoken;
	for (ftoken = 0; ftoken < ltokens.size(); ftoken++)
		if (ltokens.get(ftoken).getEnd() >= event.lineOffset)
			break;

	int ltoken = ltokens.size();
	if (line + 1 < txt.getLineCount()) {
		int pos = txt.getOffsetAtLine(line + 1);

		for (ltoken = ftoken; ltoken < ltokens.size(); ltoken++)
			if (ltokens.get(ltoken).getStart() > pos)
				break;
	}

	for (int i = ftoken; i < ltoken; i++){
		StyleRange range = getStyle(ltokens.get(i));			
		ranges.add(range);

		//If we are a backgroudn highlighted token, and a CODE SNIPPET one, then connect the highlighting over whitespace between tokens
		if( ltokens.get(i).getBackgroundReason() == SpecialBackgroundReason.CODE_SNIPPET )
			if( i + 1 < ltoken && ltokens.get(i+1).getBackgroundReason() == SpecialBackgroundReason.CODE_SNIPPET && ltokens.get(i+1).getSnippetVar() == ltokens.get(i).getSnippetVar())
				ranges.add(new StyleRange(ltokens.get(i).getEnd(),ltokens.get(i+1).getStart()-ltokens.get(i).getEnd(),null,ltokens.get(i).getSpecialBackground()));
	}

	StyleRange[] rangesArray = new StyleRange[ranges.size()];

	event.styles = ranges.toArray(rangesArray);
}
 
Example #4
Source File: ScriptConsoleViewerWrapper.java    From Pydev with Eclipse Public License 1.0 4 votes vote down vote up
public void lineGetStyle(LineStyleEvent event) {
    viewer.lineGetStyle(event);
}
 
Example #5
Source File: SOQLValuesHighlight.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
/**
 * Event.detail line start offset (input) Event.text line text (input) LineStyleEvent.styles Enumeration of
 * StyleRanges, need to be in order. (output) LineStyleEvent.background line background color (output)
 */
public void lineGetStyle( LineStyleEvent event ) {
  Vector<StyleRange> styles = new Vector<StyleRange>();
  int token;
  StyleRange lastStyle;

  if ( inBlockComment( event.lineOffset, event.lineOffset + event.lineText.length() ) ) {
    styles.addElement( new StyleRange( event.lineOffset, event.lineText.length() + 4, colors[1], null ) );
    event.styles = new StyleRange[styles.size()];
    styles.copyInto( event.styles );
    return;
  }
  scanner.setRange( event.lineText );
  String xs = ( (StyledText) event.widget ).getText();
  if ( xs != null ) {
    parseBlockComments( xs );
  }
  token = scanner.nextToken();
  while ( token != EOF ) {
    if ( token != OTHER ) {
      if ( ( token == WHITE ) && ( !styles.isEmpty() ) ) {
        int start = scanner.getStartOffset() + event.lineOffset;
        lastStyle = styles.lastElement();
        if ( lastStyle.fontStyle != SWT.NORMAL ) {
          if ( lastStyle.start + lastStyle.length == start ) {
            // have the white space take on the style before it to minimize font style
            // changes
            lastStyle.length += scanner.getLength();
          }
        }
      } else {
        Color color = getColor( token );
        if ( color != colors[0] ) { // hardcoded default foreground color, black
          StyleRange style =
            new StyleRange( scanner.getStartOffset() + event.lineOffset, scanner.getLength(), color, null );
          // if ( token == KEY ) {
          // style.fontStyle = SWT.BOLD;
          // }
          if ( styles.isEmpty() ) {
            styles.addElement( style );
          } else {
            lastStyle = styles.lastElement();
            if ( lastStyle.similarTo( style ) && ( lastStyle.start + lastStyle.length == style.start ) ) {
              lastStyle.length += style.length;
            } else {
              styles.addElement( style );
            }
          }
        }
      }
    }
    token = scanner.nextToken();
  }
  event.styles = new StyleRange[styles.size()];
  styles.copyInto( event.styles );
}
 
Example #6
Source File: LibFormulaValuesHighlight.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
/**
 * Event.detail line start offset (input) Event.text line text (input) LineStyleEvent.styles Enumeration of
 * StyleRanges, need to be in order. (output) LineStyleEvent.background line background color (output)
 */
public void lineGetStyle( LineStyleEvent event ) {
  Vector<StyleRange> styles = new Vector<StyleRange>();
  int token;
  StyleRange lastStyle;

  if ( inBlockComment( event.lineOffset, event.lineOffset + event.lineText.length() ) ) {
    styles.addElement( new StyleRange( event.lineOffset, event.lineText.length() + 4, colors[1], null ) );
    event.styles = new StyleRange[styles.size()];
    styles.copyInto( event.styles );
    return;
  }
  scanner.setRange( event.lineText );
  String xs = ( (StyledText) event.widget ).getText();
  if ( xs != null ) {
    parseBlockComments( xs );
  }
  token = scanner.nextToken();
  while ( token != EOF ) {
    if ( token != OTHER ) {
      if ( ( token == WHITE ) && ( !styles.isEmpty() ) ) {
        int start = scanner.getStartOffset() + event.lineOffset;
        lastStyle = styles.lastElement();
        if ( lastStyle.fontStyle != SWT.NORMAL ) {
          if ( lastStyle.start + lastStyle.length == start ) {
            // have the white space take on the style before it to minimize font style
            // changes
            lastStyle.length += scanner.getLength();
          }
        }
      } else {
        Color color = getColor( token );
        if ( color != colors[0] ) { // hardcoded default foreground color, black
          StyleRange style =
            new StyleRange( scanner.getStartOffset() + event.lineOffset, scanner.getLength(), color, null );
          if ( token == KEY ) {
            style.fontStyle = SWT.BOLD;
          }
          if ( styles.isEmpty() ) {
            styles.addElement( style );
          } else {
            lastStyle = styles.lastElement();
            if ( lastStyle.similarTo( style ) && ( lastStyle.start + lastStyle.length == style.start ) ) {
              lastStyle.length += style.length;
            } else {
              styles.addElement( style );
            }
          }
        }
      }
    }
    token = scanner.nextToken();
  }
  event.styles = new StyleRange[styles.size()];
  styles.copyInto( event.styles );
}
 
Example #7
Source File: MDXValuesHighlight.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
/**
 * Event.detail line start offset (input) Event.text line text (input) LineStyleEvent.styles Enumeration of
 * StyleRanges, need to be in order. (output) LineStyleEvent.background line background color (output)
 */
public void lineGetStyle( LineStyleEvent event ) {
  Vector<StyleRange> styles = new Vector<StyleRange>();
  int token;
  StyleRange lastStyle;

  if ( inBlockComment( event.lineOffset, event.lineOffset + event.lineText.length() ) ) {
    styles.addElement( new StyleRange( event.lineOffset, event.lineText.length() + 4, colors[1], null ) );
    event.styles = new StyleRange[styles.size()];
    styles.copyInto( event.styles );
    return;
  }
  scanner.setRange( event.lineText );
  String xs = ( (StyledText) event.widget ).getText();
  if ( xs != null ) {
    parseBlockComments( xs );
  }
  token = scanner.nextToken();
  while ( token != EOF ) {
    if ( token != OTHER ) {
      if ( ( token == WHITE ) && ( !styles.isEmpty() ) ) {
        int start = scanner.getStartOffset() + event.lineOffset;
        lastStyle = styles.lastElement();
        if ( lastStyle.fontStyle != SWT.NORMAL ) {
          if ( lastStyle.start + lastStyle.length == start ) {
            // have the white space take on the style before it to minimize font style
            // changes
            lastStyle.length += scanner.getLength();
          }
        }
      } else {
        Color color = getColor( token );
        if ( color != colors[0] ) { // hardcoded default foreground color, black
          StyleRange style =
            new StyleRange( scanner.getStartOffset() + event.lineOffset, scanner.getLength(), color, null );
          // if ( token == KEY ) {
          // style.fontStyle = SWT.BOLD;
          // }
          if ( styles.isEmpty() ) {
            styles.addElement( style );
          } else {
            lastStyle = styles.lastElement();
            if ( lastStyle.similarTo( style ) && ( lastStyle.start + lastStyle.length == style.start ) ) {
              lastStyle.length += style.length;
            } else {
              styles.addElement( style );
            }
          }
        }
      }
    }
    token = scanner.nextToken();
  }
  event.styles = new StyleRange[styles.size()];
  styles.copyInto( event.styles );
}
 
Example #8
Source File: SQLValuesHighlight.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
/**
 * Event.detail line start offset (input) Event.text line text (input) LineStyleEvent.styles Enumeration of
 * StyleRanges, need to be in order. (output) LineStyleEvent.background line background color (output)
 */
public void lineGetStyle( LineStyleEvent event ) {
  Vector<StyleRange> styles = new Vector<StyleRange>();
  int token;
  StyleRange lastStyle;

  if ( inBlockComment( event.lineOffset, event.lineOffset + event.lineText.length() ) ) {
    styles.addElement( new StyleRange( event.lineOffset, event.lineText.length() + 4, colors[1], null ) );
    event.styles = new StyleRange[styles.size()];
    styles.copyInto( event.styles );
    return;
  }
  scanner.setRange( event.lineText );
  String xs = ( (StyledText) event.widget ).getText();
  if ( xs != null ) {
    parseBlockComments( xs );
  }
  token = scanner.nextToken();
  while ( token != EOF ) {
    if ( token != OTHER ) {
      if ( ( token == WHITE ) && ( !styles.isEmpty() ) ) {
        int start = scanner.getStartOffset() + event.lineOffset;
        lastStyle = styles.lastElement();
        if ( lastStyle.fontStyle != SWT.NORMAL ) {
          if ( lastStyle.start + lastStyle.length == start ) {
            // have the white space take on the style before it to minimize font style
            // changes
            lastStyle.length += scanner.getLength();
          }
        }
      } else {
        Color color = getColor( token );
        if ( color != colors[0] ) { // hardcoded default foreground color, black
          StyleRange style =
            new StyleRange( scanner.getStartOffset() + event.lineOffset, scanner.getLength(), color, null );
          // if ( token == KEY ) {
          // style.fontStyle = SWT.BOLD;
          // }
          if ( styles.isEmpty() ) {
            styles.addElement( style );
          } else {
            lastStyle = styles.lastElement();
            if ( lastStyle.similarTo( style ) && ( lastStyle.start + lastStyle.length == style.start ) ) {
              lastStyle.length += style.length;
            } else {
              styles.addElement( style );
            }
          }
        }
      }
    }
    token = scanner.nextToken();
  }

  // See which backgrounds to color...
  //
  if ( scriptStatements != null ) {
    for ( SqlScriptStatement statement : scriptStatements ) {
      // Leave non-executed statements alone.
      //
      StyleRange styleRange = new StyleRange();
      styleRange.start = statement.getFromIndex();
      styleRange.length = statement.getToIndex() - statement.getFromIndex();

      if ( statement.isComplete() ) {
        if ( statement.isOk() ) {
          // GUIResource.getInstance().getColor(63, 127, 95), // green

          styleRange.background = GUIResource.getInstance().getColor( 244, 238, 224 ); // honey dew
        } else {
          styleRange.background = GUIResource.getInstance().getColor( 250, 235, 215 ); // Antique White
        }
      } else {
        styleRange.background = GUIResource.getInstance().getColorWhite();
      }

      styles.add( styleRange );
    }
  }

  event.styles = new StyleRange[styles.size()];
  styles.copyInto( event.styles );
}
 
Example #9
Source File: MDXValuesHighlight.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
/**
 * Event.detail line start offset (input) Event.text line text (input) LineStyleEvent.styles Enumeration of
 * StyleRanges, need to be in order. (output) LineStyleEvent.background line background color (output)
 */
public void lineGetStyle( LineStyleEvent event ) {
  Vector<StyleRange> styles = new Vector<StyleRange>();
  int token;
  StyleRange lastStyle;

  if ( inBlockComment( event.lineOffset, event.lineOffset + event.lineText.length() ) ) {
    styles.addElement( new StyleRange( event.lineOffset, event.lineText.length() + 4, colors[1], null ) );
    event.styles = new StyleRange[styles.size()];
    styles.copyInto( event.styles );
    return;
  }
  scanner.setRange( event.lineText );
  String xs = ( (StyledText) event.widget ).getText();
  if ( xs != null ) {
    parseBlockComments( xs );
  }
  token = scanner.nextToken();
  while ( token != EOF ) {
    if ( token != OTHER ) {
      if ( ( token == WHITE ) && ( !styles.isEmpty() ) ) {
        int start = scanner.getStartOffset() + event.lineOffset;
        lastStyle = styles.lastElement();
        if ( lastStyle.fontStyle != SWT.NORMAL ) {
          if ( lastStyle.start + lastStyle.length == start ) {
            // have the white space take on the style before it to minimize font style
            // changes
            lastStyle.length += scanner.getLength();
          }
        }
      } else {
        Color color = getColor( token );
        if ( color != colors[0] ) { // hardcoded default foreground color, black
          StyleRange style =
            new StyleRange( scanner.getStartOffset() + event.lineOffset, scanner.getLength(), color, null );
          // if ( token == KEY ) {
          // style.fontStyle = SWT.BOLD;
          // }
          if ( styles.isEmpty() ) {
            styles.addElement( style );
          } else {
            lastStyle = styles.lastElement();
            if ( lastStyle.similarTo( style ) && ( lastStyle.start + lastStyle.length == style.start ) ) {
              lastStyle.length += style.length;
            } else {
              styles.addElement( style );
            }
          }
        }
      }
    }
    token = scanner.nextToken();
  }
  event.styles = new StyleRange[styles.size()];
  styles.copyInto( event.styles );
}
 
Example #10
Source File: UserDefinedJavaClassHighlight.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
/**
 * Event.detail line start offset (input) Event.text line text (input) LineStyleEvent.styles Enumeration of
 * StyleRanges, need to be in order. (output) LineStyleEvent.background line background color (output)
 */
public void lineGetStyle( LineStyleEvent event ) {
  Vector<StyleRange> styles = new Vector<StyleRange>();
  int token;
  StyleRange lastStyle;

  if ( inBlockComment( event.lineOffset, event.lineOffset + event.lineText.length() ) ) {
    styles.addElement( new StyleRange( event.lineOffset, event.lineText.length() + 4, colors[2], null ) );
    event.styles = new StyleRange[styles.size()];
    styles.copyInto( event.styles );
    return;
  }
  scanner.setRange( event.lineText );
  String xs = ( (StyledText) event.widget ).getText();
  if ( xs != null ) {
    parseBlockComments( xs );
  }
  token = scanner.nextToken();
  while ( token != EOF ) {
    if ( token != OTHER ) {
      if ( ( token == WHITE ) && ( !styles.isEmpty() ) ) {
        int start = scanner.getStartOffset() + event.lineOffset;
        lastStyle = styles.lastElement();
        if ( lastStyle.fontStyle != SWT.NORMAL ) {
          if ( lastStyle.start + lastStyle.length == start ) {
            // have the white space take on the style before it to minimize font style
            // changes
            lastStyle.length += scanner.getLength();
          }
        }
      } else {
        Color color = getColor( token );
        if ( color != colors[0] ) { // hardcoded default foreground color, black
          StyleRange style =
            new StyleRange( scanner.getStartOffset() + event.lineOffset, scanner.getLength(), color, null );
          if ( token == KEY ) {
            style.fontStyle = SWT.BOLD;
          }
          if ( styles.isEmpty() ) {
            styles.addElement( style );
          } else {
            lastStyle = styles.lastElement();
            if ( lastStyle.similarTo( style ) && ( lastStyle.start + lastStyle.length == style.start ) ) {
              lastStyle.length += style.length;
            } else {
              styles.addElement( style );
            }
          }
        }
      }
    }
    token = scanner.nextToken();
  }
  event.styles = new StyleRange[styles.size()];
  styles.copyInto( event.styles );
}
 
Example #11
Source File: ScriptValuesHighlight.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
/**
 * Event.detail line start offset (input) Event.text line text (input) LineStyleEvent.styles Enumeration of
 * StyleRanges, need to be in order. (output) LineStyleEvent.background line background color (output)
 */
public void lineGetStyle( LineStyleEvent event ) {
  Vector<StyleRange> styles = new Vector<StyleRange>();
  int token;
  StyleRange lastStyle;

  if ( inBlockComment( event.lineOffset, event.lineOffset + event.lineText.length() ) ) {
    styles.addElement( new StyleRange( event.lineOffset, event.lineText.length() + 4, colors[2], null ) );
    event.styles = new StyleRange[styles.size()];
    styles.copyInto( event.styles );
    return;
  }
  scanner.setRange( event.lineText );
  String xs = ( (StyledText) event.widget ).getText();
  if ( xs != null ) {
    parseBlockComments( xs );
  }
  token = scanner.nextToken();
  while ( token != EOF ) {
    if ( token != OTHER ) {
      if ( ( token == WHITE ) && ( !styles.isEmpty() ) ) {
        int start = scanner.getStartOffset() + event.lineOffset;
        lastStyle = styles.lastElement();
        if ( lastStyle.fontStyle != SWT.NORMAL ) {
          if ( lastStyle.start + lastStyle.length == start ) {
            // have the white space take on the style before it to minimize font style
            // changes
            lastStyle.length += scanner.getLength();
          }
        }
      } else {
        Color color = getColor( token );
        if ( color != colors[0] ) { // hardcoded default foreground color, black
          StyleRange style =
            new StyleRange( scanner.getStartOffset() + event.lineOffset, scanner.getLength(), color, null );
          if ( token == KEY ) {
            style.fontStyle = SWT.BOLD;
          }
          if ( styles.isEmpty() ) {
            styles.addElement( style );
          } else {
            lastStyle = styles.lastElement();
            if ( lastStyle.similarTo( style ) && ( lastStyle.start + lastStyle.length == style.start ) ) {
              lastStyle.length += style.length;
            } else {
              styles.addElement( style );
            }
          }
        }
      }
    }
    token = scanner.nextToken();
  }
  event.styles = new StyleRange[styles.size()];
  styles.copyInto( event.styles );
}
 
Example #12
Source File: ScriptHighlight.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
/**
 * Event.detail line start offset (input) Event.text line text (input) LineStyleEvent.styles Enumeration of
 * StyleRanges, need to be in order. (output) LineStyleEvent.background line background color (output)
 */
public void lineGetStyle( LineStyleEvent event ) {
  Vector<StyleRange> styles = new Vector<StyleRange>();
  int token;
  StyleRange lastStyle;

  if ( inBlockComment( event.lineOffset, event.lineOffset + event.lineText.length() ) ) {
    styles.addElement( new StyleRange( event.lineOffset, event.lineText.length() + 4, colors[2], null ) );
    event.styles = new StyleRange[styles.size()];
    styles.copyInto( event.styles );
    return;
  }
  scanner.setRange( event.lineText );
  String xs = ( (StyledText) event.widget ).getText();
  if ( xs != null ) {
    parseBlockComments( xs );
  }
  token = scanner.nextToken();
  while ( token != EOF ) {
    if ( token != OTHER ) {
      if ( ( token == WHITE ) && ( !styles.isEmpty() ) ) {
        int start = scanner.getStartOffset() + event.lineOffset;
        lastStyle = styles.lastElement();
        if ( lastStyle.fontStyle != SWT.NORMAL ) {
          if ( lastStyle.start + lastStyle.length == start ) {
            // have the white space take on the style before it to minimize font style
            // changes
            lastStyle.length += scanner.getLength();
          }
        }
      } else {
        Color color = getColor( token );
        if ( color != colors[0] ) { // hardcoded default foreground color, black
          StyleRange style =
            new StyleRange( scanner.getStartOffset() + event.lineOffset, scanner.getLength(), color, null );
          if ( token == KEY ) {
            style.fontStyle = SWT.BOLD;
          }
          if ( styles.isEmpty() ) {
            styles.addElement( style );
          } else {
            lastStyle = styles.lastElement();
            if ( lastStyle.similarTo( style ) && ( lastStyle.start + lastStyle.length == style.start ) ) {
              lastStyle.length += style.length;
            } else {
              styles.addElement( style );
            }
          }
        }
      }
    }
    token = scanner.nextToken();
  }
  event.styles = new StyleRange[styles.size()];
  styles.copyInto( event.styles );
}
 
Example #13
Source File: SqlValuesHighlight.java    From hop with Apache License 2.0 4 votes vote down vote up
/**
 * Event.detail line start offset (input) Event.text line text (input) LineStyleEvent.styles Enumeration of
 * StyleRanges, need to be in order. (output) LineStyleEvent.background line background color (output)
 */
public void lineGetStyle( LineStyleEvent event ) {
  Vector<StyleRange> styles = new Vector<StyleRange>();
  int token;
  StyleRange lastStyle;

  if ( inBlockComment( event.lineOffset, event.lineOffset + event.lineText.length() ) ) {
    styles.addElement( new StyleRange( event.lineOffset, event.lineText.length() + 4, colors[ 1 ], null ) );
    event.styles = new StyleRange[ styles.size() ];
    styles.copyInto( event.styles );
    return;
  }
  scanner.setRange( event.lineText );
  String xs = ( (StyledText) event.widget ).getText();
  if ( xs != null ) {
    parseBlockComments( xs );
  }
  token = scanner.nextToken();
  while ( token != EOF ) {
    if ( token != OTHER ) {
      if ( ( token == WHITE ) && ( !styles.isEmpty() ) ) {
        int start = scanner.getStartOffset() + event.lineOffset;
        lastStyle = styles.lastElement();
        if ( lastStyle.fontStyle != SWT.NORMAL ) {
          if ( lastStyle.start + lastStyle.length == start ) {
            // have the white space take on the style before it to minimize font style
            // changes
            lastStyle.length += scanner.getLength();
          }
        }
      } else {
        Color color = getColor( token );
        if ( color != colors[ 0 ] ) { // hardcoded default foreground color, black
          StyleRange style =
            new StyleRange( scanner.getStartOffset() + event.lineOffset, scanner.getLength(), color, null );
          // if ( token == KEY ) {
          // style.fontStyle = SWT.BOLD;
          // }
          if ( styles.isEmpty() ) {
            styles.addElement( style );
          } else {
            lastStyle = styles.lastElement();
            if ( lastStyle.similarTo( style ) && ( lastStyle.start + lastStyle.length == style.start ) ) {
              lastStyle.length += style.length;
            } else {
              styles.addElement( style );
            }
          }
        }
      }
    }
    token = scanner.nextToken();
  }

  // See which backgrounds to color...
  //
  if ( scriptStatements != null ) {
    for ( SqlScriptStatement statement : scriptStatements ) {
      // Leave non-executed statements alone.
      //
      StyleRange styleRange = new StyleRange();
      styleRange.start = statement.getFromIndex();
      styleRange.length = statement.getToIndex() - statement.getFromIndex();

      if ( statement.isComplete() ) {
        if ( statement.isOk() ) {
          // GuiResource.getInstance().getColor(63, 127, 95), // green

          styleRange.background = GuiResource.getInstance().getColor( 244, 238, 224 ); // honey dew
        } else {
          styleRange.background = GuiResource.getInstance().getColor( 250, 235, 215 ); // Antique White
        }
      } else {
        styleRange.background = GuiResource.getInstance().getColorWhite();
      }

      styles.add( styleRange );
    }
  }

  event.styles = new StyleRange[ styles.size() ];
  styles.copyInto( event.styles );
}
 
Example #14
Source File: BibtexMergeDialog.java    From slr-toolkit with Eclipse Public License 1.0 4 votes vote down vote up
private void buildPreview(Composite container) {
	GridData gridData = new GridData();
	gridData.horizontalAlignment = SWT.RIGHT;
	gridData.verticalAlignment = SWT.TOP;
	gridData.grabExcessVerticalSpace = true;
	gridData.horizontalSpan = 1;
	gridData.verticalSpan = 5;

	Composite composite = new Composite(container, SWT.NONE);
	composite.setLayout(new GridLayout(1, false));
	composite.setLayoutData(gridData);

	// create overview
	Table table = new Table(composite, SWT.BORDER);
	table.setLayoutData(new GridData(SWT.RIGHT, SWT.FILL, true, true, 1, 1));

	TableColumn intersection = new TableColumn(table, SWT.CENTER);
	TableColumn mergeConflicts = new TableColumn(table, SWT.CENTER);
	TableColumn unionWithoutConflicts = new TableColumn(table, SWT.CENTER);
	intersection.setText("Intersection");
	mergeConflicts.setText("Merge conflicts");
	unionWithoutConflicts.setText("Union without conflicts");
	intersection.setWidth(80);
	mergeConflicts.setWidth(100);
	unionWithoutConflicts.setWidth(140);
	table.setHeaderVisible(true);

	previewStats = new TableItem(table, SWT.NONE);

	Label label = new Label(composite, SWT.NONE);
	label.setLayoutData(new GridData(SWT.RIGHT, SWT.FILL, true, true, 1, 1));
	label.setText("Preview: ");

	preview = new StyledText(composite, SWT.MULTI | SWT.WRAP | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
	preview.setLayoutData(new GridData(GridData.FILL_BOTH));
	preview.setEditable(false);
	preview.setEnabled(false);
	preview.setBlockSelection(true);

	// highlight current conflict
	initializeConflictIterator();
	preview.addLineStyleListener(new LineStyleListener() {
		public void lineGetStyle(LineStyleEvent event) {
			if (currentConflictedField == null
					|| currentConflictedResource.getConflictForField(currentConflictedField) == null)
				return;

			String currentConflict = currentConflictedResource.getConflictForField(currentConflictedField);
			StyleRange styleRange = new StyleRange();
			styleRange.start = preview.getText().indexOf(currentConflict);
			styleRange.length = currentConflict.length();
			styleRange.background = getParentShell().getDisplay().getSystemColor(SWT.COLOR_YELLOW);
			event.styles = new StyleRange[] { styleRange };
		}
	});

	GridData textGrid = new GridData(500, 500);
	textGrid.horizontalSpan = 2;
	preview.setLayoutData(textGrid);

	updatePreview();
}
 
Example #15
Source File: ScriptValuesHighlight.java    From hop with Apache License 2.0 4 votes vote down vote up
/**
 * Event.detail line start offset (input) Event.text line text (input) LineStyleEvent.styles Enumeration of
 * StyleRanges, need to be in order. (output) LineStyleEvent.background line background color (output)
 */
public void lineGetStyle( LineStyleEvent event ) {
  Vector<StyleRange> styles = new Vector<StyleRange>();
  int token;
  StyleRange lastStyle;

  if ( inBlockComment( event.lineOffset, event.lineOffset + event.lineText.length() ) ) {
    styles.addElement( new StyleRange( event.lineOffset, event.lineText.length() + 4, colors[ 2 ], null ) );
    event.styles = new StyleRange[ styles.size() ];
    styles.copyInto( event.styles );
    return;
  }
  scanner.setRange( event.lineText );
  String xs = ( (StyledText) event.widget ).getText();
  if ( xs != null ) {
    parseBlockComments( xs );
  }
  token = scanner.nextToken();
  while ( token != EOF ) {
    if ( token != OTHER ) {
      if ( ( token == WHITE ) && ( !styles.isEmpty() ) ) {
        int start = scanner.getStartOffset() + event.lineOffset;
        lastStyle = styles.lastElement();
        if ( lastStyle.fontStyle != SWT.NORMAL ) {
          if ( lastStyle.start + lastStyle.length == start ) {
            // have the white space take on the style before it to minimize font style
            // changes
            lastStyle.length += scanner.getLength();
          }
        }
      } else {
        Color color = getColor( token );
        if ( color != colors[ 0 ] ) { // hardcoded default foreground color, black
          StyleRange style =
            new StyleRange( scanner.getStartOffset() + event.lineOffset, scanner.getLength(), color, null );
          if ( token == KEY ) {
            style.fontStyle = SWT.BOLD;
          }
          if ( styles.isEmpty() ) {
            styles.addElement( style );
          } else {
            lastStyle = styles.lastElement();
            if ( lastStyle.similarTo( style ) && ( lastStyle.start + lastStyle.length == style.start ) ) {
              lastStyle.length += style.length;
            } else {
              styles.addElement( style );
            }
          }
        }
      }
    }
    token = scanner.nextToken();
  }
  event.styles = new StyleRange[ styles.size() ];
  styles.copyInto( event.styles );
}
 
Example #16
Source File: UserDefinedJavaClassHighlight.java    From hop with Apache License 2.0 4 votes vote down vote up
/**
 * Event.detail line start offset (input) Event.text line text (input) LineStyleEvent.styles Enumeration of
 * StyleRanges, need to be in order. (output) LineStyleEvent.background line background color (output)
 */
public void lineGetStyle( LineStyleEvent event ) {
  Vector<StyleRange> styles = new Vector<StyleRange>();
  int token;
  StyleRange lastStyle;

  if ( inBlockComment( event.lineOffset, event.lineOffset + event.lineText.length() ) ) {
    styles.addElement( new StyleRange( event.lineOffset, event.lineText.length() + 4, colors[ 2 ], null ) );
    event.styles = new StyleRange[ styles.size() ];
    styles.copyInto( event.styles );
    return;
  }
  scanner.setRange( event.lineText );
  String xs = ( (StyledText) event.widget ).getText();
  if ( xs != null ) {
    parseBlockComments( xs );
  }
  token = scanner.nextToken();
  while ( token != EOF ) {
    if ( token != OTHER ) {
      if ( ( token == WHITE ) && ( !styles.isEmpty() ) ) {
        int start = scanner.getStartOffset() + event.lineOffset;
        lastStyle = styles.lastElement();
        if ( lastStyle.fontStyle != SWT.NORMAL ) {
          if ( lastStyle.start + lastStyle.length == start ) {
            // have the white space take on the style before it to minimize font style
            // changes
            lastStyle.length += scanner.getLength();
          }
        }
      } else {
        Color color = getColor( token );
        if ( color != colors[ 0 ] ) { // hardcoded default foreground color, black
          StyleRange style =
            new StyleRange( scanner.getStartOffset() + event.lineOffset, scanner.getLength(), color, null );
          if ( token == KEY ) {
            style.fontStyle = SWT.BOLD;
          }
          if ( styles.isEmpty() ) {
            styles.addElement( style );
          } else {
            lastStyle = styles.lastElement();
            if ( lastStyle.similarTo( style ) && ( lastStyle.start + lastStyle.length == style.start ) ) {
              lastStyle.length += style.length;
            } else {
              styles.addElement( style );
            }
          }
        }
      }
    }
    token = scanner.nextToken();
  }
  event.styles = new StyleRange[ styles.size() ];
  styles.copyInto( event.styles );
}
 
Example #17
Source File: ScriptValuesHighlight.java    From hop with Apache License 2.0 4 votes vote down vote up
/**
 * Event.detail line start offset (input) Event.text line text (input) LineStyleEvent.styles Enumeration of
 * StyleRanges, need to be in order. (output) LineStyleEvent.background line background color (output)
 */
public void lineGetStyle( LineStyleEvent event ) {
  Vector<StyleRange> styles = new Vector<StyleRange>();
  int token;
  StyleRange lastStyle;

  if ( inBlockComment( event.lineOffset, event.lineOffset + event.lineText.length() ) ) {
    styles.addElement( new StyleRange( event.lineOffset, event.lineText.length() + 4, colors[ 2 ], null ) );
    event.styles = new StyleRange[ styles.size() ];
    styles.copyInto( event.styles );
    return;
  }
  scanner.setRange( event.lineText );
  String xs = ( (StyledText) event.widget ).getText();
  if ( xs != null ) {
    parseBlockComments( xs );
  }
  token = scanner.nextToken();
  while ( token != EOF ) {
    if ( token != OTHER ) {
      if ( ( token == WHITE ) && ( !styles.isEmpty() ) ) {
        int start = scanner.getStartOffset() + event.lineOffset;
        lastStyle = styles.lastElement();
        if ( lastStyle.fontStyle != SWT.NORMAL ) {
          if ( lastStyle.start + lastStyle.length == start ) {
            // have the white space take on the style before it to minimize font style
            // changes
            lastStyle.length += scanner.getLength();
          }
        }
      } else {
        Color color = getColor( token );
        if ( color != colors[ 0 ] ) { // hardcoded default foreground color, black
          StyleRange style =
            new StyleRange( scanner.getStartOffset() + event.lineOffset, scanner.getLength(), color, null );
          if ( token == KEY ) {
            style.fontStyle = SWT.BOLD;
          }
          if ( styles.isEmpty() ) {
            styles.addElement( style );
          } else {
            lastStyle = styles.lastElement();
            if ( lastStyle.similarTo( style ) && ( lastStyle.start + lastStyle.length == style.start ) ) {
              lastStyle.length += style.length;
            } else {
              styles.addElement( style );
            }
          }
        }
      }
    }
    token = scanner.nextToken();
  }
  event.styles = new StyleRange[ styles.size() ];
  styles.copyInto( event.styles );
}
 
Example #18
Source File: ScriptHighlight.java    From hop with Apache License 2.0 4 votes vote down vote up
/**
 * Event.detail line start offset (input) Event.text line text (input) LineStyleEvent.styles Enumeration of
 * StyleRanges, need to be in order. (output) LineStyleEvent.background line background color (output)
 */
public void lineGetStyle( LineStyleEvent event ) {
  Vector<StyleRange> styles = new Vector<StyleRange>();
  int token;
  StyleRange lastStyle;

  if ( inBlockComment( event.lineOffset, event.lineOffset + event.lineText.length() ) ) {
    styles.addElement( new StyleRange( event.lineOffset, event.lineText.length() + 4, colors[ 2 ], null ) );
    event.styles = new StyleRange[ styles.size() ];
    styles.copyInto( event.styles );
    return;
  }
  scanner.setRange( event.lineText );
  String xs = ( (StyledText) event.widget ).getText();
  if ( xs != null ) {
    parseBlockComments( xs );
  }
  token = scanner.nextToken();
  while ( token != EOF ) {
    if ( token != OTHER ) {
      if ( ( token == WHITE ) && ( !styles.isEmpty() ) ) {
        int start = scanner.getStartOffset() + event.lineOffset;
        lastStyle = styles.lastElement();
        if ( lastStyle.fontStyle != SWT.NORMAL ) {
          if ( lastStyle.start + lastStyle.length == start ) {
            // have the white space take on the style before it to minimize font style
            // changes
            lastStyle.length += scanner.getLength();
          }
        }
      } else {
        Color color = getColor( token );
        if ( color != colors[ 0 ] ) { // hardcoded default foreground color, black
          StyleRange style =
            new StyleRange( scanner.getStartOffset() + event.lineOffset, scanner.getLength(), color, null );
          if ( token == KEY ) {
            style.fontStyle = SWT.BOLD;
          }
          if ( styles.isEmpty() ) {
            styles.addElement( style );
          } else {
            lastStyle = styles.lastElement();
            if ( lastStyle.similarTo( style ) && ( lastStyle.start + lastStyle.length == style.start ) ) {
              lastStyle.length += style.length;
            } else {
              styles.addElement( style );
            }
          }
        }
      }
    }
    token = scanner.nextToken();
  }
  event.styles = new StyleRange[ styles.size() ];
  styles.copyInto( event.styles );
}