1*cdf0e10cSrcweir import java.awt.*; 2*cdf0e10cSrcweir import java.awt.event.*; 3*cdf0e10cSrcweir import javax.swing.*; 4*cdf0e10cSrcweir import javax.swing.border.*; 5*cdf0e10cSrcweir import java.util.Vector; 6*cdf0e10cSrcweir import com.sun.star.script.framework.runtime.XScriptContext; 7*cdf0e10cSrcweir 8*cdf0e10cSrcweir 9*cdf0e10cSrcweir public class PostNewsgroup extends JFrame 10*cdf0e10cSrcweir { 11*cdf0e10cSrcweir 12*cdf0e10cSrcweir // Post to newsgroup objects 13*cdf0e10cSrcweir private NewsGroup[] subscribedNewsgroups = null; 14*cdf0e10cSrcweir private XScriptContext xscriptcontext = null; 15*cdf0e10cSrcweir 16*cdf0e10cSrcweir private final int FRAMEX = 300; 17*cdf0e10cSrcweir private final int FRAMEY = 300; 18*cdf0e10cSrcweir private final int TEXTBOXWIDTH = 300; 19*cdf0e10cSrcweir private final int TEXTBOXHEIGHT = 24; 20*cdf0e10cSrcweir private final int TEXTAREAHEIGHT = 70; 21*cdf0e10cSrcweir private final int BUTTONWIDTH = 80; 22*cdf0e10cSrcweir private final int BUTTONHEIGHT = 30; 23*cdf0e10cSrcweir 24*cdf0e10cSrcweir private PostNewsgroup window = null; 25*cdf0e10cSrcweir private JComboBox newsgroupComboBox = null; 26*cdf0e10cSrcweir private JTextField hostTextField = null; 27*cdf0e10cSrcweir private JTextField replyTextField = null; 28*cdf0e10cSrcweir private JTextField subjectTextField = null; 29*cdf0e10cSrcweir private JTextArea commentTextArea = null; 30*cdf0e10cSrcweir private JRadioButton officeHtmlButton = null; 31*cdf0e10cSrcweir private JRadioButton officeButton = null; 32*cdf0e10cSrcweir private JRadioButton htmlButton = null; 33*cdf0e10cSrcweir private JButton postButton = null; 34*cdf0e10cSrcweir private JButton cancelButton = null; 35*cdf0e10cSrcweir 36*cdf0e10cSrcweir // JFrame for launch progress dialog 37*cdf0e10cSrcweir private StatusWindow statusWindow = null; 38*cdf0e10cSrcweir private String statusLine = ""; 39*cdf0e10cSrcweir 40*cdf0e10cSrcweir // Tool tip text 41*cdf0e10cSrcweir private final String newsgroupText = "Newsgroup name"; 42*cdf0e10cSrcweir private final String hostText = "Newsgroup host/server name"; 43*cdf0e10cSrcweir private final String replyText = "Email address to reply to"; 44*cdf0e10cSrcweir private final String subjectText = "Subject title for the mail"; 45*cdf0e10cSrcweir private final String commentText = "Additional comment on mail"; 46*cdf0e10cSrcweir private final String officeHtmlText = "Post as both Office and HTML attachments"; 47*cdf0e10cSrcweir private final String officeText = "Post as Office attachment only"; 48*cdf0e10cSrcweir private final String htmlText = "Post as HTML attachment only"; 49*cdf0e10cSrcweir private final String postText = "Post to newsgroup"; 50*cdf0e10cSrcweir private final String cancelText = "Cancel post to newsgroup"; 51*cdf0e10cSrcweir 52*cdf0e10cSrcweir 53*cdf0e10cSrcweir public void post( XScriptContext xsc ) 54*cdf0e10cSrcweir { 55*cdf0e10cSrcweir xscriptcontext = xsc; 56*cdf0e10cSrcweir window = this; 57*cdf0e10cSrcweir 58*cdf0e10cSrcweir // create mailcap and mimetypes files (fix for classloader problem) 59*cdf0e10cSrcweir MimeConfiguration.createFiles( xscriptcontext ); 60*cdf0e10cSrcweir 61*cdf0e10cSrcweir this.setTitle( "Post Document To Newsgroup" ); 62*cdf0e10cSrcweir this.setLocation( FRAMEX, FRAMEY ); 63*cdf0e10cSrcweir 64*cdf0e10cSrcweir this.addFocusListener( new FocusAdapter() 65*cdf0e10cSrcweir { 66*cdf0e10cSrcweir public void focusGained( FocusEvent event ) 67*cdf0e10cSrcweir { 68*cdf0e10cSrcweir System.out.println( "Focus gained" ); 69*cdf0e10cSrcweir window.update( window.getGraphics() ); 70*cdf0e10cSrcweir } 71*cdf0e10cSrcweir 72*cdf0e10cSrcweir public void focusLost( FocusEvent event ) 73*cdf0e10cSrcweir { 74*cdf0e10cSrcweir System.out.println( "Focus lost" ); 75*cdf0e10cSrcweir } 76*cdf0e10cSrcweir }); 77*cdf0e10cSrcweir 78*cdf0e10cSrcweir Container container = getContentPane(); 79*cdf0e10cSrcweir container.setLayout( new GridBagLayout() );; 80*cdf0e10cSrcweir GridBagConstraints constraints = new GridBagConstraints(); 81*cdf0e10cSrcweir constraints.fill = GridBagConstraints.BOTH; 82*cdf0e10cSrcweir 83*cdf0e10cSrcweir JPanel labelPanel = constructLabelPanel(); 84*cdf0e10cSrcweir JPanel textPanel = constructTextPanel(); 85*cdf0e10cSrcweir JPanel optionPanel = constructOptionPanel(); 86*cdf0e10cSrcweir JPanel buttonPanel = constructButtonPanel(); 87*cdf0e10cSrcweir 88*cdf0e10cSrcweir constraints.gridx = 0; 89*cdf0e10cSrcweir constraints.gridy = 0; 90*cdf0e10cSrcweir constraints.gridwidth = 1; 91*cdf0e10cSrcweir constraints.gridheight = 3; 92*cdf0e10cSrcweir constraints.insets = new Insets( 15, 15, 5, 5 ); 93*cdf0e10cSrcweir container.add( labelPanel, constraints ); 94*cdf0e10cSrcweir 95*cdf0e10cSrcweir constraints.gridx = 1; 96*cdf0e10cSrcweir constraints.gridy = 0; 97*cdf0e10cSrcweir constraints.gridwidth = 4; 98*cdf0e10cSrcweir constraints.gridheight = 3; 99*cdf0e10cSrcweir constraints.insets = new Insets( 15, 5, 5, 15 ); 100*cdf0e10cSrcweir container.add( textPanel, constraints ); 101*cdf0e10cSrcweir 102*cdf0e10cSrcweir constraints.gridx = 0; 103*cdf0e10cSrcweir constraints.gridy = 3; 104*cdf0e10cSrcweir constraints.gridwidth = 5; 105*cdf0e10cSrcweir constraints.gridheight = 1; 106*cdf0e10cSrcweir constraints.insets = new Insets( 5, 15, 5, 15 ); 107*cdf0e10cSrcweir container.add( optionPanel, constraints ); 108*cdf0e10cSrcweir 109*cdf0e10cSrcweir constraints.gridx = 0; 110*cdf0e10cSrcweir constraints.gridy = 4; 111*cdf0e10cSrcweir constraints.gridwidth = 5; 112*cdf0e10cSrcweir constraints.gridheight = 1; 113*cdf0e10cSrcweir constraints.insets = new Insets( 5, 5, 5, 5 ); 114*cdf0e10cSrcweir container.add( buttonPanel, constraints ); 115*cdf0e10cSrcweir 116*cdf0e10cSrcweir this.pack(); 117*cdf0e10cSrcweir this.setResizable( false ); 118*cdf0e10cSrcweir this.setVisible( true ); 119*cdf0e10cSrcweir } 120*cdf0e10cSrcweir 121*cdf0e10cSrcweir 122*cdf0e10cSrcweir private JPanel constructLabelPanel() 123*cdf0e10cSrcweir { 124*cdf0e10cSrcweir JLabel newsgroupLabel = new JLabel( "Newsgroup:" ); 125*cdf0e10cSrcweir JLabel hostLabel = new JLabel( "Host:" ); 126*cdf0e10cSrcweir JLabel replyLabel = new JLabel( "Reply:" ); 127*cdf0e10cSrcweir JLabel subjectLabel = new JLabel( "Subject:" ); 128*cdf0e10cSrcweir JLabel commentLabel = new JLabel( "Comment:" ); 129*cdf0e10cSrcweir 130*cdf0e10cSrcweir newsgroupLabel.setToolTipText( newsgroupText ); 131*cdf0e10cSrcweir hostLabel.setToolTipText( hostText ); 132*cdf0e10cSrcweir replyLabel.setToolTipText( replyText ); 133*cdf0e10cSrcweir subjectLabel.setToolTipText( subjectText ); 134*cdf0e10cSrcweir commentLabel.setToolTipText( commentText ); 135*cdf0e10cSrcweir 136*cdf0e10cSrcweir JPanel newsgroupPanel = new JPanel(); 137*cdf0e10cSrcweir newsgroupPanel.setLayout( new BorderLayout() ); 138*cdf0e10cSrcweir newsgroupPanel.add( newsgroupLabel, "West" ); 139*cdf0e10cSrcweir JPanel hostPanel = new JPanel(); 140*cdf0e10cSrcweir hostPanel.setLayout( new BorderLayout() ); 141*cdf0e10cSrcweir hostPanel.add( hostLabel, "West" ); 142*cdf0e10cSrcweir JPanel replyPanel = new JPanel(); 143*cdf0e10cSrcweir replyPanel.setLayout( new BorderLayout() ); 144*cdf0e10cSrcweir replyPanel.add( replyLabel, "West" ); 145*cdf0e10cSrcweir JPanel subjectPanel = new JPanel(); 146*cdf0e10cSrcweir subjectPanel.setLayout( new BorderLayout() ); 147*cdf0e10cSrcweir subjectPanel.add( subjectLabel, "West" ); 148*cdf0e10cSrcweir JPanel commentPanel = new JPanel(); 149*cdf0e10cSrcweir commentPanel.setLayout( new BorderLayout() ); 150*cdf0e10cSrcweir commentPanel.add( commentLabel, "West" ); 151*cdf0e10cSrcweir JPanel emptyPanel = new JPanel(); 152*cdf0e10cSrcweir 153*cdf0e10cSrcweir final int labelWidth = 80; 154*cdf0e10cSrcweir newsgroupPanel.setPreferredSize( new Dimension( labelWidth, TEXTBOXHEIGHT ) ); 155*cdf0e10cSrcweir hostPanel.setPreferredSize( new Dimension( labelWidth, TEXTBOXHEIGHT ) ); 156*cdf0e10cSrcweir replyPanel.setPreferredSize( new Dimension( labelWidth, TEXTBOXHEIGHT ) ); 157*cdf0e10cSrcweir subjectPanel.setPreferredSize( new Dimension( labelWidth, TEXTBOXHEIGHT ) ); 158*cdf0e10cSrcweir commentPanel.setPreferredSize( new Dimension( labelWidth, TEXTBOXHEIGHT ) ); 159*cdf0e10cSrcweir 160*cdf0e10cSrcweir JPanel panel = new JPanel(); 161*cdf0e10cSrcweir panel.setLayout( new GridBagLayout() ); 162*cdf0e10cSrcweir GridBagConstraints constraints = new GridBagConstraints(); 163*cdf0e10cSrcweir constraints.fill = GridBagConstraints.BOTH; 164*cdf0e10cSrcweir constraints.insets = new Insets( 5, 5, 5, 5 ); 165*cdf0e10cSrcweir 166*cdf0e10cSrcweir constraints.gridx = 0; 167*cdf0e10cSrcweir constraints.gridy = 0; 168*cdf0e10cSrcweir constraints.gridwidth = 1; 169*cdf0e10cSrcweir constraints.gridheight = 1; 170*cdf0e10cSrcweir constraints.weightx = constraints.weighty = 0.0; 171*cdf0e10cSrcweir panel.add( newsgroupPanel, constraints ); 172*cdf0e10cSrcweir 173*cdf0e10cSrcweir constraints.gridx = 0; 174*cdf0e10cSrcweir constraints.gridy = 1; 175*cdf0e10cSrcweir constraints.gridwidth = 1; 176*cdf0e10cSrcweir constraints.gridheight = 1; 177*cdf0e10cSrcweir panel.add( hostPanel, constraints ); 178*cdf0e10cSrcweir 179*cdf0e10cSrcweir constraints.gridx = 0; 180*cdf0e10cSrcweir constraints.gridy = 2; 181*cdf0e10cSrcweir constraints.gridwidth = 1; 182*cdf0e10cSrcweir constraints.gridheight = 1; 183*cdf0e10cSrcweir panel.add( replyPanel, constraints ); 184*cdf0e10cSrcweir 185*cdf0e10cSrcweir constraints.gridx = 0; 186*cdf0e10cSrcweir constraints.gridy = 3; 187*cdf0e10cSrcweir constraints.gridwidth = 1; 188*cdf0e10cSrcweir constraints.gridheight = 1; 189*cdf0e10cSrcweir panel.add( subjectPanel, constraints ); 190*cdf0e10cSrcweir 191*cdf0e10cSrcweir constraints.gridx = 0; 192*cdf0e10cSrcweir constraints.gridy = 4; 193*cdf0e10cSrcweir constraints.gridwidth = 1; 194*cdf0e10cSrcweir constraints.gridheight = 1; 195*cdf0e10cSrcweir panel.add( commentPanel, constraints ); 196*cdf0e10cSrcweir 197*cdf0e10cSrcweir constraints.gridx = 0; 198*cdf0e10cSrcweir constraints.gridy = 5; 199*cdf0e10cSrcweir constraints.gridwidth = 1; 200*cdf0e10cSrcweir constraints.gridheight = 1; 201*cdf0e10cSrcweir constraints.weightx = constraints.weighty = 1.0; 202*cdf0e10cSrcweir panel.add( emptyPanel, constraints ); 203*cdf0e10cSrcweir 204*cdf0e10cSrcweir return panel; 205*cdf0e10cSrcweir } 206*cdf0e10cSrcweir 207*cdf0e10cSrcweir 208*cdf0e10cSrcweir private JPanel constructTextPanel() 209*cdf0e10cSrcweir { 210*cdf0e10cSrcweir hostTextField = new JTextField(); 211*cdf0e10cSrcweir hostTextField.setPreferredSize( new Dimension( TEXTBOXWIDTH, TEXTBOXHEIGHT ) ); 212*cdf0e10cSrcweir hostTextField.setToolTipText( hostText ); 213*cdf0e10cSrcweir hostTextField.setBorder( new EtchedBorder() ); 214*cdf0e10cSrcweir 215*cdf0e10cSrcweir //optionPanel.setBorder( new TitledBorder( new EtchedBorder(), "Document Format" ) ); 216*cdf0e10cSrcweir newsgroupComboBox = getNewsgroupCombo(); 217*cdf0e10cSrcweir 218*cdf0e10cSrcweir replyTextField = new JTextField(); 219*cdf0e10cSrcweir replyTextField.setPreferredSize( new Dimension( TEXTBOXWIDTH, TEXTBOXHEIGHT ) ); 220*cdf0e10cSrcweir replyTextField.setToolTipText( replyText ); 221*cdf0e10cSrcweir replyTextField.setBorder( new EtchedBorder() ); 222*cdf0e10cSrcweir 223*cdf0e10cSrcweir subjectTextField = new JTextField(); 224*cdf0e10cSrcweir subjectTextField.setPreferredSize( new Dimension( TEXTBOXWIDTH, TEXTBOXHEIGHT ) ); 225*cdf0e10cSrcweir subjectTextField.setToolTipText( subjectText ); 226*cdf0e10cSrcweir subjectTextField.setBorder( new EtchedBorder() ); 227*cdf0e10cSrcweir 228*cdf0e10cSrcweir commentTextArea = new JTextArea(); 229*cdf0e10cSrcweir commentTextArea.setPreferredSize( new Dimension( TEXTBOXWIDTH, TEXTAREAHEIGHT ) ); 230*cdf0e10cSrcweir commentTextArea.setToolTipText( commentText ); 231*cdf0e10cSrcweir commentTextArea.setBorder( new EtchedBorder() ); 232*cdf0e10cSrcweir 233*cdf0e10cSrcweir JPanel panel = new JPanel(); 234*cdf0e10cSrcweir panel.setLayout( new GridBagLayout() ); 235*cdf0e10cSrcweir GridBagConstraints constraints = new GridBagConstraints(); 236*cdf0e10cSrcweir constraints.fill = GridBagConstraints.BOTH; 237*cdf0e10cSrcweir constraints.insets = new Insets( 5, 5, 5, 5 ); 238*cdf0e10cSrcweir 239*cdf0e10cSrcweir constraints.gridx = 0; 240*cdf0e10cSrcweir constraints.gridy = 0; 241*cdf0e10cSrcweir constraints.gridwidth = 1; 242*cdf0e10cSrcweir constraints.gridheight = 1; 243*cdf0e10cSrcweir panel.add( newsgroupComboBox, constraints ); 244*cdf0e10cSrcweir 245*cdf0e10cSrcweir constraints.gridx = 0; 246*cdf0e10cSrcweir constraints.gridy = 1; 247*cdf0e10cSrcweir constraints.gridwidth = 1; 248*cdf0e10cSrcweir constraints.gridheight = 1; 249*cdf0e10cSrcweir panel.add( hostTextField, constraints ); 250*cdf0e10cSrcweir 251*cdf0e10cSrcweir constraints.gridx = 0; 252*cdf0e10cSrcweir constraints.gridy = 2; 253*cdf0e10cSrcweir constraints.gridwidth = 1; 254*cdf0e10cSrcweir constraints.gridheight = 1; 255*cdf0e10cSrcweir panel.add( replyTextField, constraints ); 256*cdf0e10cSrcweir 257*cdf0e10cSrcweir constraints.gridx = 0; 258*cdf0e10cSrcweir constraints.gridy = 3; 259*cdf0e10cSrcweir constraints.gridwidth = 1; 260*cdf0e10cSrcweir constraints.gridheight = 1; 261*cdf0e10cSrcweir panel.add( subjectTextField, constraints ); 262*cdf0e10cSrcweir 263*cdf0e10cSrcweir constraints.gridx = 0; 264*cdf0e10cSrcweir constraints.gridy = 4; 265*cdf0e10cSrcweir constraints.gridwidth = 1; 266*cdf0e10cSrcweir constraints.gridheight = 2; 267*cdf0e10cSrcweir panel.add( commentTextArea, constraints ); 268*cdf0e10cSrcweir 269*cdf0e10cSrcweir return panel; 270*cdf0e10cSrcweir } 271*cdf0e10cSrcweir 272*cdf0e10cSrcweir 273*cdf0e10cSrcweir private JComboBox getNewsgroupCombo() 274*cdf0e10cSrcweir { 275*cdf0e10cSrcweir newsgroupComboBox = new JComboBox(); 276*cdf0e10cSrcweir //newsgroupComboBox.setBorder( new EtchedBorder() ); 277*cdf0e10cSrcweir 278*cdf0e10cSrcweir newsgroupComboBox.addActionListener(new ActionListener() 279*cdf0e10cSrcweir { 280*cdf0e10cSrcweir public void actionPerformed(ActionEvent e) 281*cdf0e10cSrcweir { 282*cdf0e10cSrcweir // when newsgroup is selected 283*cdf0e10cSrcweir if( subscribedNewsgroups != null ) 284*cdf0e10cSrcweir { 285*cdf0e10cSrcweir int position = newsgroupComboBox.getSelectedIndex(); 286*cdf0e10cSrcweir if( position != -1 ) 287*cdf0e10cSrcweir { 288*cdf0e10cSrcweir hostTextField.setText( subscribedNewsgroups[ position ].getHostName() ); 289*cdf0e10cSrcweir newsgroupComboBox.setToolTipText( "Newsgroup name: " + subscribedNewsgroups[ position ].getNewsgroupName() + " (Host name: " + subscribedNewsgroups[ position ].getHostName() + ")" ); 290*cdf0e10cSrcweir } 291*cdf0e10cSrcweir } 292*cdf0e10cSrcweir } 293*cdf0e10cSrcweir }); 294*cdf0e10cSrcweir 295*cdf0e10cSrcweir NewsGroup groupToSend = null; 296*cdf0e10cSrcweir SubscribedNewsgroups newsgroups = new SubscribedNewsgroups(); 297*cdf0e10cSrcweir subscribedNewsgroups = newsgroups.getNewsGroups(); 298*cdf0e10cSrcweir 299*cdf0e10cSrcweir // Test for no .mozilla or no subscribed newsgroups 300*cdf0e10cSrcweir // subscribedNewsgroups = null; 301*cdf0e10cSrcweir 302*cdf0e10cSrcweir if( subscribedNewsgroups == null ) 303*cdf0e10cSrcweir { 304*cdf0e10cSrcweir //System.out.println( "Couldn't find any subscibed newsgroups in .mozilla" ); 305*cdf0e10cSrcweir JOptionPane.showMessageDialog( window, "No subscribed newsgroups found in mozilla/netscape profile \nPlease enter newsgroup and host name", 306*cdf0e10cSrcweir "Newsgroups Information", JOptionPane.INFORMATION_MESSAGE ); 307*cdf0e10cSrcweir } 308*cdf0e10cSrcweir else 309*cdf0e10cSrcweir { 310*cdf0e10cSrcweir // Copy all newsgroups into a vector for comparison 311*cdf0e10cSrcweir // Alter entries (to include host name) if duplication is found 312*cdf0e10cSrcweir Vector vector = new Vector( subscribedNewsgroups.length ); 313*cdf0e10cSrcweir for(int i=0; i < subscribedNewsgroups.length; i++ ) 314*cdf0e10cSrcweir { 315*cdf0e10cSrcweir vector.add( subscribedNewsgroups[i].getNewsgroupName() ); 316*cdf0e10cSrcweir } 317*cdf0e10cSrcweir // Compare and alter 318*cdf0e10cSrcweir for(int i=0; i < subscribedNewsgroups.length; i++ ) 319*cdf0e10cSrcweir { 320*cdf0e10cSrcweir // check if combo box already has a newsgroup with same name 321*cdf0e10cSrcweir // then add host name to differentiate 322*cdf0e10cSrcweir for(int j=0; j < subscribedNewsgroups.length; j++ ) 323*cdf0e10cSrcweir { 324*cdf0e10cSrcweir if( j != i && subscribedNewsgroups[j].getNewsgroupName().equalsIgnoreCase( subscribedNewsgroups[i].getNewsgroupName() ) ) 325*cdf0e10cSrcweir { 326*cdf0e10cSrcweir vector.set( j, subscribedNewsgroups[j].getNewsgroupName() + " (" + subscribedNewsgroups[j].getHostName() + ")" ); 327*cdf0e10cSrcweir vector.set( i, subscribedNewsgroups[i].getNewsgroupName() + " (" + subscribedNewsgroups[i].getHostName() + ")" ); 328*cdf0e10cSrcweir } 329*cdf0e10cSrcweir } 330*cdf0e10cSrcweir } 331*cdf0e10cSrcweir // Copy converted newsgroups from vector to combo box 332*cdf0e10cSrcweir for(int i=0; i < subscribedNewsgroups.length; i++ ) 333*cdf0e10cSrcweir { 334*cdf0e10cSrcweir newsgroupComboBox.addItem( vector.elementAt(i) ); 335*cdf0e10cSrcweir } 336*cdf0e10cSrcweir }// else 337*cdf0e10cSrcweir 338*cdf0e10cSrcweir newsgroupComboBox.setPreferredSize( new Dimension( TEXTBOXWIDTH, TEXTBOXHEIGHT ) ); 339*cdf0e10cSrcweir newsgroupComboBox.setEditable( true ); 340*cdf0e10cSrcweir 341*cdf0e10cSrcweir return newsgroupComboBox; 342*cdf0e10cSrcweir } 343*cdf0e10cSrcweir 344*cdf0e10cSrcweir 345*cdf0e10cSrcweir 346*cdf0e10cSrcweir private JPanel constructOptionPanel() 347*cdf0e10cSrcweir { 348*cdf0e10cSrcweir officeHtmlButton = new JRadioButton( "Office and HTML", true ); 349*cdf0e10cSrcweir officeHtmlButton.setToolTipText( officeHtmlText ); 350*cdf0e10cSrcweir 351*cdf0e10cSrcweir officeButton = new JRadioButton( "Office" ); 352*cdf0e10cSrcweir officeButton.setToolTipText( officeText ); 353*cdf0e10cSrcweir 354*cdf0e10cSrcweir htmlButton = new JRadioButton( "HTML" ); 355*cdf0e10cSrcweir htmlButton.setToolTipText( htmlText ); 356*cdf0e10cSrcweir 357*cdf0e10cSrcweir JRadioButton[] rbuttons = { officeHtmlButton, officeButton, htmlButton }; 358*cdf0e10cSrcweir ButtonGroup radioButtonGroup = new ButtonGroup(); 359*cdf0e10cSrcweir for( int i=0; i < rbuttons.length; i++ ) 360*cdf0e10cSrcweir { 361*cdf0e10cSrcweir radioButtonGroup.add( rbuttons[i] ); 362*cdf0e10cSrcweir } 363*cdf0e10cSrcweir 364*cdf0e10cSrcweir JPanel optionPanel = new JPanel(); 365*cdf0e10cSrcweir //optionPanel.setLayout( new GridLayout( 1, 3, 20, 0 ) ); 366*cdf0e10cSrcweir optionPanel.setBorder( new TitledBorder( new EtchedBorder(), "Document Format" ) ); 367*cdf0e10cSrcweir optionPanel.setLayout( new GridBagLayout() ); 368*cdf0e10cSrcweir GridBagConstraints constraints = new GridBagConstraints(); 369*cdf0e10cSrcweir constraints.fill = GridBagConstraints.BOTH; 370*cdf0e10cSrcweir 371*cdf0e10cSrcweir constraints.gridx = 0; 372*cdf0e10cSrcweir constraints.gridy = 0; 373*cdf0e10cSrcweir constraints.gridwidth = 1; 374*cdf0e10cSrcweir constraints.gridheight = 1; 375*cdf0e10cSrcweir constraints.insets = new Insets( 5, 5, 5, 30 ); 376*cdf0e10cSrcweir optionPanel.add( officeHtmlButton, constraints ); 377*cdf0e10cSrcweir 378*cdf0e10cSrcweir constraints.gridx = 1; 379*cdf0e10cSrcweir constraints.gridy = 0; 380*cdf0e10cSrcweir constraints.gridwidth = 1; 381*cdf0e10cSrcweir constraints.gridheight = 1; 382*cdf0e10cSrcweir constraints.insets = new Insets( 5, 20, 5, 30 ); 383*cdf0e10cSrcweir optionPanel.add( officeButton, constraints ); 384*cdf0e10cSrcweir 385*cdf0e10cSrcweir constraints.gridx = 2; 386*cdf0e10cSrcweir constraints.gridy = 0; 387*cdf0e10cSrcweir constraints.gridwidth = 1; 388*cdf0e10cSrcweir constraints.gridheight = 1; 389*cdf0e10cSrcweir constraints.insets = new Insets( 5, 20, 5, 5 ); 390*cdf0e10cSrcweir optionPanel.add( htmlButton, constraints ); 391*cdf0e10cSrcweir 392*cdf0e10cSrcweir return optionPanel; 393*cdf0e10cSrcweir } 394*cdf0e10cSrcweir 395*cdf0e10cSrcweir 396*cdf0e10cSrcweir 397*cdf0e10cSrcweir public boolean sendingActions() 398*cdf0e10cSrcweir { 399*cdf0e10cSrcweir // posting actions 400*cdf0e10cSrcweir // Validate the data 401*cdf0e10cSrcweir if( isValidData() ) 402*cdf0e10cSrcweir { 403*cdf0e10cSrcweir // Create status window 404*cdf0e10cSrcweir StatusWindow statusWindow = new StatusWindow( window, "Posting to Newsgroup", FRAMEX, FRAMEY ); 405*cdf0e10cSrcweir 406*cdf0e10cSrcweir statusWindow.setVisible( true ); 407*cdf0e10cSrcweir //statusWindow.requestFocusInWindow(); 408*cdf0e10cSrcweir statusLine = "Ready to send..."; 409*cdf0e10cSrcweir statusWindow.setStatus( 0, statusLine ); 410*cdf0e10cSrcweir 411*cdf0e10cSrcweir // Get the boolean values for HTML/Office document 412*cdf0e10cSrcweir // params: ( XScriptContext, StatusWindow, html document, office document ) 413*cdf0e10cSrcweir 414*cdf0e10cSrcweir boolean html = false; 415*cdf0e10cSrcweir boolean office = false; 416*cdf0e10cSrcweir if( officeHtmlButton.isSelected() ) { html = true; office = true; } 417*cdf0e10cSrcweir if( officeButton.isSelected() ) { office = true; html = false; } 418*cdf0e10cSrcweir if( htmlButton.isSelected() ) { html = true; office = false; } 419*cdf0e10cSrcweir 420*cdf0e10cSrcweir OfficeAttachment officeAttach = new OfficeAttachment( xscriptcontext, statusWindow, html, office ); 421*cdf0e10cSrcweir 422*cdf0e10cSrcweir statusLine = "Getting user input"; 423*cdf0e10cSrcweir statusWindow.setStatus( 2, statusLine ); 424*cdf0e10cSrcweir // Get replyto, subject, comment from textboxes 425*cdf0e10cSrcweir String replyto = replyTextField.getText(); 426*cdf0e10cSrcweir String subject = subjectTextField.getText(); 427*cdf0e10cSrcweir String comment = commentTextArea.getText(); 428*cdf0e10cSrcweir 429*cdf0e10cSrcweir // Get newsgroup from combo box (corresponding position) 430*cdf0e10cSrcweir String host = ""; 431*cdf0e10cSrcweir String group = ""; 432*cdf0e10cSrcweir int position = newsgroupComboBox.getSelectedIndex(); 433*cdf0e10cSrcweir if( subscribedNewsgroups == null || position == -1 ) 434*cdf0e10cSrcweir { 435*cdf0e10cSrcweir host = hostTextField.getText(); 436*cdf0e10cSrcweir group = newsgroupComboBox.getSelectedItem().toString(); 437*cdf0e10cSrcweir } 438*cdf0e10cSrcweir else 439*cdf0e10cSrcweir { 440*cdf0e10cSrcweir //int position = newsgroupComboBox.getSelectedIndex(); 441*cdf0e10cSrcweir host = subscribedNewsgroups[ position ].getHostName(); 442*cdf0e10cSrcweir group = subscribedNewsgroups[ position ].getNewsgroupName(); 443*cdf0e10cSrcweir } 444*cdf0e10cSrcweir 445*cdf0e10cSrcweir statusLine = "Creating sender object"; 446*cdf0e10cSrcweir statusWindow.setStatus( 3, statusLine ); 447*cdf0e10cSrcweir Sender sender = new Sender( statusWindow, officeAttach, replyto, subject, comment, host, group ); 448*cdf0e10cSrcweir if( !sender.sendMail() ) 449*cdf0e10cSrcweir { 450*cdf0e10cSrcweir //System.out.println( "Should end here (?)" ); 451*cdf0e10cSrcweir statusWindow.enableCancelButton( true ); 452*cdf0e10cSrcweir officeAttach.cleanUpOnError(); 453*cdf0e10cSrcweir return false; 454*cdf0e10cSrcweir } 455*cdf0e10cSrcweir 456*cdf0e10cSrcweir statusLine = "Send is complete"; 457*cdf0e10cSrcweir statusWindow.setStatus( 14, statusLine ); 458*cdf0e10cSrcweir } 459*cdf0e10cSrcweir else 460*cdf0e10cSrcweir { 461*cdf0e10cSrcweir //System.out.println( "Non valid data" ); 462*cdf0e10cSrcweir return false; 463*cdf0e10cSrcweir } 464*cdf0e10cSrcweir return true; 465*cdf0e10cSrcweir } 466*cdf0e10cSrcweir 467*cdf0e10cSrcweir 468*cdf0e10cSrcweir private JPanel constructButtonPanel() 469*cdf0e10cSrcweir { 470*cdf0e10cSrcweir Action postAction = new AbstractAction() { 471*cdf0e10cSrcweir public void actionPerformed( ActionEvent event ) { 472*cdf0e10cSrcweir // posting actions 473*cdf0e10cSrcweir sendingActions(); 474*cdf0e10cSrcweir }// actionPerformed 475*cdf0e10cSrcweir }; 476*cdf0e10cSrcweir 477*cdf0e10cSrcweir Action cancelAction = new AbstractAction() { 478*cdf0e10cSrcweir public void actionPerformed( ActionEvent event ) { 479*cdf0e10cSrcweir // cancelling actions 480*cdf0e10cSrcweir window.dispose(); 481*cdf0e10cSrcweir } 482*cdf0e10cSrcweir }; 483*cdf0e10cSrcweir 484*cdf0e10cSrcweir postButton = new JButton(); 485*cdf0e10cSrcweir postButton.setAction( postAction ); 486*cdf0e10cSrcweir postButton.setToolTipText( postText ); 487*cdf0e10cSrcweir postButton.setText( "Post" ); 488*cdf0e10cSrcweir postButton.setPreferredSize( new Dimension( BUTTONWIDTH + 20, BUTTONHEIGHT ) ); 489*cdf0e10cSrcweir 490*cdf0e10cSrcweir cancelButton = new JButton(); 491*cdf0e10cSrcweir cancelButton.setAction( cancelAction ); 492*cdf0e10cSrcweir cancelButton.setToolTipText( cancelText ); 493*cdf0e10cSrcweir cancelButton.setText( "Cancel" ); 494*cdf0e10cSrcweir cancelButton.setPreferredSize( new Dimension( BUTTONWIDTH + 20, BUTTONHEIGHT ) ); 495*cdf0e10cSrcweir 496*cdf0e10cSrcweir JSeparator sep = new JSeparator( SwingConstants.HORIZONTAL ); 497*cdf0e10cSrcweir 498*cdf0e10cSrcweir JPanel buttonPanel = new JPanel(); 499*cdf0e10cSrcweir buttonPanel.setLayout( new GridBagLayout() ); 500*cdf0e10cSrcweir GridBagConstraints constraints = new GridBagConstraints(); 501*cdf0e10cSrcweir constraints.fill = GridBagConstraints.BOTH; 502*cdf0e10cSrcweir constraints.insets = new Insets( 5, 5, 5, 5 ); 503*cdf0e10cSrcweir 504*cdf0e10cSrcweir JPanel emptyPanel1 = new JPanel(); 505*cdf0e10cSrcweir emptyPanel1.setPreferredSize( new Dimension( BUTTONWIDTH, BUTTONHEIGHT ) ); 506*cdf0e10cSrcweir 507*cdf0e10cSrcweir JPanel emptyPanel2 = new JPanel(); 508*cdf0e10cSrcweir emptyPanel2.setPreferredSize( new Dimension( BUTTONWIDTH, BUTTONHEIGHT ) ); 509*cdf0e10cSrcweir 510*cdf0e10cSrcweir constraints.gridx = 0; 511*cdf0e10cSrcweir constraints.gridy = 0; 512*cdf0e10cSrcweir constraints.gridwidth = 4; 513*cdf0e10cSrcweir constraints.gridheight = 1; 514*cdf0e10cSrcweir buttonPanel.add( sep, constraints ); 515*cdf0e10cSrcweir 516*cdf0e10cSrcweir constraints.gridx = 0; 517*cdf0e10cSrcweir constraints.gridy = 1; 518*cdf0e10cSrcweir constraints.gridwidth = 1; 519*cdf0e10cSrcweir constraints.gridheight = 1; 520*cdf0e10cSrcweir buttonPanel.add( emptyPanel1, constraints ); 521*cdf0e10cSrcweir 522*cdf0e10cSrcweir constraints.gridx = 1; 523*cdf0e10cSrcweir constraints.gridy = 1; 524*cdf0e10cSrcweir constraints.gridwidth = 1; 525*cdf0e10cSrcweir constraints.gridheight = 1; 526*cdf0e10cSrcweir buttonPanel.add( emptyPanel2, constraints ); 527*cdf0e10cSrcweir 528*cdf0e10cSrcweir constraints.gridx = 2; 529*cdf0e10cSrcweir constraints.gridy = 1; 530*cdf0e10cSrcweir constraints.gridwidth = 1; 531*cdf0e10cSrcweir constraints.gridheight = 1; 532*cdf0e10cSrcweir buttonPanel.add( postButton, constraints ); 533*cdf0e10cSrcweir 534*cdf0e10cSrcweir constraints.gridx = 3; 535*cdf0e10cSrcweir constraints.gridy = 1; 536*cdf0e10cSrcweir constraints.gridwidth = 1; 537*cdf0e10cSrcweir constraints.gridheight = 1; 538*cdf0e10cSrcweir constraints.insets = new Insets( 5, 5, 5, 0 ); 539*cdf0e10cSrcweir buttonPanel.add( cancelButton, constraints ); 540*cdf0e10cSrcweir 541*cdf0e10cSrcweir return buttonPanel; 542*cdf0e10cSrcweir } 543*cdf0e10cSrcweir 544*cdf0e10cSrcweir 545*cdf0e10cSrcweir public void enableButtons( boolean enable ) 546*cdf0e10cSrcweir { 547*cdf0e10cSrcweir if( enable ) 548*cdf0e10cSrcweir { 549*cdf0e10cSrcweir postButton.setEnabled( true ); 550*cdf0e10cSrcweir cancelButton.setEnabled( true ); 551*cdf0e10cSrcweir } 552*cdf0e10cSrcweir else 553*cdf0e10cSrcweir { 554*cdf0e10cSrcweir postButton.setEnabled( false ); 555*cdf0e10cSrcweir cancelButton.setEnabled( false ); 556*cdf0e10cSrcweir } 557*cdf0e10cSrcweir } 558*cdf0e10cSrcweir 559*cdf0e10cSrcweir 560*cdf0e10cSrcweir private boolean isValidData() 561*cdf0e10cSrcweir { 562*cdf0e10cSrcweir // newsgroupComboBox must not be blank (format? dots and whitespace) 563*cdf0e10cSrcweir String newsgroupString = ""; 564*cdf0e10cSrcweir int position = newsgroupComboBox.getSelectedIndex(); 565*cdf0e10cSrcweir if( subscribedNewsgroups == null || position == -1 ) 566*cdf0e10cSrcweir { 567*cdf0e10cSrcweir newsgroupString = newsgroupComboBox.getSelectedItem().toString(); 568*cdf0e10cSrcweir } 569*cdf0e10cSrcweir else 570*cdf0e10cSrcweir { 571*cdf0e10cSrcweir //int position = newsgroupComboBox.getSelectedIndex(); 572*cdf0e10cSrcweir newsgroupString = subscribedNewsgroups[ position ].getNewsgroupName(); 573*cdf0e10cSrcweir } 574*cdf0e10cSrcweir if( newsgroupString.length() == 0 ) 575*cdf0e10cSrcweir { 576*cdf0e10cSrcweir //System.out.println( "Please enter a newsgroup name" ); 577*cdf0e10cSrcweir newsgroupComboBox.requestFocus(); 578*cdf0e10cSrcweir JOptionPane.showMessageDialog( window, "Please enter a newsgroup name", "Input Error", JOptionPane.ERROR_MESSAGE ); 579*cdf0e10cSrcweir return false; 580*cdf0e10cSrcweir } 581*cdf0e10cSrcweir 582*cdf0e10cSrcweir 583*cdf0e10cSrcweir // hostTextField must not be blank (format?) 584*cdf0e10cSrcweir String hostString = hostTextField.getText(); 585*cdf0e10cSrcweir if( hostString.length() == 0 ) 586*cdf0e10cSrcweir { 587*cdf0e10cSrcweir //System.out.println( "Please enter a hostname" ); 588*cdf0e10cSrcweir hostTextField.requestFocus(); 589*cdf0e10cSrcweir JOptionPane.showMessageDialog( window, "Please enter a hostname", "Input Error", JOptionPane.ERROR_MESSAGE ); 590*cdf0e10cSrcweir return false; 591*cdf0e10cSrcweir } 592*cdf0e10cSrcweir 593*cdf0e10cSrcweir 594*cdf0e10cSrcweir // replyTextField must have <string>@<string>.<string> 595*cdf0e10cSrcweir // (string at least 2 chars long) 596*cdf0e10cSrcweir // consider <s>.<s>@<s>.<s>.<s> format? (array of dot positons?) 597*cdf0e10cSrcweir String replyString = replyTextField.getText(); 598*cdf0e10cSrcweir int atPos = replyString.indexOf( "@" ); 599*cdf0e10cSrcweir int dotPos = replyString.lastIndexOf( "." ); 600*cdf0e10cSrcweir int length = replyString.length(); 601*cdf0e10cSrcweir //System.out.println( "length: " + length + "\n atPos: " + atPos + "\n dotPos: " + dotPos ); 602*cdf0e10cSrcweir if( length == 0 || atPos == -1 || dotPos == -1 || atPos < 2 || dotPos < atPos || dotPos + 2 == length || atPos + 2 == dotPos || atPos != replyString.lastIndexOf( "@" ) || replyString.indexOf(" ") != -1 ) 603*cdf0e10cSrcweir { 604*cdf0e10cSrcweir //System.out.println( "Please enter a valid reply to email address" ); 605*cdf0e10cSrcweir replyTextField.requestFocus(); 606*cdf0e10cSrcweir JOptionPane.showMessageDialog( window, "Please enter a valid reply to email address", "Input Error", JOptionPane.ERROR_MESSAGE ); 607*cdf0e10cSrcweir return false; 608*cdf0e10cSrcweir } 609*cdf0e10cSrcweir 610*cdf0e10cSrcweir 611*cdf0e10cSrcweir // subjectTextField must not be blank? 612*cdf0e10cSrcweir String subjectString = subjectTextField.getText(); 613*cdf0e10cSrcweir if( subjectString.length() == 0 ) 614*cdf0e10cSrcweir { 615*cdf0e10cSrcweir //System.out.println( "Please enter subject title" ); 616*cdf0e10cSrcweir subjectTextField.requestFocus(); 617*cdf0e10cSrcweir JOptionPane.showMessageDialog( window, "Please enter subject title", "Input Error", JOptionPane.ERROR_MESSAGE ); 618*cdf0e10cSrcweir return false; 619*cdf0e10cSrcweir } 620*cdf0e10cSrcweir 621*cdf0e10cSrcweir // details are valid 622*cdf0e10cSrcweir return true; 623*cdf0e10cSrcweir } 624*cdf0e10cSrcweir 625*cdf0e10cSrcweir } 626