Browse Source

Added logging to IconColorMapper.

Make sure theme installed events are dispatched after ui reloading is finished.
Fixed background painting for trees in OverlayScrollPane.
Added colorful sample for OverlayScrollPane.
pull/188/head
weisj 5 years ago
parent
commit
4e5fe2a6fa
  1. 3
      core/src/main/java/com/github/weisj/darklaf/DarkLaf.java
  2. 4
      core/src/main/java/com/github/weisj/darklaf/LafManager.java
  3. 4
      core/src/main/java/com/github/weisj/darklaf/components/OverlayScrollPane.java
  4. 6
      core/src/main/java/com/github/weisj/darklaf/graphics/ImageUtil.java
  5. 27
      core/src/main/java/com/github/weisj/darklaf/ui/tree/DarkTreeUI.java
  6. 35
      core/src/test/java/ui/scrollPane/OverlayScrollPaneDemo.java
  7. 55
      core/src/test/java/ui/scrollPane/OverlayScrollPaneTextDemo.java
  8. 1
      property-loader/src/main/java/com/github/weisj/darklaf/icons/IconColorMapper.java

3
core/src/main/java/com/github/weisj/darklaf/DarkLaf.java

@ -56,11 +56,10 @@ public class DarkLaf extends BasicLookAndFeel {
new IdeaDefaultsInitTask(), new IdeaDefaultsInitTask(),
new FontDefaultsInitTask(), new FontDefaultsInitTask(),
new StyleSheetInitTask(), new StyleSheetInitTask(),
new UtilityDefaultsInitTask(),
new SystemDefaultsInitTask(), new SystemDefaultsInitTask(),
new PlatformDefaultsInitTask(), new PlatformDefaultsInitTask(),
new UserInitTask(), new UserInitTask(),
}; new UtilityDefaultsInitTask()};
/* /*
* The base look and feel. This may vary to handle different platform support. * The base look and feel. This may vary to handle different platform support.
*/ */

4
core/src/main/java/com/github/weisj/darklaf/LafManager.java

@ -379,8 +379,8 @@ public final class LafManager {
getTheme(); getTheme();
UIManager.setLookAndFeel(DarkLaf.class.getCanonicalName()); UIManager.setLookAndFeel(DarkLaf.class.getCanonicalName());
updateLaf(); updateLaf();
eventSupport.dispatchEvent(new ThemeChangeEvent(null, getTheme()), SwingUtilities.invokeLater(() -> eventSupport.dispatchEvent(new ThemeChangeEvent(null, getTheme()),
ThemeChangeListener::themeInstalled); ThemeChangeListener::themeInstalled));
} catch (final ClassNotFoundException } catch (final ClassNotFoundException
| InstantiationException | InstantiationException
| IllegalAccessException | IllegalAccessException

4
core/src/main/java/com/github/weisj/darklaf/components/OverlayScrollPane.java

@ -123,7 +123,7 @@ public class OverlayScrollPane extends JLayeredPane implements PropertyChangeLis
scrollPane.setRowHeader(scrollPane.getRowHeader()); scrollPane.setRowHeader(scrollPane.getRowHeader());
} }
protected JScrollBar createScrollBar(final int orientation) { protected PopupScrollBar createScrollBar(final int orientation) {
return new PopupScrollBar(orientation); return new PopupScrollBar(orientation);
} }
@ -243,7 +243,7 @@ public class OverlayScrollPane extends JLayeredPane implements PropertyChangeLis
}); });
} }
private static final class PopupScrollBar extends JScrollBar { protected static final class PopupScrollBar extends JScrollBar {
private PopupScrollBar(final int direction) { private PopupScrollBar(final int direction) {
super(direction); super(direction);

6
core/src/main/java/com/github/weisj/darklaf/graphics/ImageUtil.java

@ -59,14 +59,14 @@ public final class ImageUtil {
} }
public static Image createFrameIcon(final Icon icon, final JFrame c) { public static Image createFrameIcon(final Icon icon, final JFrame c) {
return createFrameIcon(icon, c, JFrame::setIconImage); return createWindowIcon(icon, c, JFrame::setIconImage);
} }
public static Image createFrameIcon(final Icon icon, final JDialog c) { public static Image createFrameIcon(final Icon icon, final JDialog c) {
return createFrameIcon(icon, c, JDialog::setIconImage); return createWindowIcon(icon, c, JDialog::setIconImage);
} }
public static <T extends Window> Image createFrameIcon(final Icon icon, final T c, private static <T extends Window> Image createWindowIcon(final Icon icon, final T c,
final BiConsumer<T, Image> iconSetter) { final BiConsumer<T, Image> iconSetter) {
if (icon == null) return null; if (icon == null) return null;
if (c != null) { if (c != null) {

27
core/src/main/java/com/github/weisj/darklaf/ui/tree/DarkTreeUI.java

@ -414,6 +414,13 @@ public class DarkTreeUI extends BasicTreeUI implements PropertyChangeListener {
TreePath path; TreePath path;
boolean rootVisible = isRootVisible(); boolean rootVisible = isRootVisible();
final int containerWidth = tree.getParent() instanceof JViewport
? tree.getParent().getWidth()
: tree.getWidth();
final int xOffset = tree.getParent() instanceof JViewport
? ((JViewport) tree.getParent()).getViewPosition().x
: 0;
// Paint row backgrounds // Paint row backgrounds
Enumeration<?> backgroundEnumerator = treeState.getVisiblePathsFrom(initialPath); Enumeration<?> backgroundEnumerator = treeState.getVisiblePathsFrom(initialPath);
while (backgroundEnumerator != null && backgroundEnumerator.hasMoreElements()) { while (backgroundEnumerator != null && backgroundEnumerator.hasMoreElements()) {
@ -428,9 +435,11 @@ public class DarkTreeUI extends BasicTreeUI implements PropertyChangeListener {
} }
bounds = getPathBounds(path, insets, boundsBuffer); bounds = getPathBounds(path, insets, boundsBuffer);
if (bounds == null) return; if (bounds == null) return;
bounds.x = xOffset;
bounds.width = containerWidth;
if (paintBounds.intersects(bounds)) { if (paintBounds.intersects(bounds)) {
paintRowBackground(g, paintBounds, insets, bounds, path, paintRowBackground(g, paintBounds, bounds, path,
tree.getRowForPath(path), isExpanded, hasBeenExpanded, isLeaf); tree.getRowForPath(path));
} }
} }
} }
@ -515,23 +524,15 @@ public class DarkTreeUI extends BasicTreeUI implements PropertyChangeListener {
} }
protected void paintRowBackground(final Graphics g, final Rectangle clipBounds, protected void paintRowBackground(final Graphics g, final Rectangle clipBounds,
final Insets insets, final Rectangle bounds, final TreePath path, final Rectangle bounds, final TreePath path,
final int row, final boolean isExpanded, final int row) {
final boolean hasBeenExpanded, final boolean isLeaf) {
final int containerWidth = tree.getParent() instanceof JViewport
? tree.getParent().getWidth()
: tree.getWidth();
final int xOffset = tree.getParent() instanceof JViewport
? ((JViewport) tree.getParent()).getViewPosition().x
: 0;
if (path != null) { if (path != null) {
boolean selected = tree.isPathSelected(path); boolean selected = tree.isPathSelected(path);
Graphics2D rowGraphics = (Graphics2D) g.create(); Graphics2D rowGraphics = (Graphics2D) g.create();
rowGraphics.setClip(clipBounds); rowGraphics.setClip(clipBounds);
rowGraphics.setColor(CellUtil.getTreeBackground(tree, selected, row)); rowGraphics.setColor(CellUtil.getTreeBackground(tree, selected, row));
rowGraphics.fillRect(xOffset, bounds.y, containerWidth, bounds.height); rowGraphics.fillRect(bounds.x, bounds.y, bounds.width, bounds.height);
rowGraphics.dispose(); rowGraphics.dispose();
} }

35
core/src/test/java/ui/scrollPane/OverlayScrollPaneDemo.java

@ -25,15 +25,14 @@
package ui.scrollPane; package ui.scrollPane;
import java.awt.*; import java.awt.*;
import java.util.Random;
import javax.swing.*; import javax.swing.*;
import ui.ComponentDemo; import ui.ComponentDemo;
import ui.DemoPanel; import ui.DemoPanel;
import ui.DemoResources;
import com.github.weisj.darklaf.components.OverlayScrollPane; import com.github.weisj.darklaf.components.OverlayScrollPane;
import com.github.weisj.darklaf.util.StringUtil;
public class OverlayScrollPaneDemo implements ComponentDemo { public class OverlayScrollPaneDemo implements ComponentDemo {
@ -43,8 +42,36 @@ public class OverlayScrollPaneDemo implements ComponentDemo {
@Override @Override
public JComponent createComponent() { public JComponent createComponent() {
OverlayScrollPane scrollPane = new OverlayScrollPane(new JTextArea(StringUtil.repeat(DemoResources.LOREM_IPSUM, JComponent component = new JComponent() {
5)));
private final Random r = new Random();
private final Color[][] colors = new Color[100][100];
{
for (int x = 0; x < 100; x++) {
for (int y = 0; y < 100; y++) {
colors[x][y] = new Color(r.nextInt());
}
}
}
@Override
protected void paintComponent(final Graphics g) {
super.paintComponent(g);
for (int x = 0; x < 100; x++) {
for (int y = 0; y < 100; y++) {
g.setColor(colors[x][y]);
g.fillRect(x * 10, y * 10, 10, 10);
}
}
}
@Override
public Dimension getPreferredSize() {
return new Dimension(1000, 1000);
}
};
OverlayScrollPane scrollPane = new OverlayScrollPane(component);
return new DemoPanel(scrollPane, new BorderLayout(), 0); return new DemoPanel(scrollPane, new BorderLayout(), 0);
} }

55
core/src/test/java/ui/scrollPane/OverlayScrollPaneTextDemo.java

@ -0,0 +1,55 @@
/*
* MIT License
*
* Copyright (c) 2020 Jannis Weis
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*/
package ui.scrollPane;
import java.awt.*;
import javax.swing.*;
import ui.ComponentDemo;
import ui.DemoPanel;
import ui.DemoResources;
import com.github.weisj.darklaf.components.OverlayScrollPane;
import com.github.weisj.darklaf.util.StringUtil;
public class OverlayScrollPaneTextDemo implements ComponentDemo {
public static void main(final String[] args) {
ComponentDemo.showDemo(new OverlayScrollPaneTextDemo());
}
@Override
public JComponent createComponent() {
OverlayScrollPane scrollPane = new OverlayScrollPane(new JTextArea(StringUtil.repeat(DemoResources.LOREM_IPSUM,
5)));
return new DemoPanel(scrollPane, new BorderLayout(), 0);
}
@Override
public String getTitle() {
return "OverlayScrollPane Demo";
}
}

1
property-loader/src/main/java/com/github/weisj/darklaf/icons/IconColorMapper.java

@ -54,6 +54,7 @@ public final class IconColorMapper {
public static void patchColors(final SVGIcon svgIcon, final UIDefaults defaults) { public static void patchColors(final SVGIcon svgIcon, final UIDefaults defaults) {
SVGUniverse universe = svgIcon.getSvgUniverse(); SVGUniverse universe = svgIcon.getSvgUniverse();
SVGDiagram diagram = universe.getDiagram(svgIcon.getSvgURI()); SVGDiagram diagram = universe.getDiagram(svgIcon.getSvgURI());
LOGGER.fine(() -> "Patching colors of icon " + svgIcon.getSvgURI());
try { try {
loadColors(diagram, defaults); loadColors(diagram, defaults);
} catch (SVGElementException e) { } catch (SVGElementException e) {

Loading…
Cancel
Save