[Jsxe-cvs] SF.net SVN: jsxe: [1089] branches/sourceview2
Status: Inactive
Brought to you by:
ian_lewis
From: <ian...@us...> - 2006-07-29 04:43:06
|
Revision: 1089 Author: ian_lewis Date: 2006-07-28 21:42:42 -0700 (Fri, 28 Jul 2006) ViewCVS: http://svn.sourceforge.net/jsxe/?rev=1089&view=rev Log Message: ----------- Merge from trunk/sourceview of revision 1086 ViewCVS Links: ------------- http://svn.sourceforge.net/jsxe/?rev=1086&view=rev Modified Paths: -------------- branches/sourceview2/Changelog branches/sourceview2/build.xml branches/sourceview2/dependency.props branches/sourceview2/messages/messages.de branches/sourceview2/src/org/syntax/jedit/DefaultInputHandler.java branches/sourceview2/src/org/syntax/jedit/InputHandler.java branches/sourceview2/src/org/syntax/jedit/JEditTextArea.java branches/sourceview2/src/org/syntax/jedit/TextAreaPainter.java branches/sourceview2/src/sourceview/SourceView.java branches/sourceview2/src/sourceview/SourceViewDocument.java branches/sourceview2/src/sourceview/SourceViewPlugin.java branches/sourceview2/src/sourceview/SourceViewSearchDialog.java branches/sourceview2/src/sourceview/action/EditCopyAction.java branches/sourceview2/src/sourceview/action/EditCutAction.java branches/sourceview2/src/sourceview/action/EditFindAction.java branches/sourceview2/src/sourceview/action/EditPasteAction.java branches/sourceview2/src/sourceview/sourceview.props Added Paths: ----------- branches/sourceview2/messages/messages branches/sourceview2/messages/messages.en_GB branches/sourceview2/messages/messages.ja branches/sourceview2/src/sourceview/SourceViewOptionPane.java branches/sourceview2/src/sourceview/SourceViewSearch.java branches/sourceview2/src/sourceview/action/EditFindNextAction.java Removed Paths: ------------- branches/sourceview2/messages/messages.en branches/sourceview2/src/sourceview/SourceViewOptionsPanel.java Modified: branches/sourceview2/Changelog =================================================================== --- branches/sourceview2/Changelog 2006-07-29 04:41:34 UTC (rev 1088) +++ branches/sourceview2/Changelog 2006-07-29 04:42:42 UTC (rev 1089) @@ -1,3 +1,40 @@ +07/26/2006 Ian Lewis <Ian...@me...> + + * Addded support for the findnext action + +07/21/2006 Ian Lewis <Ian...@me...> + + * Added better horizontal scrolling support. It isn't perfect because + it's hard to know the true width of the line because parts of it + can have bold text while other parts don't. + +07/20/2006 Ian Lewis <Ian...@me...> + + * Added Japanese translation + * Fixed syntax highlighting colors when you first load jsXe + +07/06/2006 Ian Lewis <Ian...@me...> + + * Updated to support the new Messages format. + +06/23/2006 Ian Lewis <Ian...@me...> + + * Added back rudimentary key bindings using Swing Actions so they get + dispached by Swing and are displayed in menus. But infrastructure is + in place to allow jsXe to catch key bindings itself. + +06/20/2006 Ian Lewis <Ian...@me...> + + * Updated the sourceview's actions to extend the new LocalizedAction class. + +06/13/2006 Ian Lewis <Ian...@me...> + + * Updated the source view options panel to extend AbstractOptionPane + +06/09/2006 Ian Lewis <Ian...@me...> + + * Updated version and dependency info + 06/03/2006 Ian Lewis <Ian...@me...> * Updated the SourceView to use the new XMLDocumentListener interface Modified: branches/sourceview2/build.xml =================================================================== --- branches/sourceview2/build.xml 2006-07-29 04:41:34 UTC (rev 1088) +++ branches/sourceview2/build.xml 2006-07-29 04:42:42 UTC (rev 1089) @@ -1,7 +1,10 @@ <?xml version="1.0" encoding="UTF-8"?> <!-- - This is a build.xml file for building the Source View for jsXe. - Version: $Id$ + :tabSize=2:indentSize=2:noTabs=true: + :folding=explicit:collapseFolds=1: + + This is a build.xml file for building the Source View for jsXe. + Version: $Id$ --> <project basedir="." default="usage" name="sourceview"> @@ -26,6 +29,7 @@ <property name="build.help" value="${build.docs}/help"/> <property name="jsxe.dir" value="${root.dir}/../.."/> <property name="jsxe.jar" value="${jsxe.dir}/jsXe.jar"/> + <property name="jsxe.lib.dir" value="${jsxe.dir}/../lib"/> <property name="javac.debug" value="on"/> <property name="javac.optimize" value="off"/> <property name="javac.deprecation" value="on"/> @@ -34,7 +38,7 @@ <property name="javadoc.link" value="http://java.sun.com/j2se/1.3/docs/api/"/> <property name="main.class" value="sourceview.SourceViewPlugin"/> <property name="major.version" value="0"/> - <property name="minor.version" value="4"/> + <property name="minor.version" value="5"/> <property name="build.version" value="3"/> <property name="app.version" value="${major.version}.${minor.version}.${build.version}"/> <property name="app_version" value="${major.version}_${minor.version}_${build.version}"/> @@ -47,6 +51,9 @@ <pathelement location="${build.src}"/> <pathelement location="${src.dir}"/> <pathelement location="${jsxe.jar}"/> + <fileset dir="${jsxe.lib.dir}"> + <include name="**/*.jar"/> + </fileset> </path> <echo message="${readable.name} ${app.version}"/> <echo message="----------------------------------------------------------"/> @@ -67,11 +74,15 @@ <target depends="init" name="prepare"> <mkdir dir="${build.dir}"/> <mkdir dir="${build.messages}"/> - <copy todir="${build.messages}"> + + <!--<copy todir="${build.messages}"> <fileset dir="${messages.dir}"> <include name="**/messages.*"/> </fileset> - </copy> + </copy>--> + + <!-- run native2ascii on these files --> + <native2ascii encoding="UTF-8" src="${messages.dir}" dest="${build.messages}" includes="messages*"/> </target> <!-- }}} --> <!-- {{{ ============ Prepares the documentation ======================= --> @@ -133,7 +144,7 @@ <jar jarfile="${root.dir}/../${app.name}.jar" manifest="${app.name}.manifest"> <fileset dir="${build.dir}"> - <include name="messages/messages.*"/> + <include name="messages/messages*"/> </fileset> <fileset dir="${build.dest}"> <include name="**/*.class"/> Modified: branches/sourceview2/dependency.props =================================================================== --- branches/sourceview2/dependency.props 2006-07-29 04:41:34 UTC (rev 1088) +++ branches/sourceview2/dependency.props 2006-07-29 04:42:42 UTC (rev 1089) @@ -1 +1 @@ -dependency.0=jsxe 00.04.03.00 +dependency.0=jsxe 00.05.03.00 Copied: branches/sourceview2/messages/messages (from rev 1084, trunk/sourceview/messages/messages) =================================================================== --- branches/sourceview2/messages/messages (rev 0) +++ branches/sourceview2/messages/messages 2006-07-29 04:42:42 UTC (rev 1089) @@ -0,0 +1,33 @@ +# JSXE source view English properties file +# $Id$ +#:mode=properties: +#:tabSize=4:indentSize=4:noTabs=true: +#:folding=explicit:collapseFolds=1 + +#{{{ Source View Options +SourceView.Options.Title=Source View +SourceView.Options.EndOfLineMarker=End of line markers +SourceView.Syntax.Object=Node Type +SourceView.Syntax.Style=Text Style +SourceView.ColorChooser.Title=Color Chooser +SourceView.Markup=Markup +SourceView.Invalid=Invalid +#}}} + +#{{{ Style Editor +SourceView.StyleEditor.Title=Style Editor +SourceView.StyleEditor.Color=Text Color +SourceView.StyleEditor.Bold=Bold +SourceView.StyleEditor.Italics=Italics +#}}} + +#{{{ Find Dialog +SourceView.Find.title and Replace +SourceView.Ignore.Case=Ignore Case +SourceView.Search.For=Search for: +SourceView.Replace.With=Replace With: +SourceView.Replace.And.Find=Replace&Find +SourceView.No.More.Matches.title=No More Matches +SourceView.No.More.Matches.message="No more matches were found. Continue search from the beginning?" +SourceView.Search.Error.title=Search Error +#}}} \ No newline at end of file Modified: branches/sourceview2/messages/messages.de =================================================================== --- branches/sourceview2/messages/messages.de 2006-07-29 04:41:34 UTC (rev 1088) +++ branches/sourceview2/messages/messages.de 2006-07-29 04:42:42 UTC (rev 1089) @@ -5,22 +5,22 @@ #:tabSize=4:indentSize=4:noTabs=true: #:folding=explicit:collapseFolds=1: -#{{{ Source View +# ä Ä é ö Ö ü Ü ß #{{{ Source View Options SourceView.Options.Title=Source View Optionen SourceView.Syntax.Object=Knoten Typ SourceView.Syntax.Style=Text Stil -SourceView.Syntax.ToolTip=Dieses Tool erm�glicht es, den Font f�r verschiedene Knoten zu setzen. -SourceView.ColorChooser.Title=Farbw�hler +SourceView.Syntax.ToolTip=Dieses Tool ermöglicht es, den Font für verschiedene Knoten zu setzen. +SourceView.ColorChooser.Title=Farbwähler SourceView.Markup=Markup -SourceView.Invalid=Ung�ltig +SourceView.Invalid=Ungültig #}}} #{{{ Style Editor SourceView.StyleEditor.Title=Stil Editor SourceView.StyleEditor.Color=Textfarbe -SourceView.StyleEditor.Color.ToolTip=<HTML>Die Farbe dieses Knoten Typs kann hier ge�ndert werden. <BR>H�ckchen dieser Box entfernen setzten die Farbe zu schwarz zur�ck. <BR>Die rechteckige Box neben diesr Auswahl, kann<BR> benutzt werden um verschiedene Farben auszuw�hlen.</HTML> +SourceView.StyleEditor.Color.ToolTip=<HTML>Die Farbe dieses Knoten Typs kann hier geändert werden. <BR>H�ckchen dieser Box entfernen setzten die Farbe zu schwarz zurück. <BR>Die rechteckige Box neben diesr Auswahl, kann<BR> benutzt werden um verschiedene Farben auszuwählen.</HTML> SourceView.StyleEditor.Bold=Fett SourceView.StyleEditor.Bold.ToolTip=schaltet Fettdruck an/aus SourceView.StyleEditor.Italics=Kursiv @@ -28,5 +28,3 @@ #}}} -#}}} - Deleted: branches/sourceview2/messages/messages.en =================================================================== --- branches/sourceview2/messages/messages.en 2006-07-29 04:41:34 UTC (rev 1088) +++ branches/sourceview2/messages/messages.en 2006-07-29 04:42:42 UTC (rev 1089) @@ -1,27 +0,0 @@ -# JSXE source view English properties file -# $Id$ -#:mode=properties: -#:tabSize=4:indentSize=4:noTabs=true: -#:folding=explicit:collapseFolds=1 - -#{{{ Source View - -#{{{ Source View Options -SourceView.Options.Title=Source View Options -SourceView.Options.EndOfLineMarker=End of line markers -SourceView.Syntax.Object=Node Type -SourceView.Syntax.Style=Text Style -SourceView.ColorChooser.Title=Color Chooser -SourceView.Markup=Markup -SourceView.Invalid=Invalid -#}}} - -#{{{ Style Editor -SourceView.StyleEditor.Title=Style Editor -SourceView.StyleEditor.Color=Text Color -SourceView.StyleEditor.Bold=Bold -SourceView.StyleEditor.Italics=Italics -#}}} - -#}}} - Copied: branches/sourceview2/messages/messages.en_GB (from rev 1084, trunk/sourceview/messages/messages.en_GB) =================================================================== --- branches/sourceview2/messages/messages.en_GB (rev 0) +++ branches/sourceview2/messages/messages.en_GB 2006-07-29 04:42:42 UTC (rev 1089) @@ -0,0 +1,13 @@ +# JSXE source view British English properties file +# $Id: messages 996 2006-07-07 03:46:52Z ian_lewis $ +#:mode=properties: +#:tabSize=4:indentSize=4:noTabs=true: +#:folding=explicit:collapseFolds=1 + +#{{{ Source View Options +SourceView.ColorChooser.Title=Colour Chooser +#}}} + +#{{{ Style Editor +SourceView.StyleEditor.Color=Text Colour +#}}} Copied: branches/sourceview2/messages/messages.ja (from rev 1084, trunk/sourceview/messages/messages.ja) =================================================================== --- branches/sourceview2/messages/messages.ja (rev 0) +++ branches/sourceview2/messages/messages.ja 2006-07-29 04:42:42 UTC (rev 1089) @@ -0,0 +1,13 @@ +# JSXE source view Japanese properties file +# $Id$ +# Maintained by Ian Lewis +#:mode=properties: +#:tabSize=4:indentSize=4:noTabs=true: +#:folding=explicit:collapseFolds=1: + +#{{{ Source View Options +SourceView.Options.Title=ソース表示 +SourceView.Syntax.Object=ノードタイプ +SourceView.Markup=マーク付け +SourceView.Invalid=無効 +#}}} Modified: branches/sourceview2/src/org/syntax/jedit/DefaultInputHandler.java =================================================================== --- branches/sourceview2/src/org/syntax/jedit/DefaultInputHandler.java 2006-07-29 04:41:34 UTC (rev 1088) +++ branches/sourceview2/src/org/syntax/jedit/DefaultInputHandler.java 2006-07-29 04:42:42 UTC (rev 1089) @@ -78,9 +78,9 @@ addKeyBinding("C+ENTER",REPEAT); // Clipboard - addKeyBinding("C+C", CLIP_COPY); - addKeyBinding("C+V", CLIP_PASTE); - addKeyBinding("C+X", CLIP_CUT); + // addKeyBinding("C+C", CLIP_COPY); + // addKeyBinding("C+V", CLIP_PASTE); + // addKeyBinding("C+X", CLIP_CUT); } /** Modified: branches/sourceview2/src/org/syntax/jedit/InputHandler.java =================================================================== --- branches/sourceview2/src/org/syntax/jedit/InputHandler.java 2006-07-29 04:41:34 UTC (rev 1088) +++ branches/sourceview2/src/org/syntax/jedit/InputHandler.java 2006-07-29 04:42:42 UTC (rev 1089) @@ -142,10 +142,10 @@ */ public static String getActionName(ActionListener listener) { - Enumeration enum = getActions(); - while(enum.hasMoreElements()) + Enumeration actions = getActions(); + while(actions.hasMoreElements()) { - String name = (String)enum.nextElement(); + String name = (String)actions.nextElement(); ActionListener _listener = getAction(name); if(_listener == listener) return name; Modified: branches/sourceview2/src/org/syntax/jedit/JEditTextArea.java =================================================================== --- branches/sourceview2/src/org/syntax/jedit/JEditTextArea.java 2006-07-29 04:41:34 UTC (rev 1088) +++ branches/sourceview2/src/org/syntax/jedit/JEditTextArea.java 2006-07-29 04:42:42 UTC (rev 1089) @@ -6,7 +6,6 @@ Copyright (C) 1999 Slava Pestov Copyright (C) 2002 Ian Lewis (Ian...@me...) - You may use and modify this package for any purpose. Redistribution is permitted, in both source and binary form, provided that this notice remains intact in all source distributions of this package. @@ -252,21 +251,18 @@ * if the number of lines in the document changes, or when the * size of the text are changes. */ - public void updateScrollBars() - { - if(vertical != null && visibleLines != 0) - { + public void updateScrollBars() { + if (vertical != null && visibleLines != 0) { vertical.setValues(firstLine,visibleLines,0,getLineCount()); vertical.setUnitIncrement(2); vertical.setBlockIncrement(visibleLines); } - int width = painter.getWidth(); - if(horizontal != null && width != 0) - { - horizontal.setValues(-horizontalOffset,width,0,width * 5); - horizontal.setUnitIncrement(painter.getFontMetrics() - .charWidth('w')); + if (horizontal != null && width != 0) { + // Log.log(Log.DEBUG, this, "value: "+ (-horizontalOffset)); + + horizontal.setValue(-horizontalOffset); + horizontal.setUnitIncrement(painter.getFontMetrics().charWidth('w')); horizontal.setBlockIncrement(width / 2); } } @@ -330,13 +326,14 @@ * implement horizontal scrolling. * @param horizontalOffset offset The new horizontal offset */ - public void setHorizontalOffset(int horizontalOffset) - { - if(horizontalOffset == this.horizontalOffset) + public void setHorizontalOffset(int horizontalOffset) { + if (horizontalOffset == this.horizontalOffset) { return; + } this.horizontalOffset = horizontalOffset; - if(horizontalOffset != horizontal.getValue()) + if (horizontalOffset != horizontal.getValue()) { updateScrollBars(); + } painter.repaint(); } @@ -1604,6 +1601,8 @@ protected int magicCaret; protected boolean overwrite; protected boolean rectSelect; + + private int maxHorizontalScrollWidth; protected void fireCaretEvent() { @@ -2132,6 +2131,51 @@ return false; } } + + //{{{ updateMaxHorizontalScrollWidth() method + void updateMaxHorizontalScrollWidth() { + + int max = 0; + + for (int i = firstLine; i < firstLine + visibleLines && i < getLineCount(); i++) { + /* + TODO: This is broken since some parts of the line can be bold and + thus be wider than other parts of the line. Need to implement + a chunk cache like jEdit has. + */ + int width = (int)Math.round( + painter.getFont().deriveFont(Font.BOLD).getStringBounds(getLineText(i), + new java.awt.font.FontRenderContext(null,false,false)).getWidth()); + if (width > max) { + max = width; + } + } + + int _tabSize = ((Integer)getDocument().getProperty(PlainDocument.tabSizeAttribute)).intValue(); + char[] foo = new char[] { ' ' }; + + int charWidth = (int)Math.round( + painter.getFont().getStringBounds(foo,0,1, + new java.awt.font.FontRenderContext(null,false,false)).getWidth()); + + // Log.log(Log.DEBUG, this, "value: "+ Math.max(0, + // Math.min(maxHorizontalScrollWidth /*+ charWidth*/ + // - painter.getWidth(), + // -horizontalOffset)) + // +" extent: "+painter.getWidth() + // +" min: "+0 + // +" max: "+max); + if (max != maxHorizontalScrollWidth) { + maxHorizontalScrollWidth = max; + horizontal.setValues(Math.max(0, + Math.min(maxHorizontalScrollWidth + charWidth + - painter.getWidth(), + -horizontalOffset)), + painter.getWidth(), + 0,maxHorizontalScrollWidth + + charWidth); + } + } //}}} //{{{ WheelScrollListener class static class MouseWheelHandler implements MouseWheelListener { Modified: branches/sourceview2/src/org/syntax/jedit/TextAreaPainter.java =================================================================== --- branches/sourceview2/src/org/syntax/jedit/TextAreaPainter.java 2006-07-29 04:41:34 UTC (rev 1088) +++ branches/sourceview2/src/org/syntax/jedit/TextAreaPainter.java 2006-07-29 04:42:42 UTC (rev 1089) @@ -1,14 +1,32 @@ /* - * TextAreaPainter.java - Paints the text area - * Copyright (C) 1999 Slava Pestov - * - * 08/05/2002 Cursor (caret) rendering fixed for JDK 1.4 (Anonymous) - * - * You may use and modify this package for any purpose. Redistribution is - * permitted, in both source and binary form, provided that this notice - * remains intact in all source distributions of this package. - */ +TextAreaPainter.java +:tabSize=4:indentSize=4:noTabs=true: +:folding=explicit:collapseFolds=1: +Copyright (C) 1999 Slava Pestov +Copyright (C) 2002 Ian Lewis (Ian...@me...) + +You may use and modify this package for any purpose. Redistribution is +permitted, in both source and binary form, provided that this notice +remains intact in all source distributions of this package. + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +Optionally, you may find a copy of the GNU General Public License +from http://www.fsf.org/copyleft/gpl.txt +*/ + package org.syntax.jedit; import org.syntax.jedit.tokenmarker.*; @@ -25,6 +43,8 @@ * The text area repaint manager. It performs double buffering and paints * lines of text. * @author Slava Pestov + * @author Ian Lewis (<a href="mailto:Ian...@me...">Ian...@me...</a>) + * * @version $Id$ */ public class TextAreaPainter extends JComponent implements TabExpander @@ -47,7 +67,7 @@ currentLineIndex = -1; setCursor(Cursor.getPredefinedCursor(Cursor.TEXT_CURSOR)); - + setFont(new Font("Monospaced",Font.PLAIN,14)); setForeground(Color.black); setBackground(Color.white); @@ -66,7 +86,28 @@ eolMarkerColor = defaults.eolMarkerColor; eolMarkers = defaults.eolMarkers; } + + //{{{ setBounds() method + /** + * It is a bad idea to override this, but we need to get the component + * event before the first repaint. + */ + public void setBounds(int x, int y, int width, int height) { + if (x == getX() && y == getY() && width == getWidth() && height == getHeight()) { + return; + } + super.setBounds(x,y,width,height); + + textArea.recalculateVisibleLines(); + // if (textArea.getBuffer().isLoaded()) { + // textArea.recalculateLastPhysicalLine(); + // } + // textArea.propertiesChanged(); + textArea.updateMaxHorizontalScrollWidth(); + textArea.scrollBarsInitialized = true; + } //}}} + /** * Returns if this component can be traversed by pressing the * Tab key. This returns false. @@ -352,8 +393,7 @@ * cached font metrics and to recalculate which lines are visible. * @param font The font */ - public void setFont(Font font) - { + public void setFont(Font font) { super.setFont(font); //TODO: this is deprecated, figure out how to do it the right way. fm = Toolkit.getDefaultToolkit().getFontMetrics(font); @@ -364,10 +404,8 @@ * Repaints the text. * @param g The graphics context */ - public void paint(Graphics gfx) - { - tabSize = fm.charWidth(' ') * ((Integer)textArea - .getDocument().getProperty( + public void paint(Graphics gfx) { + tabSize = fm.charWidth(' ') * ((Integer)textArea.getDocument().getProperty( PlainDocument.tabSizeAttribute)).intValue(); Rectangle clipRect = gfx.getClipBounds(); @@ -385,25 +423,22 @@ // too many lines will always be painted. int lastInvalid = firstLine + (clipRect.y + clipRect.height - 1) / height; - try - { - TokenMarker tokenMarker = textArea.getDocument() - .getTokenMarker(); + try { + TokenMarker tokenMarker = textArea.getDocument().getTokenMarker(); int x = textArea.getHorizontalOffset(); - for(int line = firstInvalid; line <= lastInvalid; line++) - { + for(int line = firstInvalid; line <= lastInvalid; line++) { paintLine(gfx,tokenMarker,line,x); } - if(tokenMarker != null && tokenMarker.isNextLineRequested()) - { + if (tokenMarker != null && tokenMarker.isNextLineRequested()) { int h = clipRect.y + clipRect.height; repaint(0,h,getWidth(),getHeight() - h); } - } - catch(Exception e) - { + + textArea.updateMaxHorizontalScrollWidth(); + + } catch(Exception e) { System.err.println("Error repainting line" + " range {" + firstInvalid + "," + lastInvalid + "}:"); @@ -502,7 +537,7 @@ protected FontMetrics fm; protected Highlight highlights; - + protected void paintLine(Graphics gfx, TokenMarker tokenMarker, int line, int x) { @@ -696,7 +731,7 @@ fm.getHeight() - 1); } -protected void paintCaret(Graphics gfx, int line, int y) + protected void paintCaret(Graphics gfx, int line, int y) { if(textArea.isCaretVisible()) { Modified: branches/sourceview2/src/sourceview/SourceView.java =================================================================== --- branches/sourceview2/src/sourceview/SourceView.java 2006-07-29 04:41:34 UTC (rev 1088) +++ branches/sourceview2/src/sourceview/SourceView.java 2006-07-29 04:42:42 UTC (rev 1089) @@ -34,12 +34,11 @@ //{{{ jsXe classes import net.sourceforge.jsxe.*; import net.sourceforge.jsxe.gui.Messages; -import net.sourceforge.jsxe.gui.OptionsPanel; import net.sourceforge.jsxe.gui.DocumentView; import net.sourceforge.jsxe.dom.AdapterNode; import net.sourceforge.jsxe.dom.XMLDocument; import net.sourceforge.jsxe.dom.XMLDocumentListener; -import net.sourceforge.jsxe.dom.XMLDocumentEvent; +import net.sourceforge.jsxe.msg.PropertyChanged; import net.sourceforge.jsxe.util.Log; import net.sourceforge.jsxe.util.MiscUtilities; //}}} @@ -82,19 +81,11 @@ * @author Ian Lewis (<a href="mailto:Ian...@me...">Ian...@me...</a>) * @version $Id$ */ -public class SourceView extends JPanel implements DocumentView { +public class SourceView extends JPanel implements DocumentView, EBListener { - // Temporary Hack - protected static ArrayList m_sourceviews = new ArrayList(); - - //{{{ Private static members - private static final String _VIEWNAME = "source"; - //}}} - //{{{ Public static members - public static final String SOFT_TABS = _VIEWNAME+".soft.tabs"; - public static final String LAST_FIND_STRING = _VIEWNAME+".last.find.string"; - public static final String END_OF_LINE_MARKS = _VIEWNAME+".end-of-line-markers"; + public static final String SOFT_TABS = SourceViewPlugin.PLUGIN_NAME+".soft.tabs"; + public static final String END_OF_LINE_MARKS = SourceViewPlugin.PLUGIN_NAME+".end-of-line-markers"; //}}} //{{{ SourceView constructor @@ -118,19 +109,19 @@ TextAreaPainter painter = m_textarea.getPainter(); painter.setEOLMarkersPainted(jsXe.getBooleanProperty(SourceView.END_OF_LINE_MARKS, true)); painter.setStyles( - new SyntaxStyle[] { SourceViewOptionsPanel.parseStyle(jsXe.getProperty("source.text.color")), - SourceViewOptionsPanel.parseStyle(jsXe.getProperty("source.comment.color")), - SourceViewOptionsPanel.parseStyle(jsXe.getProperty("source.doctype.color")), - SourceViewOptionsPanel.parseStyle(jsXe.getProperty("source.attribute.value.color")), - SourceViewOptionsPanel.parseStyle(jsXe.getProperty("source.attribute.value.color")), - SourceViewOptionsPanel.parseStyle(jsXe.getProperty("source.cdata.color")), - SourceViewOptionsPanel.parseStyle(jsXe.getProperty("source.entity.reference.color")), - SourceViewOptionsPanel.parseStyle(jsXe.getProperty("source.element.color")), - SourceViewOptionsPanel.parseStyle(jsXe.getProperty("source.attribute.color")), - SourceViewOptionsPanel.parseStyle(jsXe.getProperty("source.processing.instruction.color")), - SourceViewOptionsPanel.parseStyle(jsXe.getProperty("source.namespace.prefix.color")), - SourceViewOptionsPanel.parseStyle(jsXe.getProperty("source.markup.color")), - SourceViewOptionsPanel.parseStyle(jsXe.getProperty("source.invalid.color")), + new SyntaxStyle[] { SourceViewOptionPane.parseStyle(jsXe.getProperty("sourceview.text.color")), + SourceViewOptionPane.parseStyle(jsXe.getProperty("sourceview.comment.color")), + SourceViewOptionPane.parseStyle(jsXe.getProperty("sourceview.doctype.color")), + SourceViewOptionPane.parseStyle(jsXe.getProperty("sourceview.attribute.value.color")), + SourceViewOptionPane.parseStyle(jsXe.getProperty("sourceview.attribute.value.color")), + SourceViewOptionPane.parseStyle(jsXe.getProperty("sourceview.cdata.color")), + SourceViewOptionPane.parseStyle(jsXe.getProperty("sourceview.entity.reference.color")), + SourceViewOptionPane.parseStyle(jsXe.getProperty("sourceview.element.color")), + SourceViewOptionPane.parseStyle(jsXe.getProperty("sourceview.attribute.color")), + SourceViewOptionPane.parseStyle(jsXe.getProperty("sourceview.processing.instruction.color")), + SourceViewOptionPane.parseStyle(jsXe.getProperty("sourceview.namespace.prefix.color")), + SourceViewOptionPane.parseStyle(jsXe.getProperty("sourceview.markup.color")), + SourceViewOptionPane.parseStyle(jsXe.getProperty("sourceview.invalid.color")), }); // textarea.setFont(new Font("Monospaced", 0, 12)); m_textarea.setCaretPosition(0); @@ -142,15 +133,17 @@ //{{{ create popup menu JPopupMenu popup = new JPopupMenu(); - JMenuItem menuItem = new JMenuItem(jsXe.getAction("sourceview.cut")); + JMenuItem menuItem = new JMenuItem(ActionManager.getAction("cut")); popup.add(menuItem); - menuItem = new JMenuItem(jsXe.getAction("sourceview.copy")); + menuItem = new JMenuItem(ActionManager.getAction("copy")); popup.add(menuItem); - menuItem = new JMenuItem(jsXe.getAction("sourceview.paste")); + menuItem = new JMenuItem(ActionManager.getAction("paste")); popup.add(menuItem); popup.addSeparator(); - menuItem = new JMenuItem(jsXe.getAction("sourceview.find")); + menuItem = new JMenuItem(ActionManager.getAction("find")); popup.add(menuItem); + menuItem = new JMenuItem(ActionManager.getAction("findnext")); + popup.add(menuItem); m_textarea.setRightClickPopup(popup); //}}} @@ -169,21 +162,19 @@ // menuItem.addActionListener( new EditRedoAction() ); // menu.add(menuItem); // menu.addSeparator(); - menuItem = new JMenuItem(jsXe.getAction("sourceview.cut")); + menuItem = new JMenuItem(ActionManager.getAction("cut")); m_editMenu.add(menuItem); - menuItem = new JMenuItem(jsXe.getAction("sourceview.copy")); + menuItem = new JMenuItem(ActionManager.getAction("copy")); m_editMenu.add(menuItem); - menuItem = new JMenuItem(jsXe.getAction("sourceview.paste")); + menuItem = new JMenuItem(ActionManager.getAction("paste")); m_editMenu.add(menuItem); m_editMenu.addSeparator(); - menuItem = new JMenuItem(jsXe.getAction("sourceview.find")); + menuItem = new JMenuItem(ActionManager.getAction("find")); m_editMenu.add(menuItem); - // menuItem = new JMenuItem(new EditFindNextAction()); - // menu.add(menuItem); + menuItem = new JMenuItem(ActionManager.getAction("findnext")); + m_editMenu.add(menuItem); //}}} - m_sourceviews.add(this); - setDocumentBuffer(document); //focus on the text area the first time the view is shown @@ -202,8 +193,39 @@ });//}}} + EditBus.addToBus(this); }//}}} + //{{{ handleMessage() + public void handleMessage(EBMessage message) { + if (message instanceof PropertyChanged) { + String key = ((PropertyChanged)message).getKey(); + TextAreaPainter painter = getTextArea().getPainter(); + if (key.equals("source.end-of-line-markers")) { + painter.setEOLMarkersPainted(jsXe.getBooleanProperty("source.end-of-line-markers", false)); + } + + if (key.startsWith("source.") && key.endsWith(".color")) { + painter.setStyles( + new SyntaxStyle[] { + SourceViewOptionPane.parseStyle(jsXe.getProperty("source.text.color")), + SourceViewOptionPane.parseStyle(jsXe.getProperty("source.comment.color")), + SourceViewOptionPane.parseStyle(jsXe.getProperty("source.doctype.color")), + SourceViewOptionPane.parseStyle(jsXe.getProperty("source.attribute.value.color")), + SourceViewOptionPane.parseStyle(jsXe.getProperty("source.attribute.value.color")), + SourceViewOptionPane.parseStyle(jsXe.getProperty("source.cdata.color")), + SourceViewOptionPane.parseStyle(jsXe.getProperty("source.entity.reference.color")), + SourceViewOptionPane.parseStyle(jsXe.getProperty("source.element.color")), + SourceViewOptionPane.parseStyle(jsXe.getProperty("source.attribute.color")), + SourceViewOptionPane.parseStyle(jsXe.getProperty("source.processing.instruction.color")), + SourceViewOptionPane.parseStyle(jsXe.getProperty("source.namespace.prefix.color")), + SourceViewOptionPane.parseStyle(jsXe.getProperty("source.markup.color")), + SourceViewOptionPane.parseStyle(jsXe.getProperty("source.invalid.color")), + }); + } + } + }//}}} + //{{{ getTextArea() public JEditTextArea getTextArea() { @@ -226,7 +248,6 @@ dialog.dispose(); } m_document.removeXMLDocumentListener(docListener); - m_sourceviews.remove(this); return true; }//}}} @@ -285,52 +306,6 @@ //{{{ Private members - //{{{ EditUndoAction class - - private class EditUndoAction implements ActionListener { - - //{{{ actionPerformed() - - public void actionPerformed(ActionEvent e) { - //undo does nothing for now - }//}}} - - }//}}} - - //{{{ EditRedoAction class - - private class EditRedoAction implements ActionListener { - - //{{{ actionPerformed() - - public void actionPerformed(ActionEvent e) { - //redo action does nothing for now. - }//}}} - - }//}}} - - //{{{ EditFindNextAction class - - private class EditFindNextAction extends AbstractAction { - - //{{{ EditFindNextAction constructor - - public EditFindNextAction() { - //putValue(Action.NAME, "Find Next"); - putValue(Action.NAME, Messages.getMessage("SourceView.FindNext")); - putValue(Action.ACCELERATOR_KEY,KeyStroke.getKeyStroke("ctrl G")); - putValue(Action.MNEMONIC_KEY, new Integer(KeyStroke.getKeyStroke("N").getKeyCode())); - }//}}} - - //{{{ actionPerformed() - - public void actionPerformed(ActionEvent e) { - //use previous find string - - }//}}} - - }//}}} - //{{{ SourceViewXMLDocumentListener class private class SourceViewXMLDocumentListener implements XMLDocumentListener { @@ -350,14 +325,6 @@ //{{{ structureChanged() public void structureChanged(XMLDocument source, AdapterNode location) {}//}}} - //{{{ insertUpdate() - public void insertUpdate(XMLDocumentEvent event) {}//}}} - - //{{{ removeUpdate() - public void removeUpdate(XMLDocumentEvent event) {}//}}} - - //{{{ changeUpdate() - public void changeUpdate(XMLDocumentEvent event) {}//}}} }//}}} //{{{ SourceViewEnter Modified: branches/sourceview2/src/sourceview/SourceViewDocument.java =================================================================== --- branches/sourceview2/src/sourceview/SourceViewDocument.java 2006-07-29 04:41:34 UTC (rev 1088) +++ branches/sourceview2/src/sourceview/SourceViewDocument.java 2006-07-29 04:42:42 UTC (rev 1089) @@ -138,29 +138,6 @@ //}}} - // private class SourceViewDocumentXMLDocumentListener implements XMLDocumentListener {//{{{ - // - // public void propertiesChanged(XMLDocument source, String propertyKey) { - // if (propertyKey.equals("encoding")) { - // try { - // String text = getText(0, getLength()); - // SourceViewDocument.super.remove(0, getLength()); - // SourceViewDocument.super.insertString(0, document.getSource(), new SimpleAttributeSet()); - // } catch (BadLocationException ble) { - // //This should never happen. If it does however jsXe will - // //act abnormally so... crash. - // jsXe.exiterror(view, ble.toString(), 1); - // } catch (IOException ioe) { - // //This might happen. If it does jsXe will - // //act abnormally so... crash. - // jsXe.exiterror(view, ioe.toString(), 1); - // } - // } - // } - // - // public void fileChanged(XMLDocument source) {} - // }//}}} - //{{{ Private members private XMLDocument m_document; //}}} Copied: branches/sourceview2/src/sourceview/SourceViewOptionPane.java (from rev 1084, trunk/sourceview/src/sourceview/SourceViewOptionPane.java) =================================================================== --- branches/sourceview2/src/sourceview/SourceViewOptionPane.java (rev 0) +++ branches/sourceview2/src/sourceview/SourceViewOptionPane.java 2006-07-29 04:42:42 UTC (rev 1089) @@ -0,0 +1,696 @@ +/* +SourceViewOptionPane.java +:tabSize=4:indentSize=4:noTabs=true: +:folding=explicit:collapseFolds=1: + +Copyright (C) 2002, 2006 Ian Lewis (Ian...@me...) +Portions Copyright (C) 1999, 2000, 2001, 2002 Slava Pestov + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +Optionally, you may find a copy of the GNU General Public License +from http://www.fsf.org/copyleft/gpl.txt +*/ + +package sourceview; + +//{{{ Imports + +import org.syntax.jedit.*; + +//{{{ jsXe classes +import net.sourceforge.jsxe.*; +import net.sourceforge.jsxe.gui.*; +import net.sourceforge.jsxe.options.*; +import net.sourceforge.jsxe.msg.PropertyChanged; +import net.sourceforge.jsxe.util.MiscUtilities; +//}}} + +//{{{ Java Classes +import java.awt.*; +import java.awt.event.*; +import javax.swing.*; +import javax.swing.table.*; +import javax.swing.border.EmptyBorder; +import java.util.Vector; +import java.util.StringTokenizer; +import java.util.Iterator; +//}}} + +//}}} + +public class SourceViewOptionPane extends AbstractOptionPane { + + //{{{ SourceViewOptionPane constructor + public SourceViewOptionPane(DocumentBuffer buffer) { + super("sourceview"); + }//}}} + + //{{{ _init() + protected void _init() { + setLayout(new BorderLayout(6,6)); + + // {{{ styles + + add(BorderLayout.CENTER,createStyleTableScroller()); + + //}}} + + //{{{ end of line markers + m_endOfLineMarkCheckBox = new JCheckBox(Messages.getMessage("SourceView.Options.EndOfLineMarker"),jsXe.getBooleanProperty("source.end-of-line-markers",true)); + m_endOfLineMarkCheckBox.setToolTipText(Messages.getMessage("SourceView.Options.EndOfLineMarker.Tooltip")); + add(BorderLayout.SOUTH, m_endOfLineMarkCheckBox); + + //}}} + + }//}}} + + //{{{ _save() + protected void _save() { + styleModel.save(); + jsXe.setBooleanProperty("source.end-of-line-markers",m_endOfLineMarkCheckBox.isSelected()); + }//}}} + + //{{{ getTitle() + + public String getTitle() { + return Messages.getMessage("SourceView.Options.Title"); + }//}}} + + //{{{ parseStyle() method + /** + * Converts a style string to a style object. + * @param str The style string + * @param family Style strings only specify font style, not font family + * @param size Style strings only specify font style, not font family + * @param color If false, the styles will be monochrome + * @exception IllegalArgumentException if the style is invalid + */ + public static SyntaxStyle parseStyle(String str) throws IllegalArgumentException { + Color fgColor = Color.black; + Color bgColor = null; + boolean italic = false; + boolean bold = false; + StringTokenizer st = new StringTokenizer(str); + while(st.hasMoreTokens()) { + String s = st.nextToken(); + if (s.startsWith("color:")) { + fgColor = parseColor(s.substring(6), Color.black); + } + else if (s.startsWith("style:")) { + for (int i = 6; i < s.length(); i++) { + if (s.charAt(i) == 'i') + italic = true; + else if(s.charAt(i) == 'b') + bold = true; + else + throw new IllegalArgumentException("Invalid style: " + s); + } + } + else + throw new IllegalArgumentException("Invalid directive: " + s); + } + return new SyntaxStyle(fgColor, italic, bold); + } //}}} + + //{{{ parseColor() method + public static Color parseColor(String name, Color defaultColor) { + if (name == null) + return defaultColor; + else if(name.startsWith("#")) { + try + { + return Color.decode(name); + } + catch(NumberFormatException nf) + { + return defaultColor; + } + } + else if("red".equals(name)) + return Color.red; + else if("green".equals(name)) + return Color.green; + else if("blue".equals(name)) + return Color.blue; + else if("yellow".equals(name)) + return Color.yellow; + else if("orange".equals(name)) + return Color.orange; + else if("white".equals(name)) + return Color.white; + else if("lightGray".equals(name)) + return Color.lightGray; + else if("gray".equals(name)) + return Color.gray; + else if("darkGray".equals(name)) + return Color.darkGray; + else if("black".equals(name)) + return Color.black; + else if("cyan".equals(name)) + return Color.cyan; + else if("magenta".equals(name)) + return Color.magenta; + else if("pink".equals(name)) + return Color.pink; + else + return defaultColor; + } //}}} + + //{{{ Private Members + + //{{{ getParentDialog() method + /** + * Traverses the given component's parent tree looking for an + * instance of JDialog, and return it. If not found, return null. + * @param c The component + */ + private static JDialog getParentDialog(Component c) { + Component p = c.getParent(); + while (p != null && !(p instanceof JDialog)) { + p = p.getParent(); + } + + return (p instanceof JDialog) ? (JDialog) p : null; + } //}}} + + //{{{ getStyleString() method + /** + * Converts a style into it's string representation. + * @param style The style + */ + private static String getStyleString(SyntaxStyle style) { + StringBuffer buf = new StringBuffer(); + + if (style.getColor() != null) { + buf.append("color:" + getColorHexString(style.getColor())); + } + + if (!style.isPlain()) { + buf.append(" style:" + (style.isItalic() ? "i" : "") + + (style.isBold() ? "b" : "")); + } + + return buf.toString(); + }//}}} + + //{{{ createStyleTableScroller() method + + private JScrollPane createStyleTableScroller() { + styleModel = createStyleTableModel(); + styleTable = new JTable(styleModel); + styleTable.setRowSelectionAllowed(false); + styleTable.setColumnSelectionAllowed(false); + styleTable.setCellSelectionEnabled(false); + styleTable.getTableHeader().setReorderingAllowed(false); + styleTable.addMouseListener(new MouseHandler()); + TableColumnModel tcm = styleTable.getColumnModel(); + TableColumn styleColumn = tcm.getColumn(1); + styleColumn.setCellRenderer(new StyleTableModel.StyleRenderer()); + Dimension d = styleTable.getPreferredSize(); + d.height = Math.min(d.height,100); + JScrollPane scroller = new JScrollPane(styleTable); + scroller.setPreferredSize(d); + return scroller; + } //}}} + + //{{{ createStyleTableModel() method + + private StyleTableModel createStyleTableModel() { + return new StyleTableModel(); + } //}}} + + //{{{ getColorHexString() method + /** + * Converts a color object to its hex value. The hex value + * prefixed is with `#', for example `#ff0088'. + * @param c The color object + */ + private static String getColorHexString(Color c) { + String colString = Integer.toHexString(c.getRGB() & 0xffffff); + return "#000000".substring(0,7 - colString.length()).concat(colString); + } //}}} + + //{{{ MouseHandler class + + private class MouseHandler extends MouseAdapter { + public void mouseClicked(MouseEvent evt) { + int row = styleTable.rowAtPoint(evt.getPoint()); + if(row == -1) + return; + + SyntaxStyle style = new StyleEditor( + SourceViewOptionPane.this, + (SyntaxStyle)styleModel.getValueAt( + row,1)).getStyle(); + if(style != null) + styleModel.setValueAt(style,row,1); + } + } //}}} + + //{{{ StyleEditor class + private static class StyleEditor extends EnhancedDialog implements ActionListener { + //{{{ StyleEditor constructor + public StyleEditor(Component comp, SyntaxStyle style) { + super(getParentDialog(comp), + Messages.getMessage("SourceView.StyleEditor.Title"),true); + + JPanel content = new JPanel(new BorderLayout(12,12)); + content.setBorder(new EmptyBorder(12,12,12,12)); + setContentPane(content); + + GridBagLayout layout = new GridBagLayout(); + JPanel panel = new JPanel(layout); + + GridBagConstraints cons = new GridBagConstraints(); + cons.gridx = cons.gridy = 0; + cons.gridwidth = 2; + cons.gridheight = 1; + cons.fill = GridBagConstraints.BOTH; + cons.weightx = 0.0f; + + italics = new JCheckBox(Messages.getMessage("SourceView.StyleEditor.Italics")); + italics.setSelected(style.isItalic()); + italics.setToolTipText(Messages.getMessage("SourceView.StyleEditor.Italics.ToolTip")); + layout.setConstraints(italics,cons); + panel.add(italics); + + cons.gridy++; + bold = new JCheckBox(Messages.getMessage("SourceView.StyleEditor.Bold")); + bold.setSelected(style.isBold()); + bold.setToolTipText(Messages.getMessage("SourceView.StyleEditor.Bold.ToolTip")); + layout.setConstraints(bold,cons); + panel.add(bold); + + cons.gridy++; + cons.gridwidth = 1; + Color fg = style.getColor(); + + fgColorCheckBox = new JCheckBox(Messages.getMessage("SourceView.StyleEditor.Color")); + fgColorCheckBox.setSelected(fg != null); + fgColorCheckBox.addActionListener(this); + fgColorCheckBox.setBorder(new EmptyBorder(0,0,0,12)); + fgColorCheckBox.setToolTipText(Messages.getMessage("SourceView.StyleEditor.Color.ToolTip")); + layout.setConstraints(fgColorCheckBox,cons); + panel.add(fgColorCheckBox); + + cons.gridx++; + fgColor = new ColorWellButton(fg); + fgColor.setEnabled(fg != null); + layout.setConstraints(fgColor,cons); + panel.add(fgColor); + + content.add(BorderLayout.CENTER,panel); + + Box box = new Box(BoxLayout.X_AXIS); + box.add(Box.createGlue()); + box.add(ok = new JButton(Messages.getMessage("common.ok"))); + getRootPane().setDefaultButton(ok); + ok.addActionListener(this); + box.add(Box.createHorizontalStrut(6)); + box.add(cancel = new JButton(Messages.getMessage("common.cancel"))); + cancel.addActionListener(this); + box.add(Box.createGlue()); + + content.add(BorderLayout.SOUTH,box); + + pack(); + setLocationRelativeTo(getParentDialog(comp)); + + setResizable(false); + show(); + } //}}} + + //{{{ actionPerformed() method + public void actionPerformed(ActionEvent evt) { + Object source = evt.getSource(); + if(source == ok) + ok(); + else if(source == cancel) + cancel(); + else if(source == fgColorCheckBox) + fgColor.setEnabled(fgColorCheckBox.isSelected()); + } //}}} + + //{{{ ok() method + public void ok() { + okClicked = true; + dispose(); + } //}}} + + //{{{ cancel() method + public void cancel() { + dispose(); + } //}}} + + //{{{ getStyle() method + public SyntaxStyle getStyle() { + if(!okClicked) + return null; + + Color foreground = (fgColorCheckBox.isSelected() + ? fgColor.getSelectedColor() + : null); + + return new SyntaxStyle(foreground, italics.isSelected(), bold.isSelected()); + } //}}} + + //{{{ Private members + private JCheckBox italics; + private JCheckBox bold; + private JCheckBox fgColorCheckBox; + private ColorWellButton fgColor; + private JButton ok; + private JButton cancel; + private boolean okClicked; + //}}} + } //}}} + + //{{{ StyleTableModel class + private static class StyleTableModel extends AbstractTableModel { + private Vector styleChoices; + + //{{{ StyleTableModel constructor + public StyleTableModel() { + styleChoices = new Vector(9); + addStyleChoice("SourceView.Markup", "sourceview.markup.color"); + addStyleChoice("xml.namespace.prefix", "sourceview.namespace.prefix.color"); + addStyleChoice("xml.text", "sourceview.text.color"); + addStyleChoice("xml.element", "sourceview.element.color"); + addStyleChoice("xml.attribute", "sourceview.attribute.color"); + addStyleChoice("xml.attribute.value", "sourceview.attribute.value.color"); + addStyleChoice("xml.cdata", "sourceview.cdata.color"); + addStyleChoice("xml.processing.instruction", "sourceview.processing.instruction.color"); + addStyleChoice("xml.entity.reference", "sourceview.entity.reference.color"); + addStyleChoice("xml.comment", "sourceview.comment.color"); + addStyleChoice("xml.doctype", "sourceview.doctype.color"); + addStyleChoice("SourceView.Invalid", "sourceview.invalid.color"); + MiscUtilities.quicksort(styleChoices, new MiscUtilities.StringCompare()); + } //}}} + + //{{{ getColumnCount() method + public int getColumnCount() + { + return 2; + } //}}} + + //{{{ getRowCount() method + public int getRowCount() + { + return styleChoices.size(); + } //}}} + + //{{{ getValueAt() method + public Object getValueAt(int row, int col) + { + StyleChoice ch = (StyleChoice)styleChoices.elementAt(row); + switch(col) + { + case 0: + return ch.label; + case 1: + return ch.style; + default: + return null; + } + } //}}} + + //{{{ setValueAt() method + public void setValueAt(Object value, int row, int col) + { + StyleChoice ch = (StyleChoice)styleChoices.elementAt(row); + if(col == 1) + ch.style = (SyntaxStyle)value; + fireTableRowsUpdated(row,row); + } //}}} + + //{{{ getColumnName() method + public String getColumnName(int index) + { + switch(index) + { + case 0: + return Messages.getMessage("SourceView.Syntax.Object"); + case 1: + return Messages.getMessage("SourceView.Syntax.Style"); + default: + return null; + } + } //}}} + + //{{{ save() method + public void save() { + for (int i = 0; i < styleChoices.size(); i++) { + StyleChoice ch = (StyleChoice)styleChoices.elementAt(i); + jsXe.setProperty(ch.property, getStyleString(ch.style)); + } + } //}}} + + //{{{ addStyleChoice() method + private void addStyleChoice(String label, String property) { + styleChoices.addElement(new StyleChoice(Messages.getMessage(label), property, parseStyle(jsXe.getProperty(property, "color:#000000")))); + } //}}} + + //{{{ StyleChoice class + private class StyleChoice { + String label; + String property; + SyntaxStyle style; + + StyleChoice(String label, String property, SyntaxStyle style) { + this.label = label; + this.property = property; + this.style = style; + } + + // for sorting + public String toString() { + return label; + } + } //}}} + + //{{{ StyleRenderer class + static class StyleRenderer extends JLabel implements TableCellRenderer { + //{{{ StyleRenderer constructor + public StyleRenderer() { + setOpaque(true); + // setBorder(); + setText("Hello World"); + setToolTipText(Messages.getMessage("SourceView.Syntax.ToolTip")); + } //}}} + + //{{{ getTableCellRendererComponent() method + public Component getTableCellRendererComponent( + JTable table, + Object value, + boolean isSelected, + boolean cellHasFocus, + int row, + int col) + { + if (value != null) { + SyntaxStyle style = (SyntaxStyle)value; + setForeground(style.getColor()); + setBackground(Color.WHITE); + setFont(new Font("Monospaced", (style.isItalic() ? Font.ITALIC : 0) | (style.isBold() ? Font.BOLD : 0), 12)); + } + + //Set a border if focused? + // setBorder(); + return this; + } //}}} + } //}}} + } //}}} + + //{{{ ColorWellButton class + + /** + * A button that, when clicked, shows a color chooser. + * + * You can get and set the currently selected color using + * {@link #getSelectedColor()} and {@link #setSelectedColor(Color)}. + * @author Slava Pestov + * @version $Id$ + */ + public static class ColorWellButton extends JButton { + + //{{{ ColorWellButton constructor + public ColorWellButton(Color color) + { + setIcon(new ColorWell(color)); + setMargin(new Insets(2,2,2,2)); + addActionListener(new ActionHandler()); + + // according to krisk this looks better on OS X... + if(OperatingSystem.isMacOSLF()) + putClientProperty("JButton.buttonType","toolbar"); + } //}}} + + //{{{ getSelectedColor() method + public Color getSelectedColor() + { + return ((ColorWell)getIcon()).color; + } //}}} + + //{{{ setSelectedColor() method + public void setSelectedColor(Color color) + { + ((ColorWell)getIcon()).color = color; + repaint(); + } //}}} + + //{{{ ColorWell class + private class ColorWell implements Icon { + + Color color; + + ColorWell(Color color) + { + this.color = color; + } + + public int getIconWidth() + { + return 35; + } + + public int getIconHeight() + { + return 10; + } + + public void paintIcon(Component c, Graphics g, int x, int y) + { + if(color == null) + return; + + g.setColor(color); + g.fillRect(x,y,getIconWidth(),getIconHeight()); + g.setColor(color.darker()); + g.drawRect(x,y,getIconWidth()-1,getIconHeight()-1); + } + } //}}} + + //{{{ ActionHandler class + class ActionHandler implements ActionListener + { + public void actionPerformed(ActionEvent evt) + { + JDialog parent = getParentDialog(ColorWellButton.this); + JDialog dialog; + if (parent != null) + { + dialog = new ColorPickerDialog(parent, + Messages.getMessage("SourceView.ColorChooser.Title"), + true); + } + else + { + dialog = new ColorPickerDialog( + JOptionPane.getFrameForComponent( + ColorWellButton.this), + Messages.getMessage("SourceView.ColorChooser.Title"), + true); + } + dialog.pack(); + dialog.show(); + } + } //}}} + + //{{{ ColorPickerDialog class + /** + * Replacement for the color picker dialog provided with Swing. This version + * supports dialog as well as frame parents. + */ + private class ColorPickerDialog extends EnhancedDialog implements ActionListener + { + public ColorPickerDialog(Frame parent, String title, boolean modal) + { + super(parent,title,modal); + + init(); + } + + public ColorPickerDialog(Dialog parent, String title, boolean modal) + { + super(parent,title,modal); + + getContent... [truncated message content] |