Пример #1
0
    @Override
    public void actionPerformed(ActionEvent e) {
      // TODO Auto-generated method stub

      Object source = e.getSource();
      if (source == ok) {
        response = APPLY_OPTION;
        this.setVisible(false);
      } else if (source == cancel) {
        response = CANCEL_OPTION;
        this.setVisible(false);
      } else if (source == sizeCombo) {
        // get the number from the source
        JComboBox number = (JComboBox) source;
        String numberItem = (String) number.getSelectedItem();
        Font temp = example.getFont();
        // then set the font
        int newSize = Integer.parseInt(numberItem);
        example.setFont(new Font(temp.getFamily(), temp.getStyle(), newSize));
      } else if (source == fontCombo) {
        JComboBox font = (JComboBox) source;
        String s = (String) font.getSelectedItem();
        Font tmp = example.getFont();
        example.setFont(new Font(s, tmp.getStyle(), tmp.getSize()));
      } else if (source == foreground) {
        Color tmp = JColorChooser.showDialog(this, "Choose text color", example.getForeground());
        MenuBar.shapeLBG.setBackground(tmp);
        if (tmp != null) example.setForeground(tmp);
      }
    }
Пример #2
0
    @Override
    public void itemStateChanged(ItemEvent e) {
      // TODO Auto-generated method stub
      Object source = e.getSource();
      Font tmp = example.getFont();
      int style = tmp.getStyle();

      if (source == italic)
        if (italic.isSelected()) style = style | Font.ITALIC; // turn italic on
        else style = style & ~Font.ITALIC; // turn italic off
      else if (source == bold)
        if (bold.isSelected()) style = style | Font.BOLD; // turn bold on
        else style = style & ~Font.BOLD; // turn bold off

      example.setFont(new Font(tmp.getFamily(), style, tmp.getSize()));
    }
  private void prepareToShow() {
    final MouseAdapter mouseAdapter =
        new MouseAdapter() {
          public void mousePressed(MouseEvent e) {
            Point point = (Point) e.getPoint().clone();
            SwingUtilities.convertPointToScreen(point, e.getComponent());

            final Dimension dimension = myContent.getSize();
            dimension.height +=
                myResizable && isToDrawMacCorner() ? ourMacCorner.getHeight(myContent) : 4;
            dimension.width += 4;
            Point locationOnScreen = myContent.getLocationOnScreen();
            final Rectangle bounds =
                new Rectangle(new Point(locationOnScreen.x - 2, locationOnScreen.y - 2), dimension);
            if (!bounds.contains(point)) {
              cancel();
            }
          }
        };
    myContent.addMouseListener(mouseAdapter);
    Disposer.register(
        this,
        new Disposable() {
          public void dispose() {
            myContent.removeMouseListener(mouseAdapter);
          }
        });

    myContent.registerKeyboardAction(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            if (myCancelKeyEnabled) {
              cancel();
            }
          }
        },
        KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0),
        JComponent.WHEN_IN_FOCUSED_WINDOW);

    mySearchKeyListener = new SpeedSearchKeyListener();
    myContent.addKeyListener(mySearchKeyListener);

    if (myCancelOnMouseOutCallback != null || myCancelOnWindow) {
      myMouseOutCanceller = new Canceller();
      Toolkit.getDefaultToolkit()
          .addAWTEventListener(
              myMouseOutCanceller,
              AWTEvent.MOUSE_EVENT_MASK
                  | WindowEvent.WINDOW_ACTIVATED
                  | AWTEvent.MOUSE_MOTION_EVENT_MASK);
    }

    myFocusWatcher =
        new ChildFocusWatcher(myContent) {
          protected void onFocusGained(final FocusEvent event) {
            setWindowActive(true);
          }

          protected void onFocusLost(final FocusEvent event) {
            setWindowActive(false);
          }
        };

    mySpeedSearchPatternField = new JTextField();
    if (SystemInfo.isMac) {
      Font f = mySpeedSearchPatternField.getFont();
      mySpeedSearchPatternField.setFont(f.deriveFont(f.getStyle(), f.getSize() - 2));
    }
  }
  public JComponent createComponent() {
    myPanel = new JPanel(new GridBagLayout());

    myStartIndex = new JTextField(5);
    myEndIndex = new JTextField(5);
    myEntriesLimit = new JTextField(5);

    final FontMetrics fontMetrics = myStartIndex.getFontMetrics(myStartIndex.getFont());
    final Dimension minSize = new Dimension(myStartIndex.getPreferredSize());
    //noinspection HardCodedStringLiteral
    minSize.width = fontMetrics.stringWidth("AAAAA");
    myStartIndex.setMinimumSize(minSize);
    myEndIndex.setMinimumSize(minSize);
    myEntriesLimit.setMinimumSize(minSize);

    JLabel startIndexLabel =
        new JLabel(DebuggerBundle.message("label.array.renderer.configurable.start.index"));
    startIndexLabel.setLabelFor(myStartIndex);

    JLabel endIndexLabel =
        new JLabel(DebuggerBundle.message("label.array.renderer.configurable.end.index"));
    endIndexLabel.setLabelFor(myEndIndex);

    JLabel entriesLimitLabel =
        new JLabel(DebuggerBundle.message("label.array.renderer.configurable.max.count1"));
    entriesLimitLabel.setLabelFor(myEntriesLimit);

    myPanel.add(
        startIndexLabel,
        new GridBagConstraints(
            0,
            GridBagConstraints.RELATIVE,
            1,
            1,
            0.0,
            0.0,
            GridBagConstraints.WEST,
            GridBagConstraints.NONE,
            new Insets(0, 0, 0, 8),
            0,
            0));
    myPanel.add(
        myStartIndex,
        new GridBagConstraints(
            1,
            GridBagConstraints.RELATIVE,
            1,
            1,
            0.0,
            0.0,
            GridBagConstraints.NORTHWEST,
            GridBagConstraints.NONE,
            new Insets(0, 0, 0, 8),
            0,
            0));
    myPanel.add(
        endIndexLabel,
        new GridBagConstraints(
            2,
            GridBagConstraints.RELATIVE,
            1,
            1,
            0.0,
            0.0,
            GridBagConstraints.WEST,
            GridBagConstraints.NONE,
            new Insets(0, 0, 0, 8),
            0,
            0));
    myPanel.add(
        myEndIndex,
        new GridBagConstraints(
            3,
            GridBagConstraints.RELATIVE,
            1,
            1,
            1.0,
            0.0,
            GridBagConstraints.NORTHWEST,
            GridBagConstraints.NONE,
            new Insets(0, 0, 0, 0),
            0,
            0));

    myPanel.add(
        entriesLimitLabel,
        new GridBagConstraints(
            0,
            GridBagConstraints.RELATIVE,
            1,
            1,
            0.0,
            0.0,
            GridBagConstraints.WEST,
            GridBagConstraints.NONE,
            new Insets(4, 0, 0, 8),
            0,
            0));
    myPanel.add(
        myEntriesLimit,
        new GridBagConstraints(
            1,
            GridBagConstraints.RELATIVE,
            1,
            1,
            0.0,
            0.0,
            GridBagConstraints.NORTHWEST,
            GridBagConstraints.NONE,
            new Insets(4, 0, 0, 8),
            0,
            0));
    myPanel.add(
        new JLabel(DebuggerBundle.message("label.array.renderer.configurable.max.count2")),
        new GridBagConstraints(
            2,
            GridBagConstraints.RELATIVE,
            2,
            1,
            0.0,
            0.0,
            GridBagConstraints.WEST,
            GridBagConstraints.NONE,
            new Insets(4, 0, 0, 0),
            0,
            0));

    // push other components up
    myPanel.add(
        new JLabel(),
        new GridBagConstraints(
            0,
            GridBagConstraints.RELATIVE,
            1,
            1,
            0.0,
            1.0,
            GridBagConstraints.WEST,
            GridBagConstraints.NONE,
            new Insets(0, 0, 0, 0),
            0,
            0));

    final DocumentListener listener =
        new DocumentListener() {
          private void updateEntriesLimit() {
            final boolean state = myIndexUpdateEnabled;
            myIndexUpdateEnabled = false;
            try {
              if (myEntriesLimitUpdateEnabled) {
                myEntriesLimit.setText(
                    String.valueOf(getInt(myEndIndex) - getInt(myStartIndex) + 1));
              }
            } finally {
              myIndexUpdateEnabled = state;
            }
          }

          public void changedUpdate(DocumentEvent e) {
            updateEntriesLimit();
          }

          public void insertUpdate(DocumentEvent e) {
            updateEntriesLimit();
          }

          public void removeUpdate(DocumentEvent e) {
            updateEntriesLimit();
          }
        };
    myStartIndex.getDocument().addDocumentListener(listener);
    myEndIndex.getDocument().addDocumentListener(listener);
    myEntriesLimit
        .getDocument()
        .addDocumentListener(
            new DocumentListener() {
              private void updateEndIndex() {
                final boolean state = myEntriesLimitUpdateEnabled;
                myEntriesLimitUpdateEnabled = false;
                try {
                  if (myIndexUpdateEnabled) {
                    myEndIndex.setText(
                        String.valueOf(getInt(myEntriesLimit) + getInt(myStartIndex) - 1));
                  }
                } finally {
                  myEntriesLimitUpdateEnabled = state;
                }
              }

              public void insertUpdate(DocumentEvent e) {
                updateEndIndex();
              }

              public void removeUpdate(DocumentEvent e) {
                updateEndIndex();
              }

              public void changedUpdate(DocumentEvent e) {
                updateEndIndex();
              }
            });
    return myPanel;
  }
Пример #5
0
  private void initComponents() {
    nameText.setComponentPopupMenu(TextFieldPopupMenu.INSTANCE);
    titleText.setComponentPopupMenu(TextFieldPopupMenu.INSTANCE);
    gameVersionText.setComponentPopupMenu(TextFieldPopupMenu.INSTANCE);
    launchFlagsArea.setComponentPopupMenu(TextFieldPopupMenu.INSTANCE);
    userFilesIncludeArea.setComponentPopupMenu(TextFieldPopupMenu.INSTANCE);

    launchFlagsArea.setFont(nameText.getFont());
    userFilesIncludeArea.setFont(nameText.getFont());
    userFilesExcludeArea.setFont(nameText.getFont());

    JTabbedPane tabbedPane = new JTabbedPane();

    JPanel container = new JPanel();
    container.setLayout(new MigLayout("fill, insets dialog"));

    tabbedPane.addTab("Modpack", null, createMainPanel());
    tabbedPane.addTab("Launch", null, createLaunchPanel());
    tabbedPane.addTab("User Files", null, createUserFilesPanel());
    tabbedPane.addTab("Optional Features", null, createFeaturesPanel());

    container.add(tabbedPane, "span, grow, gapbottom unrel");

    JButton saveButton = new JButton("Save");
    JButton cancelButton = new JButton("Cancel");

    container.add(saveButton, "tag ok, span, split 2, sizegroup bttn");
    container.add(cancelButton, "tag cancel, sizegroup bttn");

    getRootPane().setDefaultButton(saveButton);
    getRootPane()
        .registerKeyboardAction(
            event -> cancelButton.doClick(),
            KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0),
            JComponent.WHEN_IN_FOCUSED_WINDOW);

    add(container, BorderLayout.CENTER);

    saveButton.addActionListener(
        e -> {
          if (nameText.getText().trim().isEmpty()) {
            SwingHelper.showErrorDialog(
                BuilderConfigDialog.this, "The 'Name' field cannot be empty.", "Input Error");
            return;
          }

          if (gameVersionText.getText().trim().isEmpty()) {
            SwingHelper.showErrorDialog(
                BuilderConfigDialog.this,
                "The 'Game Version' field must be a Minecraft version.",
                "Input Error");
            return;
          }

          copyTo();
          saved = true;
          dispose();
        });

    cancelButton.addActionListener(e -> dispose());

    TableSearchable tableSearchable = SearchableUtils.installSearchable(featuresTable);
    tableSearchable.setMainIndex(-1);
  }
Пример #6
0
 public Font getFont() {
   return example.getFont();
 }