Update of /cvsroot/contiki/contiki-2.x/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/plugins
In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv29726/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/plugins
Modified Files:
CodeUI.java
Log Message:
faster repaint for large source files
Index: CodeUI.java
===================================================================
RCS file: /cvsroot/contiki/contiki-2.x/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/plugins/CodeUI.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -d -r1.7 -r1.8
*** CodeUI.java 12 Jun 2009 15:11:22 -0000 1.7
--- CodeUI.java 23 Sep 2009 08:16:06 -0000 1.8
***************
*** 32,45 ****
package se.sics.cooja.mspmote.plugins;
! import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
- import java.awt.event.MouseListener;
import java.io.File;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Vector;
! import javax.swing.*;
import org.apache.log4j.Logger;
--- 32,59 ----
package se.sics.cooja.mspmote.plugins;
! import java.awt.BorderLayout;
! import java.awt.Color;
! import java.awt.Component;
! import java.awt.Font;
! import java.awt.Point;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
+ import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.File;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Vector;
!
! import javax.swing.AbstractListModel;
! import javax.swing.JLabel;
! import javax.swing.JList;
! import javax.swing.JMenuItem;
! import javax.swing.JPanel;
! import javax.swing.JPopupMenu;
! import javax.swing.JSeparator;
! import javax.swing.ListCellRenderer;
! import javax.swing.SwingUtilities;
!
import org.apache.log4j.Logger;
***************
*** 189,193 ****
* @param lineNr Line numer
*/
! public void displayNewCode(final File codeFile, final String[] codeData, final int lineNr) {
displayedFile = codeFile;
--- 203,207 ----
* @param lineNr Line numer
*/
! public void displayNewCode(File codeFile, String[] codeData, final int lineNr) {
displayedFile = codeFile;
***************
*** 197,228 ****
}
SwingUtilities.invokeLater(new Runnable() {
public void run() {
- // Display code
- codeList = new JList(new CodeListModel(codeData));
- codeList.setBackground(Color.WHITE);
- codeList.setFont(new Font("courier", 0, 12));
- codeList.setCellRenderer(new CodeCellRenderer(lineNr));
- codeList.addMouseListener(new MouseListener() {
- public void mousePressed(MouseEvent e) {
- handleMouseEvent(e);
- }
- public void mouseReleased(MouseEvent e) {
- handleMouseEvent(e);
- }
- public void mouseEntered(MouseEvent e) {
- handleMouseEvent(e);
- }
- public void mouseExited(MouseEvent e) {
- handleMouseEvent(e);
- }
- public void mouseClicked(MouseEvent e) {
- handleMouseEvent(e);
- }
- });
panel.removeAll();
panel.add(codeList);
!
! createTokens(codeData);
displayLine(lineNr);
}
--- 211,248 ----
}
+ logger.info("Opening " + codeFile + " (" + codeData.length + " lines)");
+
+ /* Create new list */
+ final JList newList = new JList(new CodeListModel(codeData));
+ newList.setBackground(Color.WHITE);
+ newList.setFont(new Font("courier", 0, 12));
+ newList.setCellRenderer(new CodeCellRenderer(lineNr));
+ ((CodeCellRenderer)newList.getCellRenderer()).setNice(false);
+ newList.setFixedCellHeight(12);
+ newList.addMouseListener(new MouseAdapter() {
+ public void mousePressed(MouseEvent e) {
+ handleMouseEvent(e);
+ }
+ public void mouseReleased(MouseEvent e) {
+ handleMouseEvent(e);
+ }
+ public void mouseEntered(MouseEvent e) {
+ handleMouseEvent(e);
+ }
+ public void mouseExited(MouseEvent e) {
+ handleMouseEvent(e);
+ }
+ public void mouseClicked(MouseEvent e) {
+ handleMouseEvent(e);
+ }
+ });
+ createTokens(codeData);
+
SwingUtilities.invokeLater(new Runnable() {
public void run() {
panel.removeAll();
+ codeList = newList;
panel.add(codeList);
! panel.validate();
displayLine(lineNr);
}
***************
*** 232,258 ****
/**
* Mark given line number in shown source code.
*
* @param lineNumber Line number
*/
! public void displayLine(final int lineNumber) {
! if (codeList == null || lineNumber < 0) {
! SwingUtilities.invokeLater(new Runnable() {
! public void run() {
! codeList.updateUI();
! }
! });
return;
}
SwingUtilities.invokeLater(new Runnable() {
public void run() {
! ((CodeCellRenderer) codeList.getCellRenderer()).changeCurrentLine(lineNumber);
! int index = lineNumber - 1;
! codeList.setSelectedIndex(index);
!
! codeList.ensureIndexIsVisible(Math.max(0, index-3));
! codeList.ensureIndexIsVisible(Math.min(index+3, codeList.getModel().getSize()));
! codeList.ensureIndexIsVisible(index);
! codeList.updateUI();
}
});
--- 252,281 ----
/**
* Mark given line number in shown source code.
+ * Should be called from AWT thread.
*
* @param lineNumber Line number
*/
! public void displayLine(int lineNumber) {
! if (codeList == null) {
return;
}
+ ((CodeCellRenderer) codeList.getCellRenderer()).setNice(false);
+ ((CodeCellRenderer) codeList.getCellRenderer()).changeCurrentLine(lineNumber);
+ ((CodeCellRenderer) codeList.getCellRenderer()).validate();
+
+ if (lineNumber > 0) {
+ int index = lineNumber - 1;
+ codeList.setSelectedIndex(index);
+ codeList.ensureIndexIsVisible(Math.max(0, index-3));
+ codeList.ensureIndexIsVisible(Math.min(index+3, codeList.getModel().getSize()));
+ codeList.ensureIndexIsVisible(index);
+ }
+
+ codeList.updateUI();
SwingUtilities.invokeLater(new Runnable() {
public void run() {
! ((CodeCellRenderer) codeList.getCellRenderer()).setNice(true);
! codeList.repaint();
}
});
***************
*** 269,277 ****
final int currentLine = codeList.locationToIndex(new Point(event.getX(), event.getY())) + 1;
! SwingUtilities.invokeLater(new Runnable() {
! public void run() {
! codeList.setSelectedIndex(currentLine - 1);
! }
! });
JPopupMenu popupMenu = createPopupMenu(displayedFile, currentLine);
--- 292,296 ----
final int currentLine = codeList.locationToIndex(new Point(event.getX(), event.getY())) + 1;
! codeList.setSelectedIndex(currentLine - 1);
JPopupMenu popupMenu = createPopupMenu(displayedFile, currentLine);
***************
*** 398,406 ****
private class CodeCellRenderer extends JLabel implements ListCellRenderer {
private int currentIndex;
!
public CodeCellRenderer(int currentLineNr) {
this.currentIndex = currentLineNr - 1;
}
public void changeCurrentLine(int currentLineNr) {
this.currentIndex = currentLineNr - 1;
--- 417,430 ----
private class CodeCellRenderer extends JLabel implements ListCellRenderer {
private int currentIndex;
! private boolean nice = true;
!
public CodeCellRenderer(int currentLineNr) {
this.currentIndex = currentLineNr - 1;
}
+ public void setNice(boolean b) {
+ nice = b;
+ }
+
public void changeCurrentLine(int currentLineNr) {
this.currentIndex = currentLineNr - 1;
***************
*** 408,421 ****
private String getColoredLabelText(int lineNr, int lineStartPos, Token[] tokens, String code) {
! String html = "<html>";
!
/* Add line number */
String lineString = "0000" + Integer.toString(lineNr);
lineString = lineString.substring(lineString.length() - 4);
! html += "<font color=\"333333\">" + lineString + ": </font>";
/* Add code */
if (tokens == null || tokens.length == 0 || lineStartPos < 0) {
! html += "<font color=\"000000\">" + code + "</font>";
} else {
for (int i=tokens.length-1; i >= 0; i--) {
--- 432,450 ----
private String getColoredLabelText(int lineNr, int lineStartPos, Token[] tokens, String code) {
! StringBuilder sb = new StringBuilder();
! sb.append("<html>");
!
/* Add line number */
String lineString = "0000" + Integer.toString(lineNr);
lineString = lineString.substring(lineString.length() - 4);
! sb.append("<font color=\"333333\">");
! sb.append(lineString);
! sb.append(": </font>");
/* Add code */
if (tokens == null || tokens.length == 0 || lineStartPos < 0) {
! sb.append("<font color=\"000000\">");
! sb.append(code);
! sb.append("</font>");
} else {
for (int i=tokens.length-1; i >= 0; i--) {
***************
*** 467,475 ****
code = code.replace(" ", " ");
! html += code;
}
! html += "</html>";
! return html;
}
--- 496,504 ----
code = code.replace(" ", " ");
! sb.append(code);
}
! sb.append("</html>");
! return sb.toString();
}
***************
*** 482,487 ****
{
int lineNr = index + 1;
!
! if (tokensArray != null && index < tokensArray.length && tokensArray[index] != null) {
setText(getColoredLabelText(lineNr, tokensStartPos[index], tokensArray[index], (String) value));
} else {
--- 511,517 ----
{
int lineNr = index + 1;
! if (!nice) {
! setText((String) value);
! } else if (tokensArray != null && index < tokensArray.length && tokensArray[index] != null) {
setText(getColoredLabelText(lineNr, tokensStartPos[index], tokensArray[index], (String) value));
} else {
|