Ejemplo n.º 1
0
  public void updateConnectionStatus(boolean connected) {
    if (connected == true) {
      headerPanel.setLogoutText();
      loginMenuItem.setText("Logout");
    } else {
      headerPanel.setLoginText();
      loginMenuItem.setText("Login...");
    }
    mainCommandPanel.updateConnectionStatus(connected);
    propertiePanel.updateConnectionStatus(connected);
    cmdConsole.updateConnectionStatus(connected);
    Iterator iterator = plugins.iterator();
    PluginPanel updatePluginPanel = null;
    while (iterator.hasNext()) {
      updatePluginPanel = (PluginPanel) iterator.next();
      updatePluginPanel.updateConnectionStatus(connected);
    }

    if (connected == true) {
      int selected = tabbedPane.getSelectedIndex();
      if (selected >= 2) {
        ((PluginPanel) pluginPanelMap.get("" + selected)).activated();
      }
    }
  }
Ejemplo n.º 2
0
 public void propertyChange(PropertyChangeEvent e) {
   String propertyName = e.getPropertyName();
   if (e.getPropertyName().equals(Action.NAME)) {
     String text = (String) e.getNewValue();
     menuItem.setText(text);
   } else if (propertyName.equals("enabled")) {
     Boolean enabledState = (Boolean) e.getNewValue();
     menuItem.setEnabled(enabledState.booleanValue());
   }
 }
Ejemplo n.º 3
0
 public void actionPerformed(ActionEvent e) {
   JMenuItem jmi = (JMenuItem) e.getSource();
   Iterator marks = mediator.getMarkerModel().getMarkersWithLabel(jmi.getText());
   if (marks.hasNext()) {
     ChronicleMarker marker = (ChronicleMarker) marks.next();
     Instant to = marker.getWhen();
     Instant from = mediator.getMajorMoment();
     viper.api.impl.Util.shiftDescriptors(new Descriptor[] {desc}, from, to);
   }
 }
Ejemplo n.º 4
0
 public void actionPerformed(ActionEvent e) {
   Iterator toInterp = Collections.singleton(desc).iterator();
   JMenuItem jmi = (JMenuItem) e.getSource();
   Iterator marks = mediator.getMarkerModel().getMarkersWithLabel(jmi.getText());
   if (marks.hasNext()) {
     ChronicleMarker marker = (ChronicleMarker) marks.next();
     Instant to = marker.getWhen();
     Instant from = mediator.getMajorMoment();
     mediator.getPropagator().interpolateDescriptors(toInterp, from, to);
   }
 }
Ejemplo n.º 5
0
    public DescPropPopup() {
      super("Descriptor Properties");
      v = new JCheckBoxMenuItem("Valid");
      v.addActionListener(new ValidAction());
      p = new JCheckBoxMenuItem("Propagating");
      p.addActionListener(new PropAction());
      delete = new JMenuItem("Delete");
      delete.addActionListener(new DeleteAction());
      duplicate = new JMenuItem("Duplicate");
      duplicate.addActionListener(new DuplicateAction());
      interp = new JMenuItem("Interpolate...");
      interp.addActionListener(new InterpAction());
      interpToMark = new JMenu("Interpolate to Mark");
      interpToMark.setEnabled(false);
      itmAction = new InterpToMarkAction();
      shift = new JMenuItem("Shift...");
      shift.addActionListener(new ShiftAction());
      shiftToMark = new JMenu("Shift to Mark");
      shiftToMark.setEnabled(false);
      stmAction = new ShiftToMarkAction();

      occlusions = new JMenuItem("Occlusions...");
      occAction = new OccAction();
      occlusions.addActionListener(occAction);
      occSeparator = new JSeparator();

      wrt = new JCheckBoxMenuItem("Display with Respect To", false);
      wrt.addActionListener(new WithRespectToAction());

      add(occlusions);
      add(occSeparator);
      add(v);
      add(p);
      add(occSeparator);
      add(delete);
      add(duplicate);
      add(occSeparator);
      add(interp);
      add(interpToMark);
      add(occSeparator);
      add(shift);
      add(shiftToMark);
      add(occSeparator);
      add(wrt);
    }
Ejemplo n.º 6
0
  private void buildMenu() {
    jMenuBar = new javax.swing.JMenuBar();
    mainMenu = new javax.swing.JMenu();
    mainMenu.setText("Main");

    loginMenuItem = new JMenuItem("Login...");
    loginMenuItem.addActionListener(
        new java.awt.event.ActionListener() {
          public void actionPerformed(java.awt.event.ActionEvent evt) {
            headerPanel.handleLoginLogout();
          }
        });

    mainMenu.add(loginMenuItem);

    exitMenuItem = new JMenuItem("Exit");
    exitMenuItem.addActionListener(
        new java.awt.event.ActionListener() {
          public void actionPerformed(java.awt.event.ActionEvent evt) {
            if (qsadminMain.isConnected() == true) {
              headerPanel.handleLoginLogout();
            }
            System.exit(0);
          }
        });
    mainMenu.add(exitMenuItem);

    helpMenu = new javax.swing.JMenu();
    helpMenu.setText("Help");

    aboutMenuItem = new JMenuItem("About...");
    aboutMenuItem.setEnabled(true);
    aboutMenuItem.addActionListener(
        new java.awt.event.ActionListener() {
          public void actionPerformed(java.awt.event.ActionEvent evt) {
            about();
          }
        });
    helpMenu.add(aboutMenuItem);

    jMenuBar.add(mainMenu);
    jMenuBar.add(helpMenu);

    parentFrame.setJMenuBar(jMenuBar);
  }
 /** 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);
 }
Ejemplo n.º 8
0
 private void resetMarks() {
   interpToMark.removeAll();
   shiftToMark.removeAll();
   Iterator marks = mediator.getMarkerModel().getLabels().iterator();
   boolean hasMark = false;
   while (marks.hasNext()) {
     String mark = (String) marks.next();
     if (!ChronicleViewer.CURR_FRAME_LABEL.equals(mark)) {
       JMenuItem mi = new JMenuItem(mark);
       mi.addActionListener(itmAction);
       interpToMark.add(mi);
       mi = new JMenuItem(mark);
       mi.addActionListener(stmAction);
       shiftToMark.add(mi);
       hasMark = true;
     }
   }
   shiftToMark.setEnabled(hasMark);
   interpToMark.setEnabled(hasMark);
 }
Ejemplo n.º 9
0
    public ConfigEditPopup() {
      super("Config Properties");

      newDescriptor = new JMenuItem("New Descriptor Type");
      newDescriptor.addActionListener(newConfigListener);

      newAttribute = new JMenuItem("New Attribute Type");
      newAttribute.addActionListener(new NewAttributeAction());

      delete = new JMenuItem("Delete");
      delete.addActionListener(new DeleteAction());

      duplicate = new JMenuItem("Duplicate");
      duplicate.addActionListener(new DuplicateAction());

      add(newDescriptor);
      add(newAttribute);
      // add(duplicate);
      add(new JSeparator());
      add(delete);
    }
Ejemplo n.º 10
0
    public void show(Component invoker, int x, int y) {
      ViperViewMediator mediator = getMediator();
      Point pnt = new Point(x, y);
      EnhancedTable tab = getTable();
      int row = tab.rowAtPoint(pnt);
      desc = getCurrentModel().getDescriptorAtRow(row);
      int col = tab.columnAtPoint(pnt);
      Object cellValue = tab.getValueAt(row, col);
      if (cellValue instanceof Attribute) {
        attr = (Attribute) cellValue;

        // hide the "Occlusions..." option when we're not dealing with a Textline object
        boolean isTextline = attr.getAttrConfig().getAttrType().endsWith("textline");
        occlusions.setVisible(isTextline);
        occSeparator.setVisible(isTextline);

        Instant now = mediator.getCurrentFrame();
        if (now == null) {
          mediator.getDisplayWRTManager().setAttribute(null, null);
          wrt.setEnabled(false);
          wrt.setSelected(false);
        } else {
          boolean isDwrt = attr == mediator.getDisplayWRTManager().getAttribute();
          boolean dwrtable =
              (attr.getAttrValueAtInstant(now) instanceof HasCentroid
                  && attr.getDescriptor().getValidRange().contains(now));
          wrt.setEnabled(dwrtable);
          wrt.setSelected(isDwrt);
        }
      } else {
        attr = null;
        wrt.setEnabled(false);
        wrt.setSelected(false);
      }
      if (null != desc) {
        PropagateInterpolateModule proper = getMediator().getPropagator();
        p.setSelected(proper.isPropagatingThis(desc));
        v.setSelected(mediator.isThisValidNow(desc));
        resetMarks();
        super.show(invoker, x, y);
      }
    }
Ejemplo n.º 11
0
 public void show(Component invoker, int x, int y) {
   Object o = getTree().getClosestPathForLocation(x, y).getLastPathComponent();
   if (null != o) {
     node = (Node) o;
     if ((node instanceof AttrConfig) || (node instanceof Config)) {
       newAttribute.setEnabled(true);
       duplicate.setEnabled(true);
       delete.setEnabled(true);
     } else {
       newAttribute.setEnabled(false);
       duplicate.setEnabled(false);
       delete.setEnabled(false);
     }
     super.show(invoker, x, y);
   }
 }
Ejemplo n.º 12
0
 /** This is the hook through which all menu items are created. */
 protected JMenuItem createMenuItem(String cmd) {
   JMenuItem mi = new JMenuItem(getResourceString(cmd + labelSuffix));
   URL url = getResource(cmd + imageSuffix);
   if (url != null) {
     mi.setHorizontalTextPosition(JButton.RIGHT);
     mi.setIcon(new ImageIcon(url));
   }
   String astr = getProperty(cmd + actionSuffix);
   if (astr == null) {
     astr = cmd;
   }
   mi.setActionCommand(astr);
   Action a = getAction(astr);
   if (a != null) {
     mi.addActionListener(a);
     a.addPropertyChangeListener(createActionChangeListener(mi));
     mi.setEnabled(a.isEnabled());
   } else {
     mi.setEnabled(false);
   }
   return mi;
 }
Ejemplo n.º 13
0
  /**
   * Modified "Generated Code". Initialize the GUI Components of the program. THIS PART GETS
   * EXTREMELY CONFUSING.
   */
  @SuppressWarnings("unchecked")
  // <editor-fold defaultstate="collapsed" desc="Bull Excrements Code">
  private void initComponents() {
    // MainFrame = new JFrame();

    sb = new StringBuilder(64);

    sb.append(instructions2());

    MessageLabel = new JLabel(sb.toString());

    MainPanel = new JPanel();
    MainMenuBar = new JMenuBar();
    FileMenu = new JMenu();
    NewGameMenu = new JMenu();
    EasyButton = new JMenuItem();
    MediumButton = new JMenuItem();
    HardButton = new JMenuItem();
    QuitButton = new JMenuItem();
    HelpMenu = new JMenu();

    // frame things -- useless!
    /*
    GroupLayout mainFrameLayout = new GroupLayout(MainFrame.getContentPane());
    MainFrame.getContentPane().setLayout(mainFrameLayout);
    mainFrameLayout.setHorizontalGroup(
        mainFrameLayout.createParallelGroup(GroupLayout.Alignment.LEADING)
        .addGap(0, 400, Short.MAX_VALUE)
    );
    mainFrameLayout.setVerticalGroup(
        mainFrameLayout.createParallelGroup(GroupLayout.Alignment.LEADING)
        .addGap(0, 300, Short.MAX_VALUE)
    );
    */
    setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);

    addMouseListener(
        new MouseAdapter() {
          @Override
          public void mouseReleased(MouseEvent evt) {
            formMouseReleased(evt);
          }
        });
    addKeyListener(
        new KeyAdapter() {
          @Override
          public void keyPressed(KeyEvent evt) {
            formKeyPressed(evt);
          }
        });

    GroupLayout mainPanelLayout = new GroupLayout(MainPanel);
    MainPanel.setLayout(mainPanelLayout);
    mainPanelLayout.setHorizontalGroup(
        mainPanelLayout
            .createParallelGroup(GroupLayout.Alignment.LEADING)
            .addGroup(
                mainPanelLayout
                    .createSequentialGroup()
                    .addGap(40, 60, 80)
                    .addComponent(MessageLabel)
                    .addContainerGap(50, Short.MAX_VALUE)));
    mainPanelLayout.setVerticalGroup(
        mainPanelLayout
            .createParallelGroup(GroupLayout.Alignment.LEADING)
            .addGroup(
                mainPanelLayout
                    .createSequentialGroup()
                    .addGap(54, 54, 54)
                    .addComponent(MessageLabel)
                    .addContainerGap(200, Short.MAX_VALUE)));

    FileMenu.setText("File");
    FileMenu.addMouseListener(
        new MouseAdapter() {
          @Override
          public void mouseClicked(MouseEvent evt) {
            FileMenuMouseClicked(evt);
          }
        });

    NewGameMenu.setText("New Game");

    EasyButton.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F2, 0));
    EasyButton.setText("Easy");
    EasyButton.addMouseListener(
        new MouseAdapter() {
          @Override
          public void mouseReleased(MouseEvent evt) {
            EasyButtonMouseReleased(evt);
          }
        });
    NewGameMenu.add(EasyButton);

    MediumButton.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F3, 0));
    MediumButton.setText("Medium");
    MediumButton.addMouseListener(
        new MouseAdapter() {
          @Override
          public void mouseReleased(MouseEvent evt) {
            MediumButtonMouseReleased(evt);
          }
        });
    NewGameMenu.add(MediumButton);

    HardButton.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F4, 0));
    HardButton.setText("Hard");
    HardButton.addMouseListener(
        new MouseAdapter() {
          @Override
          public void mouseReleased(MouseEvent evt) {
            HardButtonMouseReleased(evt);
          }
        });
    NewGameMenu.add(HardButton);

    FileMenu.add(NewGameMenu);

    QuitButton.setText("Quit");
    QuitButton.addMouseListener(
        new MouseAdapter() {
          @Override
          public void mouseReleased(MouseEvent evt) {
            QuitButtonMouseReleased(evt);
          }
        });
    FileMenu.add(QuitButton);

    MainMenuBar.add(FileMenu);

    HelpMenu.setText("Help");
    MainMenuBar.add(HelpMenu);

    setJMenuBar(MainMenuBar);

    GroupLayout layout = new GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(
        layout
            .createParallelGroup(GroupLayout.Alignment.LEADING)
            .addComponent(
                MainPanel,
                GroupLayout.PREFERRED_SIZE,
                GroupLayout.DEFAULT_SIZE,
                GroupLayout.PREFERRED_SIZE));
    layout.setVerticalGroup(
        layout
            .createParallelGroup(GroupLayout.Alignment.LEADING)
            .addComponent(
                MainPanel,
                GroupLayout.DEFAULT_SIZE,
                GroupLayout.DEFAULT_SIZE,
                GroupLayout.PREFERRED_SIZE));

    // post everything
    this.setTitle("Arcade");

    JLabel label = new JLabel(sb.toString());
    add(label);

    setVisible(true);
    repaint();
    pack();
  } // </editor-fold>
  /** 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) {}
        });
  }