@Override
 public void setForegroundColor(final Color foreground) {
   super.setForegroundColor(foreground);
   fContentComposite.setForeground(foreground);
   fTitleText.setForeground(foreground);
   fInfoText.setForeground(foreground);
 }
Example #2
0
  public void initLogControl(StyledText log) {
    log.setFont(iniAppearance.getFontLog());
    log.setBackground(iniAppearance.getColorLogBackground());
    log.setForeground(iniAppearance.getColorLogBackground());

    logControls.add(log);
  }
 public static void main(String[] args) {
   final Display display = new Display();
   final Shell shell = new Shell(display);
   shell.setLayout(new FillLayout());
   final StyledText styledText = new StyledText(shell, SWT.WRAP | SWT.BORDER);
   styledText.setText(text);
   FontData data = display.getSystemFont().getFontData()[0];
   Font font = new Font(display, data.getName(), 16, SWT.BOLD);
   styledText.setFont(font);
   styledText.setForeground(display.getSystemColor(SWT.COLOR_BLUE));
   styledText.addListener(
       SWT.Resize,
       new Listener() {
         public void handleEvent(Event event) {
           Rectangle rect = styledText.getClientArea();
           Image newImage = new Image(display, 1, Math.max(1, rect.height));
           GC gc = new GC(newImage);
           gc.setForeground(display.getSystemColor(SWT.COLOR_WHITE));
           gc.setBackground(display.getSystemColor(SWT.COLOR_YELLOW));
           gc.fillGradientRectangle(rect.x, rect.y, 1, rect.height, true);
           gc.dispose();
           styledText.setBackgroundImage(newImage);
           if (oldImage != null) oldImage.dispose();
           oldImage = newImage;
         }
       });
   shell.setSize(700, 400);
   shell.open();
   while (!shell.isDisposed()) {
     if (!display.readAndDispatch()) display.sleep();
   }
   if (oldImage != null) oldImage.dispose();
   font.dispose();
   display.dispose();
 }
  private void styleViewer() {
    IPreferenceStore store = EditorsUI.getPreferenceStore();
    Color foreground = null;
    if (!store.getBoolean(AbstractTextEditor.PREFERENCE_COLOR_FOREGROUND_SYSTEM_DEFAULT))
      foreground = getEditorColor(AbstractTextEditor.PREFERENCE_COLOR_FOREGROUND);

    Color background = null;
    if (!store.getBoolean(AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT))
      background = getEditorColor(AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND);

    Color selectionForeground = null;
    if (!store.getBoolean(AbstractTextEditor.PREFERENCE_COLOR_SELECTION_FOREGROUND_SYSTEM_DEFAULT))
      selectionForeground =
          getEditorColor(AbstractTextEditor.PREFERENCE_COLOR_SELECTION_FOREGROUND);

    Color selectionBackground = null;
    if (!store.getBoolean(AbstractTextEditor.PREFERENCE_COLOR_SELECTION_BACKGROUND_SYSTEM_DEFAULT))
      selectionBackground =
          getEditorColor(AbstractTextEditor.PREFERENCE_COLOR_SELECTION_BACKGROUND);

    StyledText text = getTextWidget();
    text.setForeground(foreground);
    text.setBackground(background);
    text.setSelectionForeground(selectionForeground);
    text.setSelectionBackground(selectionBackground);
    text.setFont(JFaceResources.getFont(JFaceResources.TEXT_FONT));
    if (lineNumberRuler != null) {
      lineNumberRuler.setFont(text.getFont());
      lineNumberRuler.setForeground(foreground);
      lineNumberRuler.setBackground(background);
    }
  }
Example #5
0
  public void applyColor(ColorType type, RGB rgb) {
    Color newColor = new Color(SwtUtils.DISPLAY, rgb);
    Color oldColor = null;

    switch (type) {
      case BACKGROUND:
        {
          oldColor = iniAppearance.getColorBackground();

          for (Control control : controls) {
            if (control.isDisposed()) continue;

            control.setBackground(newColor);
          }
          for (Text chat : chatControls) {
            if (chat.isDisposed()) continue;

            chat.setBackground(newColor);
          }

          iniAppearance.setColorBackground(newColor);
          break;
        }
      case FOREGROUND:
        {
          oldColor = iniAppearance.getColorForeground();

          for (Control control : controls) {
            if (control.isDisposed()) continue;

            control.setForeground(newColor);
          }
          for (Text chat : chatControls) {
            if (chat.isDisposed()) continue;

            chat.setForeground(newColor);
          }

          iniAppearance.setColorForeground(newColor);
          break;
        }
      case LOG_BACKGROUND:
        {
          oldColor = iniAppearance.getColorLogBackground();

          for (StyledText text : logControls) {
            if (text.isDisposed()) continue;

            text.setBackground(newColor);
            text.setForeground(newColor);
          }

          iniAppearance.setColorLogBackground(newColor);
        }
    }

    if (oldColor != null) oldColor.dispose();
  }
Example #6
0
 /** Create the description */
 private void createDescription() {
   final StyledText labelDescription = new StyledText(this, SWT.WRAP | SWT.READ_ONLY);
   labelDescription.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, true));
   labelDescription.setEnabled(false);
   labelDescription.setFont(getFont());
   labelDescription.setForeground(getForeground());
   labelDescription.setText(this.description);
   SWTGraphicUtil.applyHTMLFormating(labelDescription);
 }
  private void updateStyles() {
    TextStyle theme = getTheme();
    textAttributeProvider.changeTheme(theme);

    StyledText textWidget = getSourceViewer().getTextWidget();
    textWidget.setBackground(colorManager.getColor(theme.getBackgroundOrDefault()));
    textWidget.setForeground(colorManager.getColor(theme.getForegroundOrDefault()));

    adjustCurrentLineColor(theme);
    getSourceViewer().invalidateTextPresentation();
  }
Example #8
0
  @Inject
  public void setTerminalForegroundColor(
      Display display,
      @Preference(
              nodePath = IConstant.PREFERENCE_NODE,
              value = IPreferenceKey.COLOR_TERMINAL_FOREGROUND)
          String rgbText) {

    terminalForegroundColor = new Color(display, StringConverter.asRGB(rgbText));
    if (terminalText != null && !terminalText.isDisposed())
      terminalText.setForeground(terminalForegroundColor);
  }
 /**
  * Changes style/coloring scheme into the specified.
  *
  * @param name Name of color scheme (HRD name).
  * @param useBackground If true, native HRD background properties would be assigned to colored
  *     StyledText.
  */
 public void setRegionMapper(String name, boolean useBackground) {
   baseEditor.setRegionMapper("rgb", name);
   StyledRegion sr = (StyledRegion) baseEditor.getBackground();
   text.setForeground(null);
   text.setBackground(null);
   if (useBackground) {
     text.setForeground(cm.getColor(sr.bfore, sr.fore));
     text.setBackground(cm.getColor(sr.bback, sr.back));
   }
   ;
   /*
   if ((sr.style & StyledRegion.BOLD) != 0){
     Font cf = text.getFont();
     FontData fdata[] = cf.getFontData();
     fdata[0].setStyle(SWT.BOLD);
     text.setFont(new Font(text.getDisplay(), fdata));
     System.out.println("font!");
   };
   */
   setCross(vertCross, horzCross);
 };
Example #10
0
  @PostConstruct
  public void createGui(
      Composite parent, MPart part, IEclipseContext context, MApplication application) {

    LOG.debug("createGui:");

    terminalText = new StyledText(parent, SWT.MULTI | SWT.V_SCROLL);
    terminalText.setEditable(false);
    terminalText.setForeground(terminalForegroundColor);
    terminalText.setBackground(terminalBackgroundColor);
    terminalText.setFont(terminalFont);

    restorePersistedState(application, part);
  }
Example #11
0
 public static void lightenStyledTextColors(StyledText st, double pct) {
   StyleRange[] srs = st.getStyleRanges();
   Color defaultFGColor = CCWPlugin.getColor(RGBUtil.lighten(st.getForeground().getRGB(), pct));
   for (int i = 0; i < srs.length; i++) {
     StyleRange oldSR = srs[i];
     StyleRange newSR = newStyleRange(oldSR);
     Color lightForeground =
         (oldSR.foreground == null)
             ? defaultFGColor
             : CCWPlugin.getColor(RGBUtil.lighten(oldSR.foreground.getRGB(), pct));
     newSR.foreground = lightForeground;
     st.setStyleRange(newSR);
   }
   st.setForeground(defaultFGColor);
 }
  /** ftang Comment method "handleErrorOutput". */
  protected void handleErrorOutput(
      Composite outputComposite, CTabFolder tabFolder, CTabItem outputTabItem, Exception... e) {

    // Dispose all existing controls.
    if (!outputComposite.isDisposed()) {
      Control[] children = outputComposite.getChildren();
      for (Control control : children) {
        if (!control.isDisposed()) {
          control.dispose();
        }
      }
    }

    Font font = new Font(Display.getDefault(), "courier", 8, SWT.NONE); // $NON-NLS-1$

    StyledText text =
        new StyledText(outputComposite, SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL | SWT.READ_ONLY);
    GridData gridData = new GridData(GridData.FILL_BOTH);
    text.setLayoutData(gridData);
    outputComposite.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_WHITE));

    Exception exception = getException();
    if (e != null && e.length == 1) {
      exception = e[0];
    }

    String errorInfo = exception.getMessage() + "\n"; // $NON-NLS-1$
    errorInfo =
        errorInfo
            + Messages.getString("FileStep2.previewFailure")
            + "\n"; //$NON-NLS-1$ //$NON-NLS-2$
    StackTraceElement[] stackTrace = exception.getStackTrace();
    for (StackTraceElement stackTraceElement : stackTrace) {
      errorInfo = errorInfo + stackTraceElement.toString() + "\n"; // $NON-NLS-1$
    }
    text.setText(errorInfo);
    text.setForeground(Display.getDefault().getSystemColor(SWT.COLOR_RED));
    text.setFont(font);

    tabFolder.setSelection(outputTabItem);
    outputComposite.layout(true);
  }
Example #13
0
  public CommandLineUIFactory(StyledText parentText) {
    parent = parentText;

    StyledText widget = new StyledText(parent, SWT.ON_TOP);
    widget.setFont(parent.getFont());
    widget.setMargins(COMMAND_CHAR_INDENT, 3, 3, 3);
    widget.setSize(5, 5);
    widget.setBackground(parent.getBackground());
    widget.setForeground(parent.getForeground());
    widget.setWordWrap(true);
    widget.setEnabled(true);
    //        widget.setCaretOffset(2);
    widget.moveAbove(parent);
    widget.setVisible(false);
    widget.addPaintListener(new BorderPaintListener());
    commandLineText = widget;

    parent.addPaintListener(new TextEditorPaintListener());
    parent.addFocusListener(
        new FocusAdapter() {
          @Override
          public void focusGained(FocusEvent e) {
            if (commandLineUI != null && commandLineUI.isOpen()) {
              commandLineText.forceFocus();
            }
          }
        });
    parent.addDisposeListener(
        new DisposeListener() {
          @Override
          public void widgetDisposed(DisposeEvent e) {
            commandLineText.dispose();
            if (commandLineUI != null) {
              commandLineUI.dispose();
            }
          }
        });
  }
  /*
   * @see ISourceViewer#configure(SourceViewerConfiguration)
   */
  @Override
  public void configure(SourceViewerConfiguration configuration) {

    /*
     * Prevent access to colors disposed in unconfigure(), see:
     *   https://bugs.eclipse.org/bugs/show_bug.cgi?id=53641
     *   https://bugs.eclipse.org/bugs/show_bug.cgi?id=86177
     */
    StyledText textWidget = getTextWidget();
    if (textWidget != null && !textWidget.isDisposed()) {
      Color foregroundColor = textWidget.getForeground();
      if (foregroundColor != null && foregroundColor.isDisposed()) textWidget.setForeground(null);
      Color backgroundColor = textWidget.getBackground();
      if (backgroundColor != null && backgroundColor.isDisposed()) textWidget.setBackground(null);
    }

    super.configure(configuration);
    if (configuration instanceof JavaSourceViewerConfiguration) {
      JavaSourceViewerConfiguration javaSVCconfiguration =
          (JavaSourceViewerConfiguration) configuration;
      fOutlinePresenter = javaSVCconfiguration.getOutlinePresenter(this, false);
      if (fOutlinePresenter != null) fOutlinePresenter.install(this);

      fStructurePresenter = javaSVCconfiguration.getOutlinePresenter(this, true);
      if (fStructurePresenter != null) fStructurePresenter.install(this);

      fHierarchyPresenter = javaSVCconfiguration.getHierarchyPresenter(this, true);
      if (fHierarchyPresenter != null) fHierarchyPresenter.install(this);
    }

    if (fPreferenceStore != null) {
      fPreferenceStore.addPropertyChangeListener(this);
      initializeViewerColors();
    }

    fIsConfigured = true;
  }
  /**
   * view command
   *
   * @param shell shell
   * @param repositoryTab repository tab
   * @param fileData file to view
   * @param revision revision to view
   */
  CommandView(
      final Shell shell,
      final RepositoryTab repositoryTab,
      final FileData fileData,
      final String revision) {
    Composite composite, subComposite;
    Label label;
    Button button;
    Listener listener;

    // initialize variables
    this.repositoryTab = repositoryTab;
    this.fileData = fileData;

    // get display
    display = shell.getDisplay();
    clipboard = new Clipboard(display);

    // add files dialog
    dialog = Dialogs.open(shell, "View: " + fileData.getFileName(), new double[] {1.0, 0.0}, 1.0);

    composite = Widgets.newComposite(dialog);
    composite.setLayout(new TableLayout(new double[] {0.0, 1.0, 0.0}, 1.0, 4));
    Widgets.layout(composite, 0, 0, TableLayoutData.NSWE, 0, 0, 4);
    {
      subComposite = Widgets.newComposite(composite);
      subComposite.setLayout(new TableLayout(1.0, new double[] {0.0, 1.0}));
      Widgets.layout(subComposite, 0, 0, TableLayoutData.WE);
      {
        label = Widgets.newLabel(subComposite, "Revision:");
        Widgets.layout(label, 0, 0, TableLayoutData.W);

        widgetRevision = Widgets.newSelect(subComposite);
        widgetRevision.setEnabled(false);
        Widgets.layout(widgetRevision, 0, 1, TableLayoutData.WE);
        Widgets.addModifyListener(
            new WidgetListener(widgetRevision, data) {
              public void modified(Control control) {
                Widgets.setEnabled(control, (data.revisionNames != null));
              }
            });
        widgetRevision.setToolTipText("Revision to view.");

        widgetRevisionPrev = Widgets.newButton(subComposite, Onzen.IMAGE_ARROW_LEFT);
        widgetRevisionPrev.setEnabled(false);
        Widgets.layout(widgetRevisionPrev, 0, 2, TableLayoutData.NSW);
        Widgets.addModifyListener(
            new WidgetListener(widgetRevisionPrev, data) {
              public void modified(Control control) {
                Widgets.setEnabled(
                    control,
                    (data.revisionNames != null) && (widgetRevision.getSelectionIndex() > 0));
              }
            });
        widgetRevisionPrev.setToolTipText("Show previous revision.");

        widgetRevisionNext = Widgets.newButton(subComposite, Onzen.IMAGE_ARROW_RIGHT);
        widgetRevisionNext.setEnabled(false);
        Widgets.layout(widgetRevisionNext, 0, 3, TableLayoutData.NSW);
        Widgets.addModifyListener(
            new WidgetListener(widgetRevisionNext, data) {
              public void modified(Control control) {

                Widgets.setEnabled(
                    control,
                    (data.revisionNames != null)
                        && (widgetRevision.getSelectionIndex() < data.revisionNames.length - 1));
              }
            });
        widgetRevisionNext.setToolTipText("Show next revision.");
      }

      subComposite = Widgets.newComposite(composite, SWT.H_SCROLL | SWT.V_SCROLL);
      subComposite.setLayout(new TableLayout(1.0, new double[] {0.0, 1.0}));
      Widgets.layout(subComposite, 1, 0, TableLayoutData.NSWE);
      {
        widgetLineNumbers = Widgets.newTextView(subComposite, SWT.RIGHT | SWT.BORDER | SWT.MULTI);
        widgetLineNumbers.setForeground(Onzen.COLOR_GRAY);
        Widgets.layout(widgetLineNumbers, 0, 0, TableLayoutData.NS, 0, 0, 0, 0, 60, SWT.DEFAULT);
        Widgets.addModifyListener(
            new WidgetListener(widgetLineNumbers, data) {
              public void modified(Control control) {
                control.setForeground((data.lines != null) ? null : Onzen.COLOR_GRAY);
              }
            });

        widgetText = Widgets.newTextView(subComposite, SWT.LEFT | SWT.BORDER | SWT.MULTI);
        widgetText.setForeground(Onzen.COLOR_GRAY);
        Widgets.layout(widgetText, 0, 1, TableLayoutData.NSWE);
        Widgets.addModifyListener(
            new WidgetListener(widgetText, data) {
              public void modified(Control control) {
                control.setForeground((data.lines != null) ? null : Onzen.COLOR_GRAY);
              }
            });
      }
      widgetHorizontalScrollBar = subComposite.getHorizontalBar();
      widgetVerticalScrollBar = subComposite.getVerticalBar();

      subComposite = Widgets.newComposite(composite);
      subComposite.setLayout(new TableLayout(1.0, new double[] {0.0, 1.0}));
      Widgets.layout(subComposite, 2, 0, TableLayoutData.NSWE);
      {
        label = Widgets.newLabel(subComposite, "Find:", SWT.NONE, Settings.keyFind);
        Widgets.layout(label, 0, 0, TableLayoutData.W);

        widgetFind = Widgets.newText(subComposite, SWT.SEARCH | SWT.ICON_CANCEL);
        widgetFind.setMessage("Enter text to find");
        Widgets.layout(widgetFind, 0, 1, TableLayoutData.WE);

        widgetFindPrev = Widgets.newButton(subComposite, Onzen.IMAGE_ARROW_UP);
        widgetFindPrev.setEnabled(false);
        Widgets.layout(widgetFindPrev, 0, 2, TableLayoutData.NSW);
        Widgets.addModifyListener(
            new WidgetListener(widgetFindPrev, data) {
              public void modified(Control control) {
                Widgets.setEnabled(control, (data.lines != null));
              }
            });
        widgetFindPrev.setToolTipText(
            "Find previous occurrence of text ["
                + Widgets.acceleratorToText(Settings.keyFindPrev)
                + "].");

        widgetFindNext = Widgets.newButton(subComposite, Onzen.IMAGE_ARROW_DOWN);
        widgetFindNext.setEnabled(false);
        Widgets.layout(widgetFindNext, 0, 3, TableLayoutData.NSW);
        Widgets.addModifyListener(
            new WidgetListener(widgetFindNext, data) {
              public void modified(Control control) {
                Widgets.setEnabled(control, (data.lines != null));
              }
            });
        widgetFindNext.setToolTipText(
            "Find next occurrence of text  ["
                + Widgets.acceleratorToText(Settings.keyFindNext)
                + "].");
      }
    }

    // buttons
    composite = Widgets.newComposite(dialog);
    composite.setLayout(new TableLayout(0.0, 1.0));
    Widgets.layout(composite, 1, 0, TableLayoutData.WE, 0, 0, 4);
    {
      button = Widgets.newButton(composite, "Save as...");
      Widgets.layout(
          button, 0, 0, TableLayoutData.W, 0, 0, 0, 0, SWT.DEFAULT, SWT.DEFAULT, 70, SWT.DEFAULT);
      button.addSelectionListener(
          new SelectionListener() {
            public void widgetDefaultSelected(SelectionEvent selectionEvent) {}

            public void widgetSelected(SelectionEvent selectionEvent) {
              // get file name
              String fileName = Dialogs.fileSave(dialog, "Save file", "", new String[] {"*"});
              if (fileName == null) {
                return;
              }

              // check if file exists: overwrite or append
              File file = new File(fileName);
              if (file.exists()) {
                switch (Dialogs.select(
                    dialog,
                    "Confirmation",
                    String.format("File '%s' already exists.", fileName),
                    new String[] {"Overwrite", "Append", "Cancel"},
                    2)) {
                  case 0:
                    if (!file.delete()) {
                      Dialogs.error(dialog, "Cannot delete file!");
                      return;
                    }
                  case 1:
                    break;
                  case 2:
                    return;
                }
              }

              PrintWriter output = null;
              try {
                // open file
                output = new PrintWriter(new FileWriter(file, true));

                // write/append file
                for (String line : data.lines) {
                  output.println(line);
                }

                // close file
                output.close();
              } catch (IOException exception) {
                Dialogs.error(
                    dialog,
                    "Cannot write file '" + file.getName() + "' (error: " + exception.getMessage());
                return;
              } finally {
                if (output != null) output.close();
              }
            }
          });

      widgetClose = Widgets.newButton(composite, "Close");
      Widgets.layout(
          widgetClose,
          0,
          1,
          TableLayoutData.E,
          0,
          0,
          0,
          0,
          SWT.DEFAULT,
          SWT.DEFAULT,
          70,
          SWT.DEFAULT);
      widgetClose.addSelectionListener(
          new SelectionListener() {
            public void widgetDefaultSelected(SelectionEvent selectionEvent) {}

            public void widgetSelected(SelectionEvent selectionEvent) {
              Settings.geometryView = dialog.getSize();

              Dialogs.close(dialog, false);
            }
          });
    }

    // listeners
    widgetRevision.addSelectionListener(
        new SelectionListener() {
          public void widgetDefaultSelected(SelectionEvent selectionEvent) {}

          public void widgetSelected(SelectionEvent selectionEvent) {
            Combo widget = (Combo) selectionEvent.widget;

            int index = widget.getSelectionIndex();
            if ((data.revisionNames != null)
                && (index >= 0)
                && (index < data.revisionNames.length)) {
              show(data.revisionNames[index]);
            }
          }
        });
    widgetRevisionPrev.addSelectionListener(
        new SelectionListener() {
          public void widgetDefaultSelected(SelectionEvent selectionEvent) {}

          public void widgetSelected(SelectionEvent selectionEvent) {
            int index = widgetRevision.getSelectionIndex();
            if (index > 0) {
              show(data.revisionNames[index - 1]);
            }
          }
        });
    widgetRevisionNext.addSelectionListener(
        new SelectionListener() {
          public void widgetDefaultSelected(SelectionEvent selectionEvent) {}

          public void widgetSelected(SelectionEvent selectionEvent) {
            int index = widgetRevision.getSelectionIndex();
            if ((data.revisionNames != null) && (index < data.revisionNames.length - 1)) {
              show(data.revisionNames[index + 1]);
            }
          }
        });

    listener =
        new Listener() {
          public void handleEvent(Event event) {
            StyledText widget = (StyledText) event.widget;
            int topIndex = widget.getTopIndex();
            // Dprintf.dprintf("%d %d",widget.getTopPixel(),widgetText.getTopPixel());

            widgetText.setTopIndex(topIndex);
            widgetText.setCaretOffset(widgetText.getOffsetAtLine(topIndex));
          }
        };
    widgetLineNumbers.addListener(SWT.KeyDown, listener);
    widgetLineNumbers.addListener(SWT.KeyUp, listener);
    widgetLineNumbers.addListener(SWT.MouseDown, listener);
    widgetLineNumbers.addListener(SWT.MouseUp, listener);
    widgetLineNumbers.addListener(SWT.MouseMove, listener);
    widgetLineNumbers.addListener(SWT.Resize, listener);

    listener =
        new Listener() {
          public void handleEvent(Event event) {
            StyledText widget = (StyledText) event.widget;
            int topIndex = widget.getTopIndex();
            // Dprintf.dprintf("widget=%s: %d",widget,widget.getTopIndex());

            widgetLineNumbers.setTopIndex(topIndex);
            widgetVerticalScrollBar.setSelection(topIndex);
          }
        };
    widgetText.addListener(SWT.KeyDown, listener);
    widgetText.addListener(SWT.KeyUp, listener);
    widgetText.addListener(SWT.MouseDown, listener);
    widgetText.addListener(SWT.MouseUp, listener);
    widgetText.addListener(SWT.MouseMove, listener);
    widgetText.addListener(SWT.Resize, listener);
    widgetText.addLineStyleListener(
        new LineStyleListener() {
          public void lineGetStyle(LineStyleEvent lineStyleEvent) {
            // Dprintf.dprintf("x %d %s",lineStyleEvent.lineOffset,lineStyleEvent.lineText);
            String findText = widgetFind.getText().toLowerCase();
            int findTextLength = findText.length();
            if (findTextLength > 0) {
              ArrayList<StyleRange> styleRangeList = new ArrayList<StyleRange>();
              int index = 0;
              while ((index = lineStyleEvent.lineText.toLowerCase().indexOf(findText, index))
                  >= 0) {
                styleRangeList.add(
                    new StyleRange(
                        lineStyleEvent.lineOffset + index,
                        findTextLength,
                        COLOR_VIEW_SEARCH_TEXT,
                        COLOR_VIEW_SEARCH_BACKGROUND));
                index += findTextLength;
              }
              lineStyleEvent.styles = styleRangeList.toArray(new StyleRange[styleRangeList.size()]);
              // Dprintf.dprintf("lineStyleEvent.styles=%d",lineStyleEvent.styles.length);
            } else {
              lineStyleEvent.styles = null;
            }
          }
        });
    widgetText.addKeyListener(
        new KeyListener() {
          public void keyPressed(KeyEvent keyEvent) {
            if (Widgets.isAccelerator(keyEvent, SWT.CTRL + 'c')) {
              Widgets.setClipboard(clipboard, widgetText.getSelectionText());
            }
          }

          public void keyReleased(KeyEvent keyEvent) {}
        });
    widgetHorizontalScrollBar.addSelectionListener(
        new SelectionListener() {
          public void widgetDefaultSelected(SelectionEvent selectionEvent) {}

          public void widgetSelected(SelectionEvent selectionEvent) {
            ScrollBar widget = (ScrollBar) selectionEvent.widget;
            int index = widget.getSelection();

            // sync text widget
            widgetText.setHorizontalIndex(index);
          }
        });
    widgetVerticalScrollBar.addSelectionListener(
        new SelectionListener() {
          public void widgetDefaultSelected(SelectionEvent selectionEvent) {}

          public void widgetSelected(SelectionEvent selectionEvent) {
            ScrollBar widget = (ScrollBar) selectionEvent.widget;
            int index = widget.getSelection();
            // Dprintf.dprintf("widget=%s: %d %d
            // %d",widget,widget.getSelection(),widget.getMinimum(),widget.getMaximum());

            // sync  number text widget, text widget
            widgetLineNumbers.setTopIndex(index);
            widgetText.setTopIndex(index);
          }
        });

    widgetFind.addSelectionListener(
        new SelectionListener() {
          public void widgetDefaultSelected(SelectionEvent selectionEvent) {
            findNext(widgetText, widgetFind);
          }

          public void widgetSelected(SelectionEvent selectionEvent) {}
        });
    widgetFind.addKeyListener(
        new KeyListener() {
          public void keyPressed(KeyEvent keyEvent) {}

          public void keyReleased(KeyEvent keyEvent) {
            updateViewFindText(widgetText, widgetFind);
          }
        });
    widgetFindPrev.addSelectionListener(
        new SelectionListener() {
          public void widgetDefaultSelected(SelectionEvent selectionEvent) {}

          public void widgetSelected(SelectionEvent selectionEvent) {
            findPrev(widgetText, widgetFind);
          }
        });
    widgetFindNext.addSelectionListener(
        new SelectionListener() {
          public void widgetDefaultSelected(SelectionEvent selectionEvent) {}

          public void widgetSelected(SelectionEvent selectionEvent) {
            findNext(widgetText, widgetFind);
          }
        });

    KeyListener keyListener =
        new KeyListener() {
          public void keyPressed(KeyEvent keyEvent) {
            if (Widgets.isAccelerator(keyEvent, Settings.keyFind)) {
              widgetFind.forceFocus();
            } else if (Widgets.isAccelerator(keyEvent, Settings.keyFindPrev)) {
              Widgets.invoke(widgetFindPrev);
            } else if (Widgets.isAccelerator(keyEvent, Settings.keyFindNext)) {
              Widgets.invoke(widgetFindNext);
            }
          }

          public void keyReleased(KeyEvent keyEvent) {}
        };
    widgetText.addKeyListener(keyListener);
    widgetFind.addKeyListener(keyListener);
    widgetFindPrev.addKeyListener(keyListener);
    widgetFindNext.addKeyListener(keyListener);

    dialog.addListener(
        USER_EVENT_NEW_REVISION,
        new Listener() {
          public void handleEvent(Event event) {}
        });

    // show dialog
    Dialogs.show(dialog, Settings.geometryView, Settings.setWindowLocation);

    // start show file
    show(revision);

    // start add revisions (only if single file is seleccted)
    Background.run(
        new BackgroundRunnable(fileData, revision) {
          public void run(FileData fileData, final String revision) {
            // get revisions
            repositoryTab.setStatusText("Get revisions for '%s'...", fileData.getFileName());
            try {
              data.revisionNames = repositoryTab.repository.getRevisionNames(fileData);
            } catch (RepositoryException exception) {
              final String exceptionMessage = exception.getMessage();
              display.syncExec(
                  new Runnable() {
                    public void run() {
                      Dialogs.error(
                          dialog, String.format("Getting revisions fail: %s", exceptionMessage));
                    }
                  });
              return;
            } finally {
              repositoryTab.clearStatusText();
            }

            if (data.revisionNames.length > 0) {
              // add revisions
              if (!dialog.isDisposed()) {
                display.syncExec(
                    new Runnable() {
                      public void run() {
                        if (!widgetRevision.isDisposed()) {
                          int selectIndex = -1;
                          for (int z = 0; z < data.revisionNames.length; z++) {
                            widgetRevision.add(data.revisionNames[z]);
                            if ((revision != null) && revision.equals(data.revisionNames[z])) {
                              selectIndex = z;
                            }
                          }
                          widgetRevision.add(repositoryTab.repository.getLastRevision());
                          if ((revision != null)
                              && revision.equals(repositoryTab.repository.getLastRevision()))
                            selectIndex = data.revisionNames.length;
                          if (selectIndex == -1) selectIndex = data.revisionNames.length;
                          widgetRevision.select(selectIndex);
                        }

                        // notify modification
                        Widgets.modified(data);
                      }
                    });
              }
            }
          }
        });
  }
 public void setForegroundColor(Color color) {
   StyledText te = getSourceViewer().getTextWidget();
   if (te != null) te.setForeground(color);
 }
  protected void initializeViewerColors() {
    if (fPreferenceStore != null) {

      StyledText styledText = getTextWidget();

      // ----------- foreground color --------------------
      Color color =
          fPreferenceStore.getBoolean(AbstractTextEditor.PREFERENCE_COLOR_FOREGROUND_SYSTEM_DEFAULT)
              ? null
              : createColor(
                  fPreferenceStore,
                  AbstractTextEditor.PREFERENCE_COLOR_FOREGROUND,
                  styledText.getDisplay());
      styledText.setForeground(color);

      if (fForegroundColor != null) fForegroundColor.dispose();

      fForegroundColor = color;

      // ---------- background color ----------------------
      color =
          fPreferenceStore.getBoolean(AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT)
              ? null
              : createColor(
                  fPreferenceStore,
                  AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND,
                  styledText.getDisplay());
      styledText.setBackground(color);

      if (fBackgroundColor != null) fBackgroundColor.dispose();

      fBackgroundColor = color;

      // ----------- selection foreground color --------------------
      color =
          fPreferenceStore.getBoolean(
                  AbstractDecoratedTextEditorPreferenceConstants
                      .EDITOR_SELECTION_FOREGROUND_DEFAULT_COLOR)
              ? null
              : createColor(
                  fPreferenceStore,
                  AbstractDecoratedTextEditorPreferenceConstants.EDITOR_SELECTION_FOREGROUND_COLOR,
                  styledText.getDisplay());
      styledText.setSelectionForeground(color);

      if (fSelectionForegroundColor != null) fSelectionForegroundColor.dispose();

      fSelectionForegroundColor = color;

      // ---------- selection background color ----------------------
      color =
          fPreferenceStore.getBoolean(
                  AbstractDecoratedTextEditorPreferenceConstants
                      .EDITOR_SELECTION_BACKGROUND_DEFAULT_COLOR)
              ? null
              : createColor(
                  fPreferenceStore,
                  AbstractDecoratedTextEditorPreferenceConstants.EDITOR_SELECTION_BACKGROUND_COLOR,
                  styledText.getDisplay());
      styledText.setSelectionBackground(color);

      if (fSelectionBackgroundColor != null) fSelectionBackgroundColor.dispose();

      fSelectionBackgroundColor = color;
    }
  }
Example #18
0
  public void _setWhatsNew() {

    if (sWhatsNew.indexOf("<html") >= 0 || sWhatsNew.indexOf("<HTML") >= 0) {
      BrowserWrapper browser = Utils.createSafeBrowser(cWhatsNew, SWT.NONE);
      if (browser != null) {
        browser.setText(sWhatsNew);
      } else {
        try {
          File tempFile = File.createTempFile("AZU", ".html");
          tempFile.deleteOnExit();
          FileUtil.writeBytesAsFile(tempFile.getAbsolutePath(), sWhatsNew.getBytes("utf8"));
          Utils.launch(tempFile.getAbsolutePath());
          shell.dispose();
          return;
        } catch (IOException e) {
        }
      }
    } else {

      StyledText helpPanel = new StyledText(cWhatsNew, SWT.VERTICAL | SWT.HORIZONTAL);

      helpPanel.setEditable(false);
      try {
        helpPanel.setRedraw(false);
        helpPanel.setWordWrap(false);
        helpPanel.setFont(monospace);

        black = ColorCache.getColor(display, 0, 0, 0);
        white = ColorCache.getColor(display, 255, 255, 255);
        light = ColorCache.getColor(display, 200, 200, 200);
        grey = ColorCache.getColor(display, 50, 50, 50);
        green = ColorCache.getColor(display, 30, 80, 30);
        blue = ColorCache.getColor(display, 20, 20, 80);
        int style;
        boolean setStyle;

        helpPanel.setForeground(grey);

        String[] lines = sWhatsNew.split("\\r?\\n");
        for (int i = 0; i < lines.length; i++) {
          String line = lines[i];

          setStyle = false;
          fg = grey;
          bg = white;
          style = SWT.NORMAL;

          char styleChar;
          String text;

          if (line.length() < 2) {
            styleChar = ' ';
            text = " " + lineSeparator;
          } else {
            styleChar = line.charAt(0);
            text = line.substring(1) + lineSeparator;
          }

          switch (styleChar) {
            case '*':
              text = "  * " + text;
              fg = green;
              setStyle = true;
              break;
            case '+':
              text = "     " + text;
              fg = black;
              bg = light;
              style = SWT.BOLD;
              setStyle = true;
              break;
            case '!':
              style = SWT.BOLD;
              setStyle = true;
              break;
            case '@':
              fg = blue;
              setStyle = true;
              break;
            case '$':
              bg = blue;
              fg = white;
              style = SWT.BOLD;
              setStyle = true;
              break;
            case ' ':
              text = "  " + text;
              break;

            default:
              text = styleChar + text;
          }

          helpPanel.append(text);

          if (setStyle) {
            int lineCount = helpPanel.getLineCount() - 1;
            int charCount = helpPanel.getCharCount();
            //          System.out.println("Got Linecount " + lineCount + ", Charcount " +
            // charCount);

            int lineOfs = helpPanel.getOffsetAtLine(lineCount - 1);
            int lineLen = charCount - lineOfs;
            //          System.out.println("Setting Style : " + lineOfs + ", " + lineLen);
            helpPanel.setStyleRange(new StyleRange(lineOfs, lineLen, fg, bg, style));
            helpPanel.setLineBackground(lineCount - 1, 1, bg);
          }
        }

        helpPanel.setRedraw(true);
      } catch (Exception e) {
        System.out.println("Unable to load help contents because:" + e);
        // e.printStackTrace();
      }
    }

    if (labelLoading != null && !labelLoading.isDisposed()) {
      labelLoading.dispose();
    }
    shell.layout(true, true);
  }
Example #19
0
  @Override
  protected Composite createPageContainer(Composite parent) {
    this.editorParent = parent;
    Composite composite = super.createPageContainer(parent);

    EditorUtil.initializeScrollbars(getHeaderForm().getForm());

    // create left tool bar that replaces form heading label
    try {
      FormHeading heading = (FormHeading) getHeaderForm().getForm().getForm().getHead();

      Field field = FormHeading.class.getDeclaredField("titleRegion"); // $NON-NLS-1$
      field.setAccessible(true);

      TitleRegion titleRegion = (TitleRegion) field.get(heading);

      leftToolBarManager = new ToolBarManager(SWT.FLAT);
      leftToolBar = leftToolBarManager.createControl(titleRegion);
      leftToolBar.addControlListener(
          new ControlAdapter() {
            private boolean ignoreResizeEvents;

            @Override
            public void controlResized(ControlEvent e) {
              if (ignoreResizeEvents) {
                return;
              }
              ignoreResizeEvents = true;
              try {
                // the tool bar contents has changed, update state
                updateHeaderImage();
                updateHeaderLabel();
              } finally {
                ignoreResizeEvents = false;
              }
            }
          });

      // titleLabel = new Label(titleRegion, SWT.NONE);
      // need a viewer for copy support
      TextViewer titleViewer = new TextViewer(titleRegion, SWT.READ_ONLY);
      // Eclipse 3.3 needs a document, otherwise an NPE is thrown
      titleViewer.setDocument(new Document());

      titleLabel = titleViewer.getTextWidget();
      titleLabel.setForeground(heading.getForeground());
      titleLabel.setFont(heading.getFont());
      // XXX work-around problem that causes field to maintain selection when unfocused
      titleLabel.addFocusListener(
          new FocusAdapter() {
            @Override
            public void focusLost(FocusEvent e) {
              titleLabel.setSelection(0);
            }
          });

      titleRegion.addControlListener(
          new ControlAdapter() {
            @Override
            public void controlResized(ControlEvent e) {
              // do not create busyLabel to avoid recursion
              updateSizeAndLocations();
            }
          });

      IHandlerService handlerService =
          (IHandlerService) getSite().getService(IHandlerService.class);
      if (handlerService != null) {
        textSupport = new CommonTextSupport(handlerService);
        textSupport.install(titleViewer, false);
      }
    } catch (Exception e) {
      if (!toolBarFailureLogged) {
        StatusHandler.log(
            new Status(
                IStatus.ERROR,
                TasksUiPlugin.ID_PLUGIN,
                "Failed to obtain busy label toolbar",
                e)); //$NON-NLS-1$
      }
      if (titleLabel != null) {
        titleLabel.dispose();
        titleLabel = null;
      }
      if (leftToolBar != null) {
        leftToolBar.dispose();
        leftToolBar = null;
      }
      if (leftToolBarManager != null) {
        leftToolBarManager.dispose();
        leftToolBarManager = null;
      }
    }

    updateHeader();

    return composite;
  }
 /*
  * @see IInformationControl#setForegroundColor(Color)
  */
 public void setForegroundColor(Color foreground) {
   fText.setForeground(foreground);
 }
  /**
   * Creates a source viewer information control with the given shell as parent. The given shell
   * styles are applied to the created shell. The given styles are applied to the created styled
   * text widget. The text widget will be initialized with the given font. The status field will
   * contain the given text or be hidden.
   *
   * @param parent the parent shell
   * @param isResizable <code>true</code> if resizable
   * @param symbolicFontName the symbolic font name
   * @param statusFieldText the text to be used in the optional status field or <code>null</code> if
   *     the status field should be hidden
   */
  public SourceViewerInformationControl(
      Shell parent, boolean isResizable, String symbolicFontName, String statusFieldText) {
    GridLayout layout;
    GridData gd;

    int shellStyle = SWT.TOOL | SWT.ON_TOP | (isResizable ? SWT.RESIZE : 0);
    int textStyle = isResizable ? SWT.V_SCROLL | SWT.H_SCROLL : SWT.NONE;

    fShell = new Shell(parent, SWT.NO_FOCUS | SWT.ON_TOP | shellStyle);
    Display display = fShell.getDisplay();

    Composite composite = fShell;
    layout = new GridLayout(1, false);
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    composite.setLayout(layout);
    gd = new GridData(GridData.FILL_HORIZONTAL);
    composite.setLayoutData(gd);

    if (statusFieldText != null) {
      composite = new Composite(composite, SWT.NONE);
      layout = new GridLayout(1, false);
      layout.marginHeight = 0;
      layout.marginWidth = 0;
      composite.setLayout(layout);
      gd = new GridData(GridData.FILL_BOTH);
      composite.setLayoutData(gd);
      composite.setForeground(display.getSystemColor(SWT.COLOR_INFO_FOREGROUND));
      composite.setBackground(display.getSystemColor(SWT.COLOR_INFO_BACKGROUND));
    }

    // Source viewer
    fViewer = new SourceViewer(composite, null, textStyle);
    fViewer.configure(new SourceViewerConfiguration());
    fViewer.setEditable(false);

    fText = fViewer.getTextWidget();
    gd = new GridData(GridData.BEGINNING | GridData.FILL_BOTH);
    fText.setLayoutData(gd);
    fText.setForeground(parent.getDisplay().getSystemColor(SWT.COLOR_INFO_FOREGROUND));
    fText.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_INFO_BACKGROUND));
    fSymbolicFontName = symbolicFontName;
    fTextFont = JFaceResources.getFont(symbolicFontName);
    fText.setFont(fTextFont);

    fText.addKeyListener(
        new KeyListener() {

          public void keyPressed(KeyEvent e) {
            if (e.character == 0x1B) // ESC
            fShell.dispose();
          }

          public void keyReleased(KeyEvent e) {}
        });

    // Status field
    if (statusFieldText != null) {

      // Horizontal separator line
      fSeparator = new Label(composite, SWT.SEPARATOR | SWT.HORIZONTAL | SWT.LINE_DOT);
      fSeparator.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

      // Status field label
      fStatusField = new Label(composite, SWT.RIGHT);
      fStatusField.setText(statusFieldText);
      Font font = fStatusField.getFont();
      FontData[] fontDatas = font.getFontData();
      for (int i = 0; i < fontDatas.length; i++)
        fontDatas[i].setHeight(fontDatas[i].getHeight() * 9 / 10);
      fStatusTextFont = new Font(fStatusField.getDisplay(), fontDatas);
      fStatusField.setFont(fStatusTextFont);
      GridData gd2 =
          new GridData(
              GridData.FILL_VERTICAL
                  | GridData.FILL_HORIZONTAL
                  | GridData.HORIZONTAL_ALIGN_BEGINNING
                  | GridData.VERTICAL_ALIGN_BEGINNING);
      fStatusField.setLayoutData(gd2);

      fStatusTextForegroundColor =
          new Color(
              fStatusField.getDisplay(),
              blend(
                  display.getSystemColor(SWT.COLOR_INFO_BACKGROUND).getRGB(),
                  display.getSystemColor(SWT.COLOR_INFO_FOREGROUND).getRGB(),
                  0.56f));
      fStatusField.setForeground(fStatusTextForegroundColor);

      fStatusField.setBackground(display.getSystemColor(SWT.COLOR_INFO_BACKGROUND));
    }

    addDisposeListener(this);
  }
Example #22
0
  private static void createStyledText(final Group group) {
    group.setLayout(new GridLayout(2, false));
    group.setText("StyledText widget");

    final Label lbl0 = new Label(group, SWT.NONE);
    lbl0.setLayoutData(new GridData(GridData.BEGINNING, GridData.CENTER, false, false));
    lbl0.setText("No prompt :");

    final StyledText txt0 = new StyledText(group, SWT.BORDER);
    txt0.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false));

    final Label lbl1 = new Label(group, SWT.NONE);
    lbl1.setLayoutData(new GridData(GridData.BEGINNING, GridData.CENTER, false, false));
    lbl1.setText("Simple text prompt :");

    final StyledText txt1 = new StyledText(group, SWT.BORDER);
    txt1.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false));
    PromptSupport.setPrompt("Type anything you want", txt1);

    final Label lbl2 = new Label(group, SWT.NONE);
    lbl2.setLayoutData(new GridData(GridData.BEGINNING, GridData.CENTER, false, false));
    lbl2.setText("Other style (bold) :");

    final StyledText txt2 = new StyledText(group, SWT.BORDER);
    txt2.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false));
    PromptSupport.setPrompt("Type anything you want in bold", txt2);
    PromptSupport.setFontStyle(SWT.BOLD, txt2);

    final Label lbl3 = new Label(group, SWT.NONE);
    lbl3.setLayoutData(new GridData(GridData.BEGINNING, GridData.CENTER, false, false));
    lbl3.setText("Behaviour highlight :");

    final StyledText txt3 = new StyledText(group, SWT.BORDER);
    txt3.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false));
    PromptSupport.setPrompt("Type anything you want", txt3);
    PromptSupport.setFocusBehavior(FocusBehavior.HIGHLIGHT_PROMPT, txt3);

    final Label lbl4 = new Label(group, SWT.NONE);
    lbl4.setLayoutData(new GridData(GridData.BEGINNING, GridData.CENTER, false, false));
    lbl4.setText("Change colors :");

    final StyledText txt4 = new StyledText(group, SWT.BORDER);
    txt4.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false));
    PromptSupport.setPrompt("Type anything you want", txt4);
    PromptSupport.setForeground(txt4.getDisplay().getSystemColor(SWT.COLOR_YELLOW), txt4);
    PromptSupport.setBackground(txt4.getDisplay().getSystemColor(SWT.COLOR_BLACK), txt4);

    final Label lbl5 = new Label(group, SWT.NONE);
    lbl5.setLayoutData(new GridData(GridData.BEGINNING, GridData.CENTER, false, false));
    lbl5.setText("Change when widget is initialized :");

    final StyledText txt5 = new StyledText(group, SWT.BORDER);
    txt5.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false));
    txt5.setText("Remove what is typed...");
    txt5.setBackground(txt4.getDisplay().getSystemColor(SWT.COLOR_BLACK));
    txt5.setForeground(txt4.getDisplay().getSystemColor(SWT.COLOR_YELLOW));

    PromptSupport.setPrompt("Type anything you want", txt5);
    PromptSupport.setForeground(txt4.getDisplay().getSystemColor(SWT.COLOR_DARK_BLUE), txt5);
    PromptSupport.setBackground(txt4.getDisplay().getSystemColor(SWT.COLOR_WHITE), txt5);
  }