Ejemplo n.º 1
0
    public void actionPerformed(ActionEvent e) {
      JTextField tf = getTextField();
      final String text = tf.getText();
      final int caretIndex = tf.getCaretPosition();
      String pre = text.substring(0, caretIndex);
      java.util.List<TreeNode> nodes = null; // m_root.search(pre);
      // Collections.sort(nodes);
      if (nodes.isEmpty()) {
        return;
      }

      JPopupMenu jp = new JPopupMenu("options");

      JMenuItem lastItem = null;
      for (TreeNode node : nodes) {
        String nodeName = node.toString();
        String insertion = nodeName.substring(leaf(pre, ".").length());
        lastItem = createInsertAction(nodeName, caretIndex, insertion);
        jp.add(lastItem);
      }
      if (nodes.size() == 0) {
        return;
      }
      if (nodes.size() == 1) {
        lastItem.getAction().actionPerformed(null);
      } else {
        Point pos = tf.getCaret().getMagicCaretPosition();
        pos = pos != null ? pos : new Point(2, 2);
        jp.show(tf, pos.x, pos.y);
      }
    }
 private String getToolTipText(java.util.List<Modification> mods, int seqLength) {
   StringBuilder tip = new StringBuilder();
   if (mods != null && !mods.isEmpty()) {
     tip.append("<html>");
     for (Modification mod : mods) {
       tip.append("<p>");
       tip.append("<b><font size=\"3\" color=\"red\">");
       tip.append(mod.getAccession());
       tip.append("</font></b><br>");
       tip.append("<b>Name</b>:");
       tip.append(mod.getName());
       tip.append("<br>");
       tip.append("<b>Location</b>:");
       int location = mod.getLocation();
       if (location == 0) {
         tip.append("N-Terminal");
       } else if (location == seqLength) {
         tip.append("C-Terminal");
       } else {
         tip.append(location);
       }
       tip.append("<br>");
       java.util.List<Double> avgs = mod.getAvgMassDeltas();
       if (avgs != null) {
         for (Double avg : avgs) {
           tip.append("<b>Average Mass Delta</b>:");
           tip.append(avg);
           tip.append("<br>");
         }
       }
       java.util.List<Double> monos = mod.getMonoMassDeltas();
       if (monos != null) {
         for (Double mono : monos) {
           tip.append("<b>Mono Mass Delta</b>:");
           tip.append(mono);
           tip.append("<br>");
         }
       }
       tip.append("</p>");
       tip.append("<br>");
     }
     tip.append("</html>");
   }
   return tip.toString();
 }
  private void showProductPanel(String id) {
    ProductInfoExt product = m_productsset.get(id);
    if (product == null) {
      if (m_productsset.containsKey(id)) {
      } else {
        try {
          java.util.List<ProductInfoExt> products = m_dlSales.getProductComments(id);

          if (products.isEmpty()) {
            m_productsset.put(id, null);
          } else {
            product = m_dlSales.getProductInfo(id);
            m_productsset.put(id, product);

            JCatalogTab jcurrTab = new JCatalogTab();
            jcurrTab.applyComponentOrientation(getComponentOrientation());
            m_jProducts.add(jcurrTab, "PRODUCT." + id);

            // Add products
            for (ProductInfoExt prod : products) {
              jcurrTab.addButton(
                  new ImageIcon(tnbbutton.getThumbNailText(prod.getImage(), getProductLabel(prod))),
                  new SelectedAction(prod),
                  prod.getTextTip(),
                  "");
            }
            CardLayout cl = (CardLayout) (m_jProducts.getLayout());
            cl.show(m_jProducts, "PRODUCT." + id);
          }
        } catch (BasicException eb) {
          m_productsset.put(id, null);
        }
      }
    } else {

      CardLayout cl = (CardLayout) (m_jProducts.getLayout());
      cl.show(m_jProducts, "PRODUCT." + id);
    }
  }
 public void setSpinnerSemester(JSpinner spinnerSemester) {
   this.spinnerSemester = spinnerSemester;
   java.util.List<Semester> semesterList = svmContext.getSvmModel().getSemestersAll();
   if (semesterList.isEmpty()) {
     // keine Semester erfasst
     SpinnerModel spinnerModel = new SpinnerListModel(new String[] {""});
     spinnerSemester.setModel(spinnerModel);
     spinnerSemester.setEnabled(false);
     return;
   }
   Semester[] semesters = semesterList.toArray(new Semester[semesterList.size()]);
   SpinnerModel spinnerModelSemester = new SpinnerListModel(semesters);
   spinnerSemester.setModel(spinnerModelSemester);
   spinnerSemester.addChangeListener(
       new ChangeListener() {
         @Override
         public void stateChanged(ChangeEvent e) {
           onSemesterSelected();
         }
       });
   // Model initialisieren
   kurseSemesterwahlModel.setSemester(
       kurseSemesterwahlModel.getInitSemester(svmContext.getSvmModel()));
 }
Ejemplo n.º 5
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!");
    }
  }