static { HashMap<String, Integer> m = new HashMap<String, Integer>(); m.put("miter", BasicStroke.JOIN_MITER); m.put("round", BasicStroke.JOIN_ROUND); m.put("bevel", BasicStroke.JOIN_BEVEL); SVG_STROKE_LINEJOINS = Collections.unmodifiableMap(m); }
static { HashMap<String, TextAnchor> m = new HashMap<String, TextAnchor>(); m.put("start", TextAnchor.START); m.put("middle", TextAnchor.MIDDLE); m.put("end", TextAnchor.END); SVG_TEXT_ANCHORS = Collections.unmodifiableMap(m); }
static { HashMap<String, TextAlign> m = new HashMap<String, TextAlign>(); m.put("start", TextAlign.START); m.put("center", TextAlign.CENTER); m.put("end", TextAlign.END); SVG_TEXT_ALIGNS = Collections.unmodifiableMap(m); }
private HashMap<Guid, RelationOrder> getEditOutstandingOrders( BuySellType buySellType, Order mapOrder) { HashMap<Guid, RelationOrder> editOutstandingOrders; if (buySellType == BuySellType.Both) { editOutstandingOrders = this._outstandingOrders; for (Iterator<RelationOrder> iterator = this._outstandingOrders.values().iterator(); iterator.hasNext(); ) { RelationOrder relationOrder = iterator.next(); if (mapOrder != null) { relationOrder.set_IsSelected(true); } } } else { editOutstandingOrders = new HashMap<Guid, RelationOrder>(); for (Iterator<RelationOrder> iterator = this._outstandingOrders.values().iterator(); iterator.hasNext(); ) { RelationOrder relationOrder = iterator.next(); if (mapOrder != null) { relationOrder.set_IsSelected(true); } if (buySellType == BuySellType.Buy && relationOrder.get_IsBuy()) { editOutstandingOrders.put(relationOrder.get_OpenOrderId(), relationOrder); } else if (buySellType == BuySellType.Sell && !relationOrder.get_IsBuy()) { editOutstandingOrders.put(relationOrder.get_OpenOrderId(), relationOrder); } } } return editOutstandingOrders; }
static { HashMap<String, Integer> m = new HashMap<String, Integer>(); m.put("butt", BasicStroke.CAP_BUTT); m.put("round", BasicStroke.CAP_ROUND); m.put("square", BasicStroke.CAP_SQUARE); SVG_STROKE_LINECAPS = Collections.unmodifiableMap(m); }
static { HashMap<String, Double> m = new HashMap<String, Double>(); m.put("xx-small", 6.944444); m.put("x-small", 8.3333333); m.put("small", 10d); m.put("medium", 12d); m.put("large", 14.4); m.put("x-large", 17.28); m.put("xx-large", 20.736); SVG_ABSOLUTE_FONT_SIZES = Collections.unmodifiableMap(m); }
// 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; }
/* initializes the HashMap containing the numbers/flag icons */ private void initHash() { gfxHash = new HashMap<String, ImageIcon>(); gfxHash.put("gfx1", loadImageIcon("gfx/gfx1.gif")); gfxHash.put("gfx2", loadImageIcon("gfx/gfx2.gif")); gfxHash.put("gfx3", loadImageIcon("gfx/gfx3.gif")); gfxHash.put("gfx4", loadImageIcon("gfx/gfx4.gif")); gfxHash.put("gfx5", loadImageIcon("gfx/gfx5.gif")); gfxHash.put("gfx6", loadImageIcon("gfx/gfx6.gif")); gfxHash.put("gfx7", loadImageIcon("gfx/gfx7.gif")); gfxHash.put("gfx8", loadImageIcon("gfx/gfx8.gif")); gfxHash.put("gfxFlag", loadImageIcon("gfx/gfxFlag.gif")); }
// Handle button clicks, specifically the next button public void actionPerformed(ActionEvent e) { if (btnext.getText().equals("Next")) { if (quizAnswerID < 9) { map.put(quizAnswerID, getSelection()); quizAnswerID++; readQuestionAnswer(quizAnswerID); } else { map.put(quizAnswerID, getSelection()); btnext.setText("Show results"); } } else if (btnext.getText().equals("Show results")) { blankScreen(); } else if (btnext.getText().equals("Try again")) { reset(); } }
public void actionPerformed(ActionEvent e) { BasePanel panel = frame.basePanel(); if (panel == null) { return; } // idea: sort elements according to value stored in hash, keep // everything not inside hash/mainTable as it was final HashMap<String, Integer> map = new HashMap<String, Integer>(); // first element (#) not inside tableRows for (int i = 1; i < panel.mainTable.getColumnCount(); i++) { String name = panel.mainTable.getColumnName(i); if (name != null && name.length() != 0) { map.put(name.toLowerCase(), i); } } Collections.sort( tableRows, new Comparator<TableRow>() { public int compare(TableRow o1, TableRow o2) { Integer n1 = map.get(o1.name); Integer n2 = map.get(o2.name); if (n1 == null || n2 == null) { return 0; } return n1.compareTo(n2); } }); colSetup.revalidate(); colSetup.repaint(); tableChanged = true; }
/** * 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; }
// check if sudo password is correct (so sudo can be used in all other scripts, even without // password, lasts for 5 minutes) private void doSudoCmd() { String pass = passwordField.getText(); File file = null; try { // write file in /tmp file = new File("/tmp/cmd_sudo.sh"); // ""c:/temp/run.bat"" FileOutputStream fos = new FileOutputStream(file); fos.write("echo $password | sudo -S ls\nexit $?".getBytes()); // "echo $password > pipo.txt" fos.close(); // execute HashMap vars = new HashMap(); vars.put("password", pass); List oses = new ArrayList(); oses.add( new OsConstraint( "unix", null, null, null)); // "windows",System.getProperty("os.name"),System.getProperty("os.version"),System.getProperty("os.arch"))); ArrayList plist = new ArrayList(); ParsableFile pf = new ParsableFile(file.getAbsolutePath(), null, null, oses); plist.add(pf); ScriptParser sp = new ScriptParser(plist, new VariableSubstitutor(vars)); sp.parseFiles(); ArrayList elist = new ArrayList(); ExecutableFile ef = new ExecutableFile( file.getAbsolutePath(), ExecutableFile.POSTINSTALL, ExecutableFile.ABORT, oses, false); elist.add(ef); FileExecutor fe = new FileExecutor(elist); int retval = fe.executeFiles(ExecutableFile.POSTINSTALL, this); if (retval == 0) { idata.setVariable("password", pass); isValid = true; } // else is already showing dialog // { // JOptionPane.showMessageDialog(this, "Cannot execute 'sudo' cmd, check your password", // "Error", JOptionPane.ERROR_MESSAGE); // } } catch (Exception e) { // JOptionPane.showMessageDialog(this, "Cannot execute 'sudo' cmd, check your password", // "Error", JOptionPane.ERROR_MESSAGE); e.printStackTrace(); isValid = false; } try { if (file != null && file.exists()) file.delete(); // you don't want the file with password tobe arround, in case of error } catch (Exception e) { // ignore } }
/** * 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; }
private static Map<AbstractVcs, Configurable> revertMap( final Map<Configurable, AbstractVcs> confs) { final HashMap<AbstractVcs, Configurable> result = new HashMap<>(); for (Configurable configurable : confs.keySet()) { result.put(confs.get(configurable), configurable); } return result; }
/** * 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; }
void addTextBox(String name, String currentValue) { configGridLayout.setRows(configGridLayout.getRows() + 1); addConfigLabel(name); JTextField textField = new JTextField(); textField.setText(currentValue); componentByName.put(name, textField); configPanel.add(textField); }
void addBooleanComponent(String name, boolean currentValue) { configGridLayout.setRows(configGridLayout.getRows() + 1); addConfigLabel(name); JCheckBox checkBox = new JCheckBox(); checkBox.setSelected(currentValue); componentByName.put(name, checkBox); configPanel.add(checkBox); }
void addTextField(JPanel panel, String key, String label) { JLabel lab = new JLabel(label); lab.setAlignmentX(LEFT_ALIGNMENT); panel.add(lab); JTextField field = new JTextField(); field.setText(sketch.configFile.get(key)); field.setMaximumSize(new Dimension(Integer.MAX_VALUE, field.getPreferredSize().height)); fields.put(key, field); panel.add(field); }
private void storeOriginalFontDefaults(UIDefaults defaults) { UIManager.LookAndFeelInfo lf = getCurrentLookAndFeel(); HashMap<String, Object> lfDefaults = myStoredDefaults.get(lf); if (lfDefaults == null) { lfDefaults = new HashMap<String, Object>(); for (String resource : ourPatchableFontResources) { lfDefaults.put(resource, defaults.get(resource)); } myStoredDefaults.put(lf, lfDefaults); } }
public void actionPerformed(ActionEvent e) { HashMap data = getData(tree, selected_node); if (data != null) { } else { clearTable(); data = new HashMap(); data.put("Add Key", "Add Value"); } populateTable(data); getContentPane().add(tablePanel, BorderLayout.SOUTH); validate(); }
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); } }
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; }
void addTextArea(JPanel panel, String key, String label) { JLabel lab = new JLabel(label); lab.setAlignmentX(LEFT_ALIGNMENT); panel.add(lab); JTextArea field = new JTextArea(); field.setText(sketch.configFile.get(key)); field.setLineWrap(true); field.setWrapStyleWord(true); fields.put(key, field); JScrollPane scroll = new JScrollPane(field); scroll.setAlignmentX(0.0f); panel.add(scroll); }
private Shape getTextShape() { if (cachedTextShape == null) { String text = getText(); if (text == null || text.length() == 0) { text = " "; } FontRenderContext frc = getFontRenderContext(); HashMap<TextAttribute, Object> textAttributes = new HashMap<TextAttribute, Object>(); textAttributes.put(TextAttribute.FONT, getFont()); if (FONT_UNDERLINE.get(this)) { textAttributes.put(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON); } TextLayout textLayout = new TextLayout(text, textAttributes, frc); AffineTransform tx = new AffineTransform(); tx.translate(coordinates[0].x, coordinates[0].y); switch (TEXT_ANCHOR.get(this)) { case END: tx.translate(-textLayout.getAdvance(), 0); break; case MIDDLE: tx.translate(-textLayout.getAdvance() / 2d, 0); break; case START: break; } tx.rotate(rotates[0]); /* if (TRANSFORM.get(this) != null) { tx.preConcatenate(TRANSFORM.get(this)); }*/ cachedTextShape = tx.createTransformedShape(textLayout.getOutline(tx)); cachedTextShape = textLayout.getOutline(tx); } return cachedTextShape; }
private void addCreationButtonsTo(JToolBar tb, final DrawingEditor editor) { // AttributeKeys for the entitie sets HashMap<AttributeKey, Object> attributes; ResourceBundleUtil drawLabels = ResourceBundleUtil.getBundle("org.jhotdraw.draw.Labels"); ButtonFactory.addSelectionToolTo( tb, editor, ButtonFactory.createDrawingActions(editor), createSelectionActions(editor)); tb.addSeparator(); attributes = new HashMap<AttributeKey, Object>(); attributes.put(AttributeKeys.FILL_COLOR, Color.white); attributes.put(AttributeKeys.STROKE_COLOR, Color.black); ButtonFactory.addToolTo( tb, editor, new CreationTool(new SVGRectFigure(), attributes), "edit.createRectangle", drawLabels); ButtonFactory.addToolTo( tb, editor, new CreationTool(new SVGEllipseFigure(), attributes), "edit.createEllipse", drawLabels); ButtonFactory.addToolTo( tb, editor, new PathTool(new SVGPathFigure(), new SVGBezierFigure(true), attributes), "edit.createPolygon", drawLabels); attributes = new HashMap<AttributeKey, Object>(); attributes.put(AttributeKeys.FILL_COLOR, null); attributes.put(AttributeKeys.STROKE_COLOR, Color.black); ButtonFactory.addToolTo( tb, editor, new CreationTool(new SVGPathFigure(), attributes), "edit.createLine", drawLabels); ButtonFactory.addToolTo( tb, editor, new PathTool(new SVGPathFigure(), new SVGBezierFigure(false), attributes), "edit.createScribble", drawLabels); attributes = new HashMap<AttributeKey, Object>(); attributes.put(AttributeKeys.FILL_COLOR, Color.black); attributes.put(AttributeKeys.STROKE_COLOR, null); ButtonFactory.addToolTo( tb, editor, new CreationTool(new SVGTextFigure(), attributes), "edit.createText", drawLabels); TextAreaCreationTool tat = new TextAreaCreationTool(new SVGTextAreaFigure(), attributes); tat.setRubberbandColor(Color.BLACK); ButtonFactory.addToolTo(tb, editor, tat, "edit.createTextArea", drawLabels); }
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); }
public HashMap<Guid, RelationOrder> getPlaceRelation() { HashMap<Guid, RelationOrder> placeRelation = null; HashMap<Guid, RelationOrder> outstandingOrders = this.getOutstandingOrders(); for (RelationOrder relationOrder : outstandingOrders.values()) { if (relationOrder.get_IsSelected() && relationOrder.get_CloseLot().compareTo(BigDecimal.ZERO) > 0) { if (placeRelation == null) placeRelation = new HashMap<Guid, RelationOrder>(); placeRelation.put(relationOrder.get_OpenOrderId(), relationOrder); } } return placeRelation; }
public static ColorSampleLookupValue[] getColors() { if (ourColors == null) { synchronized (ColorSampleLookupValue.class) { if (ourColors == null) { ourColorNameToHexCodeMap = new HashMap<String, String>(25); ourHexCodeToColorNameMap = new HashMap<String, String>(25); List<ColorSampleLookupValue> colorsList = new LinkedList<ColorSampleLookupValue>(); StringTokenizer tokenizer = new StringTokenizer(systemColorsString, "\n"); while (tokenizer.hasMoreTokens()) { String name = tokenizer.nextToken(); colorsList.add(new ColorSampleLookupValue(name, name, false)); tokenizer.nextToken(); } tokenizer = new StringTokenizer(standardColorsString, ", \n"); HashMap<String, String> standardColors = new HashMap<String, String>(); while (tokenizer.hasMoreTokens()) { String name = tokenizer.nextToken(); String value = tokenizer.nextToken(); standardColors.put(name, name); ourColorNameToHexCodeMap.put(name, value); ourHexCodeToColorNameMap.put(value, name); colorsList.add(new ColorSampleLookupValue(name, value, true)); } tokenizer = new StringTokenizer(colorsString, " \t\n"); while (tokenizer.hasMoreTokens()) { String name = tokenizer.nextToken(); String hexValue = tokenizer.nextToken(); tokenizer.nextToken(); // skip rgb if (!standardColors.containsKey(name)) { colorsList.add(new ColorSampleLookupValue(name, hexValue, false)); ourColorNameToHexCodeMap.put(name, hexValue); ourHexCodeToColorNameMap.put(hexValue, name); } } colorsList.toArray(ourColors = new ColorSampleLookupValue[colorsList.size()]); } } } return ourColors; }
public Object addNode(String id, String label, String description, Image image, String tooltip) { if (id == null || label == null) return null; HashMap map = new HashMap(); map.put("Address", id); if (description.indexOf(id) > -1) description = description.substring(id.length()); map.put("Label", label); map.put("Description", description); map.put("Tooltip", tooltip); map.put("Image", image); map.put(" ", tooltip); map.put("Pivot", ""); map.put("Active", Boolean.FALSE); rows.add(map); return map; }
/* * Update a function. */ private void updatePlot( Function oldFunc, String newExpr[], Color3f newColor, String[] bounds, float[] stepSize) throws IllegalExpressionException { // Try evaluating the function. Function newFunc = createNewFunction(newExpr, newColor, bounds, stepSize); newFunc.setView(oldFunc.getView()); funcList.set(funcList.indexOf(oldFunc), newFunc); updateReferences(newFunc); FunctionLabel label = map.get(oldFunc); label.setMother(newFunc); map.remove(oldFunc); map.put(newFunc, label); setSelected(newFunc); plotter.removePlot(oldFunc); spawnNewPlotterThread(newFunc); }