コード例 #1
0
ファイル: Activator.java プロジェクト: go2zo/flaming-bear
  /**
   * Find the image (SWT) in registry Store image in registry if it is not found
   *
   * @param umlImage to retrieve as SWT Image in registry
   * @return the stored SWT image
   */
  public static Image getImageInRegistry(
      org.eclipse.uml2.uml.Image umlImage, VisibilityKind visibility) {
    // Retrieve registry
    ImageRegistry papyrusRegistry = getDefault().getImageRegistry();

    // Get image id for registry
    String image_id = ImageUtil.getImageId(umlImage);
    if (visibility != null) {
      image_id = image_id + "_" + visibility.getLiteral();
    }

    // Get SWT image for shape in the registry
    Image image = papyrusRegistry.get(image_id);

    // If image was not found in registry,
    // try to find an image and to update registry
    if (image == null) {

      try {
        // Try to retrieve image from UML Image content property
        image = ImageUtil.getContent(umlImage);
      } catch (Exception e) {
        // Activator.log.error(e);
      }

      // If no image was found in Content
      // Try to retrieve image from UML Image location property
      if (image == null) {
        image = ImageUtil.getImageFromLocation(umlImage);
      }

      // Add visibility decorator
      if (visibility != null) {

        getDefault();
        ImageDescriptor visDesc =
            Activator.getImageDescriptor(
                UML_VIS_ICONS_16x16 + "VisibilityKind_" + visibility.getLiteral() + ".gif");

        // Overlay custom image over base image
        OverlayVisibilityIcon overlayIcon = new OverlayVisibilityIcon(image, visDesc);
        image = overlayIcon.getImage();
      }

      if (image != null) {
        // Store image in registry
        ImageData imdata = image.getImageData();
        papyrusRegistry.put(image_id, ImageDescriptor.createFromImageData(imdata));
        image = papyrusRegistry.get(image_id);
      }
    }

    return image;
  }
コード例 #2
0
ファイル: RcpActionAdapter.java プロジェクト: halestudio/hale
  /** Set the actions icon as {@link ImageDescriptor} if possible */
  private void loadImage() {
    Object icon = action.getValue(javax.swing.Action.SMALL_ICON);

    if (icon instanceof ImageIcon) {
      try {
        setImageDescriptor(
            ImageDescriptor.createFromImageData(SwingRcpUtilities.convertToSWT((ImageIcon) icon)));
      } catch (Exception e) {
        _log.warn("Error converting action icon", e); // $NON-NLS-1$
      }
    }
  }
コード例 #3
0
 /*
  * (non-Javadoc)
  *
  * @see
  * org.talend.designer.core.ui.editor.properties2.editors.AbstractElementPropertySectionController#createCommand()
  */
 public Command createCommand(Button button) {
   Object data = button.getData(NAME);
   if (data != null) {
     if (ICON_SELECTION.equals(data)) {
       FileDialog dial = new FileDialog(composite.getShell(), SWT.NONE);
       dial.setFilterExtensions(
           new String[] {"*.jpg", "*.png", "*.gif"}); // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
       String propertyName = (String) button.getData(PARAMETER_NAME);
       String file = dial.open();
       if (file != null) {
         if (!file.equals("")) { // $NON-NLS-1$
           if (!elem.getPropertyValue(propertyName).equals(file)) {
             ImageData imageData = new ImageData(file);
             if (ImageUtils.checkSize(
                 ImageDescriptor.createFromImageData(imageData), ImageUtils.ICON_SIZE.ICON_32)) {
               if (elem instanceof IProcess2) {
                 refreshIcon(imageData);
                 return new IconSelectionCommand(
                     (IProcess2) elem, ImageDescriptor.createFromImageData(imageData), file);
               }
             } else {
               MessageDialog.openError(
                   composite.getShell(),
                   Messages.getString("IconSelectionController.MessageTitle"), // $NON-NLS-1$
                   Messages.getString("IconSelectionController.Messages")); // $NON-NLS-1$
             }
           }
         }
       }
     } else if (ICON_REVERT.equals(data)) {
       if (elem instanceof IProcess2) {
         Image defaultIcon = RepositoryLabelProvider.getDefaultJobletImage();
         ImageDescriptor imageData = ImageDescriptor.createFromImage(defaultIcon);
         refreshIcon(defaultIcon.getImageData());
         return new IconSelectionCommand((IProcess2) elem, imageData, null);
       }
     }
   }
   return null;
 }
コード例 #4
0
 /** Returns an {@link Image} instance which is located at the indicated icon path. */
 public static Image getImage(
     org.springframework.ide.eclipse.beans.core.model.INamespaceDefinition namespaceDefinition) {
   if (StringUtils.hasText(namespaceDefinition.getIconPath())) {
     synchronized (IMAGE_REGISTRY_LOCK) {
       Image image =
           BeansUIPlugin.getDefault().getImageRegistry().get(namespaceDefinition.getIconPath());
       if (image == null) {
         InputStream is = namespaceDefinition.getIconStream();
         if (is != null) {
           try {
             ImageDescriptor imageDescriptor =
                 ImageDescriptor.createFromImageData(new ImageData(is));
             BeansUIPlugin.getDefault()
                 .getImageRegistry()
                 .put(namespaceDefinition.getIconPath(), imageDescriptor);
             image =
                 BeansUIPlugin.getDefault()
                     .getImageRegistry()
                     .get(namespaceDefinition.getIconPath());
           } catch (Exception e) {
             BeansUIPlugin.log(
                 String.format(
                     "Error creating image resource for namespace definition '%s'",
                     namespaceDefinition.getNamespaceUri()),
                 e);
             return BeansUIImages.getImage(BeansUIImages.IMG_OBJS_XSD);
           } finally {
             if (is != null) {
               try {
                 is.close();
               } catch (IOException e) {
               }
             }
           }
         } else {
           BeansUIPlugin.getDefault()
               .getImageRegistry()
               .put(
                   namespaceDefinition.getIconPath(),
                   BeansUIImages.getImage(BeansUIImages.IMG_OBJS_XSD));
           image =
               BeansUIPlugin.getDefault()
                   .getImageRegistry()
                   .get(namespaceDefinition.getIconPath());
         }
       }
       return image;
     }
   } else {
     return BeansUIImages.getImage(BeansUIImages.IMG_OBJS_XSD);
   }
 }
コード例 #5
0
ファイル: AboutAction.java プロジェクト: ccbon/ocp
 public AboutAction(DataSourceWindow w) {
   window = w;
   setText("&About@Ctrl+F1");
   setToolTipText("About");
   try {
     ImageDescriptor i =
         ImageDescriptor.createFromImageData(
             new ImageData(DataSourceWindow.class.getResourceAsStream("about.png")));
     setImageDescriptor(i);
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
コード例 #6
0
ファイル: ImageManager.java プロジェクト: eclipse/mylyn.docs
  @SuppressWarnings("unchecked")
  private void updateImage(String imgSrc, ImageData imageData) {
    if (display.isDisposed() || viewer.getTextWidget().isDisposed()) {
      return;
    }
    Image image =
        imageData == null
            ? imageCache.getMissingImage()
            : ImageDescriptor.createFromImageData(imageData).createImage();
    imageCache.putImage(imgSrc, image);

    Set<ImageAnnotation> modifiedAnnotations = new HashSet<>();

    AnnotationModel annotationModel = (AnnotationModel) viewer.getAnnotationModel();
    Object annotationLockObject = annotationModel.getLockObject();
    if (annotationLockObject == null) {
      annotationLockObject = annotationModel;
    }
    synchronized (annotationLockObject) {
      Iterator<Annotation> iterator = annotationModel.getAnnotationIterator();
      while (iterator.hasNext()) {
        Annotation annotation = iterator.next();
        if (annotation instanceof ImageAnnotation) {
          ImageAnnotation imageAnnotation = (ImageAnnotation) annotation;
          if (imgSrc.equals(imageAnnotation.getUrl())) {
            imageAnnotation.setImage(image);
            modifiedAnnotations.add(imageAnnotation);
          }
        }
      }
    }

    if (!modifiedAnnotations.isEmpty()) {
      computingChanges = true;
      try {
        boolean rangesAdjusted = false;
        List<StyleRange> ranges = new ArrayList<>();

        Iterator<?> allStyleRangeIterator = viewer.getTextPresentation().getAllStyleRangeIterator();
        while (allStyleRangeIterator.hasNext()) {
          StyleRange range = (StyleRange) allStyleRangeIterator.next();
          ranges.add((StyleRange) range.clone());
        }

        GC gc = new GC(viewer.getTextWidget());
        try {
          viewer.getTextWidget().setRedraw(false);
          TextPresentation textPresentation = viewer.getTextPresentation();
          //			textPresentation.
          for (ImageAnnotation annotation : modifiedAnnotations) {
            int height = annotation.getImage().getBounds().height;
            Position position = annotationModel.getPosition(annotation);
            String widgetText = viewer.getTextWidget().getText();
            Font font = null;
            if (widgetText.length() > 0 && widgetText.length() > position.offset) {
              StyleRange styleRange = viewer.getTextWidget().getStyleRangeAtOffset(position.offset);
              if (styleRange != null) {
                font = styleRange.font;
              }
            }
            if (font == null) {
              font = viewer.getTextWidget().getFont();
            }
            gc.setFont(font);
            Point extent = gc.textExtent("\n"); // $NON-NLS-1$
            if (extent.y > 0) {
              int numNewlines = (int) Math.ceil(((double) height) / ((double) extent.y));
              final int originalNewlines = numNewlines;
              IDocument document = viewer.getDocument();
              try {
                for (int x = position.offset; x < document.getLength(); ++x) {
                  if (document.getChar(x) == '\n') {
                    if (x != position.offset
                        && Util.annotationsIncludeOffset(viewer.getAnnotationModel(), x)) {
                      break;
                    }
                    --numNewlines;
                  } else {
                    break;
                  }
                }
                if (numNewlines > 0) {
                  String newlines = ""; // $NON-NLS-1$
                  for (int x = 0; x < numNewlines; ++x) {
                    newlines += "\n"; // $NON-NLS-1$
                  }
                  document.replace(position.offset + 1, 0, newlines);
                } else if (numNewlines < 0) {
                  document.replace(position.offset, -numNewlines, ""); // $NON-NLS-1$
                }
                if (numNewlines != 0) {
                  // no need to fixup other annotation positions, since the annotation model is
                  // hooked into the document.

                  // fix up styles
                  for (StyleRange range : ranges) {
                    if (range.start > position.offset) {
                      range.start += numNewlines;
                      rangesAdjusted = true;
                    } else if (range.start + range.length > position.offset) {
                      range.length += numNewlines;
                      rangesAdjusted = true;
                    }
                  }
                }

                // bug# 248643: update the annotation size to reflect the full size of the image
                //              so that it gets repainted when some portion of the image is exposed
                //              as a result of scrolling
                if (position.getLength() != originalNewlines) {
                  annotationModel.modifyAnnotationPosition(
                      annotation, new Position(position.offset, originalNewlines));
                }
              } catch (BadLocationException e) {
                // ignore
              }
            }
          }
          if (rangesAdjusted) {
            TextPresentation presentation = new TextPresentation();
            if (textPresentation.getDefaultStyleRange() != null) {
              StyleRange defaultStyleRange =
                  (StyleRange) textPresentation.getDefaultStyleRange().clone();
              if (viewer.getDocument() != null) {
                if (defaultStyleRange.length < viewer.getDocument().getLength()) {
                  defaultStyleRange.length = viewer.getDocument().getLength();
                }
              }
              presentation.setDefaultStyleRange(defaultStyleRange);
            }
            for (StyleRange range : ranges) {
              presentation.addStyleRange(range);
            }
            viewer.setTextPresentation(presentation);
            viewer.invalidateTextPresentation();
          }
        } finally {
          viewer.getTextWidget().setRedraw(true);
          gc.dispose();
        }
        viewer.getTextWidget().redraw();
      } finally {
        computingChanges = false;
      }
    }
  }