001package apps.startup; 002 003import java.awt.Component; 004import java.io.IOException; 005import javax.swing.JFileChooser; 006import org.slf4j.Logger; 007import org.slf4j.LoggerFactory; 008 009/** 010 * 011 * @author Randall Wood 012 */ 013public class ScriptButtonPanel extends javax.swing.JPanel { 014 015 private final Component parent; 016 private final JFileChooser chooser; 017 private final static Logger log = LoggerFactory.getLogger(ScriptButtonPanel.class); 018 019 /** 020 * Creates new form ScriptButtonPanel 021 * 022 * @param chooser {@link JFileChooser} to use for Browse action 023 * @param parent parent {@link Component} within which this is contained 024 */ 025 public ScriptButtonPanel(JFileChooser chooser, Component parent) { 026 initComponents(); 027 this.parent = parent; 028 this.chooser = chooser; 029 } 030 031 /** 032 * This method is called from within the constructor to initialize the form. 033 * WARNING: Do NOT modify this code. The content of this method is always 034 * regenerated by the Form Editor. 035 */ 036 // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents 037 private void initComponents() { 038 039 buttonName = new javax.swing.JTextField(); 040 nameLabel = new javax.swing.JLabel(); 041 scriptLabel = new javax.swing.JLabel(); 042 script = new javax.swing.JTextField(); 043 scriptButton = new javax.swing.JButton(); 044 045 java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle("apps/startup/Bundle"); // NOI18N 046 buttonName.setText(bundle.getString("ScriptButtonPanel.buttonName.text")); // NOI18N 047 048 nameLabel.setText(bundle.getString("ScriptButtonPanel.nameLabel.text")); // NOI18N 049 050 scriptLabel.setText(bundle.getString("ScriptButtonPanel.scriptLabel.text")); // NOI18N 051 052 script.setText(bundle.getString("ScriptButtonPanel.script.text")); // NOI18N 053 054 scriptButton.setText(bundle.getString("ScriptButtonPanel.scriptButton.text")); // NOI18N 055 scriptButton.addActionListener(new java.awt.event.ActionListener() { 056 @Override 057 public void actionPerformed(java.awt.event.ActionEvent evt) { 058 scriptButtonActionPerformed(evt); 059 } 060 }); 061 062 javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); 063 this.setLayout(layout); 064 layout.setHorizontalGroup( 065 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 066 .addGroup(layout.createSequentialGroup() 067 .addContainerGap() 068 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 069 .addComponent(nameLabel) 070 .addComponent(scriptLabel)) 071 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) 072 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 073 .addComponent(script, javax.swing.GroupLayout.DEFAULT_SIZE, 220, Short.MAX_VALUE) 074 .addComponent(buttonName)) 075 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) 076 .addComponent(scriptButton) 077 .addContainerGap()) 078 ); 079 layout.setVerticalGroup( 080 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 081 .addGroup(layout.createSequentialGroup() 082 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) 083 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) 084 .addComponent(buttonName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) 085 .addComponent(nameLabel)) 086 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) 087 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) 088 .addComponent(script, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) 089 .addComponent(scriptLabel) 090 .addComponent(scriptButton))) 091 ); 092 }// </editor-fold>//GEN-END:initComponents 093 094 private void scriptButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_scriptButtonActionPerformed 095 if (this.chooser.showOpenDialog(parent) == JFileChooser.APPROVE_OPTION) { 096 try { 097 this.script.setText(this.chooser.getSelectedFile().getCanonicalPath()); 098 } catch (IOException ex) { 099 log.error("File {} does not exist.", this.chooser.getSelectedFile()); 100 } 101 } 102 }//GEN-LAST:event_scriptButtonActionPerformed 103 104 105 // Variables declaration - do not modify//GEN-BEGIN:variables 106 private javax.swing.JTextField buttonName; 107 private javax.swing.JLabel nameLabel; 108 private javax.swing.JTextField script; 109 private javax.swing.JButton scriptButton; 110 private javax.swing.JLabel scriptLabel; 111 // End of variables declaration//GEN-END:variables 112 113 /** 114 * @return the name 115 */ 116 protected String getButtonName() { 117 return buttonName.getText(); 118 } 119 120 /** 121 * @param name the name to set 122 */ 123 protected void setButtonName(String name) { 124 this.buttonName.setText(name); 125 } 126 127 /** 128 * @return the script 129 */ 130 protected String getScript() { 131 return script.getText(); 132 } 133 134 /** 135 * @param script the script to set 136 */ 137 protected void setScript(String script) { 138 this.script.setText(script); 139 } 140}