Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions jhotdraw-gui/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@
<artifactId>jhotdraw-gui</artifactId>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>jhotdraw-utils</artifactId>
Expand All @@ -30,5 +36,14 @@
<version>${project.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
</plugin>
</plugins>
</build>
<name>jhotdraw-gui</name>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ public void paintColorTrack(Graphics g, int x, int y, int width, int height, int
}
}
if (colorTrackImage != null) {
g.drawImage(colorTrackImage, x, y, slider);
g.drawImage(colorTrackImage, x, y, null);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,4 @@ public void setColorToModel(Color color) {
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JSlider brightnessSlider;
// End of variables declaration//GEN-END:variables
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package org.jhotdraw.color;

import org.junit.jupiter.api.Test;

import javax.swing.*;
import java.awt.*;
import java.awt.image.BufferedImage;

import static org.junit.jupiter.api.Assertions.fail;
import org.jhotdraw.color.ColorSliderModel;
import org.jhotdraw.color.DefaultColorSliderModel;
import org.jhotdraw.color.HSVColorSpace;


public class ColorSliderUIRegressionTest {

@Test
void paintColorTrack_doesNotCallImageUpdate_andDoesNotCrash() throws Exception {
SwingUtilities.invokeAndWait(() -> {
// Custom slider that fails if Swing calls imageUpdate on it.
// After our fix (drawImage observer = null), this should never be called.
JSlider slider = new JSlider(JSlider.HORIZONTAL) {
@Override
public boolean imageUpdate(Image img, int infoflags, int x, int y, int w, int h) {
fail("imageUpdate() was called. The color track should be drawn with a null ImageObserver.");
return super.imageUpdate(img, infoflags, x, y, w, h);
}
};

// Install JHotDraw custom slider UI
slider.setUI((ColorSliderUI) ColorSliderUI.createUI(slider));

// Configure like in the real chooser panels (model + client properties)
ColorSliderModel model = new DefaultColorSliderModel(HSVColorSpace.getInstance());
model.configureSlider(2, slider);

// Give it a size so painting runs
slider.setSize(300, 50);
slider.doLayout();

// Paint into an offscreen image (headless-friendly)
BufferedImage img = new BufferedImage(300, 50, BufferedImage.TYPE_INT_ARGB);
Graphics2D g2 = img.createGraphics();
try {
slider.paint(g2);
} finally {
g2.dispose();
}
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,10 @@ private JPanel createColorWheelChooser(ColorSpace sys, int angularIndex, int rad
w.setFlipY(flipY);
w.setModel(m);
JSlider s = new JSlider(JSlider.VERTICAL);
m.configureSlider(verticalIndex, s);
s.setMajorTickSpacing(10);
s.setPaintLabels(true);
s.setPaintTicks(true);
m.configureSlider(verticalIndex, s);
p.add(new JLabel("<html>" + ColorUtil.getName(sys) + "<br>α:" + angularIndex + " r:" + radialIndex + " v:" + verticalIndex), BorderLayout.NORTH);
p.add(w, BorderLayout.CENTER);
p.add(s, BorderLayout.EAST);
Expand Down Expand Up @@ -181,10 +181,10 @@ private JPanel createSliderChooser(ColorSpace sys, boolean vertical) {
for (int i = 0; i < m.getComponentCount(); i++) {
final int comp = i;
JSlider s = new JSlider(JSlider.HORIZONTAL);
m.configureSlider(comp, s);
s.setMajorTickSpacing(50);
s.setPaintTicks(true);
s.setOrientation(vertical ? JSlider.VERTICAL : JSlider.HORIZONTAL);
m.configureSlider(comp, s);
if (vertical) {
gbc.gridx = i;
gbc.gridy = 0;
Expand Down