-
Notifications
You must be signed in to change notification settings - Fork 13
/
WorkbenchFrame.java
2353 lines (2083 loc) · 93.5 KB
/
WorkbenchFrame.java
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
/*
* The Unified Mapping Platform (JUMP) is an extensible, interactive GUI for
* visualizing and manipulating spatial features with geometry and attributes.
*
* Copyright (C) 2003 Vivid Solutions
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation; either version 2 of the License, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along with
* this program; if not, write to the Free Software Foundation, Inc., 59 Temple
* Place - Suite 330, Boston, MA 02111-1307, USA.
*
* For more information, contact:
*
* Vivid Solutions Suite #1A 2328 Government Street Victoria BC V8T 5G5 Canada
*
* (250)385-6040 www.vividsolutions.com
*/
package com.vividsolutions.jump.workbench.ui;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Container;
import java.awt.Dialog;
import java.awt.Dimension;
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.GraphicsEnvironment;
import java.awt.KeyEventDispatcher;
import java.awt.KeyboardFocusManager;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.Window;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.WindowEvent;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.beans.PropertyVetoException;
import java.io.File;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.sql.SQLException;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import javax.swing.*;
import javax.swing.border.Border;
import javax.swing.event.InternalFrameAdapter;
import javax.swing.event.InternalFrameEvent;
import javax.swing.event.InternalFrameListener;
import javax.swing.event.MenuEvent;
import javax.swing.event.PopupMenuEvent;
import javax.swing.event.PopupMenuListener;
import javax.swing.text.JTextComponent;
import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.Level;
import org.openjump.core.CheckOS;
import org.openjump.core.model.TaskEvent;
import org.openjump.core.model.TaskListener;
import org.openjump.core.ui.plugin.view.ZoomToScalePlugIn;
import org.openjump.core.ui.swing.DetachableInternalFrame;
import org.openjump.core.ui.util.ScreenScale;
import org.openjump.swing.factory.component.ComponentFactory;
import org.locationtech.jts.geom.Envelope;
import org.locationtech.jts.util.Assert;
import com.vividsolutions.jump.I18N;
import com.vividsolutions.jump.util.Blackboard;
import com.vividsolutions.jump.util.Block;
import com.vividsolutions.jump.util.CollectionUtil;
import com.vividsolutions.jump.util.StringUtil;
import com.vividsolutions.jump.workbench.JUMPWorkbench;
import com.vividsolutions.jump.workbench.Logger;
import com.vividsolutions.jump.workbench.WorkbenchContext;
import com.vividsolutions.jump.workbench.model.Category;
import com.vividsolutions.jump.workbench.model.CategoryEvent;
import com.vividsolutions.jump.workbench.model.FeatureEvent;
import com.vividsolutions.jump.workbench.model.Layer;
import com.vividsolutions.jump.workbench.model.LayerEvent;
import com.vividsolutions.jump.workbench.model.LayerEventType;
import com.vividsolutions.jump.workbench.model.LayerListener;
import com.vividsolutions.jump.workbench.model.LayerManager;
import com.vividsolutions.jump.workbench.model.LayerManagerProxy;
import com.vividsolutions.jump.workbench.model.Layerable;
import com.vividsolutions.jump.workbench.model.StandardCategoryNames;
import com.vividsolutions.jump.workbench.model.Task;
import com.vividsolutions.jump.workbench.model.UndoableEditReceiver;
import com.vividsolutions.jump.workbench.model.WMSLayer;
import com.vividsolutions.jump.workbench.plugin.AbstractPlugIn;
import com.vividsolutions.jump.workbench.plugin.EnableCheck;
import com.vividsolutions.jump.workbench.plugin.EnableChecked;
import com.vividsolutions.jump.workbench.plugin.PlugIn;
import com.vividsolutions.jump.workbench.plugin.PlugInContext;
import com.vividsolutions.jump.workbench.ui.cursortool.editing.EditingPlugIn;
import com.vividsolutions.jump.workbench.ui.images.IconLoader;
import com.vividsolutions.jump.workbench.ui.plugin.FeatureInstaller;
import com.vividsolutions.jump.workbench.ui.plugin.OptionsPlugIn;
import com.vividsolutions.jump.workbench.ui.plugin.PersistentBlackboardPlugIn;
import com.vividsolutions.jump.workbench.ui.plugin.SaveProjectPlugIn;
import com.vividsolutions.jump.workbench.ui.plugin.ViewAttributesPlugIn.ViewAttributesFrame;
import com.vividsolutions.jump.workbench.ui.renderer.style.ChoosableStyle;
import com.vividsolutions.jump.workbench.ui.task.TaskMonitorManager;
import com.vividsolutions.jump.workbench.ui.toolbox.ToolboxDialog;
import com.vividsolutions.jump.workbench.ui.zoom.ZoomToCoordinatePlugIn;
import java.util.List;
/**
* This class is responsible for the main window of the JUMP application.
*/
public class WorkbenchFrame extends JFrame implements LayerViewPanelContext,
ViewportListener, ErrorHandler {
private static I18N i18n = I18N.getInstance();
private String EXIT_OPENJUMP = I18N.getInstance().get("ui.WorkbenchFrame.exit-jump");
private String CLOSE_PROJECT = I18N.getInstance().get("ui.WorkbenchFrame.close-task");
private String CLOSE_PROJECT_QUESTION = I18N.getInstance().get("ui.WorkbenchFrame.do-you-want-to-close-project");
private String SAVE_PROJECT = I18N.getInstance().get("ui.WorkbenchFrame.save-project-before-closing-openjump");
private String PROJECT_SAVED = I18N.getInstance().get("ui.WorkbenchFrame.save-project-saved");
// To translate
public static String MEMORY_GC = I18N.getInstance().get("ui.WorkbenchFrame.started-garbage-collection");
public static String MEMORY_TIPS = I18N.getInstance().get("ui.WorkbenchFrame.click-to-garbage-collector");
public static String COORDINATES = I18N.getInstance().get("ui.WorkbenchFrame.coordinates");
public static String COORDINATES_TIPS = I18N.getInstance().get("ui.WorkbenchFrame.click-to-zoom-to-coordinates");
public static String SCALE = I18N.getInstance().get("ui.WorkbenchFrame.scale");
public static String SCALE_TIPS = I18N.getInstance().get("ui.WorkbenchFrame.click-to-change-view-scale");
BorderLayout borderLayout1 = new BorderLayout();
JMenuBar menuBar = new JMenuBar() {
public void processKeyEvent(KeyEvent e, MenuElement[] path,
MenuSelectionManager manager) {
super.processKeyEvent(e, path, manager);
}
// filter how we react on specific key events
protected boolean processKeyBinding(KeyStroke ks, KeyEvent e,
int condition, boolean pressed) {
// catch Alt release events which cause menubar to get focussed
// during editing when quasimodes are used
if (e.getKeyCode() == KeyEvent.VK_ALT
&& e.getID() == KeyEvent.KEY_RELEASED)
return true;
// this disables the menu item accelerators to be executed
// we simply do not let menubar route the key down to the items
return false; // super.processKeyBinding(ks, e, condition, pressed);
}
};
JMenu fileMenu = (JMenu) FeatureInstaller.installMnemonic(new JMenu(
MenuNames.FILE), menuBar);
public class ExitPlugin extends AbstractPlugIn {
public ExitPlugin() {
super(I18N.getInstance().get("ui.WorkbenchFrame.exit"));
this.setShortcutKeys(KeyEvent.VK_Q);
this.setShortcutModifiers(KeyEvent.CTRL_DOWN_MASK);
}
public void initialize(PlugInContext context) throws Exception {
super.initialize(context);
context.getFeatureInstaller().addMainMenuPlugin(this,
new String[] { MenuNames.FILE });
// register and block menu accelerator action
context.getFeatureInstaller().registerShortcuts(this);
}
public boolean execute(PlugInContext context) throws Exception {
closeApplication();
return true;
}
public Icon getIcon() {
return IconLoader.icon("famfam/door_in.png");
}
};
private TaskFrame activeTaskFrame = null;
// StatusBar
private JPanel statusPanel;
private JTextArea messageText;
private JLabel timeLabel, memoryLabel, scaleLabel, coordinateLabel;
private DecimalFormat scaleFormat = new DecimalFormat("#,###");
private DecimalFormat scaleFormatSmall = new DecimalFormat("#.####");
private ZoomToScalePlugIn zoomToScalePlugin = new ZoomToScalePlugIn();
private ZoomToCoordinatePlugIn zoomToCoordPlugin = new ZoomToCoordinatePlugIn();
private String lastStatusMessage = "";
// the four SplitPanes for the statusbar
private JSplitPane statusPanelSplitPane1;
private JSplitPane statusPanelSplitPane2;
private JSplitPane statusPanelSplitPane3;
private JSplitPane statusPanelSplitPane4;
// the vertically resizeable statusbar
private JSplitPane desktopStatusSplit;
WorkbenchToolBar toolBar;
private static Icon internalFrameDefaultIcon = null;
private static boolean internalFrameDefaultIconSet = false;
JMenu windowMenu = (JMenu) FeatureInstaller.installMnemonic(new JMenu(
MenuNames.WINDOW), menuBar);
private DecimalFormat memoryFormat = new DecimalFormat("###,###");
private TitledPopupMenu categoryPopupMenu = new TitledPopupMenu() {
{
addPopupMenuListener(new PopupMenuListener() {
public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
LayerNamePanel panel = ((LayerNamePanelProxy) getActiveInternalFrame())
.getLayerNamePanel();
setTitle((panel.selectedNodes(Category.class).size() != 1) ? ("("
+ panel.selectedNodes(Category.class).size() + " categories selected)")
: ((Category) panel.selectedNodes(Category.class)
.iterator().next()).getName());
}
public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {
}
public void popupMenuCanceled(PopupMenuEvent e) {
}
});
}
};
private JDesktopPane desktopPane = new JDesktopPane() {
{
// Simple workaround for the following JUMP bug: if you maximize one
// JInternalFrame, then all JInternalFrames get maximized (including attribute
// windows, undesirably). The workaround is to use the DefaultDesktopManager
// instead of the one installed by the Windows L&F (the WindowsDesktopManager).
// (Uwe Dalluege noticed that the problem occurred with the Windows L&F but not
// the Metal L&F -- this observation led me to the solution).
// [Jon Aquino 2005-07-04]
setDesktopManager(new DefaultDesktopManager());
// make sure bg is blue in all implementations
setBackground(new Color(58, 110, 165));
}
};
// <<TODO:REMOVE>> Actually we're not using the three optimization
// parameters
// below. Remove. [Jon Aquino]
private int envelopeRenderingThreshold = 500;
private HTMLFrame outputFrame = null;
private TitledPopupMenu layerNamePopupMenu = new TitledPopupMenu() {
{
addPopupMenuListener(new PopupMenuListener() {
public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
LayerNamePanel panel = ((LayerNamePanelProxy) getActiveInternalFrame())
.getLayerNamePanel();
setTitle((panel.selectedNodes(Layer.class).size() != 1) ? ("("
+ panel.selectedNodes(Layer.class).size()
+ " "
+ I18N.getInstance().get("ui.WorkbenchFrame.layers-selected") + ")")
: ((Layerable) panel.selectedNodes(Layer.class)
.iterator().next()).getName());
}
public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {
}
public void popupMenuCanceled(PopupMenuEvent e) {
}
});
}
};
private TitledPopupMenu wmsLayerNamePopupMenu = new TitledPopupMenu() {
{
addPopupMenuListener(new PopupMenuListener() {
public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
LayerNamePanel panel = ((LayerNamePanelProxy) getActiveInternalFrame())
.getLayerNamePanel();
setTitle((panel.selectedNodes(WMSLayer.class).size() != 1) ? ("("
+ panel.selectedNodes(WMSLayer.class).size()
+ " "
+ I18N.getInstance().get("ui.WorkbenchFrame.wms-layers-selected") + ")")
: ((Layerable) panel.selectedNodes(WMSLayer.class)
.iterator().next()).getName());
}
public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {
}
public void popupMenuCanceled(PopupMenuEvent e) {
}
});
}
};
private LayerNamePanelListener layerNamePanelListener = new LayerNamePanelListener() {
public void layerSelectionChanged() {
toolBar.updateEnabledState();
}
};
// Here is a small patch to JUMP to avoid creating a StringBuffer every
// coordinate change (which could be many thousands). Replace the innter
// class in WorkbenchFrame.java with the following. I am assuming only one
// thread can call the listener at a time. If that is untrue please
// synchronize
// cursorPositionChanged().
//
// Sheldon Young 2004-01-30
private LayerViewPanelListener layerViewPanelListener = new LayerViewPanelListener() {
// Avoid creating an expensive StringBuffer when the cursor position
// changes.
private StringBuffer positionStatusBuf = new StringBuffer("(");
public void cursorPositionChanged(String x, String y) {
positionStatusBuf.setLength(1);
positionStatusBuf.append(x).append(" ; ").append(y).append(")");
coordinateLabel.setText(positionStatusBuf.toString());
coordinateLabel.setToolTipText("<html><body>"
+ GUIUtil.escapeHTML(COORDINATES + ": "
+ positionStatusBuf.toString()) + "<br><br>"
+ GUIUtil.escapeHTML(COORDINATES_TIPS) + "</body></html>");
}
public void selectionChanged() {
toolBar.updateEnabledState();
}
public void fenceChanged() {
toolBar.updateEnabledState();
}
public void painted(Graphics graphics) {
}
};
// <<TODO:NAMING>> This name is not clear [Jon Aquino]
private int maximumFeatureExtentForEnvelopeRenderingInPixels = 10;
// <<TODO:NAMING>> This name is not clear [Jon Aquino]
private int minimumFeatureExtentForAnyRenderingInPixels = 2;
// private StringBuffer log = new StringBuffer();
private int taskSequence = 1;
private WorkbenchContext workbenchContext;
private Set choosableStyleClasses = new HashSet();
private ArrayList<TaskListener> taskListeners = new ArrayList<TaskListener>();
private ArrayList<ApplicationExitHandler> applicationExitHandlers = new ArrayList<>();
private Map<Class<?>,JPopupMenu> nodeClassToLayerNamePopupMenuMap =
CollectionUtil.createMap(new Object[] {
Layer.class, layerNamePopupMenu,
WMSLayer.class, wmsLayerNamePopupMenu,
Category.class, categoryPopupMenu
});
private int positionIndex = -1;
private int primaryInfoFrameIndex = -1;
private int addedMenuItems = -1;
private ComponentFactory<TaskFrame> taskFrameFactory;
// RecursiveKeyListener easyKeyListener;
MultiRecursiveKeyListener easyKeyListener;
ShortcutPluginExecuteKeyListener shortcutListener;
public WorkbenchFrame(String title, final WorkbenchContext workbenchContext)
throws Exception {
setTitle(title);
this.workbenchContext = workbenchContext;
// set icon for the app frame
JUMPWorkbench.setIcon(this);
// prevent loosing windows when frame is resized,
// resize and move them back into if needed
getDesktopPane().addComponentListener(new ComponentAdapter() {
@Override
public void componentResized(ComponentEvent e) {
for (JInternalFrame iframe : getInternalFrames()) {
legalize(iframe);
}
}
});
toolBar = new WorkbenchToolBar(workbenchContext);
toolBar.setTaskMonitorManager(new TaskMonitorManager());
try {
jbInit();
configureStatusBarComponent(messageText, 90);
configureStatusBarComponent(timeLabel, 90);
configureStatusBarComponent(memoryLabel, 90);
configureStatusBarComponent(scaleLabel, 90); // [Giuseppe Aruta
// 2012-feb-18]
configureStatusBarComponent(coordinateLabel, 90);
} catch (Exception e) {
e.printStackTrace();
}
new Timer(1000, new ActionListener() {
public void actionPerformed(ActionEvent e) {
String msg = getMBCommittedMemory() + " MB "
+ I18N.getInstance().get("ui.WorkbenchFrame.committed-memory");
memoryLabel.setText(msg);
memoryLabel.setToolTipText("<html><body>"
+ GUIUtil.escapeHTML(msg) + "<br><br>"
+ GUIUtil.escapeHTML(MEMORY_TIPS) + "</body></html>");
// memoryLabel.setToolTipText(LayerManager.layerManagerCount() +
// " "
// + I18N.getInstance().get("ui.WorkbenchFrame.layer-manager")
// + StringUtil.s(LayerManager.layerManagerCount()));
}
}).start();
// attach a multi listener (plugins use to get notified about key events
// etc.)
easyKeyListener = new MultiRecursiveKeyListener(this);
// create a run plugin via shortcut listener
shortcutListener = new ShortcutPluginExecuteKeyListener(
workbenchContext);
// these register handlers for mac menus, needs apple
// stubs in lib/orange*.jar in classpath to compile
if (CheckOS.isMacOsx()) {
try {
new AppleHandler().register();
} catch (Throwable e) {
// the whole handling above is optional, inform but don't fail
StringWriter sw = new StringWriter();
e.printStackTrace(new PrintWriter(sw));
log(sw.toString());
}
}
// intercept global key events via custom dispatcher, see
// http://tips4java.wordpress.com/2009/09/06/global-event-dispatching/
// this is a HACK. we intercept registered shortcuts here because
// - this way we get keyinput regardless which component has focus
// - menu item accelerators are disabled in menubar, we execute them
// here
// - we block ALT-char combinations which can be menu mnemonics by
// consuming
// the event here if the combination is actually an registered shortcut
// TODO: we should check/reassign mnemonics on every shortcut assignment
// to prevent dead mnemonics
KeyEventDispatcher dispatcher = new KeyEventDispatcher() {
public boolean dispatchKeyEvent(KeyEvent e) {
// hands up, who's got the focus
Component focussed = KeyboardFocusManager
.getCurrentKeyboardFocusManager().getFocusOwner();
// traverse through parents, see if we are in a valid one
boolean valid = false;
// System.out.println("START");
Component c = focussed;
while (c != null) {
// System.out.println(c.getClass());
// ignore statuspanel,
// copy/paste is available via textfield's own keyboard
// actions
if (c.equals(statusPanel)) {
break;
}
// ignore LayerTree textfields, we have currently no plugin
// w/ shortcuts
// doing anything w/ it, preserving layer name editing
// shortcuts this way
if (c instanceof TreeLayerNamePanel
&& focussed instanceof JTextComponent) {
break;
}
if (c instanceof TaskFrame
|| (c instanceof ToolboxDialog && c
.equals(EditingPlugIn.getInstance()
.getToolbox()))
|| c instanceof WorkbenchFrame) {
valid = true;
break;
}
// we treat windows and jinternalframes as our ultimate
// parent, as pretty much everything would end up with
// WorkbenchFrame as parent in the end
if (c instanceof Window || c instanceof JInternalFrame)
break;
c = c.getParent();
}
// if we are not in one of the containers above
// we do not use global shortcuts
if (!valid) {
return false; // nothing dispatched
}
// TODO: eventually the whole filtering above should be
// moved into ShortcutPluginExecuteKeyListener where plugins
// define focussed ui components they feel responsible for
switch (e.getID()) {
case KeyEvent.KEY_PRESSED:
shortcutListener.keyPressed(e);
break;
case KeyEvent.KEY_RELEASED:
shortcutListener.keyReleased(e);
break;
case KeyEvent.KEY_TYPED:
shortcutListener.keyTyped(e);
break;
}
// signaling we dispatched it, or not
return e.isConsumed();
}
};
KeyboardFocusManager.getCurrentKeyboardFocusManager()
.addKeyEventDispatcher(dispatcher);
}
/**
* Unlike #add(KeyListener), listeners registered using this method are
* notified when KeyEvents occur on this frame's child components. Note:
* Bug: KeyListeners registered using this method may receive events
* multiple times.
*
* @see #addKeyboardShortcut
*/
public void addEasyKeyListener(KeyListener l) {
// System.out.println("add "+l);
// easyKeyListeners.add(l);
easyKeyListener.addKeyListener(l);
}
public void removeEasyKeyListener(KeyListener l) {
// System.out.println("rem "+l);
// easyKeyListeners.remove(l);
easyKeyListener.removeKeyListener(l);
}
public void addEasyKeyListenerToComp(Component c) {
easyKeyListener.listenTo(c);
}
public void removeEasyKeyListenerFromComp(Component c) {
easyKeyListener.ignore(c);
}
public String getMBCommittedMemory() {
long totalMemory = Runtime.getRuntime().totalMemory();
long freeMemory = Runtime.getRuntime().freeMemory();
long usedMemory = totalMemory - freeMemory;
double usedMemoryInMB = usedMemory / (1024 * 1024d);
String memoryStr = memoryFormat.format(usedMemoryInMB);
return memoryStr;
}
/**
* @param newEnvelopeRenderingThreshold
* the number of on-screen features above which envelope
* rendering should occur
*/
public void setEnvelopeRenderingThreshold(int newEnvelopeRenderingThreshold) {
envelopeRenderingThreshold = newEnvelopeRenderingThreshold;
}
public void setMaximumFeatureExtentForEnvelopeRenderingInPixels(
int newMaximumFeatureExtentForEnvelopeRenderingInPixels) {
maximumFeatureExtentForEnvelopeRenderingInPixels = newMaximumFeatureExtentForEnvelopeRenderingInPixels;
}
/**
* backward compatibility log method for legacy code
* @deprecated - use com.vividsolutions.jump.workbench.Logger instead
*/
@Deprecated
public void log(String message) {
log(message, null, new Exception().getStackTrace()[0]);
}
/**
* backward compatibility log method for legacy code.
* NOTE: parameter clazz is ignored
* @deprecated - use com.vividsolutions.jump.workbench.Logger instead
*/
@Deprecated
public void log(String message, Class clazz) {
log(message, null, new Exception().getStackTrace()[0]);
}
/**
* backward compatibility log method for legacy code
* @deprecated - use com.vividsolutions.jump.workbench.Logger instead
*/
@Deprecated
public void log(String message, Throwable t) {
log(message, t, new Exception().getStackTrace()[0]);
}
private void log(String message, Throwable t, StackTraceElement calledFrom) {
Logger.log(message, Logger.isDebugEnabled() ? t : null, Logger.Level.INFO, calledFrom);
}
public void setMinimumFeatureExtentForAnyRenderingInPixels(
int newMinimumFeatureExtentForAnyRenderingInPixels) {
minimumFeatureExtentForAnyRenderingInPixels = newMinimumFeatureExtentForAnyRenderingInPixels;
}
public void displayLastStatusMessage() {
setStatusMessage(lastStatusMessage);
}
public void setStatusMessage(String message) {
setStatusMessage(message, null);
}
// set message for a time only
public void setStatusMessage(String message, int millis) {
setStatusMessage(message, millis, null, false);
}
public void setStatusMessage(String message, Color color) {
lastStatusMessage = message;
setStatusBarText(message);
boolean high = color != null;
setStatusBarTextHighlighted(high, color);
}
Thread thread = null;
public void setStatusMessage(final String msg, final int millis,
final Color color, final boolean flash) {
if (thread != null) {
thread.interrupt();
}
thread = new Thread(new Runnable() {
public void run() {
if (flash)
flashStatusMessage(msg, color);
else {
setStatusMessage(msg, color);
}
if (millis > 0) {
try {
Thread.sleep(millis);
} catch (Exception e) {
}
if (getStatusBarText().equals(msg))
setStatusMessage("");
}
}
});
thread.start();
}
private void setStatusBarText(String message) {
// Make message at least a space so that the label won't collapse [Jon
// Aquino]
// message = (message == null || message.equals("")) ? " " : message;
messageText.setText(message);
messageText.setToolTipText("<html><body>"
+ GUIUtil.escapeHTML(message)
+ "<br><br>"
+ GUIUtil.escapeHTML(I18N.getInstance().get("ui.WorkbenchFrame.copy-to-clipboard"))
+ "</body></html>");
}
private String getStatusBarText() {
return messageText.getText();
}
/**
* To highlight a message, call #warnUser.
*/
private void setStatusBarTextHighlighted(boolean highlighted, Color color) {
// Use #coordinateLabel rather than (unattached) dummy label because
// dummy label's background does not change when L&F changes. [Jon
// Aquino]
messageText.setForeground(highlighted ? Color.black : coordinateLabel
.getForeground());
messageText.setBackground(highlighted ? color : coordinateLabel
.getBackground());
}
public void setTimeMessage(String message) {
// Make message at least a space so that the label won't collapse [Jon
// Aquino]
message = (message == null || message.equals("")) ? " " : message;
timeLabel.setText(message);
timeLabel.setToolTipText(message);
}
// Add new JLabel for scale //
// [Giuseppe Aruta 2012-feb-18] //
public void setScaleText(String message) {
// Make message at least a space so that the label won't collapse [Jon
// Aquino]
message = (message == null || message.equals("")) ? " " : message;
scaleLabel.setText(message);
scaleLabel.setToolTipText("<html><body>"
+ GUIUtil.escapeHTML(SCALE + " " + message) + "<br><br>"
+ GUIUtil.escapeHTML(SCALE_TIPS) + "</body></html>");
}
// make really extra sure message textarea looks like the jlabel
private boolean init_message_lnf = false;
public void setVisible(boolean b) {
if (b && !init_message_lnf) {
messageText.setFont(coordinateLabel.getFont());
messageText.setBackground(coordinateLabel.getBackground());
messageText.setForeground(coordinateLabel.getForeground());
init_message_lnf = true;
}
super.setVisible(b);
}
public JInternalFrame getActiveInternalFrame() {
return desktopPane.getSelectedFrame();
}
public JInternalFrame[] getInternalFrames() {
return desktopPane.getAllFrames();
}
public TitledPopupMenu getCategoryPopupMenu() {
return categoryPopupMenu;
}
public WorkbenchContext getContext() {
return workbenchContext;
}
public JDesktopPane getDesktopPane() {
return desktopPane;
}
public int getEnvelopeRenderingThreshold() {
return envelopeRenderingThreshold;
}
public TitledPopupMenu getLayerNamePopupMenu() {
return layerNamePopupMenu;
}
public TitledPopupMenu getWMSLayerNamePopupMenu() {
return wmsLayerNamePopupMenu;
}
public LayerViewPanelListener getLayerViewPanelListener() {
return layerViewPanelListener;
}
public Map<Class<?>,JPopupMenu> getNodeClassToPopupMenuMap() {
return nodeClassToLayerNamePopupMenuMap;
}
public LayerNamePanelListener getLayerNamePanelListener() {
return layerNamePanelListener;
}
public int getMaximumFeatureExtentForEnvelopeRenderingInPixels() {
return maximumFeatureExtentForEnvelopeRenderingInPixels;
}
public int getMinimumFeatureExtentForAnyRenderingInPixels() {
return minimumFeatureExtentForAnyRenderingInPixels;
}
public HTMLFrame getOutputFrame() {
if (outputFrame == null)
outputFrame = new HTMLFrame(this) {
public void setTitle(String title) {
// Don't allow the title of the output frame to be changed.
}
{
super.setTitle(I18N.getInstance().get("ui.WorkbenchFrame.output"));
}
};
return outputFrame;
}
public WorkbenchToolBar getToolBar() {
return toolBar;
}
public void activateFrame(JInternalFrame frame) {
try {
if (frame.isIcon()) {
frame.setIcon(false);
}
frame.moveToFront();
frame.requestFocus();
frame.setSelected(true);
if (!(frame instanceof TaskFrame)) {
frame.setMaximum(false);
}
} catch (PropertyVetoException e) {
warnUser(StringUtil.stackTrace(e));
}
}
/**
* If internalFrame is a LayerManagerProxy, the close behaviour will be
* altered so that the user is prompted if it is the last window on the
* LayerManager.
*/
public void addInternalFrame(final JInternalFrame internalFrame) {
addInternalFrame(internalFrame, false, true);
}
public void addInternalFrame(final JInternalFrame internalFrame,
boolean alwaysOnTop, boolean autoUpdateToolBar) {
if (internalFrame instanceof LayerManagerProxy) {
setClosingBehaviour((LayerManagerProxy) internalFrame);
installTitleBarModifiedIndicator((LayerManagerProxy) internalFrame);
}
// <<TODO:IMPROVE>> Listen for when the frame closes, and when it does,
// activate the topmost frame. Because Swing does not seem to do this
// automatically. [Jon Aquino]
// fetch icon on first addition after lnf is setup properly
if (!internalFrameDefaultIconSet) {
internalFrameDefaultIcon = new JInternalFrame().getFrameIcon();
internalFrameDefaultIconSet = true;
}
// only set icon if none set already
if (internalFrame.getFrameIcon() == null
|| internalFrame.getFrameIcon()
.equals(internalFrameDefaultIcon))
JUMPWorkbench.setIcon(internalFrame);
// Call JInternalFrame#setVisible before JDesktopPane#add; otherwise,
// the TreeLayerNamePanel starts too narrow (100 pixels or so) for some
// reason. <<TODO>>Investigate. [Jon Aquino]
internalFrame.setVisible(true);
desktopPane.add(internalFrame, alwaysOnTop ? JLayeredPane.PALETTE_LAYER
: JLayeredPane.DEFAULT_LAYER);
if (autoUpdateToolBar) {
internalFrame.addInternalFrameListener(new InternalFrameListener() {
public void internalFrameActivated(InternalFrameEvent e) {
toolBar.updateEnabledState();
if (internalFrame instanceof TaskFrameProxy) {
setActiveTaskFrame(((TaskFrameProxy) internalFrame)
.getTaskFrame());
}
// Associate current cursortool with the new frame [Jon
// Aquino]
// move to ActivateTaskFrame internal class
// toolBar.reClickSelectedCursorToolButton();
}
public void internalFrameClosed(InternalFrameEvent e) {
toolBar.updateEnabledState();
}
public void internalFrameClosing(InternalFrameEvent e) {
toolBar.updateEnabledState();
}
public void internalFrameDeactivated(InternalFrameEvent e) {
toolBar.updateEnabledState();
}
public void internalFrameDeiconified(InternalFrameEvent e) {
toolBar.updateEnabledState();
}
public void internalFrameIconified(InternalFrameEvent e) {
toolBar.updateEnabledState();
}
public void internalFrameOpened(InternalFrameEvent e) {
toolBar.updateEnabledState();
}
});
}
// prevent user to drag frame out of desktop pane (left and top)
internalFrame.addComponentListener(new ComponentAdapter() {
@Override
public void componentMoved(ComponentEvent e) {
// ignore detached frames, which are hidden in the minus area
if (internalFrame instanceof DetachableInternalFrame
&& ((DetachableInternalFrame) internalFrame)
.isDetached()) {
return;
}
int x = internalFrame.getX();
int y = internalFrame.getY();
int new_x = x < 0 ? 0 : x;
int new_y = y < 0 ? 0 : y;
if (x != new_x || y != new_y)
internalFrame.setLocation(new_x, new_y);
}
});
// relocate in window when maximized is disabled
internalFrame.addComponentListener(new ComponentAdapter() {
public void componentResized(ComponentEvent e) {
if (internalFrame.isMaximizable())
legalize(internalFrame);
;
}
});
// Call #activateFrame *after* adding the listener. [Jon Aquino]
position(internalFrame);
activateFrame(internalFrame);
}
private void installTitleBarModifiedIndicator(
final LayerManagerProxy internalFrame) {
final JInternalFrame i = (JInternalFrame) internalFrame;
new Block() {
// Putting updatingTitle in a Block is better than making it an
// instance variable, because this way there is one updatingTitle
// for each
// internal frame, rather than one for all internal frames. [Jon
// Aquino]
private boolean updatingTitle = false;
private void updateTitle() {
if (updatingTitle) {
return;
}
updatingTitle = true;
try {
String newTitle = i.getTitle();
if (newTitle.length() > 0 && newTitle.charAt(0) == '*') {
newTitle = newTitle.substring(1);
}
if (!internalFrame.getLayerManager()
.getLayersWithModifiedFeatureCollections()
.isEmpty()) {
newTitle = '*' + newTitle;
}
i.setTitle(newTitle);
} finally {
updatingTitle = false;
}
}
public Object yield() {
final LayerListener layerListener = new LayerListener() {
public void layerChanged(LayerEvent e) {
if ((e.getType() == LayerEventType.METADATA_CHANGED)
|| (e.getType() == LayerEventType.REMOVED)) {
updateTitle();
}
if (e.getType() == LayerEventType.REMOVED) {
if (!(internalFrame instanceof TaskFrame)) {
internalFrame.getLayerManager().removeLayerListener(this);
}
}
}
public void categoryChanged(CategoryEvent e) {
}