00001 package testbench;
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 import java.awt.BorderLayout;
00033 import java.awt.GridLayout;
00034 import java.awt.event.ActionEvent;
00035 import java.awt.event.ActionListener;
00036 import java.awt.image.renderable.ParameterBlock;
00037 import java.net.MalformedURLException;
00038 import java.net.URL;
00039
00040 import javax.media.jai.JAI;
00041 import javax.media.jai.PlanarImage;
00042 import javax.swing.JButton;
00043 import javax.swing.JLabel;
00044 import javax.swing.JPanel;
00045 import javax.swing.border.EmptyBorder;
00046
00047 import commandline.ImageTools.ImageDisplay;
00048
00049 public class Arithmetic extends JPanel
00050 implements ActionListener {
00051
00052 private PlanarImage src1 = null;
00053 private PlanarImage src2 = null;
00054 private ImageDisplay ic1 = null;
00055 private ImageDisplay ic2 = null;
00056 private ImageDisplay ic3 = null;
00057 private JButton b1;
00058 private JButton b2;
00059 private JButton b3;
00060 private JButton b4;
00061
00062 public Arithmetic(String im1, String im2) {
00063 super(true);
00064 setLayout(new BorderLayout());
00065
00066
00067
00068
00069
00070 try
00071 {
00072 src1 = JAI.create ( "url", new URL (im1) );
00073 src2 = JAI.create ( "url", new URL (im2) );
00074 }
00075 catch (MalformedURLException e)
00076 { return; }
00077 catch (Exception e) {
00078 System.err.println("couldn't create JAI Image Arithmetic");
00079 }
00080
00081
00082 Byte[] bandValues = new Byte[3];
00083 bandValues[0] = new Byte((byte)2);
00084 bandValues[1] = new Byte((byte)2);
00085 bandValues[2] = new Byte((byte)2);
00086
00087
00088 ParameterBlock pb = new ParameterBlock();
00089 pb.add((float)src2.getWidth());
00090 pb.add((float)src2.getHeight());
00091 pb.add(bandValues);
00092 PlanarImage temp = JAI.create("constant", pb, null);
00093
00094 pb = new ParameterBlock();
00095 pb.addSource(src2);
00096 pb.addSource(temp);
00097
00098 src2 = JAI.create("add", pb, null);
00099
00100 ic1 = new ImageDisplay(src1);
00101 ic2 = new ImageDisplay(src2);
00102
00103 ic3 = new ImageDisplay(src1.getWidth(),
00104 src1.getHeight());
00105
00106
00107 JPanel imagePanel = new JPanel();
00108 imagePanel.setLayout(new GridLayout(3,1,0,0));
00109
00110 imagePanel.add(ic1);
00111 imagePanel.add(ic2);
00112 imagePanel.add(ic3);
00113
00114 add(imagePanel, BorderLayout.CENTER);
00115
00116
00117 JPanel panel = new JPanel();
00118 panel.setLayout(new GridLayout(1,4,4,4));
00119 panel.setBorder(new EmptyBorder(10,10,10,10));
00120
00121 b1 = new JButton("Add");
00122 b2 = new JButton("Subtract");
00123 b3 = new JButton("Multiply");
00124 b4 = new JButton("Divide");
00125
00126 b1.addActionListener(this);
00127 b2.addActionListener(this);
00128 b3.addActionListener(this);
00129 b4.addActionListener(this);
00130
00131 panel.add(b1);
00132 panel.add(b2);
00133 panel.add(b3);
00134 panel.add(b4);
00135 add(panel, BorderLayout.SOUTH);
00136
00137
00138 add(new JLabel(" "), BorderLayout.WEST);
00139 add(new JLabel(" "), BorderLayout.EAST);
00140 }
00141
00142 public void actionPerformed(ActionEvent e) {
00143 PlanarImage target = null;
00144 JButton b = (JButton)e.getSource();
00145 ParameterBlock pb = new ParameterBlock();
00146 pb.addSource(src1);
00147 pb.addSource(src2);
00148
00149 if ( b == b1 ) {
00150 target = JAI.create("add", pb, null);
00151 } else if ( b == b2 ) {
00152 target = JAI.create("subtract", pb, null);
00153 } else if ( b == b3 ) {
00154 target = JAI.create("multiply", pb, null);
00155 } else if ( b == b4 ) {
00156 target = JAI.create("divide", pb, null);
00157 }
00158
00159 ic3.set(target);
00160 }
00161 }