FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Updating display style of Examples Tree · Jonham/processing@6a0aed8 · GitHub

Repository navigation

Commit 6a0aed8

Browse files
committed
Updating display style of Examples Tree
1 parent 6a5a8ec commit 6a0aed8

2 files changed

Lines changed: 95 additions & 111 deletions

File tree

‎app/src/processing/app/Mode.java‎

Lines changed: 93 additions & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -595,10 +595,10 @@ public boolean accept(File dir, String name) {
595595
}
596596

597597

598-
public JTree buildExamplesTree() {
598+
public DefaultMutableTreeNode buildExamplesTree() {
599599
DefaultMutableTreeNode node = new DefaultMutableTreeNode("Examples");
600600

601-
JTree examplesTree = new JTree(node);
601+
// JTree examplesTree = new JTree(node);
602602
// rebuildExamplesTree(node);
603603
// }
604604

@@ -617,30 +617,28 @@ public JTree buildExamplesTree() {
617617
// });
618618
File[] subfolders = getExampleCategoryFolders();
619619

620-
// DefaultMutableTreeNode examplesParent = new DefaultMutableTreeNode("Examples");
620+
DefaultMutableTreeNode modeExParent = new DefaultMutableTreeNode("Mode Examples");
621+
621622
for (File sub : subfolders) {
622623
DefaultMutableTreeNode subNode = new DefaultMutableTreeNode(sub.getName());
623624
if (base.addSketches(subNode, sub)) {
624625
// examplesParent.add(subNode);
625-
node.add(subNode);
626+
modeExParent.add(subNode);
626627
}
627628
}
628-
// node.add(examplesParent);
629-
// examplesTree.expandPath(new TreePath(examplesParent));
630-
629+
631630
// get library examples
632631
boolean any = false;
633-
DefaultMutableTreeNode libParent = new DefaultMutableTreeNode("Libraries");
634632
for (Library lib : coreLibraries) {
635633
if (lib.hasExamples()) {
636634
DefaultMutableTreeNode libNode = new DefaultMutableTreeNode(lib.getName());
637-
any |= base.addSketches(libNode, lib.getExamplesFolder());
638-
libParent.add(libNode);
635+
if (base.addSketches(libNode, lib.getExamplesFolder()))
636+
modeExParent.add(libNode);
639637
}
640638
}
641-
if (any) {
642-
node.add(libParent);
643-
}
639+
640+
if (modeExParent.getChildCount() > 0)
641+
node.add(modeExParent);
644642

645643
// get contrib library examples
646644
any = false;
@@ -651,7 +649,7 @@ public JTree buildExamplesTree() {
651649
}
652650
if (any) {
653651
// menu.addSeparator();
654-
DefaultMutableTreeNode contribParent = new DefaultMutableTreeNode("Contributed Libraries");
652+
DefaultMutableTreeNode contribParent = new DefaultMutableTreeNode("Library Examples");
655653
// Base.addDisabledItem(menu, "Contributed");
656654
for (Library lib : contribLibraries) {
657655
if (lib.hasExamples()) {
@@ -668,15 +666,17 @@ public JTree buildExamplesTree() {
668666
} catch (IOException e) {
669667
e.printStackTrace();
670668
}
671-
return examplesTree;
669+
670+
DefaultMutableTreeNode contribExampleNode = buildContributedExamplesTrees();
671+
if (contribExampleNode.getChildCount() > 0)
672+
node.add(contribExampleNode);
673+
return node;
672674
}
673675

674676

675-
public JTree buildContributedExamplesTrees() {
677+
public DefaultMutableTreeNode buildContributedExamplesTrees() {
676678
DefaultMutableTreeNode node = new DefaultMutableTreeNode("Contributed Examples");
677679

678-
JTree examplesTree = new JTree(node);
679-
680680
try {
681681
File[] subfolders = ContributionType.EXAMPLE.listCandidates(examplesContribFolder);
682682
if (subfolders == null) {
@@ -688,6 +688,7 @@ public JTree buildContributedExamplesTrees() {
688688
DefaultMutableTreeNode subNode = new DefaultMutableTreeNode(sub.getName());
689689
if (base.addSketches(subNode, sub)) {
690690
node.add(subNode);
691+
System.out.println(subNode);
691692
int exampleNodeNumber = -1;
692693
for (int y = 0; y < subNode.getChildCount(); y++)
693694
if (subNode.getChildAt(y).toString().equals("example"))
@@ -699,13 +700,14 @@ public JTree buildContributedExamplesTrees() {
699700
int count = exampleNode.getChildCount();
700701
for (int x = 0; x < count; x++) {
701702
subNode.add((DefaultMutableTreeNode) exampleNode.getChildAt(0));
703+
System.out.println(subNode);
702704
}
703705
}
704706
}
705707
} catch (IOException e) {
706708
e.printStackTrace();
707709
}
708-
return examplesTree;
710+
return node;//examplesTree;
709711
}
710712

711713

@@ -767,8 +769,78 @@ public void mouseClicked(MouseEvent e) {
767769
}
768770
});
769771

770-
final JTree tree = buildExamplesTree();
771-
setupExamplesTree(tree);
772+
final JTree tree = new JTree(buildExamplesTree());
773+
774+
775+
tree.setOpaque(true);
776+
tree.setAlignmentX(Component.LEFT_ALIGNMENT);
777+
778+
tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
779+
tree.setShowsRootHandles(true);
780+
// tree.setToggleClickCount(2);
781+
// expand the root
782+
tree.expandRow(0);
783+
// now hide the root
784+
tree.setRootVisible(false);
785+
786+
// After 2.0a7, no longer expanding each of the categories at Casey's
787+
// request. He felt that the window was too complicated too quickly.
788+
// for (int row = tree.getRowCount()-1; row >= 0; --row) {
789+
// tree.expandRow(row);
790+
// }
791+
792+
tree.addMouseListener(new MouseAdapter() {
793+
public void mouseClicked(MouseEvent e) {
794+
if (e.getClickCount() == 2) {
795+
DefaultMutableTreeNode node =
796+
(DefaultMutableTreeNode) tree.getLastSelectedPathComponent();
797+
798+
int selRow = tree.getRowForLocation(e.getX(), e.getY());
799+
//TreePath selPath = tree.getPathForLocation(e.getX(), e.getY());
800+
//if (node != null && node.isLeaf() && node.getPath().equals(selPath)) {
801+
if (node != null && node.isLeaf() && selRow != -1) {
802+
SketchReference sketch = (SketchReference) node.getUserObject();
803+
base.handleOpen(sketch.getPath());
804+
}
805+
}
806+
}
807+
});
808+
tree.addKeyListener(new KeyAdapter() {
809+
public void keyPressed(KeyEvent e) {
810+
if (e.getKeyCode() == KeyEvent.VK_ESCAPE) { // doesn't fire keyTyped()
811+
examplesFrame.setVisible(false);
812+
}
813+
}
814+
public void keyTyped(KeyEvent e) {
815+
if (e.getKeyChar() == KeyEvent.VK_ENTER) {
816+
DefaultMutableTreeNode node =
817+
(DefaultMutableTreeNode) tree.getLastSelectedPathComponent();
818+
if (node != null && node.isLeaf()) {
819+
SketchReference sketch = (SketchReference) node.getUserObject();
820+
base.handleOpen(sketch.getPath());
821+
}
822+
}
823+
}
824+
});
825+
826+
tree.addTreeExpansionListener(new TreeExpansionListener() {
827+
@Override
828+
public void treeExpanded(TreeExpansionEvent event) {
829+
updateExpanded(tree);
830+
}
831+
832+
@Override
833+
public void treeCollapsed(TreeExpansionEvent event) {
834+
updateExpanded(tree);
835+
}
836+
});
837+
838+
tree.setBorder(new EmptyBorder(5, 5, 5, 5));
839+
if (Base.isMacOS()) {
840+
tree.setToggleClickCount(2);
841+
} else {
842+
tree.setToggleClickCount(1);
843+
}
772844

773845
JScrollPane treePane = new JScrollPane(tree);
774846
treePane.setPreferredSize(new Dimension(250, 300));
@@ -777,25 +849,8 @@ public void mouseClicked(MouseEvent e) {
777849
treePane.setBackground(Color.WHITE);
778850
treePane.setAlignmentX(Component.LEFT_ALIGNMENT);
779851

780-
JLabel contribExLabel = new JLabel("Contributed Examples");
781-
contribExLabel.setOpaque(false);
782-
contribExLabel.setBorder(new EmptyBorder(10, 6, 1, 5));
783-
contribExLabel.setAlignmentX(Component.LEFT_ALIGNMENT);
784-
785-
final JTree tree2 = buildContributedExamplesTrees();
786-
setupExamplesTree(tree2);
787-
788-
JScrollPane treePane2 = new JScrollPane(tree2);
789-
treePane2.setPreferredSize(new Dimension(250, 300));
790-
treePane2.setBorder(new EmptyBorder(0, 0, 10, 0));
791-
treePane2.setOpaque(true);
792-
treePane2.setBackground(Color.WHITE);
793-
treePane2.setAlignmentX(Component.LEFT_ALIGNMENT);
794-
795852
examplesPanel.add(openExamplesManagerLabel);
796853
examplesPanel.add(treePane);
797-
examplesPanel.add(contribExLabel);
798-
examplesPanel.add(treePane2);
799854
examplesFrame.getContentPane().add(examplesPanel);
800855
examplesFrame.pack();
801856

@@ -818,78 +873,6 @@ public void mouseClicked(MouseEvent e) {
818873
}
819874

820875

821-
private void setupExamplesTree(final JTree tree) {
822-
tree.setOpaque(true);
823-
tree.setAlignmentX(Component.LEFT_ALIGNMENT);
824-
825-
tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
826-
tree.setShowsRootHandles(true);
827-
// tree.setToggleClickCount(2);
828-
// expand the root
829-
tree.expandRow(0);
830-
// now hide the root
831-
tree.setRootVisible(false);
832-
833-
// After 2.0a7, no longer expanding each of the categories at Casey's
834-
// request. He felt that the window was too complicated too quickly.
835-
// for (int row = tree.getRowCount()-1; row >= 0; --row) {
836-
// tree.expandRow(row);
837-
// }
838-
839-
tree.addMouseListener(new MouseAdapter() {
840-
public void mouseClicked(MouseEvent e) {
841-
if (e.getClickCount() == 2) {
842-
DefaultMutableTreeNode node =
843-
(DefaultMutableTreeNode) tree.getLastSelectedPathComponent();
844-
845-
int selRow = tree.getRowForLocation(e.getX(), e.getY());
846-
//TreePath selPath = tree.getPathForLocation(e.getX(), e.getY());
847-
//if (node != null && node.isLeaf() && node.getPath().equals(selPath)) {
848-
if (node != null && node.isLeaf() && selRow != -1) {
849-
SketchReference sketch = (SketchReference) node.getUserObject();
850-
base.handleOpen(sketch.getPath());
851-
}
852-
}
853-
}
854-
});
855-
tree.addKeyListener(new KeyAdapter() {
856-
public void keyPressed(KeyEvent e) {
857-
if (e.getKeyCode() == KeyEvent.VK_ESCAPE) { // doesn't fire keyTyped()
858-
examplesFrame.setVisible(false);
859-
}
860-
}
861-
public void keyTyped(KeyEvent e) {
862-
if (e.getKeyChar() == KeyEvent.VK_ENTER) {
863-
DefaultMutableTreeNode node =
864-
(DefaultMutableTreeNode) tree.getLastSelectedPathComponent();
865-
if (node != null && node.isLeaf()) {
866-
SketchReference sketch = (SketchReference) node.getUserObject();
867-
base.handleOpen(sketch.getPath());
868-
}
869-
}
870-
}
871-
});
872-
873-
tree.addTreeExpansionListener(new TreeExpansionListener() {
874-
@Override
875-
public void treeExpanded(TreeExpansionEvent event) {
876-
updateExpanded(tree);
877-
}
878-
879-
@Override
880-
public void treeCollapsed(TreeExpansionEvent event) {
881-
updateExpanded(tree);
882-
}
883-
});
884-
885-
tree.setBorder(new EmptyBorder(5, 5, 5, 5));
886-
if (Base.isMacOS()) {
887-
tree.setToggleClickCount(2);
888-
} else {
889-
tree.setToggleClickCount(1);
890-
}
891-
}
892-
893876
protected void updateExpanded(JTree tree) {
894877
Enumeration en = tree.getExpandedDescendants(new TreePath(tree.getModel().getRoot()));
895878
//en.nextElement(); // skip the root "Examples" node

‎app/src/processing/app/contrib/ExampleContribution.java‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import java.util.HashMap;
66

77
import processing.app.Base;
8+
import processing.core.PApplet;
89

910
public class ExampleContribution extends LocalContribution {
1011

@@ -24,7 +25,7 @@ private static ArrayList<String> parseCompatibleModesList(String unparsedModes)
2425
ArrayList<String> modesList = new ArrayList<String>();
2526
if (unparsedModes == null || unparsedModes.isEmpty())
2627
return modesList;
27-
String[] splitStr = unparsedModes.split(",");
28+
String[] splitStr = PApplet.trim(PApplet.split(unparsedModes, ','));//unparsedModes.split(",");
2829
for (String mode : splitStr)
2930
modesList.add(mode.trim());
3031
return modesList;

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL