Package com.intellij.openapi.graph.builder.renderer

Source Code of com.intellij.openapi.graph.builder.renderer.AbstractColoredNodeCellRenderer$ShadowedLineBorder

package com.intellij.openapi.graph.builder.renderer;

import com.intellij.openapi.graph.view.Graph2DView;
import com.intellij.openapi.graph.view.NodeRealizer;
import com.intellij.openapi.util.ModificationTracker;
import com.intellij.ui.components.panels.NonOpaquePanel;

import javax.swing.*;
import javax.swing.border.LineBorder;
import java.awt.*;

/**
* User: Serega.Vasiliev
*/
public abstract class AbstractColoredNodeCellRenderer extends BasicNodeCellRenderer {
  private static final Color BORDER_COLOR = Color.LIGHT_GRAY;
  private static final Color SHADOW_BORDER_COLOR = Color.GRAY;

  protected AbstractColoredNodeCellRenderer(ModificationTracker modificationTracker) {
    super(modificationTracker);
  }

  protected JComponent getRendererComponent(Graph2DView graph2DView, NodeRealizer nodeRealizer, Object object, boolean sel) {
    final JPanel innerPanel = new JPanel(new BorderLayout());
    final NonOpaquePanel outerPanel = new NonOpaquePanel(innerPanel);

    outerPanel.setBorder(sel ? new LineBorder(getSelectionColor(), getSelectionBorderWidth(), true) : new ShadowedLineBorder());
    innerPanel.setBorder(sel ? new LineBorder(Color.ORANGE) : new LineBorder(Color.LIGHT_GRAY));

    tuneNode(nodeRealizer, innerPanel);

    return outerPanel;
  }

  abstract public void tuneNode(NodeRealizer realizer, final JPanel wrapper);

  public class ShadowedLineBorder extends LineBorder {
    public ShadowedLineBorder() {
      super(AbstractColoredNodeCellRenderer.BORDER_COLOR, getSelectionBorderWidth());
    }

    public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
      Color oldColor = g.getColor();

      g.setColor(SHADOW_BORDER_COLOR);

      final int selectionBorderWidth = getSelectionBorderWidth();
      g.fillRect(x + 2* selectionBorderWidth, y + height - selectionBorderWidth, width - 2*selectionBorderWidth, selectionBorderWidth);
      g.fillRect(x + width - selectionBorderWidth, y + 2*selectionBorderWidth, selectionBorderWidth, height - 2*selectionBorderWidth);

      g.setColor(oldColor);
    }
  }


  protected int getSelectionBorderWidth() {
    return 1;
  }

  protected Color getSelectionColor() {
    return Color.ORANGE;
  }
}
TOP

Related Classes of com.intellij.openapi.graph.builder.renderer.AbstractColoredNodeCellRenderer$ShadowedLineBorder

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.