예제 #1
0
 public void actionPerformed(ActionEvent ae) {
   if (ae.getActionCommand() == "timer") {
     if (counter >= imagePaths.length) {
       timer.stop();
       counter = 0;
       PlayStopButton.setText("Play");
     } else {
       try {
         // if the array contains URLs
         if (imagePaths[counter].contains("http://")) {
           scrollPane.setToolTipText(imagePaths[counter]);
           imageIcon = new ImageIcon((new URL(imagePaths[counter++])));
           scrollPane.setViewportView(new JLabel(imageIcon));
         }
         // if the array contains local images
         else {
           image.setIcon(new ImageIcon(imagePaths[counter]));
           image.setToolTipText(imagePaths[counter++]);
         }
       } catch (MalformedURLException ex) {
         Logger.getLogger(Slideshow.class.getName()).log(Level.SEVERE, null, ex);
         image = new JLabel("?" + imagePaths);
       }
     }
   }
 }
예제 #2
0
  /**
   * Create a button to go inside of the toolbar. By default this will load an image resource. The
   * image filename is relative to the classpath (including the '.' directory if its a part of the
   * classpath), and may either be in a JAR file or a separate file.
   *
   * @param key The key in the resource file to serve as the basis of lookups.
   */
  protected JButton createToolbarButton(String key) {
    URL url = getResource(key + imageSuffix);
    JButton b =
        new JButton(new ImageIcon(url)) {

          @Override
          public float getAlignmentY() {
            return 0.5f;
          }
        };
    b.setRequestFocusEnabled(false);
    b.setMargin(new Insets(1, 1, 1, 1));

    String astr = getProperty(key + actionSuffix);
    if (astr == null) {
      astr = key;
    }
    Action a = getAction(astr);
    if (a != null) {
      b.setActionCommand(astr);
      b.addActionListener(a);
    } else {
      b.setEnabled(false);
    }

    String tip = getResourceString(key + tipSuffix);
    if (tip != null) {
      b.setToolTipText(tip);
    }

    return b;
  }
예제 #3
0
  /** Initializes this dialog. */
  private void initDialog() {
    setMinimumSize(new Dimension(640, 480));

    final JComponent settingsPane = createSettingsPane();
    final JComponent previewPane = createPreviewPane();

    final JPanel contentPane = new JPanel(new GridBagLayout());
    contentPane.add(
        settingsPane,
        new GridBagConstraints(
            0,
            0,
            1,
            1,
            0.0,
            0.0,
            GridBagConstraints.NORTH,
            GridBagConstraints.NONE,
            new Insets(2, 0, 2, 0),
            0,
            0));
    contentPane.add(
        previewPane,
        new GridBagConstraints(
            1,
            0,
            1,
            1,
            1.0,
            1.0,
            GridBagConstraints.NORTH,
            GridBagConstraints.BOTH,
            new Insets(2, 0, 2, 0),
            0,
            0));

    final JButton runAnalysisButton = ToolUtils.createRunAnalysisButton(this);
    this.runAnalysisAction = (RestorableAction) runAnalysisButton.getAction();

    final JButton exportButton = ToolUtils.createExportButton(this);
    this.exportAction = exportButton.getAction();
    this.exportAction.setEnabled(false);

    final JButton closeButton = ToolUtils.createCloseButton();
    this.closeAction = closeButton.getAction();

    final JComponent buttons =
        SwingComponentUtils.createButtonPane(runAnalysisButton, exportButton, closeButton);

    SwingComponentUtils.setupWindowContentPane(this, contentPane, buttons, runAnalysisButton);
  }
 /** Reset the interface layout */
 private void clearInterface() {
   epanetNetwork = null;
   inpFile = null;
   frame.setTitle(APP_TITTLE);
   textReservoirs.setText("0");
   textTanks.setText("0");
   textPipes.setText("0");
   textNodes.setText("0");
   textDuration.setText("00:00:00");
   textHydraulic.setText("00:00:00");
   textPattern.setText("00:00:00");
   textUnits.setText("NONE");
   textHeadloss.setText("NONE");
   textQuality.setText("NONE");
   textDemand.setText("0.0");
   saveAction.setEnabled(false);
   runAction.setEnabled(false);
   runSimulationButton.setEnabled(false);
 }
예제 #5
0
  Slideshow(String images[]) {
    // transfer array of images into local array
    imagePaths = images;

    // create the frame and set its size, layout, location, and close operation
    frame = new JFrame("Slideshow");
    frame.setSize(800, 600);
    frame.setLayout(new BorderLayout());
    frame.setLocationRelativeTo(frame);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    // create center and play/stop buttons
    centerButton = new JButton("center");
    PlayStopButton = new JButton("Play");

    // set actionListener for timer
    timer = new Timer(seconds, this);
    timer.setActionCommand("timer");

    // set actionListener for the Play/Stop button
    PlayStopButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent ae) {
            if (PlayStopButton.getText() == "Play") {
              PlayStopButton.setText("Stop");
              timer.start();
            } else if (PlayStopButton.getText() == "Stop") {
              PlayStopButton.setText("Play");
              timer.stop();
            }
          }
        });

    // add the JLabel to the JScrollPane
    image = new JLabel("");
    scrollPane = new JScrollPane(image);

    // add everything to the frame and display it
    frame.add(scrollPane);
    frame.add(PlayStopButton, BorderLayout.SOUTH);
    frame.setVisible(true);
  }
  /**
   * Creates a dialog where the user can specify the location of the database,including the type of
   * network connection (if this is a networked client)and IP address and port number; or search and
   * select the database on a local drive if this is a standalone client.
   *
   * @param parent Defines the Component that is to be the parent of this dialog box. For
   *     information on how this is used, see <code>JOptionPane</code>
   * @param connectionMode Specifies the type of connection (standalone or networked)
   * @see JOptionPane
   */
  public DatabaseLocationDialog(Frame parent, ApplicationMode connectionMode) {
    configOptions = (new ConfigOptions(connectionMode));
    configOptions.getObservable().addObserver(this);

    // load saved configuration
    SavedConfiguration config = SavedConfiguration.getSavedConfiguration();

    // the port and connection type are irrelevant in standalone mode
    if (connectionMode == ApplicationMode.STANDALONE_CLIENT) {
      validPort = true;
      validCnx = true;
      networkType = ConnectionType.DIRECT;
      location = config.getParameter(SavedConfiguration.DATABASE_LOCATION);
    } else {
      // there may not be a network connectivity type defined and, if
      // not, we do not set a default - force the user to make a choice
      // the at least for the first time they run this.
      String tmp = config.getParameter(SavedConfiguration.NETWORK_TYPE);
      if (tmp != null) {
        try {
          networkType = ConnectionType.valueOf(tmp);
          configOptions.setNetworkConnection(networkType);
          validCnx = true;
        } catch (IllegalArgumentException e) {
          log.warning("Unknown connection type: " + networkType);
        }
      }

      // there is always at least a default port number, so we don't have
      // to validate this.
      port = config.getParameter(SavedConfiguration.SERVER_PORT);
      configOptions.setPortNumberText(port);
      validPort = true;

      location = config.getParameter(SavedConfiguration.SERVER_ADDRESS);
    }

    // there may not be a default database location, so we had better
    // validate before using the returned value.
    if (location != null) {
      configOptions.setLocationFieldText(location);
      validDb = true;
    }

    options =
        new JOptionPane(configOptions, JOptionPane.QUESTION_MESSAGE, JOptionPane.OK_CANCEL_OPTION);

    connectButton.setActionCommand(CONNECT);
    connectButton.addActionListener(this);

    boolean allValid = validDb && validPort && validCnx;
    connectButton.setEnabled(allValid);

    exitButton.setActionCommand(EXIT);
    exitButton.addActionListener(this);

    options.setOptions(new Object[] {connectButton, exitButton});

    dialog = options.createDialog(parent, TITLE);
    dialog.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
    dialog.addWindowListener(this);
    dialog.setVisible(true);
  }
  /**
   * Callback method to process modifications in the common ConfigOptions panel. ConfigOptions was
   * developed to be common to many applications (even though we only have three modes), so it does
   * not have any knowledge of how we are using it within this dialog box. So ConfigOptions just
   * sends updates to registered Observers whenever anything changes. We can receive those
   * notifications here, and decide whether we have enough information to enable the "Connect"
   * button of the dialog box.
   */
  public void update(Observable o, Object arg) {
    // we are going to ignore the Observable object, since we are only
    // observing one object. All we are interested in is the argument.

    if (!(arg instanceof OptionUpdate)) {
      log.log(
          Level.WARNING,
          "DatabaseLocationDialog received update type: " + arg,
          new IllegalArgumentException());
      return;
    }

    OptionUpdate optionUpdate = (OptionUpdate) arg;

    // load saved configuration
    SavedConfiguration config = SavedConfiguration.getSavedConfiguration();

    switch (optionUpdate.getUpdateType()) {
      case DB_LOCATION_CHANGED:
        location = (String) optionUpdate.getPayload();
        if (configOptions.getApplicationMode() == ApplicationMode.STANDALONE_CLIENT) {
          File f = new File(location);
          if (f.exists() && f.canRead() && f.canWrite()) {
            validDb = true;
            log.info("File chosen " + location);
            config.setParameter(SavedConfiguration.DATABASE_LOCATION, location);
          } else {
            log.warning("Invalid file " + location);
          }
        } else {
          try {
            if (location.matches("\\d+\\.\\d+\\.\\d+\\.\\d+")) {
              // location given matches 4 '.' separated numbers
              // regex could be improved by limiting each quad to
              // no more than 3 digits.
              String[] quads = location.split("\\.");
              byte[] address = new byte[quads.length];
              for (int i = 0; i < quads.length; i++) {
                address[i] = new Integer(quads[i]).byteValue();
              }
              InetAddress.getByAddress(address);
            } else {
              InetAddress.getAllByName(location);
            }
            log.info("Server specified " + location);
            validDb = true;
            config.setParameter(SavedConfiguration.SERVER_ADDRESS, location);
          } catch (UnknownHostException uhe) {
            log.warning("Unknown host: " + location);
            validDb = false;
          }
        }
        break;
      case PORT_CHANGED:
        port = (String) optionUpdate.getPayload();
        int p = Integer.parseInt(port);

        if (p >= LOWEST_PORT && p < HIGHEST_PORT) {
          if (p < SYSTEM_PORT_BOUNDARY) {
            log.info("User chose System port " + port);
          } else if (p < IANA_PORT_BOUNDARY) {
            log.info("User chose IANA port " + port);
          } else {
            log.info("User chose dynamic port " + port);
          }
          validPort = true;
          config.setParameter(SavedConfiguration.SERVER_PORT, port);
        } else {
          validPort = false;
        }
        break;
      case NETWORK_CHOICE_MADE:
        networkType = (ConnectionType) optionUpdate.getPayload();
        switch (networkType) {
          case SOCKET:
            log.info("Server connection via Sockets");
            break;
          case RMI:
            log.info("Server connection via RMI");
            break;
          default:
            log.info("Unknown connection type: " + networkType);
            break;
        }
        config.setParameter(SavedConfiguration.NETWORK_TYPE, "" + networkType);
        validCnx = true;
        break;
      default:
        log.warning("Unknown update: " + optionUpdate);
        break;
    }

    boolean allValid = validDb && validPort && validCnx;
    connectButton.setEnabled(allValid);
  }
예제 #8
0
  public TestFrame(String title) throws HeadlessException {
    super(title);
    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Container contentPane = this.getContentPane();
    contentPane.setLayout(new BorderLayout());
    JPanel topPanel = new JPanel();
    topPanel.setLayout(new BorderLayout());
    JPanel bottomPanel = new JPanel();
    bottomPanel.setLayout(new BorderLayout());
    final JTextField textField = new JTextField();
    this.addressField = textField;
    JButton button = new JButton("Parse & Render");
    final JTabbedPane tabbedPane = new JTabbedPane();
    final JTree tree = new JTree();
    final JScrollPane scrollPane = new JScrollPane(tree);

    this.tree = tree;

    contentPane.add(topPanel, BorderLayout.NORTH);
    contentPane.add(bottomPanel, BorderLayout.CENTER);

    topPanel.add(new JLabel("URL: "), BorderLayout.WEST);
    topPanel.add(textField, BorderLayout.CENTER);
    topPanel.add(button, BorderLayout.EAST);

    bottomPanel.add(tabbedPane, BorderLayout.CENTER);

    final HtmlPanel panel = new HtmlPanel();
    panel.addSelectionChangeListener(
        new SelectionChangeListener() {
          public void selectionChanged(SelectionChangeEvent event) {
            if (logger.isLoggable(Level.INFO)) {
              logger.info("selectionChanged(): selection node: " + panel.getSelectionNode());
            }
          }
        });
    this.htmlPanel = panel;
    UserAgentContext ucontext = new SimpleUserAgentContext();
    this.rcontext = new LocalHtmlRendererContext(panel, ucontext);

    final JTextArea textArea = new JTextArea();
    this.textArea = textArea;
    textArea.setEditable(false);
    final JScrollPane textAreaSp = new JScrollPane(textArea);

    tabbedPane.addTab("HTML", panel);
    tabbedPane.addTab("Tree", scrollPane);
    tabbedPane.addTab("Source", textAreaSp);
    tabbedPane.addChangeListener(
        new ChangeListener() {
          public void stateChanged(ChangeEvent e) {
            Component component = tabbedPane.getSelectedComponent();
            if (component == scrollPane) {
              tree.setModel(new NodeTreeModel(panel.getRootNode()));
            } else if (component == textAreaSp) {
              textArea.setText(rcontext.getSourceCode());
            }
          }
        });

    button.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent event) {
            process(textField.getText());
          }
        });
  }
예제 #9
0
  public TestXEmbedServer(boolean manual) {

    // Enable testing extensions in XEmbed server
    System.setProperty("sun.awt.xembed.testing", "true");

    f = new Frame("Main frame");
    f.addWindowListener(
        new WindowAdapter() {
          public void windowClosing(WindowEvent e) {
            synchronized (TestXEmbedServer.this) {
              TestXEmbedServer.this.notifyAll();
            }
            dummy.dispose();
            f.dispose();
          }
        });

    f.setLayout(new BorderLayout());

    Container bcont = new Container();

    toFocus = new Button("Click to focus server");
    final TextField tf = new TextField(20);
    tf.setName("0");
    DragSource ds = new DragSource();
    final DragSourceListener dsl =
        new DragSourceAdapter() {
          public void dragDropEnd(DragSourceDropEvent dsde) {}
        };
    final DragGestureListener dgl =
        new DragGestureListener() {
          public void dragGestureRecognized(DragGestureEvent dge) {
            dge.startDrag(null, new StringSelection(tf.getText()), dsl);
          }
        };
    ds.createDefaultDragGestureRecognizer(tf, DnDConstants.ACTION_COPY, dgl);

    final DropTargetListener dtl =
        new DropTargetAdapter() {
          public void drop(DropTargetDropEvent dtde) {
            dtde.acceptDrop(DnDConstants.ACTION_COPY);
            try {
              tf.setText(
                  tf.getText()
                      + (String) dtde.getTransferable().getTransferData(DataFlavor.stringFlavor));
            } catch (Exception e) {
            }
          }
        };
    final DropTarget dt = new DropTarget(tf, dtl);

    Button b_add = new Button("Add client");
    b_add.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            addClient();
          }
        });
    Button b_remove = new Button("Remove client");
    b_remove.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            if (clientCont.getComponentCount() != 0) {
              clientCont.remove(clientCont.getComponentCount() - 1);
            }
          }
        });
    b_close = new JButton("Close modal dialog");
    b_close.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            modal_d.dispose();
          }
        });
    b_modal = new Button("Show modal dialog");
    b_modal.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            modal_d = new JDialog(f, "Modal dialog", true);
            modal_d.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
            modal_d.setBounds(0, 100, 200, 50);
            modal_d.getContentPane().add(b_close);
            modal_d.validate();
            modal_d.show();
          }
        });

    bcont.add(tf);
    bcont.add(toFocus);
    bcont.add(b_add);
    bcont.add(b_remove);
    bcont.add(b_modal);
    if (manual) {
      Button pass = new Button("Pass");
      pass.addActionListener(
          new ActionListener() {
            public void actionPerformed(ActionEvent e) {
              passed = true;
              synchronized (TestXEmbedServer.this) {
                TestXEmbedServer.this.notifyAll();
              }
            }
          });
      bcont.add(pass);
      Button fail = new Button("Fail");
      fail.addActionListener(
          new ActionListener() {
            public void actionPerformed(ActionEvent e) {
              passed = false;
              synchronized (TestXEmbedServer.this) {
                TestXEmbedServer.this.notifyAll();
              }
            }
          });
      bcont.add(fail);
    }
    b_modal.setName("2");
    bcont.setLayout(new FlowLayout());
    f.add(bcont, BorderLayout.NORTH);

    clientCont = Box.createVerticalBox();
    f.add(clientCont, BorderLayout.CENTER);

    dummy = new JFrame("Dummy");
    dummy.getContentPane().add(new JButton("Button"));
    dummy.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
    dummy.setBounds(0, VERTICAL_POSITION, 100, 100);
    dummy.setVisible(true);

    f.setBounds(300, VERTICAL_POSITION, 800, 300);
    f.setVisible(true);
  }
예제 #10
0
  public LoginPanel(Image img, ActionListener listener) {
    super(null);
    this.listener = listener;
    if (img == null) {
      InputStream inData = getClass().getResourceAsStream("/resources/background.gif");
      BufferedImage back = null;
      if (inData != null)
        try {
          back = ImageIO.read(inData);
        } catch (IOException e) {
          loger.finest("LoginPanel class can't get the background image");
        }
      this.background = back;
    }

    setLayout(null);
    JPanel logingPanel = new JPanel();
    loginTitle = new JLabel("Autentificare");
    logingPanel.setSize(250, 150);
    logingPanel.setBorder(new javax.swing.border.LineBorder(Color.black, 2));
    logingPanel.setLayout(null);
    loginTitle.setBounds(3, 0, logingPanel.getWidth(), 20);
    logingPanel.add(loginTitle);
    JLabel loginUser = new JLabel("Utilizator");
    loginUser.setBounds(
        80 - loginUser.getPreferredSize().width,
        40,
        loginUser.getPreferredSize().width,
        loginUser.getPreferredSize().height);
    logingPanel.add(loginUser);
    user = new JTextField(10);
    user.setBounds(85, 40, user.getPreferredSize().width, user.getPreferredSize().height);
    // user.setText("test");
    // loginUser.setLabelFor(user);
    logingPanel.add(user);
    JLabel loginPass = new JLabel("Parola");
    loginPass.setBounds(
        80 - loginPass.getPreferredSize().width,
        80,
        loginPass.getPreferredSize().width,
        loginPass.getPreferredSize().height);
    logingPanel.add(loginPass);
    // JTextField pass = new JTextField(10);
    pass = new JPasswordField(10);
    pass.setBounds(85, 80, pass.getPreferredSize().width, pass.getPreferredSize().height);
    pass.addKeyListener(this);
    // pass.setText("test");
    // loginUser.setLabelFor(user);
    logingPanel.add(pass);
    JButton loginButton = new JButton("Start");
    loginButton.setActionCommand("LOGIN");
    loginButton.setBounds(
        60, 110, loginButton.getPreferredSize().width, loginButton.getPreferredSize().height);
    // loginButton.setOpaque(false);
    loginButton.setFocusPainted(false);
    // loginButton.setContentAreaFilled(false);
    // loginButton.setBorderPainted(false);
    loginButton.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
    loginButton.addActionListener(listener);
    logingPanel.add(loginButton);

    add(logingPanel);
  }
예제 #11
0
  public void run() {

    // Collect some user data.
    dlg = new JDialog(console.frame, "Example 1 Setup", true);
    dlg.getContentPane().setLayout(new BorderLayout());

    // Properties area
    propPanel = new JPanel();
    dlg.getContentPane().add(propPanel, BorderLayout.CENTER);

    GridBagLayout gbl = new GridBagLayout();
    propPanel.setLayout(gbl);

    // List of voice resources
    DefaultListModel dlm = new DefaultListModel();
    for (int x = 1; ; x++) {
      try {
        int c = x % 4 == 0 ? 4 : x % 4;
        int b = c == 4 ? x / 4 : x / 4 + 1;
        String devName = "dxxxB" + b + "C" + c;
        int dev = dx.open(devName, 0);
        try {
          // If any of the voice resources _are not_ connected to
          // analog loop-start lines, then they will be suppressed
          // here because sethook() will not be supported.
          dx.sethook(dev, dx.DX_ONHOOK, dx.EV_SYNC);
          dlm.addElement(devName);
        } catch (Exception ignore) {
        }
        dx.close(dev);
      } catch (Exception ignore) {
        break;
      }
    }
    analogDxList = new JList(dlm);
    {
      GridBagConstraints gbc;
      // Choose a voice resource:
      gbc = new GridBagConstraints();
      gbc.gridx = 0;
      gbc.gridy = 0;
      gbc.fill = GridBagConstraints.BOTH;
      JTextField t = new JTextField("Analog Voice Resource");
      t.setEditable(false);
      gbl.setConstraints(t, gbc);
      propPanel.add(t);
      gbc = new GridBagConstraints();
      gbc.gridx = 1;
      gbc.gridy = 0;
      gbc.fill = GridBagConstraints.BOTH;
      JScrollPane s = new JScrollPane(analogDxList);
      gbl.setConstraints(s, gbc);
      propPanel.add(s);
    }

    // Dialog buttons at the bottom.
    JPanel buttonPanel = new JPanel();
    buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.X_AXIS));
    dlg.getContentPane().add(buttonPanel, BorderLayout.SOUTH);
    // "Run"
    {
      JButton b = new JButton("Run");
      b.addActionListener(
          new AbstractAction() {
            public void actionPerformed(ActionEvent e) {
              final Object[] dx = analogDxList.getSelectedValues();
              if (dx.length != 1) {
                // "Please select one, and only one, voice resource."
                JOptionPane.showMessageDialog(
                    dlg,
                    "Please select one, and only one, resource.",
                    "Error",
                    JOptionPane.ERROR_MESSAGE);
                return;
              }
              Thread t =
                  new Thread() {
                    public void run() {
                      runExample((String) dx[0]);
                    }
                  };
              t.start();
              dlg.dispose();
            }
          });
      buttonPanel.add(b);
    }
    // "Cancel"
    {
      JButton b = new JButton("Cancel");
      b.addActionListener(
          new AbstractAction() {
            public void actionPerformed(ActionEvent e) {
              dlg.dispose();
            }
          });
      buttonPanel.add(b);
    }

    // Pack and Show
    dlg.pack();
    dlg.setLocationRelativeTo(console.frame);
    dlg.setVisible(true);
  }
  /** Show the open dialog and open the INP/XLSX and XML files. */
  private void openEvent() {
    if (fileChooser == null) {
      // fileChooser = new FileDialog(frame);
      fileChooser = new JFileChooser(System.getProperty("user.dir"));
      fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
      fileChooser.setAcceptAllFileFilterUsed(false);
      fileChooser.addChoosableFileFilter(new XLSXFilter());
      fileChooser.addChoosableFileFilter(new XMLFilter());
      fileChooser.addChoosableFileFilter(new MSXFilter());
      fileChooser.addChoosableFileFilter(new INPFilter());
      fileChooser.addChoosableFileFilter(new AllSuportedFilesFilter());
    }

    if (fileChooser.showOpenDialog(frame) == JFileChooser.APPROVE_OPTION) {
      File netFile = fileChooser.getSelectedFile();
      String fileExtension = Utilities.getFileExtension(netFile.getName());

      if (fileExtension.equals("xlsx")
          || fileExtension.equals("inp")
          || fileExtension.equals("xml")) {
        inpFile = netFile;
        msxFile = null;
        msxName.setText("");

        Network.FileType netType = Network.FileType.INP_FILE;
        if (fileExtension.equals("xlsx")) netType = Network.FileType.EXCEL_FILE;
        else if (fileExtension.equals("xml")) {
          netType = Network.FileType.XML_FILE;
          JOptionPane.showMessageDialog(
              frame, "Not supported yet !", "Error", JOptionPane.OK_OPTION);
          return;
        }

        epanetNetwork = new Network();
        InputParser inpParser = InputParser.create(netType, log);
        try {
          inpParser.parse(epanetNetwork, inpFile);
        } catch (ENException en_ex) {
          JOptionPane.showMessageDialog(
              frame,
              en_ex.toString() + "\nCheck epanet.log for detailed error description",
              "Error",
              JOptionPane.OK_OPTION);
          clearInterface();
          inpFile = null;
          return;
        } catch (Exception egen) {
          JOptionPane.showMessageDialog(
              frame, "Unable to parse network configuration file", "Error", JOptionPane.OK_OPTION);
          log.log(ENLevels.ERROR, "openEvent", egen);
          clearInterface();
          inpFile = null;

          return;
        }

        int resrvCount = 0;
        int tanksCount = 0;

        for (Tank tank : epanetNetwork.getTanks())
          if (tank.getArea() == 0.0) resrvCount++;
          else tanksCount++;

        textReservoirs.setText(Integer.toString(resrvCount));
        textTanks.setText(Integer.toString(tanksCount));
        textPipes.setText(Integer.toString(epanetNetwork.getLinks().size()));
        textNodes.setText(Integer.toString(epanetNetwork.getNodes().size()));
        try {
          textDuration.setText(
              Utilities.getClockTime(epanetNetwork.getPropertiesMap().getDuration()));
          textUnits.setText(epanetNetwork.getPropertiesMap().getUnitsflag().name());
          textHeadloss.setText(epanetNetwork.getPropertiesMap().getFormflag().name());
          textQuality.setText(epanetNetwork.getPropertiesMap().getQualflag().name());
          textDemand.setText(epanetNetwork.getPropertiesMap().getDmult().toString());
          textHydraulic.setText(
              Utilities.getClockTime(epanetNetwork.getPropertiesMap().getHstep()));
          textPattern.setText(Utilities.getClockTime(epanetNetwork.getPropertiesMap().getPstep()));
        } catch (ENException ex) {
        }
        frame.setTitle(APP_TITTLE + inpFile.getName());
        inpName.setText(inpFile.getName());
        runSimulationButton.setEnabled(true);

        saveButton.setEnabled(true);
        reportOptions = null;
      } else if (fileExtension.equals("msx")) {
        if (inpFile == null) {
          JOptionPane.showMessageDialog(
              frame,
              "Load an INP or XLSX file with network configuration before opening the MSX file.",
              "Error",
              JOptionPane.OK_OPTION);
          return;
        }

        msxFile = netFile;
        msxName.setText(fileChooser.getSelectedFile().getName()); // fileChooser.getFile());
        reportOptions = null;
      }

      saveAction.setEnabled(true);
      runAction.setEnabled(true);
    }
  }
  /** Aware-P Epanet frontend constructor. */
  public EpanetUI() {
    initLogger();

    frame = new JFrame();
    frame.setTitle(APP_TITTLE);
    frame.add(root);

    if (!Utilities.isMac()) {
      JMenuBar menuBar = new JMenuBar();

      JMenu fileMenu = new JMenu("File");
      menuBar.add(fileMenu);

      openAction = new JMenuItem("Open");
      saveAction = new JMenuItem("Save");
      runAction = new JMenuItem("Run");

      fileMenu.add(openAction);
      fileMenu.add(openAction);
      fileMenu.add(runAction);

      frame.setJMenuBar(menuBar);
    }

    openAction.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent actionEvent) {
            openEvent();
            network.repaint();
          }
        });

    saveAction.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent actionEvent) {
            saveEvent();
          }
        });

    runAction.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent actionEvent) {
            runSimulation();
          }
        });

    frame.pack();
    frame.setMinimumSize(new Dimension(848, 500));
    frame.setLocationRelativeTo(null);

    clearInterface();

    frame.setVisible(true);

    openINPButton.addActionListener(this);
    runSimulationButton.addActionListener(this);
    logoB.addActionListener(this);
    checkTanks.addActionListener(this);
    checkNodes.addActionListener(this);
    checkPipes.addActionListener(this);
    saveButton.addActionListener(this);
    // runMSXButton.addActionListener(this);
    // saveReport.addActionListener(this);

    frame.addWindowListener(
        new WindowListener() {
          public void windowOpened(WindowEvent e) {}

          public void windowClosing(WindowEvent e) {
            for (Handler handler : log.getHandlers()) {
              handler.flush();
            }
            System.exit(0);
          }

          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) {}
        });
  }