Commits

Anonymous committed 8b52480

Added preference to change colors of inspectable and prompt in REPL.
However these changes do not work yet.

Comments (0)

Files changed (12)

org.lispdev.console/src/org/lispdev/console/LispConsoleViewer.java

 import org.eclipse.swt.events.KeyListener;
 import org.eclipse.swt.events.VerifyEvent;
 import org.eclipse.swt.events.VerifyListener;
+import org.eclipse.swt.graphics.Color;
 import org.eclipse.swt.graphics.Point;
 import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.Event;
   }
 
   /**
+   * Appends text and creates partition data using <code>context</code> and
+   * style defined by other variables.
+   * @param str
+   * @param context
+   * @param id
+   * @param foreground
+   * @param background
+   * @param fontStyle
+   * @param onNewLine
+   */
+  public void appendText(String str, String context, String id,
+      Color foreground, Color background, int fontStyle, boolean onNewLine)
+  {
+    Trace.CONSOLE.trace("\""+str+"\",\""+context+"\"");
+    PartitionData pd = new PartitionData(0,str.length(), context, id,
+        new StyleRange[]{new StyleRange(0,str.length(),foreground,
+            background,fontStyle)});
+    appendText(str, pd, onNewLine);
+  }
+
+
+
+  /**
    * If <code>inEditMode</code> and <code>offset</code> is inside read-only
    * partition of current edit region, returns that partition.
    * Otherwise returns <code>null</code>

org.lispdev.editor/plugin.xml

             name="Editor">
       </page>
       <page
-            category="org.lispdev/org.lispdev.editor"
+            category="org.lispdev.editor"
             class="org.lispdev.editor.preferences.ColorPreferencePage"
             id="org.lispdev.editor.colors"
             name="Colors">

org.lispdev.editor/src/org/lispdev/editor/ColorManager.java

 import org.eclipse.swt.widgets.Display;
 
 /**
- * All colors should be obtained through this manager getColor function.
+ * All colors should be obtained through this manager's getColor function.
  */
 public class ColorManager
 {

org.lispdev.editor/src/org/lispdev/editor/LispEditor.java

   LispOutlinePage outline;
 
   @Override
-  @SuppressWarnings("unchecked")
-  public Object getAdapter(Class adapter)
+  public Object getAdapter(@SuppressWarnings("rawtypes") Class adapter)
   {
     if( IContentOutlinePage.class.equals(adapter) )
     {

org.lispdev.editor/src/org/lispdev/editor/preferences/Preference.java

       ColorManager.DEFAULT_KEYWORD, "Keyword", "Color of keyword"),
 
   COLOR_PARAM("colorParam", PreferenceType.COLOR,
-      ColorManager.DEFAULT_PARAM, "Param", "Color of parameter, e.g. '&param'"),
+      ColorManager.DEFAULT_PARAM, "Param", "Color of parameter, e.g. '&&param'"),
 
   COLOR_KEY("colorKey", PreferenceType.COLOR,
       ColorManager.DEFAULT_KEY, "Key", "Color of key, e.g. ':key'"),

org.lispdev.replview/META-INF/MANIFEST.MF

  org.lispdev.log;bundle-version="1.0.0",
  org.lispdev.repl;bundle-version="1.0.0",
  org.lispdev.main;bundle-version="1.0.0",
- org.lispdev.console.core;bundle-version="1.0.0"
+ org.lispdev.console.core;bundle-version="1.0.0",
+ org.lispdev.preferences;bundle-version="0.0.0"
 Bundle-ActivationPolicy: lazy
 Bundle-RequiredExecutionEnvironment: JavaSE-1.6

org.lispdev.replview/plugin.xml

             id="org.lispdev.debug.model">
       </debugModelPresentation>
    </extension>
+   <extension
+         point="org.eclipse.ui.preferencePages">
+      <page
+            category="org.lispdev"
+            class="org.lispdev.replview.ReplPreferencePage"
+            id="org.lispdev.repl"
+            name="REPL">
+      </page>
+   </extension>
 
 </plugin>

org.lispdev.replview/src/org/lispdev/replview/ColorManager.java

+package org.lispdev.replview;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.RGB;
+import org.eclipse.swt.widgets.Display;
+
+/**
+ * All colors should be obtained through this manager's getColor function.
+ */
+public class ColorManager
+{
+  public static RGB DEFAULT_PROMPT = new RGB(200, 0, 0);
+  public static RGB DEFAULT_INSPECTABLE = new RGB(200,200,200);
+  public static RGB DEFAULT_DEFAULT = new RGB(0, 0, 0);
+
+  protected Map<RGB, Color> fColorTable = new HashMap<RGB, Color>(10);
+
+  public void dispose()
+  {
+    Iterator<Color> e = fColorTable.values().iterator();
+    while(e.hasNext())
+      e.next().dispose();
+  }
+
+  public Color getColor(RGB rgb)
+  {
+    Color color = fColorTable.get(rgb);
+    if(color == null)
+    {
+      color = new Color(Display.getCurrent(), rgb);
+      fColorTable.put(rgb, color);
+    }
+    return color;
+  }
+}

org.lispdev.replview/src/org/lispdev/replview/Preference.java

+package org.lispdev.replview;
+
+import org.lispdev.preferences.PreferenceItem;
+import org.lispdev.preferences.PreferenceType;
+import org.lispdev.preferences.PreferencesService;
+
+public enum Preference
+{
+  COLOR_INSPECTABLE("colorInspectable", PreferenceType.COLOR,
+      ColorManager.DEFAULT_INSPECTABLE, "Inspectable",
+      "Color of inspectable background"),
+
+  COLOR_PROMPT("colorPrompt", PreferenceType.COLOR,
+      ColorManager.DEFAULT_PROMPT, "Prompt", "Color of prompt")
+  ;
+
+  private Preference(String id, PreferenceType type, Object defaultValue,
+      String label, String tooltip)
+  {
+    item = new PreferenceItem(id, type, defaultValue, label, tooltip);
+  }
+
+  private final PreferenceItem item;
+
+  public PreferenceItem item()
+  {
+    return item;
+  }
+
+  public static void init(PreferencesService service)
+  {
+    for( Preference p : values() )
+    {
+      p.item.initDefault(service);
+    }
+  }
+
+  public static Preference[] replColors()
+  {
+    return new Preference[]{COLOR_INSPECTABLE, COLOR_PROMPT};
+  }
+}

org.lispdev.replview/src/org/lispdev/replview/ReplConsolePage.java

 import org.lispdev.repl.AbstractRepl;
 import org.lispdev.repl.IState;
 import org.lispdev.repl.ReadState;
+import org.lispdev.replview.ReplViewPlugin.IResetColorListener;
 import org.lispdev.swank.SwankPlugin;
 import org.lispdev.swank.debug.LispDebugTarget;
 import org.lispdev.swank.debug.LispProcess;
 import org.lispdev.swank.debug.LispThread;
 import org.lispdev.swank.runnables.SwankDebugRunnable.DebugInfo;
 
-public class ReplConsolePage implements IPageBookViewPage
+public class ReplConsolePage implements IPageBookViewPage, IResetColorListener
 {
   private IPageSite fSite;
 
     @Override
     public void appendOutInspectable(String text, String id)
     {
-      replConsole.appendText(text,"inspectable",id, null, true);
+      replConsole.appendText(text,"inspectable",id, null,
+          ReplViewPlugin.get().getInspectableColor(),SWT.NONE, true);
     }
 
     @Override
     public void packageChanged(String pkg)
     {
       replConsole.setPrompt(
-          new Prompt(pkg.toUpperCase()+">", pkg, "1", null,null,SWT.BOLD,false));
+          new Prompt(pkg.toUpperCase()+">", pkg, "1",
+              ReplViewPlugin.get().getPromptColor(),null,SWT.BOLD,false));
     }
 
     @Override
     {
       replConsole.setPrompt(
           new Prompt(swank.getCurrPackage().toUpperCase()+">",
-              swank.getCurrPackage(), "1", null,null,SWT.BOLD,false));
+              swank.getCurrPackage(), "1",
+              ReplViewPlugin.get().getPromptColor(),null,SWT.BOLD,false));
       enterTrigger.setDoIt(false);
       enterTrigger.setStateMask(SWT.SHIFT);
       eval(msg);
         });
     replConsole.getTextWidget().setFont(JFaceResources.getTextFont());
     JFaceResources.getFontRegistry().addListener(fontListener);
+    ReplViewPlugin.get().addResetColorListener(this);
     replConsole.getTextWidget().addFocusListener(new FocusListener(){
       @Override
       public void focusLost(FocusEvent e)
-      {
-      }
+      {}
 
       @Override
       public void focusGained(FocusEvent e)
           MessageBox mbox =
             new MessageBox(fSite.getShell(), SWT.ICON_INFORMATION
                 | SWT.APPLICATION_MODAL);
-        mbox.setText("Info");
-        mbox.setMessage("Active configuration is " + repl.getConfig().getName());
-        mbox.open();
+          mbox.setText("Info");
+          mbox.setMessage("Active configuration is " + repl.getConfig().getName());
+          mbox.open();
         }
       }
     });
     enterTrigger.addInputListener(repl);
     replConsole.getTextWidget().addVerifyKeyListener(enterTrigger);
     replConsole.setPrompt(
-        new Prompt("CL-USER>","prompt","0",null,null,SWT.BOLD,false));
+        new Prompt("CL-USER>","prompt","0",
+            ReplViewPlugin.get().getPromptColor(),null,SWT.BOLD,false));
     replConsole.startEdit();
     repl.disconnected();
     if( process.getSwank().isConnected() )
   public void dispose()
   {
     JFaceResources.getFontRegistry().removeListener(fontListener);
+    ReplViewPlugin.get().removeResetColorListener(this);
     repl.dispose();
   }
 
     }
   }
 
+  @Override
+  public void handleResetColors()
+  {
+    //TODO: reset all appropriate colors in viewer
+  }
+
 }

org.lispdev.replview/src/org/lispdev/replview/ReplPreferencePage.java

+package org.lispdev.replview;
+
+import org.eclipse.ui.IWorkbench;
+import org.lispdev.preferences.ItemPreferencesPage;
+
+public class ReplPreferencePage extends ItemPreferencesPage
+{
+
+  public ReplPreferencePage()
+  {
+    super(ReplViewPlugin.get().getPreferences(), GRID, "REPL settings", null);
+  }
+
+  @Override
+  protected void createFieldEditors()
+  {
+    for( Preference p : Preference.replColors() )
+    {
+      addDefaultItemField(p.item());
+    }
+  }
+
+  @Override
+  public void init(IWorkbench workbench)
+  {
+  }
+
+}

org.lispdev.replview/src/org/lispdev/replview/ReplViewPlugin.java

 package org.lispdev.replview;
 
+import org.eclipse.core.runtime.ListenerList;
+import org.eclipse.core.runtime.preferences.DefaultScope;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.RGB;
 import org.eclipse.ui.plugin.AbstractUIPlugin;
+import org.lispdev.log.Log;
+import org.lispdev.preferences.ItemListener;
+import org.lispdev.preferences.PreferenceItem;
+import org.lispdev.preferences.PreferencesPlugin;
+import org.lispdev.preferences.PreferencesService;
 import org.osgi.framework.BundleContext;
 
 /**
     return plugin;
   }
 
+  /// preferences
+  /**
+   * The unique project-independent preferences service for this plugin.
+   * Uses whatever this plugin activator's getLanguageID() method returns
+   * as the language.
+   */
+  protected PreferencesService prefServices = null;
+
+  public PreferencesService getPreferences()
+  {
+    if( prefServices == null )
+    {
+      prefServices = new PreferencesService(PreferencesPlugin.LangID);
+      // To trigger the automatic invocation of the preferences initializer:
+      try
+      {
+        new DefaultScope().getNode(ID);
+      }
+      catch(Exception e)
+      {
+        // If this ever happens, it will probably be because the preferences
+        // and their initializer haven't been defined yet. In that situation
+        // there's not really anything to do--you can't initialize preferences
+        // that don't exist. So swallow the exception and continue ...
+      }
+      Preference.init(prefServices);
+      for( Preference p : Preference.replColors() )
+      {
+        p.item().addListener(getPreferences(), replPreferenceListener);
+      }
+    }
+    return prefServices;
+  }
+
+  private final ReplPreferenceListener replPreferenceListener =
+    new ReplPreferenceListener();
+
+  private class ReplPreferenceListener implements ItemListener
+  {
+    @Override
+    public void handleChange(PreferenceItem item, Object oldValue, Object newValue)
+    {
+      resetColors();
+    }
+  }
+
+  private boolean activatedColors = false;
+  private Color inspectableColor;
+  private Color promptColor;
+
+  private void resetColors()
+  {
+    PreferencesService service = getPreferences();
+    final ColorManager cm = getColorManager();
+    inspectableColor = cm.getColor(
+        (RGB)Preference.COLOR_INSPECTABLE.item().get(service));
+    promptColor = cm.getColor(
+        (RGB)Preference.COLOR_PROMPT.item().get(service));
+    activatedColors = true;
+    for( Object o : resetColorListeners.getListeners() )
+    {
+      try
+      {
+        ((IResetColorListener)o).handleResetColors();
+      }
+      catch( Exception e )
+      {
+        Log.logException(e);
+      }
+    }
+  }
+
+  public interface IResetColorListener
+  {
+    void handleResetColors();
+  }
+
+  ListenerList resetColorListeners = new ListenerList();
+
+  public void addResetColorListener(IResetColorListener listener)
+  {
+    resetColorListeners.add(listener);
+  }
+
+  public void removeResetColorListener(IResetColorListener listener)
+  {
+    resetColorListeners.remove(listener);
+  }
+
+  public Color getInspectableColor()
+  {
+    if( !activatedColors ) resetColors();
+    return inspectableColor;
+  }
+
+  public Color getPromptColor()
+  {
+    if( !activatedColors ) resetColors();
+    return promptColor;
+  }
+
+  private ColorManager colorManager;
+
+  public ColorManager getColorManager()
+  {
+    if( colorManager == null )
+    {
+      colorManager = new ColorManager();
+    }
+    return colorManager;
+  }
 }
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.