/** @param args */
  public static void main(String[] args) {
    Display display = new Display();
    JFaceResources.getImageRegistry()
        .put(
            "IMG_1",
            ImageDescriptor.createFromURL(
                Snippet033CellEditorPerRowPre33.class
                    .getClassLoader()
                    .getResource("org/eclipse/jface/snippets/dialogs/cancel.png")));
    JFaceResources.getImageRegistry()
        .put(
            "IMG_2",
            ImageDescriptor.createFromURL(
                Snippet033CellEditorPerRowPre33.class
                    .getClassLoader()
                    .getResource("org/eclipse/jface/snippets/dialogs/filesave.png")));
    Shell shell = new Shell(display);
    shell.setLayout(new FillLayout());
    new Snippet033CellEditorPerRowPre33(shell);
    shell.open();

    while (!shell.isDisposed()) {
      if (!display.readAndDispatch()) display.sleep();
    }

    display.dispose();
  }
 /**
  * Fetches image descriptor by path.
  *
  * @param path path
  * @return {@link ImageDescriptor}
  */
 public static ImageDescriptor getImageDescriptor(String path) {
   final String key = path;
   ImageDescriptor regImage = JFaceResources.getImageRegistry().getDescriptor(key);
   if (regImage == null) {
     regImage = Activator.getImageDescriptor("icons/merge/" + path);
     JFaceResources.getImageRegistry().put(key, regImage);
   }
   return regImage;
 }
示例#3
0
  public static Image getImage(String pluginId, String path) {
    Image image = JFaceResources.getImageRegistry().get(path);
    if (image == null) {
      ImageDescriptor descriptor = AbstractUIPlugin.imageDescriptorFromPlugin(pluginId, path);
      if (descriptor == null) {
        descriptor = ImageDescriptor.getMissingImageDescriptor();
      }
      JFaceResources.getImageRegistry().put(path, image = descriptor.createImage());
    }

    return image;
  }
示例#4
0
 protected Image getImageImage(String path) {
   Image image = JFaceResources.getImageRegistry().get(path);
   if (image == null) {
     ImageDescriptor descriptor =
         AbstractUIPlugin.imageDescriptorFromPlugin(
             "org.reuseware.application.taipan", path); // $NON-NLS-1$
     if (descriptor == null) {
       descriptor = ImageDescriptor.getMissingImageDescriptor();
     }
     JFaceResources.getImageRegistry().put(path, image = descriptor.createImage());
   }
   return image;
 }
示例#5
0
 /** Get image descriptors for the clear button. */
 static {
   ImageDescriptor descriptor =
       AbstractUIPlugin.imageDescriptorFromPlugin(
           PlatformUI.PLUGIN_ID, "$nl$/icons/full/etool16/clear_co.gif"); // $NON-NLS-1$
   if (descriptor != null) {
     JFaceResources.getImageRegistry().put(CLEAR_ICON, descriptor);
   }
   descriptor =
       AbstractUIPlugin.imageDescriptorFromPlugin(
           PlatformUI.PLUGIN_ID, "$nl$/icons/full/dtool16/clear_co.gif"); // $NON-NLS-1$
   if (descriptor != null) {
     JFaceResources.getImageRegistry().put(DCLEAR_ICON, descriptor);
   }
 }
示例#6
0
  /**
   * Create the button that clears the text.
   *
   * @param parent parent <code>Composite</code> of toolbar button
   */
  private void createClearText(Composite parent) {
    ToolBar toolBar = new ToolBar(parent, SWT.FLAT | SWT.HORIZONTAL);
    filterToolBar = new ToolBarManager(toolBar);

    IAction clearTextAction = new Action("", IAction.AS_PUSH_BUTTON) { // $NON-NLS-1$
          /*
           * (non-Javadoc)
           *
           * @see org.eclipse.jface.action.Action#run()
           */
          public void run() {
            clearText();
          }
        };

    clearTextAction.setToolTipText(WorkbenchMessages.FilteredTree_ClearToolTip);
    clearTextAction.setImageDescriptor(JFaceResources.getImageRegistry().getDescriptor(CLEAR_ICON));
    clearTextAction.setDisabledImageDescriptor(
        JFaceResources.getImageRegistry().getDescriptor(DCLEAR_ICON));

    filterToolBar.add(clearTextAction);
  }
  /**
   * Returns a corner image for the specified position and color.
   *
   * <p>The returned image is cached and may not be disposed.
   *
   * @param position the wanted position of the image
   * @param rgb the wanted color
   * @return the image
   */
  public static Image getCornerImage(DecorationPosition position, RGB rgb) {
    final String key = "CORNER_IMAGE:" + position + ":" + rgb; // $NON-NLS-1$ //$NON-NLS-2$
    final ImageRegistry ir = JFaceResources.getImageRegistry();
    Image image = ir.get(key);
    if (image != null) return image;

    final Display device = Display.getDefault();
    final Color color = new Color(device, rgb);

    image = new Image(device, 5, 5);
    final GC gc = new GC(image);
    gc.setBackground(color);

    switch (position) {
      case TOP_LEFT:
        gc.fillPolygon(new int[] {0, 0, 4, 0, 0, 4});
        break;
      case CENTER_LEFT:
        gc.fillPolygon(new int[] {0, 0, 4, 2, 0, 4});
        break;
      case BOTTOM_LEFT:
        gc.fillPolygon(new int[] {0, 0, 4, 4, 0, 4});
        break;
      case TOP_RIGHT:
        gc.fillPolygon(new int[] {4, 0, 0, 0, 4, 4});
        break;
      case CENTER_RIGHT:
        gc.fillPolygon(new int[] {4, 0, 2, 0, 4, 4});
        break;
      case BOTTOM_RIGHT:
        gc.fillPolygon(new int[] {4, 0, 4, 0, 4, 4});
        break;
    }

    gc.dispose();
    color.dispose();

    /*
     * Set the transparent color
     */
    final ImageData ideaData = image.getImageData();
    final int whitePixel = ideaData.palette.getPixel(new RGB(255, 255, 255));
    ideaData.transparentPixel = whitePixel;

    ir.put(key, image);

    return image;
  }
示例#8
0
  /**
   * Finds and caches the image from the image descriptor for this particular bundle.
   *
   * @param bundle the bundle to search
   * @param path the path to the image
   * @return the image, or null if not found
   */
  public static Image getImage(Bundle bundle, String path) {
    if (path.charAt(0) != '/') {
      path = "/" + path; // $NON-NLS-1$
    }

    String computedName = bundle.getSymbolicName() + path;
    Image image = JFaceResources.getImage(computedName);
    if (image != null) {
      return image;
    }

    ImageDescriptor id = AbstractUIPlugin.imageDescriptorFromPlugin(bundle.getSymbolicName(), path);
    if (id != null) {
      JFaceResources.getImageRegistry().put(computedName, id);
      return JFaceResources.getImage(computedName);
    }
    return null;
  }
public class ImageManager implements IImageManager {

  private static final ImageRegistry IMAGE_REGISTRY = JFaceResources.getImageRegistry();

  ImageManager() {
    String[] imageNames =
        new String[] {METHOD_ENTRY, METHOD_EXIT, EXCEPTION_CATCH, EXCEPTION_THROW, WARNING, LOGO};

    for (String imageName : imageNames) {
      URL url = Platform.getBundle(Activator.PLUGIN_ID).getEntry("/icons/" + imageName + ".gif");
      ImageDescriptor imageDescriptor = ImageDescriptor.createFromURL(url);
      IMAGE_REGISTRY.put(imageName, imageDescriptor);
    }
  }

  @Override
  public Image getImage(String name) {
    return IMAGE_REGISTRY.get(name);
  }
}
  /**
   * Returns a square image for the specified color.
   *
   * <p>The returned image is cached and may not be disposed.
   *
   * @param rgb the wanted color
   * @param size TODO
   * @return the image
   */
  public static Image getSquareImage(RGB rgb, int size) {
    final String key = "SQUARE_IMAGE:" + rgb; // $NON-NLS-1$
    final ImageRegistry ir = JFaceResources.getImageRegistry();
    Image image = ir.get(key);
    if (image != null) return image;

    final Display device = Display.getDefault();
    final Color color = new Color(device, rgb);

    image = new Image(device, size, size);
    final GC gc = new GC(image);
    gc.setBackground(color);

    gc.fillRectangle(0, 0, size, size);

    gc.dispose();
    color.dispose();

    ir.put(key, image);

    return image;
  }
  public void testGetString() {

    // note, we must touch the class to ensure the static initialer runs
    // so the image registry is up to date
    Dialog.getBlockedHandler();

    String[] imageNames =
        new String[] {
          Dialog.DLG_IMG_ERROR,
          Dialog.DLG_IMG_INFO,
          Dialog.DLG_IMG_QUESTION,
          Dialog.DLG_IMG_WARNING,
          Dialog.DLG_IMG_MESSAGE_ERROR,
          Dialog.DLG_IMG_MESSAGE_INFO,
          Dialog.DLG_IMG_MESSAGE_WARNING
        };

    ImageRegistry reg = JFaceResources.getImageRegistry();

    for (String imageName : imageNames) {
      Image image1 = reg.get(imageName);
      assertTrue("Returned null image", image1 != null);
    }
  }
示例#12
0
/**
 * An abstract base implementation of a wizard. A typical client subclasses <code>Wizard</code> to
 * implement a particular wizard.
 *
 * <p>Subclasses may call the following methods to configure the wizard:
 *
 * <ul>
 *   <li><code>addPage</code>
 *   <li><code>setHelpAvailable</code>
 *   <li><code>setDefaultPageImageDescriptor</code>
 *   <li><code>setDialogSettings</code>
 *   <li><code>setNeedsProgressMonitor</code>
 *   <li><code>setTitleBarColor</code>
 *   <li><code>setWindowTitle</code>
 * </ul>
 *
 * <p>Subclasses may override these methods if required:
 *
 * <ul>
 *   <li>reimplement <code>createPageControls</code>
 *   <li>reimplement <code>performCancel</code>
 *   <li>extend <code>addPages</code>
 *   <li>reimplement <code>performFinish</code>
 *   <li>extend <code>dispose</code>
 * </ul>
 *
 * <p>Note that clients are free to implement <code>IWizard</code> from scratch instead of
 * subclassing <code>Wizard</code>. Correct implementations of <code>IWizard</code> will work with
 * any correct implementation of <code>IWizardPage</code>.
 */
public abstract class Wizard implements IWizard {
  /**
   * Image registry key of the default image for wizard pages (value <code>
   * "org.eclipse.jface.wizard.Wizard.pageImage"</code>).
   */
  public static final String DEFAULT_IMAGE =
      "org.eclipse.jface.wizard.Wizard.pageImage"; //$NON-NLS-1$

  /** The wizard container this wizard belongs to; <code>null</code> if none. */
  private IWizardContainer container = null;

  /** This wizard's list of pages (element type: <code>IWizardPage</code>). */
  private List pages = new ArrayList();

  /** Indicates whether this wizard needs a progress monitor. */
  private boolean needsProgressMonitor = false;

  /**
   * Indicates whether this wizard needs previous and next buttons even if the wizard has only one
   * page.
   */
  private boolean forcePreviousAndNextButtons = false;

  /** Indicates whether this wizard supports help. */
  private boolean isHelpAvailable = false;

  /** The default page image for pages without one of their one; <code>null</code> if none. */
  private Image defaultImage = null;

  /**
   * The default page image descriptor, used for creating a default page image if required; <code>
   * null</code> if none.
   */
  private ImageDescriptor defaultImageDescriptor =
      JFaceResources.getImageRegistry().getDescriptor(DEFAULT_IMAGE);

  /** The color of the wizard title bar; <code>null</code> if none. */
  private RGB titleBarColor = null;

  /** The window title string for this wizard; <code>null</code> if none. */
  private String windowTitle = null;

  /** The dialog settings for this wizard; <code>null</code> if none. */
  private IDialogSettings dialogSettings = null;

  /** Creates a new empty wizard. */
  protected Wizard() {
    super();
  }

  /**
   * Adds a new page to this wizard. The page is inserted at the end of the page list.
   *
   * @param page the new page
   */
  public void addPage(IWizardPage page) {
    pages.add(page);
    page.setWizard(this);
  }

  /**
   * The <code>Wizard</code> implementation of this <code>IWizard</code> method does nothing.
   * Subclasses should extend if extra pages need to be added before the wizard opens. New pages
   * should be added by calling <code>addPage</code>.
   */
  public void addPages() {}

  /*
   * (non-Javadoc) Method declared on IWizard.
   */
  public boolean canFinish() {
    // Default implementation is to check if all pages are complete.
    for (int i = 0; i < pages.size(); i++) {
      if (!((IWizardPage) pages.get(i)).isPageComplete()) {
        return false;
      }
    }
    return true;
  }

  /**
   * The <code>Wizard</code> implementation of this <code>IWizard</code> method creates all the
   * pages controls using <code>IDialogPage.createControl</code>. Subclasses should reimplement this
   * method if they want to delay creating one or more of the pages lazily. The framework ensures
   * that the contents of a page will be created before attempting to show it.
   */
  public void createPageControls(Composite pageContainer) {
    // the default behavior is to create all the pages controls
    for (int i = 0; i < pages.size(); i++) {
      IWizardPage page = (IWizardPage) pages.get(i);
      page.createControl(pageContainer);
      // page is responsible for ensuring the created control is
      // accessable
      // via getControl.
      Assert.isNotNull(page.getControl());
    }
  }

  /**
   * The <code>Wizard</code> implementation of this <code>IWizard</code> method disposes all the
   * pages controls using <code>DialogPage.dispose</code>. Subclasses should extend this method if
   * the wizard instance maintains addition SWT resource that need to be disposed.
   */
  public void dispose() {
    // notify pages
    for (int i = 0; i < pages.size(); i++) {
      try {
        ((IWizardPage) pages.get(i)).dispose();
      } catch (Exception e) {
        Status status = new Status(IStatus.ERROR, Policy.JFACE, IStatus.ERROR, e.getMessage(), e);
        Policy.getLog().log(status);
      }
    }
    // dispose of image
    if (defaultImage != null) {
      JFaceResources.getResources().destroyImage(defaultImageDescriptor);
      defaultImage = null;
    }
  }

  /*
   * (non-Javadoc) Method declared on IWizard.
   */
  public IWizardContainer getContainer() {
    return container;
  }

  /*
   * (non-Javadoc) Method declared on IWizard.
   */
  public Image getDefaultPageImage() {
    if (defaultImage == null) {
      defaultImage = JFaceResources.getResources().createImageWithDefault(defaultImageDescriptor);
    }
    return defaultImage;
  }

  /*
   * (non-Javadoc) Method declared on IWizard.
   */
  public IDialogSettings getDialogSettings() {
    return dialogSettings;
  }

  /*
   * (non-Javadoc) Method declared on IWizard. The default behavior is to
   * return the page that was added to this wizard after the given page.
   */
  public IWizardPage getNextPage(IWizardPage page) {
    int index = pages.indexOf(page);
    if (index == pages.size() - 1 || index == -1) {
      // last page or page not found
      return null;
    }
    return (IWizardPage) pages.get(index + 1);
  }

  /*
   * (non-Javadoc) Method declared on IWizard.
   */
  public IWizardPage getPage(String name) {
    for (int i = 0; i < pages.size(); i++) {
      IWizardPage page = (IWizardPage) pages.get(i);
      String pageName = page.getName();
      if (pageName.equals(name)) {
        return page;
      }
    }
    return null;
  }

  /*
   * (non-Javadoc) Method declared on IWizard.
   */
  public int getPageCount() {
    return pages.size();
  }

  /*
   * (non-Javadoc) Method declared on IWizard.
   */
  public IWizardPage[] getPages() {
    return (IWizardPage[]) pages.toArray(new IWizardPage[pages.size()]);
  }

  /*
   * (non-Javadoc) Method declared on IWizard. The default behavior is to
   * return the page that was added to this wizard before the given page.
   */
  public IWizardPage getPreviousPage(IWizardPage page) {
    int index = pages.indexOf(page);
    if (index == 0 || index == -1) {
      // first page or page not found
      return null;
    }
    return (IWizardPage) pages.get(index - 1);
  }

  /**
   * Returns the wizard's shell if the wizard is visible. Otherwise <code>null</code> is returned.
   *
   * @return Shell
   */
  public Shell getShell() {
    if (container == null) {
      return null;
    }
    return container.getShell();
  }

  /*
   * (non-Javadoc) Method declared on IWizard. By default this is the first
   * page inserted into the wizard.
   */
  public IWizardPage getStartingPage() {
    if (pages.size() == 0) {
      return null;
    }
    return (IWizardPage) pages.get(0);
  }

  /*
   * (non-Javadoc) Method declared on IWizard.
   */
  public RGB getTitleBarColor() {
    return titleBarColor;
  }

  /*
   * (non-Javadoc) Method declared on IWizard.
   */
  public String getWindowTitle() {
    return windowTitle;
  }

  /*
   * (non-Javadoc) Method declared on IWizard.
   */
  public boolean isHelpAvailable() {
    return isHelpAvailable;
  }

  /*
   * (non-Javadoc) Method declared on IWizard.
   */
  public boolean needsPreviousAndNextButtons() {
    return forcePreviousAndNextButtons || pages.size() > 1;
  }

  /*
   * (non-Javadoc) Method declared on IWizard.
   */
  public boolean needsProgressMonitor() {
    return needsProgressMonitor;
  }

  /**
   * The <code>Wizard</code> implementation of this <code>IWizard</code> method does nothing and
   * returns <code>true</code>. Subclasses should reimplement this method if they need to perform
   * any special cancel processing for their wizard.
   */
  public boolean performCancel() {
    return true;
  }

  /**
   * Subclasses must implement this <code>IWizard</code> method to perform any special finish
   * processing for their wizard.
   */
  public abstract boolean performFinish();

  /*
   * (non-Javadoc) Method declared on IWizard.
   */
  public void setContainer(IWizardContainer wizardContainer) {
    container = wizardContainer;
  }

  /**
   * Sets the default page image descriptor for this wizard.
   *
   * <p>This image descriptor will be used to generate an image for a page with no image of its own;
   * the image will be computed once and cached.
   *
   * @param imageDescriptor the default page image descriptor
   */
  public void setDefaultPageImageDescriptor(ImageDescriptor imageDescriptor) {
    defaultImageDescriptor = imageDescriptor;
  }

  /**
   * Sets the dialog settings for this wizard.
   *
   * <p>The dialog settings is used to record state between wizard invocations (for example, radio
   * button selection, last import directory, etc.)
   *
   * @param settings the dialog settings, or <code>null</code> if none
   * @see #getDialogSettings
   */
  public void setDialogSettings(IDialogSettings settings) {
    dialogSettings = settings;
  }

  /**
   * Controls whether the wizard needs Previous and Next buttons even if it currently contains only
   * one page.
   *
   * <p>This flag should be set on wizards where the first wizard page adds follow-on wizard pages
   * based on user input.
   *
   * @param b <code>true</code> to always show Next and Previous buttons, and <code>false</code> to
   *     suppress Next and Previous buttons for single page wizards
   */
  public void setForcePreviousAndNextButtons(boolean b) {
    forcePreviousAndNextButtons = b;
  }

  /**
   * Sets whether help is available for this wizard.
   *
   * <p>The result of this method is typically used by the container to show or hide the button
   * labeled "Help".
   *
   * <p><strong>Note:</strong> This wizard's container might be a {@link TrayDialog} which provides
   * its own help support that is independent of this property.
   *
   * <p><strong>Note 2:</strong> In the default {@link WizardDialog} implementation, the "Help"
   * button only works when {@link org.eclipse.jface.dialogs.IDialogPage#performHelp()} is
   * implemented.
   *
   * @param b <code>true</code> if help is available, <code>false</code> otherwise
   * @see #isHelpAvailable()
   * @see TrayDialog#isHelpAvailable()
   * @see TrayDialog#setHelpAvailable(boolean)
   */
  public void setHelpAvailable(boolean b) {
    isHelpAvailable = b;
  }

  /**
   * Sets whether this wizard needs a progress monitor.
   *
   * @param b <code>true</code> if a progress monitor is required, and <code>false</code> if none is
   *     needed
   * @see #needsProgressMonitor()
   */
  public void setNeedsProgressMonitor(boolean b) {
    needsProgressMonitor = b;
  }

  /**
   * Sets the title bar color for this wizard.
   *
   * @param color the title bar color
   */
  public void setTitleBarColor(RGB color) {
    titleBarColor = color;
  }

  /**
   * Sets the window title for the container that hosts this page to the given string.
   *
   * @param newTitle the window title for the container
   */
  public void setWindowTitle(String newTitle) {
    windowTitle = newTitle;
    if (container != null) {
      container.updateWindowTitle();
    }
  }
}
 public Image getImage() {
   // TODO Auto-generated method stub
   return JFaceResources.getImageRegistry().get(PROCEDURE_COLUMN_ICON);
 }
 static {
   ImageRegistry reg = JFaceResources.getImageRegistry();
   reg.put(
       PROCEDURE_COLUMN_ICON,
       ImageDescriptor.createFromFile(JdbcPlugin.class, "icons/column.gif")); // $NON-NLS-1$
 }
 public Image getImage() {
   return JFaceResources.getImageRegistry().get(PROCEDURE_ICON);
 }
 /**
  * Returns the image registry for this plugin.
  *
  * @return ImageRegistry - image registry for this plugin
  */
 private static ImageRegistry getImageRegistry() {
   return JFaceResources.getImageRegistry();
 }
  public void testGetNull() {
    ImageRegistry reg = JFaceResources.getImageRegistry();

    Image result = reg.get((String) null);
    assertTrue("Registry should handle null", result == null);
  }