/*
   * (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);
  }
Exemplo n.º 2
0
  /** Creates a new <code>Autumn</code> skin. */
  public AutumnSkin() {
    SubstanceSkin.ColorSchemes schemes =
        SubstanceSkin.getColorSchemes("org/pushingpixels/substance/api/skin/autumn.colorschemes");

    SubstanceColorScheme activeScheme = schemes.get("Autumn Active");
    SubstanceColorScheme enabledScheme = schemes.get("Autumn Enabled");
    SubstanceColorScheme disabledScheme = enabledScheme;

    SubstanceColorSchemeBundle defaultSchemeBundle =
        new SubstanceColorSchemeBundle(activeScheme, enabledScheme, disabledScheme);
    defaultSchemeBundle.registerColorScheme(
        disabledScheme, 0.6f, ComponentState.DISABLED_UNSELECTED);
    defaultSchemeBundle.registerColorScheme(activeScheme, 0.6f, ComponentState.DISABLED_SELECTED);

    this.registerDecorationAreaSchemeBundle(defaultSchemeBundle, DecorationAreaType.NONE);

    SubstanceColorSchemeBundle titlePaneSchemeBundle =
        new SubstanceColorSchemeBundle(activeScheme, enabledScheme, disabledScheme);
    titlePaneSchemeBundle.registerColorScheme(
        disabledScheme, 0.6f, ComponentState.DISABLED_UNSELECTED);
    titlePaneSchemeBundle.registerColorScheme(activeScheme, 0.6f, ComponentState.DISABLED_SELECTED);

    SubstanceColorScheme borderScheme = enabledScheme.saturate(0.2f);
    titlePaneSchemeBundle.registerColorScheme(
        borderScheme, ColorSchemeAssociationKind.BORDER, ComponentState.ENABLED);

    this.registerDecorationAreaSchemeBundle(
        titlePaneSchemeBundle,
        activeScheme,
        DecorationAreaType.PRIMARY_TITLE_PANE,
        DecorationAreaType.SECONDARY_TITLE_PANE);

    SubstanceColorScheme watermarkScheme = schemes.get("Autumn Watermark");

    this.registerAsDecorationArea(
        activeScheme,
        DecorationAreaType.PRIMARY_TITLE_PANE,
        DecorationAreaType.SECONDARY_TITLE_PANE,
        DecorationAreaType.HEADER);

    this.registerAsDecorationArea(
        watermarkScheme,
        DecorationAreaType.GENERAL,
        DecorationAreaType.FOOTER,
        DecorationAreaType.TOOLBAR);

    // add an overlay painter to paint a drop shadow along the top
    // edge of toolbars
    this.addOverlayPainter(TopShadowOverlayPainter.getInstance(), DecorationAreaType.TOOLBAR);

    // add an overlay painter to paint separator lines along the bottom
    // edges of title panes and menu bars
    this.bottomLineOverlayPainter = new BottomLineOverlayPainter(ColorSchemeSingleColorQuery.DARK);
    this.addOverlayPainter(
        this.bottomLineOverlayPainter,
        DecorationAreaType.PRIMARY_TITLE_PANE,
        DecorationAreaType.SECONDARY_TITLE_PANE,
        DecorationAreaType.HEADER);

    this.buttonShaper = new ClassicButtonShaper();
    this.fillPainter = new MatteFillPainter();
    this.borderPainter =
        new CompositeBorderPainter(
            "Autumn",
            new ClassicBorderPainter(),
            new DelegateBorderPainter(
                "Autumn Inner",
                new ClassicBorderPainter(),
                new ColorSchemeTransform() {
                  @Override
                  public SubstanceColorScheme transform(SubstanceColorScheme scheme) {
                    return scheme.tint(0.8f);
                  }
                }));

    this.highlightPainter = new ClassicHighlightPainter();

    MarbleNoiseDecorationPainter decorationPainter = new MarbleNoiseDecorationPainter();
    decorationPainter.setTextureAlpha(0.7f);
    this.decorationPainter = decorationPainter;
  }
  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;
  }