1 19 package org.lucane.applications.sendfile; 20 21 import java.awt.BorderLayout ; 22 import java.awt.Dimension ; 23 import java.awt.GridLayout ; 24 import java.awt.event.ActionEvent ; 25 import java.awt.event.ActionListener ; 26 27 import javax.swing.*; 28 29 import org.lucane.client.Client; 30 import org.lucane.client.widgets.HTMLEditor; 31 import org.lucane.client.widgets.ManagedWindow; 32 33 public class SendFileDialog extends ManagedWindow 34 implements ActionListener 35 { 36 private SendFile plugin; 37 private boolean start; 38 39 private JTextField filePath; 40 private HTMLEditor comment; 41 42 private JButton btnSend; 44 private JButton btnCancel; 45 private JButton btnSelect; 46 47 private JButton btnSave; 49 private JButton btnOpen; 50 private JButton btnOpenOther; 51 private JButton btnReject; 52 53 public SendFileDialog(SendFile plugin, String title, boolean start) 54 { 55 super(plugin, title); 56 this.plugin = plugin; 57 this.start = start; 58 59 initComponents(); 60 setPreferredSize(new Dimension (500, 300)); 61 setName("dialog"); 62 } 63 64 private void initComponents() 65 { 66 getContentPane().setLayout(new BorderLayout ()); 67 68 JPanel filePanel = new JPanel(new BorderLayout ()); 70 filePanel.add(new JLabel(plugin.tr("lbl.file")), BorderLayout.WEST); 71 filePath = new JTextField(""); 72 filePath.setEditable(false); 73 filePanel.add(filePath, BorderLayout.CENTER); 74 if(start) 75 { 76 btnSelect = new JButton(plugin.tr("btn.select")); 77 btnSelect.addActionListener(this); 78 filePanel.add(btnSelect, BorderLayout.EAST); 79 } 80 getContentPane().add(filePanel, BorderLayout.NORTH); 81 82 comment = new HTMLEditor(); 84 comment.setBorder(BorderFactory.createTitledBorder(plugin.tr("lbl.comment"))); 85 if(!start) 86 { 87 comment.setEditable(false); 88 comment.setToolbarVisible(false); 89 } 90 getContentPane().add(comment, BorderLayout.CENTER); 91 92 JPanel buttonPanel = new JPanel(new BorderLayout ()); 94 JPanel buttons = null; 95 if(start) 96 { 97 buttons = new JPanel(new GridLayout (1, 2)); 98 btnSend = new JButton(plugin.tr("btn.send"), Client.getImageIcon("ok.png")); 99 btnCancel = new JButton(plugin.tr("btn.cancel"), Client.getImageIcon("cancel.png")); 100 btnSend.addActionListener(this); 101 btnCancel.addActionListener(this); 102 buttons.add(btnSend); 103 buttons.add(btnCancel); 104 } 105 else 106 { 107 String command = plugin.getShortCommand(); 108 109 buttons = new JPanel(new GridLayout (1, 0)); 110 btnSave = new JButton(plugin.tr("btn.save"), Client.getImageIcon("ok.png")); 111 btnSave.addActionListener(this); 112 buttons.add(btnSave); 113 114 if(command != null) 115 { 116 btnOpen = new JButton(command, Client.getImageIcon("open.png")); 117 btnOpen.setToolTipText(plugin.getCommand()); 118 btnOpen.addActionListener(this); 119 buttons.add(btnOpen); 120 } 121 122 btnOpenOther = new JButton(plugin.tr("btn.open"), Client.getImageIcon("open.png")); 123 btnOpenOther.addActionListener(this); 124 buttons.add(btnOpenOther); 125 126 btnReject = new JButton(plugin.tr("btn.reject"), Client.getImageIcon("cancel.png")); 127 btnReject.addActionListener(this); 128 buttons.add(btnReject); 129 } 130 buttonPanel.add(buttons, BorderLayout.EAST); 131 getContentPane().add(buttonPanel, BorderLayout.SOUTH); 132 } 133 134 public void setFilePath(String filePath) 135 { 136 this.filePath.setText(filePath); 137 } 138 139 public String getFilePath() 140 { 141 return this.filePath.getText(); 142 } 143 144 public void setComment(String html) 145 { 146 this.comment.setText(html); 147 } 148 149 public String getComment() 150 { 151 return this.comment.getText(); 152 } 153 154 public void actionPerformed(ActionEvent ae) 155 { 156 if(ae.getSource() == btnCancel) 157 dispose(); 158 else if(ae.getSource() == btnReject) 159 plugin.rejectFile(); 160 else if(ae.getSource() == btnSave) 161 { 162 Runnable r = new Runnable () { 163 public void run() { 164 plugin.saveFile(); 165 } 166 }; 167 new Thread (r).start(); 168 } 169 else if(ae.getSource() == btnOpen) 170 { 171 Runnable r = new Runnable () { 172 public void run() { 173 plugin.openFile(); 174 } 175 }; 176 new Thread (r).start(); 177 } 178 else if(ae.getSource() == btnOpenOther) 179 { 180 if(plugin.selectCommand() != null) 181 { 182 Runnable r = new Runnable () { 183 public void run() { 184 plugin.openFile(); 185 } 186 }; 187 new Thread (r).start(); 188 } 189 } 190 else if(ae.getSource() == btnSelect) 191 plugin.selectFile(this); 192 else if(ae.getSource() == btnSend) 193 { 194 Runnable r = new Runnable () { 195 public void run() { 196 plugin.askForAccept(getFilePath(), getComment()); 197 } 198 }; 199 new Thread (r).start(); 200 } 201 } 202 } | Popular Tags |