1 50 package com.lowagie.tools.arguments; 51 52 import java.awt.event.ActionEvent; 53 54 import javax.swing.JCheckBox; 55 import javax.swing.JOptionPane; 56 57 import com.lowagie.tools.plugins.AbstractTool; 58 59 62 public class BitsetArgument extends ToolArgument { 63 64 private JCheckBox[] options; 65 66 73 public BitsetArgument(AbstractTool tool, String name, String description, String[] options) { 74 super(tool, name, description, String.class.getName()); 75 this.options = new JCheckBox[options.length]; 76 for (int i = 0; i < options.length; i++) { 77 this.options[i] = new JCheckBox(options[i]); 78 } 79 } 80 81 86 public Object getArgument() throws InstantiationException { 87 return value; 88 } 89 90 93 public String getUsage() { 94 StringBuffer buf = new StringBuffer(super.getUsage()); 95 buf.append(" possible options:\n"); 96 for (int i = 0; i < options.length; i++) { 97 buf.append(" - "); 98 buf.append(options[i].getText()); 99 buf.append("\n"); 100 } 101 return buf.toString(); 102 } 103 104 107 public void actionPerformed(ActionEvent evt) { 108 Object[] message = new Object[1 + options.length]; 109 message[0] = "Check the options you need:"; 110 for(int i = 0; i < options.length; i++ ) { 111 message[i+1] = options[i]; 112 } 113 int result = JOptionPane.showOptionDialog( 114 tool.getInternalFrame(), 115 message, 116 description, 117 JOptionPane.OK_CANCEL_OPTION, 118 JOptionPane.QUESTION_MESSAGE, 119 null, 120 null, 121 null 122 ); 123 if (result == 0) { 124 StringBuffer buf = new StringBuffer(); 125 for (int i = 0; i < options.length; i++) { 126 if (options[i].isSelected()) { 127 buf.append("1"); 128 } 129 else { 130 buf.append("0"); 131 } 132 } 133 setValue(buf.toString()); 134 } 135 } 136 } | Popular Tags |