From: <nic...@us...> - 2009-11-02 01:41:09
|
Revision: 16430 http://jedit.svn.sourceforge.net/jedit/?rev=16430&view=rev Author: nicarran Date: 2009-11-02 01:40:59 +0000 (Mon, 02 Nov 2009) Log Message: ----------- * Revamped LineInfo evaluation: now it uses only the line indentation, Now it is not dependent on folding info! * Enriched the default configuration for java and xml file modes. * Some refactoring: changed "[Ff]old" to "[Ss]trip". * Fixed bug that prevented regex matching on Windows-style terminated lines (0d). Modified Paths: -------------- plugins/CandyFolds/trunk/CandyFolds-properties/java-CandyFolds.properties plugins/CandyFolds/trunk/CandyFolds.props plugins/CandyFolds/trunk/candyfolds/CandyFoldsPlugin.java plugins/CandyFolds/trunk/candyfolds/LineInfo.java plugins/CandyFolds/trunk/candyfolds/TextAreaExt.java plugins/CandyFolds/trunk/candyfolds/config/Config.java plugins/CandyFolds/trunk/candyfolds/config/ModeConfig.java plugins/CandyFolds/trunk/candyfolds/config/PluginHome.java plugins/CandyFolds/trunk/candyfolds/config/gui/ModeConfigPanel.java plugins/CandyFolds/trunk/description.html plugins/CandyFolds/trunk/docs/users-guide.xml Added Paths: ----------- plugins/CandyFolds/trunk/CandyFolds-properties/xml-CandyFolds.properties plugins/CandyFolds/trunk/candyfolds/config/StripConfig.java plugins/CandyFolds/trunk/candyfolds/config/gui/StripConfigsOpPanel.java plugins/CandyFolds/trunk/candyfolds/config/gui/StripConfigsTable.java Removed Paths: ------------- plugins/CandyFolds/trunk/candyfolds/config/FoldConfig.java plugins/CandyFolds/trunk/candyfolds/config/gui/FoldConfigsOpPanel.java plugins/CandyFolds/trunk/candyfolds/config/gui/FoldConfigsTable.java Modified: plugins/CandyFolds/trunk/CandyFolds-properties/java-CandyFolds.properties =================================================================== --- plugins/CandyFolds/trunk/CandyFolds-properties/java-CandyFolds.properties 2009-11-02 00:36:34 UTC (rev 16429) +++ plugins/CandyFolds/trunk/CandyFolds-properties/java-CandyFolds.properties 2009-11-02 01:40:59 UTC (rev 16430) @@ -1,29 +1,45 @@ -#Fri Mar 07 15:28:01 COT 2008 -java.0.color=178,0,178,128 -java.0.name=class -java.0.regex=.*\\s+((class)|(interface))\\s+.* -java.1.color=178,0,178,128 -java.1.name=new-anonymous-class -java.1.regex=.*new\\s.*\\)\\s*\\{\\s* -java.2.color=255,0,0,64 -java.2.name=for-do-while -java.2.regex=\\s*((for)|(do)|(while))\\s*\\(.* -java.3.color=178,178,0,128 -java.3.name=if -java.3.regex=\\s*if\\s*\\(.* -java.4.color=178,178,0,128 -java.4.name=else -java.4.regex=.*(\\s|\\})*else[\\s\\{]*(if)?.* -java.5.color=0,255,0,64 -java.5.name=try -java.5.regex=.*\\s*try\\s*\\{.* -java.6.color=0,255,0,64 -java.6.name=catch -java.6.regex=.*(\\s|\\})*catch(\\s|\\()+.* -java.7.color=0,255,0,64 -java.7.name=finally -java.7.regex=.*(\\s|\\})*finally(\\s|\\{)+.* -java.8.color=178,140,0,64 -java.8.name=case -java.8.regex=.*(\\s|\\})*case\\s(\\S)+(\\s)*\\\:.* +#Sun Nov 01 19:22:55 COT 2009 +java.0.color=216,115,2,89 +java.0.name=for-do-while +java.0.regex=\\s*((for)|(do)|(while))\\s*(\\(|\\{).* +java.1.color=192,213,1,211 +java.1.name=if +java.1.regex=\\s*if\\s*\\(.* +java.10.color=0,193,198,128 +java.10.name=case +java.10.regex=.*(\\s|\\})*case\\s(\\S)+(\\s)*\\\:.* +java.11.color=0,6,255,99 +java.11.name=constructor +java.11.regex=\\s*((public\\s)|(private\\s))?\\s*\\p{Upper}\\w+\\(.* +java.12.color=1,1,1,72 +java.12.name=method +java.12.regex=.*\\)\\s*\\{\\s* +java.13.color=181,181,181,0 +java.13.name=javadoc +java.13.regex=.*/\\*\\*.* +java.2.color=194,212,2,211 +java.2.name=else +java.2.regex=.*(\\s|\\})*else[\\s\\{]*(if)?.* +java.3.color=254,254,254,0 +java.3.name=molder class +java.3.regex=.*\\s+(class)\\s+\\S+Molder\\W.* +java.4.color=178,0,178,128 +java.4.name=class-interface-enum +java.4.regex=.*\\s+((class)|(interface)|(enum))\\s+.* +java.5.color=178,0,178,128 +java.5.name=new-anonymous-class +java.5.regex=.*\\s*new\\s+.*\\)\\s*\\{.* +java.6.color=113,3,4,126 +java.6.name=sync +java.6.regex=.*((synchronized)|(lock)).* +java.7.color=1,156,1,64 +java.7.name=try +java.7.regex=.*\\s*try\\s*\\{.* +java.8.color=0,255,0,64 +java.8.name=catch +java.8.regex=.*(\\s|\\})*catch(\\s|\\()+.* +java.9.color=0,255,0,64 +java.9.name=finally +java.9.regex=.*(\\s|\\})*finally(\\s|\\{)+.* +java.bigLines=true java.enabled=true Added: plugins/CandyFolds/trunk/CandyFolds-properties/xml-CandyFolds.properties =================================================================== --- plugins/CandyFolds/trunk/CandyFolds-properties/xml-CandyFolds.properties (rev 0) +++ plugins/CandyFolds/trunk/CandyFolds-properties/xml-CandyFolds.properties 2009-11-02 01:40:59 UTC (rev 16430) @@ -0,0 +1,6 @@ +#Sun Nov 01 18:56:27 COT 2009 +xml.0.color=1,1,136,96 +xml.0.name=target +xml.0.regex=\\s*<target\\s.* +xml.bigLines=false +xml.enabled=true Modified: plugins/CandyFolds/trunk/CandyFolds.props =================================================================== --- plugins/CandyFolds/trunk/CandyFolds.props 2009-11-02 00:36:34 UTC (rev 16429) +++ plugins/CandyFolds/trunk/CandyFolds.props 2009-11-02 01:40:59 UTC (rev 16430) @@ -2,8 +2,8 @@ plugin.candyfolds.CandyFoldsPlugin.name=CandyFolds plugin.candyfolds.CandyFoldsPlugin.author=Nicol\xE1s Carranza # inspired and based on work by Andr\xE9 Kaplan & Nathan Jones (WhiteSpace plugin) -plugin.candyfolds.CandyFoldsPlugin.version=1.0.0 -plugin.candyfolds.CandyFoldsPlugin.description=CandyFolds draws colored fold-guides on the text area to improve code readability. CandyFolds was based on the WhiteSpace plugin's fold-guides. +plugin.candyfolds.CandyFoldsPlugin.version=1.1.0 +plugin.candyfolds.CandyFoldsPlugin.description=CandyFolds draws colored indentation-guides on the text area to improve code readability. plugin.candyfolds.CandyFoldsPlugin.docs=index.html #v Dependencies Modified: plugins/CandyFolds/trunk/candyfolds/CandyFoldsPlugin.java =================================================================== --- plugins/CandyFolds/trunk/candyfolds/CandyFoldsPlugin.java 2009-11-02 00:36:34 UTC (rev 16429) +++ plugins/CandyFolds/trunk/candyfolds/CandyFoldsPlugin.java 2009-11-02 01:40:59 UTC (rev 16430) @@ -20,13 +20,15 @@ % }] */ package candyfolds; +import candyfolds.config.Config; import java.awt.Color; import java.io.File; import java.util.HashMap; import java.util.HashSet; +import java.util.logging.Level; +import java.util.logging.Logger; import java.util.Map; import java.util.Set; -import candyfolds.config.Config; import org.gjt.sp.jedit.EBMessage; import org.gjt.sp.jedit.EBPlugin; import org.gjt.sp.jedit.EditPane; @@ -39,6 +41,9 @@ public class CandyFoldsPlugin extends EBPlugin { + static final Logger L=Logger.getLogger(CandyFoldsPlugin.class.getName()); + static { L.setLevel(Level.ALL); } + private static CandyFoldsPlugin INSTANCE; public static CandyFoldsPlugin getInstance() { @@ -131,7 +136,4 @@ //Log.log(Log.NOTICE, this, logM+": "+editPaneUpdate.getEditPane()); } } - - - -} +} \ No newline at end of file Modified: plugins/CandyFolds/trunk/candyfolds/LineInfo.java =================================================================== --- plugins/CandyFolds/trunk/candyfolds/LineInfo.java 2009-11-02 00:36:34 UTC (rev 16429) +++ plugins/CandyFolds/trunk/candyfolds/LineInfo.java 2009-11-02 01:40:59 UTC (rev 16430) @@ -20,159 +20,188 @@ % }] */ package candyfolds; +import candyfolds.config.StripConfig; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; -import candyfolds.config.FoldConfig; +import java.util.logging.Level; +import java.util.logging.Logger; +import javax.swing.text.Segment; import org.gjt.sp.jedit.Buffer; import org.gjt.sp.util.Log; final class LineInfo { + static final Logger L=Logger.getLogger(LineInfo.class.getName()); + static { L.setLevel(Level.ALL); } + private final TextAreaExt textAreaExt; - private int line; - - final List<Integer> indents=new ArrayList<Integer>(); - final List<Integer> lines=new ArrayList<Integer>(); // lines where the indents belong (1:1). - final List<Integer> foldLevels=new ArrayList<Integer>(); - final List<FoldConfig> foldConfigs=new ArrayList<FoldConfig>(); - + private int lineIndent; + private final List<Integer> indents=new ArrayList<Integer>(); + private final List<Integer> lines=new ArrayList<Integer>(); // lines where the indents belong (1:1). + private final List<StripConfig> stripConfigs=new ArrayList<StripConfig>(); + LineInfo(TextAreaExt textAreaExt) { this.textAreaExt=textAreaExt; } - + int getLine(){ return line; } + int getIndentsSize(){ + return indents.size(); + } + + int getIndent(int indentIndex){ + return indents.get(indentIndex); + } + + StripConfig getStripConfig(int indentIndex){ + return stripConfigs.get(indentIndex); + } + private void clear() { + line=lineIndent=0; indents.clear(); lines.clear(); - foldLevels.clear(); - foldConfigs.clear(); + stripConfigs.clear(); } - - void eval(Buffer buffer, - int line) { - eval(buffer, line, null); - } - - void copyFrom(LineInfo lineInfo) { + + void copyFrom(LineInfo lineInfo){ clear(); line=lineInfo.line; indents.addAll(lineInfo.indents); lines.addAll(lineInfo.lines); - foldLevels.addAll(lineInfo.foldLevels); - foldConfigs.addAll(lineInfo.foldConfigs); + stripConfigs.addAll(lineInfo.stripConfigs); } - void eval(Buffer buffer, - int line, - LineInfo stopLineInfo) { - //long startTime=System.nanoTime(); - if(stopLineInfo==null) { - eval(buffer, line, 0); - //Log.log(Log.NOTICE, this, "line evaluation time: "+(System.nanoTime()-startTime)+" NO "+line); - return ; - } - if(stopLineInfo.line==line) { - copyFrom(stopLineInfo); - //Log.log(Log.NOTICE, this, "No need to eval "+line); - return ; - } - if(stopLineInfo.line>line) - throw new AssertionError("stopLineInfo was "+stopLineInfo+", and requested for "+line); - eval(buffer, line, stopLineInfo.line+1); - append(stopLineInfo); - //Log.log(Log.NOTICE, this, "line evaluation time: "+(System.nanoTime()-startTime)+" O "+line); + void eval(Buffer buffer, int line){ + eval(buffer, line, null); } - private void eval(Buffer buffer, - int line, - int stopLine) { + void eval(Buffer buffer, int line, LineInfo upLineInfo){ clear(); this.line=line; - int indent; - int foldLevel, lastCaughtFoldLevel=Integer.MAX_VALUE, lastCaughtIndent=0; - for(int i=line; i>=stopLine; i--) { - foldLevel=buffer.getFoldLevel(i); - if(foldLevel< lastCaughtFoldLevel) { - indent=foldLevel==0? 0: buffer.getCurrentIndentForLine(i, null); - //v check if this is an indented second (or third, or...) line of a fold... like a funcion with its parameters indented: - if(foldLevel!=0) - for(int j=i-1, upperLineIndent; j>=stopLine && buffer.getFoldLevel(j)==foldLevel; j--) { - upperLineIndent=buffer.getCurrentIndentForLine(j, null); // optim? this is a second call - if(indent!=0 && upperLineIndent==0) // optim - break; - if( indent==0 || (upperLineIndent!=0 && upperLineIndent<indent) ) {//indent==0 fixes when fold are made on empty lines - indent=upperLineIndent; - i=j; - } - } - //^ - lastCaughtFoldLevel=foldLevel; - if(lastCaughtIndent>0 && indent>lastCaughtIndent) { // los indent siempre van disminuyendo si es que no se trataba de un indent en 0 que era una linea vacia + int upLine= upLineInfo==null? 0: upLineInfo.line+1; + + int calcLine; + if(isEmptySegment(buffer, line)){ + int firstIndentUp=-1, firstIndentUpLine=line; + for(int i=line; i>=upLine; i--){ + if(i!=0 && isEmptySegment(buffer, i)) continue; - } + firstIndentUp=buffer.getCurrentIndentForLine(i, null); + firstIndentUpLine=i; + break; + } + if(firstIndentUp==-1){ + firstIndentUp=upLineInfo.lineIndent; + firstIndentUpLine=upLineInfo.line; + } + int firstIndentDown=-1, firstIndentDownLine=line; + for(int i=line, lineCount=buffer.getLineCount(); i<lineCount; i++){ // TODO: optimize for performance on large files with a lot of empty lines... + if(isEmptySegment(buffer, i)) + continue; + firstIndentDown=buffer.getCurrentIndentForLine(i, null); + firstIndentDownLine=i; + break; + } + if(firstIndentDown>firstIndentUp){ + calcLine=firstIndentDownLine; + lineIndent=firstIndentDown; + }else{ + calcLine=firstIndentUpLine; + lineIndent=firstIndentUp; + } + } + else{ + calcLine=line; + lineIndent=buffer.getCurrentIndentForLine(line, null); + } + + int indent, lastCaughtIndent=Integer.MAX_VALUE; + for(; calcLine>=upLine; calcLine--) { + indent=buffer.getCurrentIndentForLine(calcLine, null); + if(indent>=lastCaughtIndent || + indent>lineIndent) + continue; + if(isEmptySegment(buffer, calcLine)) + continue; + lastCaughtIndent=indent; + //L.fine("adding indent="+indent+" on line="+calcLine); + indents.add(indent); + lines.add(calcLine); + addStripConfig(buffer, calcLine, indent); + if(lastCaughtIndent==0) // optimization + break; + } + + if(upLineInfo!=null + && lastCaughtIndent>0 // optimization + ){ + for(int i=0; i<upLineInfo.indents.size(); i++){ + indent=upLineInfo.indents.get(i); + if(indent>=lastCaughtIndent || + indent>lineIndent) + continue; lastCaughtIndent=indent; + //L.fine("line="+line+", adding upLineInfo indent="+indent); indents.add(indent); - lines.add(i); - foldLevels.add(foldLevel); + lines.add(upLineInfo.lines.get(i)); + stripConfigs.add(upLineInfo.stripConfigs.get(i)); } - if(foldLevel<=1) // change this to zero if you want the top level too... put this as pref? - break; } - removeRepeated(); - selectFoldConfigs(buffer); } - private void removeRepeated() { - int indent; - for(int i=0, size=indents.size(); i<size;) { - indent=indents.get(i); - if(/*indent==0 ||*/ // se dejan pues puede ser el primero. el primero se ignora. (pensar en caso de lineas vacias dentro de fold) - (i+1<size && indent==indents.get(i+1)) ) { - indents.remove(i); - lines.remove(i+1); // remove the next line info - foldLevels.remove(i+1); - // foldConfigs.remove(i+1); has not been loaded! - size--; - } else - i++; - } + private boolean isEmptySegment(Buffer buffer, int line){ + buffer.getLineText(line, textAreaExt.segment); + return isEmptySegment(textAreaExt.segment); } - private void selectFoldConfigs(Buffer buffer) { - for(int i=0, size=indents.size(); i<size; i++ ) - selectFoldConfig(buffer, lines.get(i), i); + private static boolean isEmptySegment(Segment segment){ + for(int i=segment.length(); --i>=0; ) + if(!Character.isWhitespace(segment.charAt(i))) + return false; + return true; } - private void selectFoldConfig(Buffer buffer, int line, int lineIndex) { - FoldConfig foldConfig; - if(indents.get(lineIndex)==0) { - foldConfig=null; - } else { - buffer.getLineText(line, textAreaExt.segment); - foldConfig=textAreaExt.getModeConfig().evalFoldConfig(textAreaExt.segment); - } - foldConfigs.add(lineIndex, foldConfig); + private void addStripConfig(Buffer buffer, int line, int lineIndent) { + prepareSegmentForStripConfig(buffer, line, lineIndent); + StripConfig stripConfig=textAreaExt.getModeConfig().evalStripConfig(textAreaExt.segment); + stripConfigs.add(stripConfig); } - - private void append(LineInfo extLineInfo) { - int lastFoldLevel=foldLevels.get(foldLevels.size()-1); // I assume that I have always at least one element - int prevIndent=indents.get(indents.size()-1); - for(int i=0, size=extLineInfo.foldLevels.size(); i<size; i++) { - int extFoldLevel=extLineInfo.foldLevels.get(i); - if(extFoldLevel>=lastFoldLevel) - continue; - int extIndent=extLineInfo.indents.get(i); - if(extIndent==0 || extIndent==prevIndent) // extIndent==prevIndent may be true only in the first iteration - continue; - prevIndent=extIndent; - indents.add(extIndent); - lines.add(extLineInfo.lines.get(i)); - foldLevels.add(extFoldLevel); - foldConfigs.add(extLineInfo.foldConfigs.get(i)); + private void prepareSegmentForStripConfig(final Buffer buffer, final int line, final int lineIndent){ + final Segment segment=textAreaExt.segment; + boolean usePrevLine=false; + if(textAreaExt.getModeConfig().getUseBigLinesForStripConfigs()){ + for( int prevLine=line ; prevLine>=0; prevLine-- ){ // TODO: use a limit instead of 0? + buffer.getLineText(prevLine, segment); + int segmentContentLength=evalSegmentContentLength(segment); + if(segmentContentLength==0) + continue; + int prevLineIndent=buffer.getCurrentIndentForLine(prevLine, null); + if(prevLineIndent>lineIndent) + continue; + if(prevLineIndent<lineIndent) + break; + if(segmentContentLength==1) + continue; + usePrevLine=true; + // -> the segment is ready on prevLine + break; + } } + if(!usePrevLine) + buffer.getLineText(line, segment); } -} + + private static int evalSegmentContentLength(Segment segment){ + int contentLength=0; + for(int i=segment.length(); --i>=0; ) + if(!Character.isWhitespace(segment.charAt(i))) + contentLength++; + return contentLength; + } +} \ No newline at end of file Modified: plugins/CandyFolds/trunk/candyfolds/TextAreaExt.java =================================================================== --- plugins/CandyFolds/trunk/candyfolds/TextAreaExt.java 2009-11-02 00:36:34 UTC (rev 16429) +++ plugins/CandyFolds/trunk/candyfolds/TextAreaExt.java 2009-11-02 01:40:59 UTC (rev 16430) @@ -35,10 +35,15 @@ import java.util.LinkedHashSet; import java.util.List; import java.util.ListIterator; +import java.util.logging.Level; +import java.util.logging.Logger; import java.util.Map; import java.util.Set; import javax.swing.text.Segment; import org.gjt.sp.jedit.Buffer; +import org.gjt.sp.jedit.buffer.JEditBuffer; +import org.gjt.sp.jedit.buffer.BufferAdapter; +import org.gjt.sp.jedit.buffer.BufferListener; import org.gjt.sp.jedit.EditPane; import org.gjt.sp.jedit.textarea.JEditTextArea; import org.gjt.sp.jedit.textarea.TextArea; @@ -49,17 +54,38 @@ final class TextAreaExt extends TextAreaExtension { + static final Logger L=Logger.getLogger(TextAreaExt.class.getName()); + static { L.setLevel(Level.ALL); } final CandyFoldsPlugin foldsPlugin; final EditPane editPane; private final TextAreaPainter painter; - private final LineInfo firstInRangeLineInfo=new LineInfo(this); - private final LineInfo lineInfo=new LineInfo(this); - private final LineInfo toolTipLineInfo=new LineInfo(this); + /* + private final LineInfo firstLineInfo=new LineInfo(this); + private Buffer firstLineInfoBuffer; + private final BufferListener firstLineInfoBufferL=new BufferAdapter(){ + @Override + public void contentInserted(JEditBuffer buffer, int startLine, int offset, int numLines, int length){ + contentChanged(); + } + @Override + public void contentRemoved(JEditBuffer buffer, int startLine, int offset, int numLines, int length){ + contentChanged(); + } + private void contentChanged(){ + unregisterFirstLineInfoBuffer(); + } + };*/ + private LineInfo previousLineInfo=new LineInfo(this); + private LineInfo currentLineInfo=new LineInfo(this); + //private final LineInfo toolTipLineInfo=new LineInfo(this); + + private final FontMetricsInfo fontMetricsInfo=new FontMetricsInfo(); private static final class FontMetricsInfo { + private FontMetrics fontMetrics; int spaceWidth; int lineHeight; @@ -75,6 +101,7 @@ } } + private ModeConfig modeConfig; private String modeConfigName; // use it separated from modeConfig because modeConfig can be null! private final Line2D.Float line2D=new Line2D.Float(); @@ -130,46 +157,71 @@ int y, int lineHeight) { //Log.log(Log.NOTICE, this, "painting range: firstLine="+firstLine+", lastLine=" + lastLine + ", y=" + y+"lineHeight="+lineHeight); + //long nanoTime=System.nanoTime(); Buffer buffer = editPane.getBuffer(); setModeConfig(buffer); if(!getModeConfig().getEnabled()) return; for(int i = 0; i < physicalLines.length; i++) { - int screenLine = i + firstLine; - if(physicalLines[i]==-1) + int line=physicalLines[i]; + if(line==-1) continue; - //Log.log(Log.NOTICE, this, "physicalLine="+physicalLines[i]+", start="+start[i]+", end="+end[i]+", lineHeight="+lineHeight); - if(i==0) { - firstInRangeLineInfo.eval(buffer, physicalLines[i]); - drawLine(firstInRangeLineInfo, g, y); - } else { - lineInfo.eval(buffer, physicalLines[i], firstInRangeLineInfo); - drawLine(lineInfo, g, y); + if(i==0){ + /* this optimization does not worth the effort! + if(firstLineInfoBuffer!=buffer // firstLineInfoBuffer is set to null when buffer changes + || firstLineInfo.getLine()!=line){ + firstLineInfo.eval(buffer, line); + registerFirstLineInfoBuffer(buffer); + } + currentLineInfo.copyFrom(firstLineInfo);*/ + currentLineInfo.eval(buffer, line); } + else + currentLineInfo.eval(buffer, line, previousLineInfo); + drawLineIndents(buffer, currentLineInfo, g, y); + LineInfo swap=previousLineInfo; + previousLineInfo=currentLineInfo; + currentLineInfo=swap; y += lineHeight; } //Log.log(Log.NOTICE, this, "done painting range"); + //L.fine("new painting time="+(System.nanoTime()-nanoTime)); } - private void drawLine(LineInfo lineInfo, Graphics2D g, int y) { - if(lineInfo.indents.size()<=1) + /* + private synchronized void registerFirstLineInfoBuffer(Buffer buffer){ + if(buffer==firstLineInfoBuffer) return; + unregisterFirstLineInfoBuffer(); + firstLineInfoBuffer=buffer; + firstLineInfoBuffer.addBufferListener(firstLineInfoBufferL); + } + + private synchronized void unregisterFirstLineInfoBuffer(){ + if(firstLineInfoBuffer!=null) + firstLineInfoBuffer.removeBufferListener(firstLineInfoBufferL); + firstLineInfoBuffer=null; + }*/ + + private void drawLineIndents(Buffer buffer, LineInfo lineInfo, Graphics2D g, int y) { fontMetricsInfo.setFontMetrics(painter.getFontMetrics()); Stroke gStroke=g.getStroke(); g.setStroke(fontMetricsInfo.barStroke); - //float x; int x; int indent; int horizontalOffset=editPane.getTextArea().getHorizontalOffset(); - for (int i =lineInfo.indents.size();--i>=1;) { // ignore the first. Iteration from outer to inner fold. the first is right above the first char of the line. - indent =lineInfo.indents.get(i); + + for (int i =lineInfo.getIndentsSize();--i>=1;) {// ATTENTION: omit the first + indent =lineInfo.getIndent(i); if(indent==0) continue; - g.setColor(lineInfo.foldConfigs.get(i).getColor()); - x= (int)((indent+0.4f )* fontMetricsInfo.spaceWidth+horizontalOffset);//(indent+0.4f) * fontMetricsInfo.spaceWidth; - //line2D.setLine(x, y, x, y+fontMetricsInfo.lineHeight); - //g.draw(line2D); this is slooow compared to drawLine (at least in my comp)! + //Log.log(Log.NOTICE, this, "painting indent="+indent); + Color color=lineInfo.getStripConfig(i).getColor(); + if(color.getAlpha()==0) + continue; + g.setColor(color); + x= (int)((indent+0.4f )* fontMetricsInfo.spaceWidth+horizontalOffset); g.drawLine(x, y,x, y+fontMetricsInfo.lineHeight); } g.setStroke(gStroke); @@ -203,11 +255,11 @@ rect.x= (int)(indent* fontMetricsInfo.spaceWidth+horizontalOffset); if(rect.contains(x, y)){ //int foldLevel=toolTipLineInfo.foldLevels.get(i); - String foldConfigName=toolTipLineInfo.foldConfigs.get(i).getName(); + String stripConfigName=toolTipLineInfo.stripConfigs.get(i).getName(); buffer.getLineText(toolTipLineInfo.lines.get(i), segment); - return segment.toString().trim()+"... : "+foldConfigName; + return segment.toString().trim()+"... : "+stripConfigName; } } return null; - }*/ +}*/ } \ No newline at end of file Modified: plugins/CandyFolds/trunk/candyfolds/config/Config.java =================================================================== --- plugins/CandyFolds/trunk/candyfolds/config/Config.java 2009-11-02 00:36:34 UTC (rev 16429) +++ plugins/CandyFolds/trunk/candyfolds/config/Config.java 2009-11-02 01:40:59 UTC (rev 16430) @@ -45,9 +45,9 @@ public Config() { load(defaultModeConfig); - if(defaultModeConfig.foldConfigsA.isEmpty()) { - FoldConfig defFoldConfig=defaultModeConfig.addFoldConfig(); - defFoldConfig.setName("all"); + if(defaultModeConfig.stripConfigsA.isEmpty()) { + StripConfig defStripConfig=defaultModeConfig.addStripConfig(); + defStripConfig.setName("all"); store(); } } Deleted: plugins/CandyFolds/trunk/candyfolds/config/FoldConfig.java =================================================================== --- plugins/CandyFolds/trunk/candyfolds/config/FoldConfig.java 2009-11-02 00:36:34 UTC (rev 16429) +++ plugins/CandyFolds/trunk/candyfolds/config/FoldConfig.java 2009-11-02 01:40:59 UTC (rev 16430) @@ -1,166 +0,0 @@ -/* % [{ -% (C) Copyright 2008 Nicolas Carranza and individual contributors. -% See the CandyFolds-copyright.txt file in the CandyFolds distribution for a full -% listing of individual contributors. -% -% This file is part of CandyFolds. -% -% CandyFolds 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 3 of the License, -% or (at your option) any later version. -% -% CandyFolds 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 CandyFolds. If not, see <http://www.gnu.org/licenses/>. -% }] */ -package candyfolds.config; - -import java.awt.Color; -import java.util.Properties; -import java.util.regex.Matcher; -import java.util.regex.Pattern; -import java.util.regex.PatternSyntaxException; -import javax.swing.text.Segment; -import org.gjt.sp.util.Log; - -public final class FoldConfig { - public static final Color DEFAULT_COLOR=new Color(0, 0, 128, 86); // WARNING: using transparency slows drawing (noticeable on my computer 2ghz pentium + radeon 9700...) - private String name=""; - private Color color=DEFAULT_COLOR; - private String regex; - private Pattern pattern; - private Matcher matcher; - - FoldConfig() { - } - - public String getName() { - return name; - } - - public void setName(String name) { - if(name==null) - name=""; - this.name=name.trim(); - } - - synchronized boolean matches(Segment segment) { - if(matcher==null) { - if(pattern==null) - return true; - else { - matcher=pattern.matcher(segment); - //Log.log(Log.NOTICE, this, "matcher setted"); - } - } else - matcher.reset(segment); - return matcher.matches(); - } - - public void setRegex(String regex) - throws PatternSyntaxException { - if(regex!=null) { - regex=regex.trim(); - this.pattern=Pattern.compile(regex); - } else - this.pattern=null; - this.regex=regex; - matcher=null; - } - - public String getRegex() { - return regex; - } - - public void setColor(Color color) { - if(color==null) - throw new NullPointerException(); - this.color=color; - } - - public Color getColor() { - return color; - } - - boolean load(Properties ps, ModeConfig mc, StringBuilder sb, int i) { - String colorPropName= mc.getPropertyNameB(sb, String.valueOf(i)). - append(".color").toString(); - String regexPropName=mc.getPropertyNameB(sb, String.valueOf(i)). - append(".regex").toString(); - String namePropName=mc.getPropertyNameB(sb, String.valueOf(i)). - append(".name").toString(); - return load(ps, colorPropName, regexPropName, namePropName); - } - - boolean load(Properties ps, - String colorPropName, - String regexPropName, - String namePropName) { - String colorS=ps.getProperty(colorPropName); - if(colorS==null) - return false; - Color color=decodeColor(colorS); - if(color==null) - return false; - setColor(color); - setRegex(ps.getProperty(regexPropName)); - setName(ps.getProperty(namePropName)); - return true; - } - - void store(Properties ps, ModeConfig mc, StringBuilder sb, int i) { - store(ps, mc.getPropertyNameB(sb, String.valueOf(i)). - append(".color").toString(), - mc.getPropertyNameB(sb, String.valueOf(i)). - append(".regex").toString(), - mc.getPropertyNameB(sb, String.valueOf(i)). - append(".name").toString() - ); - } - - void store(Properties ps, - String colorPropName, - String regexPropName, - String namePropName) { - ps.setProperty(colorPropName, encodeColor(new StringBuilder(), color)); - if(regex!=null) - ps.setProperty(regexPropName, regex); - ps.setProperty(namePropName, name); - } - - static String encodeColor(StringBuilder sb, Color color) { - sb.setLength(0); - sb.append(color.getRed()); - sb.append(","); - sb.append(color.getGreen()); - sb.append(","); - sb.append(color.getBlue()); - if(color.getAlpha()!=255) { - sb.append(","); - sb.append(color.getAlpha()); - } - return sb.toString(); - } - - static Color decodeColor(String colorS) { - String[] colorComps=colorS.split(","); - int[] colorCompVals=new int[colorComps.length]; - for(int i=colorComps.length; --i>=0;) { - colorCompVals[i]=Integer.valueOf(colorComps[i].trim()); - if(colorCompVals[i]<0 || colorCompVals[i]>255) - return null; - } - if(colorCompVals.length<3) - return null; - if(colorCompVals.length==3) - return new Color(colorCompVals[0], colorCompVals[1], colorCompVals[2]); - else - return new Color(colorCompVals[0], colorCompVals[1], colorCompVals[2], colorCompVals[3]); - } - -} Modified: plugins/CandyFolds/trunk/candyfolds/config/ModeConfig.java =================================================================== --- plugins/CandyFolds/trunk/candyfolds/config/ModeConfig.java 2009-11-02 00:36:34 UTC (rev 16429) +++ plugins/CandyFolds/trunk/candyfolds/config/ModeConfig.java 2009-11-02 01:40:59 UTC (rev 16430) @@ -31,9 +31,10 @@ public static final int MAX_FOLD_CONFIGS=20; public final Config config; public final String name; - private final List<FoldConfig> foldConfigs=new ArrayList<FoldConfig>(); - public final List<FoldConfig> foldConfigsA=Collections.unmodifiableList(foldConfigs); + private final List<StripConfig> stripConfigs=new ArrayList<StripConfig>(); + public final List<StripConfig> stripConfigsA=Collections.unmodifiableList(stripConfigs); private boolean enabled=true; + private boolean useBigLinesForStripConfigs=true; ModeConfig(Config config, String name) { this.config=config; @@ -50,52 +51,61 @@ this.enabled=enabled; } - public FoldConfig addFoldConfig() { - if(config.defaultModeConfig==this && !foldConfigs.isEmpty()) + public boolean getUseBigLinesForStripConfigs(){ + return useBigLinesForStripConfigs; + } + + public void setUseBigLinesForStripConfigs(boolean useBigLinesForStripConfigs){ + this.useBigLinesForStripConfigs=useBigLinesForStripConfigs; + } + + public StripConfig addStripConfig() { + if(config.defaultModeConfig==this && !stripConfigs.isEmpty()) return null; - FoldConfig foldConfig=new FoldConfig(); - foldConfigs.add(foldConfig); - return foldConfig; + StripConfig stripConfig=new StripConfig(); + stripConfigs.add(stripConfig); + return stripConfig; } - public void removeFoldConfig(int index) { - if(config.defaultModeConfig==this && foldConfigs.size()==1) + public void removeStripConfig(int index) { + if(config.defaultModeConfig==this && stripConfigs.size()==1) return; - foldConfigs.remove(index); + stripConfigs.remove(index); } - public boolean moveUp(int foldConfigIndex) { - if(foldConfigIndex>0 && foldConfigIndex<foldConfigs.size()) { - FoldConfig toMove=foldConfigs.remove(foldConfigIndex); - foldConfigs.add(foldConfigIndex-1, toMove); + public boolean moveUp(int stripConfigIndex) { + if(stripConfigIndex>0 && stripConfigIndex<stripConfigs.size()) { + StripConfig toMove=stripConfigs.remove(stripConfigIndex); + stripConfigs.add(stripConfigIndex-1, toMove); return true; } return false; } - public boolean moveDown(int foldConfigIndex) { - if(foldConfigIndex>=0 && foldConfigIndex<foldConfigs.size()-1) { - FoldConfig toMove=foldConfigs.remove(foldConfigIndex); - foldConfigs.add(foldConfigIndex+1, toMove); + public boolean moveDown(int stripConfigIndex) { + if(stripConfigIndex>=0 && stripConfigIndex<stripConfigs.size()-1) { + StripConfig toMove=stripConfigs.remove(stripConfigIndex); + stripConfigs.add(stripConfigIndex+1, toMove); return true; } return false; } - public FoldConfig evalFoldConfig(Segment segment) { - for(FoldConfig foldConfig: foldConfigs) { - if(foldConfig.matches(segment)) - return foldConfig; + public StripConfig evalStripConfig(Segment segment) { + for(StripConfig stripConfig: stripConfigs) { + if(stripConfig.matches(segment)) + return stripConfig; } - return config.defaultModeConfig.foldConfigs.get(0); + return config.defaultModeConfig.stripConfigs.get(0); } void store(Properties ps) { StringBuilder sb=new StringBuilder(); ps.clear(); ps.setProperty(getPropertyName(sb, "enabled"), String.valueOf(enabled)); - for(int i=0, size=foldConfigs.size(); i<size && i<MAX_FOLD_CONFIGS; i++) { - foldConfigs.get(i).store(ps, this, sb, i); + ps.setProperty(getPropertyName(sb, "bigLines"), String.valueOf(useBigLinesForStripConfigs)); + for(int i=0, size=stripConfigs.size(); i<size && i<MAX_FOLD_CONFIGS; i++) { + stripConfigs.get(i).store(ps, this, sb, i); } } @@ -120,11 +130,13 @@ if(this!=config.defaultModeConfig) setEnabled(Boolean.valueOf( ps.getProperty(getPropertyName(sb, "enabled")))); - foldConfigs.clear(); + setUseBigLinesForStripConfigs(Boolean.valueOf( + ps.getProperty(getPropertyName(sb, "bigLines")))); + stripConfigs.clear(); for(int i=0; i<MAX_FOLD_CONFIGS; i++) { - FoldConfig foldConfig=new FoldConfig(); - if(foldConfig.load(ps, this, sb, i)) { - foldConfigs.add(foldConfig); + StripConfig stripConfig=new StripConfig(); + if(stripConfig.load(ps, this, sb, i)) { + stripConfigs.add(stripConfig); } else break; } @@ -132,4 +144,4 @@ ex.printStackTrace(); } } -} +} \ No newline at end of file Modified: plugins/CandyFolds/trunk/candyfolds/config/PluginHome.java =================================================================== --- plugins/CandyFolds/trunk/candyfolds/config/PluginHome.java 2009-11-02 00:36:34 UTC (rev 16429) +++ plugins/CandyFolds/trunk/candyfolds/config/PluginHome.java 2009-11-02 01:40:59 UTC (rev 16430) @@ -62,7 +62,7 @@ modeConfigName+MODE_CONFIG_FILE_SUFIX); } - static final String[] distribModeConfigNames={"java"}; + static final String[] distribModeConfigNames={"java", "xml"}; private static void initializeDistribModeConfigFiles() { Log.log(Log.NOTICE, PluginHome.class, "Initializing distrib config files."); Added: plugins/CandyFolds/trunk/candyfolds/config/StripConfig.java =================================================================== --- plugins/CandyFolds/trunk/candyfolds/config/StripConfig.java (rev 0) +++ plugins/CandyFolds/trunk/candyfolds/config/StripConfig.java 2009-11-02 01:40:59 UTC (rev 16430) @@ -0,0 +1,174 @@ +/* % [{ +% (C) Copyright 2008 Nicolas Carranza and individual contributors. +% See the CandyFolds-copyright.txt file in the CandyFolds distribution for a full +% listing of individual contributors. +% +% This file is part of CandyFolds. +% +% CandyFolds 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 3 of the License, +% or (at your option) any later version. +% +% CandyFolds 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 CandyFolds. If not, see <http://www.gnu.org/licenses/>. +% }] */ +package candyfolds.config; + +import java.awt.Color; +import java.util.logging.Level; +import java.util.logging.Logger; +import java.util.Properties; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import java.util.regex.PatternSyntaxException; +import javax.swing.text.Segment; +import org.gjt.sp.util.Log; + +public final class StripConfig { + static final Logger L=Logger.getLogger(StripConfig.class.getName()); + static { L.setLevel(Level.ALL); } + + public static final Color DEFAULT_COLOR=new Color(181, 181, 181, 255); // WARNING: using transparency slows drawing (noticeable on my computer 2ghz pentium + radeon 9700...) + private String name=""; + private Color color=DEFAULT_COLOR; + private String regex; + private Pattern pattern; + private Matcher matcher; + + StripConfig() { + } + + public String getName() { + return name; + } + + public void setName(String name) { + if(name==null) + name=""; + this.name=name.trim(); + } + + synchronized boolean matches(Segment segment) { + if(matcher==null) { + if(pattern==null) + return true; + else { + matcher=pattern.matcher(segment); + //Log.log(Log.NOTICE, this, "matcher setted"); + } + } else + matcher.reset(segment); + //long nanos=System.nanoTime(); + boolean r=matcher.lookingAt(); + //L.fine("regex time="+(System.nanoTime()-nanos)); // find() is slooow! + return r; + } + + public void setRegex(String regex) + throws PatternSyntaxException { + if(regex!=null) { + regex=regex.trim(); + this.pattern=Pattern.compile(regex); + } else + this.pattern=null; + this.regex=regex; + matcher=null; + } + + public String getRegex() { + return regex; + } + + public void setColor(Color color) { + if(color==null) + throw new NullPointerException(); + this.color=color; + } + + public Color getColor() { + return color; + } + + boolean load(Properties ps, ModeConfig mc, StringBuilder sb, int i) { + String colorPropName= mc.getPropertyNameB(sb, String.valueOf(i)). + append(".color").toString(); + String regexPropName=mc.getPropertyNameB(sb, String.valueOf(i)). + append(".regex").toString(); + String namePropName=mc.getPropertyNameB(sb, String.valueOf(i)). + append(".name").toString(); + return load(ps, colorPropName, regexPropName, namePropName); + } + + boolean load(Properties ps, + String colorPropName, + String regexPropName, + String namePropName) { + String colorS=ps.getProperty(colorPropName); + if(colorS==null) + return false; + Color color=decodeColor(colorS); + if(color==null) + return false; + setColor(color); + setRegex(ps.getProperty(regexPropName)); + setName(ps.getProperty(namePropName)); + return true; + } + + void store(Properties ps, ModeConfig mc, StringBuilder sb, int i) { + store(ps, mc.getPropertyNameB(sb, String.valueOf(i)). + append(".color").toString(), + mc.getPropertyNameB(sb, String.valueOf(i)). + append(".regex").toString(), + mc.getPropertyNameB(sb, String.valueOf(i)). + append(".name").toString() + ); + } + + void store(Properties ps, + String colorPropName, + String regexPropName, + String namePropName) { + ps.setProperty(colorPropName, encodeColor(new StringBuilder(), color)); + if(regex!=null) + ps.setProperty(regexPropName, regex); + ps.setProperty(namePropName, name); + } + + static String encodeColor(StringBuilder sb, Color color) { + sb.setLength(0); + sb.append(color.getRed()); + sb.append(","); + sb.append(color.getGreen()); + sb.append(","); + sb.append(color.getBlue()); + if(color.getAlpha()!=255) { + sb.append(","); + sb.append(color.getAlpha()); + } + return sb.toString(); + } + + static Color decodeColor(String colorS) { + String[] colorComps=colorS.split(","); + int[] colorCompVals=new int[colorComps.length]; + for(int i=colorComps.length; --i>=0;) { + colorCompVals[i]=Integer.valueOf(colorComps[i].trim()); + if(colorCompVals[i]<0 || colorCompVals[i]>255) + return null; + } + if(colorCompVals.length<3) + return null; + if(colorCompVals.length==3) + return new Color(colorCompVals[0], colorCompVals[1], colorCompVals[2]); + else + return new Color(colorCompVals[0], colorCompVals[1], colorCompVals[2], colorCompVals[3]); + } + +} \ No newline at end of file Deleted: plugins/CandyFolds/trunk/candyfolds/config/gui/FoldConfigsOpPanel.java =================================================================== --- plugins/CandyFolds/trunk/candyfolds/config/gui/FoldConfigsOpPanel.java 2009-11-02 00:36:34 UTC (rev 16429) +++ plugins/CandyFolds/trunk/candyfolds/config/gui/FoldConfigsOpPanel.java 2009-11-02 01:40:59 UTC (rev 16430) @@ -1,127 +0,0 @@ -/* % [{ -% (C) Copyright 2008 Nicolas Carranza and individual contributors. -% See the CandyFolds-copyright.txt file in the CandyFolds distribution for a full -% listing of individual contributors. -% -% This file is part of CandyFolds. -% -% CandyFolds 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 3 of the License, -% or (at your option) any later version. -% -% CandyFolds 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 CandyFolds. If not, see <http://www.gnu.org/licenses/>. -% }] */ -package candyfolds.config.gui; - -import java.awt.event.ActionEvent; -import javax.swing.AbstractAction; -import javax.swing.Action; -import javax.swing.BoxLayout; -import javax.swing.JButton; -import javax.swing.JPanel; -import javax.swing.JToolBar; -import candyfolds.config.FoldConfig; -import candyfolds.config.ModeConfig; -import org.gjt.sp.jedit.GUIUtilities; -import org.gjt.sp.jedit.jEdit; - -class FoldConfigsOpPanel { - final JToolBar panel=new JToolBar(); - private final FoldConfigsTable foldConfigsTable; - final Action[] actions=new Action[]{ - new AbstractAction("Add", GUIUtilities.loadIcon("Plus.png")) { - { - putValue(Action.SHORT_DESCRIPTION, jEdit.getProperty("common.add")); - } - @Override - public void actionPerformed(ActionEvent ev) { - if(getModeConfig()!=null) { - getModeConfig().addFoldConfig(); - foldConfigsTable.fireTableDataChanged(); - } - } - }, - new AbstractAction("Remove", GUIUtilities.loadIcon("Minus.png")) { - { - putValue(Action.SHORT_DESCRIPTION, jEdit.getProperty("common.remove")); - } - @Override - public void actionPerformed(ActionEvent ev) { - int row=foldConfigsTable.getSelectedIndex(); - if(row<0) - return; - if(getModeConfig()!=null) { - getModeConfig().removeFoldConfig(row); - foldConfigsTable.fireTableDataChanged(); - } - } - }, - new AbstractAction("Move Up", GUIUtilities.loadIcon("ArrowU.png")) { - { - putValue(Action.SHORT_DESCRIPTION, jEdit.getProperty("common.moveUp")); - } - @Override - public void actionPerformed(ActionEvent ev) { - int row=foldConfigsTable.getSelectedIndex(); - if(row<0) - return; - if(getModeConfig()!=null) { - if(getModeConfig().moveUp(row)) { - foldConfigsTable.fireTableDataChanged(); - foldConfigsTable.setSelectedRow(row-1); - } - } - } - }, - new AbstractAction("Move Down", GUIUtilities.loadIcon("ArrowD.png")) { - { - putValue(Action.SHORT_DESCRIPTION, jEdit.getProperty("common.moveDown")); - } - @Override - public void actionPerformed(ActionEvent ev) { - int row=foldConfigsTable.getSelectedIndex(); - if(row<0) - return; - if(getModeConfig()!=null) { - if(getModeConfig().moveDown(row)) { - foldConfigsTable.fireTableDataChanged(); - foldConfigsTable.setSelectedRow(row+1); - } - } - } - }, - }; - - { - //BoxLayout l=new BoxLayout(panel, BoxLayout.X_AXIS); - //panel.setLayout(l); - panel.setRollover(true); - panel.setBorderPainted(false); - panel.setFloatable(false); - - for(int i=0; i<actions.length; i++){ - JButton b=panel.add(actions[i]); - b.setText(null); - } - } - - FoldConfigsOpPanel(FoldConfigsTable foldConfigsTable) { - this.foldConfigsTable=foldConfigsTable; - } - - ModeConfig getModeConfig() { - return foldConfigsTable.getModeConfig(); - } - - void setEnabled(boolean enabled) { - for(int i=actions.length; --i>=0;) - actions[i].setEnabled(enabled); - } -} Deleted: plugins/CandyFolds/trunk/candyfolds/config/gui/FoldConfigsTable.java =================================================================== --- plugins/CandyFolds/trunk/candyfolds/config/gui/FoldConfigsTable.java 2009-11-02 00:36:34 UTC (rev 16429) +++ plugins/CandyFolds/trunk/candyfolds/config/gui/FoldConfigsTable.java 2009-11-02 01:40:59 UTC (rev 16430) @@ -1,257 +0,0 @@ -/* % [{ -% (C) Copyright 2008 Nicolas Carranza and individual contributors. -% See the CandyFolds-copyright.txt file in the CandyFolds distribution for a full -% listing of individual contributors. -% -% This file is part of CandyFolds. -% -% CandyFolds 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 3 of the License, -% or (at your option) any later version. -% -% CandyFolds 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 CandyFolds. If not, see <http://www.gnu.org/licenses/>. -% }] */ -package candyfolds.config.gui; - -import candyfolds.config.FoldConfig; -import candyfolds.config.ModeConfig; -import java.awt.Color; -import java.awt.Component; -import java.awt.Dimension; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.awt.event.FocusAdapter; -import java.awt.event.FocusEvent; -import java.awt.Graphics; -import java.awt.Graphics2D; -import java.awt.Rectangle; -import java.util.regex.PatternSyntaxException; -import javax.swing.AbstractCellEditor; -import javax.swing.CellEditor; -import javax.swing.JButton; -import javax.swing.JColorChooser; -import javax.swing.JComponent; -import javax.swing.JLabel; -import javax.swing.JTable; -import javax.swing.table.AbstractTableModel; -import javax.swing.table.DefaultTableCellRenderer; -import javax.swing.table.TableCellEditor; -import javax.swing.table.TableCellRenderer; -import org.gjt.sp.util.Log; - -class FoldConfigsTable - extends AbstractTableModel { - private ModeConfig modeConfig; - - JTable table=new JTable(this); - - FoldConfigsTable() { - table.getColumnModel().getColumn(0).setMaxWidth(20); - table.setDefaultRenderer(Color.class, new ColorCellRenderer()); - table.setDefaultEditor(Color.class, new ColorCellEditor()); - } - - void save(){ - CellEditor cellEditor=table.getCellEditor(); - if(cellEditor!=null) - cellEditor.stopCellEditing(); - } - - class ColorCellRenderer - extends DefaultTableCellRenderer { - private Color color; - private Rectangle rectangle=new Rectangle(0, 0, 0,0); - {setOpaque(true);} - @Override - public Component getTableCellRendererComponent(JTable table, - Object value, - boolean isSelected, - boolean hasFocus, - int row, - int column) { - super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); - setValue(null); - FoldConfig foldConfig=getFoldConfig(row); - //Log.log(Log.NOTICE, this, "foldConfig on Renderer: "+foldConfig.getName()); - if(foldConfig==null) { - throw new AssertionError(); - } - color=foldConfig.getColor(); - return this; - } - @Override - public void paintComponent(Graphics g) { - super.paintComponent(g); - g.setColor(color); - Dimension d=getSize(); - g.fillRect(2, 2, d.width-4, d.height-4); - } - } - - class ColorCellEditor - extends AbstractCellEditor - implements TableCellEditor { - - private Color color; - - private final JButton button=new JButton() { - { - addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent ev) { - Color newColor=FullColorChooser.showDialog(button, "Select Candy Color", color); - if(newColor!=null) - color=newColor; - fireEditingStopped(); - } - } - ); - } - @Override - public void paintComponent(Graphics g) { - Dimension d=getSize(); - g.setColor(Color.white); - g.fillRect(2, 2, d.width-4, d.height-4); - g.setColor(color); - g.fillRect(2, 2, d.width-4, d.height-4); - } - }; - - @Override - public Component getTableCellEditorComponent(JTable table, - Object value, - boolean isSelected, - int row, - int column) { - FoldConfig foldConfig=getFoldConfig(row); - //Log.log(Log.NOTICE, this, "foldConfig of cellEditor: "+foldConfig.getName()); - if(foldConfig==null) - throw new AssertionError(); - this.color=foldConfig.getColor(); - return button; - } - - @Override - public Object getCellEditorValue() { - return color; - } - } - - public void setModeConfig(ModeConfig modeConfig) { - this.modeConfig=modeConfig; - fireTableDataChanged(); - } - - ModeConfig getModeConfig() { - return modeConfig; - } - - @Override - public int getRowCount() { - return modeConfig==null? 0: modeConfig.foldConfigsA.size(); - } - @Override - public int getColumnCount() { - return 3; - } - @Override - public String getColumnName(int col) { - switch(col) { - case 0: - return "" ; - case 1: - return "Name"; - case 2: - return "Regular Expression"; - default: - return null; - } - } - - int getSelectedIndex() { - return table.getSelectedRow(); - } - - void setSelectedRow(int row) { - if(row<0 || row>=modeConfig.foldConfigsA.size()) - return; - table.setRowSelectionInterval(row, row); - } - - FoldConfig getSelected() { - int row=table.getSelectedRow(); - if(row<0) - return null; - return modeConfig.foldConfigsA.get(row); - } - - private FoldConfig getFoldConfig(int row) { - return modeConfig==null? null: modeConfig.foldConfigsA.get(row); - } - - @Override - public Object getValueAt(int row, int col) { - FoldConfig foldConfig=getFoldConfig(row); - if(foldConfig==null) - return null; - switch(col) { - case 0: - return foldConfig.getColor(); - case 1 : - return foldConfig.getName(); - case 2: - return foldConfig.getRegex(); - default: - return null; - } - } - - @Override - public Class getColumnClass(int col) { - switch(col) { - case 0: - return Color.class; - default: - return String.class; - } - } - - @Override - public boolean isCellEditable(int row, int col) { - if(modeConfig!=null && modeConfig==modeConfig.config.defaultModeConfig && - col!=0) - return false; - return true; - } - - @Override - public void setValueAt(Object o, int row, int col) { - FoldConfig foldConfig=getFoldConfig(row); - if(foldConfig==null) - throw new AssertionError(); - switch(col) { - case 0: - Color color=(Color)o; - foldConfig.setColor(color); - break; - case 1: - String name=(String)o; - foldConfig.setName(name); - break; - case 2: - try { - String regex=(String)o; - foldConfig.setRegex(regex); - } catch(PatternSyntaxException ex) {} - break; - } - } - -} \ No newline at end of file Modified: plugins/CandyFolds/trunk/candyfolds/config/gui/ModeConfigPanel.java =================================================================== --- plugins/CandyFolds/trunk/candyfolds/config/gui/ModeConfigPanel.java 2009-11-02 00:36:34 UTC (rev 16429) +++ plugins/CandyFolds/trunk/candyfolds/config/gui/ModeConfigPanel.java 2009-11-02 01:40:59 UTC (rev 16430) @@ -20,35 +20,37 @@ % }] */ package candyfolds.config.gui; +import candyfolds.config.ModeConfig; import java.awt.BorderLayout; import java.awt.Dimension; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.BorderFactory; +import javax.swing.Box; +import javax.swing.BoxLayout; import javax.swing.JCheckBox; import javax.swing.JPanel; import javax.swing.JScrollPane; -import candyfolds.config.ModeConfig; class ModeConfigPanel { final JPanel panel=new JPanel(new BorderLayout()); private ModeConfig modeConfig; final JCheckBox enabledCB=new JCheckBox("Enable CandyFolds for this mode"); - private final FoldConfigsTable foldConfigsTable=new FoldConfigsTable(); + final JCheckBox useBigLinesForStripConfigsCB=new JCheckBox("Prefer matching against lines with more than 1 non-space characters"); + private final StripConfigsTable stripConfigsTable=new StripConfigsTable(); private final JPanel tablePanel=new JPanel(new BorderLayout()); - private final FoldConfigsOpPanel foldConfigsOpPanel=new FoldConfigsOpPanel(foldConfigsTable); + private final StripConfigsOpPanel stripConfigsOpPanel=new StripConfigsOpPanel(stripConfigsTable); { - JScrollPane sp=new JScrollPane(foldConfigsTable.table); + JScrollPane sp=new JScrollPane(stripConfigsTable.table); sp.setPreferredSize(new Dimension(10, 10)); sp.setBorder(BorderFactory.createEmptyBorder(3, 0, 0, 0)); tablePanel.add(sp); - tablePanel.add(foldConfigsOpPanel.panel, BorderLayout.SOUTH); + tablePanel.add(stripConfigsOpPanel.panel, BorderLayout.SOUTH); //tablePanel.setBorder(BorderFactory.createTitledBorder("Candies")); - panel.add(tablePanel); - panel.add(enabledCB, BorderLayout.NORTH); - + + Box box=new Box(BoxLayout.Y_AXIS); enabledCB.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent ev) { @@ -58,31 +60,46 @@ } } ); + box.add(enabledCB); + useBigLinesForStripConfigsCB.addActionListener(new ActionListener(){ + @Override + public void actionPerformed(ActionEvent ev){ + if(modeConfig!=null) + modeConfig.setUseBigLinesForStripConfigs(useBigLinesForStripConfigsCB.isSelected()); + updateView(); + } + }); + box.add(useBigLinesForStripConfigsCB); + panel.add(box, BorderLayout.NORTH); + updateView(); } void setModeConfig(ModeConfig modeConfig) { this.modeConfig=modeConfig; - foldConfigsTable.setModeConfig(modeConfig); + stripConfigsTable.setModeConfig(modeConfig); updateView(); } private void updateView() { if(modeConfig!=null) { enabledCB.setSelected(modeConfig.getEnabled()); - enabledCB.setVisible(modeConfig!=modeConfig.config.defaultModeConfig); - foldConfigsOpPanel.panel.setVisible( + boolean isDefault=modeConfig!=modeConfig.config.defaultModeConfig; + enabledCB.setVisible(isDefault); + useBigLinesForStripConfigsCB.setSelected(modeConfig.getUseBigLinesForStripConfigs()); + stripConfigsOpPanel.panel.setVisible( modeConfig!=modeConfig.config.defaultModeConfig); } - setEnabledFoldConfigs(enabledCB.isSelected()); + useBigLinesForStripConfigsCB.setEnabled(enabledCB.isSelected()); + setEnabledStripConfigs(enabledCB.isSelected()); } - private void setEnabledFoldConfigs(boolean enabled) { - foldConfigsTable.table.setEnabled(enabled); - foldConfigsOpPanel.setEnabled(enabled); + private void setEnabledStripConfigs(boolean enabled) { + stripConfigsTable.table.setEnabled(enabled); + stripConfigsOpPanel.setEnabled(enabled); } - + void save(){ - foldConfigsTable.save(); + stripConfigsTable.save(); } -} +} \ No newline at end of file Added: plugins/CandyFolds/trunk/candyfolds/config/gui/StripConfigsOpPanel.java =================================================================== --- plugins/CandyFolds/trunk/candyfolds/config/gui/StripConfigsOpPanel.java (rev 0) +++ plugins/CandyFolds/trunk/candyfolds/config/gui/StripConfigsOpPanel.java 2009-11-02 01:40:59 UTC (rev 16430) @@ -0,0 +1,127 @@ +/* % [{ +% (C) Copyright 2008 Nicolas Carranza and individual contributors. +% See the CandyFolds-copyright.txt file in the CandyFolds distribution for a full +% listing of individual contributors. +% +% This file is part of CandyFolds. +% +% CandyFolds 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 3 of the License, +% or (at your option) any later version. +% +% CandyFolds 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 CandyFolds. If not, see <http://www.gnu.org/licenses/>. +% }] */ +package candyfolds.config.gui; + +import java.awt.event.ActionEvent; +import javax.swing.AbstractAction; +import javax.swing.Action; +import javax.swing.BoxLayout; +import javax.swing.JButton; +import javax.swing.JPanel; +import javax.swing.JToolBar; +import candyfolds.config.StripConfig; +import candyfolds.config.ModeConfig; +import org.gjt.sp.jedit.GUIUtilities; +import org.gjt.sp.jedit.jEdit; + +class StripConfigsOpPanel { + final JToolBar panel=new JToolBar(); + private final StripConfigsTable stripConfigsTable; + final Action[] actions=new Action[]{ + new AbstractAction("Add", GUIUtilities.loadIcon("Plus.png")) { + { + putValue(Action.SHORT_DESCRIPTION, jEdit.getProperty("common.add")); + } + @Override + public void actionPerformed(ActionEvent ev) { + if(getModeConfig()!=null) { + getModeConfig().addStripConfig(); + stripConfigsTable.fireTableDataChanged(); + } + } + }, + new AbstractAction("Remove", GUIUtilities.loadIcon("Minus.png")) { + { + putValue(Action.SHORT_DESCRIPTION, jEdit.getProperty("common.remove")); + } + @Override + public void actionPerformed(ActionEvent ev) { + int row=stripConfigsTable.getSelectedIndex(); + if(row<0) + return; + if(getModeConfig()!=null) { + getModeConfig().removeStripConfig(row); + stripConfigsTable.fireTableDataChanged(); + } + } + }, + new AbstractAction("Move Up", GUIUtilities.loadIcon("ArrowU.png")) { + { + putValue(Action.SHORT_DESCRIPTION, jEdit.getProperty("common.moveUp")); + } + @Override + public void actionPerformed(ActionEvent ev) { + int row=stripConfigsTable.getSelectedIndex(); + if(row<0) + return; + if(getModeConfig()!=null) { + if(getModeConfig().moveUp(row)) { + stripConfigsTable.fireTableDataChanged(); + stripConfigsTable.setSelectedRow(row-1); + } + } + } + }, + new AbstractAction("Move Down", GUIUtilities.loadIcon("ArrowD.png")) { + { + putValue(Action.SHORT_DESCRIPTION, jEdit.getProperty("common.moveDown")); + } + @Override + public void actionPerformed(ActionEvent ev) { + int row=stripConfigsTable.getSelectedIndex(); + if(row<0) + return; + if(getModeConfig()!=null) { + if(getModeConfig().moveDown(row)) { + stripConfigsTable.fireTableDataChanged(); + stripConfigsTable.setSelectedRow(row+1); + } + } + } + }, + }; + + { + //BoxLayout l=new BoxLayout(panel, BoxLayout.X_AXIS); + //pan... [truncated message content] |
From: <nic...@us...> - 2009-11-06 15:26:00
|
Revision: 16446 http://jedit.svn.sourceforge.net/jedit/?rev=16446&view=rev Author: nicarran Date: 2009-11-06 15:25:50 +0000 (Fri, 06 Nov 2009) Log Message: ----------- * Some changes on LineInfo to make guidelines a little less "aggresive": ** guidelines on empty lines are now calculated only using lines below. * Cleanups. Modified Paths: -------------- plugins/CandyFolds/trunk/CandyFolds.props plugins/CandyFolds/trunk/candyfolds/LineInfo.java plugins/CandyFolds/trunk/candyfolds/TextAreaExt.java Modified: plugins/CandyFolds/trunk/CandyFolds.props =================================================================== --- plugins/CandyFolds/trunk/CandyFolds.props 2009-11-05 20:26:58 UTC (rev 16445) +++ plugins/CandyFolds/trunk/CandyFolds.props 2009-11-06 15:25:50 UTC (rev 16446) @@ -2,7 +2,7 @@ plugin.candyfolds.CandyFoldsPlugin.name=CandyFolds plugin.candyfolds.CandyFoldsPlugin.author=Nicol\xE1s Carranza # inspired and based on work by Andr\xE9 Kaplan & Nathan Jones (WhiteSpace plugin) -plugin.candyfolds.CandyFoldsPlugin.version=1.1.0 +plugin.candyfolds.CandyFoldsPlugin.version=1.1.1 plugin.candyfolds.CandyFoldsPlugin.description=CandyFolds draws colored indentation-guides on the text area to improve code readability. plugin.candyfolds.CandyFoldsPlugin.docs=index.html Modified: plugins/CandyFolds/trunk/candyfolds/LineInfo.java =================================================================== --- plugins/CandyFolds/trunk/candyfolds/LineInfo.java 2009-11-05 20:26:58 UTC (rev 16445) +++ plugins/CandyFolds/trunk/candyfolds/LineInfo.java 2009-11-06 15:25:50 UTC (rev 16446) @@ -40,7 +40,7 @@ private final List<Integer> indents=new ArrayList<Integer>(); private final List<Integer> lines=new ArrayList<Integer>(); // lines where the indents belong (1:1). private final List<StripConfig> stripConfigs=new ArrayList<StripConfig>(); - + LineInfo(TextAreaExt textAreaExt) { this.textAreaExt=textAreaExt; } @@ -67,52 +67,32 @@ lines.clear(); stripConfigs.clear(); } - - void copyFrom(LineInfo lineInfo){ - clear(); - line=lineInfo.line; - indents.addAll(lineInfo.indents); - lines.addAll(lineInfo.lines); - stripConfigs.addAll(lineInfo.stripConfigs); - } - void eval(Buffer buffer, int line){ + void eval(Buffer buffer, final int line){ eval(buffer, line, null); } - void eval(Buffer buffer, int line, LineInfo upLineInfo){ + void eval(Buffer buffer, final int line, LineInfo upLineInfo){ clear(); this.line=line; int upLine= upLineInfo==null? 0: upLineInfo.line+1; - + int calcLine; if(isEmptySegment(buffer, line)){ - int firstIndentUp=-1, firstIndentUpLine=line; - for(int i=line; i>=upLine; i--){ - if(i!=0 && isEmptySegment(buffer, i)) - continue; - firstIndentUp=buffer.getCurrentIndentForLine(i, null); - firstIndentUpLine=i; - break; - } - if(firstIndentUp==-1){ - firstIndentUp=upLineInfo.lineIndent; - firstIndentUpLine=upLineInfo.line; - } int firstIndentDown=-1, firstIndentDownLine=line; - for(int i=line, lineCount=buffer.getLineCount(); i<lineCount; i++){ // TODO: optimize for performance on large files with a lot of empty lines... + for(int i=line+1, lineCount=buffer.getLineCount(); i<lineCount; i++){ // TODO: optimize for performance on large files with a lot of empty lines... if(isEmptySegment(buffer, i)) continue; firstIndentDown=buffer.getCurrentIndentForLine(i, null); firstIndentDownLine=i; break; } - if(firstIndentDown>firstIndentUp){ + if(firstIndentDown!=-1){ calcLine=firstIndentDownLine; lineIndent=firstIndentDown; }else{ - calcLine=firstIndentUpLine; - lineIndent=firstIndentUp; + calcLine=line; + lineIndent=0; } } else{ @@ -124,7 +104,7 @@ for(; calcLine>=upLine; calcLine--) { indent=buffer.getCurrentIndentForLine(calcLine, null); if(indent>=lastCaughtIndent || - indent>lineIndent) + indent>lineIndent) continue; if(isEmptySegment(buffer, calcLine)) continue; @@ -138,12 +118,12 @@ } if(upLineInfo!=null - && lastCaughtIndent>0 // optimization - ){ + && lastCaughtIndent>0 // optimization + ){ for(int i=0; i<upLineInfo.indents.size(); i++){ indent=upLineInfo.indents.get(i); if(indent>=lastCaughtIndent || - indent>lineIndent) + indent>lineIndent) continue; lastCaughtIndent=indent; //L.fine("line="+line+", adding upLineInfo indent="+indent); @@ -180,14 +160,18 @@ buffer.getLineText(prevLine, segment); int segmentContentLength=evalSegmentContentLength(segment); if(segmentContentLength==0) - continue; + break; int prevLineIndent=buffer.getCurrentIndentForLine(prevLine, null); if(prevLineIndent>lineIndent) continue; if(prevLineIndent<lineIndent) break; - if(segmentContentLength==1) + if(segmentContentLength==1){ + if(line!=prevLine && + lineIndent==prevLineIndent) + break; continue; + } usePrevLine=true; // -> the segment is ready on prevLine break; Modified: plugins/CandyFolds/trunk/candyfolds/TextAreaExt.java =================================================================== --- plugins/CandyFolds/trunk/candyfolds/TextAreaExt.java 2009-11-05 20:26:58 UTC (rev 16445) +++ plugins/CandyFolds/trunk/candyfolds/TextAreaExt.java 2009-11-06 15:25:50 UTC (rev 16446) @@ -61,28 +61,10 @@ final EditPane editPane; private final TextAreaPainter painter; - /* - private final LineInfo firstLineInfo=new LineInfo(this); - private Buffer firstLineInfoBuffer; - private final BufferListener firstLineInfoBufferL=new BufferAdapter(){ - @Override - public void contentInserted(JEditBuffer buffer, int startLine, int offset, int numLines, int length){ - contentChanged(); - } - @Override - public void contentRemoved(JEditBuffer buffer, int startLine, int offset, int numLines, int length){ - contentChanged(); - } - private void contentChanged(){ - unregisterFirstLineInfoBuffer(); - } - };*/ private LineInfo previousLineInfo=new LineInfo(this); private LineInfo currentLineInfo=new LineInfo(this); //private final LineInfo toolTipLineInfo=new LineInfo(this); - - private final FontMetricsInfo fontMetricsInfo=new FontMetricsInfo(); private static final class FontMetricsInfo { @@ -99,7 +81,6 @@ lineHeight=fontMetrics.getHeight(); barStroke=new BasicStroke(spaceWidth/2.3f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_ROUND); } - } private ModeConfig modeConfig; @@ -138,24 +119,22 @@ @Override public void paintValidLine(Graphics2D g, - int screenLine, - int physicalLine, - int start, - int end, - int y) { - //lineInfo.eval(editPane.getBuffer(), physicalLine); - //drawLine(lineInfo, g, y); + int screenLine, + int physicalLine, + int start, + int end, + int y) { } @Override public synchronized void paintScreenLineRange(Graphics2D g, - int firstLine, - int lastLine, - int[] physicalLines, - int[] start, - int[] end, - int y, - int lineHeight) { + int firstLine, + int lastLine, + int[] physicalLines, + int[] start, + int[] end, + int y, + int lineHeight){ //Log.log(Log.NOTICE, this, "painting range: firstLine="+firstLine+", lastLine=" + lastLine + ", y=" + y+"lineHeight="+lineHeight); //long nanoTime=System.nanoTime(); Buffer buffer = editPane.getBuffer(); @@ -167,16 +146,8 @@ int line=physicalLines[i]; if(line==-1) continue; - if(i==0){ - /* this optimization does not worth the effort! - if(firstLineInfoBuffer!=buffer // firstLineInfoBuffer is set to null when buffer changes - || firstLineInfo.getLine()!=line){ - firstLineInfo.eval(buffer, line); - registerFirstLineInfoBuffer(buffer); - } - currentLineInfo.copyFrom(firstLineInfo);*/ + if(i==0) currentLineInfo.eval(buffer, line); - } else currentLineInfo.eval(buffer, line, previousLineInfo); drawLineIndents(buffer, currentLineInfo, g, y); @@ -189,21 +160,6 @@ //L.fine("new painting time="+(System.nanoTime()-nanoTime)); } - /* - private synchronized void registerFirstLineInfoBuffer(Buffer buffer){ - if(buffer==firstLineInfoBuffer) - return; - unregisterFirstLineInfoBuffer(); - firstLineInfoBuffer=buffer; - firstLineInfoBuffer.addBufferListener(firstLineInfoBufferL); - } - - private synchronized void unregisterFirstLineInfoBuffer(){ - if(firstLineInfoBuffer!=null) - firstLineInfoBuffer.removeBufferListener(firstLineInfoBufferL); - firstLineInfoBuffer=null; - }*/ - private void drawLineIndents(Buffer buffer, LineInfo lineInfo, Graphics2D g, int y) { fontMetricsInfo.setFontMetrics(painter.getFontMetrics()); Stroke gStroke=g.getStroke(); @@ -261,5 +217,5 @@ } } return null; -}*/ + }*/ } \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <nic...@us...> - 2009-11-11 07:01:19
|
Revision: 16469 http://jedit.svn.sourceforge.net/jedit/?rev=16469&view=rev Author: nicarran Date: 2009-11-11 07:01:12 +0000 (Wed, 11 Nov 2009) Log Message: ----------- * New ModeConfig.showStripOn0Indent field. Modified Paths: -------------- plugins/CandyFolds/trunk/CandyFolds.props plugins/CandyFolds/trunk/candyfolds/TextAreaExt.java plugins/CandyFolds/trunk/candyfolds/config/ModeConfig.java plugins/CandyFolds/trunk/candyfolds/config/gui/ModeConfigPanel.java Modified: plugins/CandyFolds/trunk/CandyFolds.props =================================================================== --- plugins/CandyFolds/trunk/CandyFolds.props 2009-11-10 08:14:34 UTC (rev 16468) +++ plugins/CandyFolds/trunk/CandyFolds.props 2009-11-11 07:01:12 UTC (rev 16469) @@ -2,7 +2,7 @@ plugin.candyfolds.CandyFoldsPlugin.name=CandyFolds plugin.candyfolds.CandyFoldsPlugin.author=Nicol\xE1s Carranza # inspired and based on work by Andr\xE9 Kaplan & Nathan Jones (WhiteSpace plugin) -plugin.candyfolds.CandyFoldsPlugin.version=1.1.1 +plugin.candyfolds.CandyFoldsPlugin.version=1.1.2 plugin.candyfolds.CandyFoldsPlugin.description=CandyFolds draws colored indentation-guides on the text area to improve code readability. plugin.candyfolds.CandyFoldsPlugin.docs=index.html Modified: plugins/CandyFolds/trunk/candyfolds/TextAreaExt.java =================================================================== --- plugins/CandyFolds/trunk/candyfolds/TextAreaExt.java 2009-11-10 08:14:34 UTC (rev 16468) +++ plugins/CandyFolds/trunk/candyfolds/TextAreaExt.java 2009-11-11 07:01:12 UTC (rev 16469) @@ -170,7 +170,7 @@ for (int i =lineInfo.getIndentsSize();--i>=1;) {// ATTENTION: omit the first indent =lineInfo.getIndent(i); - if(indent==0) + if(indent==0 && !modeConfig.getShowStripOn0Indent()) continue; //Log.log(Log.NOTICE, this, "painting indent="+indent); Color color=lineInfo.getStripConfig(i).getColor(); @@ -204,7 +204,7 @@ rect.height=fontMetricsInfo.lineHeight; int indent; int horizontalOffset=ta.getHorizontalOffset(); - for (int i =toolTipLineInfo.indents.size();--i>=1;) { // ignore the first. Iteration from outer to inner fold. the first is right above the first char of the line. + for (int i =toolTipLineInfo.indents.size();--i>=1;) { // ignore the first. Iteration from outer to inner fold. the first (i=0) is right over the first char of the line. indent =toolTipLineInfo.indents.get(i); if(indent==0) continue; Modified: plugins/CandyFolds/trunk/candyfolds/config/ModeConfig.java =================================================================== --- plugins/CandyFolds/trunk/candyfolds/config/ModeConfig.java 2009-11-10 08:14:34 UTC (rev 16468) +++ plugins/CandyFolds/trunk/candyfolds/config/ModeConfig.java 2009-11-11 07:01:12 UTC (rev 16469) @@ -28,13 +28,14 @@ import javax.swing.text.Segment; public final class ModeConfig { - public static final int MAX_FOLD_CONFIGS=20; + public static final int MAX_STRIP_CONFIGS=25; public final Config config; public final String name; private final List<StripConfig> stripConfigs=new ArrayList<StripConfig>(); public final List<StripConfig> stripConfigsA=Collections.unmodifiableList(stripConfigs); private boolean enabled=true; private boolean useBigLinesForStripConfigs=true; + private boolean showStripOn0Indent=false; ModeConfig(Config config, String name) { this.config=config; @@ -58,9 +59,18 @@ public void setUseBigLinesForStripConfigs(boolean useBigLinesForStripConfigs){ this.useBigLinesForStripConfigs=useBigLinesForStripConfigs; } + + public boolean getShowStripOn0Indent(){ + return showStripOn0Indent; + } + + public void setShowStripOn0Indent(boolean showStripOn0Indent){ + this.showStripOn0Indent=showStripOn0Indent; + } public StripConfig addStripConfig() { - if(config.defaultModeConfig==this && !stripConfigs.isEmpty()) + if((config.defaultModeConfig==this && !stripConfigs.isEmpty()) + || stripConfigs.size()==MAX_STRIP_CONFIGS) return null; StripConfig stripConfig=new StripConfig(); stripConfigs.add(stripConfig); @@ -104,7 +114,8 @@ ps.clear(); ps.setProperty(getPropertyName(sb, "enabled"), String.valueOf(enabled)); ps.setProperty(getPropertyName(sb, "bigLines"), String.valueOf(useBigLinesForStripConfigs)); - for(int i=0, size=stripConfigs.size(); i<size && i<MAX_FOLD_CONFIGS; i++) { + ps.setProperty(getPropertyName(sb, "showStripOn0Indent"), String.valueOf(showStripOn0Indent)); + for(int i=0, size=stripConfigs.size(); i<size && i<MAX_STRIP_CONFIGS; i++) { stripConfigs.get(i).store(ps, this, sb, i); } } @@ -132,8 +143,10 @@ ps.getProperty(getPropertyName(sb, "enabled")))); setUseBigLinesForStripConfigs(Boolean.valueOf( ps.getProperty(getPropertyName(sb, "bigLines")))); + setShowStripOn0Indent(Boolean.valueOf( + ps.getProperty(getPropertyName(sb, "showStripOn0Indent")))); stripConfigs.clear(); - for(int i=0; i<MAX_FOLD_CONFIGS; i++) { + for(int i=0; i<MAX_STRIP_CONFIGS; i++) { StripConfig stripConfig=new StripConfig(); if(stripConfig.load(ps, this, sb, i)) { stripConfigs.add(stripConfig); Modified: plugins/CandyFolds/trunk/candyfolds/config/gui/ModeConfigPanel.java =================================================================== --- plugins/CandyFolds/trunk/candyfolds/config/gui/ModeConfigPanel.java 2009-11-10 08:14:34 UTC (rev 16468) +++ plugins/CandyFolds/trunk/candyfolds/config/gui/ModeConfigPanel.java 2009-11-11 07:01:12 UTC (rev 16469) @@ -37,6 +37,7 @@ private ModeConfig modeConfig; final JCheckBox enabledCB=new JCheckBox("Enable CandyFolds for this mode"); final JCheckBox useBigLinesForStripConfigsCB=new JCheckBox("Prefer matching against lines with more than 1 non-space characters"); + final JCheckBox showStripOn0IndentCB=new JCheckBox("Show indentation-guide on left edge"); private final StripConfigsTable stripConfigsTable=new StripConfigsTable(); private final JPanel tablePanel=new JPanel(new BorderLayout()); private final StripConfigsOpPanel stripConfigsOpPanel=new StripConfigsOpPanel(stripConfigsTable); @@ -70,6 +71,15 @@ } }); box.add(useBigLinesForStripConfigsCB); + showStripOn0IndentCB.addActionListener(new ActionListener(){ + @Override + public void actionPerformed(ActionEvent ev){ + if(modeConfig!=null) + modeConfig.setShowStripOn0Indent(showStripOn0IndentCB.isSelected()); + updateView(); + } + }); + box.add(showStripOn0IndentCB); panel.add(box, BorderLayout.NORTH); updateView(); @@ -87,10 +97,12 @@ boolean isDefault=modeConfig!=modeConfig.config.defaultModeConfig; enabledCB.setVisible(isDefault); useBigLinesForStripConfigsCB.setSelected(modeConfig.getUseBigLinesForStripConfigs()); + showStripOn0IndentCB.setSelected(modeConfig.getShowStripOn0Indent()); stripConfigsOpPanel.panel.setVisible( modeConfig!=modeConfig.config.defaultModeConfig); } useBigLinesForStripConfigsCB.setEnabled(enabledCB.isSelected()); + showStripOn0IndentCB.setEnabled(enabledCB.isSelected()); setEnabledStripConfigs(enabledCB.isSelected()); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <nic...@us...> - 2012-10-02 15:07:39
|
Revision: 22278 http://jedit.svn.sourceforge.net/jedit/?rev=22278&view=rev Author: nicarran Date: 2012-10-02 15:07:27 +0000 (Tue, 02 Oct 2012) Log Message: ----------- - New ignoreLineRegex property on the mode configuration that allows to ignore lines given a regex (this new property superseeds the old useBigLinesForStripConfigs) - Added (but commented out) tool to change the line width. Was commented out because I found it wasn't really useful. Some of this code will be useful to add tool to change the line type (dotted, continuous...) in a next realease. Modified Paths: -------------- plugins/CandyFolds/trunk/CandyFolds-copyright.txt plugins/CandyFolds/trunk/candyfolds/LineInfo.java plugins/CandyFolds/trunk/candyfolds/TextAreaExt.java plugins/CandyFolds/trunk/candyfolds/config/ModeConfig.java plugins/CandyFolds/trunk/candyfolds/config/StripConfig.java plugins/CandyFolds/trunk/candyfolds/config/gui/ModeConfigPanel.java plugins/CandyFolds/trunk/candyfolds/config/gui/StripConfigsTable.java Added Paths: ----------- plugins/CandyFolds/trunk/candyfolds/config/Regex.java Modified: plugins/CandyFolds/trunk/CandyFolds-copyright.txt =================================================================== --- plugins/CandyFolds/trunk/CandyFolds-copyright.txt 2012-09-29 12:11:05 UTC (rev 22277) +++ plugins/CandyFolds/trunk/CandyFolds-copyright.txt 2012-10-02 15:07:27 UTC (rev 22278) @@ -7,7 +7,5 @@ A summary of the individual contributors is given below. Any omission should be sent to <nicarran at users.sourceforge.net>. ------------------------------------------------------------------------------- - -------------------------------------------------------------------------------- - -For more information about jpen, see <http://candyfolds.sf.net>. \ No newline at end of file + Jojaba [http://jojaba.free.fr] contributed fr translation (lang_fr.properties) +------------------------------------------------------------------------------- \ No newline at end of file Modified: plugins/CandyFolds/trunk/candyfolds/LineInfo.java =================================================================== --- plugins/CandyFolds/trunk/candyfolds/LineInfo.java 2012-09-29 12:11:05 UTC (rev 22277) +++ plugins/CandyFolds/trunk/candyfolds/LineInfo.java 2012-10-02 15:07:27 UTC (rev 22278) @@ -21,6 +21,7 @@ package candyfolds; import candyfolds.config.StripConfig; +import candyfolds.config.ModeConfig; import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -32,7 +33,7 @@ final class LineInfo { static final Logger L=Logger.getLogger(LineInfo.class.getName()); - static { L.setLevel(Level.ALL); } + //static { L.setLevel(Level.ALL); } private final TextAreaExt textAreaExt; private int line; @@ -45,9 +46,15 @@ this.textAreaExt=textAreaExt; } + /* int getLine(){ return line; } + */ + + int getLine(int i){ + return lines.get(i); + } int getIndentsSize(){ return indents.size(); @@ -111,8 +118,8 @@ lastCaughtIndent=indent; //L.fine("adding indent="+indent+" on line="+calcLine); indents.add(indent); + calcLine=addStripConfig(buffer, calcLine, indent); lines.add(calcLine); - addStripConfig(buffer, calcLine, indent); if(lastCaughtIndent==0) // optimization break; } @@ -146,39 +153,36 @@ return true; } - private void addStripConfig(Buffer buffer, int line, int lineIndent) { - prepareSegmentForStripConfig(buffer, line, lineIndent); + private int addStripConfig(Buffer buffer, int line, int lineIndent){ + line=prepareSegmentForStripConfig(buffer, line, lineIndent); StripConfig stripConfig=textAreaExt.getModeConfig().evalStripConfig(textAreaExt.segment); stripConfigs.add(stripConfig); + return line; } - private void prepareSegmentForStripConfig(final Buffer buffer, final int line, final int lineIndent){ + private int prepareSegmentForStripConfig(final Buffer buffer, final int line, final int lineIndent){ final Segment segment=textAreaExt.segment; - boolean usePrevLine=false; - if(textAreaExt.getModeConfig().getUseBigLinesForStripConfigs()){ - for( int prevLine=line ; prevLine>=0; prevLine-- ){ // TODO: use a limit instead of 0? + ModeConfig modeConfig=textAreaExt.getModeConfig(); + if(modeConfig.getUseIgnoreLineRegex()){ + for( int prevLine=line; prevLine>=0; prevLine-- ){ // TODO: use a limit instead of 0? buffer.getLineText(prevLine, segment); int segmentContentLength=evalSegmentContentLength(segment); if(segmentContentLength==0) break; int prevLineIndent=buffer.getCurrentIndentForLine(prevLine, null); - if(prevLineIndent>lineIndent) - continue; if(prevLineIndent<lineIndent) break; - if(segmentContentLength==1){ - if(line!=prevLine && - lineIndent==prevLineIndent) - break; + if(prevLineIndent>lineIndent) continue; - } - usePrevLine=true; - // -> the segment is ready on prevLine - break; + // -> here: lineIndent==prevLineIndent + if(modeConfig.ignoreLineRegex.matches(segment)) + continue; + // -> the segment is ready on the desired prevLine: + return prevLine; } } - if(!usePrevLine) - buffer.getLineText(line, segment); + buffer.getLineText(line, segment); + return line; } private static int evalSegmentContentLength(Segment segment){ Modified: plugins/CandyFolds/trunk/candyfolds/TextAreaExt.java =================================================================== --- plugins/CandyFolds/trunk/candyfolds/TextAreaExt.java 2012-09-29 12:11:05 UTC (rev 22277) +++ plugins/CandyFolds/trunk/candyfolds/TextAreaExt.java 2012-10-02 15:07:27 UTC (rev 22278) @@ -21,6 +21,7 @@ package candyfolds; import candyfolds.config.ModeConfig; +import candyfolds.config.StripConfig; import java.awt.BasicStroke; import java.awt.Color; import java.awt.FontMetrics; @@ -88,7 +89,7 @@ private final Line2D.Float line2D=new Line2D.Float(); final Segment segment=new Segment(); private final Rectangle rect=new Rectangle(); - + TextAreaExt(CandyFoldsPlugin foldsPlugin, EditPane editPane) { this.foldsPlugin=foldsPlugin; this.editPane=editPane; @@ -161,29 +162,44 @@ } private void drawLineIndents(Buffer buffer, LineInfo lineInfo, Graphics2D g, int y) { + fontMetricsInfo.setFontMetrics(painter.getFontMetrics()); - Stroke gStroke=g.getStroke(); - g.setStroke(fontMetricsInfo.barStroke); + /* + FontMetrics fontMetrics=painter.getFontMetrics(); + fontMetricsInfo.setFontMetrics(fontMetrics); + */ + int x; int indent; int horizontalOffset=editPane.getTextArea().getHorizontalOffset(); + Stroke gStroke=g.getStroke(); + g.setStroke(fontMetricsInfo.barStroke); for (int i =lineInfo.getIndentsSize();--i>=1;) {// ATTENTION: omit the first indent =lineInfo.getIndent(i); if(indent==0 && !modeConfig.getShowStripOn0Indent()) continue; //Log.log(Log.NOTICE, this, "painting indent="+indent); + /* + StripConfig stripConfig=lineInfo.getStripConfig(i); + Stroke stroke=stripConfig.fontMetricsInfo.getStroke(fontMetrics); + if(stroke==null) + continue; + g.setStroke(stroke); + Color color=stripConfig.getColor(); + */ Color color=lineInfo.getStripConfig(i).getColor(); if(color.getAlpha()==0) continue; g.setColor(color); + x= (int)((indent+0.4f )* fontMetricsInfo.spaceWidth+horizontalOffset); g.drawLine(x, y,x, y+fontMetricsInfo.lineHeight); } g.setStroke(gStroke); } - // DISABLED: does not worth the effort? + // DISABLED: not really useful? /* @Override public synchronized String getToolTipText(int x, int y) { @@ -196,7 +212,7 @@ } int physicalLine = ta.getLineOfOffset(offset); - toolTipLineInfo.eval(buffer, physicalLine); + toolTipLineInfo.eval(buffer, physicalLine); fontMetricsInfo.setFontMetrics(painter.getFontMetrics()); rect.y=ta.offsetToXY(physicalLine, 0).y; @@ -204,18 +220,20 @@ rect.height=fontMetricsInfo.lineHeight; int indent; int horizontalOffset=ta.getHorizontalOffset(); - for (int i =toolTipLineInfo.indents.size();--i>=1;) { // ignore the first. Iteration from outer to inner fold. the first (i=0) is right over the first char of the line. - indent =toolTipLineInfo.indents.get(i); - if(indent==0) + for (int i =toolTipLineInfo.getIndentsSize();--i>=1;) { // ignore the first. Iteration from outer to inner fold. the first (i=0) is right over the first char of the line. + indent =toolTipLineInfo.getIndent(i); + if(indent==0 && !getModeConfig().getShowStripOn0Indent()) continue; rect.x= (int)(indent* fontMetricsInfo.spaceWidth+horizontalOffset); if(rect.contains(x, y)){ //int foldLevel=toolTipLineInfo.foldLevels.get(i); - String stripConfigName=toolTipLineInfo.stripConfigs.get(i).getName(); - buffer.getLineText(toolTipLineInfo.lines.get(i), segment); - return segment.toString().trim()+"... : "+stripConfigName; + String stripConfigName=toolTipLineInfo.getStripConfig(i).getName(); + int line=toolTipLineInfo.getLine(i); + buffer.getLineText(line, segment); + return "<html><b>"+(line+1)+"</b> <u>"+stripConfigName+"</u>: "+segment.toString().trim()+"</html>"; } } return null; - }*/ + } + */ } \ No newline at end of file Modified: plugins/CandyFolds/trunk/candyfolds/config/ModeConfig.java =================================================================== --- plugins/CandyFolds/trunk/candyfolds/config/ModeConfig.java 2012-09-29 12:11:05 UTC (rev 22277) +++ plugins/CandyFolds/trunk/candyfolds/config/ModeConfig.java 2012-10-02 15:07:27 UTC (rev 22278) @@ -34,7 +34,8 @@ private final List<StripConfig> stripConfigs=new ArrayList<StripConfig>(); public final List<StripConfig> stripConfigsA=Collections.unmodifiableList(stripConfigs); private boolean enabled=true; - private boolean useBigLinesForStripConfigs=true; + private boolean useIgnoreLineRegex=false; + public final Regex ignoreLineRegex=new Regex(); private boolean showStripOn0Indent=false; ModeConfig(Config config, String name) { @@ -52,25 +53,25 @@ this.enabled=enabled; } - public boolean getUseBigLinesForStripConfigs(){ - return useBigLinesForStripConfigs; + public boolean getUseIgnoreLineRegex() { + return useIgnoreLineRegex; } - public void setUseBigLinesForStripConfigs(boolean useBigLinesForStripConfigs){ - this.useBigLinesForStripConfigs=useBigLinesForStripConfigs; + public void setUseIgnoreLineRegex(boolean useIgnoreLineRegex){ + this.useIgnoreLineRegex=useIgnoreLineRegex; } - + public boolean getShowStripOn0Indent(){ return showStripOn0Indent; } - + public void setShowStripOn0Indent(boolean showStripOn0Indent){ this.showStripOn0Indent=showStripOn0Indent; } public StripConfig addStripConfig() { if((config.defaultModeConfig==this && !stripConfigs.isEmpty()) - || stripConfigs.size()==MAX_STRIP_CONFIGS) + || stripConfigs.size()==MAX_STRIP_CONFIGS) return null; StripConfig stripConfig=new StripConfig(); stripConfigs.add(stripConfig); @@ -103,7 +104,7 @@ public StripConfig evalStripConfig(Segment segment) { for(StripConfig stripConfig: stripConfigs) { - if(stripConfig.matches(segment)) + if(stripConfig.regex.matches(segment)) return stripConfig; } return config.defaultModeConfig.stripConfigs.get(0); @@ -113,7 +114,12 @@ StringBuilder sb=new StringBuilder(); ps.clear(); ps.setProperty(getPropertyName(sb, "enabled"), String.valueOf(enabled)); - ps.setProperty(getPropertyName(sb, "bigLines"), String.valueOf(useBigLinesForStripConfigs)); + if(useIgnoreLineRegex){ + String ignoreLineRegexValue=ignoreLineRegex.getValue(); + if(ignoreLineRegexValue!=null && ignoreLineRegexValue.length()>0) + ps.setProperty(getPropertyName(sb, "ignoreLineRegex"), ignoreLineRegexValue); + }else + ps.remove(getPropertyName(sb, "ignoreLineRegex")); ps.setProperty(getPropertyName(sb, "showStripOn0Indent"), String.valueOf(showStripOn0Indent)); for(int i=0, size=stripConfigs.size(); i<size && i<MAX_STRIP_CONFIGS; i++) { stripConfigs.get(i).store(ps, this, sb, i); @@ -140,11 +146,21 @@ StringBuilder sb=new StringBuilder(); if(this!=config.defaultModeConfig) setEnabled(Boolean.valueOf( - ps.getProperty(getPropertyName(sb, "enabled")))); - setUseBigLinesForStripConfigs(Boolean.valueOf( - ps.getProperty(getPropertyName(sb, "bigLines")))); + ps.getProperty(getPropertyName(sb, "enabled")))); setShowStripOn0Indent(Boolean.valueOf( - ps.getProperty(getPropertyName(sb, "showStripOn0Indent")))); + ps.getProperty(getPropertyName(sb, "showStripOn0Indent")))); + //v support deprecated feature 'bigLines' with its ignoreLineRegexValue equivalent: + String ignoreLineRegexValue=null; + if(Boolean.valueOf( + ps.getProperty(getPropertyName(sb, "bigLines")))) + ignoreLineRegexValue="\\s*\\S\\s*$"; + //^ + if(ignoreLineRegexValue==null) + ignoreLineRegexValue=ps.getProperty(getPropertyName(sb, "ignoreLineRegex")); + if(ignoreLineRegexValue!=null){ + useIgnoreLineRegex=true; + ignoreLineRegex.setValue(ignoreLineRegexValue); + } stripConfigs.clear(); for(int i=0; i<MAX_STRIP_CONFIGS; i++) { StripConfig stripConfig=new StripConfig(); Added: plugins/CandyFolds/trunk/candyfolds/config/Regex.java =================================================================== --- plugins/CandyFolds/trunk/candyfolds/config/Regex.java (rev 0) +++ plugins/CandyFolds/trunk/candyfolds/config/Regex.java 2012-10-02 15:07:27 UTC (rev 22278) @@ -0,0 +1,64 @@ +/* % [{ +% (C) Copyright 2010 Nicolas Carranza and individual contributors. +% See the CandyFolds-copyright.txt file in the CandyFolds distribution for a full +% listing of individual contributors. +% +% This file is part of CandyFolds. +% +% CandyFolds 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 3 of the License, +% or (at your option) any later version. +% +% CandyFolds 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 CandyFolds. If not, see <http://www.gnu.org/licenses/>. +% }] */ +package candyfolds.config; + +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import java.util.regex.PatternSyntaxException; +import javax.swing.text.Segment; + +public final class Regex{ + private String value; + private Pattern pattern; + private Matcher matcher; + + public synchronized boolean matches(Segment segment) { + if(matcher==null) { + if(pattern==null) + return true; + else { + matcher=pattern.matcher(segment); + //Log.log(Log.NOTICE, this, "matcher setted"); + } + }else + matcher.reset(segment); + //long nanos=System.nanoTime(); + boolean r=matcher.lookingAt(); + //L.fine("regex time="+(System.nanoTime()-nanos)); // find() is slooow! + return r; + } + + public void setValue(String value) + throws PatternSyntaxException { + if(value!=null) { + value=value.trim(); + this.pattern=Pattern.compile(value); + } else + this.pattern=null; + this.value=value; + matcher=null; + } + + public String getValue() { + return value; + } + +} \ No newline at end of file Modified: plugins/CandyFolds/trunk/candyfolds/config/StripConfig.java =================================================================== --- plugins/CandyFolds/trunk/candyfolds/config/StripConfig.java 2012-09-29 12:11:05 UTC (rev 22277) +++ plugins/CandyFolds/trunk/candyfolds/config/StripConfig.java 2012-10-02 15:07:27 UTC (rev 22278) @@ -20,31 +20,63 @@ % }] */ package candyfolds.config; +import java.awt.BasicStroke; import java.awt.Color; +import java.awt.FontMetrics; +import java.awt.Stroke; import java.util.logging.Level; import java.util.logging.Logger; import java.util.Properties; -import java.util.regex.Matcher; -import java.util.regex.Pattern; -import java.util.regex.PatternSyntaxException; + import javax.swing.text.Segment; + import org.gjt.sp.util.Log; public final class StripConfig { static final Logger L=Logger.getLogger(StripConfig.class.getName()); static { L.setLevel(Level.ALL); } - + public static final Color DEFAULT_COLOR=new Color(181, 181, 181, 255); // WARNING: using transparency slows drawing (noticeable on my computer 2ghz pentium + radeon 9700...) private String name=""; private Color color=DEFAULT_COLOR; - private String regex; - private Pattern pattern; - private Matcher matcher; + public final Regex regex=new Regex(); + /* + private float strokeWidthFactor=1; + public final FontMetricsInfo fontMetricsInfo=new FontMetricsInfo(); + + public final class FontMetricsInfo{ + private FontMetrics fontMetrics; + private Stroke stroke; + + public void reset(){ + fontMetrics=null; + } + + public Stroke getStroke(FontMetrics fontMetrics){ + if(this.fontMetrics == fontMetrics) + return stroke; + this.fontMetrics = fontMetrics; + setupStroke(); + return stroke; + } + + private void setupStroke(){ + if(strokeWidthFactor==0){ + stroke=null; + return; + } + int spaceWidth = fontMetrics.charWidth(' '); + float strokeWidth=spaceWidth/2.3f * strokeWidthFactor; + stroke=new BasicStroke(strokeWidth, BasicStroke.CAP_BUTT, BasicStroke.JOIN_ROUND); + } + } + */ + StripConfig() { } - public String getName() { + public String getName(){ return name; } @@ -54,37 +86,6 @@ this.name=name.trim(); } - synchronized boolean matches(Segment segment) { - if(matcher==null) { - if(pattern==null) - return true; - else { - matcher=pattern.matcher(segment); - //Log.log(Log.NOTICE, this, "matcher setted"); - } - } else - matcher.reset(segment); - //long nanos=System.nanoTime(); - boolean r=matcher.lookingAt(); - //L.fine("regex time="+(System.nanoTime()-nanos)); // find() is slooow! - return r; - } - - public void setRegex(String regex) - throws PatternSyntaxException { - if(regex!=null) { - regex=regex.trim(); - this.pattern=Pattern.compile(regex); - } else - this.pattern=null; - this.regex=regex; - matcher=null; - } - - public String getRegex() { - return regex; - } - public void setColor(Color color) { if(color==null) throw new NullPointerException(); @@ -95,20 +96,37 @@ return color; } + /* + public void setStrokeWidthFactor(float strokeWidthFactor){ + if(strokeWidthFactor<0) + strokeWidthFactor=0; + this.strokeWidthFactor=strokeWidthFactor; + fontMetricsInfo.reset(); + } + + public float getStrokeWidthFactor() { + return strokeWidthFactor; + } + */ + boolean load(Properties ps, ModeConfig mc, StringBuilder sb, int i) { - String colorPropName= mc.getPropertyNameB(sb, String.valueOf(i)). - append(".color").toString(); - String regexPropName=mc.getPropertyNameB(sb, String.valueOf(i)). - append(".regex").toString(); - String namePropName=mc.getPropertyNameB(sb, String.valueOf(i)). - append(".name").toString(); - return load(ps, colorPropName, regexPropName, namePropName); + String iS=String.valueOf(i); + return load(ps, mc.getPropertyNameB(sb, iS). + append(".color").toString(), + mc.getPropertyNameB(sb, iS). + append(".regex").toString(), + mc.getPropertyNameB(sb, iS). + append(".name").toString()/*, + mc.getPropertyNameB(sb, iS). + append(".strokeWidthFactor").toString()*/ + ); } boolean load(Properties ps, - String colorPropName, - String regexPropName, - String namePropName) { + String colorPropName, + String regexPropName, + String namePropName/*, + String strokeWidthFactorPropName*/) { String colorS=ps.getProperty(colorPropName); if(colorS==null) return false; @@ -116,29 +134,37 @@ if(color==null) return false; setColor(color); - setRegex(ps.getProperty(regexPropName)); setName(ps.getProperty(namePropName)); + regex.setValue(ps.getProperty(regexPropName)); + //setStrokeWidthFactor(decodeStrokeWidthFactor(ps.getProperty(strokeWidthFactorPropName))); return true; } void store(Properties ps, ModeConfig mc, StringBuilder sb, int i) { - store(ps, mc.getPropertyNameB(sb, String.valueOf(i)). - append(".color").toString(), - mc.getPropertyNameB(sb, String.valueOf(i)). - append(".regex").toString(), - mc.getPropertyNameB(sb, String.valueOf(i)). - append(".name").toString() - ); + String iS=String.valueOf(i); + store(ps, + mc.getPropertyNameB(sb, iS). + append(".color").toString(), + mc.getPropertyNameB(sb, iS). + append(".regex").toString(), + mc.getPropertyNameB(sb, iS). + append(".name").toString()/*, + mc.getPropertyNameB(sb, iS). + append(".strokeWidthFactor").toString()*/ + ); } void store(Properties ps, - String colorPropName, - String regexPropName, - String namePropName) { + String colorPropName, + String regexPropName, + String namePropName/*, + String strokeWidthFactorPropName*/) { ps.setProperty(colorPropName, encodeColor(new StringBuilder(), color)); - if(regex!=null) - ps.setProperty(regexPropName, regex); + String regexValue=regex.getValue(); + if(regexValue!=null) + ps.setProperty(regexPropName, regexValue); ps.setProperty(namePropName, name); + //ps.setProperty(strokeWidthFactorPropName, Float.valueOf(strokeWidthFactor).toString()); } static String encodeColor(StringBuilder sb, Color color) { @@ -171,4 +197,23 @@ return new Color(colorCompVals[0], colorCompVals[1], colorCompVals[2], colorCompVals[3]); } + /* + static String encodeStrokeWidthFactor(float strokeWidthFactor){ + if(strokeWidthFactor<0) + return "0"; + else + return Float.toString(strokeWidthFactor); + } + + static float decodeStrokeWidthFactor(String strokeWidthFactorS){ + if(strokeWidthFactorS==null) + return 1; + try{ + return Float.valueOf(strokeWidthFactorS); + }catch(NumberFormatException ex){ + return 1; + } + } + */ + } \ No newline at end of file Modified: plugins/CandyFolds/trunk/candyfolds/config/gui/ModeConfigPanel.java =================================================================== --- plugins/CandyFolds/trunk/candyfolds/config/gui/ModeConfigPanel.java 2012-09-29 12:11:05 UTC (rev 22277) +++ plugins/CandyFolds/trunk/candyfolds/config/gui/ModeConfigPanel.java 2012-10-02 15:07:27 UTC (rev 22278) @@ -25,18 +25,27 @@ import java.awt.Dimension; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import java.awt.event.FocusAdapter; +import java.awt.event.FocusEvent; +import java.util.logging.Level; +import java.util.logging.Logger; import javax.swing.BorderFactory; import javax.swing.Box; import javax.swing.BoxLayout; import javax.swing.JCheckBox; import javax.swing.JPanel; import javax.swing.JScrollPane; +import javax.swing.JTextField; class ModeConfigPanel { + private static final Logger L=Logger.getLogger(ModeConfigPanel.class.getName()); + //static { L.setLevel(Level.ALL); } + final JPanel panel=new JPanel(new BorderLayout()); private ModeConfig modeConfig; final JCheckBox enabledCB=new JCheckBox("Enable CandyFolds for this mode"); - final JCheckBox useBigLinesForStripConfigsCB=new JCheckBox("Prefer matching against lines with more than 1 non-space characters"); + final JCheckBox useIgnoreLineRegexCB=new JCheckBox("Ignore lines matching regex:"); + final JTextField ignoreLineRegexTF=new JTextField(12); final JCheckBox showStripOn0IndentCB=new JCheckBox("Show indentation-guide on left edge"); private final StripConfigsTable stripConfigsTable=new StripConfigsTable(); private final JPanel tablePanel=new JPanel(new BorderLayout()); @@ -50,38 +59,57 @@ tablePanel.add(stripConfigsOpPanel.panel, BorderLayout.SOUTH); //tablePanel.setBorder(BorderFactory.createTitledBorder("Candies")); panel.add(tablePanel); - + Box box=new Box(BoxLayout.Y_AXIS); enabledCB.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent ev) { - if(modeConfig!=null) - modeConfig.setEnabled(enabledCB.isSelected()); - updateView(); - } - } - ); + @Override + public void actionPerformed(ActionEvent ev) { + if(modeConfig!=null) + modeConfig.setEnabled(enabledCB.isSelected()); + updateView(); + } + } + ); box.add(enabledCB); - useBigLinesForStripConfigsCB.addActionListener(new ActionListener(){ - @Override - public void actionPerformed(ActionEvent ev){ - if(modeConfig!=null) - modeConfig.setUseBigLinesForStripConfigs(useBigLinesForStripConfigsCB.isSelected()); - updateView(); - } - }); - box.add(useBigLinesForStripConfigsCB); + Box p=new Box(BoxLayout.X_AXIS); + p.setAlignmentX(0); + useIgnoreLineRegexCB.addActionListener(new ActionListener(){ + @Override + public void actionPerformed(ActionEvent ev){ + boolean useIgnoreLineRegex=useIgnoreLineRegexCB.isSelected(); + if(modeConfig!=null) + modeConfig.setUseIgnoreLineRegex(useIgnoreLineRegex); + updateView(); + if(useIgnoreLineRegex){ + if(ignoreLineRegexTF.getText().trim().length()==0){ + ignoreLineRegexTF.setText("\\s*\\S\\s*$"); + ignoreLineRegexTF.selectAll(); + } + ignoreLineRegexTF.requestFocus(); + } + } + }); + p.add(useIgnoreLineRegexCB); + ignoreLineRegexTF.addFocusListener(new FocusAdapter(){ + @Override + public void focusLost(FocusEvent ev){ + updateModeConfigIgnoreLineRegex(); + updateView(); + } + }); + p.add(ignoreLineRegexTF); + box.add(p); showStripOn0IndentCB.addActionListener(new ActionListener(){ - @Override - public void actionPerformed(ActionEvent ev){ - if(modeConfig!=null) - modeConfig.setShowStripOn0Indent(showStripOn0IndentCB.isSelected()); - updateView(); - } - }); + @Override + public void actionPerformed(ActionEvent ev){ + if(modeConfig!=null) + modeConfig.setShowStripOn0Indent(showStripOn0IndentCB.isSelected()); + updateView(); + } + }); box.add(showStripOn0IndentCB); panel.add(box, BorderLayout.NORTH); - + updateView(); } @@ -91,17 +119,24 @@ updateView(); } + private void updateModeConfigIgnoreLineRegex(){ + if(modeConfig!=null) + modeConfig.ignoreLineRegex.setValue(ignoreLineRegexTF.getText()); + } + private void updateView() { if(modeConfig!=null) { enabledCB.setSelected(modeConfig.getEnabled()); boolean isDefault=modeConfig!=modeConfig.config.defaultModeConfig; enabledCB.setVisible(isDefault); - useBigLinesForStripConfigsCB.setSelected(modeConfig.getUseBigLinesForStripConfigs()); + useIgnoreLineRegexCB.setSelected(modeConfig.getUseIgnoreLineRegex()); + ignoreLineRegexTF.setText(modeConfig.ignoreLineRegex.getValue()); showStripOn0IndentCB.setSelected(modeConfig.getShowStripOn0Indent()); stripConfigsOpPanel.panel.setVisible( - modeConfig!=modeConfig.config.defaultModeConfig); + modeConfig!=modeConfig.config.defaultModeConfig); } - useBigLinesForStripConfigsCB.setEnabled(enabledCB.isSelected()); + useIgnoreLineRegexCB.setEnabled(enabledCB.isSelected()); + ignoreLineRegexTF.setEnabled(useIgnoreLineRegexCB.isSelected()); showStripOn0IndentCB.setEnabled(enabledCB.isSelected()); setEnabledStripConfigs(enabledCB.isSelected()); } @@ -112,6 +147,7 @@ } void save(){ + updateModeConfigIgnoreLineRegex(); stripConfigsTable.save(); } } \ No newline at end of file Modified: plugins/CandyFolds/trunk/candyfolds/config/gui/StripConfigsTable.java =================================================================== --- plugins/CandyFolds/trunk/candyfolds/config/gui/StripConfigsTable.java 2012-09-29 12:11:05 UTC (rev 22277) +++ plugins/CandyFolds/trunk/candyfolds/config/gui/StripConfigsTable.java 2012-10-02 15:07:27 UTC (rev 22278) @@ -57,7 +57,7 @@ table.setDefaultRenderer(Color.class, new ColorCellRenderer()); table.setDefaultEditor(Color.class, new ColorCellEditor()); } - + void save(){ CellEditor cellEditor=table.getCellEditor(); if(cellEditor!=null) @@ -71,11 +71,11 @@ {setOpaque(true);} @Override public Component getTableCellRendererComponent(JTable table, - Object value, - boolean isSelected, - boolean hasFocus, - int row, - int column) { + Object value, + boolean isSelected, + boolean hasFocus, + int row, + int column) { super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); setValue(null); StripConfig stripConfig=getStripConfig(row); @@ -102,34 +102,34 @@ private Color color; private final JButton button=new JButton() { - { - addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent ev) { - Color newColor=FullColorChooser.showDialog(button, "Select Candy Color", color); - if(newColor!=null) - color=newColor; - fireEditingStopped(); - } - } - ); - } - @Override - public void paintComponent(Graphics g) { - Dimension d=getSize(); - g.setColor(Color.white); - g.fillRect(2, 2, d.width-4, d.height-4); - g.setColor(color); - g.fillRect(2, 2, d.width-4, d.height-4); - } - }; + { + addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent ev) { + Color newColor=FullColorChooser.showDialog(button, "Select Candy Color", color); + if(newColor!=null) + color=newColor; + fireEditingStopped(); + } + } + ); + } + @Override + public void paintComponent(Graphics g) { + Dimension d=getSize(); + g.setColor(Color.white); + g.fillRect(2, 2, d.width-4, d.height-4); + g.setColor(color); + g.fillRect(2, 2, d.width-4, d.height-4); + } + }; @Override public Component getTableCellEditorComponent(JTable table, - Object value, - boolean isSelected, - int row, - int column) { + Object value, + boolean isSelected, + int row, + int column) { StripConfig stripConfig=getStripConfig(row); //Log.log(Log.NOTICE, this, "stripConfig of cellEditor: "+stripConfig.getName()); if(stripConfig==null) @@ -159,6 +159,7 @@ } @Override public int getColumnCount() { + //return 4; return 3; } @Override @@ -170,6 +171,10 @@ return "Name"; case 2: return "Regular Expression"; + /* + case 3: + return "Stroke Width Factor"; + */ default: return null; } @@ -207,7 +212,11 @@ case 1 : return stripConfig.getName(); case 2: - return stripConfig.getRegex(); + return stripConfig.regex.getValue(); + /* + case 3: + return stripConfig.getStrokeWidthFactor(); + */ default: return null; } @@ -218,6 +227,8 @@ switch(col) { case 0: return Color.class; + case 3: + return Float.class; default: return String.class; } @@ -226,7 +237,7 @@ @Override public boolean isCellEditable(int row, int col) { if(modeConfig!=null && modeConfig==modeConfig.config.defaultModeConfig && - col!=0) + col!=0) return false; return true; } @@ -248,9 +259,14 @@ case 2: try { String regex=(String)o; - stripConfig.setRegex(regex); + stripConfig.regex.setValue(regex); } catch(PatternSyntaxException ex) {} break; + /* + case 3: + Float strokeWidthFactor=(Float)o; + stripConfig.setStrokeWidthFactor(strokeWidthFactor); + */ } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <nic...@us...> - 2012-12-05 21:10:47
|
Revision: 22539 http://jedit.svn.sourceforge.net/jedit/?rev=22539&view=rev Author: nicarran Date: 2012-12-05 21:10:39 +0000 (Wed, 05 Dec 2012) Log Message: ----------- made compilable using jdk1.6 (instead of only 1.7) and changed version to 1.2.2 Modified Paths: -------------- plugins/CandyFolds/trunk/CandyFolds.props plugins/CandyFolds/trunk/candyfolds/config/gui/CandyFoldsOptionPane.java Modified: plugins/CandyFolds/trunk/CandyFolds.props =================================================================== --- plugins/CandyFolds/trunk/CandyFolds.props 2012-12-05 15:15:42 UTC (rev 22538) +++ plugins/CandyFolds/trunk/CandyFolds.props 2012-12-05 21:10:39 UTC (rev 22539) @@ -2,7 +2,7 @@ plugin.candyfolds.CandyFoldsPlugin.name=CandyFolds plugin.candyfolds.CandyFoldsPlugin.author=Nicol\xE1s Carranza # inspired and based on work by Andr\xE9 Kaplan & Nathan Jones (WhiteSpace plugin) -plugin.candyfolds.CandyFoldsPlugin.version=1.2.1 +plugin.candyfolds.CandyFoldsPlugin.version=1.2.2 plugin.candyfolds.CandyFoldsPlugin.description=CandyFolds draws colored indentation-guides on the text area to improve code readability. plugin.candyfolds.CandyFoldsPlugin.docs=index.html Modified: plugins/CandyFolds/trunk/candyfolds/config/gui/CandyFoldsOptionPane.java =================================================================== --- plugins/CandyFolds/trunk/candyfolds/config/gui/CandyFoldsOptionPane.java 2012-12-05 15:15:42 UTC (rev 22538) +++ plugins/CandyFolds/trunk/candyfolds/config/gui/CandyFoldsOptionPane.java 2012-12-05 21:10:39 UTC (rev 22539) @@ -63,7 +63,7 @@ private Config config; final JPanel panel=new JPanel(new BorderLayout()); - final JComboBox<Object> modesCB=new JComboBox<Object>(); + final JComboBox modesCB=new JComboBox(); final ModeConfigPanel modeConfigP=new ModeConfigPanel(); final JCheckBox usesDefaultModeConfigCB=new JCheckBox("Use Only "+Config.DEFAULT_MODE_CONFIG_NAME+" Configuration"); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |