move "Add Examples" to bottom of window, more logic cleanups

This commit is contained in:
Ben Fry
2022-02-04 19:36:04 -05:00
parent 0839b129c8
commit d8785d2211
3 changed files with 38 additions and 41 deletions
+24 -31
View File
@@ -22,12 +22,7 @@
package processing.app.ui;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Cursor;
import java.awt.FlowLayout;
import java.awt.Point;
import java.awt.*;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter;
@@ -36,13 +31,7 @@ import java.io.File;
import java.io.IOException;
import java.util.Enumeration;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTree;
import javax.swing.border.Border;
import javax.swing.*;
import javax.swing.border.EmptyBorder;
import javax.swing.event.TreeExpansionEvent;
import javax.swing.event.TreeExpansionListener;
@@ -90,17 +79,6 @@ public class ExamplesFrame extends JFrame {
examplesPanel.setLayout(new BorderLayout());
examplesPanel.setBackground(Color.WHITE);
final JPanel openExamplesManagerPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
JButton addExamplesButton = new JButton(Language.text("examples.add_examples"));
openExamplesManagerPanel.add(addExamplesButton);
openExamplesManagerPanel.setOpaque(false);
Border lineBorder = BorderFactory.createMatteBorder(0, 0, 1, 0, Color.LIGHT_GRAY);
Border paddingBorder = BorderFactory.createEmptyBorder(3, 5, 1, 4);
openExamplesManagerPanel.setBorder(BorderFactory.createCompoundBorder(lineBorder, paddingBorder));
openExamplesManagerPanel.setAlignmentX(Component.LEFT_ALIGNMENT);
openExamplesManagerPanel.setCursor(new Cursor(Cursor.HAND_CURSOR));
addExamplesButton.addActionListener(e -> ContributionManager.openExamples());
final JTree tree = new JTree(buildTree());
tree.setOpaque(true);
@@ -178,9 +156,21 @@ public class ExamplesFrame extends JFrame {
treePane.setBackground(Color.WHITE);
treePane.setAlignmentX(Component.LEFT_ALIGNMENT);
examplesPanel.add(openExamplesManagerPanel,BorderLayout.PAGE_START);
//examplesPanel.add(openExamplesManagerPanel,BorderLayout.PAGE_START);
examplesPanel.add(treePane, BorderLayout.CENTER);
Container buttons = Box.createHorizontalBox();
JButton addButton = new JButton(Language.text("examples.add_examples"));
addButton.addActionListener(e -> ContributionManager.openExamples());
buttons.add(Box.createHorizontalGlue());
buttons.add(addButton);
buttons.add(Box.createHorizontalGlue());
JPanel buttonPanel = new JPanel(); // adds extra border
buttonPanel.add(buttons);
examplesPanel.add(buttonPanel, BorderLayout.SOUTH);
getContentPane().add(examplesPanel);
pack();
restoreExpanded(tree);
@@ -190,16 +180,19 @@ public class ExamplesFrame extends JFrame {
public void setVisible() {
// Space for the editor plus a li'l gap
int roughWidth = getWidth() + 20;
Point p;
// If no window open, or the editor is at the edge of the screen
Editor editor = base.getActiveEditor();
if (editor == null ||
(p = editor.getLocation()).x < roughWidth) {
// Center the window on the screen
if (editor == null) {
setLocationRelativeTo(null);
} else {
// Open the window relative to the editor
setLocation(p.x - roughWidth, p.y);
Point p = editor.getLocation();
if (p.x < roughWidth) {
// Center the window on the screen
setLocationRelativeTo(null);
} else {
// Open the window relative to the editor
setLocation(p.x - roughWidth, p.y);
}
}
setVisible(true);
}
+13 -7
View File
@@ -147,7 +147,9 @@ public class SketchbookFrame extends JFrame {
// Check whether sketchbook is empty or not
TreeModel treeModel = tree.getModel();
if (treeModel.getChildCount(treeModel.getRoot()) != 0) {
JScrollPane treePane = new JScrollPane(tree);
JScrollPane treePane = new JScrollPane(tree,
ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
treePane.setPreferredSize(Toolkit.zoom(250, 450));
treePane.setBorder(new EmptyBorder(0, 0, 0, 0));
@@ -188,20 +190,24 @@ public class SketchbookFrame extends JFrame {
public void setVisible() {
// TODO The ExamplesFrame code doesn't do this, is it necessary?
// TODO The ExamplesFrame code doesn't invokeLater(), is it necessary?
// Either one of them is wrong, or this is hiding a bug [fry 150811]
EventQueue.invokeLater(() -> {
// Space for the editor plus a li'l gap
int roughWidth = getWidth() + 20;
// If no window open, or the editor is at the edge of the screen
Editor editor = base.getActiveEditor();
Point p = editor.getLocation();
if (editor == null || p.x < roughWidth) {
// Center the window on the screen
if (editor == null) {
setLocationRelativeTo(null);
} else {
// Open the window relative to the editor
setLocation(p.x - roughWidth, p.y);
Point p = editor.getLocation();
if (p.x < roughWidth) {
// Center the window on the screen
setLocationRelativeTo(null);
} else {
// Open the window relative to the editor
setLocation(p.x - roughWidth, p.y);
}
}
setVisible(true);
});
+1 -3
View File
@@ -1,8 +1,6 @@
1281 (4.0b6)
X update to Java 17.0.2+8
_ move "Add Examples" to bottom of window
X move "Add Examples" to bottom of window
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .