mirror of
https://github.com/processing/processing4.git
synced 2026-06-16 04:26:26 +02:00
clean up editor toolbar button code a bit, add new messages when shift is pressed
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
X fix problem with windows claiming "does not appear to contain an Android SDK"
|
||||
X add methods to request rendering
|
||||
_ need to deal with fps problems with this model
|
||||
_ check on multiple pointers work (peter's msg)
|
||||
|
||||
|
||||
P1 this is embarrassing, need to fix ASAP
|
||||
|
||||
@@ -890,7 +890,8 @@ public class Base {
|
||||
|
||||
// Add a list of all sketches and subfolders
|
||||
try {
|
||||
boolean sketches = addSketches(menu, getSketchbookFolder(), true);
|
||||
//boolean sketches = addSketches(menu, getSketchbookFolder(), true);
|
||||
boolean sketches = addSketches(menu, getSketchbookFolder());
|
||||
if (sketches) menu.addSeparator();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
@@ -899,7 +900,8 @@ public class Base {
|
||||
//System.out.println("rebuilding examples menu");
|
||||
// Add each of the subfolders of examples directly to the menu
|
||||
try {
|
||||
addSketches(menu, examplesFolder, true);
|
||||
//addSketches(menu, examplesFolder, true);
|
||||
addSketches(menu, examplesFolder);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -911,7 +913,8 @@ public class Base {
|
||||
//new Exception().printStackTrace();
|
||||
try {
|
||||
menu.removeAll();
|
||||
addSketches(menu, getSketchbookFolder(), false);
|
||||
//addSketches(menu, getSketchbookFolder(), false);
|
||||
addSketches(menu, getSketchbookFolder());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -952,7 +955,8 @@ public class Base {
|
||||
//System.out.println("rebuilding examples menu");
|
||||
try {
|
||||
menu.removeAll();
|
||||
addSketches(menu, examplesFolder, false);
|
||||
//addSketches(menu, examplesFolder, false);
|
||||
addSketches(menu, examplesFolder);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -965,8 +969,7 @@ public class Base {
|
||||
* should replace the sketch in the current window, or false when the
|
||||
* sketch should open in a new window.
|
||||
*/
|
||||
protected boolean addSketches(JMenu menu, File folder,
|
||||
final boolean openReplaces) throws IOException {
|
||||
protected boolean addSketches(JMenu menu, File folder) throws IOException {
|
||||
// skip .DS_Store files, etc (this shouldn't actually be necessary)
|
||||
if (!folder.isDirectory()) return false;
|
||||
|
||||
@@ -983,7 +986,8 @@ public class Base {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
String path = e.getActionCommand();
|
||||
if (new File(path).exists()) {
|
||||
if (openReplaces) {
|
||||
// if (openReplaces) {
|
||||
if ((e.getModifiers() & ActionEvent.SHIFT_MASK) == 0) {
|
||||
handleOpenReplace(path);
|
||||
} else {
|
||||
handleOpen(path);
|
||||
@@ -1038,7 +1042,8 @@ public class Base {
|
||||
JMenu submenu = new JMenu(list[i]);
|
||||
// needs to be separate var
|
||||
// otherwise would set ifound to false
|
||||
boolean found = addSketches(submenu, subfolder, openReplaces); //, false);
|
||||
//boolean found = addSketches(submenu, subfolder, openReplaces); //, false);
|
||||
boolean found = addSketches(submenu, subfolder); //, false);
|
||||
if (found) {
|
||||
menu.add(submenu);
|
||||
ifound = true;
|
||||
|
||||
@@ -246,6 +246,9 @@ public class Editor extends JFrame implements RunnerListener {
|
||||
// (har har har.. that was wishful thinking)
|
||||
listener = new EditorListener(this, textarea);
|
||||
pain.add(box);
|
||||
|
||||
// get shift down/up events so we can show the alt version of toolbar buttons
|
||||
textarea.addKeyListener(toolbar);
|
||||
|
||||
pain.setTransferHandler(new FileDropHandler());
|
||||
|
||||
|
||||
@@ -103,6 +103,10 @@ public class EditorListener {
|
||||
char c = event.getKeyChar();
|
||||
int code = event.getKeyCode();
|
||||
|
||||
// if (code == KeyEvent.VK_SHIFT) {
|
||||
// editor.toolbar.setShiftPressed(true);
|
||||
// }
|
||||
|
||||
//System.out.println((int)c + " " + code + " " + event);
|
||||
//System.out.println();
|
||||
|
||||
@@ -455,6 +459,13 @@ public class EditorListener {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
// public boolean keyReleased(KeyEvent event) {
|
||||
// if (code == KeyEvent.VK_SHIFT) {
|
||||
// editor.toolbar.setShiftPressed(false);
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
public boolean keyTyped(KeyEvent event) {
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
/*
|
||||
Part of the Processing project - http://processing.org
|
||||
|
||||
Copyright (c) 2004-08 Ben Fry and Casey Reas
|
||||
Copyright (c) 2004-09 Ben Fry and Casey Reas
|
||||
Copyright (c) 2001-04 Massachusetts Institute of Technology
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
@@ -25,6 +25,7 @@ package processing.app;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.event.*;
|
||||
|
||||
@@ -32,19 +33,28 @@ import javax.swing.event.*;
|
||||
/**
|
||||
* run/stop/etc buttons for the ide
|
||||
*/
|
||||
public class EditorToolbar extends JComponent implements MouseInputListener {
|
||||
public class EditorToolbar extends JComponent implements MouseInputListener, KeyListener {
|
||||
|
||||
/** Rollover titles for each button. */
|
||||
static final String title[] = {
|
||||
"Run", "Stop", "New", "Open", "Save", "Export"
|
||||
};
|
||||
|
||||
/** Titles for each button when the shift key is pressed. */
|
||||
static final String titleShift[] = {
|
||||
"Present", "Stop", "New Editor Window", "Open in Another Window", "Save", "Export to Application"
|
||||
};
|
||||
|
||||
static final int BUTTON_COUNT = title.length;
|
||||
static final int BUTTON_COUNT = title.length;
|
||||
/** Width of each toolbar button. */
|
||||
static final int BUTTON_WIDTH = 27;
|
||||
static final int BUTTON_WIDTH = 27;
|
||||
/** Height of each toolbar button. */
|
||||
static final int BUTTON_HEIGHT = 32;
|
||||
/** The amount of space between groups of buttons on the toolbar. */
|
||||
static final int BUTTON_GAP = 5;
|
||||
static final int BUTTON_GAP = 5;
|
||||
/** Size of the button image being chopped up. */
|
||||
static final int BUTTON_IMAGE_SIZE = 33;
|
||||
|
||||
|
||||
static final int RUN = 0;
|
||||
static final int STOP = 1;
|
||||
@@ -59,45 +69,36 @@ public class EditorToolbar extends JComponent implements MouseInputListener {
|
||||
static final int ACTIVE = 2;
|
||||
|
||||
Editor editor;
|
||||
//boolean disableRun; // this was for library
|
||||
//Label status;
|
||||
|
||||
Image offscreen;
|
||||
int width, height;
|
||||
|
||||
Color bgcolor;
|
||||
|
||||
static Image buttons;
|
||||
static Image inactive[];
|
||||
static Image rollover[];
|
||||
static Image active[];
|
||||
static Image[][] buttonImages;
|
||||
int currentRollover;
|
||||
//int currentSelection;
|
||||
|
||||
JPopupMenu popup;
|
||||
JMenu menu;
|
||||
|
||||
int buttonCount;
|
||||
int state[] = new int[BUTTON_COUNT];
|
||||
Image stateImage[];
|
||||
int[] state = new int[BUTTON_COUNT];
|
||||
Image[] stateImage;
|
||||
int which[]; // mapping indices to implementation
|
||||
|
||||
int x1[], x2[];
|
||||
int y1, y2;
|
||||
|
||||
String status;
|
||||
Font statusFont;
|
||||
Color statusColor;
|
||||
|
||||
boolean shiftPressed;
|
||||
|
||||
|
||||
public EditorToolbar(Editor editor, JMenu menu) {
|
||||
this.editor = editor;
|
||||
this.menu = menu;
|
||||
|
||||
if (buttons == null) {
|
||||
buttons = Base.getThemeImage("buttons.gif", this);
|
||||
}
|
||||
|
||||
buttonCount = 0;
|
||||
which = new int[BUTTON_COUNT];
|
||||
|
||||
@@ -112,39 +113,35 @@ public class EditorToolbar extends JComponent implements MouseInputListener {
|
||||
currentRollover = -1;
|
||||
|
||||
bgcolor = Theme.getColor("buttons.bgcolor");
|
||||
|
||||
status = "";
|
||||
|
||||
statusFont = Theme.getFont("buttons.status.font");
|
||||
statusColor = Theme.getColor("buttons.status.color");
|
||||
|
||||
addMouseListener(this);
|
||||
addMouseMotionListener(this);
|
||||
}
|
||||
|
||||
|
||||
protected void loadButtons() {
|
||||
Image allButtons = Base.getThemeImage("buttons.gif", this);
|
||||
buttonImages = new Image[BUTTON_COUNT][3];
|
||||
|
||||
for (int i = 0; i < BUTTON_COUNT; i++) {
|
||||
for (int state = 0; state < 3; state++) {
|
||||
Image image = createImage(BUTTON_WIDTH, BUTTON_HEIGHT);
|
||||
Graphics g = image.getGraphics();
|
||||
g.drawImage(allButtons,
|
||||
-(i*BUTTON_IMAGE_SIZE) - 3,
|
||||
(-2 + state)*BUTTON_IMAGE_SIZE, null);
|
||||
buttonImages[i][state] = image;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void paintComponent(Graphics screen) {
|
||||
// this data is shared by all EditorToolbar instances
|
||||
if (inactive == null) {
|
||||
inactive = new Image[BUTTON_COUNT];
|
||||
rollover = new Image[BUTTON_COUNT];
|
||||
active = new Image[BUTTON_COUNT];
|
||||
|
||||
int IMAGE_SIZE = 33;
|
||||
|
||||
for (int i = 0; i < BUTTON_COUNT; i++) {
|
||||
inactive[i] = createImage(BUTTON_WIDTH, BUTTON_HEIGHT);
|
||||
Graphics g = inactive[i].getGraphics();
|
||||
g.drawImage(buttons, -(i*IMAGE_SIZE) - 3, -2*IMAGE_SIZE, null);
|
||||
|
||||
rollover[i] = createImage(BUTTON_WIDTH, BUTTON_HEIGHT);
|
||||
g = rollover[i].getGraphics();
|
||||
g.drawImage(buttons, -(i*IMAGE_SIZE) - 3, -1*IMAGE_SIZE, null);
|
||||
|
||||
active[i] = createImage(BUTTON_WIDTH, BUTTON_HEIGHT);
|
||||
g = active[i].getGraphics();
|
||||
g.drawImage(buttons, -(i*IMAGE_SIZE) - 3, -0*IMAGE_SIZE, null);
|
||||
}
|
||||
if (buttonImages == null) {
|
||||
loadButtons();
|
||||
}
|
||||
|
||||
// this happens once per instance of EditorToolbar
|
||||
@@ -194,9 +191,11 @@ public class EditorToolbar extends JComponent implements MouseInputListener {
|
||||
float statusX = (getSize().width - statusW) / 2;
|
||||
g2.drawString(status, statusX, statusY);
|
||||
*/
|
||||
//int statusY = (BUTTON_HEIGHT + statusFont.getAscent()) / 2;
|
||||
int statusY = (BUTTON_HEIGHT + g.getFontMetrics().getAscent()) / 2;
|
||||
g.drawString(status, buttonCount * BUTTON_WIDTH + 3 * BUTTON_GAP, statusY);
|
||||
if (currentRollover != -1) {
|
||||
int statusY = (BUTTON_HEIGHT + g.getFontMetrics().getAscent()) / 2;
|
||||
String status = shiftPressed ? titleShift[currentRollover] : title[currentRollover];
|
||||
g.drawString(status, buttonCount * BUTTON_WIDTH + 3 * BUTTON_GAP, statusY);
|
||||
}
|
||||
|
||||
screen.drawImage(offscreen, 0, 0, null);
|
||||
}
|
||||
@@ -210,16 +209,17 @@ public class EditorToolbar extends JComponent implements MouseInputListener {
|
||||
// avoid flicker, since there will probably be an update event
|
||||
setState(OPEN, INACTIVE, false);
|
||||
}
|
||||
//System.out.println(e);
|
||||
//mouseMove(e);
|
||||
handleMouse(e.getX(), e.getY());
|
||||
handleMouse(e);
|
||||
}
|
||||
|
||||
|
||||
public void mouseDragged(MouseEvent e) { }
|
||||
|
||||
|
||||
public void handleMouse(int x, int y) {
|
||||
public void handleMouse(MouseEvent e) {
|
||||
int x = e.getX();
|
||||
int y = e.getY();
|
||||
|
||||
if (currentRollover != -1) {
|
||||
if ((x > x1[currentRollover]) && (y > y1) &&
|
||||
(x < x2[currentRollover]) && (y < y2)) {
|
||||
@@ -227,7 +227,6 @@ public class EditorToolbar extends JComponent implements MouseInputListener {
|
||||
|
||||
} else {
|
||||
setState(currentRollover, INACTIVE, true);
|
||||
messageClear(title[currentRollover]);
|
||||
currentRollover = -1;
|
||||
}
|
||||
}
|
||||
@@ -235,10 +234,8 @@ public class EditorToolbar extends JComponent implements MouseInputListener {
|
||||
if (sel == -1) return;
|
||||
|
||||
if (state[sel] != ACTIVE) {
|
||||
//if (!(disableRun && ((sel == RUN) || (sel == STOP)))) {
|
||||
setState(sel, ROLLOVER, true);
|
||||
currentRollover = sel;
|
||||
//}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -260,32 +257,16 @@ public class EditorToolbar extends JComponent implements MouseInputListener {
|
||||
|
||||
|
||||
private void setState(int slot, int newState, boolean updateAfter) {
|
||||
//if (inactive == null) return;
|
||||
state[slot] = newState;
|
||||
switch (newState) {
|
||||
case INACTIVE:
|
||||
stateImage[slot] = inactive[which[slot]];
|
||||
break;
|
||||
case ACTIVE:
|
||||
stateImage[slot] = active[which[slot]];
|
||||
break;
|
||||
case ROLLOVER:
|
||||
stateImage[slot] = rollover[which[slot]];
|
||||
message(title[which[slot]]);
|
||||
break;
|
||||
}
|
||||
stateImage[slot] = buttonImages[which[slot]][newState];
|
||||
if (updateAfter) {
|
||||
//System.out.println("trying to update " + slot + " " + state[slot]);
|
||||
//new Exception("setting slot " + slot + " to " + state[slot]).printStackTrace();
|
||||
repaint(); // changed for swing from update();
|
||||
//Toolkit.getDefaultToolkit().sync();
|
||||
repaint();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void mouseEntered(MouseEvent e) {
|
||||
//mouseMove(e);
|
||||
handleMouse(e.getX(), e.getY());
|
||||
handleMouse(e);
|
||||
}
|
||||
|
||||
|
||||
@@ -297,8 +278,7 @@ public class EditorToolbar extends JComponent implements MouseInputListener {
|
||||
if (state[OPEN] != INACTIVE) {
|
||||
setState(OPEN, INACTIVE, true);
|
||||
}
|
||||
status = "";
|
||||
handleMouse(e.getX(), e.getY());
|
||||
handleMouse(e);
|
||||
}
|
||||
|
||||
int wasDown = -1;
|
||||
@@ -328,8 +308,11 @@ public class EditorToolbar extends JComponent implements MouseInputListener {
|
||||
break;
|
||||
|
||||
case NEW:
|
||||
//editor.base.handleNew(e.isShiftDown());
|
||||
editor.base.handleNewReplace();
|
||||
if (shiftPressed) {
|
||||
editor.base.handleNew();
|
||||
} else {
|
||||
editor.base.handleNewReplace();
|
||||
}
|
||||
break;
|
||||
|
||||
case SAVE:
|
||||
@@ -350,84 +333,26 @@ public class EditorToolbar extends JComponent implements MouseInputListener {
|
||||
public void mouseClicked(MouseEvent e) { }
|
||||
|
||||
|
||||
public void mouseReleased(MouseEvent e) {
|
||||
/*
|
||||
switch (currentSelection) {
|
||||
|
||||
case OPEN:
|
||||
setState(OPEN, INACTIVE, true);
|
||||
break;
|
||||
}
|
||||
currentSelection = -1;
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
//public void disableRun(boolean what) {
|
||||
//disableRun = what;
|
||||
//}
|
||||
|
||||
|
||||
/*
|
||||
public void run() {
|
||||
if (inactive == null) return;
|
||||
clear();
|
||||
setState(RUN, ACTIVE, true);
|
||||
}
|
||||
*/
|
||||
|
||||
// public void running(boolean yesno) {
|
||||
// setState(RUN, yesno ? ACTIVE : INACTIVE, true);
|
||||
// }
|
||||
public void mouseReleased(MouseEvent e) { }
|
||||
|
||||
|
||||
/**
|
||||
* Set a particular button to be active.
|
||||
*/
|
||||
public void activate(int what) {
|
||||
//System.out.println("activating " + what);
|
||||
if (inactive == null) return;
|
||||
setState(what, ACTIVE, true);
|
||||
if (buttonImages != null) {
|
||||
setState(what, ACTIVE, true);
|
||||
}
|
||||
}
|
||||
|
||||
//public void clearRun() {
|
||||
//if (inactive == null) return;
|
||||
//setState(RUN, INACTIVE, true);
|
||||
//}
|
||||
|
||||
|
||||
/**
|
||||
* Set a particular button to be active.
|
||||
*/
|
||||
public void deactivate(int what) {
|
||||
if (inactive == null) return; // don't draw if not ready
|
||||
setState(what, INACTIVE, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear all the state of all buttons.
|
||||
*/
|
||||
// public void clear() { // (int button) {
|
||||
// if (inactive == null) return;
|
||||
//
|
||||
// System.out.println("clearing state of buttons");
|
||||
// // skip the run button, do the others
|
||||
// for (int i = 1; i < buttonCount; i++) {
|
||||
// setState(i, INACTIVE, false);
|
||||
// }
|
||||
// repaint(); // changed for swing from update();
|
||||
// }
|
||||
|
||||
|
||||
public void message(String msg) {
|
||||
//status.setText(msg + " "); // don't mind the hack
|
||||
status = msg;
|
||||
}
|
||||
|
||||
|
||||
public void messageClear(String msg) {
|
||||
//if (status.getText().equals(msg + " ")) status.setText(Editor.EMPTY);
|
||||
if (status.equals(msg)) status = "";
|
||||
if (buttonImages != null) {
|
||||
setState(what, INACTIVE, true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -444,4 +369,23 @@ public class EditorToolbar extends JComponent implements MouseInputListener {
|
||||
public Dimension getMaximumSize() {
|
||||
return new Dimension(3000, BUTTON_HEIGHT);
|
||||
}
|
||||
|
||||
|
||||
public void keyPressed(KeyEvent e) {
|
||||
if (e.getKeyCode() == KeyEvent.VK_SHIFT) {
|
||||
shiftPressed = true;
|
||||
repaint();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void keyReleased(KeyEvent e) {
|
||||
if (e.getKeyCode() == KeyEvent.VK_SHIFT) {
|
||||
shiftPressed = false;
|
||||
repaint();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void keyTyped(KeyEvent e) { }
|
||||
}
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
0175 pde (private)
|
||||
X changes to editor toolbar
|
||||
X make shift-new and shift-open on the toolbar open a new window
|
||||
X when shift is down, change text of the toolbar item
|
||||
|
||||
_ add a check to make sure that people aren't running from the dmg
|
||||
|
||||
_ "not a valid android install" msg on windows (not checking .exe)
|
||||
|
||||
_ move build scripts to something better like ant
|
||||
_ too much to maintain the multiple versions, too much code
|
||||
|
||||
Reference in New Issue
Block a user