List of usage examples for org.eclipse.jface.resource JFaceResources getImage
public static Image getImage(String key)
null
if none. From source file:at.bestsolution.efxclipse.tooling.ui.preview.LivePreviewPart.java
License:Open Source License
@Override public void createPartControl(final Composite parent) { final Composite container = new Composite(parent, SWT.NONE); container.setLayout(new GridLayout(3, false)); folder = new CTabFolder(container, SWT.BOTTOM | SWT.BORDER); folder.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, true, 3, 1)); parent.getDisplay().asyncExec(new Runnable() { @Override/* ww w . j a v a2 s . com*/ public void run() { { CTabItem item = new CTabItem(folder, SWT.NONE); item.setText("Preview"); item.setImage(JFaceResources.getImage(IMAGE_PREVIEW)); swtFXContainer = new FXCanvas(folder, SWT.NONE); swtFXContainer.setEnabled(false); item.setControl(swtFXContainer); rootPane_new = new BorderPane(); Scene scene = new Scene((Parent) rootPane_new, 1000, 1000); currentScene = scene; swtFXContainer.setScene(scene); } { logItem = new CTabItem(folder, SWT.NONE); logItem.setText("Error log"); logItem.setImage(JFaceResources.getImage(IMAGE_OK)); logStatement = new Text(folder, SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL); logStatement.setEditable(false); logItem.setControl(logStatement); Menu m = new Menu(logStatement); logStatement.setMenu(m); MenuItem clearItem = new MenuItem(m, SWT.PUSH); clearItem.setText("Clear Log"); clearItem.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { logStatement.setText(""); } }); } { CTabItem fxmlContent = new CTabItem(folder, SWT.NONE); fxmlContent.setText("FXML-Source"); fxmlContent.setImage(JFaceResources.getImage(IMAGE_FXML_CONTENT)); final AnnotationModel model = new AnnotationModel(); VerticalRuler verticalRuler = new VerticalRuler(VERTICAL_RULER_WIDTH, new AnnotationAccess()); int styles = SWT.V_SCROLL | SWT.H_SCROLL | SWT.MULTI | SWT.BORDER | SWT.FULL_SELECTION; SourceViewer sourceViewer = new SourceViewer(folder, verticalRuler, styles); sourceViewer.configure(new XMLConfiguration(new ColorManager())); sourceViewer.setEditable(false); sourceViewer.getTextWidget().setFont(JFaceResources.getTextFont()); document = new Document(); IDocumentPartitioner partitioner = new FastPartitioner(new XMLPartitionScanner(), new String[] { XMLPartitionScanner.XML_TAG, XMLPartitionScanner.XML_COMMENT }); partitioner.connect(document); document.setDocumentPartitioner(partitioner); sourceViewer.setDocument(document); verticalRuler.setModel(model); fxmlContent.setControl(sourceViewer.getControl()); } folder.setSelection(0); statusLabelIcon = new Label(container, SWT.NONE); statusLabelIcon.setImage(JFaceResources.getImage(IMAGE_STATUS_NOPREVIEW)); statusLabelText = new Label(container, SWT.NONE); statusLabelText.setText(NO_PREVIEW_TEXT); statusLabelText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); Composite scaleControl = new Composite(container, SWT.NONE); scaleControl.setLayoutData(new GridData(GridData.END, GridData.CENTER, false, false)); scaleControl.setLayout(new GridLayout(2, false)); Label l = new Label(scaleControl, SWT.NONE); l.setText("Zoom"); scale = new Spinner(scaleControl, SWT.BORDER); scale.setMinimum(10); scale.setMaximum(500); scale.setIncrement(10); scale.setSelection(100); scale.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { rootPane_new.setScaleX(scale.getSelection() / 100.0); rootPane_new.setScaleY(scale.getSelection() / 100.0); if (currentFile != null) { scaleMap.put(currentFile, scale.getSelection()); } } }); parent.layout(true, true); if (currentData != null) { refreshContent(currentData); } } }); parent.layout(true, true); Action loadController = new Action("", IAction.AS_CHECK_BOX) { @Override public void run() { preference.putBoolean(PREF_LOAD_CONTROLLER, !preference.getBoolean(PREF_LOAD_CONTROLLER, false)); try { preference.flush(); synchronizer.refreshPreview(); } catch (BackingStoreException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }; loadController.setChecked(preference.getBoolean(PREF_LOAD_CONTROLLER, false)); loadController.setImageDescriptor(JFaceResources.getImageRegistry().getDescriptor(IMAGE_LOAD_CONTROLLER)); loadController.setToolTipText("Load the controller"); Action refresh = new Action("", JFaceResources.getImageRegistry().getDescriptor(IMAGE_REFRESH)) { @Override public void run() { synchronizer.refreshPreview(); } }; refresh.setToolTipText("Force a refresh"); getViewSite().getActionBars().getToolBarManager().add(refresh); getViewSite().getActionBars().getToolBarManager().add(loadController); }
From source file:at.bestsolution.efxclipse.tooling.ui.preview.LivePreviewPart.java
License:Open Source License
private void saveRefreshContent(final ContentData contentData) { folder.setVisible(true);//from w w w. ja v a 2 s. c o m ClassLoader cl = null; FXMLLoader loader; if (contentData.extraJarPath != null && !contentData.extraJarPath.isEmpty() && swtFXContainer != null) { final URLClassLoader previewClassLoader = new PreviewURLClassloader( contentData.extraJarPath.toArray(new URL[0]), swtFXContainer.getClass().getClassLoader()); cl = Thread.currentThread().getContextClassLoader(); Thread.currentThread().setContextClassLoader(previewClassLoader); loader = new FXMLLoader(); loader.setBuilderFactory(new BuilderFactory() { private BuilderFactory f = new JavaFXBuilderFactory(previewClassLoader); @Override public Builder<?> getBuilder(Class<?> type) { return f.getBuilder(type); } }); loader.setClassLoader(previewClassLoader); } else { loader = new FXMLLoader(); } String exception = null; try { currentFile = contentData.file; loader.setStaticLoad(!preference.getBoolean(PREF_LOAD_CONTROLLER, false)); try { // TODO Should we set this to the bin-Folder?? loader.setLocation( contentData.file.getParent().getLocation().toFile().getAbsoluteFile().toURI().toURL()); } catch (MalformedURLException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } if (contentData.resourceBundle != null) { FileInputStream in = null; try { in = new FileInputStream(new File(contentData.resourceBundle)); Properties p = new Properties(); p.load(in); final Object[][] entries = new Object[p.entrySet().size()][]; int i = 0; for (Entry<Object, Object> e : p.entrySet()) { entries[i++] = new Object[] { e.getKey(), e.getValue() }; } ListResourceBundle b = new ListResourceBundle() { @Override protected Object[][] getContents() { return entries; } }; loader.setResources(b); } catch (Exception e) { e.printStackTrace(); } finally { if (in != null) { try { in.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } } try { document.set(contentData.contents); ByteArrayInputStream out = new ByteArrayInputStream(contentData.contents.getBytes()); Object root = loader.load(out); out.close(); Scene scene = null; if (root instanceof Scene) { scene = (Scene) root; rootPane_new = scene.getRoot(); } else { if (contentData.previewSceneSetup != null) { ByteArrayInputStream sceneOut = new ByteArrayInputStream( contentData.previewSceneSetup.getBytes()); Object sceneRoot = loader.load(sceneOut); if (sceneRoot instanceof Scene) { scene = (Scene) sceneRoot; } } rootPane_new = (Node) root; if (scene == null) { BorderPane p = new BorderPane(); p.setCenter(rootPane_new); scene = new Scene(p, 10000, 10000, Platform.isSupported(ConditionalFeature.SCENE3D)); if (Platform.isSupported(ConditionalFeature.SCENE3D)) { scene.setCamera(new PerspectiveCamera()); } } else { Node n = scene.getRoot().lookup("#previewcontainer"); if (n == null || !(n instanceof Parent)) { n = scene.getRoot(); } String previewFeature = null; if (n.getUserData() != null && n.getUserData() != null) { previewFeature = n.getUserData().toString().trim(); } if (previewFeature != null) { try { String mName = "set" + Character.toUpperCase(previewFeature.charAt(0)) + previewFeature.substring(1); Method m = n.getClass().getMethod(mName, Node.class); m.invoke(n, rootPane_new); } catch (Throwable t) { String mName = "get" + Character.toUpperCase(previewFeature.charAt(0)) + previewFeature.substring(1); Method m = n.getClass().getMethod(mName); Object o = m.invoke(n); if (o instanceof List) { ((List<Object>) o).add(rootPane_new); } } } else { if (n instanceof BorderPane) { ((BorderPane) n).setCenter(rootPane_new); } else if (n instanceof Pane) { ((Pane) n).getChildren().add(rootPane_new); } else { throw new IllegalStateException( "The parent in the scene is not a Pane. Set a preview-property styleclass on the control"); } } } } if (rootPane_new != null) { if (scaleMap.containsKey(currentFile)) { int value = scaleMap.get(currentFile).intValue(); scale.setSelection(value); rootPane_new.setScaleX(value / 100.0); rootPane_new.setScaleY(value / 100.0); } else { scale.setSelection(100); rootPane_new.setScaleX(1); rootPane_new.setScaleY(1); } } // Force CSS-Reloading if (isJavaFX2()) { ReflectiveInvoke.onStyleManagerClass(scene); } // In FX8 we need to remove the stylesheets on the old scene to force reloading them if (swtFXContainer.getScene() != null) { swtFXContainer.getScene().getStylesheets().clear(); } scene.getStylesheets().addAll(contentData.cssFiles); currentScene = scene; swtFXContainer.setScene(scene); } catch (Exception e) { StringWriter sw = new StringWriter(); e.printStackTrace(new PrintWriter(sw)); exception = sw.toString(); } } finally { if (cl != null) { Thread.currentThread().setContextClassLoader(cl); } } if (exception != null) { final String innerException = exception; if (folder.isDisposed()) { return; } folder.getDisplay().asyncExec(new Runnable() { @Override public void run() { if (innerException != null) { logItem.setImage(JFaceResources.getImage(IMAGE_ERROR)); statusLabelIcon.setImage(JFaceResources.getImage(IMAGE_STATUS_ERROR)); statusLabelText.setText(SimpleDateFormat.getTimeInstance().format(new Date()) + ": Error while updating preview"); setTitleImage(JFaceResources.getImage(IMAGE_TAB_ERROR)); folder.setSelection(logItem); } logStatement.setText(""); logStatement.append("=================================================================" + logStatement.getLineDelimiter()); logStatement.append("Preview loading @ " + new Date() + logStatement.getLineDelimiter()); logStatement.append("=================================================================" + logStatement.getLineDelimiter()); if (innerException != null) { logStatement.append("Exception:" + logStatement.getLineDelimiter()); logStatement.append("----------" + logStatement.getLineDelimiter()); logStatement.append(innerException + logStatement.getLineDelimiter()); logStatement.append(logStatement.getLineDelimiter() + logStatement.getLineDelimiter()); logStatement.setSelection(0); } } }); } else { folder.getDisplay().asyncExec(new Runnable() { @Override public void run() { folder.setSelection(0); logItem.setImage(JFaceResources.getImage(IMAGE_OK)); statusLabelIcon.setImage(JFaceResources.getImage(IMAGE_STATUS_OK)); statusLabelText .setText(SimpleDateFormat.getTimeInstance().format(new Date()) + ": Preview updated"); setTitleImage(JFaceResources.getImage(IMAGE_TAB_NORMAL)); } }); } }
From source file:at.bestsolution.efxclipse.tooling.ui.preview.LivePreviewPart.java
License:Open Source License
public void setContents(final ContentData contentData) { if (folder.isDisposed()) { return;/*from www. j av a2s . co m*/ } if (contentData != null && contentData.contents != null) { refreshContent(contentData); } else if (rootPane_new != null) { folder.getDisplay().syncExec(new Runnable() { @Override public void run() { statusLabelIcon.setImage(JFaceResources.getImage(IMAGE_STATUS_NOPREVIEW)); statusLabelText.setText(NO_PREVIEW_TEXT); folder.setVisible(false); } }); } }
From source file:at.bestsolution.efxclipse.tooling.ui.util.IconKeys.java
License:Open Source License
public static Image getIcon(String id) { return JFaceResources.getImage(id); }
From source file:bndtools.utils.MessagesPopupDialog.java
License:Open Source License
static Image getMessageImage(int messageType) { switch (messageType) { case IMessageProvider.INFORMATION: return JFaceResources.getImage(Dialog.DLG_IMG_MESSAGE_INFO); case IMessageProvider.WARNING: return JFaceResources.getImage(Dialog.DLG_IMG_MESSAGE_WARNING); case IMessageProvider.ERROR: return JFaceResources.getImage(Dialog.DLG_IMG_MESSAGE_ERROR); default://w ww . ja va 2 s . c om return null; } }
From source file:com.aptana.ide.core.ui.SWTUtils.java
License:Open Source License
/** * Finds and caches the image from the image descriptor for this particular bundle * /*from w w w . ja va2s . co m*/ * @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); } else { return null; } }
From source file:com.aptana.ui.util.SWTUtils.java
License:Open Source License
/** * Finds and caches the image from the image descriptor for this particular bundle. * // w w w . j a v a 2s . co m * @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; }
From source file:com.architexa.org.eclipse.gef.ui.palette.customize.PaletteCustomizerDialog.java
License:Open Source License
/** * Creates the title for the properties panel. It is a PageBook that can switch between * showing the regular title (the selected entry's label and icon) and an error message if * an error has occured.// ww w .j ava 2 s. c o m * * @param parent The parent composite * @return The newly created PageBook title */ protected PageBook createPropertiesPanelTitle(Composite parent) { GridLayout layout; PageBook book = new PageBook(parent, SWT.NONE); book.setFont(parent.getFont()); book.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_FILL)); titlePage = new Composite(book, SWT.NONE); titlePage.setFont(book.getFont()); layout = new GridLayout(2, false); layout.horizontalSpacing = 0; layout.marginWidth = 0; layout.marginHeight = 0; layout.verticalSpacing = 0; titlePage.setLayout(layout); title = createSectionTitle(titlePage, PaletteMessages.NO_SELECTION_TITLE); errorPage = new Composite(book, SWT.NONE); errorPage.setFont(book.getFont()); layout = new GridLayout(1, false); layout.horizontalSpacing = 0; layout.marginWidth = 0; layout.marginHeight = 0; layout.verticalSpacing = 0; errorPage.setLayout(layout); Composite intermediary = new Composite(errorPage, SWT.NONE) { public Point computeSize(int wHint, int hHint, boolean changed) { Rectangle bounds = title.getBounds(); return new Point(bounds.width, bounds.height); } }; intermediary.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_FILL)); StackLayout stackLayout = new StackLayout(); intermediary.setLayout(stackLayout); errorTitle = new MultiLineLabel(intermediary); stackLayout.topControl = errorTitle; errorTitle.setImage(JFaceResources.getImage(DLG_IMG_MESSAGE_ERROR)); errorTitle.setFont(errorPage.getFont()); Label separator = new Label(errorPage, SWT.SEPARATOR | SWT.HORIZONTAL); separator.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); book.showPage(titlePage); return book; }
From source file:com.bdaum.zoom.ui.preferences.AbstractPreferencePage.java
License:Open Source License
/** * Creates the help control button or link * * @param parent//ww w . j ava2s . c o m * - parent composite * @return - help button or link */ protected static Control createHelpControl(Composite parent) { Image helpImage = JFaceResources.getImage(Dialog.DLG_IMG_HELP); return (helpImage != null) ? createHelpImageButton(parent, helpImage) : createHelpLink(parent); }
From source file:com.google.dart.tools.debug.ui.internal.chrome.DartChromeMainTab.java
License:Open Source License
private void validateBrowsers() { if (DartDebugCorePlugin.getPlugin().getConfiguredBrowsers().size() == 0) { browserWarningLabel.setImage(JFaceResources.getImage(Dialog.DLG_IMG_MESSAGE_WARNING)); browserWarningLabel.setText("No Chrome browsers are configured."); } else {/*ww w . ja v a 2s .c o m*/ browserWarningLabel.setImage(null); browserWarningLabel.setText(""); } }