1 30 package com.genimen.djeneric.tools.specifier.components; 31 32 import java.awt.BorderLayout ; 33 import java.awt.Frame ; 34 import java.awt.event.ActionEvent ; 35 import java.awt.event.FocusEvent ; 36 import java.awt.event.FocusListener ; 37 import java.awt.event.KeyEvent ; 38 39 import javax.swing.JComponent ; 40 import javax.swing.JPanel ; 41 42 import com.genimen.djeneric.repository.exceptions.DjenericException; 43 import com.genimen.djeneric.tools.specifier.interfaces.ObjectViewer; 44 import com.genimen.djeneric.ui.Util; 45 import com.genimen.djeneric.util.DjLogger; 46 import com.hexidec.ekit.EkitCore; 47 48 public class DjHtmlArea extends JPanel implements DjBindable, FocusListener 49 { 50 private static final long serialVersionUID = 1L; 51 private BindingMediator _mediator; 52 private EkitCore _ekitCore; 53 54 public DjHtmlArea(ObjectViewer viewer, String propertyName) throws DjenericException 55 { 56 super(); 57 setLayout(new BorderLayout ()); 58 _ekitCore = new EkitCore(); 59 add(_ekitCore.getToolBar(true), BorderLayout.NORTH); 60 add(_ekitCore, BorderLayout.CENTER); 61 _ekitCore.getTextPane().addFocusListener(this); 62 _mediator = new BindingMediator(this, viewer, propertyName); 63 64 _ekitCore.getTextPane().add(_ekitCore.getMenuBar()); 67 68 _ekitCore.getTextPane().addKeyListener(new java.awt.event.KeyAdapter () 69 { 70 public void keyPressed(KeyEvent e) 71 { 72 if (e.getKeyCode() == KeyEvent.VK_ENTER && (e.getModifiers() & KeyEvent.CTRL_MASK) != 0) 73 { 74 _ekitCore.actionPerformed(new ActionEvent (this, 0, "insertbreak")); 75 } 76 } 77 }); 78 79 } 80 81 public void clear() 82 { 83 _ekitCore.setDocumentText(""); 84 } 85 86 public boolean isComponentWritable() 87 { 88 return _mediator.isComponentWritable(); 89 } 90 91 public void setToolTipText(String text) 92 { 93 _ekitCore.getTextPane().setToolTipText(text); 94 } 95 96 public void apply() throws DjenericException 97 { 98 _mediator.setValue(_ekitCore.getDocumentText()); 99 } 100 101 Frame _frame = null; 102 103 public void focusGained(FocusEvent e) 104 { 105 _mediator.getViewer().focusReceived(this); 106 107 if (_frame == null) 108 { 109 _frame = Util.findFrame(this); 110 if (_frame != null) _ekitCore.setFrame(_frame); 111 } 112 } 113 114 public void focusLost(FocusEvent e) 115 { 116 try 117 { 118 apply(); 119 } 120 catch (Exception x) 121 { 122 DjLogger.log(x); 123 } 124 } 125 126 public void setPropertyName(String propertyName) throws DjenericException 127 { 128 _mediator.setPropertyName(propertyName); 129 } 130 131 public void setViewer(ObjectViewer viewer) 132 { 133 _mediator.setViewer(viewer); 134 } 135 136 public void synchronize() throws DjenericException 137 { 138 _ekitCore.getTextPane().setText(_mediator.getPropertyValueString()); 139 _ekitCore.setCaretPosition(0); 140 } 141 142 public Object getDisplayedValue() 143 { 144 return _ekitCore.getDocumentText(); 145 } 146 147 public String getPropertyName() 148 { 149 return _mediator.getPropertyName(); 150 } 151 152 public JComponent getFocussableComponent() 153 { 154 return _ekitCore; 155 } 156 157 public synchronized void addFocusListener(FocusListener l) 158 { 159 if (_ekitCore != null) _ekitCore.addFocusListener(l); 160 } 161 162 public synchronized void removeFocusListener(FocusListener l) 163 { 164 if (_ekitCore != null) _ekitCore.removeFocusListener(l); 165 } 166 167 public void requestFocus() 168 { 169 _ekitCore.getTextPane().requestFocus(); 170 } 171 172 } | Popular Tags |