de.lessvoid.nifty
Class Nifty

java.lang.Object
  extended by de.lessvoid.nifty.Nifty

public class Nifty
extends Object

The main Nifty class.

Author:
void

Nested Class Summary
 class Nifty.ClosePopUp
           
 class Nifty.ElementMoveAction
           
 class Nifty.ElementRemoveAction
           
 
Constructor Summary
Nifty(RenderDevice newRenderDevice, SoundDevice newSoundDevice, InputSystem newInputSystem, TimeProvider newTimeProvider)
          Create nifty with optional console parameter.
 
Method Summary
 void addControl(Screen screen, Element element, StandardControl standardControl)
           
 void addControls()
           
 void addControlsWithoutStartScreen()
           
 void addResourceBundle(String id, String filename)
           
 void addScreen(String id, Screen screen)
           
 void addXml(InputStream stream)
          Load an additional xml from a stream without removing any of the data that might already been loaded.
 void addXml(String filename)
          Load an additional xml file without removing any of the data that might already been loaded.
 void closePopup(String id)
          Close the Popup with the given id.
 void closePopup(String id, EndNotify closeNotify)
          Close the Popup with the given id.
 Element createElementFromType(Screen screen, Element parent, ElementType type)
           
 RenderFont createFont(String name)
           
 NiftyImage createImage(String name, boolean filterLinear)
          Create a new Image.
 Element createPopup(String popupId)
           
 Element createPopupWithId(String popupId, String id)
           
 Element createPopupWithStyle(String popupId, String style)
           
 Element createPopupWithStyle(String popupId, String style, Attributes parameters)
           
 Element createPopupWithStyle(String popupId, String id, String style)
           
 void delayedMethodInvoke(NiftyDelayedMethodInvoke method, Object[] params)
           
 void disableAutoScaling()
           
 void enableAutoScaling(int baseResolutionX, int baseResolutionY)
          Enable automatic scaling of all GUI elements in relation to the given base resolution.
 void enableAutoScaling(int baseResolutionX, int baseResolutionY, float scaleX, float scaleY)
           
 void executeEndOfFrameElementActions()
           
 void exit()
          exit.
 Element findPopupByName(String id)
           
 ScreenController findScreenController(String controllerClass)
          find a ScreenController instance that matches the given controllerClass name.
 void fromXml(String fileId, InputStream input, String startScreen)
          fromXml.
 void fromXml(String fileId, InputStream input, String startScreen, ScreenController... controllers)
          fromXml with ScreenControllers.
 void fromXml(String filename, String startScreen)
          Initialize this Nifty instance from the given xml file.
 void fromXml(String filename, String startScreen, ScreenController... controllers)
          Initialize this Nifty instance from the given xml file.
 void fromXmlWithoutStartScreen(String filename)
          Initialize this Nifty instance from the given xml file.
 void fromXmlWithoutStartScreen(String fileId, InputStream input)
          fromXmlWithoutStartScreen.
 Collection<String> getAllScreensName()
          Returns a collection of the name of all screens
 Collection<String> getAllStylesName()
          This returns all the style names currently registed with nifty.
 String getAlternateKey()
           
 Clipboard getClipboard()
           
 Screen getCurrentScreen()
          Get current screen.
 StyleResolver getDefaultStyleResolver()
           
 org.bushe.swing.event.EventService getEventService()
           
 String getFontname(RenderFont font)
           
 Properties getGlobalProperties()
           
 NiftyLoader getLoader()
           
 MouseInputEventProcessor getMouseInputEventQueue()
           
 NiftyMouse getNiftyMouse()
           
 NiftyRenderEngine getRenderEngine()
          Return the RenderDevice.
 InputStream getResourceAsStream(String ref)
          Return an InputStream for the given resource name.
 Map<String,ResourceBundle> getResourceBundles()
           
 NiftyResourceLoader getResourceLoader()
          Return the ResourceLoader of this Nifty instance.
 RootLayerFactory getRootLayerFactory()
           
 Screen getScreen(String id)
          get a specific screen.
 SoundSystem getSoundSystem()
          Get the SoundSystem.
 TimeProvider getTimeProvider()
           
 Element getTopMostPopup()
           
 void gotoScreen(String id)
          goto screen command. this will send first an endScreen event to the current screen.
 void invokeMethods()
           
 boolean isActive(String filename, String screenId)
          Check if nifty displays the file with the given filename and is at a screen with the given screenId.
 boolean isDebugOptionPanelColors()
          Returns true if the debug option to render panel colors in enabled.
 void loadControlFile(String controlFile)
           
 void loadStyleFile(String styleFile)
           
 void moveElement(Screen screen, Element elementToMove, Element destination, EndNotify endNotify)
           
 void publishEvent(String id, NiftyEvent event)
           
 void registerControlDefintion(ControlDefinitionType controlDefintion)
           
 void registerEffect(RegisterEffectType registerEffectType)
           
 void registerEffect(String name, String classParam)
           
 void registerMouseCursor(String id, String filename, int hotspotX, int hotspotY)
           
 void registerMusic(String id, String filename)
           
 void registerPopup(PopupType popup)
          popup.
 void registerResourceBundle(String id, String filename)
           
 void registerScreenController(ScreenController... controllers)
          Register a ScreenController instance.
 void registerSound(String id, String filename)
           
 void registerStyle(StyleType style)
           
 void removeElement(Screen screen, Element element)
           
 void removeElement(Screen screen, Element element, EndNotify endNotify)
           
 void removeScreen(String id)
           
 void render(boolean clearScreen)
          Render Nifty.
 void resetMouseInputEvents()
           
 void resolutionChanged()
           
 ControlDefinitionType resolveControlDefinition(String name)
           
 RegisterEffectType resolveRegisteredEffect(String name)
           
 void setAlternateKey(String alternateKey)
          Set alternate key for all screen.
 void setAlternateKeyForNextLoadXml(String alternateKeyForNextLoadXmlParam)
           
 void setClipboard(Clipboard clipboard)
           
 void setDebugOptionPanelColors(boolean option)
          You can set this option to true to let Nifty automatically render all panels in random background colors for debugging purposes.
 void setGlobalProperties(Properties globalProperties)
           
 void setLocale(Locale locale)
           
 void showPopup(Screen screen, String id, Element defaultFocusElement)
          show popup in the given screen.
 String specialValuesReplace(String value)
          A helper method to call the special values replace method ${} syntax
<T,S extends org.bushe.swing.event.EventTopicSubscriber<? extends T>>
void
subscribe(Screen screen, String elementId, Class<T> eventClass, S subscriber)
           
 void subscribeAnnotations(Object object)
           
 void unsubscribe(String elementId, Object object)
           
 void unsubscribeAnnotations(Object object)
           
 void unsubscribeElement(Screen screen, String elementId)
           
 void unsubscribeScreen(Screen screen)
           
 boolean update()
          Update Nifty.
 void validateXml(InputStream stream)
          Load and validate the given stream.
 void validateXml(String filename)
          Load and validate the given filename.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Nifty

public Nifty(RenderDevice newRenderDevice,
             SoundDevice newSoundDevice,
             InputSystem newInputSystem,
             TimeProvider newTimeProvider)
Create nifty with optional console parameter.

Parameters:
newRenderDevice - the RenderDevice
newSoundSystem - SoundSystem
newInputSystem - InputSystem
newTimeProvider - the TimeProvider
Method Detail

getEventService

public org.bushe.swing.event.EventService getEventService()

publishEvent

public void publishEvent(String id,
                         NiftyEvent event)

subscribeAnnotations

public void subscribeAnnotations(Object object)

unsubscribeAnnotations

public void unsubscribeAnnotations(Object object)

subscribe

public <T,S extends org.bushe.swing.event.EventTopicSubscriber<? extends T>> void subscribe(Screen screen,
                                                                                            String elementId,
                                                                                            Class<T> eventClass,
                                                                                            S subscriber)

unsubscribe

public void unsubscribe(String elementId,
                        Object object)

unsubscribeScreen

public void unsubscribeScreen(Screen screen)

unsubscribeElement

public void unsubscribeElement(Screen screen,
                               String elementId)

setAlternateKeyForNextLoadXml

public void setAlternateKeyForNextLoadXml(String alternateKeyForNextLoadXmlParam)

update

public boolean update()
Update Nifty.

Returns:
true when nifty has finished processing the screen and false when rendering should continue.

render

public void render(boolean clearScreen)
Render Nifty.

Parameters:
clearScreen - true if nifty should clean the screen and false when you've done that already.

resetMouseInputEvents

public void resetMouseInputEvents()

addControls

public void addControls()

addControlsWithoutStartScreen

public void addControlsWithoutStartScreen()

executeEndOfFrameElementActions

public void executeEndOfFrameElementActions()

fromXml

public void fromXml(String filename,
                    String startScreen)
Initialize this Nifty instance from the given xml file.

Parameters:
filename - filename to nifty xml
startScreen - screen to start exec

fromXmlWithoutStartScreen

public void fromXmlWithoutStartScreen(String filename)
Initialize this Nifty instance from the given xml file.

Parameters:
filename - filename to nifty xml

fromXml

public void fromXml(String filename,
                    String startScreen,
                    ScreenController... controllers)
Initialize this Nifty instance from the given xml file.

Parameters:
filename - filename to nifty xml
startScreen - screen to start exec
controllers - controllers to use

fromXml

public void fromXml(String fileId,
                    InputStream input,
                    String startScreen)
fromXml.

Parameters:
fileId - fileId
input - inputStream
startScreen - screen to start

fromXmlWithoutStartScreen

public void fromXmlWithoutStartScreen(String fileId,
                                      InputStream input)
fromXmlWithoutStartScreen.

Parameters:
fileId - fileId
input - inputStream

fromXml

public void fromXml(String fileId,
                    InputStream input,
                    String startScreen,
                    ScreenController... controllers)
fromXml with ScreenControllers.

Parameters:
fileId - fileId
input - inputStream
startScreen - screen to start
controllers - controllers to use

addXml

public void addXml(String filename)
Load an additional xml file without removing any of the data that might already been loaded.

Parameters:
filename - the file to load

addXml

public void addXml(InputStream stream)
Load an additional xml from a stream without removing any of the data that might already been loaded.

Parameters:
stream - the stream to load

validateXml

public void validateXml(String filename)
                 throws Exception
Load and validate the given filename. If the file is valid, nothing happens. If it is invalid you'll get an exception explaining the error.

Parameters:
filename - filename to check
Throws:
Exception - exception describing the error

validateXml

public void validateXml(InputStream stream)
                 throws Exception
Load and validate the given stream. If the stream is valid, nothing happens. If it is invalid you'll get an exception explaining the error.

Parameters:
filename - filename to check
Throws:
Exception - exception describing the error

gotoScreen

public void gotoScreen(String id)
goto screen command. this will send first an endScreen event to the current screen.

Parameters:
id - the new screen id we should go to.

setAlternateKey

public void setAlternateKey(String alternateKey)
Set alternate key for all screen. This could be used to change behavior on all screens.

Parameters:
alternateKey - the new alternate key to use

getAllScreensName

public Collection<String> getAllScreensName()
Returns a collection of the name of all screens

Returns:
sn The collection containing the name of all screens

removeScreen

public void removeScreen(String id)

getAllStylesName

public Collection<String> getAllStylesName()
This returns all the style names currently registed with nifty.

Returns:
Collection of all style names

exit

public void exit()
exit.


resolutionChanged

public void resolutionChanged()

getScreen

public Screen getScreen(String id)
get a specific screen.

Parameters:
id - the id of the screen to retrieve.
Returns:
the screen

getSoundSystem

public SoundSystem getSoundSystem()
Get the SoundSystem.

Returns:
SoundSystem

getRenderEngine

public NiftyRenderEngine getRenderEngine()
Return the RenderDevice.

Returns:
RenderDevice

getCurrentScreen

public Screen getCurrentScreen()
Get current screen.

Returns:
current screen

isActive

public boolean isActive(String filename,
                        String screenId)
Check if nifty displays the file with the given filename and is at a screen with the given screenId.

Parameters:
filename - filename
screenId - screenId
Returns:
true if the given screen is active and false when not

registerPopup

public void registerPopup(PopupType popup)
popup.

Parameters:
popup - popup

showPopup

public void showPopup(Screen screen,
                      String id,
                      Element defaultFocusElement)
show popup in the given screen.

Parameters:
screen - screen
id - id

createPopup

public Element createPopup(String popupId)

createPopupWithId

public Element createPopupWithId(String popupId,
                                 String id)

createPopupWithStyle

public Element createPopupWithStyle(String popupId,
                                    String id,
                                    String style)

createPopupWithStyle

public Element createPopupWithStyle(String popupId,
                                    String style)

createPopupWithStyle

public Element createPopupWithStyle(String popupId,
                                    String style,
                                    Attributes parameters)

findPopupByName

public Element findPopupByName(String id)

getTopMostPopup

public Element getTopMostPopup()

closePopup

public void closePopup(String id)
Close the Popup with the given id.

Parameters:
id - id of popup to close

closePopup

public void closePopup(String id,
                       EndNotify closeNotify)
Close the Popup with the given id. This calls the given EndNotify when the onEndScreen of the popup ends.

Parameters:
id - id of popup to close
closeNotify - EndNotify callback

addControl

public void addControl(Screen screen,
                       Element element,
                       StandardControl standardControl)

removeElement

public void removeElement(Screen screen,
                          Element element)

removeElement

public void removeElement(Screen screen,
                          Element element,
                          EndNotify endNotify)

moveElement

public void moveElement(Screen screen,
                        Element elementToMove,
                        Element destination,
                        EndNotify endNotify)

getMouseInputEventQueue

public MouseInputEventProcessor getMouseInputEventQueue()
Returns:
the mouseInputEventQueue

registerScreenController

public void registerScreenController(ScreenController... controllers)
Register a ScreenController instance.

Parameters:
controllers - ScreenController

findScreenController

public ScreenController findScreenController(String controllerClass)
find a ScreenController instance that matches the given controllerClass name.

Parameters:
controllerClass - controller class name
Returns:
ScreenController instance

getLoader

public NiftyLoader getLoader()

getTimeProvider

public TimeProvider getTimeProvider()

addScreen

public void addScreen(String id,
                      Screen screen)

registerStyle

public void registerStyle(StyleType style)

registerControlDefintion

public void registerControlDefintion(ControlDefinitionType controlDefintion)

registerEffect

public void registerEffect(RegisterEffectType registerEffectType)

resolveControlDefinition

public ControlDefinitionType resolveControlDefinition(String name)

resolveRegisteredEffect

public RegisterEffectType resolveRegisteredEffect(String name)

getDefaultStyleResolver

public StyleResolver getDefaultStyleResolver()

getAlternateKey

public String getAlternateKey()

delayedMethodInvoke

public void delayedMethodInvoke(NiftyDelayedMethodInvoke method,
                                Object[] params)

invokeMethods

public void invokeMethods()

setLocale

public void setLocale(Locale locale)

getResourceBundles

public Map<String,ResourceBundle> getResourceBundles()

addResourceBundle

public void addResourceBundle(String id,
                              String filename)

getGlobalProperties

public Properties getGlobalProperties()

setGlobalProperties

public void setGlobalProperties(Properties globalProperties)

getRootLayerFactory

public RootLayerFactory getRootLayerFactory()

loadStyleFile

public void loadStyleFile(String styleFile)

loadControlFile

public void loadControlFile(String controlFile)

registerResourceBundle

public void registerResourceBundle(String id,
                                   String filename)

registerEffect

public void registerEffect(String name,
                           String classParam)

registerSound

public void registerSound(String id,
                          String filename)

registerMusic

public void registerMusic(String id,
                          String filename)

registerMouseCursor

public void registerMouseCursor(String id,
                                String filename,
                                int hotspotX,
                                int hotspotY)

getNiftyMouse

public NiftyMouse getNiftyMouse()

createElementFromType

public Element createElementFromType(Screen screen,
                                     Element parent,
                                     ElementType type)

createImage

public NiftyImage createImage(String name,
                              boolean filterLinear)
Create a new Image. This is a helper method so that you don't need to get the RenderEngine.

Parameters:
name - file name to use
filterLinear - filter
Returns:
RenderImage instance

setDebugOptionPanelColors

public void setDebugOptionPanelColors(boolean option)
You can set this option to true to let Nifty automatically render all panels in random background colors for debugging purposes.

Parameters:
option - enable (true) or disable (false) this feature

isDebugOptionPanelColors

public boolean isDebugOptionPanelColors()
Returns true if the debug option to render panel colors in enabled.

Returns:
true if the option is enabled and false if not

specialValuesReplace

public String specialValuesReplace(String value)
A helper method to call the special values replace method ${} syntax

Parameters:
value - the value to perform the replace on
Returns:
the value with stuff replaced

getClipboard

public Clipboard getClipboard()

setClipboard

public void setClipboard(Clipboard clipboard)

createFont

public RenderFont createFont(String name)

getFontname

public String getFontname(RenderFont font)

enableAutoScaling

public void enableAutoScaling(int baseResolutionX,
                              int baseResolutionY)
Enable automatic scaling of all GUI elements in relation to the given base resolution.

Parameters:
baseResultionX - width, for instance 1024
baseResolutionY - height, for instance 768

enableAutoScaling

public void enableAutoScaling(int baseResolutionX,
                              int baseResolutionY,
                              float scaleX,
                              float scaleY)

disableAutoScaling

public void disableAutoScaling()

getResourceAsStream

public InputStream getResourceAsStream(String ref)
Return an InputStream for the given resource name. This is resolved using the currently registered ResourceLocations.

Parameters:
ref - the name of the resource to load
Returns:
the InputStream of the resource data

getResourceLoader

public NiftyResourceLoader getResourceLoader()
Return the ResourceLoader of this Nifty instance.

Returns:
the ResourceLoader to load resources


Copyright © 2011. All Rights Reserved.