Update Tab started

This commit is contained in:
Akarshit Wal
2015-07-12 02:10:28 +05:30
parent 428b8afd2c
commit 2ffa83ff77
3 changed files with 209 additions and 22 deletions
@@ -52,13 +52,15 @@ public class ContributionListPanel extends JPanel implements Scrollable, Contrib
private ContributionPanel selectedPanel;
// protected JPanel statusPlaceholder;
// private StatusPanel status;
private ContributionFilter filter;
protected ContributionFilter filter;
// private ContributionListing contribListing;
private ContributionListing contribListing = ContributionListing.getInstance();
private JTable table;
protected JTable table;
DefaultTableModel dtm;
public ContributionListPanel() {
// TODO Auto-generated constructor stub
}
public ContributionListPanel(final ContributionTab contributionTab,
ContributionFilter filter) {
super();
@@ -117,7 +119,7 @@ public class ContributionListPanel extends JPanel implements Scrollable, Contrib
table.getSelectionModel().addListSelectionListener(new ListSelectionListener(){
public void valueChanged(ListSelectionEvent event) {
//TODO this executes 2 times when clicked and 1 time when traversed using arrow keys
//Ideally this should always be try but while clearing the table something fishy is going on
//Ideally this should always be true but while clearing the table something fishy is going on
if(table.getSelectedRow() != -1){
setSelectedPanel(panelByContribution.get(table.getValueAt(table.getSelectedRow(), 0)));
}
@@ -164,6 +166,9 @@ public class ContributionListPanel extends JPanel implements Scrollable, Contrib
JTextPane name = new JTextPane();
name.setContentType("text/html");
name.setEditable(false);
if(!contribution.isCompatible(Base.getRevision())){
name.setForeground(Color.LIGHT_GRAY);
}
name.setText("<html><body><b>" + contribution.getName() + "</b> - "
+ contribution.getSentence() + "</body></html>");
GroupLayout layout = new GroupLayout(label);
@@ -204,6 +209,9 @@ public class ContributionListPanel extends JPanel implements Scrollable, Contrib
author.setText(name.toString());
author.setEditable(false);
author.setOpaque(false);
if(!contribution.isCompatible(Base.getRevision())){
author.setForeground(Color.LIGHT_GRAY);
}
if (table.isRowSelected(row)) {
label.setBackground(Color.BLUE);
}
@@ -222,7 +230,7 @@ public class ContributionListPanel extends JPanel implements Scrollable, Contrib
}
}
class MyTableModel extends DefaultTableModel{
private class MyTableModel extends DefaultTableModel{
MyTableModel() {
super(0,0);
}
@@ -232,17 +240,11 @@ public class ContributionListPanel extends JPanel implements Scrollable, Contrib
}
@Override
public Class<?> getColumnClass(int columnIndex) {
// if(columnIndex == 0){
// return Icon.class;
// }
// if(columnIndex == 1){
// return String.class;
// }
return Contribution.class;
}
}
private void updatePanelOrdering(Set<Contribution> contributionsSet) {
void updatePanelOrdering(Set<Contribution> contributionsSet) {
/* int row = 0;
for (Entry<Contribution, ContributionPanel> entry : panelByContribution.entrySet()) {
GridBagConstraints c = new GridBagConstraints();
@@ -264,15 +266,12 @@ public class ContributionListPanel extends JPanel implements Scrollable, Contrib
c.anchor = GridBagConstraints.NORTH;
add(status, c);*/
// System.out.println(dtm.getDataVector());
if(contributionTab.contributionType == null){
contributionTab.contributionManagerDialog.numberLabel.setText(Integer.toString(panelByContribution.size()));
dtm.getDataVector().removeAllElements();
dtm.fireTableDataChanged();
for (Contribution entry : contributionsSet) {
((MyTableModel) table.getModel()).addRow(new Object[] {
entry, entry, entry });
}
dtm.getDataVector().removeAllElements();
dtm.fireTableDataChanged();
for (Contribution entry : contributionsSet) {
((MyTableModel) table.getModel()).addRow(new Object[] {
entry, entry, entry });
}
}
@@ -86,11 +86,15 @@ public class ContributionTab {
filter = type.createFilter();
}
statusPanel = new StatusPanel(450,this);
this.statusPanel = new StatusPanel(450,this);
this.contributionType = type;
this.contributionManagerDialog = contributionManagerDialog;
contribListing = ContributionListing.getInstance();
contributionListPanel = new ContributionListPanel(this, filter);
if (contributionType == null) {
contributionListPanel = new UpdateContribListingPanel(this, filter);
} else {
contributionListPanel = new ContributionListPanel(this, filter);
}
contribListing.addContributionListener(contributionListPanel);
}
@@ -0,0 +1,184 @@
package processing.app.contrib;
import java.awt.Color;
import java.awt.Component;
import java.util.Comparator;
import java.util.Set;
import java.util.TreeMap;
import javax.swing.BorderFactory;
import javax.swing.GroupLayout;
import javax.swing.JComponent;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.ListSelectionModel;
import javax.swing.UIManager;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableCellRenderer;
import processing.app.Base;
public class UpdateContribListingPanel extends ContributionListPanel {
public UpdateContribListingPanel(ContributionTab contributionTab,
ContributionFilter filter) {
super.contributionTab = contributionTab;
super.filter = filter;
setOpaque(true);
if (Base.isLinux()) {
// Because of a bug with GNOME, getColor returns the wrong value for
// List.background. We'll just assume its white. The number of people
// using Linux and an inverted color theme should be small enough.
setBackground(Color.white);
} else {
setBackground(UIManager.getColor("List.background"));
}
// statusPlaceholder = new JPanel();
// statusPlaceholder.setVisible(false);
// status = new StatusPanel(null);
String[] colName = { "", "Name", "Author", "Installed", "Update To" };
dtm = new MyTableModel();
dtm.setColumnIdentifiers(colName);
table = new JTable(dtm){
@Override
public Component prepareRenderer(
TableCellRenderer renderer, int row, int column) {
Component c = super.prepareRenderer(renderer, row, column);
String title = (String) getValueAt(row, 1);
if (title.equals("<html><i>Library</i></html>") || title.equals("Tools")
|| title.equals("Modes") || title.equals("Examples")) {
((JComponent) c).setBorder(BorderFactory
.createMatteBorder(row == 0 ? 0 : 2, 0, 2, 0, Color.BLACK));
}
return c;
}
@Override
public void changeSelection(int rowIndex, int columnIndex,
boolean toggle, boolean extend) {
String title = (String) getValueAt(rowIndex, 1);
if(title.equals("<html><i>Library</i></html>")){
return;
}
super.changeSelection(rowIndex, columnIndex, toggle, extend);
}
// @Override
// public boolean isRowSelected(int row) {
// if (row == 0) {
// return false;
// }
// return super.isRowSelected(row);
// }
};
JScrollPane scrollPane = new JScrollPane(table);
table.setFillsViewportHeight(true);
table.setRowHeight(30);
table.setRowMargin(6);
table.getColumnModel().setColumnMargin(-1);
table.getColumnModel().getColumn(0).setMaxWidth(60);
table.setShowGrid(false);
table.setCellSelectionEnabled(false);
table.setRowSelectionAllowed(true);
table.setAutoCreateColumnsFromModel(true);
table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
GroupLayout layout = new GroupLayout(this);
layout.setHorizontalGroup(layout.createParallelGroup().addComponent(scrollPane));
layout.setVerticalGroup(layout.createSequentialGroup().addComponent(scrollPane));
this.setLayout(layout);
table.setVisible(true);
panelByContribution = new TreeMap<Contribution, ContributionPanel>(new Comparator<Contribution>() {
@Override
public int compare(Contribution o1, Contribution o2) {
int val1 = 0;
int val2 = 0;
switch(o1.getType()){
case LIBRARY: val1 = 1;
break;
case TOOL: val1 = 2;
break;
case MODE: val1 = 3;
break;
case EXAMPLES: val1 = 4;
break;
}
switch(o2.getType()){
case LIBRARY: val2 = 1;
break;
case TOOL: val2 = 2;
break;
case MODE: val2 = 3;
break;
case EXAMPLES: val2 = 4;
break;
}
if(val1 == val2){
return o1.getName().toLowerCase().compareTo(o2.getName().toLowerCase());
}
return val1 - val2;
}
});
}
//
// @Override
// public void contributionAdded(Contribution contribution) {
// if(filter.matches(contribution)){
// super.contributionAdded(contribution);
// }
// }
//
@Override
void updatePanelOrdering(Set<Contribution> contributionsSet) {
contributionTab.contributionManagerDialog.numberLabel.setText(Integer
.toString(panelByContribution.size()));
dtm.getDataVector().removeAllElements();
dtm.fireTableDataChanged();
ContributionType temp = null;
for (Contribution entry : contributionsSet) {
if(entry.getType() != temp){
temp = entry.getType();
dtm.addRow(new Object[] { null, "<html><i>" + temp.getTitle() + "</i></html>", null, null, null });
}
//TODO Make this into a function
StringBuilder name = new StringBuilder("");
String authorList = entry.getAuthorList();
if (authorList != null) {
for (int i = 0; i < authorList.length(); i++) {
if (authorList.charAt(i) == '[' || authorList.charAt(i) == ']') {
continue;
}
if (authorList.charAt(i) == '(') {
i++;
while (authorList.charAt(i) != ')') {
i++;
}
} else {
name.append(authorList.charAt(i));
}
}
}
dtm
.addRow(new Object[] {
"", "<html><b>" + entry.getName() + "</b></html>", name, entry.getPrettyVersion(),
contributionTab.contribListing.getLatestVersion(entry) });
}
}
private class MyTableModel extends DefaultTableModel{
MyTableModel() {
super(0,0);
}
@Override
public boolean isCellEditable(int row, int column) {
return false;
}
}
}