[#75] Remove reference to BrowserTopComponent.settings from layer.xml
[nbgit.git] / src / org / nbgit / ui / browser / BrowserTopComponent.java
blob5e5c4067679437498eda547933cd08ab50f0438c
1 /*
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
4 * Copyright 2009 Jonas Fonseca <fonseca@diku.dk>
6 * The contents of this file are subject to the terms of either the GNU
7 * General Public License Version 2 only ("GPL") or the Common
8 * Development and Distribution License("CDDL") (collectively, the
9 * "License"). You may not use this file except in compliance with the
10 * License. You can obtain a copy of the License at
11 * http://www.netbeans.org/cddl-gplv2.html. See the License for the
12 * specific language governing permissions and limitations under the
13 * License. When distributing the software, include this License Header
14 * Notice in each file.
16 * This particular file is subject to the "Classpath" exception as provided
17 * by Sun in the GPL Version 2 section of the License file that
18 * accompanied this code. If applicable, add the following below the
19 * License Header, with the fields enclosed by brackets [] replaced by
20 * your own identifying information:
21 * "Portions Copyrighted [year] [name of copyright owner]"
23 * Contributor(s):
25 * If you wish your version of this file to be governed by only the CDDL
26 * or only the GPL Version 2, indicate your decision by adding
27 * "[Contributor] elects to include this software in this distribution
28 * under the [CDDL or GPL Version 2] license." If you do not indicate a
29 * single choice of license, a recipient has the option to distribute
30 * your version of this file under either the CDDL, the GPL Version 2 or
31 * to extend the choice of license to its licensees as provided above.
32 * However, if you add GPL Version 2 code and therefore, elected the GPL
33 * Version 2 license, then the option applies only if the new code is
34 * made subject to such option by the copyright holder.
36 package org.nbgit.ui.browser;
38 import javax.swing.ListSelectionModel;
39 import javax.swing.SwingUtilities;
40 import javax.swing.event.DocumentEvent;
41 import javax.swing.event.DocumentListener;
42 import javax.swing.event.ListSelectionEvent;
43 import javax.swing.event.ListSelectionListener;
45 import org.eclipse.jgit.awtui.CommitGraphPane;
46 import org.openide.util.NbBundle;
47 import org.openide.windows.TopComponent;
48 import org.openide.util.ImageUtilities;
50 /**
51 * Repository browser top component.
53 public final class BrowserTopComponent extends TopComponent {
55 private static final String ICON_PATH = "org/nbgit/resources/icons/gitvcs-icon.png"; // NOI18N
56 private static final String PREFERRED_ID = "org-nbgit-ui-browser"; // NOI18N
57 private int commitIndex = -1;
59 public BrowserTopComponent(BrowserModel model) {
60 initComponents();
61 setName(_("CTL_BrowserTopComponent")); // NOI18N
62 setToolTipText(_("HINT_BrowserTopComponent")); // NOI18N
63 setIcon(ImageUtilities.loadImage(ICON_PATH, true));
64 model.setCommitList(commitGraphPane.getCommitList());
65 textArea.setDocument(model.getDocument());
66 model.getDocument().addDocumentListener(new DocumentListener() {
68 public void updateId(DocumentEvent e) {
69 String id = e.getDocument().getProperty(BrowserModel.CONTENT_ID).toString();
70 idField.setText(id);
71 scrollTextToStart();
74 public void insertUpdate(DocumentEvent e) {
75 updateId(e);
78 public void removeUpdate(DocumentEvent e) {
79 updateId(e);
82 public void changedUpdate(DocumentEvent e) {
83 updateId(e);
85 });
86 commitGraphPane.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
88 public void valueChanged(ListSelectionEvent event) {
89 ListSelectionModel listModel = (ListSelectionModel) event.getSource();
90 for (int i = event.getFirstIndex(); i <= event.getLastIndex(); i++) {
91 if (!listModel.isSelectedIndex(i))
92 continue;
93 firePropertyChange(BrowserProperty.COMMIT_INDEX, commitIndex, i);
94 commitIndex = i;
95 break;
99 });
102 private void scrollTextToStart() {
103 SwingUtilities.invokeLater(new Runnable() {
105 public void run() {
106 idField.setCaretPosition(0);
107 textArea.setCaretPosition(0);
113 @Override
114 public int getPersistenceType() {
115 return TopComponent.PERSISTENCE_NEVER;
118 @Override
119 protected String preferredID() {
120 return PREFERRED_ID;
123 private void firePropertyChange(BrowserProperty property, Object oldValue, Object newValue) {
124 super.firePropertyChange(property.name(), oldValue, newValue);
127 private static String _(String id, Object... args) {
128 return NbBundle.getMessage(BrowserTopComponent.class, id, args);
131 /** This method is called from within the constructor to
132 * initialize the form.
133 * WARNING: Do NOT modify this code. The content of this method is
134 * always regenerated by the Form Editor.
136 // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
137 private void initComponents() {
139 browserSplitPane.setDividerLocation(200);
140 browserSplitPane.setOrientation(javax.swing.JSplitPane.VERTICAL_SPLIT);
141 browserSplitPane.setOneTouchExpandable(true);
143 graphScrollPane.setViewportView(commitGraphPane);
145 browserSplitPane.setTopComponent(graphScrollPane);
147 toolBar.setFloatable(false);
148 toolBar.setRollover(true);
149 toolBar.setFocusable(false);
150 toolBar.setRequestFocusEnabled(false);
151 toolBar.setVerifyInputWhenFocusTarget(false);
153 org.openide.awt.Mnemonics.setLocalizedText(idLabel, org.openide.util.NbBundle.getMessage(BrowserTopComponent.class, "BrowserTopComponent.idLabel.text")); // NOI18N
154 toolBar.add(idLabel);
156 idField.setColumns(20);
157 idField.setEditable(false);
158 toolBar.add(idField);
160 textArea.setEditable(false);
161 textScrollPane.setViewportView(textArea);
163 org.jdesktop.layout.GroupLayout textPanelLayout = new org.jdesktop.layout.GroupLayout(textPanel);
164 textPanel.setLayout(textPanelLayout);
165 textPanelLayout.setHorizontalGroup(
166 textPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
167 .add(textScrollPane, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 451, Short.MAX_VALUE)
168 .add(toolBar, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 451, Short.MAX_VALUE)
170 textPanelLayout.setVerticalGroup(
171 textPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
172 .add(textPanelLayout.createSequentialGroup()
173 .add(toolBar, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 25, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
174 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
175 .add(textScrollPane, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 63, Short.MAX_VALUE))
178 browserSplitPane.setRightComponent(textPanel);
180 org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
181 this.setLayout(layout);
182 layout.setHorizontalGroup(
183 layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
184 .add(browserSplitPane, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 451, Short.MAX_VALUE)
186 layout.setVerticalGroup(
187 layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
188 .add(browserSplitPane, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 300, Short.MAX_VALUE)
190 }// </editor-fold>//GEN-END:initComponents
192 // Variables declaration - do not modify//GEN-BEGIN:variables
193 private final javax.swing.JSplitPane browserSplitPane = new javax.swing.JSplitPane();
194 private final CommitGraphPane commitGraphPane = new CommitGraphPane();
195 private final javax.swing.JScrollPane graphScrollPane = new javax.swing.JScrollPane();
196 private final javax.swing.JTextField idField = new javax.swing.JTextField();
197 private final javax.swing.JLabel idLabel = new javax.swing.JLabel();
198 private final javax.swing.JTextArea textArea = new javax.swing.JTextArea();
199 private final javax.swing.JPanel textPanel = new javax.swing.JPanel();
200 private final javax.swing.JScrollPane textScrollPane = new javax.swing.JScrollPane();
201 private final javax.swing.JToolBar toolBar = new javax.swing.JToolBar();
202 // End of variables declaration//GEN-END:variables