Example usage for org.json.simple JSONValue parse

List of usage examples for org.json.simple JSONValue parse

Introduction

In this page you can find the example usage for org.json.simple JSONValue parse.

Prototype

public static Object parse(String s) 

Source Link

Usage

From source file:me.fromgate.facechat.UpdateChecker.java

private static void updateLastVersion() {
    if (!enableUpdateChecker)
        return;/* w  w  w. j  a  v a  2  s  . c o m*/
    URL url = null;
    try {
        url = new URL(projectApiUrl);
    } catch (Exception e) {
        log("Failed to create URL: " + projectApiUrl);
        return;
    }
    try {
        URLConnection conn = url.openConnection();
        conn.addRequestProperty("X-API-Key", null);
        conn.addRequestProperty("User-Agent", projectName + " using UpdateChecker (by fromgate)");
        BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
        String response = reader.readLine();
        JSONArray array = (JSONArray) JSONValue.parse(response);
        if (array.size() > 0) {
            JSONObject latest = (JSONObject) array.get(array.size() - 1);
            String plugin_name = (String) latest.get("name");
            projectLastVersion = plugin_name.replace(projectName + " v", "").trim();
        }
    } catch (Exception e) {
        log("Failed to check last version");
    }
}

From source file:it.acubelab.batframework.systemPlugins.TagmeAnnotator.java

@Override
public HashSet<ScoredAnnotation> solveSa2W(String text) throws AnnotationException {
    // System.out.println(text.length()+ " "+text.substring(0,
    // Math.min(text.length(), 15)));
    // TODO: workaround for a bug in tagme. should be deleted afterwards.
    String newText = "";
    for (int i = 0; i < text.length(); i++)
        newText += (text.charAt(i) > 127 ? ' ' : text.charAt(i));
    text = newText;//  w ww.  j a va 2 s .co m

    // avoid crashes for empty documents
    int j = 0;
    while (j < text.length() && text.charAt(j) == ' ')
        j++;
    if (j == text.length())
        return new HashSet<ScoredAnnotation>();

    HashSet<ScoredAnnotation> res;
    String params = null;
    try {
        res = new HashSet<ScoredAnnotation>();

        params = "key=" + this.key;
        params += "&lang=en";
        if (epsilon >= 0)
            params += "&epsilon=" + epsilon;
        if (minComm >= 0)
            params += "&min_comm=" + minComm;
        if (minLink >= 0)
            params += "&min_link=" + minLink;
        params += "&text=" + URLEncoder.encode(text, "UTF-8");
        URL wikiApi = new URL(url);

        HttpURLConnection slConnection = (HttpURLConnection) wikiApi.openConnection();
        slConnection.setRequestProperty("accept", "text/xml");
        slConnection.setDoOutput(true);
        slConnection.setDoInput(true);
        slConnection.setRequestMethod("POST");
        slConnection.setRequestProperty("charset", "utf-8");
        slConnection.setRequestProperty("Content-Length", Integer.toString(params.getBytes().length));
        slConnection.setUseCaches(false);
        slConnection.setReadTimeout(0);

        DataOutputStream wr = new DataOutputStream(slConnection.getOutputStream());
        wr.writeBytes(params);
        wr.flush();
        wr.close();

        Scanner s = new Scanner(slConnection.getInputStream());
        Scanner s2 = s.useDelimiter("\\A");
        String resultStr = s2.hasNext() ? s2.next() : "";
        s.close();

        JSONObject obj = (JSONObject) JSONValue.parse(resultStr);
        lastTime = (Long) obj.get("time");

        JSONArray jsAnnotations = (JSONArray) obj.get("annotations");
        for (Object js_ann_obj : jsAnnotations) {
            JSONObject js_ann = (JSONObject) js_ann_obj;
            System.out.println(js_ann);
            int start = ((Long) js_ann.get("start")).intValue();
            int end = ((Long) js_ann.get("end")).intValue();
            int id = ((Long) js_ann.get("id")).intValue();
            float rho = Float.parseFloat((String) js_ann.get("rho"));
            System.out.println(text.substring(start, end) + "->" + id + " (" + rho + ")");
            res.add(new ScoredAnnotation(start, end - start, id, (float) rho));
        }

    } catch (Exception e) {
        e.printStackTrace();
        throw new AnnotationException("An error occurred while querying TagMe API. Message: " + e.getMessage()
                + " Parameters:" + params);
    }
    return res;

}

From source file:it.serverSystem.ServerSystemTest.java

/**
 * SONAR-5197/*w  w w  .ja v  a  2 s  .  c  o  m*/
 */
// TODO should be moved elsewhere
@Test
public void api_ws_shortcut() throws Exception {
    Response response = call(orchestrator.getServer().getUrl() + "/api");
    assertThat(response.isSuccessful()).as("Response code is %s", response.code()).isTrue();
    String json = IOUtils.toString(response.body().byteStream());
    Map jsonAsMap = (Map) JSONValue.parse(json);
    assertThat(jsonAsMap.get("webServices")).isNotNull();
}

From source file:ch.simas.jtoggl.JToggl.java

/**
 * Get a time entry.//w  w  w.ja va 2 s . c  o m
 * 
 * @param id
 * @return TimeEntry or null if no Entry is found.
 */
public TimeEntry getTimeEntry(Long id) {
    Client client = prepareClient();
    String url = TIME_ENTRY.replace(PLACEHOLDER, id.toString());
    WebResource webResource = client.resource(url);

    String response = null;
    try {
        response = webResource.get(String.class);
    } catch (UniformInterfaceException uniformInterfaceException) {
        return null;
    }

    JSONObject object = (JSONObject) JSONValue.parse(response);
    JSONObject data = (JSONObject) object.get(DATA);
    if (data == null)
        return null;

    return new TimeEntry(data.toJSONString());
}

From source file:com.precioustech.fxtrading.oanda.restapi.position.OandaPositionManagementProvider.java

@Override
public Position<String> getPositionForInstrument(Long accountId, TradeableInstrument<String> instrument) {
    CloseableHttpClient httpClient = getHttpClient();
    try {//from   www. j  a  v a2s.  c o  m
        String strResp = getResponseAsString(getPositionForInstrumentUrl(accountId, instrument), httpClient);
        if (strResp != StringUtils.EMPTY) {
            return parsePositionInfo((JSONObject) JSONValue.parse(strResp));
        }
    } catch (Exception ex) {
        LOG.error(String.format("error encountered whilst fetching position for instrument %s and account %d",
                instrument.getInstrument(), accountId), ex);
    } finally {
        TradingUtils.closeSilently(httpClient);
    }
    return null;
}

From source file:com.turt2live.uuid.turt2live.v1.ApiV1Service.java

@Override
public List<PlayerRecord> getRandomSample(int amount) {
    if (amount <= 0)
        throw new IllegalArgumentException();

    String response = doUrlRequest(getConnectionUrl() + "/random/" + amount);
    if (response == null || response.length() <= 2)
        return null;

    JSONArray array = (JSONArray) JSONValue.parse(response);
    List<PlayerRecord> records = new ArrayList<>();

    for (Object o : array) {
        PlayerRecord record = parsePlayerRecord(o.toString());

        if (record != null)
            records.add(record);/*from  w  w w.  j  a  va2 s .  c o  m*/
    }

    return records;
}

From source file:hwcdhackwaterloo.GUIMain.java

/**
 * This method is called from within the constructor to initialize the form.
 * WARNING: Do NOT modify this code. The content of this method is always
 * regenerated by the Form Editor.//  ww  w.j av a 2s.  com
 */
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {

    menuPanel = new javax.swing.JPanel();
    titleLabel = new javax.swing.JLabel();
    closeButton = new javax.swing.JButton();
    topPanel = new javax.swing.JPanel();
    jLabel1 = new javax.swing.JLabel();
    roomChoice = new javax.swing.JComboBox();
    jLabel3 = new javax.swing.JLabel();
    jLabel5 = new javax.swing.JLabel();
    timeField = new javax.swing.JTextField();
    findButton = new javax.swing.JButton();
    monthChoice = new javax.swing.JComboBox();
    dayChoice = new javax.swing.JComboBox();
    jLabel6 = new javax.swing.JLabel();
    middlePanel = new javax.swing.JPanel();
    resultHeader = new javax.swing.JLabel();
    result = new javax.swing.JLabel();
    bottomPanel = new javax.swing.JPanel();
    jLabel4 = new javax.swing.JLabel();

    setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
    setTitle("Fuck_Nuts");
    setBackground(new java.awt.Color(0, 0, 0));
    setForeground(java.awt.Color.pink);
    setUndecorated(true);
    setResizable(false);

    menuPanel.setBackground(new java.awt.Color(10, 10, 10));

    titleLabel.setBackground(new java.awt.Color(255, 255, 255));
    titleLabel.setFont(new java.awt.Font("DejaVu Sans Condensed", 0, 18)); // NOI18N
    titleLabel.setForeground(new java.awt.Color(230, 230, 230));
    titleLabel.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
    titleLabel.setText("WaterLOOKup");

    closeButton.setBackground(new java.awt.Color(0, 0, 0));
    closeButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/closeButtonAlt.png"))); // NOI18N
    closeButton.addMouseListener(new java.awt.event.MouseAdapter() {
        public void mouseClicked(java.awt.event.MouseEvent evt) {
            closeButtonMouseClicked(evt);
        }
    });

    javax.swing.GroupLayout menuPanelLayout = new javax.swing.GroupLayout(menuPanel);
    menuPanel.setLayout(menuPanelLayout);
    menuPanelLayout
            .setHorizontalGroup(menuPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(menuPanelLayout.createSequentialGroup()
                            .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(titleLabel).addGap(156, 156, 156).addComponent(closeButton,
                                    javax.swing.GroupLayout.PREFERRED_SIZE, 27,
                                    javax.swing.GroupLayout.PREFERRED_SIZE)));
    menuPanelLayout.setVerticalGroup(menuPanelLayout
            .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(menuPanelLayout.createSequentialGroup()
                    .addGroup(menuPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(titleLabel, javax.swing.GroupLayout.DEFAULT_SIZE,
                                    javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING,
                                    menuPanelLayout.createSequentialGroup().addGap(0, 0, Short.MAX_VALUE)
                                            .addComponent(closeButton, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                    29, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addContainerGap()));

    topPanel.setBackground(new java.awt.Color(135, 0, 71));
    topPanel.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));

    jLabel1.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
    jLabel1.setForeground(new java.awt.Color(250, 250, 250));
    jLabel1.setText("SEARCH FOR AVAILABLE ROOMS");

    roomChoice.setBackground(new java.awt.Color(200, 50, 100));
    roomChoice.addItem("MC");

    roomChoice.addItemListener(new ItemListener() {
        Object state = new Object();
        //Object oldState = new Object();
        Object oldState = roomChoice.getSelectedItem();

        public void itemStateChanged(ItemEvent e) {

            state = e.getItem();
            if (state != oldState) {
                //System.out.println("changed to:"+ state);
                // code here to pass info to openroom.java
            }
            oldState = state;

        }
    });
    String json = getJSONData("/buildings/list");
    JSONObject obj = (JSONObject) JSONValue.parse(json);
    JSONArray courses = (JSONArray) obj.get("data");
    ArrayList<String> buildingNames = new ArrayList<>();
    for (Object course : courses) {
        JSONObject courseBlock = (JSONObject) course;
        buildingNames.add(courseBlock.get("building_code").toString());
    }
    Collections.sort(buildingNames);
    for (String buildingName : buildingNames) {
        roomChoice.addItem(buildingName);
    }

    jLabel3.setFont(new java.awt.Font("Tahoma", 0, 16)); // NOI18N
    jLabel3.setForeground(new java.awt.Color(250, 250, 250));
    jLabel3.setText("WHAT'S DA CLOSEST BUILDIN TO YOU?");

    jLabel5.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
    jLabel5.setForeground(new java.awt.Color(250, 250, 250));
    jLabel5.setText("WHEN DO YOU WANT A ROOM, AND FOR HOW LONG?");

    timeField.setBackground(new java.awt.Color(255, 160, 202));
    timeField.setText("(minutes)");

    findButton.setBackground(new java.awt.Color(255, 170, 202));
    findButton.setText("FIND AVAILABLE ROOM!");
    Object comboBoxState = roomChoice.getSelectedItem();
    findButton.setActionCommand("FIND");
    //findButton.addActionListener(this);
    findButton.setToolTipText("Dooooo itttt!");

    //pubic void actionPerformed(ActionEvent e){
    //    if("FIND".equals(e.getActionCommand())){
    //        System.out.println("Press registered.");
    //    }
    //}
    findButton.addMouseListener(new java.awt.event.MouseAdapter() {
        public void mouseReleased(java.awt.event.MouseEvent evt) {
            findButtonMouseReleased(evt);
        }
    });

    monthChoice.setBackground(new java.awt.Color(200, 50, 100));
    monthChoice.setModel(new javax.swing.DefaultComboBoxModel(
            new String[] { "<select month>", "January", "February", "March", "April", "May", "June", "July",
                    "August", "September", "October", "November", "December" }));
    monthChoice.addItemListener(new java.awt.event.ItemListener() {
        public void itemStateChanged(java.awt.event.ItemEvent evt) {
            monthChoiceItemStateChanged(evt);
        }
    });

    dayChoice.setBackground(new java.awt.Color(200, 50, 100));

    jLabel6.setForeground(new java.awt.Color(255, 255, 255));
    jLabel6.setText("DURATION:");

    javax.swing.GroupLayout topPanelLayout = new javax.swing.GroupLayout(topPanel);
    topPanel.setLayout(topPanelLayout);
    topPanelLayout.setHorizontalGroup(topPanelLayout
            .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(topPanelLayout.createSequentialGroup().addGroup(topPanelLayout
                    .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(topPanelLayout.createSequentialGroup().addGap(34, 34, 34)
                            .addGroup(topPanelLayout
                                    .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel3)
                                    .addComponent(roomChoice, javax.swing.GroupLayout.PREFERRED_SIZE, 87,
                                            javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jLabel5)
                                    .addGroup(topPanelLayout.createSequentialGroup()
                                            .addComponent(monthChoice, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                    122, javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                            .addComponent(dayChoice, javax.swing.GroupLayout.PREFERRED_SIZE, 55,
                                                    javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED,
                                                    javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                            .addComponent(jLabel6)
                                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                            .addComponent(timeField, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                    108, javax.swing.GroupLayout.PREFERRED_SIZE))))
                    .addGroup(topPanelLayout.createSequentialGroup().addGap(135, 135, 135).addComponent(
                            findButton, javax.swing.GroupLayout.PREFERRED_SIZE, 187,
                            javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGap(38, 38, 38))
            .addGroup(topPanelLayout.createSequentialGroup().addGap(93, 93, 93).addComponent(jLabel1)
                    .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)));
    topPanelLayout.setVerticalGroup(topPanelLayout
            .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(topPanelLayout.createSequentialGroup()
                    .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 25,
                            javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 23,
                            javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(roomChoice, javax.swing.GroupLayout.DEFAULT_SIZE,
                            javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 23,
                            javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(topPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(timeField, javax.swing.GroupLayout.PREFERRED_SIZE,
                                    javax.swing.GroupLayout.DEFAULT_SIZE,
                                    javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(monthChoice, javax.swing.GroupLayout.PREFERRED_SIZE,
                                    javax.swing.GroupLayout.DEFAULT_SIZE,
                                    javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(dayChoice, javax.swing.GroupLayout.PREFERRED_SIZE,
                                    javax.swing.GroupLayout.DEFAULT_SIZE,
                                    javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel6))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(findButton, javax.swing.GroupLayout.DEFAULT_SIZE, 34, Short.MAX_VALUE)
                    .addContainerGap()));

    middlePanel.setBackground(new java.awt.Color(0, 129, 16));
    middlePanel.setForeground(new java.awt.Color(240, 240, 240));

    resultHeader.setFont(new java.awt.Font("Tahoma", 0, 18));
    resultHeader.setForeground(new java.awt.Color(250, 250, 250));

    result.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
    result.setForeground(new java.awt.Color(255, 255, 255));

    javax.swing.GroupLayout middlePanelLayout = new javax.swing.GroupLayout(middlePanel);
    middlePanel.setLayout(middlePanelLayout);
    middlePanelLayout.setHorizontalGroup(middlePanelLayout
            .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(middlePanelLayout.createSequentialGroup().addGap(84, 84, 84)
                    .addComponent(resultHeader, javax.swing.GroupLayout.PREFERRED_SIZE, 267,
                            javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addContainerGap(115, Short.MAX_VALUE))
            .addGroup(middlePanelLayout.createSequentialGroup().addContainerGap().addComponent(result,
                    javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addContainerGap()));
    middlePanelLayout.setVerticalGroup(middlePanelLayout
            .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(middlePanelLayout.createSequentialGroup()
                    .addComponent(resultHeader, javax.swing.GroupLayout.PREFERRED_SIZE, 27,
                            javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 49, Short.MAX_VALUE)
                    .addComponent(result, javax.swing.GroupLayout.PREFERRED_SIZE, 82,
                            javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGap(44, 44, 44)));

    bottomPanel.setBackground(new java.awt.Color(159, 238, 0));

    jLabel4.setFont(new java.awt.Font("Tahoma", 0, 10)); // NOI18N
    jLabel4.setText("BY: KERI WARR, ANTHONY CALANDRA, DANIEL HOPPER, NEIL DE VRIES");

    javax.swing.GroupLayout bottomPanelLayout = new javax.swing.GroupLayout(bottomPanel);
    bottomPanel.setLayout(bottomPanelLayout);
    bottomPanelLayout
            .setHorizontalGroup(bottomPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING,
                            bottomPanelLayout.createSequentialGroup()
                                    .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 406,
                                            javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addContainerGap()));
    bottomPanelLayout.setVerticalGroup(
            bottomPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(
                    javax.swing.GroupLayout.Alignment.TRAILING,
                    bottomPanelLayout.createSequentialGroup().addGap(0, 132, Short.MAX_VALUE).addComponent(
                            jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 23,
                            javax.swing.GroupLayout.PREFERRED_SIZE)));

    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(middlePanel, javax.swing.GroupLayout.DEFAULT_SIZE,
                    javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(menuPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
                    Short.MAX_VALUE)
            .addComponent(bottomPanel, javax.swing.GroupLayout.DEFAULT_SIZE,
                    javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(topPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
                    Short.MAX_VALUE));
    layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                    .addComponent(menuPanel, javax.swing.GroupLayout.PREFERRED_SIZE, 33,
                            javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(topPanel, javax.swing.GroupLayout.PREFERRED_SIZE,
                            javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(middlePanel, javax.swing.GroupLayout.PREFERRED_SIZE,
                            javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(bottomPanel, javax.swing.GroupLayout.PREFERRED_SIZE,
                            javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)));

    pack();
}

From source file:mml.test.Editor.java

/**
 * Create a select dropdown with the dialect's styles
 * @param dialect the dialect file//from w ww. j  ava  2  s  . c o m
 * @return a select list with groups for para headings and charfmts
 */
private Element getStyles(String dialect) {
    JSONObject dObj = (JSONObject) JSONValue.parse(dialect);
    Element select = new Element("select");
    select.addAttribute("id", "styles");
    addOptGroup(select, dObj, "headings", "headings");
    addOptGroup(select, dObj, "paraformats", "paragraph formats");
    addOptGroup(select, dObj, "charformats", "character formats");
    addOptGroup(select, dObj, "dividers", "dividers");
    addOptGroup(select, dObj, "milestones", "milestones");
    addOptGroup(select, dObj, "codeblocks", "verbatim");
    addOptGroup(select, dObj, "quotations", "quotations");
    return select;
}

From source file:com.precioustech.fxtrading.oanda.restapi.trade.OandaTradeManagementProvider.java

@Override
public Trade<Long, String, Long> getTradeForAccount(Long tradeId, Long accountId) {
    CloseableHttpClient httpClient = getHttpClient();
    try {/* ww  w.  j  a  v  a2 s . co  m*/
        HttpUriRequest httpGet = new HttpGet(getTradeForAccountUrl(tradeId, accountId));
        httpGet.setHeader(this.authHeader);
        httpGet.setHeader(OandaConstants.UNIX_DATETIME_HEADER);
        LOG.info(TradingUtils.executingRequestMsg(httpGet));
        HttpResponse resp = httpClient.execute(httpGet);
        String strResp = TradingUtils.responseToString(resp);
        if (strResp != StringUtils.EMPTY) {
            JSONObject trade = (JSONObject) JSONValue.parse(strResp);
            return parseTrade(trade, accountId);
        } else {
            TradingUtils.printErrorMsg(resp);
        }
    } catch (Exception ex) {
        LOG.error(
                String.format("error encountered whilst fetching trade %d for account %d", tradeId, accountId),
                ex);
    } finally {
        TradingUtils.closeSilently(httpClient);
    }
    return null;
}

From source file:it.cnr.isti.thematrix.scripting.sys.DatasetSchema.java

/**
 * Convert the argument JSON string into a DatasetSchema
 * @param jsonContent //from  ww w .j a va  2 s.  c  om
 * @return a DatasetSchema
 */
public static DatasetSchema fromJSON(String jsonContent) {
    Object obj = JSONValue.parse(jsonContent);
    JSONArray array = (JSONArray) obj;

    String schemaName = (String) array.get(0);
    DatasetSchema ds = new DatasetSchema(schemaName);

    for (int i = 1; i < array.size(); i++) {
        JSONObject o = (JSONObject) array.get(i);
        String name = (String) o.get("name");
        DataType type = DataType.valueOf((String) o.get("type"));
        ds.put(new Symbol<Integer>(name, null, type));
    }

    return ds;
}