Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
COMP90015-DSAss2-InfinityMonkeys-remaster
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
RUNZHE WANG
COMP90015-DSAss2-InfinityMonkeys-remaster
Commits
21e3ad35
Commit
21e3ad35
authored
Oct 22, 2019
by
Chang Che Hao
Browse files
Options
Downloads
Patches
Plain Diff
Replace DrawingArea.java
parent
795499fb
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/client/DrawingArea.java
+142
-58
142 additions, 58 deletions
src/client/DrawingArea.java
with
142 additions
and
58 deletions
src/client/DrawingArea.java
+
142
−
58
View file @
21e3ad35
package
client
;
import
javax.imageio.ImageIO
;
import
javax.imageio.ImageIO
;
import
javax.swing.*
;
import
javax.swing.*
;
import
java.awt.*
;
import
java.awt.*
;
...
@@ -15,7 +17,7 @@ import java.io.IOException;
...
@@ -15,7 +17,7 @@ import java.io.IOException;
public
class
DrawingArea
extends
JPanel
{
public
class
DrawingArea
extends
JPanel
{
/// enum for all different mode ///
/// enum for all different mode ///
enum
Mode
{
FREEHAND
,
LINE
,
CIRCLE
,
RECTANGLE
,
OVAL
,
ERASE
}
enum
Mode
{
FREEHAND
,
LINE
,
CIRCLE
,
RECTANGLE
,
OVAL
,
ERASE
,
TEXT
}
/// Canvas size parameter ///
/// Canvas size parameter ///
private
final
static
int
AREA_WIDTH
=
600
;
private
final
static
int
AREA_WIDTH
=
600
;
...
@@ -33,6 +35,10 @@ public class DrawingArea extends JPanel {
...
@@ -33,6 +35,10 @@ public class DrawingArea extends JPanel {
/// Default mode and color ///
/// Default mode and color ///
private
Color
shapeColor
=
new
Color
(
0
,
0
,
0
);
private
Color
shapeColor
=
new
Color
(
0
,
0
,
0
);
private
Mode
currentMode
=
Mode
.
FREEHAND
;
private
Mode
currentMode
=
Mode
.
FREEHAND
;
private
Stroke
lineStroke
=
new
BasicStroke
(
3
);
private
int
eraserSize
=
10
;
private
int
textSize
=
60
;
private
String
textString
=
"Test"
;
/// Shape to be drawn on the canvas ///
/// Shape to be drawn on the canvas ///
private
Shape
drawing
;
private
Shape
drawing
;
...
@@ -79,6 +85,42 @@ public class DrawingArea extends JPanel {
...
@@ -79,6 +85,42 @@ public class DrawingArea extends JPanel {
drawing
=
new
Rectangle2D
.
Double
();
drawing
=
new
Rectangle2D
.
Double
();
break
;
break
;
case
TEXT:
g2
.
setFont
(
new
Font
(
"TimesRoman"
,
Font
.
PLAIN
,
textSize
));
g2
.
drawString
(
textString
,
startPoint
.
x
,
startPoint
.
y
);
// FontRenderContext frc = g2.getFontRenderContext();
// Font f = new Font("Helvetica", Font.PLAIN, textSize);
// TextLayout textTl = new TextLayout(textString, f, frc);
//// AffineTransform transform = new AffineTransform();
// drawing = textTl.getOutline(null);
//// transform = g2.getTransform();
//// transform.translate(startPoint.x, startPoint.y);
//// g2.transform(transform);
//// g2.fill(drawing);
// Font f = getFont().deriveFont(Font.BOLD, 70);
// GlyphVector v = f.createGlyphVector(getFontMetrics(f).getFontRenderContext(), "Hello");
// v.setGlyphPosition(0, startPoint);
// v.setGlyphPosition(1, startPoint);
// v.setGlyphPosition(2, startPoint);
// v.setGlyphPosition(3, startPoint);
// v.setGlyphPosition(4, startPoint);
// drawing = v.getOutline();
// drawing.
// g2.setPaint(Color.BLUE);
// g2.draw(drawing);
break
;
}
}
}
}
});
});
...
@@ -101,6 +143,7 @@ public class DrawingArea extends JPanel {
...
@@ -101,6 +143,7 @@ public class DrawingArea extends JPanel {
((
Line2D
)
drawing
).
setLine
(
currentPoint
,
previousPoint
);
((
Line2D
)
drawing
).
setLine
(
currentPoint
,
previousPoint
);
g2
.
setColor
(
shapeColor
);
g2
.
setColor
(
shapeColor
);
g2
.
setStroke
(
lineStroke
);
g2
.
draw
(
drawing
);
g2
.
draw
(
drawing
);
previousPoint
=
currentPoint
;
previousPoint
=
currentPoint
;
break
;
break
;
...
@@ -114,7 +157,7 @@ public class DrawingArea extends JPanel {
...
@@ -114,7 +157,7 @@ public class DrawingArea extends JPanel {
/// Eraser is continuously drawing "small white circle" from current point to previous point ///
/// Eraser is continuously drawing "small white circle" from current point to previous point ///
case
ERASE:
case
ERASE:
((
Ellipse2D
)
drawing
).
setFrame
(
currentPoint
.
getX
(),
currentPoint
.
getY
(),
10
,
10
);
((
Ellipse2D
)
drawing
).
setFrame
(
currentPoint
.
getX
(),
currentPoint
.
getY
(),
eraserSize
,
eraserSize
);
g2
.
setColor
(
Color
.
WHITE
);
g2
.
setColor
(
Color
.
WHITE
);
g2
.
fill
(
drawing
);
g2
.
fill
(
drawing
);
g2
.
draw
(
drawing
);
g2
.
draw
(
drawing
);
...
@@ -139,6 +182,17 @@ public class DrawingArea extends JPanel {
...
@@ -139,6 +182,17 @@ public class DrawingArea extends JPanel {
((
Rectangle2D
)
drawing
).
setFrame
(
x
,
y
,
width
,
height
);
((
Rectangle2D
)
drawing
).
setFrame
(
x
,
y
,
width
,
height
);
break
;
break
;
case
TEXT:
break
;
// AffineTransform transform = new AffineTransform();
// transform.translate(currentPoint.x, currentPoint.y);
// g2.transform(transform);
// g2.fill(drawing);
}
}
repaint
();
repaint
();
...
@@ -277,70 +331,100 @@ public class DrawingArea extends JPanel {
...
@@ -277,70 +331,100 @@ public class DrawingArea extends JPanel {
currentMode
=
Mode
.
ERASE
;
currentMode
=
Mode
.
ERASE
;
}
}
/// Drawing color setters ///
public
void
setModeText
(
String
string
,
int
size
)
{
currentMode
=
Mode
.
TEXT
;
public
void
setColorAqua
()
{
textString
=
string
;
shapeColor
=
new
Color
(
0
,
255
,
255
);
textSize
=
size
;
}
public
void
setColorBlack
()
{
shapeColor
=
new
Color
(
0
,
0
,
0
);
}
public
void
setColorBlue
()
{
shapeColor
=
new
Color
(
0
,
0
,
255
);
}
public
void
setColorFuchsia
()
{
shapeColor
=
new
Color
(
255
,
0
,
255
);
}
public
void
setColorGray
()
{
shapeColor
=
new
Color
(
128
,
128
,
128
);
}
public
void
setColorGreen
()
{
shapeColor
=
new
Color
(
0
,
128
,
0
);
}
public
void
setColorLime
()
{
shapeColor
=
new
Color
(
0
,
255
,
0
);
}
public
void
setColorMaroon
()
{
shapeColor
=
new
Color
(
128
,
0
,
0
);
}
public
void
setColorNavy
()
{
shapeColor
=
new
Color
(
0
,
0
,
128
);
}
}
public
void
setColorOlive
()
{
/// Drawing color setters ///
shapeColor
=
new
Color
(
128
,
128
,
0
);
}
public
void
setColorPurple
()
{
shapeColor
=
new
Color
(
128
,
0
,
128
);
}
public
void
setColorRed
()
{
shapeColor
=
new
Color
(
255
,
0
,
0
);
}
public
void
setColorSilver
()
{
shapeColor
=
new
Color
(
192
,
192
,
192
);
}
public
void
setColorTeal
()
{
shapeColor
=
new
Color
(
0
,
128
,
128
);
}
public
void
setColorWhite
()
{
shapeColor
=
new
Color
(
255
,
255
,
255
);
}
public
void
setColorYellow
()
{
public
void
setColor
(
Color
color
)
{
shapeColor
=
new
Color
(
255
,
255
,
0
);
shapeColor
=
color
;
}
}
/// Drawing stroke setter ///
public
void
setStroke
(
int
size
)
{
lineStroke
=
new
BasicStroke
(
size
);
}
public
void
setEraserSize
(
int
size
)
{
eraserSize
=
size
;
}
//
///// Font setter ///
//
// public void setText(String text, int size) {
//
// textString = text;
// textSize = size;
//
// }
//
// public void setColorAqua() {
// shapeColor = new Color(0,255, 255);
// }
//
// public void setColorBlack() {
// shapeColor = new Color(0, 0, 0);
// }
//
// public void setColorBlue() {
// shapeColor = new Color(0, 0, 255);
// }
//
// public void setColorFuchsia() {
// shapeColor = new Color(255, 0, 255);
// }
//
// public void setColorGray() {
// shapeColor = new Color(128, 128, 128);
// }
//
// public void setColorGreen() {
// shapeColor = new Color(0, 128, 0);
// }
//
// public void setColorLime() {
// shapeColor = new Color(0, 255, 0);
// }
//
// public void setColorMaroon() {
// shapeColor = new Color(128,0, 0);
// }
//
// public void setColorNavy() {
// shapeColor = new Color(0, 0, 128);
// }
//
// public void setColorOlive() {
// shapeColor = new Color(128, 128, 0);
// }
//
// public void setColorPurple() {
// shapeColor = new Color(128, 0, 128);
// }
//
// public void setColorRed() {
// shapeColor = new Color(255, 0, 0);
// }
//
// public void setColorSilver() {
// shapeColor = new Color(192, 192, 192);
// }
//
// public void setColorTeal() {
// shapeColor = new Color(0, 128, 128);
// }
//
// public void setColorWhite() {
// shapeColor = new Color(255, 255, 255);
// }
//
// public void setColorYellow() {
// shapeColor = new Color(255, 255, 0);
// }
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment