void handleSyntaxColorListSelection() {
    final TokenHighlight item = getHighlight();

    fEnableCheckbox.setEnabled(item != null);
    fSyntaxForegroundColorEditor.getButton().setEnabled(item != null);
    fColorEditorLabel.setEnabled(item != null);
    fBoldCheckBox.setEnabled(item != null);
    fItalicCheckBox.setEnabled(item != null);
    fStrikethroughCheckBox.setEnabled(item != null);
    fUnderlineCheckBox.setEnabled(item != null);

    if (item == null) {
      return;
    }

    final HighlightStyle style = item.getStyle(fOverlayStore);
    fSyntaxForegroundColorEditor.setColorValue(style.getColor());
    fBoldCheckBox.setSelection(style.hasStyle(SWT.BOLD));
    fItalicCheckBox.setSelection(style.hasStyle(SWT.ITALIC));
    fStrikethroughCheckBox.setSelection(style.hasStyle(TextAttribute.STRIKETHROUGH));
    fUnderlineCheckBox.setSelection(style.hasStyle(TextAttribute.UNDERLINE));

    // if (item instanceof SemanticHighlightingColorListItem) {
    // fEnableCheckbox.setEnabled(true);
    // final boolean enable = getPreferenceStore().getBoolean(
    // ((SemanticHighlightingColorListItem) item).getEnableKey());
    // fEnableCheckbox.setSelection(enable);
    // fSyntaxForegroundColorEditor.getButton().setEnabled(enable);
    // fColorEditorLabel.setEnabled(enable);
    // fBoldCheckBox.setEnabled(enable);
    // fItalicCheckBox.setEnabled(enable);
    // fStrikethroughCheckBox.setEnabled(enable);
    // fUnderlineCheckBox.setEnabled(enable);
    // }
  }
  protected void initializeFields() {
    Iterator<Object> e = fColorButtons.keySet().iterator();
    while (e.hasNext()) {
      ColorSelector c = (ColorSelector) e.next();
      String key = fColorButtons.get(c);
      RGB rgb = PreferenceConverter.getColor(fOverlayStore, key);
      c.setColorValue(rgb);
    }

    e = fCheckBoxes.keySet().iterator();
    while (e.hasNext()) {
      Button b = (Button) e.next();
      String key = fCheckBoxes.get(b);
      b.setSelection(fOverlayStore.getBoolean(key));
    }

    e = fTextFields.keySet().iterator();
    while (e.hasNext()) {
      Text t = (Text) e.next();
      String key = fTextFields.get(t);
      t.setText(fOverlayStore.getString(key));
    }

    e = fComboBoxes.keySet().iterator();
    while (e.hasNext()) {
      Combo c = (Combo) e.next();
      String key = fComboBoxes.get(c);
      String state = fOverlayStore.getString(key);
      // Interpret the state string as a Combo state description
      ProposalFilterPreferencesUtil.restoreComboFromString(c, state);
    }
  }
  protected Control addColorButton(Composite parent, String label, String key, int indentation) {

    Composite composite = new Composite(parent, SWT.NONE);
    GridData gd = new GridData(GridData.FILL_HORIZONTAL);
    gd.horizontalSpan = 2;
    composite.setLayoutData(gd);

    GridLayout layout = new GridLayout();
    layout.numColumns = 2;
    layout.marginWidth = 0;
    layout.marginHeight = 0;
    composite.setLayout(layout);

    Label labelControl = new Label(composite, SWT.NONE);
    labelControl.setText(label);

    gd = new GridData(GridData.FILL_HORIZONTAL);
    gd.horizontalIndent = indentation;
    labelControl.setLayoutData(gd);

    ColorSelector editor = new ColorSelector(composite);
    Button button = editor.getButton();
    button.setData(editor);

    gd = new GridData();
    gd.horizontalAlignment = GridData.END;
    button.setLayoutData(gd);
    button.addSelectionListener(fColorButtonListener);

    fColorButtons.put(editor, key);

    return composite;
  }
  private void createProgressMessageConfig(Composite parent) {
    fAddMessageButton = createButton(parent, fToolkit, PDEUIMessages.SplashSection_progressMessage);
    fAddMessageButton.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            boolean enable = fAddMessageButton.getSelection();
            getSplashInfo().addProgressMessage(enable, false);
            updateFieldEnablement();
          }
        });
    fAddMessageButton.setEnabled(false);

    Color foreground = fToolkit.getColors().getColor(IFormColors.TITLE);

    fMessageControls[0] =
        createLabel(parent, fToolkit, foreground, PDEUIMessages.SplashSection_messageX);
    fMessageControls[1] = fMessageSpinners[0] = createSpinner(parent, fToolkit);
    fMessageControls[2] =
        createLabel(parent, fToolkit, foreground, PDEUIMessages.SplashSection_messageY);
    fMessageControls[3] = fMessageSpinners[1] = createSpinner(parent, fToolkit);

    fMessageControls[4] =
        createLabel(parent, fToolkit, foreground, PDEUIMessages.SplashSection_messageWidth);
    fMessageControls[5] = fMessageSpinners[2] = createSpinner(parent, fToolkit);
    fMessageControls[6] =
        createLabel(parent, fToolkit, foreground, PDEUIMessages.SplashSection_messageHeight);
    fMessageControls[7] = fMessageSpinners[3] = createSpinner(parent, fToolkit);

    fMessageControls[8] =
        createLabel(parent, fToolkit, foreground, PDEUIMessages.SplashSection_messageColor);
    fColorSelector = new ColorSelector(parent);
    fColorSelector.addListener(
        new IPropertyChangeListener() {
          @Override
          public void propertyChange(PropertyChangeEvent event) {
            if (!event.getNewValue().equals(event.getOldValue())) applyColor();
          }
        });
    fToolkit.adapt(fColorSelector.getButton(), true, true);
    fMessageControls[9] = fColorSelector.getButton();
    // Add tooltips to coordinate controls
    addOffsetTooltips(fMessageControls);

    for (Spinner spinner : fMessageSpinners) {
      spinner.setEnabled(isEditable());
      spinner.addModifyListener(
          new ModifyListener() {
            @Override
            public void modifyText(ModifyEvent e) {
              applySpinners(false);
            }
          });
    }
  }
 private void updateAppearanceColorWidgets(String systemDefaultKey) {
   if (systemDefaultKey == null) {
     fAppearanceColorDefault.setSelection(false);
     fAppearanceColorDefault.setVisible(false);
     fAppearanceColorEditor.getButton().setEnabled(true);
   } else {
     boolean systemDefault = getPreferenceStore().getBoolean(systemDefaultKey);
     fAppearanceColorDefault.setSelection(systemDefault);
     fAppearanceColorDefault.setVisible(true);
     fAppearanceColorEditor.getButton().setEnabled(!systemDefault);
   }
 }
  public AbstractSelectionRegion<?> getEditingRegion() {

    final String txt = nameText.getText();
    try {
      xyGraph.renameRegion(editingRegion, txt);
    } catch (Exception e) {
      MessageDialog.openError(
          Display.getDefault().getActiveShell(),
          "Region Exists",
          "The region '"
              + txt
              + "' already exists.\n\n"
              + "Please choose a unique name for regions.");
    }
    final AspectAxis x = getAxis(xyGraph.getXAxisList(), xCombo.getSelectionIndex());
    final AspectAxis y = getAxis(xyGraph.getYAxisList(), yCombo.getSelectionIndex());
    RegionCoordinateSystem sys = new RegionCoordinateSystem(getImageTrace(), x, y);
    editingRegion.setCoordinateSystem(sys);
    editingRegion.setShowPosition(showPoints.getSelection());
    editingRegion.setRegionColor(new Color(getDisplay(), colorSelector.getColorValue()));
    editingRegion.setAlpha(alpha.getSelection());
    editingRegion.setMobile(mobile.getSelection());
    editingRegion.setVisible(visible.getSelection());
    editingRegion.setShowLabel(showLabel.getSelection());
    editingRegion.setFill(fillRegion.getSelection());

    return editingRegion;
  }
  protected void onSave() {
    try {
      int channelInt = Integer.parseInt(channelName.getText());
      if (channelInt < 0 || channelInt > 256) {
        throw new Exception();
      }
      String key = getKey(String.valueOf(channelInt));
      raptorPreferenceStore.setValue(key, colorSelector.getColorValue());

      boolean channelsHasSelection = false;
      for (int i = 0; i < channels.getItemCount(); i++) {
        if (channels.getItem(i).equals(String.valueOf(channelInt))) {
          channelsHasSelection = true;
          break;
        }
      }

      if (!channelsHasSelection) {
        channels.add(String.valueOf(channelInt));
      }
    } catch (Throwable t) {
      MessageDialog.openInformation(
          Raptor.getInstance().getWindow().getShell(),
          local.getString("alert"),
          local.getString("chatConColP3"));
    }
  }
  /**
   * Notifies that the selection is changed on attributes viewer.
   *
   * @param selection The selection
   */
  void viewerSlectionChanged(IStructuredSelection selection) {
    if (selection.isEmpty()) {
      if (removeButton != null) {
        removeButton.setEnabled(false);
      }
      colorSelector.setEnabled(false);
      return;
    }

    MBeanAttribute attribute = (MBeanAttribute) selection.getFirstElement();
    if (removeButton != null) {
      removeButton.setEnabled(true);
    }
    colorSelector.setEnabled(true);
    colorSelector.setColorValue(attribute.getRgb());
  }
 /**
  * Creates the color selector.
  *
  * @param parent The parent composite
  * @return The color selector
  */
 private ColorSelector createColorSelector(Composite parent) {
   final ColorSelector selector = new ColorSelector(parent);
   selector.addListener(
       new IPropertyChangeListener() {
         @Override
         public void propertyChange(PropertyChangeEvent event) {
           IStructuredSelection selection = (IStructuredSelection) attributesViewer.getSelection();
           MBeanAttribute attribute = (MBeanAttribute) selection.getFirstElement();
           if (attribute != null) {
             attribute.setRgb(selector.getColorValue());
           }
         }
       });
   selector.setEnabled(false);
   return selector;
 }
 private void handleAppearanceColorListSelection() {
   int i = fAppearanceColorList.getSelectionIndex();
   if (i == -1) return;
   String key = fAppearanceColorListModel[i][1];
   RGB rgb = PreferenceConverter.getColor(getPreferenceStore(), key);
   fAppearanceColorEditor.setColorValue(rgb);
   updateAppearanceColorWidgets(fAppearanceColorListModel[i][2]);
 }
 private void handleSyntaxColorListSelection() {
   HighlightingColorListItem item = getHighlightingColorListItem();
   if (item == null) {
     fEnableCheckbox.setEnabled(false);
     fSyntaxForegroundColorEditor.getButton().setEnabled(false);
     fColorEditorLabel.setEnabled(false);
     fBoldCheckBox.setEnabled(false);
     fItalicCheckBox.setEnabled(false);
     fStrikethroughCheckBox.setEnabled(false);
     fUnderlineCheckBox.setEnabled(false);
     return;
   }
   RGB rgb = PreferenceConverter.getColor(getPreferenceStore(), item.getColorKey());
   fSyntaxForegroundColorEditor.setColorValue(rgb);
   fBoldCheckBox.setSelection(getPreferenceStore().getBoolean(item.getBoldKey()));
   fItalicCheckBox.setSelection(getPreferenceStore().getBoolean(item.getItalicKey()));
   fStrikethroughCheckBox.setSelection(
       getPreferenceStore().getBoolean(item.getStrikethroughKey()));
   fUnderlineCheckBox.setSelection(getPreferenceStore().getBoolean(item.getUnderlineKey()));
   if (item instanceof SemanticHighlightingColorListItem) {
     boolean semanticHighlightingEnabled =
         getPreferenceStore().getBoolean(PreferenceConstants.EDITOR_SEMANTIC_HIGHLIGHTING_ENABLED);
     fEnableCheckbox.setEnabled(semanticHighlightingEnabled);
     boolean enable =
         semanticHighlightingEnabled
             && getPreferenceStore()
                 .getBoolean(((SemanticHighlightingColorListItem) item).getEnableKey());
     fEnableCheckbox.setSelection(enable);
     fSyntaxForegroundColorEditor.getButton().setEnabled(enable);
     fColorEditorLabel.setEnabled(enable);
     fBoldCheckBox.setEnabled(enable);
     fItalicCheckBox.setEnabled(enable);
     fStrikethroughCheckBox.setEnabled(enable);
     fUnderlineCheckBox.setEnabled(enable);
   } else {
     fSyntaxForegroundColorEditor.getButton().setEnabled(true);
     fColorEditorLabel.setEnabled(true);
     fBoldCheckBox.setEnabled(true);
     fItalicCheckBox.setEnabled(true);
     fStrikethroughCheckBox.setEnabled(true);
     fUnderlineCheckBox.setEnabled(true);
     fEnableCheckbox.setEnabled(false);
     fEnableCheckbox.setSelection(true);
   }
 }
  @Override
  public void refresh() {
    ISplashInfo info = getSplashInfo();
    fBlockNotification = true;

    fColorSelector.setColorValue(hexToRGB(info.getForegroundColor()));

    int[] pgeo = info.getProgressGeometry();
    boolean addProgress = pgeo != null;
    info.addProgressBar(addProgress, fBlockNotification);
    if (addProgress) {
      for (int i = 0; i < pgeo.length; i++) {
        fBarSpinners[i].setSelection(pgeo[i]);
      }
    } else {
      resetProgressBarGeometry();
    }

    fAddBarButton.setSelection(addProgress);

    int[] mgeo = info.getMessageGeometry();
    boolean addMessage = mgeo != null;
    info.addProgressMessage(addMessage, fBlockNotification);
    if (addMessage) {
      for (int i = 0; i < mgeo.length; i++) {
        fMessageSpinners[i].setSelection(mgeo[i]);
      }
    } else {
      resetProgressMessageGeometry();
    }
    fColorSelector.setColorValue(
        addMessage ? hexToRGB(info.getForegroundColor()) : new RGB(0, 0, 0));

    fAddMessageButton.setSelection(addMessage);

    // Update the UI
    updateUIFieldTemplateCombo();
    fBlockNotification = false;
    super.refresh();
    // Update this sections enablement
    updateFieldEnablement();
  }
  private Composite createAppearance(final Composite pageComposite) {
    final Group group = new Group(pageComposite, SWT.NONE);
    group.setText("Output" + ':');
    group.setLayout(LayoutUtil.applyGroupDefaults(new GridLayout(), 2));

    {
      final Label label = new Label(group, SWT.NONE);
      label.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
      label.setText("Size (characters):");
      final Text text = new Text(group, SWT.BORDER | SWT.RIGHT);
      final GridData gd = new GridData(SWT.LEFT, SWT.CENTER, true, false);
      gd.widthHint = LayoutUtil.hintWidth(text, 12);
      text.setLayoutData(gd);
      text.setTextLimit(20);
      fCharLimitControl = text;
    }
    {
      final Label label = new Label(group, SWT.NONE);
      label.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
      label.setText("Prompt/Info:");
      final ColorSelector selector = new ColorSelector(group);
      selector.getButton().setLayoutData(new GridData(SWT.LEFT, SWT.FILL, false, false));
      fColorInfoControl = selector;
    }
    {
      final Label label = new Label(group, SWT.NONE);
      label.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
      label.setText("Input:");
      final ColorSelector selector = new ColorSelector(group);
      selector.getButton().setLayoutData(new GridData(SWT.LEFT, SWT.FILL, false, false));
      fColorInputControl = selector;
    }
    {
      final Label label = new Label(group, SWT.NONE);
      label.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
      label.setText("Output:");
      final ColorSelector selector = new ColorSelector(group);
      selector.getButton().setLayoutData(new GridData(SWT.LEFT, SWT.FILL, false, false));
      fColorOutputControl = selector;
    }
    {
      final Label label = new Label(group, SWT.NONE);
      label.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
      label.setText("Error:");
      final ColorSelector selector = new ColorSelector(group);
      selector.getButton().setLayoutData(new GridData(SWT.LEFT, SWT.FILL, false, false));
      fColorErrorControl = selector;
    }

    return group;
  }
  private void initialize() {
    nameText.setText(annotation.getName());
    nameText.setSelection(0, nameText.getText().length());
    snapToTrace.setSelection(!annotation.isFree());
    xAxisLabel.setText(
        snapToTrace.getSelection() ? Messages.Annotation_Trace : Messages.Annotation_XAxis);
    xAxisOrTraceCombo.removeAll();
    if (!annotation.isFree()) {
      for (Trace trace : xyGraph.getPlotArea().getTraceList())
        xAxisOrTraceCombo.add(trace.getName());
      xAxisOrTraceCombo.select(xyGraph.getPlotArea().getTraceList().indexOf(annotation.getTrace()));
    } else {
      for (Axis axis : xyGraph.getXAxisList()) xAxisOrTraceCombo.add(axis.getTitle());
      xAxisOrTraceCombo.select(xyGraph.getXAxisList().indexOf(annotation.getXAxis()));
    }
    for (Axis axis : xyGraph.getYAxisList()) yAxisCombo.add(axis.getTitle());
    yAxisCombo.select(xyGraph.getYAxisList().indexOf(annotation.getYAxis()));
    yAxisLabel.setVisible(!snapToTrace.getSelection());
    yAxisCombo.setVisible(!snapToTrace.getSelection());
    useDefaultColorButton.setSelection(annotation.getAnnotationColor() == null);
    colorLabel.setVisible(!useDefaultColorButton.getSelection());
    colorSelector.getButton().setVisible(annotation.getAnnotationColor() != null);
    colorSelector.setColorValue(
        annotation.getAnnotationColor() == null
            ? annotation.getYAxis().getForegroundColor().getRGB()
            : annotation.getAnnotationColor().getRGB());

    fontLabel.setText(
        Messages.Annotation_Font
            + (font == null ? Messages.Annotation_SystemDefault : font.getFontData()[0].getName()));
    fontLabel.setFont(font);
    cursorLineCombo.select(annotation.getCursorLineStyle().getIndex());
    showNameButton.setSelection(annotation.isShowName());
    showSampleInfoButton.setSelection(annotation.isShowSampleInfo());
    showPositionButton.setSelection(annotation.isShowPosition());
  }
  public void applyChanges() {
    annotation.setName(nameText.getText());
    if (snapToTrace.getSelection())
      annotation.setTrace(
          xyGraph.getPlotArea().getTraceList().get(xAxisOrTraceCombo.getSelectionIndex()));
    else
      annotation.setFree(
          xyGraph.getXAxisList().get(xAxisOrTraceCombo.getSelectionIndex()),
          xyGraph.getYAxisList().get(yAxisCombo.getSelectionIndex()));

    if (!useDefaultColorButton.getSelection())
      annotation.setAnnotationColor(
          XYGraphMediaFactory.getInstance().getColor(colorSelector.getColorValue()));
    else annotation.setAnnotationColor(null);
    annotation.setFont(font);
    annotation.setCursorLineStyle(CursorLineStyle.values()[cursorLineCombo.getSelectionIndex()]);
    annotation.setShowName(showNameButton.getSelection());
    annotation.setShowSampleInfo(showSampleInfoButton.getSelection());
    annotation.setShowPosition(showPositionButton.getSelection());
  }
  public void setEditingRegion(final AbstractSelectionRegion<?> region) {

    this.editingRegion = region;
    this.roiViewer.setRegion(region.getROI(), region.getRegionType(), region.getCoordinateSystem());
    this.roiListener =
        new IROIListener.Stub() {
          @Override
          public void roiChanged(ROIEvent evt) {
            region.setROI(evt.getROI());
          }
        };
    roiViewer.addROIListener(roiListener);

    Range range = xyGraph.primaryXAxis.getRange();
    roiViewer.setXLowerBound(Math.min(range.getUpper(), range.getLower()));
    roiViewer.setXUpperBound(Math.max(range.getUpper(), range.getLower()));

    range = xyGraph.primaryYAxis.getRange();
    roiViewer.setYLowerBound(Math.min(range.getUpper(), range.getLower()));
    roiViewer.setYUpperBound(Math.max(range.getUpper(), range.getLower()));

    nameText.setText(region.getName());
    regionType.select(region.getRegionType().getIndex());
    regionType.setEnabled(false);
    regionType.setEditable(false);

    int index = xyGraph.getXAxisList().indexOf(region.getCoordinateSystem().getX());
    xCombo.select(index);

    index = xyGraph.getYAxisList().indexOf(region.getCoordinateSystem().getY());
    yCombo.select(index);

    colorSelector.setColorValue(region.getRegionColor().getRGB());
    alpha.setSelection(region.getAlpha());
    mobile.setSelection(region.isMobile());
    showPoints.setSelection(region.isShowPosition());
    visible.setSelection(region.isVisible());
    showLabel.setSelection(region.isShowLabel());
    fillRegion.setSelection(region.isFill());
  }
  public void createPage(final Composite composite) {
    this.composite = composite;
    composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    composite.setLayout(new GridLayout(2, false));

    final Label nameLabel = new Label(composite, 0);
    nameLabel.setText(Messages.Annotation_Name);
    nameLabel.setLayoutData(new GridData());

    nameText = new Text(composite, SWT.BORDER | SWT.SINGLE);
    nameText.setToolTipText(Messages.Annotation_NameTT);
    nameText.setLayoutData(new GridData(SWT.FILL, 0, true, false));

    snapToTrace = new Button(composite, SWT.CHECK);
    snapToTrace.setText(Messages.Annotation_Snap);
    snapToTrace.setToolTipText(Messages.Annotation_SnapTT);
    snapToTrace.setLayoutData(new GridData(0, 0, false, false, 2, 1));

    xAxisLabel = new Label(composite, 0);
    xAxisLabel.setLayoutData(new GridData());

    xAxisOrTraceCombo = new Combo(composite, SWT.DROP_DOWN);
    xAxisOrTraceCombo.setLayoutData(new GridData(SWT.FILL, 0, true, false));

    yAxisLabel = new Label(composite, 0);
    yAxisLabel.setText(Messages.Annotation_YAxis);
    yAxisLabel.setLayoutData(new GridData());

    yAxisCombo = new Combo(composite, SWT.DROP_DOWN);
    yAxisCombo.setToolTipText(Messages.Annotation_YAxisSnapTT);
    yAxisCombo.setLayoutData(new GridData(SWT.FILL, 0, true, false));

    // snapToTrace listener
    snapToTrace.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(final SelectionEvent e) {
            if (snapToTrace.getSelection()) {
              xAxisLabel.setText(Messages.Annotation_Trace);
              xAxisOrTraceCombo.setToolTipText(Messages.Annotation_TraceSnapTT);
            } else {
              xAxisLabel.setText(Messages.Annotation_XAxis);
              xAxisOrTraceCombo.setToolTipText(Messages.Annotation_XAxisSnapTT);
            }

            xAxisOrTraceCombo.removeAll();
            if (snapToTrace.getSelection()) {
              for (Trace trace : xyGraph.getPlotArea().getTraceList())
                xAxisOrTraceCombo.add(trace.getName());
            } else {
              for (Axis axis : xyGraph.getXAxisList()) xAxisOrTraceCombo.add(axis.getTitle());
            }
            xAxisOrTraceCombo.select(0);
            if (annotation.isFree() && !snapToTrace.getSelection())
              xAxisOrTraceCombo.select(xyGraph.getXAxisList().indexOf(annotation.getXAxis()));
            else if (!annotation.isFree() && snapToTrace.getSelection())
              xAxisOrTraceCombo.select(
                  xyGraph.getPlotArea().getTraceList().indexOf(annotation.getTrace()));

            yAxisLabel.setVisible(!snapToTrace.getSelection());
            yAxisCombo.setVisible(!snapToTrace.getSelection());
            composite.layout(true, true);
          }
        });
    // annotation color
    useDefaultColorButton = new Button(composite, SWT.CHECK);
    useDefaultColorButton.setText(Messages.Annotation_ColorFromYAxis);
    useDefaultColorButton.setLayoutData(new GridData(SWT.FILL, 0, false, false, 2, 1));

    colorLabel = new Label(composite, 0);
    colorLabel.setText(Messages.Annotation_Color);
    colorLabel.setLayoutData(new GridData());

    colorSelector = new ColorSelector(composite);
    colorSelector.getButton().setLayoutData(new GridData());
    useDefaultColorButton.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            colorSelector.getButton().setVisible(!useDefaultColorButton.getSelection());
            colorLabel.setVisible(!useDefaultColorButton.getSelection());
          }
        });

    fontLabel = new Label(composite, 0);
    fontLabel.setLayoutData(new GridData());

    final Button fontButton = new Button(composite, SWT.PUSH);
    fontButton.setText(Messages.Annotation_ChangeFont);
    fontButton.setLayoutData(new GridData());
    fontButton.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            FontDialog fontDialog = new FontDialog(composite.getShell());
            if (font != null) fontDialog.setFontList(font.getFontData());
            FontData fontData = fontDialog.open();
            if (fontData != null) {
              font = XYGraphMediaFactory.getInstance().getFont(fontData);
              fontLabel.setFont(font);
              fontLabel.setText(Messages.Annotation_Font + fontData.getName());
              composite.getShell().layout(true, true);
            }
          }
        });

    final Label cursorLineLabel = new Label(composite, 0);
    cursorLineLabel.setText(Messages.Annotation_Cursor);
    cursorLineLabel.setLayoutData(new GridData());

    cursorLineCombo = new Combo(composite, SWT.DROP_DOWN);
    cursorLineCombo.setItems(CursorLineStyle.stringValues());
    cursorLineCombo.setLayoutData(new GridData());

    showNameButton = new Button(composite, SWT.CHECK);
    showNameButton.setText(Messages.Annotation_ShowName);
    showNameButton.setLayoutData(new GridData(0, 0, false, false, 2, 1));

    showSampleInfoButton = new Button(composite, SWT.CHECK);
    showSampleInfoButton.setText(Messages.Annotation_ShowInfo);
    showSampleInfoButton.setLayoutData(new GridData(0, 0, false, false, 2, 1));

    showPositionButton = new Button(composite, SWT.CHECK);
    showPositionButton.setText(Messages.Annotation_ShowPosition);
    showPositionButton.setLayoutData(new GridData(0, 0, false, false, 2, 1));
    initialize();
  }
  /**
   * Used internally
   *
   * @param parent
   * @param plottingSystem
   * @param style
   * @param xyGraph
   * @param defaultRegion
   * @param isImplicit Flag to tell whether the RegionComposite is used in a specific window with an
   *     apply button or part of a view where the changes are implicit
   */
  public RegionEditComposite(
      final Composite parent,
      final IPlottingSystem<?> plottingSystem,
      final int style,
      final XYRegionGraph xyGraph,
      final RegionType defaultRegion,
      final boolean isImplicit) {

    super(parent, SWT.NONE);

    this.setImplicit(isImplicit);

    this.xyGraph = xyGraph;
    this.plottingSystem = plottingSystem;

    setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
    setLayout(new org.eclipse.swt.layout.GridLayout(2, false));

    final Label nameLabel = new Label(this, SWT.NONE);
    nameLabel.setText("Name   ");
    nameLabel.setLayoutData(new GridData());

    nameText = new Text(this, SWT.BORDER | SWT.SINGLE);
    nameText.setToolTipText("Region name");
    nameText.setLayoutData(new GridData(SWT.FILL, 0, true, false));
    if (isImplicit()) {
      nameText.addSelectionListener(
          new SelectionAdapter() {
            @Override
            public void widgetDefaultSelected(SelectionEvent e) {
              AbstractSelectionRegion<?> region = getEditingRegion();
              region.repaint();
            }
          });
    }

    final Label horiz = new Label(this, SWT.SEPARATOR | SWT.HORIZONTAL);
    horiz.setLayoutData(new GridData(SWT.FILL, 0, true, false, 2, 1));

    final Label typeLabel = new Label(this, SWT.NONE);
    typeLabel.setText("Type");
    typeLabel.setLayoutData(new GridData());

    regionType = new CCombo(this, SWT.BORDER | SWT.NONE);
    regionType.setEditable(false);
    regionType.setToolTipText("Region type");
    regionType.setLayoutData(new GridData(SWT.FILL, 0, true, false));
    for (RegionType type : RegionType.ALL_TYPES) {
      regionType.add(type.getName());
    }
    regionType.select(defaultRegion.getIndex());

    xCombo = createAxisChooser(this, "X Axis", xyGraph.getXAxisList());
    yCombo = createAxisChooser(this, "Y Axis", xyGraph.getYAxisList());

    Label colorLabel = new Label(this, 0);
    colorLabel.setText("Selection Color");
    colorLabel.setLayoutData(new GridData());

    colorSelector = new ColorSelector(this);
    colorSelector.getButton().setLayoutData(new GridData());
    colorSelector.setColorValue(defaultRegion.getDefaultColor().getRGB());
    if (isImplicit()) {
      colorSelector.addListener(
          new IPropertyChangeListener() {
            @Override
            public void propertyChange(PropertyChangeEvent event) {
              AbstractSelectionRegion<?> region = getEditingRegion();
              region.repaint();
            }
          });
    }

    final Label horiz2 = new Label(this, SWT.SEPARATOR | SWT.HORIZONTAL);
    horiz2.setLayoutData(new GridData(SWT.FILL, 0, true, false, 2, 1));

    Label alphaLabel = new Label(this, 0);
    alphaLabel.setText("Alpha level");
    alphaLabel.setLayoutData(new GridData());

    alpha = new Spinner(this, SWT.NONE);
    alpha.setToolTipText("Alpha transparency level of the shaded shape");
    alpha.setLayoutData(new GridData());
    alpha.setMinimum(0);
    alpha.setMaximum(255);
    alpha.setSelection(80);
    if (isImplicit()) {
      alpha.addSelectionListener(
          new SelectionAdapter() {
            @Override
            public void widgetSelected(SelectionEvent e) {
              AbstractSelectionRegion<?> region = getEditingRegion();
              region.repaint();
            }
          });
    }

    this.mobile = new Button(this, SWT.CHECK);
    mobile.setText("   Mobile   ");
    mobile.setToolTipText("When true, this selection can be resized and moved around the graph.");
    mobile.setLayoutData(new GridData(0, 0, false, false, 2, 1));
    mobile.setSelection(true);
    if (isImplicit()) {
      mobile.addSelectionListener(
          new SelectionAdapter() {
            @Override
            public void widgetSelected(SelectionEvent e) {
              AbstractSelectionRegion<?> region = getEditingRegion();
              region.repaint();
            }
          });
    }

    this.showPoints = new Button(this, SWT.CHECK);
    showPoints.setText("   Show vertex values");
    showPoints.setToolTipText(
        "When on this will show the actual value of the point in the axes it was added.");
    showPoints.setLayoutData(new GridData(0, 0, false, false, 2, 1));
    if (isImplicit()) {
      showPoints.addSelectionListener(
          new SelectionAdapter() {
            @Override
            public void widgetSelected(SelectionEvent e) {
              AbstractSelectionRegion<?> region = getEditingRegion();
              region.repaint();
            }
          });
    }

    this.visible = new Button(this, SWT.CHECK);
    visible.setText("   Show region");
    visible.setToolTipText("You may turn off the visibility of this region.");
    visible.setLayoutData(new GridData(0, 0, false, false, 2, 1));
    visible.setSelection(true);
    if (isImplicit()) {
      visible.addSelectionListener(
          new SelectionAdapter() {
            @Override
            public void widgetSelected(SelectionEvent e) {
              AbstractSelectionRegion<?> region = getEditingRegion();
              region.repaint();
            }
          });
    }

    this.showLabel = new Button(this, SWT.CHECK);
    showLabel.setText("   Show name");
    showLabel.setToolTipText("Turn on to show the name of a selection region.");
    showLabel.setLayoutData(new GridData(0, 0, false, false, 2, 1));
    showLabel.setSelection(true);
    if (isImplicit()) {
      showLabel.addSelectionListener(
          new SelectionAdapter() {
            @Override
            public void widgetSelected(SelectionEvent e) {
              AbstractSelectionRegion<?> region = getEditingRegion();
              region.repaint();
            }
          });
    }

    this.fillRegion = new Button(this, SWT.CHECK);
    fillRegion.setText("   Fill region");
    fillRegion.setToolTipText("Fill the body of an area region");
    fillRegion.setLayoutData(new GridData(0, 0, false, false, 2, 1));
    fillRegion.setSelection(true);
    if (isImplicit()) {
      fillRegion.addSelectionListener(
          new SelectionAdapter() {
            @Override
            public void widgetSelected(SelectionEvent e) {
              AbstractSelectionRegion<?> region = getEditingRegion();
              region.repaint();
            }
          });
    }

    final Label spacer = new Label(this, SWT.SEPARATOR | SWT.HORIZONTAL);
    spacer.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));

    // We add a composite for setting the region location programmatically.
    final Label location = new Label(this, SWT.NONE);
    location.setText("Region Location");
    location.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));

    this.roiViewer = new ROIEditTable();
    roiViewer.createPartControl(this);

    // Should be last
    nameText.setText(getDefaultName(defaultRegion.getIndex()));
  }
  @Override
  protected Control createContents(Composite parent) {
    parent = new Composite(parent, SWT.NONE);
    parent.setLayout(new GridLayout(3, false));

    Label label = new Label(parent, SWT.NONE);
    label.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 3, 1));
    label.setText(
        WordUtils.wrap(local.getString("chatConColP1"), 70)
            + WordUtils.wrap(local.getString("chatConColP2"), 70));

    Label channelNamesLabel = new Label(parent, SWT.NONE);
    channelNamesLabel.setText(local.getString("channels"));
    channelNamesLabel.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1));

    channels = new Combo(parent, SWT.DROP_DOWN | SWT.READ_ONLY);
    channels.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 2, 1));
    channels.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            String selectedChannelName = channels.getItem(channels.getSelectionIndex());
            channelName.setText(selectedChannelName);
            String key = getKey(selectedChannelName);
            colorSelector.setColorValue(raptorPreferenceStore.getColor(key).getRGB());
          }
        });

    Label channelNameLabel = new Label(parent, SWT.NONE);
    channelNameLabel.setText(local.getString("chanName"));
    channelNameLabel.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1));

    channelName = new Text(parent, SWT.SINGLE | SWT.BORDER);
    channelName.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));

    colorSelector = new ColorSelector(parent);
    colorSelector.getButton().setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, false, 1, 1));

    saveButton = new Button(parent, SWT.PUSH);
    saveButton.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 3, 1));
    saveButton.setText(local.getString("svAddChCol"));
    saveButton.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            onSave();
          }
        });

    // deleteButton = new Button(parent, SWT.PUSH);
    // deleteButton.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false,
    // false, 2, 1));
    // deleteButton.setText("Delete Channel Color");
    // deleteButton.addSelectionListener(new SelectionAdapter() {
    // @Override
    // public void widgetSelected(SelectionEvent e) {
    // try {
    // int channelInt = Integer.parseInt(channelName.getText());
    // String key = getKey("" + channelInt);
    // channels.remove("" + channelInt);
    // raptorPreferenceStore.putValue(key, null);
    // } catch (NumberFormatException nfe) {
    // MessageDialog
    // .openInformation(Raptor.getInstance()
    // .getRaptorWindow().getShell(), "Alert",
    // "Channel name must be an integer greater than -1 and less than 256.");
    // }
    // }
    // });

    updateChannelsCombo();
    if (channels.getItemCount() > 0) {
      channels.select(0);
      String selectedChannelName = channels.getItem(channels.getSelectionIndex());
      channelName.setText(selectedChannelName);
      String key = getKey(selectedChannelName);
      colorSelector.setColorValue(raptorPreferenceStore.getColor(key).getRGB());
    }

    return parent;
  }
 @Override
 public void widgetSelected(SelectionEvent e) {
   ColorSelector editor = (ColorSelector) e.widget.getData();
   PreferenceConverter.setValue(
       fOverlayStore, fColorButtons.get(editor), editor.getColorValue());
 }
  private Control createSyntaxPage(final Composite parent) {
    final Composite colorComposite = new Composite(parent, SWT.NONE);
    GridLayout layout = new GridLayout();
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    colorComposite.setLayout(layout);

    final Link link = new Link(colorComposite, SWT.NONE);
    link.setText(PreferencesMessages.ErlEditorColoringConfigurationBlock_link);
    link.addSelectionListener(
        new SelectionAdapter() {

          @Override
          public void widgetSelected(final SelectionEvent e) {
            PreferencesUtil.createPreferenceDialogOn(parent.getShell(), e.text, null, null);
          }
        });

    final GridData gridData = new GridData(SWT.FILL, SWT.BEGINNING, true, false);
    gridData.widthHint = 150;
    gridData.horizontalSpan = 2;
    link.setLayoutData(gridData);

    addFiller(colorComposite, 1);

    Label label;
    label = new Label(colorComposite, SWT.LEFT);
    label.setText(PreferencesMessages.ErlEditorPreferencePage_coloring_element);
    label.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

    final Composite editorComposite = new Composite(colorComposite, SWT.NONE);
    layout = new GridLayout();
    layout.numColumns = 2;
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    editorComposite.setLayout(layout);
    GridData gd = new GridData(SWT.FILL, SWT.BEGINNING, true, false);
    editorComposite.setLayoutData(gd);

    fListViewer = new TreeViewer(editorComposite, SWT.SINGLE | SWT.BORDER);
    final Tree tree = fListViewer.getTree();
    final GridData gd_tree = new GridData(SWT.FILL, SWT.FILL, false, false, 1, 1);
    gd_tree.widthHint = 100;
    tree.setLayoutData(gd_tree);
    fListViewer.setLabelProvider(new ColorListLabelProvider());
    fListViewer.setContentProvider(new ColorListContentProvider());
    fListViewer.setInput(fColors);
    fListViewer.setSelection(new StructuredSelection(fErlangCategory));
    fListViewer.setSorter(
        new ViewerSorter() {

          @Override
          public int category(final Object element) {
            // don't sort the top level categories
            if (fErlangCategory.equals(element)) {
              return 0;
            }
            // if (fEdocCategory.equals(element)) {
            // return 1;
            // }
            // to sort semantic settings after partition based ones:
            // if (element instanceof SemanticHighlightingColorListItem)
            // return 1;
            return 0;
          }
        });
    gd = new GridData(SWT.BEGINNING, SWT.BEGINNING, false, true);
    gd.heightHint = convertHeightInCharsToPixels(9);
    int maxWidth = 0;
    for (final TokenHighlight item : fColors.keySet()) {
      maxWidth = Math.max(maxWidth, convertWidthInCharsToPixels(item.getName().length()));
    }
    final ScrollBar vBar = ((Scrollable) fListViewer.getControl()).getVerticalBar();
    if (vBar != null) {
      maxWidth += vBar.getSize().x * 3; // scrollbars and tree
    }
    // indentation guess
    gd.widthHint = maxWidth;

    fListViewer.getControl().setLayoutData(gd);
    fListViewer.expandAll();

    final Composite stylesComposite = new Composite(editorComposite, SWT.NONE);
    layout = new GridLayout();
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    layout.numColumns = 2;
    stylesComposite.setLayout(layout);
    stylesComposite.setLayoutData(new GridData(GridData.FILL_BOTH));

    fEnableCheckbox = new Button(stylesComposite, SWT.CHECK);
    fEnableCheckbox.setText(PreferencesMessages.ErlEditorPreferencePage_enable);
    gd = new GridData(GridData.FILL_HORIZONTAL);
    gd.horizontalAlignment = GridData.BEGINNING;
    gd.horizontalSpan = 2;
    fEnableCheckbox.setLayoutData(gd);
    // TODO hide this until reworking the dialog
    fEnableCheckbox.setVisible(false);

    fColorEditorLabel = new Label(stylesComposite, SWT.LEFT);
    fColorEditorLabel.setText(PreferencesMessages.ErlEditorPreferencePage_color);
    gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
    gd.horizontalIndent = 20;
    fColorEditorLabel.setLayoutData(gd);

    fSyntaxForegroundColorEditor = new ColorSelector(stylesComposite);
    final Button foregroundColorButton = fSyntaxForegroundColorEditor.getButton();
    gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
    foregroundColorButton.setLayoutData(gd);
    new Label(stylesComposite, SWT.NONE);

    fBoldCheckBox = new Button(stylesComposite, SWT.CHECK);
    fBoldCheckBox.setText(PreferencesMessages.ErlEditorPreferencePage_bold);
    gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
    gd.horizontalIndent = 20;
    gd.horizontalSpan = 2;
    fBoldCheckBox.setLayoutData(gd);

    fItalicCheckBox = new Button(stylesComposite, SWT.CHECK);
    fItalicCheckBox.setText(PreferencesMessages.ErlEditorPreferencePage_italic);
    gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
    gd.horizontalIndent = 20;
    gd.horizontalSpan = 2;
    fItalicCheckBox.setLayoutData(gd);

    fStrikethroughCheckBox = new Button(stylesComposite, SWT.CHECK);
    fStrikethroughCheckBox.setText(PreferencesMessages.ErlEditorPreferencePage_strikeout);
    gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
    gd.horizontalIndent = 20;
    gd.horizontalSpan = 2;
    fStrikethroughCheckBox.setLayoutData(gd);

    fUnderlineCheckBox = new Button(stylesComposite, SWT.CHECK);
    fUnderlineCheckBox.setText(PreferencesMessages.ErlEditorPreferencePage_underline);
    gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
    gd.horizontalIndent = 20;
    gd.horizontalSpan = 2;
    fUnderlineCheckBox.setLayoutData(gd);

    label = new Label(colorComposite, SWT.LEFT);
    label.setText(
        PreferencesMessages.ErlEditorPreferencePage_preview
            + "\n  - Currently the preview doesn't work, but this dialog does."
            + "\n  - Open files need to be reopened to refresh the coloring.");
    label.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));

    final String content =
        loadPreviewContentFromFile(getClass(), "ColorSettingPreviewCode.txt"); // $NON-NLS-1$
    fPreviewViewer = createErlangPreviewer(colorComposite, fColorManager, fColors, content);
    final Control previewer = fPreviewViewer.getControl();
    gd = new GridData(GridData.FILL_BOTH);
    gd.widthHint = convertWidthInCharsToPixels(20);
    gd.heightHint = convertHeightInCharsToPixels(5);
    gd.grabExcessHorizontalSpace = true;
    previewer.setLayoutData(gd);

    fListViewer.addSelectionChangedListener(
        new ISelectionChangedListener() {

          @Override
          public void selectionChanged(final SelectionChangedEvent event) {
            handleSyntaxColorListSelection();
          }
        });

    foregroundColorButton.addSelectionListener(
        new SelectionListener() {
          @Override
          public void widgetDefaultSelected(final SelectionEvent e) {
            // do nothing
          }

          @Override
          public void widgetSelected(final SelectionEvent e) {
            final TokenHighlight item = getHighlight();
            final HighlightStyle data = fColors.get(item);
            if (data == null) {
              return;
            }
            data.setColor(fSyntaxForegroundColorEditor.getColorValue());
            fPreviewViewer.invalidateTextPresentation();
          }
        });

    fBoldCheckBox.addSelectionListener(
        new SelectionListener() {
          @Override
          public void widgetDefaultSelected(final SelectionEvent e) {
            // do nothing
          }

          @Override
          public void widgetSelected(final SelectionEvent e) {
            final TokenHighlight item = getHighlight();
            final HighlightStyle data = fColors.get(item);
            if (data == null) {
              return;
            }
            data.setStyle(SWT.BOLD, fBoldCheckBox.getSelection());
            fPreviewViewer.invalidateTextPresentation();
          }
        });

    fItalicCheckBox.addSelectionListener(
        new SelectionListener() {
          @Override
          public void widgetDefaultSelected(final SelectionEvent e) {
            // do nothing
          }

          @Override
          public void widgetSelected(final SelectionEvent e) {
            final TokenHighlight item = getHighlight();
            final HighlightStyle data = fColors.get(item);
            if (data == null) {
              return;
            }
            data.setStyle(SWT.ITALIC, fItalicCheckBox.getSelection());
            fPreviewViewer.invalidateTextPresentation();
          }
        });
    fStrikethroughCheckBox.addSelectionListener(
        new SelectionListener() {
          @Override
          public void widgetDefaultSelected(final SelectionEvent e) {
            // do nothing
          }

          @Override
          public void widgetSelected(final SelectionEvent e) {
            final TokenHighlight item = getHighlight();
            final HighlightStyle data = fColors.get(item);
            if (data == null) {
              return;
            }
            data.setStyle(TextAttribute.STRIKETHROUGH, fStrikethroughCheckBox.getSelection());
            fPreviewViewer.invalidateTextPresentation();
          }
        });

    fUnderlineCheckBox.addSelectionListener(
        new SelectionListener() {
          @Override
          public void widgetDefaultSelected(final SelectionEvent e) {
            // do nothing
          }

          @Override
          public void widgetSelected(final SelectionEvent e) {
            final TokenHighlight item = getHighlight();
            final HighlightStyle data = fColors.get(item);
            if (data == null) {
              return;
            }
            data.setStyle(TextAttribute.UNDERLINE, fUnderlineCheckBox.getSelection());
            fPreviewViewer.invalidateTextPresentation();
          }
        });

    fEnableCheckbox.addSelectionListener(
        new SelectionListener() {
          @Override
          public void widgetDefaultSelected(final SelectionEvent e) {
            // do nothing
          }

          @Override
          public void widgetSelected(final SelectionEvent e) {
            fEnableCheckbox.setSelection(true);
            // final TokenHighlight item = getHighlight();
            // if (item instanceof SemanticHighlightingColorListItem) {
            // final boolean enable = fEnableCheckbox.getSelection();
            // getPreferenceStore().setValue(
            // ((SemanticHighlightingColorListItem) item)
            // .getEnableKey(), enable);
            // fEnableCheckbox.setSelection(enable);
            // fSyntaxForegroundColorEditor.getButton().setEnabled(enable);
            // fColorEditorLabel.setEnabled(enable);
            // fBoldCheckBox.setEnabled(enable);
            // fItalicCheckBox.setEnabled(enable);
            // fStrikethroughCheckBox.setEnabled(enable);
            // fUnderlineCheckBox.setEnabled(enable);
            // }
          }
        });

    colorComposite.layout(false);

    return colorComposite;
  }
 private void applyColor() {
   if (fBlockNotification) return;
   RGB rgb = fColorSelector.getColorValue();
   getSplashInfo().setForegroundColor(rgbToHEX(rgb), false);
 }
  private Control createSyntaxPage(final Composite parent) {

    Composite colorComposite = new Composite(parent, SWT.NONE);
    GridLayout layout = new GridLayout();
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    colorComposite.setLayout(layout);

    Link link = new Link(colorComposite, SWT.NONE);
    link.setText(PreferencesMessages.CEditorColoringConfigurationBlock_link);
    link.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            PreferencesUtil.createPreferenceDialogOn(parent.getShell(), e.text, null, null);
          }
        });
    // TODO replace by link-specific tooltips when
    // bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=88866 gets fixed
    //		link.setToolTipText(PreferencesMessages.CEditorColoringConfigurationBlock_link_tooltip);

    GridData gridData = new GridData(SWT.FILL, SWT.BEGINNING, true, false);
    gridData.widthHint = 150; // only expand further if anyone else requires it
    gridData.horizontalSpan = 2;
    link.setLayoutData(gridData);

    addFiller(colorComposite, 1);

    fEnableSemanticHighlightingCheckbox =
        addCheckBox(
            colorComposite,
            PreferencesMessages.CEditorColoringConfigurationBlock_enable_semantic_highlighting,
            PreferenceConstants.EDITOR_SEMANTIC_HIGHLIGHTING_ENABLED,
            0);

    Label label;
    label = new Label(colorComposite, SWT.LEFT);
    label.setText(PreferencesMessages.CEditorColoringConfigurationBlock_coloring_element);
    label.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

    Composite editorComposite = new Composite(colorComposite, SWT.NONE);
    layout = new GridLayout();
    layout.numColumns = 2;
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    editorComposite.setLayout(layout);
    GridData gd = new GridData(SWT.FILL, SWT.BEGINNING, true, false);
    editorComposite.setLayoutData(gd);

    fListViewer = new TreeViewer(editorComposite, SWT.SINGLE | SWT.BORDER);
    fListViewer.setLabelProvider(new ColorListLabelProvider());
    fListViewer.setContentProvider(new ColorListContentProvider());
    fListViewer.setSorter(
        new ViewerSorter() {
          @Override
          public int category(Object element) {
            // don't sort the top level categories
            if (fCodeCategory.equals(element)) return 0;
            if (fAssemblyCategory.equals(element)) return 1;
            if (fCommentsCategory.equals(element)) return 2;
            if (fPreprocessorCategory.equals(element)) return 3;
            if (fDoxygenCategory.equals(element)) return 4;
            return 0;
          }
        });
    gd = new GridData(SWT.BEGINNING, SWT.BEGINNING, false, true);
    gd.heightHint = convertHeightInCharsToPixels(9);
    int maxWidth = 0;
    for (HighlightingColorListItem item : fListModel) {
      maxWidth = Math.max(maxWidth, convertWidthInCharsToPixels(item.getDisplayName().length()));
    }
    ScrollBar vBar = ((Scrollable) fListViewer.getControl()).getVerticalBar();
    if (vBar != null) maxWidth += vBar.getSize().x * 3; // scrollbars and tree indentation guess
    gd.widthHint = maxWidth;

    fListViewer.getControl().setLayoutData(gd);

    Composite stylesComposite = new Composite(editorComposite, SWT.NONE);
    layout = new GridLayout();
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    layout.numColumns = 2;
    stylesComposite.setLayout(layout);
    stylesComposite.setLayoutData(new GridData(GridData.FILL_BOTH));

    fEnableCheckbox = new Button(stylesComposite, SWT.CHECK);
    fEnableCheckbox.setText(PreferencesMessages.CEditorColoringConfigurationBlock_enable);
    gd = new GridData(GridData.FILL_HORIZONTAL);
    gd.horizontalAlignment = GridData.BEGINNING;
    gd.horizontalSpan = 2;
    fEnableCheckbox.setLayoutData(gd);

    fColorEditorLabel = new Label(stylesComposite, SWT.LEFT);
    fColorEditorLabel.setText(PreferencesMessages.CEditorColoringConfigurationBlock_color);
    gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
    gd.horizontalIndent = 20;
    fColorEditorLabel.setLayoutData(gd);

    fSyntaxForegroundColorEditor = new ColorSelector(stylesComposite);
    Button foregroundColorButton = fSyntaxForegroundColorEditor.getButton();
    gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
    foregroundColorButton.setLayoutData(gd);

    fBoldCheckBox = new Button(stylesComposite, SWT.CHECK);
    fBoldCheckBox.setText(PreferencesMessages.CEditorColoringConfigurationBlock_bold);
    gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
    gd.horizontalIndent = 20;
    gd.horizontalSpan = 2;
    fBoldCheckBox.setLayoutData(gd);

    fItalicCheckBox = new Button(stylesComposite, SWT.CHECK);
    fItalicCheckBox.setText(PreferencesMessages.CEditorColoringConfigurationBlock_italic);
    gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
    gd.horizontalIndent = 20;
    gd.horizontalSpan = 2;
    fItalicCheckBox.setLayoutData(gd);

    fStrikethroughCheckBox = new Button(stylesComposite, SWT.CHECK);
    fStrikethroughCheckBox.setText(
        PreferencesMessages.CEditorColoringConfigurationBlock_strikethrough);
    gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
    gd.horizontalIndent = 20;
    gd.horizontalSpan = 2;
    fStrikethroughCheckBox.setLayoutData(gd);

    fUnderlineCheckBox = new Button(stylesComposite, SWT.CHECK);
    fUnderlineCheckBox.setText(PreferencesMessages.CEditorColoringConfigurationBlock_underline);
    gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
    gd.horizontalIndent = 20;
    gd.horizontalSpan = 2;
    fUnderlineCheckBox.setLayoutData(gd);

    label = new Label(colorComposite, SWT.LEFT);
    label.setText(PreferencesMessages.CEditorColoringConfigurationBlock_preview);
    label.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

    Control previewer = createPreviewer(colorComposite);
    gd = new GridData(GridData.FILL_BOTH);
    gd.widthHint = convertWidthInCharsToPixels(20);
    gd.heightHint = convertHeightInCharsToPixels(5);
    previewer.setLayoutData(gd);

    fListViewer.addSelectionChangedListener(
        new ISelectionChangedListener() {
          @Override
          public void selectionChanged(SelectionChangedEvent event) {
            handleSyntaxColorListSelection();
          }
        });

    foregroundColorButton.addSelectionListener(
        new SelectionListener() {
          @Override
          public void widgetDefaultSelected(SelectionEvent e) {
            // do nothing
          }

          @Override
          public void widgetSelected(SelectionEvent e) {
            HighlightingColorListItem item = getHighlightingColorListItem();
            PreferenceConverter.setValue(
                getPreferenceStore(),
                item.getColorKey(),
                fSyntaxForegroundColorEditor.getColorValue());
          }
        });

    fBoldCheckBox.addSelectionListener(
        new SelectionListener() {
          @Override
          public void widgetDefaultSelected(SelectionEvent e) {
            // do nothing
          }

          @Override
          public void widgetSelected(SelectionEvent e) {
            HighlightingColorListItem item = getHighlightingColorListItem();
            getPreferenceStore().setValue(item.getBoldKey(), fBoldCheckBox.getSelection());
          }
        });

    fItalicCheckBox.addSelectionListener(
        new SelectionListener() {
          @Override
          public void widgetDefaultSelected(SelectionEvent e) {
            // do nothing
          }

          @Override
          public void widgetSelected(SelectionEvent e) {
            HighlightingColorListItem item = getHighlightingColorListItem();
            getPreferenceStore().setValue(item.getItalicKey(), fItalicCheckBox.getSelection());
          }
        });
    fStrikethroughCheckBox.addSelectionListener(
        new SelectionListener() {
          @Override
          public void widgetDefaultSelected(SelectionEvent e) {
            // do nothing
          }

          @Override
          public void widgetSelected(SelectionEvent e) {
            HighlightingColorListItem item = getHighlightingColorListItem();
            getPreferenceStore()
                .setValue(item.getStrikethroughKey(), fStrikethroughCheckBox.getSelection());
          }
        });

    fUnderlineCheckBox.addSelectionListener(
        new SelectionListener() {
          @Override
          public void widgetDefaultSelected(SelectionEvent e) {
            // do nothing
          }

          @Override
          public void widgetSelected(SelectionEvent e) {
            HighlightingColorListItem item = getHighlightingColorListItem();
            getPreferenceStore()
                .setValue(item.getUnderlineKey(), fUnderlineCheckBox.getSelection());
          }
        });

    fEnableCheckbox.addSelectionListener(
        new SelectionListener() {
          @Override
          public void widgetDefaultSelected(SelectionEvent e) {
            // do nothing
          }

          @Override
          public void widgetSelected(SelectionEvent e) {
            HighlightingColorListItem item = getHighlightingColorListItem();
            if (item instanceof SemanticHighlightingColorListItem) {
              boolean enable = fEnableCheckbox.getSelection();
              getPreferenceStore()
                  .setValue(((SemanticHighlightingColorListItem) item).getEnableKey(), enable);
              fEnableCheckbox.setSelection(enable);
              fSyntaxForegroundColorEditor.getButton().setEnabled(enable);
              fColorEditorLabel.setEnabled(enable);
              fBoldCheckBox.setEnabled(enable);
              fItalicCheckBox.setEnabled(enable);
              fStrikethroughCheckBox.setEnabled(enable);
              fUnderlineCheckBox.setEnabled(enable);
              uninstallSemanticHighlighting();
              installSemanticHighlighting();
            }
          }
        });

    fEnableSemanticHighlightingCheckbox.addSelectionListener(
        new SelectionListener() {
          @Override
          public void widgetDefaultSelected(SelectionEvent e) {
            // do nothing
          }

          @Override
          public void widgetSelected(SelectionEvent e) {
            fListViewer.refresh(true);
            HighlightingColorListItem item = getHighlightingColorListItem();
            if (item instanceof SemanticHighlightingColorListItem) {
              handleSyntaxColorListSelection();
              uninstallSemanticHighlighting();
              installSemanticHighlighting();
            }
          }
        });

    colorComposite.layout(false);

    return colorComposite;
  }
  private Control createAppearancePage(Composite parent) {

    Composite appearanceComposite = new Composite(parent, SWT.NONE);
    GridLayout layout = new GridLayout();
    layout.numColumns = 2;
    appearanceComposite.setLayout(layout);

    String label;

    label = PreferencesMessages.JavaEditorPreferencePage_subWordNavigation;
    addCheckBox(appearanceComposite, label, PreferenceConstants.EDITOR_SUB_WORD_NAVIGATION, 0);

    label = PreferencesMessages.JavaEditorPreferencePage_analyseAnnotationsWhileTyping;
    addCheckBox(
        appearanceComposite, label, PreferenceConstants.EDITOR_EVALUTE_TEMPORARY_PROBLEMS, 0);

    String text = PreferencesMessages.SmartTypingConfigurationBlock_annotationReporting_link;
    addLink(appearanceComposite, text, INDENT);

    Label spacer = new Label(appearanceComposite, SWT.LEFT);
    GridData gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
    gd.horizontalSpan = 2;
    gd.heightHint = convertHeightInCharsToPixels(1) / 2;
    spacer.setLayoutData(gd);

    label = PreferencesMessages.JavaEditorPreferencePage_highlightMatchingBrackets;
    Button master =
        addCheckBox(appearanceComposite, label, PreferenceConstants.EDITOR_MATCHING_BRACKETS, 0);

    label = PreferencesMessages.JavaEditorPreferencePage_highlightBothBrackets;
    Button slave =
        addCheckBox(
            appearanceComposite,
            label,
            PreferenceConstants.EDITOR_HIGHLIGHT_BRACKET_AT_CARET_LOCATION,
            0);
    createDependency(master, slave);

    label = PreferencesMessages.JavaEditorPreferencePage_highlightEnclosingBrackets;
    slave =
        addCheckBox(appearanceComposite, label, PreferenceConstants.EDITOR_ENCLOSING_BRACKETS, 0);
    createDependency(master, slave);

    label = PreferencesMessages.JavaEditorPreferencePage_quickassist_lightbulb;
    addCheckBox(appearanceComposite, label, PreferenceConstants.EDITOR_QUICKASSIST_LIGHTBULB, 0);

    label = PreferencesMessages.JavaEditorPreferencePage_showJavaElementOnly;
    addCheckBox(appearanceComposite, label, PreferenceConstants.EDITOR_SHOW_SEGMENTS, 0);

    Label l = new Label(appearanceComposite, SWT.LEFT);
    gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
    gd.horizontalSpan = 2;
    gd.heightHint = convertHeightInCharsToPixels(1) / 2;
    l.setLayoutData(gd);

    l = new Label(appearanceComposite, SWT.LEFT);
    l.setText(PreferencesMessages.JavaEditorPreferencePage_appearanceOptions);
    gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
    gd.horizontalSpan = 2;
    l.setLayoutData(gd);

    Composite editorComposite = new Composite(appearanceComposite, SWT.NONE);
    layout = new GridLayout();
    layout.numColumns = 2;
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    editorComposite.setLayout(layout);
    gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.FILL_VERTICAL);
    gd.horizontalSpan = 2;
    editorComposite.setLayoutData(gd);

    fAppearanceColorList = new List(editorComposite, SWT.SINGLE | SWT.V_SCROLL | SWT.BORDER);
    gd = new GridData(GridData.VERTICAL_ALIGN_BEGINNING | GridData.FILL_HORIZONTAL);
    gd.heightHint = convertHeightInCharsToPixels(12);
    fAppearanceColorList.setLayoutData(gd);

    Composite stylesComposite = new Composite(editorComposite, SWT.NONE);
    layout = new GridLayout();
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    layout.numColumns = 2;
    stylesComposite.setLayout(layout);
    stylesComposite.setLayoutData(new GridData(GridData.FILL_BOTH));

    l = new Label(stylesComposite, SWT.LEFT);
    l.setText(PreferencesMessages.JavaEditorPreferencePage_color);
    gd = new GridData();
    gd.horizontalAlignment = GridData.BEGINNING;
    l.setLayoutData(gd);

    fAppearanceColorEditor = new ColorSelector(stylesComposite);
    Button foregroundColorButton = fAppearanceColorEditor.getButton();
    gd = new GridData(GridData.FILL_HORIZONTAL);
    gd.horizontalAlignment = GridData.BEGINNING;
    foregroundColorButton.setLayoutData(gd);

    SelectionListener colorDefaultSelectionListener =
        new SelectionListener() {
          public void widgetSelected(SelectionEvent e) {
            boolean systemDefault = fAppearanceColorDefault.getSelection();
            fAppearanceColorEditor.getButton().setEnabled(!systemDefault);

            int i = fAppearanceColorList.getSelectionIndex();
            if (i == -1) return;

            String key = fAppearanceColorListModel[i][2];
            if (key != null) getPreferenceStore().setValue(key, systemDefault);
          }

          public void widgetDefaultSelected(SelectionEvent e) {}
        };

    fAppearanceColorDefault = new Button(stylesComposite, SWT.CHECK);
    fAppearanceColorDefault.setText(PreferencesMessages.JavaEditorPreferencePage_systemDefault);
    gd = new GridData(GridData.FILL_HORIZONTAL);
    gd.horizontalAlignment = GridData.BEGINNING;
    gd.horizontalSpan = 2;
    fAppearanceColorDefault.setLayoutData(gd);
    fAppearanceColorDefault.setVisible(false);
    fAppearanceColorDefault.addSelectionListener(colorDefaultSelectionListener);

    fAppearanceColorList.addSelectionListener(
        new SelectionListener() {
          public void widgetDefaultSelected(SelectionEvent e) {
            // do nothing
          }

          public void widgetSelected(SelectionEvent e) {
            handleAppearanceColorListSelection();
          }
        });
    foregroundColorButton.addSelectionListener(
        new SelectionListener() {
          public void widgetDefaultSelected(SelectionEvent e) {
            // do nothing
          }

          public void widgetSelected(SelectionEvent e) {
            int i = fAppearanceColorList.getSelectionIndex();
            if (i == -1) return;

            String key = fAppearanceColorListModel[i][1];
            PreferenceConverter.setValue(
                getPreferenceStore(), key, fAppearanceColorEditor.getColorValue());
          }
        });
    return appearanceComposite;
  }