33import java .awt .BorderLayout ;
44import java .awt .Component ;
55import java .awt .Dimension ;
6- import java .awt .FileDialog ;
76import java .awt .FlowLayout ;
87import java .awt .GridBagConstraints ;
98import java .awt .GridBagLayout ;
9+ import java .awt .Insets ;
1010import java .awt .event .ActionEvent ;
1111import java .awt .event .ActionListener ;
1212import java .awt .event .ItemEvent ;
1515import java .awt .event .MouseEvent ;
1616import java .awt .event .WindowAdapter ;
1717import java .awt .event .WindowEvent ;
18- import java .io .File ;
19- import java .nio .file .Paths ;
2018import java .util .ArrayList ;
2119import java .util .regex .Pattern ;
2220
@@ -66,6 +64,8 @@ public class CellEditDialog
6664
6765 private static String [] possibleActionsArray = new String [] {"" , "text_to_clipboard" , "file_to_clipboard" };
6866
67+ private static boolean selectedByUser = true ;
68+
6969 public static void initializeCellEditDialog ()
7070 {
7171 cellEditDialog = new JDialog (MainGui .window );
@@ -292,15 +292,11 @@ public static void processCell(Cell cell)
292292 actionsEditPanel .removeAll ();
293293 actionComboboxList .clear ();
294294 actionTextfieldList .clear ();
295- for (String action : cell .getActionString (). split ( "#" ) )
295+ for (String [] action : cell .getActionsArray ( ) )
296296 {
297- String [] action_arr = action .split (":" , 2 );
298- if (action_arr .length < 2 )
299- continue ;
300-
301297 JComboBox <String > comboBox = new JComboBox <String >(possibleActionsArray );
302- comboBox .setSelectedItem (action_arr [0 ] );
303- JTextField textField = new JTextField (action_arr [1 ], 15 );
298+ comboBox .setSelectedItem (action [0 ] );
299+ JTextField textField = new JTextField (action [1 ], 15 );
304300
305301 actionComboboxList .add (comboBox );
306302 actionTextfieldList .add (textField );
@@ -317,7 +313,6 @@ public static void processCell(Cell cell)
317313 cellEditDialog .setVisible (true );
318314 }
319315
320-
321316 private static void updateActionsEdit ()
322317 {
323318 actionsEditPanel .removeAll ();
@@ -399,7 +394,6 @@ private static void updateEditPanels()
399394 cellEditDialog .pack ();
400395 }
401396
402-
403397 private static ActionListener getSplitAtCurserListener ()
404398 {
405399 return new ActionListener () {
@@ -431,7 +425,6 @@ public void actionPerformed(ActionEvent e)
431425 };
432426 }
433427
434-
435428 private static ActionListener getIconEditListener ()
436429 {
437430 return new ActionListener () {
@@ -448,23 +441,30 @@ public void actionPerformed(ActionEvent ae)
448441 main_image_abbr = ( (EditIconLabel ) selectedCellPanel ).getMainImageAbbr ();
449442 layered_image_abbr = ( (EditIconLabel ) selectedCellPanel ).getLayeredImageAbbr ();
450443
451- JDialog icon_dialog = new JDialog (CellEditDialog .cellEditDialog );
444+ JDialog icon_dialog = new JDialog (CellEditDialog .cellEditDialog , "Edit cell icon" );
452445
453- JPanel main_panel = new JPanel (new BorderLayout () );
446+ JPanel main_panel = new JPanel ();
454447 main_panel .setBackground (ColorSettings .getBackgroundColor () );
455448 main_panel .setBorder (GuiHelper .getDialogBorder () );
456449 icon_dialog .add (main_panel );
457450
451+ JPanel inner_panel = new JPanel (new BorderLayout () );
452+ inner_panel .setOpaque (false );
453+ inner_panel .setBorder (GuiHelper .getSpacingBorder (5 ) );
454+ main_panel .add (inner_panel );
455+
458456 JPanel content_panel = new JPanel (new GridBagLayout () );
459457 content_panel .setOpaque (false );
460- main_panel .add (content_panel , BorderLayout .CENTER );
458+ inner_panel .add (content_panel , BorderLayout .CENTER );
461459 GridBagConstraints gbc = new GridBagConstraints ();
460+ gbc .insets = new Insets (0 , 0 , 2 , 2 );
461+ gbc .fill = GridBagConstraints .BOTH ;
462462
463463 // main image
464464
465465 //label
466466 gbc .gridy = gbc .gridx = 0 ;
467- content_panel .add (GuiHelper .getLeftAlignedNonOpaqueJLabelWithCurrentTextColor ("Main image" ), gbc );
467+ content_panel .add (GuiHelper .getAlignedNonOpaqueJLabelWithCurrentColors ("Main image" , GuiHelper . LEFT ), gbc );
468468
469469 //image
470470 gbc .gridx ++;
@@ -477,74 +477,78 @@ public void actionPerformed(ActionEvent ae)
477477 main_image_edit_panel .setLayout (new GridBagLayout () );
478478 main_image_edit_panel .setOpaque (false );
479479 GridBagConstraints gbc_main = new GridBagConstraints ();
480+ gbc_main .insets = new Insets (2 , 2 , 2 , 2 );
481+ gbc_main .fill = GridBagConstraints .HORIZONTAL ;
480482 gbc_main .gridx = gbc_main .gridy = 0 ;
481483
482- main_image_edit_panel .add (GuiHelper .getLeftAlignedNonOpaqueJLabelWithCurrentTextColor ( "Select from abbreviations:" ), gbc_main );
484+ main_image_edit_panel .add (GuiHelper .getAlignedNonOpaqueJLabelWithCurrentColors ( "Abbreviations:" , GuiHelper . LEFT ), gbc_main );
483485
484486 gbc_main .gridx ++;
485487 JComboBox <String > abbr_list_main = new JComboBox <String >(Abbreviations .getArrayOfAbbreviations () );
486488 abbr_list_main .setSelectedItem (main_image_abbr );
489+ main_image_edit_panel .add (abbr_list_main , gbc_main );
490+
491+ gbc_main .gridy ++;
492+ gbc_main .gridx = 0 ;
493+ main_image_edit_panel .add (GuiHelper .getAlignedNonOpaqueJLabelWithCurrentColors ("Images:" , GuiHelper .LEFT ), gbc_main );
494+
495+ gbc_main .gridx ++;
496+ JComboBox <String > images_list_main = new JComboBox <String >(FileOperations .getNamesOfImagesInImagesDirectory () );
497+ images_list_main .setSelectedItem (main_image_abbr );
498+ main_image_edit_panel .add (images_list_main , gbc_main );
499+
487500 abbr_list_main .addItemListener (new ItemListener () {
488501 @ Override
489502 public void itemStateChanged (ItemEvent e ) {
490- if (e .getStateChange () == ItemEvent .SELECTED )
503+ if (selectedByUser && e .getStateChange () == ItemEvent .SELECTED )
491504 {
492- content_panel . remove ( main_image_label ) ;
493- gbc . gridy = 0 ;
494- gbc . gridx = 1 ;
505+ selectedByUser = false ;
506+ images_list_main . setSelectedIndex ( 0 ) ;
507+ selectedByUser = true ;
495508 main_image_abbr = (String ) abbr_list_main .getSelectedItem ();
496- main_image_label = new JLabel (GuiHelper .getScaledImageIconFromAbbreviation (main_image_abbr ) );
497- content_panel .add (main_image_label , gbc );
509+ main_image_label .setIcon (GuiHelper .getScaledImageIconFromAbbreviation (main_image_abbr ) );
498510 icon_dialog .pack ();
499511 }
500512 }
501513 });
502- main_image_edit_panel .add (abbr_list_main , gbc_main );
503-
504- gbc_main .gridy ++;
505- JButton button_change_main = new JButton ("Select from file" );
506- button_change_main .addActionListener (e ->
507- {
508- FileDialog dialog = new FileDialog (MainGui .window , "Select image" );
509- dialog .setMode (FileDialog .LOAD );
510- GuiHelper .resizeAndCenterRelativeToMainWindow (dialog );
511- dialog .setVisible (true );
512-
513- if (dialog .getDirectory () != null )
514- {
515- content_panel .remove (main_image_label );
516- gbc .gridy = 0 ;
517- gbc .gridx = 1 ;
518- main_image_abbr = Paths .get ("Images\\ " ).toAbsolutePath ().relativize (new File (dialog .getDirectory () + dialog .getFile () ).toPath () ).toString ().split (Pattern .quote ("." ) )[0 ];
519- System .out .println (main_image_abbr );
520- main_image_label = new JLabel (GuiHelper .getScaledImageIconFromAbbreviation (main_image_abbr ) );
521- content_panel .add (main_image_label , gbc );
522- icon_dialog .pack ();
523- }
514+ images_list_main .addItemListener (new ItemListener () {
515+ @ Override
516+ public void itemStateChanged (ItemEvent e ) {
517+ if (selectedByUser && e .getStateChange () == ItemEvent .SELECTED )
518+ {
519+ selectedByUser = false ;
520+ abbr_list_main .setSelectedIndex (0 );
521+ selectedByUser = true ;
522+ main_image_abbr = (String ) images_list_main .getSelectedItem ();
523+ main_image_label .setIcon (GuiHelper .getScaledImageIconFromAbbreviation (main_image_abbr ) );
524+ icon_dialog .pack ();
525+ }
526+ }
524527 });
525- main_image_edit_panel .add (button_change_main , gbc_main );
528+
529+
526530 content_panel .add (main_image_edit_panel , gbc );
527531
528532 // layered?
529533
530534 //label
531535 gbc .gridy ++;
532536 gbc .gridx = 0 ;
533- content_panel .add (GuiHelper .getLeftAlignedNonOpaqueJLabelWithCurrentTextColor ("Layered image" ), gbc );
537+ content_panel .add (GuiHelper .getAlignedNonOpaqueJLabelWithCurrentColors ("Layered image" , GuiHelper . LEFT ), gbc );
534538
535539 //check box
536540 gbc .gridx ++;
537541 JCheckBox checkbox_layered = new JCheckBox ();
538542 checkbox_layered .setSelected ( ! layered_image_abbr .equals ("" ) );
539- checkbox_layered .setBackground ( ColorSettings . getBackgroundColor () );
543+ checkbox_layered .setOpaque ( false );
540544 content_panel .add (checkbox_layered , gbc );
541545
542546 // layered image
543547
544548 //label
545549 gbc .gridy ++;
546550 gbc .gridx = 0 ;
547- content_panel .add (GuiHelper .getLeftAlignedNonOpaqueJLabelWithCurrentTextColor ("Layered image" ), gbc );
551+ content_panel .add (GuiHelper .getAlignedNonOpaqueJLabelWithCurrentColors ("Layered image" , GuiHelper . LEFT ), gbc );
548552
549553 //image
550554 gbc .gridx ++;
@@ -558,78 +562,86 @@ public void itemStateChanged(ItemEvent e) {
558562 layered_image_edit_panel .setLayout (new GridBagLayout () );
559563 layered_image_edit_panel .setOpaque (false );
560564 GridBagConstraints gbc_layered = new GridBagConstraints ();
565+ gbc_layered .insets = new Insets (2 , 2 , 2 , 2 );
566+ gbc_layered .fill = GridBagConstraints .HORIZONTAL ;
561567 gbc_layered .gridx = gbc_layered .gridy = 0 ;
562568
563- layered_image_edit_panel .add (GuiHelper .getLeftAlignedNonOpaqueJLabelWithCurrentTextColor ("Select from abbreviations:" ), gbc_layered );
569+ layered_image_edit_panel .add (GuiHelper .getAlignedNonOpaqueJLabelWithCurrentColors ("Abbreviations:" , GuiHelper .LEFT ), gbc_layered );
570+
571+ gbc_layered .gridx ++;
572+ JComboBox <String > abbr_list_layered = new JComboBox <String >(Abbreviations .getArrayOfAbbreviations () );
573+ abbr_list_layered .setSelectedItem (layered_image_abbr );
574+ layered_image_edit_panel .add (abbr_list_layered , gbc_layered );
575+
576+ gbc_layered .gridx = 0 ;
577+ gbc_layered .gridy ++;
578+ layered_image_edit_panel .add (GuiHelper .getAlignedNonOpaqueJLabelWithCurrentColors ("Images:" , GuiHelper .LEFT ), gbc_layered );
564579
565580 gbc_layered .gridx ++;
566- JComboBox <String > abbr_list_layerd = new JComboBox <String >(Abbreviations .getArrayOfAbbreviations () );
567- abbr_list_layerd .setSelectedItem (layered_image_abbr );
568- abbr_list_layerd .addItemListener (new ItemListener () {
581+ JComboBox <String > images_list_layered = new JComboBox <String >(FileOperations .getNamesOfImagesInImagesDirectory () );
582+ images_list_layered .setSelectedItem (layered_image_abbr );
583+ layered_image_edit_panel .add (images_list_layered , gbc_layered );
584+
585+ content_panel .add (layered_image_edit_panel , gbc );
586+
587+
588+ abbr_list_layered .addItemListener (new ItemListener () {
569589 @ Override
570590 public void itemStateChanged (ItemEvent e ) {
571- if (e .getStateChange () == ItemEvent .SELECTED )
591+ if (selectedByUser && e .getStateChange () == ItemEvent .SELECTED )
572592 {
573- content_panel .remove (layered_image_label );
574- gbc .gridy = 2 ;
575- gbc .gridx = 1 ;
576- layered_image_abbr = (String ) abbr_list_layerd .getSelectedItem ();
577- layered_image_label = new JLabel (GuiHelper .getScaledImageIconFromAbbreviation (layered_image_abbr ) );
578- content_panel .add (layered_image_label , gbc );
593+ selectedByUser = false ;
594+ images_list_layered .setSelectedIndex (0 );
595+ selectedByUser = true ;
596+ layered_image_abbr = (String ) abbr_list_layered .getSelectedItem ();
597+ layered_image_label .setIcon (GuiHelper .getScaledImageIconFromAbbreviation (layered_image_abbr ) );
579598 icon_dialog .pack ();
580599 }
581600 }
582601 });
583- layered_image_edit_panel .add (abbr_list_layerd , gbc_layered );
584-
585- gbc_layered .gridy ++;
586- JButton button_change_layered = new JButton ("Select from file" );
587- button_change_layered .addActionListener (e ->
588- {
589- FileDialog dialog = new FileDialog (MainGui .window , "Select image" );
590- dialog .setMode (FileDialog .LOAD );
591- GuiHelper .resizeAndCenterRelativeToMainWindow (dialog );
592- dialog .setVisible (true );
593-
594- if (dialog .getDirectory () != null )
602+ images_list_layered .addItemListener (new ItemListener () {
603+ @ Override
604+ public void itemStateChanged (ItemEvent e ) {
605+ if (selectedByUser && e .getStateChange () == ItemEvent .SELECTED )
595606 {
596- content_panel .remove (layered_image_label );
597- gbc .gridy = 2 ;
598- gbc .gridx = 1 ;
599- layered_image_abbr = Paths .get ("Images\\ " ).toAbsolutePath ().relativize (new File (dialog .getDirectory () + dialog .getFile () ).toPath () ).toString ().split (Pattern .quote ("." ) )[0 ];
600- System .out .println (layered_image_abbr );
601- layered_image_label = new JLabel (GuiHelper .getScaledImageIconFromAbbreviation (layered_image_abbr ) );
602- content_panel .add (layered_image_label , gbc );
607+ selectedByUser = false ;
608+ abbr_list_layered .setSelectedIndex (0 );
609+ selectedByUser = true ;
610+ layered_image_abbr = (String ) images_list_layered .getSelectedItem ();
611+ layered_image_label .setIcon (GuiHelper .getScaledImageIconFromAbbreviation (layered_image_abbr ) );
603612 icon_dialog .pack ();
604613 }
605- });
606- layered_image_edit_panel .add (button_change_layered , gbc_layered );
607- content_panel .add (layered_image_edit_panel , gbc );
614+ }
615+ });
608616
609617 // horizontal alignment
610618 gbc .gridy ++;
611619 gbc .gridx = 0 ;
612- content_panel .add (GuiHelper .getLeftAlignedNonOpaqueJLabelWithCurrentTextColor ( " Horizontal alignment " ), gbc );
620+ content_panel .add (GuiHelper .getAlignedNonOpaqueJLabelWithCurrentColors ( " Horizontal alignment" , GuiHelper . LEFT ), gbc );
613621
614622 gbc .gridx ++;
615- JComboBox <String > dropdown_horizontal = new JComboBox <String >(new String [] {"l " , "c " , "r " } );
623+ JComboBox <String > dropdown_horizontal = new JComboBox <String >(new String [] {"left " , "center " , "right " } );
616624 dropdown_horizontal .setSelectedItem ( ( (EditIconLabel ) selectedCellPanel ).getLayeredHorizontalAlignment () );
625+ gbc .fill = GridBagConstraints .HORIZONTAL ;
617626 content_panel .add (dropdown_horizontal , gbc );
627+ gbc .fill = GridBagConstraints .BOTH ;
618628
619629 // vertical alignment
620630 gbc .gridy ++;
621631 gbc .gridx = 0 ;
622- content_panel .add (GuiHelper .getLeftAlignedNonOpaqueJLabelWithCurrentTextColor ("Vertical alignment" ), gbc );
632+ content_panel .add (GuiHelper .getAlignedNonOpaqueJLabelWithCurrentColors ("Vertical alignment" , GuiHelper . LEFT ), gbc );
623633
624634 gbc .gridx ++;
625- JComboBox <String > dropdown_vertical = new JComboBox <String >(new String [] {"t " , "c " , "b " } );
635+ JComboBox <String > dropdown_vertical = new JComboBox <String >(new String [] {"top " , "center " , "bottom " } );
626636 dropdown_vertical .setSelectedItem ( ( (EditIconLabel ) selectedCellPanel ).getLayeredVerticalAlignment () );
637+ gbc .fill = GridBagConstraints .HORIZONTAL ;
627638 content_panel .add (dropdown_vertical , gbc );
639+ gbc .fill = GridBagConstraints .BOTH ;
628640
629641 // controls
630642 JPanel control_panel = new JPanel ();
631643 control_panel .setOpaque (false );
632- main_panel .add (control_panel , BorderLayout .PAGE_END );
644+ inner_panel .add (control_panel , BorderLayout .PAGE_END );
633645
634646 JButton button_confirm = new JButton ("Confirm" );
635647 control_panel .add (button_confirm );
@@ -652,7 +664,6 @@ public void itemStateChanged(ItemEvent e) {
652664 };
653665 }
654666
655-
656667 private static ActionListener getRemoveEditPanelListener ()
657668 {
658669 return new ActionListener () {
@@ -677,7 +688,6 @@ public void actionPerformed(ActionEvent e)
677688 };
678689 }
679690
680-
681691 private static ActionListener getAddAboveListener ()
682692 {
683693 return new ActionListener () {
@@ -698,7 +708,6 @@ public void actionPerformed(ActionEvent e)
698708 };
699709 }
700710
701-
702711 private static ActionListener getAddBelowPanelListener ()
703712 {
704713 return new ActionListener () {
0 commit comments