id stringlengths 36 36 | text stringlengths 1 1.25M |
|---|---|
67d3709d-b675-4f8c-af95-db63933c6676 | public String[] getGroupMembers() {
return getPersons("groups.getMembers").split(",");
} |
a6e0914a-0448-44c2-ad68-985da7fcd62d | public Downloader(String _id) {
id = _id;
} |
60d5e9cc-3bb8-4987-9f6d-a131a0b4eefa | protected String requestGET(String address) {
String result = "";
try {
URL url = new URL(address);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestProperty("User-Agent", "Java bot");
conn.connect();
int code = conn.getResponseCode();
if (code == 200) {
BufferedReader in = new BufferedReader(new InputStreamReader(
conn.getInputStream()));
String inputLine;
while ((inputLine = in.readLine()) != null) {
result += inputLine;
}
in.close();
}
conn.disconnect();
conn = null;
} catch (Exception e) {
e.printStackTrace();
}
return result;
} |
f3c1ecf7-7a92-41ad-a97a-e1d7c6ce87df | protected String getPersons(String request) {
String response = requestGET(BASE_URI + request + "?uid=" + id);
int start = response.indexOf('[');
int end = response.indexOf(']');
return response.substring(start + 1, end);
} |
2fcbfc2e-d905-4c7b-a80c-614a85f31540 | public String[] getPersonFriends() {
return getPersons("friends.get").split(",");
} |
5a97dd74-f9b0-4612-b393-0c8044ea2dcf | public String getPersonXMLData() {
StringBuilder request = new StringBuilder(BASE_URI);
request = request.append("users.get.xml?uid=");
request = request.append(id);
request = request.append("&fields=");
request = request.append("sex");
request = request.append(",bdate");
request = request.append(",city");
request = request.append(",can_post");
request = request.append(",status");
request = request.append(",relation");
request = request.append(",nickname");
request = request.append(",relatives");
request = request.append(",activities");
request = request.append(",interests");
request = request.append(",movies");
request = request.append(",tv");
request = request.append(",books");
request = request.append(",games");
request = request.append(",about");
request = request.append(",personal");
request = request.append(",counters");
String response = requestGET(request.toString());
return response;
} |
99a7dd29-9fa9-4ac5-a5b8-88c0e82a52cc | public DBFillerGroup (String groupId, int level) {
super(groupId, level);
registerShutdownHook(graphDb);
Transaction tx = graphDb.beginTx();
nodeIndex = graphDb.index().forNodes("uids");
tx.success();
tx.close();
} |
8989ceca-b70d-4a21-97ef-b6d8e72738c6 | @Override
public void fillDB() {
Transaction tx = graphDb.beginTx();
fillFromGroup();
tx.success();
tx.close();
} |
668471c9-2801-4990-b5cb-d353e6fb9511 | private void fillFromGroup() {
DownloaderGroup group = new DownloaderGroup(baseId);
String[] ids = group.getGroupMembers();
for(String id : ids){
fillDB_Snowball(id);
}
} |
814b2476-8cf1-4fa8-bae0-75e1f332c13e | protected void registerShutdownHook(final GraphDatabaseService graphDb) {
Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
public void run() {
graphDb.shutdown();
}
});
} |
4acbcba8-c66b-44c6-a787-70dcc91c835f | @Override
public void run() {
graphDb.shutdown();
} |
ab6aecef-ed5d-4b68-9d31-d71d92bc1d84 | public DBFiller (String startId, int level) {
MAX_LEVEL = level;
baseId = startId;
registerShutdownHook(graphDb);
Transaction tx = graphDb.beginTx();
nodeIndex = graphDb.index().forNodes("uids");
tx.success();
tx.close();
} |
0abb745c-4013-4277-8e78-046e05d86034 | protected String getOneField(String name, Element e) {
if (e.getChild(name) != null) {
String temp = e.getChild(name).getText().replaceAll("\'", "");
if (!temp.equals("")) {
return temp;
}
}
return "?";
} |
6c42e647-d06b-4208-881e-f6d6fac8a0df | protected HashMap<String, Object> parsePersonXML(String xml) {
HashMap<String, Object> personData = new HashMap<String, Object>();
try {
SAXBuilder builder = new SAXBuilder();
Document doc = builder.build(new InputSource(new StringReader(xml)));
Element root = doc.getRootElement();
Element user = root.getChild("user");
personData.put("uid", getOneField("uid", user));
personData.put("first_name", getOneField("first_name", user));
personData.put("last_name", getOneField("last_name", user));
personData.put("sex", getOneField("sex", user));
personData.put("bdate", getOneField("bdate", user));
personData.put("city", getOneField("city", user));
personData.put("can_post", getOneField("can_post", user));
personData.put("status", getOneField("status", user));
personData.put("relation", getOneField("relation", user));
personData.put("nickname", getOneField("nickname", user));
personData.put("interests", getOneField("interests", user));
personData.put("movies", getOneField("movies", user));
personData.put("tv", getOneField("tv", user));
personData.put("books", getOneField("books", user));
personData.put("games", getOneField("games", user));
personData.put("about", getOneField("about", user));
personData.put("counters", getOneField("counters", user));
} catch (JDOMException ex) {
Logger.getLogger(DBCreator.class.getName()).log(Level.SEVERE, null, ex);
} catch (IOException ex) {
Logger.getLogger(DBCreator.class.getName()).log(Level.SEVERE, null, ex);
}
return personData;
} |
5c705d4e-694c-44ac-8c1b-2c399670ac57 | protected void setRelationship(Node curPerson, Node parentPerson) {
Iterable<Relationship> relationships = curPerson.getRelationships(Direction.BOTH);
boolean relationAlreadyExist = false;
for (Relationship tempRel : relationships) {
if (tempRel.getOtherNode(curPerson).getId() == parentPerson.getId()) {
relationAlreadyExist = true;
break;
}
}
if (!relationAlreadyExist) {
Transaction tx = graphDb.beginTx();
try {
parentPerson.createRelationshipTo(curPerson, RelTypes.FRIEND);
tx.success();
} finally {
tx.close();
}
}
} |
427bb118-f146-4201-bda9-005875c697e0 | protected Node addPersonToDB(HashMap<String, Object> personProperties) {
Transaction tx = graphDb.beginTx();
Node curPerson = null;
Node existingNode = nodeIndex.get("uid", personProperties.get("uid")).getSingle();
try {
if (existingNode == null) {
curPerson = graphDb.createNode();
Iterator<String> keySetIterator = personProperties.keySet().iterator();
while (keySetIterator.hasNext()) {
String key = keySetIterator.next();
curPerson.setProperty(key, personProperties.get(key));
}
nodeIndex.add(curPerson, "uid", personProperties.get("uid"));
}
tx.success();
} finally {
tx.close();
}
return curPerson;
} |
1a3fbf3b-954e-4ace-b673-adfc36060bba | protected Node addPersonToDB(HashMap<String, Object> personProperties, String parentUid) {
Node curPerson = addPersonToDB(personProperties);
Node parentPerson = nodeIndex.get("uid", parentUid).getSingle();
Transaction tx = graphDb.beginTx();
try {
if (curPerson == null) {
curPerson = nodeIndex.get("uid", personProperties.get("uid")).getSingle();
}
setRelationship(curPerson, parentPerson);
tx.success();
} finally {
tx.close();
}
return curPerson;
} |
4db2268e-d4f8-4ff2-947a-4eefc3696cbd | public void fillDB() {
Transaction tx = graphDb.beginTx();
fillDB_Snowball(baseId);
tx.success();
tx.close();
} |
3e3d0ca8-e571-4c1e-a8d2-4e115b8b62af | protected void fillDB_Snowball(String id) {
Downloader person = new Downloader(id);
HashMap<String, Object> personData = parsePersonXML(person.getPersonXMLData());
String[] friendUids = person.getPersonFriends();
personData.put(FRIEND_LIST_KEY, friendUids);
addPersonToDB(personData);
for (String tempFriend : friendUids) {
recFillingDB(tempFriend, id, 1);
}
} |
c86ff975-5ba4-4d2e-9e12-afd2a5faaba7 | protected void recFillingDB(String curUid, String parentUid, int lvl) {
if (lvl == MAX_LEVEL) {
return;
}
Downloader person = new Downloader(curUid);
System.out.println("Parsing uid = " + curUid + " parentUid = " + parentUid);
String[] friendsUids = person.getPersonFriends();
Node existingNode = nodeIndex.get("uid", curUid).getSingle();
if (existingNode == null) {
HashMap<String, Object> personData = parsePersonXML(person.getPersonXMLData());
System.out.println(" first_name = " + personData.get("first_name")
+ " last_name = " + personData.get("last_name") + " lvl = " + lvl);
personData.put(FRIEND_LIST_KEY, friendsUids);
existingNode = addPersonToDB(personData, parentUid);
} else {
setRelationship(existingNode, nodeIndex.get("uid", parentUid).getSingle());
}
for (String tempFriend : friendsUids) {
recFillingDB(tempFriend, curUid, lvl + 1);
}
} |
a0022058-4bf3-4253-b6af-df3ebf57669c | protected void setOneNodeRelations(Node curNode) {
if (curNode.hasProperty(FRIEND_LIST_KEY)) {
String[] friendsUidList = (String[]) curNode.getProperty(FRIEND_LIST_KEY);
for (String tempFriendUid : friendsUidList) {
Node tempFriend = nodeIndex.get("uid", tempFriendUid).getSingle();
if (tempFriend == null) {
continue;
}
Iterable<Relationship> relationships = tempFriend.getRelationships(Direction.BOTH);
boolean relationAlreadyExist = false;
for (Relationship tempRel : relationships) {
if (tempRel.getEndNode().getId() == curNode.getId()) {
relationAlreadyExist = true;
break;
}
}
if (!relationAlreadyExist) {
curNode.createRelationshipTo(tempFriend, RelTypes.FRIEND);
}
}
}
} |
a974af47-5cb4-42bc-8759-d3233d5dd773 | public void setAllRelations() {
Transaction tx = graphDb.beginTx();
try {
GlobalGraphOperations glOper = GlobalGraphOperations.at(graphDb);
Iterator<Node> allNodes = glOper.getAllNodes().iterator();
while (allNodes.hasNext()) {
setOneNodeRelations(allNodes.next());
}
tx.success();
} finally {
tx.close();
}
} |
675664e9-2d2b-4843-aa2f-77cba8d944a5 | public Line(Color c, int x, int y, int x1, int y1) {
super(c);
this.x = x;
this.y = y;
this.x1 = x1;
this.y1 = y1;
} |
d7758ef5-f294-4648-b301-90ee61074ab0 | public void paintLine(Graphics g){
g.setColor(getColor());
g.drawLine(x, y, x1, y1);
} |
ea2d5878-7e6d-47c0-bcc3-ff2521ffe8a7 | public InputSaver(String phrase, String xCoord, String yCoord, String var1, String var2) {
this.phrase = phrase;
this.xCoord = xCoord;
this.yCoord = yCoord;
this.var1 = var1;
this.var2 = var2;
} |
1662c8a2-7c33-4f8c-bb04-b9e5a7876d7e | public void remove(){
phrase = "";
xCoord = "";
yCoord = "";
var1 = "";
var2 = "";
} |
285af2d2-495b-4c54-af79-b784f3f41b54 | public TheColor(Color color){
this.color = color;
} |
849190bf-2aae-4a4b-9d67-9a277a3afc94 | public OrigOutput(String phrase){
p=phrase;
} |
dc8bc984-8b0f-4ba4-9291-33f286605925 | public FilledCircle(Color color, int x, int y, int radius) {
super(color);
this.x = x;
this.y = y;
this.radius = radius;
} |
870e2832-7462-45fd-a7c8-f5bf1a974e9e | public void paintCircle(Graphics g) {
g.setColor(getColor());
g.fillOval(x, y, radius*2, radius*2);
} |
d6492225-8d55-4cef-98da-1f47e34f47d2 | public Rectangle(Color color, int x, int y, int width, int height) {
super(color);
this.x = x;
this.y = y;
this.width = width;
this.height = height;
} |
42b4c5fa-6b23-4b0a-a344-0b51bea788eb | public void paintRectangle(Graphics g) {
g.setColor(getColor());
g.drawRect(x, y, width, height);
} |
7dc90b1d-ddde-43f5-8b7b-e8af411ef012 | public Painting(Opener opener){
setSize(800, 600);
this.opener = opener;
addMouseListener(this);
} |
f5021553-b141-4e16-8851-eab0ad387431 | public void paint(Graphics g){
TheColor TC = new TheColor(Color.black); // Set initial color of TheColor class to a default black
for(InputSaver s : opener.newPhrase){
// If statements to draw proper shapes on to canvas
if(s.phrase.equals("line")){
int x = Integer.parseInt(s.xCoord);
int y = Integer.parseInt(s.yCoord);
int x1 = Integer.parseInt(s.var1);
int y1 = Integer.parseInt(s.var2);
Line li = new Line(TC.color, x, y, x1, y1);
li.paintLine(getGraphics());
}
else if(s.phrase.equals("circle")){
int x = Integer.parseInt(s.xCoord);
int y = Integer.parseInt(s.yCoord);
int r = Integer.parseInt(s.var1);
Circle circ = new Circle(TC.color, x, y, r);
circ.paintCircle(getGraphics());
}
else if(s.phrase.equals("filledcircle")){
int x = Integer.parseInt(s.xCoord);
int y = Integer.parseInt(s.yCoord);
int r = Integer.parseInt(s.var1);
FilledCircle fcirc = new FilledCircle(TC.color, x, y, r);
fcirc.paintCircle(getGraphics());
}
else if(s.phrase.equals("rectangle")){
int x = Integer.parseInt(s.xCoord);
int y = Integer.parseInt(s.yCoord);
int w = Integer.parseInt(s.var1);
int h = Integer.parseInt(s.var2);
Rectangle r = new Rectangle(TC.color, x, y, w, h);
r.paintRectangle(getGraphics());
}
else if(s.phrase.equals("filledrectangle")){
int x = Integer.parseInt(s.xCoord);
int y = Integer.parseInt(s.yCoord);
int w = Integer.parseInt(s.var1);
int h = Integer.parseInt(s.var2);
FilledRectangle fr = new FilledRectangle(TC.color, x, y, w, h);
fr.paintRectangle(getGraphics());
}
else if(s.phrase.equals("square")){
int x = Integer.parseInt(s.xCoord);
int y = Integer.parseInt(s.yCoord);
int wh = Integer.parseInt(s.var1);
Square sq = new Square(TC.color, x, y, wh);
sq.paintRectangle(getGraphics());
}
else if(s.phrase.equals("filledsquare")){
int x = Integer.parseInt(s.xCoord);
int y = Integer.parseInt(s.yCoord);
int wh = Integer.parseInt(s.var1);
FilledSquare fsq = new FilledSquare(TC.color, x, y, wh);
fsq.paintRectangle(getGraphics());
}
//Sets new color of the super class for all other shapes to inherit
else if(s.phrase.equals("color")){
int r = Integer.parseInt(s.xCoord);
int gr = Integer.parseInt(s.yCoord);
int b = Integer.parseInt(s.var1);
Color newColor = new Color(r, gr, b);
TC.color = newColor;
}
}// End for loop
}// End paint class |
71c2e81c-a206-4a8e-9e51-ea0c1924685d | @Override
public void mouseClicked(MouseEvent arg0) {;} |
f02a2f38-cc6f-4c2b-a8a3-d1c665dd59b5 | @Override
public void mouseEntered(MouseEvent arg0) {;} |
13f03c35-b4a7-4a8d-9ba9-d8a47ff97c84 | @Override
public void mouseExited(MouseEvent arg0) {;} |
09ce63df-364b-4972-896c-e942025113bb | @Override
public void mousePressed(MouseEvent me) {
//Assign variables to get location of mouse click
int mouseX = me.getX();
int mouseY = me.getY();
//For loop ran every time user clicks mouse to determine if mouse click is on a shape
/*
* Canvas is redrawn if one of these if statements is true because if true,
* the shape that was clicked on is removed from the ArrayList.
* It is removed because when user goes to save the new drawing, the deleted shapes will
* not appear in the .txt file
*/
for(InputSaver s : opener.newPhrase){
if(s.phrase.equals("rectangle") || s.phrase.equals("filledrectangle")){
int x = Integer.parseInt(s.xCoord);
int y = Integer.parseInt(s.yCoord);
int w = Integer.parseInt(s.var1);
int h = Integer.parseInt(s.var2);
if((mouseX >= x && mouseX <= (w + x)) &&
(mouseY >= y && mouseY <= (h + y))){
s.remove();
repaint();
}
}
else if(s.phrase.equals("square") || s.phrase.equals("filledsquare")){
int x = Integer.parseInt(s.xCoord);
int y = Integer.parseInt(s.yCoord);
int wh = Integer.parseInt(s.var1);
if((mouseX >= x && mouseX <= (wh + x)) &&
(mouseY >= y && mouseY <= (wh + y))){
s.remove();
repaint();
}
}
else if(s.phrase.equals("circle") || s.phrase.equals("filledcircle")){
int x = Integer.parseInt(s.xCoord);
int y = Integer.parseInt(s.yCoord);
int r = Integer.parseInt(s.var1);
if((mouseX >= Math.abs(x) && mouseX <= Math.abs(r*2 + x)) &&
(mouseY >= Math.abs(y) && mouseY <= Math.abs(r*2 + y))){
s.remove();
repaint();
}
}
else if(s.phrase.equals("line")){
int x = Integer.parseInt(s.xCoord);
int y = Integer.parseInt(s.yCoord);
int x1 = Integer.parseInt(s.var1);
int y1 = Integer.parseInt(s.var2);
if((mouseX >= x && (mouseX <= (x / x1))) &&
(mouseY >= y && (mouseY <= (y / y1)))){
s.remove();
repaint();
}
}
// Do nothing and continue loop if the loop reaches a color. Color will not be modified
else if(s.phrase.equals("color")){
continue;
}
}// End for loop
}// End MousePressed |
4e7dc668-cd53-43e0-8f5c-696b1a99b79a | @Override
public void mouseReleased(MouseEvent arg0) {;} |
6d7f0854-61e4-4f4c-adcb-220ca61e90a7 | @Override
public void windowActivated(WindowEvent arg0) {;} |
502fe1ea-d6a0-4e2c-95c0-877ea5479f17 | @Override
public void windowClosed(WindowEvent arg0) {;} |
6ed299b7-52b9-498e-bd05-47d56adb83fd | @Override
public void windowClosing(WindowEvent arg0) {
System.exit(0);;} |
6d40add7-1710-4dd3-a1c6-50d5f448aceb | @Override
public void windowDeactivated(WindowEvent arg0) {;} |
e25923d5-4275-47ff-8c3e-03e742b29a0a | @Override
public void windowDeiconified(WindowEvent arg0) {;} |
4702f687-2e77-480f-951b-b83bbc114551 | @Override
public void windowIconified(WindowEvent arg0) {;} |
56f63c47-416b-46b2-82ad-6d868ecc21b3 | @Override
public void windowOpened(WindowEvent arg0) {;} |
c9007d4e-d61f-417e-9c79-e68a2aff841c | public FilledSquare(Color c, int x, int y, int width) {
super(c, x, y, width, width);
} |
7166875f-19a3-426d-aa7a-33063b042d1a | public static void main(String[] args) {
// Show application
f.setSize(800,600);
f.setVisible(true);
f.setLocationRelativeTo(null);
// MenuBar can be seen as the MODEL
MenuBar bar = new MenuBar(); //create new menu bar
f.setMenuBar(bar); //add the menu bar to the frame
Menu fileMenu = new Menu("File"); //create the first menu item: file
MenuItem open = new MenuItem("Open"); //this is the flydown window that can be added to any menu item
MenuItem save = new MenuItem("Save -- (save as a .txt)");
// Add opener controller
Opener o = new Opener(f);
open.addActionListener(o);
// Add saving controller
save.addActionListener(new Saver(f, o));
fileMenu.add(open); //add 'open' to 'file'
fileMenu.add(save); // add 'save' to 'file'
bar.add(fileMenu);
// Add a Closer to exit program
f.addWindowListener(new Closer());
} |
1e54f42d-50be-4f02-8300-0976917ad310 | public FilledRectangle(Color color, int x, int y, int width, int height) {
super(color);
this.x = x;
this.y = y;
this.width = width;
this.height = height;
} |
0eb2ee6e-b496-4fd0-b4ad-07253b9b9bca | public void paintRectangle(Graphics g) {
g.setColor(getColor());
g.fillRect(x, y, width, height);
} |
0eeedb2b-35f4-4f07-8e2c-f642304154ee | public Opener(Frame app) {
this.app = app;
} |
bfb12bb5-0371-42b7-8568-0c5e56bf2b8a | @Override
public void actionPerformed(ActionEvent ae) {
// Pop up a file dialog
FileDialog open = new FileDialog(app);
open.setVisible(true);
// Get the received file + dir and save it as a single string for convenience
String path = open.getDirectory() + open.getFile();
try{
// Open the file that is the first command line parameter
FileInputStream fstream = new FileInputStream(path);
// Get the object of DataInputStream
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
// Create variable to hold each phrase and dimensions
String strLine;
// Read File Line By Line and add to arraylist
while ((strLine = br.readLine()) != null) {
oldPhrase.add(new OrigOutput(strLine));
}
// Close the input stream
in.close();
}catch (IOException ioe){// Catch exception if any
System.err.println("Error: " + ioe.getMessage());
}
/*
* For loop to iterate through every word of the .txt file to assign them to the
* InputSaver ArrayList
*/
for(int i = 0; i < oldPhrase.size(); i++){
String[] pData = oldPhrase.get(i).p.split(" ");
if(pData[0].equals("line")){
newPhrase.add(new InputSaver(pData[0], pData[1], pData[2], pData[3], pData[4]));
}
// Since some shapes don't have a 4th element, it is replaced with an empty string
else if(pData[0].equals("circle")){
newPhrase.add(new InputSaver(pData[0], pData[1], pData[2], pData[3], ""));
}
else if(pData[0].equals("filledcircle")){
newPhrase.add(new InputSaver(pData[0], pData[1], pData[2], pData[3], ""));
}
else if(pData[0].equals("rectangle")){
newPhrase.add(new InputSaver(pData[0], pData[1], pData[2], pData[3], pData[4]));
}
else if(pData[0].equals("filledrectangle")){
newPhrase.add(new InputSaver(pData[0], pData[1], pData[2], pData[3], pData[4]));
}
else if(pData[0].equals("square")){
newPhrase.add(new InputSaver(pData[0], pData[1], pData[2], pData[3], ""));
}
else if(pData[0].equals("filledsquare")){
newPhrase.add(new InputSaver(pData[0], pData[1], pData[2], pData[3], ""));
}
else if(pData[0].equals("color")){
newPhrase.add(new InputSaver(pData[0], pData[1], pData[2], pData[3], ""));
}
// Catches invalid phrase in .txt
else{
System.out.println("Invalid Shape: " + pData[0]);
}
}// End for loop
// Create new screen when file is opened so the screen knows what data to draw
Painting s = new Painting(this);
// Add the screen the main frame and repack
Main.f.add(s);
Main.f.pack();
}// End actionPerformed |
93e8ca62-d791-4e86-9028-01003b615bae | public Circle(Color color, int x, int y, int radius) {
super(color);
this.x = x;
this.y = y;
this.radius = radius;
} |
78492c4c-f353-43d7-a5ab-6d2514c63537 | public void paintCircle(Graphics g) {
g.setColor(getColor());
g.drawOval(x, y, radius*2, radius*2);
} |
02acf27f-97d0-44b6-a69b-431eb9fcc829 | public Shape(Color color) {
this.color = color;
} |
36beee1f-d658-4229-880d-362c67b81533 | public Color getColor(){
return this.color;
} |
083f129e-1c51-46e5-a9d8-1c3a9b320150 | public Saver(Frame app, Opener o) {
this.app = app;
op = o;
} |
3e4fb90b-963d-4baf-9a07-fc1ae18566f9 | @Override
public void actionPerformed(ActionEvent ae) {
// Pop up a file dialog
FileDialog open = new FileDialog(app);
open.setVisible(true);
// Assign directory and file to single variable for convenience
String path = open.getDirectory() + open.getFile();
try{
// Create file
FileWriter fstream = new FileWriter(path);
BufferedWriter out = new BufferedWriter(fstream);
// Write out every element left in the ArrayList to the .txt file
for(InputSaver p : op.newPhrase){
// If statement to make sure removed strings do not get written to file
if(!p.phrase.equals("")){
out.write(p.phrase + " " + p.xCoord + " " + p.yCoord +
" " + p.var1 + " " + p.var2);
out.newLine();
}
}
//Close the output stream
out.close();
}catch (Exception e){//Catch exception if any
System.err.println("Error: " + e.getMessage());
}
}// End actionPerformed |
90b5f4cd-5662-4062-863b-cc076f356e5d | public Square(Color color, int x, int y, int width) {
super(color, x, y, width, width);
} |
fb0ab7b5-02d7-4a6f-9a4c-c1e9efb3bf32 | public static void main(String[] args) {
final Ruang2D R2D = new Ruang2D("data/model.xls", WINDOW_WIDTH, WINDOW_HEIGHT);
frame.setContentPane(R2D);
frame.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
// Use a dedicate thread to run the stop() to ensure that the
// animator stops before program exits.
new Thread() {
@Override
public void run() {
R2D.animator.stop(); // stop the animator loop
System.exit(0);
}
}.start();
}
});
frame.setSize(WINDOW_WIDTH, WINDOW_HEIGHT);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
R2D.animator.start(); // start the animation loop
} |
27636f83-db6c-4944-b185-972262bf2bc5 | @Override
public void windowClosing(WindowEvent e) {
// Use a dedicate thread to run the stop() to ensure that the
// animator stops before program exits.
new Thread() {
@Override
public void run() {
R2D.animator.stop(); // stop the animator loop
System.exit(0);
}
}.start();
} |
49a2c5fe-5c32-4531-ab17-5b29c6621a4a | @Override
public void run() {
R2D.animator.stop(); // stop the animator loop
System.exit(0);
} |
b47184b0-19a8-454c-8759-0824b3dc8c96 | public Camera () {
width = 800;
height = 600;
camx = 0;
camy = 0;
} |
e342d511-8168-4532-a9a1-3d0fc73a0938 | public Camera (int _lx, int _ly, float _cx, float _cy, float _jarak) {
width = _lx;
height = _ly;
camx = _cx;
camy = _cy;
jarak = _jarak;
} |
8605da6c-0b70-4812-9f7c-14ec106ac425 | public float getJarak () {
return jarak;
} |
d9cdaef4-a6e2-4842-a0c0-f3e1c26b7384 | public void refreshWidthHeight(int x, int y) {
width = x;
height = y;
} |
2ebe05ac-fc22-47c7-a670-b24e836f813c | public void initCamera(GL gl, GLU glu) {
// Change to projection matrix.
gl.glMatrixMode(GL.GL_PROJECTION);
gl.glLoadIdentity();
// Perspective.
float widthHeightRatio = (float) width / (float) height;
glu.gluPerspective(45, widthHeightRatio, 1, 1000);
glu.gluLookAt(camx, camy, jarak, camx, camy, 0, 0, 1, 0);
// Change back to model view matrix.
gl.glMatrixMode(GL.GL_MODELVIEW);
gl.glLoadIdentity();
} |
d6e92879-17be-4057-9ff0-b9bc3612a945 | public void zoom(GL gl, GLU glu, int x) {
jarak += x;
} |
4685d27a-bb0e-4a3d-999a-5c46358594cb | public void geser(GL gl, GLU glu, float x, float y) {
camx += x;
camy += y;
} |
e216fa6a-b364-4c1f-a73c-12c9bfb80dab | public void setInputFile(String inputFile) {
this.inputFile = inputFile;
} |
c105a371-620d-4d21-954f-0359df5c4fed | public void read() throws IOException {
int nomor = 1;
File inputWorkbook = new File(inputFile);
Workbook w;
try {
w = Workbook.getWorkbook(inputWorkbook);
// Get the first sheet
Sheet sheet = w.getSheet(0);
// Loop over first 10 column and lines
MatriksKecepatan MV = new MatriksKecepatan(sheet.getRows(),sheet.getColumns());
for (int i = 0; i < sheet.getRows(); i++) {
for (int j = 0; j < sheet.getColumns(); j++) {
Cell cell = sheet.getCell(j, i);
CellType type = cell.getType();
MV.isiMatriks(i, j, cell.getContents());
// if (cell.getType() == CellType.LABEL) {
// System.out.println(" "+ cell.getContents());
// }
//
//
// if (cell.getType() == CellType.EMPTY) {
// System.out.println("");
// }
//
// if (cell.getType() == CellType.NUMBER) {
// //System.out.print(nomor +") " + cell.getContents());
// System.out.print(" " + cell.getContents());
// nomor++;
//// if (cell.getType() == CellType.EMPTY){
//// System.out.print("\n");
//// }
// }
}
}
MV.printMatriks();
//MV.printCell(28,4 );
//System.out.println(MV.MaxNumber());
//System.out.println(MV.MinNumber());
} catch (BiffException e) {
e.printStackTrace();
}
} |
45a8be21-4078-4403-9ca5-d516d83e7a84 | public MatriksKecepatan readtomv() throws IOException {
int nomor = 1;
File inputWorkbook = new File(inputFile);
Workbook w;
MatriksKecepatan MV = new MatriksKecepatan(1,1);
try {
w = Workbook.getWorkbook(inputWorkbook);
// Get the first sheet
Sheet sheet = w.getSheet(0);
// Loop over first 10 column and lines
MV = new MatriksKecepatan(sheet.getRows(),sheet.getColumns());
for (int i = 0; i < sheet.getRows(); i++) {
for (int j = 0; j < sheet.getColumns(); j++) {
Cell cell = sheet.getCell(j, i);
CellType type = cell.getType();
MV.isiMatriks(i, j, cell.getContents());
}
}
} catch (BiffException e) {
e.printStackTrace();
}
return MV;
} |
21376e1e-ce38-4983-87ef-299b839792db | public MatriksKecepatan() {
M = 1;
N = 1;
data = new String[M][N];
for (int i=0;i<M;i++){
for(int j=0;j<N;j++){
data[i][j]="0";
}
}
} |
10518120-510a-424f-824e-e89c9c23c77f | public MatriksKecepatan(int a, int b) {
M=a;
N=b;
data = new String[M][N];
for (int i=0;i<M;i++){
for(int j=0;j<N;j++){
data[i][j]=Float.toString(0f);
}
}
} |
d4f18f6b-c2cb-4cd6-ac10-a3cbf499a1a1 | public MatriksKecepatan(MatriksKecepatan _mk) {
M=_mk.M;
N=_mk.N;
data = new String[M][N];
for (int i=0;i<M;i++){
for(int j=0;j<N;j++){
isiMatriks(i,j, Float.toString(_mk.getFloatData(i, j)));
}
}
} |
619db7b8-a753-4661-aa74-192a3b232d8a | public int getIntData(int i, int j){
int x = Integer.decode(data[i][j]);
return x;
} |
7685bd71-9354-4fff-ad97-6bc73c66c8b6 | public float getFloatData(int i, int j){
float x = Float.valueOf(data[i][j]);
return x;
} |
837e7ef9-bc31-4133-976c-2b335585cc5e | public void printMatriks(){
for (int i=0; i<M; i++){
for (int j=0; j<N; j++){
System.out.print (" "+ data[i][j]);
}
System.out.println("");
}
} |
9bb8b96a-adb4-42af-951c-50dfe68de006 | public void printCell(int i, int j){
System.out.println(data[i][j]);
} |
c2b5a0bb-05bc-4cc5-9f0b-f861a2b14cf0 | public void isiMatriks (int i, int j, String a){
data[i][j] = a;
} |
a3575b81-36bc-48cd-8635-624c3aa020dd | private float MaxNumber(){
float max=-9999999f;
for (int i=0;i<M;i++){
for (int j=0;j<N;j++){
if (getFloatData(i,j) > max){
max = getFloatData(i,j) ;
}else{
}
}
}
return max;
} |
f2de8be7-4626-4e2b-b71f-ad31b86d8053 | private float MinNumber(){
float min=9999999f;
for (int i=0;i<M;i++){
for (int j=0;j<N;j++){
if (getFloatData(i,j) < min){
min = getFloatData(i,j) ;
}else{
}
}
}
return min;
} |
2d7125ea-0baa-463c-9192-4b3b21cd196f | public void setMaxMinVal() {
MaxVal = MaxNumber();
MinVal = MinNumber();
// System.out.println("asd"+MinVal);
} |
05f2076b-cead-4edb-858f-94a01fc18ea7 | public float getmaxv() { return MaxVal; } |
e68cc31d-5183-4587-b020-75009c7f0ce9 | public float getminv() { return MinVal; } |
b3f9a127-cd68-4016-828a-a3fe5b171e59 | public int getP() { return M;} |
42b5fa20-ceae-449f-a07f-fcd1ece5de5b | public int getL() { return N;} |
6d507a38-e535-4658-a3f8-f5c904495590 | public Ruang2D() {
canvas = new GLCanvas();
this.setLayout(new BorderLayout());
this.add(canvas, BorderLayout.CENTER);
canvas.addGLEventListener(this);
// Run the animation loop using the fixed-rate Frame-per-second animator, which calls back display() at this fixed-rate (FPS).
animator = new FPSAnimator(canvas, REFRESH_FPS, true);
jarak = 150;
layarx = 600;
layary = 480;
sbatas = 0;
ReaderExcel Reader = new ReaderExcel();
Reader.setInputFile("data/model.xls");
MatriksKecepatan MK = new MatriksKecepatan(96,96);
// try {
// MK = Reader.readtomv();
// } catch (IOException ex) {}
penggambar = new Penggambar(MK);
kamera = new Camera(layarx, layary, penggambar.getnx()/2, penggambar.getny()/2, jarak);
} |
b9269a2d-4be5-4384-8129-c05d461072b7 | public Ruang2D(String File, int _layarx, int _layary) {
canvas = new GLCanvas();
this.setLayout(new BorderLayout());
this.add(canvas, BorderLayout.CENTER);
canvas.addGLEventListener(this);
// Run the animation loop using the fixed-rate Frame-per-second animator, which calls back display() at this fixed-rate (FPS).
animator = new FPSAnimator(canvas, REFRESH_FPS, true);
jarak = 150;
layarx = _layarx;
layary = _layary;
ReaderExcel Reader = new ReaderExcel();
Reader.setInputFile(File);
MatriksKecepatan MK = new MatriksKecepatan(1,1);
try {
MK = Reader.readtomv();
} catch (IOException ex) {}
penggambar = new Penggambar(MK);
kamera = new Camera(layarx, layary, penggambar.getnx()/2, penggambar.getny()/2, jarak);
} |
02388470-703d-44f5-9826-15455dee8fa9 | public Ruang2D(int _layarx, int _layary) {
canvas = new GLCanvas();
this.setLayout(new BorderLayout());
this.add(canvas, BorderLayout.CENTER);
canvas.addGLEventListener(this);
// Run the animation loop using the fixed-rate Frame-per-second animator, which calls back display() at this fixed-rate (FPS).
animator = new FPSAnimator(canvas, REFRESH_FPS, true);
jarak = 150;
layarx = _layarx;
layary = _layary;
MatriksKecepatan MK = new MatriksKecepatan(100,100);
penggambar = new Penggambar(MK);
kamera = new Camera(layarx, layary, penggambar.getnx()/2, penggambar.getny()/2, jarak);
} |
0dc52591-2174-4255-bc6b-471e08025f92 | public void init(GLAutoDrawable drawable) {
// Use debug pipeline: drawable.setGL(new DebugGL(drawable.getGL()));
gl = drawable.getGL();
System.err.println("INIT GL IS: " + gl.getClass().getName());
// Setup the drawing area and shading mode
gl.glShadeModel(GL.GL_SMOOTH); // try setting this to GL_FLAT and see what happens.
gl.glClearColor(1.0f, 1.0f, 1.0f, 0.0f);
// Setup the depth buffer and enable the depth testing
gl.glClearDepth(1.0f); // clear z-buffer to the farthest
gl.glEnable(GL.GL_DEPTH_TEST); // enables depth testing
gl.glDepthFunc(GL.GL_LEQUAL); // the type of depth test to do
// Do the best perspective correction
gl.glHint(GL.GL_PERSPECTIVE_CORRECTION_HINT, GL.GL_NICEST);
drawable.addMouseListener(this);
drawable.addMouseMotionListener(this);
drawable.addMouseWheelListener(this);
penggambar.tes();
} |
afaeffd4-9346-45c0-b618-92d42fc918a5 | public void display(GLAutoDrawable drawable) {
gl = drawable.getGL();
glu = new GLU();
gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); // Clear the drawing area
gl.glLoadIdentity(); // Reset the current matrix to the "identity"
// --------------------------------------------------------\
// -- Penting! untuk kamera
kamera.refreshWidthHeight(getWidth(), getHeight());
kamera.initCamera(gl, glu);
// penggambar.test_pelangi();
penggambar.gambar_mk_kotakwarna(gl);
// --------------------------------------------------------
// Flush all drawing operations to the graphics card
gl.glFlush();
} |
68aefaa9-259d-420d-ae03-3adad3cad530 | public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {
gl = drawable.getGL();
height = (height == 0) ? 1 : height; // prevent divide by zero
float aspect = (float)width / height;
// Set the current view port to cover full screen
gl.glViewport(0, 0, width, height);
// Set up the projection matrix - choose perspective view
gl.glMatrixMode(GL.GL_PROJECTION);
gl.glLoadIdentity(); // reset
// Angle of view (fovy) is 45 degrees (in the up y-direction). Based on this
// canvas's aspect ratio. Clipping z-near is 0.1f and z-near is 100.0f.
glu.gluPerspective(45.0f, aspect, 0.1f, 100.0f); // fovy, aspect, zNear, zFar
// Enable the model-view transform
gl.glMatrixMode(GL.GL_MODELVIEW);
gl.glLoadIdentity(); // reset
} |
66171927-888a-4b5a-b632-1d5ed2a00062 | @Override
public void mouseWheelMoved(MouseWheelEvent e) {
int n = e.getWheelRotation();
// if(n>0)
// sbatas +=(int)(penggambar.OMK.getmaxv()/1000);
// MatriksKecepatan MK2 = penggambar.MK;
// for (int k=0;k<MK2.getP();k++){
// for(int l=0;l<MK2.getL();l++){
// MK2.data[l][k] = (Float.parseFloat(MK2.data[l][k])> MK2.getmaxv()-sbatas)? Float.toString(MK2.getmaxv()-sbatas) : MK2.data[l][k];
// }
// }
// penggambar.MK = (sbatas<penggambar.OMK.getmaxv()) ? MK2 : penggambar.OMK;
// penggambar.MK.setMaxMinVal();
// System.out.println(sbatas+" "+penggambar.OMK.getmaxv()+" "+penggambar.MK.getmaxv());
if(n>0)
kamera.zoom(gl, glu, 5);
else
kamera.zoom(gl, glu, -5);
//System.out.println(kamera.getJarak());
} |
7ac8d9de-e551-4ce9-abf4-35e8a7522190 | public void mousePressed(MouseEvent e) {
newx=e.getXOnScreen();
newy=e.getYOnScreen();
oldx=newx;
oldy=newy;
} |
d4b87856-d1ac-4d90-bdf5-c8d25bb48a5c | public void mouseDragged(MouseEvent e) {
newx=e.getXOnScreen();
newy=e.getYOnScreen();
kamera.geser(gl, glu, (-newx+oldx), (newy-oldy));
oldx=newx;
oldy=newy;
} |
f73066ee-48b8-42dd-b02a-6f36f8d2a92f | public void mouseEntered(MouseEvent e) {} |
3295ed94-dfe2-454c-9e16-03cc96165265 | public void mouseExited(MouseEvent e) {} |
70aaef21-ddfc-4784-be70-d70abd57d088 | public void mouseReleased(MouseEvent e) {} |
bd492418-5989-468d-847a-baefe5589369 | public void mouseClicked(MouseEvent e) {} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.