Skip to content

Commit e3aeb3e

Browse files
committed
Prototype project view added
1 parent a056a5f commit e3aeb3e

File tree

4 files changed

+188
-28
lines changed

4 files changed

+188
-28
lines changed

app/src/processing/app/Editor.java

+22-10
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,7 @@
2525
import static processing.app.I18n.tr;
2626
import static processing.app.Theme.scale;
2727

28-
import java.awt.BorderLayout;
29-
import java.awt.Color;
30-
import java.awt.Component;
31-
import java.awt.Container;
32-
import java.awt.Dimension;
33-
import java.awt.Rectangle;
34-
import java.awt.Toolkit;
28+
import java.awt.*;
3529
import java.awt.datatransfer.DataFlavor;
3630
import java.awt.datatransfer.Transferable;
3731
import java.awt.event.ActionEvent;
@@ -122,6 +116,8 @@ public class Editor extends JFrame implements RunnerListener {
122116
private JMenu recentSketchesMenu;
123117
private JMenu programmersMenu;
124118
private final Box upper;
119+
private final Box middle; // Contains the header, project and editor
120+
private final Box editor_upper;
125121
private ArrayList<EditorTab> tabs = new ArrayList<>();
126122
private int currentTabIndex = -1;
127123

@@ -201,6 +197,7 @@ public boolean test(SketchController controller) {
201197
final EditorHeader header;
202198
EditorStatus status;
203199
EditorConsole console;
200+
EditorProject project;
204201

205202
private JSplitPane splitPane;
206203

@@ -299,6 +296,8 @@ public void windowDeactivated(WindowEvent e) {
299296

300297
Box box = Box.createVerticalBox();
301298
upper = Box.createVerticalBox();
299+
middle = Box.createHorizontalBox();
300+
editor_upper = Box.createVerticalBox();
302301

303302
if (toolbarMenu == null) {
304303
toolbarMenu = new JMenu();
@@ -308,7 +307,7 @@ public void windowDeactivated(WindowEvent e) {
308307
upper.add(toolbar);
309308

310309
header = new EditorHeader(this);
311-
upper.add(header);
310+
editor_upper.add(header);
312311

313312
// assemble console panel, consisting of status area and the console itself
314313
JPanel consolePanel = new JPanel();
@@ -326,10 +325,23 @@ public void windowDeactivated(WindowEvent e) {
326325
lineStatus = new EditorLineStatus();
327326
consolePanel.add(lineStatus, BorderLayout.SOUTH);
328327

329-
codePanel = new JPanel(new BorderLayout());
330-
upper.add(codePanel);
331328

329+
330+
project = new EditorProject("/home/sami/Arduino", base, this);
331+
middle.add(project);
332+
codePanel = new JPanel(new BorderLayout());
333+
editor_upper.add(codePanel);
334+
middle.add(editor_upper);
335+
336+
JSplitPane splitProject = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, project, editor_upper);
337+
splitProject.setBackground(new Color(23, 161, 165));
338+
splitProject.setContinuousLayout(true);
339+
splitProject.setResizeWeight(0.25);
340+
splitProject.setBackground(Color.BLACK);
341+
middle.add(splitProject);
342+
upper.add(middle);
332343
splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, upper, consolePanel);
344+
SwingUtilities.invokeLater(project);
333345

334346
// repaint child panes while resizing
335347
splitPane.setContinuousLayout(true);
+145
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
package processing.app;
2+
3+
import javax.swing.*;
4+
import javax.swing.tree.DefaultMutableTreeNode;
5+
import javax.swing.tree.DefaultTreeModel;
6+
import javax.swing.tree.TreePath;
7+
import java.awt.*;
8+
import java.awt.event.MouseEvent;
9+
import java.awt.event.MouseListener;
10+
import java.io.File;
11+
12+
public class EditorProject extends JScrollPane implements Runnable, MouseListener {
13+
14+
private DefaultMutableTreeNode root;
15+
16+
private DefaultTreeModel treeModel;
17+
18+
private JTree tree;
19+
20+
private File fileRoot;
21+
22+
private Base base;
23+
24+
private Editor editor;
25+
26+
private String workspace = System.getProperty("user.home") + "/";
27+
28+
public EditorProject(String path, Base base, Editor editor){
29+
fileRoot = new File(path);
30+
this.base = base;
31+
this.editor = editor;
32+
this.setPreferredSize(new Dimension(400, 1000));
33+
}
34+
35+
@Override
36+
public void run() {
37+
root = new DefaultMutableTreeNode(new FileNode(fileRoot));
38+
treeModel = new DefaultTreeModel(root);
39+
40+
41+
tree = new JTree(treeModel);
42+
tree.setShowsRootHandles(true);
43+
tree.addMouseListener(this);
44+
setViewportView(tree);
45+
46+
47+
CreateChildNodes ccn =
48+
new CreateChildNodes(fileRoot, root);
49+
new Thread(ccn).start();
50+
}
51+
52+
@Override
53+
public void mouseClicked(MouseEvent e) {
54+
int selRow = tree.getRowForLocation(e.getX(), e.getY());
55+
TreePath selPath = tree.getPathForLocation(e.getX(), e.getY());
56+
if(selRow != -1) {
57+
if(e.getClickCount() == 2) {
58+
String path = selPath.toString().replaceAll("\\]| |\\[|", "").replaceAll(",", File.separator);
59+
try {
60+
editor.getSketchController().addFile(new File(workspace + path));
61+
62+
} catch (Exception exception) {
63+
exception.printStackTrace();
64+
}
65+
}
66+
}
67+
}
68+
69+
@Override
70+
public void mousePressed(MouseEvent e) {
71+
72+
}
73+
74+
@Override
75+
public void mouseReleased(MouseEvent e) {
76+
77+
}
78+
79+
@Override
80+
public void mouseEntered(MouseEvent e) {
81+
82+
}
83+
84+
@Override
85+
public void mouseExited(MouseEvent e) {
86+
87+
}
88+
89+
public class CreateChildNodes implements Runnable {
90+
91+
private DefaultMutableTreeNode root;
92+
93+
private File fileRoot;
94+
95+
public CreateChildNodes(File fileRoot,
96+
DefaultMutableTreeNode root) {
97+
this.fileRoot = fileRoot;
98+
this.root = root;
99+
}
100+
101+
@Override
102+
public void run() {
103+
createChildren(fileRoot, root);
104+
}
105+
106+
private void createChildren(File fileRoot,
107+
DefaultMutableTreeNode node) {
108+
File[] files = fileRoot.listFiles();
109+
if (files == null) return;
110+
111+
for (File file : files) {
112+
DefaultMutableTreeNode childNode =
113+
new DefaultMutableTreeNode(new FileNode(file));
114+
node.add(childNode);
115+
if (file.isDirectory()) {
116+
createChildren(file, childNode);
117+
}
118+
}
119+
}
120+
121+
}
122+
123+
public class FileNode {
124+
125+
private File file;
126+
127+
public FileNode(File file) {
128+
this.file = file;
129+
}
130+
131+
@Override
132+
public String toString() {
133+
String name = file.getName();
134+
if (name.equals("")) {
135+
return file.getAbsolutePath();
136+
} else {
137+
return name;
138+
}
139+
}
140+
}
141+
142+
}
143+
144+
145+

app/src/processing/app/EditorTab.java

+1
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ public class EditorTab extends JPanel implements SketchFile.TextStorage {
8282
* @param editor
8383
* The Editor this tab runs in
8484
* @param file
85+
}
8586
* The file to display in this tab
8687
* @param contents
8788
* Initial contents to display in this tab. Can be used when editing

app/src/processing/app/macosx/ThinkDifferent.java

+20-18
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,14 @@
2222

2323
package processing.app.macosx;
2424

25-
import com.apple.eawt.*;
26-
import com.apple.eawt.AppEvent.AppReOpenedEvent;
2725

26+
import java.awt.Desktop;
27+
28+
import com.apple.eawt.AppEvent;
2829
import processing.app.Base;
2930
import processing.app.Editor;
3031

32+
import java.awt.desktop.*;
3133
import java.io.File;
3234
import java.util.List;
3335

@@ -46,24 +48,25 @@ public class ThinkDifferent {
4648
private static final int MAX_WAIT_FOR_BASE = 30000;
4749

4850
static public void init() {
49-
Application application = Application.getApplication();
51+
Desktop application = Desktop.getDesktop();
5052

51-
application.addAppEventListener(new AppReOpenedListener() {
53+
application.addAppEventListener(new AppReopenedListener() {
5254
@Override
53-
public void appReOpened(AppReOpenedEvent aroe) {
54-
try {
55-
if (Base.INSTANCE.getEditors().size() == 0) {
56-
Base.INSTANCE.handleNew();
57-
}
58-
} catch (Exception e) {
59-
// TODO Auto-generated catch block
60-
e.printStackTrace();
55+
public void appReopened(AppReopenedEvent aroe) {
56+
try {
57+
if (Base.INSTANCE.getEditors().size() == 0) {
58+
Base.INSTANCE.handleNew();
6159
}
60+
} catch (Exception e) {
61+
// TODO Auto-generated catch block
62+
e.printStackTrace();
63+
}
6264
}
65+
6366
});
6467
application.setAboutHandler(new AboutHandler() {
6568
@Override
66-
public void handleAbout(AppEvent.AboutEvent aboutEvent) {
69+
public void handleAbout(AboutEvent aboutEvent) {
6770
new Thread(() -> {
6871
if (waitForBase()) {
6972
Base.INSTANCE.handleAbout();
@@ -73,7 +76,7 @@ public void handleAbout(AppEvent.AboutEvent aboutEvent) {
7376
});
7477
application.setPreferencesHandler(new PreferencesHandler() {
7578
@Override
76-
public void handlePreferences(AppEvent.PreferencesEvent preferencesEvent) {
79+
public void handlePreferences(PreferencesEvent preferencesEvent) {
7780
new Thread(() -> {
7881
if (waitForBase()) {
7982
Base.INSTANCE.handlePrefs();
@@ -83,7 +86,7 @@ public void handlePreferences(AppEvent.PreferencesEvent preferencesEvent) {
8386
});
8487
application.setOpenFileHandler(new OpenFilesHandler() {
8588
@Override
86-
public void openFiles(final AppEvent.OpenFilesEvent openFilesEvent) {
89+
public void openFiles(OpenFilesEvent openFilesEvent) {
8790
new Thread(() -> {
8891
if (waitForBase()) {
8992
for (File file : openFilesEvent.getFiles()) {
@@ -104,7 +107,7 @@ public void openFiles(final AppEvent.OpenFilesEvent openFilesEvent) {
104107
});
105108
application.setQuitHandler(new QuitHandler() {
106109
@Override
107-
public void handleQuitRequestWith(AppEvent.QuitEvent quitEvent, QuitResponse quitResponse) {
110+
public void handleQuitRequestWith(QuitEvent quitEvent, QuitResponse quitResponse) {
108111
new Thread(() -> {
109112
if (waitForBase()) {
110113
if (Base.INSTANCE.handleQuit()) {
@@ -114,8 +117,7 @@ public void handleQuitRequestWith(AppEvent.QuitEvent quitEvent, QuitResponse qui
114117
}
115118
}
116119
}).start();
117-
}
118-
});
120+
}});
119121
}
120122

121123
private static boolean waitForBase() {

0 commit comments

Comments
 (0)