diff --git a/app/src/cc/arduino/libraries/contributions/ui/ContributedLibraryTableCell.java b/app/src/cc/arduino/libraries/contributions/ui/ContributedLibraryTableCell.java index 3a66450b0..b84629376 100644 --- a/app/src/cc/arduino/libraries/contributions/ui/ContributedLibraryTableCell.java +++ b/app/src/cc/arduino/libraries/contributions/ui/ContributedLibraryTableCell.java @@ -28,24 +28,38 @@ */ package cc.arduino.libraries.contributions.ui; -import cc.arduino.libraries.contributions.ContributedLibrary; -import cc.arduino.libraries.contributions.ui.LibrariesIndexTableModel.ContributedLibraryReleases; -import cc.arduino.ui.InstallerTableCell; -import processing.app.Base; +import static processing.app.I18n._; +import static processing.app.I18n.format; -import javax.swing.*; +import java.awt.Color; +import java.awt.Component; +import java.awt.Dimension; +import java.awt.Insets; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.ItemEvent; +import java.awt.event.ItemListener; + +import javax.swing.Box; +import javax.swing.BoxLayout; +import javax.swing.JButton; +import javax.swing.JComboBox; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JTable; +import javax.swing.JTextPane; +import javax.swing.Timer; import javax.swing.border.EmptyBorder; import javax.swing.event.HyperlinkEvent; import javax.swing.event.HyperlinkListener; import javax.swing.text.Document; import javax.swing.text.html.HTMLDocument; import javax.swing.text.html.StyleSheet; -import java.awt.*; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import static processing.app.I18n._; -import static processing.app.I18n.format; +import processing.app.Base; +import cc.arduino.libraries.contributions.ContributedLibrary; +import cc.arduino.libraries.contributions.ui.LibrariesIndexTableModel.ContributedLibraryReleases; +import cc.arduino.ui.InstallerTableCell; @SuppressWarnings("serial") public class ContributedLibraryTableCell extends InstallerTableCell { @@ -56,6 +70,12 @@ public class ContributedLibraryTableCell extends InstallerTableCell { private JButton removeButton; private Component removeButtonPlaceholder; private Component installButtonPlaceholder; + private JComboBox downgradeChooser; + private JButton downgradeButton; + private JPanel buttonsPanel; + private Component removeButtonStrut; + private JPanel inactiveButtonsPanel; + private JLabel statusLabel; public ContributedLibraryTableCell() { description = new JTextPane(); @@ -109,17 +129,74 @@ public class ContributedLibraryTableCell extends InstallerTableCell { removeButtonPlaceholder = Box.createRigidArea(new Dimension(width, 1)); } + downgradeButton = new JButton(_("Install")); + downgradeButton.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + ContributedLibrary selected; + selected = (ContributedLibrary) downgradeChooser.getSelectedItem(); + onInstall(selected);//, editorValue.getInstalled()); + } + }); + + downgradeChooser = new JComboBox(); + downgradeChooser.addItem("-"); + downgradeChooser.setMaximumSize(downgradeChooser.getPreferredSize()); + downgradeChooser.addItemListener(new ItemListener() { + @Override + public void itemStateChanged(ItemEvent e) { + Object selectVersionItem = downgradeChooser.getItemAt(0); + boolean disableDowngrade = (e.getItem() == selectVersionItem); + downgradeButton.setEnabled(!disableDowngrade); + } + }); + panel = new JPanel(); - panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS)); + panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS)); panel.add(description); - panel.add(Box.createHorizontalStrut(5)); - panel.add(installButton); - panel.add(installButtonPlaceholder); - panel.add(Box.createHorizontalStrut(5)); - panel.add(removeButton); - panel.add(removeButtonPlaceholder); - panel.add(Box.createHorizontalStrut(5)); + + { + buttonsPanel = new JPanel(); + buttonsPanel.setLayout(new BoxLayout(buttonsPanel, BoxLayout.X_AXIS)); + buttonsPanel.setOpaque(false); + + buttonsPanel.add(Box.createHorizontalStrut(20)); + buttonsPanel.add(downgradeChooser); + buttonsPanel.add(Box.createHorizontalStrut(5)); + buttonsPanel.add(downgradeButton); + + buttonsPanel.add(Box.createHorizontalGlue()); + + buttonsPanel.add(installButton); + buttonsPanel.add(Box.createHorizontalStrut(5)); + buttonsPanel.add(removeButton); + removeButtonStrut = Box.createHorizontalStrut(5); + buttonsPanel.add(removeButtonStrut); + buttonsPanel.add(Box.createHorizontalStrut(15)); + + panel.add(buttonsPanel); + } + + { + inactiveButtonsPanel = new JPanel(); + inactiveButtonsPanel.setLayout(new BoxLayout(inactiveButtonsPanel, BoxLayout.X_AXIS)); + inactiveButtonsPanel.setOpaque(false); + + int height = installButton.getMinimumSize().height; + inactiveButtonsPanel.add(Box.createVerticalStrut(height)); + inactiveButtonsPanel.add(Box.createGlue()); + + statusLabel = new JLabel(" "); + inactiveButtonsPanel.add(statusLabel); + + inactiveButtonsPanel.add(Box.createGlue()); + inactiveButtonsPanel.add(Box.createVerticalStrut(height)); + + panel.add(inactiveButtonsPanel); + } + + panel.add(Box.createVerticalStrut(10)); } protected void onRemove(ContributedLibrary contributedPlatform) { @@ -135,6 +212,7 @@ public class ContributedLibraryTableCell extends InstallerTableCell { boolean hasFocus, int row, int column) { parentTable = table; + setEnabled(false); return getUpdatedCellComponent(value, isSelected, row); } @@ -152,6 +230,20 @@ public class ContributedLibraryTableCell extends InstallerTableCell { int column) { parentTable = table; editorValue = (ContributedLibraryReleases) value; + setEnabled(true); + + downgradeChooser.removeAllItems(); + downgradeChooser.addItem(_("Select version")); + boolean visible = false; + for (ContributedLibrary release : editorValue.releases) { + if (release.isInstalled()) + continue; + downgradeChooser.addItem(release); + visible = true; + } + downgradeChooser.setVisible(visible); + downgradeButton.setVisible(visible); + return getUpdatedCellComponent(value, true, row); } @@ -185,53 +277,55 @@ public class ContributedLibraryTableCell extends InstallerTableCell { String website = selectedLib.getWebsite(); String sentence = selectedLib.getSentence(); String paragraph = selectedLib.getParagraph(); - String availableVer = selectedLib.getVersion(); + // String availableVer = selectedLib.getVersion(); String url = selectedLib.getUrl(); String midcolor = isSelected ? "#000000" : "#888888"; String desc = ""; - // Library name - desc += format("{0}", name); + // Library name... + desc += format("{0} ", name); + if (installedLib != null && installedLib.isReadOnly()) { + desc += "Built-In "; + } + + // ...author... desc += format("", midcolor); - if (author != null && !author.isEmpty()) { desc += format(" by {1}", website, author); } - desc += "
"; - - if (sentence != null) { - desc += format("{0}
", sentence); - if (paragraph != null && !paragraph.isEmpty()) - desc += format("{0}
", paragraph); - desc += "
"; - } - - desc += "
"; // close midcolor - - // If the selected lib is available from repository... - if (url != null) { - desc += format(_("Available version: {0}"), availableVer); - removeButton.setText(_("Remove")); - } else { - removeButton.setText(_("Delete")); - } - desc += "
"; - + + // ...version. if (installedLib != null) { String installedVer = installedLib.getVersion(); if (installedVer == null) - installedVer = "Legacy"; - desc += format(_("Installed version: {0}"), installedVer); - if (installedLib.isReadOnly()) - desc += " " + _("(Bundled)"); + desc += " " + _("Version unknown"); + else + desc += " " + format(_("Version {0}"), installedVer); + } else { + // not installed... + } + desc += "
"; + + // Description + if (sentence != null) { + desc += format("{0} ", sentence); + if (paragraph != null && !paragraph.isEmpty()) + desc += format("{0}", paragraph); + desc += "
"; } - desc += "
"; desc += ""; description.setText(desc); description.setBackground(Color.WHITE); + + // If the selected lib is available from repository... + if (url != null) { + removeButton.setText(_("Remove")); + } else { + removeButton.setText(_("Delete")); + } // for modelToView to work, the text area has to be sized. It doesn't // matter if it's visible or not. @@ -239,8 +333,6 @@ public class ContributedLibraryTableCell extends InstallerTableCell { // See: // http://stackoverflow.com/questions/3081210/how-to-set-jtextarea-to-have-height-that-matches-the-size-of-a-text-it-contains int width = parentTable.getBounds().width; - width -= installButtonPlaceholder.getPreferredSize().width; - width -= removeButtonPlaceholder.getPreferredSize().width; setJTextPaneDimensionToFitContainedText(description, width); if (isSelected) { @@ -254,8 +346,27 @@ public class ContributedLibraryTableCell extends InstallerTableCell { return panel; } + private Timer enabler = new Timer(100, new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + enable(true); + enabler.stop(); + } + }); + @Override public void setEnabled(boolean enabled) { + enable(false); + if (enabled) { + enabler.start(); + } else { + enabler.stop(); + } + buttonsPanel.setVisible(enabled); + inactiveButtonsPanel.setVisible(!enabled); + } + + public void enable(boolean enabled) { installButton.setEnabled(enabled); removeButton.setEnabled(enabled); } diff --git a/app/src/cc/arduino/libraries/contributions/ui/LibraryManagerUI.java b/app/src/cc/arduino/libraries/contributions/ui/LibraryManagerUI.java index 26fe9e461..b9ef14094 100644 --- a/app/src/cc/arduino/libraries/contributions/ui/LibraryManagerUI.java +++ b/app/src/cc/arduino/libraries/contributions/ui/LibraryManagerUI.java @@ -155,7 +155,8 @@ public class LibraryManagerUI extends InstallerJDialog { try { setProgressVisible(true, _("Installing...")); installer.install(lib); - getContribModel().updateLibrary(lib); + onIndexesUpdated(); // TODO: Do a better job in refreshing only the needed element + //getContribModel().updateLibrary(lib); } catch (Exception e) { throw new RuntimeException(e); } finally { @@ -173,7 +174,8 @@ public class LibraryManagerUI extends InstallerJDialog { try { setProgressVisible(true, _("Removing...")); installer.remove(lib); - getContribModel().updateLibrary(lib); + onIndexesUpdated(); // TODO: Do a better job in refreshing only the needed element + //getContribModel().updateLibrary(lib); } catch (Exception e) { throw new RuntimeException(e); } finally { diff --git a/app/src/cc/arduino/packages/contributions/ui/ContributedPlatformTableCell.java b/app/src/cc/arduino/packages/contributions/ui/ContributedPlatformTableCell.java index f109e141f..69b216bbe 100644 --- a/app/src/cc/arduino/packages/contributions/ui/ContributedPlatformTableCell.java +++ b/app/src/cc/arduino/packages/contributions/ui/ContributedPlatformTableCell.java @@ -284,8 +284,11 @@ public class ContributedPlatformTableCell extends InstallerTableCell { desc = desc.substring(0, desc.lastIndexOf(',')) + ".
"; desc += ""; description.setText(desc); - description.setBackground(Color.WHITE); + //description.setBackground(Color.WHITE); + int width = parentTable.getBounds().width; + setJTextPaneDimensionToFitContainedText(description, width); + if (isSelected) { panel.setBackground(parentTable.getSelectionBackground()); panel.setForeground(parentTable.getSelectionForeground()); @@ -294,9 +297,6 @@ public class ContributedPlatformTableCell extends InstallerTableCell { panel.setForeground(parentTable.getForeground()); } - int width = parentTable.getBounds().width; - setJTextPaneDimensionToFitContainedText(description, width); - return panel; } diff --git a/app/src/cc/arduino/ui/InstallerTableCell.java b/app/src/cc/arduino/ui/InstallerTableCell.java index ae297f8f7..64f1c84e2 100644 --- a/app/src/cc/arduino/ui/InstallerTableCell.java +++ b/app/src/cc/arduino/ui/InstallerTableCell.java @@ -49,7 +49,7 @@ public abstract class InstallerTableCell extends AbstractCellEditor implements T try { Rectangle r = jTextPane.modelToView(jTextPane.getDocument().getLength()); - r.height += jTextPane.modelToView(0).y; // add margins + //r.height += jTextPane.modelToView(0).y; // add margins Dimension d = new Dimension(minimumDimension.width, r.y + r.height); jTextPane.setPreferredSize(d); } catch (BadLocationException e) { diff --git a/arduino-core/src/cc/arduino/libraries/contributions/ContributedLibrary.java b/arduino-core/src/cc/arduino/libraries/contributions/ContributedLibrary.java index d5daf22b1..9b5a16581 100644 --- a/arduino-core/src/cc/arduino/libraries/contributions/ContributedLibrary.java +++ b/arduino-core/src/cc/arduino/libraries/contributions/ContributedLibrary.java @@ -109,6 +109,10 @@ public abstract class ContributedLibrary extends DownloadableContribution { @Override public String toString() { + return getVersion(); + } + + public String info() { String res = ""; res += " ContributedLibrary : " + getName() + "\n"; res += " author : " + getAuthor() + "\n";