/* A basic extension of the java.applet.Applet class */ import java.awt.*; import java.applet.*; import java.net.*; import java.awt.image.*; import symantec.itools.multimedia.ImageViewer; import symantec.itools.awt.BorderPanel; import symantec.itools.awt.shape.Square; import symantec.itools.awt.shape.Rect; import symantec.itools.awt.util.ToolBarPanel; import symantec.itools.awt.util.ToolBarSpacer; import symantec.itools.awt.shape.HorizontalLine; import symantec.itools.awt.KeyPressManagerPanel; public class MainApplet extends Applet { public void init() { // Take outools.lang.Context.setApplet(this); symantec.itools.lang.Context.setApplet(this); // This code is automatically generated by Visual Cafe when you add // components to the visual environment. It instantiates and initializes // the components. To modify the code, only use code syntax that matches // what Visual Cafe can generate, or Visual Cafe may be unable to back // parse your Java file into its visual environment. //{{INIT_CONTROLS setLayout(null); setSize(1047,682); setForeground(new Color(16777215)); setBackground(new Color(0)); swapSpace = new java.awt.Button(); swapSpace.setLabel("transform"); swapSpace.setBounds(534,564,84,78); swapSpace.setForeground(new Color(16777215)); swapSpace.setBackground(new Color(-12828308)); add(swapSpace); rect1 = new symantec.itools.awt.shape.Rect(); rect1.setBounds(12,42,1024,512); rect1.setForeground(new Color(3224384)); add(rect1); param1rect = new symantec.itools.awt.shape.Rect(); try { param1rect.setFillMode(true); } catch(java.beans.PropertyVetoException e) { } param1rect.setBounds(468,564,48,24); add(param1rect); s = new CheckboxGroup(); checkZero = new java.awt.Checkbox("zero", s, false); checkZero.setBounds(12,624,48,16); checkZero.setForeground(new Color(12632256)); checkZero.setBackground(new Color(0)); add(checkZero); checkLog = new java.awt.Checkbox("log"); checkLog.setBounds(210,624,42,16); checkLog.setForeground(new Color(12632256)); checkLog.setBackground(new Color(0)); add(checkLog); checkMag = new java.awt.Checkbox("mag"); checkMag.setBounds(468,624,48,16); checkMag.setForeground(new Color(12632256)); checkMag.setBackground(new Color(0)); add(checkMag); horizontalLine1 = new symantec.itools.awt.shape.HorizontalLine(); horizontalLine1.setBounds(750,576,24,2); add(horizontalLine1); horizontalLine2 = new symantec.itools.awt.shape.HorizontalLine(); horizontalLine2.setBounds(894,576,24,2); add(horizontalLine2); greyImageViewer = new symantec.itools.multimedia.ImageViewer(); greyImageViewer.setBounds(12,564,450,24); add(greyImageViewer); mainImageViewer2 = new symantec.itools.multimedia.ImageViewer(); try { mainImageViewer2.setStyle(symantec.itools.multimedia.ImageViewer.IMAGE_NORMAL); } catch(java.beans.PropertyVetoException e) { } mainImageViewer2.setBounds(12,42,1024,512); add(mainImageViewer2); mainImageViewer = new symantec.itools.multimedia.ImageViewer(); try { mainImageViewer.setStyle(symantec.itools.multimedia.ImageViewer.IMAGE_NORMAL); } catch(java.beans.PropertyVetoException e) { } mainImageViewer.setVisible(false); mainImageViewer.setBounds(12,96,648,408); add(mainImageViewer); rect2 = new symantec.itools.awt.shape.Rect(); rect2.setBounds(12,594,450,24); add(rect2); URLfield = new java.awt.TextField(); URLfield.setText("http://www.usinternet.com/users/glenedwards/mondrian1.jpg"); URLfield.setBounds(12,12,648,24); URLfield.setFont(new Font("SansSerif", Font.PLAIN, 15)); URLfield.setForeground(new Color(16777215)); URLfield.setBackground(new Color(0)); add(URLfield); gotoButton = new java.awt.Button(); gotoButton.setLabel("go"); gotoButton.setBounds(672,12,36,27); gotoButton.setForeground(new Color(16777215)); gotoButton.setBackground(new Color(-12828308)); add(gotoButton); rangeViewer = new symantec.itools.multimedia.ImageViewer(); try { rangeViewer.setStyle(symantec.itools.multimedia.ImageViewer.IMAGE_SCALED_TO_FIT); } catch(java.beans.PropertyVetoException e) { } rangeViewer.setBounds(12,594,450,24); add(rangeViewer); choiceOperation = new java.awt.Choice(); choiceOperation.addItem("normal"); choiceOperation.addItem("multiply"); choiceOperation.addItem("add"); choiceOperation.addItem("subtract"); choiceOperation.addItem("rotate +"); choiceOperation.addItem("rotate -"); try { choiceOperation.select(0); } catch (IllegalArgumentException e) { } add(choiceOperation); choiceOperation.setBounds(630,564,120,24); choiceOperation.setFont(new Font("SansSerif", Font.PLAIN, 15)); choiceOperation.setForeground(new Color(16777215)); choiceOperation.setBackground(new Color(0)); choiceSmallMapping = new java.awt.Choice(); choiceSmallMapping.addItem("single pixel"); choiceSmallMapping.addItem("small brush"); choiceSmallMapping.addItem("large brush"); choiceSmallMapping.addItem("origin circle"); choiceSmallMapping.addItem("origin square"); try { choiceSmallMapping.select(0); } catch (IllegalArgumentException e) { } add(choiceSmallMapping); choiceSmallMapping.setBounds(774,564,120,24); choiceSmallMapping.setFont(new Font("SansSerif", Font.PLAIN, 15)); choiceSmallMapping.setForeground(new Color(16777215)); choiceSmallMapping.setBackground(new Color(0)); choiceBigMapping = new java.awt.Choice(); choiceBigMapping.addItem("normal"); choiceBigMapping.addItem("lowpass"); choiceBigMapping.addItem("highpass"); choiceBigMapping.addItem("vert mirror"); choiceBigMapping.addItem("horiz mirror"); choiceBigMapping.addItem("vert & horiz"); try { choiceBigMapping.select(0); } catch (IllegalArgumentException e) { } add(choiceBigMapping); choiceBigMapping.setBounds(918,564,120,24); choiceBigMapping.setFont(new Font("SansSerif", Font.PLAIN, 15)); choiceBigMapping.setForeground(new Color(16777215)); choiceBigMapping.setBackground(new Color(0)); choiceMapping = new java.awt.Choice(); choiceMapping.addItem("Normal"); choiceMapping.addItem("Compressed"); choiceMapping.addItem("Show phase"); choiceMapping.addItem("Magnitude"); try { choiceMapping.select(0); } catch (IllegalArgumentException e) { } choiceMapping.setVisible(false); add(choiceMapping); choiceMapping.setBounds(942,654,100,12); button1 = new java.awt.Button(); button1.setLabel("auto"); button1.setBounds(468,594,48,24); button1.setForeground(new Color(16777215)); button1.setBackground(new Color(-12828308)); add(button1); label1 = new java.awt.Label("operation",Label.RIGHT); label1.setBounds(672,588,78,22); label1.setFont(new Font("SansSerif", Font.ITALIC, 15)); label1.setForeground(new Color(12632256)); add(label1); label2 = new java.awt.Label("brush",Label.RIGHT); label2.setBounds(792,588,100,22); label2.setFont(new Font("SansSerif", Font.ITALIC, 15)); label2.setForeground(new Color(12632256)); add(label2); label3 = new java.awt.Label("mapping",Label.RIGHT); label3.setBounds(936,588,100,22); label3.setFont(new Font("SansSerif", Font.ITALIC, 15)); label3.setForeground(new Color(12632256)); add(label3); checkPhase = new java.awt.Checkbox(""); checkPhase.setBounds(444,624,18,16); checkPhase.setForeground(new Color(12632256)); checkPhase.setBackground(new Color(0)); add(checkPhase); label4 = new java.awt.Label("phase",Label.RIGHT); label4.setBounds(403,625,36,14); label4.setForeground(new Color(12632256)); label4.setBackground(new Color(0)); add(label4); scrollPane1 = new java.awt.ScrollPane(ScrollPane.SCROLLBARS_AS_NEEDED); scrollPane1.setVisible(false); scrollPane1.setBounds(72,672,45,45); add(scrollPane1); //}} //{{REGISTER_LISTENERS SymAction lSymAction = new SymAction(); gotoButton.addActionListener(lSymAction); SymMouse aSymMouse = new SymMouse(); greyImageViewer.addMouseListener(aSymMouse); mainImageViewer.addMouseListener(aSymMouse); SymMouseMotion aSymMouseMotion = new SymMouseMotion(); mainImageViewer.addMouseMotionListener(aSymMouseMotion); mainImageViewer2.addMouseListener(aSymMouse); mainImageViewer2.addMouseMotionListener(aSymMouseMotion); SymItem lSymItem = new SymItem(); choiceOperation.addItemListener(lSymItem); choiceSmallMapping.addItemListener(lSymItem); choiceBigMapping.addItemListener(lSymItem); swapSpace.addActionListener(lSymAction); choiceMapping.addItemListener(lSymItem); checkZero.addItemListener(lSymItem); checkPhase.addItemListener(lSymItem); rangeViewer.addMouseMotionListener(aSymMouseMotion); rangeViewer.addMouseListener(aSymMouse); checkMag.addItemListener(lSymItem); checkLog.addItemListener(lSymItem); button1.addActionListener(lSymAction); //}} // my stuff --- paint the bitmaps int w = 255; int h = 2; int pix[] = new int[w * h]; int index = 0; for (int y = 0; y < h; y++) { for (int x = 0; x < w; x++) { int red = (x * 255) / (w - 1); pix[index++] = (255 << 24) | (red << 16) | (red << 8) | red; } } try{ Image img = createImage(new MemoryImageSource(w, h, pix, 0, w)); greyImageViewer.setImage(img); greyImageViewer.setStyle(greyImageViewer.IMAGE_SCALED_TO_FIT); } catch (java.beans.PropertyVetoException ex){ex.printStackTrace();} // rebuild rangeImage w = 255; h = 2; index = 0; int lowcut = (int)1; int highcut = (int)254; for (int y = 0; y < h; y++) { for (int x = 0; x < w; x++) { int red; if (xhighcut) red = 255; else red = ((x-lowcut) * 255) / (highcut-lowcut); if (x == lowcut) { pix[index++] = (255 << 24) | 255; } else if (x == highcut) { pix[index++] = (255 << 24) | (255 << 16); } else { pix[index++] = (255 << 24) | (red << 16) | (red << 8) | red; } } } try{ rangeViewerSource = new MemoryImageSource(w, h, pix, 0, w); rangeViewerSource.setAnimated(true); Image img = createImage(rangeViewerSource); rangeViewer.setImage(img); } catch (java.beans.PropertyVetoException ex){ex.printStackTrace();} } // t this line if you don't use symantec.itools.net.RelativeURL or symantec.itools.awt.util.StatusScroller // symantec.i //{{DECLARE_CONTROLS java.awt.Button swapSpace; symantec.itools.awt.shape.Rect rect1; symantec.itools.awt.shape.Rect param1rect; java.awt.Checkbox checkZero; CheckboxGroup s; java.awt.Checkbox checkLog; java.awt.Checkbox checkMag; symantec.itools.awt.shape.HorizontalLine horizontalLine1; symantec.itools.awt.shape.HorizontalLine horizontalLine2; symantec.itools.multimedia.ImageViewer greyImageViewer; symantec.itools.multimedia.ImageViewer mainImageViewer2; symantec.itools.multimedia.ImageViewer mainImageViewer; symantec.itools.awt.shape.Rect rect2; java.awt.TextField URLfield; java.awt.Button gotoButton; symantec.itools.multimedia.ImageViewer rangeViewer; java.awt.Choice choiceOperation; java.awt.Choice choiceSmallMapping; java.awt.Choice choiceBigMapping; java.awt.Choice choiceMapping; java.awt.Button button1; java.awt.Label label1; java.awt.Label label2; java.awt.Label label3; java.awt.Checkbox checkPhase; java.awt.Label label4; java.awt.ScrollPane scrollPane1; //}} // the image chain PixelOp currentPixelOp; PixelMapping currentSmallMap; PixelMapping currentBigMap; ComplexImage currentComplexImage; ComplexImage spaceComplexImage; // one of these is the current 'working' image ComplexImage freqComplexImage; int spaceMappingChoice = 0; int freqMappingChoice = 0; ComplexImageMapping currentMapping; MotherImageMapping spaceMotherImageMapping; MotherImageMapping freqMotherImageMapping; ComplexImage workingComplexImage; boolean inSpace = true; // true if we are in space; ComplexImageMapping currentComplexImageMapping; boolean imageMod = true; MemoryImageSource rangeViewerSource; PixelMapping currentPipeline; class SymAction implements java.awt.event.ActionListener { public void actionPerformed(java.awt.event.ActionEvent event) { Object object = event.getSource(); if (object == gotoButton) gotoButton_ActionPerformed(event); else if (object == swapSpace) swapSpace_ActionPerformed(event); else if (object == button1) button1_ActionPerformed(event); } } void recreatePipeline() { // looking at the state of the three option box's recreate the drawing pipeling int op = choiceOperation.getSelectedIndex(); int sm = choiceSmallMapping.getSelectedIndex(); int bm = choiceBigMapping.getSelectedIndex(); switch(op) { case 0 : currentPixelOp = new PixelOp(); break;// default behavior case 1 : currentPixelOp = new MultiplyOp(); break; case 2 : currentPixelOp = new AddOp(); break; case 3 : currentPixelOp = new SubtractOp(); break; case 4 : currentPixelOp = new ClockwiseOp(); break; case 5 : currentPixelOp = new AnticlockwiseOp(); break; } switch(sm) { case 0 : currentSmallMap = new PixelMapping(currentComplexImage,null); break; case 1 : currentSmallMap = new SoftCircle(currentComplexImage,null); break; case 2 : currentSmallMap = new SoftCircle(currentComplexImage,null,40,40); break; } switch(bm) { case 0 : currentBigMap = new PixelMapping(currentComplexImage,currentSmallMap); break; case 1 : currentBigMap = new LowpassMapping(currentComplexImage,currentSmallMap); break; case 2 : currentBigMap = new HighpassMapping(currentComplexImage,currentSmallMap); break; case 3 : currentBigMap = new VertMirrorMapping(currentComplexImage,currentSmallMap); break; case 4 : currentBigMap = new HorizMirrorMapping(currentComplexImage,currentSmallMap); break; case 5 : currentBigMap = new BothMirrorMapping(currentComplexImage,currentSmallMap); break; } currentPipeline = currentBigMap; } void gotoButton_ActionPerformed(java.awt.event.ActionEvent event) { // gab the URL from URLfield; try{ URL url = symantec.itools.net.RelativeURL.getURL(URLfield.getText()); // create a new complex image from the url mainImageViewer.setStyle(mainImageViewer.IMAGE_NORMAL); mainImageViewer.setImageURL(url); //mainImageViewer.repaint(); //ImageProducer im = mainImageViewer.getImage().getSource(); //im.addConsumer((ImageConsumer)spaceComplexImage); Image im = mainImageViewer.getImage(); ImageProducer ip = im.getSource(); currentComplexImage = new ComplexImage(); currentComplexImage.grabImage(im,ip); // now replace the image with the image from the ComplexImage (!) //Image im = currentComplexImage.localImageSource.getImage(); // now just for the demo of it, try paintint on it! //currentComplexImage.imagedata.r[0] = 0; //currentComplexImage.imagedata.i[0] = 0; currentComplexImage.stuffIntArray(currentComplexImage.localImageBuffer); currentComplexImage.localImageSource.newPixels(0,0, currentComplexImage.w,currentComplexImage.h, true); mainImageViewer2.setImage(createImage(currentComplexImage.localImageSource)); mainImageViewer2.setStyle(mainImageViewer.IMAGE_NORMAL); // now start up a thread to watch its loading completion of the load // ImageLoaderThread ilt = new ImageLoaderThread(im,spaceComplexImage); // ilt.start(); } catch (java.beans.PropertyVetoException ex){ex.printStackTrace();} catch (java.net.MalformedURLException ex){ex.printStackTrace();} // make the working image workingComplexImage = new ComplexImage(currentComplexImage); spaceComplexImage = currentComplexImage; freqComplexImage = new ComplexImage(currentComplexImage.widthp2,currentComplexImage.heightp2); // just to get the size right //freqComplexImage.map = new ScaledMapping(); // freqMappingChoice = 1; // spaceMappingChoice = 0; spaceMotherImageMapping = new MotherImageMapping(); freqMotherImageMapping = new MotherImageMapping(); spaceComplexImage.map = spaceMotherImageMapping; freqComplexImage.map = freqMotherImageMapping; rebuildRangeViewer(); // rebuild the pipeline recreatePipeline(); } class SymMouse extends java.awt.event.MouseAdapter { public void mouseReleased(java.awt.event.MouseEvent event) { Object object = event.getSource(); if (object == mainImageViewer) mainImageViewer_mouseReleased(event); else if (object == mainImageViewer2) mainImageViewer2_mouseReleased(event); else if (object == rangeViewer) rangeViewer_mouseReleased(event); } public void mousePressed(java.awt.event.MouseEvent event) { Object object = event.getSource(); if (object == greyImageViewer) greyImageViewer_mousePressed(event); else if (object == mainImageViewer) mainImageViewer_mousePressed(event); else if (object == mainImageViewer2) mainImageViewer2_mousePressed(event); } public void mouseClicked(java.awt.event.MouseEvent event) { Object object = event.getSource(); if (object == greyImageViewer) greyImageViewer_mouseClicked(event); else if (object == mainImageViewer2) mainImageViewer2_mouseClicked(event); } } void greyImageViewer_mouseClicked(java.awt.event.MouseEvent event) { } void greyImageViewer_mousePressed(java.awt.event.MouseEvent event) { // to do: code goes here. // its a relative y so... float ypercent = ((float)event.getX())/greyImageViewer.bounds().width; currentPixelOp.param1=ypercent; //System.out.println("greyImageViewer_mouseClicked: y at "+ypercent+"% "+greyImageViewer.bounds().height); try{param1rect.setFillColor(new Color(ypercent,ypercent,ypercent));} catch (java.beans.PropertyVetoException ex){ex.printStackTrace();} } class SymMouseMotion extends java.awt.event.MouseMotionAdapter { public void mouseDragged(java.awt.event.MouseEvent event) { Object object = event.getSource(); if (object == mainImageViewer) mainImageViewer_mouseDragged(event); else if (object == mainImageViewer2) mainImageViewer2_mouseDragged(event); else if (object == rangeViewer) rangeViewer_mouseDragged(event); } } void mainImageViewer2_mousePressed(java.awt.event.MouseEvent event) { // to do: code goes here. } boolean dragging = false; int lowx,lowy,highx,highy; void mainImageViewer2_mouseReleased(java.awt.event.MouseEvent event) { // to do: code goes here. // redisply current image. //currentComplexImage.FFT(freqComplexImage,new TwoDimMappingFunction()); currentComplexImage.stuffIntArray(currentComplexImage.localImageBuffer); //freqComplexImage.stuffIntArray(currentComplexImage.localImageBuffer); currentComplexImage.localImageSource.newPixels(0,0, currentComplexImage.w,currentComplexImage.h, true); // make the working image. workingComplexImage.copyImage(currentComplexImage); dragging = false; imageMod = true; rebuildRangeViewer(); } void mainImageViewer2_mouseDragged(java.awt.event.MouseEvent event) { // to do: code goes here. // ok we have a mouse down here! // go throught the pipeline and see what this means int x = event.getX(); int y = event.getY(); // System.out.println("Mouse Drag at :"+x+" "+y); // need some translation in here! currentPipeline.setOrigin(x,y); lowx = 10000; lowy = 10000; highx = -10000; highy = -10000; boolean anythingHappen = false; if (currentPipeline.allowDrag | !dragging) { while (currentPipeline.morePixels()) { PixelDesc pd = currentPipeline.nextPixel(); anythingHappen = true; if (pd.y>highy) highy = pd.y; if (pd.x>highx) highx = pd.x; if (pd.ymaxhist) maxhist=mim.histo[x]; } for (int y = 0; y < h; y++) { for (int x = 0; x < w; x++) { int red; if (xhighcut) red = 255; else red = ((x-lowcut) * 255) / (highcut-lowcut); if (x == lowcut) { pix[index++] = (255 << 24) | 255; } else if (x == highcut) { pix[index++] = (255 << 24) | (255 << 16); } else //System.out.println(red); if (mim.phase) { if ((y == 0) && (xmim.lowpoint) mim.highpoint = l; } else { if (l