package frame; import java.awt.BorderLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.IOException; import java.net.URL; import java.util.ArrayList; import javax.swing.ImageIcon; import javax.swing.JButton; import javax.swing.JEditorPane; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JScrollPane; /** * Class to display custom window with information about * necessary licenses + copyright information * * @author * @version */ @SuppressWarnings("serial") public class licenseWindow extends JFrame { //Class variables JButton previous, next; JLabel licenseName; JEditorPane licenseText; JScrollPane licenseScroll; ArrayList licenseList; ArrayList licenseNameList; int index; /** * Default constructor for License frame * */ public licenseWindow() { //Make frame with size, location, layout super("Licenses"); this.setSize(600, 400); this.setLocationRelativeTo(null); this.setLayout(new BorderLayout()); //Set the frame icon to an image loaded from a file. this.setIconImage(new ImageIcon(getClass().getResource("/resources/16x16/creative_commons.png")).getImage()); //Add licenses to list licenseList = new ArrayList(); licenseList.add(getClass().getResource("/resources/apache license.txt")); licenseList.add(getClass().getResource("/resources/ganymed license.txt")); licenseList.add(getClass().getResource("/resources/CC0 1.0 Universal.txt")); licenseList.add(getClass().getResource("/resources/Attribution 3.0 Unported.txt")); licenseList.add(getClass().getResource("/resources/Attribution-ShareAlike 3.0 Unported.txt")); licenseList.add(getClass().getResource("/resources/WTFPL.txt")); //Add license names to list licenseNameList = new ArrayList(); licenseNameList.add("Apache License"); licenseNameList.add("Ganymed SSH2 License"); licenseNameList.add("Creative Commons 0 1.0 Universal"); licenseNameList.add("Creative Commons - Attribution"); licenseNameList.add("Creative Commons - Attribution Share Alike"); licenseNameList.add("WTFPL - Do What The Fuck You Want To Public License"); //Make starting index index = 0; //Make label for license title licenseName = new JLabel(""); licenseName.setHorizontalAlignment(JLabel.CENTER); //TODO pick a font //licenseName.setFont(new Font("Times New Roman", Font.BOLD, 25)); //Text editor pane with legal license text licenseText = new JEditorPane(); licenseText.setEditable(false); licenseText.setContentType("text/html"); //Load first license setLicense(index); licenseScroll = new JScrollPane(licenseText); //Make JButton for previous and next ImageIcon prevIco = new ImageIcon(getClass().getResource("/resources/32x32/arrow_left.png")); previous = new JButton(prevIco); previous.setEnabled(false); previous.addActionListener(new ActionListener(){ @Override public void actionPerformed(ActionEvent arg0) { showPrevious(); } }); ImageIcon nextIco = new ImageIcon(getClass().getResource("/resources/32x32/arrow_right.png")); next = new JButton(nextIco); next.setEnabled(true); next.addActionListener(new ActionListener(){ @Override public void actionPerformed(ActionEvent e) { showNext(); } }); //TODO fix so that buttons retain smaller size after adding to layout previous.setSize(50, 50); next.setSize(50, 50); //Add everything to panel and make it viewable this.add(licenseName, BorderLayout.NORTH); this.add(previous, BorderLayout.WEST); this.add(licenseScroll, BorderLayout.CENTER); this.add(next, BorderLayout.EAST); this.setVisible(true); } private void setLicense(int i) { licenseName.setText(licenseNameList.get(i)); try { licenseText.setPage(licenseList.get(i)); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } this.repaint(); } /** * Shows next license to display * */ protected void showNext() { index++; setLicense(index); if(index > 0) { previous.setEnabled(true); } if(index == licenseList.size() - 1) { next.setEnabled(false); } } /** * Show previous license to display * */ protected void showPrevious() { index--; setLicense(index); if(index == 0) { previous.setEnabled(false); } if(index < licenseList.size() - 1) { next.setEnabled(true); } } }