/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright 2015 Oracle and/or its affiliates. All rights reserved.
*
* Oracle and Java are registered trademarks of Oracle and/or its affiliates.
* Other names may be trademarks of their respective owners.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common
* Development and Distribution License("CDDL") (collectively, the
* "License"). You may not use this file except in compliance with the
* License. You can obtain a copy of the License at
* http://www.netbeans.org/cddl-gplv2.html
* or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
* specific language governing permissions and limitations under the
* License. When distributing the software, include this License Header
* Notice in each file and include the License file at
* nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the GPL Version 2 section of the License file that
* accompanied this code. If applicable, add the following below the
* License Header, with the fields enclosed by brackets [] replaced by
* your own identifying information:
* "Portions Copyrighted [year] [name of copyright owner]"
*
* If you wish your version of this file to be governed by only the CDDL
* or only the GPL Version 2, indicate your decision by adding
* "[Contributor] elects to include this software in this distribution
* under the [CDDL or GPL Version 2] license." If you do not indicate a
* single choice of license, a recipient has the option to distribute
* your version of this file under either the CDDL, the GPL Version 2 or
* to extend the choice of license to its licensees as provided above.
* However, if you add GPL Version 2 code and therefore, elected the GPL
* Version 2 license, then the option applies only if the new code is
* made subject to such option by the copyright holder.
*
* Contributor(s):
*
* Portions Copyrighted 2015 Sun Microsystems, Inc.
*/
package com.junichi11.netbeans.modules.github.issues.issue.ui;
import java.awt.Dimension;
import javax.swing.Icon;
import javax.swing.JPanel;
import org.eclipse.egit.github.core.Commit;
/**
*
* @author junichi11
*/
final class CommitPanel extends JPanel {
private static final long serialVersionUID = -7750751673488101906L;
private final Commit commit;
/**
* Creates new form CommitPanel
*/
public CommitPanel(Commit commit, Icon commiterIcon) {
this.commit = commit;
initComponents();
setCommiter(commiterIcon);
setMessage(commit.getMessage());
Dimension dim = messageLabel.getPreferredSize();
messageLabel.setMinimumSize(new Dimension(0, dim.height));
messageLabel.setPreferredSize(new Dimension(0, dim.height));
}
public Commit getCommit() {
return commit;
}
private void setCommiter(Icon commiterIcon) {
commiterLabel.setText(""); // NOI18N
commiterLabel.setIcon(commiterIcon);
commiterLabel.setToolTipText(commit.getCommitter().getName());
}
private void setMessage(String message) {
if (message == null) {
message = ""; // NOI18N
}
int indexOfLF = message.indexOf("\n"); // NOI18N
String moreMessage = null;
String firstLineMessage;
if (indexOfLF != -1) {
moreMessage = message.substring(indexOfLF + 1).trim();
firstLineMessage = message.substring(0, indexOfLF);
} else {
firstLineMessage = message;
}
messageLabel.setText(firstLineMessage);
messageLabel.setToolTipText(firstLineMessage);
boolean hasMore = moreMessage != null && !moreMessage.isEmpty();
moreButton.setVisible(hasMore);
if (hasMore) {
moreMessageLabel.setText("<html>" + moreMessage.replaceAll("\n", "<br />")); // NOI18N
} else {
moreMessageLabel.setText(" "); // NOI18N
}
moreMessageLabel.setVisible(false);
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
commiterLabel = new javax.swing.JLabel();
messageLabel = new javax.swing.JLabel();
moreMessageLabel = new javax.swing.JLabel();
moreButton = new javax.swing.JButton();
org.openide.awt.Mnemonics.setLocalizedText(commiterLabel, org.openide.util.NbBundle.getMessage(CommitPanel.class, "CommitPanel.commiterLabel.text")); // NOI18N
org.openide.awt.Mnemonics.setLocalizedText(messageLabel, org.openide.util.NbBundle.getMessage(CommitPanel.class, "CommitPanel.messageLabel.text")); // NOI18N
org.openide.awt.Mnemonics.setLocalizedText(moreMessageLabel, org.openide.util.NbBundle.getMessage(CommitPanel.class, "CommitPanel.moreMessageLabel.text")); // NOI18N
org.openide.awt.Mnemonics.setLocalizedText(moreButton, org.openide.util.NbBundle.getMessage(CommitPanel.class, "CommitPanel.moreButton.text")); // NOI18N
moreButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
moreButtonActionPerformed(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(6, 6, 6)
.addComponent(commiterLabel)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(messageLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(moreButton)
.addContainerGap())
.addGroup(layout.createSequentialGroup()
.addComponent(moreMessageLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addContainerGap())))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(commiterLabel)
.addComponent(messageLabel)
.addComponent(moreButton))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(moreMessageLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addContainerGap())
);
}// </editor-fold>//GEN-END:initComponents
private void moreButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_moreButtonActionPerformed
// toggle
moreMessageLabel.setVisible(!moreMessageLabel.isVisible());
}//GEN-LAST:event_moreButtonActionPerformed
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JLabel commiterLabel;
private javax.swing.JLabel messageLabel;
private javax.swing.JButton moreButton;
private javax.swing.JLabel moreMessageLabel;
// End of variables declaration//GEN-END:variables
}