/* * (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 if loading if (this.delegate instanceof AsynchronousLoading) { AsynchronousLoading asyncDelegate = (AsynchronousLoading) this.delegate; // if the delegate is still loading - do nothing if (asyncDelegate.isLoading()) return; } SubstanceColorScheme scheme = SubstanceColorSchemeUtilities.getColorScheme(c, ComponentState.DISABLED_UNSELECTED); HashMapKey key = SubstanceCoreUtilities.getHashKey( this.getIconWidth(), this.getIconHeight(), scheme.getDisplayName()); BufferedImage filtered = this.cachedImages.get(key); if (filtered == null) { BufferedImage offscreen = FlamingoUtilities.getBlankImage(this.getIconWidth(), this.getIconHeight()); Graphics2D g2d = offscreen.createGraphics(); this.delegate.paintIcon(c, g2d, 0, 0); g2d.dispose(); filtered = SubstanceImageCreator.getColorSchemeImage(offscreen, scheme, 0.5f); this.cachedImages.put(key, filtered); } g.drawImage(filtered, x, y, null); }
/* * (non-Javadoc) * * @seeorg.jvnet.flamingo.common.ui.BasicCommandButtonUI# * paintButtonVerticalSeparator(java.awt.Graphics, int) */ @Override protected void paintButtonVerticalSeparator(Graphics graphics, Rectangle separatorArea) { Graphics2D g2d = (Graphics2D) graphics.create(); g2d.translate(separatorArea.x, 0); SubstanceColorScheme colorScheme = SubstanceColorSchemeUtilities.getColorScheme( this.commandButton, ColorSchemeAssociationKind.SEPARATOR, ComponentState.getState(this.commandButton.getActionModel(), this.commandButton)); float fadeAlpha = this.getSeparatorAlpha(); g2d.setComposite(AlphaComposite.SrcOver.derive(fadeAlpha)); SeparatorPainterUtils.paintSeparator( this.commandButton, g2d, colorScheme, 1, this.commandButton.getHeight(), JSlider.VERTICAL, true, 4, 4, true); g2d.dispose(); }
/* * (non-Javadoc) * * @see * org.jvnet.flamingo.common.ui.BasicCommandButtonUI#paintButtonBackground * (java.awt.Graphics, java.awt.Rectangle) */ @Override protected void paintButtonBackground(Graphics graphics, Rectangle toFill) { if (SubstanceCoreUtilities.isButtonNeverPainted(this.commandButton)) return; ButtonModel actionModel = this.commandButton.getActionModel(); PopupButtonModel popupModel = ((JCommandButton) this.commandButton).getPopupModel(); Rectangle actionArea = this.getLayoutInfo().actionClickArea; Rectangle popupArea = this.getLayoutInfo().popupClickArea; BufferedImage fullAlphaBackground = CommandButtonBackgroundDelegate.getCombinedCommandButtonBackground( this.commandButton, actionModel, actionArea, popupModel, popupArea); // Two special cases here: // 1. Button has flat appearance and doesn't show the popup // 2. Button is disabled. // For both cases, we need to set custom translucency. boolean isFlat = this.commandButton.isFlat() && !((JCommandButton) this.commandButton).getPopupModel().isPopupShowing(); boolean isSpecial = isFlat || !this.commandButton.isEnabled(); float extraAlpha = 1.0f; if (isSpecial) { if (isFlat) { float extraActionAlpha = 0.0f; for (Map.Entry<ComponentState, StateTransitionTracker.StateContributionInfo> activeEntry : getActionTransitionTracker().getModelStateInfo().getStateContributionMap().entrySet()) { ComponentState activeState = activeEntry.getKey(); if (activeState.isDisabled()) continue; if (activeState == ComponentState.ENABLED) continue; extraActionAlpha += activeEntry.getValue().getContribution(); } float extraPopupAlpha = 0.0f; for (Map.Entry<ComponentState, StateTransitionTracker.StateContributionInfo> activeEntry : getPopupTransitionTracker().getModelStateInfo().getStateContributionMap().entrySet()) { ComponentState activeState = activeEntry.getKey(); if (activeState.isDisabled()) continue; if (activeState == ComponentState.ENABLED) continue; extraPopupAlpha += activeEntry.getValue().getContribution(); } extraAlpha = Math.max(extraActionAlpha, extraPopupAlpha); } else { ComponentState actionAreaState = ComponentState.getState(actionModel, this.commandButton); if (actionAreaState.isDisabled()) { extraAlpha = SubstanceColorSchemeUtilities.getAlpha(this.commandButton, actionAreaState); } } } // System.out.println(extraAlpha); extraAlpha = Math.min(1.0f, extraAlpha); if (extraAlpha > 0.0f) { Graphics2D g2d = (Graphics2D) graphics.create(); g2d.setComposite( LafWidgetUtilities.getAlphaComposite(this.commandButton, extraAlpha, graphics)); g2d.drawImage(fullAlphaBackground, 0, 0, null); g2d.dispose(); } }
private SubstanceColorScheme getColorSchemeForState( JTable table, SubstanceTableUI ui, ComponentState state) { UpdateOptimizationInfo updateOptimizationInfo = ui.getUpdateOptimizationInfo(); if (state == ComponentState.ENABLED) { if (updateOptimizationInfo == null) { return SubstanceColorSchemeUtilities.getColorScheme(table, state); } else { return updateOptimizationInfo.getDefaultScheme(); } } else { if (updateOptimizationInfo == null) { return SubstanceColorSchemeUtilities.getColorScheme( table, ColorSchemeAssociationKind.HIGHLIGHT, state); } else { return updateOptimizationInfo.getHighlightColorScheme(state); } } }
/* * (non-Javadoc) * * @see org.jvnet.flamingo.ribbon.ui.BasicRibbonUI#installDefaults() */ @Override protected void installDefaults() { super.installDefaults(); SubstanceLookAndFeel.setDecorationType(this.ribbon, DecorationAreaType.HEADER); Color backgr = this.ribbon.getBackground(); if (backgr == null || backgr instanceof UIResource) { Color toSet = SubstanceColorSchemeUtilities.getColorScheme(this.ribbon, ComponentState.ENABLED) .getBackgroundFillColor(); this.ribbon.setBackground(new ColorUIResource(toSet)); } }
@Override protected void paintTaskOutlines(Graphics g) { Graphics2D g2d = (Graphics2D) g.create(); SubstanceColorScheme scheme = SubstanceColorSchemeUtilities.getColorScheme( ribbon, ColorSchemeAssociationKind.SEPARATOR, ComponentState.ENABLED); Set<RibbonTask> tasksWithTrailingSeparators = new HashSet<RibbonTask>(); // add all regular tasks except the last for (int i = 0; i < ribbon.getTaskCount() - 1; i++) { RibbonTask task = ribbon.getTask(i); tasksWithTrailingSeparators.add(task); // System.out.println("Added " + task.getTitle()); } // add all tasks of visible contextual groups except last task in // each group for (int i = 0; i < ribbon.getContextualTaskGroupCount(); i++) { RibbonContextualTaskGroup group = ribbon.getContextualTaskGroup(i); if (ribbon.isVisible(group)) { for (int j = 0; j < group.getTaskCount() - 1; j++) { RibbonTask task = group.getTask(j); tasksWithTrailingSeparators.add(task); } } } for (RibbonTask taskWithTrailingSeparator : tasksWithTrailingSeparators) { JRibbonTaskToggleButton taskToggleButton = taskToggleButtons.get(taskWithTrailingSeparator); Rectangle bounds = taskToggleButton.getBounds(); int x = bounds.x + bounds.width + getTabButtonGap() / 2 - 1; g2d.translate(x, 0); SeparatorPainterUtils.paintSeparator( ribbon, g2d, scheme, 2, getHeight(), SwingConstants.VERTICAL, false, getHeight() / 3, 0, true); g2d.translate(-x, 0); } g2d.dispose(); }
/* * (non-Javadoc) * * @see org.jvnet.flamingo.ribbon.ui.BasicRibbonUI#paintTaskArea(java.awt. * Graphics , int, int, int, int) */ @Override protected void paintTaskArea(Graphics g, int x, int y, int width, int height) { if (this.ribbon.getTaskCount() == 0) return; Graphics2D g2d = (Graphics2D) g.create(); RibbonTask selectedTask = this.ribbon.getSelectedTask(); JRibbonTaskToggleButton selectedTaskButton = this.taskToggleButtons.get(selectedTask); Rectangle selectedTaskButtonBounds = selectedTaskButton.getBounds(); Point converted = SwingUtilities.convertPoint( selectedTaskButton.getParent(), selectedTaskButtonBounds.getLocation(), this.ribbon); float radius = SubstanceSizeUtils.getClassicButtonCornerRadius( SubstanceSizeUtils.getComponentFontSize(this.ribbon)); float borderDelta = SubstanceSizeUtils.getBorderStrokeWidth() / 2.0f; SubstanceBorderPainter borderPainter = SubstanceCoreUtilities.getBorderPainter(this.ribbon); float borderThickness = SubstanceSizeUtils.getBorderStrokeWidth(); AbstractRibbonBand band = (selectedTask.getBandCount() == 0) ? null : selectedTask.getBand(0); SubstanceColorScheme borderScheme = SubstanceColorSchemeUtilities.getColorScheme( band, ColorSchemeAssociationKind.BORDER, ComponentState.ENABLED); Rectangle taskToggleButtonsViewportBounds = taskToggleButtonsScrollablePanel.getView().getParent().getBounds(); taskToggleButtonsViewportBounds.setLocation( SwingUtilities.convertPoint( taskToggleButtonsScrollablePanel, taskToggleButtonsViewportBounds.getLocation(), this.ribbon)); int startSelectedX = Math.max(converted.x + 1, (int) taskToggleButtonsViewportBounds.getMinX()); startSelectedX = Math.min(startSelectedX, (int) taskToggleButtonsViewportBounds.getMaxX()); int endSelectedX = Math.min( converted.x + selectedTaskButtonBounds.width - 1, (int) taskToggleButtonsViewportBounds.getMaxX()); endSelectedX = Math.max(endSelectedX, (int) taskToggleButtonsViewportBounds.getMinX()); Shape outerContour = RibbonBorderShaper.getRibbonBorderOutline( this.ribbon, x + borderDelta, x + width - borderDelta, startSelectedX - borderThickness, endSelectedX + borderThickness, converted.y + borderDelta, y + borderDelta, y + height - borderDelta, radius); Shape innerContour = RibbonBorderShaper.getRibbonBorderOutline( this.ribbon, x + borderDelta + borderThickness, x + width - borderThickness - borderDelta, startSelectedX - borderThickness, endSelectedX + borderThickness, converted.y + borderDelta + borderThickness, y + borderDelta + borderThickness, y + height - borderThickness - borderDelta, radius); g2d.setColor( SubstanceColorSchemeUtilities.getColorScheme(band, ComponentState.ENABLED) .getBackgroundFillColor()); g2d.clipRect(x, y, width, height + 2); g2d.fill(outerContour); // g2d.setColor(Color.red); // g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, // RenderingHints.VALUE_ANTIALIAS_ON); // g2d.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, // RenderingHints.VALUE_STROKE_PURE); // g2d.setStroke(new BasicStroke(0.5f)); // g2d.draw(outerContour); // g2d.setColor(Color.blue); // g2d.draw(innerContour); borderPainter.paintBorder( g2d, this.ribbon, width, height + selectedTaskButtonBounds.height + 1, outerContour, innerContour, borderScheme); // check whether the currently selected task is a contextual task RibbonTask selected = selectedTask; RibbonContextualTaskGroup contextualGroup = selected.getContextualGroup(); if (contextualGroup != null) { // paint a small gradient directly below the task area Insets ins = this.ribbon.getInsets(); int topY = ins.top + getTaskbarHeight(); int bottomY = topY + 5; Color hueColor = contextualGroup.getHueColor(); Paint paint = new GradientPaint( 0, topY, FlamingoUtilities.getAlphaColor( hueColor, (int) (255 * RibbonContextualTaskGroup.HUE_ALPHA)), 0, bottomY, FlamingoUtilities.getAlphaColor(hueColor, 0)); g2d.setPaint(paint); g2d.clip(outerContour); g2d.fillRect(0, topY, width, bottomY - topY + 1); } // paint outlines of the contextual task groups // paintContextualTaskGroupsOutlines(g); g2d.dispose(); }
/* * (non-Javadoc) * * @see * org.jvnet.flamingo.common.ui.BasicCommandButtonUI#paint(java.awt.Graphics * , javax.swing.JComponent) */ @Override public void paint(Graphics g, JComponent c) { Graphics2D g2d = (Graphics2D) g.create(); g2d.setFont( FlamingoUtilities.getFont(this.commandButton, "Ribbon.font", "Button.font", "Panel.font")); this.layoutInfo = this.layoutManager.getLayoutInfo(this.commandButton, g); commandButton.putClientProperty("icon.bounds", layoutInfo.iconRect); commandButton.putClientProperty("icon", commandButton.getIcon()); if (this.isPaintingBackground()) { this.paintButtonBackground(g2d, new Rectangle(0, 0, c.getWidth(), c.getHeight())); } // decide which command button model should be used to // compute the foreground color of the command button's text boolean useActionAreaForFg = layoutInfo.isTextInActionArea; StateTransitionTracker transitionTrackerForFg = useActionAreaForFg ? this.getActionTransitionTracker() : this.getPopupTransitionTracker(); ModelStateInfo modelStateInfoForFg = transitionTrackerForFg.getModelStateInfo(); ComponentState currStateForFg = modelStateInfoForFg.getCurrModelState(); Color fgColor = this.commandButton.getForeground(); if (fgColor instanceof UIResource) { float buttonAlpha = SubstanceColorSchemeUtilities.getAlpha(this.commandButton, currStateForFg); fgColor = SubstanceTextUtilities.getForegroundColor( this.commandButton, this.commandButton.getText(), modelStateInfoForFg, buttonAlpha); } if (layoutInfo.textLayoutInfoList != null) { for (CommandButtonLayoutManager.TextLayoutInfo mainTextLayoutInfo : layoutInfo.textLayoutInfoList) { if (mainTextLayoutInfo.text != null) { SubstanceTextUtilities.paintText( g2d, c, mainTextLayoutInfo.textRect, mainTextLayoutInfo.text, -1, g2d.getFont(), fgColor, g2d.getClipBounds()); } } } if (layoutInfo.extraTextLayoutInfoList != null) { Color disabledFgColor = SubstanceColorSchemeUtilities.getColorScheme( this.commandButton, ComponentState.DISABLED_UNSELECTED) .getForegroundColor(); float buttonAlpha = SubstanceColorSchemeUtilities.getAlpha( this.commandButton, ComponentState.DISABLED_UNSELECTED); if (buttonAlpha < 1.0f) { Color bgFillColor = SubstanceColorUtilities.getBackgroundFillColor(this.commandButton); disabledFgColor = SubstanceColorUtilities.getInterpolatedColor(disabledFgColor, bgFillColor, buttonAlpha); } if (currStateForFg.isDisabled()) { disabledFgColor = SubstanceColorUtilities.getInterpolatedColor( disabledFgColor, SubstanceColorUtilities.getBackgroundFillColor(c), 0.5); } for (CommandButtonLayoutManager.TextLayoutInfo extraTextLayoutInfo : layoutInfo.extraTextLayoutInfoList) { if (extraTextLayoutInfo.text != null) { SubstanceTextUtilities.paintText( g2d, c, extraTextLayoutInfo.textRect, extraTextLayoutInfo.text, -1, g2d.getFont(), disabledFgColor, g2d.getClipBounds()); } } } if (layoutInfo.iconRect != null) { this.paintButtonIcon(g2d, layoutInfo.iconRect); } if (layoutInfo.popupActionRect.getWidth() > 0) { paintPopupActionIcon(g2d, layoutInfo.popupActionRect); } if (this.isPaintingSeparators() && (layoutInfo.separatorArea != null)) { if (layoutInfo.separatorOrientation == CommandButtonSeparatorOrientation.HORIZONTAL) { this.paintButtonHorizontalSeparator(g2d, layoutInfo.separatorArea); } else { this.paintButtonVerticalSeparator(g2d, layoutInfo.separatorArea); } } // g2d.setColor(Color.red); // g2d.draw(layoutInfo.iconRect); // g2d.setColor(Color.blue); // if (layoutInfo.textLayoutInfoList != null) { // for (CommandButtonLayoutManager.TextLayoutInfo mainTextLayoutInfo : // layoutInfo.textLayoutInfoList) { // if (mainTextLayoutInfo.text != null) { // g2d.draw(mainTextLayoutInfo.textRect); // } // } // } // g2d.setColor(Color.magenta); // if (layoutInfo.extraTextLayoutInfoList != null) { // for (CommandButtonLayoutManager.TextLayoutInfo extraTextLayoutInfo : // layoutInfo.extraTextLayoutInfoList) { // if (extraTextLayoutInfo.text != null) { // g2d.draw(extraTextLayoutInfo.textRect); // } // } // } // g2d.setColor(Color.green); // g2d.draw(layoutInfo.popupActionRect); g2d.dispose(); }
public Component getTableCellRendererComponentWithSubstance( JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { TableUI tableUI = table.getUI(); SubstanceTableUI ui = (SubstanceTableUI) tableUI; // Recompute the focus indication to prevent flicker - JTable // registers a listener on selection changes and repaints the // relevant cell before our listener (in TableUI) gets the // chance to start the fade sequence. The result is that the // first frame uses full opacity, and the next frame starts the // fade sequence. So, we use the UI delegate to compute the // focus indication. hasFocus = ui.isFocusedCell(row, column); TableCellId cellId = new TableCellId(row, column); StateTransitionTracker.ModelStateInfo modelStateInfo = ui.getModelStateInfo(cellId); ComponentState currState = ui.getCellState(cellId); // special case for drop location JTable.DropLocation dropLocation = table.getDropLocation(); boolean isDropLocation = (dropLocation != null && !dropLocation.isInsertRow() && !dropLocation.isInsertColumn() && dropLocation.getRow() == row && dropLocation.getColumn() == column); if (!isDropLocation && (modelStateInfo != null)) { if (ui.hasRolloverAnimations() || ui.hasSelectionAnimations()) { Map<ComponentState, StateContributionInfo> activeStates = modelStateInfo.getStateContributionMap(); SubstanceColorScheme colorScheme = getColorSchemeForState(table, ui, currState); if (currState.isDisabled() || (activeStates == null) || (activeStates.size() == 1)) { super.setForeground(new ColorUIResource(colorScheme.getForegroundColor())); } else { float aggrRed = 0; float aggrGreen = 0; float aggrBlue = 0; for (Map.Entry<ComponentState, StateTransitionTracker.StateContributionInfo> activeEntry : modelStateInfo.getStateContributionMap().entrySet()) { ComponentState activeState = activeEntry.getKey(); SubstanceColorScheme scheme = getColorSchemeForState(table, ui, activeState); Color schemeFg = scheme.getForegroundColor(); float contribution = activeEntry.getValue().getContribution(); aggrRed += schemeFg.getRed() * contribution; aggrGreen += schemeFg.getGreen() * contribution; aggrBlue += schemeFg.getBlue() * contribution; } super.setForeground( new ColorUIResource(new Color((int) aggrRed, (int) aggrGreen, (int) aggrBlue))); } } else { SubstanceColorScheme scheme = getColorSchemeForState(table, ui, currState); super.setForeground(new ColorUIResource(scheme.getForegroundColor())); } } else { SubstanceColorScheme scheme = getColorSchemeForState(table, ui, currState); if (isDropLocation) { scheme = SubstanceColorSchemeUtilities.getColorScheme( table, ColorSchemeAssociationKind.TEXT_HIGHLIGHT, currState); } super.setForeground(new ColorUIResource(scheme.getForegroundColor())); } SubstanceStripingUtils.applyStripedBackground(table, row, this); this.setFont(table.getFont()); TableCellId cellFocusId = new TableCellId(row, column); StateTransitionTracker focusStateTransitionTracker = ui.getStateTransitionTracker(cellFocusId); Insets regInsets = ui.getCellRendererInsets(); if (hasFocus || (focusStateTransitionTracker != null)) { SubstanceTableCellBorder border = new SubstanceTableCellBorder(regInsets, ui, cellFocusId); // System.out.println("[" + row + ":" + column + "] hasFocus : " // + hasFocus + ", focusState : " + focusState); if (focusStateTransitionTracker != null) { border.setAlpha(focusStateTransitionTracker.getFocusStrength(hasFocus)); } // special case for tables with no grids if (!table.getShowHorizontalLines() && !table.getShowVerticalLines()) { this.setBorder( new CompoundBorder( new EmptyBorder(table.getRowMargin() / 2, 0, table.getRowMargin() / 2, 0), border)); } else { this.setBorder(border); } } else { this.setBorder( new EmptyBorder(regInsets.top, regInsets.left, regInsets.bottom, regInsets.right)); } setValue(Math.min(100, getBarStatus(value))); setString(getDescription(value)); this.setOpaque(false); this.setEnabled(table.isEnabled()); return this; }
/** * Returns the collection of color schemes in the specified URL. * * @param resourceName Name of the resource containing the description of Substance color schemes. * @return The collection of color schemes in the specified URL. * @since version 6.0 */ public static ColorSchemes getColorSchemes(String resourceName) { ClassLoader cl = SubstanceCoreUtilities.getClassLoaderForResources(); return SubstanceColorSchemeUtilities.getColorSchemes(cl.getResource(resourceName)); }
/** * Returns the collection of color schemes in the specified URL. * * @param url URL that points to a resource containing the description of Substance color schemes. * @return The collection of color schemes in the specified URL. * @since version 5.2 */ public static ColorSchemes getColorSchemes(URL url) { return SubstanceColorSchemeUtilities.getColorSchemes(url); }