Subversion Repository Public Repository

litesoft

Diff Revisions 949 vs 950 for /trunk/Java/KeyHole/src/org/litesoft/aokeyhole/swing/simplecomponents/JComboBoxPlus.java

Diff revisions: vs.
  @@ -1,59 +1,59 @@
1 - // This Source Code is in the Public Domain per: http://unlicense.org
2 - package org.litesoft.aokeyhole.swing.simplecomponents;
3 -
4 - import org.litesoft.aokeyhole.objects.support.*;
5 - import org.litesoft.aokeyhole.swing.*;
6 -
7 - import javax.swing.*;
8 - import java.awt.*;
9 -
10 - @SuppressWarnings("unchecked")
11 - public class JComboBoxPlus extends JComboBox {
12 - public JComboBoxPlus( String[] pValidOptions, boolean pAddBlank ) {
13 - UIManager.put( "ComboBox.disabledForeground", getForeground() );
14 - UIManager.put( "ComboBox.disabledBackground", ComponentColors.getDisabled() );
15 - setBackground( ComponentColors.getEnabled() );
16 - setFont( AdjustFont.sizeBy( getFont(), Font.PLAIN ) );
17 -
18 - if ( pAddBlank ) {
19 - addItem( "" );
20 - }
21 - if ( pValidOptions != null ) {
22 - for ( String option : pValidOptions ) {
23 - addItem( option );
24 - }
25 - }
26 - }
27 -
28 - public void setOptions( String[] pOptions, boolean pForceSelectionOrAddBlank ) {
29 - Object curValue = getSelectedItem();
30 - removeAllItems();
31 - if ( pOptions != null ) {
32 - if ( pForceSelectionOrAddBlank ) {
33 - if ( curValue == null ) {
34 - curValue = pOptions[0];
35 - }
36 - } else {
37 - addItem( "" );
38 - }
39 - for ( String option : pOptions ) {
40 - addItem( option );
41 - }
42 - }
43 - setSelectedItem( ensureAnOption( curValue ) );
44 - }
45 -
46 - public Object ensureAnOption( Object pValue ) {
47 - if ( pValue == null ) {
48 - pValue = "";
49 - }
50 - int items = getItemCount();
51 - for ( int i = 0; i < items; i++ ) {
52 - if ( AbstractBase.areEqual( pValue, getItemAt( i ) ) ) {
53 - return pValue;
54 - }
55 - }
56 - addItem( pValue );
57 - return pValue;
58 - }
59 - }
1 + // This Source Code is in the Public Domain per: http://unlicense.org
2 + package org.litesoft.aokeyhole.swing.simplecomponents;
3 +
4 + import org.litesoft.aokeyhole.objects.support.*;
5 + import org.litesoft.aokeyhole.swing.*;
6 +
7 + import javax.swing.*;
8 + import java.awt.*;
9 +
10 + @SuppressWarnings("unchecked")
11 + public class JComboBoxPlus extends JComboBox {
12 + public JComboBoxPlus( String[] pValidOptions, boolean pAddBlank ) {
13 + UIManager.put( "ComboBox.disabledForeground", getForeground() );
14 + UIManager.put( "ComboBox.disabledBackground", ComponentColors.getDisabled() );
15 + setBackground( ComponentColors.getEnabled() );
16 + setFont( AdjustFont.sizeBy( getFont(), Font.PLAIN ) );
17 +
18 + if ( pAddBlank ) {
19 + addItem( "" );
20 + }
21 + if ( pValidOptions != null ) {
22 + for ( String option : pValidOptions ) {
23 + addItem( option );
24 + }
25 + }
26 + }
27 +
28 + public void setOptions( String[] pOptions, boolean pForceSelectionOrAddBlank ) {
29 + Object curValue = getSelectedItem();
30 + removeAllItems();
31 + if ( pOptions != null ) {
32 + if ( pForceSelectionOrAddBlank ) {
33 + if ( curValue == null ) {
34 + curValue = pOptions[0];
35 + }
36 + } else {
37 + addItem( "" );
38 + }
39 + for ( String option : pOptions ) {
40 + addItem( option );
41 + }
42 + }
43 + setSelectedItem( ensureAnOption( curValue ) );
44 + }
45 +
46 + public Object ensureAnOption( Object pValue ) {
47 + if ( pValue == null ) {
48 + pValue = "";
49 + }
50 + int items = getItemCount();
51 + for ( int i = 0; i < items; i++ ) {
52 + if ( AbstractBase.areEqual( pValue, getItemAt( i ) ) ) {
53 + return pValue;
54 + }
55 + }
56 + addItem( pValue );
57 + return pValue;
58 + }
59 + }