Created
December 17, 2012 03:37
-
-
Save zbriscoe/4315615 to your computer and use it in GitHub Desktop.
COMP 354
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//package xxx_sample_code; | |
import java.io.BufferedReader; | |
import java.io.IOException; | |
import java.io.InputStreamReader; | |
import java.net.MalformedURLException; | |
import java.net.URL; | |
import java.util.ArrayList; | |
public class howToDoCodeSearchViaPublicWebservice { | |
/** | |
* @param args | |
* @throws IOException | |
*/ | |
public static void main(String[] args) throws IOException { | |
//param should be something.somethingelse | |
String param1="7529"; | |
String param2="150984"; | |
howToDoCodeSearchViaPublicWebservice me=new howToDoCodeSearchViaPublicWebservice(); | |
ArrayList<String> lines=me.doCodeSearch(param1,param2); | |
for(String l : lines) | |
{ | |
System.out.println(l); | |
} | |
} | |
public ArrayList<String> doCodeSearch(String param1,String param2) | |
{ | |
ArrayList<String> lines=new ArrayList<String>(); | |
try { | |
URL url = new URL("http://aseg.cs.concordia.ca/ca.concordia.cs.aseg.secodesearch.api.webservices/codesearchpublicservice?q="+param1+","+param2); | |
BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream())); | |
String line; | |
while ((line = reader.readLine()) != null) { | |
lines.add(line); | |
} | |
reader.close(); | |
} catch (MalformedURLException e) { | |
e.printStackTrace(); | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} | |
return(lines); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//package xxx_sample_code; | |
import java.io.BufferedReader; | |
import java.io.IOException; | |
import java.io.InputStreamReader; | |
import java.net.MalformedURLException; | |
import java.net.URL; | |
import java.util.ArrayList; | |
public class howToRetrieveCodePreviewViaPublicWebservice { | |
/** | |
* @param args | |
* @throws IOException | |
*/ | |
public static void main(String[] args) throws IOException { | |
String fileAddress="static/IJaDataset2/selected_files/2606016.java"; | |
int targetLineNo=145; | |
howToRetrieveCodePreviewViaPublicWebservice me=new howToRetrieveCodePreviewViaPublicWebservice(); | |
ArrayList<String> lines=me.getSimpleCodeFragmentPreview(fileAddress,targetLineNo); | |
for(String l : lines) | |
{ | |
System.out.println(l); | |
} | |
} | |
public ArrayList<String> getSimpleCodeFragmentPreview(String fileAddress,int targetLineNo) | |
{ | |
ArrayList<String> lines=new ArrayList<String>(); | |
try { | |
URL url = new URL("http://aseg.cs.concordia.ca/ca.concordia.cs.aseg.secodesearch.api.webservices/simplecodepreviewpublicservice?q="+fileAddress+","+targetLineNo); | |
BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream())); | |
String line; | |
while ((line = reader.readLine()) != null) { | |
lines.add(line); | |
} | |
reader.close(); | |
} catch (MalformedURLException e) { | |
e.printStackTrace(); | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} | |
return(lines); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/******************************************************************************* | |
* Copyright (c) 2000, 2009 IBM Corporation and others. | |
* All rights reserved. This program and the accompanying materials | |
* are made available under the terms of the Eclipse Public License v1.0 | |
* which accompanies this distribution, and is available at | |
* http://www.eclipse.org/legal/epl-v10.html | |
* | |
* Contributors: | |
* IBM Corporation - initial API and implementation | |
*******************************************************************************/ | |
//package org.eclipse.swt.snippets; | |
/* | |
* Text example snippet: implement content assist | |
* | |
* For a list of all SWT example snippets see | |
* http://www.eclipse.org/swt/snippets/ | |
*/ | |
import org.eclipse.swt.*; | |
import org.eclipse.swt.graphics.*; | |
import org.eclipse.swt.layout.*; | |
import org.eclipse.swt.widgets.*; | |
//ADDED | |
//import java.util.ArrayList; | |
public class Snippet320 { | |
public static void main(String [] args) { | |
final Display display = new Display(); | |
final Shell shell = new Shell(display); | |
shell.setLayout(new GridLayout()); | |
final Text text = new Text(shell, SWT.SINGLE | SWT.BORDER); | |
text.setLayoutData(new GridData(150, SWT.DEFAULT)); | |
shell.pack(); | |
shell.open(); | |
final Shell popupShell = new Shell(display, SWT.ON_TOP); | |
popupShell.setLayout(new FillLayout()); | |
final Table table = new Table(popupShell, SWT.SINGLE); | |
for (int i = 0; i < 5; i++) { | |
new TableItem(table, SWT.NONE); | |
} | |
text.addListener(SWT.KeyDown, new Listener() { | |
public void handleEvent(Event event) { | |
//@Zoe | |
String string = text.getText(); | |
switch (event.keyCode) { | |
case SWT.ARROW_DOWN: | |
int index = (table.getSelectionIndex() + 1) % table.getItemCount(); | |
table.setSelection(index); | |
event.doit = false; | |
//@Zoe | |
//Change text in highlighted option | |
//Later use to display more info about result | |
if (string.length() == 0) { | |
popupShell.setVisible(false); | |
} else { | |
TableItem[] items = table.getItems(); | |
//set new value | |
items[index].setText("Highlighted text"); | |
//reset previous selection | |
int previndex; | |
if(index == 0) | |
previndex = items.length -1; | |
else | |
previndex = index - 1; | |
System.out.println("previndex: " + previndex + "items length " +items.length); | |
items[previndex].setText(string + '-' + previndex); | |
} | |
//test | |
break; | |
case SWT.ARROW_UP: | |
index = table.getSelectionIndex() - 1; | |
if (index < 0) index = table.getItemCount() - 1; | |
table.setSelection(index); | |
event.doit = false; | |
//@Zoe | |
//Change text in highlighted option | |
//Later use to display more info about result | |
/** | |
string = text.getText(); | |
if (string.length() == 0) { | |
popupShell.setVisible(false); | |
} else { | |
TableItem[] items = table.getItems(); | |
//set new value | |
items[table.getSelectionIndex()].setText("Highlighted text"); | |
//reset previous selection | |
int previndex = (table.getSelectionIndex()+1) % items.length; | |
items[previndex].setText(string + '-' + previndex); | |
} | |
//test | |
**/ | |
break; | |
//Instead of selecting the option and displaying it where | |
//the user types we will want to load it into the doc | |
case SWT.CR: | |
if (popupShell.isVisible() && table.getSelectionIndex() != -1) { | |
text.setText(table.getSelection()[0].getText()); | |
popupShell.setVisible(false); | |
} | |
break; | |
case SWT.ESC: | |
popupShell.setVisible(false); | |
break; | |
} | |
} | |
}); | |
text.addListener(SWT.Modify, new Listener() { | |
public void handleEvent(Event event) { | |
//Get typed text for output | |
//We'll use this for parsing and delivery through webservice | |
String string = text.getText(); | |
if (string.length() == 0) { | |
popupShell.setVisible(false); | |
} else { | |
TableItem[] items = table.getItems(); | |
//For now just outputs typed in text + "-" + i | |
//We will want to change this to output possible answers from DB | |
for (int i = 0; i < items.length; i++) { | |
items[i].setText(string + '-' + i); | |
} | |
Rectangle textBounds = display.map(shell, null, text.getBounds()); | |
popupShell.setBounds(textBounds.x, textBounds.y + textBounds.height, textBounds.width, 150); | |
popupShell.setVisible(true); | |
} | |
} | |
}); | |
table.addListener(SWT.DefaultSelection, new Listener() { | |
public void handleEvent(Event event) { | |
text.setText(table.getSelection()[0].getText()); | |
popupShell.setVisible(false); | |
} | |
}); | |
table.addListener(SWT.KeyDown, new Listener() { | |
public void handleEvent(Event event) { | |
if (event.keyCode == SWT.ESC) { | |
popupShell.setVisible(false); | |
} | |
} | |
}); | |
Listener focusOutListener = new Listener() { | |
public void handleEvent(Event event) { | |
/* async is needed to wait until focus reaches its new Control */ | |
display.asyncExec(new Runnable() { | |
public void run() { | |
if (display.isDisposed()) return; | |
Control control = display.getFocusControl(); | |
if (control == null || (control != text && control != table)) { | |
popupShell.setVisible(false); | |
} | |
} | |
}); | |
} | |
}; | |
table.addListener(SWT.FocusOut, focusOutListener); | |
text.addListener(SWT.FocusOut, focusOutListener); | |
shell.addListener(SWT.Move, new Listener() { | |
public void handleEvent(Event event) { | |
popupShell.setVisible(false); | |
} | |
}); | |
while (!shell.isDisposed()) { | |
if (!display.readAndDispatch()) display.sleep(); | |
} | |
display.dispose(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment