// Neutrino.java (C) 2005 by Paul Falstad, www.falstad.com import java.io.InputStream; import java.awt.*; import java.awt.image.ImageProducer; import java.applet.Applet; import java.applet.AudioClip; import java.util.Vector; import java.util.Hashtable; import java.util.Enumeration; import java.io.File; import java.net.URL; import java.io.FilterInputStream; import java.lang.reflect.Constructor; import java.lang.reflect.Method; import java.awt.image.*; import java.lang.Math; import java.awt.event.*; import java.text.DecimalFormat; import java.text.NumberFormat; class NeutrinoCanvas extends Canvas { NeutrinoFrame pg; NeutrinoCanvas(NeutrinoFrame p) { pg = p; } public Dimension getPreferredSize() { return new Dimension(300,400); } public void update(Graphics g) { pg.updateNeutrino(g); } public void paint(Graphics g) { pg.updateNeutrino(g); } }; class NeutrinoLayout implements LayoutManager { public NeutrinoLayout() {} public void addLayoutComponent(String name, Component c) {} public void removeLayoutComponent(Component c) {} public Dimension preferredLayoutSize(Container target) { return new Dimension(500, 500); } public Dimension minimumLayoutSize(Container target) { return new Dimension(100,100); } public void layoutContainer(Container target) { Insets insets = target.insets(); int targetw = target.size().width - insets.left - insets.right; int cw = targetw* 8/10; int targeth = target.size().height - (insets.top+insets.bottom); target.getComponent(0).move(insets.left, insets.top); target.getComponent(0).resize(cw, targeth); int barwidth = targetw - cw; cw += insets.left; int i; int h = insets.top; for (i = 1; i < target.getComponentCount(); i++) { Component m = target.getComponent(i); if (m.isVisible()) { Dimension d = m.getPreferredSize(); if (m instanceof Scrollbar) d.width = barwidth; if (m instanceof Choice) d.width = barwidth; if (m instanceof Label) { h += d.height/5; d.width = barwidth; } m.move(cw, h); m.resize(d.width, d.height); h += d.height; } } } }; public class Neutrino extends Applet implements ComponentListener { NeutrinoFrame ogf; void destroyFrame() { if (ogf != null) ogf.dispose(); ogf = null; repaint(); } boolean started = false; public void init() { addComponentListener(this); } void showFrame() { if (ogf == null) { started = true; try { ogf = new NeutrinoFrame(this); ogf.init(); } catch (Exception e) { e.printStackTrace(); ogf = null; security = true; repaint(); } repaint(); } } boolean security = false; public void paint(Graphics g) { String s = "Applet is open in a separate window."; if (security) s = "Security exception, use nosound version"; else if (!started) s = "Applet is starting."; else if (ogf == null) s = "Applet is finished."; else ogf.show(); g.drawString(s, 10, 30); } public void componentHidden(ComponentEvent e){} public void componentMoved(ComponentEvent e){} public void componentShown(ComponentEvent e) { showFrame(); } public void componentResized(ComponentEvent e) {} public void destroy() { if (ogf != null) ogf.dispose(); ogf = null; repaint(); } }; class NeutrinoFrame extends Frame implements ComponentListener, ActionListener, AdjustmentListener, MouseMotionListener, MouseListener, ItemListener { Dimension winSize; Image dbimage; View probView, animView, spectrumView, matrixView, infoView; int maxSampleCount = 70; // was 50 int sampleCountR, sampleCountTh; int modeCountR, modeCountTh; int maxDispRModes = 5, maxDispThModes = 5; public static final double epsilon = .00001; public static final double epsilon2 = .003; public static final double log10 = 2.30258509299404568401; public static int WINDOW_KAISER = 4; public String getAppletInfo() { return "Neutrino Series by Paul Falstad"; } Checkbox soundCheck; Checkbox displayCheck; Checkbox shiftSpectrumCheck; //Checkbox woofCheck; CheckboxMenuItem probCheckItem; CheckboxMenuItem animCheckItem; CheckboxMenuItem spectrumCheckItem; CheckboxMenuItem matrixCheckItem; CheckboxMenuItem infoCheckItem; MenuItem exitItem; Choice initialChooser, finalChooser, setupChooser; Button defaultsButton; int selection; final int SELECT_RESPONSE = 1; final int SELECT_SPECTRUM = 2; final int SELECT_POLES = 3; int filterSelection; Scrollbar angleBars[]; Scrollbar energyScaleBar; Scrollbar distanceScaleBar; Scrollbar dm12Bar; Scrollbar dm23Bar; Scrollbar dm13Bar; boolean editingFunc; boolean dragStop; double inputW; static final double pi = 3.14159265358979323846; double step; double waveGain = 1./65536; double outputGain = 1; int sampleRate; int xpoints[] = new int[4]; int ypoints[] = new int[4]; int dragX, dragY; int dragStartX, dragStartY; int mouseX, mouseY; int selectedPole, selectedZero; int lastPoleCount = 2, lastZeroCount = 2; boolean dragSet, dragClear; boolean dragging; boolean unstable; Image memimage; int pixels[]; double t; int pause; double spectrumBuf[]; double distance, energy; double distanceScale = 1e3, energyScale = 5; static final int phaseColorCount = 50*8; boolean filterChanged; Color darkYellowColor, darkCyanColor; String massNames[] = { "1", "2", "3" }; String flavorNames[] = { "e", "mu", "tau" }; String massBarLabel[] = { "composition of", "the neutrino", "(mass states)" }; String flavorBarLabel[] = { "composition of the", "x flux at x km", "(flavor states)" }; class View extends Rectangle { View(Dimension r) { super(r); } View(int a, int b, int c, int d) { super(a, b, c, d); right = a+c-1; bottom = b+d-1; } int right, bottom; void drawLabel(Graphics g, String str) { g.setColor(Color.white); centerString(g, str, y-5); } int graphTop, graphBottom; } NeutrinoCanvas cv; Neutrino applet; NumberFormat showFormat; NeutrinoFrame(Neutrino a) { super("Neutrino Oscillations Applet v1.0"); applet = a; } boolean java2 = false; public void init() { int i, j; String jv = System.getProperty("java.class.version"); double jvf = new Double(jv).doubleValue(); if (jvf >= 48) java2 = true; darkYellowColor = new Color(192, 192, 0); darkCyanColor = new Color(0, 192, 192); setLayout(new NeutrinoLayout()); cv = new NeutrinoCanvas(this); cv.addComponentListener(this); cv.addMouseMotionListener(this); cv.addMouseListener(this); add(cv); MenuBar mb = new MenuBar(); Menu m = new Menu("File"); mb.add(m); m.add(exitItem = getMenuItem("Exit")); m = new Menu("View"); mb.add(m); m.add(probCheckItem = getCheckItem("Probability", true)); m.add(animCheckItem = getCheckItem("Animation", true)); m.add(spectrumCheckItem = getCheckItem("Spectrum", true)); m.add(matrixCheckItem = getCheckItem("Matrix", true)); m.add(infoCheckItem = getCheckItem("Info", true)); setMenuBar(mb); /*woofCheck = new Checkbox("Woof"); woofCheck.addItemListener(this); add(woofCheck);*/ add(setupChooser = new Choice()); setupChooser.add("SuperKamiokande, muon"); setupChooser.add("SuperKamiokande, electron"); setupChooser.add("K2K long baseline beam"); setupChooser.add("MINOS/Gran Sasso long baseline beam"); setupChooser.add("NOVA off-axis electron appearance"); setupChooser.add("KamLAND reactor antineutrinos"); setupChooser.add("Chooz Reactor antineutrinos"); setupChooser.addItemListener(this); add(initialChooser = new Choice()); initialChooser.add("Initial = e"); initialChooser.add("Initial = mu"); initialChooser.add("Initial = tau"); initialChooser.addItemListener(this); add(finalChooser = new Choice()); finalChooser.add("Final = e"); finalChooser.add("Final = mu"); finalChooser.add("Final = tau"); finalChooser.addItemListener(this); add(new Label("Distance Scale", Label.CENTER)); add(distanceScaleBar = new Scrollbar(Scrollbar.HORIZONTAL, 53, 1, 1, 62)); distanceScaleBar.addAdjustmentListener(this); add(new Label("Energy Scale", Label.CENTER)); add(energyScaleBar = new Scrollbar(Scrollbar.HORIZONTAL, 23, 1, 1, 52)); energyScaleBar.addAdjustmentListener(this); setScales(); angleBars = new Scrollbar[3]; for (i = 0; i != 3; i++) { add(new Label((i == 0) ? "theta12" : i == 1 ? "theta13" : "theta23", Label.CENTER)); add(angleBars[i] = new Scrollbar(Scrollbar.HORIZONTAL, 25, 1, 1, 9999)); angleBars[i].addAdjustmentListener(this); } add(new Label("dm12", Label.CENTER)); add(dm12Bar = new Scrollbar(Scrollbar.HORIZONTAL, 900, 1, 1, 999)); dm12Bar.addAdjustmentListener(this); add(new Label("dm23", Label.CENTER)); add(dm23Bar = new Scrollbar(Scrollbar.HORIZONTAL, 250, 1, 1, 999)); dm23Bar.addAdjustmentListener(this); add(defaultsButton = new Button("Reset to Defaults")); defaultsButton.addActionListener(this); setAllDefaults(); reinit(); cv.setBackground(Color.white); cv.setForeground(Color.black); showFormat = DecimalFormat.getInstance(); showFormat.setMaximumFractionDigits(3); resize(800, 640); handleResize(); Dimension x = getSize(); Dimension screen = getToolkit().getScreenSize(); setLocation((screen.width - x.width)/2, (screen.height - x.height)/2); show(); } void reinit() { } MenuItem getMenuItem(String s) { MenuItem mi = new MenuItem(s); mi.addActionListener(this); return mi; } CheckboxMenuItem getCheckItem(String s, boolean b) { CheckboxMenuItem mi = new CheckboxMenuItem(s); mi.setState(b); mi.addItemListener(this); return mi; } void setDefaults() { switch (setupChooser.getSelectedIndex()) { case 0: initialChooser.select(1); energy = 1; distance = 2000; break; case 1: initialChooser.select(0); energy = 1; distance = 2000; break; case 2: initialChooser.select(1); energy = 1; distance = 250; break; case 3: initialChooser.select(1); energy = 4; distance = 732; break; case 4: initialChooser.select(1); energy = 2; distance = 810; break; case 5: initialChooser.select(0); energy = 4e-3; distance = 180; break; case 6: initialChooser.select(0); energy = 4e-3; distance = 2; break; } finalChooser.select(initialChooser.getSelectedIndex()); distanceScaleBar.setValue((int) (22+10*Math.log(distance)/Math.log(10))); energyScaleBar.setValue((int) (22+10*Math.log(energy)/Math.log(10))); setScales(); } void setAllDefaults() { setDefaults(); angleBars[0].setValue(945); angleBars[1].setValue(417); angleBars[2].setValue(1253); dm12Bar.setValue(900); dm23Bar.setValue(250); } void handleResize() { Dimension d = winSize = cv.getSize(); if (winSize.width == 0) return; int ct = 0; probView = spectrumView = matrixView = animView = infoView = null; if (probCheckItem.getState()) ct++; if (spectrumCheckItem.getState()) ct++; if (matrixCheckItem.getState()) ct++; int height = d.height; int aheight = 60; if (animCheckItem.getState()) height -= aheight; int iheight = 65; if (infoCheckItem.getState()) height -= iheight; int dh3 = height/ct; dbimage = createImage(d.width, d.height); int bd = 15; int i = 0; int y = 0; if (animCheckItem.getState()) animView = getView(y += aheight, aheight); if (probCheckItem.getState()) probView = getView(y += dh3, dh3); if (spectrumCheckItem.getState()) spectrumView = getView(y += dh3, dh3); if (matrixCheckItem.getState()) matrixView = getView(y += dh3, dh3); if (infoCheckItem.getState()) infoView = getView(y += iheight, iheight); } View getView(int y, int dh3) { int bdy = 5; int tpad = 5; int bdx = 10; return new View(bdx, bdy+y-dh3+tpad, winSize.width-bdx*2, dh3-bdy*2-tpad); } void centerString(Graphics g, String s, int y) { FontMetrics fm = g.getFontMetrics(); g.drawString(s, (winSize.width-fm.stringWidth(s))/2, y); } public void paint(Graphics g) { cv.repaint(); } long lastTime; public void updateNeutrino(Graphics realg) { Graphics g = dbimage.getGraphics(); if (winSize == null || winSize.width == 0 || dbimage == null) return; long time = System.currentTimeMillis(); t += time-lastTime; lastTime = time; g.setColor(cv.getBackground()); g.fillRect(0, 0, winSize.width, winSize.height); g.setColor(cv.getForeground()); int init = initialChooser.getSelectedIndex(); int finl = finalChooser.getSelectedIndex(); if (matrixView != null) { int i, j; calcMatrix(); g.setColor(Color.black); FontMetrics fm = g.getFontMetrics(); int spacing = fm.stringWidth("-0.9999"); int mwidth = spacing*5+spacing/2; int mxstart = winSize.width/2-mwidth/2+spacing; int mystart = matrixView.y + (matrixView.height-fm.getHeight()*3)/2 + fm.getAscent(); for (j = 0; j != 3; j++) for (i = 0; i != 3; i++) { String s = showFormat.format(matx[j][i]); g.drawString(s, mxstart+spacing*(i+1)-fm.stringWidth(s)/2, mystart+fm.getHeight()*j); } String tt = "MNS Mixing Matrix"; g.drawString(tt, mxstart+spacing*2 - fm.stringWidth(tt)/2, mystart - 2*fm.getHeight()); g.drawRect(mxstart+spacing/2 - 5, mystart - fm.getAscent() - 5, spacing*3 + 10, fm.getHeight()*3 + 10); for (i = 0; i != 3; i++) { setNeutrinoColor(g, i); String s = flavorNames[i]; g.drawString(s, mxstart-spacing/2-fm.stringWidth(s)/2, mystart+fm.getHeight()*i); setMassColor(g, i); s = massNames[i]; g.drawString(s, mxstart+spacing*4-fm.stringWidth(s)/2, mystart+fm.getHeight()*i); } g.setColor(Color.black); g.drawString("=", mxstart-fm.stringWidth("=")/2, mystart+fm.getHeight()); double comp[] = new double[3]; for (i = 0; i != 3; i++) comp[i] = matx[init][i]*matx[init][i]; //System.out.println(comp[0] + " " + comp[1] + " " + comp[2]); drawBarChart(g, comp, matrixView, matrixView.x, (matrixView.width-mwidth)/2, massNames, massBarLabel); for (i = 0; i != 3; i++) comp[i] = calcProb(init, i, distance, energy); flavorBarLabel[1] = getUnitText(energy*1e9, "eV") + " flux at " + getDistanceText(distance); drawBarChart(g, comp, matrixView, matrixView.x+(matrixView.width+mwidth)/2, (matrixView.width-mwidth)/2, flavorNames, flavorBarLabel); } if (probView != null) { drawGraphAxes(g, "Appearance/disappearance probability for E = " + getUnitText(energy*1e9, "eV"), probView, distanceScale); plotLine(g, probView, distance, distanceScale); double data[] = new double[1231]; // prime number int i; for (i = 0; i != data.length; i++) data[i] = calcProb(init, 1, distanceScale*i/(data.length-1), energy); g.setColor(Color.green); drawGraph(g, data, probView); for (i = 0; i != data.length; i++) data[i] = calcProb(init, 0, distanceScale*i/(data.length-1), energy); g.setColor(Color.blue); drawGraph(g, data, probView); for (i = 0; i != data.length; i++) data[i] = calcProb(init, 2, distanceScale*i/(data.length-1), energy); g.setColor(Color.red); drawGraph(g, data, probView); } if (spectrumView != null) { String tt = "Energy spectrum modification at distance "; if (init != finl) tt = "Energy spectrum at distance "; drawGraphAxes(g, tt + getDistanceText(distance), spectrumView, energyScale); plotLine(g, spectrumView, energy, energyScale); double data[] = new double[1231]; int i; for (i = 0; i != data.length; i++) data[i] = calcProb(init, finl, distance, energyScale*i/(data.length-1)); setNeutrinoColor(g, finl); drawGraph(g, data, spectrumView); } if (animView != null) { int x = (int) ((t/10) % animView.width); double pos = x*distanceScale/animView.width; int p = (int) (255*calcProb(init, 0, pos, energy)); int c = 0xFFFFFFFF - p*0x10100; x += animView.x - 6; int ballSize = 13; g.setColor(new Color(c)); g.fillOval(x, animView.y, ballSize, ballSize); p = (int) (255*calcProb(init, 1, pos, energy)); c = 0xFFFFFFFF - p*0x10001; g.setColor(new Color(c)); g.fillOval(x, animView.y+16, ballSize, ballSize); p = (int) (255*calcProb(init, 2, pos, energy)); c = 0xFFFFFFFF - p*0x101; g.setColor(new Color(c)); g.fillOval(x, animView.y+32, ballSize, ballSize); cv.repaint(0); } if (infoView != null) { g.setColor(Color.black); FontMetrics fm = g.getFontMetrics(); int y = infoView.y + fm.getAscent(); g.drawString(getAngleString("theta12", th12), infoView.x, y); g.drawString(getAngleString("theta13", th13), infoView.x, y += fm.getHeight()); g.drawString(getAngleString("theta23", th23), infoView.x, y += fm.getHeight()); y = infoView.y + fm.getAscent(); int x = winSize.width*2/3; g.drawString("dm12 = " + showFormat.format(dm[0][1]*1e5) + " * 10^-5 eV^2", x, y); g.drawString("dm23 = " + showFormat.format(dm[1][2]*1e3) + " * 10^-3 eV^2", x, y += fm.getHeight()); g.drawString("dm13 = " + showFormat.format(dm[0][2]*1e5) + " * 10^-5 eV^2", x, y += fm.getHeight()); } realg.drawImage(dbimage, 0, 0, this); } String getAngleString(String name, double val) { double s = Math.sin(2*val); return name + " = " + showFormat.format(val/pi) + "*pi = " + (int)(val*180/pi) + "\u00b0, sin^2(2" + name + ") = " + showFormat.format(s*s); } void plotLine(Graphics g, View v, double val, double scale) { g.setColor(Color.gray); int x = v.x + (int) (v.width * val/scale); g.drawLine(x, v.graphTop, x, v.graphBottom); } String getDistanceText(double v) { if (v < 1e-3) return showFormat.format(v*1e5) + " cm"; if (v < 1) return showFormat.format(v*1e3) + " m"; return showFormat.format(v) + " km"; } String getUnitText(double v, String u) { double va = Math.abs(v); if (va < 1e-12) return "0 " + u; if (va < 1e-9) return showFormat.format(v*1e12) + " p" + u; if (va < 1e-6) return showFormat.format(v*1e9) + " n" + u; if (va < 1e-3) return showFormat.format(v*1e6) + " u" + u; if (va < 1) return showFormat.format(v*1e3) + " m" + u; if (va < 1e3) return showFormat.format(v) + " " + u; if (va < 1e6) return showFormat.format(v*1e-3) + " k" + u; if (va < 1e9) return showFormat.format(v*1e-6) + " M" + u; if (va < 1e12) return showFormat.format(v*1e-9) + " G" + u; return showFormat.format(v*1e-12) + " T" + u; } double matx[][] = new double[3][3]; double dm[][] = new double[3][3]; double calcProb(int n1, int n2, double dist, double e) { int i, j; double res = (n1 == n2) ? 1 : 0; for (i = 0; i != 2; i++) for (j = i+1; j != 3; j++) { double sn = Math.sin(dm[i][j]*dist*1.27/e); double q = matx[n1][i]*matx[n2][i]*matx[n1][j]*matx[n2][j] * sn*sn; res -= 4*q; } return res; } double th12, th13, th23; void calcMatrix() { dm[0][1] = 1e-5*dm12Bar.getValue()/100.; dm[1][2] = 1e-3*dm23Bar.getValue()/100.; dm[0][2] = dm[0][1] + dm[1][2]; th12 = angleBars[0].getValue()*2*pi/9999.; th13 = angleBars[1].getValue()*2*pi/9999.; th23 = angleBars[2].getValue()*2*pi/9999.; //System.out.println(th12 + " " + th13 + " " + th23); double c12 = Math.cos(th12); double c23 = Math.cos(th23); double c13 = Math.cos(th13); double s12 = Math.sin(th12); double s23 = Math.sin(th23); double s13 = Math.sin(th13); matx[0][0] = c12*c13; matx[0][1] = s12*c13; matx[0][2] = s13; matx[1][0] = -s12*c23 - c12*s23*s13; matx[1][1] = c12*c23 - s12*s23*s13; matx[1][2] = s23*c13; matx[2][0] = s12*s23 - c12*c23*s13; matx[2][1] = -c12*s23 - s12*c23*s13; matx[2][2] = c23*c13; } void drawThickLine(Graphics g, int x, int y, int x2, int y2) { g.drawLine(x, y, x2, y2); g.drawLine(x+1, y, x2+1, y2); //g.drawLine(x, y+1, x2, y2+1); //g.drawLine(x+1, y+1, x2+1, y2+1); } void drawGraphAxes(Graphics g, String title, View v, double scale) { FontMetrics fm = g.getFontMetrics(); g.setColor(Color.black); centerString(g, title, v.y+fm.getAscent()); int y = v.graphTop = v.y + fm.getHeight(); int y2 = v.graphBottom = v.y + v.height - (15+fm.getHeight()); int x1 = v.x; int i; g.setColor(Color.gray); double tick = 1; int step = 1, power; for (power = -10; power < 100; power++) { double q = Math.pow(10, power); if (q*24 > scale) { tick = q; break; } if (q*100 > scale) { tick = q; step = 5; break; } } for (i = step; tick*i < scale; i += step) { double val = tick*i; int x = (int) ((v.width-1)*val/scale) + v.x; g.drawLine(x, y2-5, x, y2+5); String s = i + ""; int xt = x-fm.stringWidth(s)/2; g.drawString(s, xt, y2+6+fm.getAscent()); } String xlabel; if (v == probView) { xlabel = "Distance in "; if (power < 0) { xlabel += "m"; power += 3; } else xlabel += "km"; } else { if (power < 0) { xlabel = "MeV"; power += 3; } else xlabel = "GeV"; } if (power != 0) xlabel += " * 10^" + power; centerString(g, xlabel, v.graphBottom + fm.getHeight() + fm.getAscent() + 5); g.setColor(Color.black); g.drawLine(x1, y, x1, y2); g.drawLine(x1, y2, v.x+v.width-1, y2); } void drawGraph(Graphics g, double data[], View v) { FontMetrics fm = g.getFontMetrics(); int y1 = v.graphTop; int y2 = v.graphBottom; int i; int ox = -1, oy = -1; for (i = 0; i != data.length; i++) { int x = v.x + v.width*i/(data.length-1); int y = y2+(int) ((y1-y2)*data[i]); if (ox != -1) drawThickLine(g, ox, oy, x, y); ox = x; oy = y; } } void drawBarChart(Graphics g, double data[], View v, int x, int w, String names[], String label[]) { int i; int y = v.y; double tot = 0; int barw = 20; FontMetrics fm = g.getFontMetrics(); int barh = v.height - 10 - fm.getHeight()*3; int w1 = barw + 10 + fm.stringWidth("tau = .99999"); int barx = x+(w-w1)/2; for (i = 0; i != 3; i++) { tot += data[i]; int y2 = v.y+(int) (barh*tot*.999); if (i == 3) y2 = v.y + barh; if (names == massNames) setMassColor(g, i); else setNeutrinoColor(g, i); g.fillRect(barx, y, barw, y2-y); y = y2; } g.setColor(Color.black); for (i = 0; i != 3; i++) { y = v.y + barh*(i*2+1)/6 + fm.getAscent()/2; if (names == massNames) setMassColor(g, i); else setNeutrinoColor(g, i); g.drawString(names[i] + " = " + showFormat.format(data[i]), barx + barw + 10, y); } g.setColor(Color.black); for (i = 0; i != 3; i++) g.drawString(label[i], x+w/2-fm.stringWidth(label[i])/2, v.y + v.height - fm.getHeight()*(3-i) + fm.getAscent()); } void setNeutrinoColor(Graphics g, int i) { g.setColor(i == 0 ? Color.blue : i == 1 ? Color.green : Color.red); } void setMassColor(Graphics g, int i) { g.setColor(i == 0 ? darkYellowColor : i == 1 ? Color.magenta : darkCyanColor); } public void componentHidden(ComponentEvent e) {} public void componentMoved(ComponentEvent e){} public void componentShown(ComponentEvent e) { cv.repaint(pause); } public void componentResized(ComponentEvent e) { handleResize(); cv.repaint(pause); } public void actionPerformed(ActionEvent e) { if (e.getSource() == exitItem) { applet.destroyFrame(); return; } if (e.getSource() == defaultsButton) { setAllDefaults(); cv.repaint(pause); } } public void adjustmentValueChanged(AdjustmentEvent e) { System.out.print(((Scrollbar) e.getSource()).getValue() + "\n"); /*if ((e.getSource()) == inputBar) setInputW();*/ setScales(); cv.repaint(pause); } void setScales() { distanceScale = Math.pow(10, .1*distanceScaleBar.getValue()-2); energyScale = Math.pow(10, .1*energyScaleBar.getValue()-2); } public boolean handleEvent(Event ev) { if (ev.id == Event.WINDOW_DESTROY) { applet.destroyFrame(); return true; } return super.handleEvent(ev); } public void mouseDragged(MouseEvent e) { mouseX = e.getX(); mouseY = e.getY(); edit(e); cv.repaint(pause); } public void mouseMoved(MouseEvent e) { dragX = mouseX = e.getX(); dragY = mouseY = e.getY(); cv.repaint(pause); /*if (respView != null && respView.contains(e.getX(), e.getY())) selection = SELECT_RESPONSE; if (spectrumView != null && spectrumView.contains(e.getX(), e.getY())) selection = SELECT_SPECTRUM; if (polesView != null && polesView.contains(e.getX(), e.getY()) && !ferrisCheckItem.getState()) { selection = SELECT_POLES; selectPoleZero(e.getX(), e.getY()); }*/ } public void mouseClicked(MouseEvent e) { edit(e); } public void mouseEntered(MouseEvent e) { } public void mouseExited(MouseEvent e) { } public void mousePressed(MouseEvent e) { mouseMoved(e); edit(e); } public void mouseReleased(MouseEvent e) { } void edit(MouseEvent e) { int x = e.getX(); int y = e.getY(); if (probView.contains(x, y)) { double q = (x-probView.x)/(double) probView.width; if (q >= 0 && q <= 1) distance = q*distanceScale; } if (spectrumView.contains(x, y)) { double q = (x-spectrumView.x)/(double) spectrumView.width; if (q >= 0 && q <= 1) energy = q*energyScale; } } public void itemStateChanged(ItemEvent e) { if (e.getItemSelectable() == setupChooser) { setDefaults(); cv.repaint(pause); } if (e.getItemSelectable() == initialChooser) { finalChooser.select(initialChooser.getSelectedIndex()); cv.repaint(pause); } if (e.getItemSelectable() instanceof CheckboxMenuItem) { handleResize(); cv.repaint(pause); } } };