- Timestamp:
- 09/28/18 10:33:02 (6 years ago)
- Location:
- trunk/src/org/expeditee/items/widgets
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/expeditee/items/widgets/JavaFXWidget.java
r1098 r1177 2 2 3 3 import org.expeditee.core.Image; 4 import org.expeditee.core.bounds.AxisAlignedBoxBounds; 4 5 import org.expeditee.gio.EcosystemManager; 5 6 import org.expeditee.gio.EcosystemManager.Ecosystem; 6 7 import org.expeditee.gio.javafx.JavaFXMiscManager; 8 import org.expeditee.items.ItemParentStateChangedEvent; 7 9 import org.expeditee.items.Text; 10 import org.expeditee.items.UserAppliedPermission; 8 11 9 12 import javafx.scene.Group; … … 14 17 15 18 public abstract class JavaFXWidget extends Widget { 16 19 17 20 protected Scene _dummyScene; 18 21 protected Node _node; 19 22 20 protected JavaFXWidget(Text source, Node jfxNode, int minWidth, int maxWidth, int minHeight, int maxHeight) 21 { 23 protected JavaFXWidget(Text source, Node jfxNode, int minWidth, int maxWidth, int minHeight, int maxHeight) { 22 24 super(source, minWidth, maxWidth, minHeight, maxHeight); 23 25 _node = jfxNode; … … 27 29 28 30 @Override 29 public boolean isSupportedOnEcosystem(Ecosystem type) 30 { 31 protected void addWidgetContent(final ItemParentStateChangedEvent e) { 32 if ((e.getEventType() == ItemParentStateChangedEvent.EVENT_TYPE_ADDED_VIA_OVERLAY || e 33 .getEventType() == ItemParentStateChangedEvent.EVENT_TYPE_SHOWN_VIA_OVERLAY) 34 && e.getOverlayLevel().equals(UserAppliedPermission.none)) { 35 return; // item belongs to a non-active overlay 36 } 37 38 //TODO: Add code here that attaches JavaFX content to the widget. This was added by Bryce 39 //as it was necessary for Swing widgets functionality. 40 } 41 42 @Override 43 protected void addKeyListenerToWidget() { 44 // TODO: Add code here that attaches JavaFX key listeners 45 46 } 47 48 @Override 49 protected void addThisAsContainerListenerToContent() { 50 // TODO: Add code here that attaches the equiv of swings Content Listener 51 52 } 53 54 @Override 55 public AxisAlignedBoxBounds getContentBounds() { 56 // TODO: Return the bounds of the content that is being drawn. Potentially different from the bounds of the widget. 57 return null; 58 } 59 60 @Override 61 protected void layout() { 62 // TODO: Respond to layout 63 } 64 65 @Override 66 protected void onBoundsChanged() { 67 // TODO: Respond to widget bounds changing. 68 } 69 70 @Override 71 public boolean isSupportedOnEcosystem(Ecosystem type) { 31 72 return type == Ecosystem.JavaFX; 32 73 } 33 74 34 75 @Override 35 public void paintWidget() 36 { 76 public void paintWidget() { 37 77 SnapshotParameters params = new SnapshotParameters(); 38 78 WritableImage snapshot = _node.snapshot(params, null); … … 40 80 EcosystemManager.getGraphicsManager().drawImage(image, getPosition()); 41 81 } 42 82 43 83 @Override 44 protected void onMoved() 45 { 84 protected void onMoved() { 46 85 // Do nothing 47 86 } 48 87 49 88 @Override 50 protected void onSizeChanged() 51 { 89 protected void onSizeChanged() { 52 90 _dummyScene.getRoot().resize(getWidth(), getHeight()); 53 91 _node.resize(getWidth(), getHeight()); -
trunk/src/org/expeditee/items/widgets/SwingWidget.java
r1152 r1177 5 5 import java.awt.Graphics2D; 6 6 import java.awt.Point; 7 import java.awt.Rectangle; 8 import java.awt.event.ContainerEvent; 9 import java.awt.event.ContainerListener; 10 import java.awt.event.KeyEvent; 11 import java.awt.event.KeyListener; 12 import java.util.Arrays; 13 import java.util.LinkedList; 14 import java.util.List; 7 15 8 16 import javax.swing.JComponent; 9 17 import javax.swing.JPopupMenu; 18 19 import org.expeditee.core.bounds.AxisAlignedBoxBounds; 20 import org.expeditee.gio.EcosystemManager; 10 21 import org.expeditee.gio.EcosystemManager.Ecosystem; 22 import org.expeditee.gio.swing.SwingGraphicsManager; 23 import org.expeditee.gio.swing.SwingInputManager; 11 24 import org.expeditee.gio.swing.SwingMiscManager; 25 import org.expeditee.gui.DisplayController; 26 import org.expeditee.items.ItemParentStateChangedEvent; 12 27 import org.expeditee.items.Text; 13 14 public abstract class SwingWidget extends Widget 28 import org.expeditee.items.UserAppliedPermission; 29 30 public abstract class SwingWidget extends Widget implements ContainerListener, KeyListener 15 31 { 16 32 // A flag for signifying whether the swing components are ready to paint. … … 22 38 23 39 protected JComponent _swingComponent; 24 40 25 41 protected SwingWidget(Text source, JComponent component, int minWidth, int maxWidth, int minHeight, int maxHeight) 26 42 { 27 43 super(source, minWidth, maxWidth, minHeight, maxHeight); 28 44 29 if (component == null) throw new NullPointerException("component"); 30 45 if (component == null) { 46 throw new NullPointerException("component"); 47 } 48 31 49 _swingComponent = component; 50 _swingComponent.setFocusable(true); 51 addKeyListenerToWidget(); 52 addThisAsContainerListenerToContent(); 32 53 onBoundsChanged(); 54 55 JPopupMenu.setDefaultLightWeightPopupEnabled(false); 33 56 } 34 57 … … 36 59 { 37 60 return _swingComponent; 61 } 62 63 @Override 64 public void keyTyped(KeyEvent e) { 65 66 int keyCode = e.getKeyCode(); 67 68 if (keyCode >= KeyEvent.VK_F1 && keyCode <= KeyEvent.VK_F12) { 69 ((SwingInputManager) EcosystemManager.getInputManager()).keyTyped(e); 70 } 71 } 72 73 @Override 74 public void keyPressed(KeyEvent e) { 75 int keyCode = e.getKeyCode(); 76 77 if (keyCode >= KeyEvent.VK_F1 && keyCode <= KeyEvent.VK_F12) { 78 ((SwingInputManager) EcosystemManager.getInputManager()).keyTyped(e); 79 } 80 } 81 82 @Override 83 public void keyReleased(KeyEvent e) { 84 int keyCode = e.getKeyCode(); 85 86 if (keyCode >= KeyEvent.VK_F1 && keyCode <= KeyEvent.VK_F12) { 87 ((SwingInputManager) EcosystemManager.getInputManager()).keyTyped(e); 88 } 89 } 90 91 /** 92 * Makes sure we add our KeyListener to every child component, 93 * since it seems that's the only way to make sure we capture key events in Java 94 * (without using KeyBindings which seem to only support the keyTyped event) 95 */ 96 @Override 97 public void componentAdded(ContainerEvent e) { 98 if(e == null || e.getChild() == null) { 99 return; 100 } 101 keyListenerToChildren(e.getChild(), true); 102 } 103 104 @Override 105 public void componentRemoved(ContainerEvent e) { 106 if(e == null || e.getChild() == null) { 107 return; 108 } 109 keyListenerToChildren(e.getChild(), false); 110 } 111 112 @Override 113 protected void addWidgetContent(final ItemParentStateChangedEvent e) { 114 if ((e.getEventType() == ItemParentStateChangedEvent.EVENT_TYPE_ADDED_VIA_OVERLAY || e 115 .getEventType() == ItemParentStateChangedEvent.EVENT_TYPE_SHOWN_VIA_OVERLAY) 116 && e.getOverlayLevel().equals(UserAppliedPermission.none)) { 117 return; // item belongs to a non-active overlay 118 } 119 120 if(_swingComponent.getParent() == null) { 121 if (e.getEventType() == ItemParentStateChangedEvent.EVENT_TYPE_SHOWN 122 || e.getEventType() == ItemParentStateChangedEvent.EVENT_TYPE_SHOWN_VIA_OVERLAY 123 || e.getSource() == DisplayController.getCurrentFrame()) { 124 onBoundsChanged(); 125 ((SwingGraphicsManager) EcosystemManager.getGraphicsManager()).getContentPane().add(_swingComponent); 126 layout(_swingComponent); 127 } 128 } 129 } 130 131 @Override 132 protected void addKeyListenerToWidget() { 133 keyListenerToChildren(_swingComponent, true); 134 } 135 136 @Override 137 protected void addThisAsContainerListenerToContent() { 138 _swingComponent.addContainerListener(this); 139 } 140 141 @Override 142 public AxisAlignedBoxBounds getContentBounds() { 143 //final Rectangle bounds = _swingComponent.getBounds(); 144 //final AccessibleContext accessibleContext = _swingComponent.getAccessibleContext(); 145 //if (accessibleContext != null) { 146 // final Rectangle accessibleBounds = _swingComponent.getAccessibleContext().getAccessibleComponent().getBounds(); 147 // return new AxisAlignedBoxBounds(bounds.x, bounds.y, bounds.width, bounds.height + accessibleBounds.height); 148 //} else { 149 // return new AxisAlignedBoxBounds(bounds.x, bounds.y, bounds.width, bounds.height); 150 //} 151 final Rectangle bounds = _swingComponent.getBounds(); 152 return new AxisAlignedBoxBounds(bounds.x, bounds.y, bounds.width, bounds.height); 153 } 154 155 @Override 156 protected void layout() { 157 layout(_swingComponent); 158 } 159 160 private void keyListenerToChildren(Component parent, boolean add) { 161 List<Component> components = new LinkedList<Component>(); 162 components.add(parent); 163 while(!components.isEmpty()) { 164 Component c = components.remove(0); 165 if(c instanceof Container) { 166 components.addAll(Arrays.asList(((Container)c).getComponents())); 167 } 168 if(add && !Arrays.asList(c.getKeyListeners()).contains(this)) { 169 c.addKeyListener(this); 170 } else if (!add && Arrays.asList(c.getKeyListeners()).contains(this)) { 171 c.removeKeyListener(this); 172 } 173 } 38 174 } 39 175 … … 51 187 } 52 188 189 @Override 53 190 public final void onBoundsChanged() 54 191 { 55 if (_swingComponent == null) return; 192 if (_swingComponent == null) { 193 return; 194 } 56 195 57 196 if (isFixedSize()) { … … 71 210 private void ignoreAWTPainting(Component c) 72 211 { 73 if (c == null) return; 74 75 if (c instanceof JComponent) ((JComponent) c).setDoubleBuffered(false); 212 if (c == null) { 213 return; 214 } 215 216 if (c instanceof JComponent) { 217 ((JComponent) c).setDoubleBuffered(false); 218 } 76 219 c.setIgnoreRepaint(true); 77 220 78 221 if (c instanceof Container) { 79 222 for (Component child : ((Container) c).getComponents()) { 80 ignoreAWTPainting(child); 223 if(child instanceof Container) { 224 ignoreAWTPainting(child); 225 } else { 226 if(child instanceof JComponent) { 227 ((JComponent) child).setDoubleBuffered(false); 228 } 229 child.setIgnoreRepaint(true); 230 } 81 231 } 82 232 } … … 88 238 * @param parent 89 239 */ 90 protected void layout(Component parent) 91 { 92 if (parent == null) return; 240 private void layout(Component parent) 241 { 242 if (parent == null) { 243 return; 244 } 93 245 94 246 parent.validate(); … … 98 250 layout(child); 99 251 } 100 } 252 } 101 253 } 102 254 … … 116 268 protected void paintSwingWidget(Graphics2D g) 117 269 { 270 // final GraphicsManager gm = SwingGraphicsManager.getInstance(); 271 // final EnforcedClipKey clipKey = gm.pushClip(new Clip(getContentBounds())); 272 118 273 final Point location = _swingComponent.getLocation(); 119 274 int x = location.x; … … 122 277 _swingComponent.paint(g); 123 278 g.translate(-x, -y); 279 280 // gm.popClip(clipKey); 124 281 } 125 282 -
trunk/src/org/expeditee/items/widgets/Widget.java
r1159 r1177 542 542 } 543 543 544 //addThisAsContainerListenerToContent(); 545 //addKeyListenerToWidget(); 546 544 547 _textRepresentation = source; 545 548 … … 1113 1116 case ItemParentStateChangedEvent.EVENT_TYPE_SHOWN_VIA_OVERLAY: 1114 1117 EcosystemManager.addInteractiveWidget(this); 1118 addWidgetContent(e); 1115 1119 break; 1116 1120 } 1117 1121 1118 DisplayController.invalidateItem(_d1, get Bounds());1122 DisplayController.invalidateItem(_d1, getContentBounds()); 1119 1123 1120 1124 // Forward filtered event to upper classes... 1121 1125 onParentStateChanged(e.getEventType()); 1122 1126 } 1123 1127 1128 /** 1129 * Subclassing Widgets overwrite to add their specific content to the Frame. 1130 * For example, a widget being Java Swing must add their Swing component to Expeditee's content pane. 1131 * @param e Can be used to identify if it is appropriate to draw the widget. 1132 */ 1133 abstract protected void addWidgetContent(final ItemParentStateChangedEvent e); 1134 1135 /** 1136 * Subclassing Widgets overwrite to specify their own functionality as to how key events 1137 * are to be forwarded to Expeditee. 1138 */ 1139 abstract protected void addKeyListenerToWidget(); 1140 1141 /** 1142 * Subclassing widgets overwrite to specify how content will respond to being added and removed. 1143 */ 1144 abstract protected void addThisAsContainerListenerToContent(); 1145 1146 /** 1147 * Subclassing widgets overwrite to provide the size and position of their content. 1148 * For example, a widget using Java Swing might return _swingComponent.getBounds(). 1149 * @return The bounds of the content that is being drawn. 1150 */ 1151 abstract public AxisAlignedBoxBounds getContentBounds(); 1152 1153 /** 1154 * Due to absolute positioning... 1155 * @param parent 1156 */ 1157 abstract protected void layout(); 1158 1159 /** 1160 * Subclassing widgets overwrite to respond to changes in widget bounds. 1161 */ 1162 abstract protected void onBoundsChanged(); 1163 1124 1164 /** 1125 1165 * Override to make use of. Internally this is reported once by all corners, … … 1154 1194 public AxisAlignedBoxBounds getBounds() 1155 1195 { 1156 return new AxisAlignedBoxBounds(getX(), getY(), getWidth(), getHeight()); 1196 return getContentBounds(); 1197 //return new AxisAlignedBoxBounds(getX(), getY(), getWidth(), getHeight()); 1157 1198 } 1158 1199 … … 1882 1923 public Clip getClip() 1883 1924 { 1884 final Clip clip = new Clip(get Bounds());1925 final Clip clip = new Clip(getContentBounds()); 1885 1926 return clip; 1886 1927 } 1928 1929 public void onResized() { 1930 invalidateSelf(); 1931 onBoundsChanged(); 1932 layout(); 1933 } 1887 1934 } -
trunk/src/org/expeditee/items/widgets/WidgetCorner.java
r1102 r1177 23 23 import org.expeditee.core.Colour; 24 24 import org.expeditee.core.Point; 25 import org.expeditee.core.bounds.Bounds; 25 26 import org.expeditee.core.bounds.PolygonBounds; 26 27 import org.expeditee.items.Dot; … … 35 36 super(x, y, id); 36 37 37 if (widgetSource == null) 38 if (widgetSource == null) { 38 39 throw new NullPointerException("widgetSource"); 40 } 39 41 _widgetSource = widgetSource; 42 } 43 44 @Override 45 public Bounds updateBounds() { 46 final Bounds ret = super.updateBounds(); 47 if (_widgetSource != null) { 48 _widgetSource.onBoundsChanged(); 49 } 50 return ret; 40 51 } 41 52 … … 246 257 public boolean contains(Point p) 247 258 { 248 return super.contains(p) && !_widgetSource.get Bounds().contains(p);259 return super.contains(p) && !_widgetSource.getContentBounds().contains(p); 249 260 } 250 261 … … 253 264 if (_widgetSource != null) { 254 265 float minThickness = _widgetSource.getMinimumBorderThickness(); 255 if (newThickness < minThickness) 266 if (newThickness < minThickness) { 256 267 newThickness = minThickness; 268 } 257 269 super.setThickness(newThickness, setConnected); 258 270 _widgetSource.setSourceThickness(newThickness, false);
Note:
See TracChangeset
for help on using the changeset viewer.