@@ -650,118 +650,51 @@ public boolean accept(File dir, String name) {
650650
651651
652652 public DefaultMutableTreeNode buildExamplesTree () {
653- DefaultMutableTreeNode node = new DefaultMutableTreeNode ("Examples" );
653+ DefaultMutableTreeNode root = new DefaultMutableTreeNode ("Examples" );
654654
655- // JTree examplesTree = new JTree(node);
656- // rebuildExamplesTree(node);
657- // }
658-
659- //DefaultTreeCellRenderer renderer = tree.
660- // TreeCellRenderer tcr = examplesTree.getCellRenderer();
661-
662- //
663- //
664- // public void rebuildExamplesTree(DefaultMutableTreeNode node) {
665655 try {
666- // break down the examples folder for examples
667- // File[] subfolders = examplesFolder.listFiles(new FilenameFilter() {
668- // public boolean accept(File dir, String name) {
669- // return dir.isDirectory() && name.charAt(0) != '.';
670- // }
671- // });
672- File [] subfolders = getExampleCategoryFolders ();
673656
674- DefaultMutableTreeNode modeExParent = new DefaultMutableTreeNode ("Mode Examples" );
675-
676- for (File sub : subfolders ) {
677- DefaultMutableTreeNode subNode = new DefaultMutableTreeNode (sub .getName ());
678- if (base .addSketches (subNode , sub )) {
679- // examplesParent.add(subNode);
680- modeExParent .add (subNode );
657+ File [] examples = getExampleCategoryFolders ();
658+
659+ for (File subFolder : examples ) {
660+ DefaultMutableTreeNode subNode = new DefaultMutableTreeNode (subFolder .getName ());
661+ if (base .addSketches (subNode , subFolder )) {
662+ root .add (subNode );
681663 }
682664 }
683-
684- // get library examples
685- boolean any = false ;
665+
666+ DefaultMutableTreeNode foundationLibraries = new DefaultMutableTreeNode ("Core Libraries" );
667+
668+ // Get examples for core libraries
686669 for (Library lib : coreLibraries ) {
687670 if (lib .hasExamples ()) {
688671 DefaultMutableTreeNode libNode = new DefaultMutableTreeNode (lib .getName ());
689672 if (base .addSketches (libNode , lib .getExamplesFolder ()))
690- modeExParent .add (libNode );
673+ foundationLibraries .add (libNode );
691674 }
692675 }
676+ if (foundationLibraries .getChildCount () > 0 ) {
677+ root .add (foundationLibraries );
678+ }
693679
694- if (modeExParent .getChildCount () > 0 )
695- node .add (modeExParent );
696-
697- // get contrib library examples
698- any = false ;
680+ // Get examples for third party libraries
681+ DefaultMutableTreeNode contributed = new DefaultMutableTreeNode ("Libraries" );
699682 for (Library lib : contribLibraries ) {
700683 if (lib .hasExamples ()) {
701- any = true ;
702- }
703- }
704- if (any ) {
705- // menu.addSeparator();
706- DefaultMutableTreeNode contribParent = new DefaultMutableTreeNode ("Library Examples" );
707- // Base.addDisabledItem(menu, "Contributed");
708- for (Library lib : contribLibraries ) {
709- if (lib .hasExamples ()) {
710- // JMenu libMenu = new JMenu(lib.getName());
711684 DefaultMutableTreeNode libNode = new DefaultMutableTreeNode (lib .getName ());
712- // base.addSketches(libMenu, lib.getExamplesFolder(), replace);
713685 base .addSketches (libNode , lib .getExamplesFolder ());
714- // menu.add(libMenu);
715- contribParent .add (libNode );
716- }
686+ contributed .add (libNode );
717687 }
718- node .add (contribParent );
719- }
720- } catch (IOException e ) {
721- e .printStackTrace ();
722- }
723-
724- DefaultMutableTreeNode contribExampleNode = buildContributedExamplesTrees ();
725- if (contribExampleNode .getChildCount () > 0 )
726- node .add (contribExampleNode );
727- return node ;
728- }
729-
730-
731- public DefaultMutableTreeNode buildContributedExamplesTrees () {
732- DefaultMutableTreeNode node = new DefaultMutableTreeNode ("Contributed Examples" );
733-
734- try {
735- File [] subfolders = ContributionType .EXAMPLES .listCandidates (examplesContribFolder );
736- if (subfolders == null ) {
737- subfolders = new File [0 ]; //empty array
738688 }
739- for (File sub : subfolders ) {
740- if (!ExamplesContribution .isExamplesCompatible (base , sub ))
741- continue ;
742- DefaultMutableTreeNode subNode = new DefaultMutableTreeNode (sub .getName ());
743- if (base .addSketches (subNode , sub )) {
744- node .add (subNode );
745- int exampleNodeNumber = -1 ;
746- for (int y = 0 ; y < subNode .getChildCount (); y ++)
747- if (subNode .getChildAt (y ).toString ().equals ("examples" ))
748- exampleNodeNumber = y ;
749- if (exampleNodeNumber == -1 )
750- continue ;
751- TreeNode exampleNode = subNode .getChildAt (exampleNodeNumber );
752- subNode .remove (exampleNodeNumber );
753- int count = exampleNode .getChildCount ();
754- for (int x = 0 ; x < count ; x ++) {
755- subNode .add ((DefaultMutableTreeNode ) exampleNode .getChildAt (0 ));
756- }
757- }
689+ if (contributed .getChildCount () > 0 ){
690+ root .add (contributed );
758691 }
759692 } catch (IOException e ) {
760693 e .printStackTrace ();
761694 }
762- return node ;//examplesTree;
763- }
764695
696+ return root ;
697+ }
765698
766699 public void resetExamples () {
767700 if (examplesFrame != null ) {
@@ -886,24 +819,19 @@ public void actionPerformed(ActionEvent e) {
886819 examplesPanel .setLayout (new BorderLayout ());
887820 examplesPanel .setBackground (Color .WHITE );
888821
889- final JPanel openExamplesManagerPanel = new JPanel (new FlowLayout (FlowLayout .LEFT ));
890- JLabel openExamplesManagerLabel = new JLabel (Language .text ("examples.add_examples" ));
891- // openExamplesManagerLabel.setAlignmentX(Component.LEFT_ALIGNMENT);
892- openExamplesManagerPanel .add (openExamplesManagerLabel );
822+ final JPanel openExamplesManagerPanel = new JPanel (new FlowLayout (FlowLayout .CENTER ));
823+ JButton addExamplesButton = new JButton (Language .text ("examples.add_examples" ));
824+ openExamplesManagerPanel .add (addExamplesButton );
893825 openExamplesManagerPanel .setOpaque (false );
894826 Border lineBorder = BorderFactory .createMatteBorder (0 , 0 , 1 , 0 , Color .BLACK );
895827 Border paddingBorder = BorderFactory .createEmptyBorder (3 , 5 , 1 , 4 );
896828 openExamplesManagerPanel .setBorder (BorderFactory .createCompoundBorder (lineBorder , paddingBorder ));
897- // openExamplesManagerLabel.set
898829 openExamplesManagerPanel .setAlignmentX (Component .LEFT_ALIGNMENT );
899830 openExamplesManagerPanel .setCursor (new Cursor (Cursor .HAND_CURSOR ));
900- // openExamplesManagerLabel.setForeground(new Color(0, 0, 238));
901- openExamplesManagerPanel .addMouseListener (new MouseAdapter () {
902-
831+ addExamplesButton .addActionListener (new ActionListener () {
903832 @ Override
904- public void mouseClicked ( MouseEvent e ) {
833+ public void actionPerformed ( ActionEvent e ) {
905834 base .handleOpenExampleManager ();
906- // openExamplesManagerLabel.setForeground(new Color(85, 26, 139));
907835 }
908836 });
909837
@@ -916,7 +844,6 @@ public void mouseClicked(MouseEvent e) {
916844
917845 tree .getSelectionModel ().setSelectionMode (TreeSelectionModel .SINGLE_TREE_SELECTION );
918846 tree .setShowsRootHandles (true );
919- // tree.setToggleClickCount(2);
920847 // expand the root
921848 tree .expandRow (0 );
922849 // now hide the root
0 commit comments