1 23 package org.enhydra.kelp.common.dods; 24 25 import java.awt.*; 27 import javax.swing.*; 28 import java.beans.*; 29 30 public class InstructPanel extends JPanel { 32 private GridBagLayout layoutMain = null; 33 private JPanel panelHelp = null; 34 private JPanel panelOptions = null; 35 private GridBagLayout layoutHelp = null; 36 private JLabel labelTitle = null; 37 private BorderLayout layoutOptions = null; 38 private JTextArea textInstruct = null; 39 40 public InstructPanel() { 41 try { 42 jbInit(); 43 pmInit(); 44 } catch (Exception ex) { 45 ex.printStackTrace(); 46 } 47 } 48 49 protected String getInstruction() { 51 return textInstruct.getText(); 52 } 53 54 protected void setInstructions(String text) { 55 textInstruct.setText(text); 56 } 57 58 protected void setTitle(String text) { 59 labelTitle.setText(text); 60 } 61 62 protected String getTitle() { 63 return labelTitle.getText(); 64 } 65 66 protected void addInstuctor(Instructor i) { 67 if (i instanceof JPanel) { 68 panelOptions.removeAll(); 69 panelOptions.add((JPanel) i, BorderLayout.CENTER); 70 setInstructions(i.getInstructions()); 71 setTitle(i.getTitle()); 72 } else { 73 throw new RuntimeException ("Instructor not a JPanel " 74 + i.getTitle()); 75 } 76 } 77 78 private void pmInit() { 80 Font font = labelTitle.getFont(); 81 82 font = new Font(font.getName(), Font.BOLD, font.getSize()); 83 labelTitle.setFont(font); 84 font = new Font(font.getName(), 0, font.getSize()); 85 textInstruct.setFont(font); 86 textInstruct.setBackground(labelTitle.getBackground()); 87 } 88 89 private void jbInit() throws Exception { 90 labelTitle = (JLabel) Beans.instantiate(getClass().getClassLoader(), 91 JLabel.class.getName()); 92 panelHelp = (JPanel) Beans.instantiate(getClass().getClassLoader(), 93 JPanel.class.getName()); 94 panelOptions = (JPanel) Beans.instantiate(getClass().getClassLoader(), 95 JPanel.class.getName()); 96 layoutMain = 97 (GridBagLayout) Beans.instantiate(getClass().getClassLoader(), 98 GridBagLayout.class.getName()); 99 layoutHelp = 100 (GridBagLayout) Beans.instantiate(getClass().getClassLoader(), 101 GridBagLayout.class.getName()); 102 layoutOptions = 103 (BorderLayout) Beans.instantiate(getClass().getClassLoader(), 104 BorderLayout.class.getName()); 105 textInstruct = 106 (JTextArea) Beans.instantiate(getClass().getClassLoader(), 107 JTextArea.class.getName()); 108 labelTitle.setText("TITLE"); 109 panelHelp.setLayout(layoutHelp); 110 textInstruct.setWrapStyleWord(true); 111 textInstruct.setLineWrap(true); 112 textInstruct.setEnabled(false); 113 textInstruct.setText("INSTRUCTIONS"); 114 textInstruct.setDisabledTextColor(UIManager.getColor("textText")); 115 textInstruct.setBackground(UIManager.getColor("text")); 116 textInstruct.setEditable(false); 117 panelHelp.add(labelTitle, 118 new GridBagConstraints(0, 0, 1, 1, 0.1, 0.0, 119 GridBagConstraints.WEST, 120 GridBagConstraints.HORIZONTAL, 121 new Insets(3, 5, 1, 5), 0, 0)); 122 panelHelp.add(textInstruct, 123 new GridBagConstraints(0, 1, 1, 1, 0.1, 0.0, 124 GridBagConstraints.CENTER, 125 GridBagConstraints.HORIZONTAL, 126 new Insets(1, 5, 2, 5), 0, 0)); 127 panelOptions.setLayout(layoutOptions); 128 this.setLayout(layoutMain); 129 this.add(panelHelp, 130 new GridBagConstraints(0, 0, 1, 1, 0.1, 0.0, 131 GridBagConstraints.NORTH, 132 GridBagConstraints.BOTH, 133 new Insets(5, 5, 5, 5), 0, 0)); 134 this.add(panelOptions, 135 new GridBagConstraints(0, 3, 1, 1, 0.1, 0.9, 136 GridBagConstraints.SOUTH, 137 GridBagConstraints.BOTH, 138 new Insets(2, 5, 2, 5), 0, 0)); 139 } 140 141 } 142 | Popular Tags |