22import java.awt.Dimension;
23import java.awt.event.WindowAdapter;
24import java.awt.event.WindowEvent;
25import java.awt.event.WindowFocusListener;
27import java.util.concurrent.TimeUnit;
28import java.util.logging.Logger;
30import javax.swing.JFrame;
31import javax.swing.JOptionPane;
32import javax.swing.JPanel;
33import javax.swing.ToolTipManager;
34import javax.swing.UIManager;
36import org.apache.commons.cli.CommandLine;
38import denoptim.files.FileFormat;
39import denoptim.files.FileUtils;
40import denoptim.task.StaticTaskManager;
41import denoptim.utils.Randomizer;
56public class GUI implements Runnable
86 private CommandLine
cmd;
106 ToolTipManager.sharedInstance().setDismissDelay(6000);
107 ToolTipManager.sharedInstance().setInitialDelay(1000);
108 ToolTipManager.sharedInstance().setReshowDelay(100);
119 frame =
new JFrame(
"DENOPTIM - GUI");
121 frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
122 frame.addWindowListener(
new WindowAdapter() {
124 public void windowClosing(WindowEvent windowEvent) {
134 frame.setJMenuBar(menuBar);
153 if (UIManager.getLookAndFeel().getClass().getName().equals(
156 UIManager.getLookAndFeelDefaults().put(
"MenuBar.foreground",
157 new Color(150,150,150));
158 UIManager.getLookAndFeelDefaults().put(
"TableHeader.background",
159 new Color(200,200,200));
164 this.frame.setLocationRelativeTo(
null);
165 this.frame.setVisible(
true);
166 this.frame.addWindowFocusListener(
new WindowFocusListener() {
169 public void windowLostFocus(WindowEvent e) {
174 public void windowGainedFocus(WindowEvent e) {
179 if (
cmd!=
null &&
cmd.getArgList().size()>0)
181 for (String arg :
cmd.getArgList())
183 File file =
new File(arg);
188 }
catch (Throwable t)
195 }
catch (Exception e) {
209 final Process p = Runtime.getRuntime().exec(
new String[]
210 {
"defaults",
"read",
"-g",
"AppleInterfaceStyle"});
211 p.waitFor(100, TimeUnit.MILLISECONDS);
212 return p.exitValue() == 0;
229 String[] options =
new String[]{
"Yes, stop running tasks",
"No"};
230 int res = JOptionPane.showOptionDialog(
frame,
231 "<html>Found running tasks.<br>Do you want to "
232 +
"stop all running tasks?</html>",
234 JOptionPane.YES_NO_OPTION,
235 JOptionPane.QUESTION_MESSAGE,
236 UIManager.getIcon(
"OptionPane.warningIcon"),
239 if (res == 1 || res == -1)
247 }
catch (Exception e) {
249 String[] options =
new String[]{
"Yes, stop and close"};
250 JOptionPane.showOptionDialog(
frame,
251 "<html>Problems killing the running tasks.<br>Will force "
252 +
"quit all tasks and shutdown.</html>",
254 JOptionPane.DEFAULT_OPTION,
255 JOptionPane.QUESTION_MESSAGE,
256 UIManager.getIcon(
"OptionPane.warningIcon"),
259 Runtime.getRuntime().halt(0);
269 String[] options =
new String[]{
"Yes",
"No"};
270 int res = JOptionPane.showOptionDialog(
frame,
271 "Found unsaved changes. "
272 +
"Are you sure you want to close this window?",
274 JOptionPane.DEFAULT_OPTION,
275 JOptionPane.QUESTION_MESSAGE,
276 UIManager.getIcon(
"OptionPane.warningIcon"),
281 Runtime.getRuntime().halt(0);
288 Runtime.getRuntime().halt(0);
static FileFormat detectFileFormat(File inFile)
Inspects a file/folder and tries to detect if there is one of the data sources that is recognized by ...
Graphical User Interface of the DENOPTIM package.
CommandLine cmd
Command line options.
static final Randomizer PRNG
Random number generator specific for the GUI, and any of its tasks.
GUIMainPanel mainPanel
Panel including all but tool bar.
void closeIfAllSaved()
Close GUI is there are no unsaved changes to the open components.
void run()
Launch the application.
JPanel framePane
Panel including tool bar.
static final String GUILOGGER
Name of logger for the GUI.
GUI(CommandLine cmd)
Constructor that specifies parameters.
int height
Default height.
static boolean weRunOnMacDarkMode()
Checks if we are in dark mode.
JFrame frame
GUI window frame.
The main panel is a deck of cards that occupies all the GUI frame.
boolean hasUnsavedChanges()
Checks is any card has unsaved changes.
Component add(Component comp)
Add a component and a reference to such component in the main tool bar.
The home panel contains shortcuts buttons to perform the most common tasks.
Main tool bar of the DENOPTIM graphical user interface.
void openFile(File file, FileFormat fileFormat)
Process a file that has a recognized file format and loads a suitable GUI card to visualize the file ...
void setRefToMasterGUI(GUI gui)
Sets the reference to master GUI.
void setRefToMainPanel(GUIMainPanel mainPanel)
Sets the reference to main panel for creating functionality of menu items depending on main panel ide...
Manager for tasks submitted by the GUI.
static JProgressBar queueStatusBar
Reference to progress bar in GUI.
static boolean hasActive()
Tool to generate random numbers and random decisions.