// (C) 2001 SyGem Software import java.awt.*; import java.applet.Applet; import com.sygem.jazz3d3.*; import com.sygem.jazz3d3.primitive.Font3d; import com.sygem.jazz3d3.primitive.Text3d; // Class textExplorer public class textExplorer extends Applet implements Runnable { final int MenuBarHeight = 0; // Component Declaration public World myWorld; public Choice fontChoice; public Label Label1; public Label Label2; public TextField TextField1; public Button updateTextButton; public Label Label3; public Choice sizeChoice; public Choice depthChoice; public Label Label4; // End of Component Declaration Thread m_ce; int light1; int pid; int downx = 0; int downy = 0; double ddx = 0; double ddy = 0; boolean down = false; Font3d arial; Font3d courier; Font3d comic; Font3d century; Font3d times; Text3d mainText; // init() public void init() { // Frame Initialization setForeground(Color.black); setBackground(Color.lightGray); setFont(new Font("Dialog",Font.BOLD,12)); setLayout(null); // End of Frame Initialization // Component Initialization myWorld = new World(this); fontChoice = new Choice(); fontChoice.setFont(new Font("Dialog",Font.BOLD,12)); fontChoice.addItem("Arial"); fontChoice.addItem("ComicSans"); fontChoice.addItem("Courier"); fontChoice.addItem("20thCenturyFont"); fontChoice.addItem("TimesNewRoman"); Label1 = new Label("Select Font:",Label.LEFT); Label1.setFont(new Font("Dialog",Font.BOLD,12)); Label2 = new Label("Enter Text:",Label.LEFT); Label2.setFont(new Font("Dialog",Font.BOLD,12)); TextField1 = new TextField("Some Text"); TextField1.setForeground(Color.black); TextField1.setBackground(Color.white); TextField1.setFont(new Font("Dialog",Font.BOLD,12)); updateTextButton = new Button("Update Text"); updateTextButton.setFont(new Font("Dialog",Font.BOLD,12)); Label3 = new Label("Size:",Label.LEFT); Label3.setFont(new Font("Dialog",Font.BOLD,12)); sizeChoice = new Choice(); sizeChoice.addItem("0.1"); sizeChoice.addItem("0.2"); sizeChoice.addItem("0.3"); sizeChoice.addItem("0.4"); sizeChoice.addItem("0.5"); sizeChoice.addItem("0.6"); sizeChoice.addItem("0.7"); sizeChoice.addItem("0.8"); sizeChoice.addItem("0.9"); sizeChoice.addItem("1.0"); sizeChoice.setFont(new Font("Dialog",Font.BOLD,12)); depthChoice = new Choice(); depthChoice.addItem("0.05"); depthChoice.addItem("0.1"); depthChoice.addItem("0.15"); depthChoice.addItem("0.2"); depthChoice.addItem("0.25"); depthChoice.addItem("0.3"); depthChoice.addItem("0.35"); depthChoice.addItem("0.4"); depthChoice.addItem("0.45"); depthChoice.addItem("0.5"); depthChoice.setFont(new Font("Dialog",Font.BOLD,12)); Label4 = new Label("Depth:",Label.LEFT); Label4.setFont(new Font("Dialog",Font.BOLD,12)); // End of Component Initialization // Add()s add(Label4); add(depthChoice); add(sizeChoice); add(Label3); add(updateTextButton); add(TextField1); add(Label2); add(Label1); add(fontChoice); add(myWorld); // End of Add()s InitialPositionSet(); } // End of init() // start() public void start() { if (m_ce == null) { m_ce = new Thread(this); m_ce.start(); } } // End of start() // stop() public void stop() { if (m_ce != null) { m_ce.stop(); m_ce = null; } } // End of stop() // destroy() public void destroy() { } // End of destroy() public void run() { // Jazz3D components RenderSolid rSolid = new RenderSolid(); // Put something here to print to the screen when loading fonts arial = new Font3d("fonts/Arial.f3d"); comic = new Font3d("fonts/ComicSans.f3d"); courier = new Font3d("fonts/Courier.f3d"); century = new Font3d("fonts/20thCenturyFont.f3d"); times = new Font3d("fonts/TimesNewRoman.f3d"); mainText = new Text3d("Some Text", arial, 0.5, 0.1, 0.1, 0, 0, 8); mainText.setRenderer(rSolid); pid = myWorld.addObject(mainText); Light l1 = new Light(0,0,1); myWorld.addLight(l1); // End of Jazz3D components double z; ddx = 0.16; ddy = 0.35; z = 0.0; myWorld.prep(); while (true) { myWorld.getParentObject(pid).rotateWorld(ddy,ddx,z); myWorld.redraw(); } } public void InitialPositionSet() { // InitialPositionSet() resize(458,273); myWorld.reshape(4,5+MenuBarHeight,273,264); fontChoice.reshape(283,25+MenuBarHeight,170,27); Label1.reshape(286,6+MenuBarHeight,98,19); Label2.reshape(287,60+MenuBarHeight,86,19); TextField1.reshape(284,87+MenuBarHeight,167,27); updateTextButton.reshape(314,213+MenuBarHeight,111,25); Label3.reshape(287,128+MenuBarHeight,41,19); sizeChoice.reshape(287,150+MenuBarHeight,81,27); depthChoice.reshape(372,150+MenuBarHeight,81,27); Label4.reshape(376,129+MenuBarHeight,55,19); // End of InitialPositionSet() } public boolean handleEvent(Event evt) { // handleEvent() if (evt.id == Event.WINDOW_DESTROY && evt.target == this) textExplorer_WindowDestroy(evt.target); // End of handleEvent() return super.handleEvent(evt); } public boolean action(Event evt, Object s) { if (evt.target == updateTextButton ) { myWorld.suspend(); myWorld.deleteObject(pid); String textString = TextField1.getText().trim(); int fontID = fontChoice.getSelectedIndex(); Font3d tempFont; switch (fontID) { case 0: tempFont = arial; break; case 1: tempFont = comic; break; case 2: tempFont = courier; break; case 3: tempFont = century; break; case 4: tempFont = times; break; default: tempFont = arial; } double size = (sizeChoice.getSelectedIndex()+1)*0.1; double depth = (depthChoice.getSelectedIndex()+1)*0.05; Text3d newText = new Text3d(textString, tempFont, size, 0.1, depth, 0,0,8); RenderSolid rSolid = new RenderSolid(); newText.setRenderer(rSolid); pid = myWorld.addObject(newText); myWorld.prepNewObjects(); myWorld.resume(); } return super.action(evt,s); } // Event Handling Routines public void textExplorer_WindowDestroy(Object target) { System.exit(0); } // End of Event Handling Routines public boolean mouseDown(Event evt, int x, int y) { downx = x; downy = y; down = true; return true; } public boolean mouseUp(Event evt, int x, int y) { down = false; return true; } public boolean mouseDrag(Event evt, int x, int y) { if (down) { double dx = x - downx; double dy = y - downy; ddx = (dx / (this.size().width))*10.0; ddy = (dy / (this.size().height))*10.0; } return true; } } // End of Class textExplorer