forgot to add lots of things for the new version

This commit is contained in:
benfry
2002-04-23 12:33:36 +00:00
parent 9585adb16c
commit 46a60bacfa
6 changed files with 409 additions and 98 deletions

View File

@@ -0,0 +1,180 @@
import java.awt.*;
import java.awt.event.*;
/*
PdeEditorLabel sketchLabel = new PdeEditorLabel(1);
Color sketchBgColor = new Color(51, 51, 51);
Color sketchPrimaryTextColor = Color.white;
Color sketchSecondaryTextColor = new Color(153, 153, 153);
sketchLabel.setForeground(sketchPrimaryTextColor);
sketchLabel.setBackground(sketchBgColor);
rightPanel.add("North", sketchLabel);
*/
public class PdeEditorHeader extends Panel /* implements ActionListener*/ {
static final String PROJECT_TITLER = "sketch";
static final String USER_TITLER = "user";
static final Color primaryColor = Color.white;
static final Color secondaryColor = new Color(153, 153, 153);
static final Color backgroundColor = new Color(51, 51, 51);
PdeEditor editor;
String project;
int projectLeft;
int projectRight;
int projectTitleLeft;
String user;
int userLeft;
int userRight;
int userTitleLeft;
Font font;
FontMetrics metrics;
int fontAscent;
Image offscreen;
int sizeW, sizeH;
int imageW, imageH;
public PdeEditorHeader(PdeEditor editor, String project, String user) {
this.editor = editor;
this.project = project;
this.user = user;
}
public void setProject(String project) {
this.project = project;
projectLeft = 0;
}
public void setUser(String user) {
this.user = user;
userLeft = 0;
}
public void update() {
paint(this.getGraphics());
}
public void update(Graphics g) {
paint(g);
}
public void paint(Graphics screen) {
if (screen == null) return;
Dimension size = getSize();
if ((size.width != sizeW) || (size.height != sizeH)) {
// component has been resized
if ((size.width > imageW) || (size.height > imageH)) {
// nix the image and recreate, it's too small
offscreen = null;
} else {
// who cares, just resize
sizeW = size.width;
sizeH = size.height;
userLeft = 0; // reset
}
}
if (offscreen == null) {
sizeW = size.width;
sizeH = size.height;
userLeft = 0; // reset
imageW = sizeW;
imageH = sizeH;
offscreen = createImage(imageW, imageH);
}
Graphics g = offscreen.getGraphics();
if (font == null) {
font = new Font("SansSerif", Font.PLAIN, 12);
g.setFont(font);
metrics = g.getFontMetrics();
fontAscent = metrics.getAscent();
}
if (projectLeft == 0) {
projectTitleLeft = PdeEditor.INSET_SIZE;
projectLeft = projectTitleLeft +
metrics.stringWidth(PROJECT_TITLER) + PdeEditor.INSET_SIZE;
}
if (userLeft == 0) {
userLeft = sizeW - 20 - metrics.stringWidth(user);
userTitleLeft = userLeft - PdeEditor.INSET_SIZE -
metrics.stringWidth(USER_TITLER);
}
int baseline = (sizeH + fontAscent) / 2;
g.setColor(backgroundColor);
g.fillRect(0, 0, imageW, imageH);
// DISABLED TEMPORARILY FOR 0022
/*
g.setColor(secondaryColor);
g.drawString(PROJECT_TITLER, projectTitleLeft, baseline);
g.drawString(USER_TITLER, userTitleLeft, baseline);
g.setColor(primaryColor);
g.drawString(project, projectLeft, baseline);
g.drawString(user, userLeft, baseline);
*/
//g.setColor(fgColor[mode]);
//g.drawString(message, PdeEditor.INSET_SIZE, (sizeH + fontAscent) / 2);
screen.drawImage(offscreen, 0, 0, null);
}
/*
protected void setButtonBounds() {
int top = (sizeH - BUTTON_HEIGHT) / 2;
int noLeft = sizeW - PdeEditor.INSET_SIZE - BUTTON_WIDTH;
int yesLeft = noLeft - PdeEditor.INSET_SIZE - BUTTON_WIDTH;
noButton.setBounds(noLeft, top, BUTTON_WIDTH, BUTTON_HEIGHT);
yesButton.setBounds(yesLeft, top, BUTTON_WIDTH, BUTTON_HEIGHT);
}
*/
public Dimension getPreferredSize() {
return new Dimension(300, PdeEditor.GRID_SIZE);
}
/*
public void actionPerformed(ActionEvent e) {
if (e.getSource() == noButton) {
System.out.println("clicked no");
} else if (e.getSource() == yesButton) {
System.out.println("clicked yes");
}
}
*/
}
/*
Color noticeBgColor = new Color(102, 102, 102);
Color noticeFgColor = new Color(255, 255, 255);
Color errorBgColor = new Color(102, 26, 0);
Color errorFgColor = new Color(255, 255, 255);
Color promptBgColor = new Color(204, 153, 0);
Color promptFgColor = new COlor(0, 0, 0);
*/

View File

@@ -0,0 +1,19 @@
import java.awt.*;
public class PdeEditorLabel extends Label {
int rows;
public PdeEditorLabel(int rows) {
super(""); //pde editor label");
setRows(rows);
}
public void setRows(int rows) {
this.rows = rows;
}
public Dimension getPreferredSize() {
return new Dimension(200, rows * PdeEditorButtons.BUTTON_HEIGHT);
}
}

View File

@@ -0,0 +1,11 @@
import java.awt.*;
import java.io.*;
public class PdeEditorOutput extends Component {
PdeEditor editor;
public PdeEditorOutput(PdeEditor editor) {
this.editor = editor;
}
}

View File

@@ -0,0 +1,199 @@
import java.awt.*;
import java.awt.event.*;
public class PdeEditorStatus extends Panel implements ActionListener {
static final Color bgColor[] = {
new Color(102, 102, 102),
new Color(102, 26, 0),
new Color(204, 153, 0)
};
static final Color fgColor[] = {
new Color(255, 255, 255),
new Color(255, 255, 255),
new Color(0, 0, 0)
};
static final int NOTICE = 0;
static final int ERROR = 1;
static final int PROMPT = 2;
static final String PROMPT_YES = "yes";
static final String PROMPT_NO = "no";
static final String NO_MESSAGE = "";
static final int BUTTON_WIDTH = 66;
static final int BUTTON_HEIGHT = 20;
PdeEditor editor;
int mode;
String message;
Font font;
FontMetrics metrics;
int fontAscent;
Image offscreen;
int sizeW, sizeH;
int imageW, imageH;
Button yesButton;
Button noButton;
public PdeEditorStatus(PdeEditor editor) {
this.editor = editor;
empty();
}
public void empty() {
mode = NOTICE;
message = NO_MESSAGE;
update();
}
public void notice(String message) {
mode = NOTICE;
this.message = message;
update();
}
public void unnotice(String unmessage) {
if (message.equals(unmessage)) empty();
}
public void error(String message) {
mode = ERROR;
this.message = message;
update();
}
public void prompt(String message) {
mode = PROMPT;
this.message = message;
yesButton.setVisible(true);
noButton.setVisible(true);
update();
}
// prompt has been handled, re-hide the buttons
public void unprompt() {
yesButton.setVisible(false);
noButton.setVisible(false);
empty();
}
public void update() {
paint(this.getGraphics());
}
public void update(Graphics g) {
paint(g);
}
public void paint(Graphics screen) {
if (screen == null) return;
if (yesButton == null) {
yesButton = new Button(PROMPT_YES);
noButton = new Button(PROMPT_NO);
setLayout(null);
yesButton.addActionListener(this);
noButton.addActionListener(this);
add(yesButton);
add(noButton);
yesButton.setVisible(false);
noButton.setVisible(false);
}
Dimension size = getSize();
if ((size.width != sizeW) || (size.height != sizeH)) {
// component has been resized
if ((size.width > imageW) || (size.height > imageH)) {
// nix the image and recreate, it's too small
offscreen = null;
} else {
// who cares, just resize
sizeW = size.width;
sizeH = size.height;
setButtonBounds();
}
}
if (offscreen == null) {
sizeW = size.width;
sizeH = size.height;
setButtonBounds();
imageW = sizeW;
imageH = sizeH;
offscreen = createImage(imageW, imageH);
}
Graphics g = offscreen.getGraphics();
if (font == null) {
font = new Font("SansSerif", Font.PLAIN, 10);
g.setFont(font);
metrics = g.getFontMetrics();
fontAscent = metrics.getAscent();
}
g.setColor(bgColor[mode]);
g.fillRect(0, 0, imageW, imageH);
g.setColor(fgColor[mode]);
g.drawString(message, PdeEditor.INSET_SIZE, (sizeH + fontAscent) / 2);
screen.drawImage(offscreen, 0, 0, null);
}
protected void setButtonBounds() {
int top = (sizeH - BUTTON_HEIGHT) / 2;
int noLeft = sizeW - PdeEditor.INSET_SIZE - BUTTON_WIDTH;
int yesLeft = noLeft - PdeEditor.INSET_SIZE - BUTTON_WIDTH;
noButton.setBounds(noLeft, top, BUTTON_WIDTH, BUTTON_HEIGHT);
yesButton.setBounds(yesLeft, top, BUTTON_WIDTH, BUTTON_HEIGHT);
}
public Dimension getPreferredSize() {
return new Dimension(300, PdeEditor.GRID_SIZE);
}
public void actionPerformed(ActionEvent e) {
if (e.getSource() == noButton) {
System.out.println("clicked no");
} else if (e.getSource() == yesButton) {
System.out.println("clicked yes");
}
}
}
/*
Color noticeBgColor = new Color(102, 102, 102);
Color noticeFgColor = new Color(255, 255, 255);
Color errorBgColor = new Color(102, 26, 0);
Color errorFgColor = new Color(255, 255, 255);
Color promptBgColor = new Color(204, 153, 0);
Color promptFgColor = new COlor(0, 0, 0);
*/

View File

@@ -1,13 +0,0 @@
public interface PdeEnvironment {
// stop the currently running thread (called by gui and others)
public void terminate();
// error being reported to gui (called by dbn)
public void error(PdeException e);
// successful finish reported to gui (called by dbn)
public void finished();
// message to write to gui (called by dbn)
public void message(String msg);
}

View File

@@ -1,85 +0,0 @@
#!/usr/bin/perl
open(F, "../../bagel/Bagel.java") || die $!;
@contents = <F>;
close(F);
open(APPLET, "ProcessingApplet.java") || die $!;
@applet = <APPLET>;
close(APPLET);
$insert = 'public functions from bagel';
open(OUT, ">ProcessingApplet.java") || die $!;
foreach $line (@applet) {
print OUT $line;
last if ($line =~ /$insert/);
}
#open(OUT, ">>ProcessingApplet.java") || die $!;
select(OUT);
$comments = 0;
#print "\n\n";
#foreach $line (@contents) {
while ($line = shift(@contents)) {
$decl = "";
if ($line =~ /\/\*/) {
$comments++;
}
if ($line =~ /\*\//) {
$comments--;
}
next if ($comments > 0);
if ($line =~ /^\s*public (\w+) [a-zA-z_]+\(.*$/) {
#print "$1\n";
#$decl .= $line;
if ($1 ne 'void') {
$returns = 'return';
} else {
$returns = '';
}
print "\n\n$line";
$decl .= $line;
while (!($line =~ /\)/)) {
$line = shift (@contents);
$decl .= $line;
print $line;
#print shift (@contents);
}
$decl =~ /\s(\S+)\(/;
$decl_name = $1;
#print "dec $decl_name\n";
print " $returns g.${decl_name}(";
$decl =~ s/\s+/ /g; # smush onto a single line
$decl =~ s/^.*\(//;
$decl =~ s/\).*$//;
$prev = 0;
@parts = split(', ', $decl);
foreach $part (@parts) {
($the_type, $the_arg) = split(' ', $part);
$the_arg =~ s/[\[\]]//g;
#print "* $the_arg\n";
if ($prev != 0) {
print ", ";
}
print "${the_arg}";
$prev = 1;
}
print ");\n";
#print "$decl\r\n";
print " }\n"; #\n";
}
}
print "}\n";