0001: /*
0002: * Gruntspud
0003: *
0004: * Copyright (C) 2002 Brett Smith.
0005: *
0006: * Written by: Brett Smith <t_magicthize@users.sourceforge.net>
0007: *
0008: * This program is free software; you can redistribute it and/or
0009: * modify it under the terms of the GNU Library General Public License
0010: * as published by the Free Software Foundation; either version 2 of
0011: * the License, or (at your option) any later version.
0012: * This program is distributed in the hope that it will be useful,
0013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
0014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
0015: * GNU Library General Public License for more details.
0016: *
0017: * You should have received a copy of the GNU Library General Public
0018: * License along with this program; if not, write to the Free Software
0019: * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
0020: */
0021:
0022: package gruntspud.jedit;
0023:
0024: import gruntspud.CVSFileNode;
0025: import gruntspud.CVSSubstType;
0026: import gruntspud.Constants;
0027: import gruntspud.Gruntspud;
0028: import gruntspud.GruntspudContext;
0029: import gruntspud.GruntspudHost;
0030: import gruntspud.style.TextStyle;
0031: import gruntspud.ui.OptionDialog;
0032: import gruntspud.ui.OptionsTab;
0033: import gruntspud.ui.Tabber;
0034: import gruntspud.ui.UIUtil;
0035:
0036: import java.awt.BorderLayout;
0037: import java.awt.Color;
0038: import java.awt.Component;
0039: import java.awt.Container;
0040: import java.awt.Frame;
0041: import java.awt.Insets;
0042: import java.awt.Window;
0043: import java.io.File;
0044: import java.io.IOException;
0045: import java.io.PrintWriter;
0046: import java.io.StringWriter;
0047: import java.lang.reflect.Method;
0048: import java.net.URL;
0049: import java.util.HashMap;
0050: import java.util.Iterator;
0051: import java.util.Properties;
0052:
0053: import javax.swing.Icon;
0054: import javax.swing.JComponent;
0055: import javax.swing.JMenu;
0056: import javax.swing.JPanel;
0057: import javax.swing.JTree;
0058: import javax.swing.SwingUtilities;
0059: import javax.swing.UIManager;
0060: import javax.swing.tree.DefaultTreeCellRenderer;
0061:
0062: import jdiff.DualDiff;
0063:
0064: import org.apache.log4j.BasicConfigurator;
0065: import org.apache.log4j.Level;
0066: import org.apache.log4j.Logger;
0067: import org.gjt.sp.jedit.Buffer;
0068: import org.gjt.sp.jedit.EBComponent;
0069: import org.gjt.sp.jedit.EBMessage;
0070: import org.gjt.sp.jedit.EditPane;
0071: import org.gjt.sp.jedit.GUIUtilities;
0072: import org.gjt.sp.jedit.MiscUtilities;
0073: import org.gjt.sp.jedit.jEdit;
0074: import org.gjt.sp.jedit.help.HelpViewer;
0075: import org.gjt.sp.jedit.io.VFS;
0076: import org.gjt.sp.jedit.io.VFSManager;
0077: import org.gjt.sp.jedit.msg.BufferUpdate;
0078: import org.gjt.sp.jedit.msg.EditorExiting;
0079: import org.gjt.sp.jedit.msg.PropertiesChanged;
0080: import org.gjt.sp.jedit.msg.VFSUpdate;
0081: import org.netbeans.lib.cvsclient.file.FileStatus;
0082:
0083: import com.hexidec.filter.RGBGreyscaleFilter;
0084:
0085: /**
0086: * A CVS front end for jEdit.
0087: *
0088: *@author magicthize
0089: *@created 14 May 2002
0090: */
0091: public class JEditGruntspudHost extends JPanel implements
0092: GruntspudHost, EBComponent {
0093: public final static String AUTO_POPUP_CONSOLE = "gruntspud.jedit.autoPopupConsole";
0094: public final static String MONOCHROME_ICONS = "gruntspud.jedit.monochomeIcons";
0095:
0096: /*
0097: public final static String ERROR_LIST_REPORT_ADD =
0098: "gruntspud.jedit.errorList.reportAdd";
0099: public final static String ERROR_LIST_REPORT_REMOVE =
0100: "gruntspud.jedit.errorList.reportAdd";
0101: public final static String ERROR_LIST_REPORT_PATCHED =
0102: "gruntspud.jedit.errorList.reportPatched";
0103: public final static String ERROR_LIST_REPORT_MODIFIED =
0104: "gruntspud.jedit.errorList.reportPatched";
0105: public final static String ERROR_LIST_REPORT_UNKNOWN =
0106: "gruntspud.jedit.errorList.reportConflicts";
0107: public final static String ERROR_LIST_REPORT_CONFLICTS =
0108: "gruntspud.jedit.errorList.reportConflicts";
0109: public final static String ERROR_LIST_REPORT_UPDATED =
0110: "gruntspud.jedit.errorList.reportUpdated";
0111: public final static String ERROR_LIST_REPORT_EXCEPTIONS =
0112: "gruntspud.jedit.errorList.reportExceptions";
0113: public final static String ERROR_LIST_REPORT_STDERR =
0114: "gruntspud.jedit.errorList.reportStdErr";
0115: public final static String ERROR_LIST_REPORT_CHANGED =
0116: "gruntspud.jedit.errorList.reportChanged";
0117: public final static String ERROR_LIST_REPORT_TAGGED =
0118: "gruntspud.jedit.errorList.reportTagged";
0119: */
0120:
0121: public final static Insets FILE_RENDERER_INSETS = new Insets(1, 0,
0122: 1, 0);
0123: public final static Icon DEFAULT_FOLDER_OPEN_ICON = GUIUtilities
0124: .loadIcon("OpenFolder.png");
0125: public final static Icon DEFAULT_FOLDER_CLOSED_ICON = GUIUtilities
0126: .loadIcon("Folder.png");
0127: public final static Icon DEFAULT_LEAF_ICON = GUIUtilities
0128: .loadIcon("File.png");
0129: public final static Icon DEFAULT_LEAF_OPEN_ICON = GUIUtilities
0130: .loadIcon("OpenFile.png");
0131: public final static Icon DEFAULT_TREE_EXPANDED = GUIUtilities
0132: .loadIcon("arrow2.png");
0133: public final static Icon DEFAULT_TREE_COLLAPSED = GUIUtilities
0134: .loadIcon("arrow1.png");
0135:
0136: private UpdateLock UPDATE_LOCK = new UpdateLock();
0137:
0138: //
0139: private static boolean log4jinitialised;
0140:
0141: //
0142: private org.gjt.sp.jedit.View view;
0143: private Gruntspud gruntspud;
0144: private File tmpDir;
0145: private boolean firstLoadDone;
0146: private Method infoViewerMethod;
0147: private GruntspudContext context;
0148: private String statusLine;
0149: private String infoLine;
0150: private HashMap bwImageCache = new HashMap();
0151:
0152: /**
0153: * Creates a new JEditGruntspudHost object.
0154: *
0155: * @param view DOCUMENT ME!
0156: */
0157: public JEditGruntspudHost(org.gjt.sp.jedit.View view) {
0158: super (new BorderLayout());
0159:
0160: // Look for the InfoViewer plugin to see if it can be used to show HTML
0161: try {
0162: Class c = Class.forName("infoviewer.InfoViewerPlugin");
0163:
0164: if (c != null) {
0165: infoViewerMethod = c.getMethod("openURL", new Class[] {
0166: org.gjt.sp.jedit.View.class, String.class });
0167: }
0168: } catch (Exception e) {
0169: }
0170:
0171: BasicConfigurator.configure();
0172: if (getBooleanProperty(Constants.OPTIONS_SYSTEM_DEBUG, false)) {
0173: Logger.getRootLogger().setLevel(Level.DEBUG);
0174: } else {
0175: Logger.getRootLogger().setLevel(Level.INFO);
0176: }
0177:
0178: if (getBooleanProperty(JEditGruntspudHost.MONOCHROME_ICONS,
0179: true)) {
0180: UIUtil.setImageFilter(new RGBGreyscaleFilter());
0181: }
0182:
0183: //
0184: //
0185: this .view = view;
0186: gruntspud = new Gruntspud(this );
0187: context = gruntspud.getContext();
0188: try {
0189: gruntspud.start();
0190: gruntspud.init();
0191: gruntspud.getContext().getViewManager().reload(null);
0192: add(gruntspud, BorderLayout.CENTER);
0193:
0194: int n = Math.abs(hashCode());
0195:
0196: while (true) {
0197: tmpDir = new File(new File(System
0198: .getProperty("java.io.tmpdir")), "gruntspud_"
0199: + n + "_tmp");
0200:
0201: if (!tmpDir.exists()) {
0202: if (!tmpDir.mkdir()) {
0203: throw new Error(
0204: "Could not create temporary directory");
0205: } else {
0206:
0207: break;
0208: }
0209: } else {
0210: n++;
0211: }
0212: }
0213:
0214: context
0215: .registerOptionsTab(gruntspud.jedit.OtherOptionsTab.class);
0216: tmpDir.deleteOnExit();
0217: } catch (Exception e) {
0218:
0219: }
0220:
0221: }
0222:
0223: public GruntspudContext getContext() {
0224: return context;
0225: }
0226:
0227: public Icon getIcon(String name) {
0228: if (name.equals(Constants.ICON_TOOL_SMALL_DEFAULT_FOLDER_OPEN)) {
0229: return DEFAULT_FOLDER_OPEN_ICON;
0230: } else if (name
0231: .equals(Constants.ICON_TOOL_SMALL_DEFAULT_FOLDER_CLOSED)) {
0232: return DEFAULT_FOLDER_CLOSED_ICON;
0233: } else if (name.equals(Constants.ICON_TOOL_SMALL_DEFAULT_LEAF)) {
0234: return DEFAULT_LEAF_ICON;
0235: } else if (name
0236: .equals(Constants.ICON_TOOL_SMALL_DEFAULT_LEAF_OPEN)) {
0237: return DEFAULT_LEAF_OPEN_ICON;
0238: } else if (name
0239: .equals(Constants.ICON_TOOL_SMALL_DEFAULT_TREE_EXPANDED)) {
0240: return DEFAULT_TREE_EXPANDED;
0241: } else if (name
0242: .equals(Constants.ICON_TOOL_SMALL_DEFAULT_TREE_COLLAPSED)) {
0243: return DEFAULT_TREE_COLLAPSED;
0244: } else {
0245: return UIUtil.getCachedIcon(name);
0246: }
0247: }
0248:
0249: public Insets getFileRendererInsets() {
0250: return FILE_RENDERER_INSETS;
0251: }
0252:
0253: /**
0254: *
0255: */
0256: public TextStyle getNodeStyle(CVSFileNode node) {
0257: FileStatus s = node.getOverallStatus();
0258: TextStyle style = null;
0259: if (s != null) {
0260: style = context.getTextStyleModel().getStyle(
0261: "status." + s.toString());
0262: }
0263: if (style == null) {
0264: if (!node.isLeaf()) {
0265: style = new TextStyle();
0266: style.setBold(true);
0267: } else
0268: style = context.getTextStyleModel().getStyle(
0269: "status.Erased");
0270: }
0271: if (style != null && style.getForeground() == null) {
0272: style = (TextStyle) style.clone();
0273: style.setForeground(VFS.getDefaultColorFor(node
0274: .getCanonicalPath()));
0275: }
0276: return style;
0277: }
0278:
0279: public boolean isNodeOpenedInEditor(CVSFileNode node) {
0280: String canPath = node.getCanonicalPath();
0281: if (canPath != null) {
0282: return jEdit.getBuffer(node.getCanonicalPath()) != null;
0283: }
0284: return false;
0285: }
0286:
0287: /**
0288: * DOCUMENT ME!
0289: */
0290: public void setup() {
0291: }
0292:
0293: /**
0294: *
0295: */
0296: public boolean isExitActionAvailable() {
0297: return false;
0298: }
0299:
0300: /**
0301: * DOCUMENT ME!
0302: *
0303: * @return DOCUMENT ME!
0304: */
0305: public boolean canExit() {
0306: /** @todo prevent exit if command running */
0307: return true;
0308: }
0309:
0310: /**
0311: * DOCUMENT ME!
0312: */
0313: public void exit() {
0314: gruntspud.cleanUp();
0315: }
0316:
0317: /**
0318: * Gets the property attribute of the JEditPlugin object
0319: *
0320: *@param key Description of the Parameter
0321: *@param defaultValue Description of the Parameter
0322: *@return The property value
0323: */
0324: public JComponent getAccessoryComponent() {
0325: return null;
0326: }
0327:
0328: /**
0329: * DOCUMENT ME!
0330: *
0331: * @return DOCUMENT ME!
0332: */
0333: public String getHTMLViewerName() {
0334: return (infoViewerMethod == null) ? null : "Infoviewer plugin";
0335: }
0336:
0337: /**
0338: * View some HTML given a URL.
0339: *
0340: *@param u Description of the Parameter
0341: */
0342: public void viewHTML(URL u) {
0343: try {
0344: infoViewerMethod.invoke(null, new Object[] { view,
0345: u.toExternalForm() });
0346: } catch (Exception e) {
0347: }
0348: }
0349:
0350: /**
0351: * Return the name of the host
0352: */
0353: public String getName() {
0354: return "jEdit";
0355: }
0356:
0357: /**
0358: * Gets the diffViewerName attribute of the JEditPlugin object
0359: *
0360: *@return The diffViewerName value
0361: */
0362: public String getDiffViewerName() {
0363: return "jEdit's Diff plugin";
0364: }
0365:
0366: /**
0367: * Gets the localizedString attribute of the JEditPlugin object
0368: *
0369: *@param name Description of the Parameter
0370: *@param defaultValue Description of the Parameter
0371: *@return The localizedString value
0372: */
0373: public String getLocalizedString(String name, String defaultValue) {
0374: return defaultValue;
0375: }
0376:
0377: /**
0378: * Description of the Method
0379: *
0380: *@param f Description of the Parameter
0381: *@exception IOException Description of the Exception
0382: */
0383: public void openNode(CVSFileNode node) throws IOException {
0384:
0385: // TODO can we / do we need to support encoding in jEdit?
0386: if (node.isLeaf()
0387: && node.getFile().exists()
0388: && node.getFile().canRead()
0389: && (CVSSubstType.CVS_SUBST_TYPE_BINARY != node
0390: .getCVSSubstType())) {
0391: Buffer buffer = jEdit.openFile(view, node.getFile()
0392: .getAbsolutePath());
0393: view.setBuffer(buffer);
0394: }
0395: }
0396:
0397: /**
0398: * Description of the Method
0399: *
0400: *@param textColor Description of the Parameter
0401: *@param message Description of the Parameter
0402: */
0403: public void writeToConsole(TextStyle textStyle, String message) {
0404: if (view != null) {
0405: Color c = textStyle.getForeground();
0406: console.Console console = GruntspudPlugin.getConsole(view,
0407: getBooleanProperty(
0408: JEditGruntspudHost.AUTO_POPUP_CONSOLE,
0409: false));
0410: console.print(c == null ? console.getForeground() : c,
0411: message);
0412: }
0413: }
0414:
0415: /**
0416: * Description of the Method
0417: *
0418: *@param text Description of the Parameter
0419: *@param message Description of the Parameter
0420: */
0421: public void writeToStatusLine(Color c, String message, Icon icon) {
0422: statusLine = message;
0423: setJEditStatusText();
0424: }
0425:
0426: /**
0427: * Description of the Method
0428: *
0429: *@param text Description of the Parameter
0430: *@param message Description of the Parameter
0431: */
0432: public void writeToInfoLine(Color c, String message, Icon icon) {
0433: infoLine = message;
0434: setJEditStatusText();
0435: }
0436:
0437: private void setJEditStatusText() {
0438: if (view != null) {
0439: StringBuffer buf = new StringBuffer();
0440:
0441: if (statusLine != null) {
0442: buf.append(statusLine);
0443:
0444: }
0445: if (buf.length() > 0) {
0446: buf.append(" ");
0447:
0448: }
0449: if (infoLine != null) {
0450: buf.append(infoLine);
0451:
0452: }
0453: view.getStatus().setMessage(buf.toString());
0454: }
0455: }
0456:
0457: /**
0458: * Description of the Method
0459: *
0460: *@param t Description of the Parameter
0461: */
0462: public void showException(Throwable t) {
0463: showException(t, null);
0464: }
0465:
0466: /**
0467: * Description of the Method
0468: *
0469: *@param t Description of the Parameter
0470: *@param message Description of the Parameter
0471: */
0472: public void showException(Throwable t, String message) {
0473: StringWriter w = new StringWriter();
0474: PrintWriter pw = new PrintWriter(w);
0475:
0476: if (message != null) {
0477: pw.println(message);
0478:
0479: }
0480: if (t != null) {
0481: t.printStackTrace(pw);
0482:
0483: }
0484: writeToConsole(gruntspud.getContext().getTextStyleModel()
0485: .getStyle(Constants.OPTIONS_STYLE_ERRORS), w.toString());
0486: }
0487:
0488: /**
0489: * Description of the Method
0490: *
0491: *@param msg Description of the Parameter
0492: */
0493: public void handleMessage(EBMessage msg) {
0494: if (msg instanceof VFSUpdate) {
0495: final VFSUpdate upd = (VFSUpdate) msg;
0496: if (gruntspud != null) {
0497: Thread t = new Thread() {
0498: public void run() {
0499: synchronized (UPDATE_LOCK) {
0500: File f = new File(upd.getPath());
0501: if (!f.isDirectory())
0502: gruntspud.getContext().getViewManager()
0503: .externalFileUpdate(f, false);
0504: }
0505: }
0506: };
0507: t.setPriority(Thread.MIN_PRIORITY);
0508: t.start();
0509: }
0510: }
0511:
0512: if (msg instanceof BufferUpdate) {
0513: BufferUpdate update = (BufferUpdate) msg;
0514: if (update.getBuffer() != null
0515: && update.getWhat() == BufferUpdate.SAVED) {
0516: final File f = new File(update.getBuffer().getPath());
0517: if (f.exists()) {
0518: Thread t = new Thread() {
0519: public void run() {
0520: GruntspudPlugin.getErrorSource()
0521: .removeFileErrors(
0522: f.getAbsolutePath());
0523: }
0524: };
0525: t.start();
0526: }
0527: } else if (update.getBuffer() != null
0528: && (update.getWhat() == BufferUpdate.CLOSED || update
0529: .getWhat() == BufferUpdate.LOADED)) {
0530: /** @todo how do i find out if this is a local vfs? */
0531: final File f = new File(update.getBuffer().getPath());
0532: if (f.exists()) {
0533: Thread t = new Thread() {
0534: public void run() {
0535: CVSFileNode n = context.getViewManager()
0536: .findNodeForPath(
0537: context.getViewManager()
0538: .getRootNode(), f,
0539: false);
0540: if (n != null) {
0541: gruntspud.getContext().getViewManager()
0542: .reload(n);
0543: if (n.getLocalStatus() == FileStatus.HAS_CONFLICTS) {
0544: GruntspudPlugin.getErrorSource()
0545: .addConflictErrors(
0546: n.getFile());
0547: }
0548: }
0549: }
0550: };
0551: t.start();
0552: }
0553: }
0554: }
0555:
0556: if (msg instanceof PropertiesChanged) {
0557: PropertiesChanged pch = (PropertiesChanged) msg;
0558:
0559: if (gruntspud != null) {
0560: gruntspud.init();
0561: }
0562: }
0563:
0564: if (msg instanceof EditorExiting) {
0565: gruntspud.cleanUp();
0566: }
0567: }
0568:
0569: /**
0570: * Gets the property attribute of the JEditPlugin object
0571: *
0572: *@param key Description of the Parameter
0573: *@param defaultValue Description of the Parameter
0574: *@return The property value
0575: */
0576: public JComponent getMainComponent() {
0577: return gruntspud;
0578: }
0579:
0580: /**
0581: * Gets the tmpDir attribute of the JEditPlugin object
0582: *
0583: *@return The tmpDir value
0584: */
0585: public File getTmpDir() {
0586: return tmpDir;
0587: }
0588:
0589: /**
0590: * DOCUMENT ME!
0591: */
0592: public void reset() {
0593: gruntspud.init();
0594: }
0595:
0596: /**
0597: * Gets the useCanonicalPaths attribute of the JEditPlugin object
0598: *
0599: *@return The useCanonicalPaths value
0600: */
0601: public boolean isUseCanonicalPaths() {
0602: return true;
0603: }
0604:
0605: /**
0606: * Gets the property attribute of the JEditPlugin object
0607: *
0608: *@param key Description of the Parameter
0609: *@return The property value
0610: */
0611: public String getProperty(String key) {
0612: return jEdit.getProperty(key);
0613: }
0614:
0615: /**
0616: * Gets the property attribute of the JEditPlugin object
0617: *
0618: *@param key Description of the Parameter
0619: *@param defaultValue Description of the Parameter
0620: *@return The property value
0621: */
0622: public String getProperty(String key, String defaultValue) {
0623: return jEdit.getProperty(key, defaultValue);
0624: }
0625:
0626: /**
0627: * Gets the property attribute of the JEditPlugin object
0628: *
0629: *@param key Description of the Parameter
0630: *@param defaultValue Description of the Parameter
0631: *@return The property value
0632: */
0633: public void unsetProperty(String key) {
0634: jEdit.unsetProperty(key);
0635: }
0636:
0637: /**
0638: * Gets the property attribute of the JEditPlugin object
0639: *
0640: *@param key Description of the Parameter
0641: *@param defaultValue Description of the Parameter
0642: *@return The property value
0643: */
0644: public Properties getProperties() {
0645: return jEdit.getProperties();
0646: }
0647:
0648: /**
0649: * Gets the booleanProperty attribute of the JEditPlugin object
0650: *
0651: *@param key Description of the Parameter
0652: *@return The booleanProperty value
0653: */
0654: public boolean getBooleanProperty(String key) {
0655: return jEdit.getBooleanProperty(key);
0656: }
0657:
0658: /**
0659: * Gets the booleanProperty attribute of the JEditPlugin object
0660: *
0661: *@param key Description of the Parameter
0662: *@param defaultValue Description of the Parameter
0663: *@return The booleanProperty value
0664: */
0665: public boolean getBooleanProperty(String key, boolean defaultValue) {
0666: return jEdit.getBooleanProperty(key, defaultValue);
0667: }
0668:
0669: /**
0670: * Gets the booleanProperty attribute of the GruntspudHost object
0671: *
0672: *@param key Description of the Parameter
0673: *@return The booleanProperty value
0674: */
0675: public int getIntegerProperty(String key) {
0676: return getIntegerProperty(key, 0);
0677: }
0678:
0679: /**
0680: * Gets the booleanProperty attribute of the GruntspudHost object
0681: *
0682: *@param key Description of the Parameter
0683: *@return The booleanProperty value
0684: */
0685: public int getIntegerProperty(String key, int defaultValue) {
0686: try {
0687: return Integer.parseInt(getProperty(key, String
0688: .valueOf(defaultValue)));
0689: } catch (NumberFormatException nfe) {
0690: return defaultValue;
0691: }
0692: }
0693:
0694: /**
0695: * Sets the booleanProperty attribute of the GruntspudHost object
0696: *
0697: *@param key The new booleanProperty value
0698: *@param value The new booleanProperty value
0699: */
0700: public void setIntegerProperty(String key, int value) {
0701: setProperty(key, String.valueOf(value));
0702: }
0703:
0704: /**
0705: * Sets the property attribute of the JEditPlugin object
0706: *
0707: *@param key The new property value
0708: *@param value The new property value
0709: */
0710: public void setProperty(String key, String value) {
0711: jEdit.setProperty(key, value);
0712: }
0713:
0714: /**
0715: * Sets the booleanProperty attribute of the JEditPlugin object
0716: *
0717: *@param key The new booleanProperty value
0718: *@param value The new booleanProperty value
0719: */
0720: public void setBooleanProperty(String key, boolean value) {
0721: jEdit.setBooleanProperty(key, value);
0722: }
0723:
0724: /**
0725: * Inform of when a command starts running and stops running
0726: *
0727: * @param commandRunning command is running
0728: */
0729: public void setCommandRunning(boolean commandRunning) {
0730: // logo.setAnimate(commandRunning);
0731: }
0732:
0733: /**
0734: * Description of the Method
0735: *
0736: *@param component Description of the Parameter
0737: *@param key Description of the Parameter
0738: */
0739: public void saveGeometry(Window component, String key) {
0740: GUIUtilities.saveGeometry(component, key);
0741: }
0742:
0743: /**
0744: * Description of the Method
0745: *
0746: *@param component Description of the Parameter
0747: *@param key Description of the Parameter
0748: */
0749: public void loadGeometry(Window component, String key) {
0750: GUIUtilities.loadGeometry(component, key);
0751: }
0752:
0753: /**
0754: * Description of the Method
0755: *
0756: *@param key Description of the Parameter
0757: */
0758: public boolean isGeometryStored(String key) {
0759: return !getProperty(key + ".width", "").equals("");
0760: }
0761:
0762: /**
0763: * Description of the Method
0764: *
0765: *@param f1 Description of the Parameter
0766: *@param f2 Description of the Parameter
0767: */
0768: public void diff(File f1, String title1, File f2, String title2,
0769: String encoding) {
0770: // TODO can we / do we need to support encoding in jEdit?
0771: String s = f1.getAbsolutePath();
0772: String s1 = f2.getAbsolutePath();
0773: VFS vfs = view.getBuffer().getVFS();
0774: String s2 = vfs.getParentOfPath(view.getBuffer().getPath());
0775: VFS vfs1 = VFSManager.getVFSForPath(s);
0776: org.gjt.sp.jedit.io.VFS.DirectoryEntry directoryentry = null;
0777:
0778: try {
0779: directoryentry = vfs1._getDirectoryEntry(null, s, null);
0780: } catch (IOException ioexception) {
0781: }
0782:
0783: if (((directoryentry == null) || (directoryentry.type != 0))
0784: && !MiscUtilities.isURL(s)) {
0785: s = vfs.constructPath(s2, s);
0786:
0787: try {
0788: directoryentry = vfs._getDirectoryEntry(null, s, null);
0789: } catch (IOException ioexception1) {
0790: }
0791: }
0792:
0793: VFS vfs2 = VFSManager.getVFSForPath(s1);
0794: org.gjt.sp.jedit.io.VFS.DirectoryEntry directoryentry1 = null;
0795:
0796: try {
0797: directoryentry1 = vfs2._getDirectoryEntry(null, s1, null);
0798: } catch (IOException ioexception2) {
0799: }
0800:
0801: if (((directoryentry1 == null) || (directoryentry1.type != 0))
0802: && !MiscUtilities.isURL(s1)) {
0803: s1 = vfs.constructPath(s2, s1);
0804:
0805: try {
0806: directoryentry1 = vfs
0807: ._getDirectoryEntry(null, s1, null);
0808: } catch (IOException ioexception3) {
0809: }
0810: }
0811:
0812: int i = 0;
0813:
0814: if ((directoryentry == null) || (directoryentry.type != 0)) {
0815: i |= 1;
0816:
0817: }
0818: if ((directoryentry1 == null) || (directoryentry1.type != 0)) {
0819: i |= 2;
0820:
0821: }
0822: if (i > 0) {
0823: GUIUtilities.error(view, "jdiff.file-not-found",
0824: new Object[] { new Integer(i) });
0825:
0826: return;
0827: }
0828:
0829: Buffer buffer = jEdit.openFile(view, s);
0830: Buffer buffer1 = jEdit.openFile(view, s1);
0831:
0832: if (buffer == null) {
0833: GUIUtilities.error(view, "jdiff.file-not-opened",
0834: new Object[] { new Integer(0) });
0835:
0836: return;
0837: }
0838:
0839: if (buffer1 == null) {
0840: GUIUtilities.error(view, "jdiff.file-not-opened",
0841: new Object[] { new Integer(1) });
0842:
0843: return;
0844: }
0845:
0846: EditPane[] aeditpane = view.getEditPanes();
0847:
0848: if (aeditpane.length != 2) {
0849: if (aeditpane.length > 2) {
0850: view.unsplit();
0851:
0852: }
0853: view.splitVertically();
0854: aeditpane = view.getEditPanes();
0855: }
0856:
0857: aeditpane[0].setBuffer(buffer);
0858: aeditpane[1].setBuffer(buffer1);
0859:
0860: if (!DualDiff.isEnabledFor(view)) {
0861: try {
0862: DualDiff.toggleFor(view);
0863: } catch (Throwable t) {
0864: }
0865: }
0866: }
0867:
0868: /**
0869: * Reload the current tree
0870: */
0871: public void reload() {
0872: gruntspud.getContext().getViewManager().reload(null);
0873: }
0874:
0875: /**
0876: * Show a dialog containing the preferences for Gruntspud.
0877: */
0878: public void showPreferences() {
0879: final Tabber preferences = new Tabber();
0880: UIUtil.setTabLayoutPolicy(preferences, 1);
0881:
0882: // UIUtil.setTabLayoutPolicy(preferences, 1);
0883: int j = -1;
0884: int x = 0;
0885: for (Iterator i = context.optionsTabs(); i.hasNext();) {
0886: Class c = (Class) i.next();
0887: try {
0888: OptionsTab o = (OptionsTab) c.newInstance();
0889: o.init(context);
0890: if (o.getTabTitle().equals("Connection")) {
0891: j = x;
0892: }
0893: preferences.addTab(o);
0894: } catch (Throwable t) {
0895: t.printStackTrace();
0896: Constants.UI_LOG.error(t);
0897: }
0898: x++;
0899: }
0900: if (j != -1) {
0901: preferences.setSelectedIndex(j);
0902:
0903: }
0904: OptionDialog.Option ok = new OptionDialog.Option("Ok", "Ok",
0905: 'o');
0906: OptionDialog.Option cancel = new OptionDialog.Option("Cancel",
0907: "Cancel", 'c');
0908: OptionDialog.Option opt = OptionDialog.showOptionDialog(
0909: "Preferences", context, gruntspud,
0910: new OptionDialog.Option[] { ok, cancel }, preferences,
0911: "Preferences", ok, new OptionDialog.Callback() {
0912: public boolean canClose(OptionDialog dialog,
0913: OptionDialog.Option option) {
0914: return preferences.validateTabs();
0915: }
0916: });
0917:
0918: if (opt != ok) {
0919: return;
0920: }
0921:
0922: if (preferences.validateTabs()) {
0923: preferences.applyTabs();
0924: reset();
0925: }
0926: }
0927:
0928: /**
0929: * DOCUMENT ME!
0930: *
0931: * @param resource DOCUMENT ME!
0932: */
0933: public void showHelp(String resource) {
0934: new HelpViewer(GruntspudPlugin.class
0935: .getResource("/help/html/index.html"));
0936: }
0937:
0938: /**
0939: * DOCUMENT ME!
0940: */
0941: public void updateComponentTreeUI() {
0942: SwingUtilities.invokeLater(new Runnable() {
0943: public void run() {
0944:
0945: /** @todo there is probably overkill going on here */
0946: Frame[] frames = Frame.getFrames();
0947: for (int i = 0; i < frames.length; i++) {
0948: updateFullComponentTreeUI(frames[i]);
0949: updateAllDialogComponentTreeUIs(frames[i]);
0950: }
0951: if (gruntspud.getContext() != null
0952: && gruntspud.getContext().getViewManager() != null)
0953: SwingUtilities.updateComponentTreeUI(gruntspud
0954: .getContext().getViewManager());
0955: }
0956: });
0957: }
0958:
0959: private static void updateFullComponentTreeUI(Component component) {
0960: updateFullComponentTreeUI0(component);
0961: component.invalidate();
0962: component.validate();
0963: component.repaint();
0964: }
0965:
0966: private static void updateFullComponentTreeUI0(Component c) {
0967: if (c instanceof JComponent) {
0968: if (c instanceof JTree) {
0969: JTree tree = (JTree) c;
0970: if (tree.getCellRenderer() instanceof Component) {
0971: if (tree.getCellRenderer() instanceof DefaultTreeCellRenderer) {
0972: updateDefaultTreeCellRenderer((DefaultTreeCellRenderer) tree
0973: .getCellRenderer());
0974: } else {
0975: updateFullComponentTreeUI0((Component) tree
0976: .getCellRenderer());
0977: }
0978: }
0979: }
0980: ((JComponent) c).updateUI();
0981: }
0982: Component[] children = null;
0983: if (c instanceof JMenu) {
0984: children = ((JMenu) c).getMenuComponents();
0985: } else if (c instanceof Container) {
0986: children = ((Container) c).getComponents();
0987: }
0988: if (children != null) {
0989: for (int i = 0; i < children.length; i++) {
0990: updateFullComponentTreeUI0(children[i]);
0991: }
0992: }
0993: }
0994:
0995: private static void updateDefaultTreeCellRenderer(
0996: DefaultTreeCellRenderer r) {
0997: r.setLeafIcon(UIManager.getIcon("Tree.leafIcon"));
0998: r.setClosedIcon(UIManager.getIcon("Tree.closedIcon"));
0999: r.setOpenIcon(UIManager.getIcon("Tree.openIcon"));
1000:
1001: r.setTextSelectionColor(UIManager
1002: .getColor("Tree.selectionForeground"));
1003: r.setTextNonSelectionColor(UIManager
1004: .getColor("Tree.textForeground"));
1005: r.setBackgroundSelectionColor(UIManager
1006: .getColor("Tree.selectionBackground"));
1007: r.setBackgroundNonSelectionColor(UIManager
1008: .getColor("Tree.textBackground"));
1009: r.setBorderSelectionColor(UIManager
1010: .getColor("Tree.selectionBorderColor"));
1011: }
1012:
1013: private static void updateAllDialogComponentTreeUIs(Window win) {
1014: Window[] children = win.getOwnedWindows();
1015:
1016: for (int i = 0; i < children.length; i++) {
1017: if (win instanceof Frame) {
1018: continue;
1019: }
1020: updateFullComponentTreeUI(win);
1021: updateAllDialogComponentTreeUIs(win);
1022: }
1023: }
1024:
1025: class UpdateLock {
1026: }
1027: }
|