| 153 | } |
| 154 | |
| 155 | public JPanel createTool() { |
| 156 | JPanel jp = new JPanel(); |
| 157 | jp.setBackground(new Color(255, 255, 255)); |
| 158 | jp.setLayout(new GridLayout(1, 0)); |
| 159 | jp.setPreferredSize(new Dimension(0, 30)); |
| 160 | |
| 161 | toolImageButton = new JButton("图片"); |
| 162 | toolImageButton.setFont(new Font("menlo", Font.BOLD, 17)); |
| 163 | toolImageButton.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); |
| 164 | toolImageButton.setContentAreaFilled(false); |
| 165 | toolImageButton.setFocusPainted(false); |
| 166 | |
| 167 | Action imageAction = new AbstractAction() { |
| 168 | @Override |
| 169 | public void actionPerformed(ActionEvent e) { |
| 170 | |
| 171 | JFileChooser fd = new JFileChooser(); |
| 172 | |
| 173 | fd.setAcceptAllFileFilterUsed(false); |
| 174 | fd.setFileSelectionMode(JFileChooser.FILES_ONLY); |
| 175 | fd.setFileFilter(new FileFilter() { |
| 176 | @Override |
| 177 | public boolean accept(File f) { |
| 178 | return f.getName().endsWith(".bmp") || f.getName().endsWith(".gif") || f.getName().endsWith(".jpg") || f.getName().endsWith(".png") || f.isDirectory(); |
| 179 | } |
| 180 | |
| 181 | @Override |
| 182 | public String getDescription() { |
| 183 | return "Picture(*.png/jpg/gif/bmp)"; |
| 184 | } |
| 185 | }); |
| 186 | |
| 187 | if (fd.showOpenDialog(frame) == JFileChooser.APPROVE_OPTION) { |
| 188 | File file = fd.getSelectedFile(); |
| 189 | |
| 190 | try { |
| 191 | if (file != null) { |
| 192 | sendMsg(Utils.Base64Utils.readBase64(file), 2); |
| 193 | } |
| 194 | } catch (IOException e1) { |
| 195 | e1.printStackTrace(); |
| 196 | } |
| 197 | } |
| 198 | } |
| 199 | }; |
| 200 | toolImageButton.addActionListener(imageAction); |
| 201 | jp.add(toolImageButton); |
| 202 | toolFileButton = new JButton("文件"); |
| 203 | toolFileButton.setFont(new Font("menlo", Font.BOLD, 17)); |
| 204 | toolFileButton.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); |
| 205 | toolFileButton.setContentAreaFilled(false); |
| 206 | toolFileButton.setFocusPainted(false); |
| 207 | |
| 208 | Action fileAction = new AbstractAction() { |
| 209 | @Override |
| 210 | public void actionPerformed(ActionEvent e) { |
| 211 | JFileChooser fd = new JFileChooser(); |
| 212 | fd.setFileSelectionMode(JFileChooser.FILES_ONLY); |