View Javadoc
1   package net.sourceforge.jsh3modtool.gui.mod;
2   
3   import java.awt.BorderLayout;
4   import java.util.Iterator;
5   
6   import javax.swing.JComponent;
7   import javax.swing.JEditorPane;
8   import javax.swing.JPanel;
9   import javax.swing.JLabel;
10  import javax.swing.JScrollPane;
11  import javax.swing.JTextArea;
12  
13  import net.sourceforge.jsh3modtool.mod.GameMod;
14  import net.sourceforge.jsh3modtool.mod.ModAuthor;
15  
16  /***
17   * @author Administratör
18   */
19  public class ModSummaryPanel extends JPanel
20  {
21      private GameMod gameMod;
22  	private JScrollPane modSummaryScrollPane = null;
23  	private JLabel modNameLabel = null;
24  
25  	private JComponent modDescriptionTextArea = null;
26  	/***
27  	 * This is the default constructor
28  	 */
29  	public ModSummaryPanel(GameMod gamemod) 
30  	{
31  		super();
32  		gameMod = gamemod;
33  		initialize();
34  	}
35  	
36  	/***
37  	 * This method initializes this
38  	 * 
39  	 * @return void
40  	 */
41  	private  void initialize() {
42  
43  		modNameLabel = new JLabel();
44  		this.setLayout(new BorderLayout());
45  		this.setSize(342, 264);
46  		modNameLabel.setText("<html><body>" + gameMod.getName() + " (" + gameMod.getVersion() + ")</html></body>");
47  		modNameLabel.setFont(new java.awt.Font("Dialog", java.awt.Font.BOLD, 18));
48  		this.add(getModSummaryScrollPane(), java.awt.BorderLayout.CENTER);
49  		this.add(modNameLabel, java.awt.BorderLayout.NORTH);
50  	}
51  	/***
52  	 * This method initializes jScrollPane	
53  	 * 	
54  	 * @return javax.swing.JScrollPane	
55  	 */    
56  	private JScrollPane getModSummaryScrollPane() {
57  		if (modSummaryScrollPane == null) {
58  
59  		    
60  			modSummaryScrollPane = new JScrollPane();
61  			modSummaryScrollPane.setVerticalScrollBarPolicy(javax.swing.JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
62  			modSummaryScrollPane.setViewportView(getModDescriptionTextArea());
63  		}
64  		return modSummaryScrollPane;
65  	}
66  	
67  	/***
68  	 * This method initializes jTextArea	
69  	 * 	
70  	 * @return javax.swing.JTextArea	
71  	 */    
72  	private JComponent getModDescriptionTextArea() {
73  		if (modDescriptionTextArea == null) {
74  		    
75  
76  		    StringBuffer buffer = new StringBuffer();
77  		    buffer.append("<html><body>");
78  		    buffer.append(gameMod.getDescription());
79  		    if (gameMod.getAuthors().size() > 0)
80  		    {
81  		        buffer.append("<ul>Authors");
82  		        for (Iterator iterator = gameMod.getAuthors().iterator(); iterator.hasNext();)
83                  {
84  		            ModAuthor modAuthor = (ModAuthor) iterator.next();
85  		            buffer.append("<li><b>");
86  		            buffer.append(modAuthor.getAlias());
87  		            buffer.append("</b>");
88  		            if (modAuthor.getEmail() != null)
89  		            {
90  		                buffer.append(" (");
91  		                buffer.append(modAuthor.getEmail());
92  		                buffer.append(" )");
93  		            }
94  		            if (modAuthor.getEmail() != null)
95  		            {
96  		                buffer.append(" - ");
97  		                buffer.append(modAuthor.getWebsite());
98  		            }                    
99                  }
100 		        buffer.append("</ul>");
101 		    }
102 		    
103 		    buffer.append("</body></html>");
104 		    
105 		    
106 		    JEditorPane panel = new JEditorPane("text/html", buffer.toString());
107 		    panel.setEditable(false);
108 		    modDescriptionTextArea = panel;
109 		    
110 		    
111 			//modDescriptionTextArea = new JLabel(buffer.toString());
112 			/*modDescriptionTextArea.setLineWrap(true);
113 			modDescriptionTextArea.setWrapStyleWord(true);
114 			modDescriptionTextArea.setEditable(false);*/
115 		}
116 		return modDescriptionTextArea;
117 	}
118  }  //  @jve:decl-index=0:visual-constraint="10,10"