FileDocCategorySizeDatePackage
DemoModule.javaAPI DocSun JDK 1.4.2 Example7688Thu May 12 00:35:28 BST 2005None

DemoModule

public class DemoModule extends JApplet
A generic SwingSet2 demo module
version
1.14 01/23/03
author
Jeff Dinkins

Fields Summary
private int
PREFERRED_WIDTH
private int
PREFERRED_HEIGHT
Border
loweredBorder
public static Dimension
HGAP2
public static Dimension
VGAP2
public static Dimension
HGAP5
public static Dimension
VGAP5
public static Dimension
HGAP10
public static Dimension
VGAP10
public static Dimension
HGAP15
public static Dimension
VGAP15
public static Dimension
HGAP20
public static Dimension
VGAP20
public static Dimension
HGAP25
public static Dimension
VGAP25
public static Dimension
HGAP30
public static Dimension
VGAP30
private SwingSet2
swingset
private JPanel
panel
private String
resourceName
private String
iconPath
private String
sourceCode
private ResourceBundle
bundle
Constructors Summary
public DemoModule(SwingSet2 swingset)


       
	this(swingset, null, null);
    
public DemoModule(SwingSet2 swingset, String resourceName, String iconPath)

	panel = new JPanel();
	panel.setLayout(new BorderLayout());

	this.resourceName = resourceName;
	this.iconPath = iconPath;
	this.swingset = swingset;

	loadSourceCode();
    
Methods Summary
public javax.swing.JPanelcreateHorizontalPanel(boolean threeD)

        JPanel p = new JPanel();
        p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS));
        p.setAlignmentY(TOP_ALIGNMENT);
        p.setAlignmentX(LEFT_ALIGNMENT);
        if(threeD) {
            p.setBorder(loweredBorder);
        }
        return p;
    
public javax.swing.ImageIconcreateImageIcon(java.lang.String filename, java.lang.String description)

	if(getSwingSet2() != null) {
	    return getSwingSet2().createImageIcon(filename, description);
	} else {
	    String path = "/resources/images/" + filename;
	    return new ImageIcon(getClass().getResource(path), description); 
	}
    
public javax.swing.JPanelcreateVerticalPanel(boolean threeD)

        JPanel p = new JPanel();
        p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS));
        p.setAlignmentY(TOP_ALIGNMENT);
        p.setAlignmentX(LEFT_ALIGNMENT);
        if(threeD) {
            p.setBorder(loweredBorder);
        }
        return p;
    
public javax.swing.JPanelgetDemoPanel()

	return panel;
    
public javax.swing.IcongetIcon()

	return createImageIcon(iconPath, getResourceName() + ".name");
    
public chargetMnemonic(java.lang.String key)

	return (getString(key)).charAt(0);
    
public java.lang.StringgetName()

	return getString(getResourceName() + ".name");
    
public java.lang.StringgetResourceName()

	return resourceName;
    
public java.lang.StringgetSourceCode()

	return sourceCode;
    
public java.lang.StringgetString(java.lang.String key)

	String value = "nada";
	if(bundle == null) {
	    if(getSwingSet2() != null) {
		bundle = getSwingSet2().getResourceBundle();
	    } else {
		bundle = ResourceBundle.getBundle("resources.swingset");
	    }
	}
	try {
	    value = bundle.getString(key);
	} catch (MissingResourceException e) {
	    System.out.println("java.util.MissingResourceException: Couldn't find value for: " + key);
	}
	return value;
    
public SwingSet2getSwingSet2()

	return swingset;
    
public java.lang.StringgetToolTip()

	return getString(getResourceName() + ".tooltip");
    
public voidinit()

        getContentPane().setLayout(new BorderLayout());
        getContentPane().add(getDemoPanel(), BorderLayout.CENTER);
    
public voidloadSourceCode()

	if(getResourceName() != null) {
	    String filename = "src/" + getResourceName() + ".java";
	    sourceCode = new String("<html><body bgcolor=\"#ffffff\"><pre>");
	    char[] buff = new char[50000];
	    InputStream is;
	    InputStreamReader isr;
	    CodeViewer cv = new CodeViewer();
	    URL url;
	    
	    try {
		url = getClass().getResource(filename); 
		is = url.openStream();
		isr = new InputStreamReader(is);
		BufferedReader reader = new BufferedReader(isr);
		
		// Read one line at a time, htmlize using super-spiffy
		// html java code formating utility from www.CoolServlets.com
		String line = reader.readLine();
		while(line != null) {
		    sourceCode += cv.syntaxHighlight(line) + " \n ";
		    line = reader.readLine();
		}
		sourceCode += new String("</pre></body></html>");
            } catch (Exception ex) {
                sourceCode = "Could not load file: " + filename;
            }
	}
    
public static voidmain(java.lang.String[] args)

	DemoModule demo = new DemoModule(null);
	demo.mainImpl();
    
public voidmainImpl()

	JFrame frame = new JFrame(getName());
        frame.getContentPane().setLayout(new BorderLayout());
	frame.getContentPane().add(getDemoPanel(), BorderLayout.CENTER);
	getDemoPanel().setPreferredSize(new Dimension(PREFERRED_WIDTH, PREFERRED_HEIGHT));
	frame.pack();
	frame.show();