[logback-dev] svn commit: r1453 - in logbackPDE/trunk/plugins/ConsolePlugin: . src/main/java/ch/qos/logback/eclipse/actions src/main/java/ch/qos/logback/eclipse/dialog src/main/java/ch/qos/logback/eclipse/model src/main/java/ch/qos/logback/eclipse/views

noreply.seb at qos.ch noreply.seb at qos.ch
Thu Mar 22 17:40:10 CET 2007


Author: seb
Date: Thu Mar 22 17:40:10 2007
New Revision: 1453

Modified:
   logbackPDE/trunk/plugins/ConsolePlugin/src/main/java/ch/qos/logback/eclipse/actions/LogbackPreferencesAction.java
   logbackPDE/trunk/plugins/ConsolePlugin/src/main/java/ch/qos/logback/eclipse/dialog/LogbackPreferencesDialog.java
   logbackPDE/trunk/plugins/ConsolePlugin/src/main/java/ch/qos/logback/eclipse/model/LoggingEventManager.java
   logbackPDE/trunk/plugins/ConsolePlugin/src/main/java/ch/qos/logback/eclipse/views/LogbackView.java
   logbackPDE/trunk/plugins/ConsolePlugin/src/main/java/ch/qos/logback/eclipse/views/LoggingEventLabelProvider.java
   logbackPDE/trunk/plugins/ConsolePlugin/todo.txt

Log:
Coloring one line's background in gray every two lines added to the view
It is now able to change the font's size and name.

Modified: logbackPDE/trunk/plugins/ConsolePlugin/src/main/java/ch/qos/logback/eclipse/actions/LogbackPreferencesAction.java
==============================================================================
--- logbackPDE/trunk/plugins/ConsolePlugin/src/main/java/ch/qos/logback/eclipse/actions/LogbackPreferencesAction.java	(original)
+++ logbackPDE/trunk/plugins/ConsolePlugin/src/main/java/ch/qos/logback/eclipse/actions/LogbackPreferencesAction.java	Thu Mar 22 17:40:10 2007
@@ -3,6 +3,7 @@
 import org.eclipse.jface.action.Action;
 import org.eclipse.jface.dialogs.InputDialog;
 import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.swt.graphics.FontData;
 import org.eclipse.swt.widgets.Shell;
 
 import ch.qos.logback.eclipse.dialog.LogbackPreferencesDialog;
@@ -24,7 +25,12 @@
   }
 
   public void run() {
-    LogbackPreferencesDialog dialog = new LogbackPreferencesDialog(shell, view.getPattern(), view.getServerPort());
+    FontData[] fd = view.getFont().getFontData();
+    String name = fd[0].getName();
+    int size = fd[0].getHeight();
+    
+    LogbackPreferencesDialog dialog = new LogbackPreferencesDialog(shell, view.getPattern(), 
+        view.getServerPort(), name, size);
     if (dialog.open() != InputDialog.OK) {
       return;
     }
@@ -32,9 +38,24 @@
     if (!dialog.getPattern().equals(view.getPattern())) {
       view.updatePattern(dialog.getPattern());
     }
-    
+
     if (dialog.getServerPort() != view.getServerPort()) {
       view.updateServerPort(dialog.getServerPort());
     }
+    
+    if (fontChanged(fd, dialog)) {
+      view.updateFont(dialog.getFontName(), dialog.getFontSize());
+    }
+  }
+  
+  private boolean fontChanged(FontData[] fd, LogbackPreferencesDialog dialog) {
+    String name = fd[0].getName();
+    int size = fd[0].getHeight();
+    
+    if (dialog.getFontSize() != size || !dialog.getFontName().equals(name)) {
+      return true;
+    } else {
+      return false;
+    }
   }
 }

Modified: logbackPDE/trunk/plugins/ConsolePlugin/src/main/java/ch/qos/logback/eclipse/dialog/LogbackPreferencesDialog.java
==============================================================================
--- logbackPDE/trunk/plugins/ConsolePlugin/src/main/java/ch/qos/logback/eclipse/dialog/LogbackPreferencesDialog.java	(original)
+++ logbackPDE/trunk/plugins/ConsolePlugin/src/main/java/ch/qos/logback/eclipse/dialog/LogbackPreferencesDialog.java	Thu Mar 22 17:40:10 2007
@@ -5,9 +5,11 @@
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.events.ModifyEvent;
 import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.graphics.FontData;
 import org.eclipse.swt.graphics.Rectangle;
 import org.eclipse.swt.layout.GridData;
 import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Combo;
 import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.Control;
 import org.eclipse.swt.widgets.Label;
@@ -24,14 +26,21 @@
   private String pattern;
   private int serverPort;
   private int tmpServerPort = -1;
+  private String fontName;
+  private int fontSize;
 
   private Text patternField;
   private Text portField;
+  private Text fontField;
+  private Text fontSizeField;
 
-  public LogbackPreferencesDialog(Shell parentShell, String namePattern, int serverPort) {
+  public LogbackPreferencesDialog(Shell parentShell, String namePattern, int serverPort, String fontName
+      , int fontSize) {
     super(parentShell);
     this.pattern = namePattern;
     this.serverPort = serverPort;
+    this.fontName = fontName;
+    this.fontSize = fontSize;
 
     setShellStyle(SWT.DIALOG_TRIM | SWT.RESIZE | SWT.APPLICATION_MODAL);
   }
@@ -45,7 +54,8 @@
 
     createPatternUIParts(container);
     createServerPortUIParts(container);
-
+    createFontUIParts(container);
+    
     initContent();
 
     return container;
@@ -75,6 +85,22 @@
     portField = new Text(container, SWT.BORDER);
     portField.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false));
   }
+  
+  private void createFontUIParts(Composite container) {
+    final Label fontLabel = new Label(container, SWT.None);
+    fontLabel.setLayoutData(new GridData(GridData.END, GridData.CENTER, false, false));
+    fontLabel.setText("Select the font to use");
+    
+    fontField = new Text(container, SWT.BORDER);
+    fontField.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false));
+
+    final Label sizeLabel = new Label(container, SWT.NONE);
+    sizeLabel.setLayoutData(new GridData(GridData.END, GridData.CENTER, false, false));
+    sizeLabel.setText("Enter font size");
+
+    fontSizeField = new Text(container, SWT.BORDER);
+    fontSizeField.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false));
+  }
 
   private void initContent() {
     patternField.setText(pattern != null ? pattern : "");
@@ -90,6 +116,20 @@
         tmpServerPort = Integer.parseInt(portField.getText());
       }
     });
+    
+    fontSizeField.setText(String.valueOf(fontSize));
+    fontSizeField.addModifyListener(new ModifyListener() {
+      public void modifyText(ModifyEvent e) {
+        fontSize = Integer.parseInt(fontSizeField.getText());
+      }
+    });
+    
+    fontField.setText(fontName);
+    fontField.addModifyListener(new ModifyListener() {
+      public void modifyText(ModifyEvent e) {
+        fontName = fontField.getText();
+      }
+    });   
   }
 
   protected void configureShell(Shell newShell) {
@@ -105,6 +145,14 @@
     return serverPort;
   }
 
+  public int getFontSize() {
+    return fontSize;
+  }
+  
+  public String getFontName() {
+    return fontName;
+  }
+
   @Override
   protected void okPressed() {
     if (checkServerPort()) {
@@ -124,7 +172,7 @@
       return true;
     }
   }
-  
+
   private boolean portInBounds() {
     if (tmpServerPort > 0 && tmpServerPort <= 65535) {
       return true;

Modified: logbackPDE/trunk/plugins/ConsolePlugin/src/main/java/ch/qos/logback/eclipse/model/LoggingEventManager.java
==============================================================================
--- logbackPDE/trunk/plugins/ConsolePlugin/src/main/java/ch/qos/logback/eclipse/model/LoggingEventManager.java	(original)
+++ logbackPDE/trunk/plugins/ConsolePlugin/src/main/java/ch/qos/logback/eclipse/model/LoggingEventManager.java	Thu Mar 22 17:40:10 2007
@@ -89,4 +89,8 @@
   public int getEventCount() {
     return loggingEventList.size();
   }
+  
+  public int getIndex(LoggingEvent event) {
+    return loggingEventList.indexOf(event);
+  }
 }

Modified: logbackPDE/trunk/plugins/ConsolePlugin/src/main/java/ch/qos/logback/eclipse/views/LogbackView.java
==============================================================================
--- logbackPDE/trunk/plugins/ConsolePlugin/src/main/java/ch/qos/logback/eclipse/views/LogbackView.java	(original)
+++ logbackPDE/trunk/plugins/ConsolePlugin/src/main/java/ch/qos/logback/eclipse/views/LogbackView.java	Thu Mar 22 17:40:10 2007
@@ -15,7 +15,10 @@
 import org.eclipse.jface.viewers.TableViewer;
 import org.eclipse.jface.viewers.Viewer;
 import org.eclipse.swt.SWT;
+import org.eclipse.swt.SWTError;
+import org.eclipse.swt.graphics.Font;
 import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Display;
 import org.eclipse.swt.widgets.Menu;
 import org.eclipse.swt.widgets.Table;
 import org.eclipse.swt.widgets.TableColumn;
@@ -271,5 +274,22 @@
     }
     return null;
   }
+  
+  public Font getFont() {
+    return viewer.getTable().getFont();
+  }
+  
+  public void updateFont(String fontName, int fontSize) {
+    Font font = null;
+    try {
+      font = new Font(Display.getDefault(), fontName, fontSize, SWT.NORMAL);
+    } catch (SWTError error) {
+      PluginLogger.logInfo("Desired font could not be used");
+    }
+    if (font != null) {
+      viewer.getTable().setFont(font);
+      viewer.refresh();
+    }
+  }
 
 }
\ No newline at end of file

Modified: logbackPDE/trunk/plugins/ConsolePlugin/src/main/java/ch/qos/logback/eclipse/views/LoggingEventLabelProvider.java
==============================================================================
--- logbackPDE/trunk/plugins/ConsolePlugin/src/main/java/ch/qos/logback/eclipse/views/LoggingEventLabelProvider.java	(original)
+++ logbackPDE/trunk/plugins/ConsolePlugin/src/main/java/ch/qos/logback/eclipse/views/LoggingEventLabelProvider.java	Thu Mar 22 17:40:10 2007
@@ -6,6 +6,7 @@
 import org.eclipse.jface.viewers.ITableColorProvider;
 import org.eclipse.jface.viewers.ITableLabelProvider;
 import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.swt.SWT;
 import org.eclipse.swt.graphics.Color;
 import org.eclipse.swt.graphics.Image;
 import org.eclipse.swt.widgets.Display;
@@ -16,6 +17,7 @@
 import ch.qos.logback.classic.PatternLayout;
 import ch.qos.logback.classic.spi.LoggingEvent;
 import ch.qos.logback.eclipse.LogbackPlugin;
+import ch.qos.logback.eclipse.model.LoggingEventManager;
 
 /**
  * This class creates the label that will appear in the logback window to
@@ -35,6 +37,8 @@
 
   private Color cachedRed;
   private Color cachedBlack;
+  private Color cachedWhite;
+  private Color cachedGray;
 
   private ImageDescriptor stackTrace;
   private Image stackImage;
@@ -44,8 +48,10 @@
     context.setName("Logback Plugin Context");
     createDefaultPatternLayout();
     Display display = Display.getCurrent();
-    cachedRed = new Color(display, 255, 0, 0);
-    cachedBlack = new Color(display, 0, 0, 0);
+    cachedRed = Display.getCurrent().getSystemColor(SWT.COLOR_RED);
+    cachedBlack = Display.getCurrent().getSystemColor(SWT.COLOR_BLACK);
+    cachedWhite = Display.getCurrent().getSystemColor(SWT.COLOR_WHITE);
+    cachedGray = new Color(display, 240, 240, 240);
     loadImage();
   }
 
@@ -97,12 +103,12 @@
   }
 
   public Image getColumnImage(Object element, int columnIndex) {
-    LoggingEvent event = (LoggingEvent)element;
-    
+    LoggingEvent event = (LoggingEvent) element;
+
     if (event.getThrowableInformation() != null) {
       return stackImage;
     }
-    
+
     return null;
   }
 
@@ -117,7 +123,13 @@
   }
 
   public Color getBackground(Object element, int columnIndex) {
-    return null;
+    LoggingEvent event = (LoggingEvent) element;
+    int index = LoggingEventManager.getManager().getIndex(event);
+    if (index % 2 == 0) {
+      return cachedGray;
+    } else {
+      return cachedWhite;
+    }
   }
 
   public Color getForeground(Object element, int columnIndex) {

Modified: logbackPDE/trunk/plugins/ConsolePlugin/todo.txt
==============================================================================
--- logbackPDE/trunk/plugins/ConsolePlugin/todo.txt	(original)
+++ logbackPDE/trunk/plugins/ConsolePlugin/todo.txt	Thu Mar 22 17:40:10 2007
@@ -1,23 +1,19 @@
 Logback Console Plugin - Todo List
 ==================================
 
-Color one line each two lines with a gray background.
-->LineStyleListener might do the trick (StyledText component).
-
-Stack traces with links
-
-Allow the user to choose Font and font size
-
 Color certains lines. Based on keywords and colors?
 
 Change the image when the autoScroll button is pressed
 
 DONE:
+Allow the user to choose Font and font size
+Stack traces with links
+Color one line each two lines with a gray background
 Click on a log line and display the java class that requested the log
 Allow the user to change the socket's port
 Make the viewer always display the latest lines added
 Filter logs: threshold
 Save Preferences between sessions
 Use Cyclic Buffer to allow the user to change the pattern used to display the events. When the pattern
-is changed, we clear the console and re-enter the events contained in the buffer with the new pattern.
+is changed, we clear the console and re-enter the events contained in the buffer with the new pattern
 Autoscroll use with double-buffer and stop the filling of the console when auto scroll = off



More information about the logback-dev mailing list