3535import java .awt .event .MouseAdapter ;
3636import java .awt .event .MouseEvent ;
3737import java .awt .event .MouseListener ;
38- import java .io .Serializable ;
3938
4039import javax .accessibility .AccessibleContext ;
4140import javax .swing .Icon ;
@@ -76,7 +75,8 @@ public DefaultSwatchChooserPanel() {
7675 setInheritsPopupMenu (true );
7776 }
7877
79- public String getDisplayName () {
78+ @ Override
79+ public String getDisplayName () {
8080 return "Swatches" ;//UIManager.getString("ColorChooser.swatchesNameText");
8181 }
8282
@@ -99,7 +99,8 @@ public String getDisplayName() {
9999 * @see #getDisplayedMnemonicIndex
100100 * @since 1.4
101101 */
102- public int getMnemonic () {
102+ @ Override
103+ public int getMnemonic () {
103104 return getInt ("ColorChooser.swatchesMnemonic" , -1 );
104105 }
105106
@@ -127,27 +128,32 @@ public int getMnemonic() {
127128 * @see #getMnemonic
128129 * @since 1.4
129130 */
130- public int getDisplayedMnemonicIndex () {
131+ @ Override
132+ public int getDisplayedMnemonicIndex () {
131133 return getInt ("ColorChooser.swatchesDisplayedMnemonicIndex" , -1 );
132134 }
133135
134- public Icon getSmallDisplayIcon () {
136+ @ Override
137+ public Icon getSmallDisplayIcon () {
135138 return null ;
136139 }
137140
138- public Icon getLargeDisplayIcon () {
141+ @ Override
142+ public Icon getLargeDisplayIcon () {
139143 return null ;
140144 }
141145
142146 /**
143147 * The background color, foreground color, and font are already set to the
144148 * defaults from the defaults table before this method is called.
145149 */
146- public void installChooserPanel (JColorChooser enclosingChooser ) {
150+ @ Override
151+ public void installChooserPanel (JColorChooser enclosingChooser ) {
147152 super .installChooserPanel (enclosingChooser );
148153 }
149154
150- protected void buildChooser () {
155+ @ Override
156+ protected void buildChooser () {
151157
152158 GridBagLayout gb = new GridBagLayout ();
153159 GridBagConstraints gbc = new GridBagConstraints ();
@@ -205,7 +211,8 @@ protected void buildChooser() {
205211 add (superHolder );
206212 }
207213
208- public void uninstallChooserPanel (JColorChooser enclosingChooser ) {
214+ @ Override
215+ public void uninstallChooserPanel (JColorChooser enclosingChooser ) {
209216 super .uninstallChooserPanel (enclosingChooser );
210217 swatchPanel .removeMouseListener (mainSwatchListener );
211218 recentSwatchPanel .removeMouseListener (recentSwatchListener );
@@ -216,21 +223,24 @@ public void uninstallChooserPanel(JColorChooser enclosingChooser) {
216223 removeAll (); // strip out all the sub-components
217224 }
218225
219- public void updateChooser () {
226+ @ Override
227+ public void updateChooser () {
220228
221229 }
222230
223231
224- class RecentSwatchListener extends MouseAdapter implements Serializable {
225- public void mousePressed (MouseEvent e ) {
232+ class RecentSwatchListener extends MouseAdapter {
233+ @ Override
234+ public void mousePressed (MouseEvent e ) {
226235 Color color = recentSwatchPanel .getColorForLocation (e .getX (), e .getY ());
227236 getColorSelectionModel ().setSelectedColor (color );
228237
229238 }
230239 }
231240
232- class MainSwatchListener extends MouseAdapter implements Serializable {
233- public void mousePressed (MouseEvent e ) {
241+ class MainSwatchListener extends MouseAdapter {
242+ @ Override
243+ public void mousePressed (MouseEvent e ) {
234244 Color color = swatchPanel .getColorForLocation (e .getX (), e .getY ());
235245 getColorSelectionModel ().setSelectedColor (color );
236246 recentSwatchPanel .setMostRecentColor (color );
@@ -259,15 +269,17 @@ public SwatchPanel() {
259269 setInheritsPopupMenu (true );
260270 }
261271
262- public boolean isFocusTraversable () {
272+ @ Override
273+ public boolean isFocusTraversable () {
263274 return false ;
264275 }
265276
266277 protected void initValues () {
267278
268279 }
269280
270- public void paintComponent (Graphics g ) {
281+ @ Override
282+ public void paintComponent (Graphics g ) {
271283 g .setColor (getBackground ());
272284 g .fillRect (0 ,0 ,getWidth (), getHeight ());
273285 for (int row = 0 ; row < numSwatches .height ; row ++) {
@@ -290,7 +302,8 @@ public void paintComponent(Graphics g) {
290302 }
291303 }
292304
293- public Dimension getPreferredSize () {
305+ @ Override
306+ public Dimension getPreferredSize () {
294307 int x = numSwatches .width * (swatchSize .width + gap .width ) - 1 ;
295308 int y = numSwatches .height * (swatchSize .height + gap .height ) - 1 ;
296309 return new Dimension ( x , y );
@@ -301,7 +314,8 @@ protected void initColors() {
301314
302315 }
303316
304- public String getToolTipText (MouseEvent e ) {
317+ @ Override
318+ public String getToolTipText (MouseEvent e ) {
305319 Color color = getColorForLocation (e .getX (), e .getY ());
306320 return color .getRed ()+", " + color .getGreen () + ", " + color .getBlue ();
307321 }
@@ -328,21 +342,30 @@ private Color getColorForCell( int column, int row) {
328342}
329343
330344class RecentSwatchPanel extends SwatchPanel {
331- protected void initValues () {
345+
346+ static Color [] recentColors ; // BH SwingJS adds static recentColors just for fun
347+
348+ @ Override
349+ protected void initValues () {
332350 swatchSize = UIManager .getDimension ("ColorChooser.swatchesRecentSwatchSize" );
333351 numSwatches = new Dimension ( 5 , 7 );
334352 gap = new Dimension (1 , 1 );
335353 }
336354
337355
338- protected void initColors () {
339- Color defaultRecentColor = UIManager .getColor ("ColorChooser.swatchesDefaultRecentColor" );
340- int numColors = numSwatches .width * numSwatches .height ;
341-
342- colors = new Color [numColors ];
343- for (int i = 0 ; i < numColors ; i ++) {
344- colors [i ] = defaultRecentColor ;
345- }
356+ @ Override
357+ protected void initColors () {
358+ if (recentColors == null ) {
359+ Color defaultRecentColor = UIManager .getColor ("ColorChooser.swatchesDefaultRecentColor" );
360+ int numColors = numSwatches .width * numSwatches .height ;
361+ colors = new Color [numColors ];
362+ for (int i = 0 ; i < numColors ; i ++) {
363+ colors [i ] = defaultRecentColor ;
364+ }
365+ recentColors = colors ;
366+ } else {
367+ colors = recentColors ;
368+ }
346369 }
347370
348371 public void setMostRecentColor (Color c ) {
@@ -357,13 +380,15 @@ public void setMostRecentColor(Color c) {
357380class MainSwatchPanel extends SwatchPanel {
358381
359382
360- protected void initValues () {
383+ @ Override
384+ protected void initValues () {
361385 swatchSize = UIManager .getDimension ("ColorChooser.swatchesSwatchSize" );
362386 numSwatches = new Dimension ( 31 , 9 );
363387 gap = new Dimension (1 , 1 );
364388 }
365389
366- protected void initColors () {
390+ @ Override
391+ protected void initColors () {
367392 int [] rawValues = initRawValues ();
368393 int numColors = rawValues .length / 3 ;
369394
0 commit comments