smoothing out footer handling

This commit is contained in:
Ben Fry
2015-05-19 03:01:39 -04:00
parent b0d5472f19
commit d196b7891e
5 changed files with 102 additions and 64 deletions
+2 -1
View File
@@ -823,7 +823,8 @@ public class Base {
} catch (Throwable t) {
showBadnessTrace("Terrible News",
"A serious error occurred while " +
"trying to create a new editor window.", t, false);
"trying to create a new editor window.", t,
nextMode == getDefaultMode()); // quit if default
nextMode = getDefaultMode();
return null;
}
+8 -6
View File
@@ -30,7 +30,6 @@ import processing.core.*;
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.Frame;
@@ -96,7 +95,7 @@ public abstract class Editor extends JFrame implements RunnerListener {
protected JEditTextArea textarea;
protected EditorStatus status;
protected JSplitPane splitPane;
protected Container consolePanel;
protected EditorFooter footer;
protected EditorConsole console;
// protected EditorLineStatus lineStatus;
@@ -246,7 +245,7 @@ public abstract class Editor extends JFrame implements RunnerListener {
textarea.setRightClickPopup(new TextAreaPopup());
textarea.setHorizontalOffset(JEditTextArea.leftHandGutter);
consolePanel = createFooter();
footer = createFooter();
upper.add(textarea);
@@ -254,7 +253,7 @@ public abstract class Editor extends JFrame implements RunnerListener {
// status = new EditorStatus(this);
// upper.add(status);
splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, upper, consolePanel);
splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, upper, footer);
// disable this because it hides the message area, which is essential (issue #745)
splitPane.setOneTouchExpandable(false);
@@ -417,8 +416,11 @@ public abstract class Editor extends JFrame implements RunnerListener {
}
public Container createFooter() {
return new EditorConsole(this);
public EditorFooter createFooter() {
EditorFooter ef = new EditorFooter(this);
console = new EditorConsole(this);
ef.addPanel(Language.text("editor.footer.console"), console);
return ef;
/*
// assemble console panel, consisting of status area and the console itself
+72 -44
View File
@@ -101,6 +101,30 @@ public class EditorFooter extends Box {
}
// public void setPanel(int index) {
// cardLayout.show(cardPanel, tabs.get(index).name);
// }
public void setPanel(Component comp) {
for (Tab tab : tabs) {
if (tab.comp == comp) {
cardLayout.show(cardPanel, tab.name);
}
}
}
public void setNotification(Component comp, boolean note) {
for (Tab tab : tabs) {
if (tab.comp == comp) {
tab.notification = note;
repaint();
}
}
}
public void updateMode() {
Mode mode = editor.getMode();
@@ -127,7 +151,7 @@ public class EditorFooter extends Box {
for (Tab tab : tabs) {
if (tab.contains(x)) {
//editor.setFooterPanel(tab.index);
cardLayout.show(cardPanel, tab.text);
cardLayout.show(cardPanel, tab.name);
}
}
}
@@ -178,7 +202,7 @@ public class EditorFooter extends Box {
// reset all tab positions
for (Tab tab : tabs) {
tab.textWidth = (int)
font.getStringBounds(tab.text, g2.getFontRenderContext()).getWidth();
font.getStringBounds(tab.name, g2.getFontRenderContext()).getWidth();
}
// now actually draw the tabs
@@ -192,61 +216,64 @@ public class EditorFooter extends Box {
screen.drawImage(offscreen, 0, 0, imageW, imageH, null);
}
}
/**
* @param left starting position from the left
* @param g graphics context, or null if we're not drawing
*/
private void placeTabs(int left, Graphics2D g) {
int x = left;
/**
* @param left starting position from the left
* @param g graphics context, or null if we're not drawing
*/
private void placeTabs(int left, Graphics2D g) {
int x = left;
for (Tab tab : tabs) {
int state = tab.isCurrent() ? SELECTED : UNSELECTED;
tab.left = x;
x += TEXT_MARGIN;
x += tab.textWidth + TEXT_MARGIN;
tab.right = x;
for (Tab tab : tabs) {
int state = tab.isCurrent() ? SELECTED : UNSELECTED;
tab.left = x;
x += TEXT_MARGIN;
x += tab.textWidth + TEXT_MARGIN;
tab.right = x;
// if drawing and not just placing
if (g != null) {
g.setColor(tabColor[state]);
drawTab(g, tab.left, tab.right, tab.isFirst(), tab.isLast());
// if drawing and not just placing
if (g != null) {
g.setColor(tabColor[state]);
if (tab.notification) {
g.setColor(new Color(192, 0, 0));
}
drawTab(g, tab.left, tab.right, tab.isFirst(), tab.isLast());
int textLeft = tab.left + ((tab.right - tab.left) - tab.textWidth) / 2;
g.setColor(textColor[state]);
int tabHeight = TAB_BOTTOM - TAB_TOP;
int baseline = TAB_TOP + (tabHeight + fontAscent) / 2;
g.drawString(tab.text, textLeft, baseline);
int textLeft = tab.left + ((tab.right - tab.left) - tab.textWidth) / 2;
g.setColor(textColor[state]);
int tabHeight = TAB_BOTTOM - TAB_TOP;
int baseline = TAB_TOP + (tabHeight + fontAscent) / 2;
g.drawString(tab.name, textLeft, baseline);
}
x += TAB_BETWEEN;
}
x += TAB_BETWEEN;
}
}
private void drawTab(Graphics g, int left, int right,
boolean leftNotch, boolean rightNotch) {
Graphics2D g2 = (Graphics2D) g;
EditorHeader.roundRect(g2, left, TAB_TOP, right, TAB_BOTTOM,
0, 0,
leftNotch ? CURVE_RADIUS : 0,
rightNotch ? CURVE_RADIUS : 0);
}
private void drawTab(Graphics g, int left, int right,
boolean leftNotch, boolean rightNotch) {
Graphics2D g2 = (Graphics2D) g;
EditorHeader.roundRect(g2, left, TAB_TOP, right, TAB_BOTTOM,
0, 0,
leftNotch ? CURVE_RADIUS : 0,
rightNotch ? CURVE_RADIUS : 0);
}
public Dimension getPreferredSize() {
return new Dimension(300, HIGH);
}
public Dimension getPreferredSize() {
return new Dimension(300, HIGH);
}
public Dimension getMinimumSize() {
return getPreferredSize();
}
public Dimension getMinimumSize() {
return getPreferredSize();
}
public Dimension getMaximumSize() {
return new Dimension(super.getMaximumSize().width, HIGH);
public Dimension getMaximumSize() {
return new Dimension(super.getMaximumSize().width, HIGH);
}
}
@@ -254,15 +281,16 @@ public class EditorFooter extends Box {
class Tab {
String text;
String name;
Component comp;
boolean notification;
int left;
int right;
int textWidth;
Tab(String name, Component comp) {
this.text = name;
this.name = name;
this.comp = comp;
}
@@ -311,7 +311,7 @@ public class ContributionManager {
// To avoid the user from modifying stuff, since this function is only called
// during pre-processing
base.getActiveEditor().getTextArea().setEditable(false);
base.getActiveEditor().getConsole().clear();
// base.getActiveEditor().getConsole().clear();
ArrayList<String> installedLibList = new ArrayList<String>();
+19 -12
View File
@@ -206,7 +206,7 @@ public class JavaEditor extends Editor {
@Override
public Container createFooter() {
public EditorFooter createFooter() {
// //JPanel consolePanel = new JPanel();
// JTabbedPane footer = new JTabbedPane(JTabbedPane.BOTTOM);
//// tabPane.setUI(new BasicTabbedPaneUI());
@@ -215,7 +215,9 @@ public class JavaEditor extends Editor {
//// tabPane.setUI(new PlasticTabbedPaneUI());
//// tabPane.setBorder(BorderFactory.createEmptyBorder());
//// tabPane.setBackground(Color.RED);
EditorFooter footer = new EditorFooter(this);
// EditorFooter footer = new EditorFooter(this);
EditorFooter footer = super.createFooter();
// Adding Error Table in a scroll pane
errorTableScrollPane = new JScrollPane();
@@ -251,7 +253,8 @@ public class JavaEditor extends Editor {
// consoleProblemsPane.add(super.createConsolePanel(), Language.text("editor.footer.console"));
// consolePanel.add(consoleProblemsPane, BorderLayout.CENTER);
footer.addPanel(Language.text("editor.footer.console"), new EditorConsole(this));
// console = new EditorConsole(this);
// footer.addPanel(Language.text("editor.footer.console"), console);
footer.addPanel(Language.text("editor.footer.errors"), errorTableScrollPane);
//return consolePanel;
@@ -2571,7 +2574,8 @@ public class JavaEditor extends Editor {
public void showProblemListView(String buttonName) {
// CardLayout cl = (CardLayout) consoleProblemsPane.getLayout();
// cl.show(consoleProblemsPane, buttonName);
((JTabbedPane) consolePanel).setSelectedIndex(ERROR_TAB_INDEX);
// ((JTabbedPane) consolePanel).setSelectedIndex(ERROR_TAB_INDEX);
footer.setPanel(errorTableScrollPane);
}
@@ -2586,14 +2590,17 @@ public class JavaEditor extends Editor {
* the error button at the bottom of the PDE
*/
public void updateErrorToggle() {
String title = Language.text("editor.footer.errors");
if (JavaMode.errorCheckEnabled && errorCheckerService.hasErrors()) {
title += "*";
}
((JTabbedPane) consolePanel).setTitleAt(ERROR_TAB_INDEX, title);
// btnShowErrors.updateMarker(JavaMode.errorCheckEnabled &&
// errorCheckerService.hasErrors(),
// errorBar.errorColor);
footer.setNotification(errorTableScrollPane,
JavaMode.errorCheckEnabled &&
errorCheckerService.hasErrors());
// String title = Language.text("editor.footer.errors");
// if (JavaMode.errorCheckEnabled && errorCheckerService.hasErrors()) {
// title += "*";
// }
// ((JTabbedPane) footer).setTitleAt(ERROR_TAB_INDEX, title);
//// btnShowErrors.updateMarker(JavaMode.errorCheckEnabled &&
//// errorCheckerService.hasErrors(),
//// errorBar.errorColor);
}