id
stringlengths 36
36
| text
stringlengths 1
1.25M
|
---|---|
ab3531f1-44a1-4344-bdae-5abcdd9f3aa1
|
public Light(int x, int y, Level handle) {
hLevel = handle;
pos = new Point(x, y);
wpos = new Point(x / Level.CELL_SIZE, y / Level.CELL_SIZE);
isActive = true;
isOn = false;
//default color
// final double defR = 0.8235;
// final double defG = 0.7059;
// final double defB = 0.5098;
// setColor(defR, defG, defB);
Random gen = new Random();
setColor(gen.nextDouble(), gen.nextDouble(), gen.nextDouble());
//default radius
final short defRadius = 100;
setRadius(defRadius);
}
|
89ec138b-5c79-4bb9-944f-5c988fa8e61a
|
private void updateBounds() {
bounds = new Rectangle(
pos.x - lightRadius,
pos.y - lightRadius,
lightRadius * 2,
lightRadius * 2);
}
|
57e6de8b-4e31-47f1-adf0-09f85d82e08d
|
public void setColor(double red, double green, double blue) {
r = red;
g = green;
b = blue;
}
|
d51ba11e-1396-4351-85de-fe1f39867ac4
|
public int getColor() {
return ((int) r) << R_SHIFT + ((int) g) << G_SHIFT + (int) b;
}
|
a1b9c4cf-b6c7-42dd-acb0-bd07cbce5592
|
public void setRadius(short radius) {
lightRadius = radius;
updateBounds();
updatePixels();
}
|
33ef0ef0-71a9-4754-b51c-3a8efad0b8cd
|
public Point getLight() {
return pos;
}
|
38e297a2-0ca9-47ae-853d-83b062c15c28
|
public Point getPos() {
return pos;
}
|
34434241-869d-4c21-b0f5-c5d9d50b2e82
|
public void setOn(boolean on) {
isActive = on;
}
|
aeb2b41c-e978-4fd4-9415-0b773a4c3b6f
|
public boolean isOn() {
return isOn;
}
|
179066fa-d22c-43a1-98ee-baf83519ba59
|
private double getDistance(int x1, int x2, int y1, int y2) {
x1 = x2 - x1;
y1 = y2 - y1;
return Math.sqrt(x1 * x1 + y1 * y1);
}
|
fdedc5a4-914c-41e1-9c5f-dfe5fe9d3413
|
public boolean isActive() {
return isActive;
}
|
ed5214d6-5ec8-42b4-8a9b-901b79ccb08a
|
@Override
public boolean isTriggered(Rectangle bbox) {
boolean result = (
pos.x > bbox.x
&& pos.x < (bbox.x + bbox.width)
&& pos.y > bbox.y
&& pos.y < (bbox.y + bbox.height)
&& System.currentTimeMillis() > timeSafe);
return result;
}
|
a86d319d-b039-44f7-85bf-a2384934bb13
|
@Override
public void triggerAction() {
//toggle light
timeSafe = System.currentTimeMillis() + COOLDOWN;
if (isOn) {
isOn = false;
//set world brick dark
hLevel.setCell(wpos.x, wpos.y, Texture.bgLightDead);
} else {
isOn = true;
//set world brick light
hLevel.setCell(wpos.x, wpos.y, Texture.bgLight);
}
//filter the world
}
|
18c082ff-d8ec-4776-bb17-3cfb3eb8dc4c
|
public void updatePixels() {
pixels = new double[lightRadius << 1][lightRadius << 1][Util.CHANNELS];
//Center of light glow
double dR;
double dG;
double dB;
double distance;
for (int x = 0, ix = bounds.width - 1;
x < lightRadius;
x++, ix--) {
for (int y = 0, iy = bounds.height - 1;
y < lightRadius;
y++, iy--) {
//Get pixel distance from light source
distance = getDistance(x, lightRadius, y, lightRadius);
/* Convert distance to 0:1 with 1 at the light
* and 0 at the perimeter circle. Clamp negatives.*/
distance = Math.max(0, 1 - (distance / lightRadius));
distance = Math.pow(distance, 2);
dR = distance * r;
dG = distance * g;
dB = distance * b;
pixels[x][y][Util.R] = dR;
pixels[x][y][Util.G] = dG;
pixels[x][y][Util.B] = dB;
pixels[x][y][Util.A] = 1.0;
pixels[ix][y][Util.R] = dR;
pixels[ix][y][Util.G] = dG;
pixels[ix][y][Util.B] = dB;
pixels[ix][y][Util.A] = 1.0;
pixels[x][iy][Util.R] = dR;
pixels[x][iy][Util.G] = dG;
pixels[x][iy][Util.B] = dB;
pixels[x][iy][Util.A] = 1.0;
pixels[ix][iy][Util.R] = dR;
pixels[ix][iy][Util.G] = dG;
pixels[ix][iy][Util.B] = dB;
pixels[ix][iy][Util.A] = 1.0;
}
}
}
|
9fd7aaa4-b319-4a49-b75a-9c05652fe8fd
|
@Override
public double[][][] getPixels() {
return pixels;
}
|
1413d48c-767f-4072-896f-a8f829315843
|
@Override
public Rectangle getBounds() {
return bounds;
}
|
8cc73f9a-3cc4-4666-8d3c-73c0ece6b8ca
|
@Override
public short getDrawType() {
// TODO Auto-generated method stub
return 1;
}
|
8147a5b7-eb29-4a55-9ada-75dab4d09324
|
@Override
public boolean isDrawn() {
return isOn;
}
|
210e20ad-964c-4393-8f09-9ad620bec4b4
|
@Override
public byte[] getData() {
// TODO Auto-generated method stub
return null;
}
|
a5021aa8-42ac-4b95-83d8-e063260a9a57
|
public Burst(TexturePack tp) {
super();
super.setImage(tp.get(Texture.spark));
birth = System.nanoTime();
}
|
527c3ec5-67f4-44d8-bcf3-4735408a3d71
|
@Override
/**
* Draw the entity to the screen, at the entity's current position,
* offset by the camera's position. 8 sparks are drawn at the
* radius' distance from the center. The coordinates correspond
* to the center of the spark burst.
*
* @param comp The component used as observer
* @param page The graphics context
* @param offsetX The camera's x position
* @param offsetY The camera's y position
*/
public void draw(Component comp, Graphics page, int offsetX, int offsetY) {
if (expired) {
return;
}
radius = (int) ((System.nanoTime() - birth) / NS_PER_SEC * SPEED);
//Draw from the center, instead of the bottom left
Dimension dim = getSize();
offsetX += dim.width / 2;
offsetY += dim.height / 2;
if (radius >= MAX_SIZE) {
expired = true;
}
super.draw(comp, page,
offsetX + (int) (radius * DIAG_FACTOR),
offsetY - (int) (radius * DIAG_FACTOR));
super.draw(comp, page,
offsetX + radius,
offsetY);
super.draw(comp, page,
offsetX + (int) (radius * DIAG_FACTOR),
offsetY + (int) (radius * DIAG_FACTOR));
super.draw(comp, page,
offsetX,
offsetY + radius);
super.draw(comp, page,
offsetX - (int) (radius * DIAG_FACTOR),
offsetY + (int) (radius * DIAG_FACTOR));
super.draw(comp, page,
offsetX - radius,
offsetY);
super.draw(comp, page,
offsetX - (int) (radius * DIAG_FACTOR),
offsetY - (int) (radius * DIAG_FACTOR));
super.draw(comp, page,
offsetX,
offsetY - radius);
}
|
d78fc6f1-e022-4863-a938-1ae0a44dd6a8
|
public boolean isDead() {
return expired;
}
|
57ef92b0-c19f-4750-8f7d-0afea6b3a71a
|
public static Level genWorldRandom(int cols, int rows, TexturePack tp) {
/** Brick density. */
final double pBrick = 0.8;
/** Probability of a light in the bg. */
final double pLight = 0.02;
Level level = new Level(cols, rows, tp);
for (int row = 0; row < rows; row++) {
for (int col = 0; col < cols; col++) {
if (GEN.nextDouble() * row < pBrick) {
//solid bricks
level.setCell(col, row, Texture.brick);
} else {
//background bricks
if (GEN.nextDouble() < pLight) {
level.setCell(col, row, Texture.bgLightDead);
} else {
level.setCell(col, row, Texture.bg);
}
}
}
}
level.setStart(new Point(0, rows * Level.CELL_SIZE));
return level;
}
|
384b62f4-2a70-447f-9478-404d5642028b
|
public static Level genWorldHills(int cols, int rows, TexturePack tp) {
//Chance for ground level to rise
final double pUp = 0.2;
//Chance for ground level to drop
final double pDown = 0.2;
//probability of a hole in the world
final double pHole = 0.1;
//base probability the hole is bigger than 1 block
//(pblty diminishes with each additional block)
final double pHoleIsBig = 0.5;
Level level = new Level(cols, rows, tp);
boolean hole = false;
boolean lit = false;
int litEl = 0;
double direction = 0.0;
int height = 1;
double pBigHole = 0.0;
for (int col = 0; col < cols; col++) {
//move up, down, or stay at the same height.
direction = GEN.nextDouble();
if (direction < pUp) {
height = Math.min(height + 1, rows - 1);
} else if (direction < pUp + pDown) {
height = Math.max(height - 1, 1);
}
//determine if there should be a hole.
if (!hole) {
hole = (GEN.nextDouble() < pHole);
pBigHole = pHoleIsBig;
} else {
hole = (GEN.nextDouble() < pBigHole);
pBigHole /= 2.0;
}
lit = (GEN.nextDouble() < P_LIGHT);
if (lit) {
litEl = GEN.nextInt(LIGHT_RANGE) + LIGHT_MIN;
litEl = Math.min(height + litEl, rows - 1);
}
for (int row = 0; row < rows; row++) {
level.setCell(col, row, (row < height && !hole)
? Texture.brick
: Texture.bg);
if (lit && row == litEl) {
level.setCell(col, litEl, Texture.bgLightDead);
}
}
}
//ensure the player starts on a brick.
level.setCell(0, 0, Texture.brick);
level.setStart(new Point(0, 2 * Level.CELL_SIZE));
return level;
}
|
25698a61-1868-48d9-8194-76e5d1dd4f4b
|
public static Level genWorldPlatform(int cols, int rows, TexturePack tp) {
//initialize an empty world
Level level = new Level(cols, rows, tp);
final double pHole = 0.3;
Point pos = new Point(0, 0);
int litEl = 0;
int xDist = 0;
for (int col = 0; col < cols; col++) {
//place a brick, if the current column has a brick
if (col == pos.x) {
level.setCell(pos.x, pos.y, Texture.brick);
if (GEN.nextDouble() > pHole) {
pos.x += 1;
} else {
xDist = GEN.nextInt(6) + 2; //(2 - 7)
if (xDist == 7 && pos.y <= 1) {
xDist = 6;
}
pos.x += xDist;
switch (xDist) {
case 2:
case 3:
case 4:
pos.y += GEN.nextInt(7) - 3; //(-3 : 3)
break;
case 5:
pos.y += GEN.nextInt(6) - 3; //(-3 : 2)
break;
case 6:
pos.y += GEN.nextInt(4) - 2; //(-2 : 1)
break;
case 7:
pos.y += GEN.nextInt(3) - 3; // (-3 : -1)
break;
default:
break;
}
}
if (pos.y > rows - 1) {
pos.y = rows - 1;
} else if (pos.y < 0) {
pos.y = 0;
}
}
//place a light
if (GEN.nextDouble() < P_LIGHT) {
litEl = GEN.nextInt(LIGHT_RANGE) + LIGHT_MIN;
litEl = Math.min(pos.y + litEl, rows - 1);
level.setCell(col, litEl, Texture.bgLightDead);
}
}
level.setStart(new Point(0, 2 * Level.CELL_SIZE));
return level;
}
|
2f3af9a5-9e48-4929-8478-5b479b68020c
|
public static void genWorldFragments(int cols, int rows, TexturePack tp) {
//Level testLev = new Level(cols, rows, tp);
//Level testLev3 = new Level("fragments.txt", tp);
}
|
4d32f456-89d7-44e3-8b77-b98f0e4e92d8
|
public Level(String path, TexturePack tPack) {
tp = tPack;
//Open the file for reading
InputStream in = getClass().getResourceAsStream(BASE_PATH + path);
Scanner scan = new Scanner(in);
//Set the array size
cols = scan.nextInt();
rows = scan.nextInt();
pixels = new double[cols * CELL_SIZE][rows * CELL_SIZE][Util.CHANNELS];
map = new Texture[cols][rows];
char[][] cMap = new char[cols][rows];
char c = '0';
scan.nextLine();
String line;
//fill library from text file
for (int row = rows - 1; row >= 0; row--) {
line = scan.nextLine();
for (int col = 0; col < cols; col++) {
c = line.charAt(col);
cMap[col][row] = c;
if (c == 'I') {
start = new Point(col * CELL_SIZE, row * CELL_SIZE);
}
if (c == 'O') {
exit = new Point(col, row);
}
}
}
scan.close();
init(cMap);
updatePixels();
}
|
5a0b0805-b3d4-4945-b4f0-b2de17883cf4
|
public Level(int cols, int rows, TexturePack tPack) {
tp = tPack;
pixels = new double[cols * CELL_SIZE][rows * CELL_SIZE][Util.CHANNELS];
this.cols = cols;
this.rows = rows;
map = new Texture[cols][rows];
initEmpty();
final int defaultStart = rows * CELL_SIZE;
start = new Point(0, defaultStart);
updatePixels();
}
|
35039300-9b80-4e4e-ac73-826727dfa556
|
private void initEmpty() {
for (int col = 0; col < cols; col++) {
for (int row = 0; row < rows; row++) {
map[col][row] = Texture.bg;
}
}
}
|
806dbf1a-5a59-42af-9315-268d504f73df
|
private void init(char[][] data) {
if (data.length != map.length || data[0].length != map[0].length) {
throw new IllegalArgumentException("data array "
+ "does not match level size!");
}
for (int col = 0; col < cols; col++) {
for (int row = 0; row < rows; row++) {
map[col][row] = translate(data[col][row]);
}
}
}
|
2bd0618e-6ab9-4390-80b5-42526e1692db
|
private Texture translate(char b) {
switch (b) {
case '-':
return Texture.bg;
case 'i':
return Texture.bgLightDead;
case '#':
return Texture.brick;
default:
return Texture.bg;
}
}
|
d993c3fb-e244-4b26-9381-7ceee95a372f
|
public void pasteLevel(int bottom, int left, Level v) {
for (int col = left; col < left + v.getCols(); col++) {
for (int row = bottom; row < bottom + v.getRows(); row++) {
map[col][row] = v.getCell(col, row);
}
}
}
|
4ba47ac8-f9cd-40f6-860d-ff744815da02
|
public boolean isInBounds(int col, int row) {
if (row < 0 || row >= rows) {
return false;
}
if (col < 0 || col >= cols) {
return false;
}
return true;
}
|
e335fce9-5c26-4911-a40b-9207c1aa0ac0
|
public void setCell(int col, int row, Texture tx) {
if (!isInBounds(col, row)) {
//target (13,4) out of bounds (0:10), (0:50).
throw new IllegalArgumentException("target (" + row
+ "," + col + ") out of bounds (0:" + rows
+ "), (0:" + cols + ".");
}
map[col][row] = tx;
updatePixels(col, row);
}
|
fe75b3bf-330d-4fd5-b842-35fbd6f41b6c
|
public Texture getCell(int col, int row) {
if (isInBounds(col, row)) {
return map[col][row];
} else {
return Texture.bg;
}
}
|
4e6a4b71-bd9d-4e23-8ac9-fbb250dd1580
|
public int getCols() {
return cols;
}
|
74ab0f37-9b0d-467b-9619-fc06d3da1b06
|
public int getRows() {
return rows;
}
|
5c2b0286-6b1e-49d6-878b-8b34a4e118d6
|
public Point getStart() {
return start;
}
|
78ce01d4-dbd5-4bfd-bf78-8128a3e4c102
|
public void setStart(Point newStart) {
start = newStart;
}
|
f963fb2f-1a61-4599-8842-8cf5d7836674
|
public Point getExit() {
return exit;
}
|
b5609304-8197-4a02-a85b-8ebf36ac52d4
|
public Point[] getAll(Texture tx) {
//how much to increment the array by each time.
final int increment = 20;
//make array size 0
Point[] result = new Point[0];
Point[] temp;
int row = 0;
int col = 0;
byte lightCount = 0;
//while iteration is incomplete
while (col < cols && row < rows) {
//if out of space, resize the array
if (lightCount == result.length) {
temp = new Point[result.length + increment];
for (int i = 0; i < temp.length; i++) {
if (i < result.length) {
temp[i] = result[i];
}
}
result = temp;
}
//Advance through the array
row++;
if (row >= rows) {
row = 0;
col++;
}
//add to array if matching
if (getCell(col, row) == tx) {
result[lightCount] = new Point(col * CELL_SIZE,
row * CELL_SIZE);
lightCount++;
}
}
//crop array to minimum size
temp = result;
result = new Point[lightCount];
for (int i = 0; i < lightCount; i++) {
result[i] = temp[i];
}
//return result
return result;
}
|
14b139e6-c784-4cef-b35e-9e300589ad53
|
private void updatePixels() {
double[][][] iPixels;
//for every block in the world,
for (int col = 0; col < cols; col++) {
for (int row = 0; row < rows; row++) {
//get the pixels for that texture
iPixels = tp.getP(map[col][row]);
//paste them into the instance data pixels[][][];
for (int x = col * CELL_SIZE;
x < col * CELL_SIZE + CELL_SIZE;
x++) {
for (int y = row * CELL_SIZE;
y < row * CELL_SIZE + CELL_SIZE;
y++) {
pixels[x][y] = iPixels[x - (col * CELL_SIZE)]
[(y - (row * CELL_SIZE))];
}
}
}
}
}
|
50084c07-19f2-414c-b69f-ded4ec620e04
|
private void updatePixels(int col, int row) {
double[][][] iPixels;
//get the pixels for that texture
iPixels = tp.getP(map[col][row]);
//paste them into the instance data pixels[][][];
for (int x = col * CELL_SIZE;
x < col * CELL_SIZE + CELL_SIZE;
x++) {
for (int y = row * CELL_SIZE;
y < row * CELL_SIZE + CELL_SIZE;
y++) {
pixels[x][y] = iPixels[x - (col * CELL_SIZE)]
[(y - (row * CELL_SIZE))];
}
}
}
|
76893131-3dbe-4ebd-aa4b-536c7585e742
|
@Override
public double[][][] getPixels() {
// System.out.println("at 15,30: R=" + pixels[15][30][Util.R]
// + ", G=" + pixels[15][30][Util.G]
// + ", B=" + pixels[15][30][Util.B]);
return pixels;
}
|
04a2d189-16b4-4f4d-b604-e6fb6e04ae54
|
@Override
public Rectangle getBounds() {
bounds = new Rectangle(0, 0, cols * CELL_SIZE, rows * CELL_SIZE);
return bounds;
}
|
3c59fcd7-7ed0-4b1c-880e-4b26023e2507
|
@Override
public short getDrawType() {
return drawType;
}
|
337ceb4a-c2fb-4e40-9608-1b89ff46358c
|
public int escapeX(Dynamic obj, double velocity, Point impactZone) {
Rectangle r = obj.getCollisionBox();
int escape = 0;
//if the obj was moving right nudge it left into safety.
if (velocity > 0) {
escape = (impactZone.x * CELL_SIZE - r.width) - r.x;
//but if the obj was moving left nudge it right into safety.
} else if (velocity < 0) {
escape = CELL_SIZE - (r.x % CELL_SIZE);
}
//Clamp the velocity;
if (Math.abs(escape) > Math.abs(velocity)) {
escape = 0;
}
return escape;
}
|
83a29bae-a85b-43da-ac84-bdaad00e36b0
|
public int escapeY(Dynamic obj, double velocity, Point impactZone) {
Rectangle r = obj.getCollisionBox();
int escape = 0;
//if the obj was moving up nudge it down into safety.
if (velocity > 0) {
escape = (impactZone.y * CELL_SIZE - r.height) - r.y;
//but if the obj was moving down nudge it up into safety.
} else if (velocity < 0) {
escape = CELL_SIZE - (r.y % CELL_SIZE);
}
//Clamp the velocity;
if (Math.abs(escape) > Math.abs(velocity)) {
escape = 0;
}
return escape;
}
|
50ba65ff-4384-40ae-9b09-e528f12ebec5
|
@Override
public boolean isDrawn() {
//always draw the level.
return true;
}
|
b886448e-6647-42f8-a1b5-ec07cad01733
|
@Override
public byte[] getData() {
// TODO Auto-generated method stub
return null;
}
|
efa33f33-5c91-46a6-bf88-c141f7374cb1
|
public World(int width, int height, TexturePack texPack) {
tp = texPack;
fincomp = new BufferedImage(CELL_SIZE * WORLD_WIDTH,
CELL_SIZE * WORLD_HEIGHT,
BufferedImage.TYPE_INT_ARGB);
background = new BufferedImage(CELL_SIZE * BG_BUFFER_SIZE,
CELL_SIZE * BG_BUFFER_SIZE,
BufferedImage.TYPE_INT_RGB);
gBG = background.createGraphics();
fillBGBuffer();
}
|
ae76aad3-0463-40ed-b4d6-4502257f274e
|
public void fillBGBuffer() {
//set the brush to background bricks
for (int y = 0; y < BG_BUFFER_SIZE; y++) {
for (int x = 0; x < BG_BUFFER_SIZE; x++) {
gBG.drawImage(tp.get(Texture.bg),
x * CELL_SIZE,
// Y is upside down, but in this case doesn't matter
y * CELL_SIZE,
null);
}
}
}
|
91f3b69c-0416-46b0-80bb-91b4e8c2f012
|
public void draw(Graphics page, Component comp, int offsetX, int offsetY) {
int x = 0;
int y = 0;
//Move with the camera
x = -offsetX;
y = offsetY;
//Allow for window resizing
y = y + comp.getHeight() - WORLD_HEIGHT * CELL_SIZE;
//Draw the infinite background
int h;
int v = offsetY % CELL_SIZE + comp.getHeight();
for (; v > -background.getHeight(); v -= background.getHeight()) {
h = -(offsetX % CELL_SIZE) - CELL_SIZE;
for (; h < comp.getWidth(); h += background.getWidth()) {
page.drawImage(background, h, v, null);
}
}
//Draw the important tiles into place.
page.drawImage(fincomp, x, y, null);
}
|
1212a325-efe5-43c7-9574-d746af747b1f
|
static BufferedImage deepCopy(BufferedImage bi) {
ColorModel cm = bi.getColorModel();
boolean isAlphaPremultiplied = cm.isAlphaPremultiplied();
WritableRaster raster = bi.copyData(null);
return new BufferedImage(cm, raster, isAlphaPremultiplied, null);
}
|
db229937-ef3f-4aa1-b2ab-9ab1668bf9b8
|
public CDIFactory(Logger log, BeanManager bm) {
this.beanManager = bm;
this.log = log;
}
|
f697cb1f-ea13-4ce1-85f8-43c745a5fd0f
|
public <T> T get(Class<T> clazz) {
Set<Bean<?>> beans = beanManager.getBeans(clazz);
if(beans!=null && beans.size()>0) {
Bean<T> bean = (Bean<T>) beans.iterator().next();
CreationalContext<T> ctx = beanManager.createCreationalContext(bean);
T o = clazz.cast(beanManager.getReference(bean, clazz, ctx));
log.info("Found and returning: "+clazz.getCanonicalName());
return o;
}
return null;
}
|
de1f3f53-19bc-4044-9724-e58e5b08106f
|
public CDIObjectProvider(
Logger log,
@Local CDIFactory cdiFactory) {
this.log = log;
this.cdiFactory = cdiFactory;
}
|
50875d34-bd7f-4890-b707-1d467485117c
|
@SuppressWarnings("unchecked")
public <T> T provide(Class<T> objectType,
AnnotationProvider annotationProvider, ObjectLocator locator) {
/**
* Problem: in many cases a tapestry service will qualify as a cdi bean.
* In order to prevent cdi for managing a service that should be provided by tapestry we check if locator has the service.
*
* The MasterObjectProvider will attempt to delegate to locator after all providers has been asked.
*/
// try {
// if(locator.getService(objectType)!=null)
// return null;
// } catch (RuntimeException e) {
// // TODO: handle exception
// }
return cdiFactory.get(objectType);
// Set<Bean<?>> beans = beanManager.getBeans(objectType);
// if(beans!=null && beans.size()>0) {
// Bean<T> bean = (Bean<T>) beans.iterator().next();
// if(hasValidScope(bean)) {
// CreationalContext<T> ctx = beanManager.createCreationalContext(bean);
// T o = (T) beanManager.getReference(bean, objectType, ctx);
// log.info("Found and returning: "+objectType.getCanonicalName());
// return o;
// }
// }
// return null;
}
|
f1528d1c-cb71-4a75-89c8-fd61d4148575
|
protected <T> boolean hasValidScope(Bean<T> bean) {
return bean!=null && allowedScopes.contains(bean.getScope());
}
|
4397e6a8-6ead-427f-a091-5b27f35e9051
|
public static void bind(ServiceBinder binder) {
binder.bind(ObjectProvider.class, CDIObjectProvider.class).withId("CDIObjectProvider");
}
|
1507191c-1937-4815-a9a6-2138af946f81
|
public static BeanManager buildBeanManager(Logger log) {
log.info("buildBeanManager");
try {
BeanManager beanManager = (BeanManager) new InitialContext().lookup("java:comp/BeanManager");
return beanManager;
} catch (NamingException e) {
log.error("Could not lookup jndi resource: java:comp/BeanManager", e);
}
return null;
}
|
015e6d79-49fd-4bff-99e9-ac181c53be4e
|
public static CDIFactory buildCDIFactory(Logger log, @Local BeanManager beanManager) {
return new CDIFactory(log, beanManager);
}
|
26eee862-a909-4797-b892-469acbde84cb
|
@Contribute(InjectionProvider2.class)
public static void provideInjectionProvider(
OrderedConfiguration<InjectionProvider2> configuration,
@Local CDIFactory cdiFactory,
ComponentClassCache cache) {
// configuration.add("CDI", new CDIInjectionProvider(cdiFactory, cache), "after:*,before:Service");
configuration.add("CDI", new CDIInjectionProvider(cdiFactory, cache), "after:InjectionProvider");
}
|
9d191c9b-a8c9-40f9-81c0-2ffff47efe01
|
public static void contributeMasterObjectProvider(
@Local ObjectProvider cdiProvider,
OrderedConfiguration<ObjectProvider> configuration) {
// configuration.add("cdiProvider", cdiProvider, "after:Service,after:AnnotationBasedContributions,after:Alias,after:Autobuild");
configuration.add("cdiProvider", cdiProvider, "after:*");
}
|
3e09b3da-d0d2-41df-9de4-2d1764da3b67
|
@Contribute(ComponentClassTransformWorker2.class)
public static void provideClassTransformWorkers(
OrderedConfiguration<ComponentClassTransformWorker2> configuration) {
configuration.addInstance("CDI", CDIAnnotationWorker.class, "before:Property");
}
|
03a9f080-b363-4867-8b5b-9e56325d5dd8
|
public CDIAnnotationWorker(CDIFactory cdiFactory, ComponentClassCache cache) {
this.cdiFactory = cdiFactory;
this.cache = cache;
}
|
42d3f52d-c24a-4da0-8481-38acb0f41598
|
@Override
public void transform(PlasticClass plasticClass,
TransformationSupport support, MutableComponentModel model) {
for (PlasticField field : plasticClass.getFieldsWithAnnotation(CDI.class)) {
final CDI annotation = field.getAnnotation(CDI.class);
Class type = cache.forName(field.getTypeName());
final Object injectionValue = cdiFactory.get(type);
if (injectionValue != null) {
field.inject(injectionValue);
field.claim(annotation);
}
}
}
|
472c4978-f30e-490d-b768-f39fbac668ba
|
public CDIInjectionProvider(CDIFactory cdiFactory, ComponentClassCache cache) {
this.cdiFactory = cdiFactory;
this.cache = cache;
}
|
732d3623-fc61-4a57-8002-99a82e2b18b0
|
@Override
public boolean provideInjection(PlasticField field, ObjectLocator locator,
MutableComponentModel componentModel) {
Class type = cache.forName(field.getTypeName());
/**
* Problem: in many cases a tapestry service will qualify as a cdi bean.
* In order to prevent cdi for managing a service that should be provided by tapestry we check if locator has the service.
*/
// try {
// if(locator.getService(type)!=null)
// return false;
// } catch (RuntimeException e) {
// // TODO: handle exception
// }
final Object injectionValue = cdiFactory.get(type);
if(injectionValue!=null) {
field.inject(injectionValue);
return true;
}
return false;
}
|
005cf375-9235-4506-b554-0d4de4d97530
|
public About() {
initialize();
frame.setVisible(true);
}
|
4d40bfd9-d0c5-47e6-95dc-6211026c47b1
|
private void initialize() {
frame = new JFrame();
frame.setBounds(100, 100, 450, 300);
/* ํ๋ฉด์ ์ค์์ผ๋ก ์ ๋ ฌ */
Dimension frameSize = frame.getSize();
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
frame.setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2);
JPanel panel = new JPanel();
frame.getContentPane().add(panel, BorderLayout.CENTER);
JLabel lblLogo = new JLabel("");
lblLogo.setIcon(new ImageIcon("/Users/oming/Desktop/ebms_logo.png"));
panel.add(lblLogo);
JPanel panel_1 = new JPanel();
frame.getContentPane().add(panel_1, BorderLayout.SOUTH);
JLabel lblAbout = new JLabel(
"<html>\n<pre>E.B.M.S ์์คํ
์
๋๋ค.<br>\n© EBMS. All Right Reserved.\n</pre>\n</html>");
panel_1.add(lblAbout);
}
|
88309fd2-18af-4c45-acb4-af2123d7b45b
|
public Server(int port) {
this(port, null);
}
|
dc729f85-9382-41bb-9c9e-2814afa49a67
|
public Server(int port, ServerGUI sg) {
// GUI or not
this.sg = sg;
// the port
this.port = port;
// to display hh:mm:ss
sdf = new SimpleDateFormat("HH:mm:ss");
// ArrayList for the Client list
al = new ArrayList<ClientThread>();
}
|
c2eb6ea5-68da-44d3-bf26-788f0c406b85
|
public void start() {
keepGoing = true;
/* create socket server and wait for connection requests */
try {
// the socket used by the server
ServerSocket serverSocket = new ServerSocket(port);
// infinite loop to wait for connections
while (keepGoing) {
// format message saying we are waiting
display("Server waiting for Clients on port " + port + ".");
Socket socket = serverSocket.accept(); // accept connection
// if I was asked to stop
if (!keepGoing)
break;
ClientThread t = new ClientThread(socket); // make a thread of
// it
al.add(t); // save it in the ArrayList
t.start();
}
// I was asked to stop
try {
serverSocket.close();
for (int i = 0; i < al.size(); ++i) {
ClientThread tc = al.get(i);
try {
tc.sInput.close();
tc.sOutput.close();
tc.socket.close();
} catch (IOException ioE) {
// not much I can do
}
}
} catch (Exception e) {
display("Exception closing the server and clients: " + e);
}
}
// something went bad
catch (IOException e) {
String msg = sdf.format(new Date()) + " Exception on new ServerSocket: " + e + "\n";
display(msg);
}
}
|
b776e7b6-aa96-4ba5-9153-d0149174fb10
|
protected void stop() {
keepGoing = false;
// connect to myself as Client to exit statement
// Socket socket = serverSocket.accept();
try {
new Socket("localhost", port);
} catch (Exception e) {
// nothing I can really do
}
}
|
97283941-7dff-4184-a581-77fa9eb0667b
|
private void display(String msg) {
String time = sdf.format(new Date()) + " " + msg;
if (sg == null)
System.out.println(time);
else
sg.appendEvent(time + "\n");
}
|
064dfaa8-a0c8-460a-8400-8097beb6cd66
|
private synchronized void broadcast(String message) {
// add HH:mm:ss and \n to the message
String time = sdf.format(new Date());
String messageLf = time + " " + message + "\n";
// display message on console or GUI
if (sg == null)
System.out.print(messageLf);
else
sg.appendRoom(messageLf); // append in the room window
// we loop in reverse order in case we would have to remove a Client
// because it has disconnected
for (int i = al.size(); --i >= 0;) {
ClientThread ct = al.get(i);
// try to write to the Client if it fails remove it from the list
if (!ct.writeMsg(messageLf)) {
al.remove(i);
display("Disconnected Client " + ct.username + " removed from list.");
}
}
}
|
ebf5ca3d-59e5-4cd2-aa6f-b4a3d350414d
|
synchronized void remove(int id) {
// scan the array list until we found the Id
for (int i = 0; i < al.size(); ++i) {
ClientThread ct = al.get(i);
// found it
if (ct.id == id) {
al.remove(i);
return;
}
}
}
|
69f2b16b-0ca7-421b-812f-0eb3c57e78cc
|
public static void main(String[] args) {
// protNumber๋ฅผ ์ง์ ํ์ง ์์ผ๋ฉด 1500๋ฒ ํฌํธ๋ก ์
int portNumber = 1500;
new ConnectDB(); // DB์ฐ๊ฒฐ ์์
// ์ธ์์ ํํ์ ๋ฐ๋ฅธ ์ถ
switch (args.length) {
case 1:
try {
portNumber = Integer.parseInt(args[0]);
} catch (Exception e) {
System.out.println("Invalid port number.");
System.out.println("Usage is: > java Server [portNumber]");
return;
}
case 0:
break;
default:
System.out.println("Usage is: > java Server [portNumber]");
return;
}
// ์๋ฒ ๊ฐ์ฒด๋ฅผ ์์ฑํ๊ณ ์๋ฒ๋ฅผ ์์ํ๋ค.
Server server = new Server(portNumber);
server.start();
}
|
0063b6eb-b6c6-41a2-bbea-8ee6cf684303
|
ClientThread(Socket socket) {
// ๊ณ ์ ID
id = ++uniqueId;
this.socket = socket;
/* ๋ฐ์ดํฐ ์คํธ๋ฆผ์ ์์ฑ */
System.out.println("Thread trying to create Object Input/Output Streams");
try {
// ์ถ๋ ฅ์ ์์ฑ.
sOutput = new ObjectOutputStream(socket.getOutputStream());
sInput = new ObjectInputStream(socket.getInputStream());
// ์ฌ์ฉ์๋ช
์ ์ฝ์.
username = (String) sInput.readObject();
// ๋ณด๋ ์ ์์ ์ถ๋ ฅํจ.
display(username + " just connected.");
} catch (IOException e) {
// ์คํธ๋ฆผ ์์ฑ ์๋ฌ.
display("Exception creating new Input/output Streams: " + e);
return;
}
// have to catch ClassNotFoundException
// but I read a String, I am sure it will work
catch (ClassNotFoundException e) {
}
date = new Date().toString() + "\n";
}
|
d92ecfd8-e997-49aa-a24d-13d2d19bc5cc
|
public void run() {
// to loop until LOGOUT
boolean keepGoing = true;
while (keepGoing) {
// read a String (which is an object)
try {
cm = (ChatMessage) sInput.readObject();
} catch (IOException e) {
display(username + " Exception reading Streams: " + e);
break;
} catch (ClassNotFoundException e2) {
break;
}
// the messaage part of the ChatMessage
String message = cm.getMessage();
// Switch on the type of message receive
switch (cm.getType()) {
case ChatMessage.MESSAGE:
broadcast(username + ": " + message);
break;
case ChatMessage.LOGOUT:
display(username + " disconnected with a LOGOUT message.");
keepGoing = false;
break;
case ChatMessage.WHOISIN:
writeMsg("List of the users connected at " + sdf.format(new Date()) + "\n");
// scan al the users connected
for (int i = 0; i < al.size(); ++i) {
ClientThread ct = al.get(i);
writeMsg((i + 1) + ") " + ct.username + " since " + ct.date);
}
break;
}
}
// remove myself from the arrayList containing the list of the
// connected Clients
remove(id);
close();
}
|
aaaecfae-eb56-4b3e-9424-893eccfce0e5
|
private void close() {
// try to close the connection
try {
if (sOutput != null)
sOutput.close();
} catch (Exception e) {
}
try {
if (sInput != null)
sInput.close();
} catch (Exception e) {
}
;
try {
if (socket != null)
socket.close();
} catch (Exception e) {
}
}
|
29ab8738-b07a-46e2-bb3d-5d0a3ae540f3
|
private boolean writeMsg(String msg) {
// if Client is still connected send the message to it
if (!socket.isConnected()) {
close();
return false;
}
// write the message to the stream
try {
sOutput.writeObject(msg);
}
// if an error occurs, do not abort just inform the user
catch (IOException e) {
display("Error sending message to " + username);
display(e.toString());
}
return true;
}
|
9dd94cce-af70-4bb6-9702-2dec24b7060c
|
ChatMessage(int type, String message) {
this.type = type;
this.message = message;
}
|
dbcae27e-f898-41d0-9976-927ab63eacda
|
int getType() {
return type;
}
|
178f038d-6e01-42cb-a8b6-4db43002b34b
|
String getMessage() {
return message;
}
|
41ab4d90-b4c6-4dcb-ac86-09f1b8f21df4
|
public MainFrame() {
initialize();
frmEbms.setVisible(true);
}
|
8bf23f58-a038-4fa9-a5ab-53191e9cc666
|
private void initialize() {
frmEbms = new JFrame();
frmEbms.setTitle("EBMS");
frmEbms.setBounds(100, 100, 800, 600);
frmEbms.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
/* ํ๋ฉด์ ์ค์์ผ๋ก ์ ๋ ฌ */
Dimension frameSize = frmEbms.getSize();
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
frmEbms.setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2);
JMenuBar menuBar = new JMenuBar();
frmEbms.setJMenuBar(menuBar);
JMenu mnFile = new JMenu("File");
menuBar.add(mnFile);
JMenuItem mntmServerStart = new JMenuItem("Server Start");
mnFile.add(mntmServerStart);
JMenuItem mntmServerStop = new JMenuItem("Server Stop");
mnFile.add(mntmServerStop);
JMenuItem mntmExit = new JMenuItem("Exit");
mnFile.add(mntmExit);
JMenu mnEdit = new JMenu("Edit");
menuBar.add(mnEdit);
JMenu mnHelp = new JMenu("Help");
menuBar.add(mnHelp);
JMenuItem mntmAbout = new JMenuItem("About");
mntmAbout.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
About af = new About();
}
});
mnHelp.add(mntmAbout);
frmEbms.getContentPane().setLayout(new BorderLayout(0, 0));
JPanel panelFrame = new JPanel();
frmEbms.getContentPane().add(panelFrame, BorderLayout.CENTER);
panelFrame.setLayout(new GridLayout(0, 3, 0, 0));
JLabel label = new JLabel("1");
label.setVerticalAlignment(SwingConstants.TOP);
panelFrame.add(label);
JLabel label_1 = new JLabel("2");
label_1.setVerticalAlignment(SwingConstants.TOP);
panelFrame.add(label_1);
JLabel label_2 = new JLabel("3");
label_2.setVerticalAlignment(SwingConstants.TOP);
panelFrame.add(label_2);
JLabel label_3 = new JLabel("4");
label_3.setVerticalAlignment(SwingConstants.TOP);
panelFrame.add(label_3);
JLabel label_4 = new JLabel("5");
label_4.setVerticalAlignment(SwingConstants.TOP);
panelFrame.add(label_4);
JLabel label_5 = new JLabel("6");
label_5.setVerticalAlignment(SwingConstants.TOP);
panelFrame.add(label_5);
JLabel label_6 = new JLabel("7");
label_6.setVerticalAlignment(SwingConstants.TOP);
panelFrame.add(label_6);
JLabel label_7 = new JLabel("8");
label_7.setVerticalAlignment(SwingConstants.TOP);
panelFrame.add(label_7);
JLabel label_8 = new JLabel("9");
label_8.setVerticalAlignment(SwingConstants.TOP);
panelFrame.add(label_8);
JPanel panelControl = new JPanel();
frmEbms.getContentPane().add(panelControl, BorderLayout.SOUTH);
JButton btnStartstop = new JButton("Start/Stop");
panelControl.add(btnStartstop);
JButton btnPicontrol = new JButton("PiControl");
panelControl.add(btnPicontrol);
JButton btnDivisionFrame = new JButton("Division Frame");
panelControl.add(btnDivisionFrame);
}
|
1cde594d-b382-4fec-917e-a459a6065876
|
public void actionPerformed(ActionEvent e) {
About af = new About();
}
|
94a0d5e8-b67b-4c3b-afa4-c174f8d74a49
|
ServerGUIList() {
super("Chat Server");
setTitle("List");
// need to be informed when the user click the close button on the frame
setSize(300, 400);
// ํ๋ฉด ์ฌ์ด์ฆ ๊ตฌํ๊ธฐ ๋ฐ ํ๋ฉด ์ค์์ ์ถ๋ ฅ
Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
Dimension f_size = this.getSize();
int xpos = (int) ((screen.getWidth() / 2) - (f_size.getWidth() / 2));
int ypos = (int) ((screen.getHeight() / 2) - (f_size.getHeight() / 2));
this.setLocation(xpos, ypos);
// ํ๋ฉด ์ค์์ ๋ฟ๋ฆฌ๊ธฐ ์ข
๋ฃ
setVisible(false);
}
|
0afb4357-9229-4760-a1d1-4376566be3f7
|
@Override
public void windowActivated(WindowEvent arg0) {
}
|
67502565-1ee1-48f4-b0b0-67fe7ce02175
|
@Override
public void windowClosed(WindowEvent arg0) {
}
|
fe086bd4-49e9-4699-8223-43e8946a4ffa
|
@Override
public void windowClosing(WindowEvent arg0) {
}
|
1d3a2305-740a-4319-a70a-a7fbd7749f3e
|
@Override
public void windowDeactivated(WindowEvent arg0) {
}
|
67fda17d-2cae-4b69-8382-3fbec8254e96
|
@Override
public void windowDeiconified(WindowEvent arg0) {
}
|
edfaad19-cedb-4ede-b8d5-dde10636e2b7
|
@Override
public void windowIconified(WindowEvent arg0) {
}
|
43b4fa33-3a92-4e9c-830e-f7ee6e3a7fe3
|
@Override
public void windowOpened(WindowEvent arg0) {
}
|
7386095d-38bb-429a-8449-1ee48f967f29
|
@Override
public void actionPerformed(ActionEvent arg0) {
}
|
e146c068-ff78-413c-8c1f-3913b12ffdc4
|
ServerGUI(int port) {
super("Chat Server");
setTitle("Server");
server = null;
JPanel north = new JPanel();
north.add(new JLabel("Port number: "));
tPortNumber = new JTextField(" " + port);
north.add(tPortNumber);
// to stop or start the server, we start with "Start"
stopStart = new JButton("Start");
stopStart.setActionCommand("stopStart");
stopStart.addActionListener(this);
north.add(stopStart);
getContentPane().add(north, BorderLayout.NORTH);
// ๊ฐ ๊ฒ์ํ ์ฐ๊ฒฐ.
JPanel center = new JPanel(new GridLayout(0, 3));
getContentPane().add(center);
btn1 = new JButton("์ฐ๊ฒฐ ์์");
btn1.setActionCommand("non");
btn1.addActionListener(this);
center.add(btn1);
btn2 = new JButton("์ฐ๊ฒฐ ์์");
btn2.setActionCommand("non");
btn2.addActionListener(this);
center.add(btn2);
btn3 = new JButton("์ฐ๊ฒฐ ์์");
btn3.setActionCommand("non");
btn3.addActionListener(this);
center.add(btn3);
btn4 = new JButton("์ฐ๊ฒฐ ์์");
btn4.setActionCommand("non");
btn4.addActionListener(this);
center.add(btn4);
btn5 = new JButton("์ฐ๊ฒฐ ์์");
btn5.setActionCommand("non");
btn5.addActionListener(this);
center.add(btn5);
btn6 = new JButton("์ฐ๊ฒฐ ์์");
btn6.setActionCommand("non");
btn6.addActionListener(this);
center.add(btn6);
// ๋ฉ๋ด ๋ชฉ๋ก.
menuBar = new JPanel();
getContentPane().add(menuBar, BorderLayout.SOUTH);
link = new JButton("์ฐ๊ฒฐ ๋ชฉ๋ก");
link.setActionCommand("link");
link.addActionListener(this);
menuBar.add(link);
post = new JButton("๊ฒ์ ๋ชฉ๋ก");
post.setActionCommand("post");
post.addActionListener(this);
menuBar.add(post);
upload = new JButton("์๋ฃ ์
๋ก๋");
upload.setActionCommand("upload");
upload.addActionListener(this);
menuBar.add(upload);
selectPublic = new JButton("์ ํ ๊ฒ์");
selectPublic.setActionCommand("selectPublic");
selectPublic.addActionListener(this);
menuBar.add(selectPublic);
allPublic = new JButton("์ ์ฒด ๊ฒ์");
allPublic.setActionCommand("allPublic");
allPublic.addActionListener(this);
menuBar.add(allPublic);
// the event room
sidebar = new JPanel();
event = new JTextArea(0, 20);
event.setLineWrap(true);
event.setEditable(false);
appendEvent("Events log.\n");
sidebar.setLayout(new GridLayout(0, 1, 0, 0));
sidebar.add(new JScrollPane(event));
getContentPane().add(sidebar, BorderLayout.EAST);
addWindowListener(this);
setSize(600, 600);
// ํ๋ฉด์ ์ค์์ ํ์
Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
Dimension f_size = this.getSize();
int xpos = (int) ((screen.getWidth() / 2) - (f_size.getWidth() / 2));
int ypos = (int) ((screen.getHeight() / 2) - (f_size.getHeight() / 2));
this.setLocation(xpos, ypos);
// ํ๋ฉด ์ถ๋ ฅ.
setVisible(true);
}
|
583a73c2-f2a9-49c5-b4b7-a5abe6c7bbd9
|
void appendRoom(String str) {
event.append(str);
event.setCaretPosition(event.getText().length() - 1);
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.