Skip to content

Commit

Permalink
CollapsiblePane [ #552 ]
Browse files Browse the repository at this point in the history
- CollapsiblePanePainter.java - Added `expanded`, `expanding`, `collapsed` and `collapsing` states support for style
- AbstractHeaderPanel.java, AbstractTitleLabel.java, AbstractControlButton.java - Added `expanding` and `collapsing` states support for style
- collapsiblepane.xml - Simplified default style

Accordion [ #552 ]
- AccordionPane.java - Added `expanded`, `expanding`, `collapsed` and `collapsing` states support for style

Styling
- AbstractDecorationPainter.java - Minor code optimizations and refactoring
- DecorationState.java - Added `expanding` and `collapsing` default states
  • Loading branch information
mgarin committed Oct 1, 2019
1 parent 0bfecd5 commit a9e255b
Show file tree
Hide file tree
Showing 12 changed files with 195 additions and 62 deletions.
25 changes: 24 additions & 1 deletion modules/ui/src/com/alee/extended/accordion/AccordionPane.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,17 @@
import com.alee.extended.collapsible.HeaderLayout;
import com.alee.laf.panel.WebPanel;
import com.alee.managers.style.StyleId;
import com.alee.painter.decoration.DecorationState;
import com.alee.painter.decoration.Stateful;
import com.alee.utils.SwingUtils;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.InputEvent;
import java.awt.event.MouseEvent;
import java.util.ArrayList;
import java.util.List;

/**
* {@link AccordionPane} for a single collapsible content {@link Component} within {@link WebAccordion}.
Expand All @@ -46,7 +50,7 @@
* @see AccordionModel
* @see WebAccordionModel
*/
public class AccordionPane extends WebPanel implements Identifiable
public class AccordionPane extends WebPanel implements Stateful, Identifiable
{
/**
* {@link AccordionPane} unique identifier.
Expand Down Expand Up @@ -143,6 +147,25 @@ public String getId ()
return id;
}

@Nullable
@Override
public List<String> getStates ()
{
final List<String> states = new ArrayList<String> ( 3 );

// Header position state
states.add ( getHeaderPosition ().name () );

// Expansion state
states.add ( isExpanded () || isInTransition () ? DecorationState.expanded : DecorationState.collapsed );
if ( isInTransition () )
{
states.add ( isExpanded () ? DecorationState.expanding : DecorationState.collapsing );
}

return states;
}

/**
* Returns header {@link JComponent}.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,20 +175,15 @@ protected void updateDecorationStates ()
*/
protected void updateDecorationStates ( @NotNull final AccordionPane pane )
{
// Updating pane decoration states
DecorationUtils.fireStatesChanged ( pane );

// Updating pane header decoration states
final Component header = pane.getHeader ();
DecorationUtils.fireStatesChanged ( header );

// Updating pane header contents decoration states
if ( header instanceof AbstractHeaderPanel )
{
final AbstractHeaderPanel headerPanel = ( AbstractHeaderPanel ) header;
DecorationUtils.fireStatesChanged ( headerPanel.getTitle () );
DecorationUtils.fireStatesChanged ( headerPanel.getControl () );
}
DecorationUtils.fireStatesChanged ( header );
DecorationUtils.fireStatesChanged ( pane );
}

@NotNull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@ public List<String> getStates ()

// Expansion state
states.add ( isExpanded () || isInTransition () ? DecorationState.expanded : DecorationState.collapsed );
if ( isInTransition () )
{
states.add ( isExpanded () ? DecorationState.expanding : DecorationState.collapsing );
}

return states;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,10 @@ public List<String> getStates ()

// Expansion state
states.add ( isExpanded () || isInTransition () ? DecorationState.expanded : DecorationState.collapsed );
if ( isInTransition () )
{
states.add ( isExpanded () ? DecorationState.expanding : DecorationState.collapsing );
}

return states;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@ public List<String> getStates ()

// Expansion state
states.add ( isExpanded () || isInTransition () ? DecorationState.expanded : DecorationState.collapsed );
if ( isInTransition () )
{
states.add ( isExpanded () ? DecorationState.expanding : DecorationState.collapsing );
}

// Icon state
if ( getIcon () != null )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,14 @@

package com.alee.extended.collapsible;

import com.alee.api.annotations.NotNull;
import com.alee.painter.decoration.AbstractDecorationPainter;
import com.alee.painter.decoration.DecorationState;
import com.alee.painter.decoration.DecorationUtils;
import com.alee.painter.decoration.IDecoration;

import java.util.List;

/**
* Basic painter for {@link WebCollapsiblePane} component.
* It is used as {@link WCollapsiblePaneUI} default painter.
Expand All @@ -35,6 +40,83 @@ public class CollapsiblePanePainter<C extends WebCollapsiblePane, U extends WCol
extends AbstractDecorationPainter<C, U, D> implements ICollapsiblePanePainter<C, U>
{
/**
* Implementation is used completely from {@link AbstractDecorationPainter}.
* Listeners.
*/
protected transient CollapsiblePaneListener collapsiblePaneListener;

@Override
protected void installPropertiesAndListeners ()
{
super.installPropertiesAndListeners ();
installCollapsiblePaneListener ();
}

@Override
protected void uninstallPropertiesAndListeners ()
{
uninstallCollapsiblePaneListener ();
super.uninstallPropertiesAndListeners ();
}

/**
* Installs {@link CollapsiblePaneListener}.
*/
protected void installCollapsiblePaneListener ()
{
collapsiblePaneListener = new CollapsiblePaneListener ()
{
@Override
public void expanding ( @NotNull final WebCollapsiblePane pane )
{
DecorationUtils.fireStatesChanged ( pane );
}

@Override
public void expanded ( @NotNull final WebCollapsiblePane pane )
{
DecorationUtils.fireStatesChanged ( pane );
}

@Override
public void collapsing ( @NotNull final WebCollapsiblePane pane )
{
DecorationUtils.fireStatesChanged ( pane );
}

@Override
public void collapsed ( @NotNull final WebCollapsiblePane pane )
{
DecorationUtils.fireStatesChanged ( pane );
}
};
component.addCollapsiblePaneListener ( collapsiblePaneListener );
}

/**
* Uninstalls {@link CollapsiblePaneListener}.
*/
protected void uninstallCollapsiblePaneListener ()
{
component.removeCollapsiblePaneListener ( collapsiblePaneListener );
collapsiblePaneListener = null;
}

@NotNull
@Override
public List<String> getDecorationStates ()
{
final List<String> states = super.getDecorationStates ();

// Header position state
states.add ( component.getHeaderPosition ().name () );

// Expansion state
states.add ( component.isExpanded () || component.isInTransition () ? DecorationState.expanded : DecorationState.collapsed );
if ( component.isInTransition () )
{
states.add ( component.isExpanded () ? DecorationState.expanding : DecorationState.collapsing );
}

return states;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

package com.alee.laf.scroll.layout;

import com.alee.api.annotations.Nullable;
import com.alee.api.merge.Mergeable;
import com.thoughtworks.xstream.annotations.XStreamAlias;
import com.thoughtworks.xstream.annotations.XStreamAsAttribute;
Expand All @@ -37,6 +38,7 @@ public class ScrollBarSettings implements Mergeable, Cloneable, Serializable
* Exact corner taken by the scroll bar depends on the scroll bar orientation.
* This setting is set to {@code false} by default to replicate common Swing scroll panes behavior.
*/
@Nullable
@XStreamAsAttribute
protected Boolean leading;

Expand All @@ -45,6 +47,7 @@ public class ScrollBarSettings implements Mergeable, Cloneable, Serializable
* Exact corner taken by the scroll bar depends on the scroll bar orientation.
* This setting is set to {@code false} by default to replicate common Swing scroll panes behavior.
*/
@Nullable
@XStreamAsAttribute
protected Boolean trailing;

Expand All @@ -55,13 +58,15 @@ public class ScrollBarSettings implements Mergeable, Cloneable, Serializable
* It is important to know that hovering non-opaque scroll bar also forces underlying components to be non-opaque,
* otherwise you will encounter many repainting issues with the content and scroll bar itself.
*/
@Nullable
@XStreamAsAttribute
protected Boolean hovering;

/**
* Whether or not scroll bar should be counted in scroll pane preferred size when it is {@link #hovering}.
* It could be useful to receive a better scroll pane preferred size to avoid scroll bar obstructing any content.
*/
@Nullable
@XStreamAsAttribute
protected Boolean extending;

Expand All @@ -81,9 +86,9 @@ public ScrollBarSettings ()
* @param hovering whether scroll bar should hover above the scroll pane content instead of taking extra space
* @param extending whether or not scroll bar should be counted in scroll pane preferred size
*/
public ScrollBarSettings ( final Boolean leading, final Boolean trailing, final Boolean hovering, final Boolean extending )
public ScrollBarSettings ( @Nullable final Boolean leading, @Nullable final Boolean trailing,
@Nullable final Boolean hovering, @Nullable final Boolean extending )
{
super ();
this.leading = leading;
this.trailing = trailing;
this.hovering = hovering;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public void prepareToPaint ( final JTree.DropLocation location )
}

@Override
protected boolean isDecorationAvailable ( final D decoration )
protected boolean isDecorationAvailable ( @NotNull final D decoration )
{
// We don't need to paint anything when drop location is not available
return location != null && super.isDecorationAvailable ( decoration );
Expand Down
Loading

0 comments on commit a9e255b

Please sign in to comment.