private void addControls() {
    this.setLayout(new BoxLayout(getContentPane(), BoxLayout.PAGE_AXIS));
    panelMenu = new PanelMenu();
    panelMenu.setBorder(new EmptyBorder(5, 5, 5, 5));
    panelMenu.setPreferredSize(new Dimension(410, 50));
    add(panelMenu);

    JTabbedPane tabbedPane = new JTabbedPane();
    tabbedPane.setBorder(new EmptyBorder(5, 5, 5, 5));
    ImageIcon icon = createImageIcon("exam.jpg");

    panelExam = new PanelExam();
    tabbedPane.addTab(getText("Exams"), icon, panelExam, getText("Manage.exams"));
    tabbedPane.setMnemonicAt(0, KeyEvent.VK_1);

    icon = createImageIcon("question.png");
    panelQuestion = new PanelQuestion();
    tabbedPane.addTab(getText("Questions"), icon, panelQuestion, getText("Manage.questions"));
    tabbedPane.setMnemonicAt(1, KeyEvent.VK_2);

    icon = createImageIcon("exclamation.png");
    panelAnswer = new PanelAnswer();
    tabbedPane.addTab(getText("Answers"), icon, panelAnswer, getText("Manage.answers"));
    panelAnswer.setPreferredSize(new Dimension(410, 50));
    tabbedPane.setMnemonicAt(2, KeyEvent.VK_3);

    tabbedPane.addChangeListener(
        new ChangeListener() {

          @Override
          public void stateChanged(ChangeEvent e) {
            JTabbedPane source = (JTabbedPane) e.getSource();
            switch (source.getSelectedIndex()) {
              case 0:
                panelExam.refresh();
                break;
              case 1:
                panelQuestion.refresh();
                break;
              case 2:
                panelAnswer.refresh();
                break;
            }
          }
        });
    add(tabbedPane);
    tabbedPane.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
    panelQuestion.refresh();
  }
  public MainTabPane(JFrame parent) {
    super(new GridLayout(1, 1));
    mainTabPane = new JTabbedPane();

    mainTabPane.addTab("Officer Records", new OfficerPanel(parent));
    mainTabPane.setMnemonicAt(0, KeyEvent.VK_1);

    mainTabPane.addTab("Vehicle Records", new VehiclePanel(parent));
    mainTabPane.setMnemonicAt(1, KeyEvent.VK_2);

    mainTabPane.addTab("Fleet Records", new FleetStarterPanel(parent));
    mainTabPane.setMnemonicAt(2, KeyEvent.VK_3);

    add(mainTabPane);
  }
Exemplo n.º 3
0
  /**
   * This method populates the ProjectSelector with all the subpanels and buttons
   *
   * @param main The object to notify when the ok button is pressed.
   */
  public void populate(Object main) {
    this.main = main;

    // gather all projects
    String[] projects = getAllProjectNames();
    if (projects == null) {
      Main.fatalError(
          "Cannot find the project folder. Please ensure that the framework is installed properly.");
    }
    Arrays.sort(projects); // sort the projects in ascending order

    this.addComponentListener(
        new ComponentListener() {
          int oldX = appConfig.projectSelectorWindowPosX,
              oldY = appConfig.projectSelectorWindowPosY;

          public void componentResized(ComponentEvent e) {
            if (ProjectSelector.this.getExtendedState() == JFrame.MAXIMIZED_BOTH) {
              appConfig.projectSelectorIsMaximized = true;
              appConfig.projectSelectorWindowPosX = oldX;
              appConfig.projectSelectorWindowPosY = oldY;
            } else {
              appConfig.projectSelectorIsMaximized = false;
              appConfig.projectSelectorWindowWidth = ProjectSelector.this.getWidth();
              appConfig.projectSelectorWindowHeight = ProjectSelector.this.getHeight();
            }
            customParameters.setSize(
                100,
                customParameters
                    .getHeight()); // needed to ensure that the text field shrinks as well
          }

          public void componentMoved(ComponentEvent e) {
            oldX = appConfig.projectSelectorWindowPosX;
            oldY = appConfig.projectSelectorWindowPosY;
            appConfig.projectSelectorWindowPosX = ProjectSelector.this.getX();
            appConfig.projectSelectorWindowPosY = ProjectSelector.this.getY();
          }

          public void componentShown(ComponentEvent e) {}

          public void componentHidden(ComponentEvent e) {}
        });

    // safe the overal config file when the project selector closes
    this.addWindowListener(
        new WindowListener() {
          public void windowOpened(WindowEvent e) {}

          public void windowClosing(WindowEvent e) {
            appConfig.projectSelectorSelectedTab = 1 + right.getSelectedIndex();
            appConfig.writeConfig();
          }

          public void windowClosed(WindowEvent e) {}

          public void windowIconified(WindowEvent e) {}

          public void windowDeiconified(WindowEvent e) {}

          public void windowActivated(WindowEvent e) {}

          public void windowDeactivated(WindowEvent e) {}
        });

    this.setLayout(new BorderLayout());
    this.setResizable(true);
    if (appConfig.projectSelectorIsMaximized) {
      setExtendedState(JFrame.MAXIMIZED_BOTH);
    }
    this.setSize(
        new Dimension(appConfig.projectSelectorWindowWidth, appConfig.projectSelectorWindowHeight));
    this.setLocation(appConfig.projectSelectorWindowPosX, appConfig.projectSelectorWindowPosY);

    JPanel left = new JPanel();
    left.setLayout(new BorderLayout());
    // List of all projects
    selection.setListData(projects);
    selection.setSelectedValue(appConfig.lastChosenProject, true);
    if (!selection.isSelectionEmpty()) {
      selectedProjectName = (String) selection.getSelectedValue();
    } else {
      selectedProjectName = "";
    }
    selection.addListSelectionListener(this);
    selection.setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 0));
    selection.setBackground(listPanel.getBackground());
    listScroller = new JScrollPane(selection);
    listPanel.setLayout(new BorderLayout());
    listScroller.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
    listPanel.add(listScroller, BorderLayout.CENTER);
    listPanel.setBorder(BorderFactory.createTitledBorder("Available Projects"));
    left.add(listPanel, BorderLayout.CENTER);

    // OK / Cancel buttons
    buttonPanel.add(ok);
    buttonPanel.add(cancel);
    ok.addActionListener(this);
    cancel.addActionListener(this);
    buttonPanel.setPreferredSize(new Dimension(projectListWidth, 40));
    left.add(buttonPanel, BorderLayout.SOUTH);

    this.add(left, BorderLayout.WEST);

    // right.setBorder(BorderFactory.createTitledBorder("Project Description & Configuration"));

    // The tab containing the description of the selected project
    JPanel description = new JPanel();
    description.setLayout(new BorderLayout());
    scrollableDescriptionPane = new JScrollPane(descriptionText);
    description.add(scrollableDescriptionPane);
    descriptionText.setEditable(false);
    descriptionText.setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3));

    int i = selection.getSelectedIndex();
    if (i == -1) {
      // there was no defaultProject
      descriptionText.setText("Please select a project.");
    } else {
      generateGUIDescription(selectedProjectName);
    }
    right.addTab("Description", description);

    // The tab containing the config-file entries
    configuration.setLayout(new BoxLayout(configuration, BoxLayout.Y_AXIS));

    scrollableConfigurationPane = new JScrollPane(frameworkConfigurationPanel);
    // increment the scroll speed (for some reason the speed for the scrollableConfigurationPane is
    // very low)
    scrollableConfigurationPane.getVerticalScrollBar().setUnitIncrement(15);

    frameworkConfigurationPanel.setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3));

    configuration.add(scrollableConfigurationPane);
    JPanel bp = new JPanel();
    bp.add(saveConfig);
    saveConfig.addActionListener(this);
    saveConfig.setMnemonic(java.awt.event.KeyEvent.VK_S);
    configuration.add(bp);

    expand = createFrameworkIconButton("expand", "expand.gif", "Show advanced settings");
    collapse = createFrameworkIconButton("collapse", "collapse.gif", "Hide advanced settings");

    customConfigurationPanel.setLayout(new BorderLayout());

    JPanel mainCustomConfigurationPanel = new JPanel();
    mainCustomConfigurationPanel.setLayout(
        new BoxLayout(mainCustomConfigurationPanel, BoxLayout.Y_AXIS));
    mainCustomConfigurationPanel.add(customConfigurationPanel);
    // and the save button
    JPanel bp2 = new JPanel();
    bp2.add(saveConfig2);
    saveConfig2.addActionListener(this);
    saveConfig2.setMnemonic(java.awt.event.KeyEvent.VK_S);
    mainCustomConfigurationPanel.add(bp2);

    right.addTab("Framework Config", configuration);
    right.addTab("Project Config", mainCustomConfigurationPanel);
    right.setMnemonicAt(0, java.awt.event.KeyEvent.VK_D);
    right.setMnemonicAt(1, java.awt.event.KeyEvent.VK_F);
    right.setMnemonicAt(2, java.awt.event.KeyEvent.VK_P);
    right.setSelectedIndex(appConfig.projectSelectorSelectedTab - 1);

    if (i == -1) {
      JTextField msg = new JTextField("Please select a project.");
      msg.setEditable(false);
      frameworkConfigurationPanel.add(msg);
    } else {
      generateGUIGonfiguration(selectedProjectName);
    }

    this.add(right, BorderLayout.CENTER);

    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    this.getRootPane().setDefaultButton(ok);

    this.setVisible(true);

    // this.setUndecorated(true);
    // GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().setFullScreenWindow(this);
  }
  private void makeFrame(final Editor editor) {
    dialog = new JFrame(title);
    dialog.setMinimumSize(new Dimension(750, 500));
    tabbedPane = new JTabbedPane();

    makeAndShowTab(false, true);

    tabbedPane.addTab("Libraries", null, librariesContributionTab.panel, "Libraries");
    tabbedPane.setMnemonicAt(0, KeyEvent.VK_1);

    tabbedPane.addTab("Modes", null, modesContributionTab.panel, "Modes");
    tabbedPane.setMnemonicAt(1, KeyEvent.VK_2);

    tabbedPane.addTab("Tools", null, toolsContributionTab.panel, "Tools");
    tabbedPane.setMnemonicAt(2, KeyEvent.VK_3);

    tabbedPane.addTab("Examples", null, examplesContributionTab.panel, "Examples");
    tabbedPane.setMnemonicAt(3, KeyEvent.VK_4);

    tabbedPane.addTab("Updates", null, updatesContributionTab.panel, "Updates");
    tabbedPane.setMnemonicAt(4, KeyEvent.VK_5);

    tabbedPane.setUI(new SpacedTabbedPaneUI());
    tabbedPane.setBackground(new Color(0x132638));
    tabbedPane.setOpaque(true);

    for (int i = 0; i < 5; i++) {
      tabbedPane.setToolTipTextAt(i, null);
    }

    makeAndSetTabComponents();

    tabbedPane.addChangeListener(
        new ChangeListener() {

          @Override
          public void stateChanged(ChangeEvent e) {
            for (int i = 0; i < 4; i++) {
              tabLabels[i].setBackground(new Color(0x2d4251));
              tabLabels[i].setForeground(Color.WHITE);
            }
            updateTabPanel.setBackground(new Color(0x2d4251));
            updateTabLabel.setForeground(Color.WHITE);
            int currentIndex = tabbedPane.getSelectedIndex();
            if (currentIndex != 4) {
              tabbedPane
                  .getTabComponentAt(tabbedPane.getSelectedIndex())
                  .setBackground(new Color(0xe0fffd));
              tabbedPane
                  .getTabComponentAt(tabbedPane.getSelectedIndex())
                  .setForeground(Color.BLACK);
            } else {
              updateTabPanel.setBackground(new Color(0xe0fffd));
              updateTabLabel.setForeground(Color.BLACK);
            }
            getActiveTab().contributionListPanel.scrollPane.requestFocusInWindow();
            //        // When the tab is changed update status to the current selected panel
            //        ContributionPanel currentPanel = getActiveTab().contributionListPanel
            //          .getSelectedPanel();
            //        if (currentPanel != null) {
            //          getActiveTab().contributionListPanel.setSelectedPanel(currentPanel);
            //        }
          }
        });

    //    tabbedPane.setSize(450, 400);
    setLayout();

    restartButton = new JButton(Language.text("contrib.restart"));
    restartButton.setVisible(false);
    restartButton.addActionListener(
        new ActionListener() {

          @Override
          public void actionPerformed(ActionEvent arg0) {

            Iterator<Editor> iter = editor.getBase().getEditors().iterator();
            while (iter.hasNext()) {
              Editor ed = iter.next();
              if (ed.getSketch().isModified()) {
                int option =
                    Messages.showYesNoQuestion(
                        editor,
                        title,
                        Language.text("contrib.unsaved_changes"),
                        Language.text("contrib.unsaved_changes.prompt"));

                if (option == JOptionPane.NO_OPTION) return;
                else break;
              }
            }

            // Thanks to http://stackoverflow.com/a/4160543
            StringBuilder cmd = new StringBuilder();
            cmd.append(
                System.getProperty("java.home")
                    + File.separator
                    + "bin"
                    + File.separator
                    + "java ");
            for (String jvmArg : ManagementFactory.getRuntimeMXBean().getInputArguments()) {
              cmd.append(jvmArg + " ");
            }
            cmd.append("-cp ")
                .append(ManagementFactory.getRuntimeMXBean().getClassPath())
                .append(" ");
            cmd.append(Base.class.getName());

            try {
              Runtime.getRuntime().exec(cmd.toString());
              System.exit(0);
            } catch (IOException e) {
              e.printStackTrace();
            }
          }
        });

    Toolkit.setIcon(dialog);
    registerDisposeListeners();

    dialog.pack();
    dialog.setLocationRelativeTo(null);
  }
  @Override
  protected void startup() {
    // set the window icon:
    {
      final Image img;
      if (true) img = getContext().getResourceMap().getImageIcon("Application.icon").getImage();
      else {
        final ResourceMap r = getContext().getResourceMap();
        if (true)
          try {
            img =
                ImageIO.read(
                    this.getClass()
                        .getResource(
                            "/" + r.getResourcesDir() + "/" + r.getString("Application.icon")));
          } catch (final IOException e) {
            throw new RuntimeException("Unhandled", e);
          }
        else
          img =
              Toolkit.getDefaultToolkit()
                  .createImage(
                      this.getClass()
                          .getResource(
                              "/" + r.getResourcesDir() + "/" + r.getString("Application.icon")));
      }
      getMainFrame().setIconImage(img);
      // SystemTray tray = SystemTray.getSystemTray();
    }

    // File Filter
    jcxzPat = gui.createFileFilter("fileFilterJcxz", "jcz", "jcx");
    pngPat = gui.createFileFilter("fileFilterPng", "png");
    svgPat = gui.createFileFilter("fileFilterSvg", "svgz", "svg");

    getMainFrame().setJMenuBar(createMenuBar());

    final JComponent c = new JPanel();
    c.setLayout(new BorderLayout());
    tactics.setPreferredSize(new Dimension(400, 600));
    c.add(tactics, BorderLayout.CENTER);
    c.add(url, BorderLayout.NORTH);
    {
      final JPanel b = new JPanel();
      b.setLayout(new BorderLayout());
      final JTabbedPane t = new JTabbedPane(SwingConstants.TOP, JTabbedPane.SCROLL_TAB_LAYOUT);
      t.add("Rock", broomSwing);
      t.setMnemonicAt(0, 'R');
      t.add("Ice", curlerSwing);
      t.setMnemonicAt(1, 'I');
      t.add("Collission", new JLabel("TODO: Collission settings"));
      t.setMnemonicAt(2, 'C');
      b.add(t, BorderLayout.NORTH);
      if (false) b.add(new JLabel("TODO: Bird's eye view"), BorderLayout.CENTER);
      else b.add(birdPiccolo, BorderLayout.CENTER);
      c.add(b, BorderLayout.EAST);
    }

    show(c);
    view12Foot();
  }
Exemplo n.º 6
0
  public static void createTabItem(ActionContext actionContext) {
    Thing self = (Thing) actionContext.get("self");
    JTabbedPane parent = (JTabbedPane) actionContext.get("parent");

    Thing thing = self.getThing("Component@0");
    if (thing != null) {
      try {
        Bindings bindings = actionContext.push();
        bindings.put("parent", null);

        for (Thing child : thing.getChilds()) {
          Component c = (Component) child.doAction("create", actionContext);
          if (c != null) {
            int index = parent.getTabCount();
            parent.setComponentAt(index, c);

            Color background = AwtCreator.createColor(thing, "background", actionContext);
            if (background != null) {
              parent.setBackgroundAt(index, background);
            }

            Icon disabledIcon = SwingCreator.createIcon(thing, "disabledIcon", actionContext);
            if (disabledIcon != null) {
              parent.setDisabledIconAt(index, disabledIcon);
            }

            Integer displayedMnemonicIndex =
                JavaCreator.createInteger(thing, "displayedMnemonicIndex");
            if (displayedMnemonicIndex != null) {
              parent.setDisplayedMnemonicIndexAt(index, displayedMnemonicIndex);
            }

            Boolean enabled = JavaCreator.createBoolean(thing, "enabled");
            if (enabled != null) {
              parent.setEnabledAt(index, enabled);
            }

            Color foreground = AwtCreator.createColor(thing, "foreground", actionContext);
            if (foreground != null) {
              parent.setForeground(foreground);
            }

            Icon icon = SwingCreator.createIcon(thing, "icon", actionContext);
            if (icon != null) {
              parent.setIconAt(index, icon);
            }

            Integer mnemonic = AwtCreator.createMnemonic(thing, "mnemonic");
            if (mnemonic != null) {
              parent.setMnemonicAt(index, mnemonic);
            }

            Boolean selected = JavaCreator.createBoolean(thing, "selected");
            if (selected != null && selected) {
              parent.setSelectedIndex(index);
            }

            String title = JavaCreator.createText(thing, "title", actionContext);
            if (title != null) {
              parent.setTitleAt(index, title);
            }

            String toolTipText = JavaCreator.createText(thing, "toolTipText", actionContext);
            if (toolTipText != null) {
              parent.setToolTipTextAt(index, toolTipText);
            }
            break;
          }
        }
      } finally {
        actionContext.pop();
      }
    }
  }
Exemplo n.º 7
0
  /**
   * Constructor to initialize the GUI. This should only be invoked from the Swing event thread.
   * Properties must be initialized first. In particular, {@link Survivor#currentColourScheme} must
   * be set.
   *
   * @param survivor The Survivor object associated with this object
   */
  public RootPanel(final Survivor survivor) {
    this.backgroundColourableComponents = new HashSet<Component>();
    this.complementaryAmenableForegroundColourableComponents = new HashSet<Component>();
    this.colourSchemeButtons = new HashSet<AbstractButton>();

    this.survivor = survivor;

    // Do nothing on close to allow close to be handles identically to File>Quit.
    this.setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);

    /*
     * This is added as an anonymous inner class to
     * prevent having to extend WindowAdapter or implement WindowListener.
     */
    this.addWindowListener(
        new WindowAdapter() {
          /* (non-Javadoc)
           * @see java.awt.event.WindowAdapter#windowClosing(java.awt.event.WindowEvent)
           */
          @Override
          public void windowClosing(WindowEvent e) {
            exit();
          }
        });

    this.setTitle(application.ProjectInfo.TITLE);
    this.setSize(size);
    this.setMinimumSize(size);
    this.setLayout(new BorderLayout());

    /*
     * Attempts to set the Look and Feel to Nimbus.
     * Note that a modicum of backwards compatibility is present if Nimbus cannot be found.
     * It is ideal that it is available, since it severely reduces colour schemes.
     */
    try {
      for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
        if ("Nimbus".equals(info.getName())) {
          this.nimbus = info.getClassName();
          UIManager.setLookAndFeel(this.nimbus);
          break;
        }
      }
    } catch (Exception e) {
    }

    tabbedPane = new JTabbedPane();

    ContestantManagementTab contestantManagementTab = new ContestantManagementTab(survivor);
    tabbedPane.addTab(
        ContestantManagementTab.TITLE,
        ContestantManagementTab.ICON,
        contestantManagementTab,
        ContestantManagementTab.TOOLTIP);
    tabbedPane.setMnemonicAt(tabbedPane.getTabCount() - 1, KeyEvent.VK_C);

    PlayerManagementTab playerManagementTab = new PlayerManagementTab(survivor);
    tabbedPane.addTab(
        PlayerManagementTab.TITLE,
        PlayerManagementTab.ICON,
        playerManagementTab,
        PlayerManagementTab.TOOLTIP);
    tabbedPane.setMnemonicAt(tabbedPane.getTabCount() - 1, KeyEvent.VK_P);

    tabbedPane.addTab(
        BonusQuestionTab.TITLE,
        BonusQuestionTab.ICON,
        new BonusQuestionTab(survivor),
        BonusQuestionTab.TOOLTIP);
    tabbedPane.setMnemonicAt(tabbedPane.getTabCount() - 1, KeyEvent.VK_B);

    tabbedPane.addTab(
        StandingsTab.TITLE, StandingsTab.ICON, new StandingsTab(), StandingsTab.TOOLTIP);
    tabbedPane.setMnemonicAt(tabbedPane.getTabCount() - 1, KeyEvent.VK_S);

    JButton startGame = new JButton(START_GAME);
    startGame.addActionListener(this);
    startGame.addActionListener(contestantManagementTab);
    startGame.addActionListener(playerManagementTab);
    startGame.setFont(Constants.BOLD_FONT);
    startGame.setMnemonic(KeyEvent.VK_G);
    colourSchemeButtons.add(startGame);
    tabbedPane.add(new JPanel(new GridLayout(1, 1)));
    this.startGameTabIndex = tabbedPane.getComponentCount() - 1;
    tabbedPane.setTabComponentAt(this.startGameTabIndex, startGame);
    tabbedPane.setEnabledAt(this.startGameTabIndex, false);
    backgroundColourableComponents.add(tabbedPane);

    for (Component c : tabbedPane.getComponents()) {
      backgroundColourableComponents.add(c);
    }

    this.add(tabbedPane);
    io.io.readProperties();

    JMenuBar menuBar = new JMenuBar();
    backgroundColourableComponents.add(menuBar);

    JMenu file = new JMenu("File");
    file.setMnemonic(KeyEvent.VK_F);
    this.backgroundColourableComponents.add(file);
    this.complementaryAmenableForegroundColourableComponents.add(file);
    menuBar.add(file);

    JMenuItem menuItem = new JMenuItem(CLEAR_DATA, RESET_ICON);
    menuItem.setMnemonic(KeyEvent.VK_C);
    menuItem.addActionListener(this);
    this.backgroundColourableComponents.add(menuItem);
    file.add(menuItem);

    file.addSeparator();

    JLabel label = new JLabel("Colour Scheme");
    file.add(label);

    ButtonGroup group = new ButtonGroup();

    JRadioButtonMenuItem rbMenuItemDefault = new JRadioButtonMenuItem(DEFAULT);
    rbMenuItemDefault.addActionListener(this);
    this.colourSchemeButtons.add(rbMenuItemDefault);
    this.backgroundColourableComponents.add(rbMenuItemDefault);
    group.add(rbMenuItemDefault);
    file.add(rbMenuItemDefault);

    JRadioButtonMenuItem rbMenuItemSunset = new JRadioButtonMenuItem(SUNSET);
    rbMenuItemSunset.addActionListener(this);
    this.colourSchemeButtons.add(rbMenuItemSunset);
    this.backgroundColourableComponents.add(rbMenuItemSunset);
    group.add(rbMenuItemSunset);
    file.add(rbMenuItemSunset);

    JRadioButtonMenuItem rbMenuItemDawn = new JRadioButtonMenuItem(DAWN);
    rbMenuItemDawn.addActionListener(this);
    this.colourSchemeButtons.add(rbMenuItemDawn);
    this.backgroundColourableComponents.add(rbMenuItemDawn);
    group.add(rbMenuItemDawn);
    file.add(rbMenuItemDawn);

    /*
     * Set both the colour scheme and the corresponding selection
     * of the radio button in the file menu.
     * This data is read from the configuration file, if available.
     */
    setCurrentColourSchemeSelected();
    setColourScheme(survivor.getCurrentColourScheme());

    menuItem = new JMenuItem(QUIT, QUIT_ICON);
    menuItem.setMnemonic(KeyEvent.VK_Q);
    menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F4, ActionEvent.ALT_MASK));
    menuItem.addActionListener(this);
    this.backgroundColourableComponents.add(menuItem);
    file.add(menuItem);
    file.addSeparator();

    JMenu help = new JMenu("Help");
    help.setMnemonic(KeyEvent.VK_H);
    this.backgroundColourableComponents.add(help);
    this.complementaryAmenableForegroundColourableComponents.add(help);
    menuBar.add(help);

    menuItem = new JMenuItem(ABOUT, ABOUT_ICON);
    menuItem.setMnemonic(KeyEvent.VK_A);
    menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F1, 0));
    menuItem.addActionListener(this);
    this.backgroundColourableComponents.add(menuItem);
    help.add(menuItem);
    help.addSeparator();

    this.add(menuBar, BorderLayout.PAGE_START);

    this.setVisible(true);
  }
Exemplo n.º 8
0
  private JFrame createFrame() {
    init();
    JScrollPane primary =
        Preview.innerTitled(
            new JScrollPane(
                primaryTable,
                JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
                JScrollPane.HORIZONTAL_SCROLLBAR_NEVER),
            "P\u0332rimary");
    JScrollPane secondary =
        Preview.innerTitled(
            new JScrollPane(
                secondaryTable,
                JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
                JScrollPane.HORIZONTAL_SCROLLBAR_NEVER),
            "S\u0332econdary");
    Actions mnemonicAction = new Actions(Actions.MNEMONIC);
    mnemonicAction.registerMnemonic(primaryTable, KeyEvent.VK_P, false);
    mnemonicAction.registerMnemonic(secondaryTable, KeyEvent.VK_S, false);
    mnemonicAction.registerMnemonic(otherTable, KeyEvent.VK_A, false);
    mnemonicAction.registerMnemonic(keyFilter, KeyEvent.VK_K, true);
    mnemonicAction.registerMnemonic(typeFilter, KeyEvent.VK_T, true);
    registerSortMnemonics(primaryTable);
    registerSortMnemonics(secondaryTable);
    registerSortMnemonics(otherTable);

    JPanel colors = new JPanel(new StackedTableLayout(3, 10, true));
    colors.add(primary);
    colors.add(secondary);
    Dimension size = new Dimension(Creator.TABLE_WIDTH, primaryTable.getRowHeight() * 20);
    otherTable.setPreferredScrollableViewportSize(size);

    JScrollPane other = new JScrollPane(otherTable);
    other.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
    JPanel otherPanel = new JPanel(null);

    JPanel filters = new JPanel(new FiltersLayout());
    filters.add(keyFilter);
    filters.add(keyFilterMethod);
    filters.add(typeFilter);
    TableColumnModel model = otherTable.getColumnModel();
    model.getColumn(UITableModel.KEY_COLUMN_INDEX).addPropertyChangeListener(this);
    model.addColumnModelListener(this);
    filtersViewport = new JViewport();
    filtersViewport.setView(filters);
    other.getViewport().addChangeListener(this);

    GroupLayout layout = new GroupLayout(otherPanel);
    otherPanel.setLayout(layout);
    layout.setHorizontalGroup(
        layout
            .createSequentialGroup()
            .addGap(2)
            .addGroup(
                layout.createParallelGroup().addComponent(filtersViewport).addComponent(other)));
    final int prf = GroupLayout.PREFERRED_SIZE;
    layout.setVerticalGroup(
        layout
            .createSequentialGroup()
            .addGap(2)
            .addComponent(other)
            .addComponent(filtersViewport, prf, prf, prf));

    JTabbedPane tabs = new JTabbedPane();
    tabs.addTab("UI Base", colors);
    tabs.setMnemonicAt(0, KeyEvent.VK_B);
    tabs.addTab("UI Controls", otherPanel);
    tabs.setMnemonicAt(1, KeyEvent.VK_C);
    tabs.addChangeListener(this);

    JButton imp = new JButton("Import");
    imp.setMnemonic(KeyEvent.VK_M);
    imp.addActionListener(this);
    JButton exp = new JButton("Export");
    exp.setMnemonic(KeyEvent.VK_X);
    exp.addActionListener(this);

    Box south = Box.createHorizontalBox();
    south.setBorder(BorderFactory.createEmptyBorder(0, 3, 3, 3));
    south.add(imp);
    south.add(exp);
    south.add(Box.createHorizontalGlue());
    south.add(preview);
    south.add(Box.createHorizontalStrut(3));
    south.add(update);

    frame = new JFrame(getClass().getSimpleName());
    frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    frame.addWindowListener(this);
    frame.add(tabs, BorderLayout.CENTER);
    frame.add(south, BorderLayout.SOUTH);
    return frame;
  }
Exemplo n.º 9
0
  /** The globalvend screen which shows statistics of the overall system. */
  private void globalVendScreen() {
    // TODO Auto-generated method stub
    mainLayout.removeAll();

    mainLayout.setLayout(new BorderLayout(0, 20));
    JPanel mainLeftSide = new JPanel(new BorderLayout(0, 20));

    JLabel heading = new JLabel("<html><center>List of Vending <br>Machines</center></html>");
    heading.setFont(new Font("Verdana", Font.BOLD, 20));

    String data[] = new String[numberOfMachines];

    for (int i = 0; i < numberOfMachines; ++i) {
      data[i] = "Vending Machine " + (i + 1);
    }

    final JList<String> listVendingMachine = new JList<String>(data);

    listVendingMachine.setFont(new Font("Arial", Font.PLAIN, 20));
    listVendingMachine.setFixedCellHeight(50);
    listVendingMachine.setSelectedIndex(0);
    numOfSelected = listVendingMachine.getSelectedIndices();

    JScrollPane listOfMachineScroll = new JScrollPane(listVendingMachine);

    JPanel southPanel = new JPanel(new GridLayout(3, 1));
    JPanel southButtonPanel = new JPanel(new GridLayout(1, 2));
    JPanel southTextPanel = new JPanel(new FlowLayout());

    JLabel textLabel = new JLabel("ID's: ");
    final JTextField idNumbers = new JTextField();
    idNumbers.setPreferredSize(new Dimension(200, 50));
    southTextPanel.add(textLabel);
    southTextPanel.add(idNumbers);

    final JButton updateButton = new JButton("Update");
    JButton selectButton = new JButton("Select All");
    JButton deselectButton = new JButton("Deselect All");
    southButtonPanel.add(deselectButton);
    southButtonPanel.add(selectButton);
    southPanel.add(southTextPanel);
    southPanel.add(southButtonPanel);
    southPanel.add(updateButton);

    mainLeftSide.add(heading, BorderLayout.NORTH);
    mainLeftSide.add(listOfMachineScroll, BorderLayout.CENTER);
    mainLeftSide.add(southPanel, BorderLayout.SOUTH);

    JTabbedPane tabbedPane = new JTabbedPane();

    final JComponent panel1 = localVendListStockPanel();
    JScrollPane scrollPanel1 = new JScrollPane(panel1);
    tabbedPane.addTab("List Stock", scrollPanel1);
    tabbedPane.setMnemonicAt(0, KeyEvent.VK_5);

    // final JComponent panel4 = machineChart(curID+1);

    // tabbedPane.addTab("", panel4);

    final JComponent panel2 = localVendRestockerPanel();
    JScrollPane scrollPanel2 = new JScrollPane(panel2);
    tabbedPane.addTab("Restocker", scrollPanel2);
    tabbedPane.setMnemonicAt(1, KeyEvent.VK_2);

    final JComponent panel3 = new JPanel();
    localVendMarketingPanel((JPanel) panel3);
    JScrollPane scrollPanel3 = new JScrollPane(panel3);
    tabbedPane.addTab("Marketing", panel3);
    tabbedPane.setMnemonicAt(2, KeyEvent.VK_3);

    final JComponent panel4 = machineChart(numOfSelected);
    JScrollPane scrollPanel4 = new JScrollPane(panel4);
    tabbedPane.addTab("Item %", scrollPanel4);
    tabbedPane.setMnemonicAt(3, KeyEvent.VK_4);

    final JComponent panelGross = machineGrossChart(numOfSelected);
    JScrollPane scrollpanelGross = new JScrollPane(panelGross);
    tabbedPane.addTab("Item Gross", scrollpanelGross);
    tabbedPane.setMnemonicAt(4, KeyEvent.VK_5);

    final JComponent panel5 = machineItemChart(numOfSelected);
    JScrollPane scrollPanel5 = new JScrollPane(panel5);
    tabbedPane.addTab("% Reasons Item Sold", scrollPanel5);
    tabbedPane.setMnemonicAt(5, KeyEvent.VK_6);

    final JComponent panelIncome = makeIncomeGraph(numOfSelected);
    panelIncome.setRequestFocusEnabled(true);
    JScrollPane scrollpanelIncome = new JScrollPane(panelIncome);
    tabbedPane.addTab("Income Graph", scrollpanelIncome);
    tabbedPane.setMnemonicAt(6, KeyEvent.VK_7);

    mainLayout.add(mainLeftSide, BorderLayout.WEST);
    mainLayout.add(tabbedPane, BorderLayout.CENTER);

    SwingUtilities.updateComponentTreeUI(this);

    listVendingMachine.setSelectionModel(
        new DefaultListSelectionModel() {
          private static final long serialVersionUID = 1L;

          boolean gestureStarted = false;

          @Override
          public void setSelectionInterval(int index0, int index1) {
            if (!gestureStarted) {
              if (isSelectedIndex(index0)) {
                super.removeSelectionInterval(index0, index1);
              } else {
                super.addSelectionInterval(index0, index1);
              }
            }
            gestureStarted = true;
          }

          @Override
          public void setValueIsAdjusting(boolean isAdjusting) {
            if (isAdjusting == false) {
              gestureStarted = false;
            }
          }
        });

    listVendingMachine.addListSelectionListener(
        new ListSelectionListener() {

          @Override
          public void valueChanged(ListSelectionEvent e) {
            // TODO Auto-generated method stub
            numOfSelected = listVendingMachine.getSelectedIndices();
            ArrayList<Integer> addOns = new ArrayList<Integer>();
            if (numOfSelected.length != 0) {
              String temp = "";
              for (int i = 0; i < numOfSelected.length; ++i) {
                if (i != (numOfSelected.length - 1)) {
                  if (numOfSelected[i] + 1 == numOfSelected[i + 1]) {
                    addOns.add(numOfSelected[i]);
                  } else {
                    if (addOns.size() == 0) {
                      temp += (numOfSelected[i] + 1) + ",";
                    } else {
                      temp += (addOns.get(0) + 1) + "-" + (numOfSelected[i] + 1) + ",";
                      addOns = new ArrayList<Integer>();
                    }
                  }
                } else {
                  if (addOns.size() == 0) {
                    temp += (numOfSelected[i] + 1) + ",";
                  } else {
                    temp += (addOns.get(0) + 1) + "-" + (numOfSelected[i] + 1) + ",";
                    addOns = new ArrayList<Integer>();
                  }
                }
                // temp += (numOfSelected[i] + 1) + ",";

              }
              temp = temp.substring(0, temp.length() - 1);
              idNumbers.setText(temp);
            }
          }
        });

    idNumbers.addKeyListener(
        new KeyAdapter() {
          public void keyTyped(KeyEvent e) {
            char c = e.getKeyChar();
            char last = ' ';

            if (idNumbers.getText().length() >= 1)
              last = idNumbers.getText().charAt(idNumbers.getText().length() - 1);

            int lastDash = idNumbers.getText().lastIndexOf('-');
            int lastComma = idNumbers.getText().lastIndexOf(',');
            if ((last == ' ' && (c == '-' || c == ','))
                || (c == '-' && (lastComma - lastDash) < 0)
                || (last == '-' && (c == '-' || c == ','))
                || (last == ',' && (c == ',' || c == '-'))
                || (!Character.isDigit(c) && c != '-' && c != ',')
                    && (c != KeyEvent.VK_BACK_SPACE)) {
              e.consume(); // ignore event
            }
          }
        });

    selectButton.addActionListener(
        new ActionListener() {

          @Override
          public void actionPerformed(ActionEvent e) {
            listVendingMachine.addSelectionInterval(0, numberOfMachines - 1);

            // TODO Auto-generated method stub

          }
        });
    deselectButton.addActionListener(
        new ActionListener() {

          @Override
          public void actionPerformed(ActionEvent e) {
            // TODO Auto-generated method stub
            idNumbers.setText("");
            listVendingMachine.removeSelectionInterval(0, numberOfMachines - 1);
          }
        });

    updateButton.addActionListener(
        new ActionListener() {

          @Override
          public void actionPerformed(ActionEvent e) {
            // TODO Auto-generated method stub
            listVendingMachine.removeSelectionInterval(0, numberOfMachines - 1);
            String numbers = idNumbers.getText();
            String[] splitNumbers = numbers.split(",");

            for (int i = 0; i < splitNumbers.length; ++i) {

              if (!splitNumbers[i].equals("")) {
                if (!splitNumbers[i].contains("-")) {
                  int num = Integer.valueOf(splitNumbers[i]) - 1;
                  if (num < 0) {
                    num = 0;
                  }
                  if (num > numberOfMachines - 1) {
                    num = numberOfMachines - 1;
                  }

                  listVendingMachine.addSelectionInterval(num, num);
                } else {
                  String[] temp = splitNumbers[i].split("-");
                  if (!temp[0].equals("") && !temp[1].equals("")) {
                    int num1 = Integer.valueOf(temp[0]) - 1;
                    int num2 = Integer.valueOf(temp[1]) - 1;
                    if (num1 < 0) {
                      num1 = 0;
                    }
                    if (num2 > numberOfMachines - 1) {
                      num2 = numberOfMachines - 1;
                    }
                    listVendingMachine.addSelectionInterval(num1, num2);
                  }
                }
              }
            }

            numOfSelected = listVendingMachine.getSelectedIndices();
            if (numOfSelected.length != 0) {

              panel1.removeAll();
              panel2.removeAll();
              panel3.removeAll();
              panel4.removeAll();
              panel5.removeAll();
              panelGross.removeAll();
              panelIncome.removeAll();

              panel1.add(localVendListStockPanel());
              panel2.add(localVendRestockerPanel());
              localVendMarketingPanel((JPanel) panel3);
              panel4.add(machineChart(numOfSelected));
              panel5.add(machineItemChart(numOfSelected));
              panelGross.add(machineGrossChart(numOfSelected));
              panelIncome.add(makeIncomeGraph(numOfSelected));

              panel1.revalidate();
              panel1.repaint();
              panel2.revalidate();
              panel2.repaint();
              panel3.revalidate();
              panel3.repaint();
              panel4.revalidate();
              panel4.repaint();
              panel5.revalidate();
              panel5.repaint();
              panelGross.revalidate();
              panelGross.repaint();
              panelIncome.revalidate();
              panelIncome.repaint();
            } else {
              panel1.removeAll();
              panel2.removeAll();
              panel3.removeAll();
              panel4.removeAll();
              panel5.removeAll();
              panelGross.removeAll();
              panelIncome.removeAll();

              panel1.setLayout(new FlowLayout());
              panel2.setLayout(new FlowLayout());
              panel3.setLayout(new FlowLayout());
              panel4.setLayout(new FlowLayout());
              panel5.setLayout(new FlowLayout());
              panelGross.setLayout(new FlowLayout());
              panelIncome.setLayout(new FlowLayout());

              panel1.add(returnEmptyPanelInfo());
              panel2.add(returnEmptyPanelInfo());
              panel3.add(returnEmptyPanelInfo());
              panel4.add(returnEmptyPanelInfo());
              panel5.add(returnEmptyPanelInfo());
              panelGross.add(returnEmptyPanelInfo());
              panelIncome.add(returnEmptyPanelInfo());

              panel1.revalidate();
              panel1.repaint();
              panel2.revalidate();
              panel2.repaint();
              panel3.revalidate();
              panel3.repaint();
              panel4.revalidate();
              panel4.repaint();
              panel5.revalidate();
              panel5.repaint();
              panelGross.revalidate();
              panelGross.repaint();
              panelIncome.revalidate();
              panelIncome.repaint();
            }
          }
        });
  }