aboutsummaryrefslogtreecommitdiffstats
path: root/demos/MiscDemos/GLImageViewerWorld.java
blob: f00bd062427d767184d57015c1c3602136d0a553 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
import gl4java.*;
import gl4java.awt.*;
import gl4java.utils.textures.*;

import java.awt.*;
import java.awt.event.*;
import java.net.*;

public class GLImageViewerWorld extends Frame 
    implements ActionListener
{
    GLImageWorld1 glImageCanvas = null;

    private Choice fileTypeChoice = null;
    private Button loadButton = null;
    private Button saveButton = null;
    private Button normalButton = null;

    public GLImageViewerWorld(String title)
    {
        super(title);
	setSize(500, 300);
        Dimension d = getSize();
        setLayout(new BorderLayout());

	addWindowListener( new WindowAdapter()
			{
				public void windowClosed(WindowEvent e)
				{
					System.exit(0);
				}
				public void windowClosing(WindowEvent e)
				{
					windowClosed(e);
				}
			}
		);

	Panel filePanel = new Panel();
	filePanel.setLayout(new FlowLayout(FlowLayout.CENTER));

	fileTypeChoice = new Choice();
	fileTypeChoice.add("any");
	fileTypeChoice.add("tga");
	fileTypeChoice.add("png");
	fileTypeChoice.add("ppm");
	filePanel.add(fileTypeChoice);

        loadButton = new Button("load..");
	loadButton.addActionListener(this);
	filePanel.add(loadButton);

        saveButton = new Button("save..");
	saveButton.addActionListener(this);
	filePanel.add(saveButton);

        normalButton = new Button("normal");
	normalButton.addActionListener(this);
	filePanel.add(normalButton);

        add("North", filePanel);

	glImageCanvas = new GLImageWorld1(d.width, d.height);
	glImageCanvas.setName("GLImageWorld1");
        add("Center", glImageCanvas);

	pack();
	setVisible(true);
    }

    public void actionPerformed(ActionEvent e)
    {
    	Object src = e.getSource();
	if(src.equals(loadButton)) 
	{
	    FileDialog fd = new FileDialog(this,"Bitmap Load Menu",
	    				   FileDialog.LOAD);
	    fd.show();
	    String fname = fd.getDirectory() + fd.getFile() ;
	    fname = fname.replace('\\','/');
	    fname = fname.trim();

	    setTitle(fname);
	    glImageCanvas.loadTexture(fname, 
	    		              fileTypeChoice.getSelectedItem() );
	    repaint();
	} else if(src.equals(saveButton)) 
	{
	    FileDialog fd = new FileDialog(this,"TGA-Image Save Menu",
	    				   FileDialog.SAVE);
	    fd.show();
	    String fname = fd.getDirectory() + fd.getFile() ;
	    fname = fname.replace('\\','/');
	    fname = fname.trim();

	    setTitle(fname);
	    glImageCanvas.snapshot( new TGATextureGrabber(glImageCanvas.gl),
		                    fname);
	    repaint();
	} else if(src.equals(normalButton)) 
	{
	    glImageCanvas.setOriginalPerspective();
	}
    }

	public static void main( String args[] ) 
	{
		GLImageViewerWorld applet = 
			new GLImageViewerWorld("GLImageViewerWorld");
	}
}