import java.awt.*; import java.awt.event.*; import java.applet.*; import java.util.Enumeration; import javax.swing.event.*; public class GetRayConfig extends Applet implements AdjustmentListener, ItemListener, MouseListener { RayConfigReceiver seeRenderedApplet = null; float minweight = .01f; int maxdepth = 4; float trans = 0; int UIOrientation = Scrollbar.HORIZONTAL; boolean updatedslider = false; RayTeacher mom = null; double savevalue = 0; int currentchoice = 0; Choice choice; Scrollbar slider; Label setting; public void setMom(RayTeacher m) { mom = m; } public void init() { // Only set nondefault values if those parameters are specified System.out.println("Initializing Config: " + getName()); String inputStr = mom.getParameter("minweight"); if (inputStr != null) { Float inputStrFloat = new Float(inputStr); if (!inputStrFloat.isNaN()) { minweight = inputStrFloat.floatValue(); } } inputStr = mom.getParameter("maxdepth"); if (inputStr != null) { Integer inputStrInteger = new Integer(inputStr); maxdepth = inputStrInteger.intValue(); } inputStr = mom.getParameter("scenetrans"); if (inputStr != null) { Float inputStrFloat = new Float(inputStr); if (!inputStrFloat.isNaN()) { trans = inputStrFloat.floatValue(); } } savevalue = (double)(maxdepth); // if ((getSize().width > 230) && (getSize().width > getSize().height)) { // UIOrientation = Scrollbar.HORIZONTAL; // } GridBagConstraints c = new GridBagConstraints(); GridBagLayout gridbag = new GridBagLayout(); setLayout(gridbag); Label label = new Label("Ray termination by:", Label.CENTER); gridbag.setConstraints(label, c); add(label); choice = new Choice(); choice.addItem("adaptive threshold"); choice.addItem("recursive depth"); if (UIOrientation == Scrollbar.VERTICAL) { c.gridx = 0; c.gridy = 1; } else { c.gridx = 1; c.gridy = 0; } gridbag.setConstraints(choice, c); add(choice); c.gridx = 0; setting = new Label("0%", Label.CENTER); if (UIOrientation == Scrollbar.HORIZONTAL) { c.gridy = 1; c.fill = GridBagConstraints.HORIZONTAL; gridbag.setConstraints(setting, c); c.weightx = .4; add(setting); c.weightx = .6; c.gridx = 1; } else { c.gridy = 2; c.fill = GridBagConstraints.VERTICAL; c.weighty = .5; } slider = new Scrollbar(UIOrientation, 0, 1, 0, 21); slider.setBlockIncrement(2); gridbag.setConstraints(slider, c); add(slider); if (UIOrientation == Scrollbar.VERTICAL) { c.weightx = c.weighty = 0.; c.gridx = 0; c.gridy = 3; c.fill = GridBagConstraints.HORIZONTAL; gridbag.setConstraints(setting, c); add(setting); } slider.addAdjustmentListener(this); slider.addMouseListener(this); choice.addItemListener(this); slider.setValue(20 - (int)(minweight * 100f / 5f)); updateSetting(true); System.out.println("Finished Initializing Config"); } // ray termination method updated public void itemStateChanged(ItemEvent e) { // Was a change made? if (currentchoice != choice.getSelectedIndex()) { currentchoice = choice.getSelectedIndex(); // swap current slider value with savevalue double oldvalue = slider.getValue(); slider.setValue((int)savevalue); updateSetting(true); savevalue = oldvalue; } } public void mouseClicked(MouseEvent e) { } public void mousePressed(MouseEvent e) { } public void mouseReleased(MouseEvent e) { } // mouse entered slider public void mouseEntered(MouseEvent e) { updatedslider = false; } // mouse exited slider public void mouseExited(MouseEvent e) { if (updatedslider) updateSetting(true); } // slider position updated public void adjustmentValueChanged(AdjustmentEvent e) { updateSetting(false); } // update the slider text string synchronized void updateSetting(boolean isfinal) { updatedslider = true; if (choice.getSelectedIndex() == 0) { // adaptive? float adaptivesetting = (float)slider.getValue() * 5f; adaptivesetting = 100f - adaptivesetting; setting.setText(String.valueOf(adaptivesetting) + "%"); mom.ren.setParameters(isfinal, adaptivesetting / 100f, 20, trans); } else { int recursivedepth = (int)slider.getValue(); setting.setText(String.valueOf(recursivedepth)); mom.ren.setParameters(isfinal, 0f, recursivedepth, trans); } } // Draws a box around the applet public void paint(Graphics g) { // System.out.println("Config.paint called"); Dimension d = getSize(); g.drawRect(0,0, d.width - 1, d.height - 1); super.paint(g); } public Insets getInsets() { return new Insets(5,5,5,5); } // avoid unnecesary clean on each paint() public void update(Graphics g) { paint(g); } }