我扩展了两个jtextpane,可以在其中一个(debug)上面添加断点图标,然后在另一个(edit)jtextpane上添加highlight(高亮度条)。它们被加在一个jscrollpane上,edit是始终获得焦点,可以在edit光标所在的行用快捷键在左边的debug上添加断点图标。现在我是把它们都写在了一起,请问怎么把debug封装成一个独立的类。
debug中用到edit的地方是lp=new LinePainter(edit,currentColor);
lp.addHighlight(TextUtils.getHead(Inf[0],edit.editLines), Info[0]);
edit.repaint();
debug的构造函数中需要一个edit对象参数
使用快捷键的时候,以edit中光标所在的行为准去添加断点(需要一个debug的对象传入edti的构造函数)。
所以说就很麻烦,麻烦了各位。
debug中用到edit的地方是lp=new LinePainter(edit,currentColor);
lp.addHighlight(TextUtils.getHead(Inf[0],edit.editLines), Info[0]);
edit.repaint();
debug的构造函数中需要一个edit对象参数
使用快捷键的时候,以edit中光标所在的行为准去添加断点(需要一个debug的对象传入edti的构造函数)。
所以说就很麻烦,麻烦了各位。
解决方案 »
- IO文件的读取问题
- JCheckBox.setSelected(true)界面没效果,问题定位
- 继承中,子类向父类转型后的一些疑问
- 关于容器,组件,布局管理器,我打个比方,大家认为合不合适??
- 想利用业余的时间找私活赚钱的请光临河北项目网!信息绝对真实
- 各位大哥大姐:请问哪里可以下载到java连接access数据库的驱动!(具体连接是这样的,详细请进)
- Servlet 有没有实现这种方法的机制?
- 怎样从键盘读取数字
- 用javamail如何获得邮箱中最新的邮件
- jtable菜鸟求助
- 一个数列题,来看看吧!
- 求教一个NoClassDefFoundError异常问题 大家帮忙啊!急啊!!!!!!谢谢
private JTextComponent component;
private DefaultHighlighter highlighter;
private Lightline lightLine;
/**
* @param component paint的组件
* @param color paint的颜色
*/
public LinePainter( JTextComponent component, Color color){
super( color );
this.component = component; highlighter = (DefaultHighlighter)component.getHighlighter();
highlighter.setDrawsLayeredHighlights( true );
}
/**
* This method is overridden to get desired behaviour.
*
* The offs1 parameter is ignored and the entire line is highlighted.
*
* @param g the graphics context
* @param offs0 the starting model offset >= 0
* @param offs1 the ending model offset >= offs1
* @param bounds the bounding box of the view, which is not necessarily the region to paint.
* @param c the editor
* @param view View painting for
* @return region drawing occured in
*/
public Shape paintLayer( Graphics g, int offs0, int offs1, Shape bounds, JTextComponent c, View view ){
try
{
// Only use the first offset to get the line to highlight
Rectangle r = c.modelToView( offs0 );
r.x = 0;
r.width = c.getSize().width; // --- render ---
g.setColor( getColor() );
g.fillRect( r.x, r.y, r.width, r.height );
return r;
}
catch ( BadLocationException e )
{
return null;
}
}
/** 添加高亮度条 */
private void addHighlight( int offset,int i ){ lightLine=new Lightline(i);
try{
highlighter.addHighlight( offset, offset + 1, this );
}
catch( BadLocationException ble ){
ble.printStackTrace();
}
//以lighlight数去设置lightLine的count
lightCount++;
lightLine.setCount(lightCount);
lightLines.addElement(lightLine); } /** 删除高亮度条 */
private void removeHighlight(int i){
int c=0;
boolean b=false;
Highlighter.Highlight[] highlights = highlighter.getHighlights(); for(int j=0;j<lightLines.size();j++){
lightLine=(Lightline)lightLines.elementAt(j);
if(lightLine.getIndex()==i){
c=lightLine.getCount();
lightLines.remove(j);
b=true;
}
}
//删除highline之后把count在它后面的count -1
if(b){
for(int j=0;j<lightLines.size();j++){
lightLine=(Lightline)lightLines.elementAt(j);
if(lightLine.getCount()>c)
lightLine.setCount(lightLine.getCount()-1);
}
}
Highlighter.Highlight h = highlights[c]; try{
highlighter.removeHighlight(h); }
catch(Exception e){
e.printStackTrace();
}
lightCount--;
}
}