Ejemplo n.º 1
0
 public void layoutContainer(Container target) {
   Insets insets = target.getInsets();
   int ncomponents = target.getComponentCount();
   int top = 0;
   int left = insets.left;
   Dimension tps = target.getPreferredSize();
   Dimension targetSize = target.getSize();
   Component comp;
   Dimension ps;
   if (horizontalOrientation == Orientation.CENTER)
     left = left + (targetSize.width / 2) - (tps.width / 2);
   if (horizontalOrientation == Orientation.RIGHT) left = left + targetSize.width - tps.width;
   for (int i = 0; i < ncomponents; i++) {
     comp = target.getComponent(i);
     if (comp.isVisible()) {
       ps = comp.getPreferredSize();
       if (verticalOrientation == Orientation.CENTER)
         top = (targetSize.height / 2) - (ps.height / 2);
       else if (verticalOrientation == Orientation.TOP) top = insets.top;
       else if (verticalOrientation == Orientation.BOTTOM)
         top = targetSize.height - ps.height - insets.bottom;
       comp.setBounds(left, top, ps.width, ps.height);
       left += ps.width + gap;
     }
   }
 }
Ejemplo n.º 2
0
  protected static Point calculateCenter(Container container) {

    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    Dimension containerSize = container.getPreferredSize();

    int x = (screenSize.width / 2) - (containerSize.width / 2);
    int y = (screenSize.height / 2) - (containerSize.height / 2);

    return new Point(x, y);
  }
Ejemplo n.º 3
0
 void makeImage() {
   // if we have no image or if the image has changed
   if (getGraphicsConfiguration() != null && getWidth() > 0) {
     Dimension dim = c.getPreferredSize();
     // width and height must be > 0 to be able to create an image
     if (dim.height > 0) {
       img = getGraphicsConfiguration().createCompatibleImage(getWidth(), dim.height);
       c.setSize(getWidth(), dim.height);
       c.paint(img.getGraphics());
     } else {
       img = null;
     }
   }
 }
Ejemplo n.º 4
0
    @Override
    public Dimension preferredLayoutSize(Container parent) {
      if (parent.isPreferredSizeSet() || parent.getComponentCount() == 0) {
        return parent.getPreferredSize();
      } else {
        int x = -1, y = -1;
        for (Component child : parent.getComponents()) {
          Dimension dim = child.getPreferredSize();
          x = Math.max(dim.width, x);
          y = Math.max(dim.height, y);
        }

        return new Dimension(x, y);
      }
    }
Ejemplo n.º 5
0
  public void updateSize() {
    this.setMinimumSize(this.prefixRowsPanel.getSize());

    // --- update width of the JTextFieldResizing to the max size per
    // column
    // - begin ---
    if (this.prefixRowsPanel.getComponentCount() >= 3) {
      // -- get max width for each column - begin --
      int maxWidthLeftColumn = 10;
      int maxWidthRightColumn = 150;
      Container textField = null;
      Dimension d = null;

      // walk through rows...
      for (int i = 0; i < this.prefixRowsPanel.getComponentCount(); i += 1) {
        // left text field...
        i += 1; // skip Label
        textField = (Container) this.prefixRowsPanel.getComponent(i);

        final Dimension leftSize =
            (textField instanceof JTextFieldResizing)
                ? ((JTextFieldResizing) textField).calculateSize()
                : textField.getPreferredSize();

        maxWidthLeftColumn = Math.max(maxWidthLeftColumn, leftSize.width);

        // right text field...
        i += 1;
        i += 1; // skip Label
        textField = (Container) this.prefixRowsPanel.getComponent(i);

        final Dimension rightSize =
            (textField instanceof JTextFieldResizing)
                ? ((JTextFieldResizing) textField).calculateSize()
                : textField.getPreferredSize();

        maxWidthRightColumn = Math.max(maxWidthRightColumn, rightSize.width);

        i += 1; // skip delete-label
      }
      // -- get max width for each column - end --

      // -- update elements of each column - begin --
      // walk through rows...
      for (int i = 0; i < this.prefixRowsPanel.getComponentCount(); i += 1) {
        i += 1; // skip Label
        // left text field...
        textField = (Container) this.prefixRowsPanel.getComponent(i);
        d = new Dimension(maxWidthLeftColumn, textField.getPreferredSize().height);
        textField.setPreferredSize(d);
        textField.setSize(d);
        textField.setMaximumSize(d);
        textField.setMinimumSize(d);
        textField.repaint();

        // right text field...
        i += 1;
        i += 1; // skip Label
        textField = (Container) this.prefixRowsPanel.getComponent(i);
        d = new Dimension(maxWidthRightColumn, textField.getPreferredSize().height);
        textField.setPreferredSize(d);
        textField.setSize(d);
        textField.setMaximumSize(d);
        textField.setMinimumSize(d);
        textField.repaint();

        i += 1; // skip delete-label
      }
      // -- update elements of each column - end --
    }
    // --- update width of the JTextFieldResizing to the max size per
    // column
    // - begin ---

    // update height of the GraphBox...
    if (this.getBox() != null) {
      this.getBox().height = this.getPreferredSize().height;
    }

    this.setSize(this.getPreferredSize());
    this.revalidate(); // re-validate the PrefixPanel
  }
Ejemplo n.º 6
0
 /**
  * Creates a new TotalScaleLayout.
  *
  * @param parent The container to layout.
  */
 public TotalScaleLayout(Container parent) {
   this.parent = parent;
   preferredSize = parent.getPreferredSize();
   minimumSize = parent.getMinimumSize();
 }
Ejemplo n.º 7
0
 @Override
 public Dimension preferredLayoutSize(Container parent) {
   return parent.getPreferredSize();
 }
Ejemplo n.º 8
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();
          }
        }
      });
  }