/* * Everyone is free to use, modify, and redistribute this code as long as they * retain this comment block near the top of this file, add this comment block * to files containing significant amounts of code copied from this file, and * not remove any text from this comment block. * Text can be appended to the bottom of this comment block as a change log and * credit to the contributors. * * This code is provided "as is" without any warranty. The contributors will * not be held liable for any damages resulting from the use of this code. * * Change Log: * * YYYY/MM/DD - Contributor Name * -change1 * -change2 * * 2007/07/31 - Dylan Hoen * -Created this file named. DepthOfField.java * -Created public class DepthOfField extends Applet implements ActionListener */ import java.applet.Applet; import java.awt.*; import java.awt.event.*; import java.net.*; import java.util.StringTokenizer; public class DepthOfField extends Applet implements ActionListener, AdjustmentListener { BorderLayout borderLayout = null; DepthOfFieldCanvas depthOfFieldCanvas = null; Panel leftPanel = null; Panel centerAndBottomPanel = null; Panel bottomPanel = null; Button calculateDepthOfField = null; Button calculateHyperFocalDistance = null; Button calculateAperture = null; Button calculateApertureAndDistance = null; Button calculateApertureAndDistanceWithLargerAperture = null; Button maximizeNearToInfinity = null; Button saveAsUrl = null; Label sensorSizeLabel = null; List sensorSizeList = null; Label apertureLabel = null; TextField apertureBox = null; Label minApertureLabel = null; TextField minApertureBox = null; Label maxApertureLabel = null; TextField maxApertureBox = null; Label xResLabel = null; TextField xResBox = null; Label yResLabel = null; TextField yResBox = null; Label bayerLowPassFilterLabel = null; Checkbox bayerLowPassFilterBox = null; Label focalLengthLabel = null; TextField focalLengthBox = null; CheckboxGroup equivelentFocalLengthGroup = null; Checkbox equivelentActualBox = null; Checkbox equivelent35mmBox = null; Label focalDistanceLabel = null; TextField focalDistanceBox = null; Label nearFocalDistanceLabel = null; TextField nearFocalDistanceBox = null; Label farFocalDistanceLabel = null; TextField farFocalDistanceBox = null; Label minInFocusLinesPerHeightLabel = null; TextField minInFocusLinesPerHeightBox = null; Scrollbar apertureScrollbar = null; Scrollbar focalDistanceScrollbar = null; TextArea leftTextArea = null; TextArea rightTextArea = null; public void init () { setLayout( new BorderLayout() ); centerAndBottomPanel = new Panel(); centerAndBottomPanel.setLayout( new BorderLayout() ); leftPanel = new Panel(); leftPanel.setLayout( new GridLayout( 0, 1 ) ); leftTextArea = new TextArea( "", 12, 20 ); rightTextArea = new TextArea( "", 13, 20 ); depthOfFieldCanvas = new DepthOfFieldCanvas(); depthOfFieldCanvas.leftTextArea = leftTextArea; depthOfFieldCanvas.rightTextArea = rightTextArea; centerAndBottomPanel.add( depthOfFieldCanvas, BorderLayout.CENTER ); leftPanel.setLayout( new GridLayout(0, 2)); sensorSizeLabel = new Label( "Sensor Size:" ); leftPanel.add( sensorSizeLabel ); sensorSizeList = new List(4, false); sensorSizeList.add( "1/2.7\", 5.371mm X 4.035mm" ); sensorSizeList.add( "1/2.5\", 5.760mm X 4.290mm" ); sensorSizeList.add( "1/1.8\", 7.176mm X 5.319mm" ); sensorSizeList.add( "1/1.7\", 7.600mm X 5.700mm" ); sensorSizeList.add( "2/3\", 8.80mm X 6.60mm" ); sensorSizeList.add( "4/3\", 17.40mm X 13.10mm" ); sensorSizeList.add( "APS-C, 22.5mm X 15.0mm" ); sensorSizeList.add( "Canon 5D, 36.0mm X 24.0mm" ); sensorSizeList.add( "35mm FF, 36.0mm X 24.0mm" ); sensorSizeList.add( "medium, 48.0mm X 36.0mm" ); sensorSizeList.select( 5 ); leftPanel.add( sensorSizeList ); xResLabel = new Label( "X Resolution (Pixels):" ); leftPanel.add( xResLabel ); xResBox = new TextField( "" ); leftPanel.add( xResBox ); yResLabel = new Label( "Y Resolution (Pixels):" ); leftPanel.add( yResLabel ); yResBox = new TextField( "" ); leftPanel.add( yResBox ); bayerLowPassFilterLabel = new Label( "Bayer Low Pass Filtered:" ); leftPanel.add( bayerLowPassFilterLabel ); bayerLowPassFilterBox = new Checkbox( "", true ); leftPanel.add( bayerLowPassFilterBox ); minApertureLabel = new Label( "Minimum Aperture (F/A):" ); leftPanel.add( minApertureLabel ); minApertureBox = new TextField( "" ); leftPanel.add( minApertureBox ); maxApertureLabel = new Label( "Maximum Aperture (F/A):" ); leftPanel.add( maxApertureLabel ); maxApertureBox = new TextField( "" ); leftPanel.add( maxApertureBox ); apertureLabel = new Label( "Aperture (F/A):" ); leftPanel.add( apertureLabel ); apertureBox = new TextField( "" ); leftPanel.add( apertureBox ); leftPanel.add( new Label( "" ) ); apertureScrollbar = new Scrollbar( Scrollbar.HORIZONTAL, 50, 1, 0, 101 ); apertureScrollbar.addAdjustmentListener( this ); leftPanel.add( apertureScrollbar ); focalLengthLabel = new Label( "Focal Length (mm):" ); leftPanel.add( focalLengthLabel ); focalLengthBox = new TextField( "" ); leftPanel.add( focalLengthBox ); equivelentFocalLengthGroup = new CheckboxGroup(); equivelentActualBox = new Checkbox( "Actual Focal Length", equivelentFocalLengthGroup, true ); leftPanel.add( equivelentActualBox ); equivelent35mmBox = new Checkbox( "35mm Equivelent Focal Length", equivelentFocalLengthGroup, false ); leftPanel.add( equivelent35mmBox ); nearFocalDistanceLabel = new Label( "Subject Near Distance (m):" ); leftPanel.add( nearFocalDistanceLabel ); nearFocalDistanceBox = new TextField( "" ); leftPanel.add( nearFocalDistanceBox ); farFocalDistanceLabel = new Label( "Subject Far Distance (m):" ); leftPanel.add( farFocalDistanceLabel ); farFocalDistanceBox = new TextField( "" ); leftPanel.add( farFocalDistanceBox ); focalDistanceLabel = new Label( "Focal Distance (m):" ); leftPanel.add( focalDistanceLabel ); focalDistanceBox = new TextField( "" ); leftPanel.add( focalDistanceBox ); leftPanel.add( new Label( "" ) ); focalDistanceScrollbar = new Scrollbar( Scrollbar.HORIZONTAL, 50, 1, 0, 101 ); focalDistanceScrollbar.addAdjustmentListener( this ); leftPanel.add( focalDistanceScrollbar ); minInFocusLinesPerHeightLabel = new Label( "Min In-Focus Lines-Per-Height: " ); leftPanel.add( minInFocusLinesPerHeightLabel ); minInFocusLinesPerHeightBox = new TextField( "" ); leftPanel.add( minInFocusLinesPerHeightBox ); calculateDepthOfField = new Button( "Graph Depth Of Field" ); calculateDepthOfField.addActionListener( this ); leftPanel.add( calculateDepthOfField ); calculateHyperFocalDistance = new Button( "Calculate Hyper Focal Distance" ); calculateHyperFocalDistance.addActionListener( this ); leftPanel.add( calculateHyperFocalDistance ); calculateAperture = new Button( "Calculate Aperture" ); calculateAperture.addActionListener( this ); leftPanel.add( calculateAperture ); calculateApertureAndDistance = new Button( "Calculate Aperture and Distance" ); calculateApertureAndDistance.addActionListener( this ); leftPanel.add( calculateApertureAndDistance ); calculateApertureAndDistanceWithLargerAperture = new Button( "Calculate A and D, larger A" ); calculateApertureAndDistanceWithLargerAperture.addActionListener( this ); leftPanel.add( calculateApertureAndDistanceWithLargerAperture ); maximizeNearToInfinity = new Button( "Maximize Near Subject To Infinity" ); maximizeNearToInfinity.addActionListener( this ); leftPanel.add( maximizeNearToInfinity ); saveAsUrl = new Button( "Save As Linkable URL" ); saveAsUrl.addActionListener( this ); leftPanel.add( saveAsUrl ); bottomPanel = new Panel(); bottomPanel.setLayout( new GridLayout( 1, 2 ) ); bottomPanel.add( leftTextArea ); bottomPanel.add( rightTextArea ); centerAndBottomPanel.add( bottomPanel, BorderLayout.SOUTH ); add( centerAndBottomPanel, BorderLayout.CENTER ); add( leftPanel, BorderLayout.WEST ); writeSettingsToGui(); getSettingsFromGui(); parseUrl(); writeSettingsToGui(); getSettingsFromGui(); depthOfFieldCanvas.repaint(); } public void paint( Graphics page ) { } public void adjustmentValueChanged( AdjustmentEvent e ) { if( e.getSource() == apertureScrollbar ) { int breakpoint = 0; int value = apertureScrollbar.getValue(); getSettingsFromGui(); double alpha = value / 100.0; depthOfFieldCanvas.aperture = alpha * depthOfFieldCanvas.maxAperture + ( 1 - alpha ) * depthOfFieldCanvas.minAperture; } if( e.getSource() == focalDistanceScrollbar ) { int breakpoint = 0; int value = focalDistanceScrollbar.getValue(); getSettingsFromGui(); double alpha = value / 100.0; depthOfFieldCanvas.focalDistance = alpha * depthOfFieldCanvas.farFocalDistance + ( 1 - alpha ) * depthOfFieldCanvas.nearFocalDistance; } depthOfFieldCanvas.repaint(); writeSettingsToGui(); } public void actionPerformed( ActionEvent e ) { getSettingsFromGui(); if( e.getSource() == calculateDepthOfField ) { int breakpoint = 0; } if( e.getSource() == calculateHyperFocalDistance ) { int breakpoint = 0; depthOfFieldCanvas.focalDistance = depthOfFieldCanvas.focalLength + depthOfFieldCanvas.focalLength * depthOfFieldCanvas.focalLength / ( depthOfFieldCanvas.aperture * ( depthOfFieldCanvas.bayerLowPassPixelSize / Math.sqrt( 2 ) ) ); depthOfFieldCanvas.nearFocalDistance = depthOfFieldCanvas.focalDistance / 2; depthOfFieldCanvas.farFocalDistance = depthOfFieldCanvas.focalDistance * 5; depthOfFieldCanvas.calcuateNonInputVariables(); focalDistanceBox.requestFocus(); } if( e.getSource() == calculateAperture ) { int breakpoint = 0; calculateOptimalAperture(); apertureBox.requestFocus(); } if( e.getSource() == calculateApertureAndDistance ) { int breakpoint = 0; for( int i = 0; i < 4; i++ ) { calculateOptimalAperture(); calculateOptimalDistance(); } apertureBox.requestFocus(); } if( e.getSource() == calculateApertureAndDistanceWithLargerAperture ) { int breakpoint = 0; for( int i = 0; i < 4; i++ ) { calculateOptimalAperture(); calculateOptimalDistance(); } calculateOptimalAperture2(); apertureBox.requestFocus(); } if( e.getSource() == maximizeNearToInfinity ) { int breakpoint = 0; for( int i = 0; i < 40; i++ ) { calculateOptimalApertureInfinity(); calculateOptimalDistanceInfinity(); } apertureBox.requestFocus(); } /* if( e.getSource() == calculateApertureAndDistanceRoot2 ) { int breakpoint = 0; for( int i = 0; i < 4; i++ ) { calculateOptimalAperture(); calculateOptimalDistance(); } calculateOptimalAperture3(); apertureBox.requestFocus(); } */ if( e.getSource() == saveAsUrl ) { int breakpoint = 0; setUrl(); } depthOfFieldCanvas.repaint(); writeSettingsToGui(); } public void calculateOptimalAperture() { double minAperture = depthOfFieldCanvas.minAperture; double maxAperture = depthOfFieldCanvas.maxAperture; for( int i = 0; i < 30; i++ ) { double guess = ( minAperture + maxAperture ) / 2; double highGuess = guess + ( maxAperture - minAperture ) / 100; depthOfFieldCanvas.aperture = highGuess; depthOfFieldCanvas.calcuateNonInputVariables(); double highGuessResult = depthOfFieldCanvas.minLinesPerHeight; double lowGuess = guess - ( maxAperture - minAperture ) / 100; depthOfFieldCanvas.aperture = lowGuess; depthOfFieldCanvas.calcuateNonInputVariables(); double lowGuessResult = depthOfFieldCanvas.minLinesPerHeight; if( highGuessResult > lowGuessResult ) { minAperture = lowGuess; } else { maxAperture = highGuess; } } depthOfFieldCanvas.aperture = ( minAperture + maxAperture ) / 2; depthOfFieldCanvas.calcuateNonInputVariables(); } public void calculateOptimalApertureInfinity() { double minAperture = depthOfFieldCanvas.minAperture; double maxAperture = depthOfFieldCanvas.maxAperture; for( int i = 0; i < 30; i++ ) { double guess = ( minAperture + maxAperture ) / 2; double highGuess = guess + ( maxAperture - minAperture ) / 100; depthOfFieldCanvas.aperture = highGuess; depthOfFieldCanvas.calcuateNonInputVariables(); double highGuessResult = Math.min( depthOfFieldCanvas.f( depthOfFieldCanvas.nearFocalDistance ), depthOfFieldCanvas.f( depthOfFieldCanvas.focalDistance * 1000000 ) ); double lowGuess = guess - ( maxAperture - minAperture ) / 100; depthOfFieldCanvas.aperture = lowGuess; depthOfFieldCanvas.calcuateNonInputVariables(); double lowGuessResult = Math.min( depthOfFieldCanvas.f( depthOfFieldCanvas.nearFocalDistance ), depthOfFieldCanvas.f( depthOfFieldCanvas.focalDistance * 1000000 ) );; if( highGuessResult > lowGuessResult ) { minAperture = lowGuess; } else { maxAperture = highGuess; } } depthOfFieldCanvas.aperture = ( minAperture + maxAperture ) / 2; depthOfFieldCanvas.calcuateNonInputVariables(); } public void calculateOptimalAperture2() { calculateOptimalAperture(); depthOfFieldCanvas.calcuateNonInputVariables(); double minAperture = depthOfFieldCanvas.minAperture; double maxAperture = depthOfFieldCanvas.aperture; double targetValue = depthOfFieldCanvas.minLinesPerHeight * .9; for( int i = 0; i < 30; i++ ) { double guess = ( minAperture + maxAperture ) / 2; depthOfFieldCanvas.aperture = guess; depthOfFieldCanvas.calcuateNonInputVariables(); if( depthOfFieldCanvas.minLinesPerHeight < targetValue ) { minAperture = guess; } else { maxAperture = guess; } } depthOfFieldCanvas.aperture = ( minAperture + maxAperture ) / 2; depthOfFieldCanvas.calcuateNonInputVariables(); } public void calculateOptimalAperture3() { double minAperture = depthOfFieldCanvas.minAperture; double maxAperture = depthOfFieldCanvas.aperture; for( int i = 0; i < 30; i++ ) { double guess = ( minAperture + maxAperture ) / 2; depthOfFieldCanvas.aperture = guess; depthOfFieldCanvas.calcuateNonInputVariables(); if( depthOfFieldCanvas.minLinesPerHeight * Math.sqrt( 2 ) < depthOfFieldCanvas.f( depthOfFieldCanvas.focalDistance ) ) { minAperture = guess; } else { maxAperture = guess; } } depthOfFieldCanvas.aperture = ( minAperture + maxAperture ) / 2; depthOfFieldCanvas.calcuateNonInputVariables(); } public void calculateOptimalDistance() { double minDistance = depthOfFieldCanvas.nearFocalDistance; double maxDistance = depthOfFieldCanvas.farFocalDistance; for( int i = 0; i < 30; i++ ) { double guess = ( minDistance + maxDistance ) / 2; depthOfFieldCanvas.focalDistance = guess; depthOfFieldCanvas.calcuateNonInputVariables(); if( depthOfFieldCanvas.f( depthOfFieldCanvas.nearFocalDistance ) > depthOfFieldCanvas.f( depthOfFieldCanvas.farFocalDistance ) ) { minDistance = guess; } else { maxDistance = guess; } } depthOfFieldCanvas.focalDistance = ( minDistance + maxDistance ) / 2; depthOfFieldCanvas.calcuateNonInputVariables(); } public void calculateOptimalDistanceInfinity() { double minDistance = depthOfFieldCanvas.nearFocalDistance; double maxDistance = depthOfFieldCanvas.focalLength * 1000000; depthOfFieldCanvas.farFocalDistance = depthOfFieldCanvas.focalLength * 1000000; for( int i = 0; i < 40; i++ ) { double guess = ( minDistance + maxDistance ) / 2; double highGuess = guess + ( maxDistance - minDistance ) / 100; depthOfFieldCanvas.focalDistance = highGuess; depthOfFieldCanvas.calcuateNonInputVariables(); double highGuessResult = Math.min( depthOfFieldCanvas.f( depthOfFieldCanvas.nearFocalDistance ), depthOfFieldCanvas.f( depthOfFieldCanvas.focalDistance * 1000000 ) ); double lowGuess = guess - ( maxDistance - minDistance ) / 100; depthOfFieldCanvas.focalDistance = lowGuess; depthOfFieldCanvas.calcuateNonInputVariables(); double lowGuessResult = Math.min( depthOfFieldCanvas.f( depthOfFieldCanvas.nearFocalDistance ), depthOfFieldCanvas.f( depthOfFieldCanvas.focalDistance * 1000000 ) );; if( highGuessResult > lowGuessResult ) { minDistance = lowGuess; } else { maxDistance = highGuess; } } depthOfFieldCanvas.focalDistance = ( minDistance + maxDistance ) / 2; depthOfFieldCanvas.farFocalDistance = depthOfFieldCanvas.focalDistance * 5; depthOfFieldCanvas.calcuateNonInputVariables(); } public void getSensorSize() { switch( sensorSizeList.getSelectedIndex() ) { case 0: depthOfFieldCanvas.sensorWidth = .005371; depthOfFieldCanvas.sensorHeight = .004035; break; case 1: depthOfFieldCanvas.sensorWidth = .005760; depthOfFieldCanvas.sensorHeight = .004290; break; case 2: depthOfFieldCanvas.sensorWidth = .007176; depthOfFieldCanvas.sensorHeight = .005319; break; case 3: depthOfFieldCanvas.sensorWidth = .007600; depthOfFieldCanvas.sensorHeight = .005700; break; case 4: depthOfFieldCanvas.sensorWidth = .008800; depthOfFieldCanvas.sensorHeight = .006600; break; case 5: depthOfFieldCanvas.sensorWidth = .017400; depthOfFieldCanvas.sensorHeight = .013100; break; case 6: depthOfFieldCanvas.sensorWidth = .0225; depthOfFieldCanvas.sensorHeight = .0150; break; case 7: depthOfFieldCanvas.sensorWidth = .036000; depthOfFieldCanvas.sensorHeight = .024000; break; case 8: depthOfFieldCanvas.sensorWidth = .036000; depthOfFieldCanvas.sensorHeight = .024000; break; case 9: depthOfFieldCanvas.sensorWidth = .048000; depthOfFieldCanvas.sensorHeight = .036000; break; default: try { throw new Exception( "This line of code should not be exicuted. Sensor index = " + sensorSizeList.getSelectedIndex() ); } catch( Exception ex ) { ex.printStackTrace(); } break; } } public void getSettingsFromGui() { getSensorSize(); depthOfFieldCanvas.aperture = Double.parseDouble( apertureBox.getText() ); depthOfFieldCanvas.minAperture = Double.parseDouble( minApertureBox.getText() ); depthOfFieldCanvas.maxAperture = Double.parseDouble( maxApertureBox.getText() ); depthOfFieldCanvas.xRes = Double.parseDouble( xResBox.getText() ); depthOfFieldCanvas.yRes = Double.parseDouble( yResBox.getText() ); depthOfFieldCanvas.minInFocusLinesPerHeight = Double.parseDouble( minInFocusLinesPerHeightBox.getText() ); if( depthOfFieldCanvas.minInFocusLinesPerHeight < 4 ) { depthOfFieldCanvas.minInFocusLinesPerHeight = 4; } if( depthOfFieldCanvas.minInFocusLinesPerHeight > depthOfFieldCanvas.yRes / 2 ) { depthOfFieldCanvas.minInFocusLinesPerHeight = depthOfFieldCanvas.yRes / 2; } depthOfFieldCanvas.bayerLowPassFilter = bayerLowPassFilterBox.getState(); depthOfFieldCanvas.focalLength = Double.parseDouble( focalLengthBox.getText() ) / 1000; if( equivelentFocalLengthGroup.getSelectedCheckbox() == equivelent35mmBox ) { double sensorDiagonal = Math.sqrt( depthOfFieldCanvas.sensorWidth * depthOfFieldCanvas.sensorWidth + depthOfFieldCanvas.sensorHeight * depthOfFieldCanvas.sensorHeight ); double focalLengthMultiplier = Math.sqrt( .036 * .036 + .024 * .024 ) / sensorDiagonal; depthOfFieldCanvas.focalLength /= focalLengthMultiplier; } depthOfFieldCanvas.focalDistance = Double.parseDouble( focalDistanceBox.getText() ); depthOfFieldCanvas.nearFocalDistance = Double.parseDouble( nearFocalDistanceBox.getText() ); depthOfFieldCanvas.farFocalDistance = Double.parseDouble( farFocalDistanceBox.getText() ); if( depthOfFieldCanvas.focalLength < .001 ) { depthOfFieldCanvas.focalLength = .001; } if( depthOfFieldCanvas.nearFocalDistance < depthOfFieldCanvas.focalLength * 1.001 ) { depthOfFieldCanvas.nearFocalDistance = depthOfFieldCanvas.focalLength * 1.001; } if( depthOfFieldCanvas.farFocalDistance < depthOfFieldCanvas.nearFocalDistance * 1.0001 ) { depthOfFieldCanvas.farFocalDistance = depthOfFieldCanvas.nearFocalDistance * 1.0001; } if( depthOfFieldCanvas.focalDistance < depthOfFieldCanvas.nearFocalDistance ) { depthOfFieldCanvas.focalDistance = depthOfFieldCanvas.nearFocalDistance; } if( depthOfFieldCanvas.focalDistance > depthOfFieldCanvas.farFocalDistance ) { depthOfFieldCanvas.focalDistance = depthOfFieldCanvas.farFocalDistance; } if( depthOfFieldCanvas.xRes < 2 ) { depthOfFieldCanvas.xRes = 2; } if( depthOfFieldCanvas.yRes < 2 ) { depthOfFieldCanvas.yRes = 2; } if( depthOfFieldCanvas.minAperture < .25 ) { depthOfFieldCanvas.minAperture = .25; } if( depthOfFieldCanvas.minAperture > 1000 ) { depthOfFieldCanvas.minAperture = 1000; } if( depthOfFieldCanvas.maxAperture < .25 ) { depthOfFieldCanvas.maxAperture = .25; } if( depthOfFieldCanvas.maxAperture > 1000 ) { depthOfFieldCanvas.maxAperture = 1000; } if( depthOfFieldCanvas.maxAperture < depthOfFieldCanvas.maxAperture ) { double temp = depthOfFieldCanvas.maxAperture; depthOfFieldCanvas.maxAperture = depthOfFieldCanvas.minAperture; depthOfFieldCanvas.minAperture = temp; } if( depthOfFieldCanvas.aperture > depthOfFieldCanvas.maxAperture ) { depthOfFieldCanvas.aperture = depthOfFieldCanvas.maxAperture; } if( depthOfFieldCanvas.aperture < depthOfFieldCanvas.minAperture ) { depthOfFieldCanvas.aperture = depthOfFieldCanvas.minAperture; } depthOfFieldCanvas.calcuateNonInputVariables(); writeSettingsToGui(); } public void writeSettingsToGui() { apertureBox.setText( depthOfFieldCanvas.aperture + "" ); minApertureBox.setText( depthOfFieldCanvas.minAperture + "" ); maxApertureBox.setText( depthOfFieldCanvas.maxAperture + "" ); xResBox.setText( depthOfFieldCanvas.xRes + "" ); yResBox.setText( depthOfFieldCanvas.yRes + "" ); bayerLowPassFilterBox.setState( depthOfFieldCanvas.bayerLowPassFilter ); if( equivelentFocalLengthGroup.getSelectedCheckbox() == equivelent35mmBox ) { double sensorDiagonal = Math.sqrt( depthOfFieldCanvas.sensorWidth * depthOfFieldCanvas.sensorWidth + depthOfFieldCanvas.sensorHeight * depthOfFieldCanvas.sensorHeight ); double focalLengthMultiplier = Math.sqrt( .036 * .036 + .024 * .024 ) / sensorDiagonal; focalLengthBox.setText( ( depthOfFieldCanvas.focalLength * focalLengthMultiplier * 1000 ) + "" ); } else { focalLengthBox.setText( ( depthOfFieldCanvas.focalLength * 1000 ) + "" ); } focalDistanceBox.setText( depthOfFieldCanvas.focalDistance + "" ); nearFocalDistanceBox.setText( depthOfFieldCanvas.nearFocalDistance + "" ); farFocalDistanceBox.setText( depthOfFieldCanvas.farFocalDistance + "" ); minInFocusLinesPerHeightBox.setText( depthOfFieldCanvas.minInFocusLinesPerHeight + "" ); apertureScrollbar.setValue( (int)Math.round( 100 * ( depthOfFieldCanvas.aperture - depthOfFieldCanvas.minAperture ) / ( depthOfFieldCanvas.maxAperture - depthOfFieldCanvas.minAperture ) ) ); focalDistanceScrollbar.setValue( (int)Math.round( 100 * ( depthOfFieldCanvas.focalDistance - depthOfFieldCanvas.nearFocalDistance ) / ( depthOfFieldCanvas.farFocalDistance - depthOfFieldCanvas.nearFocalDistance ) ) ); } public void setUrl() { String url = this.getDocumentBase().toString(); if( url.lastIndexOf( '?' ) >= 0 ) { url = url.substring( 0, url.indexOf( '?' ) ); } url += "?"; url += "sensorSize=" + sensorSizeList.getSelectedIndex(); url += "&xRes=" + depthOfFieldCanvas.xRes; url += "&yRes=" + depthOfFieldCanvas.yRes; url += "&bayerLowPassFilter=" + depthOfFieldCanvas.bayerLowPassFilter; url += "&aperture=" + depthOfFieldCanvas.aperture; url += "&minAperture=" + depthOfFieldCanvas.minAperture; url += "&maxAperture=" + depthOfFieldCanvas.maxAperture; url += "&focalLength=" + depthOfFieldCanvas.focalLength; url += "&equivelent=" + ( equivelentFocalLengthGroup.getSelectedCheckbox() == equivelent35mmBox ); url += "&focalDistance=" + depthOfFieldCanvas.focalDistance; url += "&nearFocalDistance=" + depthOfFieldCanvas.nearFocalDistance; url += "&farFocalDistance=" + depthOfFieldCanvas.farFocalDistance; url += "&minInFocusLinesPerHeight=" + depthOfFieldCanvas.minInFocusLinesPerHeight; try { this.getAppletContext().showDocument( new URL( url ) ); } catch( Exception e ) { e.printStackTrace(); } } public void parseUrl() { String url = this.getDocumentBase().toString(); //System.out.println( url ); if( url.lastIndexOf( '?' ) >= 0 ) { url = url.substring( url.indexOf( '?' ) + 1 ); //System.out.println( url ); StringTokenizer st = new StringTokenizer( url, "&" ); while( st.hasMoreTokens() ) { String token = st.nextToken(); //System.out.println( token ); StringTokenizer st2 = new StringTokenizer( token, "=" ); if( st2.countTokens() == 2 ) { String variable = st2.nextToken(); String value = st2.nextToken(); //System.out.println( variable ); //System.out.println( value ); if( variable != null && value != null ) { if( variable.equals( "sensorSize" ) ) { sensorSizeList.select( Integer.parseInt( value ) ); getSensorSize(); } else if( variable.equals( "xRes" ) ) { depthOfFieldCanvas.xRes = Double.parseDouble( value ); } else if( variable.equals( "yRes" ) ) { depthOfFieldCanvas.yRes = Double.parseDouble( value ); } else if( variable.equals( "bayerLowPassFilter" ) ) { depthOfFieldCanvas.bayerLowPassFilter = Boolean.parseBoolean( value ); } else if( variable.equals( "aperture" ) ) { depthOfFieldCanvas.aperture = Double.parseDouble( value ); } else if( variable.equals( "minAperture" ) ) { depthOfFieldCanvas.minAperture = Double.parseDouble( value ); } else if( variable.equals( "maxAperture" ) ) { depthOfFieldCanvas.maxAperture = Double.parseDouble( value ); } else if( variable.equals( "focalLength" ) ) { depthOfFieldCanvas.focalLength = Double.parseDouble( value ); } else if( variable.equals( "equivelent" ) ) { if( Boolean.parseBoolean( value ) ) { equivelentFocalLengthGroup.setSelectedCheckbox( equivelent35mmBox ); } else { equivelentFocalLengthGroup.setSelectedCheckbox( equivelentActualBox ); } } else if( variable.equals( "focalDistance" ) ) { depthOfFieldCanvas.focalDistance = Double.parseDouble( value ); } else if( variable.equals( "nearFocalDistance" ) ) { depthOfFieldCanvas.nearFocalDistance = Double.parseDouble( value ); } else if( variable.equals( "farFocalDistance" ) ) { depthOfFieldCanvas.farFocalDistance = Double.parseDouble( value ); } else if( variable.equals( "minInFocusLinesPerHeight" ) ) { depthOfFieldCanvas.minInFocusLinesPerHeight = Double.parseDouble( value ); } else { try { throw new Exception( "This is not a valid paramiter: " + variable ); } catch( Exception e ) { e.printStackTrace(); } } } } } } writeSettingsToGui(); getSettingsFromGui(); } }