diff --git a/app/src/processing/app/contrib/ContributionListPanel.java b/app/src/processing/app/contrib/ContributionListPanel.java index 4fb842d82..08b6edc92 100644 --- a/app/src/processing/app/contrib/ContributionListPanel.java +++ b/app/src/processing/app/contrib/ContributionListPanel.java @@ -21,17 +21,40 @@ */ package processing.app.contrib; -import java.util.*; +import java.awt.Color; +import java.awt.Component; +import java.awt.Dimension; +import java.awt.EventQueue; +import java.awt.GridBagLayout; +import java.awt.Rectangle; import java.util.List; import java.util.Map.Entry; +import java.util.Set; +import java.util.TreeMap; +import java.util.TreeSet; -import javax.swing.*; -import javax.swing.border.*; -import javax.swing.event.*; - -import java.awt.*; +import javax.swing.BorderFactory; +import javax.swing.GroupLayout; +import javax.swing.Icon; +import javax.swing.ImageIcon; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.JTable; +import javax.swing.JTextPane; +import javax.swing.ListSelectionModel; +import javax.swing.Scrollable; +import javax.swing.SwingConstants; +import javax.swing.UIManager; +import javax.swing.border.Border; +import javax.swing.event.HyperlinkEvent; +import javax.swing.event.HyperlinkListener; +import javax.swing.table.DefaultTableCellRenderer; +import javax.swing.table.DefaultTableModel; +import javax.swing.table.TableCellRenderer; import processing.app.Base; +import processing.app.ui.Toolkit; // The "Scrollable" implementation and its methods here take care of preventing @@ -43,7 +66,7 @@ public class ContributionListPanel extends JPanel implements Scrollable, Contrib ContributionTab contributionTab; StatusPanel statusPanel; - TreeMap panelByContribution; + TreeMap panelByContribution; static HyperlinkListener nullHyperlinkListener = new HyperlinkListener() { public void hyperlinkUpdate(HyperlinkEvent e) { } @@ -55,6 +78,8 @@ public class ContributionListPanel extends JPanel implements Scrollable, Contrib private ContributionFilter filter; // private ContributionListing contribListing; private ContributionListing contribListing = ContributionListing.getInstance(); + private JTable table; + DefaultTableModel dtm; public ContributionListPanel(ContributionTab contributionTab, @@ -78,17 +103,178 @@ public class ContributionListPanel extends JPanel implements Scrollable, Contrib setBackground(UIManager.getColor("List.background")); } - panelByContribution = new TreeMap( - contribListing.getComparator()); + panelByContribution = new TreeMap(contribListing.getComparator()); // statusPlaceholder = new JPanel(); // statusPlaceholder.setVisible(false); // status = new StatusPanel(null); + + + dtm = new MyTableModel(); + table = new JTable(dtm){ + @Override + public Component prepareRenderer( + TableCellRenderer renderer, int row, int column) { + Component c = super.prepareRenderer(renderer, row, column); + if (isRowSelected(row)) { + c.setBackground(Color.blue); + } else { + c.setBackground(Color.white); + } + return c; + } + }; + String[] colName = { "Status", "Name", "Author" }; + dtm.setColumnIdentifiers(colName); + JScrollPane scrollPane = new JScrollPane(table); + table.setFillsViewportHeight(true); + table.setDefaultRenderer(Contribution.class, new StatusRendere()); + table.setRowHeight(30); + table.setRowMargin(6); + table.getColumnModel().setColumnMargin(-1); + table.getColumnModel().getColumn(0).setMaxWidth(60); + table.setShowGrid(false); + table.setColumnSelectionAllowed(false); + table.setCellSelectionEnabled(false); + 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); + } + class StatusRendere extends DefaultTableCellRenderer { + + @Override + public Component getTableCellRendererComponent(JTable table, Object value, + boolean isSelected, + boolean hasFocus, int row, + int column) { + Contribution contribution = (Contribution) value; + JLabel label = new JLabel(); + if (column == 0) { + Icon icon = null; + label.setBorder(BorderFactory.createEmptyBorder(0, 17, 0, 0)); + if (contribution.isInstalled()) { + icon = UIManager.getIcon("OptionPane.warningIcon"); + if (contribListing.hasUpdates(contribution)) { + icon = Toolkit.getLibIcon("icons/pde-16.png"); + } + if (!contribution.isCompatible(Base.getRevision())) { + icon = Toolkit.getLibIcon("icons/pde-16.png"); + } + } + label.setIcon(icon); + if (isSelected) { + label.setBackground(Color.BLUE); + } + label.setOpaque(true); +// return table.getDefaultRenderer(Icon.class).getTableCellRendererComponent(table, icon, isSelected, false, row, column); + } else if (column == 1) { + JTextPane name = new JTextPane(); + name.setContentType("text/html"); + name.setEditable(false); + name.setText("" + contribution.getName() + " - " + + contribution.getSentence() + ""); + GroupLayout layout = new GroupLayout(label); + + layout.setAutoCreateGaps(true); + layout.setHorizontalGroup(layout.createSequentialGroup() + .addComponent(name)); + layout + .setVerticalGroup(layout.createParallelGroup().addComponent(name)); + if (table.isRowSelected(row)) { + name.setBackground(Color.BLUE); + name.setOpaque(true); + } + label.setLayout(layout); + } else { + JLabel icon = new JLabel( + contribution.isSpecial() ? Toolkit + .getLibIcon("icons/pde-16.png") : null); + JTextPane author = new JTextPane(); + StringBuilder name = new StringBuilder(""); + String authorList = contribution.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)); + } + } + } + author.setText(name.toString()); + author.setEditable(false); + author.setOpaque(false); + if (table.isRowSelected(row)) { + label.setBackground(Color.BLUE); + } + GroupLayout layout = new GroupLayout(label); + +// layout.setAutoCreateGaps(true); + layout.setHorizontalGroup(layout.createSequentialGroup() + .addContainerGap().addComponent(icon).addComponent(author)); + layout.setVerticalGroup(layout + .createParallelGroup(GroupLayout.Alignment.CENTER) + .addComponent(author).addComponent(icon)); + label.setLayout(layout); + label.setOpaque(true); + } + return label; + } + + } + class MyTableModel extends DefaultTableModel{ + MyTableModel() { + super(0,0); + } + @Override + public boolean isCellEditable(int row, int column) { + return false; + } + @Override + public Class getColumnClass(int columnIndex) { +// if(columnIndex == 0){ +// return Icon.class; +// } +// if(columnIndex == 1){ +// return String.class; +// } + return Contribution.class; + } + } private void updatePanelOrdering() { - int row = 0; + dtm.getDataVector().removeAllElements(); + dtm.fireTableDataChanged(); + for (Entry entry : panelByContribution.entrySet()) { +// ImageIcon icon = null; +// if (entry.getKey().isInstalled()) { +// icon = Toolkit.getLibIcon("icons/pde-16.png"); +// if (contribListing.hasUpdates(entry.getKey())) { +// icon = Toolkit.getLibIcon("icons/pde-16.png"); +// } +// if (!entry.getKey().isCompatible(Base.getRevision())) { +// icon = Toolkit.getLibIcon("icons/pde-16.png"); +// } +// } + ((DefaultTableModel)table.getModel()).addRow(new Object[]{entry.getKey(), entry.getKey(), entry.getKey()});//"" +// + entry.getKey().getName() + " - " + entry.getKey().getSentence() +// + "" + } + /* int row = 0; for (Entry entry : panelByContribution.entrySet()) { GridBagConstraints c = new GridBagConstraints(); c.fill = GridBagConstraints.HORIZONTAL; @@ -99,7 +285,7 @@ public class ContributionListPanel extends JPanel implements Scrollable, Contrib add(entry.getValue(), c); } -/* + GridBagConstraints c = new GridBagConstraints(); c.fill = GridBagConstraints.BOTH; c.weightx = 1;