Class CaroselLayout
- java.lang.Object
-
- org.pushingpixels.radiance.theming.extras.internal.contrib.blogofbug.swing.layout.CaroselLayout
-
- All Implemented Interfaces:
java.awt.event.ActionListener
,java.awt.LayoutManager
,java.util.EventListener
- Direct Known Subclasses:
OffsetCaroselLayout
public class CaroselLayout extends java.lang.Object implements java.awt.LayoutManager, java.awt.event.ActionListener
Layout engine for JCarousel components (although would work for any container). It does have a closer than usual relationship with the container, sometimes causing the container to repaint.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static class
CaroselLayout.CaroselPosition
-
Field Summary
Fields Modifier and Type Field Description protected java.util.Hashtable
additionalData
List of additional information held on components in the carouselprivate javax.swing.Timer
animationTimer
Time for driving animationsprotected java.util.LinkedList<java.awt.Component>
components
List of components being laid outprivate java.awt.Container
container
The container the layout is...private boolean
depthBasedAlpha
Should items furtehr away from the observer be faded out?private int
neutralContentWidth
The width of a component when the scale is 1.0protected int
numberOfItems
Number of items in the carousel (that are visible)protected double
rotationalOffset
The current degree of rotation of the carouselprotected double
targetOffset
The desired rotational offset, which will be moved to by a timer animating the carousel
-
Constructor Summary
Constructors Constructor Description CaroselLayout(java.awt.Container forContainer)
Creates a new instance of the layout engine, tied to the specified container.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
actionPerformed(java.awt.event.ActionEvent actionEvent)
Manages timer actions, terminating the timer if any event is fully achievedvoid
addLayoutComponent(java.lang.String name, java.awt.Component comp)
Name is ignoredprotected java.awt.Point
calculateCenter(java.awt.Insets insets, int width, int height, int widest)
Determines the center of the carouselvoid
finalizeLayoutImmediately()
Moves everything to their "target" positions, without animating anythingdouble
getAngle()
Returns the current rotational angleprotected java.awt.Dimension
getCarouselRadius(java.awt.Container target, java.awt.Insets insets, int width, int height, int widestComponent)
Determines the correct size of the carousel for the containerint
getComponentCount()
The number of components being laid out.int
getComponentIndex(java.awt.Component comp)
Gets the index of the supplied componentint
getNeutralContentWidth()
The size of comopnents a neutral widthjava.awt.Component
getNextComponent(java.awt.Component component)
Retrieve the component after the specified one.protected CaroselLayout.CaroselPosition
getPosition(java.awt.Component comp)
Gets the additional data stored by the layout manager for a given componentjava.awt.Component
getPreviousComponent(java.awt.Component component)
Retrieve the component before the specified one.protected double
getScale(double angle, double x, double y, double carouselX, double carouselY)
Determines the scale to be applied to the component.protected boolean
isAnimating()
Determines if an animation is currently playingvoid
layoutContainer(java.awt.Container target)
Lays out all of the components on the carosel.java.awt.Dimension
minimumLayoutSize(java.awt.Container parent)
Cheats and bases it's size on the prefered sizes of each componentvoid
moveComponentTo(int i, java.awt.Component comp)
Moves a layout component at a particular location in the carouseljava.awt.Dimension
preferredLayoutSize(java.awt.Container parent)
Determine the widest and tallest dimensions, then return the height as 1.5 * the highest, and 3 * the widestprotected void
recalculateCarosel()
Updates all of the positions of the carousel.protected int
recalculateVisibleItems()
Determines how many of the items being laid out are currently visible.void
removeLayoutComponent(java.awt.Component comp)
Remove the componentvoid
setAngle(double d)
Sets the current rotational angle.void
setDepthBasedAlpha(boolean depthBasedAlpha)
Controls if items should fade as they move to the back of the carouselvoid
setFrontMostComponent(java.awt.Component component)
Moves the specified component to the frontvoid
setNeutralContentWidth(int neutralContentWidth)
Specify the neutral content width of any laid out component.protected void
setTarget(double target)
Sets a target angle to rotate to, always choses a direction that is less than or equal to 180 degreesprotected boolean
shouldHide(java.awt.Component comp, double angle, double s)
Can be over-ridden to restrict the range of angles where the child component is shown
-
-
-
Field Detail
-
numberOfItems
protected int numberOfItems
Number of items in the carousel (that are visible)
-
components
protected java.util.LinkedList<java.awt.Component> components
List of components being laid out
-
additionalData
protected java.util.Hashtable additionalData
List of additional information held on components in the carousel
-
rotationalOffset
protected double rotationalOffset
The current degree of rotation of the carousel
-
targetOffset
protected double targetOffset
The desired rotational offset, which will be moved to by a timer animating the carousel
-
animationTimer
private javax.swing.Timer animationTimer
Time for driving animations
-
container
private java.awt.Container container
The container the layout is... laying out
-
depthBasedAlpha
private boolean depthBasedAlpha
Should items furtehr away from the observer be faded out?
-
neutralContentWidth
private int neutralContentWidth
The width of a component when the scale is 1.0
-
-
Method Detail
-
setNeutralContentWidth
public void setNeutralContentWidth(int neutralContentWidth)
Specify the neutral content width of any laid out component.- Parameters:
neutralContentWidth
- The neutral width of components
-
moveComponentTo
public void moveComponentTo(int i, java.awt.Component comp)
Moves a layout component at a particular location in the carousel- Parameters:
i
- The location at which to insertcomp
- The component to insert
-
addLayoutComponent
public void addLayoutComponent(java.lang.String name, java.awt.Component comp)
Name is ignored- Specified by:
addLayoutComponent
in interfacejava.awt.LayoutManager
- Parameters:
name
- The name of the component, ignored.comp
- The component being added
-
removeLayoutComponent
public void removeLayoutComponent(java.awt.Component comp)
Remove the component- Specified by:
removeLayoutComponent
in interfacejava.awt.LayoutManager
- Parameters:
comp
- The component being removed
-
getPosition
protected CaroselLayout.CaroselPosition getPosition(java.awt.Component comp)
Gets the additional data stored by the layout manager for a given component- Parameters:
comp
- The component you wish retreive the data for- Returns:
- A position, which is added if it does not already exist. Never null unless you run out of memory!
-
recalculateVisibleItems
protected int recalculateVisibleItems()
Determines how many of the items being laid out are currently visible.- Returns:
- How many of the items in the carousel are currently visible.
-
recalculateCarosel
protected void recalculateCarosel()
Updates all of the positions of the carousel. Does not do a repaint, just does the math ready for the next one.
-
minimumLayoutSize
public java.awt.Dimension minimumLayoutSize(java.awt.Container parent)
Cheats and bases it's size on the prefered sizes of each component- Specified by:
minimumLayoutSize
in interfacejava.awt.LayoutManager
- Parameters:
parent
- The container interested in the layout size- Returns:
- The minimum size of the layout. See above.
-
preferredLayoutSize
public java.awt.Dimension preferredLayoutSize(java.awt.Container parent)
Determine the widest and tallest dimensions, then return the height as 1.5 * the highest, and 3 * the widest- Specified by:
preferredLayoutSize
in interfacejava.awt.LayoutManager
- Parameters:
parent
- The container for the layout- Returns:
- The prefered size of the layout
-
calculateCenter
protected java.awt.Point calculateCenter(java.awt.Insets insets, int width, int height, int widest)
Determines the center of the carousel- Parameters:
insets
- The insets of the containerwidth
- The width of the containerheight
- The height of the containerwidest
- The widest component- Returns:
- A point at the center of the carousel
-
setDepthBasedAlpha
public void setDepthBasedAlpha(boolean depthBasedAlpha)
Controls if items should fade as they move to the back of the carousel- Parameters:
depthBasedAlpha
- True if they should fade, false if they shouldn't
-
shouldHide
protected boolean shouldHide(java.awt.Component comp, double angle, double s)
Can be over-ridden to restrict the range of angles where the child component is shown- Parameters:
comp
- Controls if components are hidden or not, in the case of this layout it always returns falseangle
- The angle of the component under considerations
- The scale of the component under consideration- Returns:
- false if the component should not be shown
-
getCarouselRadius
protected java.awt.Dimension getCarouselRadius(java.awt.Container target, java.awt.Insets insets, int width, int height, int widestComponent)
Determines the correct size of the carousel for the container- Parameters:
target
- The target containerinsets
- Insets into the target containerwidth
- Width of the target containerheight
- Height of the target containerwidestComponent
- The widest component in the container- Returns:
- The
-
getScale
protected double getScale(double angle, double x, double y, double carouselX, double carouselY)
Determines the scale to be applied to the component. The default calculation divides the y co-ordinate by the y-cordinate of the centre. Other implimentations may use some of the other parameters- Parameters:
angle
- The angle of the componentx
- The x-position of the componenty
- The y-position of the componentcarouselX
- The x centre of the carouselcarouselY
- The y centre of the carousel- Returns:
- A double which will be used to scale x and y co-ordinates
-
layoutContainer
public void layoutContainer(java.awt.Container target)
Lays out all of the components on the carosel. Using the preferred width and height to base scaling on- Specified by:
layoutContainer
in interfacejava.awt.LayoutManager
- Parameters:
target
- The container currently being laid out
-
getAngle
public double getAngle()
Returns the current rotational angle- Returns:
- The current rotated angle in radians
-
setAngle
public void setAngle(double d)
Sets the current rotational angle. Will not cause an animation to start- Parameters:
d
- The desired angle in radians
-
isAnimating
protected boolean isAnimating()
Determines if an animation is currently playing- Returns:
- true if it is animating, false if it isn't
-
actionPerformed
public void actionPerformed(java.awt.event.ActionEvent actionEvent)
Manages timer actions, terminating the timer if any event is fully achieved- Specified by:
actionPerformed
in interfacejava.awt.event.ActionListener
- Parameters:
actionEvent
- the action event, although this will always be the timer
-
finalizeLayoutImmediately
public void finalizeLayoutImmediately()
Moves everything to their "target" positions, without animating anything
-
setTarget
protected final void setTarget(double target)
Sets a target angle to rotate to, always choses a direction that is less than or equal to 180 degrees- Parameters:
target
- The target angle in radians
-
setFrontMostComponent
public void setFrontMostComponent(java.awt.Component component)
Moves the specified component to the front- Parameters:
component
- The component move to the front
-
getPreviousComponent
public java.awt.Component getPreviousComponent(java.awt.Component component)
Retrieve the component before the specified one. It does not filter out invisible ones.- Parameters:
component
- The component you are looking for the one before for.- Returns:
- The component before it
-
getNextComponent
public java.awt.Component getNextComponent(java.awt.Component component)
Retrieve the component after the specified one. It does not filter out invisible ones.- Parameters:
component
- The component- Returns:
- The one after it
-
getComponentCount
public int getComponentCount()
The number of components being laid out. Does not included hidden ones- Returns:
- The number of components
-
getComponentIndex
public int getComponentIndex(java.awt.Component comp)
Gets the index of the supplied component- Parameters:
comp
- The component- Returns:
- The index
-
getNeutralContentWidth
public int getNeutralContentWidth()
The size of comopnents a neutral width- Returns:
- The size of components at neutral width (scale 1.0)
-
-