Skip to content

Commit

Permalink
Tasks for demo classes.
Browse files Browse the repository at this point in the history
  • Loading branch information
weisJ committed Apr 10, 2020
1 parent fa34d54 commit 900a683
Show file tree
Hide file tree
Showing 17 changed files with 392 additions and 63 deletions.
26 changes: 17 additions & 9 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,20 @@ jobs:
name: macOS (Java 11)
runs-on: macos-latest
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 10
- name: Set up JDK 11
uses: actions/setup-java@v1
with:
java-version: 11
- name: Build
run: ./gradlew build
- uses: actions/checkout@v2
with:
fetch-depth: 10
- name: Set up JDK 11
uses: actions/setup-java@v1
with:
java-version: 11
- name: Build
run: ./gradlew build
- name: Test
run: ./gradlew AccentColorTest
- name: Upload artifact
uses: actions/upload-artifact@v1
with:
name: accent_color
path: build/screenshots/accent_colors

16 changes: 16 additions & 0 deletions core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,22 @@ tasks.jar {
}
}

project.properties
.filter { it.key.startsWith("demoClass") }
.forEach {
val name = it.key.split(".")[1]
rootProject.tasks.register(name, JavaExec::class) {
group = "Demo"
description = "Run the demo '$name'."
dependsOn(tasks.testClasses)

workingDir = File(project.rootDir, "build")
workingDir.mkdirs()
main = it.value?.toString() ?: throw GradleException("Main class for demo ``$name` not specified.")
classpath(sourceSets.main.get().runtimeClasspath, sourceSets.test.get().runtimeClasspath)
}
}

val makeDocumentation by tasks.registering(JavaExec::class) {
group = "Development"
description = "Builds the documentation"
Expand Down
43 changes: 42 additions & 1 deletion core/gradle.properties
Original file line number Diff line number Diff line change
@@ -1 +1,42 @@
generatePomFile = true
generatePomFile = true

demoClass.AccentColorTest = test.AccentColorTest
demoClass.UIManagerDefaults = defaults.UIManagerDefaults
demoClass.AllIcons = icon.AllIcons
demoClass.IconDemo = icon.IconDemo
demoClass.RotatableIconDemo = icon.RotatableIconDemo
demoClass.ButtonDemo = ui.button.ButtonDemo
demoClass.GroupedButtonDemo = ui.button.GroupedButtonDemo
demoClass.ToggleButtonDemo = ui.button.ToggleButtonDemo
demoClass.CheckBoxDemo = ui.checkBox.CheckBoxDemo
demoClass.TriCheckBoxDemo = ui.checkBox.TriCheckBoxDemo
demoClass.ColorChooserDemo = ui.colorChooser.ColorChooserDemo
demoClass.ComboBoxDemo = ui.comboBox.ComboBoxDemo
demoClass.DialogDemo = ui.dialog.DialogDemo
demoClass.FileChooserDemo = ui.fileChooser.FileChooserDemo
demoClass.InternalFrameDemo = ui.internalFrame.InternalFrameDemo
demoClass.LabelDemo = ui.label.LabelDemo
demoClass.ListDemo = ui.list.ListDemo
demoClass.PopupMenuDemo = ui.popupMenu.PopupMenuDemo
demoClass.ProgressBarDemo = ui.progressBar.ProgressBarDemo
demoClass.RadioButtonDemo = ui.radioButton.RadioButtonDemo
demoClass.ScrollPaneDemo = ui.scrollPane.ScrollPaneDemo
demoClass.OverlayScrollPaneDemo = ui.scrollPane.OverlayScrollPaneDemo
demoClass.SliderDemo = ui.slider.SliderDemo
demoClass.SpinnerDemo = ui.spinner.SpinnerDemo
demoClass.SplitPaneDemo = ui.splitPane.SplitPaneDemo
demoClass.TabbedPaneDemo = ui.tabbedPane.TabbedPaneDemo
demoClass.TabbedPaneKeyboardShortcutDemo = ui.tabbedPane.TabbedPaneKeyboardShortcut
demoClass.ClosableTabbedPaneDemo = ui.tabbedPane.ClosableTabbedPaneDemo
demoClass.TabFrameDemo = ui.tabFrame.TabFrameDemo
demoClass.TableDemo = ui.table.TableDemo
demoClass.EditorPaneDemo = ui.text.EditorPaneDemo
demoClass.FormattedTextFieldDemo = ui.text.FormattedTextFieldDemo
demoClass.PasswordFieldDemo = ui.text.PasswordFieldDemo
demoClass.TextAreaDemo = ui.text.TextAreaDemo
demoClass.TextFieldDemo = ui.text.TextFieldDemo
demoClass.TextPaneDemo = ui.text.TextPaneDemo
demoClass.ToolBarDemo = ui.toolBar.ToolBarDemo
demoClass.ToolTipDemo = ui.toolTip.ToolTipDemo
demoClass.TreeDemo = ui.tree.TreeDemo
demoClass.PreferenceChangeDemo = PreferenceChangeDemo
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ public static void paintOutlineBorder(final Graphics2D g, final int width, final
private static void doPaint(final Graphics2D g, final int width, final int height, final float arc,
final float bw) {
GraphicsContext context = GraphicsUtil.setupStrokePainting(g);

Shape outerRect = new RoundRectangle2D.Float(0, 0, width, height, arc + bw, arc + bw);
Shape innerRect = new RoundRectangle2D.Float(bw, bw, width - 2 * bw, height - 2 * bw, arc - bw, arc - bw);
Path2D path = new Path2D.Float(Path2D.WIND_EVEN_ODD);
Expand Down Expand Up @@ -183,11 +182,12 @@ public static void paintLineBorder(final Graphics2D g, final float x, final floa
final boolean growByStroke) {
GraphicsContext config = GraphicsUtil.setupStrokePainting(g);
Stroke stroke = g.getStroke();
float lw = stroke instanceof BasicStroke ? ((BasicStroke) stroke).getLineWidth() : 1;
float lw = stroke instanceof BasicStroke ? ((BasicStroke) stroke).getLineWidth() : 1f;
lw /= 2;
if (growByStroke) {
g.draw(new RoundRectangle2D.Float(x - lw, y - lw, width + lw, height + lw, arc, arc));
} else {
g.draw(new RoundRectangle2D.Float(x, y, width, height, arc, arc));
g.draw(new RoundRectangle2D.Float(x, y, width - lw, height - lw, arc - 3, arc - 3));
}
config.restore();
}
Expand Down
11 changes: 4 additions & 7 deletions core/src/main/java/com/github/weisj/darklaf/util/ImageUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,7 @@ public static Image createDragImage(final Component c, final Rectangle bounds,
* @param bounds the bounds inside the component to capture.
* @return image containing the captured area.
*/

public static Image scaledImageFromComponent(final Component c, final Rectangle bounds) {
public static BufferedImage scaledImageFromComponent(final Component c, final Rectangle bounds) {
return scaledImageFromComponent(c, bounds, Scale.SCALE_X, Scale.SCALE_Y);
}

Expand All @@ -77,9 +76,8 @@ public static Image scaledImageFromComponent(final Component c, final Rectangle
* @param scaley the y scale
* @return image containing the captured area.
*/

public static Image scaledImageFromComponent(final Component c, final Rectangle bounds,
final double scalex, final double scaley) {
public static BufferedImage scaledImageFromComponent(final Component c, final Rectangle bounds,
final double scalex, final double scaley) {
BufferedImage image;
boolean scale = scalex != 1.0 || scaley != 1.0;
if (scale) {
Expand All @@ -106,8 +104,7 @@ public static Image scaledImageFromComponent(final Component c, final Rectangle
* @param bounds the bounds inside the component to capture.
* @return image containing the captured area.
*/

public static Image imageFromComponent(final Component c, final Rectangle bounds) {
public static BufferedImage imageFromComponent(final Component c, final Rectangle bounds) {
return scaledImageFromComponent(c, bounds, 1.0, 1.0);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,5 @@ Table.alternateRowColor = true
Tree.alternateRowColor = true
List.alternateRowColor = true
FileChooser.listViewWindowsStyle = false
CheckBox.borderInsets = 2,2,2,2
RadioButton.borderInsets = 2,2,2,2
PopupMenu.defaultLightWeightPopups = false
ToolTip.paintShadow = false
47 changes: 39 additions & 8 deletions core/src/test/java/PreferenceChangeDemo.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import com.github.weisj.darklaf.LafManager;
import com.github.weisj.darklaf.icons.SolidColorIcon;
import com.github.weisj.darklaf.theme.Theme;
import ui.ComponentDemo;
import ui.DemoPanel;

import javax.swing.*;
import java.awt.*;
Expand Down Expand Up @@ -40,20 +42,49 @@ public static void main(final String[] args) {
@Override
public JComponent createComponent() {
LafManager.addThemePreferenceChangeListener(LafManager::installTheme);
return new JPanel(new GridBagLayout()) {{
add(new JToggleButton("Start") {{
addActionListener(e -> {
setText(isSelected() ? "Stop" : "Start");
});
}});
}};
DemoPanel panel = new DemoPanel(new JToggleButton("Start") {{
addActionListener(e -> {
setText(isSelected() ? "Stop" : "Start");
LafManager.enabledPreferenceChangeReporting(isSelected());
});
}});
Icon accentColorIcon = new SolidColorIcon() {
@Override
public Color getColor() {
return LafManager.getTheme().getAccentColorRule().getAccentColor();
}
};
Icon selectionColorIcon = new SolidColorIcon() {
@Override
public Color getColor() {
return LafManager.getTheme().getAccentColorRule().getSelectionColor();
}
};
JPanel controlPanel = panel.addControls();
controlPanel.add(new JLabel("Accent Color", accentColorIcon, JLabel.LEFT));
controlPanel.add(new JLabel("Selection Color", selectionColorIcon, JLabel.LEFT));

controlPanel = panel.addControls();
controlPanel.add(new JTextArea() {{
setMargin(new Insets(5, 5, 5, 5));
setEditable(false);
setText("Press start/stop to enable/disable preference monitoring.\n"
+ "Then do one of the following\n"
+ " - switch between dark/light theme (Windows/macOS)\n"
+ " - toggle high contrast mode (Windows/macOS)\n"
+ " - change accent color (Windows/macOS)\n"
+ " - change selection color (macOS)\n"
+ " - change font scaling (Windows)\n"
+ "The theme should then adjust automatically (if monitoring is started).\n");
}});
return panel;
}

@Override
public WindowListener createWindowListener() {
return new WindowAdapter() {
@Override
public void windowClosed(final WindowEvent e) {
public void windowClosing(final WindowEvent e) {
LafManager.enabledPreferenceChangeReporting(false);
}
};
Expand Down
Loading

0 comments on commit 900a683

Please sign in to comment.