Solstice::IconService - Gives access to a library of icons.


Solstice documentation Contained in the Solstice distribution.

Index


Code Index:

NAME

Top

Solstice::IconService - Gives access to a library of icons.

SYNOPSIS

Top

  use Solstice::IconService;

DESCRIPTION

Top

Superclass

Solstice::Service

Export

No symbols exported.

Methods

new([\%params])

Creates a new Solstice::IconService object.

setSize($int)

Set the size attribute, in pixels. Available values are 16, 20 and 32.

getSize()

Return the size attribute.

setLocked($bool)

Set the locked boolean attribute. Specifies a "locked" version of the icon if set.

getLocked()

Return the locked attribute.

setColor($string)
getColor()
getIconByType($type) {

Return the icon path for the passed file content-type. Returns the path for a generic icon if the type is unknown.

getIconByName($name)

Return an icon path for the passed icon name.

getIconByAction($name)

Return an icon path for the passed icon name.

Private Methods

_getObjectIconPath($icon)

Return a file path for an icon file.

_getActionIconPath($icon)

Return a file path for an icon file.

_getClassName()

Return the class name. Overridden to avoid a ref() in the superclass.

Modules Used

Solstice::Service.

AUTHOR

Top

Catalyst Group, <catalyst@u.washington.edu>

VERSION

Top

$Revision: 3364 $

COPYRIGHT

Top


Solstice documentation Contained in the Solstice distribution.
package Solstice::IconService;

# $Id: IconService.pm 3364 2006-05-05 07:18:21Z mcrawfor $

use 5.006_000;
use strict;
use warnings;

use base qw(Solstice::Service);

use constant OBJECT_IMAGES => 'images/icons/';
use constant ACTION_IMAGES => 'images/actions/';
use constant EXTENSION     => '.gif';
use constant DEFAULT_COLOR => 'blue';

our ($VERSION) = ('$Revision: 3364 $' =~ /^\$Revision:\s*([\d.]*)/);

sub new {
    my $class = shift;
    my $params = shift;
    
    my $self = $class->SUPER::new(@_);
    
    if (defined $params) {
        $self->setSize($params->{'size'});
        $self->setLocked($params->{'locked'});
        $self->setColor($params->{'color'});
    }
    
    return $self;
}

sub setSize {
    my $self = shift;
    my $size = shift;
    $self->set('size', $size);
}

sub getSize {
    my $self = shift;
    return $self->get('size');
}

sub setLocked {
    my $self = shift;
    my $locked = shift;
    $self->set('locked', $locked);
}

sub getLocked {
    my $self = shift;
    return $self->get('locked');
}

sub setColor {
    my $self = shift;
    my $color = shift;
    $self->set('color', $color);
}

sub getColor {
    my $self = shift;
    return $self->get('color');
}

sub getIconByType {
    my $self = shift;
    my $type = shift;
    
    return undef unless defined $type;

    my $size = $self->getSize() || 16;

    return OBJECT_IMAGES .
        ($size < 17 ? '16/' : '32/') .
        ($self->getLocked() ? 'locked/' : 'unlocked/') .
        $self->getContentTypeService()->getIconByContentType($type);
}    

sub getIconByName {
    my $self = shift;
    my $name = shift;

    return undef unless defined $name;
    
    return $self->_getObjectIconPath($name);
}

sub getIconByAction {
    my $self = shift;
    my $name = shift;

    return undef unless defined $name;
    
    return $self->_getActionIconPath($name);
}

sub _getObjectIconPath {
    my $self = shift;
    my $icon = shift;

    my $size   = $self->getSize() || 16;
    my $locked = $self->getLocked();

    return OBJECT_IMAGES . 
        ($size < 17 ? '16/'     : '32/') .
        ($locked    ? 'locked/' : 'unlocked/') .
        $icon . EXTENSION;
}

sub _getActionIconPath {
    my $self = shift;
    my $icon = shift;

    my $size  = $self->getSize()  || 20;

    return ACTION_IMAGES .
        $size . '/' .
        ($self->getColor || DEFAULT_COLOR) . '/' .
        $icon . EXTENSION;
}

sub _getClassName {
    return 'Solstice::IconService';
}


1;
__END__