mirror of
https://github.com/arduino/Arduino.git
synced 2025-01-18 07:52:14 +01:00
Factored installer GUI code
This commit is contained in:
parent
dece2b4751
commit
2c941d424e
@ -39,7 +39,6 @@ import java.awt.Rectangle;
|
|||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionEvent;
|
||||||
import java.awt.event.ActionListener;
|
import java.awt.event.ActionListener;
|
||||||
|
|
||||||
import javax.swing.AbstractCellEditor;
|
|
||||||
import javax.swing.Box;
|
import javax.swing.Box;
|
||||||
import javax.swing.BoxLayout;
|
import javax.swing.BoxLayout;
|
||||||
import javax.swing.JButton;
|
import javax.swing.JButton;
|
||||||
@ -49,8 +48,6 @@ import javax.swing.JTextPane;
|
|||||||
import javax.swing.border.EmptyBorder;
|
import javax.swing.border.EmptyBorder;
|
||||||
import javax.swing.event.HyperlinkEvent;
|
import javax.swing.event.HyperlinkEvent;
|
||||||
import javax.swing.event.HyperlinkListener;
|
import javax.swing.event.HyperlinkListener;
|
||||||
import javax.swing.table.TableCellEditor;
|
|
||||||
import javax.swing.table.TableCellRenderer;
|
|
||||||
import javax.swing.text.BadLocationException;
|
import javax.swing.text.BadLocationException;
|
||||||
import javax.swing.text.Document;
|
import javax.swing.text.Document;
|
||||||
import javax.swing.text.html.HTMLDocument;
|
import javax.swing.text.html.HTMLDocument;
|
||||||
@ -59,10 +56,10 @@ import javax.swing.text.html.StyleSheet;
|
|||||||
import processing.app.Base;
|
import processing.app.Base;
|
||||||
import cc.arduino.libraries.contributions.ContributedLibrary;
|
import cc.arduino.libraries.contributions.ContributedLibrary;
|
||||||
import cc.arduino.libraries.contributions.ui.LibrariesIndexTableModel.ContributedLibraryReleases;
|
import cc.arduino.libraries.contributions.ui.LibrariesIndexTableModel.ContributedLibraryReleases;
|
||||||
|
import cc.arduino.ui.InstallerTableCell;
|
||||||
|
|
||||||
@SuppressWarnings("serial")
|
@SuppressWarnings("serial")
|
||||||
public class ContributedLibraryTableCell extends AbstractCellEditor implements
|
public class ContributedLibraryTableCell extends InstallerTableCell {
|
||||||
TableCellEditor, TableCellRenderer {
|
|
||||||
|
|
||||||
private JPanel panel;
|
private JPanel panel;
|
||||||
private JTextPane description;
|
private JTextPane description;
|
||||||
@ -281,7 +278,8 @@ public class ContributedLibraryTableCell extends AbstractCellEditor implements
|
|||||||
return panel;
|
return panel;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setEnabled(boolean enabled) {
|
@Override
|
||||||
|
public void setEnabled(boolean enabled) {
|
||||||
installButton.setEnabled(enabled);
|
installButton.setEnabled(enabled);
|
||||||
removeButton.setEnabled(enabled);
|
removeButton.setEnabled(enabled);
|
||||||
}
|
}
|
||||||
|
@ -34,15 +34,14 @@ import java.util.ArrayList;
|
|||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import javax.swing.table.AbstractTableModel;
|
|
||||||
|
|
||||||
import cc.arduino.libraries.contributions.ContributedLibrary;
|
import cc.arduino.libraries.contributions.ContributedLibrary;
|
||||||
import cc.arduino.libraries.contributions.LibrariesIndexer;
|
import cc.arduino.libraries.contributions.LibrariesIndexer;
|
||||||
import cc.arduino.packages.contributions.ContributedPackage;
|
import cc.arduino.packages.contributions.ContributedPackage;
|
||||||
import cc.arduino.packages.contributions.ContributedPlatform;
|
import cc.arduino.packages.contributions.ContributedPlatform;
|
||||||
|
import cc.arduino.ui.FilteredAbstractTableModel;
|
||||||
|
|
||||||
@SuppressWarnings("serial")
|
@SuppressWarnings("serial")
|
||||||
public class LibrariesIndexTableModel extends AbstractTableModel {
|
public class LibrariesIndexTableModel extends FilteredAbstractTableModel {
|
||||||
|
|
||||||
public final static int DESCRIPTION_COL = 0;
|
public final static int DESCRIPTION_COL = 0;
|
||||||
|
|
||||||
|
@ -28,123 +28,37 @@
|
|||||||
*/
|
*/
|
||||||
package cc.arduino.libraries.contributions.ui;
|
package cc.arduino.libraries.contributions.ui;
|
||||||
|
|
||||||
import static cc.arduino.packages.contributions.ui.ContributionIndexTableModel.DESCRIPTION_COL;
|
|
||||||
import static processing.app.I18n._;
|
|
||||||
|
|
||||||
import java.awt.BorderLayout;
|
|
||||||
import java.awt.Component;
|
|
||||||
import java.awt.Container;
|
|
||||||
import java.awt.Dialog;
|
import java.awt.Dialog;
|
||||||
import java.awt.Dimension;
|
|
||||||
import java.awt.Frame;
|
import java.awt.Frame;
|
||||||
import java.awt.event.ActionEvent;
|
|
||||||
import java.awt.event.ActionListener;
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
|
||||||
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.JScrollPane;
|
|
||||||
import javax.swing.JTable;
|
|
||||||
import javax.swing.ListSelectionModel;
|
|
||||||
import javax.swing.ScrollPaneConstants;
|
|
||||||
import javax.swing.SwingUtilities;
|
|
||||||
import javax.swing.border.EmptyBorder;
|
|
||||||
import javax.swing.event.TableModelEvent;
|
|
||||||
import javax.swing.event.TableModelListener;
|
|
||||||
import javax.swing.table.TableCellEditor;
|
|
||||||
import javax.swing.table.TableCellRenderer;
|
|
||||||
import javax.swing.table.TableColumn;
|
|
||||||
import javax.swing.table.TableColumnModel;
|
|
||||||
|
|
||||||
import processing.app.Theme;
|
|
||||||
import cc.arduino.libraries.contributions.ContributedLibrary;
|
import cc.arduino.libraries.contributions.ContributedLibrary;
|
||||||
import cc.arduino.libraries.contributions.LibrariesIndexer;
|
import cc.arduino.libraries.contributions.LibrariesIndexer;
|
||||||
import cc.arduino.ui.FilterJTextField;
|
import cc.arduino.ui.FilteredAbstractTableModel;
|
||||||
import cc.arduino.ui.ProgressJProgressBar;
|
import cc.arduino.ui.InstallerJDialog;
|
||||||
|
import cc.arduino.ui.InstallerTableCell;
|
||||||
import cc.arduino.utils.Progress;
|
import cc.arduino.utils.Progress;
|
||||||
|
|
||||||
@SuppressWarnings("serial")
|
@SuppressWarnings("serial")
|
||||||
public class LibraryManagerUI extends JDialog {
|
public class LibraryManagerUI extends InstallerJDialog {
|
||||||
|
|
||||||
private FilterJTextField filterField;
|
|
||||||
|
|
||||||
private JLabel categoryLabel;
|
|
||||||
private JComboBox categoryChooser;
|
|
||||||
private Component categoryStrut1;
|
|
||||||
private Component categoryStrut2;
|
|
||||||
private Component categoryStrut3;
|
|
||||||
|
|
||||||
private LibrariesIndexTableModel contribModel = new LibrariesIndexTableModel();
|
|
||||||
private JTable contribTable;
|
|
||||||
private ProgressJProgressBar progressBar;
|
|
||||||
|
|
||||||
private Box progressBox;
|
|
||||||
private Box updateBox;
|
|
||||||
|
|
||||||
private ContributedLibraryTableCell cellEditor;
|
|
||||||
|
|
||||||
// Currently selected category and filters
|
|
||||||
private String category;
|
|
||||||
private String[] filters;
|
|
||||||
|
|
||||||
public LibraryManagerUI(Frame parent) {
|
|
||||||
super(parent, "Library 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);
|
|
||||||
|
|
||||||
categoryLabel = new JLabel(_("Category:"));
|
|
||||||
|
|
||||||
categoryChooser = new JComboBox();
|
|
||||||
categoryChooser.setMaximumRowCount(20);
|
|
||||||
categoryChooser.setEnabled(false);
|
|
||||||
|
|
||||||
filterField = new FilterJTextField(_("Filter your search...")) {
|
|
||||||
@Override
|
@Override
|
||||||
protected void onFilter(String[] _filters) {
|
protected FilteredAbstractTableModel createContribModel() {
|
||||||
filters = _filters;
|
return new LibrariesIndexTableModel();
|
||||||
cellEditor.stopCellEditing();
|
|
||||||
contribModel.updateIndexFilter(category, filters);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
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);
|
private LibrariesIndexTableModel getContribModel() {
|
||||||
contribTable.setTableHeader(null);
|
return (LibrariesIndexTableModel) contribModel;
|
||||||
contribTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
}
|
||||||
contribTable.setColumnSelectionAllowed(false);
|
|
||||||
contribTable.setDragEnabled(false);
|
@Override
|
||||||
contribTable.setIntercellSpacing(new Dimension(0, 1));
|
protected InstallerTableCell createCellRenderer() {
|
||||||
contribTable.setShowVerticalLines(false);
|
return new ContributedLibraryTableCell();
|
||||||
contribTable.setSelectionBackground(Theme.getColor("status.notice.bgcolor"));
|
}
|
||||||
{
|
|
||||||
TableColumnModel tcm = contribTable.getColumnModel();
|
@Override
|
||||||
TableColumn col = tcm.getColumn(DESCRIPTION_COL);
|
protected InstallerTableCell createCellEditor() {
|
||||||
col.setCellRenderer(new ContributedLibraryTableCell());
|
return new ContributedLibraryTableCell() {
|
||||||
cellEditor = new ContributedLibraryTableCell() {
|
|
||||||
@Override
|
@Override
|
||||||
protected void onInstall(ContributedLibrary selectedPlatform) {
|
protected void onInstall(ContributedLibrary selectedPlatform) {
|
||||||
onInstallPressed(selectedPlatform);
|
onInstallPressed(selectedPlatform);
|
||||||
@ -155,89 +69,24 @@ public class LibraryManagerUI extends JDialog {
|
|||||||
onRemovePressed(installedPlatform);
|
onRemovePressed(installedPlatform);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
col.setCellEditor(cellEditor);
|
|
||||||
col.setResizable(true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
public LibraryManagerUI(Frame parent) {
|
||||||
JScrollPane s = new JScrollPane();
|
super(parent, "Library Manager", Dialog.ModalityType.APPLICATION_MODAL);
|
||||||
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);
|
|
||||||
|
|
||||||
{
|
|
||||||
progressBar = new ProgressJProgressBar();
|
|
||||||
progressBar.setStringPainted(true);
|
|
||||||
progressBar.setString(" ");
|
|
||||||
progressBar.setVisible(true);
|
|
||||||
|
|
||||||
JButton cancelButton = new JButton(_("Cancel"));
|
|
||||||
cancelButton.addActionListener(new ActionListener() {
|
|
||||||
@Override
|
|
||||||
public void actionPerformed(ActionEvent arg0) {
|
|
||||||
onCancelPressed();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
JButton updateButton = new JButton(_("Update list"));
|
|
||||||
updateButton.addActionListener(new ActionListener() {
|
|
||||||
@Override
|
|
||||||
public void actionPerformed(ActionEvent arg0) {
|
|
||||||
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(600, 450));
|
|
||||||
}
|
|
||||||
|
|
||||||
private TableModelListener tableModelListener = new TableModelListener() {
|
|
||||||
@Override
|
|
||||||
public void tableChanged(final TableModelEvent arg0) {
|
|
||||||
SwingUtilities.invokeLater(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
updateCellsHeight(arg0);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
public void setIndexer(LibrariesIndexer indexer) {
|
public void setIndexer(LibrariesIndexer indexer) {
|
||||||
contribModel.removeTableModelListener(tableModelListener);
|
getContribModel().removeTableModelListener(tableModelListener);
|
||||||
categoryChooser.removeActionListener(categoryChooserActionListener);
|
categoryChooser.removeActionListener(categoryChooserActionListener);
|
||||||
|
|
||||||
contribModel.setIndexer(indexer);
|
// TODO: Remove setIndexer and make getContribModel
|
||||||
|
// return a FilteredAbstractTableModel
|
||||||
|
getContribModel().setIndexer(indexer);
|
||||||
|
|
||||||
category = null;
|
category = null;
|
||||||
categoryChooser.removeAllItems();
|
categoryChooser.removeAllItems();
|
||||||
|
|
||||||
contribModel.addTableModelListener(tableModelListener);
|
getContribModel().addTableModelListener(tableModelListener);
|
||||||
categoryChooser.addActionListener(categoryChooserActionListener);
|
categoryChooser.addActionListener(categoryChooserActionListener);
|
||||||
|
|
||||||
// Load categories
|
// Load categories
|
||||||
@ -261,46 +110,6 @@ public class LibraryManagerUI extends JDialog {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
ActionListener categoryChooserActionListener = new ActionListener() {
|
|
||||||
@Override
|
|
||||||
public void actionPerformed(ActionEvent arg0) {
|
|
||||||
String selected = (String) categoryChooser.getSelectedItem();
|
|
||||||
if (category == null || !category.equals(selected)) {
|
|
||||||
category = selected;
|
|
||||||
cellEditor.stopCellEditing();
|
|
||||||
contribModel.updateIndexFilter(category, filters);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
public void setProgressVisible(boolean visible) {
|
|
||||||
progressBox.setVisible(visible);
|
|
||||||
|
|
||||||
filterField.setEnabled(!visible);
|
|
||||||
categoryChooser.setEnabled(!visible);
|
|
||||||
contribTable.setEnabled(!visible);
|
|
||||||
updateBox.setVisible(!visible);
|
|
||||||
updateBox.setEnabled(!visible);
|
|
||||||
cellEditor.setEnabled(!visible);
|
|
||||||
|
|
||||||
if (visible && contribTable.isEditing()) {
|
|
||||||
TableCellEditor editor = contribTable.getCellEditor();
|
|
||||||
if (editor != null)
|
|
||||||
editor.stopCellEditing();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void updateCellsHeight(TableModelEvent e) {
|
|
||||||
int first = e.getFirstRow();
|
|
||||||
int last = Math.min(e.getLastRow(), contribTable.getRowCount() - 1);
|
|
||||||
for (int row = first; row <= last; row++) {
|
|
||||||
TableCellRenderer editor = new ContributedLibraryTableCell();
|
|
||||||
Component comp = contribTable.prepareRenderer(editor, row, 0);
|
|
||||||
int height = comp.getPreferredSize().height;
|
|
||||||
contribTable.setRowHeight(row, height);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setProgress(Progress progress) {
|
public void setProgress(Progress progress) {
|
||||||
progressBar.setValue(progress);
|
progressBar.setValue(progress);
|
||||||
}
|
}
|
||||||
@ -312,12 +121,14 @@ public class LibraryManagerUI extends JDialog {
|
|||||||
private LibraryInstaller installer;
|
private LibraryInstaller installer;
|
||||||
private Thread installerThread = null;
|
private Thread installerThread = null;
|
||||||
|
|
||||||
public void onCancelPressed() {
|
@Override
|
||||||
|
protected void onCancelPressed() {
|
||||||
if (installerThread != null)
|
if (installerThread != null)
|
||||||
installerThread.interrupt();
|
installerThread.interrupt();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onUpdatePressed() {
|
@Override
|
||||||
|
protected void onUpdatePressed() {
|
||||||
installerThread = new Thread(new Runnable() {
|
installerThread = new Thread(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
@ -343,7 +154,7 @@ public class LibraryManagerUI extends JDialog {
|
|||||||
try {
|
try {
|
||||||
setProgressVisible(true);
|
setProgressVisible(true);
|
||||||
installer.install(lib);
|
installer.install(lib);
|
||||||
contribModel.updateLibrary(lib);
|
getContribModel().updateLibrary(lib);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
// TODO Show ERROR
|
// TODO Show ERROR
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@ -362,7 +173,7 @@ public class LibraryManagerUI extends JDialog {
|
|||||||
try {
|
try {
|
||||||
setProgressVisible(true);
|
setProgressVisible(true);
|
||||||
installer.remove(lib);
|
installer.remove(lib);
|
||||||
contribModel.updateLibrary(lib);
|
getContribModel().updateLibrary(lib);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
// TODO Show ERROR
|
// TODO Show ERROR
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
@ -38,7 +38,6 @@ import java.awt.Insets;
|
|||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionEvent;
|
||||||
import java.awt.event.ActionListener;
|
import java.awt.event.ActionListener;
|
||||||
|
|
||||||
import javax.swing.AbstractCellEditor;
|
|
||||||
import javax.swing.Box;
|
import javax.swing.Box;
|
||||||
import javax.swing.BoxLayout;
|
import javax.swing.BoxLayout;
|
||||||
import javax.swing.JButton;
|
import javax.swing.JButton;
|
||||||
@ -48,8 +47,6 @@ import javax.swing.JTextPane;
|
|||||||
import javax.swing.border.EmptyBorder;
|
import javax.swing.border.EmptyBorder;
|
||||||
import javax.swing.event.HyperlinkEvent;
|
import javax.swing.event.HyperlinkEvent;
|
||||||
import javax.swing.event.HyperlinkListener;
|
import javax.swing.event.HyperlinkListener;
|
||||||
import javax.swing.table.TableCellEditor;
|
|
||||||
import javax.swing.table.TableCellRenderer;
|
|
||||||
import javax.swing.text.Document;
|
import javax.swing.text.Document;
|
||||||
import javax.swing.text.html.HTMLDocument;
|
import javax.swing.text.html.HTMLDocument;
|
||||||
import javax.swing.text.html.StyleSheet;
|
import javax.swing.text.html.StyleSheet;
|
||||||
@ -58,10 +55,10 @@ import processing.app.Base;
|
|||||||
import cc.arduino.packages.contributions.ContributedBoard;
|
import cc.arduino.packages.contributions.ContributedBoard;
|
||||||
import cc.arduino.packages.contributions.ContributedPlatform;
|
import cc.arduino.packages.contributions.ContributedPlatform;
|
||||||
import cc.arduino.packages.contributions.ui.ContributionIndexTableModel.ContributedPlatformReleases;
|
import cc.arduino.packages.contributions.ui.ContributionIndexTableModel.ContributedPlatformReleases;
|
||||||
|
import cc.arduino.ui.InstallerTableCell;
|
||||||
|
|
||||||
@SuppressWarnings("serial")
|
@SuppressWarnings("serial")
|
||||||
public class ContributedPlatformTableCell extends AbstractCellEditor implements
|
public class ContributedPlatformTableCell extends InstallerTableCell {
|
||||||
TableCellEditor, TableCellRenderer {
|
|
||||||
|
|
||||||
private JPanel panel;
|
private JPanel panel;
|
||||||
private JTextPane description;
|
private JTextPane description;
|
||||||
@ -225,7 +222,8 @@ public class ContributedPlatformTableCell extends AbstractCellEditor implements
|
|||||||
return panel;
|
return panel;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setEnabled(boolean enabled) {
|
@Override
|
||||||
|
public void setEnabled(boolean enabled) {
|
||||||
installButton.setEnabled(enabled);
|
installButton.setEnabled(enabled);
|
||||||
removeButton.setEnabled(enabled);
|
removeButton.setEnabled(enabled);
|
||||||
}
|
}
|
||||||
|
@ -31,14 +31,13 @@ package cc.arduino.packages.contributions.ui;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import javax.swing.table.AbstractTableModel;
|
|
||||||
|
|
||||||
import cc.arduino.packages.contributions.ContributedPackage;
|
import cc.arduino.packages.contributions.ContributedPackage;
|
||||||
import cc.arduino.packages.contributions.ContributedPlatform;
|
import cc.arduino.packages.contributions.ContributedPlatform;
|
||||||
import cc.arduino.packages.contributions.ContributionsIndex;
|
import cc.arduino.packages.contributions.ContributionsIndex;
|
||||||
|
import cc.arduino.ui.FilteredAbstractTableModel;
|
||||||
|
|
||||||
@SuppressWarnings("serial")
|
@SuppressWarnings("serial")
|
||||||
public class ContributionIndexTableModel extends AbstractTableModel {
|
public class ContributionIndexTableModel extends FilteredAbstractTableModel {
|
||||||
|
|
||||||
public final static int DESCRIPTION_COL = 0;
|
public final static int DESCRIPTION_COL = 0;
|
||||||
|
|
||||||
|
@ -28,123 +28,40 @@
|
|||||||
*/
|
*/
|
||||||
package cc.arduino.packages.contributions.ui;
|
package cc.arduino.packages.contributions.ui;
|
||||||
|
|
||||||
import static cc.arduino.packages.contributions.ui.ContributionIndexTableModel.DESCRIPTION_COL;
|
|
||||||
import static processing.app.I18n._;
|
|
||||||
|
|
||||||
import java.awt.BorderLayout;
|
|
||||||
import java.awt.Component;
|
|
||||||
import java.awt.Container;
|
|
||||||
import java.awt.Dialog;
|
import java.awt.Dialog;
|
||||||
import java.awt.Dimension;
|
|
||||||
import java.awt.Frame;
|
import java.awt.Frame;
|
||||||
import java.awt.event.ActionEvent;
|
|
||||||
import java.awt.event.ActionListener;
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
|
||||||
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.JScrollPane;
|
|
||||||
import javax.swing.JTable;
|
|
||||||
import javax.swing.ListSelectionModel;
|
|
||||||
import javax.swing.ScrollPaneConstants;
|
|
||||||
import javax.swing.SwingUtilities;
|
|
||||||
import javax.swing.border.EmptyBorder;
|
|
||||||
import javax.swing.event.TableModelEvent;
|
|
||||||
import javax.swing.event.TableModelListener;
|
|
||||||
import javax.swing.table.TableCellEditor;
|
|
||||||
import javax.swing.table.TableCellRenderer;
|
|
||||||
import javax.swing.table.TableColumn;
|
|
||||||
import javax.swing.table.TableColumnModel;
|
|
||||||
|
|
||||||
import cc.arduino.packages.contributions.ContributedPlatform;
|
import cc.arduino.packages.contributions.ContributedPlatform;
|
||||||
import cc.arduino.packages.contributions.ContributionInstaller;
|
import cc.arduino.packages.contributions.ContributionInstaller;
|
||||||
import cc.arduino.packages.contributions.ContributionsIndexer;
|
import cc.arduino.packages.contributions.ContributionsIndexer;
|
||||||
import cc.arduino.ui.FilterJTextField;
|
import cc.arduino.ui.FilteredAbstractTableModel;
|
||||||
import cc.arduino.ui.ProgressJProgressBar;
|
import cc.arduino.ui.InstallerJDialog;
|
||||||
|
import cc.arduino.ui.InstallerTableCell;
|
||||||
import cc.arduino.utils.Progress;
|
import cc.arduino.utils.Progress;
|
||||||
|
|
||||||
@SuppressWarnings("serial")
|
@SuppressWarnings("serial")
|
||||||
public class ContributionManagerUI extends JDialog {
|
public class ContributionManagerUI extends InstallerJDialog {
|
||||||
|
|
||||||
private FilterJTextField filterField;
|
// private ContributedPlatformTableCell cellEditor;
|
||||||
|
|
||||||
private JLabel categoryLabel;
|
|
||||||
private JComboBox categoryChooser;
|
|
||||||
private Component categoryStrut1;
|
|
||||||
private Component categoryStrut2;
|
|
||||||
private Component categoryStrut3;
|
|
||||||
|
|
||||||
private ContributionIndexTableModel contribModel = new ContributionIndexTableModel();
|
|
||||||
private JTable contribTable;
|
|
||||||
private ProgressJProgressBar progressBar;
|
|
||||||
|
|
||||||
private Box progressBox;
|
|
||||||
private Box updateBox;
|
|
||||||
|
|
||||||
private ContributedPlatformTableCell cellEditor;
|
|
||||||
|
|
||||||
// Currently selected category and filters
|
|
||||||
private String category;
|
|
||||||
private String[] filters;
|
|
||||||
|
|
||||||
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);
|
|
||||||
|
|
||||||
categoryLabel = new JLabel(_("Category:"));
|
|
||||||
|
|
||||||
categoryChooser = new JComboBox();
|
|
||||||
categoryChooser.setMaximumRowCount(20);
|
|
||||||
categoryChooser.setEnabled(false);
|
|
||||||
|
|
||||||
filterField = new FilterJTextField(_("Filter your search...")) {
|
|
||||||
@Override
|
@Override
|
||||||
protected void onFilter(String[] _filters) {
|
protected FilteredAbstractTableModel createContribModel() {
|
||||||
filters = _filters;
|
return new ContributionIndexTableModel();
|
||||||
cellEditor.stopCellEditing();
|
|
||||||
contribModel.updateIndexFilter(category, filters);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
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);
|
private ContributionIndexTableModel getContribModel() {
|
||||||
contribTable.setTableHeader(null);
|
return (ContributionIndexTableModel) contribModel;
|
||||||
contribTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
}
|
||||||
contribTable.setColumnSelectionAllowed(false);
|
|
||||||
contribTable.setDragEnabled(false);
|
|
||||||
contribTable.setIntercellSpacing(new Dimension(0, 1));
|
|
||||||
contribTable.setShowVerticalLines(false);
|
|
||||||
|
|
||||||
{
|
@Override
|
||||||
TableColumnModel tcm = contribTable.getColumnModel();
|
protected InstallerTableCell createCellRenderer() {
|
||||||
TableColumn col = tcm.getColumn(DESCRIPTION_COL);
|
return new ContributedPlatformTableCell();
|
||||||
col.setCellRenderer(new ContributedPlatformTableCell());
|
}
|
||||||
cellEditor = new ContributedPlatformTableCell() {
|
|
||||||
|
@Override
|
||||||
|
protected InstallerTableCell createCellEditor() {
|
||||||
|
return new ContributedPlatformTableCell() {
|
||||||
@Override
|
@Override
|
||||||
protected void onInstall(ContributedPlatform selectedPlatform) {
|
protected void onInstall(ContributedPlatform selectedPlatform) {
|
||||||
onInstallPressed(selectedPlatform);
|
onInstallPressed(selectedPlatform);
|
||||||
@ -155,91 +72,24 @@ public class ContributionManagerUI extends JDialog {
|
|||||||
onRemovePressed(installedPlatform);
|
onRemovePressed(installedPlatform);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
col.setCellEditor(cellEditor);
|
|
||||||
col.setResizable(true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
public ContributionManagerUI(Frame parent) {
|
||||||
JScrollPane s = new JScrollPane();
|
super(parent, "Boards Manager", Dialog.ModalityType.APPLICATION_MODAL);
|
||||||
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);
|
|
||||||
|
|
||||||
{
|
|
||||||
progressBar = new ProgressJProgressBar();
|
|
||||||
progressBar.setStringPainted(true);
|
|
||||||
progressBar.setString(" ");
|
|
||||||
progressBar.setVisible(true);
|
|
||||||
|
|
||||||
JButton cancelButton = new JButton(_("Cancel"));
|
|
||||||
cancelButton.addActionListener(new ActionListener() {
|
|
||||||
@Override
|
|
||||||
public void actionPerformed(ActionEvent arg0) {
|
|
||||||
onCancelPressed();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
JButton updateButton = new JButton(_("Update list"));
|
|
||||||
updateButton.addActionListener(new ActionListener() {
|
|
||||||
@Override
|
|
||||||
public void actionPerformed(ActionEvent arg0) {
|
|
||||||
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(600, 450));
|
|
||||||
}
|
|
||||||
|
|
||||||
private TableModelListener tableModelListener = new TableModelListener() {
|
|
||||||
@Override
|
|
||||||
public void tableChanged(final TableModelEvent arg0) {
|
|
||||||
SwingUtilities.invokeLater(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
updateCellsHeight(arg0);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
public void setIndexer(ContributionsIndexer indexer) {
|
public void setIndexer(ContributionsIndexer indexer) {
|
||||||
contribModel.removeTableModelListener(tableModelListener);
|
getContribModel().removeTableModelListener(tableModelListener);
|
||||||
categoryChooser.removeActionListener(categoryChooserActionListener);
|
categoryChooser.removeActionListener(categoryChooserActionListener);
|
||||||
|
|
||||||
contribModel.setIndex(indexer.getIndex());
|
getContribModel().setIndex(indexer.getIndex());
|
||||||
|
|
||||||
category = null;
|
category = null;
|
||||||
categoryChooser.removeAllItems();
|
categoryChooser.removeAllItems();
|
||||||
|
|
||||||
filterField.setEnabled(contribModel.getRowCount() > 0);
|
filterField.setEnabled(getContribModel().getRowCount() > 0);
|
||||||
|
|
||||||
contribModel.addTableModelListener(tableModelListener);
|
getContribModel().addTableModelListener(tableModelListener);
|
||||||
categoryChooser.addActionListener(categoryChooserActionListener);
|
categoryChooser.addActionListener(categoryChooserActionListener);
|
||||||
|
|
||||||
// Enable categories combo only if there are two or more choices
|
// Enable categories combo only if there are two or more choices
|
||||||
@ -259,46 +109,6 @@ public class ContributionManagerUI extends JDialog {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
ActionListener categoryChooserActionListener = new ActionListener() {
|
|
||||||
@Override
|
|
||||||
public void actionPerformed(ActionEvent arg0) {
|
|
||||||
String selected = (String) categoryChooser.getSelectedItem();
|
|
||||||
if (category == null || !category.equals(selected)) {
|
|
||||||
category = selected;
|
|
||||||
cellEditor.stopCellEditing();
|
|
||||||
contribModel.updateIndexFilter(category, filters);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
public void setProgressVisible(boolean visible) {
|
|
||||||
progressBox.setVisible(visible);
|
|
||||||
|
|
||||||
filterField.setEnabled(!visible);
|
|
||||||
categoryChooser.setEnabled(!visible);
|
|
||||||
contribTable.setEnabled(!visible);
|
|
||||||
updateBox.setVisible(!visible);
|
|
||||||
updateBox.setEnabled(!visible);
|
|
||||||
cellEditor.setEnabled(!visible);
|
|
||||||
|
|
||||||
if (visible && contribTable.isEditing()) {
|
|
||||||
TableCellEditor editor = contribTable.getCellEditor();
|
|
||||||
if (editor != null)
|
|
||||||
editor.stopCellEditing();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void updateCellsHeight(TableModelEvent e) {
|
|
||||||
int first = e.getFirstRow();
|
|
||||||
int last = Math.min(e.getLastRow(), contribTable.getRowCount() - 1);
|
|
||||||
for (int row = first; row <= last; row++) {
|
|
||||||
TableCellRenderer editor = new ContributedPlatformTableCell();
|
|
||||||
Component comp = contribTable.prepareRenderer(editor, row, 0);
|
|
||||||
int height = comp.getPreferredSize().height;
|
|
||||||
contribTable.setRowHeight(row, height);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setProgress(Progress progress) {
|
public void setProgress(Progress progress) {
|
||||||
progressBar.setValue(progress);
|
progressBar.setValue(progress);
|
||||||
}
|
}
|
||||||
@ -310,11 +120,13 @@ public class ContributionManagerUI extends JDialog {
|
|||||||
private ContributionInstaller installer;
|
private ContributionInstaller installer;
|
||||||
private Thread installerThread = null;
|
private Thread installerThread = null;
|
||||||
|
|
||||||
|
@Override
|
||||||
public void onCancelPressed() {
|
public void onCancelPressed() {
|
||||||
if (installerThread != null)
|
if (installerThread != null)
|
||||||
installerThread.interrupt();
|
installerThread.interrupt();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void onUpdatePressed() {
|
public void onUpdatePressed() {
|
||||||
installerThread = new Thread(new Runnable() {
|
installerThread = new Thread(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
@ -370,6 +182,11 @@ public class ContributionManagerUI extends JDialog {
|
|||||||
installerThread.start();
|
installerThread.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Callback invoked when indexes are updated
|
||||||
|
*
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
protected void onIndexesUpdated() throws Exception {
|
protected void onIndexesUpdated() throws Exception {
|
||||||
// Empty
|
// Empty
|
||||||
}
|
}
|
||||||
|
37
app/src/cc/arduino/ui/FilteredAbstractTableModel.java
Normal file
37
app/src/cc/arduino/ui/FilteredAbstractTableModel.java
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
/*
|
||||||
|
* 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.ui;
|
||||||
|
|
||||||
|
import javax.swing.table.AbstractTableModel;
|
||||||
|
|
||||||
|
public abstract class FilteredAbstractTableModel extends AbstractTableModel {
|
||||||
|
|
||||||
|
abstract public void updateIndexFilter(String category, String[] filters);
|
||||||
|
|
||||||
|
}
|
281
app/src/cc/arduino/ui/InstallerJDialog.java
Normal file
281
app/src/cc/arduino/ui/InstallerJDialog.java
Normal file
@ -0,0 +1,281 @@
|
|||||||
|
/*
|
||||||
|
* 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.ui;
|
||||||
|
|
||||||
|
import static cc.arduino.packages.contributions.ui.ContributionIndexTableModel.DESCRIPTION_COL;
|
||||||
|
import static processing.app.I18n._;
|
||||||
|
|
||||||
|
import java.awt.BorderLayout;
|
||||||
|
import java.awt.Component;
|
||||||
|
import java.awt.Container;
|
||||||
|
import java.awt.Dimension;
|
||||||
|
import java.awt.Frame;
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
import java.awt.event.ActionListener;
|
||||||
|
|
||||||
|
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.JScrollPane;
|
||||||
|
import javax.swing.JTable;
|
||||||
|
import javax.swing.ListSelectionModel;
|
||||||
|
import javax.swing.ScrollPaneConstants;
|
||||||
|
import javax.swing.SwingUtilities;
|
||||||
|
import javax.swing.border.EmptyBorder;
|
||||||
|
import javax.swing.event.TableModelEvent;
|
||||||
|
import javax.swing.event.TableModelListener;
|
||||||
|
import javax.swing.table.TableCellEditor;
|
||||||
|
import javax.swing.table.TableCellRenderer;
|
||||||
|
import javax.swing.table.TableColumn;
|
||||||
|
import javax.swing.table.TableColumnModel;
|
||||||
|
|
||||||
|
import processing.app.Theme;
|
||||||
|
|
||||||
|
public abstract class InstallerJDialog extends JDialog {
|
||||||
|
|
||||||
|
// Toolbar on top of the window:
|
||||||
|
// - Categories drop-down menu
|
||||||
|
protected JLabel categoryLabel;
|
||||||
|
protected JComboBox categoryChooser;
|
||||||
|
protected Component categoryStrut1;
|
||||||
|
protected Component categoryStrut2;
|
||||||
|
protected Component categoryStrut3;
|
||||||
|
// - Search text-field
|
||||||
|
protected FilterJTextField filterField;
|
||||||
|
// Currently selected category and filters
|
||||||
|
protected String category;
|
||||||
|
protected String[] filters;
|
||||||
|
|
||||||
|
// Real contribution table
|
||||||
|
protected JTable contribTable;
|
||||||
|
// Model behind the table
|
||||||
|
protected FilteredAbstractTableModel contribModel;
|
||||||
|
// Default table model listener
|
||||||
|
protected TableModelListener tableModelListener = new TableModelListener() {
|
||||||
|
@Override
|
||||||
|
public void tableChanged(final TableModelEvent event) {
|
||||||
|
SwingUtilities.invokeLater(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
updateCellsHeight(event);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
abstract protected FilteredAbstractTableModel createContribModel();
|
||||||
|
|
||||||
|
abstract protected InstallerTableCell createCellRenderer();
|
||||||
|
|
||||||
|
abstract protected InstallerTableCell createCellEditor();
|
||||||
|
|
||||||
|
// Bottom:
|
||||||
|
// - Progress bar
|
||||||
|
protected ProgressJProgressBar progressBar;
|
||||||
|
protected Box progressBox;
|
||||||
|
protected Box updateBox;
|
||||||
|
|
||||||
|
protected InstallerTableCell cellEditor;
|
||||||
|
|
||||||
|
public InstallerJDialog(Frame parent, String title,
|
||||||
|
ModalityType applicationModal) {
|
||||||
|
super(parent, title, applicationModal);
|
||||||
|
|
||||||
|
setResizable(true);
|
||||||
|
|
||||||
|
Container pane = getContentPane();
|
||||||
|
pane.setLayout(new BorderLayout());
|
||||||
|
|
||||||
|
{
|
||||||
|
categoryStrut1 = Box.createHorizontalStrut(5);
|
||||||
|
categoryStrut2 = Box.createHorizontalStrut(5);
|
||||||
|
categoryStrut3 = Box.createHorizontalStrut(5);
|
||||||
|
|
||||||
|
categoryLabel = new JLabel(_("Category:"));
|
||||||
|
|
||||||
|
categoryChooser = new JComboBox();
|
||||||
|
categoryChooser.setMaximumRowCount(20);
|
||||||
|
categoryChooser.setEnabled(false);
|
||||||
|
|
||||||
|
filterField = new FilterJTextField(_("Filter your search...")) {
|
||||||
|
@Override
|
||||||
|
protected void onFilter(String[] _filters) {
|
||||||
|
filters = _filters;
|
||||||
|
cellEditor.stopCellEditing();
|
||||||
|
contribModel.updateIndexFilter(category, filters);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
contribModel = createContribModel();
|
||||||
|
contribTable = new JTable(contribModel);
|
||||||
|
contribTable.setTableHeader(null);
|
||||||
|
contribTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
||||||
|
contribTable.setColumnSelectionAllowed(false);
|
||||||
|
contribTable.setDragEnabled(false);
|
||||||
|
contribTable.setIntercellSpacing(new Dimension(0, 1));
|
||||||
|
contribTable.setShowVerticalLines(false);
|
||||||
|
contribTable
|
||||||
|
.setSelectionBackground(Theme.getColor("status.notice.bgcolor"));
|
||||||
|
|
||||||
|
{
|
||||||
|
TableColumnModel tcm = contribTable.getColumnModel();
|
||||||
|
TableColumn col = tcm.getColumn(DESCRIPTION_COL);
|
||||||
|
col.setCellRenderer(createCellRenderer());
|
||||||
|
cellEditor = createCellEditor();
|
||||||
|
col.setCellEditor(cellEditor);
|
||||||
|
col.setResizable(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
JScrollPane s = new JScrollPane();
|
||||||
|
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);
|
||||||
|
|
||||||
|
progressBar = new ProgressJProgressBar();
|
||||||
|
progressBar.setStringPainted(true);
|
||||||
|
progressBar.setString(" ");
|
||||||
|
progressBar.setVisible(true);
|
||||||
|
|
||||||
|
{
|
||||||
|
JButton cancelButton = new JButton(_("Cancel"));
|
||||||
|
cancelButton.addActionListener(new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent arg0) {
|
||||||
|
onCancelPressed();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
JButton updateButton = new JButton(_("Update list"));
|
||||||
|
updateButton.addActionListener(new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent arg0) {
|
||||||
|
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(600, 450));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setProgressVisible(boolean visible) {
|
||||||
|
progressBox.setVisible(visible);
|
||||||
|
|
||||||
|
filterField.setEnabled(!visible);
|
||||||
|
categoryChooser.setEnabled(!visible);
|
||||||
|
contribTable.setEnabled(!visible);
|
||||||
|
updateBox.setVisible(!visible);
|
||||||
|
updateBox.setEnabled(!visible);
|
||||||
|
cellEditor.setEnabled(!visible);
|
||||||
|
|
||||||
|
if (visible && contribTable.isEditing()) {
|
||||||
|
TableCellEditor editor = contribTable.getCellEditor();
|
||||||
|
if (editor != null)
|
||||||
|
editor.stopCellEditing();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateCellsHeight(TableModelEvent e) {
|
||||||
|
int first = e.getFirstRow();
|
||||||
|
int last = Math.min(e.getLastRow(), contribTable.getRowCount() - 1);
|
||||||
|
for (int row = first; row <= last; row++) {
|
||||||
|
TableCellRenderer editor = createCellRenderer();
|
||||||
|
Component comp = contribTable.prepareRenderer(editor, row, 0);
|
||||||
|
int height = comp.getPreferredSize().height;
|
||||||
|
contribTable.setRowHeight(row, height);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected ActionListener categoryChooserActionListener = new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent arg0) {
|
||||||
|
String selected = (String) categoryChooser.getSelectedItem();
|
||||||
|
if (category == null || !category.equals(selected)) {
|
||||||
|
category = selected;
|
||||||
|
cellEditor.stopCellEditing();
|
||||||
|
contribModel.updateIndexFilter(category, filters);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Action performed when the Cancel button is pressed.
|
||||||
|
*/
|
||||||
|
protected void onCancelPressed() {
|
||||||
|
// Empty
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Action performed when the "Update List" button is pressed.
|
||||||
|
*/
|
||||||
|
protected void onUpdatePressed() {
|
||||||
|
// Empty
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
42
app/src/cc/arduino/ui/InstallerTableCell.java
Normal file
42
app/src/cc/arduino/ui/InstallerTableCell.java
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
/*
|
||||||
|
* 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.ui;
|
||||||
|
|
||||||
|
import javax.swing.AbstractCellEditor;
|
||||||
|
import javax.swing.table.TableCellEditor;
|
||||||
|
import javax.swing.table.TableCellRenderer;
|
||||||
|
|
||||||
|
public abstract class InstallerTableCell extends AbstractCellEditor implements
|
||||||
|
TableCellEditor, TableCellRenderer {
|
||||||
|
|
||||||
|
public void setEnabled(boolean b) {
|
||||||
|
// Empty
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user