PageRenderTime 52ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/src/mpv5/ui/panels/MassPrintPanel.java

http://mp-rechnungs-und-kundenverwaltung.googlecode.com/
Java | 747 lines | 655 code | 66 blank | 26 comment | 58 complexity | 04af50f04f65f1c2114abbb29c5dd8f0 MD5 | raw file
Possible License(s): LGPL-3.0, Apache-2.0, GPL-3.0, GPL-2.0, AGPL-3.0, JSON, BSD-3-Clause
  1. /*
  2. * To change this template, choose Tools | Templates
  3. * and open the template in the editor.
  4. */
  5. /*
  6. * MassPrintUI.java
  7. *
  8. * Created on 09.05.2011, 22:07:37
  9. */
  10. package mpv5.ui.panels;
  11. import enoa.handler.TemplateHandler;
  12. import java.awt.Font;
  13. import java.awt.GraphicsEnvironment;
  14. import java.awt.event.ActionEvent;
  15. import java.awt.event.ActionListener;
  16. import java.awt.event.MouseEvent;
  17. import java.io.ByteArrayOutputStream;
  18. import java.io.File;
  19. import java.io.IOException;
  20. import java.util.ArrayList;
  21. import java.util.HashMap;
  22. import java.util.List;
  23. import javax.swing.DefaultComboBoxModel;
  24. import javax.swing.DefaultListModel;
  25. import javax.swing.JComboBox;
  26. import javax.swing.JTextPane;
  27. import javax.swing.JToggleButton;
  28. import javax.swing.text.AttributeSet;
  29. import javax.swing.text.BadLocationException;
  30. import javax.swing.text.MutableAttributeSet;
  31. import javax.swing.text.SimpleAttributeSet;
  32. import javax.swing.text.StyleConstants;
  33. import javax.swing.text.StyledDocument;
  34. import javax.swing.text.StyledEditorKit;
  35. import javax.swing.text.rtf.RTFEditorKit;
  36. import mpv5.db.common.Context;
  37. import mpv5.db.common.DatabaseObject;
  38. import mpv5.db.common.DatabaseSearch;
  39. import mpv5.db.common.NodataFoundException;
  40. import mpv5.db.common.QueryHandler;
  41. import mpv5.db.common.ReturnValue;
  42. import mpv5.db.objects.Contact;
  43. import mpv5.db.objects.MailMessage;
  44. import mpv5.db.objects.MassprintRules;
  45. import mpv5.db.objects.Template;
  46. import mpv5.db.objects.User;
  47. import mpv5.globals.Constants;
  48. import mpv5.globals.LocalSettings;
  49. import mpv5.globals.Messages;
  50. import mpv5.logging.Log;
  51. import mpv5.ui.dialogs.DialogForFile;
  52. import mpv5.ui.dialogs.Popup;
  53. import mpv5.ui.menus.ListMenuItem;
  54. import mpv5.ui.popups.ListPopUp;
  55. import mpv5.usermanagement.MPSecurityManager;
  56. import mpv5.utils.export.Export;
  57. import mpv5.utils.jobs.Job;
  58. import mpv5.utils.jobs.Waitable;
  59. /**
  60. *
  61. * @author Samsung SA11
  62. */
  63. public class MassPrintPanel
  64. extends javax.swing.JPanel
  65. implements ActionListener {
  66. private static MassPrintPanel me;
  67. private final DefaultListModel model;
  68. private static final long serialVersionUID = -4425127949239926332L;
  69. /**
  70. * Singleton
  71. * @return
  72. */
  73. public static MassPrintPanel instanceOf() {
  74. if (me == null) {
  75. me = new MassPrintPanel();
  76. }
  77. me.setContacts();
  78. me.setTemplateList();
  79. me.setMessageTemplateList();
  80. return me;
  81. }
  82. private int cursorPosition;
  83. /** Creates new form MassPrintUI */
  84. public MassPrintPanel() {
  85. model = new DefaultListModel();
  86. initComponents();
  87. setName("MassPrintPanel");
  88. }
  89. /** This method is called from within the constructor to
  90. * initialize the form.
  91. * WARNING: Do NOT modify this code. The content of this method is
  92. * always regenerated by the Form Editor.
  93. */
  94. @SuppressWarnings("unchecked")
  95. // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
  96. private void initComponents() {
  97. jPanel3 = new javax.swing.JPanel();
  98. jComboBox2 = new javax.swing.JComboBox();
  99. String fontSizes[] = {"8", "10", "11", "12", "14", "16", "18",
  100. "20", "24", "30", "36", "40", "48", "60", "72"};
  101. for (int index = 0; index < fontSizes.length; index++) {
  102. jComboBox2.addItem(fontSizes[index]);
  103. }
  104. jComboBox1 = new javax.swing.JComboBox();
  105. try {
  106. String[] fonts = GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames();
  107. Log.Debug(this, "Ermittelte Fonts: " + fonts.length);
  108. for (int index = 0; index < fonts.length; index++) {
  109. jComboBox1.addItem(fonts[index]);
  110. }
  111. } catch (Exception e) {
  112. Log.Debug(MassPrintPanel.class, e);
  113. }
  114. jToggleButton3 = new javax.swing.JToggleButton();
  115. jToggleButton1 = new javax.swing.JToggleButton();
  116. jToggleButton2 = new javax.swing.JToggleButton();
  117. jLabel3 = new javax.swing.JLabel();
  118. jScrollPane1 = new javax.swing.JScrollPane();
  119. RTF_Text = new javax.swing.JTextPane();
  120. dateTo = new mpv5.ui.beans.DateChooser();
  121. templates = new javax.swing.JComboBox();
  122. jButton1 = new javax.swing.JButton();
  123. jLabel5 = new javax.swing.JLabel();
  124. jButton2 = new javax.swing.JButton();
  125. messageTpl = new javax.swing.JComboBox();
  126. jLabel6 = new javax.swing.JLabel();
  127. jLabel7 = new javax.swing.JLabel();
  128. jPanel1 = new javax.swing.JPanel();
  129. jScrollPane2 = new javax.swing.JScrollPane();
  130. contactlist = new javax.swing.JList();
  131. setName("Form"); // NOI18N
  132. setPreferredSize(new java.awt.Dimension(1004, 333));
  133. setLayout(new java.awt.BorderLayout());
  134. java.util.ResourceBundle bundle = mpv5.i18n.LanguageManager.getBundle(); // NOI18N
  135. jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder(bundle.getString("ConversationPanel.jPanel3.border.title"))); // NOI18N
  136. jPanel3.setPreferredSize(new java.awt.Dimension(818, 333));
  137. jComboBox2.setName("jComboBox2"); // NOI18N
  138. jComboBox2.addActionListener(new java.awt.event.ActionListener() {
  139. public void actionPerformed(java.awt.event.ActionEvent evt) {
  140. jComboBox2ActionPerformed(evt);
  141. }
  142. });
  143. jComboBox1.setName("jComboBox1"); // NOI18N
  144. jComboBox1.addActionListener(new java.awt.event.ActionListener() {
  145. public void actionPerformed(java.awt.event.ActionEvent evt) {
  146. jComboBox1ActionPerformed(evt);
  147. }
  148. });
  149. jToggleButton3.setFont(jToggleButton3.getFont());
  150. jToggleButton3.setText(bundle.getString("ConversationPanel.jToggleButton3.text")); // NOI18N
  151. jToggleButton3.setName("jToggleButton3"); // NOI18N
  152. jToggleButton3.addActionListener(new java.awt.event.ActionListener() {
  153. public void actionPerformed(java.awt.event.ActionEvent evt) {
  154. jToggleButton3ActionPerformed(evt);
  155. }
  156. });
  157. jToggleButton1.setFont(new java.awt.Font("Tahoma", 1, 11));
  158. jToggleButton1.setText(bundle.getString("ConversationPanel.jToggleButton1.text")); // NOI18N
  159. jToggleButton1.setName("jToggleButton1"); // NOI18N
  160. jToggleButton1.addActionListener(new java.awt.event.ActionListener() {
  161. public void actionPerformed(java.awt.event.ActionEvent evt) {
  162. jToggleButton1ActionPerformed(evt);
  163. }
  164. });
  165. jToggleButton2.setFont(new java.awt.Font("Tahoma", 2, 11));
  166. jToggleButton2.setText(bundle.getString("ConversationPanel.jToggleButton2.text")); // NOI18N
  167. jToggleButton2.setName("jToggleButton2"); // NOI18N
  168. jToggleButton2.addActionListener(new java.awt.event.ActionListener() {
  169. public void actionPerformed(java.awt.event.ActionEvent evt) {
  170. jToggleButton2ActionPerformed(evt);
  171. }
  172. });
  173. jLabel3.setText(bundle.getString("ConversationPanel.jLabel3.text")); // NOI18N
  174. jLabel3.setName("jLabel3"); // NOI18N
  175. jScrollPane1.setName("jScrollPane1"); // NOI18N
  176. RTF_Text.setDocument(new javax.swing.text.rtf.RTFEditorKit().createDefaultDocument());
  177. RTF_Text.setEditorKit(new javax.swing.text.rtf.RTFEditorKit());
  178. RTF_Text.setFont(Font.decode(LocalSettings.getProperty(LocalSettings.DEFAULT_FONT)).deriveFont(Font.PLAIN, 11));
  179. RTF_Text.setName("RTF_Text"); // NOI18N
  180. RTF_Text.addCaretListener(new javax.swing.event.CaretListener() {
  181. public void caretUpdate(javax.swing.event.CaretEvent evt) {
  182. RTF_TextCaretUpdate(evt);
  183. }
  184. });
  185. jScrollPane1.setViewportView(RTF_Text);
  186. dateTo.setMaximumSize(new java.awt.Dimension(32767, 20));
  187. dateTo.setMinimumSize(new java.awt.Dimension(120, 20));
  188. dateTo.setName("dateTo"); // NOI18N
  189. dateTo.setPreferredSize(new java.awt.Dimension(150, 20));
  190. templates.setModel(new DefaultComboBoxModel());
  191. templates.setName("templates"); // NOI18N
  192. jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/mpv5/resources/images/32/bright_printer.png"))); // NOI18N
  193. jButton1.setText(bundle.getString("MassPrintPanel.jButton1.text")); // NOI18N
  194. jButton1.setName("jButton1"); // NOI18N
  195. jButton1.addActionListener(new java.awt.event.ActionListener() {
  196. public void actionPerformed(java.awt.event.ActionEvent evt) {
  197. jButton1ActionPerformed(evt);
  198. }
  199. });
  200. jLabel5.setText(bundle.getString("ConversationPanel.jLabel3.text")); // NOI18N
  201. jLabel5.setBorder(javax.swing.BorderFactory.createEtchedBorder());
  202. jLabel5.setName("jLabel5"); // NOI18N
  203. jButton2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/mpv5/resources/images/32/acroread.png"))); // NOI18N
  204. jButton2.setText(bundle.getString("MassPrintPanel.jButton2.text_1")); // NOI18N
  205. jButton2.setName("jButton2"); // NOI18N
  206. jButton2.addActionListener(new java.awt.event.ActionListener() {
  207. public void actionPerformed(java.awt.event.ActionEvent evt) {
  208. jButton2ActionPerformed(evt);
  209. }
  210. });
  211. messageTpl.setModel(new DefaultComboBoxModel());
  212. messageTpl.setName("messageTpl"); // NOI18N
  213. messageTpl.addActionListener(new java.awt.event.ActionListener() {
  214. public void actionPerformed(java.awt.event.ActionEvent evt) {
  215. messageTplActionPerformed(evt);
  216. }
  217. });
  218. jLabel6.setText(bundle.getString("MassPrintPanel.jLabel6.text")); // NOI18N
  219. jLabel6.setName("jLabel6"); // NOI18N
  220. jLabel7.setText(bundle.getString("MassPrintPanel.jLabel7.text")); // NOI18N
  221. jLabel7.setName("jLabel7"); // NOI18N
  222. javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
  223. jPanel3.setLayout(jPanel3Layout);
  224. jPanel3Layout.setHorizontalGroup(
  225. jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  226. .addGroup(jPanel3Layout.createSequentialGroup()
  227. .addContainerGap()
  228. .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  229. .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 820, Short.MAX_VALUE)
  230. .addGroup(jPanel3Layout.createSequentialGroup()
  231. .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  232. .addGroup(jPanel3Layout.createSequentialGroup()
  233. .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
  234. .addComponent(jLabel6, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  235. .addComponent(templates, javax.swing.GroupLayout.Alignment.LEADING, 0, 183, Short.MAX_VALUE))
  236. .addGap(18, 18, 18)
  237. .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
  238. .addComponent(messageTpl, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  239. .addComponent(jLabel7, javax.swing.GroupLayout.DEFAULT_SIZE, 210, Short.MAX_VALUE))
  240. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  241. .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 178, javax.swing.GroupLayout.PREFERRED_SIZE)
  242. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  243. .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 190, javax.swing.GroupLayout.PREFERRED_SIZE)
  244. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED))
  245. .addGroup(jPanel3Layout.createSequentialGroup()
  246. .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, 295, javax.swing.GroupLayout.PREFERRED_SIZE)
  247. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  248. .addComponent(jComboBox2, javax.swing.GroupLayout.PREFERRED_SIZE, 63, javax.swing.GroupLayout.PREFERRED_SIZE)
  249. .addGap(7, 7, 7)
  250. .addComponent(jToggleButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 68, javax.swing.GroupLayout.PREFERRED_SIZE)
  251. .addGap(2, 2, 2)
  252. .addComponent(jToggleButton2)
  253. .addGap(5, 5, 5)
  254. .addComponent(jToggleButton3)
  255. .addGap(22, 22, 22)
  256. .addComponent(jLabel3)
  257. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
  258. .addComponent(dateTo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
  259. .addGap(10, 10, 10))
  260. .addComponent(jLabel5, javax.swing.GroupLayout.DEFAULT_SIZE, 820, Short.MAX_VALUE)))
  261. );
  262. jPanel3Layout.setVerticalGroup(
  263. jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  264. .addGroup(jPanel3Layout.createSequentialGroup()
  265. .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
  266. .addGroup(jPanel3Layout.createSequentialGroup()
  267. .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
  268. .addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
  269. .addComponent(jLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE))
  270. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  271. .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
  272. .addComponent(templates, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  273. .addComponent(messageTpl, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)))
  274. .addComponent(jButton2, javax.swing.GroupLayout.Alignment.CENTER, javax.swing.GroupLayout.DEFAULT_SIZE, 46, Short.MAX_VALUE)
  275. .addComponent(jButton1, javax.swing.GroupLayout.Alignment.CENTER, javax.swing.GroupLayout.DEFAULT_SIZE, 45, Short.MAX_VALUE))
  276. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
  277. .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
  278. .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  279. .addComponent(jComboBox2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  280. .addComponent(jToggleButton1)
  281. .addComponent(jToggleButton2)
  282. .addComponent(jToggleButton3)
  283. .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
  284. .addComponent(dateTo, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE))
  285. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
  286. .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
  287. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  288. .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 232, Short.MAX_VALUE))
  289. );
  290. add(jPanel3, java.awt.BorderLayout.CENTER);
  291. jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(bundle.getString("MassPrintPanel.jPanel1.border.title_1"))); // NOI18N
  292. jPanel1.setPreferredSize(new java.awt.Dimension(170, 333));
  293. jScrollPane2.setName("jScrollPane2"); // NOI18N
  294. contactlist.setModel(model);
  295. contactlist.setToolTipText(bundle.getString("MassPrintPanel.contactlist.toolTipText_1")); // NOI18N
  296. contactlist.setName("contactlist"); // NOI18N
  297. contactlist.setSelectionBackground(java.awt.Color.green);
  298. contactlist.setSelectionForeground(java.awt.Color.black);
  299. contactlist.addMouseListener(new java.awt.event.MouseAdapter() {
  300. public void mouseReleased(java.awt.event.MouseEvent evt) {
  301. contactlistMouseReleased(evt);
  302. }
  303. });
  304. jScrollPane2.setViewportView(contactlist);
  305. javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
  306. jPanel1.setLayout(jPanel1Layout);
  307. jPanel1Layout.setHorizontalGroup(
  308. jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  309. .addGroup(jPanel1Layout.createSequentialGroup()
  310. .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 158, javax.swing.GroupLayout.PREFERRED_SIZE)
  311. .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
  312. );
  313. jPanel1Layout.setVerticalGroup(
  314. jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  315. .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 349, Short.MAX_VALUE)
  316. );
  317. add(jPanel1, java.awt.BorderLayout.WEST);
  318. }// </editor-fold>//GEN-END:initComponents
  319. private void jToggleButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jToggleButton1ActionPerformed
  320. JToggleButton btn = (JToggleButton) evt.getSource();
  321. RTFEditorKit kit = (RTFEditorKit) RTF_Text.getEditorKit();
  322. MutableAttributeSet attr = kit.getInputAttributes();
  323. boolean bold = (StyleConstants.isBold(attr)) ? false : true;
  324. btn.setSelected(bold);
  325. SimpleAttributeSet sas = new SimpleAttributeSet();
  326. StyleConstants.setBold(sas, bold);
  327. RTF_Text.setCharacterAttributes(sas, false);
  328. }//GEN-LAST:event_jToggleButton1ActionPerformed
  329. private void jToggleButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jToggleButton2ActionPerformed
  330. JToggleButton btn = (JToggleButton) evt.getSource();
  331. RTFEditorKit kit = (RTFEditorKit) RTF_Text.getEditorKit();
  332. MutableAttributeSet attr = kit.getInputAttributes();
  333. boolean italic = (StyleConstants.isItalic(attr)) ? false : true;
  334. btn.setSelected(italic);
  335. SimpleAttributeSet sas = new SimpleAttributeSet();
  336. StyleConstants.setItalic(sas, italic);
  337. RTF_Text.setCharacterAttributes(sas, false);
  338. }//GEN-LAST:event_jToggleButton2ActionPerformed
  339. private void jToggleButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jToggleButton3ActionPerformed
  340. JToggleButton btn = (JToggleButton) evt.getSource();
  341. RTFEditorKit kit = (RTFEditorKit) RTF_Text.getEditorKit();
  342. MutableAttributeSet attr = kit.getInputAttributes();
  343. boolean under = (StyleConstants.isUnderline(attr)) ? false : true;
  344. btn.setSelected(under);
  345. SimpleAttributeSet sas = new SimpleAttributeSet();
  346. StyleConstants.setUnderline(sas, under);
  347. RTF_Text.setCharacterAttributes(sas, false);
  348. }//GEN-LAST:event_jToggleButton3ActionPerformed
  349. private void RTF_TextCaretUpdate(javax.swing.event.CaretEvent evt) {//GEN-FIRST:event_RTF_TextCaretUpdate
  350. JTextPane text = (JTextPane) evt.getSource();
  351. StyledDocument doc = text.getStyledDocument();
  352. if (doc.getLength() > 0) {
  353. Boolean isBold = null;
  354. Boolean isItalic = null;
  355. Boolean isUnderline = null;
  356. Boolean tmp = null;
  357. String fontFamily = null;
  358. int fontSize = 8;
  359. cursorPosition = evt.getDot();
  360. for (int i = evt.getMark(); i < cursorPosition; i++) {
  361. AttributeSet atts = doc.getCharacterElement(i).getAttributes();
  362. tmp = StyleConstants.isBold(atts);
  363. if (isBold == null) {
  364. isBold = tmp;
  365. } else if (tmp.equals(isBold) == false) {
  366. isBold = false;
  367. }
  368. tmp = StyleConstants.isItalic(atts);
  369. if (isItalic == null) {
  370. isItalic = tmp;
  371. } else if (tmp.equals(isItalic) == false) {
  372. isItalic = false;
  373. }
  374. tmp = StyleConstants.isUnderline(atts);
  375. if (isUnderline == null) {
  376. isUnderline = tmp;
  377. } else if (tmp.equals(isUnderline) == false) {
  378. isUnderline = false;
  379. }
  380. fontFamily = StyleConstants.getFontFamily(atts);
  381. fontSize = StyleConstants.getFontSize(atts);
  382. }
  383. if (isBold == null && isItalic == null && isUnderline == null) {
  384. AttributeSet atts = doc.getCharacterElement(evt.getDot() - 1).getAttributes();
  385. isBold = StyleConstants.isBold(atts);
  386. isItalic = StyleConstants.isItalic(atts);
  387. isUnderline = StyleConstants.isUnderline(atts);
  388. }
  389. if (fontFamily == null || fontSize == 8) {
  390. AttributeSet atts = doc.getCharacterElement(evt.getDot() - 1).getAttributes();
  391. fontFamily = StyleConstants.getFontFamily(atts);
  392. fontSize = StyleConstants.getFontSize(atts);
  393. }
  394. jToggleButton1.setSelected(isBold);
  395. jToggleButton2.setSelected(isItalic);
  396. jToggleButton3.setSelected(isUnderline);
  397. jComboBox1.setSelectedItem(fontFamily);
  398. jComboBox2.setSelectedItem(String.valueOf(fontSize));
  399. }
  400. }//GEN-LAST:event_RTF_TextCaretUpdate
  401. private void jComboBox1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBox1ActionPerformed
  402. JComboBox comboBox = (JComboBox) evt.getSource();
  403. javax.swing.text.StyledEditorKit.FontFamilyAction action = new StyledEditorKit.FontFamilyAction("yyy", comboBox.getSelectedItem().toString());
  404. action.actionPerformed(new ActionEvent(comboBox, ActionEvent.ACTION_PERFORMED, "yyy"));
  405. }//GEN-LAST:event_jComboBox1ActionPerformed
  406. private void jComboBox2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBox2ActionPerformed
  407. JComboBox comboBox = (JComboBox) evt.getSource();
  408. javax.swing.text.StyledEditorKit.FontSizeAction action = new StyledEditorKit.FontSizeAction("xxx", Integer.parseInt(comboBox.getSelectedItem().toString()));
  409. action.actionPerformed(new ActionEvent(comboBox, ActionEvent.ACTION_PERFORMED, "xxx"));
  410. }//GEN-LAST:event_jComboBox2ActionPerformed
  411. private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
  412. Runnable runnable = new Runnable() {
  413. @Override
  414. public void run() {
  415. Object[] sel = contactlist.getSelectedValues();
  416. Template tpl = (Template) templates.getSelectedItem();
  417. HashMap<String, Object> hm1;
  418. List<File> files = new ArrayList<File>();
  419. File f;
  420. if (tpl != null) {
  421. for (int o = 0; o < sel.length; o++) {
  422. try {
  423. Contact cont = (Contact) (Contact.getObject(Context.getContact(), ((IdItem) sel[o]).getId()));
  424. hm1 = new HashMap<String, Object>();
  425. hm1 = me.ReplaceVariablesInContent(hm1, cont);
  426. f = Export.print2(TemplateHandler.loadTemplate(tpl),
  427. cont, hm1);
  428. files.add(f);
  429. mpv5.YabsViewProxy.instance().getProgressbar().setValue((100 / sel.length) * (o + 1));
  430. mpv5.YabsViewProxy.instance().getProgressbar().setString(cont.__getCname());
  431. mpv5.YabsViewProxy.instance().getProgressbar().setStringPainted(true);
  432. } catch (NodataFoundException e) {
  433. Log.Debug(this, e);
  434. }
  435. }
  436. } else {
  437. Popup.error(MassPrintPanel.instanceOf(), Messages.NO_TEMPLATE_DEFINDED.toString());
  438. }
  439. if (!files.isEmpty()) {
  440. try {
  441. Export.print3(files, tpl.__getPrinter());
  442. } catch (Exception ex1) {
  443. Log.Debug(ex1);
  444. }
  445. }
  446. }
  447. };
  448. new Thread(runnable).start();
  449. }//GEN-LAST:event_jButton1ActionPerformed
  450. private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
  451. Object[] sel = contactlist.getSelectedValues();
  452. Template tpl = (Template) templates.getSelectedItem();
  453. HashMap<String, Object> hm1;
  454. List<Waitable> files = new ArrayList<Waitable>();
  455. if (tpl != null) {
  456. for (int o = 0; o < sel.length; o++) {
  457. try {
  458. Contact cont = (Contact) (Contact.getObject(Context.getContact(), ((IdItem) sel[o]).getId()));
  459. hm1 = new HashMap<String, Object>();
  460. hm1 = this.ReplaceVariablesInContent(hm1, cont);
  461. files.add(Export.createFile(cont.__getCname(),
  462. TemplateHandler.loadTemplate(tpl),
  463. cont,
  464. hm1));
  465. mpv5.YabsViewProxy.instance().getProgressbar().setValue((100 / sel.length) * (o + 1));
  466. mpv5.YabsViewProxy.instance().getProgressbar().setString(cont.__getCname());
  467. mpv5.YabsViewProxy.instance().getProgressbar().setStringPainted(true);
  468. } catch (NodataFoundException ex) {
  469. Log.Debug(this, ex);
  470. }
  471. }
  472. } else {
  473. Popup.error(this, Messages.NO_TEMPLATE_DEFINDED.toString());
  474. }
  475. if (!files.isEmpty()) {
  476. DialogForFile.CURRENT_DIR = new File(LocalSettings.getProperty(LocalSettings.BASE_DIR) + File.separator + "test");
  477. DialogForFile d = new DialogForFile();
  478. Job job = new Job(files, d, files.size() + " PDF " + Messages.SAVED);
  479. job.execute();
  480. mpv5.YabsViewProxy.instance().getProgressbar().setValue(100);
  481. mpv5.YabsViewProxy.instance().getProgressbar().setString(Messages.DONE.toString());
  482. }
  483. }//GEN-LAST:event_jButton2ActionPerformed
  484. private void messageTplActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_messageTplActionPerformed
  485. if (evt.getModifiers() == 16) {
  486. try {
  487. String cn = (String) messageTpl.getSelectedItem();
  488. MailMessage msg = (MailMessage) (MailMessage.getObject(Context.getMessage(), cn));
  489. StyledDocument doc = RTF_Text.getStyledDocument();
  490. doc.insertString(cursorPosition, msg.__getDescription(), null);
  491. } catch (BadLocationException ex) {
  492. Log.Debug(this, ex);
  493. } catch (NodataFoundException ex) {
  494. Log.Debug(this, ex);
  495. }
  496. }
  497. }//GEN-LAST:event_messageTplActionPerformed
  498. private void contactlistMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_contactlistMouseReleased
  499. if (evt.isPopupTrigger()) {
  500. showMenu(evt);
  501. }
  502. }//GEN-LAST:event_contactlistMouseReleased
  503. // Variables declaration - do not modify//GEN-BEGIN:variables
  504. private javax.swing.JTextPane RTF_Text;
  505. private javax.swing.JList contactlist;
  506. private mpv5.ui.beans.DateChooser dateTo;
  507. private javax.swing.JButton jButton1;
  508. private javax.swing.JButton jButton2;
  509. private javax.swing.JComboBox jComboBox1;
  510. private javax.swing.JComboBox jComboBox2;
  511. private javax.swing.JLabel jLabel3;
  512. private javax.swing.JLabel jLabel5;
  513. private javax.swing.JLabel jLabel6;
  514. private javax.swing.JLabel jLabel7;
  515. private javax.swing.JPanel jPanel1;
  516. private javax.swing.JPanel jPanel3;
  517. private javax.swing.JScrollPane jScrollPane1;
  518. private javax.swing.JScrollPane jScrollPane2;
  519. private javax.swing.JToggleButton jToggleButton1;
  520. private javax.swing.JToggleButton jToggleButton2;
  521. private javax.swing.JToggleButton jToggleButton3;
  522. private javax.swing.JComboBox messageTpl;
  523. private javax.swing.JComboBox templates;
  524. // End of variables declaration//GEN-END:variables
  525. private void setContacts() {
  526. Runnable runnable = new Runnable() {
  527. @Override
  528. public void run() {
  529. Object[][] data1 = null;
  530. data1 = new DatabaseSearch(Context.getContact(), 200).getValuesFor("ids, cname", "cname", "", true);
  531. model.clear();
  532. for (int i = 0; i < data1.length; i++) {
  533. model.addElement(new IdItem(Integer.parseInt(data1[i][0].toString()), data1[i][1].toString()));
  534. }
  535. }
  536. };
  537. new Thread(runnable).start();
  538. }
  539. private void showMenu(MouseEvent evt) {
  540. try {
  541. Object[][] d = QueryHandler.instanceOf().clone(Context.getMassprint()).select(Context.DETAILS_MASSPRINT, false);
  542. String[][] rules = new String[d.length + 1][2];
  543. ActionListener[] act = new ActionListener[d.length + 1];
  544. rules[0][0] = Messages.MASSPRINT_FILTER_ALL.toString();
  545. rules[0][1] = "999999";
  546. act[0] = this;
  547. for (int i = 0; i < d.length; i++) {
  548. rules[i + 1][0] = d[i][1].toString();
  549. rules[i + 1][1] = d[i][0].toString();
  550. act[i + 1] = this;
  551. }
  552. new ListPopUp(contactlist, rules, act);
  553. } catch (NodataFoundException ex) {
  554. Log.Debug(this, ex);
  555. }
  556. }
  557. private void setTemplateList() {
  558. Runnable runnable = new Runnable() {
  559. @Override
  560. public void run() {
  561. DefaultComboBoxModel mdl = (DefaultComboBoxModel) templates.getModel();
  562. Template[] tpl = TemplateHandler.getTemplatesForType(User.getCurrentUser().__getGroupsids(), Constants.TYPE_MASSPRINT);
  563. mdl.removeAllElements();
  564. for (int i = 0; i < tpl.length; i++) {
  565. mdl.addElement(tpl[i]);
  566. TemplateHandler.loadTemplate(tpl[i]);
  567. }
  568. }
  569. };
  570. new Thread(runnable).start();
  571. }
  572. private HashMap<String, Object> ReplaceVariablesInContent(HashMap<String, Object> hm1, Contact cont) {
  573. String rtf = serialize();
  574. hm1.put("massprint.cname", "");
  575. hm1.put("massprint.addedby", User.getCurrentUser().getName());
  576. hm1.put("massprint.dateadded", dateTo.getDate());
  577. if (cont.__getisMale()) {
  578. hm1.put("massprint.gender",
  579. Messages.CONTACT_TYPE_MALE.toString());
  580. hm1.put("massprint.intro",
  581. Messages.CONTACT_INTRO_MALE.toString());
  582. } else {
  583. hm1.put("massprint.gender",
  584. Messages.CONTACT_TYPE_FEMALE.toString());
  585. hm1.put("massprint.intro",
  586. Messages.CONTACT_INTRO_FEMALE.toString());
  587. }
  588. hm1.put("massprint.content", rtf);
  589. return hm1;
  590. }
  591. private String serialize() {
  592. ByteArrayOutputStream out;
  593. RTFEditorKit kit = (RTFEditorKit) RTF_Text.getEditorKit();
  594. StyledDocument doc = RTF_Text.getStyledDocument();
  595. out = new ByteArrayOutputStream();
  596. try {
  597. kit.write(out,
  598. doc,
  599. 0,
  600. doc.getLength());
  601. } catch (BadLocationException ex) {
  602. Log.Debug(this,
  603. ex.toString());
  604. } catch (IOException ex) {
  605. Log.Debug(this,
  606. ex.toString());
  607. }
  608. String str = null;
  609. str = out.toString();
  610. str = str.replaceAll("[\r\n]+",
  611. " ");
  612. str = str.replaceAll(" ",
  613. " ");
  614. return str;
  615. }
  616. private void setMessageTemplateList() {
  617. Runnable runnable = new Runnable() {
  618. @Override
  619. public void run() {
  620. DefaultComboBoxModel mdl = (DefaultComboBoxModel) messageTpl.getModel();
  621. Object[][] data1 = null;
  622. data1 = new DatabaseSearch(Context.getMessage(), 200).getValuesFor("cname", "cname", "", true);
  623. mdl.removeAllElements();
  624. for (int i = 0; i < data1.length; i++) {
  625. mdl.addElement((String) data1[i][0]);
  626. }
  627. }
  628. };
  629. new Thread(runnable).start();
  630. }
  631. public void actionPerformed(ActionEvent e) {
  632. int cname = 0;
  633. ListMenuItem mi = (ListMenuItem) e.getSource();
  634. Log.Debug(this, " Executing Rule: " + mi.getID());
  635. Object[][] data = null;
  636. int ids = 0;
  637. try {
  638. if (mi.getID() == 999999) {
  639. model.clear();
  640. data = new DatabaseSearch(Context.getContact(), 200).getValuesFor("ids, cname", "cname", "", true);
  641. for (int i = 0; i < data.length; i++) {
  642. model.addElement(new IdItem(Integer.parseInt(data[i][0].toString()), data[i][1].toString()));
  643. }
  644. } else {
  645. MassprintRules mpr = (MassprintRules) (DatabaseObject.getObject(Context.getMassprint(), mi.getID()));
  646. model.clear();
  647. ReturnValue ret = QueryHandler.instanceOf().freeSelectQuery(mpr.__getContent(), MPSecurityManager.VIEW, null);
  648. String[] cols = ret.getFullColumnNames();
  649. for (int j = 0; j < cols.length; j++) {
  650. if (cols[j].equalsIgnoreCase("contacts.cname")) {
  651. cname = j;
  652. }
  653. if (cols[j].equalsIgnoreCase("contacts.ids")) {
  654. ids = j;
  655. }
  656. }
  657. data = ret.getData();
  658. for (int i = 0; i < data.length; i++) {
  659. model.addElement(new IdItem(Integer.parseInt(data[i][ids].toString()), data[i][cname].toString()));
  660. }
  661. }
  662. } catch (NodataFoundException ex) {
  663. Log.Debug(this, ex);
  664. }
  665. }
  666. class IdItem {
  667. int id;
  668. String description;
  669. IdItem(int id, String description) {
  670. this.id = id;
  671. this.description = description;
  672. }
  673. public int getId() {
  674. return id;
  675. }
  676. @Override
  677. public String toString() {
  678. return description;
  679. }
  680. }
  681. }