public static FormImages getInstance() { if (instance == null) instance = new FormImages(); return instance; }
@Override public void handleEvent(Event e) { Image image = Section.super.getBackgroundImage(); if (image != null) { FormImages.getInstance().markFinished(image, getDisplay()); } Section.super.setBackgroundImage(null); } };
private void updateGradientImage() { Rectangle rect = getBounds(); if (gradientImage != null) { FormImages.getInstance().markFinished(gradientImage, getDisplay()); gradientImage = null; } if (gradientInfo != null) { gradientImage = FormImages.getInstance().getGradient(gradientInfo.gradientColors, gradientInfo.percents, gradientInfo.vertical ? rect.height : rect.width, gradientInfo.vertical, getColor(COLOR_BASE_BG), getDisplay()); } else if (backgroundImage != null && !isBackgroundImageTiled()) { gradientImage = new Image(getDisplay(), Math.max(rect.width, 1), Math.max(rect.height, 1)); gradientImage.setBackground(getBackground()); GC gc = new GC(gradientImage); gc.drawImage(backgroundImage, 0, 0); gc.dispose(); } setBackgroundImage(gradientImage); }
private void updateHeaderImage(Color bg, Rectangle bounds, int theight, int realtheight) { Color gradient = getTitleBarGradientBackground() != null ? getTitleBarGradientBackground() : getBackground(); Image image = FormImages.getInstance().getSectionGradientImage(gradient, bg, realtheight, theight, marginHeight, getDisplay()); super.setBackgroundImage(image); }
public synchronized boolean markFinished(Image image, Display display) { checkHashMaps(); Integer imageHashCode = Integer.valueOf(image.hashCode()); AbstractImageDescriptor desc = descriptors.get(imageHashCode); if (desc != null) { LocalResourceManager resourceManager = manager.getResourceManager(display); resourceManager.destroyImage(desc); if (resourceManager.find(desc) == null) { descriptors.remove(imageHashCode); validateHashMaps(); } return true; } // if the image was not found, dispose of it for the caller image.dispose(); validateHashMaps(); return false; }
public Image getSectionGradientImage(Color color1, Color color2, int realtheight, int theight, int marginHeight, Display display) { if (color1 == null || color1.isDisposed()) return null; AbstractImageDescriptor desc = new SimpleSectionGradientImageDescriptor(color1, color2, realtheight, theight, marginHeight); return getGradient(desc, display); }
private synchronized Image getGradient(AbstractImageDescriptor desc, Display display) { checkHashMaps(); Image result = manager.getResourceManager(display).createImage(desc); descriptors.put(Integer.valueOf(result.hashCode()), desc); return result; }
private void updateGradientImage() { Rectangle rect = getBounds(); Image oldGradientImage = gradientImage; gradientImage = null; if (gradientInfo != null) { gradientImage = FormImages.getInstance().getGradient(gradientInfo.gradientColors, gradientInfo.percents, gradientInfo.vertical ? rect.height : rect.width, gradientInfo.vertical, getColor(COLOR_BASE_BG), getDisplay()); } else if (backgroundImage != null && !isBackgroundImageTiled()) { gradientImage = new Image(getDisplay(), Math.max(rect.width, 1), Math.max(rect.height, 1)); gradientImage.setBackground(getBackground()); GC gc = new GC(gradientImage); gc.drawImage(backgroundImage, 0, 0); gc.dispose(); } if (oldGradientImage != null) { FormImages.getInstance().markFinished(oldGradientImage, getDisplay()); } setBackgroundImage(gradientImage); }
private void updateHeaderImage(Color bg, Rectangle bounds, int theight, int realtheight) { Color gradient = getTitleBarGradientBackground() != null ? getTitleBarGradientBackground() : getBackground(); Image image = FormImages.getInstance().getSectionGradientImage(gradient, bg, realtheight, theight, marginHeight, getDisplay()); super.setBackgroundImage(image); }
public synchronized boolean markFinished(Image image, Display display) { checkHashMaps(); Integer imageHashCode = Integer.valueOf(image.hashCode()); AbstractImageDescriptor desc = descriptors.get(imageHashCode); if (desc != null) { LocalResourceManager resourceManager = manager.getResourceManager(display); resourceManager.destroyImage(desc); if (resourceManager.find(desc) == null) { descriptors.remove(imageHashCode); validateHashMaps(); } return true; } // if the image was not found, dispose of it for the caller image.dispose(); validateHashMaps(); return false; }
public Image getSectionGradientImage(Color color1, Color color2, int realtheight, int theight, int marginHeight, Display display) { if (color1 == null || color1.isDisposed()) return null; AbstractImageDescriptor desc = new SimpleSectionGradientImageDescriptor(color1, color2, realtheight, theight, marginHeight); return getGradient(desc, display); }
private synchronized Image getGradient(AbstractImageDescriptor desc, Display display) { checkHashMaps(); Image result = manager.getResourceManager(display).createImage(desc); descriptors.put(Integer.valueOf(result.hashCode()), desc); return result; }
@Override public void handleEvent(Event e) { if (gradientImage != null) { FormImages.getInstance().markFinished(gradientImage, getDisplay()); gradientImage = null; } } });
public Image getGradient(Color color1, Color color2, int realtheight, int theight, int marginHeight, Display display) { if (color1 == null || color1.isDisposed() || color2 == null || color2.isDisposed()) return null; AbstractImageDescriptor desc = new SimpleImageDescriptor(color1, color2, realtheight, theight, marginHeight); return getGradient(desc, display); }
public static FormImages getInstance() { if (instance == null) instance = new FormImages(); return instance; }
Section(Composite parent, int cstyle, int style) { super(parent, cstyle | getBackgroundStyle(style), style); int rtl = cstyle & SWT.RIGHT_TO_LEFT; if ((style & DESCRIPTION) != 0) { descriptionControl = new Label(this, SWT.WRAP | rtl); } if ((style & TITLE_BAR) != 0) { Listener listener = e -> { Image image = Section.super.getBackgroundImage(); if (image != null) { FormImages.getInstance().markFinished(image, getDisplay()); } Section.super.setBackgroundImage(null); }; addListener(SWT.Dispose, listener); addListener(SWT.Resize, listener); } }
public Image getGradient(Color color1, Color color2, int realtheight, int theight, int marginHeight, Display display) { if (color1 == null || color1.isDisposed() || color2 == null || color2.isDisposed()) return null; AbstractImageDescriptor desc = new SimpleImageDescriptor(color1, color2, realtheight, theight, marginHeight); return getGradient(desc, display); }
public void setTextBackground(Color[] gradientColors, int[] percents, boolean vertical) { if (gradientColors != null) { gradientInfo = new GradientInfo(); gradientInfo.gradientColors = gradientColors; gradientInfo.percents = percents; gradientInfo.vertical = vertical; setBackground(null); updateGradientImage(); } else { // reset gradientInfo = null; if (gradientImage != null) { FormImages.getInstance().markFinished(gradientImage, getDisplay()); gradientImage = null; setBackgroundImage(null); } } }
public Image getGradient(Color[] colors, int[] percents, int length, boolean vertical, Color bg, Display display) { if (colors.length == 0) return null; for (Color color : colors) if (color == null || color.isDisposed()) return null; if (bg != null && bg.isDisposed()) return null; AbstractImageDescriptor desc = new ComplexImageDescriptor(colors, length, percents, vertical, bg); return getGradient(desc, display); }
public void setTextBackground(Color[] gradientColors, int[] percents, boolean vertical) { if (gradientColors != null) { gradientInfo = new GradientInfo(); gradientInfo.gradientColors = gradientColors; gradientInfo.percents = percents; gradientInfo.vertical = vertical; setBackground(null); updateGradientImage(); } else { // reset gradientInfo = null; if (gradientImage != null) { FormImages.getInstance().markFinished(gradientImage, getDisplay()); gradientImage = null; setBackgroundImage(null); } } }