/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* Provides the Synth L&F UI delegate for
* {@link javax.swing.JComboBox}.
*
* @author Scott Violet
* @since 1.7
*/
private boolean useListColors;
/**
* Used to adjust the location and size of the popup. Very useful for
* situations such as we find in Nimbus where part of the border is used
* to paint the focus. In such cases, the border is empty space, and not
* part of the "visual" border, and in these cases, you'd like the popup
* to be adjusted such that it looks as if it were next to the visual border.
* You may want to use negative insets to get the right look.
*/
/**
* This flag may be set via UIDefaults. By default, it is false, to
* preserve backwards compatibility. If true, then the combo will
* "act as a button" when it is not editable.
*/
private boolean buttonWhenNotEditable;
/**
* A flag to indicate that the combo box and combo box button should
* remain in the PRESSED state while the combo popup is visible.
*/
private boolean pressedWhenPopupVisible;
/**
* When buttonWhenNotEditable is true, this field is used to help make
* the combo box appear and function as a button when the combo box is
* not editable. In such a state, you can click anywhere on the button
* to get it to open the popup. Also, anywhere you hover over the combo
* will cause the entire combo to go into "rollover" state, and anywhere
* you press will go into "pressed" state. This also keeps in sync the
* state of the combo and the arrowButton.
*/
/**
*/
/**
* If true, then the cell renderer will be forced to be non-opaque when
* used for rendering the selected item in the combo box (not in the list),
* and forced to opaque after rendering the selected value.
*/
private boolean forceOpaque = false;
/**
* Creates a new UI object for the given component.
*
* @param c component to create UI object for
* @return the UI object
*/
return new SynthComboBoxUI();
}
/**
* @inheritDoc
*
* Overridden to ensure that ButtonHandler is created prior to any of
* the other installXXX methods, since several of them reference
* buttonHandler.
*/
buttonHandler = new ButtonHandler();
super.installUI(c);
}
protected void installDefaults() {
}
"ComboBox.rendererUseListColors", true);
"ComboBox.buttonWhenNotEditable", false);
"ComboBox.pressedWhenPopupVisible", false);
"ComboBox.squareButton", true);
}
"ComboBox.forceOpaque", false);
}
}
}
/**
* @inheritDoc
*/
protected void installListeners() {
super.installListeners();
}
/**
* @inheritDoc
*/
if (popup instanceof SynthComboPopup) {
}
super.uninstallUI(c);
}
/**
* @inheritDoc
*/
protected void uninstallDefaults() {
}
/**
* @inheritDoc
*/
protected void uninstallListeners() {
buttonHandler.pressed = false;
buttonHandler.over = false;
super.uninstallListeners();
}
/**
* @inheritDoc
*/
return getContext(c, getComponentState(c));
}
}
// currently we have a broken situation where if a developer
// takes the border from a JComboBox and sets it on a JTextField
// then the codepath will eventually lead back to this method
// but pass in a JTextField instead of JComboBox! In case this
// happens, we just return the normal synth state for the component
// instead of doing anything special
if (shouldActLikeButton()) {
if ((!c.isEnabled())) {
}
if (buttonHandler.isPressed()) {
}
if (buttonHandler.isRollover()) {
state |= MOUSE_OVER;
}
if (box.isFocusOwner()) {
}
return state;
} else {
// for editable combos the editor component has the focus not the
// combo box its self, so we should make the combo paint focused
// when its editor has focus
if (box.isEditable() &&
basicState |= FOCUSED;
}
return basicState;
}
}
/**
* @inheritDoc
*/
return p;
}
/**
* @inheritDoc
*/
return new SynthComboBoxRenderer();
}
/**
* @inheritDoc
*/
return new SynthComboBoxEditor();
}
//
// end UI Initialization
//======================
/**
* @inheritDoc
*/
if (SynthLookAndFeel.shouldUpdateStyle(e)) {
}
}
/**
* @inheritDoc
*/
return button;
}
//=================================
// begin ComponentUI Implementation
/**
* Notifies this UI delegate to repaint the specified component.
* This method paints the component background, then calls
* the {@link #paint(SynthContext,Graphics)} method.
*
* <p>In general, this method does not need to be overridden by subclasses.
* All Look and Feel rendering code should reside in the {@code paint} method.
*
* @param g the {@code Graphics} object used for painting
* @param c the component being painted
* @see #paint(SynthContext,Graphics)
*/
}
/**
* Paints the specified component according to the Look and Feel.
* <p>This method is not used by Synth Look and Feel.
* Painting is handled by the {@link #paint(SynthContext,Graphics)} method.
*
* @param g the {@code Graphics} object used for painting
* @param c the component being painted
* @see #paint(SynthContext,Graphics)
*/
}
/**
* Paints the specified component.
*
* @param context context for the component being painted
* @param g the {@code Graphics} object used for painting
* @see #update(Graphics,JComponent)
*/
if ( !comboBox.isEditable() ) {
paintCurrentValue(g,r,hasFocus);
}
}
/**
* @inheritDoc
*/
int y, int w, int h) {
}
/**
* Paints the currently selected item.
*/
Component c;
// Fix for 4238829: should lay out the JPanel.
boolean shouldValidate = false;
if (c instanceof JPanel) {
shouldValidate = true;
}
if (c instanceof UIResource) {
c.setName("ComboBox.renderer");
}
if (force) {
((JComponent)c).setOpaque(false);
}
}
if (force) {
((JComponent)c).setOpaque(true);
}
}
/**
* @return true if this combo box should act as one big button. Typically
* only happens when buttonWhenNotEditable is true, and comboBox.isEditable
* is false.
*/
private boolean shouldActLikeButton() {
}
/**
* Returns the default size of an empty display area of the combo box using
* the current renderer and font.
*
* This method was overridden to use SynthComboBoxRenderer instead of
* DefaultListCellRenderer as the default renderer when calculating the
* size of the combo box. This is used in the case of the combo not having
* any data.
*
* @return the size of an empty display area
* @see #getDisplaySize
*/
SynthComboBoxRenderer r = new SynthComboBoxRenderer();
}
/**
* From BasicComboBoxRenderer v 1.18.
*
* Be aware that SynthFileChooserUIImpl relies on the fact that the default
* renderer installed on a Synth combo box is a JLabel. If this is changed,
* then an assert will fail in SynthFileChooserUIImpl
*/
public SynthComboBoxRenderer() {
super();
setText(" ");
}
// SynthComboBoxRenderer should have installed Name while constructor is working.
// The setName invocation in the SynthComboBoxRenderer() constructor doesn't work
// because of the opaque property is installed in the constructor based on the
// component name (see GTKStyle.isOpaque())
}
setName("ComboBox.listRenderer");
if (isSelected) {
if (!useListColors) {
}
} else {
}
setText("");
} else {
text = " ";
}
}
// The renderer component should inherit the enabled and
// orientation state of its parent combobox. This is
// especially needed for GTK comboboxes, where the
// ListCellRenderer's state determines the visual state
// of the combobox.
}
return this;
}
super.paint(g);
}
}
private static class SynthComboBoxEditor
extends BasicComboBoxEditor.UIResource {
f.setName("ComboBox.textField");
return f;
}
}
/**
* Handles all the logic for treating the combo as a button when it is
* not editable, and when shouldActLikeButton() is true. This class is a
* special ButtonModel, and installed on the arrowButton when appropriate.
* It also is installed as a mouse listener and mouse motion listener on
* the combo box. In this way, the state between the button and combo
* are in sync. Whenever one is "over" both are. Whenever one is pressed,
* both are.
*/
implements MouseListener, PopupMenuListener {
/**
* Indicates that the mouse is over the combo or the arrow button.
* This field only has meaning if buttonWhenNotEnabled is true.
*/
private boolean over;
/**
* Indicates that the combo or arrow button has been pressed. This
* field only has meaning if buttonWhenNotEnabled is true.
*/
private boolean pressed;
//------------------------------------------------------------------
// State Methods
//------------------------------------------------------------------
/**
* <p>Updates the internal "pressed" state. If shouldActLikeButton()
* is true, and if this method call will change the internal state,
* then the combo and button will be repainted.</p>
*
* <p>Note that this method is called either when a press event
* occurs on the combo box, or on the arrow button.</p>
*/
private void updatePressed(boolean p) {
if (shouldActLikeButton()) {
}
}
/**
* <p>Updates the internal "over" state. If shouldActLikeButton()
* is true, and if this method call will change the internal state,
* then the combo and button will be repainted.</p>
*
* occurs on the combo box, or on the arrow button.</p>
*/
private void updateOver(boolean o) {
boolean old = isRollover();
boolean newo = isRollover();
}
}
//------------------------------------------------------------------
// DefaultButtonModel Methods
//------------------------------------------------------------------
/**
* @inheritDoc
*
* Ensures that isPressed() will return true if the combo is pressed,
* or the arrowButton is pressed, <em>or</em> if the combo popup is
* visible. This is the case because a combo box looks pressed when
* the popup is visible, and so should the arrow button.
*/
public boolean isPressed() {
}
/**
* @inheritDoc
*
* Ensures that the armed state is in sync with the pressed state
* if shouldActLikeButton is true. Without this method, the arrow
* button will not look pressed when the popup is open, regardless
* of the result of isPressed() alone.
*/
public boolean isArmed() {
boolean b = shouldActLikeButton() ||
}
/**
* @inheritDoc
*
* Ensures that isRollover() will return true if the combo is
* rolled over, or the arrowButton is rolled over.
*/
public boolean isRollover() {
}
/**
* @inheritDoc
*
* Forwards pressed states to the internal "pressed" field
*/
public void setPressed(boolean b) {
super.setPressed(b);
updatePressed(b);
}
/**
* @inheritDoc
*
* Forwards rollover states to the internal "over" field
*/
public void setRollover(boolean b) {
super.setRollover(b);
updateOver(b);
}
//------------------------------------------------------------------
// MouseListener/MouseMotionListener Methods
//------------------------------------------------------------------
updateOver(true);
}
updateOver(false);
}
updatePressed(true);
}
updatePressed(false);
}
//------------------------------------------------------------------
// PopupMenuListener Methods
//------------------------------------------------------------------
/**
* @inheritDoc
*
* Ensures that the combo box is repainted when the popup is closed.
* This avoids a bug where clicking off the combo wasn't causing a repaint,
* and thus the combo box still looked pressed even when it was not.
*
* This bug was only noticed when acting as a button, but may be generally
* present. If so, remove the if() block
*/
if (shouldActLikeButton() || pressedWhenPopupVisible) {
}
}
}
/**
*/
if (editorComponent != null){
editorComponent.addFocusListener(this);
}
}
}
public void unregister(){
if (editorComponent!=null){
}
}
/** Invoked when a component gains the keyboard focus. */
// repaint whole combo on focus gain
}
/** Invoked when a component loses the keyboard focus. */
// repaint whole combo on focus loss
}
/**
* Called when the combos editor changes
*
* @param evt A PropertyChangeEvent object describing the event source and
* the property that has changed.
*/
if (editorComponent!=null){
}
if (editorComponent != null){
editorComponent.addFocusListener(this);
}
}
}
}
}
}