/* * Props.java * * Created on Jan 7, 2011, 10:13:43 AM * * @author pquiring */ public class Permissions extends javax.swing.JDialog { /** Creates new form Props */ public Permissions(java.awt.Frame parent, boolean modal, String fileName, int value) { super(parent, modal); initComponents(); file.setText(fileName); octal.setText(Integer.toString(value,8)); owner_read.setSelected((value & 0x100) != 0); owner_write.setSelected((value & 0x80) != 0); owner_exec.setSelected((value & 0x40) != 0); group_read.setSelected((value & 0x20) != 0); group_write.setSelected((value & 0x10) != 0); group_exec.setSelected((value & 0x08) != 0); public_read.setSelected((value & 0x04) != 0); public_write.setSelected((value & 0x02) != 0); public_exec.setSelected((value & 0x01) != 0); } /** 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(); owner_read = new javax.swing.JCheckBox(); owner_write = new javax.swing.JCheckBox(); owner_exec = new javax.swing.JCheckBox(); jPanel5 = new javax.swing.JPanel(); group_read = new javax.swing.JCheckBox(); group_write = new javax.swing.JCheckBox(); group_exec = new javax.swing.JCheckBox(); jPanel6 = new javax.swing.JPanel(); public_read = new javax.swing.JCheckBox(); public_write = new javax.swing.JCheckBox(); public_exec = new javax.swing.JCheckBox(); jLabel2 = new javax.swing.JLabel(); octal = new javax.swing.JTextField(); ok = new javax.swing.JButton(); cancel = new javax.swing.JButton(); file = new javax.swing.JTextField(); setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); setTitle("Permissions"); setResizable(false); jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Owner")); owner_read.setText("Read"); owner_read.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { owner_readActionPerformed(evt); } }); owner_write.setText("Write"); owner_write.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { owner_writeActionPerformed(evt); } }); owner_exec.setText("Execute"); owner_exec.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { owner_execActionPerformed(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(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(owner_read) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(owner_write) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(owner_exec)) ); jPanel1Layout.setVerticalGroup( jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createSequentialGroup() .addContainerGap() .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(owner_read) .addComponent(owner_exec) .addComponent(owner_write)) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) ); jPanel5.setBorder(javax.swing.BorderFactory.createTitledBorder("Group")); group_read.setText("Read"); group_read.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { group_readActionPerformed(evt); } }); group_write.setText("Write"); group_write.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { group_writeActionPerformed(evt); } }); group_exec.setText("Execute"); group_exec.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { group_execActionPerformed(evt); } }); javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5); jPanel5.setLayout(jPanel5Layout); jPanel5Layout.setHorizontalGroup( jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel5Layout.createSequentialGroup() .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(group_read) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(group_write) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(group_exec)) ); jPanel5Layout.setVerticalGroup( jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel5Layout.createSequentialGroup() .addContainerGap() .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(group_read, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(group_write) .addComponent(group_exec)) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) ); jPanel6.setBorder(javax.swing.BorderFactory.createTitledBorder("Public")); public_read.setText("Read"); public_read.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { public_readActionPerformed(evt); } }); public_write.setText("Write"); public_write.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { public_writeActionPerformed(evt); } }); public_exec.setText("Execute"); public_exec.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { public_execActionPerformed(evt); } }); javax.swing.GroupLayout jPanel6Layout = new javax.swing.GroupLayout(jPanel6); jPanel6.setLayout(jPanel6Layout); jPanel6Layout.setHorizontalGroup( jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel6Layout.createSequentialGroup() .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(public_read) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(public_write) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(public_exec)) ); jPanel6Layout.setVerticalGroup( jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel6Layout.createSequentialGroup() .addContainerGap() .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(public_read, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(public_write) .addComponent(public_exec)) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) ); jLabel2.setText("Octal:"); octal.setText("000"); octal.addKeyListener(new java.awt.event.KeyAdapter() { public void keyTyped(java.awt.event.KeyEvent evt) { octalKeyTyped(evt); } }); ok.setText("Ok"); ok.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { okActionPerformed(evt); } }); cancel.setText("Cancel"); cancel.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { cancelActionPerformed(evt); } }); file.setText("file"); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false) .addGroup(layout.createSequentialGroup() .addContainerGap() .addComponent(file)) .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup() .addContainerGap() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false) .addComponent(jPanel6, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jPanel5, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jPanel1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addGroup(layout.createSequentialGroup() .addComponent(jLabel2) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(octal, javax.swing.GroupLayout.PREFERRED_SIZE, 133, javax.swing.GroupLayout.PREFERRED_SIZE)))) .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup() .addGap(35, 35, 35) .addComponent(ok) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(cancel))) .addContainerGap()) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap() .addComponent(file, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jPanel6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel2) .addComponent(octal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(ok) .addComponent(cancel)) .addContainerGap()) ); pack(); }// </editor-fold>//GEN-END:initComponents private void okActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_okActionPerformed value = Integer.valueOf(octal.getText(), 8); dispose(); }//GEN-LAST:event_okActionPerformed private void cancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelActionPerformed value = -1; dispose(); }//GEN-LAST:event_cancelActionPerformed private void owner_readActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_owner_readActionPerformed updateOctal(); }//GEN-LAST:event_owner_readActionPerformed private void owner_writeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_owner_writeActionPerformed updateOctal(); }//GEN-LAST:event_owner_writeActionPerformed private void owner_execActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_owner_execActionPerformed updateOctal(); }//GEN-LAST:event_owner_execActionPerformed private void group_readActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_group_readActionPerformed updateOctal(); }//GEN-LAST:event_group_readActionPerformed private void group_writeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_group_writeActionPerformed updateOctal(); }//GEN-LAST:event_group_writeActionPerformed private void group_execActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_group_execActionPerformed updateOctal(); }//GEN-LAST:event_group_execActionPerformed private void public_readActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_public_readActionPerformed updateOctal(); }//GEN-LAST:event_public_readActionPerformed private void public_writeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_public_writeActionPerformed updateOctal(); }//GEN-LAST:event_public_writeActionPerformed private void public_execActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_public_execActionPerformed updateOctal(); }//GEN-LAST:event_public_execActionPerformed private void octalKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_octalKeyTyped // TODO : consume invalid keys }//GEN-LAST:event_octalKeyTyped // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton cancel; private javax.swing.JTextField file; private javax.swing.JCheckBox group_exec; private javax.swing.JCheckBox group_read; private javax.swing.JCheckBox group_write; private javax.swing.JLabel jLabel2; private javax.swing.JPanel jPanel1; private javax.swing.JPanel jPanel5; private javax.swing.JPanel jPanel6; private javax.swing.JTextField octal; private javax.swing.JButton ok; private javax.swing.JCheckBox owner_exec; private javax.swing.JCheckBox owner_read; private javax.swing.JCheckBox owner_write; private javax.swing.JCheckBox public_exec; private javax.swing.JCheckBox public_read; private javax.swing.JCheckBox public_write; // End of variables declaration//GEN-END:variables public int value; //return value private void updateOctal() { int newValue = 0; if (owner_read.isSelected()) newValue += 0x100; if (owner_write.isSelected()) newValue += 0x80; if (owner_exec.isSelected()) newValue += 0x40; if (group_read.isSelected()) newValue += 0x20; if (group_write.isSelected()) newValue += 0x10; if (group_exec.isSelected()) newValue += 0x08; if (public_read.isSelected()) newValue += 0x04; if (public_write.isSelected()) newValue += 0x02; if (public_exec.isSelected()) newValue += 0x01; octal.setText(Integer.toString(newValue,8)); } }