Esempio n. 1
0
 /** force the search button to be large enough for the longer of the two texts */
 private void setSearchButtonSizes() {
   search.setText(Globals.lang("Search specified field(s)"));
   Dimension size1 = search.getPreferredSize();
   search.setText(Globals.lang("Search all fields"));
   Dimension size2 = search.getPreferredSize();
   size2.width = Math.max(size1.width, size2.width);
   search.setMinimumSize(size2);
   search.setPreferredSize(size2);
 }
Esempio n. 2
0
  /**
   * Computer the maximum width of the ok, cancel and continue buttons and set the okCancelDimension
   * to be representative of that size.
   */
  private static void computeButtonWidths() {
    if (okCancelDimension != null) return;

    JButton okButton = new JButton(getOkLabel());
    JButton cancelButton = new JButton(getCancelLabel());
    JButton continueButton = new JButton(getContinueLabel());

    int maxWidth =
        Math.max(cancelButton.getPreferredSize().width, okButton.getPreferredSize().width);
    maxWidth = Math.max(maxWidth, continueButton.getPreferredSize().width);

    okCancelDimension = new Dimension(maxWidth, okButton.getPreferredSize().height);
  }
 /**
  * The class constructor.
  *
  * <p>Adds and creates a message saying bye.
  */
 public Instruction2() {
   setLayout(null);
   JButton back = new JButton(new ImageIcon("Back.png"));
   back.setOpaque(false);
   back.setContentAreaFilled(false);
   back.setBorderPainted(false);
   back.setFocusable(false);
   back.setRolloverIcon(new ImageIcon("Backrollover.png"));
   back.setActionCommand("Back");
   back.addActionListener(this);
   JLabel pic = new JLabel(new ImageIcon("Instructions2.png"));
   pic.setBounds(0, 0, pic.getPreferredSize().width, pic.getPreferredSize().height);
   back.setBounds(5, 200, back.getPreferredSize().width, back.getPreferredSize().height);
   add(pic);
   add(back);
 }
Esempio n. 4
0
  // constructor of TextFrame
  public TextFrame() {
    // this.message = message;
    message = "Click to Edit Text";
    messageFont = new Font("Arial", Font.PLAIN, 30);
    foreground = Color.black;
    background = Color.white;

    // custom dialog (it's a private class inside TextFrame)
    cd = new CustomDialog(this);

    messageField = new JTextField();
    messageField.setPreferredSize(new Dimension(300, 200));
    messageField.setEditable(false);
    messageField.setHorizontalAlignment(SwingConstants.CENTER);
    messageField.setAlignmentX(Component.CENTER_ALIGNMENT);
    updateMessage();

    customize = new JButton("Customize");
    customize.setMaximumSize(customize.getPreferredSize());
    customize.setAlignmentX(Component.CENTER_ALIGNMENT);

    apply = new JButton("Apply");
    apply.setMaximumSize(customize.getPreferredSize());
    apply.setAlignmentX(Component.CENTER_ALIGNMENT);

    /*add the listeners*/
    customize.addActionListener(this);
    apply.addActionListener(this);
    messageField.addMouseListener(new PopUpClass());

    // customize
    JPanel p = new JPanel();
    p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS));
    p.add(customize);
    p.add(Box.createRigidArea(new Dimension(0, 25)));
    p.add(messageField);
    p.add(Box.createRigidArea(new Dimension(0, 25)));
    p.add(apply);
    p.setBorder(BorderFactory.createEmptyBorder(25, 25, 25, 25));

    // make panel this JFrame's content pane

    this.setContentPane(p);
  }
Esempio n. 5
0
 public void doLayout() {
   if (isStuck()) {
     Dimension size = getSize();
     Dimension unStickSize = unstickButton.getPreferredSize();
     int x = size.width - unStickSize.width;
     int y = size.height / 2 - unStickSize.height / 2;
     unstickButton.setSize(unStickSize);
     unstickButton.setLocation(x, y);
   }
 }
  public MavenProjectImportStep(WizardContext wizardContext) {
    super(wizardContext);

    myImportingSettingsForm =
        new MavenImportingSettingsForm(true, wizardContext.isCreatingNewProject()) {
          public String getDefaultModuleDir() {
            return myRootPathComponent.getPath();
          }
        };

    myRootPathComponent =
        new NamePathComponent(
            "",
            ProjectBundle.message("maven.import.label.select.root"),
            ProjectBundle.message("maven.import.title.select.root"),
            "",
            false,
            false);

    JButton envSettingsButton =
        new JButton(ProjectBundle.message("maven.import.environment.settings"));
    envSettingsButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            ShowSettingsUtil.getInstance()
                .editConfigurable(myPanel, new MavenEnvironmentConfigurable());
          }
        });

    myPanel = new JPanel(new GridBagLayout());
    myPanel.setBorder(BorderFactory.createEtchedBorder());

    GridBagConstraints c = new GridBagConstraints();
    c.gridx = 0;
    c.gridy = 0;
    c.weightx = 1;
    c.fill = GridBagConstraints.HORIZONTAL;
    c.insets = JBUI.insets(4, 4, 0, 4);

    myPanel.add(myRootPathComponent, c);

    c.gridy = 1;
    c.insets = JBUI.insets(4, 4, 0, 4);
    myPanel.add(myImportingSettingsForm.createComponent(), c);

    c.gridy = 2;
    c.fill = GridBagConstraints.NONE;
    c.anchor = GridBagConstraints.NORTHEAST;
    c.weighty = 1;
    c.insets = JBUI.insets(4 + envSettingsButton.getPreferredSize().height, 4, 4, 4);
    myPanel.add(envSettingsButton, c);

    myRootPathComponent.setNameComponentVisible(false);
  }
Esempio n. 7
0
  /**
   * Creates a button pane in which the given buttons are neatly aligned with proper spacings.
   *
   * @param aButtons the buttons to add to the created button pane, will be added in the given
   *     order.
   * @return the button pane, never <code>null</code>.
   */
  public static JComponent createButtonPane(final JButton... aButtons) {
    if ((aButtons == null) || (aButtons.length < 1)) {
      throw new IllegalArgumentException("Need at least one button!");
    }

    final JPanel buttonPane = new JPanel();
    buttonPane.setLayout(new BoxLayout(buttonPane, BoxLayout.LINE_AXIS));
    buttonPane.setBorder(
        BorderFactory.createEmptyBorder(
            BUTTONS_PADDING_TOP,
            BUTTONS_PADDING_LEFT,
            BUTTONS_PADDING_BOTTOM,
            BUTTONS_PADDING_RIGHT));

    buttonPane.add(Box.createHorizontalGlue());

    // we want equally sized buttons, so we are recording preferred sizes while
    // adding the buttons and set them to the maximum afterwards...
    int width = 1;
    int height = 1;

    for (JButton button : aButtons) {
      width = Math.max(width, button.getPreferredSize().width);
      height = Math.max(height, button.getPreferredSize().height);

      buttonPane.add(Box.createHorizontalStrut(BUTTONS_SPACING_DEFAULT));
      buttonPane.add(button);
    }

    buttonPane.add(Box.createHorizontalStrut(BUTTONS_SPACING_DEFAULT));

    final Dimension newDims = new Dimension(width, height);

    // everything added; let's set all sizes
    for (final JButton button : aButtons) {
      button.setPreferredSize(newDims);
    }

    return buttonPane;
  }
Esempio n. 8
0
 protected void setButtonsSize() {
   int nMaxWidth = 0, nMaxHeight = 0;
   Dimension objSize;
   Iterator objIterator = buttons.values().iterator();
   while (objIterator.hasNext()) {
     JButton objButton = (JButton) objIterator.next();
     objButton.setPreferredSize(null);
     objSize = objButton.getPreferredSize();
     nMaxWidth = Math.max(nMaxWidth, objSize.width);
     nMaxHeight = Math.max(nMaxHeight, objSize.height);
   }
   objSize = new Dimension(nMaxWidth, nMaxHeight);
   d = objSize;
   objIterator = buttons.values().iterator();
   while (objIterator.hasNext()) {
     ((JButton) objIterator.next()).setPreferredSize(objSize);
   }
 }
Esempio n. 9
0
  public final void createNotificationUI() {
    JButton createMasks = new JButton("Recreate Bathymetry Masks");
    createMasks.setPreferredSize(createMasks.getPreferredSize());
    createMasks.setMinimumSize(createMasks.getPreferredSize());
    createMasks.setMaximumSize(createMasks.getPreferredSize());

    createMasks.addActionListener(
        new ActionListener() {

          public void actionPerformed(ActionEvent event) {
            bathymetryData.setDeleteMasks(true);
            dispose();
          }
        });

    JButton cancelButton = new JButton("Cancel");
    cancelButton.setPreferredSize(cancelButton.getPreferredSize());
    cancelButton.setMinimumSize(cancelButton.getPreferredSize());
    cancelButton.setMaximumSize(cancelButton.getPreferredSize());

    cancelButton.addActionListener(
        new ActionListener() {

          public void actionPerformed(ActionEvent event) {
            dispose();
          }
        });

    JLabel filler = new JLabel("                            ");

    JPanel buttonsJPanel = new JPanel(new GridBagLayout());
    buttonsJPanel.add(
        cancelButton,
        new ExGridBagConstraints(0, 0, 1, 0, GridBagConstraints.WEST, GridBagConstraints.NONE));
    buttonsJPanel.add(
        filler,
        new ExGridBagConstraints(
            1, 0, 0, 0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL));
    buttonsJPanel.add(
        createMasks,
        new ExGridBagConstraints(2, 0, 1, 0, GridBagConstraints.EAST, GridBagConstraints.NONE));
    buttonsJPanel.add(
        helpButton,
        new ExGridBagConstraints(3, 0, 1, 0, GridBagConstraints.EAST, GridBagConstraints.NONE));

    JLabel jLabel = new JLabel("Bathymetry has already been created for this product");

    JPanel jPanel = new JPanel(new GridBagLayout());
    jPanel.add(
        jLabel,
        new ExGridBagConstraints(0, 0, 0, 0, GridBagConstraints.CENTER, GridBagConstraints.NONE));
    jPanel.add(
        buttonsJPanel,
        new ExGridBagConstraints(0, 1, 0, 0, GridBagConstraints.CENTER, GridBagConstraints.NONE));

    add(jPanel);

    setModalityType(ModalityType.APPLICATION_MODAL);

    setTitle("Bathymetry");
    setDefaultCloseOperation(DISPOSE_ON_CLOSE);
    setLocationRelativeTo(null);
    pack();

    setPreferredSize(getPreferredSize());
    setMinimumSize(getPreferredSize());
    setMaximumSize(getPreferredSize());
    setSize(getPreferredSize());
  }
Esempio n. 10
0
  public final void createBathymetryUI(boolean bandCreated) {

    final int rightInset = 5;

    final MaskEnabledAllBandsCheckbox maskEnabledAllBandsCheckbox =
        new MaskEnabledAllBandsCheckbox(bathymetryData);
    final MaskTransparencySpinner maskTransparencySpinner =
        new MaskTransparencySpinner(bathymetryData);
    final MaskColorComboBox maskColorComboBox = new MaskColorComboBox(bathymetryData);
    final MaskMaxDepthTextfield maskMaxDepthTextfield = new MaskMaxDepthTextfield(bathymetryData);
    final MaskMinDepthTextfield maskMinDepthTextfield = new MaskMinDepthTextfield(bathymetryData);

    final boolean[] fileSelectorEnabled = {true};

    if (bandCreated) {
      fileSelectorEnabled[0] = false;
    } else {
      fileSelectorEnabled[0] = true;
    }

    final ResolutionComboBox resolutionComboBox = new ResolutionComboBox(bathymetryData);

    JPanel resolutionSamplingPanel = new JPanel(new GridBagLayout());
    resolutionSamplingPanel.setBorder(BorderFactory.createTitledBorder(""));

    if (fileSelectorEnabled[0]) {
      resolutionSamplingPanel.add(
          resolutionComboBox.getjLabel(),
          new ExGridBagConstraints(
              0,
              0,
              0,
              0,
              GridBagConstraints.EAST,
              GridBagConstraints.NONE,
              new Insets(0, 0, 0, rightInset)));

      JComboBox jComboBox = resolutionComboBox.getjComboBox();
      jComboBox.setEnabled(fileSelectorEnabled[0]);

      bathymetryData.addPropertyChangeListener(
          BathymetryData.PROMPT_REQUEST_TO_INSTALL_FILE_EVENT,
          new PropertyChangeListener() {
            @Override
            public void propertyChange(PropertyChangeEvent evt) {
              SourceFileInfo sourceFileInfo =
                  (SourceFileInfo) resolutionComboBox.getjComboBox().getSelectedItem();

              InstallResolutionFileDialog dialog =
                  new InstallResolutionFileDialog(
                      bathymetryData,
                      sourceFileInfo,
                      InstallResolutionFileDialog.Step.INSTALLATION);
              dialog.setVisible(true);
              dialog.setEnabled(true);
            }
          });

      resolutionSamplingPanel.add(
          jComboBox,
          new ExGridBagConstraints(1, 0, 0, 0, GridBagConstraints.WEST, GridBagConstraints.NONE));
    } else {
      resolutionSamplingPanel.add(
          new JLabel("Note: Cannot recreate a different band, only a different mask"),
          new ExGridBagConstraints(1, 0, 0, 0, GridBagConstraints.WEST, GridBagConstraints.NONE));
    }

    JPanel maskJPanel = new JPanel(new GridBagLayout());
    maskJPanel.setBorder(BorderFactory.createTitledBorder(""));

    JTextField maskNameTextfield = new JTextField(bathymetryData.getMaskName());
    maskNameTextfield.setEditable(false);
    maskNameTextfield.setToolTipText("Name of the mask (this field is not editable)");

    maskJPanel.add(
        new JLabel("Mask Name"),
        new ExGridBagConstraints(
            0,
            0,
            0,
            0,
            GridBagConstraints.EAST,
            GridBagConstraints.NONE,
            new Insets(0, 0, 0, rightInset)));

    maskJPanel.add(
        maskNameTextfield,
        new ExGridBagConstraints(1, 0, 0, 0, GridBagConstraints.WEST, GridBagConstraints.NONE));

    maskJPanel.add(
        maskColorComboBox.getjLabel(),
        new ExGridBagConstraints(
            0,
            1,
            0,
            0,
            GridBagConstraints.EAST,
            GridBagConstraints.NONE,
            new Insets(0, 0, 0, rightInset)));

    maskJPanel.add(
        maskColorComboBox.getColorExComboBox(),
        new ExGridBagConstraints(1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.NONE));

    maskJPanel.add(
        maskTransparencySpinner.getjLabel(),
        new ExGridBagConstraints(
            0,
            2,
            0,
            0,
            GridBagConstraints.EAST,
            GridBagConstraints.NONE,
            new Insets(0, 0, 0, rightInset)));

    maskJPanel.add(
        maskTransparencySpinner.getjSpinner(),
        new ExGridBagConstraints(1, 2, 0, 0, GridBagConstraints.WEST, GridBagConstraints.NONE));

    maskJPanel.add(
        maskMaxDepthTextfield.getjLabel(),
        new ExGridBagConstraints(
            0,
            3,
            0,
            0,
            GridBagConstraints.EAST,
            GridBagConstraints.NONE,
            new Insets(0, 0, 0, rightInset)));

    maskJPanel.add(
        maskMaxDepthTextfield.getjTextField(),
        new ExGridBagConstraints(1, 3, 0, 0, GridBagConstraints.WEST, GridBagConstraints.NONE));

    maskJPanel.add(
        maskMinDepthTextfield.getjLabel(),
        new ExGridBagConstraints(
            0,
            4,
            0,
            0,
            GridBagConstraints.EAST,
            GridBagConstraints.NONE,
            new Insets(0, 0, 0, rightInset)));

    maskJPanel.add(
        maskMinDepthTextfield.getjTextField(),
        new ExGridBagConstraints(1, 4, 0, 0, GridBagConstraints.WEST, GridBagConstraints.NONE));

    maskJPanel.add(
        maskEnabledAllBandsCheckbox.getjLabel(),
        new ExGridBagConstraints(
            0,
            5,
            0,
            0,
            GridBagConstraints.EAST,
            GridBagConstraints.NONE,
            new Insets(0, 0, 0, rightInset)));

    maskJPanel.add(
        maskEnabledAllBandsCheckbox.getjCheckBox(),
        new ExGridBagConstraints(1, 5, 0, 0, GridBagConstraints.WEST, GridBagConstraints.NONE));

    JPanel mainPanel = new JPanel(new GridBagLayout());

    mainPanel.add(
        resolutionSamplingPanel,
        new ExGridBagConstraints(
            0, 0, 0, 0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, 3));

    mainPanel.add(
        maskJPanel,
        new ExGridBagConstraints(
            0, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, 3));

    String label;
    if (bandCreated) {
      label = "Recreate Bathymetry Mask";
    } else {
      label = "Create Bathymetry Band and Mask";
    }
    JButton createMasks = new JButton(label);
    createMasks.setPreferredSize(createMasks.getPreferredSize());
    createMasks.setMinimumSize(createMasks.getPreferredSize());
    createMasks.setMaximumSize(createMasks.getPreferredSize());

    createMasks.addActionListener(
        new ActionListener() {

          public void actionPerformed(ActionEvent event) {
            bathymetryData.setCreateMasks(true);
            dispose();
          }
        });

    JButton cancelButton = new JButton("Cancel");
    cancelButton.setPreferredSize(cancelButton.getPreferredSize());
    cancelButton.setMinimumSize(cancelButton.getPreferredSize());
    cancelButton.setMaximumSize(cancelButton.getPreferredSize());

    cancelButton.addActionListener(
        new ActionListener() {

          public void actionPerformed(ActionEvent event) {
            dispose();
          }
        });

    JLabel filler = new JLabel("                            ");

    JPanel buttonsJPanel = new JPanel(new GridBagLayout());
    buttonsJPanel.add(
        cancelButton,
        new ExGridBagConstraints(0, 0, 1, 0, GridBagConstraints.WEST, GridBagConstraints.NONE));
    buttonsJPanel.add(
        filler,
        new ExGridBagConstraints(
            1, 0, 0, 0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL));
    buttonsJPanel.add(
        createMasks,
        new ExGridBagConstraints(2, 0, 1, 0, GridBagConstraints.EAST, GridBagConstraints.NONE));
    buttonsJPanel.add(
        helpButton,
        new ExGridBagConstraints(3, 0, 1, 0, GridBagConstraints.EAST, GridBagConstraints.NONE));

    createMasks.setAlignmentX(0.5f);

    mainPanel.add(
        buttonsJPanel,
        new ExGridBagConstraints(0, 4, 0, 0, GridBagConstraints.WEST, GridBagConstraints.NONE, 5));

    add(mainPanel);

    setModalityType(ModalityType.APPLICATION_MODAL);

    setTitle("Bathymetry");
    setDefaultCloseOperation(DISPOSE_ON_CLOSE);
    setLocationRelativeTo(null);
    pack();

    setPreferredSize(getPreferredSize());
    setMinimumSize(getPreferredSize());
    setMaximumSize(getPreferredSize());
    setSize(getPreferredSize());
  }
Esempio n. 11
0
  /**
   * Standard constructor: it needs the parent frame.
   *
   * @param parent the dialog's parent
   */
  public DialogPrint(JFrame parent) {
    super(400, 350, parent, Globals.messages.getString("Print_dlg"), true);
    addComponentListener(this);
    export = false;

    // Ensure that under MacOSX >= 10.5 Leopard, this dialog will appear
    // as a document modal sheet

    getRootPane().putClientProperty("apple.awt.documentModalSheet", Boolean.TRUE);

    GridBagLayout bgl = new GridBagLayout();
    GridBagConstraints constraints = new GridBagConstraints();
    Container contentPane = getContentPane();
    contentPane.setLayout(bgl);

    constraints.insets.right = 30;

    JLabel empty = new JLabel("  ");
    constraints.weightx = 100;
    constraints.weighty = 100;
    constraints.gridx = 0;
    constraints.gridy = 0;
    constraints.gridwidth = 1;
    constraints.gridheight = 1;
    contentPane.add(empty, constraints); // Add "   " label

    JLabel empty1 = new JLabel("  ");
    constraints.weightx = 100;
    constraints.weighty = 100;
    constraints.gridx = 3;
    constraints.gridy = 0;
    constraints.gridwidth = 1;
    constraints.gridheight = 1;
    contentPane.add(empty1, constraints); // Add "   " label

    mirror_CB = new JCheckBox(Globals.messages.getString("Mirror"));
    constraints.gridx = 1;
    constraints.gridy = 0;
    constraints.gridwidth = 2;
    constraints.gridheight = 1;
    constraints.anchor = GridBagConstraints.WEST;
    contentPane.add(mirror_CB, constraints); // Add Print Mirror cb

    fit_CB = new JCheckBox(Globals.messages.getString("FitPage"));
    constraints.gridx = 1;
    constraints.gridy = 1;
    constraints.gridwidth = 2;
    constraints.gridheight = 1;
    constraints.anchor = GridBagConstraints.WEST;
    contentPane.add(fit_CB, constraints); // Add Fit to page cb

    bw_CB = new JCheckBox(Globals.messages.getString("B_W"));
    constraints.gridx = 1;
    constraints.gridy = 2;
    constraints.gridwidth = 2;
    constraints.gridheight = 1;
    constraints.anchor = GridBagConstraints.WEST;
    contentPane.add(bw_CB, constraints); // Add BlackWhite cb

    landscape_CB = new JCheckBox(Globals.messages.getString("Landscape"));
    constraints.gridx = 1;
    constraints.gridy = 3;
    constraints.gridwidth = 2;
    constraints.gridheight = 1;
    constraints.anchor = GridBagConstraints.WEST;
    contentPane.add(landscape_CB, constraints); // Add landscape cb

    // Put the OK and Cancel buttons and make them active.
    JButton ok = new JButton(Globals.messages.getString("Ok_btn"));
    JButton cancel = new JButton(Globals.messages.getString("Cancel_btn"));

    constraints.gridx = 0;
    constraints.gridy = 4;
    constraints.gridwidth = 4;
    constraints.gridheight = 1;
    constraints.anchor = GridBagConstraints.EAST;

    // Put the OK and Cancel buttons and make them active.
    Box b = Box.createHorizontalBox();
    b.add(Box.createHorizontalGlue());
    ok.setPreferredSize(cancel.getPreferredSize());

    if (Globals.okCancelWinOrder) {
      b.add(ok);
      b.add(Box.createHorizontalStrut(12));
      b.add(cancel);

    } else {
      b.add(cancel);
      b.add(Box.createHorizontalStrut(12));
      b.add(ok);
    }

    ok.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent evt) {
            export = true;
            setVisible(false);
          }
        });
    cancel.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent evt) {
            setVisible(false);
          }
        });
    // Here is an action in which the dialog is closed

    AbstractAction cancelAction =
        new AbstractAction() {
          public void actionPerformed(ActionEvent e) {
            setVisible(false);
          }
        };
    contentPane.add(b, constraints); // Add OK/cancel dialog

    DialogUtil.addCancelEscape(this, cancelAction);
    pack();
    DialogUtil.center(this);
    getRootPane().setDefaultButton(ok);
  }
Esempio n. 12
0
  public LoginPanel(Image img, ActionListener listener) {
    super(null);
    this.listener = listener;
    if (img == null) {
      InputStream inData = getClass().getResourceAsStream("/resources/background.gif");
      BufferedImage back = null;
      if (inData != null)
        try {
          back = ImageIO.read(inData);
        } catch (IOException e) {
          loger.finest("LoginPanel class can't get the background image");
        }
      this.background = back;
    }

    setLayout(null);
    JPanel logingPanel = new JPanel();
    loginTitle = new JLabel("Autentificare");
    logingPanel.setSize(250, 150);
    logingPanel.setBorder(new javax.swing.border.LineBorder(Color.black, 2));
    logingPanel.setLayout(null);
    loginTitle.setBounds(3, 0, logingPanel.getWidth(), 20);
    logingPanel.add(loginTitle);
    JLabel loginUser = new JLabel("Utilizator");
    loginUser.setBounds(
        80 - loginUser.getPreferredSize().width,
        40,
        loginUser.getPreferredSize().width,
        loginUser.getPreferredSize().height);
    logingPanel.add(loginUser);
    user = new JTextField(10);
    user.setBounds(85, 40, user.getPreferredSize().width, user.getPreferredSize().height);
    // user.setText("test");
    // loginUser.setLabelFor(user);
    logingPanel.add(user);
    JLabel loginPass = new JLabel("Parola");
    loginPass.setBounds(
        80 - loginPass.getPreferredSize().width,
        80,
        loginPass.getPreferredSize().width,
        loginPass.getPreferredSize().height);
    logingPanel.add(loginPass);
    // JTextField pass = new JTextField(10);
    pass = new JPasswordField(10);
    pass.setBounds(85, 80, pass.getPreferredSize().width, pass.getPreferredSize().height);
    pass.addKeyListener(this);
    // pass.setText("test");
    // loginUser.setLabelFor(user);
    logingPanel.add(pass);
    JButton loginButton = new JButton("Start");
    loginButton.setActionCommand("LOGIN");
    loginButton.setBounds(
        60, 110, loginButton.getPreferredSize().width, loginButton.getPreferredSize().height);
    // loginButton.setOpaque(false);
    loginButton.setFocusPainted(false);
    // loginButton.setContentAreaFilled(false);
    // loginButton.setBorderPainted(false);
    loginButton.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
    loginButton.addActionListener(listener);
    logingPanel.add(loginButton);

    add(logingPanel);
  }
Esempio n. 13
0
  private void setupRightSideToolBar() {
    JToolBar fixedTools = new JToolBar();
    fixedTools.setOrientation(JToolBar.HORIZONTAL);

    JButton cutB = new JButton(new ImageIcon(loadIcon(ICON_PATH + "cut.png").getImage()));
    cutB.setBorder(BorderFactory.createEmptyBorder(0, 8, 0, 0));
    cutB.setToolTipText("Cut selected (Ctrl+X)");
    JButton copyB = new JButton(new ImageIcon(loadIcon(ICON_PATH + "page_copy.png").getImage()));
    copyB.setBorder(BorderFactory.createEmptyBorder(0, 8, 0, 0));
    copyB.setToolTipText("Copy selected (Ctrl+C)");
    JButton pasteB = new JButton(new ImageIcon(loadIcon(ICON_PATH + "paste_plain.png").getImage()));
    pasteB.setBorder(BorderFactory.createEmptyBorder(0, 8, 0, 0));
    pasteB.setToolTipText("Paste from clipboard (Ctrl+V)");
    JButton deleteB = new JButton(new ImageIcon(loadIcon(ICON_PATH + "delete.png").getImage()));
    deleteB.setBorder(BorderFactory.createEmptyBorder(0, 8, 0, 0));
    deleteB.setToolTipText("Delete selected (DEL)");
    final JToggleButton snapToGridB =
        new JToggleButton(new ImageIcon(loadIcon(ICON_PATH + "shape_handles.png").getImage()));
    // m_snapToGridB.setBorder(BorderFactory.createEmptyBorder(0, 8, 0, 0));
    snapToGridB.setToolTipText("Snap to grid (Ctrl+G)");
    JButton saveB = new JButton(new ImageIcon(loadIcon(ICON_PATH + "disk.png").getImage()));
    saveB.setBorder(BorderFactory.createEmptyBorder(0, 8, 0, 0));
    saveB.setToolTipText("Save layout (Ctrl+S)");
    JButton saveBB =
        new JButton(new ImageIcon(loadIcon(ICON_PATH + "disk_multiple.png").getImage()));
    saveBB.setBorder(BorderFactory.createEmptyBorder(0, 8, 0, 0));
    saveBB.setToolTipText("Save layout with new name");
    JButton loadB = new JButton(new ImageIcon(loadIcon(ICON_PATH + "folder_add.png").getImage()));
    loadB.setToolTipText("Open (Ctrl+O)");
    loadB.setBorder(BorderFactory.createEmptyBorder(0, 8, 0, 0));
    JButton newB = new JButton(new ImageIcon(loadIcon(ICON_PATH + "page_add.png").getImage()));
    newB.setToolTipText("New layout (Ctrl+N)");
    newB.setBorder(BorderFactory.createEmptyBorder(0, 8, 0, 0));
    newB.setEnabled(m_mainPerspective.getAllowMultipleTabs());
    final JButton helpB = new JButton(new ImageIcon(loadIcon(ICON_PATH + "help.png").getImage()));
    helpB.setBorder(BorderFactory.createEmptyBorder(0, 8, 0, 0));
    helpB.setToolTipText("Display help (Ctrl+H)");
    JButton togglePerspectivesB =
        new JButton(new ImageIcon(loadIcon(ICON_PATH + "cog_go.png").getImage()));
    togglePerspectivesB.setBorder(BorderFactory.createEmptyBorder(0, 8, 0, 0));
    togglePerspectivesB.setToolTipText("Show/hide perspectives toolbar (Ctrl+P)");
    final JButton templatesB =
        new JButton(new ImageIcon(loadIcon(ICON_PATH + "application_view_tile.png").getImage()));
    templatesB.setBorder(BorderFactory.createEmptyBorder(0, 8, 0, 0));
    templatesB.setToolTipText("Load a template layout");
    JButton noteB = new JButton(new ImageIcon(loadIcon(ICON_PATH + "note_add.png").getImage()));
    noteB.setBorder(BorderFactory.createEmptyBorder(0, 8, 0, 0));
    noteB.setToolTipText("Add a note to the layout (Ctrl+I)");
    JButton selectAllB =
        new JButton(new ImageIcon(loadIcon(ICON_PATH + "shape_group.png").getImage()));
    selectAllB.setBorder(BorderFactory.createEmptyBorder(0, 8, 0, 0));
    selectAllB.setToolTipText("Select all (Ctrl+A)");
    final JButton zoomInB =
        new JButton(new ImageIcon(loadIcon(ICON_PATH + "zoom_in.png").getImage()));
    zoomInB.setBorder(BorderFactory.createEmptyBorder(0, 8, 0, 0));
    zoomInB.setToolTipText("Zoom in (Ctrl++)");
    final JButton zoomOutB =
        new JButton(new ImageIcon(loadIcon(ICON_PATH + "zoom_out.png").getImage()));
    zoomOutB.setBorder(BorderFactory.createEmptyBorder(0, 8, 0, 0));
    zoomOutB.setToolTipText("Zoom out (Ctrl+-)");
    JButton undoB = new JButton(new ImageIcon(loadIcon(ICON_PATH + "arrow_undo.png").getImage()));
    undoB.setBorder(BorderFactory.createEmptyBorder(0, 8, 0, 0));
    undoB.setToolTipText("Undo (Ctrl+U)");

    // actions
    final Action saveAction =
        new AbstractAction("Save") {
          @Override
          public void actionPerformed(ActionEvent e) {
            if (m_mainPerspective.getCurrentTabIndex() >= 0) {
              m_mainPerspective.saveLayout(m_mainPerspective.getCurrentTabIndex(), false);
            }
          }
        };
    KeyStroke saveKey = KeyStroke.getKeyStroke(KeyEvent.VK_S, InputEvent.CTRL_DOWN_MASK);
    m_mainPerspective.getActionMap().put("Save", saveAction);
    m_mainPerspective.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(saveKey, "Save");
    saveB.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            saveAction.actionPerformed(e);
          }
        });

    KeyStroke saveAsKey = KeyStroke.getKeyStroke(KeyEvent.VK_Y, InputEvent.CTRL_DOWN_MASK);
    final Action saveAsAction =
        new AbstractAction() {
          @Override
          public void actionPerformed(ActionEvent e) {
            m_mainPerspective.saveLayout(m_mainPerspective.getCurrentTabIndex(), true);
          }
        };
    m_mainPerspective.getActionMap().put("SaveAS", saveAsAction);
    m_mainPerspective.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(saveAsKey, "SaveAS");

    saveBB.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            saveAsAction.actionPerformed(e);
          }
        });

    final Action openAction =
        new AbstractAction("Open") {
          @Override
          public void actionPerformed(ActionEvent e) {
            m_mainPerspective.loadLayout();
          }
        };
    KeyStroke openKey = KeyStroke.getKeyStroke(KeyEvent.VK_O, InputEvent.CTRL_DOWN_MASK);
    m_mainPerspective.getActionMap().put("Open", openAction);
    m_mainPerspective.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(openKey, "Open");
    loadB.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            openAction.actionPerformed(e);
          }
        });

    final Action newAction =
        new AbstractAction("New") {
          @Override
          public void actionPerformed(ActionEvent e) {
            m_mainPerspective.addUntitledTab();
          }
        };
    KeyStroke newKey = KeyStroke.getKeyStroke(KeyEvent.VK_N, InputEvent.CTRL_DOWN_MASK);
    m_mainPerspective.getActionMap().put("New", newAction);
    m_mainPerspective.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(newKey, "New");
    newB.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent ae) {
            newAction.actionPerformed(ae);
          }
        });

    final Action selectAllAction =
        new AbstractAction("SelectAll") {
          @Override
          public void actionPerformed(ActionEvent e) {
            if (m_mainPerspective.getCurrentLayout() != null
                && m_mainPerspective.getCurrentLayout().numSteps() > 0) {
              List<StepVisual> newSelected = newSelected = new ArrayList<StepVisual>();
              newSelected.addAll(m_mainPerspective.getCurrentLayout().getRenderGraph());

              // toggle
              if (newSelected.size()
                  == m_mainPerspective.getCurrentLayout().getSelectedSteps().size()) {
                // unselect all
                m_mainPerspective.getCurrentLayout().setSelectedSteps(new ArrayList<StepVisual>());
              } else {
                // select all
                m_mainPerspective.getCurrentLayout().setSelectedSteps(newSelected);
              }
              m_mainPerspective.revalidate();
              m_mainPerspective.repaint();
              m_mainPerspective.notifyIsDirty();
            }
          }
        };
    KeyStroke selectAllKey = KeyStroke.getKeyStroke(KeyEvent.VK_A, InputEvent.CTRL_DOWN_MASK);
    m_mainPerspective.getActionMap().put("SelectAll", selectAllAction);
    m_mainPerspective.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(selectAllKey, "SelectAll");
    selectAllB.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            selectAllAction.actionPerformed(e);
          }
        });

    final Action zoomInAction =
        new AbstractAction("ZoomIn") {
          @Override
          public void actionPerformed(ActionEvent e) {
            if (m_mainPerspective.getCurrentLayout() != null) {
              int z = m_mainPerspective.getCurrentLayout().getZoomSetting();
              z += 25;
              zoomOutB.setEnabled(true);
              if (z >= 200) {
                z = 200;
                zoomInB.setEnabled(false);
              }
              m_mainPerspective.getCurrentLayout().setZoomSetting(z);
              m_mainPerspective.revalidate();
              m_mainPerspective.repaint();
              m_mainPerspective.notifyIsDirty();
            }
          }
        };
    KeyStroke zoomInKey = KeyStroke.getKeyStroke(KeyEvent.VK_EQUALS, InputEvent.CTRL_DOWN_MASK);
    m_mainPerspective.getActionMap().put("ZoomIn", zoomInAction);
    m_mainPerspective.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(zoomInKey, "ZoomIn");
    zoomInB.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            zoomInAction.actionPerformed(e);
          }
        });

    final Action zoomOutAction =
        new AbstractAction("ZoomOut") {
          @Override
          public void actionPerformed(ActionEvent e) {
            if (m_mainPerspective.getCurrentLayout() != null) {
              int z = m_mainPerspective.getCurrentLayout().getZoomSetting();
              z -= 25;
              zoomInB.setEnabled(true);
              if (z <= 50) {
                z = 50;
                zoomOutB.setEnabled(false);
              }
              m_mainPerspective.getCurrentLayout().setZoomSetting(z);
              m_mainPerspective.revalidate();
              m_mainPerspective.repaint();
              m_mainPerspective.notifyIsDirty();
            }
          }
        };
    KeyStroke zoomOutKey = KeyStroke.getKeyStroke(KeyEvent.VK_MINUS, InputEvent.CTRL_DOWN_MASK);
    m_mainPerspective.getActionMap().put("ZoomOut", zoomOutAction);
    m_mainPerspective.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(zoomOutKey, "ZoomOut");
    zoomOutB.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            zoomOutAction.actionPerformed(e);
          }
        });

    final Action cutAction =
        new AbstractAction("Cut") {
          @Override
          public void actionPerformed(ActionEvent e) {
            if (m_mainPerspective.getCurrentLayout() != null
                && m_mainPerspective.getCurrentLayout().getSelectedSteps().size() > 0) {
              try {
                m_mainPerspective.getCurrentLayout().copySelectedStepsToClipboard();
                m_mainPerspective.getCurrentLayout().removeSelectedSteps();
              } catch (WekaException e1) {
                m_mainPerspective.showErrorDialog(e1);
              }
            }
          }
        };
    KeyStroke cutKey = KeyStroke.getKeyStroke(KeyEvent.VK_X, InputEvent.CTRL_DOWN_MASK);
    m_mainPerspective.getActionMap().put("Cut", cutAction);
    m_mainPerspective.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(cutKey, "Cut");
    cutB.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            cutAction.actionPerformed(e);
          }
        });

    final Action deleteAction =
        new AbstractAction("Delete") {
          @Override
          public void actionPerformed(ActionEvent e) {
            if (m_mainPerspective.getCurrentLayout() != null) {
              try {
                m_mainPerspective.getCurrentLayout().removeSelectedSteps();
              } catch (WekaException e1) {
                m_mainPerspective.showErrorDialog(e1);
              }
            }
          }
        };
    KeyStroke deleteKey = KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0);
    m_mainPerspective.getActionMap().put("Delete", deleteAction);
    m_mainPerspective.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(deleteKey, "Delete");
    deleteB.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            deleteAction.actionPerformed(e);
          }
        });

    final Action copyAction =
        new AbstractAction("Copy") {
          @Override
          public void actionPerformed(ActionEvent e) {
            if (m_mainPerspective.getCurrentLayout() != null
                && m_mainPerspective.getCurrentLayout().getSelectedSteps().size() > 0) {
              try {
                m_mainPerspective.getCurrentLayout().copySelectedStepsToClipboard();
                m_mainPerspective.getCurrentLayout().setSelectedSteps(new ArrayList<StepVisual>());
              } catch (WekaException e1) {
                m_mainPerspective.showErrorDialog(e1);
              }
            }
          }
        };
    KeyStroke copyKey = KeyStroke.getKeyStroke(KeyEvent.VK_C, InputEvent.CTRL_DOWN_MASK);
    m_mainPerspective.getActionMap().put("Copy", copyAction);
    m_mainPerspective.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(copyKey, "Copy");
    copyB.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            copyAction.actionPerformed(e);
          }
        });

    final Action pasteAction =
        new AbstractAction("Paste") {
          @Override
          public void actionPerformed(ActionEvent e) {
            if (m_mainPerspective.getCurrentLayout() != null
                && m_mainPerspective.getPasteBuffer().length() > 0) {
              m_mainPerspective.setCursor(Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR));
              m_mainPerspective
                  .getCurrentLayout()
                  .setFlowLayoutOperation(VisibleLayout.LayoutOperation.PASTING);
            }
          }
        };
    KeyStroke pasteKey = KeyStroke.getKeyStroke(KeyEvent.VK_V, InputEvent.CTRL_DOWN_MASK);
    m_mainPerspective.getActionMap().put("Paste", pasteAction);
    m_mainPerspective.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(pasteKey, "Paste");
    pasteB.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            pasteAction.actionPerformed(e);
          }
        });

    final Action snapAction =
        new AbstractAction("Snap") {
          @Override
          public void actionPerformed(ActionEvent e) {
            // toggle first
            // snapToGridB.setSelected(!snapToGridB.isSelected());
            if (snapToGridB.isSelected()) {
              if (m_mainPerspective.getCurrentLayout() != null) {
                m_mainPerspective.getCurrentLayout().snapSelectedToGrid();
              }
            }
          }
        };
    KeyStroke snapKey = KeyStroke.getKeyStroke(KeyEvent.VK_G, InputEvent.CTRL_DOWN_MASK);
    m_mainPerspective.getActionMap().put("Snap", snapAction);
    m_mainPerspective.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(snapKey, "Snap");
    snapToGridB.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            if (snapToGridB.isSelected()) {
              snapAction.actionPerformed(e);
            }
          }
        });

    final Action noteAction =
        new AbstractAction("Note") {
          @Override
          public void actionPerformed(ActionEvent e) {
            if (m_mainPerspective.getCurrentLayout() != null) {
              m_mainPerspective.getCurrentLayout().initiateAddNote();
            }
          }
        };
    KeyStroke noteKey = KeyStroke.getKeyStroke(KeyEvent.VK_I, InputEvent.CTRL_DOWN_MASK);
    m_mainPerspective.getActionMap().put("Note", noteAction);
    m_mainPerspective.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(noteKey, "Note");
    noteB.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            noteAction.actionPerformed(e);
          }
        });

    final Action undoAction =
        new AbstractAction("Undo") {
          @Override
          public void actionPerformed(ActionEvent e) {
            if (m_mainPerspective.getCurrentLayout() != null) {
              m_mainPerspective.getCurrentLayout().popAndLoadUndo();
            }
          }
        };
    KeyStroke undoKey = KeyStroke.getKeyStroke(KeyEvent.VK_U, InputEvent.CTRL_DOWN_MASK);
    m_mainPerspective.getActionMap().put("Undo", undoAction);
    m_mainPerspective.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(undoKey, "Undo");
    undoB.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            undoAction.actionPerformed(e);
          }
        });

    final Action helpAction =
        new AbstractAction("Help") {
          @Override
          public void actionPerformed(ActionEvent e) {
            popupHelp(helpB);
          }
        };
    KeyStroke helpKey = KeyStroke.getKeyStroke(KeyEvent.VK_H, InputEvent.CTRL_DOWN_MASK);
    m_mainPerspective.getActionMap().put("Help", helpAction);
    m_mainPerspective.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(helpKey, "Help");
    helpB.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent ae) {
            helpAction.actionPerformed(ae);
          }
        });

    templatesB.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            // createTemplateMenuPopup();
            PopupMenu popupMenu = new PopupMenu();
            List<String> builtinTemplates =
                m_mainPerspective.getTemplateManager().getBuiltinTemplateDescriptions();
            List<String> pluginTemplates =
                m_mainPerspective.getTemplateManager().getPluginTemplateDescriptions();

            for (final String desc : builtinTemplates) {
              MenuItem menuItem = new MenuItem(desc);
              menuItem.addActionListener(
                  new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent e) {
                      try {
                        Flow templateFlow =
                            m_mainPerspective.getTemplateManager().getTemplateFlow(desc);
                        m_mainPerspective.addTab(desc);
                        m_mainPerspective.getCurrentLayout().setFlow(templateFlow);
                      } catch (WekaException ex) {
                        m_mainPerspective.showErrorDialog(ex);
                      }
                    }
                  });
              popupMenu.add(menuItem);
            }
            if (builtinTemplates.size() > 0 && pluginTemplates.size() > 0) {
              popupMenu.addSeparator();
            }
            for (final String desc : pluginTemplates) {
              MenuItem menuItem = new MenuItem(desc);
              menuItem.addActionListener(
                  new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent e) {
                      try {
                        Flow templateFlow =
                            m_mainPerspective.getTemplateManager().getTemplateFlow(desc);
                        m_mainPerspective.addTab(desc);
                        m_mainPerspective.getCurrentLayout().setFlow(templateFlow);
                      } catch (WekaException ex) {
                        m_mainPerspective.showErrorDialog(ex);
                      }
                    }
                  });
              popupMenu.add(menuItem);
            }
            templatesB.add(popupMenu);
            popupMenu.show(templatesB, 0, 0);
          }
        });
    templatesB.setEnabled(m_mainPerspective.getTemplateManager().numTemplates() > 0);

    final Action togglePerspectivesAction =
        new AbstractAction("Toggle perspectives") {
          @Override
          public void actionPerformed(ActionEvent e) {
            if (!Utils.getDontShowDialog("weka.gui.knowledgeflow.PerspectiveInfo")) {
              JCheckBox dontShow = new JCheckBox("Do not show this message again");
              Object[] stuff = new Object[2];
              stuff[0] =
                  "Perspectives are environments that take over the\n"
                      + "Knowledge Flow UI and provide major additional functionality.\n"
                      + "Many perspectives will operate on a set of instances. Instances\n"
                      + "Can be sent to a perspective by placing a DataSource on the\n"
                      + "layout canvas, configuring it and then selecting \"Send to perspective\"\n"
                      + "from the contextual popup menu that appears when you right-click on\n"
                      + "it. Several perspectives are built in to the Knowledge Flow, others\n"
                      + "can be installed via the package manager.\n";
              stuff[1] = dontShow;

              JOptionPane.showMessageDialog(
                  m_mainPerspective, stuff, "Perspective information", JOptionPane.OK_OPTION);

              if (dontShow.isSelected()) {
                try {
                  Utils.setDontShowDialog("weka.gui.Knowledgeflow.PerspectiveInfo");
                } catch (Exception ex) {
                  // quietly ignore
                }
              }
            }
            if (m_mainPerspective.getMainApplication().isPerspectivesToolBarVisible()) {
              m_mainPerspective.getMainApplication().hidePerspectivesToolBar();
            } else {
              m_mainPerspective.getMainApplication().showPerspectivesToolBar();
            }
            m_mainPerspective.revalidate();
            m_mainPerspective.notifyIsDirty();
          }
        };
    KeyStroke togglePerspectivesKey =
        KeyStroke.getKeyStroke(KeyEvent.VK_P, InputEvent.CTRL_DOWN_MASK);
    m_mainPerspective.getActionMap().put("Toggle perspectives", togglePerspectivesAction);
    m_mainPerspective
        .getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW)
        .put(togglePerspectivesKey, "Toggle perspectives");
    togglePerspectivesB.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            togglePerspectivesAction.actionPerformed(e);
          }
        });

    addWidgetToToolBar(fixedTools, Widgets.ZOOM_IN_BUTTON.toString(), zoomInB);
    addMenuItemToMenu("View", Widgets.ZOOM_IN_BUTTON.toString(), zoomInAction, zoomInKey);
    addWidgetToToolBar(fixedTools, Widgets.ZOOM_OUT_BUTTON.toString(), zoomOutB);
    addMenuItemToMenu("View", Widgets.ZOOM_OUT_BUTTON.toString(), zoomOutAction, zoomOutKey);
    fixedTools.addSeparator();
    addWidgetToToolBar(fixedTools, Widgets.SELECT_ALL_BUTTON.toString(), selectAllB);
    addWidgetToToolBar(fixedTools, Widgets.CUT_BUTTON.toString(), cutB);
    addMenuItemToMenu("Edit", Widgets.CUT_BUTTON.toString(), cutAction, cutKey);
    addWidgetToToolBar(fixedTools, Widgets.COPY_BUTTON.toString(), copyB);
    addMenuItemToMenu("Edit", Widgets.COPY_BUTTON.toString(), copyAction, copyKey);
    addMenuItemToMenu("Edit", Widgets.PASTE_BUTTON.toString(), pasteAction, pasteKey);
    addWidgetToToolBar(fixedTools, Widgets.DELETE_BUTTON.toString(), deleteB);
    addMenuItemToMenu("Edit", Widgets.DELETE_BUTTON.toString(), deleteAction, deleteKey);
    addWidgetToToolBar(fixedTools, Widgets.PASTE_BUTTON.toString(), pasteB);
    addWidgetToToolBar(fixedTools, Widgets.UNDO_BUTTON.toString(), undoB);
    addMenuItemToMenu("Edit", Widgets.UNDO_BUTTON.toString(), undoAction, undoKey);
    addWidgetToToolBar(fixedTools, Widgets.NOTE_BUTTON.toString(), noteB);
    addMenuItemToMenu("Insert", Widgets.NOTE_BUTTON.toString(), noteAction, noteKey);
    fixedTools.addSeparator();
    addWidgetToToolBar(fixedTools, Widgets.SNAP_TO_GRID_BUTTON.toString(), snapToGridB);
    fixedTools.addSeparator();
    addWidgetToToolBar(fixedTools, Widgets.NEW_FLOW_BUTTON.toString(), newB);
    addMenuItemToMenu("File", Widgets.NEW_FLOW_BUTTON.toString(), newAction, newKey);
    addWidgetToToolBar(fixedTools, Widgets.SAVE_FLOW_BUTTON.toString(), saveB);
    addMenuItemToMenu("File", Widgets.LOAD_FLOW_BUTTON.toString(), openAction, openKey);
    addMenuItemToMenu("File", Widgets.SAVE_FLOW_BUTTON.toString(), saveAction, saveKey);
    addWidgetToToolBar(fixedTools, Widgets.SAVE_FLOW_AS_BUTTON.toString(), saveBB);
    addMenuItemToMenu("File", Widgets.SAVE_FLOW_AS_BUTTON.toString(), saveAction, saveAsKey);
    addWidgetToToolBar(fixedTools, Widgets.LOAD_FLOW_BUTTON.toString(), loadB);
    addWidgetToToolBar(fixedTools, Widgets.TEMPLATES_BUTTON.toString(), templatesB);
    fixedTools.addSeparator();
    addWidgetToToolBar(
        fixedTools, Widgets.TOGGLE_PERSPECTIVES_BUTTON.toString(), togglePerspectivesB);
    addWidgetToToolBar(fixedTools, Widgets.HELP_BUTTON.toString(), helpB);
    Dimension d = undoB.getPreferredSize();
    Dimension d2 = fixedTools.getMinimumSize();
    Dimension d3 = new Dimension(d2.width, d.height + 4);
    fixedTools.setPreferredSize(d3);
    fixedTools.setMaximumSize(d3);
    fixedTools.setFloatable(false);
    add(fixedTools, BorderLayout.EAST);
  }
Esempio n. 14
0
  private void setupLeftSideToolBar() {
    JToolBar fixedTools2 = new JToolBar();
    fixedTools2.setOrientation(JToolBar.HORIZONTAL);
    fixedTools2.setFloatable(false);

    JButton playB =
        new JButton(new ImageIcon(loadIcon(ICON_PATH + "resultset_next.png").getImage()));
    playB.setBorder(BorderFactory.createEmptyBorder(0, 5, 0, 0));
    playB.setToolTipText("Run this flow (all start points launched in parallel)");
    final Action playParallelAction =
        new AbstractAction() {
          @Override
          public void actionPerformed(ActionEvent e) {
            if (m_mainPerspective.getCurrentLayout() != null) {
              boolean proceed = true;
              if (m_mainPerspective.isMemoryLow()) {
                proceed = m_mainPerspective.showMemoryIsLow();
              }
              if (proceed) {
                try {
                  m_mainPerspective.getCurrentLayout().executeFlow(false);
                } catch (WekaException e1) {
                  m_mainPerspective.showErrorDialog(e1);
                }
              }
            }
          }
        };
    playB.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            playParallelAction.actionPerformed(e);
          }
        });

    JButton playBB =
        new JButton(new ImageIcon(loadIcon(ICON_PATH + "resultset_last.png").getImage()));
    playBB.setBorder(BorderFactory.createEmptyBorder(0, 5, 0, 0));
    playBB.setToolTipText("Run this flow (start points launched sequentially)");
    final Action playSequentialAction =
        new AbstractAction() {
          @Override
          public void actionPerformed(ActionEvent e) {
            if (m_mainPerspective.getCurrentLayout() != null) {
              if (!Utils.getDontShowDialog("weka.gui.knowledgeflow.SequentialRunInfo")) {
                JCheckBox dontShow = new JCheckBox("Do not show this message again");
                Object[] stuff = new Object[2];
                stuff[0] =
                    "The order that data sources are launched in can be\n"
                        + "specified by setting a custom name for each data source that\n"
                        + "that includes a number. E.g. \"1:MyArffLoader\". To set a name,\n"
                        + "right-click over a data source and select \"Set name\"\n\n"
                        + "If the prefix is not specified, then the order of execution\n"
                        + "will correspond to the order that the components were added\n"
                        + "to the layout. Note that it is also possible to prevent a data\n"
                        + "source from executing by prefixing its name with a \"!\". E.g\n"
                        + "\"!:MyArffLoader\"";
                stuff[1] = dontShow;

                JOptionPane.showMessageDialog(
                    m_mainPerspective,
                    stuff,
                    "Sequential execution information",
                    JOptionPane.OK_OPTION);

                if (dontShow.isSelected()) {
                  try {
                    Utils.setDontShowDialog("weka.gui.knowledgeFlow.SequentialRunInfo");
                  } catch (Exception e1) {
                  }
                }
              }

              boolean proceed = true;
              if (m_mainPerspective.isMemoryLow()) {
                proceed = m_mainPerspective.showMemoryIsLow();
              }
              if (proceed) {
                try {
                  m_mainPerspective.getCurrentLayout().executeFlow(true);
                } catch (WekaException e1) {
                  m_mainPerspective.showErrorDialog(e1);
                }
              }
            }
          }
        };
    playBB.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            playSequentialAction.actionPerformed(e);
          }
        });

    JButton stopB = new JButton(new ImageIcon(loadIcon(ICON_PATH + "shape_square.png").getImage()));
    stopB.setBorder(BorderFactory.createEmptyBorder(0, 8, 0, 0));
    stopB.setToolTipText("Stop all execution");
    final Action stopAction =
        new AbstractAction() {
          @Override
          public void actionPerformed(ActionEvent e) {
            if (m_mainPerspective.getCurrentLayout() != null) {
              m_mainPerspective
                  .getCurrentLayout()
                  .getLogPanel()
                  .statusMessage("@!@[KnowledgeFlow]|Attempting to stop all components...");
              m_mainPerspective.getCurrentLayout().stopFlow();
              m_mainPerspective
                  .getCurrentLayout()
                  .getLogPanel()
                  .statusMessage("@!@[KnowledgeFlow]|OK.");
            }
          }
        };

    stopB.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            stopAction.actionPerformed(e);
          }
        });

    JButton pointerB = new JButton(new ImageIcon(loadIcon(ICON_PATH + "cursor.png").getImage()));
    pointerB.setBorder(BorderFactory.createEmptyBorder(0, 5, 0, 0));
    pointerB.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            m_mainPerspective.setPalleteSelectedStep(null);
            m_mainPerspective.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));

            m_mainPerspective.clearDesignPaletteSelection();

            if (m_mainPerspective.getCurrentLayout() != null) {
              m_mainPerspective
                  .getCurrentLayout()
                  .setFlowLayoutOperation(VisibleLayout.LayoutOperation.NONE);
            }
          }
        });

    addWidgetToToolBar(fixedTools2, Widgets.POINTER_BUTTON.toString(), pointerB);
    addWidgetToToolBar(fixedTools2, Widgets.PLAY_PARALLEL_BUTTON.toString(), playB);
    addWidgetToToolBar(fixedTools2, Widgets.PLAY_SEQUENTIAL_BUTTON.toString(), playBB);
    addWidgetToToolBar(fixedTools2, Widgets.STOP_BUTTON.toString(), stopB);
    Dimension d = playB.getPreferredSize();
    Dimension d2 = fixedTools2.getMinimumSize();
    Dimension d3 = new Dimension(d2.width, d.height + 4);
    fixedTools2.setPreferredSize(d3);
    fixedTools2.setMaximumSize(d3);
    add(fixedTools2, BorderLayout.WEST);
  }
Esempio n. 15
0
  public Preferences() {

    // setup dialog for the prefs

    //dialog = new JDialog(editor, "Preferences", true);
    dialog = new JFrame(_("Preferences"));
    dialog.setResizable(false);

    Container pain = dialog.getContentPane();
    pain.setLayout(null);

    int top = GUI_BIG;
    int left = GUI_BIG;
    int right = 0;

    JLabel label;
    JButton button; //, button2;
    //JComboBox combo;
    Dimension d, d2; //, d3;
    int h, vmax;


    // Sketchbook location:
    // [...............................]  [ Browse ]

    label = new JLabel(_("Sketchbook location:"));
    pain.add(label);
    d = label.getPreferredSize();
    label.setBounds(left, top, d.width, d.height);
    top += d.height; // + GUI_SMALL;

    sketchbookLocationField = new JTextField(40);
    pain.add(sketchbookLocationField);
    d = sketchbookLocationField.getPreferredSize();

    button = new JButton(PROMPT_BROWSE);
    button.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
          File dflt = new File(sketchbookLocationField.getText());
          File file =
            Base.selectFolder(_("Select new sketchbook location"), dflt, dialog);
          if (file != null) {
            sketchbookLocationField.setText(file.getAbsolutePath());
          }
        }
      });
    pain.add(button);
    d2 = button.getPreferredSize();

    // take max height of all components to vertically align em
    vmax = Math.max(d.height, d2.height);
    sketchbookLocationField.setBounds(left, top + (vmax-d.height)/2,
                                      d.width, d.height);
    h = left + d.width + GUI_SMALL;
    button.setBounds(h, top + (vmax-d2.height)/2,
                     d2.width, d2.height);

    right = Math.max(right, h + d2.width + GUI_BIG);
    top += vmax + GUI_BETWEEN;


    // Preferred language: [        ] (requires restart of Arduino)
    Container box = Box.createHorizontalBox();
    label = new JLabel(_("Editor language: "));
    box.add(label);
    comboLanguage = new JComboBox(languages);
    comboLanguage.setSelectedIndex((Arrays.asList(languagesISO)).indexOf(Preferences.get("editor.languages.current")));
    box.add(comboLanguage);
    label = new JLabel(_("  (requires restart of Arduino)"));
    box.add(label);
    pain.add(box);
    d = box.getPreferredSize();
    box.setForeground(Color.gray);
    box.setBounds(left, top, d.width, d.height);
    right = Math.max(right, left + d.width);
    top += d.height + GUI_BETWEEN;

    // Editor font size [    ]

    box = Box.createHorizontalBox();
    label = new JLabel(_("Editor font size: "));
    box.add(label);
    fontSizeField = new JTextField(4);
    box.add(fontSizeField);
    label = new JLabel(_("  (requires restart of Arduino)"));
    box.add(label);
    pain.add(box);
    d = box.getPreferredSize();
    box.setBounds(left, top, d.width, d.height);
    Font editorFont = Preferences.getFont("editor.font");
    fontSizeField.setText(String.valueOf(editorFont.getSize()));
    top += d.height + GUI_BETWEEN;


    // Show verbose output during: [ ] compilation [ ] upload

    box = Box.createHorizontalBox();
    label = new JLabel(_("Show verbose output during: "));
    box.add(label);
    verboseCompilationBox = new JCheckBox(_("compilation "));
    box.add(verboseCompilationBox);
    verboseUploadBox = new JCheckBox(_("upload"));
    box.add(verboseUploadBox);
    pain.add(box);
    d = box.getPreferredSize();
    box.setBounds(left, top, d.width, d.height);
    top += d.height + GUI_BETWEEN;

    // [ ] Verify code after upload

    verifyUploadBox = new JCheckBox(_("Verify code after upload"));
    pain.add(verifyUploadBox);
    d = verifyUploadBox.getPreferredSize();
    verifyUploadBox.setBounds(left, top, d.width + 10, d.height);
    right = Math.max(right, left + d.width);
    top += d.height + GUI_BETWEEN;

    // [ ] Use external editor

    externalEditorBox = new JCheckBox(_("Use external editor"));
    pain.add(externalEditorBox);
    d = externalEditorBox.getPreferredSize();
    externalEditorBox.setBounds(left, top, d.width + 10, d.height);
    right = Math.max(right, left + d.width);
    top += d.height + GUI_BETWEEN;


    // [ ] Check for updates on startup

    checkUpdatesBox = new JCheckBox(_("Check for updates on startup"));
    pain.add(checkUpdatesBox);
    d = checkUpdatesBox.getPreferredSize();
    checkUpdatesBox.setBounds(left, top, d.width + 10, d.height);
    right = Math.max(right, left + d.width);
    top += d.height + GUI_BETWEEN;

    // [ ] Update sketch files to new extension on save (.pde -> .ino)

    updateExtensionBox = new JCheckBox(_("Update sketch files to new extension on save (.pde -> .ino)"));
    pain.add(updateExtensionBox);
    d = updateExtensionBox.getPreferredSize();
    updateExtensionBox.setBounds(left, top, d.width + 10, d.height);
    right = Math.max(right, left + d.width);
    top += d.height + GUI_BETWEEN;

    domainPortField= new JTextField();
    domainPortField.setColumns(30);
    Box domainBox = Box.createHorizontalBox();
    domainBox.add(new JLabel("Tftp upload Domain:"));
    domainBox.add(domainPortField);
    pain.add(domainBox);
    d = domainBox.getPreferredSize();
    domainBox.setBounds(left, top, d.width, d.height);
    top += d.height + GUI_BETWEEN;

    autoResetPortField= new JTextField();
    autoResetPortField.setColumns(8);
    Box resetBox = Box.createHorizontalBox();
    resetBox.add(new JLabel("Auto Reset Port:"));
    resetBox.add(autoResetPortField);
    pain.add(resetBox);
    d = resetBox.getPreferredSize();
    resetBox.setBounds(left, top, d.width, d.height);
    top += d.height + GUI_BETWEEN;


    tftpPassField = new JTextField();
    tftpPassField.setColumns(30);
    Box tftpBox = Box.createHorizontalBox();
    tftpBox.add(new JLabel("Tftp Secret Password:"******"Automatically associate .ino files with Arduino"));
      pain.add(autoAssociateBox);
      d = autoAssociateBox.getPreferredSize();
      autoAssociateBox.setBounds(left, top, d.width + 10, d.height);
      right = Math.max(right, left + d.width);
      top += d.height + GUI_BETWEEN;
    }

    // More preferences are in the ...

    label = new JLabel(_("More preferences can be edited directly in the file"));
    pain.add(label);
    d = label.getPreferredSize();
    label.setForeground(Color.gray);
    label.setBounds(left, top, d.width, d.height);
    right = Math.max(right, left + d.width);
    top += d.height; // + GUI_SMALL;

    label = new JLabel(preferencesFile.getAbsolutePath());
    final JLabel clickable = label;
    label.addMouseListener(new MouseAdapter() {
        public void mousePressed(MouseEvent e) {
          Base.openFolder(Base.getSettingsFolder());
        }

        public void mouseEntered(MouseEvent e) {
          clickable.setForeground(new Color(0, 0, 140));
        }

        public void mouseExited(MouseEvent e) {
          clickable.setForeground(Color.BLACK);
        }
      });
    pain.add(label);
    d = label.getPreferredSize();
    label.setBounds(left, top, d.width, d.height);
    right = Math.max(right, left + d.width);
    top += d.height;

    label = new JLabel(_("(edit only when Arduino is not running)"));
    pain.add(label);
    d = label.getPreferredSize();
    label.setForeground(Color.gray);
    label.setBounds(left, top, d.width, d.height);
    right = Math.max(right, left + d.width);
    top += d.height; // + GUI_SMALL;


    // [  OK  ] [ Cancel ]  maybe these should be next to the message?

    button = new JButton(PROMPT_OK);
    button.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
          applyFrame();
          disposeFrame();
        }
      });
    pain.add(button);
    d2 = button.getPreferredSize();
    BUTTON_HEIGHT = d2.height;

    h = right - (BUTTON_WIDTH + GUI_SMALL + BUTTON_WIDTH);
    button.setBounds(h, top, BUTTON_WIDTH, BUTTON_HEIGHT);
    h += BUTTON_WIDTH + GUI_SMALL;

    button = new JButton(PROMPT_CANCEL);
    button.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
          disposeFrame();
        }
      });
    pain.add(button);
    button.setBounds(h, top, BUTTON_WIDTH, BUTTON_HEIGHT);

    top += BUTTON_HEIGHT + GUI_BETWEEN;


    // finish up

    wide = right + GUI_BIG;
    high = top + GUI_SMALL;


    // closing the window is same as hitting cancel button

    dialog.addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
          disposeFrame();
        }
      });

    ActionListener disposer = new ActionListener() {
        public void actionPerformed(ActionEvent actionEvent) {
          disposeFrame();
        }
      };
    Base.registerWindowCloseKeys(dialog.getRootPane(), disposer);
    Base.setIcon(dialog);

    Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
    dialog.setLocation((screen.width - wide) / 2,
                      (screen.height - high) / 2);

    dialog.pack(); // get insets
    Insets insets = dialog.getInsets();
    dialog.setSize(wide + insets.left + insets.right,
                  high + insets.top + insets.bottom);


    // handle window closing commands for ctrl/cmd-W or hitting ESC.

    pain.addKeyListener(new KeyAdapter() {
        public void keyPressed(KeyEvent e) {
          //System.out.println(e);
          KeyStroke wc = Editor.WINDOW_CLOSE_KEYSTROKE;
          if ((e.getKeyCode() == KeyEvent.VK_ESCAPE) ||
              (KeyStroke.getKeyStrokeForEvent(e).equals(wc))) {
            disposeFrame();
          }
        }
      });
  }
Esempio n. 16
0
  // Here some legacy code makes use of generics. They are tested, so there
  // is no risk of an actual error, but Java issues a warning.
  @SuppressWarnings("unchecked")
  public DialogParameters(
      JFrame parent, Vector<ParameterDescription> vec, boolean strict, Vector<LayerDesc> layers) {
    super(parent, Globals.messages.getString("Param_opt"), true);

    keyb1 = new OSKeybPanel(KEYBMODES.GREEK);
    keyb2 = new OSKeybPanel(KEYBMODES.MISC);
    keyb1.setField(this);
    keyb2.setField(this);
    keyb.addTab("Greek", keyb1);
    keyb.addTab("Misc", keyb2);
    keyb.setVisible(false);
    v = vec;

    int ycount = 0;

    // We create dynamically all the needed elements.
    // For this reason, we work on arrays of the potentially useful Swing
    // objects.

    jtf = new JTextField[MAX_ELEMENTS];
    jcb = new JCheckBox[MAX_ELEMENTS];
    jco = new JComboBox[MAX_ELEMENTS];

    active = false;
    addComponentListener(this);

    GridBagLayout bgl = new GridBagLayout();
    GridBagConstraints constraints = new GridBagConstraints();
    Container contentPane = getContentPane();
    contentPane.setLayout(bgl);
    boolean extStrict = strict;

    ParameterDescription pd;

    int top = 0;

    JLabel lab;

    tc = 0;
    cc = 0;
    co = 0;

    // We process all parameter passed. Depending on its type, a
    // corresponding interface element will be created.
    // A symmetrical operation is done when validating parameters.

    for (ycount = 0; ycount < v.size(); ++ycount) {
      if (ycount > MAX) break;

      pd = (ParameterDescription) v.elementAt(ycount);

      // We do not need to store label objects, since we do not need
      // to retrieve data from them.

      lab = new JLabel(pd.description);
      constraints.weightx = 100;
      constraints.weighty = 100;
      constraints.gridx = 1;
      constraints.gridy = ycount;
      constraints.gridwidth = 1;
      constraints.gridheight = 1;

      // The first element needs a little bit more space at the top.
      if (ycount == 0) top = 10;
      else top = 0;

      // Here we configure the grid layout

      constraints.insets = new Insets(top, 20, 0, 6);

      constraints.fill = GridBagConstraints.VERTICAL;
      constraints.anchor = GridBagConstraints.EAST;
      lab.setEnabled(!(pd.isExtension && extStrict));

      if (!(pd.parameter instanceof Boolean)) contentPane.add(lab, constraints);

      constraints.anchor = GridBagConstraints.WEST;
      constraints.insets = new Insets(top, 0, 0, 0);
      constraints.fill = GridBagConstraints.HORIZONTAL;

      // Now, depending on the type of parameter we create interface
      // elements and we populate the dialog.

      if (pd.parameter instanceof PointG) {
        jtf[tc] = new JTextField(10);
        jtf[tc].setText("" + ((PointG) (pd.parameter)).x);
        constraints.weightx = 100;
        constraints.weighty = 100;
        constraints.gridx = 2;
        constraints.gridy = ycount;
        constraints.gridwidth = 1;
        constraints.gridheight = 1;
        // Disable FidoCadJ extensions in the strict compatibility mode
        jtf[tc].setEnabled(!(pd.isExtension && extStrict));

        contentPane.add(jtf[tc++], constraints);

        jtf[tc] = new JTextField(10);
        jtf[tc].setText("" + ((PointG) (pd.parameter)).y);
        constraints.weightx = 100;
        constraints.weighty = 100;
        constraints.gridx = 3;
        constraints.gridy = ycount;
        constraints.gridwidth = 1;
        constraints.gridheight = 1;
        constraints.insets = new Insets(top, 6, 0, 20);
        constraints.fill = GridBagConstraints.HORIZONTAL;
        jtf[tc].setEnabled(!(pd.isExtension && extStrict));
        contentPane.add(jtf[tc++], constraints);
      } else if (pd.parameter instanceof String) {
        jtf[tc] = new JTextField(24);
        jtf[tc].setText((String) (pd.parameter));
        // If we have a String text field in the first position, its
        // contents should be evidenced, since it is supposed to be
        // the most important field (e.g. for the AdvText primitive)
        if (ycount == 0) jtf[tc].selectAll();
        constraints.weightx = 100;
        constraints.weighty = 100;
        constraints.gridx = 2;
        constraints.gridy = ycount;
        constraints.gridwidth = 2;
        constraints.gridheight = 1;
        constraints.insets = new Insets(top, 0, 0, 20);
        constraints.fill = GridBagConstraints.HORIZONTAL;
        jtf[tc].setEnabled(!(pd.isExtension && extStrict));

        contentPane.add(jtf[tc++], constraints);

      } else if (pd.parameter instanceof Boolean) {
        jcb[cc] = new JCheckBox(pd.description);
        jcb[cc].setSelected(((Boolean) (pd.parameter)).booleanValue());
        constraints.weightx = 100;
        constraints.weighty = 100;
        constraints.gridx = 2;
        constraints.gridy = ycount;
        constraints.gridwidth = 2;
        constraints.gridheight = 1;
        constraints.insets = new Insets(top, 0, 0, 20);
        constraints.fill = GridBagConstraints.HORIZONTAL;
        jcb[cc].setEnabled(!(pd.isExtension && extStrict));
        contentPane.add(jcb[cc++], constraints);
      } else if (pd.parameter instanceof Integer) {
        jtf[tc] = new JTextField(24);
        jtf[tc].setText(((Integer) pd.parameter).toString());
        constraints.weightx = 100;
        constraints.weighty = 100;
        constraints.gridx = 2;
        constraints.gridy = ycount;
        constraints.gridwidth = 2;
        constraints.gridheight = 1;
        constraints.insets = new Insets(top, 0, 0, 20);
        constraints.fill = GridBagConstraints.HORIZONTAL;
        jtf[tc].setEnabled(!(pd.isExtension && extStrict));
        contentPane.add(jtf[tc++], constraints);
      } else if (pd.parameter instanceof Float) {
        // TODO.
        // WARNING: (DB) this is supposed to be temporary. In fact, I
        // am planning to upgrade some of the parameters from int
        // to float. But for a few months, the users should not be
        // aware of that, even if the internal representation is
        // slowing being adapted.
        jtf[tc] = new JTextField(24);
        int dummy = java.lang.Math.round((Float) pd.parameter);
        jtf[tc].setText("" + dummy);
        constraints.weightx = 100;
        constraints.weighty = 100;
        constraints.gridx = 2;
        constraints.gridy = ycount;
        constraints.gridwidth = 2;
        constraints.gridheight = 1;
        constraints.insets = new Insets(top, 0, 0, 20);
        constraints.fill = GridBagConstraints.HORIZONTAL;
        jtf[tc].setEnabled(!(pd.isExtension && extStrict));
        contentPane.add(jtf[tc++], constraints);
      } else if (pd.parameter instanceof FontG) {
        GraphicsEnvironment gE;
        gE = GraphicsEnvironment.getLocalGraphicsEnvironment();
        String[] s = gE.getAvailableFontFamilyNames();
        jco[co] = new JComboBox();

        for (int i = 0; i < s.length; ++i) {
          jco[co].addItem(s[i]);
          if (s[i].equals(((FontG) pd.parameter).getFamily())) jco[co].setSelectedIndex(i);
        }
        constraints.weightx = 100;
        constraints.weighty = 100;
        constraints.gridx = 2;
        constraints.gridy = ycount;
        constraints.gridwidth = 2;
        constraints.gridheight = 1;
        constraints.insets = new Insets(top, 0, 0, 20);
        constraints.fill = GridBagConstraints.HORIZONTAL;
        jco[co].setEnabled(!(pd.isExtension && extStrict));
        contentPane.add(jco[co++], constraints);
      } else if (pd.parameter instanceof LayerInfo) {
        jco[co] = new JComboBox(new Vector<LayerDesc>(layers));
        jco[co].setSelectedIndex(((LayerInfo) pd.parameter).layer);
        jco[co].setRenderer(new LayerCellRenderer());

        constraints.weightx = 100;
        constraints.weighty = 100;
        constraints.gridx = 2;
        constraints.gridy = ycount;
        constraints.gridwidth = 2;
        constraints.gridheight = 1;
        constraints.insets = new Insets(top, 0, 0, 20);
        constraints.fill = GridBagConstraints.HORIZONTAL;
        jco[co].setEnabled(!(pd.isExtension && extStrict));
        contentPane.add(jco[co++], constraints);

      } else if (pd.parameter instanceof ArrowInfo) {
        jco[co] = new JComboBox<ArrowInfo>();
        jco[co].addItem(new ArrowInfo(0));
        jco[co].addItem(new ArrowInfo(1));
        jco[co].addItem(new ArrowInfo(2));
        jco[co].addItem(new ArrowInfo(3));

        jco[co].setSelectedIndex(((ArrowInfo) pd.parameter).style);
        jco[co].setRenderer(new ArrowCellRenderer());

        constraints.weightx = 100;
        constraints.weighty = 100;
        constraints.gridx = 2;
        constraints.gridy = ycount;
        constraints.gridwidth = 2;
        constraints.gridheight = 1;
        constraints.insets = new Insets(top, 0, 0, 20);
        constraints.fill = GridBagConstraints.HORIZONTAL;
        jco[co].setEnabled(!(pd.isExtension && extStrict));
        contentPane.add(jco[co++], constraints);

      } else if (pd.parameter instanceof DashInfo) {

        jco[co] = new JComboBox<DashInfo>();

        for (int k = 0; k < Globals.dashNumber; ++k) {
          jco[co].addItem(new DashInfo(k));
        }

        jco[co].setSelectedIndex(((DashInfo) pd.parameter).style);
        jco[co].setRenderer(new DashCellRenderer());

        constraints.weightx = 100;
        constraints.weighty = 100;
        constraints.gridx = 2;
        constraints.gridy = ycount;
        constraints.gridwidth = 2;
        constraints.gridheight = 1;
        constraints.insets = new Insets(top, 0, 0, 20);
        constraints.fill = GridBagConstraints.HORIZONTAL;
        jco[co].setEnabled(!(pd.isExtension && extStrict));
        contentPane.add(jco[co++], constraints);
      }
    }
    // Put the OK and Cancel buttons and make them active.
    JButton ok = new JButton(Globals.messages.getString("Ok_btn"));
    JButton cancel = new JButton(Globals.messages.getString("Cancel_btn"));
    JButton keybd = new JButton("\u00B6\u2211\u221A"); // phylum
    keybd.setFocusable(false);
    keybd.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            // If at this point, the keyboard is not visible, this means
            // that it will become visible in a while. It is better to
            // resize first and then show up the keyboard.
            if (keyb.isVisible()) {
              MIN_WIDTH = 400;
              MIN_HEIGHT = 350;
            } else {
              MIN_WIDTH = 400;
              MIN_HEIGHT = 500;
            }
            // setSize(MIN_WIDTH, MIN_HEIGHT);
            keyb.setVisible(!keyb.isVisible());
            pack();
          }
        });

    constraints.gridx = 0;
    constraints.gridy = ycount++;
    constraints.gridwidth = 4;
    constraints.gridheight = 1;
    constraints.anchor = GridBagConstraints.EAST;
    constraints.insets = new Insets(6, 20, 20, 20);

    // Put the OK and Cancel buttons and make them active.
    Box b = Box.createHorizontalBox();
    b.add(keybd); // phylum

    b.add(Box.createHorizontalGlue());
    ok.setPreferredSize(cancel.getPreferredSize());

    if (Globals.okCancelWinOrder) {
      b.add(ok);
      b.add(Box.createHorizontalStrut(12));
      b.add(cancel);

    } else {
      b.add(cancel);
      b.add(Box.createHorizontalStrut(12));
      b.add(ok);
    }
    // b.add(Box.createHorizontalStrut(12));
    contentPane.add(b, constraints);

    constraints.gridx = 0;
    constraints.gridy = ycount;
    constraints.gridwidth = 4;
    constraints.gridheight = 1;
    constraints.anchor = GridBagConstraints.EAST;
    constraints.insets = new Insets(6, 20, 20, 20);

    contentPane.add(keyb, constraints);

    ok.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent evt) {
            try {
              int ycount;
              ParameterDescription pd;
              tc = 0;
              cc = 0;
              co = 0;

              // Here we read all the contents of the interface and we
              // update the contents of the parameter description array.

              for (ycount = 0; ycount < v.size(); ++ycount) {
                if (ycount > MAX) break;
                pd = (ParameterDescription) v.elementAt(ycount);

                if (pd.parameter instanceof PointG) {
                  ((PointG) (pd.parameter)).x = Integer.parseInt(jtf[tc++].getText());
                  ((PointG) (pd.parameter)).y = Integer.parseInt(jtf[tc++].getText());
                } else if (pd.parameter instanceof String) {
                  pd.parameter = jtf[tc++].getText();
                } else if (pd.parameter instanceof Boolean) {
                  pd.parameter = Boolean.valueOf(jcb[cc++].isSelected());
                } else if (pd.parameter instanceof Integer) {
                  pd.parameter = Integer.valueOf(Integer.parseInt(jtf[tc++].getText()));
                } else if (pd.parameter instanceof Float) {
                  pd.parameter = Float.valueOf(Float.parseFloat(jtf[tc++].getText()));
                } else if (pd.parameter instanceof FontG) {
                  pd.parameter = new FontG((String) jco[co++].getSelectedItem());
                } else if (pd.parameter instanceof LayerInfo) {
                  pd.parameter = new LayerInfo(jco[co++].getSelectedIndex());
                } else if (pd.parameter instanceof ArrowInfo) {
                  pd.parameter = new ArrowInfo(jco[co++].getSelectedIndex());
                } else if (pd.parameter instanceof DashInfo) {
                  pd.parameter = new DashInfo(jco[co++].getSelectedIndex());
                }
              }
            } catch (NumberFormatException E) {
              // Error detected. Probably, the user has entered an
              // invalid string when FidoCadJ was expecting a numerical
              // input.

              JOptionPane.showMessageDialog(
                  null,
                  Globals.messages.getString("Format_invalid"),
                  "",
                  JOptionPane.INFORMATION_MESSAGE);
              return;
            }

            active = true;
            // Globals.activeWindow.setEnabled(true);
            setVisible(false);
            keyb.setVisible(false);
          }
        });
    cancel.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent evt) {
            // Globals.activeWindow.setEnabled(true);
            setVisible(false);
            keyb.setVisible(false);
          }
        });
    // Here is an action in which the dialog is closed

    AbstractAction cancelAction =
        new AbstractAction() {
          public void actionPerformed(ActionEvent e) {
            // Globals.activeWindow.setEnabled(true);
            setVisible(false);
            keyb.setVisible(false);
          }
        };
    DialogUtil.addCancelEscape(this, cancelAction);

    this.addWindowListener(
        new WindowAdapter() {
          public void windowClosing(WindowEvent e) {
            // Globals.activeWindow.setEnabled(true);
            keyb.setVisible(false);
          }
        });

    pack();
    DialogUtil.center(this);
    getRootPane().setDefaultButton(ok);
  }
Esempio n. 17
0
  /** Constructs the <tt>LoginWindow</tt>. */
  private void init() {
    String title;

    if (windowTitle != null) title = windowTitle;
    else
      title =
          DesktopUtilActivator.getResources()
              .getI18NString("service.gui.AUTHENTICATION_WINDOW_TITLE", new String[] {server});

    String text;
    if (windowText != null) text = windowText;
    else
      text =
          DesktopUtilActivator.getResources()
              .getI18NString("service.gui.AUTHENTICATION_REQUESTED_SERVER", new String[] {server});

    String uinText;
    if (usernameLabelText != null) uinText = usernameLabelText;
    else uinText = DesktopUtilActivator.getResources().getI18NString("service.gui.IDENTIFIER");

    String passText;
    if (passwordLabelText != null) passText = passwordLabelText;
    else passText = DesktopUtilActivator.getResources().getI18NString("service.gui.PASSWORD");

    setTitle(title);

    infoTextArea.setEditable(false);
    infoTextArea.setOpaque(false);
    infoTextArea.setLineWrap(true);
    infoTextArea.setWrapStyleWord(true);
    infoTextArea.setFont(infoTextArea.getFont().deriveFont(Font.BOLD));
    infoTextArea.setText(text);
    infoTextArea.setAlignmentX(0.5f);

    JLabel uinLabel = new JLabel(uinText);
    uinLabel.setFont(uinLabel.getFont().deriveFont(Font.BOLD));

    JLabel passwdLabel = new JLabel(passText);
    passwdLabel.setFont(passwdLabel.getFont().deriveFont(Font.BOLD));

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

    labelsPanel.add(uinLabel);
    labelsPanel.add(passwdLabel);

    TransparentPanel textFieldsPanel = new TransparentPanel(new GridLayout(0, 1, 8, 8));

    textFieldsPanel.add(uinValue);
    textFieldsPanel.add(passwdField);

    JPanel southFieldsPanel = new TransparentPanel(new GridLayout(1, 2));

    this.rememberPassCheckBox.setOpaque(false);
    this.rememberPassCheckBox.setBorder(null);

    southFieldsPanel.add(rememberPassCheckBox);
    if (signupLink != null && signupLink.length() > 0)
      southFieldsPanel.add(
          createWebSignupLabel(
              DesktopUtilActivator.getResources().getI18NString("plugin.simpleaccregwizz.SIGNUP"),
              signupLink));
    else southFieldsPanel.add(new JLabel());

    boolean allowRememberPassword = true;

    String allowRemPassStr =
        DesktopUtilActivator.getResources().getSettingsString(PNAME_ALLOW_SAVE_PASSWORD);
    if (allowRemPassStr != null) {
      allowRememberPassword = Boolean.parseBoolean(allowRemPassStr);
    }
    allowRememberPassword =
        DesktopUtilActivator.getConfigurationService()
            .getBoolean(PNAME_ALLOW_SAVE_PASSWORD, allowRememberPassword);

    setAllowSavePassword(allowRememberPassword);

    JPanel buttonPanel = new TransparentPanel(new FlowLayout(FlowLayout.CENTER));

    buttonPanel.add(loginButton);
    buttonPanel.add(cancelButton);

    JPanel southEastPanel = new TransparentPanel(new BorderLayout());
    southEastPanel.add(buttonPanel, BorderLayout.EAST);

    TransparentPanel mainPanel = new TransparentPanel(new BorderLayout(10, 10));

    mainPanel.setBorder(BorderFactory.createEmptyBorder(20, 0, 20, 20));

    JPanel mainFieldsPanel = new TransparentPanel(new BorderLayout(0, 10));
    mainFieldsPanel.add(labelsPanel, BorderLayout.WEST);
    mainFieldsPanel.add(textFieldsPanel, BorderLayout.CENTER);
    mainFieldsPanel.add(southFieldsPanel, BorderLayout.SOUTH);

    mainPanel.add(infoTextArea, BorderLayout.NORTH);
    mainPanel.add(mainFieldsPanel, BorderLayout.CENTER);
    mainPanel.add(southEastPanel, BorderLayout.SOUTH);

    this.getContentPane().add(mainPanel, BorderLayout.EAST);

    this.loginButton.setName("ok");
    this.cancelButton.setName("cancel");
    if (loginButton.getPreferredSize().width > cancelButton.getPreferredSize().width)
      cancelButton.setPreferredSize(loginButton.getPreferredSize());
    else loginButton.setPreferredSize(cancelButton.getPreferredSize());

    this.loginButton.setMnemonic(
        DesktopUtilActivator.getResources().getI18nMnemonic("service.gui.OK"));
    this.cancelButton.setMnemonic(
        DesktopUtilActivator.getResources().getI18nMnemonic("service.gui.CANCEL"));

    this.loginButton.addActionListener(this);
    this.cancelButton.addActionListener(this);

    this.getRootPane().setDefaultButton(loginButton);
  }
Esempio n. 18
0
  public SketchProperties(Editor e, Sketch s) {
    super();

    editor = e;
    sketch = s;

    fields = new HashMap<String, JComponent>();

    this.setPreferredSize(new Dimension(500, 400));
    this.setMinimumSize(new Dimension(500, 400));
    this.setMaximumSize(new Dimension(500, 400));
    this.setSize(new Dimension(500, 400));
    Point eLoc = editor.getLocation();
    int x = eLoc.x;
    int y = eLoc.y;

    Dimension eSize = editor.getSize();
    int w = eSize.width;
    int h = eSize.height;

    int cx = x + (w / 2);
    int cy = y + (h / 2);

    this.setLocation(new Point(cx - 250, cy - 200));
    this.setModal(true);

    outer = new JPanel(new BorderLayout());
    outer.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
    this.add(outer);

    win = new JPanel();
    win.setLayout(new BorderLayout());
    outer.add(win, BorderLayout.CENTER);

    buttonBar = new JPanel(new FlowLayout(FlowLayout.RIGHT));

    saveButton = new JButton("OK");
    saveButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            save();
            SketchProperties.this.dispose();
          }
        });

    cancelButton = new JButton("Cancel");
    cancelButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            SketchProperties.this.dispose();
          }
        });

    buttonBar.add(saveButton);
    buttonBar.add(cancelButton);

    win.add(buttonBar, BorderLayout.SOUTH);

    tabs = new JTabbedPane();

    overviewPane = new JPanel();
    overviewPane.setLayout(new BoxLayout(overviewPane, BoxLayout.PAGE_AXIS));
    overviewPane.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
    addTextField(overviewPane, "author", "Sketch author:");
    addTextArea(overviewPane, "summary", "Summary:");
    addTextArea(overviewPane, "license", "Copyright / License:");
    tabs.add("Overview", overviewPane);

    objectsPane = new JPanel();
    objectsPane.setLayout(new BoxLayout(objectsPane, BoxLayout.PAGE_AXIS));
    objectsPane.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
    addTextField(objectsPane, "board", "Board:");
    addTextField(objectsPane, "core", "Core:");
    addTextField(objectsPane, "compiler", "Compiler:");
    addTextField(objectsPane, "port", "Serial port:");
    addTextField(objectsPane, "programmer", "Programmer:");
    JButton setDef = new JButton("Set to current IDE values");
    setDef.setMaximumSize(setDef.getPreferredSize());
    setDef.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            setObjectValues();
          }
        });
    objectsPane.add(Box.createVerticalGlue());
    objectsPane.add(setDef);

    tabs.add("Objects", objectsPane);

    win.add(tabs, BorderLayout.CENTER);

    this.setTitle("Sketch Properties");

    this.pack();
    this.setVisible(true);
  }
Esempio n. 19
0
 @Override
 public Dimension getPreferredSize() {
   Dimension dim = super.getPreferredSize();
   int w = button.isVisible() ? 80 - button.getPreferredSize().width : 80;
   return new Dimension(w, dim.height);
 }
Esempio n. 20
0
    public CustomDialog(Frame name) {
      super(name, "Customize Text Properties", true);
      this.setResizable(false);
      this.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);

      GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
      String[] fontList = ge.getAvailableFontFamilyNames();
      fontCombo = new JComboBox(fontList);

      italic = new JCheckBox("Italic");
      bold = new JCheckBox("Bold");

      sizeCombo = new JComboBox(stringSize);
      ((JLabel) sizeCombo.getRenderer()).setHorizontalAlignment(SwingConstants.CENTER);
      sizeCombo.setSelectedIndex(4);
      sizeCombo.setPreferredSize(new Dimension(45, 21)); // tweek size

      example = new JTextField(" Preview ");
      example.setHorizontalAlignment(SwingConstants.CENTER);
      example.setFont(new Font("sanserif", Font.PLAIN, 28));
      example.setEditable(false);

      ok = new JButton("Apply");
      cancel = new JButton("Cancel");
      ok.setPreferredSize(cancel.getPreferredSize());

      foreground = new JButton("Edit Color");

      foreground.setPreferredSize(new Dimension(100, 50));

      // add the listeners
      fontCombo.addActionListener(this);
      italic.addItemListener(this);
      bold.addItemListener(this);
      sizeCombo.addActionListener(this);
      ok.addActionListener(this);
      cancel.addActionListener(this);
      foreground.addActionListener(this);

      JPanel p0 = new JPanel();
      p0.add(fontCombo);
      p0.setBorder(new TitledBorder(new EtchedBorder(), "Font family"));

      JPanel p1a = new JPanel();
      p1a.add(italic);
      p1a.add(bold);
      p1a.setBorder(new TitledBorder(new EtchedBorder(), "Font style"));

      JPanel p1b = new JPanel();
      p1b.add(sizeCombo);
      p1b.add(new JLabel("pt."));
      p1b.setBorder(new TitledBorder(new EtchedBorder(), "Font size"));

      JPanel p1 = new JPanel();
      p1.setLayout(new BoxLayout(p1, BoxLayout.X_AXIS));
      p1.add(p1a);
      p1.add(p1b);
      p1.setAlignmentX(Component.CENTER_ALIGNMENT);

      JPanel p2 = new JPanel(); // use FlowLayout
      p2.add(foreground);

      p2.setBorder(new TitledBorder(new EtchedBorder(), "Message color"));
      p2.setAlignmentX(Component.CENTER_ALIGNMENT);

      JPanel p3 = new JPanel();
      p3.setLayout(new BoxLayout(p3, BoxLayout.Y_AXIS));
      p3.add(example);
      p3.setPreferredSize(new Dimension(250, 60));
      p3.setMaximumSize(new Dimension(250, 60));
      p3.setAlignmentX(Component.CENTER_ALIGNMENT);

      JPanel p4 = new JPanel();
      p4.add(ok);
      p4.add(cancel);
      p4.setAlignmentX(Component.CENTER_ALIGNMENT);

      JPanel p = new JPanel();
      p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS));
      p.add(p0);
      p.add(Box.createRigidArea(new Dimension(0, 10)));
      p.add(p1);
      p.add(Box.createRigidArea(new Dimension(0, 10)));
      p.add(p2);
      p.add(Box.createRigidArea(new Dimension(0, 10)));
      p.add(p3);
      p.add(Box.createRigidArea(new Dimension(0, 10)));
      p.add(p4);
      p.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));

      Dimension d1 = p3.getPreferredSize();
      Dimension d2 = p1.getPreferredSize();
      p1.setPreferredSize(new Dimension(d1.width, d2.height));
      p1.setMaximumSize(new Dimension(d1.width, d2.height));
      d2 = p2.getPreferredSize();
      p2.setPreferredSize(new Dimension(d1.width, d2.height));
      p2.setMaximumSize(new Dimension(d1.width, d2.height));

      this.setContentPane(p);
      this.pack();
    }