function chartable(h)

import javax.swing.*;

%% Method which builds/populates the char table on the node panel

if isempty(h.Handles) || isempty(h.Handles.PNLAnnoation) || ...
        ~ishandle(h.Handles.PNLAnnoation)
    return % No panel
end

%% Assemble the axes table data by traversing each characteristic
tableData = {false, 'Mean',;...
             false, 'Median';...
             false, 'Normal distribution'};

%% Populate the table - if necessary creating it
if ~isfield(h.Handles,'annoationTable') || ...
        isempty(h.Handles.annoationTable)
    headings = {'Show (y/n?)','Annotations'};
    [h.Handles.annoationTable, h.Handles.PNLannotationTable] = ... 
        uitable(ancestor(h.Handles.PNLAnnoation,'figure'),tableData,headings);
    set(h.Handles.PNLannotationTable,'Parent',h.Handles.PNLAnnoation)
    % Turn off the default uitable context menus
    mouseListeners = h.Handles.annoationTable.getTable.getMouseListeners;
    for k=1:length(mouseListeners)
        if isa(mouseListeners(k), 'com.mathworks.widgets.spreadsheet.SpreadsheetTable$TableMouseEventListener')
            h.Handles.annoationTable.getTable.removeMouseListener(mouseListeners(k));
        end
    end
    % Check box editor for 1st col
    h.Handles.annoationTable.setCheckBoxEditor(1);
    % DataChange listener
    set(h.Handles.annoationTable,'DataChangedCallback',{@localDataChange ...
        h.Handles.annoationTable h})
else
    tstableSetData(h.Handles.annoationTable,tableData)
    drawnow
end

%% De-activate row header
set(h.Handles.annoationTable.TableScrollPane.getRowHeader,'Visible','off');
%% Pack the table
awtinvoke(h.Handles.annoationTable.getTable,'setAutoResizeMode',true)


function localDataChange(eventSrc, eventData, table, h)

%% Prevent recursion
% if strcmp(h.EditLock,'on')
%     return
% end

%h.EditLock = 'on';

%% Find the data which was changed
selRow = eventData.getEvent.getFirstRow+1;
col = eventData.getEvent.getColumn+1;

%% Get current table data
tableData = cell(table.Data);
       
switch col
    case 1 % Visibility change
        %% Set the visibility of the selected chars      

        %% Find the char
        charlist = localGetChars(h, selRow);

        %% Checked = visible
        if tableData{selRow,1}
            set(charlist,'Visible','on');
            set(h.Plot.AxesGrid.findMenu(charlist(1).Identifier),'Checked','on')
        else
            set(charlist,'Visible','off');
            set(h.Plot.AxesGrid.findMenu(charlist(1).Identifier),'Checked','off')
        end

    case 3 % Start time change
        %% Find the char
        charlist = localGetChars(h,selRow);
            
        %% Set the start time of each char in the list
        startfreq = str2num(tableData{selRow,3});      
        if ~isempty(startfreq) % Valid start time, reset the chars
            for k=1:length(charlist)  
                charlist(k).Data.Startfreq = starfreq;
            end
        else % Invlid start time - revert table to the val of the char
            tableData{startRow,3} = charlist(1).Data.Startfreq;
        end      
    case 4 % End time change
         %% Find the char
        charlist = localGetChars(h,selRow);
            
        %% Set the end time of each char in the list
        endfreq = str2num(tableData{selRow,4});      
        if ~isempty(endfreq) % Valid start time, reset the chars
            for k=1:length(charlist)  
                charlist(k).Data.Endfreq = endfreq;
            end
        else % Invlid start time - revert table to the val of the char
            tableData{selRow,4} = charlist(1).Data.Endfreq;
        end                   
end

h.Plot.AxesGrid.send('DataChanged');
tstableSetData(table,tableData)
drawnow

function charlist = localGetChars(h,startRow)

%% Creates a list of all the characteristics of the type defined in the
%% table row "startRow" for all the attached waves

%% Define string constants 
charList = {'Mean','Control','????','????'};
dataList = {'tsguis.tsMeanData','tsguis.tsMeanBandData','',''};
viewList = {'tsguis.tsMeanView','tsguis.tsMeanBandView','',''};

%% Find the selected chars. If necesssary creating them 
charlist = [];
for k=1:length(h.Plot.Waves)
    % Find the position of the char in the char array for this wave 
    ind = find(strcmp(charList{startRow},...
        get(h.Plot.Waves(k).Characteristics,{'Identifier'})));
    if ~isempty(ind) % Add the found char to the list
        charlist = [charlist; h.Plot.Waves(k).Characteristics(ind)];
    else % Create a new char and add it to the list
        h.Plot.Waves(k).addchar(charList{startRow},dataList{startRow}, ...
            viewList{startRow}); 
        charlist = [charlist; h.Plot.Waves(k).Characteristics(end)]; 
    end
end
            