Пример #1
0
 /**
  * Create a menu for the app. By default this pulls the definition of the menu from the associated
  * resource file.
  */
 protected JMenu createMenu(String key) {
   JMenu menu = new JMenu(getResourceString(key + labelSuffix));
   for (String itemKey : getItemKeys(key)) {
     if (itemKey.equals("-")) {
       menu.addSeparator();
     } else {
       JMenuItem mi = createMenuItem(itemKey);
       menu.add(mi);
     }
   }
   return menu;
 }
Пример #2
0
 // create the menu bar (changed to private)
 private static JMenuBar createMenuBar() {
   JMenuBar menuBar = new JMenuBar();
   JMenu menu = new JMenu("File");
   menuBar.add(menu);
   JMenuItem saveItem = new JMenuItem(" Save...   ");
   saveItem.addActionListener(std);
   saveItem.setAccelerator(
       KeyStroke.getKeyStroke(
           KeyEvent.VK_S, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
   menu.add(saveItem);
   return menuBar;
 }
Пример #3
0
  private void addMenuToTray() {
    HashMap categories = new HashMap();

    // create menu list
    Iterator plugins = PluginManager.getInstance().getAvailablePlugins();
    plugins = PluginComparator.sortPlugins(plugins);

    while (plugins.hasNext()) {
      Plugin p = (Plugin) plugins.next();

      JMenu category = (JMenu) categories.get(p.getCategory());
      if (category == null) {
        category = new JMenu(p.getCategory());
        categories.put(p.getCategory(), category);

        // copy menu to real one
        if (!p.getCategory().equals("Invisible")) this.trayIcon.add(category);
      }

      ImageIcon icon = new ImageIcon();
      try {
        icon = new ImageIcon(new URL(p.getDirectory() + p.getIcon()));
        icon = new ImageIcon(icon.getImage().getScaledInstance(16, 16, Image.SCALE_SMOOTH));
      } catch (Exception e) {
        // error at icon loading
      }

      JMenuItem menu = new JMenuItem(p.getTitle(), icon);
      menu.setName(p.getName());
      menu.setToolTipText(p.getToolTip());
      menu.addActionListener(this);
      category.add(menu);
    }

    this.trayIcon.addSeparator();

    // windows
    this.trayIcon.add(new WindowMenu(this));

    // open main interface
    JMenuItem menu = new JMenuItem(tr("open"));
    menu.setName("org.lucane.applications.maininterface");
    menu.addActionListener(this);
    this.trayIcon.add(menu);

    // exit
    menu = new JMenuItem(tr("exit"));
    menu.setName("exit");
    menu.addActionListener(this);
    this.trayIcon.add(menu);
  }
Пример #4
0
  public void populateMenu(JMenu menu, int flags) {
    if (flags == (Plugin.MENU_TOOLS | Plugin.MENU_MID)) {
      Sketch sketch = editor.getSketch();
      JMenuItem item = new JMenu("Program Bootloader");
      item.addActionListener(
          new ActionListener() {
            public void actionPerformed(ActionEvent e) {
              run();
            }
          });
      menu.add(item);

      PropertyFile props = sketch.mergeAllProperties();
      String blProgs = props.get("bootloader.upload");
      if (blProgs == null) {
        JMenuItem sub = new JMenuItem("No bootloader programmer defined!");
        item.add(sub);
        return;
      }
      String[] progs = blProgs.split("::");
      for (String prog : progs) {
        JMenuItem sub = new JMenuItem(sketch.parseString(props.get("upload." + prog + ".name")));
        sub.setActionCommand(prog);
        sub.addActionListener(
            new ActionListener() {
              public void actionPerformed(ActionEvent e) {
                doProgram(e.getActionCommand());
              }
            });
        item.add(sub);
      }
    }
  }
Пример #5
0
  public void initUI() {
    try {
      UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
      JPopupMenu.setDefaultLightWeightPopupEnabled(false);
      frame = new JFrame("Project Benelux | 317 | Fullscreen - Resizeable");
      frame.setLayout(new BorderLayout());
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      gamePanel = new JPanel();
      new AutoUpdater().run();
      webclient = false;
      gamePanel.setLayout(new BorderLayout());
      gamePanel.add(this);
      JMenu fileMenu = new JMenu("File");

      String[] mainButtons = new String[] {"-", "Exit", "-"};

      for (String name : mainButtons) {
        JMenuItem menuItem = new JMenuItem(name);
        if (name.equalsIgnoreCase("-")) {
          fileMenu.addSeparator();
        } else {
          menuItem.addActionListener(this);
          fileMenu.add(menuItem);
        }
      }

      JMenuBar menuBar = new JMenuBar();
      JMenuBar jmenubar = new JMenuBar();
      Dimension dimension1 = new Dimension(765 + 16, 503 + 59);
      frame.setMinimumSize(dimension1);
      frame.add(jmenubar);
      menuBar.add(fileMenu);
      frame.getContentPane().add(menuBar, BorderLayout.NORTH);
      frame.getContentPane().add(gamePanel, BorderLayout.CENTER);
      frame.pack();

      frame.setVisible(true); // can see the client
      frame.setResizable(true); // resizeable frame
      init();
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
Пример #6
0
  public ShowComp() throws InterruptedException, IOException {
    super("CONNECTED COMPUTERS");
    int x = 0, d = 20;
    mb = new JMenuBar();
    File = new JMenu("File");
    mb.add(File);
    exit = new JMenuItem("Exit");
    exit.addActionListener(this);
    File.add(exit);
    ta = new JTextArea();
    ta.setBounds(20, 30, 315, 470);
    ta.setEditable(false);
    add(ta);

    setJMenuBar(mb);

    sel = new JLabel("The connected computers are..");
    sel.setBounds(15, 5, 300, 30);
    add(sel);
    b1 = new JButton("<< BACK");
    b1.setBounds(140, 510, 100, 30);
    b1.setToolTipText("Back to main page");
    b1.addActionListener(this);
    add(b1);
    setLayout(null);
    while (x < 360) {
      x = x + d;
      setBounds(675, 50, x, 600);
      this.show();
    }
    // setVisible(true);
    String s = "192.168.0.", temp = null;
    Printer printer = new Printer();
    printer.start();
    Connector connector = new Connector(printer);
    connector.start();

    LinkedList targets = new LinkedList();
    for (int i = 1; i <= 255; i++) {
      temp = s + Integer.toString(i);
      Target t = new Target(temp);
      targets.add(t);
      connector.add(t);
    }
    Thread.sleep(2000);
    connector.shutdown();
    connector.join();

    for (Iterator i = targets.iterator(); i.hasNext(); ) {
      Target t = (Target) i.next();
      if (!t.shown) t.show();
    }

    setDefaultCloseOperation(DISPOSE_ON_CLOSE);
  }
Пример #7
0
  public static void main(String[] args) throws IOException {
    ServerSocket s = new ServerSocket(PORT);
    System.out.println("Started: " + s);
    frame.setPreferredSize(new Dimension(400, 400));
    frame.addWindowListener(
        new WindowAdapter() {
          public void windowClosing(WindowEvent e) {
            System.exit(0);
          }
        });
    JMenuBar one = new JMenuBar();
    JMenu second = new JMenu("OPTIONS");
    //	JMenuItem third = new JMenuItem("NEW GAME");
    JMenuItem fourth = new JMenuItem("EXIT");
    fourth.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent evt) {
            try {
              exit(evt);
            } catch (IOException e) {
            }
          }
        });
    // second.add(third);
    second.add(fourth);
    one.add(second);
    frame.setJMenuBar(one);
    frame.setLayout(new java.awt.GridLayout(3, 3));
    button = new JButton[10];
    for (int i = 1; i < 10; i++) {
      button[i] = new JButton();
      button[i].setBackground(Color.lightGray);
      button[i].setActionCommand(Integer.toString(i));
      button[i].addActionListener(
          new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
              print(evt.getActionCommand());
              try {
                func(socket, evt.getActionCommand());
                String check = win();
                finalresult(check);
                if (check != "") {
                  func(socket, check);
                } else {
                  func(socket, evt.getActionCommand());
                }
                ;
              } catch (IOException e) {
              }
            }
          });
      frame.add(button[i]);
    }

    try {
      socket = s.accept();
      frame.pack();
      frame.setVisible(true);
      try {
        System.out.println("Connection accepted: " + socket);
        BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
        /*  while(true)
        {
        String str=in.readLine();
        print2(str);
        }*/
        while (true) {
          String str = in.readLine();
          if (str.equals("exit")) {
            System.exit(0);
          }
          if (str.equals("tie")) {
            JOptionPane.showMessageDialog(null, "It is a tie between the two");
            System.exit(0);
          } else {

            if (str.equals("winserver")) {
              System.out.println("server has won");
              JOptionPane.showMessageDialog(null, "the server has won the game");
              System.exit(0);
            } else {
              if (str.equals("winclient")) {
                JOptionPane.showMessageDialog(null, "the client has won the game");
                System.exit(0);
              } else {
                System.out.println(str);
                print2(str);
              }
            }
          }
        }
      } catch (Exception e) {
      } // finally {socket.close();
      // }
    } catch (Exception e) {
    } // finally {s.close();
    // }
  }
Пример #8
0
 private void jbInit() throws Exception {
   ////////////////////////////////////////////////////////
   // Init LAF
   ////////////////////////////////////////////////////////
   ButtonGroup grpLAF = new ButtonGroup();
   ActionListener lsnLAF =
       new ActionListener() {
         public void actionPerformed(ActionEvent evt) {
           int iIndex = mvtLAFItem.indexOf(evt.getSource());
           if (iIndex >= 0) changeLAF(iIndex);
         }
       };
   ////////////////////////////////////////////////////////
   UIManager.LookAndFeelInfo laf =
       new UIManager.LookAndFeelInfo(
           "Kunststoff", "com.incors.plaf.kunststoff.KunststoffLookAndFeel");
   marrLaf = UIManager.getInstalledLookAndFeels();
   int iIndex = 0;
   while (iIndex < marrLaf.length && !marrLaf[iIndex].getName().equals(laf.getName())) iIndex++;
   if (iIndex >= marrLaf.length) {
     UIManager.installLookAndFeel(laf);
     marrLaf = UIManager.getInstalledLookAndFeels();
   }
   for (iIndex = 0; iIndex < marrLaf.length; iIndex++) {
     JMenuItem mnu = new JRadioButtonMenuItem(marrLaf[iIndex].getName());
     mnu.addActionListener(lsnLAF);
     mvtLAFItem.addElement(mnu);
     mnuUI.add(mnu);
     grpLAF.add(mnu);
   }
   mnuUI.addSeparator();
   ////////////////////////////////////////////////////////
   // Init language
   ////////////////////////////////////////////////////////
   ButtonGroup grpLanguage = new ButtonGroup();
   ActionListener lsnLanguage =
       new ActionListener() {
         public void actionPerformed(ActionEvent e) {
           int iIndex = mvtLanguageItem.indexOf(e.getSource());
           if (iIndex >= 0) changeDictionary((String) mvtLanguage.elementAt(iIndex));
         }
       };
   ////////////////////////////////////////////////////////
   String[] str = MonitorDictionary.getSupportedLanguage();
   for (iIndex = 0; iIndex < str.length; iIndex++) {
     JMenuItem mnu =
         new JRadioButtonMenuItem(MonitorDictionary.getDictionary(str[iIndex]).getLanguage());
     mnu.addActionListener(lsnLanguage);
     mvtLanguage.addElement(str[iIndex]);
     mvtLanguageItem.addElement(mnu);
     mnuUI.add(mnu);
     grpLanguage.add(mnu);
   }
   ////////////////////////////////////////////////////////
   // Add to main menu
   ////////////////////////////////////////////////////////
   mnuMain.removeAll();
   mnuMain.add(mnuSystem);
   mnuSystem.add(mnuSystem_Login);
   mnuSystem.add(mnuSystem_ChangePassword);
   mnuSystem.addSeparator();
   mnuSystem.add(mnuSystem_StopServer);
   mnuSystem.add(mnuSystem_EnableThreads);
   mnuMain.add(mnuUI);
   mnuMain.add(mnuHelp);
   mnuHelp.add(mnuHelp_About);
   ////////////////////////////////////////////////////////
   mnuMain.add(chkVietnamese);
   mnuMain.add(lblStatus);
   ////////////////////////////////////////////////////////
   pnlThread.setTabPlacement(JTabbedPane.LEFT);
   pnlThread.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
   ////////////////////////////////////////////////////////
   tblUser.addColumn("", 1, false);
   tblUser.addColumn("", 2, false, Global.FORMAT_DATE_TIME);
   tblUser.addColumn("", 3, false);
   ////////////////////////////////////////////////////////
   JPanel pnlMessage = new JPanel();
   pnlMessage.setLayout(new GridBagLayout());
   pnlMessage.add(
       new JScrollPane(txtBoard),
       new GridBagConstraints(
           0,
           0,
           2,
           1,
           1.0,
           1.0,
           GridBagConstraints.CENTER,
           GridBagConstraints.BOTH,
           new Insets(2, 2, 2, 2),
           0,
           0));
   pnlMessage.add(
       txtMessage,
       new GridBagConstraints(
           0,
           1,
           1,
           1,
           1.0,
           0.0,
           GridBagConstraints.CENTER,
           GridBagConstraints.BOTH,
           new Insets(2, 2, 2, 2),
           0,
           0));
   pnlMessage.add(
       btnSend,
       new GridBagConstraints(
           1,
           1,
           1,
           1,
           0.0,
           0.0,
           GridBagConstraints.CENTER,
           GridBagConstraints.NONE,
           new Insets(2, 2, 2, 2),
           0,
           0));
   txtBoard.setEditable(false);
   txtBoard.setAutoscrolls(true);
   txtBoard.setContentType("text/html");
   clearAll(txtBoard);
   ////////////////////////////////////////////////////////
   JPanel pnlUserButton = new JPanel(new GridLayout(1, 2, 4, 4));
   pnlUserButton.add(btnKick);
   pnlUserButton.add(btnRefresh);
   ////////////////////////////////////////////////////////
   JPanel pnlManager = new JPanel(new GridBagLayout());
   pnlManager.add(
       new JScrollPane(tblUser),
       new GridBagConstraints(
           0,
           0,
           1,
           1,
           1.0,
           1.0,
           GridBagConstraints.CENTER,
           GridBagConstraints.BOTH,
           new Insets(2, 2, 2, 2),
           0,
           0));
   pnlManager.add(
       pnlUserButton,
       new GridBagConstraints(
           0,
           1,
           1,
           1,
           0.0,
           0.0,
           GridBagConstraints.CENTER,
           GridBagConstraints.NONE,
           new Insets(4, 2, 4, 2),
           0,
           0));
   ////////////////////////////////////////////////////////
   pnlUser.setDividerLocation(320);
   pnlUser.setLeftComponent(pnlManager);
   pnlUser.setRightComponent(pnlMessage);
   pnlUser.setOneTouchExpandable(true);
   ////////////////////////////////////////////////////////
   setOrientation(JSplitPane.VERTICAL_SPLIT);
   setOneTouchExpandable(true);
   pnlThread.setVisible(false);
   pnlUser.setVisible(false);
   setTopComponent(pnlThread);
   setBottomComponent(pnlUser);
   ////////////////////////////////////////////////////////
   pmn.add(mnuSelectAll);
   pmn.addSeparator();
   pmn.add(mnuClearSelected);
   pmn.add(mnuClearAll);
   ////////////////////////////////////////////////////////
   setBorder(BorderFactory.createEmptyBorder());
   pnlUser.setBorder(BorderFactory.createEmptyBorder());
   pnlManager.setBorder(
       BorderFactory.createBevelBorder(
           javax.swing.border.BevelBorder.RAISED,
           Color.white,
           UIManager.getColor("Panel.background"),
           UIManager.getColor("Panel.background"),
           UIManager.getColor("Panel.background")));
   pnlMessage.setBorder(
       BorderFactory.createBevelBorder(
           javax.swing.border.BevelBorder.RAISED,
           Color.white,
           UIManager.getColor("Panel.background"),
           UIManager.getColor("Panel.background"),
           UIManager.getColor("Panel.background")));
   ////////////////////////////////////////////////////////
   Skin.applySkin(mnuMain);
   Skin.applySkin(tblUser);
   Skin.applySkin(pmn);
   Skin.applySkin(this);
   ////////////////////////////////////////////////////////
   // Default setting
   ////////////////////////////////////////////////////////
   Hashtable prt = null;
   try {
     prt = Global.loadHashtable(Global.FILE_CONFIG);
   } catch (Exception e) {
     prt = new Hashtable();
   }
   changeLAF(Integer.parseInt(StringUtil.nvl(prt.get("LAF"), "0")));
   changeDictionary(StringUtil.nvl(prt.get("Language"), "VN"));
   Skin.LANGUAGE_CHANGE_LISTENER = this;
   MonitorProcessor.setRootObject(this);
   updateKeyboardUI();
   ////////////////////////////////////////////////////////
   // Event handler
   ////////////////////////////////////////////////////////
   tblUser.addMouseListener(
       new MouseAdapter() {
         public void mouseClicked(MouseEvent e) {
           if (e.getClickCount() > 1) btnKick.doClick();
         }
       });
   ////////////////////////////////////////////////////////
   btnRefresh.addActionListener(
       new java.awt.event.ActionListener() {
         public void actionPerformed(ActionEvent evt) {
           try {
             DDTP request = new DDTP();
             request.setRequestID(String.valueOf(System.currentTimeMillis()));
             DDTP response = channel.sendRequest("ThreadProcessor", "queryUserList", request);
             if (response != null) {
               tblUser.setData((Vector) response.getReturn());
               if (mstrChannel != null) removeUser(mstrChannel);
             }
           } catch (Exception e) {
             e.printStackTrace();
             MessageBox.showMessageDialog(pnlThread, e, Global.APP_NAME, MessageBox.ERROR_MESSAGE);
           }
         }
       });
   ////////////////////////////////////////////////////////
   btnKick.addActionListener(
       new java.awt.event.ActionListener() {
         public void actionPerformed(ActionEvent evt) {
           int iSelected = tblUser.getSelectedRow();
           if (iSelected < 0) return;
           int iResult =
               MessageBox.showConfirmDialog(
                   pnlThread,
                   mdic.getString("ConfirmKick"),
                   Global.APP_NAME,
                   MessageBox.YES_NO_OPTION);
           if (iResult == MessageBox.NO_OPTION) return;
           try {
             String strChannel = (String) tblUser.getRow(iSelected).elementAt(0);
             DDTP request = new DDTP();
             request.setRequestID(String.valueOf(System.currentTimeMillis()));
             request.setString("strChannel", strChannel);
             DDTP response = channel.sendRequest("ThreadProcessor", "kickUser", request);
           } catch (Exception e) {
             e.printStackTrace();
             MessageBox.showMessageDialog(pnlThread, e, Global.APP_NAME, MessageBox.ERROR_MESSAGE);
           }
         }
       });
   ////////////////////////////////////////////////////////
   txtMessage.addActionListener(
       new java.awt.event.ActionListener() {
         public void actionPerformed(ActionEvent evt) {
           btnSend.doClick();
         }
       });
   ////////////////////////////////////////////////////////
   btnSend.addActionListener(
       new java.awt.event.ActionListener() {
         public void actionPerformed(ActionEvent evt) {
           if (txtMessage.getText().length() == 0) return;
           try {
             DDTP request = new DDTP();
             request.setString("strMessage", txtMessage.getText());
             channel.sendRequest("ThreadProcessor", "sendMessage", request);
             txtMessage.setText("");
           } catch (Exception e) {
             e.printStackTrace();
             MessageBox.showMessageDialog(pnlThread, e, Global.APP_NAME, MessageBox.ERROR_MESSAGE);
           }
         }
       });
   ////////////////////////////////////////////////////////
   mnuClearAll.addActionListener(
       new java.awt.event.ActionListener() {
         public void actionPerformed(ActionEvent e) {
           clearAll(txtBoard);
         }
       });
   ////////////////////////////////////////////////////////
   mnuClearSelected.addActionListener(
       new java.awt.event.ActionListener() {
         public void actionPerformed(ActionEvent e) {
           txtBoard.setEditable(true);
           txtBoard.replaceSelection("");
           txtBoard.setEditable(false);
         }
       });
   ////////////////////////////////////////////////////////
   mnuSelectAll.addActionListener(
       new java.awt.event.ActionListener() {
         public void actionPerformed(ActionEvent e) {
           txtBoard.requestFocus();
           txtBoard.selectAll();
         }
       });
   ////////////////////////////////////////////////////////
   txtBoard.addMouseListener(
       new MouseAdapter() {
         public void mouseClicked(MouseEvent e) {
           if (e.getButton() == e.BUTTON3) pmn.show(txtBoard, e.getX(), e.getY());
         }
       });
   ////////////////////////////////////////////////////////
   mnuSystem_Login.addActionListener(
       new ActionListener() {
         public void actionPerformed(ActionEvent e) {
           login();
         }
       });
   ////////////////////////////////////////////////////////
   mnuSystem_ChangePassword.addActionListener(
       new ActionListener() {
         public void actionPerformed(ActionEvent e) {
           changePassword();
         }
       });
   ////////////////////////////////////////////////////////
   mnuSystem_StopServer.addActionListener(
       new ActionListener() {
         public void actionPerformed(ActionEvent e) {
           stopServer();
         }
       });
   ////////////////////////////////////////////////////////
   mnuSystem_EnableThreads.addActionListener(
       new ActionListener() {
         public void actionPerformed(ActionEvent e) {
           manageThreads();
         }
       });
   ////////////////////////////////////////////////////////
   mnuHelp_About.addActionListener(
       new ActionListener() {
         public void actionPerformed(ActionEvent e) {
           WindowManager.centeredWindow(new DialogAbout(PanelThreadManager.this));
         }
       });
   ////////////////////////////////////////////////////////
   chkVietnamese.addActionListener(
       new java.awt.event.ActionListener() {
         public void actionPerformed(ActionEvent e) {
           switchKeyboard();
         }
       });
 }
Пример #9
0
  public void initUI() {
    try {
      UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
      JPopupMenu.setDefaultLightWeightPopupEnabled(false);
      frame = new JFrame("Vestige-x Developers Client");
      frame.setIconImage(
          Toolkit.getDefaultToolkit().getImage(signlink.findcachedir() + "Cursor.png"));
      frame.setLayout(new BorderLayout());
      frame.setResizable(false);
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      JPanel gamePanel = new JPanel();
      gamePanel.setLayout(new BorderLayout());
      gamePanel.add(this);
      Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
      int w = 765;
      int h = 503;
      int x = (dim.width - w) / 2;
      int y = (dim.height - h) / 2;
      frame.setLocation(x, y);
      gamePanel.setPreferredSize(new Dimension(765, 503));
      JMenu fileMenu = new JMenu("  File  ");
      JMenu toolMenu = new JMenu("  Tools  ");
      JMenu infoMenu = new JMenu("  Info  ");
      JMenu toggleMenu = new JMenu("  Toggles  ");
      JMenu profileMenu = new JMenu("  Links  ");
      JButton shotMenu = new JButton("Take Screenshot");
      shotMenu.setActionCommand("Screenshot");
      shotMenu.addActionListener(this);
      String[] mainButtons = new String[] {"View Images", "Exit"};
      String[] toolButtons = new String[] {"World Map"};
      String[] infoButtons = new String[] {"Client Information", "Support"};
      String[] toggleButtons = new String[] {"Toggle 10x Damage", "Untoggle 10x Damage"};
      String[] profileButtons =
          new String[] {"Donate", "Vote", "-", "Highscores", "Guides", "YouTube", "Forums"};

      for (String name : mainButtons) {
        JMenuItem menuItem = new JMenuItem(name);
        if (name.equalsIgnoreCase("-")) {
          fileMenu.addSeparator();
        } else {
          menuItem.addActionListener(this);
          fileMenu.add(menuItem);
        }
      }
      for (String name : toolButtons) {
        JMenuItem menuItem = new JMenuItem(name);
        if (name.equalsIgnoreCase("-")) toolMenu.addSeparator();
        else {
          menuItem.addActionListener(this);
          toolMenu.add(menuItem);
        }
      }

      for (String name : infoButtons) {
        JMenuItem menuItem = new JMenuItem(name);
        if (name.equalsIgnoreCase("-")) infoMenu.addSeparator();
        else {
          menuItem.addActionListener(this);
          infoMenu.add(menuItem);
        }
      }
      for (String name : toggleButtons) {
        JMenuItem menuItem = new JMenuItem(name);
        if (name.equalsIgnoreCase("-")) toggleMenu.addSeparator();
        else {
          menuItem.addActionListener(this);
          toggleMenu.add(menuItem);
        }
      }
      for (String name : profileButtons) {
        JMenuItem menuItem = new JMenuItem(name);
        if (name.equalsIgnoreCase("-")) toggleMenu.addSeparator();
        else {
          menuItem.addActionListener(this);
          profileMenu.add(menuItem);
        }
      }
      JMenuBar menuBar = new JMenuBar();
      JMenuBar jmenubar = new JMenuBar();

      frame.add(jmenubar);
      menuBar.add(fileMenu);
      menuBar.add(toolMenu);
      menuBar.add(infoMenu);
      // menuBar.add(toggleMenu);
      menuBar.add(profileMenu);
      menuBar.add(shotMenu);
      frame.getContentPane().add(menuBar, BorderLayout.NORTH);
      frame.getContentPane().add(gamePanel, BorderLayout.CENTER);
      frame.pack();

      frame.setVisible(true); // can see the client
      frame.setResizable(false); // resizeable frame
      init();
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
Пример #10
0
  /**
   * Set up the menu bar.
   *
   * @return The JMenuBar we set up.
   */
  private JMenuBar setupMenuBar() {
    JMenuBar menuBar = new JMenuBar();

    /* File */
    JMenu fileMenu = new JMenu("File");
    menuBar.add(fileMenu);

    /* File -> Open CSV */
    JMenuItem miFileOpenCSV =
        new JMenuItem(
            new AbstractAction("Open CSV") {
              @Override
              public void actionPerformed(ActionEvent e) {
                FileDialog fd =
                    new FileDialog(mainFrame, "Open Darwin CSV file ...", FileDialog.LOAD);
                fd.setVisible(true);
                File file;
                if (fd.getDirectory() != null) {
                  file = new File(fd.getDirectory(), fd.getFile());
                } else if (fd.getFile() != null) {
                  file = new File(fd.getFile());
                } else {
                  return;
                }

                // Clear out old file.
                loadFile(null);

                // SwingWorker MAGIC!
                new MainFrameWorker("loading file '" + file + "'", file) {
                  @Override
                  protected Object doInBackground() throws Exception {
                    System.err.println("Loading file: " + input);
                    loadFile((File) input, DarwinCSV.FILE_CSV_DELIMITED);

                    return null;
                  }
                }.execute();
              }
            });
    fileMenu.add(miFileOpenCSV);

    /* File -> Open CSV without UI */
    JMenuItem miFileOpenCSVnoUI =
        new JMenuItem(
            new AbstractAction("Open CSV without UI") {
              @Override
              public void actionPerformed(ActionEvent e) {
                FileDialog fd =
                    new FileDialog(mainFrame, "Open Darwin CSV file ...", FileDialog.LOAD);
                fd.setVisible(true);

                File file;
                if (fd.getDirectory() != null) {
                  file = new File(fd.getDirectory(), fd.getFile());
                } else if (fd.getFile() != null) {
                  file = new File(fd.getFile());
                } else {
                  return;
                }

                // Clear out old file
                loadFile(null);

                loadFile(file, DarwinCSV.FILE_CSV_DELIMITED);
              }
            });
    fileMenu.add(miFileOpenCSVnoUI);

    /* File -> Open tab-delimited */
    JMenuItem miFileOpenTab =
        new JMenuItem(
            new AbstractAction("Open tab-delimited") {
              @Override
              public void actionPerformed(ActionEvent e) {
                FileDialog fd =
                    new FileDialog(
                        mainFrame, "Open Darwin tab-delimited file ...", FileDialog.LOAD);
                fd.setVisible(true);

                File file;
                if (fd.getDirectory() != null) {
                  file = new File(fd.getDirectory(), fd.getFile());
                } else if (fd.getFile() != null) {
                  file = new File(fd.getFile());
                } else {
                  return;
                }

                // Clear out old file
                loadFile(null);

                // SwingWorker MAGIC!
                new MainFrameWorker("loading file '" + file + "'", file) {
                  @Override
                  protected Object doInBackground() throws Exception {
                    loadFile((File) input, DarwinCSV.FILE_TAB_DELIMITED);

                    return null;
                  }
                }.execute();
              }
            });
    fileMenu.add(miFileOpenTab);

    /* File -> Save CSV */
    JMenuItem miFileSave =
        new JMenuItem(
            new AbstractAction("Save as CSV") {
              @Override
              public void actionPerformed(ActionEvent e) {
                FileDialog fd =
                    new FileDialog(mainFrame, "Save Darwin CSV file ...", FileDialog.SAVE);
                fd.setVisible(true);

                File file;
                if (fd.getDirectory() != null) {
                  file = new File(fd.getDirectory(), fd.getFile());
                } else if (fd.getFile() != null) {
                  file = new File(fd.getFile());
                } else {
                  return;
                }

                // SwingWorker MAGIC!
                new MainFrameWorker("saving CSV file '" + file + "'", file) {
                  @Override
                  protected Object doInBackground() throws Exception {
                    currentCSV.saveToFile((File) input, DarwinCSV.FILE_CSV_DELIMITED);

                    return null;
                  }
                }.execute();
              }
            });
    fileMenu.add(miFileSave);

    /* File -> Exit */
    JMenuItem miFileExit =
        new JMenuItem(
            new AbstractAction("Exit") {
              @Override
              public void actionPerformed(ActionEvent e) {
                mainFrame.setVisible(false);
                mainFrame.dispose();
              }
            });
    fileMenu.add(miFileExit);

    /* Match */
    JMenu matchMenu = new JMenu("Match");
    menuBar.add(matchMenu);

    /* Match -> Against CSV */
    JMenuItem miMatchCSV =
        new JMenuItem(
            new AbstractAction("Match against CSV") {
              @Override
              public void actionPerformed(ActionEvent e) {
                FileDialog fd =
                    new FileDialog(
                        mainFrame, "Open Darwin CSV file for matching ...", FileDialog.LOAD);
                fd.setVisible(true);

                if (fd.getFile() == null) return;

                File file = new File(fd.getFile());
                if (fd.getDirectory() != null) {
                  file = new File(fd.getDirectory(), fd.getFile());
                }

                // Clear out old match against.
                matchAgainst(null);

                // SwingWorker MAGIC!
                new MainFrameWorker("matching against file '" + file + "'", file) {
                  @Override
                  protected Object doInBackground() throws Exception {
                    matchAgainst(new DarwinCSV((File) input, DarwinCSV.FILE_CSV_DELIMITED));

                    return null;
                  }
                }.execute();
              }
            });
    matchMenu.add(miMatchCSV);

    /* Match -> Against ITIS */
    JMenuItem miMatchITIS =
        new JMenuItem(
            new AbstractAction("Match against ITIS") {
              @Override
              public void actionPerformed(ActionEvent e) {
                DarwinCSV csv = DownloadITIS.getIt(mainFrame);
                matchAgainst(csv);
                table.repaint();
              }
            });
    matchMenu.add(miMatchITIS);

    /* TaxonID */
    JMenu taxonIDMenu = new JMenu("TaxonIDs");
    menuBar.add(taxonIDMenu);

    /* TaxonID -> Treat TaxonIDs as ... */
    JMenu treatTaxonIDsAs = new JMenu("Treat TaxonIDs as ...");
    taxonIDMenu.add(treatTaxonIDsAs);

    /* TaxonID -> Treat -> ITIS TSNs */
    JCheckBoxMenuItem miITIS_TSNs =
        new JCheckBoxMenuItem(
            new AbstractAction("ITIS TSNs") {
              @Override
              public void actionPerformed(ActionEvent e) {
                // Don't let the user unselect this.
                ((JCheckBoxMenuItem) e.getSource()).setSelected(true);
              }
            });
    miITIS_TSNs.setSelected(true);
    treatTaxonIDsAs.add(miITIS_TSNs);

    /* TaxonID -> Create family column */
    JMenuItem miTaxonID_createFamily =
        new JMenuItem(
            new AbstractAction("Create family column") {
              @Override
              public void actionPerformed(ActionEvent e) {
                /*
                if(currentCSV == null)
                	return;

                if(currentMatch == null)
                	return;

                int col = getJTable().getSelectedColumn();
                if(col == -1)
                	return;

                RowIndex rowIndex = currentCSV.getRowIndex();

                String colName = rowIndex.getColumnName(col);
                if(rowIndex.hasColumn(colName + "_family")) {
                	// TODO MessageBox
                	return;
                }

                if(Name.class.isAssignableFrom(currentCSV.getRowIndex().getColumnClass(col))) {
                	// A name class! Make a new column!
                	currentCSV.getRowIndex().setColumnClass(colName + "_family", String.class);
                	currentCSV.getRowIndex().createNewColumn(colName + "_family", col + 1, colName, new MapOperation() {
                		@Override
                		public Object mapTo(Object value) {
                			return "family";
                		}
                	});

                	// Repaint the table.
                	getJTable().repaint();
                }
                */
              }
            });
    taxonIDMenu.add(miTaxonID_createFamily);

    /* Help */
    JMenu helpMenu = new JMenu("Help");
    menuBar.add(helpMenu);

    /* Help -> Memory information */
    JMenuItem miHelpMemory =
        new JMenuItem(
            new AbstractAction("Memory information") {
              @Override
              public void actionPerformed(ActionEvent e) {
                System.gc();

                MessageBox.messageBox(
                    mainFrame,
                    "Memory information",
                    "Maximum memory: "
                        + Runtime.getRuntime().maxMemory() / (1024 * 1024)
                        + " MB\n"
                        + "Total memory: "
                        + Runtime.getRuntime().totalMemory() / (1024 * 1024)
                        + " MB\n"
                        + "Used memory: "
                        + (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory())
                            / (1024 * 1024)
                        + " MB\n"
                        + "Free memory: "
                        + Runtime.getRuntime().freeMemory() / (1024 * 1024)
                        + " MB\n"
                        + "Available memory: "
                        + (Runtime.getRuntime().maxMemory()
                                - Runtime.getRuntime().totalMemory()
                                + Runtime.getRuntime().freeMemory())
                            / (1024 * 1024)
                        + " MB");
              }
            });
    helpMenu.add(miHelpMemory);

    return menuBar;
  }
Пример #11
0
  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);
  }