<HTML>
<HEAD><TITLE>File list</TITLE></HEAD>
<%@ page import="java.io.*,javax.media.jai.*"%>
<jsp:useBean id="list" scope="session" class="viewer.ListImagesBean" />
<%String imageDir = (String)request.getAttribute("imageDir");
  if(imageDir!= null)session.putValue("imageDir", imageDir);
  else imageDir= (String)session.getValue("imageDir");
  String fileList[] = list.listFiles(imageDir);
  //Compute a random file anme
  double numd = Math.random();
  int num = Math.round((float)(numd*1000));
  String filename = "readfile"+Integer.toString(num)+".jpg";
  String oldfile = (String)session.getValue("tempfile");
  if(oldfile != null) {
     try {
     String tp = application.getRealPath(File.separator);
     File fl = new File(tp+File.separator+oldfile);
     fl.delete();
    } catch(Exception e){}
  }
  session.putValue("tempfile", filename);
%>

<jsp:useBean id="manip" scope="session" class="viewer.JAIManipBean" />
<%
  String img = request.getParameter("images");
  if((img == null)&& (fileList[0] !=null)) img = fileList[0];
  String rot = request.getParameter("rotAngle");
  if(rot == null) rot = "0";
  String mag = request.getParameter("magFactor");
  if(mag == null) mag = "100";
  double magFactor = 0.0, rotAngle = 0.0;
  try {
     rotAngle = Math.toRadians((Double.valueOf(rot)).doubleValue());
     manip.setRotationAngle(rotAngle);
     } catch(Exception e) {}
  try{
     magFactor = (Integer.valueOf(mag)).intValue()/100.0;
     manip.setMagFactor(magFactor);
  } catch(Exception e) {}
  
  //Temp file to write the resulting image
  String temppath = application.getRealPath(File.separator);
  FileOutputStream out1 = new FileOutputStream(temppath+filename);
  if((imageDir!=null) && (img != null)) manip.manipAndPost(imageDir+File.separator+img, out1);
%>

<% StringBuffer reqUrl = HttpUtils.getRequestURL(request);%>
<FORM ACTION=<%=reqUrl %>  method="POST">
<BODY>
<TABLE border=1 align= left>
<TR><TH>ID</TH><TH>Image</TH></TR>
<%
for(int i=0;i<fileList.length;i++) {%>
<tr><td>
<%=i %>
</td>
<td>
<% String checked = ""; 
   if(img.equals(fileList[i])) checked ="CHECKED";
%>
<INPUT TYPE="RADIO" name="images" value= <%=fileList[i]%> <%=checked%>
 ><%=fileList[i]%>
</td></tr>
<% }%>
</TABLE>
 Rotate: <INPUT TYPE="TEXT" name="rotAngle" value=<%=rot%> >degrees  <BR>
 Zoom  : <INPUT TYPE="TEXT" name="magFactor" value=<%=mag%>  >percent <BR><BR>
<INPUT TYPE= "SUBMIT" VALUE="DISPLAY">
<IMG SRC=/examples/<%=filename%> align=right >
<FORM>
</BODY></HTML>