PageRenderTime 82ms CodeModel.GetById 64ms app.highlight 16ms RepoModel.GetById 1ms app.codeStats 0ms

/jEdit/tags/jedit-4-2-pre4/org/gjt/sp/jedit/gui/FilesChangedDialog.java

#
Java | 221 lines | 153 code | 31 blank | 37 comment | 15 complexity | 473d44ac845e6dc99d610a4ce92e85c2 MD5 | raw file
  1/*
  2 * FilesChangedDialog.java - Files changed on disk
  3 * :tabSize=8:indentSize=8:noTabs=false:
  4 * :folding=explicit:collapseFolds=1:
  5 *
  6 * Copyright (C) 2003 Slava Pestov
  7 *
  8 * This program is free software; you can redistribute it and/or
  9 * modify it under the terms of the GNU General Public License
 10 * as published by the Free Software Foundation; either version 2
 11 * of the License, or any later version.
 12 *
 13 * This program is distributed in the hope that it will be useful,
 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 16 * GNU General Public License for more details.
 17 *
 18 * You should have received a copy of the GNU General Public License
 19 * along with this program; if not, write to the Free Software
 20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 21 */
 22
 23package org.gjt.sp.jedit.gui;
 24
 25//{{{ Imports
 26import javax.swing.border.*;
 27import javax.swing.event.*;
 28import javax.swing.tree.*;
 29import javax.swing.*;
 30import java.awt.event.*;
 31import java.awt.*;
 32import org.gjt.sp.jedit.io.*;
 33import org.gjt.sp.jedit.*;
 34//}}}
 35
 36/**
 37 * Files changed on disk dialog.
 38 *
 39 * @author Slava Pestov
 40 * @version $Id: FilesChangedDialog.java 4755 2003-06-03 22:02:40Z spestov $
 41 */
 42public class FilesChangedDialog extends EnhancedDialog
 43{
 44	//{{{ FilesChangedDialog constructor
 45	public FilesChangedDialog(View view, int[] states)
 46	{
 47		super(view,jEdit.getProperty("files-changed.title"),false);
 48
 49		this.view = view;
 50
 51		JPanel content = new JPanel(new BorderLayout(12,12));
 52		content.setBorder(new EmptyBorder(12,12,12,12));
 53		setContentPane(content);
 54
 55		Box iconBox = new Box(BoxLayout.Y_AXIS);
 56		iconBox.add(new JLabel(UIManager.getIcon("OptionPane.warningIcon")));
 57		iconBox.add(Box.createGlue());
 58		content.add(BorderLayout.WEST,iconBox);
 59
 60		JPanel centerPanel = new JPanel(new BorderLayout());
 61
 62		JLabel label = new JLabel(jEdit.getProperty("files-changed.caption"));
 63		label.setBorder(new EmptyBorder(0,0,6,0));
 64		centerPanel.add(BorderLayout.NORTH,label);
 65
 66		DefaultMutableTreeNode deleted = new DefaultMutableTreeNode(
 67			jEdit.getProperty("files-changed.deleted"),true);
 68		DefaultMutableTreeNode changed = new DefaultMutableTreeNode(
 69			jEdit.getProperty("files-changed.changed"),true);
 70		DefaultMutableTreeNode changedDirty = new DefaultMutableTreeNode(
 71			jEdit.getProperty("files-changed.changed-dirty"),true);
 72		Buffer[] buffers = jEdit.getBuffers();
 73		for(int i = 0; i < states.length; i++)
 74		{
 75			Buffer buffer = buffers[i];
 76			DefaultMutableTreeNode addTo;
 77			switch(states[i])
 78			{
 79			case Buffer.FILE_DELETED:
 80				addTo = deleted;
 81				break;
 82			case Buffer.FILE_CHANGED:
 83				addTo = (buffer.isDirty() ? changedDirty : changed);
 84				break;
 85			default:
 86				addTo = null;
 87				break;
 88			}
 89
 90			if(addTo != null)
 91				addTo.add(new DefaultMutableTreeNode(buffer));
 92		}
 93
 94		DefaultMutableTreeNode root = new DefaultMutableTreeNode("",true);
 95		if(deleted.getChildCount() != 0)
 96			root.add(deleted);
 97		if(changed.getChildCount() != 0)
 98			root.add(changed);
 99		if(changedDirty.getChildCount() != 0)
100			root.add(changedDirty);
101
102		bufferTree = new JTree(new DefaultTreeModel(root));
103		bufferTree.setRootVisible(false);
104		bufferTree.setVisibleRowCount(10);
105		bufferTree.setCellRenderer(new Renderer());
106		bufferTree.getSelectionModel().addTreeSelectionListener(new TreeHandler());
107		bufferTree.getSelectionModel().setSelectionMode(
108			ListSelectionModel.SINGLE_SELECTION);
109
110		centerPanel.add(BorderLayout.CENTER,new JScrollPane(bufferTree));
111
112		content.add(BorderLayout.CENTER,centerPanel);
113
114		Box buttons = new Box(BoxLayout.X_AXIS);
115		buttons.add(Box.createGlue());
116		JButton close = new JButton(jEdit.getProperty("common.close"));
117		getRootPane().setDefaultButton(close);
118		buttons.add(close);
119		close.addActionListener(new ActionHandler());
120		buttons.add(Box.createGlue());
121
122		content.add(BorderLayout.SOUTH,buttons);
123
124		bufferTree.expandPath(new TreePath(
125			new Object[] {
126				root,
127				deleted
128			}));
129		bufferTree.expandPath(new TreePath(
130			new Object[] {
131				root,
132				changed
133			}));
134		bufferTree.expandPath(new TreePath(
135			new Object[] {
136				root,
137				changedDirty
138			}));
139
140		GUIUtilities.requestFocus(this,bufferTree);
141
142		pack();
143		setLocationRelativeTo(view);
144		show();
145	} //}}}
146
147	//{{{ ok() method
148	public void ok()
149	{
150		dispose();
151	} //}}}
152
153	//{{{ cancel() method
154	public void cancel()
155	{
156		dispose();
157	} //}}}
158
159	//{{{ Private members
160	private View view;
161	private JTree bufferTree;
162	//}}}
163
164	//{{{ ActionHandler class
165	class ActionHandler implements ActionListener
166	{
167		public void actionPerformed(ActionEvent evt)
168		{
169			dispose();
170		}
171	} //}}}
172
173	//{{{ TreeHandler class
174	class TreeHandler implements TreeSelectionListener
175	{
176		public void valueChanged(TreeSelectionEvent evt)
177		{
178			TreePath path = bufferTree.getSelectionPath();
179			if(path != null)
180			{
181				DefaultMutableTreeNode node = (DefaultMutableTreeNode)path.getLastPathComponent();
182				if(node.getUserObject() instanceof Buffer)
183					view.goToBuffer((Buffer)node.getUserObject());
184			}
185		}
186	} //}}}
187
188	//{{{ Renderer class
189	class Renderer extends DefaultTreeCellRenderer
190	{
191		public Renderer()
192		{
193			entryFont = UIManager.getFont("Tree.font");
194			if(entryFont == null)
195				entryFont = jEdit.getFontProperty("metal.secondary.font");
196			groupFont = entryFont.deriveFont(Font.BOLD);
197		}
198
199		public Component getTreeCellRendererComponent(JTree tree,
200			Object value, boolean selected, boolean expanded,
201			boolean leaf, int row, boolean hasFocus)
202		{
203			super.getTreeCellRendererComponent(tree,value,
204				selected,expanded,leaf,row,hasFocus);
205
206			DefaultMutableTreeNode node = (DefaultMutableTreeNode)value;
207
208			if (node.getUserObject() instanceof String)
209				this.setFont(groupFont);
210			else
211				this.setFont(entryFont);
212
213			setIcon(null);
214
215			return this;
216		}
217
218		private Font entryFont;
219		private Font groupFont;
220	} //}}}
221}