@Override
    public void keyPressed(KeyEvent e) {
        int keyCode = e.getKeyCode();

         if(keyCode == KeyEvent.VK_ENTER){
            final JDialog dialog = new JDialog();
            dialog.setTitle("Search results");
            dialog.setModal(true);
            int height = 40;
            
            dialog.setBounds(0, 0, 300, 500);

            JPanel panel = new JPanel();                     
            ArrayList list = DataLayer.search(zoekBalk.getText());
            panel.setLayout(new GridLayout(list.size(), 1));
            
            if(list.size() == 0){
                JOptionPane.showMessageDialog(null, zoekBalk.getText() + " kon niet gevonden worden/ bestaat niet!", "Niet gevonden", JOptionPane.INFORMATION_MESSAGE);
                //panel.add(new JLabel(zoekBalk.getText() + " kon niet gevonden worden/ bestaat niet!"));
            }else{
                for(int i = 0; i < list.size(); i++){
                    panel.add(new JLabel(list.get(i).toString()));
                    height = height + 20;
                }
                dialog.setPreferredSize(new Dimension(200, height));
                dialog.add(panel);
                dialog.pack();
                dialog.setLocationRelativeTo(null);
                dialog.setVisible(true);
                dialog.validate();
            }
        }
    }
 protected void center(JDialog dialog) {
   GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
   Point center = ge.getCenterPoint();
   int w = dialog.getPreferredSize().width;
   int h = dialog.getPreferredSize().height;
   int x = center.x - w / 2, y = center.y - h / 2;
   dialog.setBounds(x, y, w, h);
   dialog.validate();
 }
Exemple #3
0
  /**
   * Initialise and layout the GUI.
   *
   * @param container The Swing component that will contain the GUI controls.
   */
  @Override
  protected void prepareGUI(Container container) {
    renderer = new SwingBiomorphRenderer();
    console = new SwingConsole(5);
    selectionDialog = new JDialog((JFrame) null, "Biomorph Selection", true);
    biomorphHolder = new JPanel(new GridLayout(1, 1));

    container.add(new ControlPanel(), BorderLayout.WEST);
    container.add(biomorphHolder, BorderLayout.CENTER);
    biomorphHolder.setBorder(BorderFactory.createTitledBorder("Last Evolved Biomorph"));
    biomorphHolder.add(new JLabel("Nothing generated yet.", JLabel.CENTER));
    selectionDialog.add(console, BorderLayout.CENTER);
    selectionDialog.setSize(800, 600);
    selectionDialog.validate();
  }
  @SuppressWarnings("serial")
  public void showCredits() {
    dialog = new JDialog(parent, true);
    dialog.setUndecorated(true);

    final ScrollingLinesPanel panel = new ScrollingLinesPanel(image, lines);
    panel.setBorder(BorderFactory.createLineBorder(UIManager.getColor("Separator.foreground")));

    dialog.add(panel);
    dialog.pack();
    dialog.validate();
    dialog.setPreferredSize(panel.getPreferredSize());
    centerDialogLocation(dialog);

    Action scrollText =
        new AbstractAction() {
          @Override
          public void actionPerformed(ActionEvent e) {
            panel.incrementYPos();
            dialog.repaint();
          }
        };

    timer = new Timer(100, scrollText);

    dialog.addMouseListener(
        new MouseAdapter() {
          @Override
          public void mouseClicked(MouseEvent e) {
            hideCredits();
          }
        });

    Action cancelAction =
        new AbstractAction() {
          @Override
          public void actionPerformed(ActionEvent e) {
            hideCredits();
          }
        };

    LookAndFeelUtil.setDefaultOkCancelKeyStrokes(dialog.getRootPane(), null, cancelAction);

    timer.start();
    dialog.setVisible(true);
  }
    @Override
    public void actionPerformed(ActionEvent e) {
        if (e.getActionCommand().equals("Acties")) {
            controller.add(new Actiescreen());
        }

        if (e.getActionCommand().equals("Editmenu")) {
            JDialog dialog = new JDialog();
            dialog.setBounds(0, 0, 300, 500);

            dialog.add(new EditScreen(1));
            dialog.pack();
            dialog.setLocationRelativeTo(null);
            dialog.setVisible(true);
        }

        if (e.getActionCommand().equals("Kalenderoverzicht")) {
            controller.add(new Kalenderscreen());
        }

        if (e.getActionCommand().equals("Gedachte toevoegen")) {
            JDialog dialog = new JDialog();
            dialog.setTitle("Gedachte Toevoegen");
            dialog.setModal(true);
            dialog.setBounds(0, 0, 300, 500);

            dialog.add(new EditScreen(2));
            dialog.pack();
            dialog.setLocationRelativeTo(null);
            dialog.setVisible(true);
            dialog.validate();
        }

        if (e.getActionCommand().equals("Edit gedachte")) {
            final JDialog dialog = new JDialog();
            dialog.setTitle("Edit gedachte");
            dialog.setModal(true);
            dialog.setBounds(0, 0, 300, 500);

            JPanel panel = new JPanel();
            panel.setLayout(new BorderLayout());
            final JTextField text = new JTextField();
            JButton button = new JButton("Toepassen");
            panel.add(text, BorderLayout.NORTH);
            panel.add(button, BorderLayout.SOUTH);
            button.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent ae) {
                    String change = text.getText();
                    int gedachte = controller.getCurrentThought();
                    DataLayer.changeThought(gedachte, change);
                    dialog.setVisible(false);
                    controller.updateThouhts();
                }
            });

            dialog.add(panel);
            dialog.pack();
            dialog.setLocationRelativeTo(null);
            dialog.setVisible(true);
            dialog.validate();
        }

        if (e.getActionCommand().equals("Gedachte omzetten naar actie")) {
            ArrayList<Projectscreen> test = controller.getProjects();
            if (test.get(0).getList().getSelectedIndex() == -1) {
                JOptionPane.showMessageDialog(null, "Selecteer eerst een gedachte", "Error", JOptionPane.ERROR_MESSAGE);
            } else {
                final JDialog dialog = new JDialog();
                dialog.setPreferredSize(new Dimension(500, 200));
                dialog.setTitle("Gedachte omzetten naar actie");
                dialog.setModal(true);

                JPanel master = new JPanel();
                dialog.add(master);
                master.setLayout(new GridLayout(0, 1));

                // Project kiezen
                JPanel projects = new JPanel();
                projects.setLayout(new BorderLayout());
                JLabel projectnaam = new JLabel("Project");
                final JComboBox box = new JComboBox();
                final ArrayList<Projectscreen> arraylist = controller.getProjects();
                Projectscreen thoughts = arraylist.get(0);
                for (Projectscreen s : arraylist) {
                    if (!s.getNaam().equals("Gedachten")){
                    String naam = s.getNaam();
                    box.addItem(naam);
                    box.validate();
                    }
                }
                projects.add(projectnaam, BorderLayout.WEST);
                projects.add(box, BorderLayout.CENTER);
                master.add(projects);

                //gedachte
                JPanel gedachten = new JPanel();
                gedachten.setLayout(new BorderLayout());
                JLabel n = new JLabel("Gedachte: ");
                final JTextField n1 = new JTextField();
                final int id = controller.getCurrentThought();
                final JList list = thoughts.getList();
                final String s = (String) list.getSelectedValue();
                String[] s1 = s.split(" ");
                String s2 = s1[0];
                n1.setText(s.replaceFirst(s2, ""));
                n1.setText(n1.getText().trim());
                gedachten.add(n, BorderLayout.WEST);
                gedachten.add(n1, BorderLayout.CENTER);
                master.add(gedachten);

                // beschrijving
                JPanel beschrijving = new JPanel();
                beschrijving.setLayout(new BorderLayout());
                JLabel b = new JLabel("Beschrijving");
                final JTextArea b1 = new JTextArea(0, 3);
                b1.setLineWrap(true);
                b1.setRows(3);
                b1.setWrapStyleWord(true);
                b1.setColumns(0);
                JScrollPane scroll = new JScrollPane();
                scroll.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
                scroll.getViewport().setView(b1);
                beschrijving.add(b, BorderLayout.WEST);
                beschrijving.add(scroll, BorderLayout.CENTER);
                master.add(beschrijving);
                
                // context
                
                JPanel context = new JPanel();
                context.setLayout(new BorderLayout());
                JLabel co = new JLabel("Context");
                final JComboBox co1 = new JComboBox();
                co1.setEditable(true);
                final ArrayList<String> co2 = DataLayer.getContexts();
                if (!co2.isEmpty()){
                    for (String t : co2){
                        co1.addItem(t);
                    }
                }
                
                context.add(co, BorderLayout.WEST);
                context.add(co1, BorderLayout.CENTER);
                master.add(context);

                // status
                JPanel status = new JPanel();
                status.setLayout(new BorderLayout());
                JLabel st = new JLabel("Status");
                final JComboBox box1 = new JComboBox();
                ArrayList<String> arrayStatus = DataLayer.getStatuses();
                for (String t : arrayStatus) {
                    box1.addItem(t.toString());
                    box1.validate();
                }
                status.add(st, BorderLayout.WEST);
                status.add(box1, BorderLayout.CENTER);
                master.add(status);

                // datum
                JPanel datum = new JPanel();
                datum.setLayout(new BorderLayout());
                JLabel d = new JLabel("Datum");
                final JFormattedTextField d1 = new JFormattedTextField(new SimpleDateFormat("yyyy-mm-dd"));
                d1.setText("yyyy-mm-dd");
                datum.add(d, BorderLayout.WEST);
                datum.add(d1, BorderLayout.CENTER);
                master.add(datum);

                // button
                JButton toepassen = new JButton("Toepassen");
                master.add(toepassen);
                toepassen.addActionListener(new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent ae) {
                        String description = n1.getText();
                        String notes = b1.getText();
                        
                        String co3 = (String) co1.getSelectedItem();
                        boolean bestaat = false;
                        for (String t : co2){
                            if (t.equals(co3)){
                                bestaat = true;
                            }
                        }
                        
                        if (!bestaat){
                            DataLayer.addContext(co3);
                        }
                        
                        String context = co3;
                        String status = box1.getSelectedItem().toString();
                        int projectid = arraylist.get(box.getSelectedIndex()).getID() + 1;
                        String datum = d1.getText();
                        int idGedachte = Integer.parseInt("" + s.charAt(0)) - 1;

                        if (datum.equals("yyyy-mm-dd") | datum.equals("")) {
                            JOptionPane.showMessageDialog(null, "Vul een datum in", "Error", JOptionPane.ERROR_MESSAGE);
                        } else {
                            DataLayer.addAction(description, notes, context, status, projectid, datum);
                            DataLayer.deleteThought(idGedachte);
                            controller.updateThouhts();
                            controller.updateProjects();
                            dialog.setVisible(false);
                            ArrayList<Projectscreen> project = controller.getProjects();
                            Projectscreen t = project.get(0);
                            int i = t.getList().getModel().getSize();
                            int x = t.getList().getSelectedIndex();
                        }
                    }
                });

                dialog.pack();
                dialog.setLocationRelativeTo(null);
                dialog.setVisible(true);
                dialog.validate();
            }
        }

        if (e.getActionCommand().equals("Wis gedachte")) {
            DataLayer.deleteThought(controller.getCurrentThought());
            controller.updateThouhts();
        }

        if (e.getActionCommand().equals("Voeg project toe")) {
            final JDialog dialog = new JDialog();
            dialog.setTitle("Project toevoegen");
            dialog.setModal(true);

            JPanel panel = new JPanel();
            panel.setLayout(new BorderLayout());
            final JTextField naam = new JTextField();

            JPanel projectnaam = new JPanel();
            projectnaam.setLayout(new BorderLayout());
            projectnaam.add(new JLabel("Projectnaam"), BorderLayout.WEST);
            projectnaam.add(naam, BorderLayout.CENTER);

            JButton button = new JButton("Aanmaken");
            panel.add(projectnaam, BorderLayout.NORTH);
            panel.add(button, BorderLayout.SOUTH);
            button.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent ae) {
                    String e = DataLayer.addProject(naam.getText());
                    controller.updateProjects(e);
                    dialog.setVisible(false);
                    validate();
                }
            });

            dialog.add(panel);
            dialog.pack();
            dialog.setLocationRelativeTo(null);
            dialog.setVisible(true);
            dialog.validate();
        }

        if (e.getActionCommand().equals("Bewerk project")) {
            final JDialog dialog = new JDialog();
            dialog.setTitle("Bewerk project");
            dialog.setModal(true);
            dialog.setBounds(0, 0, 300, 500);

            JPanel panel = new JPanel();
            panel.setLayout(new BorderLayout());
            final JTextField naam = new JTextField();
            final JComboBox box = new JComboBox();
            box.setEditable(false);
            final ArrayList<Projectscreen> projects = controller.getProjects();
            projects.remove(0);
            for (Projectscreen t : projects) {
                box.addItem(t.getNaam());
                box.validate();
            }

            JPanel projectid = new JPanel();
            projectid.setLayout(new BorderLayout());
            projectid.add(new JLabel("Kies project"), BorderLayout.WEST);
            projectid.add(box, BorderLayout.CENTER);

            JPanel projectnaam = new JPanel();
            projectnaam.setLayout(new BorderLayout());
            projectnaam.add(new JLabel("Nieuwe projectnaam"), BorderLayout.WEST);
            projectnaam.add(naam, BorderLayout.CENTER);

            JButton button = new JButton("Bewerk");
            panel.add(projectid, BorderLayout.NORTH);
            panel.add(projectnaam, BorderLayout.CENTER);
            panel.add(button, BorderLayout.SOUTH);
            button.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent ae) {
                    int d = box.getSelectedIndex();
                    projects.get(d).changeName(naam.getText());
                    DataLayer.changeProject(projects.get(d).getID(), naam.getText());
                    dialog.setVisible(false);
                    validate();
                }
            });

            dialog.add(panel);
            dialog.pack();
            dialog.setLocationRelativeTo(null);
            dialog.setVisible(true);
            dialog.validate();
        }

        if (e.getActionCommand().equals("Verwijder project")) {
            final JDialog dialog = new JDialog();
            dialog.setTitle("Wis project");
            dialog.setModal(true);
            dialog.setBounds(0, 0, 300, 500);

            JPanel panel = new JPanel();
            panel.setLayout(new BorderLayout());
            final JTextField naam = new JTextField();

            final JComboBox box = new JComboBox();
            box.setEditable(false);
            final ArrayList<Projectscreen> projects = controller.getProjects();
            projects.remove(0);
            for (Projectscreen t : projects) {
                box.addItem(t.getNaam());
                box.validate();
            }

            JPanel projectnaam = new JPanel();
            projectnaam.setLayout(new BorderLayout());
            projectnaam.add(new JLabel("Project"), BorderLayout.WEST);
            projectnaam.add(box, BorderLayout.CENTER);

            JButton button = new JButton("Wissen");
            panel.add(projectnaam, BorderLayout.NORTH);
            panel.add(button, BorderLayout.SOUTH);
            button.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent ae) {
                    //pj.deleteProject(naam.getText(), id.getNumber().intValue()); 
                    int d = box.getSelectedIndex();
                    projects.get(d).changeName(naam.getText());
                    DataLayer.deleteProject(projects.get(d).getID());
                    controller.updateIDprojects(d);
                    dialog.setVisible(false);
                    validate();
                }
            });

            dialog.add(panel);
            dialog.pack();
            dialog.setLocationRelativeTo(null);
            dialog.setVisible(true);
            dialog.validate();
        }

        if (e.getActionCommand().equals("Uitloggen")) {
            controller.logOff();
        }

        if (e.getActionCommand().equals("Afsluiten")) {
            controller.quit();
        }
    }
 @Override
 protected void validateTree() {
   super.validateTree();
   if (target instanceof JFrame) ((JFrame) target).getRootPane().validate();
   else if (target instanceof JDialog) ((JDialog) target).getRootPane().validate();
 }
  /** Create the ViewKeys frame. */
  public ViewKeys(JFrame homeFrame, String keypairDescription) {

    final JDialog viewGeneratedKeysFrame = new JDialog(homeFrame, "Generated RSA Key Pair", true);

    KeypairPOJO keypair = null;
    final KeypairPOJO finalKeypair;

    JPanel parentPanel = new JPanel(new BorderLayout());
    JPanel textAreaPanel = new JPanel(new BorderLayout());
    JPanel buttonsPanel = new JPanel();
    buttonsPanel.setLayout(new GridLayout(1, 3, 10, 0));

    JTextArea keyPairtextArea = new JTextArea(20, 70);
    keyPairtextArea.setEditable(false);
    // keyPairtextArea.setEnabled(false);
    keyPairtextArea.setLineWrap(true);

    ArrayList<KeypairPOJO> registeredKeypairs = null;
    try {
      registeredKeypairs = KeypairDAO.getKeypairs();
    } catch (Exception e) {
      e.printStackTrace();
    }

    if (keypairDescription == null) {
      if (registeredKeypairs.isEmpty()) {
        JOptionPane.showMessageDialog(
            null, "There are no keypairs registered.", "Notice", JOptionPane.INFORMATION_MESSAGE);
      } else {
        keypair = registeredKeypairs.get(registeredKeypairs.size() - 1);
        keyPairtextArea.setText(
            "-----BEGIN RSA PUBLIC KEY-----\n"
                + "Public Exponent: "
                + keypair.getPublicExponent()
                + "\n"
                + "Modulus: "
                + keypair.getModulus()
                + "\n"
                + "-----END RSA PUBLIC KEY-----\n"
                + "-----BEGIN RSA PRIVATE KEY-----\n"
                + "Private Exponent: "
                + keypair.getPrivateExponent()
                + "\n"
                + "Modulus: "
                + keypair.getModulus()
                + "\n"
                + "-----END RSA PRIVATE KEY-----");
      }
    } else {
      try {
        keypair = KeypairDAO.getKeypairByDescription(keypairDescription);

        keyPairtextArea.setText(
            "-----BEGIN RSA PUBLIC KEY-----\n"
                + "Public Exponent: "
                + keypair.getPublicExponent()
                + "\n"
                + "Modulus: "
                + keypair.getModulus()
                + "\n"
                + "-----END RSA PUBLIC KEY-----\n"
                + "-----BEGIN RSA PRIVATE KEY-----\n"
                + "Private Exponent: "
                + keypair.getPrivateExponent()
                + "\n"
                + "Modulus: "
                + keypair.getModulus()
                + "\n"
                + "-----END RSA PRIVATE KEY-----");
      } catch (Exception e) {
        e.printStackTrace();
      }
    }

    finalKeypair = keypair;
    keyPairtextArea.addMouseListener(new PopUpMenuClickListener(keyPairtextArea));
    textAreaPanel.add(keyPairtextArea);

    JButton exportKeyPairToFileButton = new JButton("Export to file");
    exportKeyPairToFileButton.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent evt) {
            ExportKey.exportToFileAsPlainText(finalKeypair, viewGeneratedKeysFrame);
          }
        });

    JButton purgeKeyPairButton = new JButton("Purge key pair");
    purgeKeyPairButton.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent evt) {
            try {
              KeypairDAO.deleteKeypair(finalKeypair);
              viewGeneratedKeysFrame.dispose();
            } catch (Exception e) {
              e.printStackTrace();
            }
          }
        });

    JButton cancelButton = new JButton("Cancel");
    cancelButton.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent evt) {
            viewGeneratedKeysFrame.dispose();
          }
        });

    buttonsPanel.add(exportKeyPairToFileButton);
    buttonsPanel.add(purgeKeyPairButton);
    buttonsPanel.add(cancelButton);

    // parentPanel.add(headerPanel, BorderLayout.NORTH);
    parentPanel.add(textAreaPanel, BorderLayout.CENTER);
    parentPanel.add(buttonsPanel, BorderLayout.SOUTH);
    viewGeneratedKeysFrame.setContentPane(parentPanel);
    viewGeneratedKeysFrame.pack();
    viewGeneratedKeysFrame.validate();
    viewGeneratedKeysFrame.setResizable(true);
    viewGeneratedKeysFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    viewGeneratedKeysFrame.setLocationRelativeTo(null);
    viewGeneratedKeysFrame.setVisible(true);
  }
Exemple #8
0
  public Login(JFrame dialogOwner) {
    login = new JDialog(dialogOwner, "LOGIN", true);
    login.setSize(290, 150);
    login.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
    login.setLayout(null);
    login.getContentPane().setBackground(Color.white);

    lblUeberschrift = new JLabel("Login to BigOne");
    lblUeberschrift.setBounds(10, 10, 270, 25);

    lblName = new JLabel("Username");
    lblName.setBounds(10, 40, 100, 25);

    lblPW = new JLabel("Password");
    lblPW.setBounds(10, 70, 100, 25);

    txtBenutzer = new JTextField();
    txtBenutzer.setBounds(120, 40, 120, 25);
    // txtBenutzer.setText("");

    txtPW = new JPasswordField("");
    txtPW.setBounds(120, 70, 120, 25);
    // txtPW.setText("");

    btnLogin = new JButton("Login");
    btnLogin.setBounds(100, 100, 90, 25);
    btnLogin.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {

            // zuweisung der Textfeldwerte an die lokalen Varablen
            strB = txtBenutzer.getText();
            strPW = new String(txtPW.getPassword());

            try {
              // Select fitting database driver and connect:
              Class.forName(strDbDrv);
              cn = DriverManager.getConnection(strDbUrl + strDatabase, strB, strPW);
              login.dispose();
            } catch (Exception ex) {
              // ausnahme beschreibung auf der konsole ausgeben
              txtPW.setText("");
              txtPW.requestFocus();
              Logincount++;
              if (Logincount == 3) {
                JOptionPane.showMessageDialog(
                    null,
                    "maximale Anzahl der Loginversuche überschritten",
                    "Achtung",
                    JOptionPane.INFORMATION_MESSAGE);
                login.dispose();
              }
              // System.out.println(ex.toString());
            }
          }
        });

    login.add(lblUeberschrift);
    login.add(lblName);
    login.add(lblPW);
    login.add(txtBenutzer);
    login.add(txtPW);
    login.add(btnLogin);
    login.validate();
    login.repaint();
    login.setVisible(true);

    txtBenutzer.requestFocus();
  }