de.lessvoid.nifty.Nifty Java Examples

The following examples show how to use de.lessvoid.nifty.Nifty. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GElement.java    From niftyeditor with Apache License 2.0 6 votes vote down vote up
public void refresh() {
    Nifty temp = nElement.getNifty();
    Attributes att = this.nElement.getElementType().getAttributes();
    String newStyle = att.get("style");
    Attributes attcopy = new Attributes(att);
    // Add the old style if there was one
    if (oldStyle != null && !oldStyle.equals(newStyle)) {

        att.set("style", oldStyle);
        nElement.setStyle(newStyle);
        attcopy = att;
        oldStyle = newStyle;
    }
    if (att.isSet("renderOrder")) {
        int renderorder = att.get("renderOrder").isEmpty() ? this.parent.children.indexOf(this) : att.getAsInteger("renderOrder");
        nElement.setRenderOrder(renderorder);
    }
    nElement.setId(id);
    this.internalRefresh(temp, attcopy);
    this.processRemoved();
    fireUpdate();
}
 
Example #2
Source File: GUIEditor.java    From niftyeditor with Apache License 2.0 6 votes vote down vote up
/**
 * Create a new empty gui with one screen and set as the current gui.
 * @param nifty a valid Nifty instace @see Nifty
 * @throws ParserConfigurationException if controller failed to create
 * a valid document instance
 */
public void createNewGui(Nifty nifty) throws ParserConfigurationException, JAXBException, ClassNotFoundException, IOException, NoProductException{
    gui= GUIFactory.getInstance().createGUI(nifty);
    GScreen screen = (GScreen) GUIFactory.getInstance().newGElement(GScreen.class);
    GLayer layer1 = (GLayer) GUIFactory.getInstance().newGElement(GLayer.class);
    screen.addChild(layer1, true);
    getGui().addScreen(screen);
    this.currentS = screen;
    this.currentL = layer1;
    this.currentlayers.clear();
    this.currentlayers.add(layer1);
    GUseControls standardControls = new GUseControls();
    GUseStyle standardStyle = new GUseStyle();
    standardControls.setFilename("nifty-default-controls.xml");
    standardStyle.setFilename("nifty-default-styles.xml");
    this.gui.addUseControls(standardControls);
    this.gui.addUseStyles(standardStyle);
    this.model.setCurentGUI(gui);
    this.setChanged();
    this.notifyObservers(new ReloadGuiEvent(gui));
    this.clearChanged();
    writer = new GUIWriter(gui);
    dragDropManager = new NiftyDDManager(nifty);
    System.gc();
}
 
Example #3
Source File: TestIssue99.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public void simpleInitApp() {
    /*
     * GUI requires a cursor; prevent flyCam from hiding it.
     */
    flyCam.setDragToRotate(true);
    /*
     * Start NiftyGUI without the batched renderer.
     */
    NiftyJmeDisplay niftyDisplay = new NiftyJmeDisplay(
            assetManager, inputManager, audioRenderer, guiViewPort);
    guiViewPort.addProcessor(niftyDisplay);
    /*
     * Load GUI controls, styles, and layout from XML assets.
     */
    Nifty nifty = niftyDisplay.getNifty();
    nifty.loadControlFile("nifty-default-controls.xml");
    nifty.loadStyleFile("nifty-default-styles.xml");
    nifty.fromXml("Interface/Nifty/test-issue-99.xml",
            "test-issue-99", this);
}
 
Example #4
Source File: J2DNiftyView.java    From niftyeditor with Apache License 2.0 6 votes vote down vote up
public void init() {
       InputSystemAwtImpl inputSystem = new InputSystemAwtImpl();
       FontProviderJava2dImpl fontProvider = new FontProviderJava2dImpl();
registerFonts(fontProvider);
       RenderDeviceJava2dImpl renderDevice = new RenderDeviceJava2dImpl(graphWrap);
renderDevice.setFontProvider(fontProvider);
nifty = new Nifty(renderDevice,  new SoudDevicenull(), inputSystem,new TimeProvider());
      
       java.net.URL empty = getClass().getResource("/jada/ngeditor/resources/empty.xml");
       try {
           nifty.fromXml(empty.getFile(),empty.openStream(), "screen1");
       } catch (IOException ex) {
           Logger.getLogger(J2DNiftyView.class.getName()).log(Level.SEVERE, null, ex);
       }
       this.dragDropManager = new NiftyDDManager(nifty);
       timer = new Timer(30,this); 
       timer.start();
       this.setIgnoreRepaint(true);
       nifty.resolutionChanged();
   }
 
Example #5
Source File: NiftyJmeDisplay.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Create a standard NiftyJmeDisplay. This uses the old Nifty renderer. It's probably slower then the batched
 * renderer and is mainly here for backwards compatibility.
 *
 * @param assetManager jME AssetManager
 * @param inputManager jME InputManager
 * @param audioRenderer jME AudioRenderer
 * @param vp Viewport to use
 */
public NiftyJmeDisplay(AssetManager assetManager,
                       InputManager inputManager,
                       AudioRenderer audioRenderer,
                       ViewPort vp){
    initialize(assetManager, inputManager, audioRenderer, vp);

    this.renderDev = new RenderDeviceJme(this);
    this.batchRendererBackend = null;

    nifty = new Nifty(renderDev, soundDev, inputSys, new AccurateTimeProvider());
    inputSys.setNifty(nifty);

    resourceLocation = new ResourceLocationJme();
    nifty.getResourceLoader().removeAllResourceLocations();
    nifty.getResourceLoader().addResourceLocation(resourceLocation);
}
 
Example #6
Source File: NiftyJmeDisplay.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private NiftyJmeDisplay(
    final AssetManager assetManager,
    final InputManager inputManager,
    final AudioRenderer audioRenderer,
    final ViewPort viewport,
    final BatchRenderConfiguration batchRenderConfiguration) {
  initialize(assetManager, inputManager, audioRenderer, viewport);

  this.renderDev = null;
  this.batchRendererBackend = new JmeBatchRenderBackend(this);

  nifty = new Nifty(
      new BatchRenderDevice(batchRendererBackend, batchRenderConfiguration),
      soundDev,
      inputSys,
      new AccurateTimeProvider());
  inputSys.setNifty(nifty);

  resourceLocation = new ResourceLocationJme();
  nifty.getResourceLoader().removeAllResourceLocations();
  nifty.getResourceLoader().addResourceLocation(resourceLocation);
}
 
Example #7
Source File: NiftyJmeDisplay.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public NiftyJmeDisplay(AssetManager assetManager, 
                       InputManager inputManager,
                       AudioRenderer audioRenderer,
                       ViewPort vp){
    this.assetManager = assetManager;

    w = vp.getCamera().getWidth();
    h = vp.getCamera().getHeight();

    soundDev = new SoundDeviceJme(assetManager, audioRenderer);
    renderDev = new RenderDeviceJme(this);
    inputSys = new InputSystemJme(inputManager);
    if (inputManager != null)
        inputManager.addRawInputListener(inputSys);
    
    nifty = new Nifty(renderDev, soundDev, inputSys, new FastTimeProvider());
    inputSys.setNifty(nifty);

    resourceLocation = new ResourceLocationJme();
    nifty.getResourceLoader().removeAllResourceLocations();
    nifty.getResourceLoader().addResourceLocation(resourceLocation);
}
 
Example #8
Source File: TestContextSwitching.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public void bind(Nifty nifty, Screen screen) {
    applyButton = screen.findNiftyControl("ApplyButton", Button.class);
    platformListBox = screen.findNiftyControl("PlatformListBox", ListBox.class);
    deviceListBox = screen.findNiftyControl("DeviceListBox", ListBox.class);
    infoLabel = screen.findNiftyControl("InfoLabel", Label.class);
    
    updateInfos();
    
    platformListBox.clear();
    for (Platform p : availabePlatforms) {
        platformListBox.addItem(p.getName());
    }
    platformListBox.selectItem(selectedPlatform);
    changePlatform(selectedPlatform);
}
 
Example #9
Source File: NiftyDDManager.java    From niftyeditor with Apache License 2.0 5 votes vote down vote up
public NiftyDDManager(Nifty nifty){
    Element temp = nifty.findPopupByName(NIFTY_EDITOR_POPUP_SUPPORT);
    if(temp == null){
        PopupBuilder builder = new PopupBuilder(NIFTY_EDITOR_POPUP_SUPPORT);
        builder.childLayoutAbsolute();
        builder.registerPopup(nifty);
        temp = nifty.createPopup(NIFTY_EDITOR_POPUP_SUPPORT);
    }
    popUp = temp;
    this.nifty = nifty;
    dragged = null;
}
 
Example #10
Source File: GUI.java    From niftyeditor with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new gui
 *
 * @param nifty
 */
protected GUI(Nifty nifty) {
    this.manager = nifty;
    this.screens = new LinkedList<GScreen>();
    this.currentS = null;
    ID = GUI.GUIID++;
    this.assetsFile = new File(".");
    this.selection = new Selection();
}
 
Example #11
Source File: GScreen.java    From niftyeditor with Apache License 2.0 5 votes vote down vote up
@Override
public void reloadElement(Nifty manger) {
     Nifty nif = manger;
    if(nElement != null)
        nif = nElement.getNifty();
    Collection<String> pe = nif.getAllScreensName();
    
    nElement = nif.getScreen(id).getRootElement();
     for(String sel : attributes.keySet()){
           nElement.getElementType().getAttributes().set(sel, attributes.get(sel));
     }
}
 
Example #12
Source File: GScreen.java    From niftyeditor with Apache License 2.0 5 votes vote down vote up
@Override
public void createNiftyElement(Nifty nifty) {
    Screen screen = new ScreenBuilder(id){{
         
    }}.build(nifty);
    nElement = screen.getRootElement();
     for(String sel : attributes.keySet()){
           nElement.getElementType().getAttributes().set(sel, attributes.get(sel));
     }
    
}
 
Example #13
Source File: BattlefieldController.java    From OpenRTS with MIT License 5 votes vote down vote up
public BattlefieldController(MapView view, Nifty nifty, InputManager inputManager, Camera cam) {
	super(view, inputManager, cam);
	this.view = view;
	inputInterpreter = new BattlefieldInputInterpreter(this);
	guiController = new BattlefieldGUIController(nifty, this);

	EventManager.register(this);

	cameraManager = new IsometricCameraManager(cam, 10);
}
 
Example #14
Source File: GElement.java    From niftyeditor with Apache License 2.0 5 votes vote down vote up
public void reloadElement(Nifty manager) {
    Nifty nif = manager;
    if (nElement != null) {
        nif = nElement.getNifty();
    }
    nElement = parent.nElement.findElementById(id);
}
 
Example #15
Source File: GroundController.java    From OpenRTS with MIT License 5 votes vote down vote up
public GroundController(EditorView view, Nifty nifty, InputManager inputManager, Camera cam) {
	super(view, inputManager, cam);

	inputInterpreter = new GroundInputInterpreter(this);
	cameraManager = new GroundCameraManager(cam);
	guiController = new GroundGUIController(nifty, this);
}
 
Example #16
Source File: GElement.java    From niftyeditor with Apache License 2.0 5 votes vote down vote up
public void createNiftyElement(Nifty nifty) {
    for (String sel : attributes.keySet()) {
        builder.set(sel, attributes.get(sel));
    }
    nElement = builder.build(nifty, nifty.getCurrentScreen(), this.parent.getDropContext());

}
 
Example #17
Source File: GControl.java    From niftyeditor with Apache License 2.0 5 votes vote down vote up
@Override
protected void internalRefresh(Nifty nifty, Attributes att) {
    int index = parent.getNiftyElement().getChildren().indexOf(nElement);
    final GElement telement = this;

    nElement.markForRemoval(new EndNotify() {
        @Override
        public void perform() {
            this.buildChild(telement);
        }

        private void buildChild(GElement ele) {
            for (GElement e : ele.getElements()) {
                ele.getDropContext().addChild(e.getNiftyElement());
                e.refresh();
                this.buildChild(e);
            }
        }
    });
    for (String sel : attributes.keySet()) {
        builder.set(sel, attributes.get(sel));
    }

    nElement = builder.build(nifty, nifty.getCurrentScreen(), this.parent.getDropContext(), index);
    nifty.getCurrentScreen().layoutLayers();
    String keyWord = "style-refresh:"+attributes.get("style");
    nifty.getEventService().unsubscribe(keyWord, specialRerefresher);
    nifty.getEventService().subscribe(keyWord, specialRerefresher);
}
 
Example #18
Source File: EditorController.java    From OpenRTS with MIT License 5 votes vote down vote up
public EditorController(EditorView view, Nifty nifty, InputManager inputManager, Camera cam) {
	super(view, inputManager, cam);
	this.view = view;
	inputInterpreter = new EditorInputInterpreter(this);
	guiController = new EditorGUIController(nifty, this);
	cameraManager = new IsometricCameraManager(cam, 10);

	EventManager.register(this);
}
 
Example #19
Source File: NiftyJmeDisplay.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public NiftyJmeDisplay(AssetManager assetManager, 
                       InputSystem inputManager,
                       AudioRenderer audioRenderer,
                       ViewPort vp){
    this.assetManager = assetManager;
    //TODO: move
    ((DesktopAssetManager)assetManager).clearCache();
    w = vp.getCamera().getWidth();
    h = vp.getCamera().getHeight();

    soundDev = new SoundDeviceJme(assetManager, audioRenderer);
    renderDev = new RenderDeviceJme(this);
    nifty = new Nifty(renderDev, soundDev, inputManager, new TimeProvider());
}
 
Example #20
Source File: GUIEditor.java    From niftyeditor with Apache License 2.0 5 votes vote down vote up
/**
 * Create a new gui from a file and current assetFolder as assets
 * @param nifty a valid Nifty instace @see Nifty
 * @throws ParserConfigurationException if controller failed to create
 * a valid document instance
 * @throws IOException
 * @throws  SAXException
 * @throws Exception if nifty can't create the gui
 * @return A string with the elements that weren't loaded
 * 
 */
public String createNewGui(Nifty nifty ,File filename) throws ParserConfigurationException, IOException, SAXException, NoProductException, Exception{
   String assets= ".";
   if(this.gui != null){
      assets = this.gui.getAssetFolder().getPath(); 
   }
   GUIReader reader = new GUIReader(nifty);
   String res = "";
   this.gui = reader.readGUI(filename);
   this.gui.setAssetFolder(new File(assets));
   res = reader.getTagNotLoaded();
   final GScreen screen =this.getGui().gettopScreen();
   for(String sel : nifty.getAllScreensName()){
                nifty.removeScreen(sel);
   }
   writer = new GUIWriter(gui);
  nifty.scheduleEndOfFrameElementAction(new Reload(nifty, screen.getID()), new EndNotify() {

        @Override
        public void perform() {
           setChanged();
           notifyObservers(new ReloadGuiEvent(gui));
           clearChanged();
        }
    });
   currentL=gui.getTopLayer();
   currentS=gui.gettopScreen();
   currentlayers.addAll(gui.getLayers());
   dragDropManager = new NiftyDDManager(nifty);
   this.model.setCurentGUI(gui);
   return res;
        
}
 
Example #21
Source File: GUIEditor.java    From niftyeditor with Apache License 2.0 5 votes vote down vote up
/**
 * Create a new gui from a file with given assetsFolder
 * @param nifty a valid Nifty instace @see Nifty
 * @throws ParserConfigurationException if controller failed to create
 * a valid document instance
 * @throws IOException
 * @throws  SAXException
 * @throws Exception if nifty can't create the gui
 * @return A string with the elements that weren't loaded
  */
 public String createNewGui(Nifty nifty ,File filename,File assetsFolder) throws ParserConfigurationException, IOException, SAXException, NoProductException, Exception{
   GUIReader reader = new GUIReader(nifty);
   String res = "";
   this.gui = reader.readGUI(filename);
   this.gui.setAssetFolder(assetsFolder);
   res = reader.getTagNotLoaded();
   final GScreen screen =this.getGui().gettopScreen();
   for(String sel : nifty.getAllScreensName()){
                nifty.removeScreen(sel);
   }
   writer = new GUIWriter(gui);
  nifty.scheduleEndOfFrameElementAction(new Reload(nifty, screen.getID()), new EndNotify() {

        @Override
        public void perform() {
           setChanged();
           notifyObservers(new ReloadGuiEvent(gui));
           clearChanged();
        }
    });
   currentL=gui.getTopLayer();
   currentS=gui.gettopScreen();
   currentlayers.addAll(gui.getLayers());
   dragDropManager = new NiftyDDManager(nifty);
   this.model.setCurentGUI(gui);
   return res;
        
}
 
Example #22
Source File: GUIEditor.java    From niftyeditor with Apache License 2.0 5 votes vote down vote up
/**
 * Create a new gui from a file with given assetsFolder
 * @param nifty a valid Nifty instace @see Nifty
 * @throws ParserConfigurationException if controller failed to create
 * a valid document instance
 * @throws IOException
 * @throws  SAXException
 * @throws Exception if nifty can't create the gui
 * @return A string with the elements that weren't loaded
  */
 public String createNewGui(Nifty nifty , InputStream stream,File assetsFolder) throws ParserConfigurationException, IOException, SAXException, NoProductException, Exception{
   GUIReader reader = new GUIReader(nifty);
   String res = "";
   this.gui = reader.readGUI(stream);
   this.gui.setAssetFolder(assetsFolder);
   res = reader.getTagNotLoaded();
   final GScreen screen =this.getGui().gettopScreen();
   for(String sel : nifty.getAllScreensName()){
                nifty.removeScreen(sel);
   }
   writer = new GUIWriter(gui);
  nifty.scheduleEndOfFrameElementAction(new Reload(nifty, screen.getID()), new EndNotify() {

        @Override
        public void perform() {
           setChanged();
           notifyObservers(new ReloadGuiEvent(gui));
           clearChanged();
        }
    });
   currentL=gui.getTopLayer();
   currentS=gui.gettopScreen();
   currentlayers.addAll(gui.getLayers());
   dragDropManager = new NiftyDDManager(nifty);
   this.model.setCurentGUI(gui);
   return res;
        
}
 
Example #23
Source File: GUIEditor.java    From niftyeditor with Apache License 2.0 5 votes vote down vote up
/**
 * Refresh the current gui . It causes a call to nifty.fromXml method. 
 * @param nifty
 * @throws Exception if nifty can't load the old gui
 */
public void refresh(Nifty nifty) throws Exception{
    if(getGui() != null){
        String screenID =this.currentS.getID();
            nifty.scheduleEndOfFrameElementAction(new Reload(nifty, screenID), null);
            
            
    }
}
 
Example #24
Source File: GElement.java    From niftyeditor with Apache License 2.0 5 votes vote down vote up
public void lightRefresh() {
    Nifty temp = nElement.getNifty();
    Screen currentScreen = temp.getCurrentScreen();
    Attributes att = this.nElement.getElementType().getAttributes();
    nElement.initializeFromAttributes(currentScreen, att, temp.getRenderEngine());
    currentScreen.layoutLayers();
}
 
Example #25
Source File: NiftyJmeDisplay.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Create a new NiftyJmeDisplay for use with the Batched Nifty Renderer (improved Nifty rendering performance).
 *
 * Nifty will use a single texture of the given dimensions (see atlasWidth and atlasHeight parameters). Every
 * graphical asset you're rendering through Nifty will be placed into this big texture. The goal is to render
 * all Nifty components in a single (or at least very few) draw calls. This should speed up rendering quite a
 * bit.
 *
 * Currently you have to make sure to not use more image space than this single texture provides. However, Nifty
 * tries to be smart about this and internally will make sure that only the images are uploaded that your GUI
 * really needs. So in general this shouldn't be an issue.
 *
 * A complete re-organisation of the texture atlas happens when a Nifty screen ends and another begins. Dynamically
 * adding images while a screen is running is supported as well.
 *
 * @param assetManager jME AssetManager
 * @param inputManager jME InputManager
 * @param audioRenderer jME AudioRenderer
 * @param viewport Viewport to use
 * @param atlasWidth the width of the texture atlas Nifty uses to speed up rendering (2048 is a good value)
 * @param atlasHeight the height of the texture atlas Nifty uses to speed up rendering (2048 is a good value)
 *
 * @deprecated use the static factory methods {@link #newNiftyJmeDisplay(com.jme3.asset.AssetManager, com.jme3.input.InputManager, com.jme3.audio.AudioRenderer, com.jme3.renderer.ViewPort) }
 * or {@link #newNiftyJmeDisplay(com.jme3.asset.AssetManager, com.jme3.input.InputManager, com.jme3.audio.AudioRenderer, com.jme3.renderer.ViewPort, de.lessvoid.nifty.render.batch.BatchRenderConfiguration) }
 * instead of this constructor.
 */
public NiftyJmeDisplay(
    final AssetManager assetManager,
    final InputManager inputManager,
    final AudioRenderer audioRenderer,
    final ViewPort viewport,
    final int atlasWidth,
    final int atlasHeight) {
  // The code duplication in here really sucks - it's a copy of the
  // private constructor below that takes a BatchRenderConfiguration as an
  // additional parameter. This method should really be removed soon and
  // users should simply call the new factory methods.
  //
  // For now I keep this constructor as-is but have marked it as deprecated
  // to allow migration to the new way to instantiate this class.
  initialize(assetManager, inputManager, audioRenderer, viewport);

  this.renderDev = null;
  this.batchRendererBackend = new JmeBatchRenderBackend(this);

  BatchRenderConfiguration batchRenderConfiguration = new BatchRenderConfiguration();
  batchRenderConfiguration.atlasWidth = atlasWidth;
  batchRenderConfiguration.atlasHeight = atlasHeight;

  nifty = new Nifty(
      new BatchRenderDevice(batchRendererBackend, batchRenderConfiguration),
      soundDev,
      inputSys,
      new AccurateTimeProvider());
  inputSys.setNifty(nifty);

  resourceLocation = new ResourceLocationJme();
  nifty.getResourceLoader().removeAllResourceLocations();
  nifty.getResourceLoader().addResourceLocation(resourceLocation);
}
 
Example #26
Source File: GElement.java    From niftyeditor with Apache License 2.0 4 votes vote down vote up
private void lightRefresh(Attributes att) {
    Nifty temp = nElement.getNifty();
    Screen currentScreen = temp.getCurrentScreen();
    nElement.initializeFromAttributes(currentScreen, att, temp.getRenderEngine());
    currentScreen.layoutLayers();
}
 
Example #27
Source File: GElement.java    From niftyeditor with Apache License 2.0 4 votes vote down vote up
protected void internalRefresh(Nifty nifty,Attributes att){
    Screen currentScreen = nifty.getCurrentScreen();
    nElement.initializeFromAttributes(currentScreen, att, nifty.getRenderEngine());
    currentScreen.layoutLayers();
}
 
Example #28
Source File: GuiTrack.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public GuiTrack(Nifty nifty, String screen) {
    this.screen = screen;
    this.nifty = nifty;
}
 
Example #29
Source File: GUseControls.java    From niftyeditor with Apache License 2.0 4 votes vote down vote up
@Override
public void createInNifty(Nifty manger) {
    manger.loadControlFile(filename);
}
 
Example #30
Source File: GuiTrack.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public void setNifty(Nifty nifty) {
    this.nifty = nifty;
}