deeper into the contrib manager rabbit hole

This commit is contained in:
Ben Fry
2015-09-22 15:31:50 -04:00
parent 57453ce9f8
commit 6ef565f7c3
9 changed files with 187 additions and 146 deletions
+3 -2
View File
@@ -268,7 +268,8 @@ public class Base {
public Base(String[] args) throws Exception {
ContributionManager.cleanup(this);
ContributionManager.init(this);
buildCoreModes();
rebuildContribModes();
rebuildContribExamples();
@@ -686,7 +687,7 @@ public class Base {
JMenuItem item = new JMenuItem(Language.text("menu.tools.add_tool"));
item.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
ContributionManager.openToolManager(getActiveEditor());
ContributionManager.openTools();
}
});
toolsMenu.add(item);
+2 -2
View File
@@ -416,7 +416,7 @@ public abstract class Mode {
item = new JMenuItem(Language.text("examples.add_examples"));
item.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
ContributionManager.openExampleManager(base.getActiveEditor());
ContributionManager.openExamples();
}
});
toolbarMenu.add(item);
@@ -492,7 +492,7 @@ public abstract class Mode {
JMenuItem addLib = new JMenuItem(Language.text("menu.library.add_library"));
addLib.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
ContributionManager.openLibraryManager(base.getActiveEditor());
ContributionManager.openLibraries();
}
});
importMenu.add(addLib);
+1 -1
View File
@@ -180,7 +180,7 @@ public class UpdateCheck {
options,
options[0]);
if (result == JOptionPane.YES_OPTION) {
ContributionManager.openUpdates(base.getActiveEditor());
ContributionManager.openUpdates();
return true;
}
@@ -30,7 +30,6 @@ import javax.swing.SwingWorker;
import processing.app.Base;
import processing.app.Language;
import processing.app.Messages;
import processing.app.Settings;
import processing.app.Util;
import processing.app.ui.Editor;
import processing.core.PApplet;
@@ -481,7 +480,7 @@ public class ContributionManager {
* and remove any "requires restart" flags.
* Also updates all entries previously marked for update.
*/
static public void cleanup(final Base base) throws Exception {
static private void cleanup(final Base base) throws Exception {
deleteTemp(Base.getSketchbookModesFolder());
deleteTemp(Base.getSketchbookToolsFolder());
@@ -649,47 +648,52 @@ public class ContributionManager {
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
static ManagerFrame managerDialog =
new ManagerFrame();
static ManagerFrame managerDialog;
static public void init(Base base) throws Exception {
managerDialog = new ManagerFrame(base);
cleanup(base);
}
/**
* Show the Library installer window.
*/
static public void openLibraryManager(Editor editor) {
managerDialog.showFrame(editor, ContributionType.LIBRARY);
}
/**
* Show the Tool installer window.
*/
static public void openToolManager(Editor editor) {
managerDialog.showFrame(editor, ContributionType.TOOL);
static public void openLibraries() {
managerDialog.showFrame(ContributionType.LIBRARY);
}
/**
* Show the Mode installer window.
*/
static public void openModeManager(Editor editor) {
managerDialog.showFrame(editor, ContributionType.MODE);
static public void openModes() {
managerDialog.showFrame(ContributionType.MODE);
}
/**
* Show the Tool installer window.
*/
static public void openTools() {
managerDialog.showFrame(ContributionType.TOOL);
}
/**
* Show the Examples installer window.
*/
static public void openExampleManager(Editor editor) {
managerDialog.showFrame(editor, ContributionType.EXAMPLES);
static public void openExamples() {
managerDialog.showFrame(ContributionType.EXAMPLES);
}
/**
* Open the updates panel.
*/
static public void openUpdates(Editor editor) {
managerDialog.showFrame(editor, null);
static public void openUpdates() {
managerDialog.showFrame(null);
}
+115 -92
View File
@@ -3,7 +3,7 @@
/*
Part of the Processing project - http://processing.org
Copyright (c) 2013 The Processing Foundation
Copyright (c) 2013-15 The Processing Foundation
Copyright (c) 2011-12 Ben Fry and Casey Reas
This program is free software; you can redistribute it and/or modify
@@ -25,10 +25,6 @@ import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.EmptyBorder;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import javax.swing.plaf.basic.BasicTabbedPaneUI;
import processing.app.*;
import processing.app.ui.Editor;
@@ -46,30 +42,33 @@ public class ManagerFrame {
static final int TAB_HEIGHT = 34;
static final int AUTHOR_WIDTH = 240;
static final int STATUS_WIDTH = 66;
static final int BORDER = 8;
static final String title = "Manager";
Base base;
JFrame frame;
JTabbedPane tabbedPane;
// JTabbedPane tabbedPane;
ManagerTabs tabs;
// the calling editor, so updates can be applied
Editor editor;
// Editor editor;
ContributionTab librariesTab;
ContributionTab modesTab;
ContributionTab toolsTab;
ContributionTab examplesTab;
UpdateContributionTab updatesTab;
JLabel numberLabel;
// JLabel numberLabel;
private JLabel[] tabLabels;
private JPanel updateTabPanel;
private JLabel updateTabLabel;
// private JLabel[] tabLabels;
// private JPanel updateTabPanel;
// private JLabel updateTabLabel;
public ManagerFrame() {
numberLabel = new JLabel(Toolkit.getLibIconX("manager/notification"));
public ManagerFrame(Base base) {
this.base = base;
// numberLabel = new JLabel(Toolkit.getLibIconX("manager/notification"));
librariesTab = new ContributionTab(ContributionType.LIBRARY, this);
modesTab = new ContributionTab(ContributionType.MODE, this);
toolsTab = new ContributionTab(ContributionType.TOOL, this);
@@ -78,53 +77,54 @@ public class ManagerFrame {
}
public void showFrame(Editor editor, ContributionType contributionType) {
this.editor = editor;
// TODO remove this Editor... need to use Base.getActiveEditor()
// The editor may be closed while still running the contrib manager
public void showFrame(ContributionType contributionType) {
// this.editor = editor;
ContributionTab showTab = getTab(contributionType);
// Calculating index to switch to the required tab
int index = ContributionManager.getTypeIndex(contributionType);
//int index = ContributionManager.getTypeIndex(contributionType);
if (frame == null) {
makeFrame(editor);
makeFrame();
// done before as downloadAndUpdateContributionListing()
// requires the current selected tab
tabbedPane.setSelectedIndex(index);
downloadAndUpdateContributionListing(editor.getBase());
if (index != 4) {
Component selected =
tabbedPane.getTabComponentAt(tabbedPane.getSelectedIndex());
// tabbedPane.setSelectedIndex(index);
tabs.setPanel(showTab);
downloadAndUpdateContributionListing(base);
if (showTab != updatesTab) {
// Component selected =
// tabbedPane.getTabComponentAt(tabbedPane.getSelectedIndex());
Component selected = showTab; // what the.. ? [fry]
selected.setBackground(new Color(0xe0fffd));
selected.setForeground(Color.BLACK);
} else {
updateTabPanel.setBackground(new Color(0xe0fffd));
updateTabLabel.setForeground(Color.BLACK);
// updateTabPanel.setBackground(new Color(0xe0fffd));
// updateTabLabel.setForeground(Color.BLACK);
}
} else {
// tabbedPane.setSelectedIndex(index);
tabs.setPanel(showTab);
}
tabbedPane.setSelectedIndex(index);
frame.setVisible(true);
}
protected ContributionTab getTab(ContributionType contributionType) {
if (contributionType == ContributionType.LIBRARY) {
return librariesTab;
} else if (contributionType == ContributionType.MODE) {
return modesTab;
} else if (contributionType == ContributionType.TOOL) {
return toolsTab;
} else if (contributionType == ContributionType.EXAMPLES) {
return examplesTab;
}
return updatesTab;
}
private void makeFrame(final Editor editor) {
private void makeFrame() {
frame = new JFrame(title);
frame.setMinimumSize(new Dimension(750, 500));
tabbedPane = new JTabbedPane();
tabs = new ManagerTabs(base);
makeAndShowTab(false, true);
tabs.add(librariesTab);
tabs.add(modesTab);
tabs.add(toolsTab);
tabs.add(examplesTab);
tabs.add(updatesTab);
/*
tabbedPane.addTab("Libraries", null, librariesTab, "Libraries");
tabbedPane.setMnemonicAt(0, KeyEvent.VK_1);
@@ -147,47 +147,9 @@ public class ManagerFrame {
for (int i = 0; i < 5; i++) {
tabbedPane.setToolTipTextAt(i, null);
}
*/
makeAndSetTabComponents();
tabbedPane.addChangeListener(new ChangeListener() {
@Override
public void stateChanged(ChangeEvent e) {
for(int i = 0 ; i < 4; i++){
tabLabels[i].setBackground(new Color(0x2d4251));
tabLabels[i].setForeground(Color.WHITE);
}
updateTabPanel.setBackground(new Color(0x2d4251));
updateTabLabel.setForeground(Color.WHITE);
int currentIndex = tabbedPane.getSelectedIndex();
if(currentIndex != 4){
tabbedPane.getTabComponentAt(tabbedPane.getSelectedIndex()).setBackground(new Color(0xe0fffd));
tabbedPane.getTabComponentAt(tabbedPane.getSelectedIndex()).setForeground(Color.BLACK);
}else{
updateTabPanel.setBackground(new Color(0xe0fffd));
updateTabLabel.setForeground(Color.BLACK);
}
getActiveTab().contributionListPanel.scrollPane.requestFocusInWindow();
}
});
frame.setResizable(true);
tabbedPane.setBorder(new EmptyBorder(BORDER, BORDER, BORDER, BORDER));
frame.getContentPane().add(tabbedPane);
frame.getContentPane().setBackground(new Color(0x132638));
frame.validate();
frame.repaint();
Toolkit.setIcon(frame);
registerDisposeListeners();
frame.pack();
frame.setLocationRelativeTo(null);
}
private void makeAndSetTabComponents() {
/*
final String[] tabTitles = {
"Libraries", "Modes", "Tools", "Examples", "Updates"
};
@@ -215,7 +177,9 @@ public class ManagerFrame {
tabLabels[i].setFont(Toolkit.getSansFont(14, Font.BOLD));
tabbedPane.setTabComponentAt(i, tabLabels[i]);
}
*/
/*
updateTabPanel = new JPanel() {
@Override
protected void paintComponent(Graphics g) {
@@ -236,7 +200,9 @@ public class ManagerFrame {
updateTabPanel.setBorder(BorderFactory.createEmptyBorder(6, 6, 6, 6));
updateTabPanel.setPreferredSize(new Dimension(TAB_WIDTH, TAB_HEIGHT));
tabbedPane.setTabComponentAt(4, updateTabPanel);
*/
/*
GroupLayout tabLayout = new GroupLayout(updateTabPanel);
tabLayout.setAutoCreateGaps(true);
updateTabPanel.setLayout(tabLayout);
@@ -253,13 +219,60 @@ public class ManagerFrame {
.addComponent(numberLabel).addComponent(updateTabLabel));
numberLabel.setVisible(false);
*/
/*
tabbedPane.addChangeListener(new ChangeListener() {
@Override
public void stateChanged(ChangeEvent e) {
for(int i = 0 ; i < 4; i++){
tabLabels[i].setBackground(new Color(0x2d4251));
tabLabels[i].setForeground(Color.WHITE);
}
updateTabPanel.setBackground(new Color(0x2d4251));
updateTabLabel.setForeground(Color.WHITE);
int currentIndex = tabbedPane.getSelectedIndex();
if(currentIndex != 4){
tabbedPane.getTabComponentAt(tabbedPane.getSelectedIndex()).setBackground(new Color(0xe0fffd));
tabbedPane.getTabComponentAt(tabbedPane.getSelectedIndex()).setForeground(Color.BLACK);
}else{
updateTabPanel.setBackground(new Color(0xe0fffd));
updateTabLabel.setForeground(Color.BLACK);
}
getActiveTab().contributionListPanel.scrollPane.requestFocusInWindow();
}
});
*/
frame.setResizable(true);
// tabbedPane.setBorder(new EmptyBorder(BORDER, BORDER, BORDER, BORDER));
frame.getContentPane().add(tabs);
frame.validate();
frame.repaint();
Toolkit.setIcon(frame);
registerDisposeListeners();
frame.pack();
frame.setLocationRelativeTo(null);
}
/**
* Close the window after an OK or Cancel.
*/
protected void disposeFrame() {
frame.dispose();
// editor = null;
}
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
public class SpacedTabbedPaneUI extends BasicTabbedPaneUI {
/*
private class SpacedTabbedPaneUI extends BasicTabbedPaneUI {
@Override
protected void installDefaults() {
@@ -317,20 +330,12 @@ public class ManagerFrame {
};
}
}
*/
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
/**
* Close the window after an OK or Cancel.
*/
protected void disposeFrame() {
frame.dispose();
editor = null;
}
private void registerDisposeListeners() {
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
@@ -399,6 +404,7 @@ public class ManagerFrame {
void makeAndShowTab(boolean error, boolean loading) {
Editor editor = base.getActiveEditor();
librariesTab.showFrame(editor, error, loading);
modesTab.showFrame(editor, error, loading);
toolsTab.showFrame(editor, error, loading);
@@ -407,7 +413,23 @@ public class ManagerFrame {
}
protected ContributionTab getTab(ContributionType contributionType) {
if (contributionType == ContributionType.LIBRARY) {
return librariesTab;
} else if (contributionType == ContributionType.MODE) {
return modesTab;
} else if (contributionType == ContributionType.TOOL) {
return toolsTab;
} else if (contributionType == ContributionType.EXAMPLES) {
return examplesTab;
}
return updatesTab;
}
ContributionTab getActiveTab() {
return (ContributionTab) tabs.getPanel();
/*
switch (tabbedPane.getSelectedIndex()) {
case 0:
return librariesTab;
@@ -420,5 +442,6 @@ public class ManagerFrame {
default:
return updatesTab;
}
*/
}
}
+33 -19
View File
@@ -36,9 +36,10 @@ import java.util.ArrayList;
import java.util.List;
import javax.swing.*;
import javax.swing.border.EmptyBorder;
import processing.app.Base;
import processing.app.Mode;
import processing.app.Sketch;
import processing.app.ui.Editor;
import processing.app.ui.Toolkit;
@@ -50,6 +51,9 @@ public class ManagerTabs extends Box {
// height of this tab bar
static final int HIGH = 32;
// amount of space around the entire window
static final int BORDER = 8;
static final int CURVE_RADIUS = 6;
static final int TAB_TOP = 2;
@@ -70,9 +74,9 @@ public class ManagerTabs extends Box {
Color[] textColor = new Color[2];
Color[] tabColor = new Color[2];
Editor editor;
List<Tab> tabList = new ArrayList<>();
List<Tab> tabs = new ArrayList<>();
Mode mode;
Font font;
int fontAscent;
@@ -87,14 +91,15 @@ public class ManagerTabs extends Box {
CardLayout cardLayout;
Controller controller;
Component currentPanel;
public ManagerTabs(Editor eddie) {
public ManagerTabs(Base base) {
super(BoxLayout.Y_AXIS);
this.editor = eddie;
// A mode shouldn't actually override these, they're coming from theme.txt.
// But use the default (Java) mode settings just in case.
Mode mode = editor.getBase().getDefaultMode();
mode = base.getDefaultMode();
textColor[SELECTED] = mode.getColor("manager.tab.text.selected.color");
textColor[UNSELECTED] = mode.getColor("manager.tab.text.unselected.color");
@@ -105,6 +110,9 @@ public class ManagerTabs extends Box {
gradient = mode.makeGradient("manager.tab", 400, HIGH);
setBackground(mode.getColor("manager.tab.background"));
setBorder(new EmptyBorder(BORDER, BORDER, BORDER, BORDER));
controller = new Controller();
add(controller);
@@ -127,7 +135,10 @@ public class ManagerTabs extends Box {
* @param icon Prefix of the file name for the icon
*/
public void addPanel(Component comp, String name, String icon) {
tabs.add(new Tab(comp, name, icon));
if (tabList.isEmpty()) {
currentPanel = comp;
}
tabList.add(new Tab(comp, name, icon));
cardPanel.add(name, comp);
}
@@ -138,8 +149,9 @@ public class ManagerTabs extends Box {
public void setPanel(Component comp) {
for (Tab tab : tabs) {
for (Tab tab : tabList) {
if (tab.comp == comp) {
currentPanel = comp;
cardLayout.show(cardPanel, tab.name);
repaint();
}
@@ -147,8 +159,13 @@ public class ManagerTabs extends Box {
}
public Component getPanel() {
return currentPanel;
}
public void setNotification(Component comp, boolean note) {
for (Tab tab : tabs) {
for (Tab tab : tabList) {
if (tab.comp == comp) {
tab.notification = note;
repaint();
@@ -166,10 +183,10 @@ public class ManagerTabs extends Box {
addMouseListener(new MouseAdapter() {
public void mousePressed(MouseEvent e) {
int x = e.getX();
for (Tab tab : tabs) {
for (Tab tab : tabList) {
if (tab.contains(x)) {
//editor.setFooterPanel(tab.index);
cardLayout.show(cardPanel, tab.name);
//cardLayout.show(cardPanel, tab.name);
setPanel(tab.comp);
repaint();
}
}
@@ -179,8 +196,6 @@ public class ManagerTabs extends Box {
public void paintComponent(Graphics screen) {
if (screen == null) return;
Sketch sketch = editor.getSketch();
if (sketch == null) return; // possible?
Dimension size = getSize();
if ((size.width != sizeW) || (size.height != sizeH)) {
@@ -223,7 +238,7 @@ public class ManagerTabs extends Box {
g.drawImage(gradient, 0, 2, imageW, imageH, this);
// reset all tab positions
for (Tab tab : tabs) {
for (Tab tab : tabList) {
tab.textWidth = (int)
font.getStringBounds(tab.name, g2.getFontRenderContext()).getWidth();
}
@@ -248,7 +263,7 @@ public class ManagerTabs extends Box {
private void placeTabs(int left, Graphics2D g) {
int x = left;
for (Tab tab : tabs) {
for (Tab tab : tabList) {
tab.left = x;
x += MARGIN;
if (tab.hasIcon()) {
@@ -332,7 +347,6 @@ public class ManagerTabs extends Box {
this.name = name;
if (icon != null) {
Mode mode = editor.getMode();
enabledIcon = mode.loadImageX(icon + "-enabled");
selectedIcon = mode.loadImageX(icon + "-selected");
if (selectedIcon == null) {
@@ -350,11 +364,11 @@ public class ManagerTabs extends Box {
}
boolean isFirst() {
return tabs.get(0) == this;
return tabList.get(0) == this;
}
boolean isLast() {
return tabs.get(tabs.size() - 1) == this;
return tabList.get(tabList.size() - 1) == this;
}
int getTextLeft() {
@@ -12,7 +12,6 @@ import javax.swing.BorderFactory;
import javax.swing.GroupLayout;
import javax.swing.Icon;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.ListSelectionModel;
@@ -148,13 +147,13 @@ public class UpdateListPanel extends ListPanel {
@Override
void updatePanelOrdering(Set<Contribution> contributionsSet) {
JLabel label = contributionTab.contribDialog.numberLabel;
if (getNoOfRows() == 0) {
label.setVisible(false);
} else {
label.setVisible(true);
label.setText(Integer.toString(panelByContribution.size()));
}
// JLabel label = contributionTab.contribDialog.numberLabel;
// if (getNoOfRows() == 0) {
// label.setVisible(false);
// } else {
// label.setVisible(true);
// label.setText(Integer.toString(panelByContribution.size()));
// }
model.getDataVector().removeAllElements();
model.fireTableDataChanged();
ContributionType temp = null;
+1 -1
View File
@@ -501,7 +501,7 @@ public abstract class Editor extends JFrame implements RunnerListener {
JMenuItem addLib = new JMenuItem(Language.text("toolbar.add_mode"));
addLib.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
ContributionManager.openModeManager(Editor.this);
ContributionManager.openModes();
}
});
modePopup.add(addLib);
+1 -1
View File
@@ -108,7 +108,7 @@ public class ExamplesFrame extends JFrame {
addExamplesButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
ContributionManager.openExampleManager(base.getActiveEditor());
ContributionManager.openExamples();
}
});