Skip to content

Commit

Permalink
Don't show overlays on ribbon title pane / taskbar popups
Browse files Browse the repository at this point in the history
Closes #307
  • Loading branch information
kirill-grouchnikov committed Oct 1, 2020
1 parent 953fa28 commit 1f7612a
Show file tree
Hide file tree
Showing 14 changed files with 177 additions and 120 deletions.
Binary file modified drop/3.5-SNAPSHOT/core/radiance-flamingo-3.5-SNAPSHOT.jar
Binary file not shown.
Binary file modified drop/3.5-SNAPSHOT/core/radiance-substance-3.5-SNAPSHOT.jar
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.pushingpixels.flamingo.api.common.model.CommandMenuContentModel;
import org.pushingpixels.flamingo.api.common.model.CommandPanelContentModel;
import org.pushingpixels.flamingo.internal.ui.common.popup.ScrollableHost;
import org.pushingpixels.substance.internal.utils.SubstancePopupContainer;

import javax.swing.*;
import javax.swing.JPopupMenu.Separator;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import org.pushingpixels.flamingo.internal.ui.common.popup.ColorSelectorPopupMenuMultiRowSelector;
import org.pushingpixels.flamingo.internal.ui.common.popup.ColorSelectorPopupMenuSingleRowSelector;
import org.pushingpixels.flamingo.internal.ui.common.popup.JColorSelectorPanel;
import org.pushingpixels.substance.internal.utils.SubstancePopupContainer;

import javax.swing.*;
import javax.swing.event.ChangeEvent;
Expand All @@ -50,6 +51,7 @@
import java.util.LinkedList;
import java.util.List;

@SubstancePopupContainer
public class JColorSelectorPopupMenu extends AbstractPopupMenu {
/**
* @see #getUIClassID
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import org.pushingpixels.flamingo.api.common.projection.Projection;
import org.pushingpixels.flamingo.internal.substance.common.ui.SubstanceCommandPopupMenuUI;
import org.pushingpixels.flamingo.internal.ui.common.popup.ScrollableHost;
import org.pushingpixels.substance.internal.utils.SubstancePopupContainer;

import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
Expand All @@ -51,6 +52,7 @@
*
* @author Kirill Grouchnikov
*/
@SubstancePopupContainer
public class JCommandPopupMenu extends AbstractPopupMenu implements ScrollableHost {
/**
* @see #getUIClassID
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
import org.pushingpixels.neon.api.NeonCortex;
import org.pushingpixels.neon.api.icon.ResizableIcon;
import org.pushingpixels.substance.internal.utils.SubstanceCoreUtilities;
import org.pushingpixels.substance.internal.utils.SubstancePopupContainer;

import javax.swing.*;
import java.awt.*;
Expand Down Expand Up @@ -630,6 +631,7 @@ private boolean isInTaskbar(Component c) {
}
}

@SubstancePopupContainer
public static class GlobalPopupMenu extends JCommandPopupMenu {
public GlobalPopupMenu(Projection<JCommandPopupMenu, CommandMenuContentModel,
CommandPopupMenuPresentationModel> projection) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import org.pushingpixels.substance.internal.painter.DecorationPainterUtils;
import org.pushingpixels.substance.internal.utils.SubstanceColorSchemeUtilities;
import org.pushingpixels.substance.internal.utils.SubstanceCoreUtilities;
import org.pushingpixels.substance.internal.utils.SubstancePopupContainer;
import org.pushingpixels.substance.internal.utils.WidgetUtilities;
import org.pushingpixels.substance.internal.utils.menu.SubstanceMenuBackgroundDelegate;

Expand Down Expand Up @@ -91,6 +92,7 @@ protected JPanel createMenuPanel() {
return result;
}

@SubstancePopupContainer
protected class SubstanceMenuPanel extends MenuPanel {
@Override
protected void paintIconGutterBackground(Graphics g) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,13 +163,21 @@ public int getPreferredIconSize(JCommandButton commandButton) {
}
}

@SubstancePopupContainer
private class TaskbarOverflowPopupPanelContent extends JPanel {
public TaskbarOverflowPopupPanelContent(LayoutManager layout) {
super(layout);
}
}

@SubstancePopupContainer
public class TaskbarOverflowPopupPanel extends JPopupPanel {
private TaskbarOverflowPopupPanel(List<Component> overflowComponents,
Dimension size, boolean hasScrolling) {
this.setLayout(new BorderLayout());

JPanel overflowPanel = new JPanel(new FlowLayout(FlowLayout.CENTER,
getTaskBarLayoutGap(this), 0));
JPanel overflowPanel = new TaskbarOverflowPopupPanelContent(
new FlowLayout(FlowLayout.CENTER, getTaskBarLayoutGap(this), 0));
for (Component overflow : overflowComponents) {
overflowPanel.add(overflow);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import org.pushingpixels.substance.api.SubstanceSlices;
import org.pushingpixels.substance.internal.painter.BackgroundPaintingUtils;
import org.pushingpixels.substance.internal.utils.SubstanceCoreUtilities;
import org.pushingpixels.substance.internal.utils.SubstancePopupContainer;
import org.pushingpixels.substance.internal.utils.SubstanceSizeUtils;

import javax.swing.*;
Expand Down Expand Up @@ -93,6 +94,7 @@ public abstract class BasicRibbonBandUI extends RibbonBandUI {
*
* @author Kirill Grouchnikov
*/
@SubstancePopupContainer
protected static class CollapsedButtonPopupPanel extends JPopupPanel {
/**
* The main component of <code>this</code> popup panel. Can be <code>null</code>.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import org.pushingpixels.substance.api.SubstanceCortex;
import org.pushingpixels.substance.api.SubstanceSlices;
import org.pushingpixels.substance.internal.utils.SubstanceMetricsUtilities;
import org.pushingpixels.substance.internal.utils.SubstancePopupContainer;

import javax.swing.*;
import javax.swing.border.Border;
Expand Down Expand Up @@ -1355,6 +1356,7 @@ public List<JCommandButton> getAnchoredCommandButtons() {
return Collections.unmodifiableList(result);
}

@SubstancePopupContainer
private static class BandHostPopupPanel extends JPopupPanel {
private BandHostPopupPanel(Component component, Dimension originalSize) {
this.setLayout(new BorderLayout());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,11 @@
import org.pushingpixels.flamingo.api.ribbon.RibbonApplicationMenu;
import org.pushingpixels.flamingo.internal.substance.ribbon.ui.SubstanceRibbonApplicationMenuPopupPanelUI;
import org.pushingpixels.flamingo.internal.ui.common.popup.ScrollableHost;
import org.pushingpixels.substance.internal.utils.SubstancePopupContainer;

import javax.swing.*;

@SubstancePopupContainer
public class JRibbonApplicationMenuPopupPanel extends AbstractPopupMenu implements ScrollableHost {
/**
* The UI class ID string.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ public GreenMagicSkin() {
SubstanceColorScheme footerFillScheme = schemes.get("Green Magic Footer Fill");
this.registerAsDecorationArea(footerFillScheme, DecorationAreaType.FOOTER);


// Add overlay painters to paint drop shadow and a dark line along the bottom
// edges of headers
this.addOverlayPainter(BottomShadowOverlayPainter.getInstance(100), DecorationAreaType.HEADER);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,141 +32,131 @@
import org.pushingpixels.substance.api.SubstanceCortex.ComponentOrParentChainScope;
import org.pushingpixels.substance.api.SubstanceSkin;
import org.pushingpixels.substance.api.SubstanceSlices.DecorationAreaType;
import org.pushingpixels.substance.internal.utils.SubstanceColorUtilities;
import org.pushingpixels.substance.internal.utils.SubstanceCoreUtilities;
import org.pushingpixels.substance.internal.utils.WidgetUtilities;
import org.pushingpixels.substance.internal.utils.*;

import javax.swing.*;
import javax.swing.text.JTextComponent;
import java.awt.*;

/**
* Delegate for painting filled backgrounds.
*
*
* @author Kirill Grouchnikov
*/
public class BackgroundPaintingUtils {
/**
* Updates the background of the specified component on the specified
* graphic context. The background is updated only if the component is
* opaque.
*
* @param g
* Graphic context.
* @param c
* Component.
*/
public static void updateIfOpaque(Graphics g, JComponent c) {
if (SubstanceCoreUtilities.isOpaque(c)) {
update(g, c, false);
}
}
/**
* Updates the background of the specified component on the specified
* graphic context. The background is updated only if the component is
* opaque.
*
* @param g Graphic context.
* @param c Component.
*/
public static void updateIfOpaque(Graphics g, JComponent c) {
if (SubstanceCoreUtilities.isOpaque(c)) {
update(g, c, false);
}
}

/**
* Updates the background of the specified component on the specified
* graphic context. The background is not painted when the
* <code>force</code> parameter is <code>false</code> and at least one of
* the following conditions holds:
* <ul>
* <li>The component is in a cell renderer.</li>
* <li>The component is not showing on the screen.</li>
* <li>The component is in the preview mode.</li>
* </ul>
*
* @param g
* Graphic context.
* @param c
* Component.
* @param force
* If <code>true</code>, the painting of background is enforced.
*/
public static void update(Graphics g, JComponent c, boolean force) {
// failsafe for LAF change
if (!SubstanceCoreUtilities.isCurrentLookAndFeel()) {
return;
}
/**
* Updates the background of the specified component on the specified
* graphic context. The background is not painted when the
* <code>force</code> parameter is <code>false</code> and at least one of
* the following conditions holds:
* <ul>
* <li>The component is in a cell renderer.</li>
* <li>The component is not showing on the screen.</li>
* <li>The component is in the preview mode.</li>
* </ul>
*
* @param g Graphic context.
* @param c Component.
* @param force If <code>true</code>, the painting of background is enforced.
*/
public static void update(Graphics g, JComponent c, boolean force) {
// failsafe for LAF change
if (!SubstanceCoreUtilities.isCurrentLookAndFeel()) {
return;
}

Graphics2D graphics = (Graphics2D) g.create();
// optimization - do not call fillRect on graphics with anti-alias turned on
graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_OFF);
graphics.setComposite(WidgetUtilities.getAlphaComposite(c, g));
Graphics2D graphics = (Graphics2D) g.create();
// optimization - do not call fillRect on graphics with anti-alias turned on
graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_OFF);
graphics.setComposite(WidgetUtilities.getAlphaComposite(c, g));

DecorationAreaType decorationType = ComponentOrParentChainScope.getDecorationType(c);
SubstanceSkin skin = SubstanceCoreUtilities.getSkin(c);
boolean isShowing = c.isShowing();
boolean showOverlays = true;
if (c.getParent() instanceof JPopupMenu) {
// Don't show any overlays on content in popup menus
showOverlays = false;
} else {
if (c instanceof JMenuItem) {
showOverlays = false;
if (c instanceof JMenu) {
// Show overlays on top-level menu content
showOverlays = ((JMenu) c).isTopLevelMenu();
}
} else if (c instanceof JMenuBar) {
// Show overlays on menu bar
showOverlays = true;
}
}
DecorationAreaType decorationType = ComponentOrParentChainScope.getDecorationType(c);
SubstanceSkin skin = SubstanceCoreUtilities.getSkin(c);
boolean isShowing = c.isShowing();
boolean showOverlays = true;
if ((c.getParent() instanceof JPopupMenu) ||
(c.getClass().isAnnotationPresent(SubstancePopupContainer.class))) {
// Don't show any overlays on content in popup menus
showOverlays = false;
} else {
if (c instanceof JMenuItem) {
showOverlays = false;
if (c instanceof JMenu) {
// Show overlays on top-level menu content
showOverlays = ((JMenu) c).isTopLevelMenu();
}
} else if (c instanceof JMenuBar) {
// Show overlays on menu bar
showOverlays = true;
}
}

if (isShowing && (decorationType != DecorationAreaType.NONE)
&& (skin.isRegisteredAsDecorationArea(decorationType))) {
// use the decoration painter
DecorationPainterUtils.paintDecorationBackground(graphics, c, force);
if (showOverlays) {
OverlayPainterUtils.paintOverlays(graphics, c, skin, decorationType);
if (isShowing && (decorationType != DecorationAreaType.NONE)
&& (skin.isRegisteredAsDecorationArea(decorationType))) {
// use the decoration painter
DecorationPainterUtils.paintDecorationBackground(graphics, c, force);
if (showOverlays) {
OverlayPainterUtils.paintOverlays(graphics, c, skin, decorationType);
}
} else {
// fill the area with solid color
Color backgr = SubstanceColorUtilities
.getBackgroundFillColor(((c instanceof JTextComponent) || (c instanceof JSpinner))
? c.getParent() : c);
graphics.setColor(backgr);
graphics.fillRect(0, 0, c.getWidth(), c.getHeight());
} else {
// fill the area with solid color
Color backgr = SubstanceColorUtilities
.getBackgroundFillColor(((c instanceof JTextComponent) || (c instanceof JSpinner))
? c.getParent() : c);
graphics.setColor(backgr);
graphics.fillRect(0, 0, c.getWidth(), c.getHeight());

if (isShowing) {
if (showOverlays) {
// add overlays
OverlayPainterUtils.paintOverlays(graphics, c, skin, decorationType);
}
}
}
if (isShowing) {
if (showOverlays) {
// add overlays
OverlayPainterUtils.paintOverlays(graphics, c, skin, decorationType);
}
}
}

graphics.dispose();
}
graphics.dispose();
}

/**
* Updates the background of the specified component on the specified
* graphic context in the specified rectangle.
*
* @param g
* Graphic context.
* @param c
* Component.
* @param fillColor
* Fill color.
* @param rect
* The rectangle to fill.
*/
public static void fillBackground(Graphics g, JComponent c, Color fillColor, Rectangle rect) {
// failsafe for LAF change
if (!SubstanceCoreUtilities.isCurrentLookAndFeel()) {
return;
}
/**
* Updates the background of the specified component on the specified
* graphic context in the specified rectangle.
*
* @param g Graphic context.
* @param c Component.
* @param fillColor Fill color.
* @param rect The rectangle to fill.
*/
public static void fillBackground(Graphics g, JComponent c, Color fillColor, Rectangle rect) {
// failsafe for LAF change
if (!SubstanceCoreUtilities.isCurrentLookAndFeel()) {
return;
}

boolean isInCellRenderer = (SwingUtilities.getAncestorOfClass(
CellRendererPane.class, c) != null);
if ((!c.isShowing()) && (!isInCellRenderer)) {
return;
}
boolean isInCellRenderer = (SwingUtilities.getAncestorOfClass(
CellRendererPane.class, c) != null);
if ((!c.isShowing()) && (!isInCellRenderer)) {
return;
}

Graphics2D graphics = (Graphics2D) g.create();
graphics.setComposite(WidgetUtilities.getAlphaComposite(c, g));
graphics.setColor(fillColor);
graphics.fillRect(rect.x, rect.y, rect.width, rect.height);
graphics.dispose();
}
Graphics2D graphics = (Graphics2D) g.create();
graphics.setComposite(WidgetUtilities.getAlphaComposite(c, g));
graphics.setColor(fillColor);
graphics.fillRect(rect.x, rect.y, rect.width, rect.height);
graphics.dispose();
}
}
Loading

0 comments on commit 1f7612a

Please sign in to comment.