id
stringlengths
36
36
text
stringlengths
1
1.25M
d4f937c2-46f0-481b-af15-fb8fb5885217
public void println(String s);
0219a5eb-2766-4b3d-a7e4-9130d9bd8b87
public String readLine();
5b260c3b-cd16-41e7-989f-c155a378c434
public boolean isInputStreamReady();
6da9aebc-8f24-4666-988c-d9936e443726
public void disconnect();
bd0fe99b-ff68-4bab-b179-9b8541e89293
@Override public String getNick() { return "SillyBot"; }
7294bc23-6c07-4123-888a-bb277e8da085
@Override public void println(String s) { }
4c7b3033-0c15-4f33-b526-d88bf97d52e8
@Override public String readLine() { again = !again; if(again) { return "TURN" + (position++ % 9); } else { return Game.AGAIN_MESSAGE; } }
fa5e3cd6-f297-47e6-9c65-fe1935e49c55
@Override public boolean isInputStreamReady() { return true; }
0155eff3-bcca-4797-9429-ef957010e224
@Override public void disconnect() { }
51ade206-2a9d-4161-b3c8-08b05aa4b9cb
public void start() { ServerSocket socket = null; try { socket = new ServerSocket(port); } catch (IOException e) { System.out.println("Could not listen on port " + port + "\n"); System.exit(-1); } while(true) { RealClient client1 = null; RealClient client2 = null; try { socket.setSoTimeout(0); client1 = new RealClient(socket.accept(), "guest" + (RealClient.getClientsNumber() + 1)); client1.println(WELCOME_MESSAGE); socket.setSoTimeout(15000); client2 = new RealClient(socket.accept(), "guest" + (RealClient.getClientsNumber() + 1)); client2.println(WELCOME_MESSAGE); new Game(client1, client2).start(); System.out.println("Game created"); } catch(SocketTimeoutException e) { SillyBot bot = new SillyBot(); new Game(client1, bot).start(); } catch(IOException e) { System.out.println("Could not accept client"); } } }
8772a59a-d923-466b-a57f-bea900bff88d
public static void main(String[] args) { new Server().start(); }
19b2908e-9edd-46f3-8704-044cfaa0d421
public SocketWrap(Socket clientSocket) { socket = clientSocket; try { out = new PrintWriter( socket.getOutputStream(), true); in = new BufferedReader( new InputStreamReader( socket.getInputStream())); } catch(IOException e) { System.err.println("SocketWrap->SocketWrap()->IOException"); } }
83271bd1-2177-4e5e-bca1-c8cbe50a79ff
public void println(String s) { if(s != null) { out.println(s); } }
0ef692f0-fbbe-487e-92d7-0f89717b8f2c
public String readLine() { String s; try { s = in.readLine(); } catch(IOException e) { s = null; } return s; }
b04b7842-c946-4cd2-9762-2c69803ea705
public boolean isInputStreamReady() { try { return in.ready(); } catch(IOException e) { return false; } }
7d9fe80b-3841-46f4-b1fa-272fc980a073
public void disconnect() { try { in.close(); out.close(); socket.close(); } catch(IOException e) { System.err.println("SocketWrap->disconnect()->IOException"); } }
ca6ad19d-1651-490b-bb1c-e5d10c84abb6
Game(Client client1, Client client2) { super("Game"); this.client1 = client1; this.client2 = client2; }
adb8e661-7f0c-4784-aea0-3140a0d98b23
@Override public void run() { client1.println(SESSION_CREATED_MESSAGE); client2.println(SESSION_CREATED_MESSAGE); client1.println(OPPONENT_INFO_MESSAGE + client2.getNick()); client2.println(OPPONENT_INFO_MESSAGE + client1.getNick()); isOnGame = true; while(isOnGame) { turn(client1, client2); turn(client2, client1); } client1.println(GAME_OVER_MESSAGE); client2.println(GAME_OVER_MESSAGE); boolean newGameStarted = false; boolean want1 = false; boolean want2 = false; long startTime = System.currentTimeMillis(); while(System.currentTimeMillis() - startTime < 30000) { if(want1 && want2) { new Game(client2, client1).start(); newGameStarted = true; break; } if(client1.isInputStreamReady()) { String line = client1.readLine(); if((line == null) || (line.equals(FAREWELL_MESSAGE))) { if(want2) { client2.println(NOT_AGAIN_MESSAGE); } break; } if(line.equals(AGAIN_MESSAGE)) { if(!want1) { want1 = true; client2.println(WANT_AGAIN_MESSAGE); } } } if(client2.isInputStreamReady()) { String line = client2.readLine(); if((line == null) || (line.equals(FAREWELL_MESSAGE))) { if(want1) { client1.println(NOT_AGAIN_MESSAGE); } break; } if(line.equals(AGAIN_MESSAGE)) { if(!want2) { want2 = true; client1.println(WANT_AGAIN_MESSAGE); } } } } if(!newGameStarted) { client1.println(SESSION_CLOSED_MESSAGE); client2.println(SESSION_CLOSED_MESSAGE); client1.disconnect(); client2.disconnect(); } }
f58df08d-a71e-4d3f-88e7-5f494f99bda8
private void turn(Client fromClient, Client toClient) { if(isOnGame) { fromClient.println(YOUR_TURN_MESSAGE); long timeStart = System.currentTimeMillis(); boolean isValidTurn = false; while((!isValidTurn) && (System.currentTimeMillis() - timeStart < 10000)) { if(fromClient.isInputStreamReady()) { String line = fromClient.readLine(); if(line == null) { break; } if(tryTurn(fromClient, line)) { isValidTurn = true; fromClient.println(ACK_MESSAGE); toClient.println(line); int winner = hasWinner(); if(winner != 0) { if(winner == 1) { onWin(client1, client2); break; } else { onWin(client2, client1); break; } } if(!hasFreeCells()) { onTie(); break; } } else { fromClient.println(BAD_MESSAGE); } } try { Thread.sleep(100); } catch(InterruptedException e) { } } if(!isValidTurn) { onWin(toClient, fromClient); } } }
30830809-618a-448d-a3e6-f02bfbc4957e
private int hasWinner() { for(int i = 0; i < 3; i++) { int row = 3 * i; if((board[row] == board[row + 1]) && (board[row + 1] == board[row + 2]) && (board[row] != 0)) { winnerLine = "" + row + "" + (row + 1) + "" + (row + 2); return board[row]; }if((board[i] == board[i + 3]) && (board[i + 3] == board[i + 6]) && (board[i] != 0)) { winnerLine = "" + i + "" + (i + 3) + "" + (i + 6); return board[i]; } } if((board[0] == board[4]) && (board[4] == board[8]) && (board[0] != 0)) { winnerLine = "048"; return board[0]; }if((board[2] == board[4]) && (board[4] == board[6]) && (board[2] != 0)) { winnerLine = "246"; return board[2]; } return 0; }
bc1e20b9-b0ee-4c5b-9ff7-626e7044b66c
private boolean hasFreeCells() { for(int i = 0; i < 9; i++) { if(board[i] == 0) { return true; } } return false; }
0efc4cca-c17e-4143-98b2-3ecf536b4b79
private boolean tryTurn(Client client, String line) { if(!line.matches("TURN[0-8]")) { return false; } else { int position = line.charAt(4) - '0'; if(board[position] == 0) { if(client.equals(client1)) { board[position] = 1; } else { board[position] = -1; } return true; } else { return false; } } }
ff698f44-f63e-4073-a78b-968e645bdfdc
private void onWin(Client winner, Client loser) { isOnGame = false; winner.println(WON_MESSAGE); winner.println(winnerLine); loser.println(LOST_MESSAGE); loser.println(winnerLine); System.out.println(winner.getNick() + " won"); }
9719d053-8f9e-480f-840e-58dd9f6111f4
private void onTie() { isOnGame = false; client1.println(NO_EMPTY_MESSAGE); client2.println(NO_EMPTY_MESSAGE); System.out.println("tie"); }
754107c7-3fa6-4d66-8497-33369e686abd
public RealClient(Socket clientSocket, String nick) { super(clientSocket); this.nick = nick; clientsNumber++; activeClientsNumber++; }
3b7269ac-ee2b-446a-beac-591365444734
public static int getClientsNumber() { return clientsNumber; }
f8b7a179-2d95-40ba-9512-dcadaacdfd68
public static int getActiveClientsNumber() { return activeClientsNumber; }
8b736047-fc29-41c5-95a0-a86558bf50e6
@Override public String getNick() { return nick; }
e39fe15d-7b5c-4269-82ae-7571e8880dfd
@Override public void disconnect() { activeClientsNumber--; super.disconnect(); }
4f2534f3-2e0f-4ddd-bd87-1292d340b7a7
@Override public void start(Stage primaryStage) { drawStage(primaryStage); }
73222669-3ff7-4433-a3fe-0067c63e86d9
private void drawStage(Stage primaryStage) { primaryStage.setTitle("ClientXO"); primaryStage.setOnCloseRequest(new EventHandler() { @Override public void handle(Event t) { onCloseRequest(); } }); GridPane mainGrid = new GridPane(); mainGrid.setPadding(new Insets(5)); mainGrid.setGridLinesVisible(true); double playersInfoColumnWidth = 100; ColumnConstraints columnOpponentInfo = new ColumnConstraints(playersInfoColumnWidth); columnOpponentInfo.setHgrow(Priority.NEVER); ColumnConstraints columnPlayerInfo = new ColumnConstraints(playersInfoColumnWidth); columnPlayerInfo.setHgrow(Priority.NEVER); ColumnConstraints columnCenter = new ColumnConstraints(); columnCenter.setHgrow(Priority.ALWAYS); mainGrid.getColumnConstraints().addAll(columnOpponentInfo, columnCenter, columnPlayerInfo); RowConstraints row = new RowConstraints(200, 200, Double.MAX_VALUE); row.setVgrow(Priority.ALWAYS); mainGrid.getRowConstraints().add(row); mainGrid.add(drawPlayerInfo(labelOpponentNick, HPos.RIGHT), 0, 0); mainGrid.add(drawCenterField(), 1, 0); mainGrid.add(drawPlayerInfo(labelPlayerNick, HPos.LEFT), 2, 0); Scene scene = new Scene(mainGrid); primaryStage.setScene(scene); primaryStage.show(); setOpponentNick("Opponent"); setPlayerNick("Player"); }
cbefce2a-298a-4593-b8e1-14012d06c230
@Override public void handle(Event t) { onCloseRequest(); }
b92e752d-0e57-4173-9be4-3a44c04654fc
private void onCloseRequest() { System.out.println("bye"); }
e97afc86-040c-4ef0-b05d-6884c444316d
private void setOpponentNick(String nick) { labelOpponentNick.setText(nick); }
498f1810-8c40-40c6-961c-9ae6bf44c64f
private void setPlayerNick(String nick) { labelPlayerNick.setText(nick); }
fd8ac988-1de3-4874-8e92-c3da1c9e632e
private GridPane drawCenterField() { GridPane grid = new GridPane(); grid.setGridLinesVisible(true); grid.setPadding(new Insets(5)); grid.setHgap(5); grid.setVgap(5); grid.setPadding(new Insets(5)); RowConstraints rowScore = new RowConstraints(); rowScore.setVgrow(Priority.NEVER); rowScore.setValignment(VPos.CENTER); RowConstraints rowGameField = new RowConstraints(); rowGameField.setVgrow(Priority.ALWAYS); rowGameField.setValignment(VPos.TOP); RowConstraints rowStatus = new RowConstraints(); rowStatus.setVgrow(Priority.NEVER); rowStatus.setValignment(VPos.CENTER); grid.getRowConstraints().addAll(rowScore, rowGameField, rowStatus); ColumnConstraints column = new ColumnConstraints( 200, 200, Double.MAX_VALUE, Priority.ALWAYS, HPos.CENTER, true); grid.getColumnConstraints().add(column); grid.add(labelScore, 0, 0); grid.add(labelStatus, 0, 2); drawGameField(); grid.add(gameField, 0, 1); return grid; }
b56324fb-54a0-4116-a5e4-d874f9b2874a
private void drawGameField() { gameField.setGridLinesVisible(true); for(int i = 0; i < 4; i++) { RowConstraints row = new RowConstraints(); row.setVgrow(Priority.ALWAYS); row.setValignment(VPos.CENTER); gameField.getRowConstraints().add(row); ColumnConstraints column = new ColumnConstraints(); column.setHgrow(Priority.ALWAYS); column.setHalignment(HPos.CENTER); gameField.getColumnConstraints().add(column); } ColumnConstraints column = new ColumnConstraints(); column.setHgrow(Priority.ALWAYS); column.setHalignment(HPos.CENTER); gameField.getColumnConstraints().add(column); gameField.setMinHeight(100); ResizeListener resizeListener = new ResizeListener(gameField, 0, 4, 3); gameField.widthProperty().addListener(resizeListener); gameField.heightProperty().addListener(resizeListener); }
581aaddf-585e-471e-bfef-8610165268e0
private GridPane drawPlayerInfo(Label nick, HPos hpos) { GridPane grid = new GridPane(); grid.setPadding(new Insets(5)); ColumnConstraints column1 = new ColumnConstraints( 0, 0, Double.MAX_VALUE, Priority.ALWAYS, hpos, true); grid.getColumnConstraints().add(column1); grid.add(nick, 0, 0); grid.setGridLinesVisible(true); return grid; }
3960ffe7-d975-4b94-ae6e-d51c1480a9a4
public static void main(String[] args) { launch(args); }
640f6ac6-e92c-4d95-97b2-456f60e721f2
ResizeListener(GridPane gameField, int columnIndex1, int columnIndex2, int rowIndex) { this.gameField = gameField; tunableRow = gameField.getRowConstraints().get(rowIndex); tunableColumn1 = gameField.getColumnConstraints().get(columnIndex1); tunableColumn2 = gameField.getColumnConstraints().get(columnIndex2); }
dd0d36cf-f346-4e5a-8af6-db811c53271c
@Override public void changed(ObservableValue<? extends Number> ov, Number t, Number t1) { double width = gameField.getWidth(); double height = gameField.getHeight(); double delta = Math.abs(width - height); double deltaRow; double deltaColumn; if(width < height) { deltaRow = delta; deltaColumn = 0; } else { deltaRow = 0; deltaColumn = delta / 2; } tunableRow.setMaxHeight(deltaRow); tunableRow.setMinHeight(deltaRow); tunableColumn1.setMaxWidth(deltaColumn); tunableColumn1.setMinWidth(deltaColumn); tunableColumn2.setMaxWidth(deltaColumn); tunableColumn2.setMinWidth(deltaColumn); }
89821fd8-d3f4-4a0c-90d6-bc7ef942aecc
@BeforeClass public void init() { //System.out.println(); }
96d5908a-77d6-4138-852a-3057f3377733
public void init() { Lists.newArrayList(); Maps.newHashMap(); }
24352824-bf63-4fc3-ab01-5cf8389ebf12
@Transactional public void doInMarkerTransactionWithPublic() { }
71c351c3-5309-4a91-a857-4fcb5aea05f8
@Transactional(readOnly = true) public void doInNormalTransactionWithPublic() { }
fe99596e-6038-43db-8d0e-cf3b553376de
@PreDestroy public void foo() { for (int i = 0; i < 10; i++) { for (int k = 0; k < 20; i++) { } } }
94750c61-cb75-4dd6-a945-221e678e1d8c
@Transactional @PreDestroy protected void doInMarkerTransaction() { }
4b4f6f93-a51f-413a-936a-888c764b234a
@PreDestroy @Transactional(readOnly = true) protected void doInNormalTransaction() { }
589e45d1-15d4-4ed8-8492-50c7adba353f
@Transactional(readOnly = true, propagation = Propagation.MANDATORY) protected void doInNormalTransactionWithTwoParams() { }
2e8b751b-4070-4eea-8a24-05e35eb7fc36
@Transactional @PreDestroy private void doInMarkerTransactionPrivate() { }
bc160136-325d-4000-b37a-6902289ff39f
@SuppressWarnings("resource") public static void main(String[] args) { new AnnotationConfigApplicationContext(App.class); }
e15e8e6a-359f-49a1-adac-3d4493300e37
public void sendRedirect(String s) { }
277988f0-7e43-4963-a01c-083b22f37b92
public void method0(ClassWithStringMethod obj) { String strValue = ""; obj.sendRedirect("qqq"); obj.sendRedirect(strValue + "qqq"); obj.sendRedirect(CONST_VALUE); obj.sendRedirect(strValue); }
f05ee225-4170-4592-81c9-5fce1506de5f
@Test public void testApp() { assertTrue( true ); }
eb30bf54-a28a-48d8-9008-f1ea779bff17
public static Color getColor(int systemColorID) { Display display = Display.getCurrent(); return display.getSystemColor(systemColorID); }
e308b574-b616-4f3f-b6d7-eddd5e3b24bb
public static Color getColor(int r, int g, int b) { return getColor(new RGB(r, g, b)); }
ba8bf0c3-1ced-4611-a7e1-dda78a1fc8ef
public static Color getColor(RGB rgb) { Color color = m_colorMap.get(rgb); if (color == null) { Display display = Display.getCurrent(); color = new Color(display, rgb); m_colorMap.put(rgb, color); } return color; }
51d8d589-67c1-4dee-8848-ff3f08f14dba
public static void disposeColors() { for (Color color : m_colorMap.values()) { color.dispose(); } m_colorMap.clear(); }
2c7c7858-f2c4-431f-a278-64db49bd059a
protected static Image getImage(InputStream stream) throws IOException { try { Display display = Display.getCurrent(); ImageData data = new ImageData(stream); if (data.transparentPixel > 0) { return new Image(display, data, data.getTransparencyMask()); } return new Image(display, data); } finally { stream.close(); } }
1fc9937f-b8ca-4a59-92b3-7b0e63884e28
public static Image getImage(String path) { Image image = m_imageMap.get(path); if (image == null) { try { image = getImage(new FileInputStream(path)); m_imageMap.put(path, image); } catch (Exception e) { image = getMissingImage(); m_imageMap.put(path, image); } } return image; }
7ad7678c-2de4-4165-a32a-776c30747e4c
public static Image getImage(Class<?> clazz, String path) { String key = clazz.getName() + '|' + path; Image image = m_imageMap.get(key); if (image == null) { try { image = getImage(clazz.getResourceAsStream(path)); m_imageMap.put(key, image); } catch (Exception e) { image = getMissingImage(); m_imageMap.put(key, image); } } return image; }
1fda385b-7267-49fb-aabb-dd512ca10e70
private static Image getMissingImage() { Image image = new Image(Display.getCurrent(), MISSING_IMAGE_SIZE, MISSING_IMAGE_SIZE); // GC gc = new GC(image); gc.setBackground(getColor(SWT.COLOR_RED)); gc.fillRectangle(0, 0, MISSING_IMAGE_SIZE, MISSING_IMAGE_SIZE); gc.dispose(); // return image; }
8ff95c68-eb98-43bd-8c01-0350164bbb84
public static Image decorateImage(Image baseImage, Image decorator) { return decorateImage(baseImage, decorator, BOTTOM_RIGHT); }
bd94f940-77d2-471b-8fea-0f83d670f733
public static Image decorateImage(final Image baseImage, final Image decorator, final int corner) { if (corner <= 0 || corner >= LAST_CORNER_KEY) { throw new IllegalArgumentException("Wrong decorate corner"); } Map<Image, Map<Image, Image>> cornerDecoratedImageMap = m_decoratedImageMap[corner]; if (cornerDecoratedImageMap == null) { cornerDecoratedImageMap = new HashMap<Image, Map<Image, Image>>(); m_decoratedImageMap[corner] = cornerDecoratedImageMap; } Map<Image, Image> decoratedMap = cornerDecoratedImageMap.get(baseImage); if (decoratedMap == null) { decoratedMap = new HashMap<Image, Image>(); cornerDecoratedImageMap.put(baseImage, decoratedMap); } // Image result = decoratedMap.get(decorator); if (result == null) { Rectangle bib = baseImage.getBounds(); Rectangle dib = decorator.getBounds(); // result = new Image(Display.getCurrent(), bib.width, bib.height); // GC gc = new GC(result); gc.drawImage(baseImage, 0, 0); if (corner == TOP_LEFT) { gc.drawImage(decorator, 0, 0); } else if (corner == TOP_RIGHT) { gc.drawImage(decorator, bib.width - dib.width, 0); } else if (corner == BOTTOM_LEFT) { gc.drawImage(decorator, 0, bib.height - dib.height); } else if (corner == BOTTOM_RIGHT) { gc.drawImage(decorator, bib.width - dib.width, bib.height - dib.height); } gc.dispose(); // decoratedMap.put(decorator, result); } return result; }
5b45aa92-c587-4bb3-bdd7-859580a43eb0
public static void disposeImages() { // dispose loaded images { for (Image image : m_imageMap.values()) { image.dispose(); } m_imageMap.clear(); } // dispose decorated images for (int i = 0; i < m_decoratedImageMap.length; i++) { Map<Image, Map<Image, Image>> cornerDecoratedImageMap = m_decoratedImageMap[i]; if (cornerDecoratedImageMap != null) { for (Map<Image, Image> decoratedMap : cornerDecoratedImageMap.values()) { for (Image image : decoratedMap.values()) { image.dispose(); } decoratedMap.clear(); } cornerDecoratedImageMap.clear(); } } }
58495891-c1ad-4537-b2a6-c1a8d2ece00f
public static Font getFont(String name, int height, int style) { return getFont(name, height, style, false, false); }
b5910a11-a716-4a56-bfc3-ca6965db2871
public static Font getFont(String name, int size, int style, boolean strikeout, boolean underline) { String fontName = name + '|' + size + '|' + style + '|' + strikeout + '|' + underline; Font font = m_fontMap.get(fontName); if (font == null) { FontData fontData = new FontData(name, size, style); if (strikeout || underline) { try { Class<?> logFontClass = Class.forName("org.eclipse.swt.internal.win32.LOGFONT"); //$NON-NLS-1$ Object logFont = FontData.class.getField("data").get(fontData); //$NON-NLS-1$ if (logFont != null && logFontClass != null) { if (strikeout) { logFontClass.getField("lfStrikeOut").set(logFont, Byte.valueOf((byte) 1)); //$NON-NLS-1$ } if (underline) { logFontClass.getField("lfUnderline").set(logFont, Byte.valueOf((byte) 1)); //$NON-NLS-1$ } } } catch (Throwable e) { System.err.println("Unable to set underline or strikeout" + " (probably on a non-Windows platform). " + e); //$NON-NLS-1$ //$NON-NLS-2$ } } font = new Font(Display.getCurrent(), fontData); m_fontMap.put(fontName, font); } return font; }
e4ddcb04-5d6e-4ea5-b36b-215ea29c4919
public static Font getBoldFont(Font baseFont) { Font font = m_fontToBoldFontMap.get(baseFont); if (font == null) { FontData fontDatas[] = baseFont.getFontData(); FontData data = fontDatas[0]; font = new Font(Display.getCurrent(), data.getName(), data.getHeight(), SWT.BOLD); m_fontToBoldFontMap.put(baseFont, font); } return font; }
828fb933-9af7-4004-a00b-95d1e057d105
public static void disposeFonts() { // clear fonts for (Font font : m_fontMap.values()) { font.dispose(); } m_fontMap.clear(); // clear bold fonts for (Font font : m_fontToBoldFontMap.values()) { font.dispose(); } m_fontToBoldFontMap.clear(); }
918458b9-cf62-4187-a047-bf031a72a680
public static Cursor getCursor(int id) { Integer key = Integer.valueOf(id); Cursor cursor = m_idToCursorMap.get(key); if (cursor == null) { cursor = new Cursor(Display.getDefault(), id); m_idToCursorMap.put(key, cursor); } return cursor; }
98a2b204-5651-4bbc-b087-cc09e2e0807e
public static void disposeCursors() { for (Cursor cursor : m_idToCursorMap.values()) { cursor.dispose(); } m_idToCursorMap.clear(); }
a7584cfe-08d2-4f6c-9499-317b0518e003
public static void dispose() { disposeColors(); disposeImages(); disposeFonts(); disposeCursors(); }
33b34f3b-6db7-4eee-8619-94f84edab8e2
public static void main(String[] args) { CateCalcu cc = new CateCalcu(); WordCalcu wc = new WordCalcu(); Algo a = new Algo(); }
869fb978-7d2e-4c95-8cdb-4bb65eeb0855
public static void main(String[] args) { try { NbcMain window = new NbcMain(); window.open(); } catch (Exception e) { e.printStackTrace(); } }
34c5dd9d-3fb8-45fd-a863-0f253df1c0d2
public void open() { Display display = Display.getDefault(); createContents(); shell.open(); shell.layout(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } }
894c6d41-c117-4ce5-a9a1-15a7e934e49b
protected void createContents() { shell = new Shell(); shell.setSize(600, 450); shell.setText("Naive Bayes Classification"); Group grpInput = new Group(shell, SWT.NONE); grpInput.setForeground(SWTResourceManager.getColor(SWT.COLOR_BLACK)); grpInput.setText("Input"); grpInput.setBounds(10, 39, 295, 362); Label lblTrainingSet = new Label(grpInput, SWT.NONE); lblTrainingSet.setBounds(10, 26, 74, 15); lblTrainingSet.setText("Training Set"); List lstEW = new List(grpInput, SWT.BORDER | SWT.H_SCROLL); lstEW.setBounds(10, 198, 275, 55); lstEW.add("Punctuation: . , ; : \" / \\ "); lstEW.add("Common word: với, mà, luôn, bởi, để, của," + "tại, được, cho, trong, là, đã, đó, có, và," + "các, do, khi, như, thế, nhưng, chỉ, sau, việc, về."); final List listInput = new List(grpInput, SWT.BORDER | SWT.V_SCROLL); listInput.setBounds(10, 47, 275, 47); Button btnRunTrainingSet = new Button(grpInput, SWT.NONE); btnRunTrainingSet.addMouseListener(new MouseAdapter() { @Override public void mouseDown(MouseEvent e) { if (!isTraining) { isTraining = true; listInput.add("------------------------------------------"); listInput .add("Training set are load from following paths:"); listInput.add("------------------------------------------"); listInput.add("Path to Advertisement Training Set."); listInput.add(" " + InitCon.PATH + InitCon.CONFIRMED); listInput.add("Path to Non-Advertisement Training Set."); listInput.add(" " + InitCon.PATH + InitCon.NEGATIVE); CateCalcu c = new CateCalcu(); WordCalcu w = new WordCalcu(); } } }); btnRunTrainingSet.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { } }); btnRunTrainingSet.setBounds(27, 317, 63, 35); btnRunTrainingSet.setText("Training"); Label lblTargetData = new Label(grpInput, SWT.NONE); lblTargetData.setBounds(10, 117, 74, 15); lblTargetData.setText("Target Data"); txtTarget = new Text(grpInput, SWT.BORDER); txtTarget.setBounds(8, 138, 277, 21); Button btnClassify = new Button(grpInput, SWT.NONE); btnClassify.addMouseListener(new MouseAdapter() { @Override public void mouseDown(MouseEvent e) { isRun = true; if (isTraining) { txtTarget.setText(InitCon.PATH_TEST); Algo a = new Algo(); } else { String[] buttons = { "OK", "Cancel" }; int rc = JOptionPane.showOptionDialog(null, "Bạn chưa chạy tập dữ liệu huấn luyện", "Warning", JOptionPane.YES_NO_OPTION, 0, null, buttons, null); } } }); btnClassify.setBounds(199, 317, 86, 35); btnClassify.setText("Classify"); Label lblExcludeWord = new Label(grpInput, SWT.NONE); lblExcludeWord.setBounds(10, 179, 74, 15); lblExcludeWord.setText("Exclude Word"); Button btnInfo = new Button(grpInput, SWT.NONE); btnInfo.addMouseListener(new MouseAdapter() { @Override public void mouseDown(MouseEvent e) { isRun = false; Algo a = new Algo(); listLogs.removeAll(); if (isTraining) { listLogs.add("PARAMETER INFO"); listLogs.add("-----------------------------------------"); for (Cate cate : CateCalcu.cs) { if(cate.getName() == "confirmed") { listLogs.add("Rate of advertisement file: " + cate.getRoi()); } else { listLogs.add("Rate of non-advertisement file: " + cate.getRoi()); } } listLogs.add("-----------------------------------------"); listLogs.add("Number of word in: "); listLogs.add("+ Advertisement training set: " + Algo.countCC); listLogs.add("+ Non-advertisement training set: " + Algo.countCN); listLogs.add("-----------------------------------------"); } else { String[] buttons = { "OK", "Cancel" }; int rc = JOptionPane.showOptionDialog(null, "Bạn chưa chạy tập dữ liệu huấn luyện", "Warning", JOptionPane.YES_NO_OPTION, 0, null, buttons, null); } } }); btnInfo.setBounds(107, 317, 75, 35); btnInfo.setText("Info"); Group grpOuput = new Group(shell, SWT.NONE); grpOuput.setText("Ouput"); grpOuput.setBounds(311, 39, 263, 362); Label lblLogs = new Label(grpOuput, SWT.NONE); lblLogs.setBounds(20, 28, 55, 15); lblLogs.setText("Logs"); listLogs = new List(grpOuput, SWT.BORDER | SWT.V_SCROLL); listLogs.setBounds(10, 49, 243, 303); Button btnClear = new Button(grpOuput, SWT.NONE); btnClear.setBounds(191, 18, 62, 25); btnClear.setText("Clear"); btnClear.addMouseListener(new MouseAdapter() { @Override public void mouseDown(MouseEvent e) { listLogs.removeAll(); } }); Button btnAbout = new Button(shell, SWT.NONE); btnAbout.addMouseListener(new MouseAdapter() { @Override public void mouseDown(MouseEvent e) { System.out.println("About me"); String[] buttons = { "OK", "Cancel" }; int rc = JOptionPane.showOptionDialog(null, "Name: Bùi Đức Hiếu - MSSV: 7140231", "About me", JOptionPane.OK_OPTION, 1, null, buttons, null); } }); btnAbout.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { } }); btnAbout.setBounds(496, 10, 78, 25); btnAbout.setText("About me"); }
12ba6354-660c-4146-80f0-633663c2e787
@Override public void mouseDown(MouseEvent e) { if (!isTraining) { isTraining = true; listInput.add("------------------------------------------"); listInput .add("Training set are load from following paths:"); listInput.add("------------------------------------------"); listInput.add("Path to Advertisement Training Set."); listInput.add(" " + InitCon.PATH + InitCon.CONFIRMED); listInput.add("Path to Non-Advertisement Training Set."); listInput.add(" " + InitCon.PATH + InitCon.NEGATIVE); CateCalcu c = new CateCalcu(); WordCalcu w = new WordCalcu(); } }
e05347a3-6ff9-4a18-ab29-856019c75b5a
@Override public void widgetSelected(SelectionEvent e) { }
71479f75-3680-41c5-bf68-51e84ec53f14
@Override public void mouseDown(MouseEvent e) { isRun = true; if (isTraining) { txtTarget.setText(InitCon.PATH_TEST); Algo a = new Algo(); } else { String[] buttons = { "OK", "Cancel" }; int rc = JOptionPane.showOptionDialog(null, "Bạn chưa chạy tập dữ liệu huấn luyện", "Warning", JOptionPane.YES_NO_OPTION, 0, null, buttons, null); } }
5593c217-546b-4b81-814e-08acbe1d54e2
@Override public void mouseDown(MouseEvent e) { isRun = false; Algo a = new Algo(); listLogs.removeAll(); if (isTraining) { listLogs.add("PARAMETER INFO"); listLogs.add("-----------------------------------------"); for (Cate cate : CateCalcu.cs) { if(cate.getName() == "confirmed") { listLogs.add("Rate of advertisement file: " + cate.getRoi()); } else { listLogs.add("Rate of non-advertisement file: " + cate.getRoi()); } } listLogs.add("-----------------------------------------"); listLogs.add("Number of word in: "); listLogs.add("+ Advertisement training set: " + Algo.countCC); listLogs.add("+ Non-advertisement training set: " + Algo.countCN); listLogs.add("-----------------------------------------"); } else { String[] buttons = { "OK", "Cancel" }; int rc = JOptionPane.showOptionDialog(null, "Bạn chưa chạy tập dữ liệu huấn luyện", "Warning", JOptionPane.YES_NO_OPTION, 0, null, buttons, null); } }
f41d3452-0983-43e0-bbca-08c66b1841fb
@Override public void mouseDown(MouseEvent e) { listLogs.removeAll(); }
88f2f481-c682-4154-8b16-1f017cae4458
@Override public void mouseDown(MouseEvent e) { System.out.println("About me"); String[] buttons = { "OK", "Cancel" }; int rc = JOptionPane.showOptionDialog(null, "Name: Bùi Đức Hiếu - MSSV: 7140231", "About me", JOptionPane.OK_OPTION, 1, null, buttons, null); }
99f69f8d-a065-4daa-b828-ff63f221d8b2
@Override public void widgetSelected(SelectionEvent e) { }
0bbb6988-555a-4299-af7e-9ec2788a54ba
public String getName() { return name; }
53f2f345-e7ea-454b-adb3-61c9648c0b3c
public void setName(String name) { this.name = name; }
1b47a068-7325-4e63-a7e5-dfe6f857602c
public double getRoi() { return roi; }
437c5ec4-ac3b-40d4-b19d-289d60a659d4
public void setRoi(double roi) { this.roi = roi; }
e2079c0d-163d-4e22-9ecb-f5bcb7587435
public Cate(String cat, double roi) { super(); this.name = cat; this.roi = roi; }
6e9a33f2-4be3-473d-8a21-79fdc524ee70
public String getValue() { return value; }
552dee4a-d717-457a-9caa-2e57946276d7
public void setValue(String value) { this.value = value; }
940b2c08-e5e4-48bc-9f48-e1956b50f456
public int getNoa() { return noa; }
8856a180-d629-44b0-9637-ef8705ffa934
public void setNoa(int noa) { this.noa = noa; }
475051b3-55f2-424c-a84c-ffd338e70c7e
public int getAic() { return aic; }
f03ef13a-910c-4b52-acb8-7992d881ef09
public void setAic(int aic) { this.aic = aic; }
496ab98e-13c8-4b61-9f55-2028a00c6fa7
public int getAin() { return ain; }
db1e6e71-9e08-46cc-8fb8-06d161d9ac4b
public void setAin(int ain) { this.ain = ain; }
02071b83-4b95-4a7b-b99c-5ae13a5313d5
public double getPc() { return pc; }
fbf5b7b7-6367-41ac-80dc-d9ab66015ff0
public void setPc(double pc) { this.pc = pc; }
68cd1f19-6a64-4c20-8835-947d151a7e16
public double getPn() { return pn; }
7e006361-c2f3-4c0d-932c-40555ee14e94
public void setPn(double pn) { this.pn = pn; }