summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.ui/src/org/eclipse
diff options
context:
space:
mode:
authorMykola Nikishov <mn@mn.com.ua>2009-10-09 21:57:59 +0300
committerShawn O. Pearce <spearce@spearce.org>2009-10-31 16:35:10 -0700
commitcf2edb65180b66bb191a7db1dfa24eeb5801d246 (patch)
tree20605f49e223661dbdd1ee195bb8ab36495b3124 /org.eclipse.jgit.ui/src/org/eclipse
parent99ab22c474ffccbdd9081959b80f3b4bd1967c84 (diff)
downloadjgit-cf2edb65180b66bb191a7db1dfa24eeb5801d246.tar.gz
jgit-cf2edb65180b66bb191a7db1dfa24eeb5801d246.zip
Move AWT UI code to new org.eclipse.jgit.ui bundle
This new UI bundle contains the org.eclipse.jgit.awtui package, which was moved out of the org.eclipse.jgit bundle. org.eclipse.jgit.pgm depends on org.eclipse.jgit.ui, so we need to update the classpath and make_jgit.sh to include it. This move takes the awtui classes out of the Maven build, which means we are no longer able to distribute these classes to our downstream Maven customers. The entire Maven package structure needs to be overhauled so that Eclipse bundle matches 1:1 with the Maven artifact. Bug: https://bugs.eclipse.org/291124 Change-Id: Ibf1a9968387e3d11fdce54592f710ec4cc7f1ddb Signed-off-by: Mykola Nikishov <mn@mn.com.ua> Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Diffstat (limited to 'org.eclipse.jgit.ui/src/org/eclipse')
-rw-r--r--org.eclipse.jgit.ui/src/org/eclipse/jgit/awtui/AWTPlotRenderer.java190
-rw-r--r--org.eclipse.jgit.ui/src/org/eclipse/jgit/awtui/AwtAuthenticator.java197
-rw-r--r--org.eclipse.jgit.ui/src/org/eclipse/jgit/awtui/CommitGraphPane.java256
-rw-r--r--org.eclipse.jgit.ui/src/org/eclipse/jgit/awtui/SwingCommitList.java87
4 files changed, 730 insertions, 0 deletions
diff --git a/org.eclipse.jgit.ui/src/org/eclipse/jgit/awtui/AWTPlotRenderer.java b/org.eclipse.jgit.ui/src/org/eclipse/jgit/awtui/AWTPlotRenderer.java
new file mode 100644
index 0000000000..007a0e8d46
--- /dev/null
+++ b/org.eclipse.jgit.ui/src/org/eclipse/jgit/awtui/AWTPlotRenderer.java
@@ -0,0 +1,190 @@
+/*
+ * Copyright (C) 2008, Robin Rosenberg <robin.rosenberg@dewire.com>
+ * Copyright (C) 2008, Shawn O. Pearce <spearce@spearce.org>
+ * and other copyright owners as documented in the project's IP log.
+ *
+ * This program and the accompanying materials are made available
+ * under the terms of the Eclipse Distribution License v1.0 which
+ * accompanies this distribution, is reproduced below, and is
+ * available at http://www.eclipse.org/org/documents/edl-v10.php
+ *
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * - Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided
+ * with the distribution.
+ *
+ * - Neither the name of the Eclipse Foundation, Inc. nor the
+ * names of its contributors may be used to endorse or promote
+ * products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+ * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+package org.eclipse.jgit.awtui;
+
+import java.awt.Color;
+import java.awt.Graphics;
+import java.awt.Graphics2D;
+import java.awt.Polygon;
+
+import org.eclipse.jgit.awtui.CommitGraphPane.GraphCellRender;
+import org.eclipse.jgit.awtui.SwingCommitList.SwingLane;
+import org.eclipse.jgit.lib.Constants;
+import org.eclipse.jgit.lib.Ref;
+import org.eclipse.jgit.revplot.AbstractPlotRenderer;
+import org.eclipse.jgit.revplot.PlotCommit;
+
+final class AWTPlotRenderer extends AbstractPlotRenderer<SwingLane, Color> {
+
+ final GraphCellRender cell;
+
+ Graphics2D g;
+
+ AWTPlotRenderer(final GraphCellRender c) {
+ cell = c;
+ }
+
+ void paint(final Graphics in, final PlotCommit<SwingLane> commit) {
+ g = (Graphics2D) in.create();
+ try {
+ final int h = cell.getHeight();
+ g.setColor(cell.getBackground());
+ g.fillRect(0, 0, cell.getWidth(), h);
+ if (commit != null)
+ paintCommit(commit, h);
+ } finally {
+ g.dispose();
+ g = null;
+ }
+ }
+
+ @Override
+ protected void drawLine(final Color color, int x1, int y1, int x2,
+ int y2, int width) {
+ if (y1 == y2) {
+ x1 -= width / 2;
+ x2 -= width / 2;
+ } else if (x1 == x2) {
+ y1 -= width / 2;
+ y2 -= width / 2;
+ }
+
+ g.setColor(color);
+ g.setStroke(CommitGraphPane.stroke(width));
+ g.drawLine(x1, y1, x2, y2);
+ }
+
+ @Override
+ protected void drawCommitDot(final int x, final int y, final int w,
+ final int h) {
+ g.setColor(Color.blue);
+ g.setStroke(CommitGraphPane.strokeCache[1]);
+ g.fillOval(x, y, w, h);
+ g.setColor(Color.black);
+ g.drawOval(x, y, w, h);
+ }
+
+ @Override
+ protected void drawBoundaryDot(final int x, final int y, final int w,
+ final int h) {
+ g.setColor(cell.getBackground());
+ g.setStroke(CommitGraphPane.strokeCache[1]);
+ g.fillOval(x, y, w, h);
+ g.setColor(Color.black);
+ g.drawOval(x, y, w, h);
+ }
+
+ @Override
+ protected void drawText(final String msg, final int x, final int y) {
+ final int texth = g.getFontMetrics().getHeight();
+ final int y0 = y - texth/2 + (cell.getHeight() - texth)/2;
+ g.setColor(cell.getForeground());
+ g.drawString(msg, x, y0 + texth - g.getFontMetrics().getDescent());
+ }
+
+ @Override
+ protected Color laneColor(final SwingLane myLane) {
+ return myLane != null ? myLane.color : Color.black;
+ }
+
+ void paintTriangleDown(final int cx, final int y, final int h) {
+ final int tipX = cx;
+ final int tipY = y + h;
+ final int baseX1 = cx - 10 / 2;
+ final int baseX2 = tipX + 10 / 2;
+ final int baseY = y;
+ final Polygon triangle = new Polygon();
+ triangle.addPoint(tipX, tipY);
+ triangle.addPoint(baseX1, baseY);
+ triangle.addPoint(baseX2, baseY);
+ g.fillPolygon(triangle);
+ g.drawPolygon(triangle);
+ }
+
+ @Override
+ protected int drawLabel(int x, int y, Ref ref) {
+ String txt;
+ String name = ref.getOrigName();
+ if (name.startsWith(Constants.R_HEADS)) {
+ g.setBackground(Color.GREEN);
+ txt = name.substring(Constants.R_HEADS.length());
+ } else if (name.startsWith(Constants.R_REMOTES)){
+ g.setBackground(Color.LIGHT_GRAY);
+ txt = name.substring(Constants.R_REMOTES.length());
+ } else if (name.startsWith(Constants.R_TAGS)){
+ g.setBackground(Color.YELLOW);
+ txt = name.substring(Constants.R_TAGS.length());
+ } else {
+ // Whatever this would be
+ g.setBackground(Color.WHITE);
+ if (name.startsWith(Constants.R_REFS))
+ txt = name.substring(Constants.R_REFS.length());
+ else
+ txt = name; // HEAD and such
+ }
+ if (ref.getPeeledObjectId() != null) {
+ float[] colorComponents = g.getBackground().getRGBColorComponents(null);
+ colorComponents[0] *= 0.9;
+ colorComponents[1] *= 0.9;
+ colorComponents[2] *= 0.9;
+ g.setBackground(new Color(colorComponents[0],colorComponents[1],colorComponents[2]));
+ }
+ if (txt.length() > 12)
+ txt = txt.substring(0,11) + "\u2026"; // ellipsis "…" (in UTF-8)
+
+ final int texth = g.getFontMetrics().getHeight();
+ int textw = g.getFontMetrics().stringWidth(txt);
+ g.setColor(g.getBackground());
+ int arcHeight = texth/4;
+ int y0 = y - texth/2 + (cell.getHeight() - texth)/2;
+ g.fillRoundRect(x , y0, textw + arcHeight*2, texth -1, arcHeight, arcHeight);
+ g.setColor(g.getColor().darker());
+ g.drawRoundRect(x, y0, textw + arcHeight*2, texth -1 , arcHeight, arcHeight);
+ g.setColor(Color.BLACK);
+ g.drawString(txt, x + arcHeight, y0 + texth - g.getFontMetrics().getDescent());
+
+ return arcHeight * 3 + textw;
+ }
+}
diff --git a/org.eclipse.jgit.ui/src/org/eclipse/jgit/awtui/AwtAuthenticator.java b/org.eclipse.jgit.ui/src/org/eclipse/jgit/awtui/AwtAuthenticator.java
new file mode 100644
index 0000000000..995fe9a935
--- /dev/null
+++ b/org.eclipse.jgit.ui/src/org/eclipse/jgit/awtui/AwtAuthenticator.java
@@ -0,0 +1,197 @@
+/*
+ * Copyright (C) 2008, Shawn O. Pearce <spearce@spearce.org>
+ * and other copyright owners as documented in the project's IP log.
+ *
+ * This program and the accompanying materials are made available
+ * under the terms of the Eclipse Distribution License v1.0 which
+ * accompanies this distribution, is reproduced below, and is
+ * available at http://www.eclipse.org/org/documents/edl-v10.php
+ *
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * - Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided
+ * with the distribution.
+ *
+ * - Neither the name of the Eclipse Foundation, Inc. nor the
+ * names of its contributors may be used to endorse or promote
+ * products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+ * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+package org.eclipse.jgit.awtui;
+
+import java.awt.Container;
+import java.awt.GridBagConstraints;
+import java.awt.GridBagLayout;
+import java.awt.Insets;
+import java.net.Authenticator;
+import java.net.PasswordAuthentication;
+import java.util.ArrayList;
+import java.util.Collection;
+
+import javax.swing.JLabel;
+import javax.swing.JOptionPane;
+import javax.swing.JPanel;
+import javax.swing.JPasswordField;
+import javax.swing.JTextField;
+
+/** Basic network prompt for username/password when using AWT. */
+public class AwtAuthenticator extends Authenticator {
+ private static final AwtAuthenticator me = new AwtAuthenticator();
+
+ /** Install this authenticator implementation into the JVM. */
+ public static void install() {
+ setDefault(me);
+ }
+
+ /**
+ * Add a cached authentication for future use.
+ *
+ * @param ca
+ * the information we should remember.
+ */
+ public static void add(final CachedAuthentication ca) {
+ synchronized (me) {
+ me.cached.add(ca);
+ }
+ }
+
+ private final Collection<CachedAuthentication> cached = new ArrayList<CachedAuthentication>();
+
+ @Override
+ protected PasswordAuthentication getPasswordAuthentication() {
+ for (final CachedAuthentication ca : cached) {
+ if (ca.host.equals(getRequestingHost())
+ && ca.port == getRequestingPort())
+ return ca.toPasswordAuthentication();
+ }
+
+ final GridBagConstraints gbc = new GridBagConstraints(0, 0, 1, 1, 1, 1,
+ GridBagConstraints.NORTHWEST, GridBagConstraints.NONE,
+ new Insets(0, 0, 0, 0), 0, 0);
+ final Container panel = new JPanel();
+ panel.setLayout(new GridBagLayout());
+
+ final StringBuilder instruction = new StringBuilder();
+ instruction.append("Enter username and password for ");
+ if (getRequestorType() == RequestorType.PROXY) {
+ instruction.append(getRequestorType());
+ instruction.append(" ");
+ instruction.append(getRequestingHost());
+ if (getRequestingPort() > 0) {
+ instruction.append(":");
+ instruction.append(getRequestingPort());
+ }
+ } else {
+ instruction.append(getRequestingURL());
+ }
+
+ gbc.weightx = 1.0;
+ gbc.gridwidth = GridBagConstraints.REMAINDER;
+ gbc.gridx = 0;
+ panel.add(new JLabel(instruction.toString()), gbc);
+ gbc.gridy++;
+
+ gbc.gridwidth = GridBagConstraints.RELATIVE;
+
+ // Username
+ //
+ final JTextField username;
+ gbc.fill = GridBagConstraints.NONE;
+ gbc.gridx = 0;
+ gbc.weightx = 1;
+ panel.add(new JLabel("Username:"), gbc);
+
+ gbc.gridx = 1;
+ gbc.fill = GridBagConstraints.HORIZONTAL;
+ gbc.weighty = 1;
+ username = new JTextField(20);
+ panel.add(username, gbc);
+ gbc.gridy++;
+
+ // Password
+ //
+ final JPasswordField password;
+ gbc.fill = GridBagConstraints.NONE;
+ gbc.gridx = 0;
+ gbc.weightx = 1;
+ panel.add(new JLabel("Password:"), gbc);
+
+ gbc.gridx = 1;
+ gbc.fill = GridBagConstraints.HORIZONTAL;
+ gbc.weighty = 1;
+ password = new JPasswordField(20);
+ panel.add(password, gbc);
+ gbc.gridy++;
+
+ if (JOptionPane.showConfirmDialog(null, panel,
+ "Authentication Required", JOptionPane.OK_CANCEL_OPTION,
+ JOptionPane.QUESTION_MESSAGE) == JOptionPane.OK_OPTION) {
+ final CachedAuthentication ca = new CachedAuthentication(
+ getRequestingHost(), getRequestingPort(), username
+ .getText(), new String(password.getPassword()));
+ cached.add(ca);
+ return ca.toPasswordAuthentication();
+ }
+
+ return null; // cancel
+ }
+
+ /** Authentication data to remember and reuse. */
+ public static class CachedAuthentication {
+ final String host;
+
+ final int port;
+
+ final String user;
+
+ final String pass;
+
+ /**
+ * Create a new cached authentication.
+ *
+ * @param aHost
+ * system this is for.
+ * @param aPort
+ * port number of the service.
+ * @param aUser
+ * username at the service.
+ * @param aPass
+ * password at the service.
+ */
+ public CachedAuthentication(final String aHost, final int aPort,
+ final String aUser, final String aPass) {
+ host = aHost;
+ port = aPort;
+ user = aUser;
+ pass = aPass;
+ }
+
+ PasswordAuthentication toPasswordAuthentication() {
+ return new PasswordAuthentication(user, pass.toCharArray());
+ }
+ }
+}
diff --git a/org.eclipse.jgit.ui/src/org/eclipse/jgit/awtui/CommitGraphPane.java b/org.eclipse.jgit.ui/src/org/eclipse/jgit/awtui/CommitGraphPane.java
new file mode 100644
index 0000000000..da68c81953
--- /dev/null
+++ b/org.eclipse.jgit.ui/src/org/eclipse/jgit/awtui/CommitGraphPane.java
@@ -0,0 +1,256 @@
+/*
+ * Copyright (C) 2008, Shawn O. Pearce <spearce@spearce.org>
+ * and other copyright owners as documented in the project's IP log.
+ *
+ * This program and the accompanying materials are made available
+ * under the terms of the Eclipse Distribution License v1.0 which
+ * accompanies this distribution, is reproduced below, and is
+ * available at http://www.eclipse.org/org/documents/edl-v10.php
+ *
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * - Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided
+ * with the distribution.
+ *
+ * - Neither the name of the Eclipse Foundation, Inc. nor the
+ * names of its contributors may be used to endorse or promote
+ * products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+ * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+package org.eclipse.jgit.awtui;
+
+import java.awt.BasicStroke;
+import java.awt.Component;
+import java.awt.Graphics;
+import java.awt.Stroke;
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+
+import javax.swing.JTable;
+import javax.swing.ListSelectionModel;
+import javax.swing.table.AbstractTableModel;
+import javax.swing.table.DefaultTableCellRenderer;
+import javax.swing.table.JTableHeader;
+import javax.swing.table.TableCellRenderer;
+import javax.swing.table.TableColumn;
+import javax.swing.table.TableColumnModel;
+import javax.swing.table.TableModel;
+
+import org.eclipse.jgit.awtui.SwingCommitList.SwingLane;
+import org.eclipse.jgit.lib.PersonIdent;
+import org.eclipse.jgit.revplot.PlotCommit;
+import org.eclipse.jgit.revplot.PlotCommitList;
+
+/**
+ * Draws a commit graph in a JTable.
+ * <p>
+ * This class is currently a very primitive commit visualization tool. It shows
+ * a table of 3 columns:
+ * <ol>
+ * <li>Commit graph and short message</li>
+ * <li>Author name and email address</li>
+ * <li>Author date and time</li>
+ * </ul>
+ */
+public class CommitGraphPane extends JTable {
+ private static final long serialVersionUID = 1L;
+
+ private final SwingCommitList allCommits;
+
+ /** Create a new empty panel. */
+ public CommitGraphPane() {
+ allCommits = new SwingCommitList();
+ configureHeader();
+ setShowHorizontalLines(false);
+ setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
+ configureRowHeight();
+ }
+
+ private void configureRowHeight() {
+ int h = 0;
+ for (int i = 0; i<getColumnCount(); ++i) {
+ TableCellRenderer renderer = getDefaultRenderer(getColumnClass(i));
+ Component c = renderer.getTableCellRendererComponent(this, "ÅOj", false, false, 0, i);
+ h = Math.max(h, c.getPreferredSize().height);
+ }
+ setRowHeight(h + getRowMargin());
+ }
+
+ /**
+ * Get the commit list this pane renders from.
+ *
+ * @return the list the caller must populate.
+ */
+ public PlotCommitList getCommitList() {
+ return allCommits;
+ }
+
+ @Override
+ public void setModel(final TableModel dataModel) {
+ if (dataModel != null && !(dataModel instanceof CommitTableModel))
+ throw new ClassCastException("Must be special table model.");
+ super.setModel(dataModel);
+ }
+
+ @Override
+ protected TableModel createDefaultDataModel() {
+ return new CommitTableModel();
+ }
+
+ private void configureHeader() {
+ final JTableHeader th = getTableHeader();
+ final TableColumnModel cols = th.getColumnModel();
+
+ final TableColumn graph = cols.getColumn(0);
+ final TableColumn author = cols.getColumn(1);
+ final TableColumn date = cols.getColumn(2);
+
+ graph.setHeaderValue("");
+ author.setHeaderValue("Author");
+ date.setHeaderValue("Date");
+
+ graph.setCellRenderer(new GraphCellRender());
+ author.setCellRenderer(new NameCellRender());
+ date.setCellRenderer(new DateCellRender());
+ }
+
+ class CommitTableModel extends AbstractTableModel {
+ private static final long serialVersionUID = 1L;
+
+ PlotCommit<SwingLane> lastCommit;
+
+ PersonIdent lastAuthor;
+
+ public int getColumnCount() {
+ return 3;
+ }
+
+ public int getRowCount() {
+ return allCommits != null ? allCommits.size() : 0;
+ }
+
+ public Object getValueAt(final int rowIndex, final int columnIndex) {
+ final PlotCommit<SwingLane> c = allCommits.get(rowIndex);
+ switch (columnIndex) {
+ case 0:
+ return c;
+ case 1:
+ return authorFor(c);
+ case 2:
+ return authorFor(c);
+ default:
+ return null;
+ }
+ }
+
+ PersonIdent authorFor(final PlotCommit<SwingLane> c) {
+ if (c != lastCommit) {
+ lastCommit = c;
+ lastAuthor = c.getAuthorIdent();
+ }
+ return lastAuthor;
+ }
+ }
+
+ class NameCellRender extends DefaultTableCellRenderer {
+ private static final long serialVersionUID = 1L;
+
+ public Component getTableCellRendererComponent(final JTable table,
+ final Object value, final boolean isSelected,
+ final boolean hasFocus, final int row, final int column) {
+ final PersonIdent pi = (PersonIdent) value;
+
+ final String valueStr;
+ if (pi != null)
+ valueStr = pi.getName() + " <" + pi.getEmailAddress() + ">";
+ else
+ valueStr = "";
+ return super.getTableCellRendererComponent(table, valueStr,
+ isSelected, hasFocus, row, column);
+ }
+ }
+
+ class DateCellRender extends DefaultTableCellRenderer {
+ private static final long serialVersionUID = 1L;
+
+ private final DateFormat fmt = new SimpleDateFormat(
+ "yyyy-MM-dd HH:mm:ss");
+
+ public Component getTableCellRendererComponent(final JTable table,
+ final Object value, final boolean isSelected,
+ final boolean hasFocus, final int row, final int column) {
+ final PersonIdent pi = (PersonIdent) value;
+
+ final String valueStr;
+ if (pi != null)
+ valueStr = fmt.format(pi.getWhen());
+ else
+ valueStr = "";
+ return super.getTableCellRendererComponent(table, valueStr,
+ isSelected, hasFocus, row, column);
+ }
+ }
+
+ class GraphCellRender extends DefaultTableCellRenderer {
+ private static final long serialVersionUID = 1L;
+
+ private final AWTPlotRenderer renderer = new AWTPlotRenderer(this);
+
+ PlotCommit<SwingLane> commit;
+
+ public Component getTableCellRendererComponent(final JTable table,
+ final Object value, final boolean isSelected,
+ final boolean hasFocus, final int row, final int column) {
+ super.getTableCellRendererComponent(table, value, isSelected,
+ hasFocus, row, column);
+ commit = (PlotCommit<SwingLane>) value;
+ return this;
+ }
+
+ @Override
+ protected void paintComponent(final Graphics inputGraphics) {
+ if (inputGraphics == null)
+ return;
+ renderer.paint(inputGraphics, commit);
+ }
+ }
+
+ static final Stroke[] strokeCache;
+
+ static {
+ strokeCache = new Stroke[4];
+ for (int i = 1; i < strokeCache.length; i++)
+ strokeCache[i] = new BasicStroke(i);
+ }
+
+ static Stroke stroke(final int width) {
+ if (width < strokeCache.length)
+ return strokeCache[width];
+ return new BasicStroke(width);
+ }
+
+}
diff --git a/org.eclipse.jgit.ui/src/org/eclipse/jgit/awtui/SwingCommitList.java b/org.eclipse.jgit.ui/src/org/eclipse/jgit/awtui/SwingCommitList.java
new file mode 100644
index 0000000000..4a11964473
--- /dev/null
+++ b/org.eclipse.jgit.ui/src/org/eclipse/jgit/awtui/SwingCommitList.java
@@ -0,0 +1,87 @@
+/*
+ * Copyright (C) 2008, Shawn O. Pearce <spearce@spearce.org>
+ * and other copyright owners as documented in the project's IP log.
+ *
+ * This program and the accompanying materials are made available
+ * under the terms of the Eclipse Distribution License v1.0 which
+ * accompanies this distribution, is reproduced below, and is
+ * available at http://www.eclipse.org/org/documents/edl-v10.php
+ *
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * - Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided
+ * with the distribution.
+ *
+ * - Neither the name of the Eclipse Foundation, Inc. nor the
+ * names of its contributors may be used to endorse or promote
+ * products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+ * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+package org.eclipse.jgit.awtui;
+
+import java.awt.Color;
+import java.util.LinkedList;
+
+import org.eclipse.jgit.revplot.PlotCommitList;
+import org.eclipse.jgit.revplot.PlotLane;
+
+class SwingCommitList extends PlotCommitList<SwingCommitList.SwingLane> {
+ final LinkedList<Color> colors;
+
+ SwingCommitList() {
+ colors = new LinkedList<Color>();
+ repackColors();
+ }
+
+ private void repackColors() {
+ colors.add(Color.green);
+ colors.add(Color.blue);
+ colors.add(Color.red);
+ colors.add(Color.magenta);
+ colors.add(Color.darkGray);
+ colors.add(Color.yellow.darker());
+ colors.add(Color.orange);
+ }
+
+ @Override
+ protected SwingLane createLane() {
+ final SwingLane lane = new SwingLane();
+ if (colors.isEmpty())
+ repackColors();
+ lane.color = colors.removeFirst();
+ return lane;
+ }
+
+ @Override
+ protected void recycleLane(final SwingLane lane) {
+ colors.add(lane.color);
+ }
+
+ static class SwingLane extends PlotLane {
+ Color color;
+ }
+}