lots of ui tweaking.. deal with button sizes, esc/ctrl-w to close

windows, other layout issues
This commit is contained in:
benfry
2005-12-14 01:22:24 +00:00
parent 75eda2482e
commit 8a90cdb1e6
6 changed files with 235 additions and 287 deletions
+51 -65
View File
@@ -49,7 +49,7 @@ import processing.core.PApplet;
* properties files are iso8859-1, which is highly likely to
* be a problem when trying to save sketch folders and locations.
*/
public class Preferences extends JComponent {
public class Preferences {
// what to call the feller
@@ -75,7 +75,7 @@ public class Preferences extends JComponent {
* Standardized width for buttons. Mac OS X 10.3 wants 70 as its default,
* Windows XP needs 66, and Linux needs 76, so 76 seems proper.
*/
static int BUTTON_WIDTH = 76;
static public int BUTTON_WIDTH = 76;
/**
* Standardized button height. Mac OS X 10.3 (Java 1.4) wants 29,
@@ -84,7 +84,7 @@ public class Preferences extends JComponent {
* would be). Because of the disparity, on Mac OS X, it will be set
* inside a static block.
*/
static int BUTTON_HEIGHT = 24;
static public int BUTTON_HEIGHT = 24;
static {
if (Base.isMacOS()) BUTTON_HEIGHT = 29;
}
@@ -93,7 +93,10 @@ public class Preferences extends JComponent {
static final int GRID_SIZE = 33;
// gui variables
// indents and spacing standards. these probably need to be modified
// per platform as well, since macosx is so huge, windows is smaller,
// and linux is all over the map
static final int GUI_BIG = 13;
static final int GUI_BETWEEN = 10;
@@ -101,14 +104,12 @@ public class Preferences extends JComponent {
// gui elements
//JFrame frame;
JDialog frame;
JDialog dialog;
int wide, high;
JTextField sketchbookLocationField;
JCheckBox sketchPromptBox;
JCheckBox sketchCleanBox;
//JCheckBox exportLibraryBox;
JCheckBox externalEditorBox;
JCheckBox checkUpdatesBox;
@@ -123,7 +124,6 @@ public class Preferences extends JComponent {
static Hashtable table = new Hashtable();;
static File preferencesFile;
//boolean firstTime; // first time this feller has been run
static public void init() {
@@ -164,9 +164,6 @@ public class Preferences extends JComponent {
// next load user preferences file
//File home = new File(System.getProperty("user.home"));
//File processingHome = new File(home, "Processing");
//preferencesFile = new File(home, PREFS_FILE);
preferencesFile = Base.getSettingsFile(PREFS_FILE);
if (!preferencesFile.exists()) {
@@ -193,14 +190,12 @@ public class Preferences extends JComponent {
public Preferences() {
// setup frame for the prefs
// setup dialog for the prefs
//frame = new JFrame("Preferences");
frame = new JDialog(editor, "Preferences", true);
//frame.setResizable(false);
dialog = new JDialog(editor, "Preferences", true);
dialog.setResizable(false);
//Container pain = this;
Container pain = frame.getContentPane();
Container pain = dialog.getContentPane();
pain.setLayout(null);
int top = GUI_BIG;
@@ -296,20 +291,6 @@ public class Preferences extends JComponent {
top += d.height + GUI_BETWEEN;
// [ ] Enable export to "Library"
/*
exportLibraryBox = new JCheckBox("Enable advanced \"Library\" features" +
" (requires restart)");
exportLibraryBox.setEnabled(false);
pain.add(exportLibraryBox);
d = exportLibraryBox.getPreferredSize();
exportLibraryBox.setBounds(left, top, d.width, d.height);
right = Math.max(right, left + d.width);
top += d.height + GUI_BETWEEN;
*/
// [ ] Use external editor
externalEditorBox = new JCheckBox("Use external editor");
@@ -332,21 +313,6 @@ public class Preferences extends JComponent {
// More preferences are in the ...
/*
String blather =
"More preferences can be edited directly\n" +
"in the file " + preferencesFile.getAbsolutePath();
//"More preferences are in the 'lib' folder inside text files\n" +
//"named preferences.txt and pde_" +
//Base.platforms[Base.platform] + ".properties";
JTextArea textarea = new JTextArea(blather);
textarea.setEditable(false);
textarea.setBorder(new EmptyBorder(0, 0, 0, 0));
textarea.setBackground(null);
textarea.setFont(new Font("Dialog", Font.PLAIN, 12));
pain.add(textarea);
*/
label = new JLabel("More preferences can be edited directly in the file");
pain.add(label);
@@ -374,9 +340,6 @@ public class Preferences extends JComponent {
// [ OK ] [ Cancel ] maybe these should be next to the message?
//right = Math.max(right, left + d.width + GUI_BETWEEN +
// BUTTON_WIDTH + GUI_SMALL + BUTTON_WIDTH);
button = new JButton(PROMPT_OK);
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
@@ -387,10 +350,6 @@ public class Preferences extends JComponent {
pain.add(button);
d2 = button.getPreferredSize();
BUTTON_HEIGHT = d2.height;
//System.out.println("changing button height to " + BUTTON_HEIGHT);
// smoosh up to the line before
//top -= BUTTON_HEIGHT;
h = right - (BUTTON_WIDTH + GUI_SMALL + BUTTON_WIDTH);
button.setBounds(h, top, BUTTON_WIDTH, BUTTON_HEIGHT);
@@ -411,33 +370,40 @@ public class Preferences extends JComponent {
// finish up
wide = right + GUI_BIG;
high = top + GUI_SMALL; //GUI_BIG;
setSize(wide, high);
high = top + GUI_SMALL;
//setSize(wide, high);
// closing the window is same as hitting cancel button
frame.addWindowListener(new WindowAdapter() {
dialog.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
disposeFrame();
}
});
Container content = frame.getContentPane();
content.setLayout(new BorderLayout());
content.add(this, BorderLayout.CENTER);
frame.pack();
ActionListener disposer = new ActionListener() {
public void actionPerformed(ActionEvent actionEvent) {
disposeFrame();
}
};
Base.registerWindowCloseKeys(dialog.getRootPane(), disposer);
Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
frame.setLocation((screen.width - wide) / 2,
dialog.setLocation((screen.width - wide) / 2,
(screen.height - high) / 2);
dialog.pack(); // get insets
Insets insets = dialog.getInsets();
dialog.setSize(wide + insets.left + insets.right,
high + insets.top + insets.bottom);
// handle window closing commands for ctrl/cmd-W or hitting ESC.
addKeyListener(new KeyAdapter() {
pain.addKeyListener(new KeyAdapter() {
public void keyPressed(KeyEvent e) {
System.out.println(e);
KeyStroke wc = Editor.WINDOW_CLOSE_KEYSTROKE;
if ((e.getKeyCode() == KeyEvent.VK_ESCAPE) ||
(KeyStroke.getKeyStrokeForEvent(e).equals(wc))) {
@@ -448,6 +414,26 @@ public class Preferences extends JComponent {
}
/*
protected JRootPane createRootPane() {
System.out.println("creating root pane esc received");
ActionListener actionListener = new ActionListener() {
public void actionPerformed(ActionEvent actionEvent) {
//setVisible(false);
System.out.println("esc received");
}
};
JRootPane rootPane = new JRootPane();
KeyStroke stroke = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0);
rootPane.registerKeyboardAction(actionListener, stroke,
JComponent.WHEN_IN_FOCUSED_WINDOW);
return rootPane;
}
*/
public Dimension getPreferredSize() {
return new Dimension(wide, high);
}
@@ -460,7 +446,7 @@ public class Preferences extends JComponent {
* Close the window after an OK or Cancel.
*/
public void disposeFrame() {
frame.dispose();
dialog.dispose();
}
@@ -500,7 +486,7 @@ public class Preferences extends JComponent {
externalEditorBox.setSelected(getBoolean("editor.external"));
checkUpdatesBox.setSelected(getBoolean("update.check"));
frame.show();
dialog.show();
}