Merge pull request #3468 from Akarshit/gsoc-CMtable

Added ellipses, improved error Panel, fixed a previous NPE bug
This commit is contained in:
Ben Fry
2015-07-16 12:33:31 -04:00
4 changed files with 39 additions and 34 deletions

View File

@@ -271,40 +271,38 @@ public class ContributionListPanel extends JPanel implements Scrollable, Contrib
label.setOpaque(true);
// return table.getDefaultRenderer(Icon.class).getTableCellRendererComponent(table, icon, isSelected, false, row, column);
} else if (column == 1) {
//TODO add ellipses, currently the height of JTextPane = height of font + 4
JTextPane name = new JTextPane();
name.setContentType("text/html");
name.setEditable(false);
if(!contribution.isCompatible(Base.getRevision())){
name.setForeground(Color.LIGHT_GRAY);
// Generating ellipses based on fontMetrics
FontMetrics fontMetrics = table.getFontMetrics(table.getFont());
int colSize = table.getColumnModel().getColumn(1).getWidth();
String sentence = contribution.getSentence();
int currentWidth = table.getFontMetrics(table.getFont().deriveFont(Font.BOLD)).stringWidth(contribution.getName());
int ellipsesWidth = fontMetrics.stringWidth(" ...");
String name = "<html><body><b>" + contribution.getName() + "</b>";
if (sentence == null) {
label.setText(name + "</body></html>");
} else {
sentence = " - " + sentence;
currentWidth += ellipsesWidth;
int i = 0;
for (i = 0; i < sentence.length(); i++) {
currentWidth += fontMetrics.charWidth(sentence.charAt(i));
if (currentWidth >= colSize) {
break;
}
}
label.setText(name + sentence.substring(0, i) + " ...</body></html>");
}
if (!contribution.isCompatible(Base.getRevision())) {
label.setForeground(Color.LIGHT_GRAY);
}
name.setText("<html><body><b>" + contribution.getName() + "</b> - "
+ contribution.getSentence() + "</body></html>");
int textHeight = table.getFontMetrics(table.getFont().deriveFont(Font.BOLD)).getHeight() + 4;
GroupLayout layout = new GroupLayout(label);
layout.setAutoCreateGaps(true);
layout.setHorizontalGroup(layout.createSequentialGroup()
.addComponent(name));
layout.setVerticalGroup(layout
.createSequentialGroup()
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED,
GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE)
.addComponent(name, 0,
textHeight,
textHeight)
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED,
GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE));
if (table.isRowSelected(row)) {
label.setBackground(Color.BLUE);
name.setOpaque(false);
}
label.setOpaque(true);
label.setLayout(layout);
} else {
label = new JLabel(
contribution.isSpecial() ? Toolkit
.getLibIcon("icons/pde-16.png") : null);
contribution.isSpecial() ? Toolkit
.getLibIcon("icons/pde-16.png") : null);
StringBuilder name = new StringBuilder("");
String authorList = contribution.getAuthorList();
if (authorList != null) {

View File

@@ -486,6 +486,9 @@ public class ContributionListing {
String getLatestVersion(Contribution contribution) {
Contribution newestContrib = getAvailableContribution(contribution);
if(newestContrib == null){
return null;
}
String latestVersion = newestContrib.getPrettyVersion();
if (latestVersion != null && !latestVersion.isEmpty()) {
if (latestVersion.toLowerCase().startsWith("build")) // For Python mode

View File

@@ -262,12 +262,14 @@ public class ContributionTab {
layout.setAutoCreateGaps(true);
layout.setAutoCreateContainerGaps(true);
errorPanel.setLayout(layout);
errorPanel.setBorder(BorderFactory.createMatteBorder(2, 0, 0, 0, Color.BLACK));
errorMessage = new JTextPane();
errorMessage.setEditable(false);
errorMessage.setText("Could not connect to the Processing server. "
+ "Contributions cannot be installed or updated without an Internet connection. "
+ "Please verify your network connection again, then try connecting again.");
errorMessage.setMaximumSize(new Dimension(450, 50));
errorMessage.setContentType("text/html");
errorMessage.setText("<html><body>Could not connect to the Processing server.<br>"
+ "Contributions cannot be installed or updated without an Internet connection.<br>"
+ "Please verify your network connection again, then try connecting again.</body></html>");
errorMessage.setMaximumSize(new Dimension(550, 50));
errorMessage.setOpaque(false);
StyledDocument doc = errorMessage.getStyledDocument();
@@ -312,7 +314,7 @@ public class ContributionTab {
layout.setVerticalGroup(layout
.createSequentialGroup()
.addGroup(layout.createParallelGroup().addComponent(errorMessage)
.addComponent(closeButton)).addComponent(tryAgainButton));
.addComponent(closeButton)).addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED).addComponent(tryAgainButton));
errorPanel.setBackground(Color.PINK);
errorPanel.validate();
}

View File

@@ -184,8 +184,10 @@ class StatusPanel extends JPanel {
}
void clear() {
label.setText(null);
label.repaint();
if (label != null) {
label.setText(null);
label.repaint();
}
}
public void update(ContributionPanel panel) {