source: java/main/src/main/java/com/framsticks/gui/windows/console/ConsolePainter.java @ 84

Last change on this file since 84 was 84, checked in by psniegowski, 11 years ago

HIGHLIGHTS:

  • simplification of entities management model
  • cleanup around params (improve hierarchy)
  • migrate from JUnit to TestNG
  • introduce FEST to automatically test GUI
  • improve slider control
  • loosen synchronization between gui tree and backend representation
  • and many other bug fixes

NOTICE:

  • a great many of lines is changed only because of substituting spaces with tabs

CHANGELOG (oldest changes at the bottom):

Some cleaning after fix found.

Fix bug with tree.

More changes with TreeNodes?.

Finally fix issue with tree.

Improve gui tree management.

Decouple update of values from fetch request in gui.

Minor changes.

Minor changes.

Minor change.

Change Path construction wording.

More fixes to SliderControl?.

Fix SliderControl?.

Fix SliderControl?.

Minor improvement.

Several changes.

Make NumberParam? a generic class.

Add robot to the gui test.

Setup common testing logging configuration.

Remove Parameters class.

Remove entityOwner from Parameters.

Move name out from Parameters class.

Move configuration to after the construction.

Simplify observers and endpoints.

Remove superfluous configureEntity overrides.

Add dependency on fest-swing-testng.

Use FEST for final print test.

Use FEST for more concise and readable assertions.

Divide test of F0Parser into multiple methods.

Migrate to TestNG

Minor change.

Change convention from LOGGER to log.

Fix reporting of errors during controls filling.

Bound maximal height of SliderControl?.

Minor improvements.

Improve tooltips for controls.

Also use Delimeted in more places.

Move static control utilities to Gui.

Rename package gui.components to controls.

Some cleaning in controls.

Improve Param classes placing.

Move ValueParam?, PrimitiveParam? and CompositeParam? one package up.

Improve ParamBuilder?.

Move getDef to ValueParam? and PrimitiveParam?.

Move getMax and getDef to ValueParam?.

Move getMin to ValueParam?.

Upgrade to laters apache commons versions.

Use filterInstanceof extensively.

Add instanceof filters.

Make ValueParam? in many places of Param.

Place assertions about ValueParam?.

Add ValueParam?

Rename ValueParam? to PrimitiveParam?

Minor changes.

Several improvements to params types.

Add NumberParam?.

Add TextControl? component.

Add .swp files to .gitignore

Greatly improved slider component.

Some improvements.

Make Param.reassign return also a state.

Add IterableIterator?.

Several changes.

  • Move util classes to better packages.
  • Remove warnings from eclim.

Several improvements.

Fix bug with BooleanParam?.

Some experiments with visualization.

Another fix to panel management.

Improve panel management.

Some refactorization around panels.

Add root class for panel.

File size: 4.7 KB
Line 
1package com.framsticks.gui.windows.console;
2
3import com.framsticks.communication.File;
4// import org.apache.log4j.Logger;
5
6import java.awt.Color;
7
8import javax.swing.JTextPane;
9import javax.swing.text.BadLocationException;
10import javax.swing.text.Document;
11import javax.swing.text.SimpleAttributeSet;
12
13/**
14 * Class paints messages.
15 */
16public class ConsolePainter {
17        // private static final Logger log = Logger.getLogger(ConsolePainter.class.getName());
18
19        private Document doc;
20        private JTextPane textPane;
21        // private Color c1 = new Color(192, 0, 0);
22        // private Color c2 = new Color(84, 141, 212);
23        // private Color c3 = new Color(118, 146, 60);
24        // private Color c4 = new Color(0, 0, 128);
25        private SimpleLinePainter linePainter1;
26        private SimpleLinePainter linePainter2;
27        private final SimpleAttributeSet set = new SimpleAttributeSet();
28
29
30        /**
31         * Constructor sets reference to pane with text.
32         * @param pane Pane where text is displaying.
33         */
34        public ConsolePainter(JTextPane pane) {
35                this.textPane = pane;
36                doc = textPane.getStyledDocument();
37                linePainter1 = new SimpleLinePainter(textPane, new Color(224, 224, 255));
38                linePainter2 = new SimpleLinePainter(textPane, new Color(240, 240, 255));
39        }
40
41        /**
42         * Paints message.
43         */
44        public void paintMessage(File file) {
45
46
47                String line;
48                // Boolean boldNextId = false;
49                // Boolean doNotPaint = false;
50
51                while ((line = file.getContent().readLine()) != null) {
52                        paintLine(line + "\n");
53                        /*
54                        if (doNotPaint) {
55                                plainText(line);
56                                if (line.endsWith("~\n")) {
57                                        doNotPaint = false;
58                                }
59                                continue;
60                        }
61
62                        int indColon = line.indexOf(':');
63
64                        if (indColon == -1) {
65                                String word = firstWord(line);
66                                String rest = line.substring(word.length());
67                                Color col = c1;
68
69                                if (word.startsWith("ok")) {
70                                        col = Color.BLACK;
71                                } else if (word.startsWith("error")) {
72                                        col = Color.RED;
73                                }
74
75                                paintLine(word, col, "b");
76                                paintLine(rest, Color.BLACK, "b");
77                                continue;
78                        }
79
80                        if (indColon == line.length() - 2) {
81                                String before = line.substring(0, indColon);
82                                String type = "b";
83
84                                if (before.equals("class")) {
85                                        boldNextId = true;
86                                }
87
88                                paintLine(before + ":", c2, type);
89                                paintLine("\n", Color.BLACK, "");
90                                continue;
91                        }
92                        String before = line.substring(0, indColon);
93                        String after = line.substring(indColon + 1);
94
95                        String type;
96
97                        if (before.equals("id") && boldNextId) {
98                                type = "b";
99                                boldNextId = false;
100                        } else {
101                                type = "";
102                        }
103
104                        paintLine(before + ":", c3, "b");
105                        paintLine(after, Color.BLACK, type);
106
107                        if (after.startsWith("~")) {
108                                doNotPaint = true;
109                        }*/
110
111                }
112
113                scrollDown();
114
115        }
116
117        private void paintLine(String text) {
118                //TODO colouring output, maybe using parsers?
119                try {
120                        doc.insertString(doc.getLength(), text, set);
121                } catch (BadLocationException e) {
122                        e.printStackTrace();
123                }
124        }
125        /**
126         * Paints line of text.
127         * @param text Line of text to be painted.
128         * @param color Font color.
129         * @param type Font attributes [b|i|u] (bold | italic | underline)
130         */
131        /*
132        private void paintLine(String text, Color color, String type) {
133                SimpleAttributeSet set = new SimpleAttributeSet();
134
135                if (type.contains("b")) {
136                        StyleConstants.setBold(set, true);
137                }
138
139                if (type.contains("i")) {
140                        StyleConstants.setItalic(set, true);
141                }
142
143                if (type.contains("u")) {
144                        StyleConstants.setUnderline(set, true);
145                }
146
147                StyleConstants.setFontFamily(set, "Monospaced");
148                StyleConstants.setForeground(set, color);
149                textPane.setCharacterAttributes(set, true);
150
151                try {
152                        doc.insertString(doc.getLength(), text, set);
153                } catch (BadLocationException e) {
154                        e.printStackTrace();
155                }
156
157        }
158        */
159
160
161
162        /**
163         * Returns first word in text line.
164         * @param line Line of text.
165         * @return First word in text line (with space char).
166         */
167        // private String firstWord(String line) {
168        //      String result;
169        //      int spaceIndex = line.indexOf(' ');
170
171        //      if (spaceIndex == -1) {
172        //              result = line;
173        //      } else {
174        //              result = line.substring(0, spaceIndex + 1);
175        //      }
176
177        //      return result;
178        // }
179
180        /**
181         * Paint line as plain text.
182         * @param msg
183         */
184        /*
185        private void plainText(String msg) {
186                paintLine(msg, Color.BLACK, "");
187        }
188        */
189
190        /**
191         * Adds message typed by user.
192         * @param msg Message typed by user.
193         */
194        public void userMsg(String msg) {
195                paintLine("[USER]> "/*, c4, "b"*/);
196                scrollDown();
197                linePainter1.resetHighlight();
198                paintLine(msg);
199                scrollDown();
200        }
201
202        /**
203         * Adds message that user 'clicked' in interface.
204         * @param msg Message sent from interface.
205         */
206        public void clickMsg(String msg) {
207                paintLine("[click]> "/*, c4, "b"*/);
208                scrollDown();
209                linePainter2.resetHighlight();
210                paintLine(msg);
211                scrollDown();
212        }
213
214        /**
215         * Scrolling text pane.
216         */
217        private void scrollDown() {
218                textPane.setCaretPosition(doc.getLength() - 1);
219        }
220
221}
Note: See TracBrowser for help on using the repository browser.