-
Notifications
You must be signed in to change notification settings - Fork 115
/
MainView.java
3880 lines (3542 loc) · 147 KB
/
MainView.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
/**
* This file is part of VisiCut.
* Copyright (C) 2011 - 2013 Thomas Oster <thomas.oster@rwth-aachen.de>
* RWTH Aachen University - 52062 Aachen, Germany
*
* VisiCut is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* VisiCut 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with VisiCut. If not, see <http://www.gnu.org/licenses/>.
**/
package com.t_oster.visicut.gui;
// Do not add this import!
// It is loaded dynamically iff JavaFX is available:
// import com.tur0kk.thingiverse.gui.ThingiverseLoginDialog;
import com.tur0kk.thingiverse.gui.ThingiverseDialog;
import com.apple.eawt.AppEvent.AboutEvent;
import com.apple.eawt.AppEvent.OpenFilesEvent;
import com.apple.eawt.AppEvent.PreferencesEvent;
import com.apple.eawt.AppEvent.QuitEvent;
import com.apple.eawt.QuitResponse;
import com.frochr123.fabqr.FabQRFunctions;
import com.frochr123.fabqr.gui.FabQRUploadDialog;
import com.frochr123.gui.QRWebcamScanDialog;
import com.frochr123.helper.QRCodeInfo;
import com.t_oster.liblasercut.IllegalJobException;
import com.t_oster.liblasercut.LaserCutter;
import com.t_oster.liblasercut.LaserProperty;
import com.t_oster.liblasercut.ProgressListener;
import com.t_oster.liblasercut.platform.Util;
import com.t_oster.visicut.misc.FileUtils;
import com.t_oster.uicomponents.PlatformIcon;
import com.t_oster.uicomponents.Ruler;
import com.t_oster.uicomponents.warnings.Message;
import com.t_oster.visicut.VisicutModel;
import com.t_oster.visicut.VisicutModel.Modification;
import com.t_oster.visicut.gui.beans.CreateNewMaterialDialog;
import com.t_oster.visicut.gui.beans.CreateNewThicknessDialog;
import com.t_oster.visicut.gui.parameterpanel.ParameterPanel;
import com.t_oster.visicut.managers.LaserDeviceManager;
import com.t_oster.visicut.managers.LaserPropertyManager;
import com.t_oster.visicut.managers.MappingManager;
import com.t_oster.visicut.managers.MaterialManager;
import com.t_oster.visicut.managers.PreferencesManager;
import com.t_oster.visicut.managers.ProfileManager;
import com.t_oster.visicut.misc.DialogHelper;
import com.t_oster.visicut.misc.ExtensionFilter;
import com.t_oster.visicut.misc.Helper;
import com.t_oster.visicut.model.LaserDevice;
import com.t_oster.visicut.model.LaserProfile;
import com.t_oster.visicut.model.MaterialProfile;
import com.t_oster.visicut.model.PlfFile;
import com.t_oster.visicut.model.PlfPart;
import com.t_oster.visicut.model.Raster3dProfile;
import com.t_oster.visicut.model.RasterProfile;
import com.t_oster.visicut.model.VectorProfile;
import com.t_oster.visicut.model.graphicelements.psvgsupport.ParametricPlfPart;
import com.t_oster.visicut.model.mapping.MappingSet;
import com.tur0kk.facebook.FacebookManager;
import com.tur0kk.facebook.gui.FacebookDialog;
import com.tur0kk.thingiverse.ThingiverseManager;
import com.frochr123.periodictasks.RefreshCameraThread;
import com.frochr123.periodictasks.RefreshProjectorThread;
import com.frochr123.periodictasks.RefreshQRCodesTask;
import com.t_oster.uicomponents.warnings.WarningPanel;
import com.t_oster.visicut.Preferences;
import java.awt.Desktop;
import java.awt.Dimension;
import java.awt.FileDialog;
import java.awt.Image;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ComponentEvent;
import java.awt.event.ComponentListener;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.awt.geom.AffineTransform;
import java.awt.image.BufferedImage;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FilenameFilter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.net.URI;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLClassLoader;
import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.ResourceBundle;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.imageio.ImageIO;
import javax.imageio.stream.ImageInputStream;
import javax.imageio.stream.MemoryCacheImageInputStream;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
import javax.swing.JViewport;
import javax.swing.filechooser.FileFilter;
import org.jdesktop.application.Action;
/**
*
* @author Thomas Oster <thomas.oster@rwth-aachen.de>
*/
public class MainView extends javax.swing.JFrame
{
private static MainView instance = null;
private ResourceBundle bundle = java.util.ResourceBundle.getBundle("com/t_oster/visicut/gui/resources/MainView");
private ThingiverseDialog thingiverseDialog = null;
private ParameterPanel parameterPanel = new ParameterPanel();
private boolean cameraActive = false;
private boolean cameraCapturing = false;
private String cameraCapturingError = "";
private RefreshCameraThread cameraThread = null;
private boolean projectorActive = false;
private RefreshProjectorThread projectorThread = null;
private RefreshQRCodesTask qrCodesTask = null;
private boolean editGuiForQRCodesDisabled = false;
private boolean laserJobInProgress = false;
private boolean isFabqrUploadDialogOpened = false;
public static MainView getInstance()
{
return instance;
}
final protected DialogHelper dialog = new DialogHelper(this, this.getTitle())
{
@Override
public void showWarningMessage(String text)
{
MainView.this.warningPanel.addMessage(new Message("Warning", text, Message.Type.WARNING, null));
}
@Override
public void showWarningMessageOnce(String text, String messageId, int timeout)
{
// use timeout=-1 to disable timeout
MainView.this.warningPanel.addMessageOnce(new Message("Warning", text, Message.Type.WARNING, null, timeout), messageId);
}
@Override
public void showSuccessMessage(String text)
{
MainView.this.warningPanel.addMessage(new Message("Success", text, Message.Type.SUCCESS, null, 10000));
}
@Override
public void showInfoMessage(String text)
{
MainView.this.warningPanel.addMessage(new Message("Info", text, Message.Type.INFO, null));
}
@Override
public void showErrorMessage(Exception ex)
{
Throwable cause = ex;
while ((cause.getMessage() == null || "".equals(cause.getMessage())) && cause.getCause() != null)
{
cause = cause.getCause();
}
cause.printStackTrace();
MainView.this.warningPanel.addMessage(new Message("Error", "Exception: " + cause.getLocalizedMessage(), Message.Type.ERROR, null));
}
@Override
public void showErrorMessage(Exception cause, String text)
{
cause.printStackTrace();
MainView.this.warningPanel.addMessage(new Message("Error", text + ": " + cause.getLocalizedMessage(), Message.Type.ERROR, null));
}
@Override
public void showErrorMessage(String text)
{
MainView.this.warningPanel.addMessage(new Message("Error", text, Message.Type.ERROR, null));
}
@Override
public void removeMessageWithId(String messageId)
{
MainView.this.warningPanel.removeMessageWithId(messageId);
}
};
private boolean ignoreLaserCutterComboBoxUpdates;
public MainView(File loadedFile)
{
this();
this.loadFileReal(loadedFile, true);
}
/**
* Shows the according EditLaserProfile dialog for the given
* laser-profile and returns the altered clone of the profile if ok
* was pressed, and null else. The given LaserProfile is not touched
* @param lp
* @return
*/
public LaserProfile editLaserProfile(LaserProfile profile)
{
if (profile instanceof VectorProfile)
{
EditVectorProfileDialog d = new EditVectorProfileDialog(null, true);
d.setVectorProfile((VectorProfile) ((VectorProfile) profile).clone());
d.setOnlyEditParameters(true);
d.setVisible(true);
profile = d.isOkPressed() ? d.getVectorProfile() : null;
}
else if (profile instanceof RasterProfile)
{
EditRasterProfileDialog d = new EditRasterProfileDialog(null, true);
d.setRasterProfile((RasterProfile) profile);
d.setOnlyEditParameters(true);
d.setVisible(true);
profile = d.getRasterProfile();
}
else if (profile instanceof Raster3dProfile)
{
EditRaster3dProfileDialog d = new EditRaster3dProfileDialog(null, true);
d.setRasterProfile((Raster3dProfile) profile);
d.setOnlyEditParameters(true);
d.setVisible(true);
profile = d.getRasterProfile();
}
return profile;
}
/** Creates new form MainView */
public MainView()
{
try
{
Image i = ImageIO.read(this.getClass().getResourceAsStream("resources/visicut.png"));
this.setIconImage(i);
}
catch (Exception e)
{
System.err.println("Error reading image: " + e);
}
instance = this;
initComponents();
jScrollPane2.setColumnHeaderView(new Ruler(this.previewPanel, Ruler.HORIZONTAL));
jScrollPane2.setRowHeaderView(new Ruler(this.previewPanel, Ruler.VERTICAL));
jScrollPane2.setCorner(JScrollPane.UPPER_LEFT_CORNER, new JLabel("cm"));
//fixes slow scrolling issue on Mac OS X
JViewport viewPort = jScrollPane2.getViewport();
viewPort.setScrollMode(JViewport.BLIT_SCROLL_MODE);
viewPort.setScrollMode(JViewport.BACKINGSTORE_SCROLL_MODE);
viewPort.setScrollMode(JViewport.SIMPLE_SCROLL_MODE);
jScrollPane2.addComponentListener(new ComponentListener()
{
public void componentResized(ComponentEvent ce)
{
MainView.this.previewPanel.resizeToFitZoomAndArea();
}
public void componentMoved(ComponentEvent ce)
{
}
public void componentShown(ComponentEvent ce)
{
}
public void componentHidden(ComponentEvent ce)
{
}
});
if (Helper.isMacOS())
{//Mac OS has its own exit menu and different Keybindings
fileMenu.remove(exitMenuItem);
openMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_O, java.awt.event.InputEvent.META_MASK));
newMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_N, java.awt.event.InputEvent.META_MASK));
saveMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_S, java.awt.event.InputEvent.META_MASK));
executeJobMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_P, java.awt.event.InputEvent.META_MASK));
zoomInMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_ADD, java.awt.event.InputEvent.META_MASK));
zoomOutMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_SUBTRACT, java.awt.event.InputEvent.META_MASK));
}
fixMaterialThicknesses();
fillComboBoxes();
refreshMaterialThicknessesComboBox();
if (Helper.isMacOS())
{
com.apple.eawt.Application macApplication = com.apple.eawt.Application.getApplication();
jmPreferences.setVisible(false);
macApplication.setPreferencesHandler(new com.apple.eawt.PreferencesHandler()
{
public void handlePreferences(PreferencesEvent pe)
{
MainView.this.jmPreferencesActionPerformed(null);
}
});
exitMenuItem.setVisible(false);
macApplication.setQuitHandler(new com.apple.eawt.QuitHandler()
{
public void handleQuitRequestWith(QuitEvent qe, QuitResponse qr)
{
MainView.this.exitMenuItemActionPerformed(null);
}
});
aboutMenuItem.setVisible(false);
macApplication.setAboutHandler(new com.apple.eawt.AboutHandler()
{
public void handleAbout(AboutEvent ae)
{
MainView.this.aboutMenuItemActionPerformed(null);
}
});
macApplication.setOpenFileHandler(new com.apple.eawt.OpenFilesHandler()
{
public void openFiles(OpenFilesEvent ofe)
{
for (File f : ofe.getFiles())
{
MainView.this.loadFile(f, false);
}
}
});
}
//Window listener for capturing close and save preferences before exiting
this.addWindowListener(new WindowListener()
{
public void windowOpened(WindowEvent e)
{
}
public void windowClosing(WindowEvent e)
{
MainView.this.exitMenuItemActionPerformed(null);
}
public void windowClosed(WindowEvent e)
{
}
public void windowIconified(WindowEvent e)
{
}
public void windowDeiconified(WindowEvent e)
{
}
public void windowActivated(WindowEvent e)
{
}
public void windowDeactivated(WindowEvent e)
{
}
});
this.refreshRecentFilesMenu();
this.jmInstallInkscape.setEnabled(Helper.isInkscapeExtensionInstallable());
this.jmInstallIllustrator.setEnabled(Helper.isIllustratorScriptInstallable());
if (!Helper.isInkscapeExtensionInstallable() && !Helper.isIllustratorScriptInstallable())
{
this.jmExtras.setVisible(false);
}
this.refreshExampleMenu();
//initialize states coorectly
this.visicutModel1PropertyChange(new java.beans.PropertyChangeEvent(visicutModel1, VisicutModel.PROP_SELECTEDLASERDEVICE, null, null));
this.visicutModel1PropertyChange(new java.beans.PropertyChangeEvent(visicutModel1, VisicutModel.PROP_SELECTEDPART, null, null));
this.visicutModel1PropertyChange(new java.beans.PropertyChangeEvent(visicutModel1, VisicutModel.PROP_PREFERENCES, null, null));
PositionPanelController c = new PositionPanelController(positionPanel, visicutModel1);
this.warningPanel.setVisible(false);
LaserDeviceManager.getInstance().addPropertyChangeListener(new PropertyChangeListener()
{
public void propertyChange(PropertyChangeEvent pce)
{
refreshLaserDeviceComboBox();
}
});
//apply the saved window size and position, if in current screen size
Rectangle lastBounds = PreferencesManager.getInstance().getPreferences().getWindowBounds();
if (lastBounds != null && this.getGraphicsConfiguration().getBounds().contains(lastBounds))
{
this.setExtendedState(JFrame.NORMAL);
this.setPreferredSize(new Dimension(lastBounds.width, lastBounds.height));
this.setBounds(lastBounds);
}
// all GUI parts are now initialised.
if (LaserDeviceManager.getInstance().getAll().isEmpty())
{
this.jmDownloadSettingsActionPerformed(null);
}
// Cleanup old temporary files, which might not have been deleted correctly
FileUtils.cleanupOldTempFilesAtStartup();
}
private ActionListener exampleItemClicked = new ActionListener()
{
public void actionPerformed(ActionEvent ae)
{
if (!"".equals(ae.getActionCommand()))
{
MainView.this.loadFile(new File(ae.getActionCommand()), false);
}
}
};
private void fillMenu(JMenu parent, Map<String, Object> map)
{
for (Entry<String, Object> e : map.entrySet())
{
if (e.getValue() instanceof File)
{
JMenuItem item = new JMenuItem(e.getKey());
item.setActionCommand(((File) e.getValue()).getAbsolutePath());
item.addActionListener(exampleItemClicked);
parent.add(item);
}
else if (e.getValue() instanceof Map)
{
JMenu m = new JMenu(e.getKey());
fillMenu(m, (Map) e.getValue());
parent.add(m);
}
}
}
private JMenuItem openExamples;
private void refreshExampleMenu()
{
jmExamples.removeAll();
JMenu builtin = new JMenu(bundle.getString("BUILTIN"));
this.fillMenu(builtin, PreferencesManager.getInstance().getBuiltinExampleFiles());
jmExamples.add(builtin);
this.fillMenu(jmExamples, PreferencesManager.getInstance().getExampleFiles());
if (openExamples == null)
{
openExamples = new JMenuItem(bundle.getString("EDIT"));
openExamples.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent ae)
{
dialog.openInFilebrowser(new File(Helper.getBasePath(), "examples"));
//TODO refresh menu on next click (menu and action-listener don't work)
}
});
}
jmExamples.add(openExamples);
}
/**
* Fills the recent files menu from the current
* list in preferences
*/
private void refreshRecentFilesMenu()
{
this.recentFilesMenu.removeAll();
for (String p : this.visicutModel1.getPreferences().getRecentFiles())
{
final File f = new File(p);
if (f.isFile())
{
JMenuItem i = new JMenuItem(f.getName());
i.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent ae)
{
loadFile(f, false);
}
});
this.recentFilesMenu.add(i);
}
}
}
private void refreshMaterialComboBox()
{
this.ignoreMaterialComboBoxChanges = true;
String sp = this.visicutModel1.getMaterial() != null ? this.visicutModel1.getMaterial().getName() : null;
this.materialComboBox.removeAllItems();
for (MaterialProfile mp : MaterialManager.getInstance().getAll())
{
this.materialComboBox.addItem(mp);
if (mp.getName().equals(sp))
{
this.materialComboBox.setSelectedItem(mp);
}
}
this.ignoreMaterialComboBoxChanges = false;
//hide material combo box if only one material available
boolean materialUiVisible = true;
if (this.materialComboBox.getItemCount() == 1 && MaterialManager.getInstance().getAll().get(0).getMaterialThicknesses().size() == 1)
{
this.materialComboBox.setSelectedIndex(0);
materialUiVisible = false;
}
this.materialComboBox.setVisible(materialUiVisible);
this.btAddMaterial.setVisible(materialUiVisible);
this.cbMaterialThickness.setVisible(materialUiVisible);
this.btAddMaterialThickness.setVisible(materialUiVisible);
this.jLabel1.setVisible(materialUiVisible);
this.jLabel5.setVisible(materialUiVisible);
}
// add a "0.0mm" material thickness if the material has an empty list of thicknesses
private void fixMaterialThicknesses()
{
List<MaterialProfile> materials = MaterialManager.getInstance().getAll();
for (MaterialProfile mp : materials)
{
if (mp.getMaterialThicknesses().isEmpty())
{
LinkedList<Float> l = new LinkedList<Float>();
l.add((float) 0.0);
mp.setMaterialThicknesses(l);
System.err.println("Found material \"" + mp.getName() + "\" without a thickness entry - this should not happen! Adding a thickness 0.0 for this material. Please report if you find a way to create materials without a thickness.");
try
{
MaterialManager.getInstance().save(mp);
}
catch (IOException e)
{
System.err.println("Failed to fix because of exception " + e);
}
}
}
}
/*
* Initially fills LaserCutter, Material, Object and Mapping ComboBox with all possible Elements
*/
private void fillComboBoxes()
{
this.refreshLaserDeviceComboBox();
this.refreshMaterialComboBox();
this.refreshObjectComboBox();
}
private void refreshLaserDeviceComboBox()
{
String sld = this.visicutModel1.getSelectedLaserDevice() != null ? this.visicutModel1.getSelectedLaserDevice().getName() : null;
ignoreLaserCutterComboBoxUpdates = true;
this.laserCutterComboBox.removeAllItems();
for (LaserDevice ld : LaserDeviceManager.getInstance().getAll())
{
this.laserCutterComboBox.addItem(ld);
if (ld.getName().equals(sld))
{
this.laserCutterComboBox.setSelectedItem(ld);
}
}
//hide lasercutter combo box if only one lasercutter available
if (this.laserCutterComboBox.getItemCount() == 1)
{
this.laserCutterComboBox.setSelectedIndex(0);
this.laserCutterComboBox.setVisible(false);
this.jLabel9.setVisible(false);
}
else
{
this.laserCutterComboBox.setVisible(true);
this.jLabel9.setVisible(true);
}
ignoreLaserCutterComboBoxUpdates = false;
}
/**
* update entries of objectComboBox, then update selection
* @param forceUpdate even update if the list of PlfParts has not changed
* @throws RuntimeException if forceUpdate==false and PlfParts have not changed
*/
public void refreshObjectComboBox()
{
this.ignoreObjectComboBoxEvents = true;
// fill new list of PlfItems
this.objectComboBox.removeAllItems();
if (VisicutModel.getInstance().getSelectedPart() == null)
{
// add default "nothing selected" item if nothing is selected
this.objectComboBox.addItem(java.util.ResourceBundle.getBundle("com/t_oster/visicut/gui/resources/MainView").getString("(nothing selected)"));
}
for (PlfPart p : VisicutModel.getInstance().getPlfFile())
{
if (p == null || p.getSourceFile() == null)
{ // necessary?
continue;
}
// add regular item
this.objectComboBox.addItem(p);
}
// now set the correct selection
if (VisicutModel.getInstance().getSelectedPart() != null)
{
// something is selected, also select this in the combobox
this.objectComboBox.setSelectedItem(VisicutModel.getInstance().getSelectedPart());
}
else
{
// no PlfPart is selected, so select the pseudo-item "nothing selected"
this.objectComboBox.setSelectedIndex(0);
}
//gradually hide complexity. Issue #71
int files = this.visicutModel1.getPlfFile().size();
boolean selected = this.visicutModel1.getSelectedPart() != null;
if (files == 1 && selected)
{
this.jLabel2.setText("<html>" + this.bundle.getString("jLabel2.text") + " <b>" + this.visicutModel1.getSelectedPart().getSourceFile().getName() + "</b></html>");
}
else
{
this.jLabel2.setText(this.bundle.getString("jLabel2.text") + (files == 1 && !selected ? " " + this.bundle.getString("(nothing selected)") : ""));
}
// Avoid some frequent visible changes if GUI is disabled for QR code detection
// Once this mode turns on / off again, the correct state is restored
if (!isEditGuiForQRCodesDisabled())
{
this.objectComboBox.setVisible(files > 1);
}
this.btRemoveObject.setVisible(files > 0 && selected);
this.ignoreObjectComboBoxEvents = false;
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents()
{
bindingGroup = new org.jdesktop.beansbinding.BindingGroup();
visicutModel1 = VisicutModel.getInstance();
filesDropSupport1 = new com.t_oster.uicomponents.FilesDropSupport();
saveFileChooser = new javax.swing.JFileChooser();
buttonGroup1 = new javax.swing.ButtonGroup();
jScrollPane2 = new javax.swing.JScrollPane();
previewPanel = new com.t_oster.visicut.gui.beans.PreviewPanel();
jScrollPane1 = new javax.swing.JScrollPane();
jPanel2 = new javax.swing.JPanel();
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
jLabel5 = new javax.swing.JLabel();
materialComboBox = new com.t_oster.uicomponents.ImageComboBox();
jLabel9 = new javax.swing.JLabel();
laserCutterComboBox = new com.t_oster.uicomponents.ImageComboBox();
jLabel10 = new javax.swing.JLabel();
jLabelJobName = new javax.swing.JLabel();
jTextFieldJobName = new javax.swing.JTextField();
calculateTimeButton = new javax.swing.JButton();
timeLabel = new javax.swing.JLabel();
mappingTabbedPane = new javax.swing.JTabbedPane();
mappingPanel = new com.t_oster.visicut.gui.mapping.MappingPanel();
positionPanel = new com.t_oster.uicomponents.PositionPanel();
propertyPanelContainer = new javax.swing.JScrollPane();
propertiesPanel = new com.t_oster.visicut.gui.propertypanel.PropertiesPanel();
btAddMaterial = new javax.swing.JButton();
cbMaterialThickness = new javax.swing.JComboBox();
btAddMaterialThickness = new javax.swing.JButton();
jCheckBox1 = new javax.swing.JCheckBox();
executeJobButton = new javax.swing.JButton();
objectComboBox = new javax.swing.JComboBox();
jSeparator1 = new javax.swing.JSeparator();
btRemoveObject = new javax.swing.JButton();
btAddObject = new javax.swing.JButton();
warningPanel = new com.t_oster.uicomponents.warnings.WarningPanel();
jPanel1 = new javax.swing.JPanel();
jButton2 = new javax.swing.JButton();
jButton1 = new javax.swing.JButton();
btFitScreen = new javax.swing.JButton();
bt1to1 = new javax.swing.JButton();
filler2 = new javax.swing.Box.Filler(new java.awt.Dimension(0, 0), new java.awt.Dimension(35, 35), new java.awt.Dimension(35, 35));
btFacebook = new javax.swing.JButton();
btThingiverse = new javax.swing.JButton();
btQRWebcamScan = new javax.swing.JButton();
jPanel3 = new javax.swing.JPanel();
progressBar = new javax.swing.JProgressBar();
menuBar = new javax.swing.JMenuBar();
fileMenu = new javax.swing.JMenu();
newMenuItem = new javax.swing.JMenuItem();
openMenuItem = new javax.swing.JMenuItem();
importMenuItem = new javax.swing.JMenuItem();
recentFilesMenu = new javax.swing.JMenu();
jmExamples = new javax.swing.JMenu();
jSeparator5 = new javax.swing.JPopupMenu.Separator();
saveMenuItem = new javax.swing.JMenuItem();
saveAsMenuItem = new javax.swing.JMenuItem();
exportGcodeMenuItem = new javax.swing.JMenuItem();
jSeparator4 = new javax.swing.JPopupMenu.Separator();
executeJobMenuItem = new javax.swing.JMenuItem();
jSeparator6 = new javax.swing.JPopupMenu.Separator();
exitMenuItem = new javax.swing.JMenuItem();
viewMenu = new javax.swing.JMenu();
zoomOutMenuItem = new javax.swing.JMenuItem();
zoomInMenuItem = new javax.swing.JMenuItem();
zoomWindowMenuItem = new javax.swing.JMenuItem();
zoomRealMenuItem = new javax.swing.JMenuItem();
jSeparator2 = new javax.swing.JPopupMenu.Separator();
cameraActiveMenuItem = new javax.swing.JCheckBoxMenuItem();
projectorActiveMenuItem = new javax.swing.JCheckBoxMenuItem();
jSeparator7 = new javax.swing.JPopupMenu.Separator();
showGridMenuItem = new javax.swing.JCheckBoxMenuItem();
actionsMenu = new javax.swing.JMenu();
facebookMenuItem = new javax.swing.JMenuItem();
thingiverseMenuItem = new javax.swing.JMenuItem();
webcamQRCodeMenuItem = new javax.swing.JMenuItem();
optionsMenu = new javax.swing.JMenu();
calibrateCameraMenuItem = new javax.swing.JMenuItem();
jSeparator9 = new javax.swing.JPopupMenu.Separator();
jMenuItem1 = new javax.swing.JMenuItem();
jmImportSettings = new javax.swing.JMenuItem();
jmExportSettings = new javax.swing.JMenuItem();
jSeparator8 = new javax.swing.JPopupMenu.Separator();
editMappingMenuItem = new javax.swing.JMenuItem();
jmManageLaserprofiles = new javax.swing.JMenuItem();
materialMenuItem = new javax.swing.JMenuItem();
jMenuItem2 = new javax.swing.JMenuItem();
jSeparator10 = new javax.swing.JPopupMenu.Separator();
jmPreferences = new javax.swing.JMenuItem();
jmExtras = new javax.swing.JMenu();
jmInstallInkscape = new javax.swing.JMenuItem();
jmInstallIllustrator = new javax.swing.JMenuItem();
helpMenu = new javax.swing.JMenu();
manualMenuItem = new javax.swing.JMenuItem();
wikiMenuItem = new javax.swing.JMenuItem();
jSeparator3 = new javax.swing.JPopupMenu.Separator();
aboutMenuItem = new javax.swing.JMenuItem();
visicutModel1.addPropertyChangeListener(new java.beans.PropertyChangeListener()
{
public void propertyChange(java.beans.PropertyChangeEvent evt)
{
visicutModel1PropertyChange(evt);
}
});
filesDropSupport1.setComponent(previewPanel);
filesDropSupport1.addPropertyChangeListener(new java.beans.PropertyChangeListener()
{
public void propertyChange(java.beans.PropertyChangeEvent evt)
{
filesDropSupport1PropertyChange(evt);
}
});
saveFileChooser.setAcceptAllFileFilterUsed(false);
saveFileChooser.setDialogType(javax.swing.JFileChooser.SAVE_DIALOG);
saveFileChooser.setFileFilter(new ExtensionFilter(".plf", java.util.ResourceBundle.getBundle("com/t_oster/visicut/gui/resources/MainView").getString("VISICUT PORTABLE LASER FILE")));
saveFileChooser.setName("saveFileChooser"); // NOI18N
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(com.t_oster.visicut.gui.VisicutApp.class).getContext().getResourceMap(MainView.class);
setTitle(resourceMap.getString("Form.title")); // NOI18N
setName("Form"); // NOI18N
jScrollPane2.setBorder(javax.swing.BorderFactory.createTitledBorder(resourceMap.getString("jPanel1.border.title"))); // NOI18N
jScrollPane2.setName("jScrollPane2"); // NOI18N
jScrollPane2.setWheelScrollingEnabled(false);
previewPanel.setName("previewPanel"); // NOI18N
com.t_oster.visicut.gui.PreviewPanelKeyboardMouseHandler ppMouseHandler = new com.t_oster.visicut.gui.PreviewPanelKeyboardMouseHandler(this.previewPanel);
javax.swing.GroupLayout previewPanelLayout = new javax.swing.GroupLayout(previewPanel);
previewPanel.setLayout(previewPanelLayout);
previewPanelLayout.setHorizontalGroup(
previewPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 605, Short.MAX_VALUE)
);
previewPanelLayout.setVerticalGroup(
previewPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 457, Short.MAX_VALUE)
);
jScrollPane2.setViewportView(previewPanel);
jScrollPane1.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
jScrollPane1.setName("jScrollPane1"); // NOI18N
jPanel2.setName("jPanel2"); // NOI18N
jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
jLabel1.setName("jLabel1"); // NOI18N
jLabel2.setText(resourceMap.getString("jLabel2.text")); // NOI18N
jLabel2.setName("jLabel2"); // NOI18N
jLabel5.setText(resourceMap.getString("jLabel5.text")); // NOI18N
jLabel5.setName("jLabel5"); // NOI18N
materialComboBox.setName("materialComboBox"); // NOI18N
materialComboBox.addActionListener(new java.awt.event.ActionListener()
{
public void actionPerformed(java.awt.event.ActionEvent evt)
{
materialComboBoxActionPerformed(evt);
}
});
jLabel9.setText(resourceMap.getString("jLabel9.text")); // NOI18N
jLabel9.setName("jLabel9"); // NOI18N
laserCutterComboBox.setName("laserCutterComboBox"); // NOI18N
laserCutterComboBox.addActionListener(new java.awt.event.ActionListener()
{
public void actionPerformed(java.awt.event.ActionEvent evt)
{
laserCutterComboBoxActionPerformed(evt);
}
});
jLabel10.setText(resourceMap.getString("jLabel10.text")); // NOI18N
jLabel10.setName("jLabel10"); // NOI18N
jLabelJobName.setText(resourceMap.getString("jLabelJobName.text")); // NOI18N
jLabelJobName.setName("jLabelJobName"); // NOI18N
jTextFieldJobName.setName("jTextFieldJobName"); // NOI18N
calculateTimeButton.setText(resourceMap.getString("calculateTimeButton.text")); // NOI18N
calculateTimeButton.setEnabled(false);
calculateTimeButton.setName("calculateTimeButton"); // NOI18N
calculateTimeButton.addActionListener(new java.awt.event.ActionListener()
{
public void actionPerformed(java.awt.event.ActionEvent evt)
{
calculateTimeButtonActionPerformed(evt);
}
});
timeLabel.setText(resourceMap.getString("timeLabel.text")); // NOI18N
timeLabel.setName("timeLabel"); // NOI18N
mappingTabbedPane.setName("Custom"); // NOI18N
mappingPanel.setName("mappingPanel"); // NOI18N
mappingTabbedPane.addTab(resourceMap.getString("mappingPanel.TabConstraints.tabTitle"), mappingPanel); // NOI18N
positionPanel.setName("positionPanel"); // NOI18N
mappingTabbedPane.addTab(resourceMap.getString("positionPanel.TabConstraints.tabTitle"), positionPanel); // NOI18N
propertyPanelContainer.setName("propertyPanelContainer"); // NOI18N
propertiesPanel.setName("propertiesPanel"); // NOI18N
propertiesPanel.setLayout(new javax.swing.BoxLayout(propertiesPanel, javax.swing.BoxLayout.Y_AXIS));
propertyPanelContainer.setViewportView(propertiesPanel);
mappingTabbedPane.addTab(resourceMap.getString("propertyPanelContainer.TabConstraints.tabTitle"), propertyPanelContainer); // NOI18N
btAddMaterial.setIcon(PlatformIcon.get(PlatformIcon.ADD));
btAddMaterial.setName("btAddMaterial"); // NOI18N
btAddMaterial.addActionListener(new java.awt.event.ActionListener()
{
public void actionPerformed(java.awt.event.ActionEvent evt)
{
btAddMaterialActionPerformed(evt);
}
});
cbMaterialThickness.setName("cbMaterialThickness"); // NOI18N
cbMaterialThickness.addActionListener(new java.awt.event.ActionListener()
{
public void actionPerformed(java.awt.event.ActionEvent evt)
{
cbMaterialThicknessActionPerformed(evt);
}
});
btAddMaterialThickness.setIcon(PlatformIcon.get(PlatformIcon.ADD));
btAddMaterialThickness.setName("btAddMaterialThickness"); // NOI18N
btAddMaterialThickness.addActionListener(new java.awt.event.ActionListener()
{
public void actionPerformed(java.awt.event.ActionEvent evt)
{
btAddMaterialThicknessActionPerformed(evt);
}
});
jCheckBox1.setText(resourceMap.getString("jCheckBox1.text")); // NOI18N
jCheckBox1.setToolTipText(resourceMap.getString("jCheckBox1.toolTipText")); // NOI18N
jCheckBox1.setName("jCheckBox1"); // NOI18N
org.jdesktop.beansbinding.Binding binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, visicutModel1, org.jdesktop.beansbinding.ELProperty.create("${useThicknessAsFocusOffset}"), jCheckBox1, org.jdesktop.beansbinding.BeanProperty.create("selected"), "cbUseThickness");
bindingGroup.addBinding(binding);
executeJobButton.setText(resourceMap.getString("executeJobButton.text")); // NOI18N
executeJobButton.setName("executeJobButton"); // NOI18N
executeJobButton.addActionListener(new java.awt.event.ActionListener()
{
public void actionPerformed(java.awt.event.ActionEvent evt)
{
executeJobButtonActionPerformed(evt);
}
});
objectComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
objectComboBox.setName("objectComboBox"); // NOI18N
objectComboBox.addItemListener(new java.awt.event.ItemListener()
{
public void itemStateChanged(java.awt.event.ItemEvent evt)
{
objectComboBoxChangeHandler(evt);
}
});
jSeparator1.setName("jSeparator1"); // NOI18N
btRemoveObject.setIcon(PlatformIcon.get(PlatformIcon.REMOVE_FILE));
java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle("com/t_oster/uicomponents/resources/EditableTablePanel"); // NOI18N
btRemoveObject.setToolTipText(bundle.getString("-")); // NOI18N
btRemoveObject.setName("btRemoveObject"); // NOI18N
btRemoveObject.addActionListener(new java.awt.event.ActionListener()
{
public void actionPerformed(java.awt.event.ActionEvent evt)
{
btRemoveObjectActionPerformed(evt);
}
});
btAddObject.setIcon(PlatformIcon.get(PlatformIcon.ADD_FILE));
btAddObject.setToolTipText(bundle.getString("+")); // NOI18N
btAddObject.setName("btAddObject"); // NOI18N
btAddObject.addActionListener(new java.awt.event.ActionListener()
{
public void actionPerformed(java.awt.event.ActionEvent evt)
{
btAddObjectActionPerformed(evt);
}
});
javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
jPanel2.setLayout(jPanel2Layout);
jPanel2Layout.setHorizontalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel2Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel2Layout.createSequentialGroup()
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel2Layout.createSequentialGroup()
.addComponent(jLabelJobName)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jTextFieldJobName, javax.swing.GroupLayout.DEFAULT_SIZE, 168, Short.MAX_VALUE)
.addGap(199, 199, 199)
.addComponent(executeJobButton))
.addGroup(jPanel2Layout.createSequentialGroup()
.addComponent(jLabel10)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(timeLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 166, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 199, Short.MAX_VALUE)
.addComponent(calculateTimeButton)))
.addContainerGap())
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(mappingTabbedPane, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 514, Short.MAX_VALUE)
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel2Layout.createSequentialGroup()
.addComponent(jLabel2)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(objectComboBox, 0, 416, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btAddObject, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)