function axespanel(h,view,type)

import com.mathworks.mwswing.*;
import javax.swing.*;
import javax.swing.table.*
import java.awt.*;
import com.mathworks.page.utils.VertFlowLayout;

%% Method which builds/populates the axes panel on the Property Editor

%% Assemble the axes table data by traversing the axesgrid, finding its
%% position, and writing the corresponding row

if strcmp(type,'Y')
    tableData = cell([view.AxesGrid.size(1),4]);
    for k=1:view.Axesgrid.size(1)
        ylimmode = view.Axesgrid.YlimMode{k};       
        ylims = view.Axesgrid.getylim(k);
        tableData(k,:) = {view.AxesGrid.RowLabel{k}, ...
            view.Axesgrid.YlimMode{k},ylims(1),ylims(2)};
    end
    % (Re)Create the table model
    tableModel = DefaultTableModel(tableData,{'Title','Scaling','Ymin','Ymax'});
else
    tableData = cell([view.AxesGrid.size(2),4]);
    for k=1:view.Axesgrid.size(2)
        xlimmode = view.Axesgrid.XlimMode{k};       
        xlims = view.Axesgrid.getxlim(k);
        tableData(k,:) = {view.AxesGrid.ColumnLabel{k}, ...
            view.Axesgrid.XlimMode{k},xlims(1),xlims(2)};
    end    
    % (Re)Create the table model
    tableModel = DefaultTableModel(tableData,{'Title','Scaling','Xmin','Xmax'});
end

%% (Re)Create the table model
set(handle(tableModel,'callbackproperties'),'TableChangedCallback',...
    {@localDataChange tableModel view type});

%% Find the axes tab
thisTab = h.findtab([type 'Axes']);

%% If necessary build the axes tab
if isempty(thisTab)
    % Build the axes table
    thisTab.Handles.AxesGridTable = MJTable(tableModel);
    thisTab.Handles.AxesGridTable.setRowSelectionAllowed(true);
    thisTab.Handles.AxesGridTable.setColumnSelectionAllowed(false);
    thisTab.Handles.AxesGridTable.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
    sPanel = MJScrollPane(thisTab.Handles.AxesGridTable);
    
    % Define the axes panel container
    container = MJPanel(BorderLayout(5,5));
    container.add(sPanel,BorderLayout.CENTER);
    h.Handles.TabPane.add(['Define ' type ' Axes Scaling'],container);

    % Update the Tabs structure
    thisTab.Name = [type 'Axes'];
    h.Tabs = [h.Tabs; thisTab];

else % Update the table model
    awtinvoke(thisTab.Handles.AxesGridTable,'setModel(Ljavax/swing/table/TableModel;)',...
        tableModel);
    % add combo box for 'auto' and 'manual'
    tmp = JComboBox;
    tmp.addItem('auto');
    tmp.addItem('manual');
    ed = DefaultCellEditor(tmp);
    if thisTab.Handles.AxesGridTable.getColumnModel.getColumnCount>=2 % columnModel may not yet be up to date
        thisTab.Handles.AxesGridTable.getColumnModel.getColumn(1).setCellEditor(ed);
    end
end


function localDataChange(eventSrc,eventData,model,h,type)

%% Find the data which was changed
startRow = eventData.getFirstRow;
endRow = eventData.getLastRow;
col = eventData.getColumn;

%% Update the @timeplot
switch col
    case 0
        if isa(h,'resppack.respplot')
            if strcmp(type,'X')
                h.InputName{startRow+1} = model.getValueAt(startRow,0);
            elseif strcmp(type,'Y')
                h.OutputName{startRow+1} = model.getValueAt(startRow,0);
            end
        elseif isa(h,'wavepack.waveplot') && strcmp(type,'Y')
            h.ChannelName{startRow+1} = model.getValueAt(startRow,0);
        end
    case 1
        if strcmp(type,'Y')
            Ylimmode = h.Axesgrid.YlimMode;
            Ylimmode{startRow+1} = model.getValueAt(startRow,1);
            h.Axesgrid.YlimMode = Ylimmode;
        else
            Xlimmode = h.Axesgrid.XlimMode;
            Xlimmode{startRow+1} = model.getValueAt(startRow,1);
            h.Axesgrid.XlimMode = Xlimmode;
        end
    case {2,3}
        for r=1:2
            if ischar(model.getValueAt(startRow,1+r))
                tmp = eval(model.getValueAt(startRow,1+r),'[]');
                if isempty(tmp)
                    oldylim=h.Axesgrid.getylim(startRow+1);
                    awtinvoke(model,'setValueAt(Ljava/lang/Object;II)',java.lang.String(num2str(oldylim(r))),startRow,1+r);
                    return
                else
                    lim(r)=tmp;
                end
            else
                lim(r) = model.getValueAt(startRow,1+r);
            end
        end
        if lim(2)<=lim(1)
            errordlg('The MIN limit must be smaller than the MAX limit','Time Series Tools','modal')
            oldylim=h.Axesgrid.getylim(startRow+1);
            awtinvoke(model,'setValueAt(Ljava/lang/Object;II)',java.lang.String(num2str(oldylim(1))),startRow,2);
            awtinvoke(model,'setValueAt(Ljava/lang/Object;II)',java.lang.String(num2str(oldylim(2))),startRow,3);
            return
        end
        if strcmp(type,'Y')
            h.Axesgrid.setylim(lim,startRow+1);
        else
            h.Axesgrid.setxlim(lim,startRow+1);
        end   
end

%% Send a viewchnage to refeesh absolute x axes time labels
h.AxesGrid.send('viewchange')

function localRmAxes(es,ed,h,thisTab,view)

%% Remove axes 
selRow = thisTab.Handles.AxesGridTable.getSelectedRow+1;
if selRow>0
    view.rmaxes(selRow);
end