Font size, tab size, etc

ls://dev.artenum.com/projects/jyconsole/wishList/Font_size_tab_size_etc
Id : 265
Type : IMPROVEMENT
Reporter : Nishio Hirokazu
Assignee :
(empty node)
Priority : MINOR
Creation Date : 27 Sep 07 10:21
Last Update Date : 27 Sep 07 10:49
Resolution : UNRESOLVED
Font size, tab size, etc
Hi, I'm Nishio, now writing Jython book in Japanese. I appreciate your JyConsole, but I modified it a little to satisfy my needs.

My needs are:

  • Make letter size larger.
(I did presentation of Jython in front of 300 people and the default letter size is too small.)
  • Set tab size as 4 spaces.
  • Make font monospaced.
I contribute those patches. But it is not good patch because I was hurried. Especially font-size is not flexible...

Index: JyConsole.java
===================================================================
--- JyConsole.java	(revision 1)
+++ JyConsole.java	(working copy)
@@ -49,6 +49,7 @@
 import java.awt.Color;
 import java.awt.Component;
 import java.awt.Event;
+import java.awt.Font;
 import java.awt.Point;
 import java.awt.event.ComponentEvent;
 import java.awt.event.ComponentListener;
@@ -203,6 +204,25 @@
         // add ui in panel
         scroll = new JScrollPane(uiContent);
         add(scroll, BorderLayout.CENTER);
+
+        
+        
+        Font font = Utils.font;
+        cmdUI.setFont(font);
+        cmdLineUI.setFont(font);
+        archiveUI.setFont(font);
+        Utils.setTabWidth(archiveUI);
+
+        StyleConstants.setFontSize(
+        		cmdUI.getStyle(STYLE_NORMAL), Utils.FONT_SIZE);
+        StyleConstants.setFontSize(
+        		cmdModel.getStyle(STYLE_NORMAL), Utils.FONT_SIZE);
+        StyleConstants.setFontSize(
+        		archiveUI.getStyle(STYLE_NORMAL), Utils.FONT_SIZE);
+        StyleConstants.setFontSize(
+        		archiveModel.getStyle(STYLE_NORMAL), Utils.FONT_SIZE);
+
+        
         // Init pref
         preference = new Hashtable();
         if (System.getProperty(PREF_SCRIPT_DIR) != null) {
@@ -544,6 +564,11 @@
         setColorToStyle(STYLE_NORMAL, fg);
     }

+ public void setFontSizeToStyle(String styleName, int fontsize) { + StyleConstants.setFontSize(archiveModel.getStyle(styleName), fontsize); + StyleConstants.setFontSize(cmdModel.getStyle(styleName), fontsize); + } + public void setColorToStyle(String styleName, Color fg) { StyleConstants.setForeground(archiveModel.getStyle(styleName), fg); StyleConstants.setForeground(cmdModel.getStyle(styleName), fg); Index: ui/Prompt.java =================================================================== --- ui/Prompt.java (revision 1) +++ ui/Prompt.java (working copy) @@ -23,6 +23,7 @@ package com.artenum.jyconsole.ui;

import java.awt.Color; +import java.awt.Font; import java.awt.event.ComponentEvent; import java.awt.event.ComponentListener;

@@ -37,21 +38,26 @@ import javax.swing.JPanel; import javax.swing.JTextPane;

+import com.artenum.jyconsole.Utils; + /** * @author Sebastien Jourdain, jourdain@artenum.com */ public class Prompt extends JPanel implements ComponentListener { - private final static String l1 = ">>> "; + private final static String l1 = ">>> "; private final static String ln = "<br>… "; private JTextPane txtCmd; - private JLabel label; + private JLabel label = new JLabel();

public Prompt(JTextPane txtCmd) { setOpaque(true); - label = new JLabel(); label.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2)); showNLines(1); this.txtCmd = txtCmd; + label.setFont(Utils.font); + txtCmd.setFont(Utils.font); + Utils.setTabWidth(txtCmd); + txtCmd.addComponentListener(this); setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); add(label); Index: Utils.java =================================================================== --- Utils.java (revision 0) +++ Utils.java (revision 0) @@ -0,0 +1,36 @@ +package com.artenum.jyconsole; + +import java.awt.Font; +import java.awt.FontMetrics; + +import javax.swing.JTextPane; +import javax.swing.text.SimpleAttributeSet; +import javax.swing.text.StyleConstants; +import javax.swing.text.TabSet; +import javax.swing.text.TabStop; + +/** + * ad-hoc utility class to modify JyConsole's + * font size and tab width + * @author NISHIO Hirokazu + * + */ +public class Utils { + public static final int FONT_SIZE = 40; + public static final Font font = new Font("Monospaced", 0 , FONT_SIZE); + + public static void setTabWidth(JTextPane textpane) { + FontMetrics fm = textpane.getFontMetrics(textpane.getFont()); + int charWidth = fm.charWidth('m'); + int tabLength = charWidth * 4; + TabStop"resourceLink" href="/projects/jyconsole/wishList/Font_size_tab_size_etc">Font size, tab size, etc tabs = new TabStop"resourceLink" href="/projects/jyconsole/wishList/Font_size_tab_size_etc/10">"error">! 10 !; + for(int j=0;j<tabs.length;j++) { + tabs"resourceLink" href="/projects/jyconsole/wishList/Font_size_tab_size_etc/j">"error">! j ! = new TabStop((j+1)*tabLength); + } + TabSet tabSet = new TabSet(tabs); + SimpleAttributeSet attrs = new SimpleAttributeSet(); + StyleConstants.setTabSet(attrs, tabSet); + int l = textpane.getDocument().getLength(); + textpane.getStyledDocument().setParagraphAttributes(0, l, attrs, false); + } +}



nishio.patch 4 ko. Sep 27, 2007 10:22 AM Go to file

Upload a new file :   
4 comment(s)
comment by Jourdain Sebastien - 27 Sep 07 10:49 AM Don't worry I will make it more flexible and configurable…
comment by Jourdain Sebastien - 27 Sep 07 10:42 AM Thanks for your support I will integrate it when I will find some time…
comment by Nishio Hirokazu - 27 Sep 07 10:23 AM Please see the uploaded patch.
comment by Nishio Hirokazu - 27 Sep 07 10:22 AM OOPS, I upload patch.
Post a comment :


Decorated version - Feeds - LibreSource