Esempio n. 1
0
 public void setObjectValues() {
   ((JTextField) (fields.get("board"))).setText(sketch.getBoard().getName());
   ((JTextField) (fields.get("core"))).setText(sketch.getCore().getName());
   ((JTextField) (fields.get("compiler"))).setText(sketch.getCompiler().getName());
   ((JTextField) (fields.get("port"))).setText(sketch.getDevice().toString());
   ((JTextField) (fields.get("programmer"))).setText(sketch.getProgrammer());
 }
    public void addValue(long x, double y) {
      // calculate the bar in which this value should go
      int bar = (int) (x / barsize);

      double Y = y;
      if (ysum.containsKey(bar)) {

        double newyvalue = Y + ysum.get(bar);
        long newxvalue = x + xsum.get(bar);

        Integer newcount = count.get(bar) + 1;

        ysum.put(bar, newyvalue);
        xsum.put(bar, newxvalue);
        count.put(bar, newcount);
        Vector<Double> barvalues = values.get(bar);
        barvalues.add(Y);
        values.put(bar, barvalues);

      } else {
        ysum.put(bar, Y);
        xsum.put(bar, x);
        count.put(bar, 1);
        Vector<Double> barvalues = new Vector<Double>();
        barvalues.add(Y);
        values.put(bar, barvalues);
      }
    }
 public XYSeries getXYSeries(String rowname, long factor) {
   XYSeries mydataset = new XYSeries(rowname);
   for (Integer key : ysum.keySet()) {
     Double value = ysum.get(key) / (double) count.get(key);
     Double point = (double) xsum.get(key) / (double) count.get(key);
     mydataset.add(point / factor, value);
   }
   return mydataset;
 }
Esempio n. 4
0
  /**
   * Build a list of installed plugins.
   *
   * @return a list of plugin names and version numbers.
   */
  public static EventList<NameAndVersion> findInstalledPlugins() {
    EventList<NameAndVersion> plugins = new BasicEventList<NameAndVersion>();
    if (!PluginCore.userPluginDir.exists()) return plugins;
    String[] files =
        PluginCore.userPluginDir.list(
            new FilenameFilter() {
              public boolean accept(File dir, String name) {
                return name.endsWith(".jar");
              }
            });

    HashMap<String, PluginDescriptor> urls = new HashMap<String, PluginDescriptor>();
    Collection<PluginDescriptor> descriptors =
        PluginCore.getManager().getRegistry().getPluginDescriptors();
    for (PluginDescriptor desc : descriptors) {
      if ((desc.getPluginClassName() == null)
          || !desc.getPluginClassName().equals("net.sf.jabref.plugin.core.JabRefPlugin")) {
        urls.put(desc.getId(), desc);
      }
    }

    for (String file1 : files) {
      File file = new File(PluginCore.userPluginDir, file1);
      String[] nav = getNameAndVersion(file);
      if (nav != null) {
        VersionNumber vn = nav[1] != null ? new VersionNumber(nav[1]) : null;
        NameAndVersion nameAndVersion = new NameAndVersion(nav[0], vn, true, file);
        for (Iterator<String> it = urls.keySet().iterator(); it.hasNext(); ) {
          String loc = it.next();
          if (loc.contains(nav[0])) {
            PluginDescriptor desc = urls.get(loc);
            // System.out.println("Accounted for: "+desc.getId()+" "+desc.getVersion().toString());
            if (!PluginCore.getManager().isPluginEnabled(urls.get(loc)))
              nameAndVersion.setStatus(BAD);
            else nameAndVersion.setStatus(LOADED);
            it.remove();
          }
        }
        plugins.add(nameAndVersion);
      }
    }

    for (String url : urls.keySet()) {
      PluginDescriptor desc = urls.get(url);
      File location = new File(desc.getLocation().getFile());
      if (location.getPath().contains(PluginCore.userPluginDir.getPath()))
        continue; // This must be a loaded user dir plugin that's been deleted.
      // System.out.println("File: "+desc.getLocation().getFile());
      NameAndVersion nameAndVersion =
          new NameAndVersion(
              desc.getId(), new VersionNumber(desc.getVersion().toString()), false, location);
      if (!PluginCore.getManager().isPluginEnabled(urls.get(url))) nameAndVersion.setStatus(BAD);
      else nameAndVersion.setStatus(LOADED);
      plugins.add(nameAndVersion);
    }
    return plugins;
  }
Esempio n. 5
0
 /** Redraw ell shapes currently on the Canvas. */
 private void redraw() {
   erase();
   for (Iterator i = objects.iterator(); i.hasNext(); ) {
     shapes.get(i.next()).draw(graphic);
   }
   canvas.repaint();
 }
    /** Displays the labels and the values for the panel. */
    protected void displayPnlFields(HashMap hmPnl) {
      if (hmPnl == null || hmPnl.isEmpty()) return;

      Iterator keySetItr = hmPnl.keySet().iterator();
      String strLabel = "";
      String strValue = "";

      // if the file is empty, then create an empty set of textfields.
      if (hmPnl == null || hmPnl.isEmpty()) {
        displayNewTxf("", "");
        return;
      }

      Container container = getParent();
      if (container != null) container.setVisible(false);
      try {
        // Get each set of label and value, and display them.
        while (keySetItr.hasNext()) {
          strLabel = (String) keySetItr.next();
          strValue = (String) hmPnl.get(strLabel);

          displayNewTxf(strLabel, strValue);
        }

        if (container != null) container.setVisible(true);
        revalidate();
        repaint();
      } catch (Exception e) {
        Messages.writeStackTrace(e);
        // e.printStackTrace();
        Messages.postDebug(e.toString());
      }
    }
Esempio n. 7
0
  public void updateConnectionStatus(boolean connected) {
    if (connected == true) {
      headerPanel.setLogoutText();
      loginMenuItem.setText("Logout");
    } else {
      headerPanel.setLoginText();
      loginMenuItem.setText("Login...");
    }
    mainCommandPanel.updateConnectionStatus(connected);
    propertiePanel.updateConnectionStatus(connected);
    cmdConsole.updateConnectionStatus(connected);
    Iterator iterator = plugins.iterator();
    PluginPanel updatePluginPanel = null;
    while (iterator.hasNext()) {
      updatePluginPanel = (PluginPanel) iterator.next();
      updatePluginPanel.updateConnectionStatus(connected);
    }

    if (connected == true) {
      int selected = tabbedPane.getSelectedIndex();
      if (selected >= 2) {
        ((PluginPanel) pluginPanelMap.get("" + selected)).activated();
      }
    }
  }
Esempio n. 8
0
 // Calculate the number of correct answers
 public int calCorrectAnswer() {
   int questionNumber = 10;
   int count = 0;
   for (int questionID = 0; questionID < questionNumber; questionID++)
     if (quizCorrectAnswers[questionID][1].equals(map.get(questionID))) count++;
   return count;
 }
Esempio n. 9
0
 /** Redraw ell shapes currently on the Canvas. */
 private void redraw() {
   erase();
   for (Object shape : objects) {
     shapes.get(shape).draw(graphic);
   }
   canvas.repaint();
 }
 @SuppressWarnings("UnusedDeclaration")
 @Nullable
 public DebuggerSession getDebugSession(final ProcessHandler processHandler) {
   synchronized (mySessions) {
     return mySessions.get(processHandler);
   }
 }
Esempio n. 11
0
 private boolean hasChange(DataGrid grid, HashMap<Guid, RelationOrder> relationOrders) {
   if (grid.get_BindingSource() == null || grid.getRowCount() != relationOrders.size()) {
     return true;
   } else {
     int openOrderSummaryColumn = -1;
     for (int column = 0; column < grid.getColumnModel().getColumnCount(); column++) {
       if (grid.getColumnModel()
           .getColumn(column)
           .getIdentifier()
           .equals(OutstandingOrderColKey.OpenOrderSummary)) {
         openOrderSummaryColumn = column;
         break;
       }
     }
     for (int row = 0; row < grid.getRowCount(); row++) {
       RelationOrder realtionOrder = (RelationOrder) grid.getObject(row);
       Guid openOrderId = realtionOrder.get_OpenOrderId();
       RelationOrder realtionOrder2 = relationOrders.get(openOrderId);
       if (realtionOrder2 == null
           || realtionOrder2.getAvailableCloseLot().compareTo(realtionOrder.getAvailableCloseLot())
               != 0
           || (openOrderSummaryColumn > -1
               && !realtionOrder2
                   .get_OpenOrderSummary()
                   .equals(grid.getValueAt(row, openOrderSummaryColumn).toString()))) {
         return true;
       }
     }
   }
   return false;
 }
 @Override
 public DebugProcessImpl getDebugProcess(final ProcessHandler processHandler) {
   synchronized (mySessions) {
     DebuggerSession session = mySessions.get(processHandler);
     return session != null ? session.getProcess() : null;
   }
 }
Esempio n. 13
0
  /**
   * Returns the specified image as icon.
   *
   * @param name name of icon
   * @return icon
   */
  public static ImageIcon icon(final String name) {
    ImageIcon ii = ICONS.get(name);
    if (ii != null) return ii;

    Image img;
    if (GUIConstants.scale > 1) {
      // choose large image or none
      final URL url =
          GUIConstants.large() ? BaseXImages.class.getResource("/img/" + name + "_32.png") : null;

      if (url == null) {
        // resize low-res image if no hi-res image exists
        img = get(url(name));
        final int w = (int) (img.getWidth(null) * GUIConstants.scale);
        final int h = (int) (img.getHeight(null) * GUIConstants.scale);
        final BufferedImage tmp = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
        final Graphics2D g2 = tmp.createGraphics();
        g2.setRenderingHint(
            RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
        g2.drawImage(img, 0, 0, w, h, null);
        g2.dispose();
        img = tmp;
      } else {
        img = get(url);
      }
    } else {
      img = get(name);
    }
    ii = new ImageIcon(img);
    ICONS.put(name, ii);
    return ii;
  }
Esempio n. 14
0
  public void save() {
    for (String key : fields.keySet()) {
      JComponent comp = fields.get(key);

      if (comp instanceof JTextField) {
        JTextField c = (JTextField) comp;

        if (c.getText().trim().equals("")) {
          sketch.configFile.unset(key);
        } else {
          sketch.configFile.set(key, c.getText());
        }
      } else if (comp instanceof JTextArea) {
        JTextArea c = (JTextArea) comp;

        if (c.getText().trim().equals("")) {
          sketch.configFile.unset(key);
        } else {
          sketch.configFile.set(key, c.getText());
        }
      }
    }

    sketch.saveConfig();
  }
Esempio n. 15
0
  /**
   * Returns an icon for the specified file.
   *
   * @param file file reference
   * @return icon
   */
  public static Icon file(final IOFile file) {
    if (file == null) return UNKNOWN;

    // fallback code for displaying icons
    final String path = file.path();
    final MediaType type = MediaType.get(path);
    if (type.isXML()) return XML;
    if (type.isXQuery()) return XQUERY;
    if (path.contains(IO.BASEXSUFFIX)) return BASEX;

    // only works with standard dpi (https://bugs.openjdk.java.net/browse/JDK-6817929)
    if (Prop.WIN && !GUIConstants.large()) {
      // retrieve system icons (only supported on Windows)
      final int p = path.lastIndexOf(path, '.');
      final String suffix = p == -1 ? null : path.substring(p + 1);
      Icon icon = null;
      if (suffix != null) icon = FILES.get(suffix);
      if (icon == null) {
        icon = FS.getSystemIcon(file.file());
        if (suffix != null) FILES.put(suffix, icon);
      }
      return icon;
    }
    // default icon chooser
    return type.isText() ? TEXT : UNKNOWN;
  }
Esempio n. 16
0
 // Returns the counts from the mapping, in the same order as the labels
 double[] amounts(HashMap map, String[] revisedLabels) {
   // Extract amounts
   double[] amounts = new double[map.size()];
   for (int i = 0; i < amounts.length; i++)
     amounts[i] = ((Double) (map.get(revisedLabels[i]))).doubleValue();
   return amounts;
 }
Esempio n. 17
0
  private void updateEditorView() {
    editorPane.setText("");
    numParameters = 0;
    try {
      java.util.List elements = editableTemplate.getPrintfElements();
      for (Iterator it = elements.iterator(); it.hasNext(); ) {
        PrintfUtil.PrintfElement el = (PrintfUtil.PrintfElement) it.next();
        if (el.getFormat().equals(PrintfUtil.PrintfElement.FORMAT_NONE)) {
          appendText(el.getElement(), PLAIN_ATTR);
        } else {
          insertParameter(
              (ConfigParamDescr) paramKeys.get(el.getElement()),
              el.getFormat(),
              editorPane.getDocument().getLength());
        }
      }
    } catch (Exception ex) {
      JOptionPane.showMessageDialog(
          this,
          "Invalid Format: " + ex.getMessage(),
          "Invalid Printf Format",
          JOptionPane.ERROR_MESSAGE);

      selectedPane = 1;
      printfTabPane.setSelectedIndex(selectedPane);
      updatePane(selectedPane);
    }
  }
Esempio n. 18
0
 public void setIcon(String command, ImageIcon icon) {
   JButton b = (JButton) buttons.get(command);
   if (b != null) {
     b.setIcon(icon);
     b.revalidate();
     setButtonsSize();
   }
 }
  // ===================================================
  // ObjHtmlPanel.Listener
  public void linkSelected(java.net.URL href, String target) {
    String url = href.toExternalForm();
    int slash = url.lastIndexOf('/');
    if (slash > 0) url = url.substring(slash + 1);

    Job t = actionMap.get(url);
    fapp.guiRun().run(this, new Job(t.getPermissions(), t.getCBRunnable()));
  }
  // ===================================================
  // ObjHtmlPanel.Listener
  public void linkSelected(java.net.URL href, String target) {
    String url = href.toExternalForm();
    int slash = url.lastIndexOf('/');
    if (slash > 0) url = url.substring(slash + 1);

    Job job = actionMap.get(url);
    if (job != null) app.guiRun().run(this, job);
  }
Esempio n. 21
0
 protected void updateRoi() {
   // System.out.println("image:"+currentImage.getTitle()+ " slice:"+currentImage.getSlice());
   Roi r = currentROIs.get(currentImage.getSlice());
   if (r != null) {
     currentImage.setRoi(r);
   } else {
     currentImage.killRoi();
   }
   currentImage.updateAndDraw();
 }
 private void restoreOriginalFontDefaults(UIDefaults defaults) {
   UIManager.LookAndFeelInfo lf = getCurrentLookAndFeel();
   HashMap<String, Object> lfDefaults = myStoredDefaults.get(lf);
   if (lfDefaults != null) {
     for (String resource : ourPatchableFontResources) {
       defaults.put(resource, lfDefaults.get(resource));
     }
   }
   JBUI.setScaleFactor(JBUI.Fonts.label().getSize() / 12f);
 }
Esempio n. 23
0
 public void setShowNames(boolean b) {
   if (shownames == b) return;
   shownames = b;
   Iterator it = buttons.keySet().iterator();
   while (it.hasNext()) {
     String command = (String) it.next();
     JButton button = (JButton) buttons.get(command);
     button.setText((shownames) ? command : "");
     button.setToolTipText((!shownames) ? command : "");
   }
   setButtonsSize();
 }
Esempio n. 24
0
 // Takes objects and produces an object->count mapping
 HashMap convertIntoAmountsAndLabels(Object[] objs) {
   // Total the amounts
   HashMap map = new HashMap();
   for (int i = 0; i < objs.length; i++) {
     String label = "null";
     if (objs[i] != null) label = objs[i].toString();
     if (map.containsKey(label))
       map.put(label, new Double(((Double) (map.get(label))).doubleValue() + 1));
     else map.put(label, new Double(1));
   }
   return map;
 }
Esempio n. 25
0
  private JButton createButton(final Commontags commontag) {

    if (mapButtons.containsKey(commontag)) {
      OPDE.debug("shortcut");
      return mapButtons.get(commontag);
    }

    final JButton jButton =
        new JButton(
            commontag.getText(),
            editmode ? SYSConst.icon16tagPurpleDelete2 : SYSConst.icon16tagPurple);
    jButton.setFont(SYSConst.ARIAL12);
    jButton.setBorder(new RoundedBorder(10));
    jButton.setHorizontalTextPosition(SwingConstants.LEADING);
    jButton.setForeground(SYSConst.purple1[SYSConst.dark3]);

    if (editmode) {

      jButton.addActionListener(
          e -> {
            listSelectedTags.remove(commontag);
            mapButtons.remove(commontag);
            SwingUtilities.invokeLater(
                () -> {
                  removeAll();

                  add(txtTags);
                  if (btnPickTags != null) {
                    add(btnPickTags);
                  }
                  int tagnum = 1;

                  for (JButton btn : mapButtons.values()) {
                    if (tagnum % MAXLINE == 0) {
                      add(btn, RiverLayout.LINE_BREAK);
                    } else {
                      add(btn, RiverLayout.LEFT);
                    }
                    tagnum++;
                  }

                  remove(jButton);
                  revalidate();
                  repaint();
                  notifyListeners(commontag);
                });
          });
    }
    mapButtons.put(commontag, jButton);

    return jButton;
  }
Esempio n. 26
0
  private void addMenuToTray() {
    HashMap categories = new HashMap();

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

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

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

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

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

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

    this.trayIcon.addSeparator();

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

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

    // exit
    menu = new JMenuItem(tr("exit"));
    menu.setName("exit");
    menu.addActionListener(this);
    this.trayIcon.add(menu);
  }
Esempio n. 27
0
  private void cmbTagsActionPerformed(ActionEvent e) {

    if (!editmode) return;

    if (txtTags.getText().isEmpty()) return;
    if (txtTags.getText().length() > 100) return;

    final String enteredText = SYSTools.tidy(txtTags.getText()).toLowerCase();

    if (!addNewTags && !mapAllTags.containsKey(enteredText)) return;

    if (!mapAllTags.containsKey(enteredText)) {
      Commontags myNewCommontag = new Commontags(SYSTools.tidy(enteredText));
      mapAllTags.put(enteredText, myNewCommontag);
      ac.uninstallListeners();
      ac = new AutoCompletion(txtTags, mapAllTags.keySet().toArray(new String[] {}));
      ac.setStrict(false);
      ac.setStrictCompletion(false);
    }

    if (!listSelectedTags.contains(mapAllTags.get(enteredText))) {
      listSelectedTags.add(mapAllTags.get(enteredText));

      SwingUtilities.invokeLater(
          () -> {
            if (listSelectedTags.size() % MAXLINE == 0) {
              add(createButton(mapAllTags.get(enteredText)), RiverLayout.LINE_BREAK);
            } else {
              add(createButton(mapAllTags.get(enteredText)), RiverLayout.LEFT);
            }

            txtTags.setText("");
            revalidate();
            repaint();
            notifyListeners(mapAllTags.get(enteredText));
          });
    }
  }
  private void applyChanges() {
    boolean changedFieldSet = false; // Watch if we need to rebuild entry editors

    // First remove the mappings for fields that have been deleted.
    // If these were re-added, they will be added below, so it doesn't
    // cause any harm to remove them here.
    for (Iterator<String> i = removedFields.iterator(); i.hasNext(); ) {
      String fieldName = i.next();
      metaData.remove(Globals.SELECTOR_META_PREFIX + fieldName);
      changedFieldSet = true;
    }

    // Cycle through all fields that we have created listmodels for:
    loop:
    for (Iterator<String> i = wordListModels.keySet().iterator(); i.hasNext(); ) {
      // For each field name, store the values:
      String fieldName = i.next();
      if ((fieldName == null) || FIELD_FIRST_LINE.equals(fieldName)) continue loop;
      DefaultListModel lm = wordListModels.get(fieldName);
      int start = 0;
      // Avoid storing the <new word> marker if it is there:
      if (lm.size() > 0)
        while ((start < lm.size()) && (lm.get(start)).equals(WORD_FIRSTLINE_TEXT)) start++;
      Vector<String> data = metaData.getData(Globals.SELECTOR_META_PREFIX + fieldName);
      boolean newField = false;
      if (data == null) {
        newField = true;
        data = new Vector<String>();
        changedFieldSet = true;

      } else data.clear();
      for (int wrd = start; wrd < lm.size(); wrd++) {
        String word = (String) lm.get(wrd);
        data.add(word);
      }
      if (newField) metaData.putData(Globals.SELECTOR_META_PREFIX + fieldName, data);
    }

    // System.out.println("TODO: remove metadata for removed selector field.");
    panel.markNonUndoableBaseChanged();

    // Update all selectors in the current BasePanel.
    if (changedFieldSet) {
      panel.rebuildAllEntryEditors();
    } else {
      panel.updateAllContentSelectors();
    }
    panel.addContentSelectorValuesToAutoCompleters();
  }
Esempio n. 29
0
  public void setSelected(Function f) {
    try {

      ACTIVE_FUNCTION = f;
      if (f != selectedFunction) {
        // Deselection.
        if (selectedFunction != null && selectedFunction == templateFunc) {
          for (int i = 0; i < input.length; i++) {
            input[i].setBackground(NORMAL_COLOR);
          }
        } else if (selectedFunction != null) {
          FunctionLabel label = map.get(selectedFunction);
          if (label != null) label.setSelected(false);
        }
        selectedFunction = f;

        // Selection of input fields.
        if (selectedFunction != null && selectedFunction == templateFunc) {
          for (int i = 0; i < input.length; i++) {
            input[i].setBackground(SELECTED_COLOR);
          }

          updateReferences(selectedFunction);
        }
      }

      // Needed for picking. The caret might not be active,
      if (selectedFunction != null && selectedFunction != templateFunc) {
        FunctionLabel selectedLabel = map.get(selectedFunction);
        updateReferences(selectedFunction);
        selectedLabel.setSelected(true);
      }
    } catch (IllegalExpressionException e) {

    }
  }
  /**
   * Construct a "simplified name" based on the subject DN from the certificate. The purpose is to
   * have something shorter to display in the list. The name used is one of the following DN parts,
   * if available, otherwise the complete DN: 'CN', 'OU' or else 'O'.
   *
   * @param cert to read subject DN from
   * @return the simplified name
   */
  private static String getSimplifiedName(X509Certificate cert) {
    final HashMap<String, String> parts = new HashMap<String, String>();
    try {
      for (Rdn name : new LdapName(cert.getSubjectX500Principal().getName()).getRdns()) {
        if (name.getType() != null && name.getValue() != null) {
          parts.put(name.getType(), name.getValue().toString());
        }
      }
    } catch (InvalidNameException ignored) // NOPMD
    {
    }

    String result = parts.get("CN");
    if (result == null) {
      result = parts.get("OU");
    }
    if (result == null) {
      result = parts.get("O");
    }
    if (result == null) {
      result = cert.getSubjectX500Principal().getName();
    }
    return result;
  }