mirror of
https://github.com/processing/processing4.git
synced 2026-06-16 04:26:26 +02:00
got editor buttons working
This commit is contained in:
@@ -86,12 +86,8 @@ public class PdeBase /*extends JFrame implements ActionListener*/
|
||||
|
||||
public PdeBase() {
|
||||
|
||||
// build the editor object
|
||||
|
||||
editor = new PdeEditor();
|
||||
|
||||
|
||||
// figure out which operating system
|
||||
// this has to be first, since editor needs to know
|
||||
|
||||
if (System.getProperty("mrj.version") != null) { // running on a mac
|
||||
platform = (System.getProperty("os.name").equals("Mac OS X")) ?
|
||||
@@ -116,6 +112,11 @@ public class PdeBase /*extends JFrame implements ActionListener*/
|
||||
}
|
||||
|
||||
|
||||
// build the editor object
|
||||
|
||||
editor = new PdeEditor();
|
||||
|
||||
|
||||
// set the look and feel before opening the window
|
||||
|
||||
try {
|
||||
|
||||
@@ -135,8 +135,10 @@ public class PdeEditor extends JFrame
|
||||
//static Properties keywords; // keyword -> reference html lookup
|
||||
|
||||
|
||||
public PdeEditor() { //PdeBase base) {
|
||||
//this.base = base;
|
||||
public PdeEditor() {
|
||||
// this is needed by just about everything else
|
||||
preferences = new PdePreferences();
|
||||
|
||||
|
||||
#ifdef MACOS
|
||||
// #@$*(@#$ apple.. always gotta think different
|
||||
@@ -168,17 +170,21 @@ public class PdeEditor extends JFrame
|
||||
PdeKeywords keywords = new PdeKeywords();
|
||||
history = new PdeHistory(this);
|
||||
sketchbook = new PdeSketchbook(this);
|
||||
preferences = new PdePreferences();
|
||||
|
||||
JMenuBar menubar = new JMenuBar();
|
||||
menubar.add(buildFileMenu());
|
||||
menubar.add(buildEditMenu());
|
||||
menubar.setHelpMenu(buildHelpMenu());
|
||||
// what platform has their help menu way on the right?
|
||||
//if ((PdeBase.platform == PdeBase.WINDOWS) ||
|
||||
//menubar.add(Box.createHorizontalGlue());
|
||||
menubar.add(buildHelpMenu());
|
||||
|
||||
setJMenuBar(menubar);
|
||||
|
||||
Container pain = getContentPane();
|
||||
pain.setLayout(new BorderLayout());
|
||||
|
||||
/*
|
||||
Panel leftPanel = new Panel();
|
||||
leftPanel.setLayout(new BorderLayout());
|
||||
|
||||
@@ -192,6 +198,8 @@ public class PdeEditor extends JFrame
|
||||
leftPanel.add("Center", dummy);
|
||||
|
||||
pain.add("West", leftPanel);
|
||||
*/
|
||||
pain.add("West", new PdeEditorButtons(this));
|
||||
|
||||
JPanel rightPanel = new JPanel();
|
||||
rightPanel.setLayout(new BorderLayout());
|
||||
@@ -1376,7 +1384,8 @@ public class PdeEditor extends JFrame
|
||||
|
||||
public void setSketchModified(boolean what) {
|
||||
header.sketchModified = what;
|
||||
header.update();
|
||||
//header.update();
|
||||
header.repaint();
|
||||
sketchModified = what;
|
||||
}
|
||||
|
||||
|
||||
@@ -25,6 +25,8 @@
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import java.awt.font.*;
|
||||
import java.awt.geom.*;
|
||||
import javax.swing.*;
|
||||
import javax.swing.event.*;
|
||||
|
||||
@@ -58,6 +60,8 @@ public class PdeEditorButtons extends JComponent implements MouseInputListener {
|
||||
Image offscreen;
|
||||
int width, height;
|
||||
|
||||
Color bgcolor;
|
||||
|
||||
Image buttons;
|
||||
Image inactive[];
|
||||
Image rollover[];
|
||||
@@ -98,6 +102,10 @@ public class PdeEditorButtons extends JComponent implements MouseInputListener {
|
||||
|
||||
currentRollover = -1;
|
||||
|
||||
bgcolor = PdePreferences.getColor("buttons.bgcolor");
|
||||
|
||||
status = "";
|
||||
|
||||
//setLayout(null);
|
||||
//status = new JLabel();
|
||||
statusFont = PdePreferences.getFont("buttons.status.font");
|
||||
@@ -124,6 +132,11 @@ public class PdeEditorButtons extends JComponent implements MouseInputListener {
|
||||
}
|
||||
*/
|
||||
|
||||
//public void paintComponent(Graphics g) {
|
||||
//super.paintComponent(g);
|
||||
//}
|
||||
|
||||
|
||||
public void paintComponent(Graphics screen) {
|
||||
if (inactive == null) {
|
||||
inactive = new Image[BUTTON_COUNT];
|
||||
@@ -173,7 +186,7 @@ public class PdeEditorButtons extends JComponent implements MouseInputListener {
|
||||
}
|
||||
}
|
||||
Graphics g = offscreen.getGraphics();
|
||||
g.setColor(getBackground());
|
||||
g.setColor(bgcolor); //getBackground());
|
||||
g.fillRect(0, 0, width, height);
|
||||
|
||||
for (int i = 0; i < buttonCount; i++) {
|
||||
@@ -183,9 +196,18 @@ public class PdeEditorButtons extends JComponent implements MouseInputListener {
|
||||
|
||||
g.setColor(statusColor);
|
||||
g.setFont(statusFont);
|
||||
int statusWidth = g.getFontMetrics().stringWidth(status);
|
||||
int statusX = (getSize().width - statusWidth) / 2;
|
||||
g.drawString(status, statusX, statusY);
|
||||
|
||||
// if i ever find the guy who wrote the java2d api,
|
||||
// i will hurt him. or just laugh in his face. or pity him.
|
||||
Graphics2D g2 = (Graphics2D) g;
|
||||
FontRenderContext frc = g2.getFontRenderContext();
|
||||
float statusW = (float) statusFont.getStringBounds(status, frc).getWidth();
|
||||
float statusX = (getSize().width - statusW) / 2;
|
||||
|
||||
//int statusWidth = g.getFontMetrics().stringWidth(status);
|
||||
//int statusX = (getSize().width - statusWidth) / 2;
|
||||
|
||||
g2.drawString(status, statusX, statusY);
|
||||
screen.drawImage(offscreen, 0, 0, null);
|
||||
}
|
||||
|
||||
|
||||
@@ -27,8 +27,10 @@ import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import java.io.*;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
public class PdeEditorHeader extends Panel {
|
||||
|
||||
public class PdeEditorHeader extends JPanel {
|
||||
static final String SKETCH_TITLER = "sketch";
|
||||
|
||||
static Color primaryColor;
|
||||
@@ -75,10 +77,12 @@ public class PdeEditorHeader extends Panel {
|
||||
public void reset() {
|
||||
sketchLeft = 0;
|
||||
//userLeft = 0;
|
||||
update();
|
||||
//update();
|
||||
repaint();
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
public void update() {
|
||||
paint(this.getGraphics());
|
||||
}
|
||||
@@ -86,8 +90,10 @@ public class PdeEditorHeader extends Panel {
|
||||
public void update(Graphics g) {
|
||||
paint(g);
|
||||
}
|
||||
*/
|
||||
|
||||
public void paint(Graphics screen) {
|
||||
|
||||
public void paintComponent(Graphics screen) {
|
||||
if (screen == null) return;
|
||||
if (editor.sketchName == null) return;
|
||||
|
||||
|
||||
@@ -149,10 +149,10 @@ public class PdePreferences extends JComponent {
|
||||
String actualKey = key.substring(0, key.length() - extensionLength);
|
||||
String value = get(key);
|
||||
|
||||
System.out.println("found platform specific prop \"" +
|
||||
actualKey + "\" \"" + value + "\"");
|
||||
//System.out.println("found platform specific prop \"" +
|
||||
// actualKey + "\" \"" + value + "\"");
|
||||
table.put(actualKey, value);
|
||||
System.out.println("now set to " + table.get(actualKey));
|
||||
//System.out.println("now set to " + table.get(actualKey));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -164,19 +164,13 @@ public class PdePreferences extends JComponent {
|
||||
|
||||
// next load user preferences file
|
||||
|
||||
String home = System.getProperty("user.home");
|
||||
File home = new File(System.getProperty("user.home"));
|
||||
preferencesFile = new File(home, ".processing");
|
||||
|
||||
if (!preferencesFile.exists()) {
|
||||
// create a new preferences file if none exists
|
||||
|
||||
// set default sketchbook path to the user's home folder
|
||||
// with 'sketchbook' as a subdirectory of that
|
||||
File sketchbookDir = new File(home, "sketchbook");
|
||||
set("sketchbook.path", sketchbookDir.getAbsolutePath());
|
||||
|
||||
//firstTime = true;
|
||||
save(); // will save the defaults out to the file
|
||||
// saves the defaults out to the file
|
||||
save();
|
||||
|
||||
} else {
|
||||
// load the previous preferences file
|
||||
@@ -415,13 +409,16 @@ public class PdePreferences extends JComponent {
|
||||
//table = new Hashtable();
|
||||
String line = null;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
if (line.charAt(0) == '#') continue;
|
||||
if ((line.length() == 0) ||
|
||||
(line.charAt(0) == '#')) continue;
|
||||
|
||||
// this won't properly handle = signs being in the text
|
||||
int equals = line.indexOf('=');
|
||||
String key = line.substring(0, equals).trim();
|
||||
String value = line.substring(equals + 1).trim();
|
||||
table.put(key, value);
|
||||
if (equals != -1) {
|
||||
String key = line.substring(0, equals).trim();
|
||||
String value = line.substring(equals + 1).trim();
|
||||
table.put(key, value);
|
||||
}
|
||||
}
|
||||
reader.close();
|
||||
}
|
||||
@@ -630,7 +627,7 @@ public class PdePreferences extends JComponent {
|
||||
|
||||
|
||||
static public SyntaxStyle getStyle(String what /*, String dflt*/) {
|
||||
String str = get("editor.program." + what + ".style"); //, dflt);
|
||||
String str = get("editor." + what + ".style"); //, dflt);
|
||||
|
||||
StringTokenizer st = new StringTokenizer(str, ",");
|
||||
|
||||
|
||||
@@ -46,6 +46,47 @@ public class PdeSketchbook {
|
||||
|
||||
public PdeSketchbook(PdeEditor editor) {
|
||||
this.editor = editor;
|
||||
|
||||
sketchbookPath = PdePreferences.get("sketchbook.path");
|
||||
|
||||
if (sketchbookPath == null) {
|
||||
// by default, set default sketchbook path to the user's
|
||||
// home folder with 'sketchbook' as a subdirectory of that
|
||||
File home = new File(System.getProperty("user.home"));
|
||||
|
||||
if (PdeBase.platform == PdeBase.MACOSX) {
|
||||
// on macosx put the sketchbook in the "Documents" folder
|
||||
home = new File(home, "Documents");
|
||||
|
||||
} else if (PdeBase.platform == PdeBase.WINDOWS) {
|
||||
// on windows put the sketchbook in the "My Documents" folder
|
||||
home = new File(home, "My Documents");
|
||||
}
|
||||
|
||||
String folderName = PdePreferences.get("sketchbook.name.default");
|
||||
//System.out.println("home = " + home);
|
||||
//System.out.println("fname = " + folderName);
|
||||
sketchbookFolder = new File(home, folderName);
|
||||
PdePreferences.set("sketchbook.path",
|
||||
sketchbookFolder.getAbsolutePath());
|
||||
|
||||
if (!sketchbookFolder.exists()) { // in case it exists already
|
||||
sketchbookFolder.mkdirs();
|
||||
}
|
||||
|
||||
/*
|
||||
sketchbookFolder = new File(PdePreferences.get("sketchbook.path"));
|
||||
sketchbookPath = sketchbookFolder.getAbsolutePath();
|
||||
if (!sketchbookFolder.exists()) {
|
||||
System.err.println("sketchbook folder doesn't exist, " +
|
||||
"making a new one");
|
||||
sketchbookFolder.mkdirs();
|
||||
}
|
||||
*/
|
||||
} else {
|
||||
sketchbookFolder = new File(sketchbookPath);
|
||||
}
|
||||
|
||||
menu = new JMenu("Open");
|
||||
}
|
||||
|
||||
@@ -86,14 +127,6 @@ public class PdeSketchbook {
|
||||
//menu.add(newSkechItem);
|
||||
//menu.addSeparator();
|
||||
|
||||
sketchbookFolder = new File(PdePreferences.get("sketchbook.path"));
|
||||
sketchbookPath = sketchbookFolder.getAbsolutePath();
|
||||
if (!sketchbookFolder.exists()) {
|
||||
System.err.println("sketchbook folder doesn't exist, " +
|
||||
"making a new one");
|
||||
sketchbookFolder.mkdirs();
|
||||
}
|
||||
|
||||
addSketches(menu, sketchbookFolder);
|
||||
|
||||
// TODO add examples folder here too
|
||||
|
||||
@@ -63,7 +63,8 @@ else
|
||||
# to have a copy of this guy around for messing with
|
||||
echo Copying Processing.app...
|
||||
#cp -a dist/Processing.app work/ # #@$(* bsd switches
|
||||
cp -dpR dist/Processing.app work/
|
||||
#cp -dpR dist/Processing.app work/
|
||||
cp -R dist/Processing.app work/
|
||||
#cd work/Processing.app
|
||||
#find . -name "CVS" -depth -exec rm {} \;
|
||||
#cd ../..
|
||||
|
||||
@@ -14,5 +14,6 @@ CLASSPATH=/System/Library/Java/Extensions/QTJava.zip:lib:lib/build:lib/pde.jar:l
|
||||
|
||||
export CLASSPATH
|
||||
|
||||
cd work && /System/Library/Frameworks/JavaVM.framework/Versions/1.3.1/Commands/java PdeBase
|
||||
#cd work && /System/Library/Frameworks/JavaVM.framework/Versions/1.3.1/Commands/java -Dcom.apple.macos.useScreenMenuBar=true PdeBase
|
||||
cd work && java -Dapple.laf.useScreenMenuBar=true PdeBase
|
||||
#cd work && java PdeBase
|
||||
|
||||
@@ -148,12 +148,15 @@ sketchbook.prompt = false
|
||||
# true if empty sketches should be removed automatically
|
||||
sketchbook.auto_clean = true
|
||||
|
||||
#sketchbook.path = sketchbook
|
||||
sketchbook.name.default = sketchbook
|
||||
|
||||
# note that this path should use forward slashes (like unix)
|
||||
# instead of \ on windows or : on windows or whatever else
|
||||
#sketchbook.path =
|
||||
|
||||
history.recording = true
|
||||
|
||||
# for advanced users, enable option to export a library
|
||||
export.library = false
|
||||
|
||||
# may be useful when attempting to debug the preprocessor
|
||||
|
||||
Reference in New Issue
Block a user