コード例 #1
0
  public final void initializeGui() {
    // set up the main GUI
    gui.setBorder(new EmptyBorder(5, 5, 5, 5));
    JToolBar tools = new JToolBar();
    tools.setFloatable(false);
    gui.add(tools, BorderLayout.PAGE_START);
    tools.add(new JButton("New")); // TODO - add functionality!
    tools.addSeparator();
    tools.add(new JLabel("Player:")); // TODO - add functionality!
    tools.addSeparator();
    tools.add(message);

    playBoard = new JPanel(new GridLayout(0, 11));
    playBoard.setBorder(new LineBorder(Color.BLACK));
    gui.add(playBoard);

    // create the chess board squares
    Insets buttonMargin = new Insets(0, 0, 0, 0);
    for (int ii = 0; ii < playBoardSquares.length; ii++) {
      for (int jj = 0; jj < playBoardSquares[ii].length; jj++) {
        JButton b = new JButton();
        b.setMargin(buttonMargin);
        // our chess pieces are 64x64 px in size, so we'll
        // 'fill this in' using a transparent icon..
        ImageIcon icon = new ImageIcon(new BufferedImage(50, 50, BufferedImage.TYPE_INT_ARGB));
        b.setIcon(icon);
        b.setBackground(Color.BLUE);
        playBoardSquares[jj][ii] = b;
      }
    }

    // fill the chess board
    playBoard.add(new JLabel(""));
    // fill the top row
    for (int ii = 0; ii < 10; ii++) {
      playBoard.add(new JLabel(COLS.substring(ii, ii + 1), SwingConstants.CENTER));
    }
    // fill the black non-pawn piece row
    for (int ii = 0; ii < 10; ii++) {
      for (int jj = 0; jj < 10; jj++) {
        switch (jj) {
          case 0:
            playBoard.add(new JLabel("" + (ii + 1), SwingConstants.CENTER));
          default:
            playBoard.add(playBoardSquares[jj][ii]);
        }
      }
    }
  }
コード例 #2
0
    /** Returns the tool bar for the panel. */
    protected JComponent getToolBar() {
      JToolBar tbarDir = new JToolBar();
      JButton btnNew = new JButton();
      // m_btnSave = new JButton("Save File");
      // i118n
      // btnNew.setText("New Label");
      btnNew.setText(Util.getAdmLabel("_adm_New_Label"));
      btnNew.setActionCommand("new");
      // m_btnSave.setActionCommand("save");

      ActionListener alTool =
          new ActionListener() {
            public void actionPerformed(ActionEvent e) {
              doAction(e);
            }
          };

      btnNew.addActionListener(alTool);
      // m_btnSave.addActionListener(alTool);

      tbarDir.setFloatable(false);
      tbarDir.add(btnNew);
      /*tbarDir.add(new JLabel("        "));
      tbarDir.add(m_btnSave);*/

      return tbarDir;
    }
コード例 #3
0
ファイル: InterpreterFrame.java プロジェクト: DavePearce/jkit
 private JToolBar buildToolBar() {
   // build tool bar
   JToolBar toolBar = new JToolBar("Toolbar");
   toolBar.add(makeToolbarButton("stock_new.png", "New file", "New"));
   toolBar.add(makeToolbarButton("stock_open.png", "Open file", "Open"));
   toolBar.add(makeToolbarButton("stock_save.png", "Save file", "Save"));
   // run button is special
   runButton = makeToolbarButton("Play24.gif", "Run Program", "Run");
   toolBar.add(runButton);
   toolBar.add(makeToolbarButton("stock_text_left.png", "Pretty Print", "Pretty"));
   toolBar.addSeparator();
   toolBar.add(new JButton(copyAction));
   toolBar.add(new JButton(cutAction));
   toolBar.add(new JButton(pasteAction));
   return toolBar;
 }
コード例 #4
0
ファイル: AnimationWidget.java プロジェクト: nbearson/IDV
  /**
   * Make the UI for this widget.
   *
   * @param floatToolBar true if the toolbar should be floatable
   * @return UI as a Component
   */
  private JComponent doMakeContents(boolean floatToolBar) {

    String imgp = "/auxdata/ui/icons/";
    KeyListener listener =
        new KeyAdapter() {
          public void keyPressed(KeyEvent e) {
            if ((e.getSource() instanceof JComboBox)) {
              return;
            }
            int code = e.getKeyCode();
            char c = e.getKeyChar();
            if ((code == KeyEvent.VK_RIGHT) || (code == KeyEvent.VK_KP_RIGHT)) {
              if (e.isShiftDown()) {
                gotoIndex(anime.getNumSteps() - 1);
              } else {
                actionPerformed(CMD_FORWARD);
              }
            } else if ((code == KeyEvent.VK_LEFT) || (code == KeyEvent.VK_KP_LEFT)) {
              if (e.isShiftDown()) {
                gotoIndex(0);
              } else {
                actionPerformed(CMD_BACKWARD);
              }
            } else if (code == KeyEvent.VK_ENTER) {
              actionPerformed(CMD_STARTSTOP);
            } else if ((code == KeyEvent.VK_P) && e.isControlDown()) {
              actionPerformed(CMD_PROPS);
            } else if (Character.isDigit(c)) {
              int step = new Integer("" + c).intValue() - 1;
              if (step < 0) {
                step = 0;
              }
              if (step >= anime.getNumSteps()) {
                step = anime.getNumSteps() - 1;
              }
              gotoIndex(step);
            }
          }
        };

    List buttonList = new ArrayList();
    buttonList.add(timesCbx);
    // Update the list of times
    setTimesInTimesBox();

    Dimension preferredSize = timesCbx.getPreferredSize();
    if (preferredSize != null) {
      int height = preferredSize.height;
      if (height < 50) {
        JComponent filler = GuiUtils.filler(3, height);
        buttonList.add(filler);
      }
    }

    String[][] buttonInfo = {
      {"Go to first frame", CMD_BEGINNING, getIcon("Rewind")},
      {"One frame back", CMD_BACKWARD, getIcon("StepBack")},
      {"Run/Stop", CMD_STARTSTOP, getIcon("Play")},
      {"One frame forward", CMD_FORWARD, getIcon("StepForward")},
      {"Go to last frame", CMD_END, getIcon("FastForward")},
      {"Properties", CMD_PROPS, getIcon("Information")}
    };

    for (int i = 0; i < buttonInfo.length; i++) {
      JButton btn = GuiUtils.getScaledImageButton(buttonInfo[i][2], getClass(), 2, 2);
      btn.setToolTipText(buttonInfo[i][0]);
      btn.setActionCommand(buttonInfo[i][1]);
      btn.addActionListener(this);
      btn.addKeyListener(listener);
      //            JComponent wrapper = GuiUtils.center(btn);
      //            wrapper.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED));
      btn.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED));
      buttonList.add(btn);
      //            buttonList.add(wrapper);
      if (i == 2) {
        startStopBtn = btn;
      }
    }

    JComponent contents = GuiUtils.hflow(buttonList, 1, 0);
    if (boxPanel == null) {
      boxPanel = new AnimationBoxPanel(this);
      if (timesArray != null) {
        updateBoxPanel(timesArray);
      }
    }
    boxPanel.addKeyListener(listener);
    if (!getBoxPanelVisible()) {
      boxPanel.setVisible(false);
    }
    contents =
        GuiUtils.doLayout(new Component[] {boxPanel, contents}, 1, GuiUtils.WT_Y, GuiUtils.WT_N);
    //      GuiUtils.addKeyListenerRecurse(listener,contents);
    if (floatToolBar) {
      JToolBar toolbar = new JToolBar(JToolBar.HORIZONTAL);
      toolbar.setFloatable(true);
      contents = GuiUtils.left(contents);
      toolbar.add(contents);
      contents = toolbar;
    }

    updateRunButton();
    madeContents = true;
    return contents;
  }
コード例 #5
0
ファイル: SceneLayoutApp.java プロジェクト: jnorthrup/scene
  public SceneLayoutApp() {
    super();
    new Pair();
    final JFrame frame = new JFrame("Scene Layout");

    final JPanel panel = new JPanel(new BorderLayout());
    frame.setContentPane(panel);
    final Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    frame.setMaximumSize(screenSize);
    frame.setSize(screenSize);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    final JMenuBar mb = new JMenuBar();
    frame.setJMenuBar(mb);

    final JMenu jMenu = new JMenu("File");
    mb.add(jMenu);
    mb.add(new JMenu("Edit"));
    mb.add(new JMenu("Help"));
    JMenu menu = new JMenu("Look and Feel");

    //
    // Get all the available look and feel that we are going to use for
    // creating the JMenuItem and assign the action listener to handle
    // the selection of menu item to change the look and feel.
    //
    UIManager.LookAndFeelInfo[] lookAndFeelInfos = UIManager.getInstalledLookAndFeels();
    for (int i = 0; i < lookAndFeelInfos.length; i++) {
      final UIManager.LookAndFeelInfo lookAndFeelInfo = lookAndFeelInfos[i];
      JMenuItem item = new JMenuItem(lookAndFeelInfo.getName());
      item.addActionListener(
          new ActionListener() {
            public void actionPerformed(ActionEvent e) {
              try {
                //
                // Set the look and feel for the frame and update the UI
                // to use a new selected look and feel.
                //
                UIManager.setLookAndFeel(lookAndFeelInfo.getClassName());
                SwingUtilities.updateComponentTreeUI(frame);
              } catch (ClassNotFoundException e1) {
                e1.printStackTrace();
              } catch (InstantiationException e1) {
                e1.printStackTrace();
              } catch (IllegalAccessException e1) {
                e1.printStackTrace();
              } catch (UnsupportedLookAndFeelException e1) {
                e1.printStackTrace();
              }
            }
          });
      menu.add(item);
    }

    mb.add(menu);
    jMenu.add(new JMenuItem(new scene.action.QuitAction()));

    panel.add(new JScrollPane(desktopPane), BorderLayout.CENTER);
    final JToolBar bar = new JToolBar();

    panel.add(bar, BorderLayout.NORTH);

    final JComboBox comboNewWindow =
        new JComboBox(
            new String[] {"320:180", "320:240", "640:360", "640:480", "1280:720", "1920:1080"});

    comboNewWindow.addActionListener(new CreateSceneWindowAction());

    comboNewWindow.setBorder(BorderFactory.createTitledBorder("Create New Window"));
    bar.add(comboNewWindow);
    bar.add(
        new AbstractAction("Progress Bars") {

          /** Invoked when an action occurs. */
          @Override
          public void actionPerformed(ActionEvent e) {
            new ProgressBarAnimator();
          }
        });
    bar.add(
        new AbstractAction("Sliders") {

          /** Invoked when an action occurs. */
          @Override
          public void actionPerformed(ActionEvent e) {
            new SliderBarAnimator();
          }
        });

    final JCheckBox permaViz = new JCheckBox();
    permaViz.setText("Show the dump window");
    permaViz.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED));

    dumpWindow = new JInternalFrame("perma dump window");
    dumpWindow.setContentPane(new JScrollPane(permText));

    permaViz.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            dumpWindow.setVisible(permaViz.isSelected());
          }
        });

    comboNewWindow.setMaximumSize(comboNewWindow.getPreferredSize());

    permaViz.setSelected(false);
    bar.add(new CreateWebViewV1Action());
    bar.add(new CreateWebViewV2Action());
    bar.add(permaViz);
    desktopPane.add(dumpWindow);
    dumpWindow.setSize(400, 400);
    dumpWindow.setResizable(true);
    dumpWindow.setClosable(false);
    dumpWindow.setIconifiable(false);
    final JMenuBar m = new JMenuBar();
    final JMenu cmenu = new JMenu("Create");
    m.add(cmenu);
    final JMenuItem menuItem =
        new JMenuItem(
            new AbstractAction("new") {
              @Override
              public void actionPerformed(ActionEvent e) {
                Runnable runnable =
                    new Runnable() {
                      public void run() {
                        Object[] in = (Object[]) XSTREAM.fromXML(permText.getText());

                        final JInternalFrame ff = new JInternalFrame();

                        final ScenePanel c = new ScenePanel();
                        ff.setContentPane(c);
                        desktopPane.add(ff);
                        final Dimension d = (Dimension) in[0];
                        c.setMaximumSize(d);
                        c.setPreferredSize(d);

                        ff.setSize(d.width + 50, d.height + 50);
                        ScenePanel.panes.put(c, (List<Pair<Point, ArrayList<URL>>>) in[1]);

                        c.invalidate();
                        c.repaint();

                        ff.pack();
                        ff.setClosable(true);

                        ff.setMaximizable(false);
                        ff.setIconifiable(false);
                        ff.setResizable(false);
                        ff.show();
                      }
                    };

                SwingUtilities.invokeLater(runnable);
              }
            });
    cmenu.add(menuItem);
    //        JMenuBar menuBar = new JMenuBar();

    //        getContentPane().add(menuBar);

    dumpWindow.setJMenuBar(m);
    frame.setVisible(true);
  }