Revision 44112
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.swing/org.gvsig.expressionevaluator.swing.impl/src/main/java/org/gvsig/expressionevaluator/swing/impl/DefaultJExpressionBuilder.java | ||
---|---|---|
3 | 3 |
import java.awt.BorderLayout; |
4 | 4 |
import java.awt.Color; |
5 | 5 |
import java.awt.Dimension; |
6 |
import java.awt.Toolkit; |
|
7 |
import java.awt.datatransfer.Clipboard; |
|
8 |
import java.awt.datatransfer.StringSelection; |
|
6 | 9 |
import java.awt.event.ActionEvent; |
7 | 10 |
import java.awt.event.ActionListener; |
8 | 11 |
import java.awt.event.KeyAdapter; |
... | ... | |
21 | 24 |
import javax.swing.JEditorPane; |
22 | 25 |
import javax.swing.JLabel; |
23 | 26 |
import javax.swing.JList; |
27 |
import javax.swing.JMenuItem; |
|
24 | 28 |
import javax.swing.JOptionPane; |
29 |
import javax.swing.JPopupMenu; |
|
25 | 30 |
import javax.swing.JScrollPane; |
31 |
import javax.swing.JTextArea; |
|
26 | 32 |
import javax.swing.JTree; |
27 | 33 |
import javax.swing.SwingUtilities; |
28 | 34 |
import javax.swing.Timer; |
... | ... | |
69 | 75 |
import org.gvsig.tools.swing.api.pickercontroller.PickerController; |
70 | 76 |
import org.gvsig.tools.swing.api.script.ScriptSwingManager; |
71 | 77 |
import org.gvsig.tools.swing.api.threadsafedialogs.ThreadSafeDialogsManager; |
78 |
import org.gvsig.tools.swing.api.windowmanager.Dialog; |
|
79 |
import org.gvsig.tools.swing.api.windowmanager.WindowManager; |
|
80 |
import org.gvsig.tools.swing.api.windowmanager.WindowManager_v2; |
|
72 | 81 |
import org.gvsig.tools.swing.icontheme.IconTheme; |
73 | 82 |
|
74 | 83 |
/** |
... | ... | |
96 | 105 |
private ImageIcon defaultIconElement; |
97 | 106 |
private JScrollPane scrDescription; |
98 | 107 |
private Color color_ok; |
108 |
private String messageValue; |
|
99 | 109 |
|
100 | 110 |
private class ElementsTreeModel implements TreeModel { |
101 | 111 |
|
... | ... | |
212 | 222 |
} |
213 | 223 |
|
214 | 224 |
private void initComponents() { |
215 |
ToolsSwingManager toolsSwingManager = ToolsSwingLocator.getToolsSwingManager(); |
|
225 |
final ToolsSwingManager toolsSwingManager = ToolsSwingLocator.getToolsSwingManager();
|
|
216 | 226 |
final IconTheme theme = ToolsSwingLocator.getIconThemeManager().getCurrent(); |
227 |
final I18nManager i18n = ToolsLocator.getI18nManager(); |
|
217 | 228 |
|
218 | 229 |
this.btnTip.setVisible(false); |
219 | 230 |
this.btnTip.addActionListener(new ActionListener() { |
... | ... | |
254 | 265 |
doFilter(); |
255 | 266 |
} |
256 | 267 |
}); |
268 |
JMenuItem msgMenuTextEditor = new JMenuItem(i18n.getTranslation("text_editor")); |
|
269 |
msgMenuTextEditor.addActionListener(new ActionListener() { |
|
270 |
@Override |
|
271 |
public void actionPerformed(ActionEvent e) { |
|
272 |
JEditorPane text = new JEditorPane(); |
|
273 |
JScrollPane scroll = new JScrollPane(text); |
|
274 |
scroll.setPreferredSize(new Dimension(500, 300)); |
|
275 |
toolsSwingManager.setDefaultPopupMenu(text); |
|
276 |
text.setContentType("text/html"); |
|
277 |
text.setText("<html>"+messageValue+"</html>"); |
|
278 |
text.setCaretPosition(0); |
|
279 |
WindowManager_v2 winmgr = (WindowManager_v2) ToolsSwingLocator.getWindowManager(); |
|
280 |
Dialog dialog = winmgr.createDialog( |
|
281 |
scroll, |
|
282 |
i18n.getTranslation("_Preview_value"), |
|
283 |
null, |
|
284 |
WindowManager_v2.BUTTONS_OK |
|
285 |
); |
|
286 |
dialog.show(WindowManager.MODE.DIALOG); |
|
287 |
} |
|
288 |
}); |
|
289 |
JMenuItem msgMenuCopy = new JMenuItem(i18n.getTranslation("copy")); |
|
290 |
msgMenuTextEditor.addActionListener(new ActionListener() { |
|
291 |
@Override |
|
292 |
public void actionPerformed(ActionEvent e) { |
|
293 |
StringSelection selection = new StringSelection(messageValue); |
|
294 |
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); |
|
295 |
clipboard.setContents(selection, selection); |
|
296 |
} |
|
297 |
}); |
|
298 |
|
|
299 |
JPopupMenu msgMenu = new JPopupMenu(); |
|
300 |
msgMenu.add(msgMenuTextEditor); |
|
301 |
msgMenu.addSeparator(); |
|
302 |
msgMenu.add(msgMenuCopy); |
|
303 |
this.lblMsg.setComponentPopupMenu(msgMenu); |
|
304 |
|
|
257 | 305 |
this.pnlDescription.setLayout(new BorderLayout()); |
258 | 306 |
this.pnlDescription.setBackground(this.txtDescription.getBackground()); |
259 | 307 |
this.color_ok = this.txtExpression.getBackground(); |
... | ... | |
514 | 562 |
Expression expression = this.getExpression(); |
515 | 563 |
this.btnTip.setVisible(false); |
516 | 564 |
if( expression == null ) { |
517 |
this.lblMsg.setText("");
|
|
565 |
this.setMessage("");
|
|
518 | 566 |
this.txtExpression.setBackground(this.color_ok); |
519 | 567 |
return; |
520 | 568 |
} |
521 | 569 |
try { |
522 | 570 |
expression.getCode(); |
523 |
this.lblMsg.setText("");
|
|
571 |
this.setMessage("");
|
|
524 | 572 |
this.txtExpression.setBackground(this.color_ok); |
525 | 573 |
} catch(ExpressionSyntaxException ex) { |
526 |
this.lblMsg.setText("<html>"+ex.getDescription()+"</html>");
|
|
574 |
this.setMessage(ex.getDescription());
|
|
527 | 575 |
this.txtExpression.setBackground(COLOR_ERROR); |
528 | 576 |
return; |
529 | 577 |
} catch(Exception ex) { |
530 |
this.lblMsg.setText("Syntax error in expression");
|
|
578 |
this.setMessage("Syntax error in expression");
|
|
531 | 579 |
this.txtExpression.setBackground(COLOR_ERROR); |
532 | 580 |
return; |
533 | 581 |
} |
... | ... | |
536 | 584 |
ExpressionEvaluatorManager theManager = ExpressionEvaluatorLocator.getManager(); |
537 | 585 |
MutableSymbolTable symbolTable = theManager.createSymbolTable(); |
538 | 586 |
Object value = expression.execute(symbolTable); |
539 |
this.lblMsg.setText("<html>"+StringUtils.abbreviate(Utils.toString(value),100)+"</html>");
|
|
587 |
this.setMessage(Utils.toString(value));
|
|
540 | 588 |
this.txtExpression.setBackground(this.color_ok); |
541 | 589 |
} catch(Exception ex) { |
542 |
this.lblMsg.setText("");
|
|
590 |
this.setMessage("");
|
|
543 | 591 |
} |
544 | 592 |
} else { |
545 | 593 |
try { |
546 | 594 |
Object value = expression.execute(this.config.getPreviewSymbolTable()); |
547 |
this.lblMsg.setText("<html>"+StringUtils.abbreviate(Utils.toString(value),100)+"</html>");
|
|
595 |
this.setMessage(Utils.toString(value));
|
|
548 | 596 |
this.txtExpression.setBackground(this.color_ok); |
549 | 597 |
} catch(ExpressionRuntimeException ex) { |
550 | 598 |
if( !StringUtils.isBlank(ex.getTip()) ) { |
551 | 599 |
this.btnTip.setToolTipText(ex.getTip()); |
552 | 600 |
this.btnTip.setVisible(true); |
553 | 601 |
} |
554 |
this.lblMsg.setText("<html>Runtime error. "+ex.getMessage()+"</html>");
|
|
602 |
this.setMessage("Runtime error. "+ex.getMessage());
|
|
555 | 603 |
this.txtExpression.setBackground(COLOR_ERROR); |
556 | 604 |
} catch(Exception ex) { |
557 |
this.lblMsg.setText("<html>Runtime error. "+ex.getMessage()+"</html>");
|
|
605 |
this.setMessage("Runtime error. "+ex.getMessage());
|
|
558 | 606 |
this.txtExpression.setBackground(COLOR_ERROR); |
559 | 607 |
} |
560 | 608 |
} |
561 | 609 |
} |
610 |
|
|
611 |
private void setMessage(String msg) { |
|
612 |
this.messageValue = msg; |
|
613 |
this.lblMsg.setText("<html>"+StringUtils.abbreviate(msg,100)+"</html>"); |
|
614 |
} |
|
562 | 615 |
|
563 | 616 |
private String removeCursorMark(String s) { |
564 | 617 |
s = s.replace("{{", ""); |
Also available in: Unified diff