/**
   * Attempts to search the mod website for the mod and pull the recent versions of the mod.
   *
   * @param mod The Mod to search for on the website.
   * @param modInfoList The JList to populate/alter.
   */
  public void getRecentVersionsOfModAsync(Profile.Mod mod, JList modInfoList) {
    // Here we set a thread task to get the version numbers for the mod. This will look at the site
    // and search for the mod, then pull all versions from it.
    Runnable task = () -> Crawler.readVersionInfoOfMod(mod.nameWithoutVersion);
    Thread thread = new Thread(task);
    thread.start();

    // Our timer that checks every 200ms if the thread has finished.
    Timer timer = new Timer(200, null);
    timer.addActionListener(
        ev -> {
          if (thread.getState() != Thread.State.TERMINATED) timer.restart();
          else {
            timer.stop();
            DefaultListModel listModel = (DefaultListModel) modInfoList.getModel();
            // Get the modVersionInfo from the crawler. If not null, add to the list.
            String[][] modVersionInfo = Crawler.getModVersionInfo();
            if (modVersionInfo != null) {
              listModel.addElement("Recent Versions:");
              for (String[] info : modVersionInfo) {
                listModel.addElement("    v" + info[0] + " for " + info[1]);
              }
            } else {
              listModel.addElement("Couldn't find the mod on the website.");
            }
            modInfoList.setModel(listModel);
          }
        });
    timer.start();
  }
예제 #2
0
파일: JSheet.java 프로젝트: karlvr/Quaqua
  @Override
  @SuppressWarnings("deprecation")
  public void hide() {
    if (isExperimentalSheet()) {
      OSXSheetSupport.hideSheet(this);
      hide0();
      uninstallSheet();
    } else if (isAnimated() && isShowAsSheet() && !isNativeSheetSupported()) {
      getContentPane().setVisible(false);

      final Rectangle startBounds = getBounds();
      int parentWidth = getParent().getWidth();
      final Rectangle endBounds =
          new Rectangle(
              (parentWidth < startBounds.width)
                  ? startBounds.x + (startBounds.width - parentWidth) / 2
                  : startBounds.x,
              startBounds.y,
              Math.min(startBounds.width, parentWidth),
              0);
      final Timer timer = new Timer(20, null);
      timer.addActionListener(
          new ActionListener() {

            long startTime;
            long endTime;

            public void actionPerformed(ActionEvent evt) {
              long now = System.currentTimeMillis();
              if (startTime == 0) {
                startTime = now;
                endTime = startTime + 200;
              }
              if (now > endTime) {
                timer.stop();
                hide0();
                setBounds(startBounds);
                getContentPane().setVisible(true);
                uninstallSheet();
              } else {
                float ratio = (now - startTime) / (float) (endTime - startTime);
                setBounds(
                    (int) (startBounds.x * (1f - ratio) + endBounds.x * ratio),
                    (int) (startBounds.y * (1f - ratio) + endBounds.y * ratio),
                    (int) (startBounds.width * (1f - ratio) + endBounds.width * ratio),
                    (int) (startBounds.height * (1f - ratio) + endBounds.height * ratio));
              }
            }
          });
      timer.setRepeats(true);
      timer.setInitialDelay(5);
      timer.start();
    } else {
      hide0();
      uninstallSheet();
    }
  }
예제 #3
0
 public Stars() {
   setPreferredSize(new Dimension(150, 150));
   setBackground(new Color(0, 86, 141));
   appDisplay = new JFrame("Stars");
   appDisplay.getContentPane().add(this);
   appDisplay.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
   appDisplay.pack();
   appDisplay.setVisible(true);
   timer = new Timer(DELAY, null);
   timer.addActionListener(new StarListener());
   timer.start();
 }
예제 #4
0
파일: JSheet.java 프로젝트: karlvr/Quaqua
  @Override
  @SuppressWarnings("deprecation")
  public void show() {
    if (isExperimentalSheet()) {
      // Install the sheet
      installSheet();
      // Create the native peer - maybe not supported
      addNotify();
      if (OSXSheetSupport.showAsSheet(this)) {
        // Tell lightweight components to be visible
        show0();
        return;
      } else {
        isExperimentalSheet = false;
      }
    }
    if (isAnimated() && isShowAsSheet() && !isNativeSheetSupported()) {
      installSheet();
      getContentPane().setVisible(false);

      final Rectangle endBounds = getBounds();
      int parentWidth = getParent().getWidth();
      final Rectangle startBounds =
          new Rectangle(
              (parentWidth < endBounds.width)
                  ? endBounds.x + (endBounds.width - parentWidth) / 2
                  : endBounds.x,
              endBounds.y,
              Math.min(endBounds.width, parentWidth),
              0);
      setBounds(startBounds);
      if (!isDocumentModalitySupported()) {
        ((Window) getParent()).toFront();
      }
      final Timer timer = new Timer(20, null);
      timer.addActionListener(
          new ActionListener() {

            long startTime;
            long endTime;

            public void actionPerformed(ActionEvent evt) {
              long now = System.currentTimeMillis();
              if (startTime == 0) {
                startTime = now;
                endTime = startTime + 200;
              }
              if (now > endTime) {
                timer.stop();
                setBounds(endBounds);
                getContentPane().setVisible(true);

                Component c = getFocusTraversalPolicy().getInitialComponent(JSheet.this);
                if (c != null) {
                  c.requestFocus();
                } else {
                  getContentPane().requestFocus();
                }
              } else {
                float ratio = (now - startTime) / (float) (endTime - startTime);
                setBounds(
                    (int) (startBounds.x * (1f - ratio) + endBounds.x * ratio),
                    (int) (startBounds.y * (1f - ratio) + endBounds.y * ratio),
                    (int) (startBounds.width * (1f - ratio) + endBounds.width * ratio),
                    (int) (startBounds.height * (1f - ratio) + endBounds.height * ratio));
              }
            }
          });
      timer.setRepeats(true);
      timer.setInitialDelay(5);
      timer.start();
      show0();
    } else {
      installSheet();
      show0();
    }
    OSXApplication.requestUserAttention(true);
  }
  /** Constructor for RestaurantGui class. Sets up all the gui components. */
  public RestaurantGui() {

    super("Restaurant Application");

    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setBounds(50, 50, WINDOWX, WINDOWY);

    getContentPane().setLayout(new BoxLayout((Container) getContentPane(), BoxLayout.Y_AXIS));

    Dimension rest = new Dimension(WINDOWX, (int) (WINDOWY * .4));
    Dimension info = new Dimension(WINDOWX, (int) (WINDOWY * .1));
    restPanel.setPreferredSize(rest);
    restPanel.setMinimumSize(rest);
    restPanel.setMaximumSize(rest);
    infoPanel.setPreferredSize(info);
    infoPanel.setMinimumSize(info);
    infoPanel.setMaximumSize(info);
    infoPanel.setBorder(BorderFactory.createTitledBorder("Information"));

    inventorySetup.setLayout(new BorderLayout());
    inventorySetup.add(inventoryLabel, BorderLayout.NORTH);
    chicken.setMajorTickSpacing(1);
    chicken.setPaintLabels(true);
    chicken.setPaintTicks(true);
    steak.setMajorTickSpacing(1);
    steak.setPaintLabels(true);
    steak.setPaintTicks(true);
    pizza.setMajorTickSpacing(1);
    pizza.setPaintLabels(true);
    pizza.setPaintTicks(true);
    salad.setMajorTickSpacing(1);
    salad.setPaintLabels(true);
    salad.setPaintTicks(true);
    chicken.addChangeListener(this);
    steak.addChangeListener(this);
    pizza.addChangeListener(this);
    salad.addChangeListener(this);
    custHungerLevel.addChangeListener(this);
    currentChicken.setEditable(false);
    currentSteak.setEditable(false);
    currentSalad.setEditable(false);
    currentPizza.setEditable(false);

    moneyLabel.setText("New Customer Money");
    customerMoney.setEditable(true);
    custMoneyInput.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            custMoney = Integer.parseInt(customerMoney.getText());
          }
        });
    custMoneyInput.setText("submit");

    moneyPanel.setLayout(new GridLayout(1, 3));
    moneyPanel.add(moneyLabel);
    moneyPanel.add(customerMoney);
    moneyPanel.add(custMoneyInput);
    /*currentChicken.setText(Integer.toString(restPanel.cook.inventory.get("Chicken").currentNumber));
    currentSteak.setText(Integer.toString(restPanel.cook.inventory.get("Steak").currentNumber));
    currentPizza.setText(Integer.toString(restPanel.cook.inventory.get("Pizza").currentNumber));
    currentSalad.setText(Integer.toString(restPanel.cook.inventory.get("Salad").currentNumber));*/

    inventoryInput.setLayout(new GridLayout(5, 3));
    inventoryInput.add(chickenLabel);
    inventoryInput.add(currentChicken);
    inventoryInput.add(chicken);
    inventoryInput.add(saladLabel);
    inventoryInput.add(currentSalad);
    inventoryInput.add(salad);
    inventoryInput.add(pizzaLabel);
    inventoryInput.add(currentPizza);
    inventoryInput.add(pizza);
    inventoryInput.add(steakLabel);
    inventoryInput.add(currentSteak);
    inventoryInput.add(steak);
    inventoryInput.add(hungerLabel);
    inventoryInput.add(custHungerLevel);

    inventorySetup.add(inventoryInput, BorderLayout.CENTER);

    requestBreak.addActionListener(this);
    requestBreak.setVisible(false);

    stateCB.setVisible(false);
    stateCB.addActionListener(this);
    changeOrder.setVisible(false);
    changeOrder.addActionListener(this);

    infoPanel.setLayout(new GridLayout(1, 2, 30, 0));
    infoPanel.add(infoLabel);
    infoPanel.add(stateCB);
    infoPanel.add(requestBreak);
    infoPanel.add(changeOrder);

    getContentPane().add(restPanel);
    getContentPane().add(addTable);
    getContentPane().add(infoPanel);
    getContentPane().add(moneyPanel);
    getContentPane().add(inventorySetup);

    addTable.addActionListener(this);

    t.setDelay(40);
    t.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            updateInventory();
          }
        });
  }