1 14 package org.compiere.util; 15 16 import java.awt.BorderLayout ; 17 import java.awt.Color ; 18 import java.awt.Dimension ; 19 import java.awt.FlowLayout ; 20 import java.awt.event.ActionEvent ; 21 import java.awt.event.ActionListener ; 22 import java.net.URL ; 23 import java.util.ResourceBundle ; 24 25 import javax.swing.JButton ; 26 import javax.swing.JDialog ; 27 import javax.swing.JEditorPane ; 28 import javax.swing.JLabel ; 29 import javax.swing.JPanel ; 30 import javax.swing.JScrollPane ; 31 32 import org.compiere.plaf.CompierePLAF; 33 34 40 public final class IniDialog extends JDialog implements ActionListener 41 { 42 45 public IniDialog() 46 { 47 super(); 48 try 49 { 50 jbInit(); 51 String where = s_res.getString("license_htm"); 53 if (where == null || where.length() == 0) 54 { 55 System.err.println("IniDialog - no license pointer in resource"); 56 where = "org/compiere/license.htm"; 57 } 58 URL url = getClass().getClassLoader().getResource(where); 59 if (url == null) 60 { 61 System.err.println("IniDialog - no license in resource "); 62 url = new URL ("http://www.compiere.org/license.htm"); 63 } 64 if (url == null) 65 cmd_reject(); 66 licensePane.setPage(url); 68 CompierePLAF.showCenterScreen(this); 69 } 70 catch (Exception ex) 71 { 72 System.err.println("IniDialog error: " + ex.toString()); 73 ex.printStackTrace(); 74 cmd_reject(); 75 } 76 } 78 79 static ResourceBundle s_res = ResourceBundle.getBundle("org.compiere.util.IniRes"); 80 private boolean m_accept = false; 81 82 private JPanel mainPanel = new JPanel (); 83 private BorderLayout mainLayout = new BorderLayout (); 84 private JScrollPane scrollPane = new JScrollPane (); 85 private JPanel southPanel = new JPanel (); 86 private JButton bReject = CompierePLAF.getCancelButton(); 87 private JButton bAccept = CompierePLAF.getOKButton(); 88 private FlowLayout southLayout = new FlowLayout (); 89 private JLabel southLabel = new JLabel (); 90 private JEditorPane licensePane = new JEditorPane (); 91 92 96 private void jbInit() throws Exception 97 { 98 setTitle("Compiere - " + s_res.getString("Compiere_License")); 99 southLabel.setText(s_res.getString("Do_you_accept")); 100 bReject.setText(s_res.getString("No")); 101 bAccept.setText(s_res.getString("Yes_I_Understand")); 102 setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); 104 setModal(true); 105 mainPanel.setLayout(mainLayout); 107 bReject.setForeground(Color.red); 108 bReject.addActionListener(this); 109 bAccept.addActionListener(this); 110 southPanel.setLayout(southLayout); 111 southLayout.setAlignment(FlowLayout.RIGHT); 112 licensePane.setEditable(false); 113 licensePane.setContentType("text/html"); 114 scrollPane.setPreferredSize(new Dimension (700, 400)); 115 southPanel.add(southLabel, null); 116 getContentPane().add(mainPanel); 117 mainPanel.add(scrollPane, BorderLayout.CENTER); 118 scrollPane.getViewport().add(licensePane, null); 119 mainPanel.add(southPanel, BorderLayout.SOUTH); 120 southPanel.add(bReject, null); 121 southPanel.add(bAccept, null); 122 } 124 128 public final void actionPerformed(ActionEvent e) 129 { 130 if (e.getSource() == bAccept) 131 m_accept = true; 132 dispose(); 133 } 135 138 public final void dispose() 139 { 140 super.dispose(); 141 if (!m_accept) 142 cmd_reject(); 143 } 145 149 public final boolean isAccepted() 150 { 151 return m_accept; 152 } 154 157 public final void cmd_reject() 158 { 159 String info = "License rejected or expired"; 160 try 161 { 162 info = s_res.getString("License_rejected"); 163 } 164 catch (Exception e) 165 { 166 } 167 System.err.println(info); 168 System.exit(10); 169 } 171 175 public static final boolean accept() 176 { 177 IniDialog id = new IniDialog(); 178 if (id.isAccepted()) 179 return true; 180 System.exit(10); 181 return false; } 184 } | Popular Tags |