Java Code Examples for org.eclipse.swt.custom.StyleRange#similarTo()

The following examples show how to use org.eclipse.swt.custom.StyleRange#similarTo() . 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: 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 2
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 );
}
 
Example 3
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 4
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 5
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 6
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 7
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 8
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 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: 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 11
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 12
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 13
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 );
}