mirror of
https://github.com/esp8266/Arduino.git
synced 2025-07-30 16:24:09 +03:00
Improved platforms installer GUI. Platforms are now downloaded from network.
This commit is contained in:
committed by
Federico Fissore
parent
b249be46c7
commit
56ae061d7e
@ -0,0 +1,155 @@
|
||||
/*
|
||||
* This file is part of Arduino.
|
||||
*
|
||||
* Copyright 2014 Arduino LLC (http://www.arduino.cc/)
|
||||
*
|
||||
* Arduino is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
* As a special exception, you may use this file as part of a free software
|
||||
* library without restriction. Specifically, if other files instantiate
|
||||
* templates or use macros or inline functions from this file, or you compile
|
||||
* this file and link it with other files to produce an executable, this
|
||||
* file does not by itself cause the resulting executable to be covered by
|
||||
* the GNU General Public License. This exception does not however
|
||||
* invalidate any other reasons why the executable file might be covered by
|
||||
* the GNU General Public License.
|
||||
*/
|
||||
package cc.arduino.packages.contributions.ui;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Component;
|
||||
import java.awt.Dialog;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.FlowLayout;
|
||||
import java.awt.Window;
|
||||
import java.awt.event.ActionListener;
|
||||
|
||||
import javax.swing.Box;
|
||||
import javax.swing.BoxLayout;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JDialog;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JProgressBar;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
|
||||
import cc.arduino.packages.contributions.ContributionInstaller;
|
||||
import cc.arduino.packages.contributions.ContributionInstaller.Listener;
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
public class ContributionInstallerUI extends JDialog {
|
||||
|
||||
private final JPanel contentPanel = new JPanel();
|
||||
private JButton cancelButton;
|
||||
private JProgressBar progressBar;
|
||||
private JLabel operationLabel;
|
||||
|
||||
public ContributionInstallerUI(Window parent) {
|
||||
super(parent, "Installer progress", Dialog.ModalityType.APPLICATION_MODAL);
|
||||
|
||||
setBounds(100, 100, 450, 300);
|
||||
getContentPane().setLayout(new BorderLayout());
|
||||
contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
|
||||
getContentPane().add(contentPanel, BorderLayout.CENTER);
|
||||
contentPanel.setLayout(new BoxLayout(contentPanel, BoxLayout.Y_AXIS));
|
||||
{
|
||||
Box verticalBox = Box.createVerticalBox();
|
||||
contentPanel.add(verticalBox);
|
||||
{
|
||||
Component verticalGlue = Box.createVerticalGlue();
|
||||
verticalBox.add(verticalGlue);
|
||||
}
|
||||
{
|
||||
Box horizontalBox = Box.createHorizontalBox();
|
||||
verticalBox.add(horizontalBox);
|
||||
{
|
||||
Component horizontalGlue = Box.createHorizontalGlue();
|
||||
horizontalBox.add(horizontalGlue);
|
||||
}
|
||||
{
|
||||
JLabel lblNewLabel = new JLabel("Description");
|
||||
horizontalBox.add(lblNewLabel);
|
||||
}
|
||||
{
|
||||
Component horizontalGlue = Box.createHorizontalGlue();
|
||||
horizontalBox.add(horizontalGlue);
|
||||
}
|
||||
}
|
||||
{
|
||||
Component verticalGlue = Box.createVerticalGlue();
|
||||
verticalBox.add(verticalGlue);
|
||||
}
|
||||
{
|
||||
Box horizontalBox = Box.createHorizontalBox();
|
||||
verticalBox.add(horizontalBox);
|
||||
{
|
||||
operationLabel = new JLabel("Current running operation");
|
||||
horizontalBox.add(operationLabel);
|
||||
}
|
||||
{
|
||||
Component horizontalGlue = Box.createHorizontalGlue();
|
||||
horizontalBox.add(horizontalGlue);
|
||||
}
|
||||
}
|
||||
{
|
||||
Component verticalStrut = Box.createVerticalStrut(20);
|
||||
verticalStrut.setPreferredSize(new Dimension(0, 5));
|
||||
verticalStrut.setMinimumSize(new Dimension(0, 5));
|
||||
verticalBox.add(verticalStrut);
|
||||
}
|
||||
{
|
||||
progressBar = new JProgressBar();
|
||||
progressBar.setStringPainted(true);
|
||||
progressBar.setValue(10);
|
||||
progressBar.setSize(new Dimension(0, 30));
|
||||
progressBar.setMinimumSize(new Dimension(10, 30));
|
||||
progressBar.setMaximumSize(new Dimension(32767, 30));
|
||||
verticalBox.add(progressBar);
|
||||
}
|
||||
}
|
||||
{
|
||||
JPanel buttonPane = new JPanel();
|
||||
buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
|
||||
getContentPane().add(buttonPane, BorderLayout.SOUTH);
|
||||
{
|
||||
cancelButton = new JButton("Cancel");
|
||||
cancelButton.setActionCommand("Cancel");
|
||||
buttonPane.add(cancelButton);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void onCancel(ActionListener listener) {
|
||||
cancelButton.addActionListener(listener);
|
||||
}
|
||||
|
||||
public void setOperationText(String message) {
|
||||
operationLabel.setText(message);
|
||||
}
|
||||
|
||||
public void setProgress(int progress) {
|
||||
progressBar.setValue(progress);
|
||||
}
|
||||
|
||||
public void attach(ContributionInstaller installer) {
|
||||
installer.setListener(new Listener() {
|
||||
@Override
|
||||
public void onProgress(double progress, String message) {
|
||||
setOperationText(message);
|
||||
setProgress((int) progress);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
@ -52,10 +52,12 @@ import java.util.List;
|
||||
|
||||
import javax.swing.Box;
|
||||
import javax.swing.BoxLayout;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JComboBox;
|
||||
import javax.swing.JDialog;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JProgressBar;
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.JTable;
|
||||
import javax.swing.JTextField;
|
||||
@ -72,13 +74,11 @@ import cc.arduino.packages.contributions.ContributedPlatform;
|
||||
import cc.arduino.packages.contributions.ContributionsIndex;
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
public class JContributionManagerDialog extends JDialog {
|
||||
public class ContributionManagerUI extends JDialog {
|
||||
|
||||
private FilterField filterField;
|
||||
private JScrollPane scrollPane;
|
||||
private StatusPanel status;
|
||||
|
||||
private JContributionManagerDialogListener listener = null;
|
||||
private ContributionManagerUIListener listener = null;
|
||||
|
||||
private String category;
|
||||
private JLabel categoryLabel;
|
||||
@ -89,53 +89,59 @@ public class JContributionManagerDialog extends JDialog {
|
||||
|
||||
private ContributionIndexTableModel contribModel = new ContributionIndexTableModel();
|
||||
private JTable contribTable;
|
||||
private JProgressBar progressBar;
|
||||
|
||||
public JContributionManagerDialog(Frame parent) {
|
||||
private Box progressBox;
|
||||
private Box updateBox;
|
||||
|
||||
public ContributionManagerUI(Frame parent) {
|
||||
super(parent, "Boards Manager", Dialog.ModalityType.APPLICATION_MODAL);
|
||||
setResizable(true);
|
||||
|
||||
Container pane = getContentPane();
|
||||
pane.setLayout(new BorderLayout());
|
||||
|
||||
categoryStrut1 = Box.createHorizontalStrut(5);
|
||||
categoryStrut2 = Box.createHorizontalStrut(5);
|
||||
categoryStrut3 = Box.createHorizontalStrut(5);
|
||||
{
|
||||
categoryStrut1 = Box.createHorizontalStrut(5);
|
||||
categoryStrut2 = Box.createHorizontalStrut(5);
|
||||
categoryStrut3 = Box.createHorizontalStrut(5);
|
||||
|
||||
categoryLabel = new JLabel(_("Category:"));
|
||||
categoryLabel = new JLabel(_("Category:"));
|
||||
|
||||
categoryChooser = new JComboBox();
|
||||
categoryChooser.setMaximumRowCount(20);
|
||||
categoryChooser.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent arg0) {
|
||||
notifyCategoryChange();
|
||||
}
|
||||
});
|
||||
categoryChooser = new JComboBox();
|
||||
categoryChooser.setMaximumRowCount(20);
|
||||
categoryChooser.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent arg0) {
|
||||
notifyCategoryChange();
|
||||
}
|
||||
});
|
||||
|
||||
setCategories(new ArrayList<String>());
|
||||
setCategories(new ArrayList<String>());
|
||||
|
||||
filterField = new FilterField();
|
||||
filterField = new FilterField();
|
||||
|
||||
JPanel filterPanel = new JPanel();
|
||||
filterPanel.setLayout(new BoxLayout(filterPanel, BoxLayout.X_AXIS));
|
||||
pane.add(filterPanel, BorderLayout.NORTH);
|
||||
filterPanel.add(categoryStrut1);
|
||||
filterPanel.add(categoryLabel);
|
||||
filterPanel.add(categoryStrut2);
|
||||
filterPanel.add(categoryChooser);
|
||||
filterPanel.add(categoryStrut3);
|
||||
filterPanel.add(filterField);
|
||||
filterPanel.setBorder(new EmptyBorder(7, 7, 7, 7));
|
||||
JPanel panel = new JPanel();
|
||||
panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS));
|
||||
panel.add(categoryStrut1);
|
||||
panel.add(categoryLabel);
|
||||
panel.add(categoryStrut2);
|
||||
panel.add(categoryChooser);
|
||||
panel.add(categoryStrut3);
|
||||
panel.add(filterField);
|
||||
panel.setBorder(new EmptyBorder(7, 7, 7, 7));
|
||||
pane.add(panel, BorderLayout.NORTH);
|
||||
}
|
||||
|
||||
contribTable = new JTable(contribModel);
|
||||
// contribTable.setTableHeader(null);
|
||||
contribTable.setTableHeader(null);
|
||||
// contribTable.getTableHeader().setEnabled(false);
|
||||
// contribTable.setRowSelectionAllowed(false);
|
||||
contribTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
||||
contribTable.setColumnSelectionAllowed(false);
|
||||
contribTable.setDragEnabled(false);
|
||||
contribTable.setIntercellSpacing(new Dimension(0, 1));
|
||||
contribTable.setShowVerticalLines(false);
|
||||
contribTable.getTableHeader().setEnabled(false);
|
||||
// contribTable.addMouseListener(new MouseAdapter() {
|
||||
// @Override
|
||||
// public void mousePressed(MouseEvent e) {
|
||||
@ -147,14 +153,15 @@ public class JContributionManagerDialog extends JDialog {
|
||||
// }
|
||||
// });
|
||||
TableColumnModel tcm = contribTable.getColumnModel();
|
||||
TableColumn descriptionCol = tcm.getColumn(DESCRIPTION_COL);
|
||||
TableColumn versionCol = tcm.getColumn(VERSION_COL);
|
||||
TableColumn installedCol = tcm.getColumn(INSTALLED_COL);
|
||||
|
||||
descriptionCol.setCellRenderer(new ContributedPlatformTableCellRenderer());
|
||||
descriptionCol.setResizable(true);
|
||||
{
|
||||
TableColumn descriptionCol = tcm.getColumn(DESCRIPTION_COL);
|
||||
descriptionCol
|
||||
.setCellRenderer(new ContributedPlatformTableCellRenderer());
|
||||
descriptionCol.setResizable(true);
|
||||
}
|
||||
|
||||
{
|
||||
TableColumn versionCol = tcm.getColumn(VERSION_COL);
|
||||
versionCol.setCellRenderer(new VersionSelectorTableCellRenderer());
|
||||
VersionSelectorTableCellEditor editor = new VersionSelectorTableCellEditor();
|
||||
editor.setListener(new VersionSelectorTableCellEditor.Listener() {
|
||||
@ -172,6 +179,7 @@ public class JContributionManagerDialog extends JDialog {
|
||||
}
|
||||
|
||||
{
|
||||
TableColumn installedCol = tcm.getColumn(INSTALLED_COL);
|
||||
installedCol.setCellRenderer(new VersionInstalledTableCellRenderer());
|
||||
VersionInstalledTableCellEditor editor = new VersionInstalledTableCellEditor();
|
||||
editor.setListener(new VersionInstalledTableCellEditor.Listener() {
|
||||
@ -189,26 +197,67 @@ public class JContributionManagerDialog extends JDialog {
|
||||
installedCol.setMaxWidth(70);
|
||||
}
|
||||
|
||||
scrollPane = new JScrollPane();
|
||||
scrollPane.setPreferredSize(new Dimension(300, 300));
|
||||
scrollPane.setViewportView(contribTable);
|
||||
scrollPane
|
||||
.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
|
||||
scrollPane
|
||||
.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
|
||||
pane.add(scrollPane, BorderLayout.CENTER);
|
||||
{
|
||||
JScrollPane s = new JScrollPane();
|
||||
s.setPreferredSize(new Dimension(300, 300));
|
||||
s.setViewportView(contribTable);
|
||||
s.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
|
||||
s.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
|
||||
pane.add(s, BorderLayout.CENTER);
|
||||
}
|
||||
|
||||
pane.add(Box.createHorizontalStrut(10), BorderLayout.WEST);
|
||||
pane.add(Box.createHorizontalStrut(10), BorderLayout.EAST);
|
||||
|
||||
status = new StatusPanel();
|
||||
status.setBorder(new EmptyBorder(7, 7, 7, 7));
|
||||
pane.add(status, BorderLayout.SOUTH);
|
||||
{
|
||||
progressBar = new JProgressBar();
|
||||
progressBar.setStringPainted(true);
|
||||
progressBar.setString(" ");
|
||||
progressBar.setVisible(true);
|
||||
|
||||
setMinimumSize(new Dimension(450, 400));
|
||||
JButton cancelButton = new JButton(_("Cancel"));
|
||||
cancelButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent arg0) {
|
||||
if (listener != null)
|
||||
listener.onCancelPressed();
|
||||
}
|
||||
});
|
||||
|
||||
JButton updateButton = new JButton(_("Update list"));
|
||||
updateButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent arg0) {
|
||||
if (listener != null)
|
||||
listener.onUpdatePressed();
|
||||
}
|
||||
});
|
||||
|
||||
{
|
||||
progressBox = Box.createHorizontalBox();
|
||||
progressBox.add(progressBar);
|
||||
progressBox.add(Box.createHorizontalStrut(5));
|
||||
progressBox.add(cancelButton);
|
||||
|
||||
updateBox = Box.createHorizontalBox();
|
||||
updateBox.add(Box.createHorizontalGlue());
|
||||
updateBox.add(updateButton);
|
||||
|
||||
JPanel progressPanel = new JPanel();
|
||||
progressPanel.setBorder(new EmptyBorder(7, 7, 7, 7));
|
||||
progressPanel.setLayout(new BoxLayout(progressPanel, BoxLayout.Y_AXIS));
|
||||
progressPanel.add(progressBox);
|
||||
progressPanel.add(updateBox);
|
||||
pane.add(progressPanel, BorderLayout.SOUTH);
|
||||
|
||||
setProgressVisible(false);
|
||||
}
|
||||
}
|
||||
|
||||
setMinimumSize(new Dimension(500, 400));
|
||||
}
|
||||
|
||||
public void setListener(JContributionManagerDialogListener listener) {
|
||||
public void setListener(ContributionManagerUIListener listener) {
|
||||
this.listener = listener;
|
||||
}
|
||||
|
||||
@ -315,4 +364,19 @@ public class JContributionManagerDialog extends JDialog {
|
||||
contribModel.updateIndex(index);
|
||||
}
|
||||
|
||||
public void setProgressVisible(boolean visible) {
|
||||
progressBox.setVisible(visible);
|
||||
|
||||
filterField.setEnabled(!visible);
|
||||
categoryChooser.setEnabled(!visible);
|
||||
contribTable.setEnabled(!visible);
|
||||
updateBox.setVisible(!visible);
|
||||
updateBox.setEnabled(!visible);
|
||||
}
|
||||
|
||||
public void setProgress(int progress, String text) {
|
||||
progressBar.setValue(progress);
|
||||
if (text != null)
|
||||
progressBar.setString(text);
|
||||
}
|
||||
}
|
@ -30,12 +30,16 @@ package cc.arduino.packages.contributions.ui;
|
||||
|
||||
import cc.arduino.packages.contributions.ContributedPlatform;
|
||||
|
||||
public interface JContributionManagerDialogListener {
|
||||
public interface ContributionManagerUIListener {
|
||||
|
||||
void onCategoryChange(String category);
|
||||
|
||||
void onInstall(ContributedPlatform selected);
|
||||
|
||||
void onRemove(ContributedPlatform selected);
|
||||
|
||||
void onCancelPressed();
|
||||
|
||||
void onUpdatePressed();
|
||||
|
||||
}
|
@ -24,8 +24,10 @@ package processing.app;
|
||||
|
||||
import cc.arduino.packages.DiscoveryManager;
|
||||
import cc.arduino.packages.contributions.ContributedPlatform;
|
||||
import cc.arduino.packages.contributions.ui.JContributionManagerDialog;
|
||||
import cc.arduino.packages.contributions.ui.JContributionManagerDialogListener;
|
||||
import cc.arduino.packages.contributions.ContributionInstaller;
|
||||
import cc.arduino.packages.contributions.ContributionInstaller.Listener;
|
||||
import cc.arduino.packages.contributions.ui.ContributionManagerUI;
|
||||
import cc.arduino.packages.contributions.ui.ContributionManagerUIListener;
|
||||
import cc.arduino.view.SplashScreenHelper;
|
||||
import processing.app.debug.TargetBoard;
|
||||
import processing.app.debug.TargetPackage;
|
||||
@ -1111,32 +1113,82 @@ public class Base {
|
||||
}
|
||||
|
||||
private void openInstallBoardDialog() {
|
||||
JContributionManagerDialog dialog = new JContributionManagerDialog(
|
||||
activeEditor);
|
||||
dialog.setListener(new JContributionManagerDialogListener() {
|
||||
// Create dialog for contribution manager
|
||||
final ContributionManagerUI managerUI = new ContributionManagerUI(activeEditor);
|
||||
final Listener installerListener = new ContributionInstaller.Listener() {
|
||||
@Override
|
||||
public void onProgress(double progress, String message) {
|
||||
managerUI.setProgress((int) progress, message);
|
||||
}
|
||||
};
|
||||
managerUI.setListener(new ContributionManagerUIListener() {
|
||||
@Override
|
||||
public void onCategoryChange(String category) {
|
||||
// TODO Auto-generated method stub
|
||||
System.out.println("Selected " + category);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onInstall(ContributedPlatform platform) {
|
||||
try {
|
||||
BaseNoGui.indexer.install(platform);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
public void onUpdatePressed() {
|
||||
// TODO Auto-generated method stub
|
||||
System.out.println("Update pressed");
|
||||
}
|
||||
|
||||
Thread task = null;
|
||||
|
||||
@Override
|
||||
public void onRemove(ContributedPlatform platform) {
|
||||
BaseNoGui.indexer.remove(platform);
|
||||
public void onCancelPressed() {
|
||||
if (task != null)
|
||||
task.interrupt();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onInstall(final ContributedPlatform platform) {
|
||||
final ContributionInstaller installer = new ContributionInstaller(BaseNoGui.indexer);
|
||||
installer.setListener(installerListener);
|
||||
task = new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
managerUI.setProgressVisible(true);
|
||||
installer.install(platform);
|
||||
} catch (Exception e) {
|
||||
// TODO Show ERROR
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
managerUI.setProgressVisible(false);
|
||||
}
|
||||
}
|
||||
});
|
||||
task.start();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRemove(final ContributedPlatform platform) {
|
||||
// Create installer with his dialog
|
||||
final ContributionInstaller installer = new ContributionInstaller(BaseNoGui.indexer);
|
||||
installer.setListener(installerListener);
|
||||
task = new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
managerUI.setProgressVisible(true);
|
||||
installer.remove(platform);
|
||||
} catch (Exception e) {
|
||||
// TODO Show ERROR
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
managerUI.setProgressVisible(false);
|
||||
}
|
||||
}
|
||||
});
|
||||
task.start();
|
||||
}
|
||||
});
|
||||
dialog.setCategories(Arrays.asList("Arduino", "Arduino Certified",
|
||||
managerUI.setCategories(Arrays.asList("Arduino", "Arduino Certified",
|
||||
"Arduino@Heart"));
|
||||
dialog.addContributions(BaseNoGui.indexer.getIndex());
|
||||
dialog.setVisible(true);
|
||||
managerUI.addContributions(BaseNoGui.indexer.getIndex());
|
||||
managerUI.setVisible(true);
|
||||
}
|
||||
|
||||
public void rebuildBoardsMenu(JMenu toolsMenu, Editor editor) throws Exception {
|
||||
|
Reference in New Issue
Block a user