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

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

HIGHLIGHTS:

  • add <include/> to configuration
  • add side notes to tree
    • used to store arbitrary information alongside the tree structure
  • migrate to log4j2
    • supports lazy string evaluation of passed arguments
  • improve GUI tree
    • it stays in synchronization with actual state (even in high load test scenario)
  • improve panel management in GUI
  • make loading objects in GUI more lazy
  • offload parsing to connection receiver thread
    • info parsing
    • first step of objects parsing
  • fix connection parsing bug (eof in long values)
  • support zero-arguments procedure in table view

CHANGELOG:
Implement procedure calls from table view.

Refactorization around procedures in tables.

Add table editor for buttons.

Render buttons in the the list view.

Further improve Columns.

Add Column class for TableModel?.

Accept also non-arguments ProcedureParams? in tableView.

Increase maximal TextAreaControl? size.

Add tooltip to ProcedureControl?.

Fix bug of interpreting eofs in long values by connection reader.

Further rework connection parsing.

Simplify client connection processing.

Test ListChange? modification.

Test ListChange? events with java server.

Add TestChild?.

Fix bug with fast deregistering when connecting to running server.

Another minor refactorization in TreeOperations?.

Fix bug in SimpleAbstractAccess? loading routine.

Another minor improvement.

Minor change.

Make reading of List objects two-phase.

Another minor change.

Dispatch parsing into receiver thread.

Another step.

Enclose passing value in ObjectParam? case in closure.

Minor step.

Minor change on way to offload parsing.

Temporarily comment out single ValueParam? get.

It will be generalized to multi ValueParam?.

Process info in receiver thread.

Add DispatchingExceptionHandler?.

Make waits in browser test longer.

Use FETCHED_MARK.

It is honored in GUI, where it used to decide whether to get values

after user action.

It is set in standard algorithm for processing fetched values.

Add remove operation to side notes.

Make loading more lazy.

Improve loading policy.

On node choose load itself, on node expansion, load children.

Minor improvement.

Fix bug with panel interleaving.

Minor improvements.

Improve panel management.

More cleaning around panels.

Reorganize panels.

Further improve tree.

Fix bug in TreeModel?.

Remove children from TreeNode?.

Implement TreeNode? hashCode and equals.

Make TreeNode? delegate equals and hashcode to internal reference.

Move listeners from TreeNode? to side notes.

Store path.textual as a side note.

Side note params instead of accesses for objects.

More refactorizations.

In TreeNode? bindAccess based on side notes.

Minor step.

Hide createAccess.

Rename AccessInterface? to Access.

Minor changes.

Several improvements in high load scenarios.

Change semantics of ArrayListAccess?.set(index, null);

It now removes the element, making list shorter
(it was set to null before).

Add path remove handler.

Handle exceptions in Connection.

Update .gitignore

Configure logging to file.

Move registration to TreeModel?.

Further refactorization.

Minor refactorization.

Minor improvements.

Use specialized event also for Modify action of ListChange?.

Use remove events.

Use the insertion events for tree.

Further improve tree refreshing.

Further improve reacting on events in GUI.

Fix problem with not adding objects on addition list change.

Migrate to log4j lazy String construction interface.

Migrate imports to log4j2.

Drop dependency on adapter to version 1.2.

Switch log4j implementation to log4j2.

Add dirty mark to the NodeAtFrame?.

Make selecting in AccessInterfaces? type safe.

Ignore containers size settings in Model and Genotype.

Use tree side notes to remember local changes and panels.

Add sideNotes to tree.

They will be used to store various accompanying information
right in the tree.

Use ReferenceIdentityMap? from apache in TreeNode?.

It suits the need perfectly (weak semantics on both key and value).

Make ArrayListParam? do not react size changes.

Guard in TableModel? before not yet loaded objects.

Add <include/> clause and AutoInjector?.

Extract common columns configuration to separate xml,
that can be included by other configurations.

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