ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From meta...@locus.apache.org
Subject cvs commit: jakarta-ant/src/antidote/org/apache/tools/ant/gui ActionManager.java Console.java Main.java
Date Sat, 25 Nov 2000 04:33:05 GMT
metasim     00/11/24 20:33:05

  Modified:    src/antidote ChangeLog TODO
               src/antidote/org/apache/tools/ant/gui ActionManager.java
                        Console.java Main.java
  Log:
  Added simplistic, non-editable version of context fontification in Console.
  
  Revision  Changes    Path
  1.11      +4 -0      jakarta-ant/src/antidote/ChangeLog
  
  Index: ChangeLog
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/antidote/ChangeLog,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- ChangeLog	2000/11/21 01:06:14	1.10
  +++ ChangeLog	2000/11/25 04:33:02	1.11
  @@ -1,3 +1,7 @@
  +2000-11-24  Simeon H.K. Fitch  <simeon@fitch.net>
  +
  +	* org/apache/tools/ant/gui/Console.java: Added context colorization.
  +
   2000-11-20  Simeon H.K. Fitch  <simeon@fitch.net>
   
   	* org/apache/tools/ant/gui/command/DisplayErrorCmd.java: Added
  
  
  
  1.6       +3 -0      jakarta-ant/src/antidote/TODO
  
  Index: TODO
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/antidote/TODO,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- TODO	2000/11/24 17:09:10	1.5
  +++ TODO	2000/11/25 04:33:02	1.6
  @@ -1,4 +1,7 @@
   TODO List:
  +    * Add a Progress Monitor for file loading (especially for slow boxen like
  +      mine) .
  +
       * Implement some for of refid hyperlinking functionality.
   
       * Provide some sort of class path debugging support.
  
  
  
  1.7       +9 -3      jakarta-ant/src/antidote/org/apache/tools/ant/gui/ActionManager.java
  
  Index: ActionManager.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/antidote/org/apache/tools/ant/gui/ActionManager.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- ActionManager.java	2000/11/24 17:09:12	1.6
  +++ ActionManager.java	2000/11/25 04:33:03	1.7
  @@ -104,15 +104,19 @@
   import org.apache.tools.ant.gui.command.Command;
   import javax.swing.*;
   import java.util.*;
  +import java.lang.reflect.Constructor;
   
   /**
    * Manager of antidote actions. Receives its configuration from the action
    * ResourceBundle.
    * 
  - * @version $Revision: 1.6 $ 
  + * @version $Revision: 1.7 $ 
    * @author Simeon Fitch 
    */
   public class ActionManager {
  +    /** Parameters for the Command constructor. */
  +    private static final Class[] COMMAND_CTOR_PARAMS = { AppContext.class };
  +
       private  ResourceBundle _resources = 
           ResourceBundle.getBundle(
               "org.apache.tools.ant.gui.resources.action");
  @@ -271,8 +275,10 @@
               Class clazz = action.getCommandClass();
               if(clazz != null) {
                   try {
  -                    retval = (Command) clazz.newInstance();
  -                    retval.setContext(context);
  +                    Constructor ctor = 
  +                        clazz.getConstructor(COMMAND_CTOR_PARAMS);
  +                    retval = (Command) ctor.newInstance(
  +                        new Object[] { context });
                   }
                   catch(Exception ex) {
                       // XXX log me.
  
  
  
  1.8       +106 -20   jakarta-ant/src/antidote/org/apache/tools/ant/gui/Console.java
  
  Index: Console.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/antidote/org/apache/tools/ant/gui/Console.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- Console.java	2000/11/15 21:25:33	1.7
  +++ Console.java	2000/11/25 04:33:04	1.8
  @@ -55,16 +55,17 @@
   import org.apache.tools.ant.gui.event.*;
   import javax.swing.*;
   import javax.swing.plaf.ComponentUI;
  -import javax.swing.text.Document;
  +import javax.swing.text.*;
   import java.awt.BorderLayout;
   import java.awt.FlowLayout;
   import java.awt.Dimension;
  +import java.awt.Color;
   import java.util.EventObject;
   
   /**
    * Logging console display.
    * 
  - * @version $Revision: 1.7 $ 
  + * @version $Revision: 1.8 $ 
    * @author Simeon Fitch 
    */
   public class Console extends AntEditor {
  @@ -72,7 +73,9 @@
       private JTextPane _text = null;
       /** Selection of logging levels. */
       private JComboBox _logLevel = null;
  -        
  +    /** Display styles. */
  +    private ConsoleStyleContext _styles = null;
  +    
   	/** 
   	 * Standard ctor.
   	 * 
  @@ -83,7 +86,8 @@
           context.getEventBus().addMember(EventBus.MONITORING, new Handler());
           setLayout(new BorderLayout());
   
  -        _text = new NoWrapTextPane();
  +        _styles = new ConsoleStyleContext();
  +        _text = new JTextPane(_styles.getStyledDocument());
           _text.setEditable(false);
           JScrollPane scroller = new JScrollPane(_text);
           scroller.setVerticalScrollBarPolicy(
  @@ -124,7 +128,6 @@
               Document doc = _text.getDocument();
               try {
                   doc.remove(0, doc.getLength());
  -                
               }
               catch(Exception ex) {
                   // Intentionally ignored.
  @@ -145,6 +148,7 @@
               }
   
               AntBuildEvent buildEvent = (AntBuildEvent) event;
  +            Style style = null;
               String text = null;
   
               switch(buildEvent.getType().getValue()) {
  @@ -152,9 +156,11 @@
                     clearDisplay();
                 case BuildEventType.BUILD_FINISHED_VAL:
                     text = buildEvent.getType().toString();
  +                  style = _styles.getHeadingStyle();
                     break;
                 case BuildEventType.TARGET_STARTED_VAL:
                     text = buildEvent.getEvent().getTarget().getName() + ":";
  +                  style = _styles.getSubheadingStyle();
                     break;
                 case BuildEventType.TARGET_FINISHED_VAL:
                 case BuildEventType.TASK_STARTED_VAL:
  @@ -165,17 +171,18 @@
                     // selected filterint level.
                     LogLevelEnum level = 
                         (LogLevelEnum) _logLevel.getSelectedItem();
  -                  if(buildEvent.getEvent().getPriority() <= level.getValue()) {
  +                  int priority = buildEvent.getEvent().getPriority();
  +                  if(priority <= level.getValue()) {
                         text = buildEvent.toString();
  +                      style = _styles.getStyle(LogLevelEnum.fromInt(priority));
                     }
                     break;
               }
   
  -
               if(text != null) {
                   try {
                       Document doc = _text.getDocument();
  -                    doc.insertString(doc.getLength(), text, null);
  +                    doc.insertString(doc.getLength(), text, style);
                       doc.insertString(doc.getLength(), "\n", null);
                   }
                   catch(Exception ex) {
  @@ -200,20 +207,99 @@
                   event instanceof NewProjectEvent;
           }
       }
  +
  +    /** Style set for pretty display of the console messages. */
  +    private static class ConsoleStyleContext extends StyleContext {
  +        /** Name of the style used for headings. */
  +        public static final String HEADING_STYLE = "headingStyle";
  +        /** Name of the style used for subheadings. */
  +        public static final String SUBHEADING_STYLE = "subheadingStyle";
  +
  +        /** XXX temporary list of style colors. To go away once a real set of
  +         *  properties is implemented... */
  +        private static final Color[] _colors = {
  +            Color.red,
  +            Color.magenta,
  +            Color.black,
  +            Color.darkGray,
  +            Color.blue
  +        };
  +
  +        /** 
  +         * Default ctor.
  +         * 
  +         */
  +        public ConsoleStyleContext() {
  +            Style defaultStyle = getStyle(DEFAULT_STYLE);
  +            StyleConstants.setFontSize(defaultStyle, 12);
  +
  +            Style msgBase = addStyle("msgBase", defaultStyle);
  +            StyleConstants.setFontFamily(msgBase, "Monospaced");
  +
  +            LogLevelEnum[] levels = LogLevelEnum.getValues();
  +            for(int i = 0; i < levels.length; i++) {
  +                Style curr = addStyle(levels[i].toString(), msgBase);
  +                StyleConstants.setFontSize(curr, 10);
  +                StyleConstants.setForeground(curr, _colors[i]);
  +            }
  +
  +            Style heading = addStyle(HEADING_STYLE, defaultStyle);
  +            StyleConstants.setFontFamily(heading, "SansSerif");
  +            StyleConstants.setBold(heading, true);
  +            StyleConstants.setUnderline(heading, true);
  +
  +            Style subheading = addStyle(SUBHEADING_STYLE, heading);
  +            StyleConstants.setFontSize(subheading, 10);
  +            StyleConstants.setUnderline(subheading, false);
  +        }
  +
  +        /** 
  +         * Get the style to use for the given logging level.
  +         * 
  +         * @param level Logging level.
  +         * @return Style to use for display.
  +         */
  +        Style getStyle(LogLevelEnum level) {
  +            Style retval = getStyle(level.toString());
  +            return retval == null ? getDefaultStyle() : retval;
  +        }
  +
  +        /** 
  +         * Get the default style.
  +         * 
  +         * @return Default style.
  +         */
  +        Style getDefaultStyle() {
  +            return getStyle(DEFAULT_STYLE);
  +        }
  +
  +        /** 
  +         * Get the style to use for headings.
  +         * 
  +         * @return Heading style.
  +         */
  +        Style getHeadingStyle() {
  +            return getStyle(HEADING_STYLE);
  +        }
  +
  +        /** 
  +         * Get the style to use for subheadings.
  +         * 
  +         * @return Subheading style.
  +         */
  +        Style getSubheadingStyle() {
  +            return getStyle(SUBHEADING_STYLE);
  +        }
   
  -    /** Specialization of JTextPane to provide proper wrapping behavior. */
  -    private static class NoWrapTextPane extends JTextPane {
           /** 
  -         * Overridden to ensure that the JTextPane is only
  -         * forced to match the viewport if it is smaller than
  -         * the viewport.
  -         * 
  -         * @return True if smaller than viewport, false otherwise.
  -         */
  -        public boolean getScrollableTracksViewportWidth() {
  -            ComponentUI ui = getUI();
  -            return getParent() != null ? ui.getPreferredSize(this).width <=
  -                getParent().getSize().width : true;
  +         * Get a StyledDocument initialized with this.
  +         * 
  +         * @return SytledDocument.
  +         */
  +        StyledDocument getStyledDocument() {
  +            DefaultStyledDocument retval = new DefaultStyledDocument(this);
  +            retval.setLogicalStyle(0, getDefaultStyle());
  +            return retval;
           }
       }
   
  
  
  
  1.7       +2 -3      jakarta-ant/src/antidote/org/apache/tools/ant/gui/Main.java
  
  Index: Main.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/antidote/org/apache/tools/ant/gui/Main.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- Main.java	2000/11/24 17:09:13	1.6
  +++ Main.java	2000/11/25 04:33:04	1.7
  @@ -60,7 +60,7 @@
   /**
    * Launch point for the Antidote GUI. Configurs it as an application.
    * 
  - * @version $Revision: 1.6 $ 
  + * @version $Revision: 1.7 $ 
    * @author Simeon Fitch 
    */
   public class Main {
  @@ -99,9 +99,8 @@
               // XXX this will change once full command line argument parsing
               // is supported.
               if(args.length > 0) {
  -                LoadFileCmd load = new LoadFileCmd();
  +                LoadFileCmd load = new LoadFileCmd(context);
                   load.setFile(new File(args[0]));
  -                load.setContext(context);
                   load.run();
               }
           }
  
  
  

Mime
View raw message