% Copyright (c) 2012, Jan Philipp Kruse and Harro Schmeling, Universität Frankfurt
% All rights reserved.
% 
% Redistribution and use in source and binary forms, with or without modification, 
% are permitted provided that the following conditions are met:
% 
% Redistributions of source code must retain the above copyright notice, 
% this list of conditions and the following disclaimer.
% Redistributions in binary form must reproduce the above copyright notice, 
% this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
% 
% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 
% INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 
% IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
% OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
% LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
% WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
% EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

clear all;
clear java;
clear global;
clc
java.lang.System.gc

path([pwd,'/gui/callbacks'],path)
path([pwd,'/gui'],path)
path([pwd,'/general'],path)
path([pwd,'/moduli'],path)
path([pwd,'/visc'],path)

global Mmodels Vmodels;

Mmodels = struct('id',{},...
                'name',{},...
                'betamin',{},...
                'betamax',{},...
                'beta',{},...
                'K_0',{},...
                'mu_0',{},...
                'K_f',{},...
                'rho_0',{},...
                'drho',{},...
                'alpha1',{},'alpha3',{},...
                'kappa',{},...
                'c1i',{},'c1c',{},'c2i',{},'c2c',{},'c3i',{},'c3c',{},...
                'nmax',{},...
                'K_u',{},...
                'K_bar',{},...
                'K_iso',{},...
                'K_r',{},...
                'mu_u',{},...
                'mu_iso',{},...
                'mu_r',{},...
                'nu_u',{},...
                'nu_iso',{},...
                'nu_bar',{},...
                'nu_r',{},...
                'A_u',{},...
                'A_bar',{},...
                'A_iso',{},...
                'rho',{},...
                'v_pu',{},...
                'v_su',{},...
                'ratio_psu',{},...
                'v_pr',{},...
                'v_sr',{},...
                'ratio_psr',{},...
                'unit',{});
            
Vmodels = struct('id',{},...
                'name',{},...
                'betamin',{},...
                'betamax',{},...
                'beta',{},...
                'eta_s0',{},...
                'alpha1',{},'alpha3',{},...
                'kappa',{},...
                'c1',{},'c2',{},'c3',{},...
                'nmax',{},...
                'eta_b',{},...
                'eta_s',{},...
                'nu_r',{},...
                'A_r',{},...
                'unit',{});
            
%%

global mainframe;

mainframe       = javax.swing.JFrame('ModVisc 0.01');

%%

menubar         = javax.swing.JMenuBar();

menu1           = javax.swing.JMenu('File');
menu2           = javax.swing.JMenu('Configuration');
menu3           = javax.swing.JMenu('Help');

menuicon11      = javax.swing.ImageIcon([pwd,'\icons\matlabicon.gif']);
menuicon12      = javax.swing.ImageIcon([pwd,'\icons\knode.png']);
menuicon13      = javax.swing.ImageIcon([pwd,'\icons\exit.png']);

item11          = javax.swing.JMenuItem('save models as *.mat file',menuicon11);
item12          = javax.swing.JMenuItem('save models as *.txt files',menuicon12);
item13          = javax.swing.JMenuItem('exit program',menuicon13);

menu1.add(item11);
menu1.add(item12);
menu1.add(item13);

menubar.add(menu1);
% menubar.add(menu2);
% menubar.add(menu3);

%%

toolbar         = javax.swing.JToolBar;
starticon       = javax.swing.ImageIcon([pwd,'\icons\player_play.png']);
startbutton     = toolbar.add(javax.swing.JButton(starticon));    
startbutton.setToolTipText('start actual model');
ploticon        = javax.swing.ImageIcon([pwd,'\icons\kmplot.png']);
plotbutton      = toolbar.add(javax.swing.JButton(ploticon));    
plotbutton.setToolTipText('plot selected models');
removeicon      = javax.swing.ImageIcon([pwd,'\icons\edittrash.png']);
removebutton    = toolbar.add(javax.swing.JButton(removeicon));    
removebutton.setToolTipText('remove selected models');


mainframe.getContentPane().add(toolbar,java.awt.BorderLayout.NORTH);

%%

tabbedpane      = javax.swing.JTabbedPane(javax.swing.JTabbedPane.TOP);

%%

mpanelmod       = javax.swing.JPanel(java.awt.BorderLayout);
scrollpane1     = javax.swing.JScrollPane(mpanelmod,javax.swing.JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,...
        javax.swing.JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);

tabbedpane.addTab('Moduli',scrollpane1);

%%

mpanelvisc      = javax.swing.JPanel(java.awt.BorderLayout);
scrollpane2     = javax.swing.JScrollPane(mpanelvisc,javax.swing.JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,...
        javax.swing.JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);

tabbedpane.addTab('Viscosities',scrollpane2);

%%

modconfpanel    = javax.swing.JPanel(java.awt.BorderLayout);
mpanelmod.add(modconfpanel,java.awt.BorderLayout.NORTH);

%%

viscconfpanel   = javax.swing.JPanel(java.awt.BorderLayout);
mpanelvisc.add(viscconfpanel,java.awt.BorderLayout.NORTH);

%%

% modconfsubpanel1    = javax.swing.JPanel(java.awt.FlowLayout(java.awt.FlowLayout.LEFT));
modconfsubpanel1    = javax.swing.JPanel(java.awt.GridLayout(2,1));
modconfsubpanel1.setBorder(javax.swing.BorderFactory.createTitledBorder('general configuration'));

modconfsubpanel11   = javax.swing.JPanel(java.awt.FlowLayout(java.awt.FlowLayout.LEFT));
modconfsubpanel12   = javax.swing.JPanel(java.awt.FlowLayout(java.awt.FlowLayout.LEFT));

k0label             = modconfsubpanel11.add(javax.swing.JLabel('<html>K<sub>0</sub> = </html>'));
k0field             = modconfsubpanel11.add(javax.swing.JTextField('0.66',5));

kflabel             = modconfsubpanel11.add(javax.swing.JLabel('<html>, K<sub>f</sub> = </html>'));
kffield             = modconfsubpanel11.add(javax.swing.JTextField('0.2',5));

mu0label            = modconfsubpanel11.add(javax.swing.JLabel('<html>, &mu<sub>0</sub> = </html>'));
mu0field            = modconfsubpanel11.add(javax.swing.JTextField('0.4',5));

phiminlabel         = modconfsubpanel11.add(javax.swing.JLabel('<html>, &phi<sub>min</sub> (&ne 0) = </html>'));
phiminfield         = modconfsubpanel11.add(javax.swing.JTextField('10^-6',5));
phimaxlabel         = modconfsubpanel11.add(javax.swing.JLabel('<html>, &phi<sub>max</sub> = </html>'));
phimaxfield         = modconfsubpanel11.add(javax.swing.JTextField('0.2',5));

phinumlabel         = modconfsubpanel11.add(javax.swing.JLabel('<html>, &phi<sub>num</sub> (number of values for &phi) = </html>'));
phinumfield         = modconfsubpanel11.add(javax.swing.JTextField('10^3',5));

nmaxlabel           = modconfsubpanel11.add(javax.swing.JLabel('<html>, n<sub>max</sub> (maximum number of iterations) = </html>'));
nmaxfield           = modconfsubpanel11.add(javax.swing.JTextField('10^3',5));

unitlabel           = modconfsubpanel11.add(javax.swing.JLabel('<html>, unit = </html>'));
% unitfield           = modconfsubpanel11.add(javax.swing.JTextField('M Pa',5));
unitbox             = javax.swing.JComboBox;

unitbox.addItem('<html>G<b>Pa</b></html>');
unitbox.addItem('<html>M<b>Pa</b></html>');
unitbox.addItem('<html>k<b>Pa</b></html>');
unitbox.addItem('<html>h<b>Pa</b></html>');
unitbox.addItem('<html>d<b>Pa</b></html>');
unitbox.addItem('<html><b>Pa</b></html>');
unitbox.addItem('<html>m<b>Pa</b></html>');
unitbox.addItem('<html>&mu<b>Pa</b></html>');
unitbox.addItem('<html>n<b>Pa</b></html>');
unitbox.addItem('<html>M<b>bar</b></html>');
unitbox.addItem('<html>k<b>bar</b></html>');
unitbox.addItem('<html><b>bar</b></html>');
unitbox.addItem('<html>m<b>bar</b></html>');
unitbox.addItem('<html>&mu<b>bar</b></html>');

unitbox.setSelectedIndex(1);
modconfsubpanel11.add(unitbox);

rho0label           = modconfsubpanel12.add(javax.swing.JLabel('<html><b>densities for v<sub>p</sub> and v<sub>s</sub>:</b> &nbsp &nbsp &rho<sub>0</sub> = </html>'));
rho0field           = modconfsubpanel12.add(javax.swing.JTextField('3300',5));
rho0label2          = modconfsubpanel12.add(javax.swing.JLabel('<html>kg m<sup>-3</sup></html>'));

drholabel           = modconfsubpanel12.add(javax.swing.JLabel('<html>, &Delta &rho = </html>'));
drhofield           = modconfsubpanel12.add(javax.swing.JTextField('300',5));
drholabel2          = modconfsubpanel12.add(javax.swing.JLabel('<html>kg m<sup>-3</sup></html>'));


modconfsubpanel1.add(modconfsubpanel11);
modconfsubpanel1.add(modconfsubpanel12);
modconfpanel.add(modconfsubpanel1,java.awt.BorderLayout.NORTH);

%%

viscconfsubpanel1   = javax.swing.JPanel(java.awt.FlowLayout(java.awt.FlowLayout.LEFT));
viscconfsubpanel1.setBorder(javax.swing.BorderFactory.createTitledBorder('general configuration'));

etab0label          = viscconfsubpanel1.add(javax.swing.JLabel('<html>&eta<sub>b0</sub> = &infin</html>'));

etabflabel          = viscconfsubpanel1.add(javax.swing.JLabel('<html>, &eta<sub>bf</sub> = 0</html>'));

etas0label          = viscconfsubpanel1.add(javax.swing.JLabel('<html>, &eta<sub>s0</sub> = </html>'));
etas0field          = viscconfsubpanel1.add(javax.swing.JTextField('10^18',5));

phiminlabel2        = viscconfsubpanel1.add(javax.swing.JLabel('<html>, &phi<sub>min</sub> (&ne 0) = </html>'));
phiminfield2        = viscconfsubpanel1.add(javax.swing.JTextField('10^-6',5));
phimaxlabel2        = viscconfsubpanel1.add(javax.swing.JLabel('<html>, &phi<sub>max</sub> = </html>'));
phimaxfield2        = viscconfsubpanel1.add(javax.swing.JTextField('0.2',5));

phinumlabel2        = viscconfsubpanel1.add(javax.swing.JLabel('<html>, &phi<sub>num</sub> (number of values for &phi) = </html>'));
phinumfield2        = viscconfsubpanel1.add(javax.swing.JTextField('10^3',5));

nmaxlabel2          = viscconfsubpanel1.add(javax.swing.JLabel('<html>, n<sub>max</sub> (maximum number of iterations) = </html>'));
nmaxfield2          = viscconfsubpanel1.add(javax.swing.JTextField('10^3',5));

unitlabel2          = viscconfsubpanel1.add(javax.swing.JLabel('<html>, unit = </html>'));
unitfield2          = viscconfsubpanel1.add(javax.swing.JTextField('Pa s',5));
unitfield2.setEditable(0);
viscconfpanel.add(viscconfsubpanel1,java.awt.BorderLayout.NORTH);

%%

modconfsubpanel2    = javax.swing.JPanel(java.awt.FlowLayout(java.awt.FlowLayout.LEFT));
modconfsubpanel2.setBorder(javax.swing.BorderFactory.createTitledBorder('geometry selection of the melt phase'));

global filmcheck tubecheck sphecheck;

filmcheck           = modconfsubpanel2.add(javax.swing.JCheckBox('films'));
tubecheck           = modconfsubpanel2.add(javax.swing.JCheckBox('tubes'));
sphecheck           = modconfsubpanel2.add(javax.swing.JCheckBox('spheroids'));
sphecheck.setSelected(1)

namelabel           = javax.swing.JLabel('model name = ');
namefield           = javax.swing.JTextField('model 1',20);
modconfsubpanel2.add(namelabel);
modconfsubpanel2.add(namefield);
modconfpanel.add(modconfsubpanel2,java.awt.BorderLayout.CENTER);

%% 

global filmcheck2 tubecheck2 sphecheck2;

viscconfsubpanel2   = javax.swing.JPanel(java.awt.FlowLayout(java.awt.FlowLayout.LEFT));
viscconfsubpanel2.setBorder(javax.swing.BorderFactory.createTitledBorder('geometry selection of the melt phase'));

filmcheck2          = viscconfsubpanel2.add(javax.swing.JCheckBox('films'));
tubecheck2          = viscconfsubpanel2.add(javax.swing.JCheckBox('tubes'));
sphecheck2          = viscconfsubpanel2.add(javax.swing.JCheckBox('spheroids'));
sphecheck2.setSelected(1)

namelabel2          = javax.swing.JLabel('model name = ');
namefield2          = javax.swing.JTextField('model 1',20);
viscconfsubpanel2.add(namelabel2);
viscconfsubpanel2.add(namefield2);
viscconfpanel.add(viscconfsubpanel2,java.awt.BorderLayout.CENTER);

%% 

grayrgb             = modconfpanel.getBackground.getRGB;

modconfsubpanel3    = javax.swing.JPanel(java.awt.GridLayout(1,3));
modconfsubpanel3.setBorder(javax.swing.BorderFactory.createTitledBorder('configuration for geometries of the melt phase (sum of fraction has to be one)'));

modconffilmpanel    = modconfsubpanel3.add(javax.swing.JPanel(java.awt.GridLayout(3,1)));
modconffilmpanel.setBorder(javax.swing.BorderFactory.createTitledBorder('films configuration'));

modfilmpanel1       = modconffilmpanel.add(javax.swing.JPanel(java.awt.FlowLayout(java.awt.FlowLayout.LEFT)));
alpha1label         = modfilmpanel1.add(javax.swing.JLabel('<html>&alpha<sub>1</sub> (aspect ratio, 0 &lt &alpha<sub>1</sub> &le 0.1) = </html>'));
alpha1field         = modfilmpanel1.add(javax.swing.JTextField('0.01',5));
alpha1field.setEnabled(0);

global c1ifield c1cfield c2ifield c2cfield c3ifield c3cfield;

modfilmpanel2       = modconffilmpanel.add(javax.swing.JPanel(java.awt.FlowLayout(java.awt.FlowLayout.LEFT)));
c1ilabel            = modfilmpanel2.add(javax.swing.JLabel('<html>c<sub>1i</sub> (isolated fraction, value between 0 and 1) = </html>'));
c1ifield            = modfilmpanel2.add(javax.swing.JTextField('0',5));
c1ifield.setEnabled(0);

modfilmpanel3       = modconffilmpanel.add(javax.swing.JPanel(java.awt.FlowLayout(java.awt.FlowLayout.LEFT)));
c1clabel            = modfilmpanel3.add(javax.swing.JLabel('<html>c<sub>1c</sub> (connected fraction, value between 0 and 1) = </html>'));
c1cfield            = modfilmpanel3.add(javax.swing.JTextField('0',5));
c1cfield.setEnabled(0);

modconftubepanel    = modconfsubpanel3.add(javax.swing.JPanel(java.awt.GridLayout(3,1)));
modconftubepanel.setBorder(javax.swing.BorderFactory.createTitledBorder('tubes configuration'));

modtubepanel1       = modconftubepanel.add(javax.swing.JPanel(java.awt.FlowLayout(java.awt.FlowLayout.LEFT)));
kappalabel          = modtubepanel1.add(javax.swing.JLabel('<html>&kappa (parameter describing shape of tubular cross-sections) = </html>'));
kappafield          = modtubepanel1.add(javax.swing.JTextField('0',5));
kappafield.setEnabled(0);

modtubepanel2       = modconftubepanel.add(javax.swing.JPanel(java.awt.FlowLayout(java.awt.FlowLayout.LEFT)));
c2ilabel            = modtubepanel2.add(javax.swing.JLabel('<html>c<sub>2i</sub> (isolated fraction, value between 0 and 1) = </html>'));
c2ifield            = modtubepanel2.add(javax.swing.JTextField('0',5));
c2ifield.setEnabled(0);

modtubepanel3       = modconftubepanel.add(javax.swing.JPanel(java.awt.FlowLayout(java.awt.FlowLayout.LEFT)));
c2clabel            = modtubepanel3.add(javax.swing.JLabel('<html>c<sub>2c</sub> (connected fraction, value between 0 and 1) = </html>'));
c2cfield            = modtubepanel3.add(javax.swing.JTextField('0',5));
c2cfield.setEnabled(0);

modconfsphepanel    = modconfsubpanel3.add(javax.swing.JPanel(java.awt.GridLayout(3,1)));
modconfsphepanel.setBorder(javax.swing.BorderFactory.createTitledBorder('spheroids configuration'));
modconfsphepanel.setBackground(java.awt.Color.RED);

modsphepanel1       = modconfsphepanel.add(javax.swing.JPanel(java.awt.FlowLayout(java.awt.FlowLayout.LEFT)));
alpha3label         = modsphepanel1.add(javax.swing.JLabel('<html>&alpha<sub>3</sub> (aspect ratio, 0 &lt &alpha<sub>3</sub> &le 1) = </html>'));
alpha3field         = modsphepanel1.add(javax.swing.JTextField('0.1',5));

modsphepanel2       = modconfsphepanel.add(javax.swing.JPanel(java.awt.FlowLayout(java.awt.FlowLayout.LEFT)));
c3ilabel            = modsphepanel2.add(javax.swing.JLabel('<html>c<sub>3i</sub> (isolated fraction, value between 0 and 1) = </html>'));
c3ifield            = modsphepanel2.add(javax.swing.JTextField('0',5));

modsphepanel3       = modconfsphepanel.add(javax.swing.JPanel(java.awt.FlowLayout(java.awt.FlowLayout.LEFT)));
c3clabel            = modsphepanel3.add(javax.swing.JLabel('<html>c<sub>3c</sub> (connected fraction, value between 0 and 1) = </html>'));
c3cfield            = modsphepanel3.add(javax.swing.JTextField('1',5));

modconfpanel.add(modconfsubpanel3,java.awt.BorderLayout.SOUTH);

%%

global c1field2 c2field2 c3field2;

grayrgb2            = viscconfpanel.getBackground.getRGB;

viscconfsubpanel3   = javax.swing.JPanel(java.awt.GridLayout(1,3));
viscconfsubpanel3.setBorder(javax.swing.BorderFactory.createTitledBorder('configuration for geometries of the melt phase (sum of fraction has to be one)'));

viscconffilmpanel   = viscconfsubpanel3.add(javax.swing.JPanel(java.awt.GridLayout(3,1)));
viscconffilmpanel.setBorder(javax.swing.BorderFactory.createTitledBorder('films configuration'));

viscfilmpanel1      = viscconffilmpanel.add(javax.swing.JPanel(java.awt.FlowLayout(java.awt.FlowLayout.LEFT)));
alpha1label2        = viscfilmpanel1.add(javax.swing.JLabel('<html>&alpha<sub>1</sub> (aspect ratio, 0 &lt &alpha<sub>1</sub> &le 0.1) = </html>'));
alpha1field2        = viscfilmpanel1.add(javax.swing.JTextField('0.01',5));
alpha1field2.setEnabled(0);

viscfilmpanel2      = viscconffilmpanel.add(javax.swing.JPanel(java.awt.FlowLayout(java.awt.FlowLayout.LEFT)));
c1label2            = viscfilmpanel2.add(javax.swing.JLabel('<html>c<sub>1</sub> (fraction, value between 0 and 1) = </html>'));
c1field2            = viscfilmpanel2.add(javax.swing.JTextField('0',5));
c1field2.setEnabled(0);

viscconftubepanel   = viscconfsubpanel3.add(javax.swing.JPanel(java.awt.GridLayout(3,1)));
viscconftubepanel.setBorder(javax.swing.BorderFactory.createTitledBorder('tubes configuration'));

visctubepanel1      = viscconftubepanel.add(javax.swing.JPanel(java.awt.FlowLayout(java.awt.FlowLayout.LEFT)));
kappalabel2         = visctubepanel1.add(javax.swing.JLabel('<html>&kappa (parameter describing shape of tubular cross-sections) = </html>'));
kappafield2         = visctubepanel1.add(javax.swing.JTextField('0',5));
kappafield2.setEnabled(0);

visctubepanel2      = viscconftubepanel.add(javax.swing.JPanel(java.awt.FlowLayout(java.awt.FlowLayout.LEFT)));
c2label2            = visctubepanel2.add(javax.swing.JLabel('<html>c<sub>2</sub> (fraction, value between 0 and 1) = </html>'));
c2field2            = visctubepanel2.add(javax.swing.JTextField('0',5));
c2field2.setEnabled(0);

viscconfsphepanel   = viscconfsubpanel3.add(javax.swing.JPanel(java.awt.GridLayout(3,1)));
viscconfsphepanel.setBorder(javax.swing.BorderFactory.createTitledBorder('spheroids configuration'));
viscconfsphepanel.setBackground(java.awt.Color.RED);

viscsphepanel1      = viscconfsphepanel.add(javax.swing.JPanel(java.awt.FlowLayout(java.awt.FlowLayout.LEFT)));
alpha3label2        = viscsphepanel1.add(javax.swing.JLabel('<html>&alpha<sub>3</sub> (aspect ratio, 0 &lt &alpha<sub>3</sub> &le 1) = </html>'));
alpha3field2        = viscsphepanel1.add(javax.swing.JTextField('1',5));

viscsphepanel2      = viscconfsphepanel.add(javax.swing.JPanel(java.awt.FlowLayout(java.awt.FlowLayout.LEFT)));
c3label2            = viscsphepanel2.add(javax.swing.JLabel('<html>c<sub>3</sub> (fraction, value between 0 and 1) = </html>'));
c3field2            = viscsphepanel2.add(javax.swing.JTextField('1',5));

viscconfpanel.add(viscconfsubpanel3,java.awt.BorderLayout.SOUTH);

%%

filmhand            = filmcheck.handle;
filmlis             = handle.listener(filmhand,'ActionPerformed',{@checkboxMCallback,grayrgb,modconffilmpanel,alpha1field,c1ifield,c1cfield});
tubehand            = tubecheck.handle;
tubelis             = handle.listener(tubehand,'ActionPerformed',{@checkboxMCallback,grayrgb,modconftubepanel,kappafield,c2ifield,c2cfield});
sphehand            = sphecheck.handle;
sphelis             = handle.listener(sphehand,'ActionPerformed',{@checkboxMCallback,grayrgb,modconfsphepanel,alpha3field,c3ifield,c3cfield});

%%

filmhand2            = filmcheck2.handle;
filmlis2             = handle.listener(filmhand2,'ActionPerformed',{@checkboxVCallback,grayrgb2,viscconffilmpanel,alpha1field2,c1field2});
tubehand2            = tubecheck2.handle;
tubelis2             = handle.listener(tubehand2,'ActionPerformed',{@checkboxVCallback,grayrgb2,viscconftubepanel,kappafield2,c2field2});
sphehand2            = sphecheck2.handle;
sphelis2             = handle.listener(sphehand2,'ActionPerformed',{@checkboxVCallback,grayrgb2,viscconfsphepanel,alpha3field2,c3field2});

%%

% modplotpanel       = javax.swing.JPanel(java.awt.FlowLayout(java.awt.FlowLayout.LEFT));
modplotpanel       = javax.swing.JPanel(java.awt.GridLayout(2,1));
modplotpanel.setBorder(javax.swing.BorderFactory.createTitledBorder('plot options'));

modplotpanel1       = javax.swing.JPanel(java.awt.FlowLayout(java.awt.FlowLayout.LEFT));
modplotpanel2       = javax.swing.JPanel(java.awt.FlowLayout(java.awt.FlowLayout.LEFT));

modplotKucheck      = javax.swing.JCheckBox('<html>plot K<sub>u</sub> (unrelaxed bulk-modulus)</html>');
modplotpanel1.add(modplotKucheck);
modplotmuucheck     = javax.swing.JCheckBox('<html>plot &mu<sub>u</sub> (unrelaxed shear-modulus)</html>');
modplotpanel1.add(modplotmuucheck);
modplotnuucheck     = javax.swing.JCheckBox('<html>plot &nu<sub>u</sub> (unrelaxed poisson-ratio)</html>');
modplotpanel1.add(modplotnuucheck);
modplotKrcheck      = javax.swing.JCheckBox('<html>plot K<sub>r</sub> (relaxed bulk-modulus)</html>');
modplotpanel1.add(modplotKrcheck);
modplotmurcheck     = javax.swing.JCheckBox('<html>plot &mu<sub>r</sub> (relaxed shear-modulus)</html>');
modplotpanel1.add(modplotmurcheck);
modplotnurcheck     = javax.swing.JCheckBox('<html>plot &nu<sub>r</sub> (relaxed poisson-ratio)</html>');
modplotpanel1.add(modplotnurcheck);

modplotvpucheck     = javax.swing.JCheckBox('<html>plot v<sub>pu</sub> (unrelaxed p-wave velocity)</html>');
modplotpanel2.add(modplotvpucheck);
modplotvsucheck     = javax.swing.JCheckBox('<html>plot v<sub>su</sub> (unrelaxed s-wave velocity)</html>');
modplotpanel2.add(modplotvsucheck);
modplotvpvsucheck   = javax.swing.JCheckBox('<html>plot v<sub>pu</sub>/v<sub>su</sub> (unrelaxed velocity-ratio)</html>');
modplotpanel2.add(modplotvpvsucheck);
modplotvprcheck     = javax.swing.JCheckBox('<html>plot v<sub>pr</sub> (relaxed p-wave velocity)</html>');
modplotpanel2.add(modplotvprcheck);
modplotvsrcheck     = javax.swing.JCheckBox('<html>plot v<sub>sr</sub> (relaxed s-wave velocity)</html>');
modplotpanel2.add(modplotvsrcheck);
modplotvpvsrcheck   = javax.swing.JCheckBox('<html>plot v<sub>pr</sub>/v<sub>sr</sub> (relaxed velocity-ratio)</html>');
modplotpanel2.add(modplotvpvsrcheck);

modplotpanel.add(modplotpanel1);
modplotpanel.add(modplotpanel2);

mpanelmod.add(modplotpanel,java.awt.BorderLayout.CENTER);

%%

viscplotpanel       = javax.swing.JPanel(java.awt.FlowLayout(java.awt.FlowLayout.LEFT));
viscplotpanel.setBorder(javax.swing.BorderFactory.createTitledBorder('plot options'));

viscplotuntillabel  = javax.swing.JLabel('<html>plot until &eta<sub>b</sub> resp. &eta<sub>s</sub> &le &eta<sub>b0</sub> resp. &eta<sub>s0</sub> multiplied by </html>');
viscplotuntilfield  = javax.swing.JTextField('10^-5',10);
viscplotuntillabel2 = javax.swing.JLabel('<html>&frasl</html>');
viscplotpanel.add(viscplotuntillabel);
viscplotpanel.add(viscplotuntilfield);
viscplotpanel.add(viscplotuntillabel2);

viscplotetabcheck   = javax.swing.JCheckBox('<html>plot &eta<sub>b</sub> (bulk-viscosity)</html>');
viscplotpanel.add(viscplotetabcheck);
viscplotetascheck   = javax.swing.JCheckBox('<html>plot &eta<sub>s</sub> (shear-viscosity)</html>');
viscplotpanel.add(viscplotetascheck);
viscplotetabscheck  = javax.swing.JCheckBox('<html>plot &eta<sub>b</sub> &amp &eta<sub>s</sub> in one plot (viscosities)</html>');
viscplotpanel.add(viscplotetabscheck);
viscplotnucheck     = javax.swing.JCheckBox('<html>plot &nu (poisson-ratio)</html>');
viscplotpanel.add(viscplotnucheck);

mpanelvisc.add(viscplotpanel,java.awt.BorderLayout.CENTER);

%%

tablemodel          = javax.swing.table.DefaultTableModel;

tablecolnames       = cell(1,19);

tablecolnames{1}    = 'model name';
tablecolnames{2}    = '<html>&beta<sub>min</sub></html>';
tablecolnames{3}    = '<html>&beta<sub>max</sub></html>';
tablecolnames{4}    = '<html>K<sub>0</sub></html>';
tablecolnames{5}    = '<html>K<sub>f</sub></html>';
tablecolnames{6}    = '<html>&mu<sub>0</sub></html>';
tablecolnames{7}    = '<html>&rho<sub>0</sub></html>';
tablecolnames{8}    = '<html>&Delta &rho</html>';
tablecolnames{9}    = '<html>&alpha<sub>1</sub></html>';
tablecolnames{10}    = '<html>&kappa</html>';
tablecolnames{11}    = '<html>&alpha<sub>3</sub></html>';
tablecolnames{12}   = '<html>c<sub>1i</sub></html>';
tablecolnames{13}   = '<html>c<sub>1c</sub></html>';
tablecolnames{14}   = '<html>c<sub>2i</sub></html>';
tablecolnames{15}   = '<html>c<sub>2c</sub></html>';
tablecolnames{16}   = '<html>c<sub>3i</sub></html>';
tablecolnames{17}   = '<html>c<sub>3c</sub></html>';
tablecolnames{18}   = '<html>n<sub>max</sub></html>';
tablecolnames{19}   = '<html>unit</html>';

for i=0:18
    tablemodel.addColumn(tablecolnames{i+1});
end

datatable           = javax.swing.JTable(tablemodel);
datatable.setSelectionMode(javax.swing.ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);

tablescrollpane     = javax.swing.JScrollPane(datatable,javax.swing.JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,...
        javax.swing.JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
mpanelmod.add(tablescrollpane,java.awt.BorderLayout.SOUTH);

% jch         = datatable.handle.classhandle;
% for index = 1:numel(jch.Events), disp(jch.Events(index).Name); end

%%

tablemodel2         = javax.swing.table.DefaultTableModel;

tablecolnames2      = cell(1,12);

tablecolnames2{1}   = 'model name';
tablecolnames2{2}   = '<html>&beta<sub>min</sub></html>';
tablecolnames2{3}   = '<html>&beta<sub>max</sub></html>';
tablecolnames2{4}   = '<html>&eta<sub>s0</sub></html>';
tablecolnames2{5}   = '<html>&alpha<sub>1</sub></html>';
tablecolnames2{6}   = '<html>&kappa</html>';
tablecolnames2{7}   = '<html>&alpha<sub>3</sub></html>';
tablecolnames2{8}   = '<html>c<sub>1</sub></html>';
tablecolnames2{9}   = '<html>c<sub>2</sub></html>';
tablecolnames2{10}  = '<html>c<sub>3</sub></html>';
tablecolnames2{11}  = '<html>n<sub>max</sub></html>';
tablecolnames2{12}  = '<html>unit</html>';

for i=0:11
    tablemodel2.addColumn(tablecolnames2{i+1});
end

datatable2          = javax.swing.JTable(tablemodel2);
datatable2.setSelectionMode(javax.swing.ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);

tablescrollpane2    = javax.swing.JScrollPane(datatable2,javax.swing.JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,...
        javax.swing.JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
mpanelvisc.add(tablescrollpane2,java.awt.BorderLayout.SOUTH);

%%

starthand           = startbutton.handle;
startlis            = handle.listener(starthand,'ActionPerformed',{@startCallback,tabbedpane,namefield,k0field,kffield,mu0field,rho0field,drhofield,...
    phiminfield,phimaxfield,phinumfield,nmaxfield,unitbox,alpha1field,c1ifield,c1cfield,kappafield,c2ifield,c2cfield,alpha3field,c3ifield,c3cfield,datatable,...
    namefield2,etas0field,phiminfield2,phimaxfield2,phinumfield2,nmaxfield2,...
    unitfield2,alpha1field2,c1field2,kappafield2,c2field2,alpha3field2,c3field2,datatable2});

plothand            = plotbutton.handle;
plotlis             = handle.listener(plothand,'ActionPerformed',{@plotCallback,tabbedpane,...
    datatable,modplotKucheck,modplotmuucheck,modplotnuucheck,modplotKrcheck,modplotmurcheck,modplotnurcheck,...
    datatable2,viscplotetabcheck,viscplotetascheck,viscplotetabscheck,viscplotnucheck,viscplotuntilfield,...
    modplotvpucheck,modplotvsucheck,modplotvpvsucheck,modplotvprcheck,modplotvsrcheck,modplotvpvsrcheck});

delhand             = removebutton.handle;
dellis              = handle.listener(delhand,'ActionPerformed',{@removeCallback,tabbedpane,datatable,datatable2,namefield,namefield2});

item11hand          = item11.handle;
item11lis           = handle.listener(item11hand,'ActionPerformed',{@saveMATCallback,tabbedpane,datatable,datatable2});

item12hand          = item12.handle;
item12lis           = handle.listener(item12hand,'ActionPerformed',{@saveTXTCallback,tabbedpane,datatable,datatable2});

item13hand          = item13.handle;
item13lis           = handle.listener(item13hand,'ActionPerformed',{@exitCallback});
%%

mainframe.getContentPane().add(tabbedpane,java.awt.BorderLayout.CENTER);
env = java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment();

mainframe.setJMenuBar(menubar);
mainframe.setVisible(1);
mainframe.pack();
mainframe.setExtendedState(javax.swing.JFrame.MAXIMIZED_BOTH);
mainframe.setDefaultLookAndFeelDecorated(1)
mainframe.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);