Skip to content

Commit

Permalink
Merge pull request arduino#9164 from joew46167/buttonsInManagers
Browse files Browse the repository at this point in the history
Add Buttons in Library and Boards managers
  • Loading branch information
facchinm authored Aug 22, 2019
2 parents a740021 + 1b515b1 commit aaef922
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,12 @@
import cc.arduino.contributions.libraries.ContributedLibraryReleases;
import cc.arduino.contributions.ui.InstallerTableCell;
import processing.app.Base;
import processing.app.PreferencesData;
import processing.app.Theme;

public class ContributedLibraryTableCellJPanel extends JPanel {

final JButton moreInfoButton;
final JButton installButton;
final Component installButtonPlaceholder;
final JComboBox downgradeChooser;
Expand All @@ -40,12 +42,15 @@ public class ContributedLibraryTableCellJPanel extends JPanel {
final JPanel buttonsPanel;
final JPanel inactiveButtonsPanel;
final JLabel statusLabel;
private final String moreInfoLbl = tr("More info");

public ContributedLibraryTableCellJPanel(JTable parentTable, Object value,
boolean isSelected) {
super();
setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));

moreInfoButton = new JButton(moreInfoLbl);
moreInfoButton.setVisible(false);
installButton = new JButton(tr("Install"));
int width = installButton.getPreferredSize().width;
installButtonPlaceholder = Box.createRigidArea(new Dimension(width, 1));
Expand Down Expand Up @@ -79,6 +84,11 @@ public ContributedLibraryTableCellJPanel(JTable parentTable, Object value,
buttonsPanel.setOpaque(false);

buttonsPanel.add(Box.createHorizontalStrut(7));
if (PreferencesData.getBoolean("ide.accessible")) {
buttonsPanel.add(moreInfoButton);
buttonsPanel.add(Box.createHorizontalStrut(5));
buttonsPanel.add(Box.createHorizontalStrut(15));
}
buttonsPanel.add(downgradeChooser);
buttonsPanel.add(Box.createHorizontalStrut(5));
buttonsPanel.add(downgradeButton);
Expand Down Expand Up @@ -141,7 +151,7 @@ public ContributedLibraryTableCellJPanel(JTable parentTable, Object value,
String name = selected.getName();
String author = selected.getAuthor();
// String maintainer = selectedLib.getMaintainer();
String website = selected.getWebsite();
final String website = selected.getWebsite();
String sentence = selected.getSentence();
String paragraph = selected.getParagraph();
// String availableVer = selectedLib.getVersion();
Expand Down Expand Up @@ -188,7 +198,7 @@ public ContributedLibraryTableCellJPanel(JTable parentTable, Object value,
desc += "<br />";
}
if (author != null && !author.isEmpty()) {
desc += format("<a href=\"{0}\">More info</a>", website);
desc = setButtonOrLink(moreInfoButton, desc, moreInfoLbl, website);
}

desc += "</body></html>";
Expand All @@ -215,6 +225,25 @@ public ContributedLibraryTableCellJPanel(JTable parentTable, Object value,
}
}

// same function as in ContributedPlatformTableCellJPanel - is there a utils file this can move to?
private String setButtonOrLink(JButton button, String desc, String label, String url) {
boolean accessibleIDE = PreferencesData.getBoolean("ide.accessible");
String retString = desc;

if (accessibleIDE) {
button.setVisible(true);
button.addActionListener(e -> {
Base.openURL(url);
});
}
else {
// if not accessible IDE, keep link the same EXCEPT that now the link text is translated!
retString += format("<a href=\"{0}\">{1}</a><br/>", url, label);
}

return retString;
}

// TODO Make this a method of Theme
private JTextPane makeNewDescription() {
if (getComponentCount() > 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,14 @@
import cc.arduino.contributions.packages.ContributedPlatform;
import cc.arduino.contributions.ui.InstallerTableCell;
import processing.app.Base;
import processing.app.PreferencesData;
import processing.app.Theme;

@SuppressWarnings("serial")
public class ContributedPlatformTableCellJPanel extends JPanel {

final JButton moreInfoButton;
final JButton onlineHelpButton;
final JButton installButton;
final JButton removeButton;
final Component removeButtonPlaceholder;
Expand All @@ -72,13 +75,19 @@ public class ContributedPlatformTableCellJPanel extends JPanel {
final JPanel buttonsPanel;
final JPanel inactiveButtonsPanel;
final JLabel statusLabel;
private final String moreInfoLbl = tr("More Info");
private final String onlineHelpLbl = tr("Online Help");

public ContributedPlatformTableCellJPanel() {
super();
setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));

{
installButton = new JButton(tr("Install"));
moreInfoButton = new JButton(moreInfoLbl);
moreInfoButton.setVisible(false);
onlineHelpButton = new JButton(onlineHelpLbl);
onlineHelpButton.setVisible(false);
int width = installButton.getPreferredSize().width;
installButtonPlaceholder = Box.createRigidArea(new Dimension(width, 1));
}
Expand Down Expand Up @@ -115,6 +124,13 @@ public ContributedPlatformTableCellJPanel() {
buttonsPanel.setOpaque(false);

buttonsPanel.add(Box.createHorizontalStrut(7));
if (PreferencesData.getBoolean("ide.accessible")) { // only add the buttons if needed
buttonsPanel.add(onlineHelpButton);
buttonsPanel.add(Box.createHorizontalStrut(5));
buttonsPanel.add(moreInfoButton);
buttonsPanel.add(Box.createHorizontalStrut(5));
buttonsPanel.add(Box.createHorizontalStrut(15));
}
buttonsPanel.add(downgradeChooser);
buttonsPanel.add(Box.createHorizontalStrut(5));
buttonsPanel.add(downgradeButton);
Expand Down Expand Up @@ -149,6 +165,25 @@ public ContributedPlatformTableCellJPanel() {
add(Box.createVerticalStrut(15));
}

// same function as in ContributedLibraryTableCellJPanel - is there a utils file this can move to?
private String setButtonOrLink(JButton button, String desc, String label, String url) {
boolean accessibleIDE = PreferencesData.getBoolean("ide.accessible");
String retString = desc;

if (accessibleIDE) {
button.setVisible(true);
button.addActionListener(e -> {
Base.openURL(url);
});
}
else {
// if not accessible IDE, keep link the same EXCEPT that now the link text is translated!
retString += " " + format("<a href=\"{0}\">{1}</a><br/>", url, label);
}

return retString;
}

void update(JTable parentTable, Object value, boolean isSelected,
boolean hasBuiltInRelease) {
ContributedPlatformReleases releases = (ContributedPlatformReleases) value;
Expand Down Expand Up @@ -216,16 +251,17 @@ void update(JTable parentTable, Object value, boolean isSelected,
} else if (selected.getParentPackage().getHelp() != null) {
help = selected.getParentPackage().getHelp();
}

if (help != null) {
String url = help.getOnline();
if (url != null && !url.isEmpty()) {
desc += " " + format("<a href=\"{0}\">Online help</a><br/>", url);
desc = setButtonOrLink(onlineHelpButton, desc, onlineHelpLbl, url);
}
}

String url = selected.getParentPackage().getWebsiteURL();
if (url != null && !url.isEmpty()) {
desc += " " + format("<a href=\"{0}\">More info</a>", url);
desc = setButtonOrLink(moreInfoButton, desc, moreInfoLbl, url);
}

desc += "</body></html>";
Expand Down
1 change: 1 addition & 0 deletions app/src/cc/arduino/contributions/ui/InstallerJDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ protected void onFilter(String[] _filters) {
updateIndexFilter(filters, categoryFilter);
}
};
filterField.getAccessibleContext().setAccessibleDescription(tr("Search Filter"));

// Add cut/copy/paste contextual menu to the search filter input field.
JPopupMenu menu = new JPopupMenu();
Expand Down

0 comments on commit aaef922

Please sign in to comment.