SwingCommitList.java

  1. /*
  2.  * Copyright (C) 2008, Shawn O. Pearce <spearce@spearce.org> and others
  3.  *
  4.  * This program and the accompanying materials are made available under the
  5.  * terms of the Eclipse Distribution License v. 1.0 which is available at
  6.  * https://www.eclipse.org/org/documents/edl-v10.php.
  7.  *
  8.  * SPDX-License-Identifier: BSD-3-Clause
  9.  */

  10. package org.eclipse.jgit.awtui;

  11. import java.awt.Color;
  12. import java.util.LinkedList;

  13. import org.eclipse.jgit.revplot.PlotCommitList;
  14. import org.eclipse.jgit.revplot.PlotLane;

  15. class SwingCommitList extends PlotCommitList<SwingCommitList.SwingLane> {
  16.     final LinkedList<Color> colors;

  17.     SwingCommitList() {
  18.         colors = new LinkedList<>();
  19.         repackColors();
  20.     }

  21.     private void repackColors() {
  22.         colors.add(Color.green);
  23.         colors.add(Color.blue);
  24.         colors.add(Color.red);
  25.         colors.add(Color.magenta);
  26.         colors.add(Color.darkGray);
  27.         colors.add(Color.yellow.darker());
  28.         colors.add(Color.orange);
  29.     }

  30.     /** {@inheritDoc} */
  31.     @Override
  32.     protected SwingLane createLane() {
  33.         final SwingLane lane = new SwingLane();
  34.         if (colors.isEmpty())
  35.             repackColors();
  36.         lane.color = colors.removeFirst();
  37.         return lane;
  38.     }

  39.     /** {@inheritDoc} */
  40.     @Override
  41.     protected void recycleLane(SwingLane lane) {
  42.         colors.add(lane.color);
  43.     }

  44.     static class SwingLane extends PlotLane {
  45.         private static final long serialVersionUID = 1L;
  46.         Color color;
  47.     }
  48. }