/**
   * Tries to use the input as a hex color triplet and set the color control to the passed in color,
   * and will return any color selection made with the color control in a hex triplet (no hashes
   * included)
   */
  public String manipulate(String highlighted) {
    // this could be a selected color
    String hexstr = highlighted;

    // Shell shell = this.editor.getSite().getShell();
    Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();

    if (shell != null) {
      if (colordialog == null) {
        colordialog = new ColorDialog(shell);
      }

      RGB startrgb = guessRGBColor(highlighted);

      if (startrgb != null) {
        colordialog.setRGB(startrgb);
      }

      colordialog.open();

      RGB selectedcolor = colordialog.getRGB();
      if (selectedcolor != null) {
        hexstr =
            ensureTwoDigits(Integer.toHexString(selectedcolor.red))
                + ensureTwoDigits(Integer.toHexString(selectedcolor.green))
                + ensureTwoDigits(Integer.toHexString(selectedcolor.blue));
      }
    } else {
      System.err.println("Shell is null for some reason");
    }
    return hexstr;
  }
  @Override
  protected String browse(final Presentation context) {
    final Property property = property();

    final Shell parent = ((FormComponentPresentation) context).shell();
    final Rectangle bounds = parent.getBounds();

    // There is no means to compute the size of the color dialog. In the following
    // computations, measurements of the dialog on Windows 7 are used. Will need to
    // generalize in the future.

    final int x = bounds.x + bounds.width / 2 - 120;
    final int y = bounds.y + bounds.height / 2 - 170;

    final Shell shell = new Shell(parent);

    try {
      shell.setBounds(x, y, 0, 0);

      final ColorDialog dialog = new ColorDialog(shell);

      dialog.setText(property.definition().getLabel(false, CapitalizationType.TITLE_STYLE, false));
      dialog.setRGB(convert((Color) ((Value<?>) property).content()));

      final RGB pickedColor = dialog.open();

      if (pickedColor != null) {
        return convert(pickedColor).toString();
      }
    } finally {
      shell.dispose();
    }

    return null;
  }
Beispiel #3
0
  @Override
  public void run() {
    List<?> selection = getSelectedObjects();

    IDiagramModelObject model = (IDiagramModelObject) getFirstValidSelectedModelObject(selection);
    if (model == null) {
      return;
    }

    ColorDialog colorDialog = new ColorDialog(getWorkbenchPart().getSite().getShell());

    // Set default RGB on first selected object
    RGB defaultRGB = null;

    String s = model.getFillColor();
    if (s == null) {
      defaultRGB = ColorFactory.getDefaultFillColor(model).getRGB();
    } else {
      defaultRGB = ColorFactory.convertStringToRGB(s);
    }

    if (defaultRGB != null) {
      colorDialog.setRGB(defaultRGB);
    }

    RGB newColor = colorDialog.open();
    if (newColor != null) {
      execute(createCommand(selection, newColor));
    }
  }
  /**
   * This method is called once when the animation is created. You can use it to get user
   * configurable settings like a Color (as we do in this case)
   */
  @Override
  public void setup(Shell window) {
    // This code opens a SWT Color Dialog
    // After setup is called, we'll have the color set
    ColorDialog dialog = new ColorDialog(window);
    dialog.setRGB(color.getRGB());
    dialog.setText("Choose a color for the wipe");
    RGB rgb = dialog.open();

    // If the color we get back isn't null, use the new color.
    if (rgb != null) {
      color = new Color(window.getDisplay(), rgb);
    }
  }
 public boolean performExtendedEdit() {
   InstallOptionsLink model = (InstallOptionsLink) getModel();
   ColorDialog dialog = new ColorDialog(getViewer().getControl().getShell());
   RGB value = model.getTxtColor();
   if (value != null) {
     dialog.setRGB(value);
   } else {
     dialog.setRGB(InstallOptionsLink.DEFAULT_TXTCOLOR);
   }
   if (dialog.open() != null) {
     mNewValue = dialog.getRGB();
     return true;
   } else {
     return false;
   }
 }
  @Override
  public void runSafe(final IAction action) {
    if (guardFail()) {
      return;
    }
    if (!(getSelection() instanceof IStructuredSelection)) {
      return;
    }
    final IStructuredSelection struct = (IStructuredSelection) getSelection();
    final Object firstElement = struct.getFirstElement();
    if (!(firstElement instanceof ArtifactSelection)) {
      return;
    }
    Object element = null;
    final ArtifactSelection artifactSelection = (ArtifactSelection) firstElement;
    element = artifactSelection.getItem();
    if (element instanceof IActivity) {
      final IActivity activity = (IActivity) element;
      element = activity.getOwner();
    } else if (element instanceof IDuration) {
      final IDuration abstractDuration = (IDuration) element;
      element = abstractDuration.getOwner();
    }

    if (!(element instanceof IArtifact) && !(element instanceof ILogEvent)) {
      return;
    }
    final ArtifactColorMap colorMap = artifactSelection.getSource().getLog().getColorMap();
    final ColorDialog dlg = new ColorDialog(Display.getDefault().getActiveShell());
    final RGB color = dlg.open();
    if (color == null) {
      return;
    }

    if (element instanceof IArtifact) {
      final IArtifact abstractArtifact = (IArtifact) element;
      colorMap.setColor(abstractArtifact, color);
    } else if (element instanceof ILogEvent) {
      ILogEvent o = (ILogEvent) element;
      final ILogEvent event = (ILogEvent) o;
      final IEventColorProvider colorProvider =
          getServiceProvider().getService(IEventColorProvider.class);
      final IColor clr = ColorAdapter.valueOf(color);
      colorProvider.setColor(event.getType(), clr);
    }
  }
Beispiel #7
0
  /**
   * Handle the create button selection event.
   *
   * @param event org.eclipse.swt.events.SelectionEvent
   */
  void createButtonSelected(SelectionEvent event) {

    /* Compute the appropriate dialog style */
    int style = getDefaultStyle();
    if (okButton.getEnabled() && okButton.getSelection()) style |= SWT.OK;
    if (cancelButton.getEnabled() && cancelButton.getSelection()) style |= SWT.CANCEL;
    if (yesButton.getEnabled() && yesButton.getSelection()) style |= SWT.YES;
    if (noButton.getEnabled() && noButton.getSelection()) style |= SWT.NO;
    if (retryButton.getEnabled() && retryButton.getSelection()) style |= SWT.RETRY;
    if (abortButton.getEnabled() && abortButton.getSelection()) style |= SWT.ABORT;
    if (ignoreButton.getEnabled() && ignoreButton.getSelection()) style |= SWT.IGNORE;
    if (iconErrorButton.getEnabled() && iconErrorButton.getSelection()) style |= SWT.ICON_ERROR;
    if (iconInformationButton.getEnabled() && iconInformationButton.getSelection())
      style |= SWT.ICON_INFORMATION;
    if (iconQuestionButton.getEnabled() && iconQuestionButton.getSelection())
      style |= SWT.ICON_QUESTION;
    if (iconWarningButton.getEnabled() && iconWarningButton.getSelection())
      style |= SWT.ICON_WARNING;
    if (iconWorkingButton.getEnabled() && iconWorkingButton.getSelection())
      style |= SWT.ICON_WORKING;
    if (primaryModalButton.getEnabled() && primaryModalButton.getSelection())
      style |= SWT.PRIMARY_MODAL;
    if (applicationModalButton.getEnabled() && applicationModalButton.getSelection())
      style |= SWT.APPLICATION_MODAL;
    if (systemModalButton.getEnabled() && systemModalButton.getSelection())
      style |= SWT.SYSTEM_MODAL;
    if (saveButton.getEnabled() && saveButton.getSelection()) style |= SWT.SAVE;
    if (openButton.getEnabled() && openButton.getSelection()) style |= SWT.OPEN;
    if (multiButton.getEnabled() && multiButton.getSelection()) style |= SWT.MULTI;

    /* Open the appropriate dialog type */
    String name = dialogCombo.getText();

    if (name.equals(ControlExample.getResourceString("ColorDialog"))) {
      ColorDialog dialog = new ColorDialog(shell, style);
      dialog.setRGB(new RGB(100, 100, 100));
      dialog.setText(ControlExample.getResourceString("Title"));
      RGB result = dialog.open();
      textWidget.append(ControlExample.getResourceString("ColorDialog") + Text.DELIMITER);
      textWidget.append(
          ControlExample.getResourceString("Result", new String[] {"" + result}) + Text.DELIMITER);
      textWidget.append("getRGB() = " + dialog.getRGB() + Text.DELIMITER + Text.DELIMITER);
      return;
    }

    if (name.equals(ControlExample.getResourceString("DirectoryDialog"))) {
      DirectoryDialog dialog = new DirectoryDialog(shell, style);
      dialog.setMessage(ControlExample.getResourceString("Example_string"));
      dialog.setText(ControlExample.getResourceString("Title"));
      String result = dialog.open();
      textWidget.append(ControlExample.getResourceString("DirectoryDialog") + Text.DELIMITER);
      textWidget.append(
          ControlExample.getResourceString("Result", new String[] {"" + result})
              + Text.DELIMITER
              + Text.DELIMITER);
      return;
    }

    if (name.equals(ControlExample.getResourceString("FileDialog"))) {
      FileDialog dialog = new FileDialog(shell, style);
      dialog.setFileName(ControlExample.getResourceString("readme_txt"));
      dialog.setFilterNames(FilterNames);
      dialog.setFilterExtensions(FilterExtensions);
      dialog.setText(ControlExample.getResourceString("Title"));
      String result = dialog.open();
      textWidget.append(ControlExample.getResourceString("FileDialog") + Text.DELIMITER);
      textWidget.append(
          ControlExample.getResourceString("Result", new String[] {"" + result}) + Text.DELIMITER);
      textWidget.append("getFileNames() =" + Text.DELIMITER);
      if ((dialog.getStyle() & SWT.MULTI) != 0) {
        String[] files = dialog.getFileNames();
        for (int i = 0; i < files.length; i++) {
          textWidget.append("\t" + files[i] + Text.DELIMITER);
        }
      }
      textWidget.append(
          "getFilterIndex() = " + dialog.getFilterIndex() + Text.DELIMITER + Text.DELIMITER);
      return;
    }

    if (name.equals(ControlExample.getResourceString("FontDialog"))) {
      FontDialog dialog = new FontDialog(shell, style);
      dialog.setText(ControlExample.getResourceString("Title"));
      FontData result = dialog.open();
      textWidget.append(ControlExample.getResourceString("FontDialog") + Text.DELIMITER);
      textWidget.append(
          ControlExample.getResourceString("Result", new String[] {"" + result}) + Text.DELIMITER);
      textWidget.append("getFontList() =" + Text.DELIMITER);
      FontData[] fonts = dialog.getFontList();
      if (fonts != null) {
        for (int i = 0; i < fonts.length; i++) {
          textWidget.append("\t" + fonts[i] + Text.DELIMITER);
        }
      }
      textWidget.append("getRGB() = " + dialog.getRGB() + Text.DELIMITER + Text.DELIMITER);
      return;
    }

    if (name.equals(ControlExample.getResourceString("PrintDialog"))) {
      PrintDialog dialog = new PrintDialog(shell, style);
      dialog.setText(ControlExample.getResourceString("Title"));
      PrinterData result = dialog.open();
      textWidget.append(ControlExample.getResourceString("PrintDialog") + Text.DELIMITER);
      textWidget.append(
          ControlExample.getResourceString("Result", new String[] {"" + result}) + Text.DELIMITER);
      textWidget.append("getScope() = " + dialog.getScope() + Text.DELIMITER);
      textWidget.append("getStartPage() = " + dialog.getStartPage() + Text.DELIMITER);
      textWidget.append("getEndPage() = " + dialog.getEndPage() + Text.DELIMITER);
      textWidget.append(
          "getPrintToFile() = " + dialog.getPrintToFile() + Text.DELIMITER + Text.DELIMITER);
      return;
    }

    if (name.equals(ControlExample.getResourceString("MessageBox"))) {
      MessageBox dialog = new MessageBox(shell, style);
      dialog.setMessage(ControlExample.getResourceString("Example_string"));
      dialog.setText(ControlExample.getResourceString("Title"));
      int result = dialog.open();
      textWidget.append(ControlExample.getResourceString("MessageBox") + Text.DELIMITER);
      /*
       * The resulting integer depends on the original
       * dialog style.  Decode the result and display it.
       */
      switch (result) {
        case SWT.OK:
          textWidget.append(ControlExample.getResourceString("Result", new String[] {"SWT.OK"}));
          break;
        case SWT.YES:
          textWidget.append(ControlExample.getResourceString("Result", new String[] {"SWT.YES"}));
          break;
        case SWT.NO:
          textWidget.append(ControlExample.getResourceString("Result", new String[] {"SWT.NO"}));
          break;
        case SWT.CANCEL:
          textWidget.append(
              ControlExample.getResourceString("Result", new String[] {"SWT.CANCEL"}));
          break;
        case SWT.ABORT:
          textWidget.append(ControlExample.getResourceString("Result", new String[] {"SWT.ABORT"}));
          break;
        case SWT.RETRY:
          textWidget.append(ControlExample.getResourceString("Result", new String[] {"SWT.RETRY"}));
          break;
        case SWT.IGNORE:
          textWidget.append(
              ControlExample.getResourceString("Result", new String[] {"SWT.IGNORE"}));
          break;
        default:
          textWidget.append(ControlExample.getResourceString("Result", new String[] {"" + result}));
          break;
      }
      textWidget.append(Text.DELIMITER + Text.DELIMITER);
    }
  }
  @Override
  public void widgetSelected(SelectionEvent e) {
    Object source = e.getSource();
    boolean updateQuickly = true;

    // Tabs
    if (source == mImageRadio) {
      chooseForegroundTab((Button) source, mImageForm);
    } else if (source == mClipartRadio) {
      chooseForegroundTab((Button) source, mClipartForm);
    } else if (source == mTextRadio) {
      updateFontLabel(mFontButton.getFont());
      chooseForegroundTab((Button) source, mTextForm);
      mText.setFocus();
    }

    // Choose image file
    if (source == mPickImageButton) {
      FileDialog dialog = new FileDialog(mPickImageButton.getShell(), SWT.OPEN);
      String file = dialog.open();
      if (file != null) {
        mImagePathText.setText(file);
      }
    }

    // Enforce Radio Groups
    if (source == mCropRadio) {
      mCropRadio.setSelection(true); // Ensure that you can't toggle it off
      mCenterRadio.setSelection(false);
    } else if (source == mCenterRadio) {
      mCenterRadio.setSelection(true);
      mCropRadio.setSelection(false);
    }
    if (source == mSquareRadio) {
      mSquareRadio.setSelection(true);
      mCircleButton.setSelection(false);
    } else if (source == mCircleButton) {
      mCircleButton.setSelection(true);
      mSquareRadio.setSelection(false);
    }

    if (SUPPORT_LAUNCHER_ICON_TYPES) {
      if (source == mSimpleRadio) {
        mSimpleRadio.setSelection(true);
        mGlossyRadio.setSelection(false);
        mFancyRadio.setSelection(false);
      } else if (source == mFancyRadio) {
        mFancyRadio.setSelection(true);
        mSimpleRadio.setSelection(false);
        mGlossyRadio.setSelection(false);
      } else if (source == mGlossyRadio) {
        mGlossyRadio.setSelection(true);
        mSimpleRadio.setSelection(false);
        mFancyRadio.setSelection(false);
      }
    }

    if (source == mHoloDarkRadio) {
      mHoloDarkRadio.setSelection(true);
      mHoloLightRadio.setSelection(false);
    } else if (source == mHoloLightRadio) {
      mHoloLightRadio.setSelection(true);
      mHoloDarkRadio.setSelection(false);
    }

    if (source == mChooseClipart) {
      MessageDialog dialog =
          new MessageDialog(
              mChooseClipart.getShell(),
              "Choose Clip Art",
              null,
              "Choose Clip Art Image:",
              MessageDialog.NONE,
              new String[] {"Close"},
              0) {
            @Override
            protected Control createCustomArea(Composite parent) {
              // Outer form which just establishes a width for the inner form which
              // wraps in a RowLayout
              Composite outer = new Composite(parent, SWT.NONE);
              GridLayout gridLayout = new GridLayout();
              outer.setLayout(gridLayout);

              Composite chooserForm = new Composite(outer, SWT.NONE);
              GridData gd = new GridData();
              gd.grabExcessVerticalSpace = true;
              gd.widthHint = 450;
              chooserForm.setLayoutData(gd);
              RowLayout clipartFormLayout = new RowLayout(SWT.HORIZONTAL);
              clipartFormLayout.center = true;
              clipartFormLayout.wrap = true;
              chooserForm.setLayout(clipartFormLayout);

              MouseAdapter clickListener =
                  new MouseAdapter() {
                    @SuppressWarnings("unused")
                    @Override
                    public void mouseDown(MouseEvent event) {
                      // Clicked on some of the sample art
                      if (event.widget instanceof ImageControl) {
                        ImageControl image = (ImageControl) event.widget;
                        mSelectedClipart = (String) image.getData();
                        close();

                        for (Control c : mClipartPreviewPanel.getChildren()) {
                          c.dispose();
                        }
                        if (mClipartPreviewPanel.getChildren().length == 0) {
                          try {
                            BufferedImage icon = GraphicGenerator.getClipartIcon(mSelectedClipart);
                            if (icon != null) {
                              Display display = mClipartForm.getDisplay();
                              Image swtImage = SwtUtils.convertToSwt(display, icon, true, -1);
                              new ImageControl(mClipartPreviewPanel, SWT.NONE, swtImage);
                            }
                          } catch (IOException e1) {
                            AdtPlugin.log(e1, null);
                          }
                          mClipartPreviewPanel.pack();
                          mClipartPreviewPanel.layout();
                        }

                        updatePreview();
                      }
                    }
                  };
              Display display = chooserForm.getDisplay();
              Color hoverColor = display.getSystemColor(SWT.COLOR_RED);
              Iterator<String> clipartImages = GraphicGenerator.getClipartNames();
              while (clipartImages.hasNext()) {
                String name = clipartImages.next();
                try {
                  BufferedImage icon = GraphicGenerator.getClipartIcon(name);
                  if (icon != null) {
                    Image swtImage = SwtUtils.convertToSwt(display, icon, true, -1);
                    ImageControl img = new ImageControl(chooserForm, SWT.NONE, swtImage);
                    img.setData(name);
                    img.setHoverColor(hoverColor);
                    img.addMouseListener(clickListener);
                  }
                } catch (IOException e1) {
                  AdtPlugin.log(e1, null);
                }
              }
              outer.pack();
              outer.layout();
              return outer;
            }
          };
      dialog.open();
    }

    if (source == mBgButton) {
      ColorDialog dlg = new ColorDialog(mBgButton.getShell());
      dlg.setRGB(mBgColor);
      dlg.setText("Choose a new Background Color");
      RGB rgb = dlg.open();
      if (rgb != null) {
        // Dispose the old color, create the
        // new one, and set into the label
        updateColor(mBgButton.getDisplay(), rgb, true /*background*/);
      }
    } else if (source == mFgButton) {
      ColorDialog dlg = new ColorDialog(mFgButton.getShell());
      dlg.setRGB(mFgColor);
      dlg.setText("Choose a new Foreground Color");
      RGB rgb = dlg.open();
      if (rgb != null) {
        // Dispose the old color, create the
        // new one, and set into the label
        updateColor(mFgButton.getDisplay(), rgb, false /*background*/);
      }
    }

    if (source == mFontButton) {
      FontDialog dialog = new FontDialog(mFontButton.getShell());
      FontData[] fontList;
      if (mFontButton.getData() == null) {
        fontList = mFontButton.getDisplay().getFontList("Helvetica", true /*scalable*/);
      } else {
        fontList = mFontButton.getFont().getFontData();
      }
      dialog.setFontList(fontList);
      FontData data = dialog.open();
      if (data != null) {
        Font font = new Font(mFontButton.getDisplay(), dialog.getFontList());
        mFontButton.setFont(font);
        updateFontLabel(font);
        mFontButton.getParent().pack();
        // Mark the font on the button as custom (since the renderer needs to
        // distinguish between this font and the default font it starts out with)
        mFontButton.setData(Boolean.TRUE);
      }
    }

    if (source == mPaddingSlider) {
      mPercentLabel.setText(Integer.toString(getPadding()) + '%');

      // When dragging the slider, only do periodic updates
      updateQuickly = false;
    }

    requestUpdatePreview(updateQuickly);
  }
 private void showColorDialog() {
   ColorDialog dialog = new ColorDialog(getShell());
   RGB result = dialog.open();
   messageBoxDlgResLabel.setText("Result: " + result);
   messageBoxDlgResLabel.pack();
 }