Skip to content

Commit

Permalink
Watermarks and demo crash fix
Browse files Browse the repository at this point in the history
* Expose high-DPI aware image rendering in NeonCortex
* High-DPI aware watermarks - #27
* Add Crosshatch watermark to extras - #26
* Fix demo crash - #25
  • Loading branch information
kirill-grouchnikov committed Jun 22, 2018
1 parent 6833b3d commit 9df1767
Show file tree
Hide file tree
Showing 87 changed files with 2,719 additions and 3,469 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.pushingpixels.neon.AsynchronousLoading;
import org.pushingpixels.neon.NeonCortex;
import org.pushingpixels.neon.icon.ResizableIcon;
import org.pushingpixels.neon.internal.contrib.intellij.UIUtil;
import org.pushingpixels.substance.internal.utils.SubstanceCoreUtilities;

import java.awt.*;
Expand Down Expand Up @@ -98,12 +99,6 @@ public void setDimension(Dimension newDimension) {
delegate.setDimension(newDimension);
}

/*
* (non-Javadoc)
*
* @see javax.swing.Icon#paintIcon(java.awt.Component, java.awt.Graphics,
* int, int)
*/
@Override
public void paintIcon(Component c, Graphics g, int x, int y) {
// check cache
Expand All @@ -116,20 +111,22 @@ public void paintIcon(Component c, Graphics g, int x, int y) {
if (asyncDelegate.isLoading())
return;
}
BufferedImage offscreen = SubstanceCoreUtilities.getBlankImage(this.getIconWidth(),
BufferedImage offscreen = NeonCortex.getBlankImage(this.getIconWidth(),
this.getIconHeight());
Graphics2D g2d = offscreen.createGraphics();
this.delegate.paintIcon(c, g2d, 0, 0);
g2d.dispose();
BufferedImage filtered = this.operation.filter(offscreen, null);
this.cachedImages.put(key, filtered);
}
double scaleFactor = NeonCortex.getScaleFactor();
BufferedImage toDraw = this.cachedImages.get(key);
Graphics2D g2d = (Graphics2D) g.create();
g2d.translate(x, y);
g2d.drawImage(toDraw, 0, 0, (int) (toDraw.getWidth(null) / scaleFactor),
(int) (toDraw.getHeight(null) / scaleFactor), null);
// Note that here we shouldn't use NeonCortex.drawImage as the result of applying
// a filter is not going to be a high-DPI wrapper.
double scaleFactor = UIUtil.getScaleFactor();
g2d.drawImage(toDraw, 0, 0, (int) (toDraw.getWidth(null) / scaleFactor),
(int) (toDraw.getHeight(null) / scaleFactor), null);
g2d.dispose();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -311,10 +311,7 @@ private void paintButtonBackground(Graphics graphics, Rectangle toFill) {
Graphics2D g2d = (Graphics2D) graphics.create();
g2d.setComposite(
WidgetUtilities.getAlphaComposite(this.commandButton, extraAlpha, graphics));
double factor = NeonCortex.getScaleFactor();
g2d.drawImage(fullAlphaBackground, 0, 0,
(int) (fullAlphaBackground.getWidth() / factor),
(int) (fullAlphaBackground.getHeight() / factor), null);
NeonCortex.drawImage(g2d, fullAlphaBackground, 0, 0);
g2d.dispose();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -394,9 +394,7 @@ private void paintButtonBackground(Graphics graphics, Rectangle toFill) {
Graphics2D g2d = (Graphics2D) graphics.create();
g2d.setComposite(
WidgetUtilities.getAlphaComposite(this.commandButton, extraAlpha, graphics));
double factor = NeonCortex.getScaleFactor();
g2d.drawImage(fullAlphaBackground, 0, 0, (int) (fullAlphaBackground.getWidth() / factor),
(int) (fullAlphaBackground.getHeight() / factor), null);
NeonCortex.drawImage(g2d, fullAlphaBackground, 0, 0);
g2d.dispose();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,8 @@ private static synchronized BufferedImage getTaskToggleButtonBackground(

BufferedImage result = SubstanceCoreUtilities.getBlankImage(width, height);
Graphics2D g2d = result.createGraphics();
double scaleFactor = NeonCortex.getScaleFactor();

g2d.drawImage(baseLayer, 0, 0, (int) (baseLayer.getWidth() / scaleFactor),
(int) (baseLayer.getHeight() / scaleFactor), null);
NeonCortex.drawImage(g2d, baseLayer, 0, 0);

for (Map.Entry<ComponentState, StateTransitionTracker.StateContributionInfo> activeEntry : activeStates
.entrySet()) {
Expand Down Expand Up @@ -165,8 +163,7 @@ private static synchronized BufferedImage getTaskToggleButtonBackground(
}

g2d.setComposite(AlphaComposite.SrcOver.derive(contribution));
g2d.drawImage(layer, 0, 0, (int) (layer.getWidth() / scaleFactor),
(int) (layer.getHeight() / scaleFactor), null);
NeonCortex.drawImage(g2d, layer, 0, 0);
}

g2d.dispose();
Expand Down Expand Up @@ -263,9 +260,7 @@ public void updateTaskToggleButtonBackground(Graphics g, JRibbonTaskToggleButton
}

g2d.setComposite(WidgetUtilities.getAlphaComposite(button, extraActionAlpha, g));
double scaleFactor = NeonCortex.getScaleFactor();
g2d.drawImage(ribbonBackground, 0, 0, (int) (ribbonBackground.getWidth() / scaleFactor),
(int) (ribbonBackground.getHeight() / scaleFactor), null);
NeonCortex.drawImage(g2d, ribbonBackground, 0, 0);

g2d.dispose();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,6 @@ public void paintIcon(Component c, Graphics g, int x, int y) {

graphics.translate(x, y);
graphics.clipRect(0, 0, this.currWidth, this.currHeight);
double scaleFactor = NeonCortex.getScaleFactor();
if (this.watermark != null) {
graphics.setColor(SubstanceCoreUtilities.getSkin(c)
.getEnabledColorScheme(ComponentOrParentChainScope.getDecorationType(c))
Expand All @@ -175,15 +174,13 @@ public void paintIcon(Component c, Graphics g, int x, int y) {

int waterSize = this.currHeight / 2;
BufferedImage watermarkSign = getWatermarkSign(waterSize);
graphics.drawImage(watermarkSign, this.currWidth - waterSize - 2,
this.currHeight - waterSize - 2, (int) (watermarkSign.getWidth() / scaleFactor),
(int) (watermarkSign.getHeight() / scaleFactor), null);
NeonCortex.drawImage(graphics, watermarkSign, this.currWidth - waterSize - 2,
this.currHeight - waterSize - 2);
} else {
int waterSize = Math.min(this.currHeight, this.currWidth) - 2;
BufferedImage watermarkSign = getWatermarkSign(waterSize);
graphics.drawImage(watermarkSign, (this.currWidth - waterSize) / 2,
(this.currHeight - waterSize) / 2, (int) (watermarkSign.getWidth() / scaleFactor),
(int) (watermarkSign.getHeight() / scaleFactor), null);
NeonCortex.drawImage(graphics, watermarkSign, (this.currWidth - waterSize) / 2,
(this.currHeight - waterSize) / 2);
}
graphics.setColor(Color.black);
graphics.draw(new Rectangle2D.Float(0, 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,7 @@ public void paint(Graphics g, JComponent c) {
BufferedImage fullAlphaBackground = RibbonApplicationMenuButtonBackgroundDelegate
.getFullAlphaBackground(b, fillPainter, borderPainter, commandButton.getWidth() - 2,
commandButton.getHeight() - 2);
double scaleFactor = NeonCortex.getScaleFactor();
g2d.drawImage(fullAlphaBackground, 0, 0, (int) (fullAlphaBackground.getWidth() / scaleFactor),
(int) (fullAlphaBackground.getHeight() / scaleFactor), null);
NeonCortex.drawImage(g2d, fullAlphaBackground, 0, 0);

// Paint the icon
ResizableIcon icon = b.getIcon();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,10 +182,8 @@ public static BufferedImage getFullAlphaBackground(AbstractCommandButton command

BufferedImage result = SubstanceCoreUtilities.getBlankImage(width, height);
Graphics2D g2d = result.createGraphics();
double factor = NeonCortex.getScaleFactor();

g2d.drawImage(baseLayer, 0, 0, (int) (baseLayer.getWidth() / factor),
(int) (baseLayer.getHeight() / factor), null);
NeonCortex.drawImage(g2d, baseLayer, 0, 0);

for (Map.Entry<ComponentState, StateTransitionTracker.StateContributionInfo> activeEntry : activeStates
.entrySet()) {
Expand Down Expand Up @@ -219,8 +217,7 @@ public static BufferedImage getFullAlphaBackground(AbstractCommandButton command
}

g2d.setComposite(AlphaComposite.SrcOver.derive(contribution));
g2d.drawImage(layer, 0, 0, (int) (layer.getWidth() / factor),
(int) (layer.getHeight() / factor), null);
NeonCortex.drawImage(g2d, layer, 0, 0);
}

g2d.dispose();
Expand Down Expand Up @@ -330,10 +327,7 @@ public static BufferedImage getCombinedCommandButtonBackground(
BufferedImage layers = SubstanceCoreUtilities.getBlankImage(fullAlphaBackground.getWidth(),
fullAlphaBackground.getHeight());
Graphics2D combinedGraphics = layers.createGraphics();
double scaleFactor = NeonCortex.getScaleFactor();
combinedGraphics.drawImage(fullAlphaBackground, 0, 0,
(int) (fullAlphaBackground.getWidth() / scaleFactor),
(int) (fullAlphaBackground.getHeight() / scaleFactor), null);
NeonCortex.drawImage(combinedGraphics, fullAlphaBackground, 0, 0);

ActionPopupTransitionAwareUI ui = (ActionPopupTransitionAwareUI) commandButton.getUI();

Expand All @@ -350,9 +344,7 @@ public static BufferedImage getCombinedCommandButtonBackground(
.getFullAlphaBackground(commandButton, backgroundModel, fillPainter,
borderPainter, commandButton.getWidth(), commandButton.getHeight(),
ui.getTransitionTracker(), false);
combinedGraphics.drawImage(rolloverBackground, 0, 0,
(int) (rolloverBackground.getWidth() / scaleFactor),
(int) (rolloverBackground.getHeight() / scaleFactor), null);
NeonCortex.drawImage(combinedGraphics, rolloverBackground, 0, 0);
}

// Shape currClip = combinedGraphics.getClip();
Expand All @@ -373,9 +365,7 @@ public static BufferedImage getCombinedCommandButtonBackground(
.getFullAlphaBackground(commandButton, null, fillPainter, borderPainter,
commandButton.getWidth(), commandButton.getHeight(),
ui.getActionTransitionTracker(), false);
graphicsAction.drawImage(actionAreaBackground, 0, 0,
(int) (actionAreaBackground.getWidth() / scaleFactor),
(int) (actionAreaBackground.getHeight() / scaleFactor), null);
NeonCortex.drawImage(graphicsAction, actionAreaBackground, 0, 0);
// graphicsAction.setColor(Color.red);
// graphicsAction.fill(toFill);
graphicsAction.dispose();
Expand All @@ -400,9 +390,7 @@ public static BufferedImage getCombinedCommandButtonBackground(
.getFullAlphaBackground(commandButton, null, fillPainter, borderPainter,
commandButton.getWidth(), commandButton.getHeight(),
ui.getPopupTransitionTracker(), false);
graphicsPopup.drawImage(popupAreaBackground, 0, 0,
(int) (popupAreaBackground.getWidth() / scaleFactor),
(int) (popupAreaBackground.getHeight() / scaleFactor), null);
NeonCortex.drawImage(graphicsPopup, popupAreaBackground, 0, 0);
// graphicsPopup.setColor(Color.blue);
// graphicsPopup.fill(toFill);
graphicsPopup.dispose();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,8 @@ public static BufferedImage getFullAlphaBackground(JRibbonApplicationMenuButton

BufferedImage result = SubstanceCoreUtilities.getBlankImage(width, height);
Graphics2D g2d = result.createGraphics();
double scaleFactor = NeonCortex.getScaleFactor();

g2d.drawImage(baseLayer, 0, 0, (int) (baseLayer.getWidth() / scaleFactor),
(int) (baseLayer.getHeight() / scaleFactor), null);
NeonCortex.drawImage(g2d, baseLayer, 0, 0);

for (Map.Entry<ComponentState, StateTransitionTracker.StateContributionInfo> activeEntry : activeStates
.entrySet()) {
Expand Down Expand Up @@ -158,8 +156,7 @@ public static BufferedImage getFullAlphaBackground(JRibbonApplicationMenuButton
}

g2d.setComposite(AlphaComposite.SrcOver.derive(contribution));
g2d.drawImage(layer, 0, 0, (int) (layer.getWidth() / scaleFactor),
(int) (layer.getHeight() / scaleFactor), null);
NeonCortex.drawImage(g2d, layer, 0, 0);
}

g2d.dispose();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,7 @@ public void paintIcon(Component c, Graphics g, int x, int y) {
this.cachedImages.put(key, filtered);
}
Graphics2D g2d = (Graphics2D) g.create();
double scaleFactor = NeonCortex.getScaleFactor();
g2d.drawImage(filtered, x, y, (int) (filtered.getWidth() / scaleFactor),
(int) (filtered.getHeight() / scaleFactor), null);
NeonCortex.drawImage(g2d, filtered, 0, 0);
g2d.dispose();
}
}
27 changes: 27 additions & 0 deletions neon/src/main/java/org/pushingpixels/neon/NeonCortex.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import javax.swing.*;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.awt.image.ImageObserver;
import java.awt.print.PrinterGraphics;
import java.security.AccessController;
import java.security.PrivilegedAction;
Expand Down Expand Up @@ -219,4 +220,30 @@ public static BufferedImage getBlankUnscaledImage(int width, int height) {
return c.createCompatibleImage(width, height, Transparency.TRANSLUCENT);
}
}

public static void drawImage(Graphics g, Image img, int x, int y) {
if (img instanceof JBHiDPIScaledImage) {
double scaleFactor = UIUtil.getScaleFactor();
g.drawImage(img, x, y, (int) (img.getWidth(null) / scaleFactor),
(int) (img.getHeight(null) / scaleFactor), null);
} else {
g.drawImage(img, x, y, img.getWidth(null), img.getHeight(null), null);
}
}

public static void drawImage(Graphics g, Image img, int x, int y,
int width, int height, int offsetX, int offsetY) {
if (img instanceof JBHiDPIScaledImage) {
double scaleFactor = UIUtil.getScaleFactor();
g.drawImage(img, x, y, x + width, y + height,
x + (int) (offsetX * scaleFactor), y + (int) (offsetY * scaleFactor),
x + (int) ((offsetX + width) * scaleFactor),
y + (int) ((offsetY + height) * scaleFactor), null);
} else {
g.drawImage(img, x, y, x + width, y + height,
x + offsetX, y + offsetY,
x + offsetX + width,
y + offsetY + height, null);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,21 +58,26 @@ public Rectangle2D getBounds2D(BufferedImage src) {
return new Rectangle(0, 0, src.getWidth(), src.getHeight());
}

public static BufferedImage createCompatibleDestImageForFilter(BufferedImage src,
ColorModel destCM) {
if (destCM == null) {
destCM = src.getColorModel();
}

WritableRaster raster = destCM.createCompatibleWritableRaster(
src.getWidth(), src.getHeight());
if (src instanceof IsHiDpiAware) {
return new JBHiDPIScaledImage(destCM, raster, destCM.isAlphaPremultiplied(), null,
src.getWidth(), src.getHeight());
} else {
return new BufferedImage(destCM, raster, destCM.isAlphaPremultiplied(), null);
}
}

@Override
public BufferedImage createCompatibleDestImage(BufferedImage src,
ColorModel destCM) {
if (destCM == null) {
destCM = src.getColorModel();
}

WritableRaster raster = destCM.createCompatibleWritableRaster(
src.getWidth(), src.getHeight());
if (src instanceof IsHiDpiAware) {
return new JBHiDPIScaledImage(destCM, raster, destCM.isAlphaPremultiplied(), null,
src.getWidth(), src.getHeight());
} else {
return new BufferedImage(destCM, raster, destCM.isAlphaPremultiplied(), null);
}
return createCompatibleDestImageForFilter(src, destCM);
}

@Override
Expand Down
26 changes: 26 additions & 0 deletions scripts/doc-robot-extras-watermarks.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
export JAVA_HOME=`/usr/libexec/java_home -v 9`
alias JAVA="java"

RADIANCE_VERSION=0.9-dev
CLASSPATH=../drop/$RADIANCE_VERSION/demo/radiance-substance-tools-$RADIANCE_VERSION.jar:../build/libs-demo/fest-swing-1.2.1.jar:../build/libs-demo/fest-reflect-1.2.jar:../build/libs-demo/fest-util-1.1.3.jar:../drop/$RADIANCE_VERSION/core/radiance-substance-$RADIANCE_VERSION.jar:../drop/$RADIANCE_VERSION/core/radiance-neon-$RADIANCE_VERSION.jar:../drop/$RADIANCE_VERSION/core/radiance-trident-$RADIANCE_VERSION.jar:../drop/$RADIANCE_VERSION/demo/radiance-substance-demo-$RADIANCE_VERSION.jar:../drop/$RADIANCE_VERSION/core/radiance-substance-extras-$RADIANCE_VERSION.jar:../build/libs-demo/jgoodies-forms-1.9.0.jar:../build/libs-demo/jgoodies-common-1.8.1.jar

JAVA -cp $CLASSPATH org.pushingpixels.tools.substance.main.docrobot.RobotMain org.pushingpixels.tools.substance.extras.docrobot.watermarks.BinaryWatermark
JAVA -cp $CLASSPATH org.pushingpixels.tools.substance.main.docrobot.RobotMain org.pushingpixels.tools.substance.extras.docrobot.watermarks.BrushedMetalWatermark
JAVA -cp $CLASSPATH org.pushingpixels.tools.substance.main.docrobot.RobotMain org.pushingpixels.tools.substance.extras.docrobot.watermarks.BubblesWatermark
JAVA -cp $CLASSPATH org.pushingpixels.tools.substance.main.docrobot.RobotMain org.pushingpixels.tools.substance.extras.docrobot.watermarks.CrosshatchWatermark
JAVA -cp $CLASSPATH org.pushingpixels.tools.substance.main.docrobot.RobotMain org.pushingpixels.tools.substance.extras.docrobot.watermarks.ExceedWatermark
JAVA -cp $CLASSPATH org.pushingpixels.tools.substance.main.docrobot.RobotMain org.pushingpixels.tools.substance.extras.docrobot.watermarks.FlameFractalKaleidoscopeWatermark
JAVA -cp $CLASSPATH org.pushingpixels.tools.substance.main.docrobot.RobotMain org.pushingpixels.tools.substance.extras.docrobot.watermarks.FlameFractalScripturesWatermark
JAVA -cp $CLASSPATH org.pushingpixels.tools.substance.main.docrobot.RobotMain org.pushingpixels.tools.substance.extras.docrobot.watermarks.FlameFractalSingularityWatermark
JAVA -cp $CLASSPATH org.pushingpixels.tools.substance.main.docrobot.RobotMain org.pushingpixels.tools.substance.extras.docrobot.watermarks.FlameFractalVortexWatermark
JAVA -cp $CLASSPATH org.pushingpixels.tools.substance.main.docrobot.RobotMain org.pushingpixels.tools.substance.extras.docrobot.watermarks.KatakanaWatermark
JAVA -cp $CLASSPATH org.pushingpixels.tools.substance.main.docrobot.RobotMain org.pushingpixels.tools.substance.extras.docrobot.watermarks.LatchWatermark
JAVA -cp $CLASSPATH org.pushingpixels.tools.substance.main.docrobot.RobotMain org.pushingpixels.tools.substance.extras.docrobot.watermarks.MetalWallWatermark
JAVA -cp $CLASSPATH org.pushingpixels.tools.substance.main.docrobot.RobotMain org.pushingpixels.tools.substance.extras.docrobot.watermarks.MosaicWatermark
JAVA -cp $CLASSPATH org.pushingpixels.tools.substance.main.docrobot.RobotMain org.pushingpixels.tools.substance.extras.docrobot.watermarks.NoiseCopperplateEngravingWatermark
JAVA -cp $CLASSPATH org.pushingpixels.tools.substance.main.docrobot.RobotMain org.pushingpixels.tools.substance.extras.docrobot.watermarks.NoiseFabricWatermark
JAVA -cp $CLASSPATH org.pushingpixels.tools.substance.main.docrobot.RobotMain org.pushingpixels.tools.substance.extras.docrobot.watermarks.NoiseMagneticFieldWatermark
JAVA -cp $CLASSPATH org.pushingpixels.tools.substance.main.docrobot.RobotMain org.pushingpixels.tools.substance.extras.docrobot.watermarks.NoiseMarbleVeinWatermark
JAVA -cp $CLASSPATH org.pushingpixels.tools.substance.main.docrobot.RobotMain org.pushingpixels.tools.substance.extras.docrobot.watermarks.NoiseMazeWatermark
JAVA -cp $CLASSPATH org.pushingpixels.tools.substance.main.docrobot.RobotMain org.pushingpixels.tools.substance.extras.docrobot.watermarks.NoisePlanktonWatermark
JAVA -cp $CLASSPATH org.pushingpixels.tools.substance.main.docrobot.RobotMain org.pushingpixels.tools.substance.extras.docrobot.watermarks.NoiseWoodWatermark
Loading

0 comments on commit 9df1767

Please sign in to comment.