From 75b3eb1e70c3ccb912e47445a8cf50d3bdb1dd09 Mon Sep 17 00:00:00 2001 From: metasim Date: Tue, 14 Nov 2000 19:48:12 +0000 Subject: [PATCH] Added TargetMonitor widget which gives a better indication of what targets will be built if a build is launched. Also fixed a few buglets in the PropertyEditor. git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@268183 13f79535-47bb-0310-9956-ffa450edef68 --- src/antidote/build.xml | 9 +- .../org/apache/tools/ant/gui/Antidote.java | 3 + .../org/apache/tools/ant/gui/Console.java | 33 +++- .../tools/ant/gui/ProjectNavigator.java | 2 +- .../apache/tools/ant/gui/PropertyEditor.java | 3 +- .../apache/tools/ant/gui/TargetMonitor.java | 165 ++++++++++++++++++ .../apache/tools/ant/gui/acs/ACSElement.java | 15 ++ .../ant/gui/customizer/DynamicCustomizer.java | 3 +- .../ant/gui/resources/antidote.properties | 8 + 9 files changed, 225 insertions(+), 16 deletions(-) create mode 100644 src/antidote/org/apache/tools/ant/gui/TargetMonitor.java diff --git a/src/antidote/build.xml b/src/antidote/build.xml index 54882ef86..e70a22201 100644 --- a/src/antidote/build.xml +++ b/src/antidote/build.xml @@ -15,12 +15,12 @@ - - - + + + + - @@ -48,6 +48,7 @@ + diff --git a/src/antidote/org/apache/tools/ant/gui/Antidote.java b/src/antidote/org/apache/tools/ant/gui/Antidote.java index b84c42adc..d8e2c48aa 100644 --- a/src/antidote/org/apache/tools/ant/gui/Antidote.java +++ b/src/antidote/org/apache/tools/ant/gui/Antidote.java @@ -97,6 +97,9 @@ public class Antidote extends JPanel { add(BorderLayout.CENTER, splitter2); splitter2.resetToPreferredSizes(); + + add(BorderLayout.NORTH, populateEditors("top")); + setPreferredSize(new Dimension(640, 480)); } diff --git a/src/antidote/org/apache/tools/ant/gui/Console.java b/src/antidote/org/apache/tools/ant/gui/Console.java index 2e5413fd3..e544858b3 100644 --- a/src/antidote/org/apache/tools/ant/gui/Console.java +++ b/src/antidote/org/apache/tools/ant/gui/Console.java @@ -116,25 +116,38 @@ public class Console extends AntEditor { return _filter; } + /** + * Clear the contents of the console. + * + */ + private void clearDisplay() { + Document doc = _text.getDocument(); + try { + doc.remove(0, doc.getLength()); + + } + catch(Exception ex) { + // Intentionally ignored. + } + } + /** * Called when an event is to be posed to the member. * * @param event Event to post. */ public void eventPosted(EventObject event) { + if(event instanceof NewProjectEvent) { + clearDisplay(); + return; + } + AntBuildEvent buildEvent = (AntBuildEvent) event; String text = null; - Document doc = _text.getDocument(); - switch(buildEvent.getType().getValue()) { case BuildEventType.BUILD_STARTED_VAL: - try { - doc.remove(0, doc.getLength()); - } - catch(Exception ex) { - // Intentionally ignored. - } + clearDisplay(); break; case BuildEventType.TARGET_STARTED_VAL: text = buildEvent.getEvent().getTarget().getName() + ":"; @@ -154,6 +167,7 @@ public class Console extends AntEditor { if(text != null) { try { + Document doc = _text.getDocument(); doc.insertString(doc.getLength(), text, null); doc.insertString(doc.getLength(), "\n", null); } @@ -173,7 +187,8 @@ public class Console extends AntEditor { * @return True if event should be given to BusMember, false otherwise. */ public boolean accept(EventObject event) { - return event instanceof AntBuildEvent; + return event instanceof AntBuildEvent || + event instanceof NewProjectEvent; } } diff --git a/src/antidote/org/apache/tools/ant/gui/ProjectNavigator.java b/src/antidote/org/apache/tools/ant/gui/ProjectNavigator.java index 470b271e6..f366d1484 100644 --- a/src/antidote/org/apache/tools/ant/gui/ProjectNavigator.java +++ b/src/antidote/org/apache/tools/ant/gui/ProjectNavigator.java @@ -87,7 +87,7 @@ class ProjectNavigator extends AntEditor { add(scroller); setPreferredSize(new Dimension(150, 100)); - + setMinimumSize(new Dimension(150, 100)); } /** Class for handling project events. */ diff --git a/src/antidote/org/apache/tools/ant/gui/PropertyEditor.java b/src/antidote/org/apache/tools/ant/gui/PropertyEditor.java index b72d93c19..3c4a3bbf1 100644 --- a/src/antidote/org/apache/tools/ant/gui/PropertyEditor.java +++ b/src/antidote/org/apache/tools/ant/gui/PropertyEditor.java @@ -99,11 +99,12 @@ class PropertyEditor extends AntEditor { _customizer = null; } - if(items != null) { + if(items != null && items.length == 1) { _customizer = new DynamicCustomizer(items[0].getClass()); _customizer.setObject(items[0]); _container.add(BorderLayout.CENTER, _customizer); } + validate(); } diff --git a/src/antidote/org/apache/tools/ant/gui/TargetMonitor.java b/src/antidote/org/apache/tools/ant/gui/TargetMonitor.java new file mode 100644 index 000000000..9d890033f --- /dev/null +++ b/src/antidote/org/apache/tools/ant/gui/TargetMonitor.java @@ -0,0 +1,165 @@ +/* + * The Apache Software License, Version 1.1 + * + * Copyright (c) 1999, 2000 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, if + * any, must include the following acknowlegement: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowlegement may appear in the software itself, + * if and wherever such third-party acknowlegements normally appear. + * + * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software + * Foundation" must not be used to endorse or promote products derived + * from this software without prior written permission. For written + * permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache" + * nor may "Apache" appear in their names without prior written + * permission of the Apache Group. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + */ +package org.apache.tools.ant.gui; +import org.apache.tools.ant.gui.event.*; +import org.apache.tools.ant.gui.acs.ACSTargetElement; +import javax.swing.*; +import javax.swing.plaf.ComponentUI; +import javax.swing.text.Document; +import java.awt.BorderLayout; +import java.awt.Insets; +import java.awt.Dimension; +import java.util.EventObject; + +/** + * A widget for displaying the currently selected targets. + * + * @version $Revision$ + * @author Simeon Fitch + */ +public class TargetMonitor extends AntEditor { + + /** Place to display selected targets. */ + private JLabel _text = null; + + /** Default text. */ + private String _defText = null; + + /** + * Standard ctor. + * + * @param context Application context; + */ + public TargetMonitor(AppContext context) { + super(context); + context.getEventBus().addMember(EventBus.RESPONDING, new Handler()); + + setLayout(new BorderLayout()); + + _text = new JLabel(); + _text.setForeground(UIManager.getColor("TextField.foreground")); + add(BorderLayout.NORTH, _text); + + + _defText = context.getResources().getString(getClass(), "defText"); + setText(_defText); + } + + /** + * Set the displayed text. + * + * @param text Text to display. + */ + private void setText(String text) { + _text.setText("  " + text + ""); + } + + + /** Class for handling project events. */ + private class Handler implements BusMember { + private final Filter _filter = new Filter(); + + /** + * Get the filter to that is used to determine if an event should + * to to the member. + * + * @return Filter to use. + */ + public BusFilter getBusFilter() { + return _filter; + } + + /** + * Called when an event is to be posed to the member. + * + * @param event Event to post. + */ + public void eventPosted(EventObject event) { + ElementSelectionEvent e = (ElementSelectionEvent) event; + String text = _defText; + + ProjectProxy p = getAppContext().getProject(); + if(p != null) { + ElementSelectionModel selections = p.getTreeSelectionModel(); + ACSTargetElement[] targets = selections.getSelectedTargets(); + if(targets != null && targets.length > 0) { + StringBuffer buf = new StringBuffer(); + for(int i = 0; i < targets.length; i++) { + buf.append(targets[i].getName()); + if(i < targets.length - 1) { + buf.append(", "); + } + } + text = buf.toString(); + } + } + + setText(text); + } + } + + /** Class providing filtering for project events. */ + private static class Filter implements BusFilter { + /** + * Determines if the given event should be accepted. + * + * @param event Event to test. + * @return True if event should be given to BusMember, false otherwise. + */ + public boolean accept(EventObject event) { + return event instanceof ElementSelectionEvent; + } + } + +} diff --git a/src/antidote/org/apache/tools/ant/gui/acs/ACSElement.java b/src/antidote/org/apache/tools/ant/gui/acs/ACSElement.java index c28e7358b..a4ad0e277 100644 --- a/src/antidote/org/apache/tools/ant/gui/acs/ACSElement.java +++ b/src/antidote/org/apache/tools/ant/gui/acs/ACSElement.java @@ -96,6 +96,21 @@ public abstract class ACSElement extends ElementNode { return toString(); } + /** + * Set the given attribute. + * + * @param name Name of the attribute. + * @param value Value of the attribute. + */ + public void setAttribute(String name, String value) { + if(value == null || value.length() == 0) { + removeAttribute(name); + } + else { + super.setAttribute(name, value); + } + } + /** * Add a change listener. * diff --git a/src/antidote/org/apache/tools/ant/gui/customizer/DynamicCustomizer.java b/src/antidote/org/apache/tools/ant/gui/customizer/DynamicCustomizer.java index 8e5aa8ca0..e763caa75 100644 --- a/src/antidote/org/apache/tools/ant/gui/customizer/DynamicCustomizer.java +++ b/src/antidote/org/apache/tools/ant/gui/customizer/DynamicCustomizer.java @@ -259,7 +259,7 @@ public class DynamicCustomizer extends JPanel { return retval; } - /** Class for receiving change events from teh PropertyEditor objects. */ + /** Class for receiving change events from the PropertyEditor objects. */ private class EditorChangeListener implements PropertyChangeListener { public void propertyChange(PropertyChangeEvent e) { PropertyEditor editor = (PropertyEditor) e.getSource(); @@ -270,6 +270,7 @@ public class DynamicCustomizer extends JPanel { try { Object[] params = { editor.getValue() }; writer.invoke(_value, params); + setObject(_value); //firePropertyChange( //prop.getName(), null, editor.getValue()); } diff --git a/src/antidote/org/apache/tools/ant/gui/resources/antidote.properties b/src/antidote/org/apache/tools/ant/gui/resources/antidote.properties index 541e017c6..c36e3060e 100644 --- a/src/antidote/org/apache/tools/ant/gui/resources/antidote.properties +++ b/src/antidote/org/apache/tools/ant/gui/resources/antidote.properties @@ -13,12 +13,20 @@ org.apache.tools.ant.gui.Antidote.left.editors=\ org.apache.tools.ant.gui.Antidote.bottom.editors=\ org.apache.tools.ant.gui.Console +# Configure the editors that appear on the top of the UI. +org.apache.tools.ant.gui.Antidote.top.editors=\ + org.apache.tools.ant.gui.TargetMonitor + # Set specific class properties. org.apache.tools.ant.gui.SourceEditor.name=Source org.apache.tools.ant.gui.PropertyEditor.name=Properties org.apache.tools.ant.gui.ProjectNavigator.name=Project + +org.apache.tools.ant.gui.TargetMonitor.name=Selected Target(s) +org.apache.tools.ant.gui.TargetMonitor.defText=[none] + org.apache.tools.ant.gui.Console.name=Console org.apache.tools.ant.gui.Console.logLevel=Log message level: