1 19 20 package org.netbeans.modules.subversion.ui.commit; 21 22 import org.netbeans.modules.subversion.SvnModuleConfig; 23 import org.netbeans.modules.versioning.util.ListenersSupport; 24 import org.netbeans.modules.versioning.util.VersioningListener; 25 import org.netbeans.modules.versioning.util.Utils; 26 import org.netbeans.modules.versioning.util.StringSelector; 27 import org.openide.util.NbBundle; 28 29 import javax.swing.event.TableModelListener ; 30 import javax.swing.event.TableModelEvent ; 31 import java.util.prefs.PreferenceChangeEvent ; 32 import java.util.prefs.PreferenceChangeListener ; 33 import java.util.*; 34 import java.awt.event.MouseAdapter ; 35 import java.awt.event.MouseEvent ; 36 import java.awt.Cursor ; 37 38 42 public class CommitPanel extends javax.swing.JPanel implements PreferenceChangeListener , TableModelListener { 43 44 static final Object EVENT_SETTINGS_CHANGED = new Object (); 45 46 private CommitTable commitTable; 47 48 49 public CommitPanel() { 50 initComponents(); 51 } 52 53 void setCommitTable(CommitTable commitTable) { 54 this.commitTable = commitTable; 55 } 56 57 void setErrorLabel(String htmlErrorLabel) { 58 jLabel2.setText(htmlErrorLabel); 59 } 60 61 public void addNotify() { 62 super.addNotify(); 63 SvnModuleConfig.getDefault().getPreferences().addPreferenceChangeListener(this); 64 commitTable.getTableModel().addTableModelListener(this); 65 listenerSupport.fireVersioningEvent(EVENT_SETTINGS_CHANGED); 66 67 recentLink.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); 68 recentLink.addMouseListener(new MouseAdapter () { 69 public void mouseClicked(MouseEvent e) { 70 onBrowseRecentMessages(); 71 } 72 }); 73 74 List<String > messages = Utils.getStringList(SvnModuleConfig.getDefault().getPreferences(), CommitAction.RECENT_COMMIT_MESSAGES); 75 if (messages.size() > 0) { 76 messageTextArea.setText(messages.get(0)); 77 } 78 messageTextArea.selectAll(); 79 } 80 81 public void removeNotify() { 82 commitTable.getTableModel().removeTableModelListener(this); 83 SvnModuleConfig.getDefault().getPreferences().removePreferenceChangeListener(this); 84 super.removeNotify(); 85 } 86 87 private void onBrowseRecentMessages() { 88 String message = StringSelector.select(NbBundle.getMessage(CommitPanel.class, "CTL_CommitForm_RecentTitle"), 89 NbBundle.getMessage(CommitPanel.class, "CTL_CommitForm_RecentPrompt"), 90 Utils.getStringList(SvnModuleConfig.getDefault().getPreferences(), CommitAction.RECENT_COMMIT_MESSAGES)); 91 if (message != null) { 92 messageTextArea.replaceSelection(message); 93 } 94 } 95 96 public void preferenceChange(PreferenceChangeEvent evt) { 97 if (evt.getKey().startsWith(SvnModuleConfig.PROP_COMMIT_EXCLUSIONS)) { 98 commitTable.dataChanged(); 99 listenerSupport.fireVersioningEvent(EVENT_SETTINGS_CHANGED); 100 } 101 } 102 103 public void tableChanged(TableModelEvent e) { 104 listenerSupport.fireVersioningEvent(EVENT_SETTINGS_CHANGED); 105 } 106 107 112 private void initComponents() { 114 115 setMinimumSize(new java.awt.Dimension (400, 300)); 116 setPreferredSize(new java.awt.Dimension (650, 400)); 117 118 org.openide.awt.Mnemonics.setLocalizedText(jLabel1, org.openide.util.NbBundle.getMessage(CommitPanel.class, "CTL_CommitForm_Message")); 120 messageTextArea.setColumns(30); 121 messageTextArea.setLineWrap(true); 122 messageTextArea.setRows(6); 123 messageTextArea.setTabSize(4); 124 messageTextArea.setWrapStyleWord(true); 125 messageTextArea.setMinimumSize(new java.awt.Dimension (100, 18)); 126 jScrollPane1.setViewportView(messageTextArea); 127 128 org.openide.awt.Mnemonics.setLocalizedText(filesLabel, org.openide.util.NbBundle.getMessage(CommitPanel.class, "CTL_CommitForm_FilesToCommit")); 130 filesPanel.setPreferredSize(new java.awt.Dimension (240, 108)); 131 132 org.jdesktop.layout.GroupLayout filesPanelLayout = new org.jdesktop.layout.GroupLayout(filesPanel); 133 filesPanel.setLayout(filesPanelLayout); 134 filesPanelLayout.setHorizontalGroup( 135 filesPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 136 .add(0, 630, Short.MAX_VALUE) 137 ); 138 filesPanelLayout.setVerticalGroup( 139 filesPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 140 .add(0, 187, Short.MAX_VALUE) 141 ); 142 143 recentLink.setIcon(new javax.swing.ImageIcon (getClass().getResource("/org/netbeans/modules/subversion/resources/icons/recent_messages.png"))); 144 recentLink.setToolTipText(org.openide.util.NbBundle.getMessage(CommitPanel.class, "CTL_CommitForm_RecentMessages")); 146 org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this); 147 this.setLayout(layout); 148 layout.setHorizontalGroup( 149 layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 150 .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup() 151 .addContainerGap() 152 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING) 153 .add(org.jdesktop.layout.GroupLayout.LEADING, filesPanel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 630, Short.MAX_VALUE) 154 .add(org.jdesktop.layout.GroupLayout.LEADING, jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 630, Short.MAX_VALUE) 155 .add(org.jdesktop.layout.GroupLayout.LEADING, layout.createSequentialGroup() 156 .add(jLabel1) 157 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 530, Short.MAX_VALUE) 158 .add(recentLink)) 159 .add(org.jdesktop.layout.GroupLayout.LEADING, filesLabel) 160 .add(org.jdesktop.layout.GroupLayout.LEADING, jLabel2)) 161 .addContainerGap()) 162 ); 163 layout.setVerticalGroup( 164 layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 165 .add(layout.createSequentialGroup() 166 .addContainerGap() 167 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) 168 .add(jLabel1) 169 .add(recentLink)) 170 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 171 .add(jScrollPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) 172 .add(15, 15, 15) 173 .add(filesLabel) 174 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 175 .add(filesPanel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 187, Short.MAX_VALUE) 176 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 177 .add(jLabel2) 178 .addContainerGap()) 179 ); 180 } 182 ListenersSupport listenerSupport = new ListenersSupport(this); 183 public void addVersioningListener(VersioningListener listener) { 184 listenerSupport.addListener(listener); 185 } 186 187 public void removeVersioningListener(VersioningListener listener) { 188 listenerSupport.removeListener(listener); 189 } 190 191 final javax.swing.JLabel filesLabel = new javax.swing.JLabel (); 193 final javax.swing.JPanel filesPanel = new javax.swing.JPanel (); 194 final javax.swing.JLabel jLabel1 = new javax.swing.JLabel (); 195 final javax.swing.JLabel jLabel2 = new javax.swing.JLabel (); 196 final javax.swing.JScrollPane jScrollPane1 = new javax.swing.JScrollPane (); 197 final javax.swing.JTextArea messageTextArea = new javax.swing.JTextArea (); 198 final javax.swing.JLabel recentLink = new javax.swing.JLabel (); 199 201 } 202 | Popular Tags |