99import com .panayotis .jubler .JubFrame ;
1010import com .panayotis .jubler .subs .style .gui .tri .TriColorPickerButton ;
1111import com .panayotis .jubler .subs .style .gui .tri .TriObject ;
12- import static com .panayotis .jubler .i18n .I18N .__ ;
1312
1413import javax .swing .*;
1514import java .awt .*;
1615
16+ import static com .panayotis .jubler .i18n .I18N .__ ;
17+
1718public class JColorPickerDialog extends JWindow {
1819
1920 private TriObject [] allButtons ;
@@ -36,17 +37,24 @@ private void initComponents() {
3637 BorderFactory .createEmptyBorder (4 , 4 , 4 , 4 )
3738 ));
3839 panel .setBackground (UIManager .getColor ("Panel.background" ));
39-
40+ panel .setFocusable (true );
41+ panel .setRequestFocusEnabled (true );
42+ panel .addFocusListener (new java .awt .event .FocusAdapter () {
43+ public void focusLost (java .awt .event .FocusEvent evt ) {
44+ setVisible (false );
45+ }
46+ });
47+
4048 add (panel );
41-
49+
4250 addWindowFocusListener (new java .awt .event .WindowFocusListener () {
4351 public void windowGainedFocus (java .awt .event .WindowEvent evt ) {
4452 }
4553 public void windowLostFocus (java .awt .event .WindowEvent evt ) {
4654 setVisible (false );
4755 }
4856 });
49-
57+
5058 addFocusListener (new java .awt .event .FocusAdapter () {
5159 public void focusLost (java .awt .event .FocusEvent evt ) {
5260 setVisible (false );
@@ -56,9 +64,9 @@ public void focusLost(java.awt.event.FocusEvent evt) {
5664
5765 private void updatePanel () {
5866 panel .removeAll ();
59-
67+
6068 String [] labels = {__ ("Primary" ), __ ("Secondary" ), __ ("Outline" ), __ ("Shadow" )};
61-
69+
6270 for (int i = 0 ; i < allButtons .length ; i ++) {
6371 final int index = i ;
6472 JLabel label = new JLabel (labels [i ]);
@@ -70,6 +78,7 @@ public void mouseClicked(java.awt.event.MouseEvent evt) {
7078 if (index != currentIndex ) {
7179 pickerButton .switchToColor (index );
7280 }
81+ currentIndex = index ;
7382 setVisible (false );
7483 }
7584 public void mouseEntered (java .awt .event .MouseEvent evt ) {
@@ -84,7 +93,7 @@ public void mouseExited(java.awt.event.MouseEvent evt) {
8493 });
8594 panel .add (label );
8695 }
87-
96+
8897 pack ();
8998 }
9099
@@ -97,6 +106,8 @@ public void showBelow(JComponent component) {
97106 Point location = component .getLocationOnScreen ();
98107 setLocation (location .x , location .y + component .getHeight ());
99108 setVisible (true );
100- requestFocus ();
109+ if (!panel .requestFocusInWindow ()) {
110+ panel .requestFocus ();
111+ }
101112 }
102113}
0 commit comments