示例#1
0
  public MenuPainel() {

    try {
      i = ImageIO.read(new File("21.jpg"));
    } catch (IOException e) {
      System.out.println(e.getMessage());
      System.exit(1);
    }

    this.setLayout(null);

    JButton newgame = new JButton("Iniciar Jogo");
    newgame.setBounds(20, 240, 200, 30);
    newgame.setName("NovoJogo");
    newgame.addMouseListener(tt);

    JButton rules = new JButton("Regras");
    rules.setBounds(20, 280, 200, 30);
    rules.setName("Regras");
    rules.addMouseListener(tt);

    JButton exit = new JButton("Sair");
    exit.setBounds(20, 320, 200, 30);
    exit.setName("Sair");
    exit.addMouseListener(tt);

    this.add(newgame);
    this.add(rules);
    this.add(exit);
  }
  @Override
  public ButtonPanel createButtonPanel() {
    ButtonPanel buttonPanel = new ButtonPanel();
    JButton okButton = new JButton();
    JButton cancelButton = new JButton();
    JButton helpButton = new JButton();
    okButton.setName(OK);
    cancelButton.setName(CANCEL);
    helpButton.setName(HELP);
    buttonPanel.addButton(okButton, ButtonPanel.AFFIRMATIVE_BUTTON);
    buttonPanel.addButton(cancelButton, ButtonPanel.CANCEL_BUTTON);
    buttonPanel.addButton(helpButton, ButtonPanel.HELP_BUTTON);

    okButton.setAction(
        new AbstractAction(UIDefaultsLookup.getString("OptionPane.okButtonText")) {
          public void actionPerformed(ActionEvent e) {
            setDialogResult(RESULT_AFFIRMED);
            setVisible(false);
            dispose();
          }
        });
    cancelButton.setAction(
        new AbstractAction(UIDefaultsLookup.getString("OptionPane.cancelButtonText")) {
          public void actionPerformed(ActionEvent e) {
            setDialogResult(RESULT_CANCELLED);
            setVisible(false);
            dispose();
          }
        });
    final ResourceBundle resourceBundle = ButtonResources.getResourceBundle(Locale.getDefault());
    helpButton.setAction(
        new AbstractAction(resourceBundle.getString("Button.help")) {
          public void actionPerformed(ActionEvent e) {
            // do something
          }
        });
    helpButton.setMnemonic(resourceBundle.getString("Button.help.mnemonic").charAt(0));

    setDefaultCancelAction(cancelButton.getAction());
    setDefaultAction(okButton.getAction());
    getRootPane().setDefaultButton(okButton);
    buttonPanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
    return buttonPanel;
  }
示例#3
0
 /* create a new button and add the respective coordinates */
 public void createNewButton(int x, int y) {
   this.x = x; // Autoboxing!
   this.y = y;
   button = new JButton();
   button.setPreferredSize(new Dimension(20, 20));
   // for leftclicks
   button.setActionCommand(this.x.toString() + " " + this.y.toString());
   // for rightclicks
   button.setName(this.x.toString() + " " + this.y.toString());
 }
示例#4
0
  private JButton submitButton(final JTextField textField) {
    @SuppressWarnings("serial")
    final JButton submitButton =
        new JButton("Add Todo item") {
          {
            addActionListener(
                (ActionEvent event) -> {
                  if (ApplicationFeatures.ADD_ITEM.isActive()) {
                    todoItems.add(textField.getText());
                    updateTodoItems();
                  }
                });
          }
        };
    submitButton.setName("add");

    return submitButton;
  }
示例#5
0
 private JPanel deleteButton() {
   JPanel deleteButtonPane = new JPanel();
   deleteButtonPane.setLayout(new BorderLayout());
   @SuppressWarnings("serial")
   final JButton deleteButton =
       new JButton("Delete") {
         {
           addActionListener(
               arg0 -> {
                 if (ApplicationFeatures.DELETE_ITEM.isActive()) {
                   removeTodoItem();
                 }
               });
         }
       };
   deleteButton.setName("delete");
   deleteButtonPane.add(deleteButton, BorderLayout.EAST);
   return deleteButtonPane;
 }
示例#6
0
  /** Constructs the <tt>SearchPanel</tt>. */
  private void init() {
    String searchString = GuiActivator.getResources().getI18NString("service.gui.SEARCH");
    JLabel searchLabel = new JLabel(searchString + ": ");

    searchButton =
        new JButton(searchString, new ImageIcon(ImageLoader.getImage(ImageLoader.SEARCH_ICON)));

    this.searchTextField.getDocument().addDocumentListener(this);

    this.add(searchLabel, BorderLayout.WEST);
    this.add(searchTextField, BorderLayout.CENTER);

    searchButton.setName("search");
    searchButton.setMnemonic(GuiActivator.getResources().getI18nMnemonic("service.gui.SEARCH"));

    searchButton.addActionListener(this);

    this.historyWindow.getRootPane().setDefaultButton(searchButton);

    this.add(searchButton, BorderLayout.EAST);
  }
  /**
   * Creates the appropriate object to represent each of the objects in <code>buttons</code> and
   * adds it to <code>container</code>. This differs from addMessageComponents in that it will
   * recurse on <code>buttons</code> and that if button is not a Component it will create an
   * instance of JButton.
   */
  protected void addButtonComponents(Container container, Object[] buttons, int initialIndex) {
    if (buttons != null && buttons.length > 0) {
      boolean sizeButtonsToSame = getSizeButtonsToSameWidth();
      boolean createdAll = true;
      int numButtons = buttons.length;
      JButton[] createdButtons = null;
      int maxWidth = 0;

      if (sizeButtonsToSame) {
        createdButtons = new JButton[numButtons];
      }

      for (int counter = 0; counter < numButtons; counter++) {
        Object button = buttons[counter];
        Component newComponent;

        if (button instanceof Component) {
          createdAll = false;
          newComponent = (Component) button;
          container.add(newComponent);
          hasCustomComponents = true;

        } else {
          JButton aButton;

          if (button instanceof ButtonFactory) {
            aButton = ((ButtonFactory) button).createButton();
          } else if (button instanceof Icon) aButton = new JButton((Icon) button);
          else aButton = new JButton(button.toString());

          aButton.setName("OptionPane.button");
          aButton.setMultiClickThreshhold(
              DefaultLookup.getInt(optionPane, this, "OptionPane.buttonClickThreshhold", 0));
          configureButton(aButton);

          container.add(aButton);

          ActionListener buttonListener = createButtonActionListener(counter);
          if (buttonListener != null) {
            aButton.addActionListener(buttonListener);
          }
          newComponent = aButton;
        }
        if (sizeButtonsToSame && createdAll && (newComponent instanceof JButton)) {
          createdButtons[counter] = (JButton) newComponent;
          maxWidth = Math.max(maxWidth, newComponent.getMinimumSize().width);
        }
        if (counter == initialIndex) {
          initialFocusComponent = newComponent;
          if (initialFocusComponent instanceof JButton) {
            JButton defaultB = (JButton) initialFocusComponent;
            defaultB.addHierarchyListener(
                new HierarchyListener() {
                  public void hierarchyChanged(HierarchyEvent e) {
                    if ((e.getChangeFlags() & HierarchyEvent.PARENT_CHANGED) != 0) {
                      JButton defaultButton = (JButton) e.getComponent();
                      JRootPane root = SwingUtilities.getRootPane(defaultButton);
                      if (root != null) {
                        root.setDefaultButton(defaultButton);
                      }
                    }
                  }
                });
          }
        }
      }
      ((ButtonAreaLayout) container.getLayout())
          .setSyncAllWidths((sizeButtonsToSame && createdAll));
      /* Set the padding, windows seems to use 8 if <= 2 components,
      otherwise 4 is used. It may actually just be the size of the
      buttons is always the same, not sure. */
      if (DefaultLookup.getBoolean(optionPane, this, "OptionPane.setButtonMargin", true)
          && sizeButtonsToSame
          && createdAll) {
        JButton aButton;
        int padSize;

        padSize = (numButtons <= 2 ? 8 : 4);

        for (int counter = 0; counter < numButtons; counter++) {
          aButton = createdButtons[counter];
          aButton.setMargin(new Insets(2, padSize, 2, padSize));
        }
      }
    }
  }
  /** Initializes the <tt>NewStatusMessageDialog</tt> by adding the buttons, fields, etc. */
  private void init() {
    JLabel messageLabel =
        new JLabel(GuiActivator.getResources().getI18NString("service.gui.NEW_STATUS_MESSAGE"));

    JPanel dataPanel = new TransparentPanel(new BorderLayout(5, 5));

    JTextArea infoArea =
        new JTextArea(GuiActivator.getResources().getI18NString("service.gui.STATUS_MESSAGE_INFO"));

    JLabel infoTitleLabel =
        new JLabel(GuiActivator.getResources().getI18NString("service.gui.NEW_STATUS_MESSAGE"));

    JPanel labelsPanel = new TransparentPanel(new GridLayout(0, 1));

    JButton okButton = new JButton(GuiActivator.getResources().getI18NString("service.gui.OK"));

    JPanel buttonsPanel = new TransparentPanel(new FlowLayout(FlowLayout.RIGHT));

    this.setTitle(GuiActivator.getResources().getI18NString("service.gui.NEW_STATUS_MESSAGE"));

    this.getRootPane().setDefaultButton(okButton);

    this.setPreferredSize(new Dimension(500, 200));

    infoArea.setEditable(false);
    infoArea.setLineWrap(true);
    infoArea.setWrapStyleWord(true);
    infoArea.setOpaque(false);

    dataPanel.add(messageLabel, BorderLayout.WEST);

    messageTextField.setText(presenceOpSet.getCurrentStatusMessage());
    dataPanel.add(messageTextField, BorderLayout.CENTER);

    infoTitleLabel.setHorizontalAlignment(JLabel.CENTER);
    infoTitleLabel.setFont(infoTitleLabel.getFont().deriveFont(Font.BOLD, 18.0f));

    labelsPanel.add(infoTitleLabel);
    labelsPanel.add(infoArea);
    labelsPanel.add(dataPanel);

    messagePanel = new TransparentPanel(new GridBagLayout());
    GridBagConstraints messagePanelConstraints = new GridBagConstraints();
    messagePanelConstraints.anchor = GridBagConstraints.NORTHWEST;
    messagePanelConstraints.fill = GridBagConstraints.NONE;
    messagePanelConstraints.gridx = 0;
    messagePanelConstraints.gridy = 0;
    messagePanelConstraints.insets = new Insets(5, 0, 5, 10);
    messagePanelConstraints.weightx = 0;
    messagePanelConstraints.weighty = 0;
    messagePanel.add(
        new ImageCanvas(ImageLoader.getImage(ImageLoader.RENAME_DIALOG_ICON)),
        messagePanelConstraints);

    messagePanelConstraints.anchor = GridBagConstraints.NORTH;
    messagePanelConstraints.fill = GridBagConstraints.HORIZONTAL;
    messagePanelConstraints.gridx = 1;
    messagePanelConstraints.insets = new Insets(0, 0, 0, 0);
    messagePanelConstraints.weightx = 1;
    messagePanel.add(labelsPanel, messagePanelConstraints);

    okButton.setName("ok");
    cancelButton.setName("cancel");

    okButton.setMnemonic(GuiActivator.getResources().getI18nMnemonic("service.gui.OK"));
    cancelButton.setMnemonic(GuiActivator.getResources().getI18nMnemonic("service.gui.CANCEL"));

    okButton.addActionListener(this);
    cancelButton.addActionListener(this);

    buttonsPanel.add(okButton);
    buttonsPanel.add(cancelButton);

    JPanel mainPanel = new TransparentPanel(new GridBagLayout());
    mainPanel.setBorder(BorderFactory.createEmptyBorder(5, 10, 0, 10));

    GridBagConstraints mainPanelConstraints = new GridBagConstraints();
    mainPanelConstraints.anchor = GridBagConstraints.NORTH;
    mainPanelConstraints.fill = GridBagConstraints.BOTH;
    mainPanelConstraints.gridx = 0;
    mainPanelConstraints.gridy = 0;
    mainPanelConstraints.weightx = 1;
    mainPanelConstraints.weighty = 1;
    mainPanel.add(messagePanel, mainPanelConstraints);

    mainPanelConstraints.anchor = GridBagConstraints.SOUTHEAST;
    mainPanelConstraints.fill = GridBagConstraints.NONE;
    mainPanelConstraints.gridy = 1;
    mainPanelConstraints.weightx = 0;
    mainPanelConstraints.weighty = 0;
    mainPanel.add(buttonsPanel, mainPanelConstraints);

    this.getContentPane().add(mainPanel);
  }
示例#9
0
  /** Initialize the common user interface components. */
  private void initUI() {
    /* initialize fields */
    {
      pFileSeqPanels = new TreeMap<FileSeq, JFileSeqPanel>();
    }

    /* initialize the popup menus */
    {
      initBasicMenus(true, false);
      updateMenuToolTips();
    }

    /* initialize the panel components */
    {
      setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));

      /* header */
      {
        pApplyToolTipText = "Replace the working area files with the selected checked-in files.";
        pUnApplyToolTipText = "There are no unsaved changes to Apply at this time.";

        JPanel panel = initHeader(true);
        add(panel);
      }

      add(Box.createRigidArea(new Dimension(0, 4)));

      /* full node name */
      {
        LinkedList<Component> extra = new LinkedList<Component>();
        extra.add(Box.createRigidArea(new Dimension(4, 0)));
        {
          JButton btn = new JButton();
          pSeqLayoutButton = btn;
          btn.setName(pIsListLayout ? "ListLayoutButton" : "TabbedLayoutButton");

          Dimension size = new Dimension(19, 19);
          btn.setMinimumSize(size);
          btn.setMaximumSize(size);
          btn.setPreferredSize(size);

          btn.setActionCommand("seq-layout-changed");
          btn.addActionListener(this);

          extra.add(btn);
        }

        initNameField(this, extra);

        pNodeNameField.setFocusable(true);
        pNodeNameField.addKeyListener(this);
        pNodeNameField.addMouseListener(this);
      }

      add(Box.createRigidArea(new Dimension(0, 4)));

      {
        JTabbedPane tab = new JTabbedPane();
        pFileSeqsTab = tab;
        tab.setVisible(!pIsListLayout);
        add(tab);
      }

      {
        Box vbox = new Box(BoxLayout.Y_AXIS);
        pFileSeqsBox = vbox;

        {
          JScrollPane scroll = UIFactory.createVertScrollPane(vbox);
          pFileSeqsScroll = scroll;
          scroll.setVisible(!pIsListLayout);

          add(scroll);
        }
      }

      Dimension size = new Dimension(sSize + 22, 120);
      setMinimumSize(size);
      setPreferredSize(size);

      setFocusable(true);
      addKeyListener(this);
      addMouseListener(this);
    }

    updateNodeStatus(null, null, null);
  }
  public void createPrinterInterface(final printPDF printerObject) throws HeadlessException {

    int numOfPrinters = printerObject.getPrinters().size();
    ArrayList<String> printerName = printerObject.getPrinters();
    final JFrame frame = new JFrame("Choose a printer to print to:");
    final JPanel panel = new JPanel(new GridBagLayout());
    frame.getContentPane().add(panel, BorderLayout.NORTH);
    frame.setResizable(false);
    GridBagConstraints c = new GridBagConstraints();
    ArrayList<JButton> printerButtons = new ArrayList<JButton>();
    if (numOfPrinters == 0) {
      JLabel noPrintersFound = new JLabel("No Printers Found");
      c.gridx = 0;
      c.gridy = -1;
      c.insets = new Insets(0, 0, 100, 0);
      panel.add(noPrintersFound, c);
    }
    for (int x = 0; x < numOfPrinters; x++) {
      printerButtons.add(new JButton(printerName.get(x)));
      c.gridx = 0;
      c.gridy = x;
      printerButtons.get(x).setPreferredSize(new Dimension(250, 30));
      final JButton buttonNamer = printerButtons.get(x);
      buttonNamer.setName(printerObject.getPrinters().get(x));
      printerButtons
          .get(x)
          .addActionListener(
              new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                  System.out.println("Printing to: " + buttonNamer.getName());
                  printerObject.setPrinter(buttonNamer.getName());
                  try {
                    printerObject.printFile();
                  } catch (PrintException e1) {
                    e1.printStackTrace();
                  } catch (IOException e1) {
                    e1.printStackTrace();
                  }
                  frame.dispose();
                }
              });

      panel.add(printerButtons.get(x), c);
    }
    JButton cancel = new JButton("Cancel");
    c.gridx = 0;
    c.gridy = numOfPrinters;
    c.insets = new Insets(0, 0, 0, 0);
    cancel.setPreferredSize(new Dimension(250, 30));

    cancel.addActionListener(
        new ActionListener() {

          @Override
          public void actionPerformed(ActionEvent e) {
            frame.dispose();
          }
        });

    panel.add(cancel, c);
    final JScrollPane scroll = new JScrollPane(panel);
    frame.setLayout(new BorderLayout());
    frame.add(scroll, BorderLayout.CENTER);
    frame.setSize(300, 300);
    frame.setVisible(true);
  }
  public ConfigurationPanel(final Project project) {

    serverUrl.setName("serverUrl");
    buildDelay.setName("buildDelay");
    jobRefreshPeriod.setName("jobRefreshPeriod");
    rssRefreshPeriod.setName("rssRefreshPeriod");
    username.setName("_username_");

    passwordField.setName("passwordFile");
    crumbDataField.setName("crumbDataFile");

    testConnexionButton.setName("testConnexionButton");
    connectionStatusLabel.setName("connectionStatusLabel");

    successOrStableCheckBox.setName("successOrStableCheckBox");
    unstableOrFailCheckBox.setName("unstableOrFailCheckBox");
    abortedCheckBox.setName("abortedCheckBox");

    rssStatusFilterPanel.setBorder(IdeBorderFactory.createTitledBorder("Event Log Settings", true));

    debugPanel.setVisible(false);

    initDebugTextPane();

    buildDelay.setDocument(new NumberDocument());
    jobRefreshPeriod.setDocument(new NumberDocument());
    rssRefreshPeriod.setDocument(new NumberDocument());

    uploadPatchSettingsPanel.setBorder(
        IdeBorderFactory.createTitledBorder("Upload a Patch Settings", true));

    passwordField
        .getDocument()
        .addDocumentListener(
            new DocumentListener() {
              @Override
              public void insertUpdate(DocumentEvent e) {
                myPasswordModified = true;
              }

              @Override
              public void removeUpdate(DocumentEvent e) {
                myPasswordModified = true;
              }

              @Override
              public void changedUpdate(DocumentEvent e) {
                myPasswordModified = true;
              }
            });

    testConnexionButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent event) {
            try {
              debugPanel.setVisible(false);

              new NotNullValidator().validate(serverUrl);
              new UrlValidator().validate(serverUrl);

              JenkinsSettings jenkinsSettings = JenkinsSettings.getSafeInstance(project);

              String password =
                  isPasswordModified() ? getPassword() : jenkinsSettings.getPassword();

              RequestManager.getInstance(project)
                  .authenticate(
                      serverUrl.getText(), username.getText(), password, crumbDataField.getText());
              setConnectionFeedbackLabel(CONNECTION_TEST_SUCCESSFUL_COLOR, "Successful");
              setPassword(password);
            } catch (Exception ex) {
              setConnectionFeedbackLabel(CONNECTION_TEST_FAILED_COLOR, "[Fail] " + ex.getMessage());
              if (ex instanceof AuthenticationException) {
                AuthenticationException authenticationException = (AuthenticationException) ex;
                String responseBody = authenticationException.getResponseBody();
                if (StringUtils.isNotBlank(responseBody)) {
                  debugPanel.setVisible(true);
                  debugTextPane.setText(responseBody);
                }
              }
            }
          }
        });

    formValidator =
        FormValidator.init(this)
            .addValidator(
                username,
                new UIValidator<JTextField>() {
                  public void validate(JTextField component) throws ConfigurationException {
                    if (StringUtils.isNotBlank(component.getText())) {
                      String password = getPassword();
                      if (StringUtils.isBlank(password)) {
                        throw new ConfigurationException(
                            String.format("'%s' must be set", passwordField.getName()));
                      }
                    }
                  }
                });
  }