Skip to content

Commit

Permalink
Showing 2 changed files with 10 additions and 77 deletions.
85 changes: 8 additions & 77 deletions app/src/processing/app/contrib/ManagerTabs.java
Original file line number Diff line number Diff line change
@@ -63,11 +63,6 @@ public class ManagerTabs extends Box {
// amount of margin on the left/right for the text on the tab
static final int MARGIN = Toolkit.zoom(14);

static final int ICON_WIDTH = Toolkit.zoom(16);
static final int ICON_HEIGHT = Toolkit.zoom(16);
static final int ICON_TOP = Toolkit.zoom(7);
static final int ICON_MARGIN = Toolkit.zoom(7);

static final int UNSELECTED = 0;
static final int SELECTED = 1;

@@ -81,8 +76,6 @@ public class ManagerTabs extends Box {
Font font;
int fontAscent;

Image gradient;

JPanel cardPanel;
CardLayout cardLayout;
Controller controller;
@@ -117,32 +110,20 @@ public ManagerTabs(Base base) {
}


/** Add a panel with no icon. */
public void addPanel(Component comp, String name) {
addPanel(comp, name, null);
}


/**
* Add a panel with a name and icon.
* Add a panel with a name.
* @param comp Component that will be shown when this tab is selected
* @param name Title to appear on the tab itself
* @param icon Prefix of the file name for the icon
*/
public void addPanel(Component comp, String name, String icon) {
public void addPanel(Component comp, String name) {
if (tabList.isEmpty()) {
currentPanel = comp;
}
tabList.add(new Tab(comp, name, icon));
tabList.add(new Tab(comp, name));
cardPanel.add(name, comp);
}


// public void setPanel(int index) {
// cardLayout.show(cardPanel, tabs.get(index).name);
// }


public void setPanel(Component comp) {
for (Tab tab : tabList) {
if (tab.comp == comp) {
@@ -159,16 +140,6 @@ public Component getPanel() {
}


public void setNotification(Component comp, boolean note) {
for (Tab tab : tabList) {
if (tab.comp == comp) {
tab.notification = note;
repaint();
}
}
}


// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .


@@ -212,32 +183,19 @@ public void paintComponent(Graphics g) {
tab.textWidth = (int)
font.getStringBounds(tab.name, g2.getFontRenderContext()).getWidth();
}

placeTabs(0);
placeTabs();
// now actually draw the tabs
drawTabs(g2);
}


/**
* @param left starting position from the left
*/
private void placeTabs(int left) { //, Graphics2D g) {
int x = left;

private void placeTabs() {
int x = 0;
for (Tab tab : tabList) {
tab.left = x;
x += MARGIN;
if (tab.hasIcon()) {
x += ICON_WIDTH + MARGIN;
}
x += tab.textWidth + MARGIN;
tab.right = x;

// // if drawing and not just placing
// if (g != null) {
// tab.draw(g);
// }
x += TAB_BETWEEN;
}
// Align the final tab (the "updates") to the right-hand side
@@ -279,24 +237,13 @@ class Tab {
Component comp;
boolean notification;

Image enabledIcon;
Image selectedIcon;

int left;
int right;
int textWidth;

Tab(Component comp, String name, String icon) {
Tab(Component comp, String name) {
this.comp = comp;
this.name = name;

if (icon != null) {
enabledIcon = mode.loadImageX(icon + "-enabled");
selectedIcon = mode.loadImageX(icon + "-selected");
if (selectedIcon == null) {
selectedIcon = enabledIcon; // use this as the default
}
}
}

boolean contains(int x) {
@@ -319,36 +266,20 @@ boolean hasRightNotch() {
}

int getTextLeft() {
int links = left;
if (enabledIcon != null) {
links += ICON_WIDTH + ICON_MARGIN;
}
return links + ((right - links) - textWidth) / 2;
}

boolean hasIcon() {
return enabledIcon != null;
return left + ((right - left) - textWidth) / 2;
}

void draw(Graphics g) {
int state = isCurrent() ? SELECTED : UNSELECTED;
g.setColor(tabColor[state]);

Graphics2D g2 = (Graphics2D) g;
// g2.fill(Toolkit.createRoundRect(left, TAB_TOP, right, TAB_BOTTOM, 0, 0,
// isLast() ? CURVE_RADIUS : 0,
// hastLeftCurve() ? CURVE_RADIUS : 0));
g2.fill(Toolkit.createRoundRect(left, TAB_TOP,
right, TAB_BOTTOM,
hasLeftNotch() ? CURVE_RADIUS : 0,
hasRightNotch() ? CURVE_RADIUS : 0,
0, 0));

if (hasIcon()) {
Image icon = (isCurrent() || notification) ? selectedIcon : enabledIcon;
g.drawImage(icon, left + MARGIN, ICON_TOP, ICON_WIDTH, ICON_HEIGHT, null);
}

int textLeft = getTextLeft();
if (notification && state == UNSELECTED) {
g.setColor(textColor[SELECTED]);
2 changes: 2 additions & 0 deletions todo.txt
Original file line number Diff line number Diff line change
@@ -12,6 +12,8 @@ X https://github.com/processing/processing4/issues/445
X Manager fails to complete install of PythonMode when no windows open
X https://github.com/processing/processing/issues/5309
X https://github.com/processing/processing4/issues/446
X removed weird double call of installPreviouslyFailed()
X remove unused icon code from ManagerTabs
_ allow update of the current Mode

_ an incompatible Mode prevents the PDE from quitting after last window is closed

0 comments on commit 49393a2

Please sign in to comment.