% Heat transfer in 1D
% Version 1.1

com.femlab.controls.FlLocale.showMissingResource(false);
f1=frame('COMSOL Multiphysics - Heat transfer in 1D');

p1=panel;
p1.setFill('horizontal');
p1.add(label('Line length [m]:'),1,1);
p1.add(textfield(8,'text','1','tag','length'),1,2);
p1.addVSeparator(4,2,2);
p1.add(button('Create Geometry','tag','geombutton'),3,2,'horizontal');
p1.addBorder('Geometry');

p2=panel;
p2.add(label('Max element size [m]:'),1,1);
p2.add(textfield(8,'text','0.1','tag','meshsize'),1,2);
p2.addVSeparator(4,2,1);
p2.add(button('Generate Mesh','tag','meshbutton'),3,2,'horizontal');
p2.addBorder('Mesh');

p3=panel;
p3.setFill('horizontal');
p3.add(label('Temperature left [K]:'),1,1);
p3.add(label('Temperature right [K]:'),2,1);
p3.add(label('Conductivity [W/(m,K)]:'),3,1);
p3.add(label('<html>Heat source [W/m<sup>3</sup>]:'),4,1);
p3.add(label('Element order:'),5,1);
p3.add(textfield(12,'text','0','tag','left'),1,2);
p3.add(textfield(12,'text','10','tag','right'),2,2);
p3.add(textfield(12,'text','400','tag','cond'),3,2);
p3.add(textfield(12,'text','2e5*x','tag','source'),4,2);
p3.add(combobox('items',{'Linear','Second order'},'tag','meshorder'),5,2,'horizontal');
p3.addVSeparator(4,4,2);
p3.add(button('Solve','tag','solvebutton'),6,2);
p3.addBorder('Solve');
p3.get('meshorder').setSelectedIndex(2);

p4=panel;
p4.setFill('horizontal');
p4.add(label('Plot quantity:'),1,1);
p4.add(combobox('items',{'Temperature','Heat Flux'},'tag','plots'),1,2);
p4.addVSeparator(4,2,1);
p4.add(button('Plot','tag','plotbutton'),3,2);
p4.addBorder('Plot');

p5=panel;
p5.setFill('horizontal');
p5.add(label('Default values:'),1,1);
p5.addVSeparator(4,2,1);
p5.add(button('Default','tag','defbutton'),1,2);
p5.addBorder('Default');

logo=panel;
logo.add(label('tag','image','image',imageicon(which('logo.GIF'))),1,1);

left=panel;
left.add(p1,1,1,'horizontal');
left.add(p2,2,1,'horizontal');
left.add(p3,3,1,'horizontal');
left.add(p4,4,1,'horizontal');
left.add(p5,5,1,'horizontal');
left.add(logo,6,1,'horizontal');

pref=left.getPreferredSize; 
left.setMinimumSize(pref(1),pref(2));

% Add left panel to the left and an axes to the right 
f1.add(left,1,1); 
f1.setWeight(1e6,1e6); 
f1.add(axes('tag','axis','size',[500 300]),1,2,'both'); 
f1.resetWeight;

f1.get('geombutton').addActionListener('gui1_al');
f1.get('meshbutton').addActionListener('gui1_al');
f1.get('solvebutton').addActionListener('gui1_al');
f1.get('plotbutton').addActionListener('gui1_al');
f1.get('defbutton').addActionListener('gui1_al');

f1.show;

gui1_al(struct('source',{f1.get('defbutton')},'parent',{f1}));

