List of usage examples for org.eclipse.jface.dialogs DialogTray DialogTray
DialogTray
From source file:com.android.ide.eclipse.adt.internal.ui.ResourcePreviewHelper.java
License:Open Source License
/** * Updates the preview based on the current selection and resource type, possibly * hiding or opening the tray in the process. * * @param type the resource type for the selected resource * @param resource the full resource url *///from w w w . j a va 2 s . com public void updatePreview(ResourceType type, String resource) { boolean showPreview = type == ResourceType.DRAWABLE || type == ResourceType.COLOR; if (showPreview) { if (mPreviewTray == null) { mPreviewTray = new DialogTray() { @Override protected Control createContents(Composite parent) { // This creates a centered image control Composite panel = new Composite(parent, SWT.NONE); panel.setLayout(new GridLayout(3, false)); Label dummy1 = new Label(panel, SWT.NONE); dummy1.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, true, 1, 1)); mPreviewImageControl = new ImageControl(panel, SWT.NONE, SwtUtils.createEmptyImage(parent.getDisplay(), WIDTH, HEIGHT)); GridData gd = new GridData(SWT.CENTER, SWT.CENTER, false, false, 1, 1); gd.widthHint = WIDTH; gd.heightHint = HEIGHT; mPreviewImageControl.setLayoutData(gd); Label dummy2 = new Label(panel, SWT.NONE); dummy2.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, true, 1, 1)); return panel; } }; } if (!mShowingPreview) { mTrayDialog.openTray(mPreviewTray); } BufferedImage image = null; try { if (type == ResourceType.COLOR) { ResourceResolver resources = mEditor.getResourceResolver(); ResourceValue value = resources.findResValue(resource, false); if (value != null) { RGB color = ResourceHelper.resolveColor(resources, value); if (color != null) { image = ImageUtils.createColoredImage(WIDTH, HEIGHT, color); } } } else { assert type == ResourceType.DRAWABLE; ResourceResolver resources = mEditor.getResourceResolver(); ResourceValue drawable = resources.findResValue(resource, false); if (drawable != null) { String path = drawable.getValue(); // Special-case image files (other than 9-patch files) and render these // directly, in order to provide proper aspect ratio handling and // to handle scaling to show the full contents: if (ImageUtils.hasImageExtension(path) && !endsWithIgnoreCase(path, DOT_9PNG)) { File file = new File(path); if (file.exists()) { try { image = ImageIO.read(file); int width = image.getWidth(); int height = image.getHeight(); if (width > WIDTH || height > HEIGHT) { double xScale = WIDTH / (double) width; double yScale = HEIGHT / (double) height; double scale = Math.min(xScale, yScale); image = ImageUtils.scale(image, scale, scale); } } catch (IOException e) { AdtPlugin.log(e, "Can't read preview image %1$s", path); } } } if (image == null) { RenderService renderService = RenderService.create(mEditor); renderService.setOverrideRenderSize(WIDTH, HEIGHT); image = renderService.renderDrawable(drawable); } } } } catch (Throwable t) { // Some kind of rendering error occurred. However, we don't want to use // AdtPlugin.log(t, "Can't generate preview for %1$s", resource); // because if it's a severe type of error (such as an InternalError shown // in issue #18623) then a dialog will pop up and interfere with the // preview, so just log a warning (unfortunately without the trace) instead. AdtPlugin.log(IStatus.WARNING, "Can't generate preview for %1$s", resource); } Display display = mEditor.getSite().getShell().getDisplay(); if (image != null) { mPreviewImageControl.setImage(SwtUtils.convertToSwt(display, image, true, -1)); } else { mPreviewImageControl.setImage(SwtUtils.createEmptyImage(display, WIDTH, HEIGHT)); } mPreviewImageControl.redraw(); } else if (mPreviewTray != null && mShowingPreview) { mTrayDialog.closeTray(); } mShowingPreview = showPreview; }
From source file:com.android.ide.eclipse.auidt.internal.ui.ResourcePreviewHelper.java
License:Open Source License
/** * Updates the preview based on the current selection and resource type, possibly * hiding or opening the tray in the process. * * @param type the resource type for the selected resource * @param resource the full resource url *//* w w w . j a v a 2 s.co m*/ public void updatePreview(ResourceType type, String resource) { boolean showPreview = type == ResourceType.DRAWABLE || type == ResourceType.COLOR; if (showPreview) { if (mPreviewTray == null) { mPreviewTray = new DialogTray() { @Override protected Control createContents(Composite parent) { // This creates a centered image control Composite panel = new Composite(parent, SWT.NONE); panel.setLayout(new GridLayout(3, false)); Label dummy1 = new Label(panel, SWT.NONE); dummy1.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, true, 1, 1)); mPreviewImageControl = new ImageControl(panel, SWT.NONE, SwtUtils.createEmptyImage(parent.getDisplay(), WIDTH, HEIGHT)); GridData gd = new GridData(SWT.CENTER, SWT.CENTER, false, false, 1, 1); gd.widthHint = WIDTH; gd.heightHint = HEIGHT; mPreviewImageControl.setLayoutData(gd); Label dummy2 = new Label(panel, SWT.NONE); dummy2.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, true, 1, 1)); return panel; } }; } if (!mShowingPreview) { mTrayDialog.openTray(mPreviewTray); } BufferedImage image = null; try { if (type == ResourceType.COLOR) { ResourceResolver resources = mEditor.getResourceResolver(); ResourceValue value = resources.findResValue(resource, false); if (value != null) { RGB color = ResourceHelper.resolveColor(resources, value); if (color != null) { image = ImageUtils.createColoredImage(WIDTH, HEIGHT, color); } } } else { assert type == ResourceType.DRAWABLE; ResourceResolver resources = mEditor.getResourceResolver(); ResourceValue drawable = resources.findResValue(resource, false); if (drawable != null) { String path = drawable.getValue(); // Special-case image files (other than 9-patch files) and render these // directly, in order to provide proper aspect ratio handling and // to handle scaling to show the full contents: if (ImageUtils.hasImageExtension(path) && !endsWithIgnoreCase(path, DOT_9PNG)) { File file = new File(path); if (file.exists()) { try { image = ImageIO.read(file); int width = image.getWidth(); int height = image.getHeight(); if (width > WIDTH || height > HEIGHT) { double xScale = WIDTH / (double) width; double yScale = HEIGHT / (double) height; double scale = Math.min(xScale, yScale); image = ImageUtils.scale(image, scale, scale); } } catch (IOException e) { AdtPlugin.log(e, "Can't read preview image %1$s", path); } } } if (image == null) { RenderService renderService = RenderService.create(mEditor); renderService.setSize(WIDTH, HEIGHT); image = renderService.renderDrawable(drawable); } } } } catch (Throwable t) { // Some kind of rendering error occurred. However, we don't want to use // AdtPlugin.log(t, "Can't generate preview for %1$s", resource); // because if it's a severe type of error (such as an InternalError shown // in issue #18623) then a dialog will pop up and interfere with the // preview, so just log a warning (unfortunately without the trace) instead. AdtPlugin.log(IStatus.WARNING, "Can't generate preview for %1$s", resource); } Display display = mEditor.getSite().getShell().getDisplay(); if (image != null) { mPreviewImageControl.setImage(SwtUtils.convertToSwt(display, image, true, -1)); } else { mPreviewImageControl.setImage(SwtUtils.createEmptyImage(display, WIDTH, HEIGHT)); } mPreviewImageControl.redraw(); } else if (mPreviewTray != null && mShowingPreview) { mTrayDialog.closeTray(); } mShowingPreview = showPreview; }
From source file:org.csstudio.apputil.ui.dialog.ErrorDetailDialog.java
License:Open Source License
/** Open tray to display detail */ protected void showDetail() { final DialogTray tray = new DialogTray() { @Override//from ww w . j a v a 2 s . c om protected Control createContents(final Composite parent) { final Composite container = new Composite(parent, SWT.NONE); container.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); container.setLayout(new GridLayout()); final Text info = new Text(container, SWT.READ_ONLY | SWT.MULTI | SWT.WRAP); info.setText(detail); // Use width hint to limit growth of dialog for long texts. // User can then manually resize as desired. final GridData data = new GridData(SWT.FILL, SWT.FILL, true, false); data.widthHint = 500; info.setLayoutData(data); return container; } }; openTray(tray); }
From source file:org.eclipse.andmore.internal.ui.ResourcePreviewHelper.java
License:Open Source License
/** * Updates the preview based on the current selection and resource type, possibly * hiding or opening the tray in the process. * * @param type the resource type for the selected resource * @param resource the full resource url *//*from ww w. j a v a 2s . c om*/ public void updatePreview(ResourceType type, String resource) { boolean showPreview = type == ResourceType.DRAWABLE || type == ResourceType.COLOR; if (showPreview) { if (mPreviewTray == null) { mPreviewTray = new DialogTray() { @Override protected Control createContents(Composite parent) { // This creates a centered image control Composite panel = new Composite(parent, SWT.NONE); panel.setLayout(new GridLayout(3, false)); Label dummy1 = new Label(panel, SWT.NONE); dummy1.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, true, 1, 1)); mPreviewImageControl = new ImageControl(panel, SWT.NONE, SwtUtils.createEmptyImage(parent.getDisplay(), WIDTH, HEIGHT)); GridData gd = new GridData(SWT.CENTER, SWT.CENTER, false, false, 1, 1); gd.widthHint = WIDTH; gd.heightHint = HEIGHT; mPreviewImageControl.setLayoutData(gd); Label dummy2 = new Label(panel, SWT.NONE); dummy2.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, true, 1, 1)); return panel; } }; } if (!mShowingPreview) { mTrayDialog.openTray(mPreviewTray); } BufferedImage image = null; try { if (type == ResourceType.COLOR) { ResourceResolver resources = mEditor.getResourceResolver(); ResourceValue value = resources.findResValue(resource, false); if (value != null) { RGB color = ResourceHelper.resolveColor(resources, value); if (color != null) { image = ImageUtils.createColoredImage(WIDTH, HEIGHT, color); } } } else { assert type == ResourceType.DRAWABLE; ResourceResolver resources = mEditor.getResourceResolver(); ResourceValue drawable = resources.findResValue(resource, false); if (drawable != null) { String path = drawable.getValue(); // Special-case image files (other than 9-patch files) and render these // directly, in order to provide proper aspect ratio handling and // to handle scaling to show the full contents: if (ImageUtils.hasImageExtension(path) && !endsWithIgnoreCase(path, DOT_9PNG)) { File file = new File(path); if (file.exists()) { try { image = ImageIO.read(file); int width = image.getWidth(); int height = image.getHeight(); if (width > WIDTH || height > HEIGHT) { double xScale = WIDTH / (double) width; double yScale = HEIGHT / (double) height; double scale = Math.min(xScale, yScale); image = ImageUtils.scale(image, scale, scale); } } catch (IOException e) { AndmoreAndroidPlugin.log(e, "Can't read preview image %1$s", path); } } } if (image == null) { RenderService renderService = RenderService.create(mEditor); renderService.setOverrideRenderSize(WIDTH, HEIGHT); image = renderService.renderDrawable(drawable); } } } } catch (Throwable t) { // Some kind of rendering error occurred. However, we don't want to use // AdtPlugin.log(t, "Can't generate preview for %1$s", resource); // because if it's a severe type of error (such as an InternalError shown // in issue #18623) then a dialog will pop up and interfere with the // preview, so just log a warning (unfortunately without the trace) instead. AndmoreAndroidPlugin.log(IStatus.WARNING, "Can't generate preview for %1$s", resource); } Display display = mEditor.getSite().getShell().getDisplay(); if (image != null) { mPreviewImageControl.setImage(SwtUtils.convertToSwt(display, image, true, -1)); } else { mPreviewImageControl.setImage(SwtUtils.createEmptyImage(display, WIDTH, HEIGHT)); } mPreviewImageControl.redraw(); } else if (mPreviewTray != null && mShowingPreview) { mTrayDialog.closeTray(); } mShowingPreview = showPreview; }
From source file:org.eclipse.oomph.ui.HelpSupport.java
License:Open Source License
public final void hook(final ToolItem helpButton) { helpAnimator = new HelpAnimator(helpButton); Shell shell = dialog.getShell();// w ww. ja va2 s .c o m shell.addHelpListener(new HelpListener() { public void helpRequested(HelpEvent e) { if (UIUtil.isBrowserAvailable()) { if (dialog.getTray() != null) { dialog.closeTray(); helpButton.setSelection(false); return; } DialogTray tray = new DialogTray() { @Override protected Control createContents(Composite parent) { helpBrowser = new Browser(parent, SWT.NONE); helpBrowser.setSize(500, 800); helpBrowser.addDisposeListener(new DisposeListener() { public void widgetDisposed(DisposeEvent e) { helpBrowser = null; redrawCalloutControls(); } }); updateHelp(); return helpBrowser; } }; dialog.openTray(tray); helpButton.setSelection(true); } else { helpButton.setSelection(false); String helpPath = getHelpPath(); if (helpPath != null) { OS.INSTANCE.openSystemBrowser(getHelpURL(helpPath)); } } } }); detectInactivity(shell); }
From source file:org.eclipse.scada.core.ui.connection.login.dialog.LoginDialog.java
License:Open Source License
protected void toggleAdvanced(final boolean selection) { if (selection) { openTray(new DialogTray() { @Override/*from ww w .ja v a2s . com*/ protected Control createContents(final Composite parent) { return createAdvancedContent(parent); } }); } else { closeTray(); } }