コード例 #1
0
ファイル: Preferences.java プロジェクト: amaxilat/Arduino
  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();
          }
        }
      });
  }
コード例 #2
0
  public Whiteboard() {
    setTitle("Distributed Whiteboard");
    setResizable(false);

    btnIcon = new ImageIcon();
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    setSize(802, 607);

    JSplitPane splitPane = new JSplitPane();
    splitPane.setAutoscrolls(true);
    splitPane.setDividerSize(0);
    getContentPane().add(splitPane, BorderLayout.CENTER);

    Container drawingCanvas = new Container();
    drawingCanvas.setBackground(_bgColor);
    drawingCanvas.setForeground(_bgColor);
    splitPane.setRightComponent(drawingCanvas);

    canvas = new DrawingCanvas();
    canvas.setAutoscrolls(true);
    canvas.setBounds(0, 0, 679, 494);

    drawingCanvas.add(canvas);

    JPanel pnlTools = new JPanel();
    splitPane.setLeftComponent(pnlTools);
    GridBagLayout gbl_pnlTools = new GridBagLayout();
    gbl_pnlTools.columnWidths = new int[] {45, 30, 0, 0};
    gbl_pnlTools.rowHeights = new int[] {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
    gbl_pnlTools.columnWeights = new double[] {1.0, 0.0, 0.0, Double.MIN_VALUE};
    gbl_pnlTools.rowWeights =
        new double[] {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, Double.MIN_VALUE};
    pnlTools.setLayout(gbl_pnlTools);

    btnIcon = new ImageIcon("images/free_a.jpg");
    btnFreedraw = new JToggleButton(btnIcon);
    btnFreedraw.setToolTipText("Freedraw");
    btnIcon = new ImageIcon("images/free_b.jpg");
    btnFreedraw.setSelectedIcon(btnIcon);
    btnFreedraw.setActionCommand("Freedraw");
    btnFreedraw.addActionListener(this);
    btnFreedraw.setBorder(new BevelBorder(BevelBorder.RAISED, null, null, null, null));
    GridBagConstraints gbc_tglbtnFreedraw = new GridBagConstraints();
    gbc_tglbtnFreedraw.insets = new Insets(0, 0, 5, 5);
    gbc_tglbtnFreedraw.gridx = 0;
    gbc_tglbtnFreedraw.gridy = 0;
    pnlTools.add(btnFreedraw, gbc_tglbtnFreedraw);

    btnIcon = new ImageIcon("images/line_a.jpg");
    btnLine = new JToggleButton(btnIcon);
    btnLine.setToolTipText("Draw line");
    btnIcon = new ImageIcon("images/line_b.jpg");
    btnLine.setSelectedIcon(btnIcon);
    btnLine.setActionCommand("Line");
    btnLine.addActionListener(this);
    btnLine.setBorder(new BevelBorder(BevelBorder.RAISED, null, null, null, null));
    GridBagConstraints gbc_btnLine = new GridBagConstraints();
    gbc_btnLine.insets = new Insets(0, 0, 5, 5);
    gbc_btnLine.gridx = 1;
    gbc_btnLine.gridy = 0;
    pnlTools.add(btnLine, gbc_btnLine);

    btnIcon = new ImageIcon("images/circle_a.jpg");
    btnCircle = new JToggleButton(btnIcon);
    btnCircle.setToolTipText("Draw circle");
    btnIcon = new ImageIcon("images/circle_b.jpg");
    btnCircle.setSelectedIcon(btnIcon);
    btnCircle.setActionCommand("Circle");
    btnCircle.addActionListener(this);
    btnCircle.setBorder(new BevelBorder(BevelBorder.RAISED, null, null, null, null));
    GridBagConstraints gbc_btnCircle = new GridBagConstraints();
    gbc_btnCircle.insets = new Insets(0, 0, 5, 5);
    gbc_btnCircle.gridx = 0;
    gbc_btnCircle.gridy = 1;
    pnlTools.add(btnCircle, gbc_btnCircle);

    btnIcon = new ImageIcon("images/ellipse_a.jpg");
    btnOval = new JToggleButton(btnIcon);
    btnOval.setToolTipText("Draw ellipse");
    btnIcon = new ImageIcon("images/ellipse_b.jpg");
    btnOval.setSelectedIcon(btnIcon);
    btnOval.setBorder(new BevelBorder(BevelBorder.RAISED, null, null, null, null));
    btnOval.setActionCommand("Oval");
    btnOval.addActionListener(this);
    GridBagConstraints gbc_btnOval = new GridBagConstraints();
    gbc_btnOval.insets = new Insets(0, 0, 5, 5);
    gbc_btnOval.gridx = 1;
    gbc_btnOval.gridy = 1;
    pnlTools.add(btnOval, gbc_btnOval);

    btnIcon = new ImageIcon("images/square_a.jpg");
    btnSquare = new JToggleButton(btnIcon);
    btnSquare.setToolTipText("Square");
    btnIcon = new ImageIcon("images/square_b.jpg");
    btnSquare.setSelectedIcon(btnIcon);
    btnSquare.setActionCommand("Square");
    btnSquare.addActionListener(this);
    btnSquare.setBorder(new BevelBorder(BevelBorder.RAISED, null, null, null, null));
    GridBagConstraints gbc_btnSquare = new GridBagConstraints();
    gbc_btnSquare.insets = new Insets(0, 0, 5, 5);
    gbc_btnSquare.gridx = 0;
    gbc_btnSquare.gridy = 2;
    pnlTools.add(btnSquare, gbc_btnSquare);

    btnIcon = new ImageIcon("images/rectangle_a.jpg");
    btnRectangle = new JToggleButton(btnIcon);
    btnRectangle.setToolTipText("Draw rectangle");
    btnIcon = new ImageIcon("images/rectangle_b.jpg");
    btnRectangle.setSelectedIcon(btnIcon);
    btnRectangle.setBorder(new BevelBorder(BevelBorder.RAISED, null, null, null, null));
    btnRectangle.setActionCommand("Rectangle");
    btnRectangle.addActionListener(this);
    GridBagConstraints gbc_btnRectangle = new GridBagConstraints();
    gbc_btnRectangle.insets = new Insets(0, 0, 5, 5);
    gbc_btnRectangle.gridx = 1;
    gbc_btnRectangle.gridy = 2;
    pnlTools.add(btnRectangle, gbc_btnRectangle);

    btnIcon = new ImageIcon("images/text_a.jpg");
    btnText = new JToggleButton(btnIcon);
    btnText.setToolTipText("Insert text");
    btnIcon = new ImageIcon("images/text_b.jpg");
    btnText.setSelectedIcon(btnIcon);
    btnText.setBorder(new BevelBorder(BevelBorder.RAISED, null, null, null, null));
    btnText.setActionCommand("Text");
    btnText.addActionListener(this);
    GridBagConstraints gbc_btnText = new GridBagConstraints();
    gbc_btnText.insets = new Insets(0, 0, 5, 5);
    gbc_btnText.gridx = 0;
    gbc_btnText.gridy = 3;
    pnlTools.add(btnText, gbc_btnText);

    btnIcon = new ImageIcon("images/fill_a.jpg");
    btnFill = new JToggleButton(btnIcon);
    btnFill.setToolTipText("Fill");
    btnIcon = new ImageIcon("images/fill_b.jpg");
    btnFill.setSelectedIcon(btnIcon);
    btnFill.setBorder(new BevelBorder(BevelBorder.RAISED, null, null, null, null));
    btnFill.setActionCommand("Fill");
    btnFill.addActionListener(this);
    GridBagConstraints gbc_btnFill = new GridBagConstraints();
    gbc_btnFill.insets = new Insets(0, 0, 5, 5);
    gbc_btnFill.gridx = 1;
    gbc_btnFill.gridy = 3;
    pnlTools.add(btnFill, gbc_btnFill);

    btnIcon = new ImageIcon("images/erase_a.jpg");
    btnErase = new JToggleButton(btnIcon);
    btnErase.setToolTipText("Erase");
    btnIcon = new ImageIcon("images/erase_b.jpg");
    btnErase.setSelectedIcon(btnIcon);
    btnErase.setActionCommand("Erase");
    btnErase.addActionListener(this);
    btnErase.setBorder(new BevelBorder(BevelBorder.RAISED, null, null, null, null));
    GridBagConstraints gbc_btnErase = new GridBagConstraints();
    gbc_btnErase.insets = new Insets(0, 0, 5, 5);
    gbc_btnErase.gridx = 0;
    gbc_btnErase.gridy = 4;
    pnlTools.add(btnErase, gbc_btnErase);

    ButtonGroup group = new ButtonGroup();
    group.add(btnFreedraw);
    group.add(btnLine);
    group.add(btnCircle);
    group.add(btnOval);
    group.add(btnSquare);
    group.add(btnRectangle);
    group.add(btnText);
    group.add(btnErase);

    JPanel pnlPreviews = new JPanel();
    GridBagConstraints gbc_pnlPreviews = new GridBagConstraints();
    gbc_pnlPreviews.gridwidth = 3;
    gbc_pnlPreviews.fill = GridBagConstraints.BOTH;
    gbc_pnlPreviews.gridx = 0;
    gbc_pnlPreviews.gridy = 8;
    pnlTools.add(pnlPreviews, gbc_pnlPreviews);
    GridBagLayout gbl_pnlPreviews = new GridBagLayout();
    gbl_pnlPreviews.columnWidths = new int[] {0, 0};
    gbl_pnlPreviews.rowHeights = new int[] {0, 0, 0, 0, 0, 0, 0};
    gbl_pnlPreviews.columnWeights = new double[] {1.0, Double.MIN_VALUE};
    gbl_pnlPreviews.rowWeights = new double[] {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE};
    pnlPreviews.setLayout(gbl_pnlPreviews);

    JSeparator separator_2 = new JSeparator();
    GridBagConstraints gbc_separator_2 = new GridBagConstraints();
    gbc_separator_2.insets = new Insets(0, 0, 5, 0);
    gbc_separator_2.gridx = 0;
    gbc_separator_2.gridy = 1;
    pnlPreviews.add(separator_2, gbc_separator_2);

    JLabel label = new JLabel("");
    GridBagConstraints gbc_label = new GridBagConstraints();
    gbc_label.insets = new Insets(0, 0, 5, 0);
    gbc_label.gridx = 0;
    gbc_label.gridy = 2;
    pnlPreviews.add(label, gbc_label);

    lblPenSize = new JLabel("Pen Size");
    lblPenSize.setBorder(new BevelBorder(BevelBorder.LOWERED, null, null, null, null));
    GridBagConstraints gbc_lblPenSize = new GridBagConstraints();
    gbc_lblPenSize.insets = new Insets(0, 0, 5, 0);
    gbc_lblPenSize.gridx = 0;
    gbc_lblPenSize.gridy = 3;
    pnlPreviews.add(lblPenSize, gbc_lblPenSize);

    cboPenSize = new JComboBox<String>();
    cboPenSize.setModel(
        new DefaultComboBoxModel<String>(
            new String[] {"1", "2", "4", "6", "8", "10", "12", "14", "16", "18", "20"}));
    cboPenSize.setSelectedIndex(1);
    cboPenSize.setToolTipText("Pen and Eraser Size");
    GridBagConstraints gbc_cboPenSize = new GridBagConstraints();
    gbc_cboPenSize.insets = new Insets(0, 0, 5, 0);
    gbc_cboPenSize.fill = GridBagConstraints.HORIZONTAL;
    gbc_cboPenSize.gridx = 0;
    gbc_cboPenSize.gridy = 4;
    pnlPreviews.add(cboPenSize, gbc_cboPenSize);
    cboPenSize.addItemListener(
        new ItemListener() {
          public void itemStateChanged(ItemEvent ie) {
            _penWidth = Integer.parseInt(cboPenSize.getSelectedItem().toString());
            pen.setPen(_penWidth, pen.getPen().getEndCap(), pen.getPen().getLineJoin());
            canvas.setPen(pen);
            revalidate();
          }
        });

    pnlColorChooser = new JPanel();
    getContentPane().add(pnlColorChooser, BorderLayout.SOUTH);
    GridBagLayout gbl_pnlColorChooser = new GridBagLayout();
    gbl_pnlColorChooser.columnWidths = new int[] {0, 62, 0, 36, 0};
    gbl_pnlColorChooser.rowHeights = new int[] {0, 0, 0};
    gbl_pnlColorChooser.columnWeights = new double[] {0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE};
    gbl_pnlColorChooser.rowWeights = new double[] {0.0, 0.0, Double.MIN_VALUE};
    pnlColorChooser.setLayout(gbl_pnlColorChooser);

    btnColor = new JButton("Pen Color");
    btnColor.setActionCommand("PenColor");
    btnColor.addActionListener(this);
    GridBagConstraints gbc_btnColor = new GridBagConstraints();
    gbc_btnColor.insets = new Insets(0, 0, 5, 5);
    gbc_btnColor.gridx = 0;
    gbc_btnColor.gridy = 0;
    pnlColorChooser.add(btnColor, gbc_btnColor);

    lblColor = new JLabel("");
    lblColor.setPreferredSize(new Dimension(79, 23));
    lblColor.setMinimumSize(new Dimension(79, 23));
    lblColor.setMaximumSize(new Dimension(79, 23));
    lblColor.setOpaque(true);
    lblColor.setBorder(new BevelBorder(BevelBorder.LOWERED, null, null, null, Color.BLACK));
    lblColor.setBackground(Color.BLACK);
    GridBagConstraints gbc_lblColor = new GridBagConstraints();
    gbc_lblColor.insets = new Insets(0, 0, 0, 5);
    gbc_lblColor.gridx = 0;
    gbc_lblColor.gridy = 1;
    pnlColorChooser.add(lblColor, gbc_lblColor);

    JLabel lblSelectedTool = new JLabel("Selected Tool:");
    lblSelectedTool.setFont(new Font("Tahoma", Font.ITALIC, 10));
    GridBagConstraints gbc_lblSelectedTool = new GridBagConstraints();
    gbc_lblSelectedTool.insets = new Insets(0, 0, 0, 5);
    gbc_lblSelectedTool.gridx = 2;
    gbc_lblSelectedTool.gridy = 1;
    pnlColorChooser.add(lblSelectedTool, gbc_lblSelectedTool);

    lblTool = new JLabel("");
    lblTool.setHorizontalAlignment(SwingConstants.LEFT);
    lblTool.setFont(new Font("Tahoma", Font.BOLD | Font.ITALIC, 12));
    GridBagConstraints gbc_lblTool = new GridBagConstraints();
    gbc_lblTool.gridx = 3;
    gbc_lblTool.gridy = 1;
    pnlColorChooser.add(lblTool, gbc_lblTool);
    pnlColorChooser.setVisible(true);

    JMenuBar menuMainMenu = new JMenuBar();
    menuMainMenu.setName("");
    setJMenuBar(menuMainMenu);

    JMenu mnFile = new JMenu("File");
    mnFile.setActionCommand("File");
    menuMainMenu.add(mnFile);

    mntmNew = new JMenuItem("New");
    mntmNew.setMnemonic(KeyEvent.VK_N);
    mntmNew.setActionCommand("New");
    mntmNew.addActionListener(this);
    mnFile.add(mntmNew);

    mntmOpen = new JMenuItem("Open");
    mntmOpen.setMnemonic(KeyEvent.VK_O);
    mntmOpen.setActionCommand("Open");
    mntmOpen.addActionListener(this);
    mnFile.add(mntmOpen);

    JSeparator separator = new JSeparator();
    mnFile.add(separator);

    mntmSave = new JMenuItem("Save");
    mntmSave.setMnemonic(KeyEvent.VK_S);
    mntmSave.setActionCommand("Save");
    mntmSave.addActionListener(this);
    mnFile.add(mntmSave);

    mntmSaveAs = new JMenuItem("Save As");
    mntmSaveAs.setActionCommand("SaveAs");
    mntmSaveAs.addActionListener(this);
    mnFile.add(mntmSaveAs);

    JSeparator separator_1 = new JSeparator();
    mnFile.add(separator_1);

    mntmExit = new JMenuItem("Exit");
    mntmExit.setMnemonic(KeyEvent.VK_E);
    mntmExit.setActionCommand("Exit");
    mntmExit.addActionListener(this);
    mnFile.add(mntmExit);

    JMenu mnNetwork = new JMenu("Network");
    mnNetwork.setActionCommand("Network");
    menuMainMenu.add(mnNetwork);

    mntmConnect = new JMenuItem("Connect");
    mntmConnect.setMnemonic(KeyEvent.VK_C);
    mntmConnect.setActionCommand("Connect");
    mntmConnect.addActionListener(this);
    mnNetwork.add(mntmConnect);

    mntmDisconnect = new JMenuItem("Disconnect");
    mntmDisconnect.setMnemonic(KeyEvent.VK_D);
    mntmDisconnect.setActionCommand("Disconnect");
    mntmDisconnect.addActionListener(this);
    mntmDisconnect.setEnabled(false);
    mnNetwork.add(mntmDisconnect);

    JSeparator separator_3 = new JSeparator();
    mnNetwork.add(separator_3);

    addWindowListener(
        new WindowAdapter() {
          public void windowClosing(WindowEvent e) {
            closeOperation();
          }
        });
  }
コード例 #3
0
ファイル: Piano.java プロジェクト: kimboha/CatchMelody
  /** Constructs the GUI */
  public Piano(String userID, int userImgNum) {
    this.userID = userID;
    this.userImgNum = userImgNum;
    // ----------- 소켓 생성 ------------
    try {
      sock = new Socket(SERVER_IP, 10001);
      pw = new PrintWriter(new OutputStreamWriter(sock.getOutputStream()));
      br = new BufferedReader(new InputStreamReader(sock.getInputStream()));
      pw.println(this.userImgNum + this.userID);
      pw.flush();
    } catch (Exception ex) {
      System.out.println("서버와 접속시 오류가 발생하였습니다.");
      System.out.println(ex);
      System.exit(1);
    }
    //// 현재 클라이언트 수 파악
    try {
      String cnt = br.readLine();
      cntClient = Integer.parseInt(cnt);
      if (cntClient == -1) {
        JOptionPane.showMessageDialog(null, "게임 도중에 접속할 수 없습니다.");
        System.exit(0);
      } else if (cntClient >= 4) {
        JOptionPane.showMessageDialog(null, "방이 꽉 찼습니다.");
        System.exit(0);
      } else if (cntClient == 0) {
        // 내가 첫 입장이면
        this.bMaster = true;
        pw.println(FLAG_MASTER);
        pw.flush();
      }

      String bExist = br.readLine();
      if (bExist.equals("false")) {
        JOptionPane.showMessageDialog(null, "동일한 ID가 존재합니다.");
        System.exit(0);
      }

    } catch (IOException e) {
      e.printStackTrace();
    }

    // ----------- 채팅 스레드 생성-----------
    InputThread inputThread = new InputThread(sock, br);
    inputThread.start();

    // ------------ Create GUI -----------
    frame = new JFrame("Piano GUI");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    // Create the mainPanel
    Container mainPanel = frame.getContentPane();
    // mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.Y_AXIS));
    mainPanel.setLayout(new GridLayout(3, 1, 20, 0));
    mainPanel.setForeground(Color.WHITE);
    mainPanel.setBackground(Color.BLACK);
    // mainPanel.add(Box.createRigidArea(new Dimension(0,10)));

    // ---- Instrument and tempo panel
    // ---------------------------------------------------------------
    ImagePanel iTpanel = new ImagePanel("images/background1.png");
    // iTpanel = new ImagePanel("images/background1.png");
    iTpanel.setLayout(new BoxLayout(iTpanel, BoxLayout.X_AXIS));
    iTpanel.setForeground(Color.WHITE);
    iTpanel.setBackground(Color.GREEN);
    iTpanel.add(Box.createRigidArea(new Dimension(20, 0)));

    // --- User1 ---
    userPane1 = new JPanel();
    userPane1.setLayout(new BoxLayout(userPane1, BoxLayout.Y_AXIS));
    userPane1.setBackground(Color.GRAY);
    // img + label
    icon1 = new ImageIcon("images/user.jpg");
    UserImage1 = new JLabel(icon1);
    userPane1.add(UserImage1);
    // label pane
    labelPane1 = new JPanel();
    labelPane1.setLayout(new BoxLayout(labelPane1, BoxLayout.X_AXIS));
    labelPane1.setBackground(Color.GRAY);
    labelPane1.setMaximumSize(new Dimension(UserImage1.getPreferredSize().width, 20));
    UserLabel1 = new JLabel(" ");
    UserLabel1.setForeground(Color.WHITE);
    labelPane1.add(UserLabel1);
    labelPane1.add(Box.createRigidArea(new Dimension(10, 0)));
    ScoreLabel1 = new JLabel(" ");
    ScoreLabel1.setForeground(Color.YELLOW);
    labelPane1.add(ScoreLabel1);
    labelPane1.setAlignmentX(Component.LEFT_ALIGNMENT);
    userPane1.add(labelPane1);
    iTpanel.add(userPane1);
    iTpanel.add(Box.createRigidArea(new Dimension(10, 0)));

    // --- User2 ---
    userPane2 = new JPanel();
    userPane2.setLayout(new BoxLayout(userPane2, BoxLayout.Y_AXIS));
    userPane2.setBackground(Color.GRAY);
    // img + label
    icon2 = new ImageIcon("images/user.jpg");
    UserImage2 = new JLabel(icon2);
    userPane2.add(UserImage2);
    // label pane
    labelPane2 = new JPanel();
    labelPane2.setLayout(new BoxLayout(labelPane2, BoxLayout.X_AXIS));
    labelPane2.setBackground(Color.GRAY);
    labelPane2.setMaximumSize(new Dimension(UserImage2.getPreferredSize().width, 20));
    UserLabel2 = new JLabel(" ");
    UserLabel2.setForeground(Color.WHITE);
    labelPane2.add(UserLabel2);
    labelPane2.add(Box.createRigidArea(new Dimension(10, 0)));
    ScoreLabel2 = new JLabel(" ");
    ScoreLabel2.setForeground(Color.YELLOW);
    labelPane2.add(ScoreLabel2);
    labelPane2.setAlignmentX(Component.LEFT_ALIGNMENT);
    userPane2.add(labelPane2);
    iTpanel.add(userPane2);
    iTpanel.add(Box.createRigidArea(new Dimension(50, 0)));

    // 정답 및 힌트
    JPanel at = new JPanel();
    at.setLayout(new BoxLayout(at, BoxLayout.Y_AXIS));
    // at.setLayout(new GridLayout(2,1));
    answer = new JLabel("노래 정답", JLabel.CENTER);
    Border border = BorderFactory.createLineBorder(Color.WHITE, 2);
    answer.setBorder(border);
    answer.setForeground(Color.WHITE);
    answer.setBackground(Color.BLACK);
    answer.setOpaque(true);
    answer.setSize(5, 5);
    at.add(answer);

    time = new JLabel("시간", JLabel.CENTER);
    time.setBorder(border);
    time.setForeground(Color.WHITE);
    time.setBackground(Color.BLACK);
    time.setOpaque(true);
    time.setSize(10, 5);
    at.add(time);

    // ----------- 시간 스레드 생성-----------
    // tt = new TimeThread(time,sock,pw);

    iTpanel.add(at);
    iTpanel.add(Box.createRigidArea(new Dimension(80, 0)));

    /*JLabel time = new JLabel("시간",JLabel.CENTER);
    time.setForeground(Color.WHITE);
    time.setBackground(Color.BLACK);
    time.setOpaque(true);
    iTpanel.add(time);*/

    // ImageIcon hintImg = new ImageIcon("images/hint01.jpg");
    hintImg = new ImageIcon("images/hint0.png");
    hint = new JLabel(hintImg);
    hint.setForeground(Color.BLACK);
    iTpanel.add(hint);
    iTpanel.add(Box.createRigidArea(new Dimension(300, 0)));

    // Add iTpanel to mainPanel
    mainPanel.add(iTpanel);

    // -------- piano keys panel
    // -----------------------------------------------------------------------------------
    JLayeredPane pianoKeyPanel = makeKeys();
    mainPanel.add(pianoKeyPanel);

    // ---- Buttom panel
    // ----------------------------------------------------------------------------------
    ImagePanel iTpane2 = new ImagePanel("images/background3.png");
    iTpane2.setLayout(new BoxLayout(iTpane2, BoxLayout.X_AXIS));
    iTpane2.setForeground(Color.WHITE);
    iTpane2.setBackground(Color.BLACK);
    iTpane2.add(Box.createRigidArea(new Dimension(100, 0)));

    // Instrument List
    JPanel controlPanel = new JPanel();
    controlPanel.setLayout(new FlowLayout());
    InstList = new List(4, false);
    InstList.add("피아노");
    InstList.add("기타");
    InstList.add("비브라폰");
    InstList.add("바이올린");
    InstList.addActionListener(this);
    controlPanel.setOpaque(false);
    controlPanel.add(InstList);
    iTpane2.add(controlPanel);
    InstList.select(0);

    // ---- chatting pane ----
    JPanel chatPane = new JPanel();
    chatPane.setLayout(new BorderLayout(0, 5));
    chatPane.setBackground(Color.BLACK);

    // chatting box
    chatBox = new JTextArea();
    chatBox.setFont(new Font("Ariel", Font.PLAIN, 14));
    JScrollPane scrollPane = new JScrollPane(chatBox);
    chatPane.add(scrollPane, BorderLayout.CENTER);

    // ---chat write box (input)----
    JPanel chatInputPane = new JPanel();
    chatInputPane.setLayout(new BoxLayout(chatInputPane, BoxLayout.X_AXIS));
    // chatInputText 채팅 입력 창
    chatInputText = new JTextField();
    chatInputText.setFont(new Font("Ariel", Font.PLAIN, 14));
    chatInputText.addActionListener(this);
    chatInputPane.add(chatInputText);

    // Send Button
    chatBtn = new JButton("send");
    chatBtn.addActionListener(this);
    chatBtn.setName("chatBtn");
    chatInputPane.add(chatBtn);

    chatPane.add(chatInputPane, BorderLayout.SOUTH);

    // attach
    iTpane2.add(chatPane);
    iTpane2.add(Box.createRigidArea(new Dimension(10, 0)));

    // start button
    btStart = new JButton("start");
    btStart.addActionListener(this);
    btStart.setName("btStart");
    iTpane2.add(btStart);
    iTpane2.add(Box.createRigidArea(new Dimension(10, 0)));
    btStart.setEnabled(false);

    // User
    userPane3 = new JPanel();
    userPane3.setLayout(new BoxLayout(userPane3, BoxLayout.Y_AXIS));
    userPane3.setBackground(Color.GRAY);
    icon3 = new ImageIcon("images/user.jpg");
    UserImage3 = new JLabel(icon3);
    userPane3.add(UserImage3);
    // label pane
    labelPane3 = new JPanel();
    labelPane3.setLayout(new BoxLayout(labelPane3, BoxLayout.X_AXIS));
    labelPane3.setBackground(Color.GRAY);
    labelPane3.setMaximumSize(new Dimension(UserImage3.getPreferredSize().width, 20));
    UserLabel3 = new JLabel(" ");
    UserLabel3.setForeground(Color.WHITE);
    labelPane3.add(UserLabel3);
    labelPane3.add(Box.createRigidArea(new Dimension(10, 0)));
    ScoreLabel3 = new JLabel(" ");
    ScoreLabel3.setForeground(Color.YELLOW);
    labelPane3.add(ScoreLabel3);
    labelPane3.setAlignmentX(Component.LEFT_ALIGNMENT);
    userPane3.add(labelPane3);
    iTpane2.add(userPane3);
    iTpane2.add(Box.createRigidArea(new Dimension(10, 0)));

    userPane4 = new JPanel();
    userPane4.setLayout(new BoxLayout(userPane4, BoxLayout.Y_AXIS));
    userPane4.setBackground(Color.GRAY);
    icon4 = new ImageIcon("images/user.jpg");
    UserImage4 = new JLabel(icon4);
    userPane4.add(UserImage4);
    // label pane
    labelPane4 = new JPanel();
    labelPane4.setLayout(new BoxLayout(labelPane4, BoxLayout.X_AXIS));
    labelPane4.setBackground(Color.GRAY);
    labelPane4.setMaximumSize(new Dimension(UserImage4.getPreferredSize().width, 20));
    UserLabel4 = new JLabel(" ");
    UserLabel4.setForeground(Color.WHITE);
    labelPane4.add(UserLabel4);
    labelPane4.add(Box.createRigidArea(new Dimension(10, 0)));
    ScoreLabel4 = new JLabel(" ");
    ScoreLabel4.setForeground(Color.YELLOW);
    labelPane4.add(ScoreLabel4);
    labelPane4.setAlignmentX(Component.LEFT_ALIGNMENT);
    userPane4.add(labelPane4);
    iTpane2.add(userPane4);
    iTpane2.add(Box.createRigidArea(new Dimension(20, 0)));

    // Add iTpanel to mainPanel
    mainPanel.add(iTpane2);
    // mainPanel.add(Box.createRigidArea(new Dimension(0,20)));

    // Show the window
    frame.setVisible(true);
    frame.setResizable(false);
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    frame.setLocation(
        (screenSize.width - frame.getWidth()) / 2 - 450,
        (screenSize.height - frame.getHeight()) / 2 - 290);
    frame.setSize(900, 580);
  } // 생성자 끝