public class CaroselLayout
extends java.lang.Object
implements java.awt.LayoutManager, java.awt.event.ActionListener
Modifier and Type | Field and Description |
---|---|
protected java.util.Hashtable |
additionalData
List of additional information held on components in the carousel
|
protected java.util.LinkedList<java.awt.Component> |
components
List of components being laid out
|
protected int |
numberOfItems
Number of items in the carousel (that are visible)
|
protected double |
rotationalOffset
The current degree of rotation of the carousel
|
protected double |
targetOffset
The desired rotational offset, which will be moved to by a timer animating the carousel
|
Constructor and Description |
---|
CaroselLayout(java.awt.Container forContainer)
Creates a new instance of the layout engine, tied to the specified container.
|
Modifier and Type | Method and Description |
---|---|
void |
actionPerformed(java.awt.event.ActionEvent actionEvent)
Manages timer actions, terminating the timer if any event is fully achieved
|
void |
addLayoutComponent(java.lang.String name,
java.awt.Component comp)
Name is ignored
|
protected java.awt.Point |
calculateCenter(java.awt.Insets insets,
int width,
int height,
int widest)
Determines the center of the carousel
|
void |
finalizeLayoutImmediately()
Moves everything to their "target" positions, without animating anything
|
double |
getAngle()
Returns the current rotational angle
|
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
|
int |
getComponentCount()
The number of components being laid out.
|
int |
getComponentIndex(java.awt.Component comp)
Gets the index of the supplied component
|
int |
getNeutralContentWidth()
The size of comopnents a neutral width
|
java.awt.Component |
getNextComponent(java.awt.Component component)
Retrieve the component after the specified one.
|
protected contrib.com.blogofbug.swing.layout.CaroselLayout.CaroselPosition |
getPosition(java.awt.Component comp)
Gets the additional data stored by the layout manager for a given component
|
java.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 playing
|
void |
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 component
|
void |
moveComponentTo(int i,
java.awt.Component comp)
Moves a layout component at a particular location in the
carousel
|
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
|
protected 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 component
|
void |
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 carousel
|
void |
setFrontMostComponent(java.awt.Component component)
Moves the specified component to the front
|
void |
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 degrees
|
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
|
protected int numberOfItems
protected java.util.LinkedList<java.awt.Component> components
protected java.util.Hashtable additionalData
protected double rotationalOffset
protected double targetOffset
public CaroselLayout(java.awt.Container forContainer)
forContainer
- The container the layout will layoutpublic void setNeutralContentWidth(int neutralContentWidth)
neutralContentWidth
- The neutral width of componentspublic void moveComponentTo(int i, java.awt.Component comp)
i
- The location at which to insertcomp
- The component to insertpublic void addLayoutComponent(java.lang.String name, java.awt.Component comp)
addLayoutComponent
in interface java.awt.LayoutManager
name
- The name of the component, ignored.comp
- The component being addedpublic void removeLayoutComponent(java.awt.Component comp)
removeLayoutComponent
in interface java.awt.LayoutManager
comp
- The component being removedprotected contrib.com.blogofbug.swing.layout.CaroselLayout.CaroselPosition getPosition(java.awt.Component comp)
comp
- The component you wish retreive the data forprotected int recalculateVisibleItems()
protected void recalculateCarosel()
public java.awt.Dimension minimumLayoutSize(java.awt.Container parent)
minimumLayoutSize
in interface java.awt.LayoutManager
parent
- The container interested in the layout sizepublic java.awt.Dimension preferredLayoutSize(java.awt.Container parent)
preferredLayoutSize
in interface java.awt.LayoutManager
parent
- The container for the layoutprotected java.awt.Point calculateCenter(java.awt.Insets insets, int width, int height, int widest)
insets
- The insets of the containerwidth
- The width of the containerheight
- The height of the containerwidest
- The widest componentpublic void setDepthBasedAlpha(boolean depthBasedAlpha)
depthBasedAlpha
- True if they should fade, false if they shouldn'tprotected boolean shouldHide(java.awt.Component comp, double angle, double s)
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 considerationprotected java.awt.Dimension getCarouselRadius(java.awt.Container target, java.awt.Insets insets, int width, int height, int widestComponent)
target
- The target containerinsets
- Insets into the target containerwidth
- Width of the target containerheight
- Height of the target containerwidestComponent
- The widest component in the containerprotected double getScale(double angle, double x, double y, double carouselX, double carouselY)
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 carouselpublic void layoutContainer(java.awt.Container target)
layoutContainer
in interface java.awt.LayoutManager
target
- The container currently being laid outpublic double getAngle()
public void setAngle(double d)
d
- The desired angle in radiansprotected boolean isAnimating()
public void actionPerformed(java.awt.event.ActionEvent actionEvent)
actionPerformed
in interface java.awt.event.ActionListener
actionEvent
- the action event, although this will always be the timerpublic void finalizeLayoutImmediately()
protected final void setTarget(double target)
target
- The target angle in radianspublic void setFrontMostComponent(java.awt.Component component)
component
- The component move to the frontpublic java.awt.Component getPreviousComponent(java.awt.Component component)
component
- The component you are looking for the one before for.public java.awt.Component getNextComponent(java.awt.Component component)
component
- The componentpublic int getComponentCount()
public int getComponentIndex(java.awt.Component comp)
comp
- The componentpublic int getNeutralContentWidth()