/** * Sets whether the mouse is currently over the dropdown area of the * view or not. Clients should not call this method unless the handle all * mouse events. * @param overDropDown whether the mouse is over the dropdown area */ protected void setMouseOverDropDown( boolean overDropDown ) { this.overDropDown = overDropDown; changed(); }
@Override public void paint( Graphics g ){ BasicDropDownButtonModel model = getModel(); BackgroundPaint paint = model.getBackground(); BackgroundComponent component = model.getBackgroundComponent();
@Override public Dimension getPreferredSize() { if( isPreferredSizeSet() ) return super.getPreferredSize(); Dimension size = content.getPreferredSize(); if( model.getOrientation().isHorizontal() ) return new Dimension( size.width + 6 + dropIcon.getIconWidth(), size.height+2 ); else return new Dimension( size.width+2, size.height + 6 + dropIcon.getIconHeight() ); }
/** * Shows the popup menu */ public void popupTriggered(){ BasicDropDownButtonModel model = getModel(); JComponent button = model.getOwner(); if( model.getOrientation().isHorizontal() ){ menu.show( button, 0, button.getHeight() ); } else{ menu.show( button, button.getWidth(), 0 ); } }
if( model.isMousePressed() ){ border = Colors.diffMirror( background, 0.3 ); background = Colors.undiffMirror( background, 0.8 ); else if( model.isSelected() || model.isMouseInside() ){ border = Colors.diffMirror( background, 0.3 ); background = Colors.undiffMirror( background, 0.4 ); g.drawRoundRect( 0, 0, w, h, 4, 4 ); if( model.isMouseOverDropDown() ){ if( model.getOrientation().isHorizontal() ){ int x = w - drop.getIconWidth() - 5; g.drawLine( x, 0, x, h ); if( model.getOrientation().isHorizontal() ){ drop.paintIcon( this, g, w - drop.getIconWidth() - 2, (h - drop.getIconHeight())/2 );
String postfix = ""; boolean selected = model.isSelected(); boolean enabled = model.isEnabled(); boolean pressed = model.isMousePressed(); boolean entered = model.isMouseInside(); boolean mouseOverDrop = model.isMouseOverDropDown();
private void doPaintBackground( Graphics g ){ Color background = getBackground(); Color border = null; if( model.isMousePressed() ){ border = Colors.diffMirror( background, 0.3 ); background = Colors.undiffMirror( background, 0.8 ); } else if( model.isSelected() || model.isMouseInside() ){ border = Colors.diffMirror( background, 0.3 ); background = Colors.undiffMirror( background, 0.4 ); } int w = getWidth()-1; int h = getHeight()-1; if( border != null ){ g.setColor( background ); g.fillRoundRect( 0, 0, w, h, 4, 4 ); } }
Insets insets = getMaxBorderInsets(); if( getModel().getOrientation().isHorizontal() ){ int iconWidth = getContent().getWidth(); int dropWidth = dropIcon.getIconWidth(); if( getModel().isMouseOverDropDown() ){ border.paintBorder( this, g, 0, 0, (int)(factor * (insets.left + insets.right + iconWidth )), getHeight() ); double factor = getHeight() / sum; if( getModel().isMouseOverDropDown() ){ border.paintBorder( this, g, 0, 0, getWidth(), (int)(factor * (insets.top + insets.bottom + iconHeight )) );
public void triggered(){ BasicDropDownButtonModel model = getModel(); if( model.isMouseOverDropDown() ) popupTriggered(); else{ if( selection == null || !model.isSelectionEnabled() || !selection.getView().isTriggerable( true ) ) popupTriggered(); else{ if( selection.getView().isTriggerable( true ) ){ selection.getView().triggered(); } } } }
public void run(){ if( !model.isMousePressed() ){ requestFocusInWindow(); invokeAfterFocusRequest(); } } });
model.addListener( new BasicButtonModelAdapter(){ @Override public void mousePressed( BasicButtonModel model, boolean mousePressed ){
public void clearIcons(){ getModel().clearIcons(); }
if( model.isMousePressed() ){ border = Colors.diffMirror( background, 0.3 ); background = Colors.undiffMirror( background, 0.8 ); else if( model.isSelected() || model.isMouseInside() ){ border = Colors.diffMirror( background, 0.3 ); background = Colors.undiffMirror( background, 0.4 ); g.drawRoundRect( 0, 0, w, h, 4, 4 ); if( model.isMouseOverDropDown() ){ if( model.getOrientation().isHorizontal() ){ int x = w - drop.getIconWidth() - 5; g.drawLine( x, 0, x, h ); if( model.getOrientation().isHorizontal() ){ drop.paintIcon( this, g, w - drop.getIconWidth() - 2, (h - drop.getIconHeight())/2 );
private void doPaintBackground( Graphics g ){ Color background = getBackground(); Color border = null; if( model.isMousePressed() ){ border = Colors.diffMirror( background, 0.3 ); background = Colors.undiffMirror( background, 0.8 ); } else if( model.isSelected() || model.isMouseInside() ){ border = Colors.diffMirror( background, 0.3 ); background = Colors.undiffMirror( background, 0.4 ); } int w = getWidth()-1; int h = getHeight()-1; if( border != null ){ g.setColor( background ); g.fillRoundRect( 0, 0, w, h, 4, 4 ); } }
Insets insets = getMaxBorderInsets(); if( getModel().getOrientation().isHorizontal() ){ int iconWidth = getContent().getWidth(); int dropWidth = dropIcon.getIconWidth(); if( getModel().isMouseOverDropDown() ){ border.paintBorder( this, g, 0, 0, (int)(factor * (insets.left + insets.right + iconWidth )), getHeight() ); double factor = getHeight() / sum; if( getModel().isMouseOverDropDown() ){ border.paintBorder( this, g, 0, 0, getWidth(), (int)(factor * (insets.top + insets.bottom + iconHeight )) );
public void run(){ if( !model.isMousePressed() ){ requestFocusInWindow(); invokeAfterFocusRequest(); } } });
model.addListener( new BasicButtonModelAdapter(){ @Override public void mousePressed( BasicButtonModel model, boolean mousePressed ){
@Override public Dimension getPreferredSize() { if( isPreferredSizeSet() ) return super.getPreferredSize(); Dimension size = content.getPreferredSize(); if( model.getOrientation().isHorizontal() ) return new Dimension( size.width + 6 + dropIcon.getIconWidth(), size.height+2 ); else return new Dimension( size.width+2, size.height + 6 + dropIcon.getIconHeight() ); }
@Override protected void paintComponent( Graphics g ) { BasicDropDownButtonModel model = getModel(); BackgroundPaint paint = model.getBackground(); BackgroundComponent component = model.getBackgroundComponent();
/** * Sets whether the selected child-action of the represented {@link DropDownAction} * is currently enabled or not. * @param selectionEnabled whether the action is enabled */ public void setSelectionEnabled( boolean selectionEnabled ) { this.selectionEnabled = selectionEnabled; changed(); }