2929import java .util .List ;
3030import java .util .Map ;
3131import java .util .Optional ;
32+ import java .util .stream .Collectors ;
3233import java .util .stream .IntStream ;
3334
3435import javax .swing .*;
35- import javax .swing .border .TitledBorder ;
3636
3737import com .github .weisj .darklaf .LafManager ;
3838import com .github .weisj .darklaf .settings .ThemeSettings ;
@@ -186,7 +186,6 @@ public void actionPerformed(ActionEvent e)
186186 gbc .weightx = 1 ;
187187 frame .getContentPane ().add (inputPnl , gbc );
188188 }
189- inputPnl .setBorder (new TitledBorder ("Deobfuscator Input" ));
190189 inputPnl .setLayout (new GridBagLayout ());
191190
192191 int gridy = 0 ;
@@ -208,17 +207,18 @@ public void actionPerformed(ActionEvent e)
208207 JLabel label = new JLabel (i .getDisplayName () + ":" );
209208 {
210209 GridBagConstraints gbc = new GridBagConstraints ();
211- gbc .anchor = GridBagConstraints .PAGE_START ;
212- gbc .insets = new Insets (5 , 2 , 2 , 2 );
210+ gbc .anchor = GridBagConstraints .BASELINE ;
211+ gbc .insets = new Insets (4 , 2 , 7 , 2 );
213212 gbc .gridx = 0 ;
214213 gbc .gridy = gridy ;
215214 inputPnl .add (label , gbc );
216215 }
217216 JTextField textField = new JTextField ();
217+ label .setLabelFor (textField );
218218 i .component = textField ;
219219 {
220220 GridBagConstraints gbc = new GridBagConstraints ();
221- gbc .insets = new Insets (5 , 2 , 2 , 2 );
221+ gbc .insets = new Insets (0 , 2 , 7 , 2 );
222222 gbc .gridx = 1 ;
223223 gbc .gridy = gridy ;
224224 gbc .weightx = 1 ;
@@ -228,7 +228,7 @@ public void actionPerformed(ActionEvent e)
228228 JButton button = new JButton ("Select" );
229229 {
230230 GridBagConstraints gbc = new GridBagConstraints ();
231- gbc .insets = new Insets (5 , 7 , 2 , 2 );
231+ gbc .insets = new Insets (0 , 7 , 7 , 2 );
232232 gbc .gridx = 2 ;
233233 gbc .gridy = gridy ;
234234 gbc .ipadx = 15 ;
@@ -329,7 +329,6 @@ public void actionPerformed(ActionEvent e)
329329
330330 //Other Options
331331 JPanel optionsPnl = new JPanel ();
332- optionsPnl .setBorder (new TitledBorder ("Other Options" ));
333332 optionsPnl .setLayout (new GridBagLayout ());
334333 {
335334 GridBagConstraints gbc = new GridBagConstraints ();
@@ -358,6 +357,7 @@ public void actionPerformed(ActionEvent e)
358357 transformersPanel .setLayout (new GridBagLayout ());
359358 //First list (available)
360359 JScrollPane transformerListScroll = new JScrollPane ();
360+ transformerListScroll .setPreferredSize (new Dimension (200 , 200 ));
361361 DefaultListModel <String > transformerList = new DefaultListModel <>();
362362 for (Class <?> clazz : transformers )
363363 {
@@ -381,6 +381,7 @@ public void actionPerformed(ActionEvent e)
381381 }
382382 //Second list (selected)
383383 JScrollPane transformerSelectedScroll = new JScrollPane ();
384+ transformerSelectedScroll .setPreferredSize (new Dimension (200 , 200 ));
384385 transformerSelected = new DefaultListModel <>();
385386 JList <TransformerWithConfig > selectedJList = new JList <>(transformerSelected );
386387 selectedJList .setSelectionMode (ListSelectionModel .MULTIPLE_INTERVAL_SELECTION );
@@ -393,7 +394,7 @@ public void actionPerformed(ActionEvent e)
393394 gbc .gridheight = 4 ;
394395 gbc .anchor = GridBagConstraints .SOUTHEAST ;
395396 gbc .fill = GridBagConstraints .BOTH ;
396- gbc .insets = new Insets (10 , 0 , 10 , 10 );
397+ gbc .insets = new Insets (10 , 0 , 10 , 0 );
397398 gbc .weightx = 0.5 ;
398399 gbc .weighty = 1 ;
399400 transformersPanel .add (transformerSelectedScroll , gbc );
@@ -474,80 +475,164 @@ public void actionPerformed(ActionEvent e)
474475 {
475476 GridBagConstraints gbc = new GridBagConstraints ();
476477 gbc .gridx = 1 ;
477- gbc .weighty = 0.5 ;
478+ gbc .gridy = 0 ;
479+ gbc .weighty = 0.25 ;
478480 transformersPanel .add (panel1 , gbc );
479481 }
480-
481482 JPanel panel2 = new JPanel ();
482- panel2 .setLayout (new GridBagLayout ());
483483 {
484484 GridBagConstraints gbc = new GridBagConstraints ();
485485 gbc .gridx = 1 ;
486- gbc .weighty = 0.5 ;
486+ gbc .gridy = 3 ;
487+ gbc .weighty = 0.25 ;
487488 transformersPanel .add (panel2 , gbc );
488489 }
489490
490- JPanel panel3 = new JPanel () ;
491- panel3 . setLayout ( new GridBagLayout () );
491+ int buttonWidth = 30 ;
492+ JButton add = new JButton ( ">" );
492493 {
494+ Insets margin = add .getMargin ();
495+ add .setMargin (new Insets (margin .top + 30 , 1 , margin .bottom + 30 , 1 ));
496+ int prefHeight = add .getPreferredSize ().height ;
497+ add .setPreferredSize (new Dimension (buttonWidth , prefHeight ));
498+ add .setMinimumSize (new Dimension (buttonWidth , prefHeight ));
499+ add .setMaximumSize (new Dimension (buttonWidth , prefHeight ));
500+ add .addActionListener (e ->
501+ {
502+ for (String str : transformerJList .getSelectedValuesList ())
503+ {
504+ transformerSelected .addElement (new TransformerWithConfig (str ));
505+ }
506+ });
493507 GridBagConstraints gbc = new GridBagConstraints ();
494508 gbc .gridx = 1 ;
495- gbc .weighty = 0.5 ;
496- transformersPanel .add (panel3 , gbc );
509+ gbc .gridy = 1 ;
510+ gbc .insets = new Insets (5 , 0 , 5 , 0 );
511+ transformersPanel .add (add , gbc );
497512 }
498513
499- JPanel panel4 = new JPanel ( );
514+ JButton remove = new JButton ( "<" );
500515 {
516+ Insets margin = remove .getMargin ();
517+ remove .setMargin (new Insets (margin .top + 30 , 1 , margin .bottom + 30 , 1 ));
518+ int prefHeight2 = remove .getPreferredSize ().height ;
519+ remove .setPreferredSize (new Dimension (buttonWidth , prefHeight2 ));
520+ remove .setMinimumSize (new Dimension (buttonWidth , prefHeight2 ));
521+ remove .setMaximumSize (new Dimension (buttonWidth , prefHeight2 ));
522+ remove .addActionListener (e ->
523+ {
524+ int [] indexes = selectedJList .getSelectedIndices ();
525+ Arrays .sort (indexes );
526+ int [] reversed = IntStream .range (0 , indexes .length ).map (i -> indexes [indexes .length - i - 1 ]).toArray ();
527+ for (int i : reversed )
528+ {
529+ transformerSelected .remove (i );
530+ }
531+ });
501532 GridBagConstraints gbc = new GridBagConstraints ();
502533 gbc .gridx = 1 ;
503- gbc .weighty = 0.5 ;
504- transformersPanel .add (panel4 , gbc );
534+ gbc .gridy = 2 ;
535+ gbc .insets = new Insets (5 , 2 , 5 , 2 );
536+ transformersPanel .add (remove , gbc );
505537 }
506538
507- JButton add = new JButton (">" );
508- Insets margin = add .getMargin ();
509- add .setMargin (new Insets (margin .top + 30 , 2 , margin .bottom + 30 , 2 ));
510- add .setPreferredSize (new Dimension (30 , add .getPreferredSize ().height ));
511- add .addActionListener (e ->
539+ JButton up = new JButton ("Ʌ" );
512540 {
513- for ( String str : transformerJList . getSelectedValuesList ())
541+ up . addActionListener ( e ->
514542 {
515- transformerSelected .addElement (new TransformerWithConfig (str ));
516- }
517- });
518- {
543+ //method returns always ordered array
544+ int [] indexesArr = selectedJList .getSelectedIndices ();
545+ List <Integer > indexes = Arrays .stream (indexesArr ).boxed ().collect (Collectors .toList ());
546+ //copy for iteration
547+ ArrayList <Integer > indexesIter = new ArrayList <>(indexes );
548+ //contains target indices of elements already moved (prevents changing order of elements)
549+ List <Integer > blocked = new ArrayList <>();
550+ for (int size = indexesIter .size (), i = 0 ; i < size ; i ++)
551+ {
552+ int valI = indexesIter .get (i );
553+ int newIndex = valI - 1 ;
554+ if (blocked .contains (newIndex )) {
555+ //if target index is blocked, we cannot move, so our index is blocked too
556+ blocked .add (valI );
557+ continue ;
558+ }
559+ //move up
560+ TransformerWithConfig t = transformerSelected .remove (valI );
561+ if (newIndex < 0 )
562+ {
563+ newIndex = 0 ;
564+ //cannot move up, so block our index to prevent swapping with potential next selected element
565+ blocked .add (newIndex );
566+ }
567+ transformerSelected .add (newIndex , t );
568+ indexes .set (i , newIndex );
569+ }
570+ selectedJList .setSelectedIndices (indexes .stream ().mapToInt (i -> i ).toArray ());
571+ });
572+ Insets margin = up .getMargin ();
573+ up .setMargin (new Insets (margin .top + 30 , 1 , margin .bottom + 30 , 1 ));
574+ int prefHeight3 = up .getPreferredSize ().height ;
575+ up .setPreferredSize (new Dimension (buttonWidth , prefHeight3 ));
576+ up .setMinimumSize (new Dimension (buttonWidth , prefHeight3 ));
577+ up .setMaximumSize (new Dimension (buttonWidth , prefHeight3 ));
519578 GridBagConstraints gbc = new GridBagConstraints ();
520- gbc .anchor = GridBagConstraints .CENTER ;
521- gbc .insets = new Insets (5 , 0 , 5 , 0 );
522- gbc .ipadx = 10 ;
523- panel2 .add (add , gbc );
579+ gbc .anchor = GridBagConstraints .EAST ;
580+ gbc .gridx = 3 ;
581+ gbc .gridy = 1 ;
582+ gbc .insets = new Insets (5 , 2 , 5 , 2 );
583+ transformersPanel .add (up , gbc );
524584 }
525-
526- JButton remove = new JButton ("<" );
527- margin = remove .getMargin ();
528- remove .setMargin (new Insets (margin .top + 30 , 2 , margin .bottom + 30 , 2 ));
529- remove .setPreferredSize (new Dimension (30 , remove .getPreferredSize ().height ));
530- remove .addActionListener (e ->
585+ JButton down = new JButton ("V" );
531586 {
532- int [] indexes = selectedJList .getSelectedIndices ();
533- Arrays .sort (indexes );
534- int [] reversed = IntStream .range (0 , indexes .length ).map (i -> indexes [indexes .length - i - 1 ])
535- .toArray ();
536- for (int i : reversed )
587+ down .addActionListener (e ->
537588 {
538- transformerSelected .remove (i );
539- }
540- });
541- {
589+ //method returns always ordered array
590+ int [] indexesArr = selectedJList .getSelectedIndices ();
591+ List <Integer > indexes = Arrays .stream (indexesArr ).boxed ().collect (Collectors .toList ());
592+ //copy for iteration
593+ ArrayList <Integer > indexesIter = new ArrayList <>(indexes );
594+ //contains target indices of elements already moved (prevents changing order of elements)
595+ List <Integer > blocked = new ArrayList <>();
596+ //iterate in reverse order to move last element down first
597+ for (int size = indexesIter .size (), i = size - 1 ; i >= 0 ; i --)
598+ {
599+ int valI = indexesIter .get (i );
600+ int newIndex = valI + 1 ;
601+ if (blocked .contains (newIndex )) {
602+ //if target index is blocked, we cannot move, so our index is blocked too
603+ blocked .add (valI );
604+ continue ;
605+ }
606+ //move down
607+ TransformerWithConfig t = transformerSelected .remove (valI );
608+ if (newIndex > transformerSelected .size () - 1 )
609+ {
610+ newIndex = transformerSelected .size ();
611+ //cannot move down, so block our index to prevent swapping with potential previous selected element
612+ blocked .add (newIndex );
613+ }
614+ transformerSelected .add (newIndex , t );
615+ indexes .set (i , newIndex );
616+ }
617+ selectedJList .setSelectedIndices (indexes .stream ().mapToInt (i -> i ).toArray ());
618+ });
619+ Insets margin = down .getMargin ();
620+ down .setMargin (new Insets (margin .top + 30 , 1 , margin .bottom + 30 , 1 ));
621+ int prefHeightDown = down .getPreferredSize ().height ;
622+ down .setPreferredSize (new Dimension (buttonWidth , prefHeightDown ));
623+ down .setMinimumSize (new Dimension (buttonWidth , prefHeightDown ));
624+ down .setMaximumSize (new Dimension (buttonWidth , prefHeightDown ));
542625 GridBagConstraints gbc = new GridBagConstraints ();
543- gbc .anchor = GridBagConstraints .CENTER ;
626+ gbc .anchor = GridBagConstraints .EAST ;
627+ gbc .gridx = 3 ;
628+ gbc .gridy = 2 ;
544629 gbc .insets = new Insets (5 , 2 , 5 , 2 );
545- gbc .ipadx = 10 ;
546- panel3 .add (remove , gbc );
630+ transformersPanel .add (down , gbc );
547631 }
548632
549633 tabbedPane .addTab ("Transformers" , transformersPanel );
550634
635+ //File lists (path, libraries)
551636 for (ConfigItem i : configFieldsList )
552637 {
553638 if (i .type != ItemType .FILELIST )
@@ -969,6 +1054,10 @@ public void keyPressed(KeyEvent event)
9691054 JButton run = new JButton ("Run" );
9701055
9711056 JTextArea area = new JTextArea ();
1057+ if (!enableDarkLaf .isSelected ())
1058+ {
1059+ area .setFont (area .getFont ().deriveFont (12F ));
1060+ }
9721061 PrintStream print = new PrintStream (new DeobfuscatorOutputStream (System .out , area ));
9731062 System .setErr (print );
9741063 System .setOut (print );
@@ -984,7 +1073,7 @@ public void keyPressed(KeyEvent event)
9841073 JScrollPane outputScrollPane = new JScrollPane (area );
9851074 newFrame .getContentPane ().add (outputScrollPane );
9861075 newFrame .pack ();
987- newFrame .setSize (800 , 600 );
1076+ newFrame .setSize (1400 , 600 );
9881077 newFrame .setVisible (true );
9891078 Thread thread = new Thread (() ->
9901079 {
0 commit comments