/* * Copyright 2010 Georgios Migdos <cyberpython@gmail.com>. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * under the License. */ /* * BMachAboutDialog.java * * Created on Nov 22, 2010, 9:48:30 PM */ package bmach.ui.gui; import java.net.URI; import java.net.URISyntaxException; import javax.swing.event.HyperlinkEvent; import javax.swing.event.HyperlinkListener; /** * * @author Georgios Migdos <cyberpython@gmail.com> */ public class BMachAboutDialog extends javax.swing.JDialog { /** Creates new form BMachAboutDialog */ public BMachAboutDialog(java.awt.Frame parent, boolean modal) { super(parent, modal); initComponents(); jEditorPane1.addHyperlinkListener(new HyperlinkListener() { public void hyperlinkUpdate(HyperlinkEvent e) { if(e.getEventType()==HyperlinkEvent.EventType.ACTIVATED){ try{ openUrlInBrowser(e.getURL().toURI()); }catch(URISyntaxException use){ use.printStackTrace(); } } } }); this.setLocationRelativeTo(parent); } private void openUrlInBrowser(URI uri) { try { java.awt.Desktop desktop = java.awt.Desktop.getDesktop(); desktop.browse(uri); } catch (UnsupportedOperationException uoe) { this.xdgOpenUrl(uri); } catch (Exception e) { } } private void xdgOpenUrl(URI uri) { String CROSS_DESKTOP_OPEN_FILE_COMMAND = "/usr/bin/xdg-open"; String osName = System.getProperty("os.name").toLowerCase(); if (osName.toLowerCase().contains("linux")) { try { String cmd = "/bin/sh " + CROSS_DESKTOP_OPEN_FILE_COMMAND + " "+uri.toString(); Runtime rt = Runtime.getRuntime(); Process p = rt.exec(cmd); p.waitFor(); } catch (Exception e) { } } } /** This method is called from within the constructor to * initialize the form. * WARNING: Do NOT modify this code. The content of this method is * always regenerated by the Form Editor. */ @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents private void initComponents() { jPanel1 = new javax.swing.JPanel(); jLabel1 = new javax.swing.JLabel(); jLabel2 = new javax.swing.JLabel(); jScrollPane1 = new javax.swing.JScrollPane(); jEditorPane1 = new javax.swing.JEditorPane(); jButton1 = new javax.swing.JButton(); setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); setTitle("BMach - About"); setResizable(false); jLabel1.setFont(jLabel1.getFont().deriveFont((jLabel1.getFont().getStyle() & ~java.awt.Font.ITALIC) | java.awt.Font.BOLD, 22)); jLabel1.setText("BMach"); jLabel2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/bmach/ui/gui/resources/icon-large.png"))); // NOI18N jEditorPane1.setBackground(new java.awt.Color(255, 255, 255)); jEditorPane1.setContentType("text/html"); jEditorPane1.setEditable(false); jEditorPane1.setText("<html>\n <head>\n <style>\n ul{list-style-type: square;}\n </style>\n </head>\n <body>\n <p style=\"margin-top: 0\">\n Copyright © 2010 Georgios Migdos <<a href=\"mailto:cyberpython@gmail.com?subject=BMach\">cyberpython@gmail.com</a>>\n </p>\n <p>\n A Brookshear machine implementation in Java\n </p>\n <ul>\n <li>Icons are from the <a href=\"http://www.famfamfam.com/lab/icons/silk/\">'Silk' iconset</a> by Mark James, under the <a href=\"http://creativecommons.org/licenses/by/3.0/\">Creative Commons Attribution 3.0 License</a>.</li>\n <li>Using <a href=\"http://code.google.com/p/jsyntaxpane/\">jSyntaxpane</a>, which is available under the <a href=\"http://www.apache.org/licenses/LICENSE-2.0\">Apache License v2.0</a>.</li>\n </ul>\n </body>\n</html>\n"); jScrollPane1.setViewportView(jEditorPane1); jButton1.setText("Close"); jButton1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton1ActionPerformed(evt); } }); javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1); jPanel1.setLayout(jPanel1Layout); jPanel1Layout.setHorizontalGroup( jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createSequentialGroup() .addContainerGap() .addComponent(jLabel2) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabel1) .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 408, javax.swing.GroupLayout.PREFERRED_SIZE)) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup() .addContainerGap(423, Short.MAX_VALUE) .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 137, javax.swing.GroupLayout.PREFERRED_SIZE) .addContainerGap()) ); jPanel1Layout.setVerticalGroup( jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createSequentialGroup() .addContainerGap() .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false) .addComponent(jLabel2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup() .addComponent(jLabel1) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 212, javax.swing.GroupLayout.PREFERRED_SIZE))) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jButton1) .addContainerGap()) ); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) ); pack(); }// </editor-fold>//GEN-END:initComponents private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed this.setVisible(false); this.dispose(); }//GEN-LAST:event_jButton1ActionPerformed /** * @param args the command line arguments */ public static void main(String args[]) { java.awt.EventQueue.invokeLater(new Runnable() { public void run() { BMachAboutDialog dialog = new BMachAboutDialog(new javax.swing.JFrame(), true); dialog.addWindowListener(new java.awt.event.WindowAdapter() { public void windowClosing(java.awt.event.WindowEvent e) { System.exit(0); } }); dialog.setVisible(true); } }); } // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton jButton1; private javax.swing.JEditorPane jEditorPane1; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; private javax.swing.JPanel jPanel1; private javax.swing.JScrollPane jScrollPane1; // End of variables declaration//GEN-END:variables }