All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.cogchar.nbui.render.BehaviorPanelTopComponent Maven / Gradle / Ivy

There is a newer version: 1.1.4
Show newest version
/*
 *  Copyright 2011 by The Cogchar Project (www.cogchar.org).
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
package org.cogchar.nbui.render;

import org.cogchar.bind.mio.robot.client.RobotSelector;
import org.cogchar.bind.mio.robot.client.RobotSelector.OSGiRobotSelector;
import org.cogchar.svc.behav.control.ActionCallbackMap;
import org.openide.util.NbBundle;
import org.openide.windows.TopComponent;
import org.netbeans.api.settings.ConvertAsProperties;
import org.openide.awt.ActionID;
import org.openide.awt.ActionReference;
import org.osgi.framework.BundleContext;
import org.jflux.impl.services.rk.lifecycle.utils.SimpleLifecycle;
import org.jflux.impl.services.rk.osgi.OSGiUtils;
import org.jflux.impl.services.rk.osgi.lifecycle.OSGiComponent;
import org.mechio.api.motion.Robot;

/**
 * Top component which displays something.
 */
@ConvertAsProperties(dtd = "-//org.cogchar.nbui.render//BehaviorPanel//EN",
autostore = false)
@TopComponent.Description(preferredID = "BehaviorPanelTopComponent",
//iconBase="SET/PATH/TO/ICON/HERE", 
persistenceType = TopComponent.PERSISTENCE_ALWAYS)
@TopComponent.Registration(mode = "bottomSlidingSide", openAtStartup = true)
@ActionID(category = "Window", id = "org.cogchar.nbui.render.BehaviorPanelTopComponent")
@ActionReference(path = "Menu/Window" /*, position = 333 */)
@TopComponent.OpenActionRegistration(displayName = "#CTL_BehaviorPanelAction",
preferredID = "BehaviorPanelTopComponent")
public final class BehaviorPanelTopComponent extends TopComponent {
    private boolean myInitFlag;

    public BehaviorPanelTopComponent() {
        initComponents();
        setName(NbBundle.getMessage(BehaviorPanelTopComponent.class, "CTL_BehaviorPanelTopComponent"));
        setToolTipText(NbBundle.getMessage(BehaviorPanelTopComponent.class, "HINT_BehaviorPanelTopComponent"));
        myInitFlag = false;
    }
    
    private synchronized void init(BundleContext bundleCtx){
        if(bundleCtx == null){
            return;
        }
        if(myInitFlag){
			System.out.println("BehaviorPanelTopComponent was already initialized.");
            return;
        }
        System.out.println("init() - making trigger panel and robot selector");
        new OSGiComponent(bundleCtx, 
                new SimpleLifecycle(triggerPanel1, ActionCallbackMap.class)).start();
        new OSGiComponent(bundleCtx, 
                new SimpleLifecycle(
                        new OSGiRobotSelector(), RobotSelector.class)).start();
        myInitFlag = true;
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // //GEN-BEGIN:initComponents
    private void initComponents() {

        triggerPanel1 = new org.cogchar.nbui.render.trigger.TriggerPanel();

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(triggerPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 232, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(triggerPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 194, Short.MAX_VALUE)
        );
    }// //GEN-END:initComponents

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private org.cogchar.nbui.render.trigger.TriggerPanel triggerPanel1;
    // End of variables declaration//GEN-END:variables
    @Override
    public void componentOpened() {
		System.out.println("BehaviorPanel-componentOpened()");
        BundleContext context = OSGiUtils.getBundleContext(Robot.class);
        if(context == null){
            throw new NullPointerException(
                    "Cannot find BundleContext for" + Robot.class);
        }
        init(context);
    }

    @Override
    public void componentClosed() {
        // TODO add custom code on component closing
    }

    void writeProperties(java.util.Properties p) {
        // better to version settings since initial version as advocated at
        // http://wiki.apidesign.org/wiki/PropertyFiles
        p.setProperty("version", "1.0");
        // TODO store your settings
    }

    void readProperties(java.util.Properties p) {
        String version = p.getProperty("version");
        // TODO read your settings according to their version
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy