(Component cmp, boolean gained)
| 2958 | /// @return this method returns true if the state change needs to trigger a |
| 2959 | /// revalidate |
| 2960 | private boolean changeFocusState(Component cmp, boolean gained) { |
| 2961 | boolean trigger = false; |
| 2962 | Style selected = cmp.getSelectedStyle(); |
| 2963 | Style unselected = cmp.getUnselectedStyle(); |
| 2964 | //if selected style is different then unselected style there is a good |
| 2965 | //chance we need to trigger a revalidate |
| 2966 | if (!selected.getFont().equals(unselected.getFont()) |
| 2967 | || selected.getPaddingTop() != unselected.getPaddingTop() |
| 2968 | || selected.getPaddingBottom() != unselected.getPaddingBottom() |
| 2969 | || selected.getPaddingRight(isRTL()) != unselected.getPaddingRight(isRTL()) |
| 2970 | || selected.getPaddingLeft(isRTL()) != unselected.getPaddingLeft(isRTL()) |
| 2971 | || selected.getMarginTop() != unselected.getMarginTop() |
| 2972 | || selected.getMarginBottom() != unselected.getMarginBottom() |
| 2973 | || selected.getMarginRight(isRTL()) != unselected.getMarginRight(isRTL()) |
| 2974 | || selected.getMarginLeft(isRTL()) != unselected.getMarginLeft(isRTL())) { |
| 2975 | trigger = true; |
| 2976 | } |
| 2977 | int prefW = 0; |
| 2978 | int prefH = 0; |
| 2979 | if (trigger) { |
| 2980 | Dimension d = cmp.getPreferredSize(); |
| 2981 | prefW = d.getWidth(); |
| 2982 | prefH = d.getHeight(); |
| 2983 | } |
| 2984 | |
| 2985 | if (gained) { |
| 2986 | cmp.setFocus(true); |
| 2987 | cmp.fireFocusGained(); |
| 2988 | fireFocusGained(cmp); |
| 2989 | } else { |
| 2990 | cmp.setFocus(false); |
| 2991 | cmp.fireFocusLost(); |
| 2992 | fireFocusLost(cmp); |
| 2993 | } |
| 2994 | |
| 2995 | //if the styles are different there is a chance the preffered size is |
| 2996 | //still the same therefore make sure there is a real need to preform |
| 2997 | //a revalidate |
| 2998 | if (trigger) { |
| 2999 | cmp.setShouldCalcPreferredSize(true); |
| 3000 | Dimension d = cmp.getPreferredSize(); |
| 3001 | if (prefW != d.getWidth() || prefH != d.getHeight()) { |
| 3002 | cmp.setShouldCalcPreferredSize(false); |
| 3003 | trigger = false; |
| 3004 | } |
| 3005 | } |
| 3006 | |
| 3007 | return trigger; |
| 3008 | } |
| 3009 | |
| 3010 | /// Returns the current focus component for this form |
| 3011 | /// |
no test coverage detected