Ok, I've changed that. Debug now shows that at the line

window = (Window) wtkxSerializer.readObject(Example.class, "Example.wtkx"); 

before execution variable rx (for example) is null. During execution, the
initialize() method is called and rx assumes a value, the initial image is
assigned. After execution, rx is null again.

I'm obviously still doing something stupid, but I just can't see what.


<example:Example title="Genesis Client" maximized="true"
styles="{showWindowControls:false}"
                xmlns:bxml="http://pivot.apache.org/bxml";
        xmlns:example="com.blackbox.x.client"
        xmlns="org.apache.pivot.wtk">

                <Border styles="{color:10, cornerRadii:20}">
                
                                <TablePane>
                                        <columns>
                                                <TablePane.Column />
                                        </columns>
                                        <rows>
                                        <TablePane.Row>
                                        <Border>
                
                                        <BoxPane orientation="horizontal" >
                                        <ImageView bxml:id="car" 
styles="{verticalAlignment:'center'}"/>
                                        <ImageView bxml:id="vci_status" 
styles="{verticalAlignment:'bottom'}"/>
                                        <ImageView bxml:id="pc" 
styles="{verticalAlignment:'center'}"/>
                                        <ImageView bxml:id="pc_status" 
styles="{verticalAlignment:'bottom'}"/>
                                        <ImageView bxml:id="server" 
styles="{verticalAlignment:'center'}"/>
                                        </BoxPane>
                        
                                        </Border>
                                        </TablePane.Row>
                                        <TablePane.Row> 
                                        <Border>
                                
                                        <BoxPane orientation="horizontal">
                                        <ImageView bxml:id="rx" />
                                        <ImageView bxml:id="tx" />
                                        </BoxPane>
                        
                                        </Border>
                                        </TablePane.Row>
                                        
                                                <TablePane.Row height="300">
                                                        <Border>
                                                        
                                                                        
<ScrollPane horizontalScrollBarPolicy="fill_to_capacity">
                                                                                
<view>
                                                                                
        <TableView bxml:id="tv" selectMode="single">
                                                                                
                <columns>
                                                                                
                        <TableView.Column name="message" width="800"
                                                                                
                                headerData="Header" />
                                                                                
                </columns>
                                                                                
        </TableView>
                                                                                
</view>
                                                                        
</ScrollPane>
                                                                
                                                        </Border>
                                                </TablePane.Row>
                                                <TablePane.Row> 
                                                        <Border>
                                                        
                                                                
<ActivityIndicator bxml:id="activityIndicator"
                                                                        
preferredWidth="24" preferredHeight="24" />
                                                                        
                                                        </Border>
                                                </TablePane.Row>
                                        </rows>
                                </TablePane> 
                        
                </Border>
</example:Example>


public class Example extends Frame implements Application,
MessageBusListener, Bindable,Serializable {

        private static String host;
        private static String port;
        private Window window;
        private Display display;
        private GenesisClient service;
        private List<LogEvent> messages = new ArrayList<LogEvent>();
        @BXML private ActivityIndicator activityIndicator;
        @BXML private ImageView tx;
        @BXML private ImageView rx;
        @BXML private ImageView car;
        @BXML private ImageView vci_status;
        @BXML private ImageView pc;
        @BXML private ImageView pc_status;
        @BXML private ImageView server;
        @BXML private TableView tv;
        private static String TX_ON = "/com/blackbox/x/client/images/TxOn.png";
        private static String RX_ON = "/com/blackbox/x/client/images/RxOn.png";
        private static String TX_OFF = 
"/com/blackbox/x/client/images/TxOff.png";
        private static String RX_OFF = 
"/com/blackbox/x/client/images/RxOff.png";
        private static String CAR =
"/com/blackbox/x/client/images/transportation_car_32.png";
        private static String VCI_STATUS_OFF =
"/com/blackbox/x/client/images/cross.png";
        private static String VCI_STATUS_ON =
"/com/blackbox/x/client/images/tick.png";
        private static String PC = 
"/com/blackbox/x/client/images/generic_pc.png";
        private static String PC_STATUS_OFF =
"/com/blackbox/x/client/images/cross.png";
        private static String PC_STATUS_ON =
"/com/blackbox/x/client/images/tick.png";
        private static String SERVER =
"/com/blackbox/x/client/images/redhat_network_server.png";

        private String VERSION ="Pivot Client : Version 0.95.0.3";
        
        private static final Logger logger = Logger
        .getLogger(Example.class.getName());
        
        public void resume() throws Exception {
        

        }
        

        public boolean shutdown(boolean optional) throws Exception {
                if (window != null) {
                        window.close();
                }
                return false;
        }

        @SuppressWarnings("unchecked")
        public void startup(final Display display, Map&lt;String, String&gt;
properties)
                        throws Exception {
                
                this.display = display;
                
                registerEventListeners();
                
                BXMLSerializer wtkxSerializer = new BXMLSerializer();
                window = (Window) wtkxSerializer.readObject(Example.class,
"Example.wtkx");

                window.open(display);
                
                TaskListener<String>  taskListener = new TaskListener<String>() 
{
            public void taskExecuted(Task<String> task) {
                activityIndicator.setActive(false);
                
                                        vci_status.setImage(VCI_STATUS_ON);
                                        window.setEnabled(true);                
               
            }

            public void executeFailed(Task<String> task) {
//              activityIndicator.setActive(false);
                window.setEnabled(true);
                Exception e = (Exception) task.getFault().getCause();
                if (e instanceof VciNotFoundException) {
                Alert.alert(MessageType.ERROR,"No VCI device found. Please
check that your"
                                + " Vci device is connected securely to your 
car and PC.
Please ensure that the" 
                                + " ignition is turned on and re-try running 
this program.",
window, new DialogCloseListener()
                                 {

                                public void dialogClosed(Dialog dialog, boolean 
modal) {
                                                try {
                                                        
display.getHostWindow().dispose();
                                                        shutdown(true);
                                                        
                                                } catch (Exception e) {
                                                        e.printStackTrace();
                                                }
                                        
                                }
                
                                
                        });
                }
                
                
            }
        };
//activityIndicator.setActive(true);
window.setEnabled(false);
new ClientTask().execute(new TaskAdapter<String>(taskListener));
                
        
        }


        @SuppressWarnings("unchecked")
        private void registerEventListeners() {
                MessageBus.subscribe(LogEvent.class, this);
                MessageBus.subscribe(DataWriteEvent.class, this);
                MessageBus.subscribe(DataReadEvent.class, this);
                MessageBus.subscribe(ServerCloseEvent.class, this);
                MessageBus.subscribe(ErrorEvent.class, this);
                MessageBus.subscribe(ConnectEvent.class, this);
                MessageBus.subscribe(ContactEvent.class, this);
        }

                

        public void suspend() throws Exception {
                

        }

        public static void main(String[] args) {
                if (args[0] == null) {
                        host = "localhost";
                
                } else {
                        host = args[0];
                }
                DesktopApplicationContext.main(Example.class, args);
        }
        
        
        private void sleep(int interval) {
                
                try {
                        Thread.sleep(interval);
                } catch (InterruptedException e) {
                        
                        e.printStackTrace();
                }
                        }
        

        private class ClientTask extends Task<String> {


                @Override
                public String execute() throws TaskExecutionException {
                        messages.add(new LogEvent(VERSION));
                        
                        service = new GenesisClient(host);
                        try {
                                DataEventListener listener = new 
PivotDataEventListener();
                                service.setListener(listener);
                                
                                service.start();
                        } catch (IOException e) {
                                logger.error("GenesisClient throws IOException 
during startup");
                                } catch (VciNotFoundException e) {
                                logger.error("GenesisClient cannot find Vci 
device during startup");
                                throw new TaskExecutionException(e);            
                        }
                        return "Done";
                }
                
        }

        public void messageSent(Object message) {
                
                if (message instanceof LogEvent) {
                        messages.add((LogEvent) message);
                        return;
                } 
                
                
                if (message instanceof ServerCloseEvent) {
                        pc_status.setImage(PC_STATUS_OFF);
                        Alert.alert(MessageType.ERROR,"The Faultmate Genesis 
server has closed
the connection. ", window, new DialogCloseListener()
                                         {

                                public void dialogClosed(Dialog dialog, boolean 
modal) {
                                                try {
                                                        window.close();
                                                        shutdown(true);
                                                        
                                                } catch (Exception e) {
                                                        e.printStackTrace();
                                                }
                                        
                                }
                
                                
                        });
                    
        }
                
                if (message instanceof ErrorEvent) {
                        vci_status.setImage(VCI_STATUS_OFF);
                        Alert.alert(MessageType.ERROR,((ErrorEvent) 
message).getMessage(),
window, new DialogCloseListener()
                                         {

                                public void dialogClosed(Dialog dialog, boolean 
modal) {
                                                try {
                                                        window.close();
                                                        shutdown(true);
                                                } catch (Exception e) {
                                                        e.printStackTrace();
                                                }
                                        
                                }
                
                                
                        });
                    
                }
                
                if (message instanceof ContactEvent) {
                        vci_status.setImage(VCI_STATUS_OFF);
                        messages.add(new LogEvent(((ContactEvent) 
message).getMessage()));
                        Alert.alert(MessageType.ERROR,((ContactEvent) 
message).getMessage(),
window, new DialogCloseListener()
                                         {

                                public void dialogClosed(Dialog dialog, boolean 
modal) {
                                                try {
                                                        window.close();
                                                        shutdown(true);
                                                        } catch (Exception e) {
                                                        e.printStackTrace();
                                                }
                                        
                                }
                
                                
                        });
                    
                }
                
                if (message instanceof ConnectEvent) {
                        messages.add(new LogEvent(((ConnectEvent) 
message).getMessage()));
                        if (((ConnectEvent) message).isConnected()) {
                                pc_status.setImage(PC_STATUS_ON);
                        } else {
                                pc_status.setImage(PC_STATUS_OFF);
                        }
                }
                
        }
        

        @Override
        public void initialize(Map&lt;String, Object&gt; namespace, URL 
location,
                        Resources resources) {
                
                this.tv.setTableData(this.messages);
                /* Set the initial Modem light position */
                this.tx.setImage(TX_OFF);
                this.rx.setImage(RX_OFF);
                /* Set the initial "Connection" icon status.*/
                this.car.setImage(CAR);
                this.vci_status.setImage(VCI_STATUS_OFF);
                this.pc.setImage(PC);
                this.pc_status.setImage(PC_STATUS_OFF);
                this.server.setImage(SERVER);

        }

        

        
        
}


--
View this message in context: 
http://apache-pivot-users.399431.n3.nabble.com/Binding-Issues-converting-from-1-5-to-2-0-tp3235662p3238026.html
Sent from the Apache Pivot - Users mailing list archive at Nabble.com.

Reply via email to