5252import  java .util .ArrayList ;
5353import  java .util .Arrays ;
5454import  java .util .Collections ;
55- import  java .util .Comparator ;
5655import  java .util .Enumeration ;
5756import  java .util .HashMap ;
5857import  java .util .LinkedList ;
9695import  cc .arduino .view .findreplace .FindReplace ;
9796import  jssc .SerialPortException ;
9897import  processing .app .debug .RunnerException ;
98+ import  processing .app .debug .TargetBoard ;
9999import  processing .app .forms .PasswordAuthorizationDialog ;
100100import  processing .app .helpers .DocumentTextChangeListener ;
101101import  processing .app .helpers .Keys ;
@@ -149,9 +149,6 @@ public boolean test(SketchController controller) {
149149    }
150150  }
151151
152-   private  final  static  List <String > BOARD_PROTOCOLS_ORDER  = Arrays .asList ("serial" , "network" );
153-   private  final  static  List <String > BOARD_PROTOCOLS_ORDER_TRANSLATIONS  = Arrays .asList (tr ("Serial ports" ), tr ("Network ports" ));
154- 
155152  final  Base  base ;
156153
157154  // otherwise, if the window is resized with the message label 
@@ -1043,22 +1040,30 @@ class BoardPortJCheckBoxMenuItem extends JCheckBoxMenuItem {
10431040    private  BoardPort  port ;
10441041
10451042    public  BoardPortJCheckBoxMenuItem (BoardPort  port ) {
1046-       super (port .getLabel ());
1043+       super ();
1044+       this .port  = port ;
1045+       setText (toString ());
10471046      addActionListener (e  -> {
10481047        selectSerialPort (port .getAddress ());
10491048        base .onBoardOrPortChange ();
10501049      });
1051-       this .port  = port ;
10521050    }
10531051
10541052    @ Override 
10551053    public  String  toString () {
10561054      // This is required for serialPrompt() 
1057-       return  port .getLabel ();
1055+       String  label  = port .getLabel ();
1056+       if  (port .getBoardName () != null  && !port .getBoardName ().isEmpty ()) {
1057+         label  += " ("  + port .getBoardName () + ")" ;
1058+       }
1059+       return  label ;
10581060    }
10591061  }
10601062
10611063  private  void  populatePortMenu () {
1064+     final  List <String > PROTOCOLS_ORDER  = Arrays .asList ("serial" , "network" );
1065+     final  List <String > PROTOCOLS_LABELS  = Arrays .asList (tr ("Serial ports" ), tr ("Network ports" ));
1066+ 
10621067    portMenu .removeAll ();
10631068
10641069    String  selectedPort  = PreferencesData .get ("serial.port" );
@@ -1067,31 +1072,43 @@ private void populatePortMenu() {
10671072
10681073    ports  = platform .filterPorts (ports , PreferencesData .getBoolean ("serial.ports.showall" ));
10691074
1070-     Collections .sort (ports , new  Comparator <BoardPort >() {
1071-       @ Override 
1072-       public  int  compare (BoardPort  o1 , BoardPort  o2 ) {
1073-         return  (BOARD_PROTOCOLS_ORDER .indexOf (o1 .getProtocol ()) - BOARD_PROTOCOLS_ORDER .indexOf (o2 .getProtocol ())) * 10  +
1074-                o1 .getAddress ().compareTo (o2 .getAddress ());
1075-       }
1075+     ports .stream () // 
1076+         .filter (port  -> port .getProtocolLabel () == null  || port .getProtocolLabel ().isEmpty ())
1077+         .forEach (port  -> {
1078+           int  labelIdx  = PROTOCOLS_ORDER .indexOf (port .getProtocol ());
1079+           if  (labelIdx  != -1 ) {
1080+             port .setProtocolLabel (PROTOCOLS_LABELS .get (labelIdx ));
1081+           } else  {
1082+             port .setProtocolLabel (port .getProtocol ());
1083+           }
1084+         });
1085+ 
1086+     Collections .sort (ports , (port1 , port2 ) -> {
1087+       String  pr1  = port1 .getProtocol ();
1088+       String  pr2  = port2 .getProtocol ();
1089+       int  prIdx1  = PROTOCOLS_ORDER .contains (pr1 ) ? PROTOCOLS_ORDER .indexOf (pr1 ) : 999 ;
1090+       int  prIdx2  = PROTOCOLS_ORDER .contains (pr2 ) ? PROTOCOLS_ORDER .indexOf (pr2 ) : 999 ;
1091+       int  r  = prIdx1  - prIdx2 ;
1092+       if  (r  != 0 )
1093+         return  r ;
1094+       r  = port1 .getProtocolLabel ().compareTo (port2 .getProtocolLabel ());
1095+       if  (r  != 0 )
1096+         return  r ;
1097+       return  port1 .getAddress ().compareTo (port2 .getAddress ());
10761098    });
10771099
1078-     String  lastProtocol  = null ;
1079-     String  lastProtocolTranslated ;
1100+     String  lastProtocol  = "" ;
1101+     String  lastProtocolLabel  =  "" ;
10801102    for  (BoardPort  port  : ports ) {
1081-       if  (lastProtocol  ==  null   || !port .getProtocol ().equals (lastProtocol )) {
1082-         if  (lastProtocol  !=  null ) {
1103+       if  (! port . getProtocol (). equals ( lastProtocol )  || !port .getProtocolLabel ().equals (lastProtocolLabel )) {
1104+         if  (! lastProtocol . isEmpty () ) {
10831105          portMenu .addSeparator ();
10841106        }
10851107        lastProtocol  = port .getProtocol ();
1086- 
1087-         if  (BOARD_PROTOCOLS_ORDER .indexOf (port .getProtocol ()) != -1 ) {
1088-           lastProtocolTranslated  = BOARD_PROTOCOLS_ORDER_TRANSLATIONS .get (BOARD_PROTOCOLS_ORDER .indexOf (port .getProtocol ()));
1089-         } else  {
1090-           lastProtocolTranslated  = port .getProtocol ();
1091-         }
1092-         JMenuItem  lastProtocolMenuItem  = new  JMenuItem (tr (lastProtocolTranslated ));
1093-         lastProtocolMenuItem .setEnabled (false );
1094-         portMenu .add (lastProtocolMenuItem );
1108+         lastProtocolLabel  = port .getProtocolLabel ();
1109+         JMenuItem  item  = new  JMenuItem (tr (lastProtocolLabel ));
1110+         item .setEnabled (false );
1111+         portMenu .add (item );
10951112      }
10961113      String  address  = port .getAddress ();
10971114
@@ -2403,9 +2420,9 @@ private void handleBoardInfo() {
24032420    for  (BoardPort  port  : ports ) {
24042421      if  (port .getAddress ().equals (selectedPort )) {
24052422        label  = port .getBoardName ();
2406-         vid  = port .getVID ( );
2407-         pid  = port .getPID ( );
2408-         iserial  = port .getISerial ( );
2423+         vid  = port .getPrefs (). get ( "vid" );
2424+         pid  = port .getPrefs (). get ( "pid" );
2425+         iserial  = port .getPrefs (). get ( "iserial" );
24092426        protocol  = port .getProtocol ();
24102427        found  = true ;
24112428        break ;
@@ -2575,12 +2592,12 @@ private void statusEmpty() {
25752592  // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 
25762593
25772594  protected  void  onBoardOrPortChange () {
2578-     Map < String ,  String >  boardPreferences   = BaseNoGui .getBoardPreferences ();
2579-     if  (boardPreferences  != null )
2580-       lineStatus .setBoardName (boardPreferences . get ( "name" ));
2595+     TargetBoard   board   = BaseNoGui .getTargetBoard ();
2596+     if  (board  != null )
2597+       lineStatus .setBoardName (board . getName ( ));
25812598    else 
25822599      lineStatus .setBoardName ("-" );
2583-     lineStatus .setSerialPort (PreferencesData .get ("serial.port" ));
2600+     lineStatus .setPort (PreferencesData .get ("serial.port" ));
25842601    lineStatus .repaint ();
25852602  }
25862603
0 commit comments