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. |