more from hell

This commit is contained in:
benfry
2003-11-07 00:13:25 +00:00
parent 3f31fa8e1d
commit 75b00c385f
4 changed files with 156 additions and 205 deletions
+1 -6
View File
@@ -45,12 +45,7 @@ import com.apple.mrj.*;
* general interaction with the system (launching URLs, loading
* files and images, etc) that comes from that.
*/
#ifndef SWINGSUCKS
public class PdeBase extends JFrame
#else
public class PdeBase extends Frame
#endif
implements ActionListener
public class PdeBase extends JFrame implements ActionListener
#ifdef MACOS
, MRJAboutHandler
, MRJQuitHandler
+14 -18
View File
@@ -49,15 +49,7 @@ public class PdeEditorStatus extends Panel
static final int CANCEL = 3;
static final int OK = 4;
static final String PROMPT_YES = "Yes";
static final String PROMPT_NO = "No";
static final String PROMPT_CANCEL = "Cancel";
static final String PROMPT_OK = "Ok";
static final String NO_MESSAGE = "";
// mac needs it to be 70, windows needs 66, linux needs 76
static final int BUTTON_WIDTH = 76;
static final int BUTTON_HEIGHT = 24;
static final String NO_MESSAGE = "";
PdeEditor editor;
@@ -595,17 +587,21 @@ public class PdeEditorStatus extends Panel
protected void setButtonBounds() {
int top = (sizeH - BUTTON_HEIGHT) / 2;
int cancelLeft = sizeW - PdeEditor.INSET_SIZE - BUTTON_WIDTH;
int noLeft = cancelLeft - PdeEditor.INSET_SIZE - BUTTON_WIDTH;
int yesLeft = noLeft - PdeEditor.INSET_SIZE - BUTTON_WIDTH;
int cancelLeft = sizeW - PdeEditor.INSET_SIZE - PdePreferences.BUTTON_WIDTH;
int noLeft = cancelLeft - PdeEditor.INSET_SIZE - PdePreferences.BUTTON_WIDTH;
int yesLeft = noLeft - PdeEditor.INSET_SIZE - PdePreferences.BUTTON_WIDTH;
yesButton.setBounds(yesLeft, top, BUTTON_WIDTH, BUTTON_HEIGHT);
noButton.setBounds(noLeft, top, BUTTON_WIDTH, BUTTON_HEIGHT);
cancelButton.setBounds(cancelLeft, top, BUTTON_WIDTH, BUTTON_HEIGHT);
yesButton.setBounds(yesLeft, top,
PdePreferences.BUTTON_WIDTH, PdePreferences.BUTTON_HEIGHT);
noButton.setBounds(noLeft, top,
PdePreferences.BUTTON_WIDTH, PdePreferences.BUTTON_HEIGHT);
cancelButton.setBounds(cancelLeft, top,
PdePreferences.BUTTON_WIDTH, PdePreferences.BUTTON_HEIGHT);
editField.setBounds(yesLeft-BUTTON_WIDTH, top,
BUTTON_WIDTH*2, BUTTON_HEIGHT);
okButton.setBounds(noLeft, top, BUTTON_WIDTH, BUTTON_HEIGHT);
editField.setBounds(yesLeft - PdePreferences.BUTTON_WIDTH, top,
PdePreferences.BUTTON_WIDTH*2, PdePreferences.BUTTON_HEIGHT);
okButton.setBounds(noLeft, top,
PdePreferences.BUTTON_WIDTH, PdePreferences.BUTTON_HEIGHT);
}
+135 -168
View File
@@ -62,11 +62,29 @@ import gnu.io.*;
*/
public class PdePreferences extends JComponent {
// prompt text stuff
static final String PROMPT_YES = "Yes";
static final String PROMPT_NO = "No";
static final String PROMPT_CANCEL = "Cancel";
static final String PROMPT_OK = "OK";
// mac needs it to be 70, windows needs 66, linux needs 76
static final int BUTTON_WIDTH = 76;
static final int BUTTON_HEIGHT = 24;
// value for the size bars, buttons, etc
static final int GRID_SIZE = 33;
// gui variables
static final int BIG = 13;
static final int BETWEEN = 13;
static final int SMALL = 6;
static final int GUI_BIG = 13;
static final int GUI_BETWEEN = 13;
static final int GUI_SMALL = 6;
// gui elements
JFrame frame;
int wide, high;
@@ -78,7 +96,7 @@ public class PdePreferences extends JComponent {
// data model
static Hashtable table;
static Hashtable table = new Hashtable();;
File preferencesFile;
//boolean firstTime; // first time this feller has been run
@@ -86,57 +104,30 @@ public class PdePreferences extends JComponent {
public PdePreferences() {
// getting started
// start by loading the defaults, in case something
// important was deleted from the user prefs
properties = new Properties();
try {
if ((PdeBase.platform == PdeBase.MACOSX) ||
(PdeBase.platform == PdeBase.MACOS9)) {
load(new FileInputStream("lib/pde.properties"));
// load user preferences file
String home = System.getProperty("user.home");
preferencesFile = new File(home, ".processing");
if (!preferencesFile.exists()) {
// create a new preferences file if none exists
try {
if ((PdeBase.platform == PdeBase.MACOSX) ||
(PdeBase.platform == PdeBase.MACOS9)) {
load(new FileInputStream("lib/pde.properties"));
} else {
// under win95, current dir not set properly
// so using a relative url like "lib/" won't work
load(getClass().getResource("pde.properties").openStream());
}
} catch (Exception e) {
showError(null, "Could not read default settings.\n" +
"You'll need to reinstall Processing.", e);
System.exit(1);
//System.err.println("Error reading default settings");
//e.printStackTrace();
} else {
// under win95, current dir not set properly
// so using a relative url like "lib/" won't work
load(getClass().getResource("pde.properties").openStream());
}
firstTime = true;
} else {
// load the previous preferences file
try {
load(new FileInputStream(preferencesFile));
} catch (Exception e) {
showError("Error reading preferences",
"Error reading the preferences file. Please delete\n" +
perferencesFile.getCanonicalPath() + "\n" +
"and restart Processing.", e);
}
} catch (Exception e) {
showError(null, "Could not read default settings.\n" +
"You'll need to reinstall Processing.", e);
System.exit(1);
//System.err.println("Error reading default settings");
//e.printStackTrace();
}
// check for platform-specific properties
// check for platform-specific properties in the defaults
String platformExtension = "." + PdeBase.platforms[PdeBase.platform];
int extensionLength = platformExtension.length();
@@ -157,6 +148,31 @@ public class PdePreferences extends JComponent {
}
// next load user preferences file
String home = System.getProperty("user.home");
preferencesFile = new File(home, ".processing");
if (!preferencesFile.exists()) {
// create a new preferences file if none exists
//firstTime = true;
save(); // will save the defaults out to the file
} else {
// load the previous preferences file
try {
load(new FileInputStream(preferencesFile));
} catch (Exception e) {
showError("Error reading preferences",
"Error reading the preferences file. Please delete\n" +
perferencesFile.getCanonicalPath() + "\n" +
"and restart Processing.", e);
}
}
// setup frame for the prefs
frame = new JFrame("Preferences");
@@ -166,12 +182,12 @@ public class PdePreferences extends JComponent {
//Container pain = frame.getContentPane();
pain.setLayout(null);
int top = BIG;
int left = BIG;
int top = GUI_BIG;
int left = GUI_BIG;
int right = 0;
JLabel label;
JButton button;
JButton button, button2;
JComboBox combo;
Dimension d, d2, d3;
int h, v, vmax;
@@ -206,15 +222,15 @@ public class PdePreferences extends JComponent {
vmax = Math.max(Math.max(d.height, d2.height), d3.height);
label.setBounds(left, top + (vmax-d.height)/2,
d.width, d.height);
h = left + d.width + BETWEEN;
h = left + d.width + GUI_BETWEEN;
sketchbookLocation.setBounds(h, top + (vmax-d2.height)/2,
d2.width, d2.height);
h += d2.width + BETWEEN;
h += d2.width + GUI_BETWEEN;
button.setBounds(h, top + (vmax-d3.height)/2,
d3.width, d3.height);
right = Math.max(right, h + d3.width + BIG);
top += vmax + BETWEEN;
right = Math.max(right, h + d3.width + GUI_BIG);
top += vmax + GUI_BETWEEN;
// Default serial port: [ COM1 + ]
@@ -276,8 +292,31 @@ public class PdePreferences extends JComponent {
textarea.setBounds(left, top, d.width, d.height);
top += d.height + BETWEEN;
// OK Cancel
// OK Cancel maybe these should be next to the message?
button = new JButton(PROMPT_OK);
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
apply();
hideFrame();
}
});
pain.add(button);
button.setBounds(LEFT, top, BUTTON_WIDTH, BUTTON_HEIGHT);
h = LEFT + BUTTON_WIDTH + GUI_BETWEEN;
//d = button.getPreferredSize();
button = new JButton(PROMPT_CANCEL);
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
hideFrame();
}
});
pain.add(button);
button.setBounds(h, top, BUTTON_WIDTH, BUTTON_HEIGHT);
top += BUTTON_HEIGHT + BETWEEN;
//
@@ -305,16 +344,40 @@ public class PdePreferences extends JComponent {
}
// .................................................................
public Dimension getPreferredSize() {
return new Dimension(wide, high);
}
public void hideFrame() {
frame.hide();
}
public void showFrame() {
// reset all settings to their actual status
newSketchPromptBox.setSelected(getBoolean("sketchbook.prompt"));
sketchbookLocation.setText(get("sketchbook.path"));
newSketchPromptBox.setSelected(getBoolean("editor.external"));
frame.show();
}
// .................................................................
public void load(InputStream input) {
BufferedReader reader =
new BufferedReader(new InputStreamReader(input));
table = new Hashtable();
//table = new Hashtable();
String line = null;
while ((line = reader.readLine()) != null) {
if (line.charAt(0) == '#') continue;
@@ -328,23 +391,12 @@ public class PdePreferences extends JComponent {
}
// change settings based on what was chosen in the prefs
public void apply() {
//editor.setExternalEditor(getBoolean("editor.external"));
// put each of the settings into the table
}
// open the last-used sketch, etc
public void init() {
//public void init() {
//String what = path + File.separator + name + ".pde";
//
///String serialPort = skprops.getProperty("serial.port");
//if (serialPort != null) {
// properties.put("serial.port", serialPort);
@@ -368,27 +420,19 @@ public class PdePreferences extends JComponent {
// doesn't exist, not available, make my own
//skNew();
//}
//}
// change settings based on what was chosen in the prefs
public void apply() {
//editor.setExternalEditor(getBoolean("editor.external"));
// put each of the settings into the table
}
/*
externalEditorItem = new CheckboxMenuItem("Use External Editor");
externalEditorItem.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent e) {
//System.out.println(e);
if (e.getStateChange() == ItemEvent.SELECTED) {
editor.setExternalEditor(true);
} else {
editor.setExternalEditor(false);
}
}
});
menu.add(externalEditorItem);
*/
public Dimension getPreferredSize() {
return new Dimension(wide, high);
}
// .................................................................
public void save() {
@@ -459,6 +503,10 @@ public class PdePreferences extends JComponent {
}
}
// .................................................................
// all the information from pde.properties
//static public String get(String attribute) {
@@ -555,85 +603,4 @@ public class PdePreferences extends JComponent {
return new SyntaxStyle(color, italic, bold);
}
/*
class SerialMenuListener implements ItemListener {
//public SerialMenuListener() { }
public void itemStateChanged(ItemEvent e) {
int count = serialMenu.getItemCount();
for (int i = 0; i < count; i++) {
((CheckboxMenuItem)serialMenu.getItem(i)).setState(false);
}
CheckboxMenuItem item = (CheckboxMenuItem)e.getSource();
item.setState(true);
String name = item.getLabel();
//System.out.println(item.getLabel());
PdeBase.properties.put("serial.port", name);
//System.out.println("set to " + get("serial.port"));
}
}
*/
/*
protected Vector buildPortList() {
// get list of names for serial ports
// have the default port checked (if present)
Vector list = new Vector();
//SerialMenuListener listener = new SerialMenuListener();
boolean problem = false;
// if this is failing, it may be because
// lib/javax.comm.properties is missing.
// java is weird about how it searches for java.comm.properties
// so it tends to be very fragile. i.e. quotes in the CLASSPATH
// environment variable will hose things.
try {
//System.out.println("building port list");
Enumeration portList = CommPortIdentifier.getPortIdentifiers();
while (portList.hasMoreElements()) {
CommPortIdentifier portId =
(CommPortIdentifier) portList.nextElement();
//System.out.println(portId);
if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL) {
//if (portId.getName().equals(port)) {
String name = portId.getName();
//CheckboxMenuItem mi =
//new CheckboxMenuItem(name, name.equals(defaultName));
//mi.addItemListener(listener);
//serialMenu.add(mi);
list.addElement(name);
}
}
} catch (UnsatisfiedLinkError e) {
e.printStackTrace();
problem = true;
} catch (Exception e) {
System.out.println("exception building serial menu");
e.printStackTrace();
}
//if (serialMenu.getItemCount() == 0) {
//System.out.println("dimming serial menu");
//serialMenu.setEnabled(false);
//}
// only warn them if this is the first time
if (problem && PdeBase.firstTime) {
JOptionPane.showMessageDialog(this, //frame,
"Serial port support not installed.\n" +
"Check the readme for instructions\n" +
"if you need to use the serial port. ",
"Serial Port Warning",
JOptionPane.WARNING_MESSAGE);
}
return list;
}
*/
}
+6 -13
View File
@@ -1,20 +1,16 @@
# p r o c e s s i n g development environment settings
# these are similar to those used with the applet version.
# edit these only if you know what you're doing.
# These are the default preferences for Processing
# They will be copied to your home folder into a file called
# .processing, where you can make changes for your machine.
# a pound sign at the beginning of a line is a comment
# parameters need to be un-commented before they take effect
# usually, the default is listed here, just commented out
# default size for the main window
default.window.width = 500
default.window.height = 500
# TextAreaDefaults.java
# font size for editor
editor.font=Monospaced,plain,12
@@ -128,13 +124,10 @@ editor.wheelmouse.multiplier = 3
# background color for full-screen presentation mode
run.present.bgcolor = #666666
# prompt for sketch location when 'new' is hit
sketchbook.prompt = false
# preliminary for rev 0047, can point sketchbook at
# another location. this can be a full or relative path
# no promises on how well this works, and note that
# a 'default' directory will be created inside it,
# which is where any new sketches will be thrown.
#sketchbook.path=sketchbook
#sketchbook.path = sketchbook
# note that this path should use forward slashes (like unix)
# instead of \ on windows or : on windows or whatever else