KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > versioning > system > cvss > ui > syncview > SynchronizePanel


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.versioning.system.cvss.ui.syncview;
21
22 import java.util.prefs.PreferenceChangeEvent JavaDoc;
23 import org.netbeans.modules.versioning.system.cvss.*;
24 import org.netbeans.modules.versioning.system.cvss.util.Context;
25 import org.netbeans.modules.versioning.system.cvss.CvsModuleConfig;
26 import org.netbeans.modules.versioning.system.cvss.ui.actions.update.UpdateExecutor;
27 import org.netbeans.modules.versioning.system.cvss.ui.actions.commit.CommitAction;
28 import org.netbeans.modules.versioning.system.cvss.ui.actions.diff.DiffExecutor;
29 import org.netbeans.modules.versioning.util.VersioningListener;
30 import org.netbeans.modules.versioning.util.VersioningEvent;
31 import org.netbeans.modules.versioning.util.NoContentPanel;
32 import org.netbeans.lib.cvsclient.command.update.UpdateCommand;
33 import org.netbeans.lib.cvsclient.command.GlobalOptions;
34 import org.netbeans.api.progress.ProgressHandle;
35 import org.netbeans.api.progress.ProgressHandleFactory;
36 import org.openide.explorer.ExplorerManager;
37 import org.openide.nodes.*;
38 import org.openide.windows.TopComponent;
39 import org.openide.util.RequestProcessor;
40 import org.openide.util.NbBundle;
41 import org.openide.LifecycleManager;
42
43 import javax.swing.*;
44 import javax.swing.border.CompoundBorder JavaDoc;
45 import java.awt.*;
46 import java.awt.image.BufferedImage JavaDoc;
47 import java.awt.event.*;
48 import java.util.*;
49 import java.beans.PropertyChangeEvent JavaDoc;
50 import java.beans.PropertyChangeListener JavaDoc;
51 import java.io.File JavaDoc;
52 import java.util.prefs.PreferenceChangeListener JavaDoc;
53
54 /**
55  * The main class of the Synchronize view, shows and acts on set of file roots.
56  *
57  * @author Maros Sandor
58  */

59 class SynchronizePanel extends JPanel implements ExplorerManager.Provider, PropertyChangeListener JavaDoc, PreferenceChangeListener JavaDoc, VersioningListener, ActionListener {
60     
61     private ExplorerManager explorerManager;
62     private final CvsSynchronizeTopComponent parentTopComponent;
63     private final CvsVersioningSystem cvs;
64     private Context context;
65     private int displayStatuses;
66     private boolean pendingRefresh;
67     
68     private SyncTable syncTable;
69     private RequestProcessor.Task refreshViewTask;
70     private Thread JavaDoc refreshViewThread;
71     private ExecutorGroup refreshCommandGroup;
72
73     private static final RequestProcessor rp = new RequestProcessor("CVS-VersioningView", 1); // NOI18N
74

75     private final NoContentPanel noContentComponent = new NoContentPanel();
76
77     /**
78      * Creates a new Synchronize Panel managed by the given versioning system.
79      *
80      * @param parent enclosing top component
81      */

82     public SynchronizePanel(CvsSynchronizeTopComponent parent) {
83         this.parentTopComponent = parent;
84         this.cvs = CvsVersioningSystem.getInstance();
85         refreshViewTask = rp.create(new RefreshViewTask());
86         explorerManager = new ExplorerManager ();
87         displayStatuses = FileInformation.STATUS_REMOTE_CHANGE | FileInformation.STATUS_LOCAL_CHANGE;
88         noContentComponent.setLabel(NbBundle.getMessage(SynchronizePanel.class, "MSG_No_Changes_All"));
89         syncTable = new SyncTable();
90
91         initComponents();
92         setComponentsState();
93         setVersioningComponent(syncTable.getComponent());
94         reScheduleRefresh(0);
95
96         // XXX click it in form editor
97
jPanel2.setFloatable(false);
98         jPanel2.putClientProperty("JToolBar.isRollover", Boolean.TRUE); // NOI18N
99
jPanel2.setLayout(new ToolbarLayout());
100
101         parent.getInputMap(WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, InputEvent.SHIFT_MASK | InputEvent.ALT_MASK), "prevInnerView"); // NOI18N
102
parent.getInputMap(WHEN_FOCUSED).put(KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, InputEvent.SHIFT_MASK | InputEvent.ALT_MASK), "prevInnerView"); // NOI18N
103
parent.getInputMap(WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, InputEvent.SHIFT_MASK | InputEvent.ALT_MASK), "nextInnerView"); // NOI18N
104
parent.getInputMap(WHEN_FOCUSED).put(KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, InputEvent.SHIFT_MASK | InputEvent.ALT_MASK), "nextInnerView"); // NOI18N
105

106         getActionMap().put("prevInnerView", new AbstractAction("") { // NOI18N
107
public void actionPerformed(ActionEvent e) {
108                 onNextInnerView();
109             }
110         });
111         getActionMap().put("nextInnerView", new AbstractAction("") { // NOI18N
112
public void actionPerformed(ActionEvent e) {
113                 onPrevInnerView();
114             }
115         });
116     }
117
118     private void onPrevInnerView() {
119         if (tgbLocal.isSelected()) {
120             tgbRemote.setSelected(true);
121         } else if (tgbRemote.isSelected()) {
122             tgbAll.setSelected(true);
123         } else {
124             tgbLocal.setSelected(true);
125         }
126         onDisplayedStatusChanged();
127     }
128
129     private void onNextInnerView() {
130         if (tgbLocal.isSelected()) {
131             tgbAll.setSelected(true);
132         } else if (tgbRemote.isSelected()) {
133             tgbLocal.setSelected(true);
134         } else {
135             tgbRemote.setSelected(true);
136         }
137         onDisplayedStatusChanged();
138     }
139     
140     public void preferenceChange(PreferenceChangeEvent JavaDoc evt) {
141         if (evt.getKey().startsWith(CvsModuleConfig.PROP_COMMIT_EXCLUSIONS)) {
142             repaint();
143         }
144     }
145     
146     public void propertyChange(PropertyChangeEvent JavaDoc evt) {
147         if (ExplorerManager.PROP_SELECTED_NODES.equals(evt.getPropertyName())) {
148             TopComponent tc = (TopComponent) SwingUtilities.getAncestorOfClass(TopComponent.class, this);
149             if (tc == null) return;
150             tc.setActivatedNodes((Node[]) evt.getNewValue());
151         }
152     }
153
154     CvsVersioningSystem getCvs() {
155         return cvs;
156     }
157
158     /**
159      * Sets roots (directories) to display in the view.
160      *
161      * @param ctx new context if the Versioning panel
162      */

163     void setContext(Context ctx) {
164         context = ctx;
165         reScheduleRefresh(0);
166     }
167     
168     public ExplorerManager getExplorerManager () {
169         return explorerManager;
170     }
171     
172     public void addNotify() {
173         super.addNotify();
174         CvsModuleConfig.getDefault().getPreferences().addPreferenceChangeListener(this);
175         cvs.getStatusCache().addVersioningListener(this);
176         cvs.addVersioningListener(this);
177         explorerManager.addPropertyChangeListener(this);
178         reScheduleRefresh(0); // the view does not listen for changes when it is not visible
179
}
180
181     public void removeNotify() {
182         CvsModuleConfig.getDefault().getPreferences().removePreferenceChangeListener(this);
183         cvs.getStatusCache().removeVersioningListener(this);
184         cvs.removeVersioningListener(this);
185         explorerManager.removePropertyChangeListener(this);
186         super.removeNotify();
187     }
188     
189     private void setVersioningComponent(JComponent component) {
190         Component [] children = getComponents();
191         for (int i = 0; i < children.length; i++) {
192             Component child = children[i];
193             if (child != jPanel2) {
194                 if (child == component) {
195                     return;
196                 } else {
197                     remove(child);
198                     break;
199                 }
200             }
201         }
202         GridBagConstraints gbc = new GridBagConstraints();
203         gbc.gridx = 0; gbc.gridy = 2; gbc.gridwidth = GridBagConstraints.REMAINDER; gbc.gridheight = 1;
204         gbc.anchor = GridBagConstraints.FIRST_LINE_START; gbc.fill = GridBagConstraints.BOTH;
205         gbc.weightx = 1; gbc.weighty = 1;
206         
207         add(component, gbc);
208         revalidate();
209         repaint();
210     }
211     
212     private void setComponentsState() {
213         ButtonGroup grp = new ButtonGroup();
214         grp.add(tgbLocal);
215         grp.add(tgbRemote);
216         grp.add(tgbAll);
217         if (displayStatuses == FileInformation.STATUS_LOCAL_CHANGE) {
218             tgbLocal.setSelected(true);
219         }
220         else if (displayStatuses == FileInformation.STATUS_REMOTE_CHANGE) {
221             tgbRemote.setSelected(true);
222         }
223         else {
224             tgbAll.setSelected(true);
225         }
226     }
227
228     /**
229      * Must NOT be run from AWT.
230      */

231     private void setupModels() {
232         if (context == null) {
233             SwingUtilities.invokeLater(new Runnable JavaDoc() {
234                 public void run() {
235                     syncTable.setTableModel(new SyncFileNode[0]);
236                 }
237             });
238             return;
239         }
240         final ProgressHandle ph = ProgressHandleFactory.createHandle(NbBundle.getMessage(SynchronizePanel.class, "MSG_Refreshing_Versioning_View"));
241         try {
242             refreshViewThread = Thread.currentThread();
243             refreshViewThread.interrupted(); // clear interupted status
244
ph.start(); // XXX created handle does not have set Cancelable hook
245
final SyncFileNode [] nodes = getNodes(cvs.getFileTableModel(context, displayStatuses)); // takes long
246
if (nodes == null) {
247                 return;
248                 // finally section
249
}
250
251             final String JavaDoc [] tableColumns;
252             final String JavaDoc branchTitle;
253             if (nodes.length > 0) {
254                 boolean stickyCommon = true;
255                 String JavaDoc currentSticky = nodes[0].getSticky();
256                 for (int i = 1; i < nodes.length; i++) {
257                     if (Thread.interrupted()) {
258                         // TODO fast clean model
259
return;
260                     }
261                     String JavaDoc sticky = nodes[i].getSticky();
262                     if (sticky != currentSticky && (sticky == null || currentSticky == null || !sticky.equals(currentSticky))) {
263                         stickyCommon = false;
264                         break;
265                     }
266                 }
267                 if (stickyCommon) {
268                     tableColumns = new String JavaDoc [] { SyncFileNode.COLUMN_NAME_NAME, SyncFileNode.COLUMN_NAME_STATUS, SyncFileNode.COLUMN_NAME_PATH };
269                     branchTitle = currentSticky.length() == 0 ? null : NbBundle.getMessage(SynchronizePanel.class, "CTL_VersioningView_BranchTitle_Single", currentSticky);
270                 } else {
271                     tableColumns = new String JavaDoc [] { SyncFileNode.COLUMN_NAME_NAME, SyncFileNode.COLUMN_NAME_STICKY, SyncFileNode.COLUMN_NAME_STATUS, SyncFileNode.COLUMN_NAME_PATH };
272                     branchTitle = NbBundle.getMessage(SynchronizePanel.class, "CTL_VersioningView_BranchTitle_Multi");
273                 }
274             } else {
275                 tableColumns = null;
276                 branchTitle = null;
277             }
278
279             SwingUtilities.invokeLater(new Runnable JavaDoc() {
280                 public void run() {
281                     if (nodes.length > 0) {
282                         syncTable.setColumns(tableColumns);
283                         parentTopComponent.setBranchTitle(branchTitle);
284                         setVersioningComponent(syncTable.getComponent());
285                     } else {
286                         setVersioningComponent(noContentComponent);
287                     }
288                     syncTable.setTableModel(nodes);
289                     // finally section, it's enqueued after this request
290
}
291             });
292         } finally {
293             SwingUtilities.invokeLater(new Runnable JavaDoc() {
294                 public void run() {
295                     ph.finish();
296                     refreshViewThread = null;
297                 }
298             });
299         }
300     }
301     
302     private SyncFileNode [] getNodes(CvsFileTableModel model) {
303         CvsFileNode [] fnodes = model.getNodes();
304         SyncFileNode [] nodes = new SyncFileNode[fnodes.length];
305         for (int i = 0; i < fnodes.length; i++) {
306             if (Thread.interrupted()) return null;
307             CvsFileNode fnode = fnodes[i];
308             nodes[i] = new SyncFileNode(fnode);
309         }
310         return nodes;
311     }
312     
313     /**
314      * Performs the "cvs commit" command on all diplayed roots plus "cvs add" for files that are not yet added.
315      */

316     private void onCommitAction() {
317         LifecycleManager.getDefault().saveAll();
318         CommitAction.invokeCommit(parentTopComponent.getContentTitle(), context, null);
319     }
320     
321     /**
322      * Performs the "cvs update" command on all diplayed roots.
323      */

324     private void onUpdateAction() {
325         executeUpdateCommand(false);
326     }
327     
328     /**
329      * Refreshes statuses of all files in the view. It does that by issuing the "cvs -n update" command, updating the cache
330      * and refreshing file nodes.
331      */

332     private void onRefreshAction() {
333         LifecycleManager.getDefault().saveAll();
334         refreshStatuses();
335     }
336
337     /**
338      * Programmatically invokes the Refresh action.
339      */

340     void performRefreshAction() {
341         refreshStatuses();
342     }
343
344     private void refreshStatuses() {
345         executeUpdateCommand(true);
346         reScheduleRefresh(1000);
347     }
348
349     /**
350      * Shows Diff panel for all files in the view. The initial type of diff depends on the sync mode: Local, Remote, All.
351      * In Local mode, the diff shows CURRENT <-> BASE differences. In Remote mode, it shows BASE<->HEAD differences.
352      */

353     private void onDiffAction() {
354         ExecutorGroup group = new ExecutorGroup(NbBundle.getMessage(SynchronizePanel.class, "BK0003"));
355         group.progress(NbBundle.getMessage(SynchronizePanel.class, "BK0004"));
356         DiffExecutor exec = new DiffExecutor(context, parentTopComponent.getContentTitle());
357         if (displayStatuses == FileInformation.STATUS_LOCAL_CHANGE) {
358             LifecycleManager.getDefault().saveAll();
359             exec.showLocalDiff(group);
360         } else if (displayStatuses == FileInformation.STATUS_REMOTE_CHANGE) {
361             exec.showRemoteDiff(group);
362         } else {
363             LifecycleManager.getDefault().saveAll();
364             exec.showAllDiff(group);
365         }
366     }
367     
368     private void executeUpdateCommand(boolean doNoChanges) {
369         if (context == null || context.getRootFiles().length == 0) return;
370         UpdateCommand cmd = new UpdateCommand();
371         String JavaDoc msg;
372         if (doNoChanges) {
373             msg = NbBundle.getMessage(SynchronizePanel.class, "BK0001");
374         } else {
375             msg = NbBundle.getMessage(SynchronizePanel.class, "BK0002");
376         }
377         cmd.setDisplayName(msg);
378         GlobalOptions options = CvsVersioningSystem.createGlobalOptions();
379         if (context.getExclusions().size() > 0) {
380             options.setExclusions((File JavaDoc[]) context.getExclusions().toArray(new File JavaDoc[context.getExclusions().size()]));
381         }
382         cmd.setFiles(context.getRootFiles());
383         cmd.setBuildDirectories(true);
384         cmd.setPruneDirectories(true);
385         options.setDoNoChanges(doNoChanges);
386         // TODO: javacvs library fails to obey the -P flag when -q is specified
387
// options.setModeratelyQuiet(true);
388
refreshCommandGroup = new ExecutorGroup(msg);
389         refreshCommandGroup.addExecutors(UpdateExecutor.splitCommand(cmd, cvs, options, parentTopComponent.getContentTitle()));
390         refreshCommandGroup.execute();
391         // XXX should not be there barrier?
392
parentTopComponent.contentRefreshed();
393     }
394
395     private void onDisplayedStatusChanged() {
396         if (tgbLocal.isSelected()) {
397             setDisplayStatuses(FileInformation.STATUS_LOCAL_CHANGE);
398             noContentComponent.setLabel(NbBundle.getMessage(SynchronizePanel.class, "MSG_No_Changes_Local"));
399         }
400         else if (tgbRemote.isSelected()) {
401             setDisplayStatuses(FileInformation.STATUS_REMOTE_CHANGE);
402             noContentComponent.setLabel(NbBundle.getMessage(SynchronizePanel.class, "MSG_No_Changes_Remote"));
403         }
404         else if (tgbAll.isSelected()) {
405             setDisplayStatuses(FileInformation.STATUS_REMOTE_CHANGE | FileInformation.STATUS_LOCAL_CHANGE);
406             noContentComponent.setLabel(NbBundle.getMessage(SynchronizePanel.class, "MSG_No_Changes_All"));
407         }
408     }
409
410     private void setDisplayStatuses(int displayStatuses) {
411         this.displayStatuses = displayStatuses;
412         reScheduleRefresh(0);
413     }
414
415     public void versioningEvent(VersioningEvent event) {
416         if (event.getId() == FileStatusCache.EVENT_FILE_STATUS_CHANGED) {
417             if (!affectsView(event)) return;
418             if (cvs.getParameter(CvsVersioningSystem.PARAM_BATCH_REFRESH_RUNNING) != null) {
419                 reScheduleRefresh(1000);
420             } else {
421                 reScheduleRefresh(200);
422             }
423         } else if (event.getId() == CvsVersioningSystem.EVENT_PARAM_CHANGED) {
424             if (pendingRefresh && event.getParams()[0].equals(CvsVersioningSystem.PARAM_BATCH_REFRESH_RUNNING)) {
425                 if (cvs.getParameter(CvsVersioningSystem.PARAM_BATCH_REFRESH_RUNNING) == null) {
426                     pendingRefresh = false;
427                     reScheduleRefresh(0);
428                 }
429             }
430         }
431     }
432
433     private boolean affectsView(VersioningEvent event) {
434         File JavaDoc file = (File JavaDoc) event.getParams()[0];
435         FileInformation oldInfo = (FileInformation) event.getParams()[1];
436         FileInformation newInfo = (FileInformation) event.getParams()[2];
437         if (oldInfo == null) {
438             if ((newInfo.getStatus() & displayStatuses) == 0) return false;
439         } else {
440             if ((oldInfo.getStatus() & displayStatuses) + (newInfo.getStatus() & displayStatuses) == 0) return false;
441         }
442         if (context != null) {
443             return context.contains(file);
444         } else {
445             return false;
446         }
447     }
448
449     /** Reloads data from cache */
450     private void reScheduleRefresh(int delayMillis) {
451         refreshViewTask.schedule(delayMillis);
452     }
453
454     // TODO: HACK, replace by save/restore of column width/position
455
void deserialize() {
456         if (syncTable != null) {
457             SwingUtilities.invokeLater(new Runnable JavaDoc() {
458                 public void run() {
459                     syncTable.setDefaultColumnSizes();
460                 }
461             });
462         }
463     }
464
465     void focus() {
466         syncTable.focus();
467     }
468
469     /**
470      * Cancels both:
471      * <ul>
472      * <li>cache data fetching
473      * <li>background cvs -N update
474      * </ul>
475      */

476     public void cancelRefresh() {
477         if (refreshCommandGroup != null) {
478             refreshCommandGroup.cancel();
479         }
480         refreshViewTask.cancel();
481         if (refreshViewThread != null) {
482             refreshViewThread.interrupt();
483         }
484     }
485
486     private class RefreshViewTask implements Runnable JavaDoc {
487         public void run() {
488             setupModels();
489         }
490     }
491
492     /**
493      * Hardcoded toolbar layout. It eliminates need
494      * for nested panels their look is hardly maintanable
495      * accross several look and feels
496      * (e.g. strange layouting panel borders on GTK+).
497      *
498      * <p>It sets authoritatively component height and takes
499      * "prefered" width from components itself.
500      *
501      */

502     private class ToolbarLayout implements LayoutManager {
503
504         /** Expected border height */
505         private int TOOLBAR_HEIGHT_ADJUSTMENT = 4;
506
507         private int TOOLBAR_SEPARATOR_MIN_WIDTH = 12;
508
509         /** Cached toolbar height */
510         private int toolbarHeight = -1;
511
512         /** Guard for above cache. */
513         private Dimension parentSize;
514
515         private Set adjusted = new HashSet();
516
517         public void removeLayoutComponent(Component comp) {
518         }
519
520         public void layoutContainer(Container parent) {
521             Dimension dim = SynchronizePanel.this.getSize();
522             Dimension max = parent.getSize();
523
524             int reminder = max.width - minimumLayoutSize(parent).width;
525
526             int components = parent.getComponentCount();
527             int horizont = 0;
528             for (int i = 0; i<components; i++) {
529                 JComponent comp = (JComponent) parent.getComponent(i);
530                 if (comp.isVisible() == false) continue;
531                 comp.setLocation(horizont, 0);
532                 Dimension pref = comp.getPreferredSize();
533                 int width = pref.width;
534                 if (comp instanceof JSeparator && ((dim.height - dim.width) <= 0)) {
535                     width = Math.max(width, TOOLBAR_SEPARATOR_MIN_WIDTH);
536                 }
537                 if (comp instanceof JProgressBar && reminder > 0) {
538                     width += reminder;
539                 }
540 // if (comp == getMiniStatus()) {
541
// width = reminder;
542
// }
543

544                 // in column layout use taller toolbar
545
int height = getToolbarHeight(dim) -1;
546                 comp.setSize(width, height); // 1 verySoftBevel compensation
547
horizont += width;
548             }
549         }
550
551         public void addLayoutComponent(String JavaDoc name, Component comp) {
552         }
553
554         public Dimension minimumLayoutSize(Container parent) {
555
556             // in column layout use taller toolbar
557
Dimension dim = SynchronizePanel.this.getSize();
558             int height = getToolbarHeight(dim);
559
560             int components = parent.getComponentCount();
561             int horizont = 0;
562             for (int i = 0; i<components; i++) {
563                 Component comp = parent.getComponent(i);
564                 if (comp.isVisible() == false) continue;
565                 if (comp instanceof AbstractButton) {
566                     adjustToobarButton((AbstractButton)comp);
567                 } else {
568                     adjustToolbarComponentSize((JComponent)comp);
569                 }
570                 Dimension pref = comp.getPreferredSize();
571                 int width = pref.width;
572                 if (comp instanceof JSeparator && ((dim.height - dim.width) <= 0)) {
573                     width = Math.max(width, TOOLBAR_SEPARATOR_MIN_WIDTH);
574                 }
575                 horizont += width;
576             }
577
578             return new Dimension(horizont, height);
579         }
580
581         public Dimension preferredLayoutSize(Container parent) {
582             // Eliminates double height toolbar problem
583
Dimension dim = SynchronizePanel.this.getSize();
584             int height = getToolbarHeight(dim);
585
586             return new Dimension(Integer.MAX_VALUE, height);
587         }
588
589         /**
590          * Computes vertical toolbar components height that can used for layout manager hinting.
591          * @return size based on font size and expected border.
592          */

593         private int getToolbarHeight(Dimension parent) {
594
595             if (parentSize == null || (parentSize.equals(parent) == false)) {
596                 parentSize = parent;
597                 toolbarHeight = -1;
598             }
599
600             if (toolbarHeight == -1) {
601                 BufferedImage JavaDoc image = new BufferedImage JavaDoc(1,1,BufferedImage.TYPE_BYTE_GRAY);
602                 Graphics2D g = image.createGraphics();
603                 UIDefaults def = UIManager.getLookAndFeelDefaults();
604
605                 int height = 0;
606                 String JavaDoc[] fonts = {"Label.font", "Button.font", "ToggleButton.font"}; // NOI18N
607
for (int i=0; i<fonts.length; i++) {
608                     Font f = def.getFont(fonts[i]);
609                     FontMetrics fm = g.getFontMetrics(f);
610                     height = Math.max(height, fm.getHeight());
611                 }
612                 toolbarHeight = height + TOOLBAR_HEIGHT_ADJUSTMENT;
613                 if ((parent.height - parent.width) > 0) {
614                     toolbarHeight += TOOLBAR_HEIGHT_ADJUSTMENT;
615                 }
616             }
617
618             return toolbarHeight;
619         }
620
621
622         /** Toolbar controls must be smaller and should be transparent*/
623         private void adjustToobarButton(final AbstractButton button) {
624
625             if (adjusted.contains(button)) return;
626
627             // workaround for Ocean L&F clutter - toolbars use gradient.
628
// To make the gradient visible under buttons the content area must not
629
// be filled. To support rollover it must be temporarily filled
630
if (button instanceof JToggleButton == false) {
631                 button.setContentAreaFilled(false);
632                 button.setMargin(new Insets(0, 3, 0, 3));
633                 button.setBorderPainted(false);
634                 button.addMouseListener(new MouseAdapter() {
635                     public void mouseEntered(MouseEvent e) {
636                         button.setContentAreaFilled(true);
637                         button.setBorderPainted(true);
638                     }
639
640                     public void mouseExited(MouseEvent e) {
641                         button.setContentAreaFilled(false);
642                         button.setBorderPainted(false);
643                     }
644                 });
645             }
646
647             adjustToolbarComponentSize(button);
648         }
649
650         private void adjustToolbarComponentSize(JComponent button) {
651
652             if (adjusted.contains(button)) return;
653
654             // as we cannot get the button small enough using the margin and border...
655
if (button.getBorder() instanceof CompoundBorder JavaDoc) { // from BasicLookAndFeel
656
Dimension pref = button.getPreferredSize();
657
658                 // XXX #41827 workaround w2k, that adds eclipsis (...) instead of actual text
659
if ("Windows".equals(UIManager.getLookAndFeel().getID())) { // NOI18N
660
pref.width += 9;
661                 }
662                 button.setPreferredSize(pref);
663             }
664
665             adjusted.add(button);
666         }
667     }
668
669     /** This method is called from within the constructor to
670      * initialize the form.
671      * WARNING: Do NOT modify this code. The content of this method is
672      * always regenerated by the Form Editor.
673      */

674     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
675
private void initComponents() {
676         java.awt.GridBagConstraints JavaDoc gridBagConstraints;
677
678         jPanel2 = new javax.swing.JToolBar JavaDoc();
679         tgbAll = new javax.swing.JToggleButton JavaDoc();
680         tgbLocal = new javax.swing.JToggleButton JavaDoc();
681         tgbRemote = new javax.swing.JToggleButton JavaDoc();
682         jSeparator1 = new javax.swing.JSeparator JavaDoc();
683         btnRefresh = new javax.swing.JButton JavaDoc();
684         btnDiff = new javax.swing.JButton JavaDoc();
685         jPanel3 = new javax.swing.JPanel JavaDoc();
686         btnUpdate = new javax.swing.JButton JavaDoc();
687         btnCommit = new javax.swing.JButton JavaDoc();
688
689         setLayout(new java.awt.GridBagLayout JavaDoc());
690
691         org.openide.awt.Mnemonics.setLocalizedText(tgbAll, java.util.ResourceBundle.getBundle("org/netbeans/modules/versioning/system/cvss/ui/syncview/Bundle").getString("CTL_Synchronize_Action_All_Label"));
692         tgbAll.setToolTipText(java.util.ResourceBundle.getBundle("org/netbeans/modules/versioning/system/cvss/ui/syncview/Bundle").getString("CTL_Synchronize_Action_All_Tooltip"));
693         tgbAll.addActionListener(this);
694
695         jPanel2.add(tgbAll);
696
697         org.openide.awt.Mnemonics.setLocalizedText(tgbLocal, java.util.ResourceBundle.getBundle("org/netbeans/modules/versioning/system/cvss/ui/syncview/Bundle").getString("CTL_Synchronize_Action_Local_Label"));
698         tgbLocal.setToolTipText(java.util.ResourceBundle.getBundle("org/netbeans/modules/versioning/system/cvss/ui/syncview/Bundle").getString("CTL_Synchronize_Action_Local_Tooltip"));
699         tgbLocal.addActionListener(this);
700
701         jPanel2.add(tgbLocal);
702
703         org.openide.awt.Mnemonics.setLocalizedText(tgbRemote, java.util.ResourceBundle.getBundle("org/netbeans/modules/versioning/system/cvss/ui/syncview/Bundle").getString("CTL_Synchronize_Action_Remote_Label"));
704         tgbRemote.setToolTipText(java.util.ResourceBundle.getBundle("org/netbeans/modules/versioning/system/cvss/ui/syncview/Bundle").getString("CTL_Synchronize_Action_Remote_Tooltip"));
705         tgbRemote.addActionListener(this);
706
707         jPanel2.add(tgbRemote);
708
709         jSeparator1.setOrientation(javax.swing.SwingConstants.VERTICAL);
710         jSeparator1.setPreferredSize(new java.awt.Dimension JavaDoc(2, 20));
711         jPanel2.add(jSeparator1);
712
713         btnRefresh.setIcon(new javax.swing.ImageIcon JavaDoc(getClass().getResource("/org/netbeans/modules/versioning/system/cvss/resources/icons/refresh.png")));
714         btnRefresh.setToolTipText(java.util.ResourceBundle.getBundle("org/netbeans/modules/versioning/system/cvss/ui/syncview/Bundle").getString("CTL_Synchronize_Action_Refresh_Tooltip"));
715         btnRefresh.setActionCommand(java.util.ResourceBundle.getBundle("org/netbeans/modules/versioning/system/cvss/ui/syncview/Bundle").getString("CTL_Synchronize_TopComponent_Title"));
716         btnRefresh.setPreferredSize(new java.awt.Dimension JavaDoc(22, 23));
717         btnRefresh.addActionListener(this);
718
719         jPanel2.add(btnRefresh);
720
721         btnDiff.setIcon(new javax.swing.ImageIcon JavaDoc(getClass().getResource("/org/netbeans/modules/versioning/system/cvss/resources/icons/diff.png")));
722         btnDiff.setToolTipText(java.util.ResourceBundle.getBundle("org/netbeans/modules/versioning/system/cvss/ui/syncview/Bundle").getString("CTL_Synchronize_Action_Diff_Tooltip"));
723         btnDiff.setPreferredSize(new java.awt.Dimension JavaDoc(22, 25));
724         btnDiff.addActionListener(this);
725
726         jPanel2.add(btnDiff);
727
728         jPanel3.setOpaque(false);
729         jPanel2.add(jPanel3);
730
731         btnUpdate.setIcon(new javax.swing.ImageIcon JavaDoc(getClass().getResource("/org/netbeans/modules/versioning/system/cvss/resources/icons/update.png")));
732         btnUpdate.setToolTipText(java.util.ResourceBundle.getBundle("org/netbeans/modules/versioning/system/cvss/ui/syncview/Bundle").getString("CTL_Synchronize_Action_Update_Tooltip"));
733         btnUpdate.setActionCommand(java.util.ResourceBundle.getBundle("org/netbeans/modules/versioning/system/cvss/ui/syncview/Bundle").getString("CTL_Synchronize_TopComponent_Title"));
734         btnUpdate.setPreferredSize(new java.awt.Dimension JavaDoc(22, 25));
735         btnUpdate.addActionListener(this);
736
737         jPanel2.add(btnUpdate);
738
739         btnCommit.setIcon(new javax.swing.ImageIcon JavaDoc(getClass().getResource("/org/netbeans/modules/versioning/system/cvss/resources/icons/commit.png")));
740         btnCommit.setToolTipText(java.util.ResourceBundle.getBundle("org/netbeans/modules/versioning/system/cvss/ui/syncview/Bundle").getString("CTL_CommitForm_Action_Commit_Tooltip"));
741         btnCommit.setPreferredSize(new java.awt.Dimension JavaDoc(22, 25));
742         btnCommit.addActionListener(this);
743
744         jPanel2.add(btnCommit);
745
746         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
747         gridBagConstraints.gridx = 0;
748         gridBagConstraints.gridy = 0;
749         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
750         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
751         gridBagConstraints.anchor = java.awt.GridBagConstraints.FIRST_LINE_START;
752         gridBagConstraints.weightx = 1.0;
753         gridBagConstraints.insets = new java.awt.Insets JavaDoc(3, 0, 3, 0);
754         add(jPanel2, gridBagConstraints);
755
756     }
757
758     // Code for dispatching events from components to event handlers.
759

760     public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
761         if (evt.getSource() == tgbAll) {
762             SynchronizePanel.this.tgbAllActionPerformed(evt);
763         }
764         else if (evt.getSource() == tgbLocal) {
765             SynchronizePanel.this.tgbLocalActionPerformed(evt);
766         }
767         else if (evt.getSource() == tgbRemote) {
768             SynchronizePanel.this.tgbRemoteActionPerformed(evt);
769         }
770         else if (evt.getSource() == btnRefresh) {
771             SynchronizePanel.this.btnRefreshActionPerformed(evt);
772         }
773         else if (evt.getSource() == btnDiff) {
774             SynchronizePanel.this.btnDiffActionPerformed(evt);
775         }
776         else if (evt.getSource() == btnUpdate) {
777             SynchronizePanel.this.btnUpdateActionPerformed(evt);
778         }
779         else if (evt.getSource() == btnCommit) {
780             SynchronizePanel.this.btnCommitActionPerformed(evt);
781         }
782     }
783     // </editor-fold>//GEN-END:initComponents
784

785     private void btnDiffActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_btnDiffActionPerformed
786
onDiffAction();
787     }//GEN-LAST:event_btnDiffActionPerformed
788

789     private void tgbAllActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_tgbAllActionPerformed
790
onDisplayedStatusChanged();
791     }//GEN-LAST:event_tgbAllActionPerformed
792

793     private void btnUpdateActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_btnUpdateActionPerformed
794
onUpdateAction();
795     }//GEN-LAST:event_btnUpdateActionPerformed
796

797     private void tgbRemoteActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_tgbRemoteActionPerformed
798
onDisplayedStatusChanged();
799     }//GEN-LAST:event_tgbRemoteActionPerformed
800

801     private void tgbLocalActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_tgbLocalActionPerformed
802
onDisplayedStatusChanged();
803     }//GEN-LAST:event_tgbLocalActionPerformed
804

805     private void btnCommitActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_btnCommitActionPerformed
806
onCommitAction();
807     }//GEN-LAST:event_btnCommitActionPerformed
808

809     private void btnRefreshActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_btnRefreshActionPerformed
810
onRefreshAction();
811     }//GEN-LAST:event_btnRefreshActionPerformed
812

813     
814     // Variables declaration - do not modify//GEN-BEGIN:variables
815
private javax.swing.JButton JavaDoc btnCommit;
816     private javax.swing.JButton JavaDoc btnDiff;
817     private javax.swing.JButton JavaDoc btnRefresh;
818     private javax.swing.JButton JavaDoc btnUpdate;
819     private javax.swing.JToolBar JavaDoc jPanel2;
820     private javax.swing.JPanel JavaDoc jPanel3;
821     private javax.swing.JSeparator JavaDoc jSeparator1;
822     private javax.swing.JToggleButton JavaDoc tgbAll;
823     private javax.swing.JToggleButton JavaDoc tgbLocal;
824     private javax.swing.JToggleButton JavaDoc tgbRemote;
825     // End of variables declaration//GEN-END:variables
826

827 }
828
Popular Tags