Adjusting testing cases for current state of OCCT
[occt.git] / samples / java / java / SamplesStarter.java
1
2 //Title:        OpenCASCADE Samples
3 //Version:
4 //Copyright:    Copyright (c) 1999
5 //Author:       User Interface group
6 //Company:      Matra Datavision
7 //Description:
8
9 import java.awt.*;
10 import java.awt.event.*;
11 import javax.swing.*;
12 import javax.swing.event.*;
13 import java.util.*;
14
15
16 public class SamplesStarter extends JPanel
17                             implements ChangeListener
18 {
19   // The Frame
20   public static Frame myFrame;
21
22   // The width and height of the frame
23   public static int WIDTH = 900;
24   public static int HEIGHT = 550;
25   public static int INITIAL_WIDTH = 400;
26   public static int INITIAL_HEIGHT = 200;
27
28   // The Status Line
29   private static JLabel myStatusBar = null;
30   private Component myCurrentPage = null;
31
32   // Track progress
33   public static int totalPanels = 10;
34   public static int currentProgressValue;
35   public static JLabel progressLabel = null;
36   public static JProgressBar progressBar = null;
37
38
39 //=======================================================================//
40 // Constructor
41 //=======================================================================//
42   public SamplesStarter()
43   {
44     //-----------------------------------------------------------//
45     // Localization
46     //-----------------------------------------------------------//
47     ResourceBundle AppRes = ResourceBundle.getBundle("properties.AppRes");
48     Locale aLocale = new Locale(AppRes.getString("language"), "");
49
50     Locale.setDefault(aLocale);
51
52     setLayout(new BorderLayout());
53
54     //-----------------------------------------------------------//
55     // Create a tab pane
56     //-----------------------------------------------------------//
57     JTabbedPane tabbedPane = new JTabbedPane();
58     tabbedPane.addChangeListener(this);
59     add(tabbedPane, BorderLayout.CENTER);
60
61     // About panel
62     try {
63         progressLabel.setText("Loading Title page");
64         tabbedPane.addTab("Open CASCADE Technology", new AboutPanel());
65     }
66     catch (Exception e) {
67         e.printStackTrace();
68     }
69     progressBar.setValue(++currentProgressValue);
70           
71
72     // The Geometry sample
73     try {
74         progressLabel.setText("Loading the Geometry sample");
75         tabbedPane.addTab("Geometry", new SampleGeometryPanel());
76     }
77     catch (Exception e) {
78         e.printStackTrace();
79     }
80     progressBar.setValue(++currentProgressValue);
81
82     // The Topology samples
83     try {
84         progressLabel.setText("Loading the Topology samples");
85         tabbedPane.addTab("Topology", new SamplesTopologyPanel());
86     }
87     catch (Exception e) {
88         e.printStackTrace();
89     }
90     progressBar.setValue(++currentProgressValue);
91
92     // The Viewer3D sample
93     try {
94         progressLabel.setText("Loading the Viewer3D sample");
95         tabbedPane.addTab("Viewer3D", new SampleViewer3DPanel());
96     }
97     catch (Exception e) {
98         e.printStackTrace();
99     }
100     progressBar.setValue(++currentProgressValue);
101
102     // The AIS Basic sample
103     try {
104         progressLabel.setText("Loading the AIS Basic sample");
105         tabbedPane.addTab("AIS Basic", new SampleAISBasicPanel());
106     }
107     catch (Exception e) {
108         e.printStackTrace();
109     }
110     progressBar.setValue(++currentProgressValue);
111
112     // The AIS DisplayMode sample
113     try {
114         progressLabel.setText("Loading the AIS DisplayMode sample");
115         tabbedPane.addTab("AIS DisplayMode", new SampleAISDisplayModePanel());
116     }
117     catch (Exception e) {
118         e.printStackTrace();
119     }
120     progressBar.setValue(++currentProgressValue);
121
122     // The AIS Select sample
123     try {
124         progressLabel.setText("Loading the AIS Select sample");
125         tabbedPane.addTab("AIS Select", new SampleAISSelectPanel());
126     }
127     catch (Exception e) {
128         e.printStackTrace();
129     }
130     progressBar.setValue(++currentProgressValue);
131
132     // The Display Animation sample
133     try {
134         progressLabel.setText("Loading the Display Animation sample");
135         tabbedPane.addTab("DisplayAnimation", new SampleDisplayAnimationPanel());
136     }
137     catch (Exception e) {
138         e.printStackTrace();
139     }
140     progressBar.setValue(++currentProgressValue);
141
142     // The ImportExport sample
143     try {
144         progressLabel.setText("Loading the ImportExport sample");
145         tabbedPane.addTab("Import/Export", new SampleImportExportPanel());
146         progressBar.setValue(++currentProgressValue);
147     }
148     catch (Exception e) {
149         e.printStackTrace();
150     }
151
152     // The HLR sample
153     try {
154         progressLabel.setText("Loading the HLR sample");
155         tabbedPane.addTab("HLR", new SampleHLRPanel());
156     }
157     catch (Exception e) {
158         e.printStackTrace();
159     }
160     progressBar.setValue(++currentProgressValue);
161
162     tabbedPane.setSelectedIndex(0);
163     myCurrentPage = tabbedPane.getComponentAt(0);
164
165     //-----------------------------------------------------------//
166     // Create a status line
167     //-----------------------------------------------------------//
168     myStatusBar = new JLabel("");
169     myStatusBar.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
170     add(myStatusBar, BorderLayout.SOUTH);
171     put_info("");
172   }
173
174 //=======================================================================//
175 // Start
176 //=======================================================================//
177   public static void main(String[] args)
178   {
179     try
180     {
181       UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
182 //      UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
183     }
184     catch(Exception e)
185     {
186     }
187
188     javax.swing.ToolTipManager.sharedInstance().setLightWeightPopupEnabled(false);
189
190     WindowListener l = new WindowAdapter() {
191             public void windowClosing(WindowEvent e) {System.exit(0);}
192     };
193
194     ResourceBundle resIcons =
195          ResourceBundle.getBundle("properties.DesktopIcon");
196     ImageIcon imageIcon = new ImageIcon(resIcons.getString("MF_MATRALOGO"));
197
198     myFrame = new Frame("Open CASCADE Technology Samples");
199     myFrame.setIconImage(imageIcon.getImage());
200     myFrame.addWindowListener(l);
201
202
203     JPanel progressPanel = new JPanel() {
204         public Insets getInsets() {
205           return new Insets(40,30,20,30);
206         }
207     };
208     progressPanel.setLayout(new BoxLayout(progressPanel, BoxLayout.Y_AXIS));
209     myFrame.add(progressPanel, BorderLayout.CENTER);
210
211     Dimension d = new Dimension(400, 20);
212     SamplesStarter.progressLabel = new JLabel("Loading, please wait...");
213     SamplesStarter.progressLabel.setAlignmentX(CENTER_ALIGNMENT);
214     SamplesStarter.progressLabel.setMaximumSize(d);
215     SamplesStarter.progressLabel.setPreferredSize(d);
216     progressPanel.add(SamplesStarter.progressLabel);
217     progressPanel.add(Box.createRigidArea(new Dimension(1,20)));
218
219     SamplesStarter.progressBar = new JProgressBar(0, SamplesStarter.totalPanels);
220     SamplesStarter.progressBar.setStringPainted(true);
221     SamplesStarter.progressLabel.setLabelFor(progressBar);
222     SamplesStarter.progressBar.setAlignmentX(CENTER_ALIGNMENT);
223     progressPanel.add(SamplesStarter.progressBar);
224
225     // show the frame
226     myFrame.setSize(INITIAL_WIDTH, INITIAL_HEIGHT);
227     Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
228     myFrame.setLocation(screenSize.width/2 - INITIAL_WIDTH/2,
229                         screenSize.height/2 - INITIAL_HEIGHT/2);
230     myFrame.show();
231
232     myFrame.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
233
234     // Samples creation
235     SamplesStarter samplesStarter = new SamplesStarter();
236
237     myFrame.removeAll();
238     myFrame.setLayout(new BorderLayout());
239     myFrame.add(samplesStarter, BorderLayout.CENTER);
240     myFrame.setSize(WIDTH, HEIGHT);
241     myFrame.setLocation(screenSize.width/2 - WIDTH/2,
242                         screenSize.height/2 - HEIGHT/2);
243
244     myFrame.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
245
246     myFrame.validate();
247     //    myFrame.repaint();
248     samplesStarter.requestDefaultFocus();
249   }
250
251   public static void put_info(String message)
252   {
253     if (myStatusBar != null)
254       myStatusBar.setText(". " + message);
255   }
256
257   public static Frame getFrame()
258   {
259     return myFrame;
260   }
261
262 //=======================================================================//
263 //                          Change Listener                              //
264 //=======================================================================//
265   public void stateChanged(ChangeEvent event)
266   {
267     SamplesStarter.put_info("");
268
269     JTabbedPane tab = (JTabbedPane) event.getSource();
270     int index = tab.getSelectedIndex();
271     Component currentPage = tab.getComponentAt(index);
272
273     if (myCurrentPage != null)
274     {
275       myCurrentPage.setVisible(false);
276       myCurrentPage.setEnabled(false);
277     }
278     currentPage.setVisible(true);
279     currentPage.setEnabled(true);
280
281     myCurrentPage = currentPage;
282   }
283
284 }