1 19 20 package org.lucane.applications.todolist.gui; 21 22 import java.awt.Dimension ; 23 import java.awt.FlowLayout ; 24 import java.awt.GridBagConstraints ; 25 import java.awt.GridBagLayout ; 26 import java.awt.Insets ; 27 import java.awt.event.ActionEvent ; 28 import java.awt.event.ActionListener ; 29 30 import javax.swing.JButton ; 31 import javax.swing.JLabel ; 32 import javax.swing.JPanel ; 33 import javax.swing.JTextField ; 34 35 import org.lucane.applications.todolist.Todolist; 36 import org.lucane.applications.todolist.io.IO; 37 import org.lucane.client.Client; 38 import org.lucane.client.Plugin; 39 import org.lucane.client.widgets.HTMLEditor; 40 import org.lucane.client.widgets.ManagedWindow; 41 42 public class TodolistDialog extends ManagedWindow { 43 private JTextField jtfName; 44 private HTMLEditor htmledComment; 45 private JButton jbOk; 46 private JButton jbCancel; 47 48 private MainFrame mainFrame; 49 private Plugin plugin; 50 51 private Todolist todolist; 52 53 private boolean modify = false; 54 55 public TodolistDialog (Plugin plugin, MainFrame mainFrame) { 56 super(plugin, ""); 57 this.plugin = plugin; 58 this.mainFrame = mainFrame; 59 init(); 60 } 61 62 public TodolistDialog (Plugin plugin, MainFrame mainFrame, Todolist todolist) { 63 super(plugin, ""); 64 this.plugin = plugin; 65 this.mainFrame = mainFrame; 66 this.todolist = todolist; 67 modify=true; 68 init(); 69 } 70 71 private void init() { 72 if (modify) { 73 setTitle(plugin.tr("TodoListDialog.modificationTitle")); 74 } else { 75 setTitle(plugin.tr("TodoListDialog.creationTitle")); 76 } 77 this.setName("TodolistDialog"); 78 setPreferredSize(new Dimension (512, 384)); 79 80 jtfName = new JTextField (); 81 htmledComment = new HTMLEditor(); 82 83 jbOk = new JButton (plugin.tr("TodoListDialog.ok")); 84 this.jbOk.setIcon(Client.getImageIcon("ok.png")); 85 jbOk.addActionListener(new ActionListener () { 86 public void actionPerformed(ActionEvent arg0) { 87 if (modify) 88 mainFrame.modifyTodolist( 89 todolist, 90 new Todolist( 91 todolist.getId(), 92 todolist.getUserName(), 93 jtfName.getText(), 94 htmledComment.getText())); 95 else 96 mainFrame.addTodolist(new Todolist(IO.getInstance(plugin).getUserName(), jtfName.getText(), htmledComment.getText())); 97 hide(); 98 } 99 }); 100 jbCancel = new JButton (plugin.tr("TodoListDialog.cancel")); 101 this.jbCancel.setIcon(Client.getImageIcon("cancel.png")); 102 jbCancel.addActionListener(new ActionListener () { 103 public void actionPerformed(ActionEvent arg0) { 104 hide(); 105 } 106 }); 107 108 JPanel jpButtons = new JPanel (new FlowLayout (FlowLayout.RIGHT, 2, 2)); 109 jpButtons.add(jbOk); 110 jpButtons.add(jbCancel); 111 112 getContentPane().setLayout(new GridBagLayout ()); 113 GridBagConstraints c = new GridBagConstraints (); 114 115 c.insets=new Insets (2,2,2,2); 116 c.anchor=GridBagConstraints.NORTH; 117 c.fill=GridBagConstraints.HORIZONTAL; 118 c.gridy=0; 119 c.gridx=0; 120 c.weightx=0; 121 c.weighty=0; 122 getContentPane().add(new JLabel (plugin.tr("TodoListDialog.name")), c); 123 c.gridx=1; 124 c.weightx=1; 125 getContentPane().add(jtfName, c); 126 127 c.gridy=1; 128 c.gridx=0; 129 c.weightx=0; 130 c.weighty=1; 131 getContentPane().add(new JLabel (plugin.tr("TodoListDialog.comment")), c); 132 c.fill=GridBagConstraints.BOTH; 133 c.gridx=1; 134 c.weightx=1; 135 getContentPane().add(htmledComment, c); 136 137 c.fill=GridBagConstraints.BOTH; 138 c.gridy=2; 139 c.gridx=0; 140 c.weightx=1; 141 c.weighty=0; 142 c.gridwidth=2; 143 getContentPane().add(jpButtons, c); 144 145 if (modify) { 146 jtfName.setText(todolist.getName()); 147 htmledComment.setText(todolist.getComment()); 148 } 149 } 150 } 151 | Popular Tags |