コード例 #1
0
  /**
   * Méthode de création du panelInit
   *
   * @return
   */
  private JPanel createPanelInit() {

    JPanel panRight = new JPanel();
    panRight.setLayout(new BoxLayout(panRight, BoxLayout.Y_AXIS));

    butListParty = new JButton("Liste des parties");
    butListParty.addActionListener(this);

    JPanel panCreate = new JPanel();
    panCreate.setLayout(new BoxLayout(panCreate, BoxLayout.X_AXIS));
    textCreate = new JTextField("", 40);
    textCreate.setMaximumSize(textCreate.getPreferredSize());
    butCreateParty = new JButton("Creation de parties ");
    butCreateParty.addActionListener(this);
    SpinnerModel model = new SpinnerNumberModel(3, 2, 8, 1);
    spinNbPlayer = new JSpinner(model);
    spinNbPlayer.setMaximumSize(spinNbPlayer.getPreferredSize());
    panCreate.add(new JLabel("Nouveau nom de partie : "));
    panCreate.add(textCreate);
    panCreate.add(Box.createHorizontalStrut(20));
    panCreate.add(new JLabel("Nombres de joueurs : "));
    panCreate.add(spinNbPlayer);
    panCreate.add(butCreateParty);

    JPanel panJoin = new JPanel();
    panJoin.setLayout(new BoxLayout(panJoin, BoxLayout.X_AXIS));
    textJoin = new JTextField("", 2);
    textJoin.setMaximumSize(textJoin.getPreferredSize());
    butJoinParty = new JButton("Rejoindre la partie ");
    butJoinParty.addActionListener(this);
    panJoin.add(new JLabel("Num Partie : "));
    panJoin.add(textJoin);
    panJoin.add(butJoinParty);

    panRight.add(butListParty);
    panRight.add(panCreate);
    panRight.add(panJoin);
    panRight.add(Box.createVerticalGlue());

    textInfoInit = new JTextArea(20, 100);
    textInfoInit.setLineWrap(true);

    JScrollPane scroll =
        new JScrollPane(
            textInfoInit,
            JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
            JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
    JPanel panAll = new JPanel();
    panAll.setLayout(new BoxLayout(panAll, BoxLayout.X_AXIS));
    panAll.add(scroll);
    panAll.add(panRight);

    return panAll;
  }
コード例 #2
0
  public void actionPerformed(ActionEvent e) {

    if (e.getSource() == butConnect) {
      try {
        boolean ok = serverConnection();
        if (ok) {
          setInitPanel();
        } else {
          System.out.println("Le pseudo existe déjà, choisissez en un autre.");
        }
      } catch (IOException err) {
        System.err.println(
            "Problème de connection avec le serveur: " + err.getMessage() + "\n.Arrêt...");
        System.exit(1);
      }
    } else if (e.getSource() == butListParty) {
      try {
        // envoyer requête LIST PARTY
        oos.writeInt(JungleServer.REQ_LISTPARTY);
        oos.flush();

        // recevoir résultat et l'afficher dans textInfoInit
        System.out.println("flush");
        boolean pret = ois.readBoolean();
        System.out.println(pret);
        if (pret) {
          String nomParty = (String) ois.readObject();
          System.out.println("apres read");
          textInfoInit.append(nomParty + " ");
        }

      } catch (ClassNotFoundException err) {
      } catch (IOException err) {
        System.err.println(
            "Problème de connection avec le serveur: " + err.getMessage() + "\n.Arrêt...");
        System.exit(1);
      }

    } else if (e.getSource() == butCreateParty) {
      try {
        boolean ok;
        // envoyer requête CREATE PARTY (paramètres : nom partie et nb joueurs nécessaires)
        oos.writeInt(JungleServer.REQ_CREATEPARTY);
        oos.writeObject(textCreate.getText());
        int nbJoueurs = (Integer) spinNbPlayer.getValue();
        oos.writeInt(nbJoueurs);
        oos.flush();
        // recevoir résultat -> ok
        ok = ois.readBoolean();
        System.out.println(ok);
        // si ok == true :
        if (ok) {
          // mettre le panneau party au centre
          setPartyPanel();
          // afficher un message dans textInfoParty comme quoi il faut attendre le début de partie
          textInfoParty.append("Attendre le début de la partie");
          // créer un ThreadClient et lancer son exécution
          ThreadClient threadClient = new ThreadClient(this);
          threadClient.start();
        }
      } catch (IOException err) {
        System.err.println(
            "probleme de connection serveur : " + err.getMessage() + "\n.Aborting...");
        System.exit(1);
      }
    } else if (e.getSource() == butJoinParty) {

      try {
        int idPlayer;
        // envoyer requête JOIN PARTY (paramètres : numero partie)
        oos.writeInt(JungleServer.REQ_JOINPARTY);
        oos.flush();
        System.out.println("requete envoyée");
        int numPartie = Integer.parseInt(textJoin.getText());
        oos.writeInt(numPartie);
        oos.flush();
        System.out.println("numPartie flushé");
        // recevoir résultat -> idPlayer
        idPlayer = ois.readInt();
        System.out.println("idplayer reçu : " + idPlayer);
        // si idPlayer >= 1 :
        if (idPlayer >= 1) {
          // mettre le panneau party au centre
          setPartyPanel();
          // afficher un message dans textInfoParty comme quoi il faut attendre le début de partie
          textInfoParty.append("Attendre la début de la partie");
          // créer un ThreadClient et lancer son exécution
          System.out.println("avant démarrage du thread");
          ThreadClient threadClient = new ThreadClient(this);
          threadClient.start();
          System.out.println("Apres le thread");
        }
      } catch (IOException err) {
        System.err.println("Problème de connection serveur: " + err.getMessage() + "\n.Arrêt...");
        System.exit(1);
      }
    } else if (e.getSource() == butPlay) {
      try {
        // envoyer requête PLAY (paramètre : contenu de textPlay)
        oos.writeInt(JungleServer.REQ_PLAY);
        oos.writeObject(textPlay.getText());
        oos.flush();
        orderSent = true;
        butPlay.setEnabled(false);
        textPlay.setEnabled(false);

        // mettre orderSent à true
        // bloquer le bouton play et le textfiled associé
      } catch (IOException err) {
        System.err.println("Problème connection serveur: " + err.getMessage() + "\n.Arrêt...");
        System.exit(1);
      }
    } else if (e.getSource() == butQuit) {
      try {
        oos.close();
        ois.close();
        setConnectionPanel();
        comm = null;
      } catch (IOException err) {
        System.err.println("Problème connection serveur: " + err.getMessage() + "\n.Arrêt...");
        System.exit(1);
      }
    }
  }
コード例 #3
0
ファイル: MediaConfiguration.java プロジェクト: onsip/jitsi
  /**
   * Creates the video advanced settings.
   *
   * @return video advanced settings panel.
   */
  private static Component createVideoAdvancedSettings() {
    ResourceManagementService resources = NeomediaActivator.getResources();

    final DeviceConfiguration deviceConfig = mediaService.getDeviceConfiguration();

    TransparentPanel centerPanel = new TransparentPanel(new GridBagLayout());
    centerPanel.setMaximumSize(new Dimension(WIDTH, 150));

    JButton resetDefaultsButton =
        new JButton(resources.getI18NString("impl.media.configform.VIDEO_RESET"));
    JPanel resetButtonPanel = new TransparentPanel(new FlowLayout(FlowLayout.RIGHT));
    resetButtonPanel.add(resetDefaultsButton);

    final JPanel centerAdvancedPanel = new TransparentPanel(new BorderLayout());
    centerAdvancedPanel.add(centerPanel, BorderLayout.NORTH);
    centerAdvancedPanel.add(resetButtonPanel, BorderLayout.SOUTH);

    GridBagConstraints constraints = new GridBagConstraints();
    constraints.fill = GridBagConstraints.HORIZONTAL;
    constraints.anchor = GridBagConstraints.NORTHWEST;
    constraints.insets = new Insets(5, 5, 0, 0);
    constraints.gridx = 0;
    constraints.weightx = 0;
    constraints.weighty = 0;
    constraints.gridy = 0;

    centerPanel.add(
        new JLabel(resources.getI18NString("impl.media.configform.VIDEO_RESOLUTION")), constraints);
    constraints.gridy = 1;
    constraints.insets = new Insets(0, 0, 0, 0);
    final JCheckBox frameRateCheck =
        new SIPCommCheckBox(resources.getI18NString("impl.media.configform.VIDEO_FRAME_RATE"));
    centerPanel.add(frameRateCheck, constraints);
    constraints.gridy = 2;
    constraints.insets = new Insets(5, 5, 0, 0);
    centerPanel.add(
        new JLabel(resources.getI18NString("impl.media.configform.VIDEO_PACKETS_POLICY")),
        constraints);

    constraints.weightx = 1;
    constraints.gridx = 1;
    constraints.gridy = 0;
    constraints.insets = new Insets(5, 0, 0, 5);
    Object[] resolutionValues = new Object[DeviceConfiguration.SUPPORTED_RESOLUTIONS.length + 1];
    System.arraycopy(
        DeviceConfiguration.SUPPORTED_RESOLUTIONS,
        0,
        resolutionValues,
        1,
        DeviceConfiguration.SUPPORTED_RESOLUTIONS.length);
    final JComboBox sizeCombo = new JComboBox(resolutionValues);
    sizeCombo.setRenderer(new ResolutionCellRenderer());
    sizeCombo.setEditable(false);
    centerPanel.add(sizeCombo, constraints);

    // default value is 20
    final JSpinner frameRate = new JSpinner(new SpinnerNumberModel(20, 5, 30, 1));
    frameRate.addChangeListener(
        new ChangeListener() {
          public void stateChanged(ChangeEvent e) {
            deviceConfig.setFrameRate(
                ((SpinnerNumberModel) frameRate.getModel()).getNumber().intValue());
          }
        });
    constraints.gridy = 1;
    constraints.insets = new Insets(0, 0, 0, 5);
    centerPanel.add(frameRate, constraints);

    frameRateCheck.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            if (frameRateCheck.isSelected()) {
              deviceConfig.setFrameRate(
                  ((SpinnerNumberModel) frameRate.getModel()).getNumber().intValue());
            } else // unlimited framerate
            deviceConfig.setFrameRate(-1);

            frameRate.setEnabled(frameRateCheck.isSelected());
          }
        });

    final JSpinner videoMaxBandwidth =
        new JSpinner(
            new SpinnerNumberModel(deviceConfig.getVideoMaxBandwidth(), 1, Integer.MAX_VALUE, 1));
    videoMaxBandwidth.addChangeListener(
        new ChangeListener() {
          public void stateChanged(ChangeEvent e) {
            deviceConfig.setVideoMaxBandwidth(
                ((SpinnerNumberModel) videoMaxBandwidth.getModel()).getNumber().intValue());
          }
        });
    constraints.gridx = 1;
    constraints.gridy = 2;
    constraints.insets = new Insets(0, 0, 5, 5);
    centerPanel.add(videoMaxBandwidth, constraints);

    resetDefaultsButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            // reset to defaults
            sizeCombo.setSelectedIndex(0);
            frameRateCheck.setSelected(false);
            frameRate.setEnabled(false);
            frameRate.setValue(20);
            // unlimited framerate
            deviceConfig.setFrameRate(-1);
            videoMaxBandwidth.setValue(DeviceConfiguration.DEFAULT_VIDEO_MAX_BANDWIDTH);
          }
        });

    // load selected value or auto
    Dimension videoSize = deviceConfig.getVideoSize();

    if ((videoSize.getHeight() != DeviceConfiguration.DEFAULT_VIDEO_HEIGHT)
        && (videoSize.getWidth() != DeviceConfiguration.DEFAULT_VIDEO_WIDTH))
      sizeCombo.setSelectedItem(deviceConfig.getVideoSize());
    else sizeCombo.setSelectedIndex(0);
    sizeCombo.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            Dimension selectedVideoSize = (Dimension) sizeCombo.getSelectedItem();

            if (selectedVideoSize == null) {
              // the auto value, default one
              selectedVideoSize =
                  new Dimension(
                      DeviceConfiguration.DEFAULT_VIDEO_WIDTH,
                      DeviceConfiguration.DEFAULT_VIDEO_HEIGHT);
            }
            deviceConfig.setVideoSize(selectedVideoSize);
          }
        });

    frameRateCheck.setSelected(
        deviceConfig.getFrameRate() != DeviceConfiguration.DEFAULT_VIDEO_FRAMERATE);
    frameRate.setEnabled(frameRateCheck.isSelected());

    if (frameRate.isEnabled()) frameRate.setValue(deviceConfig.getFrameRate());

    return centerAdvancedPanel;
  }
コード例 #4
0
 public static int getInterval() {
   return (Integer) interval.getValue() * 60000;
 }
コード例 #5
0
  public GUI() {

    // Frame
    frame = new JFrame("HardwareSwap Notifier");

    // Panels
    panel = new JPanel();
    group1 = new JPanel();
    group2 = new JPanel();
    group3 = new JPanel();
    group4 = new JPanel();
    group5 = new JPanel();
    group6 = new JPanel();
    group7 = new JPanel();
    group8 = new JPanel();

    // Menu Bar
    menus = new JMenuBar();
    fileMenu = new JMenu("File");
    clearCurrent = new JMenuItem("Clear");
    quitItem = new JMenuItem("Quit");
    load = new JMenuItem("Load");
    saveCurrent = new JMenuItem("Save All");
    clearSaved = new JMenuItem("Clear Saved");
    removeItem = new JMenuItem("Remove Item");
    removePhone = new JMenuItem("Remove Phone");
    saveCurrent = new JMenuItem("Save Current");
    helpMenu = new JMenu("Help");
    help = new JMenuItem("How To Use");
    about = new JMenuItem("About");

    // Buttons
    add1 = new JButton("Add");
    add2 = new JButton("Add");
    start = new JButton("Start");
    stop = new JButton("Stop");
    save1 = new JButton("Add/Save");
    save2 = new JButton("Add/Save");
    show = new JButton("Display Data");

    add1.setFocusPainted(false);
    add2.setFocusPainted(false);
    start.setFocusPainted(false);
    stop.setFocusPainted(false);
    save1.setFocusPainted(false);
    save2.setFocusPainted(false);
    show.setFocusPainted(false);

    stop.setEnabled(false);

    // CheckBox
    remove = new JCheckBox("Remove items when found");
    remove.setFocusable(false);

    // Listener
    ButtonListener listener = new ButtonListener();

    add1.addActionListener(listener);
    add2.addActionListener(listener);
    start.addActionListener(listener);
    stop.addActionListener(listener);
    load.addActionListener(listener);
    save1.addActionListener(listener);
    save2.addActionListener(listener);
    saveCurrent.addActionListener(listener);
    show.addActionListener(listener);
    quitItem.addActionListener(listener);
    clearCurrent.addActionListener(listener);
    clearSaved.addActionListener(listener);
    saveCurrent.addActionListener(listener);
    help.addActionListener(listener);
    about.addActionListener(listener);
    removePhone.addActionListener(listener);
    removeItem.addActionListener(listener);
    remove.addActionListener(listener);

    // Carrier Selection
    options = new String[10];
    options[0] = "AT&T";
    options[1] = "Boost Mobile";
    options[2] = "Cellular One";
    options[3] = "Nextel";
    options[4] = "T-Mobile";
    options[5] = "Tracfone";
    options[6] = "US Cellular";
    options[7] = "Sprint";
    options[8] = "Verizon";
    options[9] = "Virgin Mobile";

    carriers = new JComboBox<String>(options);

    // Text Fields
    searchName = new JTextField(15);
    item = new JTextField(15);
    phone = new JTextField(15);
    interval2 = new JTextField(15);
    results = new JTextArea(10, 20);

    JScrollPane scrollPane = new JScrollPane(results);

    results.setEditable(false);

    // Interval
    intOptions = new SpinnerNumberModel(5, 1, 60, 1);
    interval = new JSpinner(intOptions);
    JFormattedTextField tf = ((JSpinner.DefaultEditor) interval.getEditor()).getTextField();
    tf.setHorizontalAlignment(JFormattedTextField.LEFT);

    // Background
    panelBackground = new Color(237, 237, 237);

    panel.setBackground(panelBackground);
    searchName.setBackground(panelBackground);
    item.setBackground(panelBackground);
    phone.setBackground(panelBackground);
    interval.setBackground(panelBackground);

    // Panel Layouts
    panel.setLayout(new BoxLayout(panel, BoxLayout.PAGE_AXIS));
    group1.setLayout(new BoxLayout(group1, BoxLayout.PAGE_AXIS));
    group2.setLayout(new BoxLayout(group2, BoxLayout.X_AXIS));
    group3.setLayout(new BoxLayout(group3, BoxLayout.PAGE_AXIS));
    group4.setLayout(new BoxLayout(group4, BoxLayout.X_AXIS));
    group5.setLayout(new BoxLayout(group5, BoxLayout.X_AXIS));
    group6.setLayout(new BoxLayout(group6, BoxLayout.X_AXIS));
    group7.setLayout(new BoxLayout(group7, BoxLayout.X_AXIS));
    group8.setLayout(new BoxLayout(group8, BoxLayout.X_AXIS));

    // Borders
    searchName.setBorder(
        BorderFactory.createTitledBorder(
            null,
            "Search Name",
            TitledBorder.DEFAULT_JUSTIFICATION,
            TitledBorder.DEFAULT_JUSTIFICATION,
            null,
            Color.DARK_GRAY));
    item.setBorder(
        BorderFactory.createTitledBorder(
            null,
            "Item",
            TitledBorder.DEFAULT_JUSTIFICATION,
            TitledBorder.DEFAULT_JUSTIFICATION,
            null,
            Color.DARK_GRAY));
    phone.setBorder(
        BorderFactory.createTitledBorder(
            null,
            "Cell Phone",
            TitledBorder.DEFAULT_JUSTIFICATION,
            TitledBorder.DEFAULT_JUSTIFICATION,
            null,
            Color.DARK_GRAY));
    group5.setBorder(
        BorderFactory.createTitledBorder(
            null,
            "Check Interval (mins)",
            TitledBorder.DEFAULT_JUSTIFICATION,
            TitledBorder.DEFAULT_JUSTIFICATION,
            null,
            Color.DARK_GRAY));

    // Sizes
    panel.setPreferredSize(new Dimension(200, 0));
    searchName.setMaximumSize(new Dimension(190, 50));
    item.setMaximumSize(new Dimension(190, 50));
    phone.setMaximumSize(new Dimension(185, 50));
    carriers.setMaximumSize(new Dimension(175, 20));
    group5.setPreferredSize(new Dimension(190, 47));
    group5.setMaximumSize(new Dimension(190, 47));

    add1.setMaximumSize(new Dimension(90, 20));
    save1.setMaximumSize(new Dimension(90, 20));
    add2.setMaximumSize(new Dimension(90, 20));
    save2.setMaximumSize(new Dimension(90, 20));
    start.setMaximumSize(new Dimension(90, 20));
    stop.setMaximumSize(new Dimension(90, 20));
    show.setMaximumSize(new Dimension(120, 20));

    // Add file menu items
    fileMenu.add(clearCurrent);
    fileMenu.add(clearSaved);
    fileMenu.add(load);
    fileMenu.add(removeItem);
    fileMenu.add(removePhone);
    fileMenu.add(saveCurrent);
    fileMenu.add(quitItem);

    // Add help menu items
    helpMenu.add(help);
    helpMenu.add(about);

    // Add to menu bar
    menus.add(fileMenu);
    menus.add(helpMenu);

    // Add items to panel
    group1.add(searchName);
    group1.add(item);

    group2.add(add1);
    group2.add(Box.createHorizontalStrut(10));
    group2.add(save1);

    group6.add(remove);

    group3.add(phone);
    group3.add(Box.createVerticalStrut(10));
    group3.add(carriers);

    group4.add(add2);
    group4.add(Box.createHorizontalStrut(10));
    group4.add(save2);

    group5.add(interval);

    group7.add(show);

    group8.add(start);
    group8.add(Box.createHorizontalStrut(10));
    group8.add(stop);

    panel.add(Box.createVerticalStrut(10));
    panel.add(group1);
    panel.add(Box.createVerticalStrut(10));
    panel.add(group2);
    panel.add(Box.createVerticalStrut(40));
    panel.add(group3);
    panel.add(Box.createVerticalStrut(10));
    panel.add(group4);
    panel.add(Box.createVerticalStrut(40));
    panel.add(group5);
    panel.add(Box.createVerticalStrut(30));
    panel.add(group6);
    panel.add(Box.createVerticalStrut(40));
    panel.add(group7);
    panel.add(Box.createVerticalStrut(10));
    panel.add(group8);
    panel.add(Box.createVerticalStrut(10));

    // Setup frame
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setJMenuBar(menus);
    frame.add(scrollPane);
    frame.add(BorderLayout.EAST, panel);
    frame.pack();
    frame.setSize(new Dimension(670, 620));
    frame.setVisible(true);
  }
コード例 #6
0
    ModiPanel(MemberPane mp, BusinessPane bp) {
      this.member_pane = mp;
      this.busi_pane = bp;
      setLayout(null);
      add(member_title);
      member_title.setBounds(20, 10, 80, 20);
      add(member_id);
      member_id.setBounds(20, 35, 80, 20);
      add(member_name);
      member_name.setBounds(20, 60, 80, 20);
      add(member_tele);
      member_tele.setBounds(20, 85, 80, 20);
      add(member_level);
      member_level.setBounds(20, 110, 80, 20);
      add(member_bal);
      member_bal.setBounds(20, 135, 80, 20);
      add(text_id);
      text_id.setBounds(100, 35, 180, 20);
      add(text_name);
      text_name.setBounds(100, 60, 180, 20);
      add(text_tele);
      text_tele.setBounds(100, 85, 180, 20);
      /*add(text_level);
      text_level.setBounds(100,90,180,20);*/
      add(text_bal);
      text_bal.setBounds(100, 135, 180, 20);
      add(spinner_level);
      spinner_level.setBounds(100, 110, 180, 20);

      add(trans_title);
      trans_title.setBounds(20, 220, 80, 20);
      add(trans_member);
      trans_member.setBounds(20, 245, 80, 20);
      add(trans_money);
      trans_money.setBounds(20, 270, 80, 20);
      add(text_member);
      text_member.setBounds(100, 245, 180, 20);
      add(text_money);
      text_money.setBounds(100, 270, 180, 20);

      add(button_add);
      button_add.setBounds(100, 165, 100, 25);
      button_add.addActionListener(
          new ActionListener() {
            public void actionPerformed(ActionEvent e) {
              try {
                System.out.println("add");
                mm.addMember(
                    text_id.getText(),
                    text_name.getText(),
                    text_tele.getText(),
                    spinner_level.getValue().toString(),
                    text_bal.getText());
                member_pane.update_table();
              } catch (Exception ex) {
                JOptionPane.showMessageDialog(
                    mainFrame, "Adding Failure!", "ERROR", JOptionPane.ERROR_MESSAGE);
              }

              // dialog_send.setVisible(false);
            }
          });

      add(button_add_trans);
      button_add_trans.setBounds(100, 305, 100, 25);
      button_add_trans.addActionListener(
          new ActionListener() {
            public void actionPerformed(ActionEvent e) {
              try {
                System.out.println("add transaction");
                Business busi =
                    new Business(
                        text_member.getText(), Float.valueOf(text_money.getText()).floatValue());
                busi.addBusi();
                busi_pane.update_table();
              } catch (Exception ex) {
                JOptionPane.showMessageDialog(
                    mainFrame, "Adding Failure!", "ERROR", JOptionPane.ERROR_MESSAGE);
              }

              // dialog_send.setVisible(false);
            }
          });

      // set font;
      member_title.setFont(font_title);
      member_id.setFont(font);
      member_name.setFont(font);
      member_tele.setFont(font);
      member_level.setFont(font);
      member_bal.setFont(font);
      button_add.setFont(font);
      trans_title.setFont(font_title);
      trans_member.setFont(font);
      trans_money.setFont(font);
      button_add_trans.setFont(font);
    }
コード例 #7
0
  public void actionPerformed(ActionEvent e) {
    SpinnerNumberModel m = ((SpinnerNumberModel) daysnr.getModel());
    int days = m.getNumber().intValue();
    String location = ((JTextField) loc).getText();
    java.util.List<PointOfInterest> points = parent.textFieldPoints(location);
    if (!points.isEmpty()) {
      double latitude = points.get(0).getLatlon().latitude.getDegrees(),
          longitude = points.get(0).getLatlon().longitude.getDegrees();
      // we want only the firs two decimals
      latitude = ((double) ((long) (latitude * 100))) / 100;
      longitude = ((double) ((long) (latitude * 100))) / 100;
      String APIKey = "65ea00ff33143650113112";
      String address =
          "http://free.worldweatheronline.com/feed/weather.ashx?"
              + "key="
              + APIKey
              + "&num_of_days="
              + days
              + "&q="
              + latitude
              + ","
              + longitude
              + "&format=json&cc=no";
      try {
        URL link = new URL(address);
        URLConnection yc = link.openConnection();
        BufferedReader in = new BufferedReader(new InputStreamReader(yc.getInputStream()));
        Vector<WeatherElements> elem = new Vector<WeatherElements>();
        String jsonFile = in.readLine();
        int i1 = 0, i2 = 0;
        for (int i = 0; i < days; i++) {
          i1 = jsonFile.indexOf("\"date\"", i2) + 9;
          i2 = jsonFile.indexOf("\"", i1);
          String date = jsonFile.substring(i1, i2);
          i2++;

          i1 = jsonFile.indexOf("\"precipMM\"", i2) + 13;
          i2 = jsonFile.indexOf("\"", i1);
          String rain = jsonFile.substring(i1, i2);
          i2++;

          i1 = jsonFile.indexOf("\"tempMaxC\"", i2) + 13;
          i2 = jsonFile.indexOf("\"", i1);
          String tempMax = jsonFile.substring(i1, i2);
          i2++;

          i1 = jsonFile.indexOf("\"tempMinC\"", i2) + 13;
          i2 = jsonFile.indexOf("\"", i1);
          String tempMin = jsonFile.substring(i1, i2);
          i2++;

          i1 = jsonFile.indexOf("\"value\"", i2) + 10;
          i2 = jsonFile.indexOf("\"", i1);
          String weatherStatus = jsonFile.substring(i1, i2);
          i2++;

          i1 = jsonFile.indexOf("\"value\"", i2) + 10;
          i2 = jsonFile.indexOf("\"", i1);
          String imgLink = jsonFile.substring(i1, i2);
          imgLink = imgLink.replace("\\", "");
          i2++;

          i1 = jsonFile.indexOf("\"winddirDegree\"", i2) + 18;
          i2 = jsonFile.indexOf("\"", i1);
          String windDirDegree = jsonFile.substring(i1, i2);
          i2++;

          i1 = jsonFile.indexOf("\"winddirection\"", i2) + 18;
          i2 = jsonFile.indexOf("\"", i1);
          String windDir = jsonFile.substring(i1, i2);
          i2++;

          i1 = jsonFile.indexOf("\"windspeedKmph\"", i2) + 18;
          i2 = jsonFile.indexOf("\"", i1);
          String windSpeed = jsonFile.substring(i1, i2);
          i2++;

          WeatherElements o =
              new WeatherElements(
                  date,
                  rain,
                  tempMax,
                  tempMin,
                  weatherStatus,
                  imgLink,
                  windDirDegree,
                  windDir,
                  windSpeed);
          elem.add(o);
        }

        weatherIcon.setVisible(true);
        dateout.setText(elem.elementAt(0).date);
        weatherIcon.setText("<html><img src=\"" + elem.elementAt(0).imgLink + "\" /></html>");
        weatherstatus.setText("<html><h1>" + elem.elementAt(0).weatherStatus + "</h1></html>");
        temperature.setText(
            "<html>Temperatures:<br />Temp min: "
                + elem.elementAt(0).tempMin
                + "°C<br />Temp max: "
                + elem.elementAt(0).tempMax
                + "°C</html>");
        rain.setText("Rain: " + elem.elementAt(0).rain + " mm");
        wind.setText(
            "<html>Wind: <br />"
                + "<img src=\"http://www.worldweatheronline.com"
                + "/App_Themes/Default/images/wind/"
                + elem.elementAt(0).windDir
                + ".png\" /><br />"
                + "Wind speed: "
                + elem.elementAt(0).windSpeed
                + "Km/h<br />"
                + elem.elementAt(0).windDir
                + "("
                + elem.elementAt(0).windDirDegree
                + "°)</html>");

        buttons.removeAll();
        pageNum.removeAll();
        buttons.updateUI();
        pageNum.updateUI();

        JButton previous = new JButton("Previous");
        previous.setEnabled(false);
        previous.setName("prev");

        JButton next = new JButton("Next");
        next.setName("next");

        if (days == 1) {
          next.setEnabled(false);
        }

        JTextField current = new JTextField("1", 3);
        current.setEditable(false);
        JTextField maxNum = new JTextField("" + elem.size(), 3);
        maxNum.setEditable(false);
        pageNum.add(current);
        pageNum.add(maxNum);

        previous.addActionListener(
            new WeatherButtonsActionListener(
                previous,
                next,
                weatherIcon,
                dateout,
                weatherstatus,
                temperature,
                rain,
                wind,
                elem,
                current));
        next.addActionListener(
            new WeatherButtonsActionListener(
                previous,
                next,
                weatherIcon,
                dateout,
                weatherstatus,
                temperature,
                rain,
                wind,
                elem,
                current));
        buttons.add(next);
        buttons.add(previous);
        JButton genHTML = new JButton("Generate HTML");
        genHTML.addActionListener(new genHTMLWeatherReport(parent, elem));
        buttons.add(genHTML);
      } catch (Exception ex) {
        parent.standardDialogBox("Fetching data error", "Somethnig goes wrong with the connection");
      }
    } else {
      parent.standardDialogBox("Incorrect input", "Input is incorrect!");
    }
  }
コード例 #8
0
  public void actionPerformed(ActionEvent e) {

    if (e.getSource() == remoteAppletPath) {//apparently no events are fired to reach this, maybe "enter" does it
      String path = remoteAppletPath.getText();
      WebExport.setAppletPath(path, true);
      return;
    }

    if (e.getSource() == localAppletPath) {//apparently no events are fired to reach this, maybe "enter" does it
      String path = localAppletPath.getText();
      WebExport.setAppletPath(path, false);
      return;
    }

    //Handle open button action.
    if (e.getSource() == addInstanceButton) {
      //make dialog to get name for instance
      //create an instance with this name.  Each instance is just a container for a string with the Jmol state
      //which contains the full information on the file that is loaded and manipulations done.
      String label = (instanceList.getSelectedIndices().length != 1 ? ""
          : getInstanceName(-1));
      String name = JOptionPane.showInputDialog(
          GT._("Give the occurrence of Jmol a name:"), label);
      if (name == null)
        return;
      //need to get the script...
      String script = viewer.getStateInfo();
      if (script == null) {
        LogPanel.log("Error trying to get Jmol State within pop_in_Jmol.");
      }
      DefaultListModel listModel = (DefaultListModel) instanceList.getModel();
      int width = 300;
      int height = 300;
      if (appletSizeSpinnerH != null) {
        width = ((SpinnerNumberModel) (appletSizeSpinnerW.getModel()))
            .getNumber().intValue();
        height = ((SpinnerNumberModel) (appletSizeSpinnerH.getModel()))
            .getNumber().intValue();
      }
      JmolInstance instance = new JmolInstance(viewer, name, script, width, height);
      if (instance == null) {
        LogPanel
            .log(GT._("Error creating new instance containing script(s) and image."));
      }

      int i;
      for (i = instanceList.getModel().getSize(); --i >= 0;)
        if (getInstanceName(i).equals(instance.name))
          break;
      if (i < 0) {
        i = listModel.getSize();
        listModel.addElement(instance);
        LogPanel.log(GT._("added Instance {0}", instance.name));
      } else {
        listModel.setElementAt(instance, i);
        LogPanel.log(GT._("updated Instance {0}", instance.name));
      }
      instanceList.setSelectedIndex(i);
      syncLists();
      return;
    }

    if (e.getSource() == deleteInstanceButton) {
      DefaultListModel listModel = (DefaultListModel) instanceList.getModel();
      //find out which are selected and remove them.
      int[] todelete = instanceList.getSelectedIndices();
      int nDeleted = 0;
      for (int i = 0; i < todelete.length; i++){
        JmolInstance instance = (JmolInstance) listModel.get(todelete[i]);
        try {
          instance.delete();
        } catch (IOException err) {
          LogPanel.log(err.getMessage());
        }
        listModel.remove(todelete[i] - nDeleted++);
      }
      syncLists();
      return;
    }

    if (e.getSource() == showInstanceButton) {
      DefaultListModel listModel = (DefaultListModel) instanceList.getModel();
      //find out which are selected and remove them.
      int[] list = instanceList.getSelectedIndices();
      if (list.length != 1)
        return;
      JmolInstance instance = (JmolInstance) listModel.get(list[0]);
      viewer.evalStringQuiet(")" + instance.script); //leading paren disabled history
      return;
    }

    if (e.getSource() == saveButton) {
      fc.setDialogTitle(GT._("Select a directory to create or an HTML file to save"));
      int returnVal = fc.showSaveDialog(this);
      if (returnVal != JFileChooser.APPROVE_OPTION)
        return;
      File file = fc.getSelectedFile();
      boolean retVal = true;
      try {
        String path = remoteAppletPath.getText();
        WebExport.setAppletPath(path, true);
        path = localAppletPath.getText();
        WebExport.setAppletPath(path, false);
        String authorName = pageAuthorName.getText();
        WebExport.setWebPageAuthor(authorName);
        retVal = fileWriter(file, instanceList);
      } catch (IOException IOe) {
        LogPanel.log(IOe.getMessage());
      }
      if (!retVal) {
        LogPanel.log(GT._("Call to FileWriter unsuccessful."));
      }
    }
    if (e.getSource() == helpButton){
      HelpDialog webExportHelp = new HelpDialog(WebExport.getFrame(), 
          WebExport.getHtmlResource(this, panelName + "_instructions"));
      webExportHelp.setVisible(true);
      webExportHelp.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
    }
  }
コード例 #9
0
 @Override
 protected String getEnabledValue() {
   return string(((Double) spinner.getValue()).doubleValue());
 }
コード例 #10
0
    public NumberField(NumberOption option) {
      super(option);

      panel = new JPanel(new GridBagLayout());
      this.step = option.getStep();
      Double min = option.getMin();
      Double max = option.getMax();
      Double defl = new Double(option.getDefault());

      // Normalize parameters
      if (min != null && defl.compareTo(min) < 0) {
        defl = min;
      } else if (max != null && defl.compareTo(max) > 0) {
        defl = max;
      }
      if (min != null) {
        sliderMin = (int) (min.doubleValue() / step);
      } else {
        sliderMin = SLIDER_DEFAULT_MIN;
      }
      if (max != null) {
        sliderMax = (int) (max.doubleValue() / step);
      } else {
        sliderMax = SLIDER_DEFAULT_MAX;
      }

      // Create spinner
      SpinnerNumberModel spinnerModel = new SpinnerNumberModel(defl, min, max, new Double(step));
      spinner = new JSpinner(spinnerModel);
      ((JSpinner.DefaultEditor) spinner.getEditor()).getTextField().setColumns(FIELD_WIDTH);

      // Create slider
      slider = new JSlider(sliderMin, sliderMax, sliderIndex(defl));
      slider.setPaintLabels(false);
      slider.setPaintTicks(false);
      slider.setSnapToTicks(false);

      // Add listeners.  The spinner is the master and the slider is
      // the slave.
      spinner.addChangeListener(
          new ChangeListener() {
            @Override
            public void stateChanged(ChangeEvent e) {
              int newIndex = sliderIndex((Double) spinner.getValue());
              if (slider.getValue() != newIndex) {
                slider.setValue(newIndex);
              }
              fireChangeEvent();
            }
          });
      slider.addChangeListener(
          new ChangeListener() {
            @Override
            public void stateChanged(ChangeEvent e) {
              int newIndex = slider.getValue();
              if (newIndex != sliderIndex((Double) spinner.getValue())) {
                spinner.setValue(new Double(newIndex * step));
              }
            }
          });

      // Create enable checkbox
      configureEnableToggle(
          option.isInitiallyEnabled(),
          string(option.getDisabledValue()),
          Arrays.asList((JComponent) spinner, slider));

      // Add to the panel
      panel.add(spinner);
      GridBagConstraints c = new GridBagConstraints();
      c.insets = new Insets(0, 8, 0, 0);
      c.fill = GridBagConstraints.HORIZONTAL;
      c.weightx = 1;
      panel.add(slider, c);
    }