-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Getting start for M5
- Loading branch information
Luke Zhang
committed
Jan 27, 2016
1 parent
f2de6d2
commit 4516fa4
Showing
56 changed files
with
2,169 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<classpath> | ||
<classpathentry kind="src" path="src"/> | ||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/> | ||
<classpathentry kind="output" path="bin"/> | ||
</classpath> |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<projectDescription> | ||
<name>Lab2-1-Lib</name> | ||
<comment></comment> | ||
<projects> | ||
</projects> | ||
<buildSpec> | ||
<buildCommand> | ||
<name>org.eclipse.jdt.core.javabuilder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
</buildSpec> | ||
<natures> | ||
<nature>org.eclipse.jdt.core.javanature</nature> | ||
</natures> | ||
</projectDescription> |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
eclipse.preferences.version=1 | ||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled | ||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 | ||
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve | ||
org.eclipse.jdt.core.compiler.compliance=1.7 | ||
org.eclipse.jdt.core.compiler.debug.lineNumber=generate | ||
org.eclipse.jdt.core.compiler.debug.localVariable=generate | ||
org.eclipse.jdt.core.compiler.debug.sourceFile=generate | ||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error | ||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error | ||
org.eclipse.jdt.core.compiler.source=1.7 |
116 changes: 116 additions & 0 deletions
116
lab2-1/lab2-1-lib/src/edu/roshulman/csse374/editor/TextEditor.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
package edu.roshulman.csse374.editor; | ||
|
||
import java.awt.BorderLayout; | ||
import java.awt.Dimension; | ||
import java.awt.event.WindowAdapter; | ||
import java.awt.event.WindowEvent; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.io.OutputStream; | ||
|
||
import javax.swing.JFrame; | ||
import javax.swing.JLabel; | ||
import javax.swing.JScrollPane; | ||
import javax.swing.JTextArea; | ||
|
||
/** | ||
* <p> | ||
* The awesomest text editor ever developed in the | ||
* awesomest language ever created by humans! | ||
* </p> | ||
* | ||
* <p> | ||
* It reads the text from the supplied {@link InputStream} and writes the text to | ||
* the supplied {@link OutputStream} when a user closes the application. | ||
* </p> | ||
* | ||
* @author Chandan R. Rupakheti ([email protected]) | ||
*/ | ||
public class TextEditor { | ||
private JFrame frame; | ||
|
||
private JScrollPane scrollPane; | ||
private JTextArea textArea; | ||
private JLabel label; | ||
|
||
private InputStream in; | ||
private OutputStream out; | ||
private String text; | ||
|
||
|
||
/** | ||
* Create the text editor object with the supplied parameters. | ||
* | ||
* @param in Take in an {@link InputStream} to read the input file from. | ||
* @param out Write the final text to the supplied {@link OutputStream} | ||
* when the user closes the application. | ||
*/ | ||
public TextEditor(InputStream in, OutputStream out) { | ||
this.in = in; | ||
this.out = out; | ||
|
||
this.text = ""; | ||
try { | ||
StringBuffer buffer = new StringBuffer(); | ||
int input = 0; | ||
while((input = in.read()) != -1) { | ||
buffer.append((char)input); | ||
} | ||
in.close(); | ||
text = buffer.toString(); | ||
} | ||
catch(Exception e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
protected void createAndShowGUI() { | ||
frame = new JFrame("Awesomest Text Viewer"); | ||
|
||
textArea = new JTextArea(text,20, 60); | ||
textArea.setPreferredSize(new Dimension(800, 600)); | ||
textArea.setLineWrap(true); | ||
scrollPane = new JScrollPane(textArea); | ||
scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); | ||
|
||
// Add the scroll pane to the center of the window | ||
frame.add(scrollPane, BorderLayout.CENTER); | ||
|
||
// Add the label as status | ||
label = new JLabel("Ready"); | ||
frame.add(label, BorderLayout.SOUTH); | ||
|
||
frame.addWindowListener(new WindowAdapter() { | ||
|
||
@Override | ||
public void windowClosing(WindowEvent e) { | ||
super.windowClosing(e); | ||
|
||
try { | ||
for(char c: textArea.getText().toCharArray()) { | ||
out.write(c); | ||
} | ||
out.close(); | ||
} catch (IOException e1) { | ||
e1.printStackTrace(); | ||
} | ||
} | ||
}); | ||
|
||
frame.pack(); | ||
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); | ||
frame.setVisible(true); | ||
} | ||
|
||
public void execute() throws Exception { | ||
//Schedule a job for the event-dispatching thread: | ||
//creating and showing this application's GUI. | ||
javax.swing.SwingUtilities.invokeLater(new Runnable() { | ||
public void run() { | ||
// Basically, shows up the GUI. | ||
createAndShowGUI(); | ||
} | ||
}); | ||
} | ||
|
||
} |
24 changes: 24 additions & 0 deletions
24
lab2-1/lab2-1-lib/src/headfirst/decorator/io/InputTest.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package headfirst.decorator.io; | ||
|
||
import java.io.*; | ||
|
||
public class InputTest { | ||
public static void main(String[] args) throws IOException { | ||
int c; | ||
|
||
try { | ||
InputStream in = | ||
new LowerCaseInputStream( | ||
new BufferedInputStream( | ||
new FileInputStream("./input_output/in.txt"))); | ||
|
||
while((c = in.read()) >= 0) { | ||
System.out.print((char)c); | ||
} | ||
|
||
in.close(); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
lab2-1/lab2-1-lib/src/headfirst/decorator/io/LowerCaseInputStream.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package headfirst.decorator.io; | ||
|
||
import java.io.*; | ||
|
||
public class LowerCaseInputStream extends FilterInputStream { | ||
|
||
public LowerCaseInputStream(InputStream in) { | ||
super(in); | ||
} | ||
|
||
public int read() throws IOException { | ||
int c = super.read(); | ||
return (c == -1 ? c : Character.toLowerCase((char)c)); | ||
} | ||
|
||
public int read(byte[] b, int offset, int len) throws IOException { | ||
int result = super.read(b, offset, len); | ||
for (int i = offset; i < offset+result; i++) { | ||
b[i] = (byte)Character.toLowerCase((char)b[i]); | ||
} | ||
return result; | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<classpath> | ||
<classpathentry kind="src" path="src"/> | ||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/> | ||
<classpathentry kind="src" path="test"/> | ||
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/> | ||
<classpathentry combineaccessrules="false" kind="src" path="/Lab2-1-Lib"/> | ||
<classpathentry kind="output" path="bin"/> | ||
</classpath> |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<projectDescription> | ||
<name>Lab2-1-Solution</name> | ||
<comment></comment> | ||
<projects> | ||
</projects> | ||
<buildSpec> | ||
<buildCommand> | ||
<name>org.eclipse.jdt.core.javabuilder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
</buildSpec> | ||
<natures> | ||
<nature>org.eclipse.jdt.core.javanature</nature> | ||
</natures> | ||
</projectDescription> |
11 changes: 11 additions & 0 deletions
11
lab2-1/lab2-1-solution/.settings/org.eclipse.jdt.core.prefs
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
eclipse.preferences.version=1 | ||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled | ||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 | ||
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve | ||
org.eclipse.jdt.core.compiler.compliance=1.7 | ||
org.eclipse.jdt.core.compiler.debug.lineNumber=generate | ||
org.eclipse.jdt.core.compiler.debug.localVariable=generate | ||
org.eclipse.jdt.core.compiler.debug.sourceFile=generate | ||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error | ||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error | ||
org.eclipse.jdt.core.compiler.source=1.7 |
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.