Browse Source

Changed "AntEditor" to "AntModule", and made construct more JavaBean

compliant (primarily a default ctor). Now has "contextualize()" method
that modules must implement.


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@268374 13f79535-47bb-0310-9956-ffa450edef68
master
metasim 24 years ago
parent
commit
8f1c824449
9 changed files with 116 additions and 197 deletions
  1. +3
    -3
      src/antidote/docs/design-overview.html
  2. +33
    -12
      src/antidote/org/apache/tools/ant/gui/AntModule.java
  3. +18
    -21
      src/antidote/org/apache/tools/ant/gui/Antidote.java
  4. +13
    -5
      src/antidote/org/apache/tools/ant/gui/Console.java
  5. +11
    -4
      src/antidote/org/apache/tools/ant/gui/ProjectNavigator.java
  6. +12
    -5
      src/antidote/org/apache/tools/ant/gui/PropertyEditor.java
  7. +0
    -130
      src/antidote/org/apache/tools/ant/gui/SourceEditor.java
  8. +12
    -5
      src/antidote/org/apache/tools/ant/gui/TargetMonitor.java
  9. +14
    -12
      src/antidote/org/apache/tools/ant/gui/resources/antidote.properties

+ 3
- 3
src/antidote/docs/design-overview.html View File

@@ -8,7 +8,7 @@

<H1>Antidote Design Overview</H1>

<P>Version 0.1 (2000/11/02)</P>
<P>Version 0.2 (2000/12/18)</P>

<P>Authors:
<A HREF="mailto:simeon@fitch.net">Simeon H.K. Fitch</A>
@@ -39,7 +39,7 @@
communications channel.</P>
<P>To a large extent, the configuration of application modules is
driven by localized configuration files, allowing new editors or
driven by localized configuration files, allowing new modules or
data views to be added, as well as providing multi-language
support.</P>

@@ -53,7 +53,7 @@ Antidote Component Architecture

+---------------+ +----------------+ +-------------+ +-------------+
| | | | | | | |
| ActionManager | | EventResponder | | AntEditor | | AntEditor |
| ActionManager | | EventResponder | | AntModule | | AntModule |
| | | | |(ProjectNav) | |(SourceEdit) |
+---------------+ +----------------+ +-------------+ +-------------+
| ^ ^ ^


src/antidote/org/apache/tools/ant/gui/AntEditor.java → src/antidote/org/apache/tools/ant/gui/AntModule.java View File

@@ -53,34 +53,51 @@
*/
package org.apache.tools.ant.gui;

import javax.swing.JPanel;
import javax.swing.JComponent;
import javax.swing.BorderFactory;

/**
* Abstract base class for an "editor", which is really anything that
* Abstract base class for a "module", which is really anything that
* can send or receive events, or edit or view the model.
*
* @version $Revision$
* @author Simeon Fitch
*/
public abstract class AntEditor extends JPanel {

/** Parameters to the Contructor. Used for loading
classes through reflection. */
public static final Class[] CTOR_PARAMS = { AppContext.class };
public abstract class AntModule extends JComponent {

/** The application context. */
private AppContext _context = null;

/**
* Standard constuctor.
* Default constructor.
*/
protected AntModule() {
// Create a dummy border so that the widget will at least have a
// minimal display in a bean environment.
setBorder(BorderFactory.createTitledBorder(getClass().getName()));
}

/**
* This method is called after instantiation when the application context
* is available for constructing the class' display. Think of this in
* a similar manner to Applet.init() or Servlet.init(). It should
* immediately call #setContext() with the given parameter.
*
* @param context Valid application context providing
* all required resources.
*/
public abstract void contextualize(AppContext context);

/**
* Set the application context.
*
* @param context Application context.
*/
protected AntEditor(AppContext context) {
protected void setContext(AppContext context) {
_context = context;
setBorder(BorderFactory.createTitledBorder(getName()));
}
setBorder(_context == null ? null :
BorderFactory.createTitledBorder(getName()));
}

/**
* Get the application context.
@@ -88,6 +105,10 @@ public abstract class AntEditor extends JPanel {
* @return Application context.
*/
public AppContext getContext() {
if(_context == null) {
throw new IllegalStateException(
"The AppContext has not been set.");
}
return _context;
}
/**
@@ -96,6 +117,6 @@ public abstract class AntEditor extends JPanel {
* @return Editor's name.
*/
public String getName() {
return _context.getResources().getString(getClass(), "name");
return getContext().getResources().getString(getClass(), "name");
}
}

+ 18
- 21
src/antidote/org/apache/tools/ant/gui/Antidote.java View File

@@ -78,10 +78,10 @@ public class Antidote extends JPanel {

_context = context;

// Add the various editors/views to the editing area.
// Add the various modules to the editing area.
JSplitPane splitter = new JSplitPane();
splitter.add(JSplitPane.LEFT, populateEditors("left"));
splitter.add(JSplitPane.RIGHT, populateEditors("right"));
splitter.add(JSplitPane.LEFT, populateModules("left"));
splitter.add(JSplitPane.RIGHT, populateModules("right"));
// This is necessary because, frankly, the JSplitPane widget
// sucks, and doesn't provide enought (working) control over the
// initial size of it's subcomponents. setDividerLocation(double)
@@ -93,38 +93,35 @@ public class Antidote extends JPanel {
splitter2.setOneTouchExpandable(true);

splitter2.add(JSplitPane.TOP, splitter);
splitter2.add(JSplitPane.BOTTOM, populateEditors("bottom"));
splitter2.add(JSplitPane.BOTTOM, populateModules("bottom"));

add(BorderLayout.CENTER, splitter2);
splitter2.resetToPreferredSizes();

add(BorderLayout.NORTH, populateEditors("top"));
add(BorderLayout.NORTH, populateModules("top"));

setPreferredSize(new Dimension(640, 600));
}


/**
* Instantiate the configured editors.
* Instantiate the configured modules.
*
* @return Component containing the editor(s).
* @return Component containing the modules(s).
*/
private JComponent populateEditors(String prefix) {
private JComponent populateModules(String prefix) {

String[] classNames = _context.getResources().
getStringArray(getClass(), prefix + ".editors");
getStringArray(getClass(), prefix + ".modules");

AntEditor[] editors = new AntEditor[classNames.length];
AntModule[] modules = new AntModule[classNames.length];

for(int i = 0; i < classNames.length; i++) {
try {
Class editorType = Class.forName(classNames[i]);
Class type = Class.forName(classNames[i]);

Constructor ctor =
editorType.getConstructor(AntEditor.CTOR_PARAMS);

editors[i] =
(AntEditor) ctor.newInstance(new Object[] { _context });
modules[i] = (AntModule) type.newInstance();
modules[i].contextualize(_context);
}
catch(Exception ex) {
// XXX log me.
@@ -132,14 +129,14 @@ public class Antidote extends JPanel {
}
}

if(editors.length == 1) {
return editors[0];
if(modules.length == 1) {
return modules[0];
}
else if(editors.length > 1) {
else if(modules.length > 1) {
JTabbedPane tabbed = new JTabbedPane(JTabbedPane.BOTTOM);

for(int i = 0; i < editors.length; i++) {
tabbed.addTab(editors[i].getName(), editors[i]);
for(int i = 0; i < modules.length; i++) {
tabbed.addTab(modules[i].getName(), modules[i]);
}
return tabbed;
}


+ 13
- 5
src/antidote/org/apache/tools/ant/gui/Console.java View File

@@ -68,7 +68,7 @@ import java.util.EventObject;
* @version $Revision$
* @author Simeon Fitch
*/
public class Console extends AntEditor {
public class Console extends AntModule {
/** Area where messages are printed. */
private JTextPane _text = null;
/** Selection of logging levels. */
@@ -77,12 +77,19 @@ public class Console extends AntEditor {
private ConsoleStyleContext _styles = null;
/**
* Standard ctor.
* Default ctor.
*/
public Console() {
}


/**
* Using the given AppContext, initialize the display.
*
* @param context Application context;
* @param context Application context.
*/
public Console(AppContext context) {
super(context);
public void contextualize(AppContext context) {
setContext(context);
context.getEventBus().addMember(EventBus.MONITORING, new Handler());
setLayout(new BorderLayout());

@@ -106,6 +113,7 @@ public class Console extends AntEditor {

}


/** Class for handling project events. */
private class Handler implements BusMember {
private final Filter _filter = new Filter();


+ 11
- 4
src/antidote/org/apache/tools/ant/gui/ProjectNavigator.java View File

@@ -66,18 +66,25 @@ import java.util.EventObject;
* @version $Revision$
* @author Simeon Fitch
*/
class ProjectNavigator extends AntEditor {
class ProjectNavigator extends AntModule {

/** Navigation via a tree widget. */
private JTree _tree = null;

/**
* Standard ctor.
* Default ctor.
*
*/
public ProjectNavigator() {
}

/**
* Using the given AppContext, initialize the display.
*
* @param context Application context.
*/
public ProjectNavigator(AppContext context) {
super(context);
public void contextualize(AppContext context) {
setContext(context);
context.getEventBus().addMember(EventBus.MONITORING, new Handler());

setLayout(new GridLayout(1,1));


+ 12
- 5
src/antidote/org/apache/tools/ant/gui/PropertyEditor.java View File

@@ -71,7 +71,7 @@ import java.awt.Point;
* @version $Revision$
* @author Simeon H.K. Fitch
*/
class PropertyEditor extends AntEditor {
public class PropertyEditor extends AntModule {

/** The editor for current bean.*/
private Customizer _customizer = null;
@@ -81,12 +81,19 @@ class PropertyEditor extends AntEditor {
private JScrollPane _scroller = null;

/**
* Standard ctor.
* Default ctor.
*
* @param context Application context.
*/
public PropertyEditor(AppContext context) {
super(context);
public PropertyEditor() {
}

/**
* Using the given AppContext, initialize the display.
*
* @param context Application context.
*/
public void contextualize(AppContext context) {
setContext(context);
context.getEventBus().addMember(EventBus.MONITORING, new Handler());
setLayout(new BorderLayout());
_container = new JPanel(new BorderLayout());


+ 0
- 130
src/antidote/org/apache/tools/ant/gui/SourceEditor.java View File

@@ -1,130 +0,0 @@
/*
* 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
* <http://www.apache.org/>.
*/
package org.apache.tools.ant.gui;
import org.apache.tools.ant.gui.event.*;

import java.util.EventObject;
import javax.swing.*;
import javax.swing.text.PlainDocument;

import java.awt.GridLayout;
import java.awt.Font;

/*
* AntEditor for the XML source. XXX Stubbed version.
*
* @version $Revision$
* @author Simeon Fitch
*/
class SourceEditor extends AntEditor {
private JEditorPane _text = null;

public SourceEditor(AppContext context) {
super(context);
context.getEventBus().addMember(EventBus.MONITORING, new Handler());

setLayout(new GridLayout(1,1));

_text = new JEditorPane();
_text.setEditable(false);
// _text.setFont(new Font("Monospaced", 10, Font.PLAIN));

JScrollPane scroller = new JScrollPane(_text);
add(scroller);
}

/** 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.
* @return true if event should be propogated, false if
* it should be cancelled.
*/
public boolean eventPosted(EventObject event) {
ProjectProxy project = getContext().getProject();

_text.setDocument(project == null ? new PlainDocument() :
project.getDocument());
return true;
}
}

/** 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 NewProjectEvent;
}
}

}

+ 12
- 5
src/antidote/org/apache/tools/ant/gui/TargetMonitor.java View File

@@ -68,7 +68,7 @@ import java.util.EventObject;
* @version $Revision$
* @author Simeon Fitch
*/
public class TargetMonitor extends AntEditor {
public class TargetMonitor extends AntModule {
/** Place to display selected targets. */
private JLabel _text = null;
@@ -77,12 +77,19 @@ public class TargetMonitor extends AntEditor {
private String _defText = null;

/**
* Standard ctor.
* Default ctor.
*
* @param context Application context;
*/
public TargetMonitor(AppContext context) {
super(context);
public TargetMonitor() {
}

/**
* Using the given AppContext, initialize the display.
*
* @param context Application context.
*/
public void contextualize(AppContext context) {
setContext(context);
context.getEventBus().addMember(EventBus.RESPONDING, new Handler());

setLayout(new BorderLayout());


+ 14
- 12
src/antidote/org/apache/tools/ant/gui/resources/antidote.properties View File

@@ -1,25 +1,27 @@
# This is the general properties file for the Antidote application.

# Configure the editors that appear on the right of the UI.
org.apache.tools.ant.gui.Antidote.right.editors=\
# The following four module properties configure those properties that
# should be initialized and displayed by default by the GUI. If more
# than one module is configured for a property (as indicated providing
# class names as a comma delimited list), then each module will appear
# in its own tab in a JTabbedPane.

# Configure the modules that appear on the right of the UI.
org.apache.tools.ant.gui.Antidote.right.modules=\
org.apache.tools.ant.gui.PropertyEditor
# org.apache.tools.ant.gui.SourceEditor

# Configure the editors that appear on the left of the UI.
org.apache.tools.ant.gui.Antidote.left.editors=\
# Configure the modules that appear on the left of the UI.
org.apache.tools.ant.gui.Antidote.left.modules=\
org.apache.tools.ant.gui.ProjectNavigator

# Configure the editors that appear on the bottom of the UI.
org.apache.tools.ant.gui.Antidote.bottom.editors=\
# Configure the modules that appear on the bottom of the UI.
org.apache.tools.ant.gui.Antidote.bottom.modules=\
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=\
# Configure the modules that appear on the top of the UI.
org.apache.tools.ant.gui.Antidote.top.modules=\
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


Loading…
Cancel
Save