forked from jgraph/mxgraph
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmxGraphComponent.java
More file actions
executable file
·4578 lines (3957 loc) · 100 KB
/
Copy pathmxGraphComponent.java
File metadata and controls
executable file
·4578 lines (3957 loc) · 100 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* $Id: mxGraphComponent.java,v 1.144 2012/03/05 08:57:38 gaudenz Exp $
* Copyright (c) 2009-2010, Gaudenz Alder, David Benson
*/
package com.mxgraph.swing;
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Component;
import java.awt.Cursor;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.RenderingHints;
import java.awt.Stroke;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import java.awt.image.BufferedImage;
import java.awt.print.PageFormat;
import java.awt.print.Printable;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.EventObject;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import javax.swing.BorderFactory;
import javax.swing.BoundedRangeModel;
import javax.swing.ImageIcon;
import javax.swing.JComponent;
import javax.swing.JPanel;
import javax.swing.JScrollBar;
import javax.swing.JScrollPane;
import javax.swing.RepaintManager;
import javax.swing.SwingUtilities;
import javax.swing.ToolTipManager;
import javax.swing.TransferHandler;
import com.mxgraph.canvas.mxGraphics2DCanvas;
import com.mxgraph.canvas.mxICanvas;
import com.mxgraph.model.mxGraphModel;
import com.mxgraph.model.mxGraphModel.Filter;
import com.mxgraph.model.mxIGraphModel;
import com.mxgraph.swing.handler.mxCellHandler;
import com.mxgraph.swing.handler.mxConnectionHandler;
import com.mxgraph.swing.handler.mxEdgeHandler;
import com.mxgraph.swing.handler.mxElbowEdgeHandler;
import com.mxgraph.swing.handler.mxGraphHandler;
import com.mxgraph.swing.handler.mxGraphTransferHandler;
import com.mxgraph.swing.handler.mxPanningHandler;
import com.mxgraph.swing.handler.mxSelectionCellsHandler;
import com.mxgraph.swing.handler.mxVertexHandler;
import com.mxgraph.swing.util.mxCellOverlay;
import com.mxgraph.swing.util.mxICellOverlay;
import com.mxgraph.swing.view.mxCellEditor;
import com.mxgraph.swing.view.mxICellEditor;
import com.mxgraph.swing.view.mxInteractiveCanvas;
import com.mxgraph.util.mxConstants;
import com.mxgraph.util.mxEvent;
import com.mxgraph.util.mxEventObject;
import com.mxgraph.util.mxEventSource;
import com.mxgraph.util.mxEventSource.mxIEventListener;
import com.mxgraph.util.mxPoint;
import com.mxgraph.util.mxRectangle;
import com.mxgraph.util.mxResources;
import com.mxgraph.util.mxUtils;
import com.mxgraph.view.mxCellState;
import com.mxgraph.view.mxEdgeStyle;
import com.mxgraph.view.mxEdgeStyle.mxEdgeStyleFunction;
import com.mxgraph.view.mxGraph;
import com.mxgraph.view.mxGraphView;
import com.mxgraph.view.mxTemporaryCellStates;
/**
* For setting the preferred size of the viewport for scrolling, use
* mxGraph.setMinimumGraphSize. This component is a combined scrollpane with an
* inner mxGraphControl. The control contains the actual graph display.
*
* To set the background color of the graph, use the following code:
*
* <pre>
* graphComponent.getViewport().setOpaque(true);
* graphComponent.getViewport().setBackground(newColor);
* </pre>
*
* This class fires the following events:
*
* mxEvent.START_EDITING fires before starting the in-place editor for an
* existing cell in startEditingAtCell. The <code>cell</code> property contains
* the cell that is being edit and the <code>event</code> property contains
* optional EventObject which was passed to startEditingAtCell.
*
* mxEvent.LABEL_CHANGED fires between begin- and endUpdate after the call to
* mxGraph.cellLabelChanged in labelChanged. The <code>cell</code> property
* contains the cell, the <code>value</code> property contains the new value for
* the cell and the optional <code>event</code> property contains the
* EventObject that started the edit.
*
* mxEvent.ADD_OVERLAY and mxEvent.REMOVE_OVERLAY fire afer an overlay was added
* or removed using add-/removeOverlay. The <code>cell</code> property contains
* the cell for which the overlay was added or removed and the
* <code>overlay</code> property contain the mxOverlay.
*
* mxEvent.BEFORE_PAINT and mxEvent.AFTER_PAINT fire before and after the paint
* method is called on the component. The <code>g</code> property contains the
* graphics context which is used for painting.
*/
public class mxGraphComponent extends JScrollPane implements Printable
{
/**
*
*/
private static final long serialVersionUID = -30203858391633447L;
/**
*
*/
public static final int GRID_STYLE_DOT = 0;
/**
*
*/
public static final int GRID_STYLE_CROSS = 1;
/**
*
*/
public static final int GRID_STYLE_LINE = 2;
/**
*
*/
public static final int GRID_STYLE_DASHED = 3;
/**
*
*/
public static final int ZOOM_POLICY_NONE = 0;
/**
*
*/
public static final int ZOOM_POLICY_PAGE = 1;
/**
*
*/
public static final int ZOOM_POLICY_WIDTH = 2;
/**
*
*/
public static ImageIcon DEFAULT_EXPANDED_ICON = null;
/**
*
*/
public static ImageIcon DEFAULT_COLLAPSED_ICON = null;
/**
*
*/
public static ImageIcon DEFAULT_WARNING_ICON = null;
/**
* Specifies the default page scale. Default is 1.4
*/
public static final double DEFAULT_PAGESCALE = 1.4;
/**
* Loads the collapse and expand icons.
*/
static
{
DEFAULT_EXPANDED_ICON = new ImageIcon(
mxGraphComponent.class
.getResource("/com/mxgraph/swing/images/expanded.gif"));
DEFAULT_COLLAPSED_ICON = new ImageIcon(
mxGraphComponent.class
.getResource("/com/mxgraph/swing/images/collapsed.gif"));
DEFAULT_WARNING_ICON = new ImageIcon(
mxGraphComponent.class
.getResource("/com/mxgraph/swing/images/warning.gif"));
}
/**
*
*/
protected mxGraph graph;
/**
*
*/
protected mxGraphControl graphControl;
/**
*
*/
protected mxEventSource eventSource = new mxEventSource(this);
/**
*
*/
protected mxICellEditor cellEditor;
/**
*
*/
protected mxConnectionHandler connectionHandler;
/**
*
*/
protected mxPanningHandler panningHandler;
/**
*
*/
protected mxSelectionCellsHandler selectionCellsHandler;
/**
*
*/
protected mxGraphHandler graphHandler;
/**
* The transparency of previewed cells from 0.0. to 0.1. 0.0 indicates
* transparent, 1.0 indicates opaque. Default is 1.
*/
protected float previewAlpha = 0.5f;
/**
* Specifies the <mxImage> to be returned by <getBackgroundImage>. Default
* is null.
*/
protected ImageIcon backgroundImage;
/**
* Background page format.
*/
protected PageFormat pageFormat = new PageFormat();
/**
*
*/
protected mxInteractiveCanvas canvas;
/**
*
*/
protected BufferedImage tripleBuffer;
/**
*
*/
protected Graphics2D tripleBufferGraphics;
/**
* Defines the scaling for the background page metrics. Default is
* {@link #DEFAULT_PAGESCALE}.
*/
protected double pageScale = DEFAULT_PAGESCALE;
/**
* Specifies if the background page should be visible. Default is false.
*/
protected boolean pageVisible = false;
/**
* If the pageFormat should be used to determine the minimal graph bounds
* even if the page is not visible (see pageVisible). Default is false.
*/
protected boolean preferPageSize = false;
/**
* Specifies if a dashed line should be drawn between multiple pages.
*/
protected boolean pageBreaksVisible = true;
/**
* Specifies the color of page breaks
*/
protected Color pageBreakColor = Color.darkGray;
/**
* Specifies the number of pages in the horizontal direction.
*/
protected int horizontalPageCount = 1;
/**
* Specifies the number of pages in the vertical direction.
*/
protected int verticalPageCount = 1;
/**
* Specifies if the background page should be centered by automatically
* setting the translate in the view. Default is true. This does only apply
* if pageVisible is true.
*/
protected boolean centerPage = true;
/**
* Color of the background area if layout view.
*/
protected Color pageBackgroundColor = new Color(144, 153, 174);
/**
*
*/
protected Color pageShadowColor = new Color(110, 120, 140);
/**
*
*/
protected Color pageBorderColor = Color.black;
/**
* Specifies if the grid is visible. Default is false.
*/
protected boolean gridVisible = false;
/**
*
*/
protected Color gridColor = new Color(192, 192, 192);
/**
* Whether or not to scroll the scrollable container the graph exists in if
* a suitable handler is active and the graph bounds already exist extended
* in the direction of mouse travel.
*/
protected boolean autoScroll = true;
/**
* Whether to extend the graph bounds and scroll towards the limit of those
* new bounds in the direction of mouse travel if a handler is active while
* the mouse leaves the container that the graph exists in.
*/
protected boolean autoExtend = true;
/**
*
*/
protected boolean dragEnabled = true;
/**
*
*/
protected boolean importEnabled = true;
/**
*
*/
protected boolean exportEnabled = true;
/**
* Specifies if folding (collapse and expand via an image icon in the graph
* should be enabled). Default is true.
*/
protected boolean foldingEnabled = true;
/**
* Specifies the tolerance for mouse clicks. Default is 4.
*/
protected int tolerance = 4;
/**
* Specifies if swimlanes are selected when the mouse is released over the
* swimlanes content area. Default is true.
*/
protected boolean swimlaneSelectionEnabled = true;
/**
* Specifies if the content area should be transparent to events. Default is
* true.
*/
protected boolean transparentSwimlaneContent = true;
/**
*
*/
protected int gridStyle = GRID_STYLE_DOT;
/**
*
*/
protected ImageIcon expandedIcon = DEFAULT_EXPANDED_ICON;
/**
*
*/
protected ImageIcon collapsedIcon = DEFAULT_COLLAPSED_ICON;
/**
*
*/
protected ImageIcon warningIcon = DEFAULT_WARNING_ICON;
/**
*
*/
protected boolean antiAlias = true;
/**
*
*/
protected boolean textAntiAlias = true;
/**
* Specifies <escape> should be invoked when the escape key is pressed.
* Default is true.
*/
protected boolean escapeEnabled = true;
/**
* If true, when editing is to be stopped by way of selection changing, data
* in diagram changing or other means stopCellEditing is invoked, and
* changes are saved. This is implemented in a mouse listener in this class.
* Default is true.
*/
protected boolean invokesStopCellEditing = true;
/**
* If true, pressing the enter key without pressing control will stop
* editing and accept the new value. This is used in <mxKeyHandler> to stop
* cell editing. Default is false.
*/
protected boolean enterStopsCellEditing = false;
/**
* Specifies the zoom policy. Default is ZOOM_POLICY_PAGE. The zoom policy
* does only apply if pageVisible is true.
*/
protected int zoomPolicy = ZOOM_POLICY_PAGE;
/**
* Internal flag to not reset zoomPolicy when zoom was set automatically.
*/
private transient boolean zooming = false;
/**
* Specifies the factor used for zoomIn and zoomOut. Default is 1.2 (120%).
*/
protected double zoomFactor = 1.2;
/**
* Specifies if the viewport should automatically contain the selection
* cells after a zoom operation. Default is false.
*/
protected boolean keepSelectionVisibleOnZoom = false;
/**
* Specifies if the zoom operations should go into the center of the actual
* diagram rather than going from top, left. Default is true.
*/
protected boolean centerZoom = true;
/**
* Specifies if an image buffer should be used for painting the component.
* Default is false.
*/
protected boolean tripleBuffered = false;
/**
* Used for debugging the dirty region.
*/
public boolean showDirtyRectangle = false;
/**
* Maps from cells to lists of heavyweights.
*/
protected Hashtable<Object, Component[]> components = new Hashtable<Object, Component[]>();
/**
* Maps from cells to lists of overlays.
*/
protected Hashtable<Object, mxICellOverlay[]> overlays = new Hashtable<Object, mxICellOverlay[]>();
/**
* Boolean flag to disable centering after the first time.
*/
private transient boolean centerOnResize = true;
/**
* Updates the heavyweight component structure after any changes.
*/
protected mxIEventListener updateHandler = new mxIEventListener()
{
public void invoke(Object sender, mxEventObject evt)
{
updateComponents();
graphControl.updatePreferredSize();
}
};
/**
*
*/
protected mxIEventListener repaintHandler = new mxIEventListener()
{
public void invoke(Object source, mxEventObject evt)
{
mxRectangle dirty = (mxRectangle) evt.getProperty("region");
Rectangle rect = (dirty != null) ? dirty.getRectangle() : null;
if (rect != null)
{
rect.grow(1, 1);
}
// Updates the triple buffer
repaintTripleBuffer(rect);
// Repaints the control using the optional triple buffer
graphControl.repaint((rect != null) ? rect : getViewport()
.getViewRect());
// ----------------------------------------------------------
// Shows the dirty region as a red rectangle (for debugging)
JPanel panel = (JPanel) getClientProperty("dirty");
if (showDirtyRectangle)
{
if (panel == null)
{
panel = new JPanel();
panel.setOpaque(false);
panel.setBorder(BorderFactory.createLineBorder(Color.RED));
putClientProperty("dirty", panel);
graphControl.add(panel);
}
if (dirty != null)
{
panel.setBounds(dirty.getRectangle());
}
panel.setVisible(dirty != null);
}
else if (panel != null && panel.getParent() != null)
{
panel.getParent().remove(panel);
putClientProperty("dirty", null);
repaint();
}
// ----------------------------------------------------------
}
};
/**
*
*/
protected PropertyChangeListener viewChangeHandler = new PropertyChangeListener()
{
/**
*
*/
public void propertyChange(PropertyChangeEvent evt)
{
if (evt.getPropertyName().equals("view"))
{
mxGraphView oldView = (mxGraphView) evt.getOldValue();
mxGraphView newView = (mxGraphView) evt.getNewValue();
if (oldView != null)
{
oldView.removeListener(updateHandler);
}
if (newView != null)
{
newView.addListener(mxEvent.SCALE, updateHandler);
newView.addListener(mxEvent.TRANSLATE, updateHandler);
newView.addListener(mxEvent.SCALE_AND_TRANSLATE,
updateHandler);
newView.addListener(mxEvent.UP, updateHandler);
newView.addListener(mxEvent.DOWN, updateHandler);
}
}
else if (evt.getPropertyName().equals("model"))
{
mxGraphModel oldModel = (mxGraphModel) evt.getOldValue();
mxGraphModel newModel = (mxGraphModel) evt.getNewValue();
if (oldModel != null)
{
oldModel.removeListener(updateHandler);
}
if (newModel != null)
{
newModel.addListener(mxEvent.CHANGE, updateHandler);
}
}
}
};
/**
* Resets the zoom policy if the scale is changed manually.
*/
protected mxIEventListener scaleHandler = new mxIEventListener()
{
/**
*
*/
public void invoke(Object sender, mxEventObject evt)
{
if (!zooming)
{
zoomPolicy = ZOOM_POLICY_NONE;
}
}
};
/**
*
* @param graph
*/
public mxGraphComponent(mxGraph graph)
{
setCellEditor(createCellEditor());
canvas = createCanvas();
// Initializes the buffered view and
graphControl = createGraphControl();
installFocusHandler();
installKeyHandler();
installResizeHandler();
setGraph(graph);
// Adds the viewport view and initializes handlers
setViewportView(graphControl);
createHandlers();
installDoubleClickHandler();
}
/**
* installs a handler to set the focus to the container.
*/
protected void installFocusHandler()
{
graphControl.addMouseListener(new MouseAdapter()
{
public void mousePressed(MouseEvent e)
{
if (!hasFocus())
{
requestFocus();
}
}
});
}
/**
* Handles escape keystrokes.
*/
protected void installKeyHandler()
{
addKeyListener(new KeyAdapter()
{
public void keyPressed(KeyEvent e)
{
if (e.getKeyCode() == KeyEvent.VK_ESCAPE && isEscapeEnabled())
{
escape(e);
}
}
});
}
/**
* Applies the zoom policy if the size of the component changes.
*/
protected void installResizeHandler()
{
addComponentListener(new ComponentAdapter()
{
public void componentResized(ComponentEvent e)
{
zoomAndCenter();
}
});
}
/**
* Adds handling of edit and stop-edit events after all other handlers have
* been installed.
*/
protected void installDoubleClickHandler()
{
graphControl.addMouseListener(new MouseAdapter()
{
public void mouseReleased(MouseEvent e)
{
if (isEnabled())
{
if (!e.isConsumed() && isEditEvent(e))
{
Object cell = getCellAt(e.getX(), e.getY(), false);
if (cell != null && getGraph().isCellEditable(cell))
{
startEditingAtCell(cell, e);
}
}
else
{
// Other languages use focus traversal here, in Java
// we explicitely stop editing after a click elsewhere
stopEditing(!invokesStopCellEditing);
}
}
}
});
}
/**
*
*/
protected mxICellEditor createCellEditor()
{
return new mxCellEditor(this);
}
/**
*
*/
public void setGraph(mxGraph value)
{
mxGraph oldValue = graph;
// Uninstalls listeners for existing graph
if (graph != null)
{
graph.removeListener(repaintHandler);
graph.getModel().removeListener(updateHandler);
graph.getView().removeListener(updateHandler);
graph.removePropertyChangeListener(viewChangeHandler);
graph.getView().removeListener(scaleHandler);
}
graph = value;
// Updates the buffer if the model changes
graph.addListener(mxEvent.REPAINT, repaintHandler);
// Installs the update handler to sync the overlays and controls
graph.getModel().addListener(mxEvent.CHANGE, updateHandler);
// Repaint after the following events is handled via
// mxGraph.repaint-events
// The respective handlers are installed in mxGraph.setView
mxGraphView view = graph.getView();
view.addListener(mxEvent.SCALE, updateHandler);
view.addListener(mxEvent.TRANSLATE, updateHandler);
view.addListener(mxEvent.SCALE_AND_TRANSLATE, updateHandler);
view.addListener(mxEvent.UP, updateHandler);
view.addListener(mxEvent.DOWN, updateHandler);
graph.addPropertyChangeListener(viewChangeHandler);
// Resets the zoom policy if the scale changes
graph.getView().addListener(mxEvent.SCALE, scaleHandler);
graph.getView().addListener(mxEvent.SCALE_AND_TRANSLATE, scaleHandler);
// Invoke the update handler once for initial state
updateHandler.invoke(graph.getView(), null);
firePropertyChange("graph", oldValue, graph);
}
/**
*
* @return Returns the object that contains the graph.
*/
public mxGraph getGraph()
{
return graph;
}
/**
* Creates the inner control that handles tooltips, preferred size and can
* draw cells onto a canvas.
*/
protected mxGraphControl createGraphControl()
{
return new mxGraphControl();
}
/**
*
* @return Returns the control that renders the graph.
*/
public mxGraphControl getGraphControl()
{
return graphControl;
}
/**
* Creates the connection-, panning and graphhandler (in this order).
*/
protected void createHandlers()
{
setTransferHandler(createTransferHandler());
panningHandler = createPanningHandler();
selectionCellsHandler = createSelectionCellsHandler();
connectionHandler = createConnectionHandler();
graphHandler = createGraphHandler();
}
/**
*
*/
protected TransferHandler createTransferHandler()
{
return new mxGraphTransferHandler();
}
/**
*
*/
protected mxSelectionCellsHandler createSelectionCellsHandler()
{
return new mxSelectionCellsHandler(this);
}
/**
*
*/
protected mxGraphHandler createGraphHandler()
{
return new mxGraphHandler(this);
}
/**
*
*/
public mxSelectionCellsHandler getSelectionCellsHandler()
{
return selectionCellsHandler;
}
/**
*
*/
public mxGraphHandler getGraphHandler()
{
return graphHandler;
}
/**
*
*/
protected mxConnectionHandler createConnectionHandler()
{
return new mxConnectionHandler(this);
}
/**
*
*/
public mxConnectionHandler getConnectionHandler()
{
return connectionHandler;
}
/**
*
*/
protected mxPanningHandler createPanningHandler()
{
return new mxPanningHandler(this);
}
/**
*
*/
public mxPanningHandler getPanningHandler()
{
return panningHandler;
}
/**
*
*/
public boolean isEditing()
{
return getCellEditor().getEditingCell() != null;
}
/**
*
*/
public mxICellEditor getCellEditor()
{
return cellEditor;
}
/**
*
*/
public void setCellEditor(mxICellEditor value)
{
mxICellEditor oldValue = cellEditor;
cellEditor = value;
firePropertyChange("cellEditor", oldValue, cellEditor);
}
/**
* @return the tolerance
*/
public int getTolerance()
{
return tolerance;
}
/**
* @param value
* the tolerance to set
*/
public void setTolerance(int value)
{
int oldValue = tolerance;
tolerance = value;
firePropertyChange("tolerance", oldValue, tolerance);
}
/**
*
*/
public PageFormat getPageFormat()
{
return pageFormat;
}
/**
*
*/
public void setPageFormat(PageFormat value)
{
PageFormat oldValue = pageFormat;
pageFormat = value;
firePropertyChange("pageFormat", oldValue, pageFormat);
}
/**
*
*/
public double getPageScale()
{
return pageScale;
}
/**
*
*/
public void setPageScale(double value)
{
double oldValue = pageScale;
pageScale = value;
firePropertyChange("pageScale", oldValue, pageScale);
}
/**
* Returns the size of the area that layouts can operate in.
*/
public mxRectangle getLayoutAreaSize()
{
if (pageVisible)
{
Dimension d = getPreferredSizeForPage();
return new mxRectangle(new Rectangle(d));
}
else
{
return new mxRectangle(new Rectangle(graphControl.getSize()));
}