コード例 #1
0
  /**
   * Create a new AddToDoItemDialog
   *
   * @param renderer the ListCellRenderer to use in order to display the offenders
   */
  public AddToDoItemDialog(ListCellRenderer renderer) {
    super(Translator.localize("dialog.title.add-todo-item"), Dialog.OK_CANCEL_OPTION, true);

    headLineTextField = new JTextField(TEXT_COLUMNS);
    priorityComboBox = new JComboBox(PRIORITIES);
    moreinfoTextField = new JTextField(TEXT_COLUMNS);
    descriptionTextArea = new JTextArea(TEXT_ROWS, TEXT_COLUMNS);

    DefaultListModel dlm = new DefaultListModel();
    Object[] offObj = TargetManager.getInstance().getModelTargets().toArray();
    for (int i = 0; i < offObj.length; i++) {
      if (offObj[i] != null) {
        dlm.addElement(offObj[i]);
      }
    }

    offenderList = new JList(dlm);
    offenderList.setCellRenderer(renderer);
    JScrollPane offenderScroll = new JScrollPane(offenderList);
    offenderScroll.setOpaque(true);

    JLabel headlineLabel = new JLabel(Translator.localize("label.headline"));
    JLabel priorityLabel = new JLabel(Translator.localize("label.priority"));
    JLabel moreInfoLabel = new JLabel(Translator.localize("label.more-info-url"));
    JLabel offenderLabel = new JLabel(Translator.localize("label.offenders"));
    priorityComboBox.setSelectedItem(PRIORITIES[0]);

    JPanel panel = new JPanel(new LabelledLayout(getLabelGap(), getComponentGap()));

    headlineLabel.setLabelFor(headLineTextField);
    panel.add(headlineLabel);
    panel.add(headLineTextField);

    priorityLabel.setLabelFor(priorityComboBox);
    panel.add(priorityLabel);
    panel.add(priorityComboBox);

    moreInfoLabel.setLabelFor(moreinfoTextField);
    panel.add(moreInfoLabel);
    panel.add(moreinfoTextField);

    offenderLabel.setLabelFor(offenderScroll);
    panel.add(offenderLabel);
    panel.add(offenderScroll);

    descriptionTextArea.setLineWrap(true); // MVW - Issue 2422
    descriptionTextArea.setWrapStyleWord(true); // MVW - Issue 2422
    descriptionTextArea.setText(Translator.localize("label.enter-todo-item") + "\n");
    descriptionTextArea.setMargin(new Insets(INSET_PX, INSET_PX, INSET_PX, INSET_PX));
    JScrollPane descriptionScroller = new JScrollPane(descriptionTextArea);
    descriptionScroller.setPreferredSize(descriptionTextArea.getPreferredSize());
    panel.add(descriptionScroller);

    setContent(panel);
  }
コード例 #2
0
ファイル: CToolTip.java プロジェクト: rkipper/AppInventor_RK
 public Dimension getPreferredSize(JComponent c) {
   String tipText = ((JToolTip) c).getTipText();
   if (tipText == null) return new Dimension(0, 0);
   textArea.setText(tipText);
   Dimension d = textArea.getPreferredSize();
   d.width = Math.min(d.width, WIDTH);
   // We need to pad the height, or else the last line
   // doesn't show in some tooltips.  Is this a Swing bug or
   // is getPreferred size the wrong thing to use here?
   // Sadly, this typically is too much padding.  But there are
   // some blocks where we need this much, for example, the
   // tooltip on the '=' block.
   d.height += PAD_HEIGHT;
   textArea.setSize(d);
   return d;
   // return textArea.getPreferredSize();
 }
コード例 #3
0
  private JPanel createPreviewPanel() {
    JPanel panel;
    YBoxPanel headerPanel;
    JScrollPane scroll;

    panel = new JPanel(new BorderLayout());
    panel.setBorder(BorderFactory.createTitledBorder(Translator.get("preview")));

    headerPanel = new YBoxPanel();
    headerPanel.add(new JLabel(Translator.get("run_dialog.run_command_description") + ":"));
    headerPanel.add(historyPreview = new EditableComboBox(new JTextField("mucommander -v")));
    historyPreview.addItem("mucommander -v");
    historyPreview.addItem("java -version");

    headerPanel.addSpace(10);
    headerPanel.add(new JLabel(Translator.get("run_dialog.command_output") + ":"));

    panel.add(headerPanel, BorderLayout.NORTH);

    shellPreview = new JTextArea(15, 15);
    panel.add(
        scroll =
            new JScrollPane(
                shellPreview,
                JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
                JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED),
        BorderLayout.CENTER);
    scroll.getViewport().setPreferredSize(shellPreview.getPreferredSize());
    shellPreview.append(RuntimeConstants.APP_STRING);
    shellPreview.append("\nCopyright (C) ");
    shellPreview.append(RuntimeConstants.COPYRIGHT);
    shellPreview.append(
        " Maxence Bernard\nThis is free software, distributed under the terms of the GNU General Public License.");
    //        shellPreview.setLineWrap(true);
    shellPreview.setCaretPosition(0);

    setForegroundColors();
    setBackgroundColors();

    return panel;
  }
コード例 #4
0
  /**
   * Initializes and draws the dialog.
   *
   * @param parent the parent frame for this dialog.
   * @param sKey the property string associated with this message - used to set FormatProperties
   *     when user ticks box.
   */
  public UIHintDialog(JFrame parent, int nType) {

    super(parent, true);
    setTitle("Hint");

    this.nType = nType;

    if (nType == PASTE_HINT) {
      this.sMessage =
          LanguageProperties.getString(LanguageProperties.DIALOGS_BUNDLE, "UIHintDialog.pasteHint1")
              + "\n\n"
              + LanguageProperties.getString(
                  LanguageProperties.DIALOGS_BUNDLE, "UIHintDialog.pasteHint2")
              + "\n\n"
              + LanguageProperties.getString(
                  LanguageProperties.DIALOGS_BUNDLE, "UIHintDialog.pasteHint3");
    }

    oContentPane = getContentPane();
    oContentPane.setLayout(new BorderLayout());

    oDetailsPanel = new JPanel(new BorderLayout());

    JPanel imagePanel = new JPanel();
    imagePanel.setBorder(new EmptyBorder(10, 10, 10, 0));

    oImage = UIImages.getNodeImage(ICoreConstants.POSITION);
    oImageLabel = new JLabel(oImage);
    oImageLabel.setVerticalAlignment(SwingConstants.TOP);
    imagePanel.add(oImageLabel);

    oDetailsPanel.add(imagePanel, BorderLayout.WEST);

    oTextArea = new JTextArea(sMessage);
    oTextArea.setEditable(false);
    oTextArea.setFont(new Font("Dialog", Font.PLAIN, 12)); // $NON-NLS-1$
    oTextArea.setBackground(oDetailsPanel.getBackground());
    oTextArea.setColumns(35);
    oTextArea.setLineWrap(true);
    oTextArea.setWrapStyleWord(true);
    oTextArea.setSize(oTextArea.getPreferredSize());

    JPanel textPanel = new JPanel();
    textPanel.setBorder(new EmptyBorder(10, 10, 20, 10));
    textPanel.setBorder(new EmptyBorder(10, 10, 20, 10));
    textPanel.add(oTextArea);

    JPanel oCheckBoxPanel = new JPanel();
    cbShowPasteHint = new JCheckBox();
    cbShowPasteHint.setText(
        LanguageProperties.getString(LanguageProperties.DIALOGS_BUNDLE, "UIHintDialog.hideHint"));
    cbShowPasteHint.setSelected(false);
    cbShowPasteHint.setHorizontalAlignment(SwingConstants.LEFT);
    oCheckBoxPanel.add(cbShowPasteHint);

    oDetailsPanel.add(textPanel, BorderLayout.CENTER);
    oDetailsPanel.add(oCheckBoxPanel, BorderLayout.SOUTH);

    oButtonPanel = new UIButtonPanel();
    pbClose =
        new UIButton(
            LanguageProperties.getString(
                LanguageProperties.DIALOGS_BUNDLE, "UIHintDialog.closeButton")); // $NON-NLS-1$
    pbClose.setMnemonic(
        LanguageProperties.getString(
                LanguageProperties.DIALOGS_BUNDLE, "UIHintDialog.closeButtonMnemonic")
            .charAt(0));
    pbClose.addActionListener(this);
    oButtonPanel.addButton(pbClose);

    oContentPane.add(oDetailsPanel, BorderLayout.CENTER);
    oContentPane.add(oButtonPanel, BorderLayout.SOUTH);

    pack();
    setResizable(false);
  }
コード例 #5
0
ファイル: VersionManagement.java プロジェクト: JoaPiep/VRL
    @SuppressWarnings("unchecked") // we must be compatible with 1.6
    public VersionManagementPanel(final VisualCanvas canvas) {

      super(canvas);

      setLayout(new GridLayout());

      // TODO @Christian Poliwoda what does manual testing mean?
      // numbers tested manually
      Dimension prefScrollPaneDim = new Dimension(100, 30);
      Dimension visibleRectDim = canvas.getVisibleRect().getSize();

      final VersionController controller =
          canvas.getProjectController().getProject().getProjectFile();

      final int numVersions = controller.getNumberOfVersions() - 1;

      versionData = new Object[numVersions];

      ArrayList<RevCommit> versions = new ArrayList<RevCommit>();

      try {
        versions = controller.getVersions();
      } catch (IOException ex) {
        Logger.getLogger(VersionManagementPanel.class.getName()).log(Level.SEVERE, null, ex);
      }

      int maxTextwidth = 0;
      String longestText = null;

      // the history with timestamp and a short commit message
      for (int i = 1; i < versions.size(); i++) {
        String text =
            // + Message.generateHTMLSpace(3)
            new Date(versions.get(i).getCommitTime() * 1000L)
                + ": "
                + versions.get(i).getShortMessage();

        // truncate texts that are too long
        int maxTextLength = 100;
        String dots = "...";

        int textLength = text.length() - dots.length();

        if (textLength > maxTextLength) {
          text = text.substring(0, maxTextLength) + dots;
        }

        versionData[versions.size() - i - 1] = new Version(text, i);

        if (text.length() > maxTextwidth) {
          maxTextwidth = text.length();
          longestText = text;
        }
      }

      resultModel = new DefaultListModel();

      // first init to show all if search not started yet
      for (int i = 0; i < versionData.length; i++) {
        resultModel.addElement(versionData[i]);
      }

      versionList = new JList(resultModel);

      // set the width of version managment window
      // dependent on largest git short message length
      double maxFontWidth =
          versionList
              .getFontMetrics(versionList.getFont())
              .getStringBounds(longestText, versionList.getGraphics())
              .getWidth();

      if (maxFontWidth <= visibleRectDim.width) {

        prefScrollPaneDim.width = (int) maxFontWidth;
      } else {

        if (visibleRectDim.width < 400) {
          prefScrollPaneDim.width = visibleRectDim.width;
        } else {
          prefScrollPaneDim.width = 400;
        }
      }

      versionList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

      versionList.setOpaque(false);

      versionList.setBackground(VSwingUtil.TRANSPARENT_COLOR);
      versionList.setBorder(new EmptyBorder(3, 3, 3, 3));

      Box upperTopBox = Box.createVerticalBox();

      // press the commits to top with VerticalGlue
      // contains search area at top and
      // search results at the botton
      Box upperOuterBox = Box.createVerticalBox();

      JButton searchButton = new JButton("search");
      searchButton.addActionListener(
          new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent ae) {
              searchAndAddToResultList();
            }
          });

      searchField = new JTextArea();

      // search area box
      Box upperBox1 = Box.createHorizontalBox();

      upperBox1.add(searchField);
      upperBox1.add(searchButton);

      Dimension fieldDim = new Dimension(Short.MAX_VALUE, searchField.getPreferredSize().height);
      searchField.setMaximumSize(fieldDim);

      searchField.addKeyListener(
          new KeyAdapter() {
            String tmp = "";

            @Override
            public void keyReleased(KeyEvent ke) {

              searchAndAddToResultList();
            }
          });

      //            upperOuterBox.add(upperBox1);
      upperTopBox.add(upperBox1);
      upperTopBox.add(upperOuterBox);

      // result area box
      Box upperBox2 = Box.createHorizontalBox();

      upperBox2.add(Box.createHorizontalGlue());
      upperBox2.add(versionList);
      upperBox2.add(Box.createHorizontalGlue());

      upperOuterBox.add(upperBox2);
      upperOuterBox.add(Box.createVerticalGlue());

      // added for optical reasons to force correct scrollbar position
      Box upperInnerBorderPane = Box.createHorizontalBox();
      upperInnerBorderPane.add(upperOuterBox);
      upperInnerBorderPane.setBorder(new EmptyBorder(5, 15, 5, 15));
      upperInnerBorderPane.setBackground(VSwingUtil.TRANSPARENT_COLOR);

      VScrollPane upperScrollPane = new VScrollPane(upperInnerBorderPane);
      upperScrollPane.setHorizontalScrollBarPolicy(VScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
      upperScrollPane.setVerticalScrollBarPolicy(VScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
      upperScrollPane.setMinimumSize(prefScrollPaneDim);

      JSplitPane splitPane = new VSplitPane(JSplitPane.VERTICAL_SPLIT);
      splitPane.setEnabled(true); // true = transparent
      splitPane.setBackground(VSwingUtil.TRANSPARENT_COLOR);
      splitPane.setBorder(new EmptyBorder(5, 5, 5, 5));
      splitPane.setDividerLocation(0.5);

      upperTopBox.add(upperScrollPane);
      splitPane.add(upperTopBox); // add in the upper part

      htmlCommit.setBackground(VSwingUtil.TRANSPARENT_COLOR);
      htmlCommit.setContentType("text/html");
      htmlCommit.setOpaque(false);
      htmlCommit.setEditable(false);
      htmlCommit.setBorder(new EmptyBorder(0, 15, 0, 15));

      Box lowerBox = Box.createVerticalBox();
      lowerBox.setAlignmentX(Component.LEFT_ALIGNMENT);
      lowerBox.add(htmlCommit);
      lowerBox.add(Box.createVerticalGlue());

      VScrollPane lowerScrollPane = new VScrollPane(lowerBox);

      lowerScrollPane.setHorizontalScrollBarPolicy(VScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
      lowerScrollPane.setVerticalScrollBarPolicy(VScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
      lowerScrollPane.setMinimumSize(new Dimension(0, 0));

      // add in the lower part
      splitPane.setBottomComponent(lowerScrollPane);

      add(splitPane);

      versionList.addMouseListener(
          new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {

              // show commit message in lower part if clicked on a row
              // in upper part
              if (e.getClickCount() == 1) {

                final VersionController controller =
                    canvas.getProjectController().getProject().getProjectFile();

                final int numVersions = controller.getNumberOfVersions() - 1;

                ArrayList<RevCommit> versions = new ArrayList<RevCommit>();

                try {
                  versions = controller.getVersions();
                } catch (IOException ex) {
                  Logger.getLogger(VersionManagementPanel.class.getName())
                      .log(Level.SEVERE, null, ex);
                }

                int versionIndex = ((Version) versionList.getSelectedValue()).getVersion();

                htmlCommit.setText(
                    "<html>"
                        + "<pre> <font color=white><br>"
                        + "<b>SHA-1:</b> "
                        + versions.get(versionIndex).getName()
                        + "<br><br>"
                        + "<b>Message:</b><br><br>"
                        + versions.get(versionIndex).getFullMessage()
                        + "</pre></p>"
                        + "</html>");
                htmlCommit.setCaretPosition(0);
              }

              if (e.getClickCount() == 2 && SwingUtilities.isLeftMouseButton(e)) {

                if (((Version) versionList.getSelectedValue()).getVersion() < 2) {
                  VDialog.showMessageDialog(
                      canvas,
                      "Cannot Load Version",
                      "The first version in a project contains no"
                          + " sessions and cannot be loaded!");
                  return;
                }

                //                        if (VDialog.showConfirmDialog(canvas,
                //                                "Checkout Version:",
                //                                "<html><div align=Center>"
                //                                + "<p>Do you want to checkout the selected"
                //                                + " version?<p>"
                //                                + "<p><b>Unsaved changes will be lost!</b></p>"
                //                                + "</div></html>",
                //                                VDialog.DialogType.YES_NO) != VDialog.YES) {
                //                            return;
                //                        }

                int answer =
                    VDialog.showConfirmDialog(
                        canvas,
                        "Checkout Version:",
                        "<html><div align=Center>"
                            + "<p>Checking out selected version.<p><br>"
                            + "<p>Do you want to save the current session?</p><br>"
                            + "<p><b>Unsaved changes will be lost!</b></p>"
                            + "</div></html>",
                        new String[] {"Save", "Discard", "Cancel"});

                if (answer == 0) {
                  try {
                    canvas.getProjectController().saveProject(false);
                  } catch (IOException ex) {
                    Logger.getLogger(VersionManagement.class.getName()).log(Level.SEVERE, null, ex);

                    VDialog.showMessageDialog(
                        canvas,
                        "Cannot save Project:",
                        "<html><div align=Center>" + "Project cannot be saved!" + "</div></html>");
                  }
                } else if (answer == 1) {
                  // nothing to do
                } else if (answer == 2) {
                  return;
                }

                try {

                  int versionIndex = ((Version) versionList.getSelectedValue()).getVersion();

                  canvas.setActive(false);

                  String currentSessionName = canvas.getProjectController().getCurrentSession();

                  canvas.getProjectController().close(currentSessionName);

                  controller.checkoutVersion(versionIndex);

                  if (dialog != null) {
                    dialog.close();
                    dialog = null;
                  }

                  if (canvas
                      .getProjectController()
                      .getProject()
                      .getSessionFileByEntryName(currentSessionName)
                      .exists()) {
                    canvas.getProjectController().open(currentSessionName, false, true);
                  } else {
                    //                                VDialog.showMessageDialog(canvas,
                    //                                        "Cannot load \""
                    //                                        + currentSessionName
                    //                                        +"\":", "<html><div align=Center>"
                    //                                        + "<p>The Session "
                    //                                        + Message.EMPHASIZE_BEGIN
                    //                                        + currentSessionName
                    //                                         +  Message.EMPHASIZE_END
                    //                                        + " does not exist in the current"
                    //                                        + " version."
                    //                                        + "<p>The <b>Main</b>-Session will"
                    //                                        + "be loaded instead</div></html>");
                    canvas.getProjectController().open("Main", false, true);
                  }

                } catch (IOException ex) {
                  Logger.getLogger(VersionManagementPanel.class.getName())
                      .log(Level.SEVERE, null, ex);
                }
              }
            }
          });

      //            setMinimumSize(visibleRectDim);
      setMaximumSize(visibleRectDim);

      int width = getPreferredSize().width;
      setPreferredSize(new Dimension(width, (int) (visibleRectDim.height * 0.5)));
    } // end constructure
コード例 #6
0
ファイル: WriteXMPAction.java プロジェクト: GeorgLink/Desktop
    public OptionsDialog(JFrame parent) {
      super(parent, Globals.lang("Writing XMP metadata for selected entries..."), false);
      okButton.setEnabled(false);

      okButton.addActionListener(
          new ActionListener() {
            public void actionPerformed(ActionEvent e) {
              dispose();
            }
          });

      AbstractAction cancel =
          new AbstractAction() {
            private static final long serialVersionUID = -338601477652815366L;

            public void actionPerformed(ActionEvent e) {
              canceled = true;
            }
          };
      cancelButton.addActionListener(cancel);

      InputMap im = cancelButton.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
      ActionMap am = cancelButton.getActionMap();
      im.put(Globals.prefs.getKey("Close dialog"), "close");
      am.put("close", cancel);

      progressArea = new JTextArea(15, 60);

      JScrollPane scrollPane =
          new JScrollPane(
              progressArea,
              JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
              JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
      Dimension d = progressArea.getPreferredSize();
      d.height += scrollPane.getHorizontalScrollBar().getHeight() + 15;
      d.width += scrollPane.getVerticalScrollBar().getWidth() + 15;

      panel.setSize(d);

      progressArea.setBackground(Color.WHITE);
      progressArea.setEditable(false);
      progressArea.setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3));
      progressArea.setText("");

      JPanel panel = new JPanel();
      panel.setBorder(BorderFactory.createEmptyBorder(3, 2, 3, 2));
      panel.add(scrollPane);

      // progressArea.setPreferredSize(new Dimension(300, 300));

      ButtonBarBuilder bb = new ButtonBarBuilder();
      bb.addGlue();
      bb.addGridded(okButton);
      bb.addRelatedGap();
      bb.addGridded(cancelButton);
      bb.addGlue();
      JPanel bbPanel = bb.getPanel();
      bbPanel.setBorder(BorderFactory.createEmptyBorder(0, 3, 3, 3));
      getContentPane().add(panel, BorderLayout.CENTER);
      getContentPane().add(bbPanel, BorderLayout.SOUTH);

      pack();
      this.setResizable(false);
    }
コード例 #7
0
    public Component getTableCellRendererComponent(
        JTable table,
        Object value,
        boolean isSelected,
        boolean hasFocus,
        final int row,
        final int column) {
      Component c = null;
      String text = null;
      if (value != null) text = (String) value;
      Dimension dim;

      TableColumn tableCol;
      if (column == getColumnIndex(ORGANISM_COL)) {
        organismTextArea.setText(text);

        tableCol = table.getColumnModel().getColumn(column);
        organismTextArea.setSize(tableCol.getWidth(), table.getRowHeight(row));

        dim = organismTextArea.getPreferredSize();
        minHeight = Math.max(minHeight, dim.height);

        c = organismTextArea;
      } else if (column == getColumnIndex(HIT_COL)) {
        hit.setText(text);
        hit.setForeground(fgLinkColor);

        c = hit;
      } else if (column == getColumnIndex(HIT_DBXREF_COL)) {
        hit_dbxref.setText(text);
        hit_dbxref.setForeground(fgLinkColor);

        c = hit_dbxref;
      } else if (column == getColumnIndex(DESCRIPTION_COL)) {
        descriptionTextArea.setText(text);

        tableCol = table.getColumnModel().getColumn(column);
        descriptionTextArea.setSize(tableCol.getWidth(), table.getRowHeight(row));

        dim = descriptionTextArea.getPreferredSize();
        minHeight = Math.max(minHeight, dim.height);
        c = descriptionTextArea;
      } else if (column == getColumnIndex(EVALUE_COL)) {
        evalue.setText(text);
        c = evalue;
      } else if (column == getColumnIndex(LENGTH_COL)) {
        length.setText(text);
        c = length;
      } else if (column == getColumnIndex(ID_COL)) {
        ungappedId.setText(text);
        c = ungappedId;
      } else if (column == getColumnIndex(QUERY_COL)) {
        queryCoord.setText(text);
        c = queryCoord;
      } else if (column == getColumnIndex(SUBJECT_COL)) {
        subjCoord.setText(text);
        c = subjCoord;
      } else if (column == getColumnIndex(SCORE_COL)) {
        score.setText(text);
        c = score;
      } else if (column == getColumnIndex(OVERLAP_COL)) {
        overlap.setText(text);
        c = overlap;
      } else if (column == getColumnIndex(METHOD_COL)) {
        method.setText(text);
        c = method;
      } else if (column == getColumnIndex(REMOVE_BUTTON_COL)) {
        if (isSelected) {
          buttRemove.setForeground(fgColor);
          buttRemove.setBackground(table.getSelectionBackground());

        } else {
          buttRemove.setForeground(fgColor);
          buttRemove.setBackground(UIManager.getColor("Button.background"));
        }
        c = buttRemove;
      } else {
        throw new RuntimeException("invalid column! " + column + " " + text);
      }

      // adjust row height for columns with multiple lines
      if (column < 4) {
        if (table.getRowHeight(row) < minHeight) table.setRowHeight(row, minHeight);

        minHeight = -1;
      }

      // highlight on selection
      if (isSelected) c.setBackground(table.getSelectionBackground());
      else c.setBackground(Color.white);

      return c;
    }