Example #1
0
 private void validatePlayable() {
   if (!instance.isPlayable()) {
     for (ActionListener al : playButton.getActionListeners()) {
       playButton.removeActionListener(al);
     }
     playButton.addActionListener(
         new ActionListener() {
           public void actionPerformed(ActionEvent e) {
             String[] options = {Language.INSTANCE.localize("common.ok")};
             JOptionPane.showOptionDialog(
                 App.settings.getParent(),
                 Language.INSTANCE.localize("instance" + "" + ".corruptplay"),
                 Language.INSTANCE.localize("instance.corrupt"),
                 JOptionPane.DEFAULT_OPTION,
                 JOptionPane.ERROR_MESSAGE,
                 null,
                 options,
                 options[0]);
           }
         });
     for (ActionListener al : backupButton.getActionListeners()) {
       backupButton.removeActionListener(al);
     }
     backupButton.addActionListener(
         new ActionListener() {
           public void actionPerformed(ActionEvent e) {
             String[] options = {Language.INSTANCE.localize("common.ok")};
             JOptionPane.showOptionDialog(
                 App.settings.getParent(),
                 Language.INSTANCE.localize("instance" + "" + ".corruptbackup"),
                 Language.INSTANCE.localize("instance.corrupt"),
                 JOptionPane.DEFAULT_OPTION,
                 JOptionPane.ERROR_MESSAGE,
                 null,
                 options,
                 options[0]);
           }
         });
     for (ActionListener al : cloneButton.getActionListeners()) {
       cloneButton.removeActionListener(al);
     }
     cloneButton.addActionListener(
         new ActionListener() {
           public void actionPerformed(ActionEvent e) {
             String[] options = {Language.INSTANCE.localize("common.ok")};
             JOptionPane.showOptionDialog(
                 App.settings.getParent(),
                 Language.INSTANCE.localize("instance" + "" + ".corruptclone"),
                 Language.INSTANCE.localize("instance.corrupt"),
                 JOptionPane.DEFAULT_OPTION,
                 JOptionPane.ERROR_MESSAGE,
                 null,
                 options,
                 options[0]);
           }
         });
   }
 }
Example #2
0
 /** Sets the enabled flag of the {@link #login} button. */
 private void enableControls() {
   boolean enabled = true;
   String s = serverText.getText();
   char[] name = pass.getPassword();
   String usr = user.getText().trim();
   if (CommonsLangUtils.isBlank(s) || CommonsLangUtils.isBlank(usr)) {
     enabled = false;
   } else {
     s = s.trim();
     if (DEFAULT_SERVER.equals(s)) {
       enabled = false;
     }
   }
   login.setEnabled(enabled);
   if (enabled) {
     ActionListener[] listeners = login.getActionListeners();
     if (listeners != null) {
       boolean set = false;
       for (int i = 0; i < listeners.length; i++) {
         if (listeners[i] == this) {
           set = true;
           break;
         }
       }
       if (!set) login.addActionListener(this);
     }
     login.setForeground(defaultForeground);
   } else {
     login.setForeground(FOREGROUND_COLOR);
   }
   layout(hasGroupOption());
 }
  @Test
  public void testBindPresenter() {

    presenter = new PresenterObject();
    model = new ModelObject();
    ViewObject view = new ViewObject();
    appController.bindPresenter(view, presenter);
    // The test on JButton binding with the presenter
    JButton okButton = view.getOkButton();
    Assert.assertTrue(okButton.getActionListeners().length != 0);
    okButton.doClick();
    // The test on JmenuItem binding with the presenter
    JMenuItem menuItem = view.getJmenuitem();
    Assert.assertTrue(menuItem.getActionListeners().length != 0);
    menuItem.doClick();
  }
 /**
  * Tests the <code>setCollapseButton(JButton)</code> for proper behavior. Verifies that field is
  * set, action listener should be removed, container is updated, property change event is fired.
  *
  * @throws Exception to JUnit
  */
 public void testMethodSetCollapseButton_JButton() throws Exception {
   JButton button = new JButton();
   JButton oldButton =
       (JButton)
           TestHelper.getPrivateField(
               DefaultExpandedSideMenuPanel.class, target, "collapseButton");
   target.setCollapseButton(button);
   // check field
   assertEquals("CollapseButton", button, target.getCollapseButton());
   // check old button
   assertEquals("action listener should be removed.", 0, oldButton.getActionListeners().length);
   PropertyChangeEvent event = listener.getEvent();
   TestHelper.assertEvent(event, DefaultExpandedSideMenuPanel.COLLAPSE_BUTTON, oldButton, button);
   // check container
   assertEquals("only 4 components there should be.", 4, target.getComponentCount());
   assertEquals("content", button, target.getComponents()[3]);
 }
Example #5
0
 private void drawHelpButton() {
   // BEGIN OF HELP BUTTON ***********************************************
   help_button_.setBounds(682, 5, 255, 28);
   help_button_.setBackground(new Color(127, 127, 127));
   help_button_.setForeground(Color.ORANGE);
   help_button_.setText("Hilfe");
   if (help_button_.getActionListeners().length == 0) {
     help_button_.addActionListener(
         new java.awt.event.ActionListener() {
           public void actionPerformed(java.awt.event.ActionEvent evt) {
             simulation_control_.printHelp();
             // SqlCommunicator.add_log("Help button pressed");
             // HelpWindow help_window=new HelpWindow(getCodeBase());
           }
         });
   }
   // END OF HELP BUTTON **************************************************
 }
Example #6
0
 private void drawNewRuleButton() {
   // BEGIN OF NEW RULE BUTTON *******************************************
   new_rule_button_.setBounds(5, 5, 248, 28);
   new_rule_button_.setBackground(new Color(127, 127, 127));
   new_rule_button_.setForeground(Color.ORANGE);
   new_rule_button_.setText("Regel hinzufügen");
   if (new_rule_button_.getActionListeners().length == 0) {
     new_rule_button_.addActionListener(
         new java.awt.event.ActionListener() {
           public void actionPerformed(java.awt.event.ActionEvent evt) { // Load rules
             // button
             // pressed
             simulation_control_.addEmptyRule();
           }
         });
   }
   // END OF NEW RULE BUTTON
   // **************************************************
 }
Example #7
0
  public void removeListeners() {

    for (JButton[] panel : spaces) {
      for (int i = 0; i < panel.length; i++) {
        Component[] camps = panel[i].getComponents();
        Component comp = null;
        for (int j = 0; j < camps.length; j++) {
          comp = camps[j];
          if (comp instanceof JButton) {
            JButton jb = (JButton) (camps[j]);
            ActionListener[] lastnrs = jb.getActionListeners();
            for (int k = 0; k < lastnrs.length; k++) {
              jb.removeActionListener(lastnrs[k]);
            }
          }
        }
      }
    }
  }
  public void query(String query) throws IOException {
    EntrySet data;
    try {
      data = DatabaseService.getConnection().query(query);
    } catch (QueryException e) {
      e.printStackTrace();
      JOptionPane.showMessageDialog(
          Main.MAIN_FRAME, e.getMessage(), "Error Querying", JOptionPane.ERROR_MESSAGE);
      return;
    }

    removeAll();
    mainPanel.removeAll();
    toolbarPanel.removeAll();
    jtable = new JTable(new DataTableModel(data));
    jtable.setDefaultRenderer(Object.class, new DataTableRenderer());
    DataTableModel model = (DataTableModel) jtable.getModel();

    for (Entry entry : data.getEntries()) {
      model.addRow(entry.getData());
    }

    jtable.addMouseListener(new RowSelectionPopupListener(jtable, data));
    jtable
        .getModel()
        .addTableModelListener(
            new TableModelListener() {
              @Override
              public void tableChanged(TableModelEvent e) {
                if (!ignoreChanges) {
                  if (e.getType() == TableModelEvent.UPDATE) {
                    ignoreChanges = true;
                    int row = e.getLastRow();

                    if (row < data.size()) {
                      Entry entry = data.getEntries()[row];
                      Change change =
                          new Change(
                              entry.getEntryID(), Change.SET, new ArrayList<>(), new ArrayList<>());
                      Change previous = ChangeService.getService().getChange(entry.getEntryID());
                      if (previous != null) {
                        change.setOriginalData(previous.getOriginalData());
                      } else {
                        change.setOriginalData(new ArrayList<>(Arrays.asList(entry.getData())));
                      }

                      for (int col = 0; col < jtable.getColumnCount(); col++) {
                        change.getData().add((Serializable) jtable.getValueAt(row, col));
                      }

                      model.setRowColor(row, Color.orange);
                      ChangeService.getService().change(change);
                      setCanCommit(true);
                      ignoreChanges = false;
                    } else {
                      JOptionPane.showMessageDialog(
                          Main.MAIN_FRAME,
                          "You must commit this entry before editing it.",
                          "Error Editing",
                          JOptionPane.WARNING_MESSAGE);
                    }
                  }
                }
              }
            });

    JButton queryButton = new JButton("Query");
    queryField.setText(lastQuery);
    AutoCompleteDocument auto = new AutoCompleteDocument(queryField, data);

    queryField.getDocument().addDocumentListener(auto);
    queryField.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_CONTROL, 0), "autocomplete");
    queryField.getActionMap().put("autocomplete", auto.getAutocompleteAction());
    mainPanel.add(queryField, 0, 0);
    mainPanel.c.anchor = GridBagConstraints.NORTHEAST;
    mainPanel.add(queryButton, 0, 0);

    queryButton.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            if (canCommit) {
              if (JOptionPane.showConfirmDialog(
                      Main.MAIN_FRAME,
                      "Requerying the table will remove your uncommited changes. Continue?",
                      "Discard Uncommited Changes?",
                      JOptionPane.YES_NO_CANCEL_OPTION)
                  != JOptionPane.YES_OPTION) {
                return;
              }
            }
            ChangeService.getService().setChanges(new ArrayList<>());
            setCanCommit(false);

            try {
              lastQuery = queryField.getText();
              DatabaseService.getConnection()
                  .query(queryField.getText() + " IN " + DatabaseService.getCurrentTableName());
              query(lastQuery.toLowerCase().startsWith("get") ? lastQuery : "GET");
            } catch (QueryException e1) {
              JOptionPane.showMessageDialog(
                  Main.MAIN_FRAME, e1.getMessage(), "Error Querying", JOptionPane.ERROR_MESSAGE);
            } catch (IOException e1) {
              e1.printStackTrace();
            }
            return;
          }
        });

    if (commitButton.getActionListeners().length > 0) {
      commitButton.removeActionListener(commitButton.getActionListeners()[0]);
    }
    commitButton.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            CommitChangesWindow window = new CommitChangesWindow(data);
            window.open();
          }
        });
    JButton addButton = new JButton(new ImageIcon("assets/GreenPlus.png"));
    addButton.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            AddEntryWindow window = new AddEntryWindow(data);
            window.open();
          }
        });

    canCommit = false;
    commitButton.setEnabled(false);
    toolbarPanel.add(addButton, 0, 0);
    toolbarPanel.add(commitButton, 0, 1);

    addButton.setToolTipText("Add Entry");
    commitButton.setToolTipText("Commit Changes");

    mainPanel.c.anchor = GridBagConstraints.NORTHWEST;
    mainPanel.add(status, 0, 1);
    mainPanel.add(new JScrollPane(jtable), 0, 2);

    add(toolbarPanel);
    add(mainPanel);
    Main.MAIN_FRAME.pack();

    Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
    Main.MAIN_FRAME.setLocation(
        dim.width / 2 - Main.MAIN_FRAME.getSize().width / 2,
        dim.height / 2 - Main.MAIN_FRAME.getSize().height / 2);
  }
Example #9
0
  public UpdaterFrame(final FilesCollection files) {
    super("ImageJ Updater");
    setPreferredSize(new Dimension(780, 560));

    this.files = files;

    setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
    addWindowListener(
        new WindowAdapter() {

          @Override
          public void windowClosing(final WindowEvent e) {
            quit();
          }
        });

    // ======== Start: LEFT PANEL ========
    final JPanel leftPanel = new JPanel();
    final GridBagLayout gb = new GridBagLayout();
    leftPanel.setLayout(gb);
    final GridBagConstraints c =
        new GridBagConstraints(
            0,
            0, // x, y
            9,
            1, // rows, cols
            0,
            0, // weightx, weighty
            GridBagConstraints.NORTHWEST, // anchor
            GridBagConstraints.HORIZONTAL, // fill
            new Insets(0, 0, 0, 0),
            0,
            0); // ipadx, ipady

    searchTerm = new JTextField();
    searchTerm
        .getDocument()
        .addDocumentListener(
            new DocumentListener() {

              @Override
              public void changedUpdate(final DocumentEvent e) {
                updateFilesTable();
              }

              @Override
              public void removeUpdate(final DocumentEvent e) {
                updateFilesTable();
              }

              @Override
              public void insertUpdate(final DocumentEvent e) {
                updateFilesTable();
              }
            });
    searchPanel = SwingTools.labelComponentRigid("Search:", searchTerm);
    gb.setConstraints(searchPanel, c);
    leftPanel.add(searchPanel);

    Component box = Box.createRigidArea(new Dimension(0, 10));
    c.gridy = 1;
    gb.setConstraints(box, c);
    leftPanel.add(box);

    viewOptions = new ViewOptions();
    viewOptions.addActionListener(
        new ActionListener() {

          @Override
          public void actionPerformed(final ActionEvent e) {
            updateFilesTable();
          }
        });

    viewOptionsPanel = SwingTools.labelComponentRigid("View Options:", viewOptions);
    c.gridy = 2;
    gb.setConstraints(viewOptionsPanel, c);
    leftPanel.add(viewOptionsPanel);

    box = Box.createRigidArea(new Dimension(0, 10));
    c.gridy = 3;
    gb.setConstraints(box, c);
    leftPanel.add(box);

    // Create labels to annotate table
    chooseLabel = SwingTools.label("Please choose what you want to install/uninstall:", null);
    c.gridy = 4;
    gb.setConstraints(chooseLabel, c);
    leftPanel.add(chooseLabel);

    box = Box.createRigidArea(new Dimension(0, 5));
    c.gridy = 5;
    gb.setConstraints(box, c);
    leftPanel.add(box);

    // Label text for file summaries
    fileSummary = new JLabel();
    summaryPanel = SwingTools.horizontalPanel();
    summaryPanel.add(fileSummary);
    summaryPanel.add(Box.createHorizontalGlue());

    // Create the file table and set up its scrollpane
    table = new FileTable(this);
    table.getSelectionModel().addListSelectionListener(this);
    final JScrollPane fileListScrollpane = new JScrollPane(table);
    fileListScrollpane.getViewport().setBackground(table.getBackground());

    c.gridy = 6;
    c.weightx = 1;
    c.weighty = 1;
    c.fill = GridBagConstraints.BOTH;
    gb.setConstraints(fileListScrollpane, c);
    leftPanel.add(fileListScrollpane);

    box = Box.createRigidArea(new Dimension(0, 5));
    c.gridy = 7;
    c.weightx = 0;
    c.weighty = 0;
    c.fill = GridBagConstraints.HORIZONTAL;
    gb.setConstraints(box, c);
    leftPanel.add(box);

    // ======== End: LEFT PANEL ========

    // ======== Start: RIGHT PANEL ========
    rightPanel = SwingTools.verticalPanel();

    rightPanel.add(Box.createVerticalGlue());

    fileDetails = new FileDetails(this);
    SwingTools.tab(fileDetails, "Details", "Individual file information", 350, 315, rightPanel);
    // TODO: put this into SwingTools, too
    rightPanel.add(Box.createRigidArea(new Dimension(0, 25)));
    // ======== End: RIGHT PANEL ========

    // ======== Start: TOP PANEL (LEFT + RIGHT) ========
    final JPanel topPanel = SwingTools.horizontalPanel();
    topPanel.add(leftPanel);
    topPanel.add(Box.createRigidArea(new Dimension(15, 0)));
    topPanel.add(rightPanel);
    topPanel.setBorder(BorderFactory.createEmptyBorder(20, 15, 5, 15));
    // ======== End: TOP PANEL (LEFT + RIGHT) ========

    // ======== Start: BOTTOM PANEL ========
    final JPanel bottomPanel2 = SwingTools.horizontalPanel();
    final JPanel bottomPanel = SwingTools.horizontalPanel();
    bottomPanel.setBorder(BorderFactory.createEmptyBorder(5, 15, 15, 15));
    bottomPanel.add(new FileAction("Keep as-is", null));
    bottomPanel.add(Box.createRigidArea(new Dimension(15, 0)));
    bottomPanel.add(new FileAction("Install", Action.INSTALL, "Update", Action.UPDATE));
    bottomPanel.add(Box.createRigidArea(new Dimension(15, 0)));
    bottomPanel.add(new FileAction("Uninstall", Action.UNINSTALL));

    bottomPanel.add(Box.createHorizontalGlue());

    // Button to start actions
    apply =
        SwingTools.button(
            "Apply changes",
            "Start installing/uninstalling files",
            new ActionListener() {

              @Override
              public void actionPerformed(final ActionEvent e) {
                applyChanges();
              }
            },
            bottomPanel);
    apply.setEnabled(files.hasChanges());

    // Manage update sites
    updateSites =
        SwingTools.button(
            "Manage update sites",
            "Manage multiple update sites for updating and uploading",
            new ActionListener() {

              @Override
              public void actionPerformed(final ActionEvent e) {
                new SitesDialog(
                        UpdaterFrame.this,
                        UpdaterFrame.this.files,
                        UpdaterFrame.this.files.hasUploadableSites())
                    .setVisible(true);
              }
            },
            bottomPanel2);

    // TODO: unify upload & apply changes (probably apply changes first, then
    // upload)
    // includes button to upload to server if is a Developer using
    bottomPanel2.add(Box.createRigidArea(new Dimension(15, 0)));
    upload =
        SwingTools.button(
            "Upload to server",
            "Upload selected files to server",
            new ActionListener() {

              @Override
              public void actionPerformed(final ActionEvent e) {
                new Thread() {

                  @Override
                  public void run() {
                    try {
                      upload();
                    } catch (final InstantiationException e) {
                      Log.error(e);
                      error("Could not upload (possibly unknown protocol)");
                    }
                  }
                }.start();
              }
            },
            bottomPanel2);
    upload.setVisible(files.hasUploadableSites());
    enableUploadOrNot();

    final IJ1Plugin fileChanges = IJ1Plugin.discover("fiji.scripting.ShowPluginChanges");
    if (fileChanges != null && files.prefix(".git").isDirectory()) {
      bottomPanel2.add(Box.createRigidArea(new Dimension(15, 0)));
      showChanges =
          SwingTools.button(
              "Show changes",
              "Show the changes in Git since the last upload",
              new ActionListener() {

                @Override
                public void actionPerformed(final ActionEvent e) {
                  new Thread() {

                    @Override
                    public void run() {
                      for (final FileObject file : table.getSelectedFiles())
                        fileChanges.run(file.filename);
                    }
                  }.start();
                }
              },
              bottomPanel2);
    }
    final IJ1Plugin rebuild = IJ1Plugin.discover("fiji.scripting.RunFijiBuild");
    if (rebuild != null && files.prefix(".git").isDirectory()) {
      bottomPanel2.add(Box.createRigidArea(new Dimension(15, 0)));
      rebuildButton =
          SwingTools.button(
              "Rebuild",
              "Rebuild using Fiji Build",
              new ActionListener() {

                @Override
                public void actionPerformed(final ActionEvent e) {
                  new Thread() {

                    @Override
                    public void run() {
                      String list = "";
                      final List<String> names = new ArrayList<String>();
                      for (final FileObject file : table.getSelectedFiles()) {
                        list += ("".equals(list) ? "" : " ") + file.filename + "-rebuild";
                        names.add(file.filename);
                      }
                      if (!"".equals(list)) rebuild.run(list);
                      final Checksummer checksummer =
                          new Checksummer(files, getProgress("Checksumming rebuilt files"));
                      checksummer.updateFromLocal(names);
                      filesChanged();
                      updateFilesTable();
                    }
                  }.start();
                }
              },
              bottomPanel2);
    }

    bottomPanel2.add(Box.createHorizontalGlue());

    bottomPanel.add(Box.createRigidArea(new Dimension(15, 0)));
    easy =
        SwingTools.button(
            "Toggle easy mode",
            "Toggle between easy and verbose mode",
            new ActionListener() {

              @Override
              public void actionPerformed(final ActionEvent e) {
                toggleEasyMode();
              }
            },
            bottomPanel);

    bottomPanel.add(Box.createRigidArea(new Dimension(15, 0)));
    cancel =
        SwingTools.button(
            "Close",
            "Exit Update Manager",
            new ActionListener() {

              @Override
              public void actionPerformed(final ActionEvent e) {
                quit();
              }
            },
            bottomPanel);
    // ======== End: BOTTOM PANEL ========

    getContentPane().setLayout(new BoxLayout(getContentPane(), BoxLayout.Y_AXIS));
    getContentPane().add(topPanel);
    getContentPane().add(summaryPanel);
    getContentPane().add(bottomPanel);
    getContentPane().add(bottomPanel2);

    getRootPane().setDefaultButton(apply);

    table.getModel().addTableModelListener(this);

    pack();

    SwingTools.addAccelerator(
        cancel,
        (JComponent) getContentPane(),
        cancel.getActionListeners()[0],
        KeyEvent.VK_ESCAPE,
        0);

    addCustomViewOptions();
  }
 /**
  * Removes all action listeners from a button. TODO consider moving this out, or starting own
  * JButton subclass.
  */
 public void removeAllActionListener(JButton button) {
   for (ActionListener al : button.getActionListeners()) {
     button.removeActionListener(al);
   }
 }