id
stringlengths
36
36
text
stringlengths
1
1.25M
5d04e64a-29f7-407f-bbd8-d94710149ec7
private static String unescape_space(String s) { s = s.replace("%20", " "); return s; }
2a2f61be-8fac-4674-9456-12ed149569e1
private static String unescape_unicode_rus(String s) { for (int index = 0; index < ESCAPE_CHARS.length; ++index) s = s.replace(ESCAPE_CHARS[index], RUSSIAN_CHARS[index]); return s; }
3acf0688-8b91-418f-903f-c98f9abd1a82
private static String unescape_win1251_rus(String s) { for (int index = 0; index < WIN1251_CHARS.length; ++index) s = s.replace(WIN1251_CHARS[index], RUSSIAN_CHARS[index]); return s; }
cc684ba0-2e9c-4750-ac17-88a5905db4a4
public static String replaceToUpCase(String s, Pattern p) { StringBuilder text = new StringBuilder(s); Matcher m2 = p.matcher(text); int matchPointer = 0;// First search begins at the start of the string while (m2.find(matchPointer)) { matchPointer = m2.end(); // Next search starts from where this one // ended text.replace(m2.start(), m2.end(), m2.group().toUpperCase()); } return text.toString(); }
653c202a-b118-4f7d-9df7-274484b1a053
public static byte[] readRawLine(InputStream inputStream) throws IOException { ByteArrayOutputStream buf = new ByteArrayOutputStream(); int ch; while ((ch = inputStream.read()) >= 0) { buf.write(ch); if (ch == '\n') { break; } } if (buf.size() == 0) { return null; } return buf.toByteArray(); }
d8005484-0333-498c-981b-c8ad808e8e1f
public static String readLine(InputStream inputStream) throws IOException { byte[] rawdata = readRawLine(inputStream); if (rawdata == null) { return null; } int len = rawdata.length; int offset = 0; if (len > 0) { if (rawdata[len - 1] == '\n') { offset++; if (len > 1) { if (rawdata[len - 2] == '\r') { offset++; } } } } return getString(rawdata, 0, len - offset); }
7ae7a215-8eee-46ef-8a35-f905e5557197
public static String getString(final byte[] data, int offset, int length) { if (data == null) { throw new IllegalArgumentException("Parameter may not be null"); } try { return new String(data, offset, length, HTTP_ELEMENT_CHARSET); } catch (Exception e) { return new String(data, offset, length); } }
581055bc-e68d-4492-98b2-70eb24d17150
public static void main(String[] args) throws UnknownHostException, IOException { try { ServerSocket serverSocket = new ServerSocket(3132, 50, InetAddress.getByName("localhost")); // ServerSocket serverSocket = new ServerSocket(3132, 1000, InetAddress.getByName("192.168.117.121")); // ServerSocket serverSocket = new ServerSocket(3132); // serverSocket.setSoTimeout(10 * 1000); // System.out.println(InetAddress.getByName("localhost")); // System.out.println("proxy is started"); ExecutorService executorService = Executors.newFixedThreadPool(10); LOGGER.info(InetAddress.getByName("localhost")); LOGGER.info("proxy is started"); while (true) { Socket client = null; try { client = serverSocket.accept(); LOGGER.info("Got new request" + client.getInetAddress().toString()); executorService.submit(new CacheThread(client)); // CacheThread cacheThread = new CacheThread(client); // cacheThread.start(); // cacheThread.join(); LOGGER.info("Complete request: " + client.getInetAddress().toString()); } catch (Exception ex) { LOGGER.error(ex.getMessage(), ex); client.close(); } } } catch (Exception e) { LOGGER.error(e.getMessage(), e); } // by socket binding error }
c517ebee-7c69-4504-afb2-0153aa954bba
private ThreadPool() { }
7fc98177-7370-427b-a0aa-b7d8ca60c30a
public static ThreadPool getInstance() { return INSTANCE; }
9308f429-6e9f-4b7f-bd7a-3f11fd804e57
public void addOrPut(Socket s) throws Exception { InputStream is; // входящий поток от сокета OutputStream os; // исходящий поток от сокета is = s.getInputStream(); os = s.getOutputStream(); byte buf[] = new byte[64 * 1024]; int r = is.read(buf); String header = new String(buf, 0, r); if (header.indexOf("GET ", 0) == 0) { String path = getPath(header); if (path == null) { printError(os, "invalid request:\n" + header); return; } } }
ce3469a5-c08a-4f30-99c2-3bef83de1749
protected void printError(OutputStream os, String err) throws Exception { os.write((new String(PROXY_ERROR + err)).getBytes()); }
c55a0c4e-51cf-4bab-8bd2-8f18197a3bf6
public AppTest( String testName ) { super( testName ); }
6079e89f-7376-4eac-b419-9247a22d32bf
public static Test suite() { return new TestSuite( AppTest.class ); }
ee787dab-cb7b-4795-bc74-536dbb21f70d
public void testApp() { assertTrue( true ); }
10301af9-f1c5-4923-945f-1bf0759891b7
public Agent(Simulation controller) { sim = controller; age = 0; energy = 6; }
7aedbc5e-c575-45a2-9433-a979ceab59f8
public void act() { // This function handles all of an Agents' behavior in // any given step. // First, check if the Agent has enough energy to survive // the step, otherwise remove it. if (energy < metabolism) { remove(); } else { // Let the Agent know it has survived another step. age++; // 'Cost of living': Subtracting the metabolism from the // Agents' energy level. energy -= metabolism; // Generating a vector with the Sites that can be moved to, // and a vector with Sites suitable for offspring.. Vector<Site> freeSites = findFreeSites(); // Evaluating each of the possible Sites to move to. // YOU WILL NEED TO IMPLEMENT FINDBESTSITE YOURSELF. Site bestSite = findBestSite(freeSites); // Moving to the best possible Site, and reaping the energy // from it. // YOU WILL NEED TO IMPLEMENT MOVE AND REAP YOURSELF. move(bestSite); reap(bestSite); // Checking if the Agent is fertile and has a free neighboring // Site, and if so, producing offspring. if (energy > procreateReq) { Vector<Site> babySites = findBabySites(); if (babySites.size() > 0) { procreate(babySites); } } } }
5b653354-b9fb-4f6c-8606-f921f8367f93
public Site findBestSite(Vector<Site> freeSites) { // Your own code determining what the best Site is of all // possible freeSites for the agent to move to; Iterator<Site> i = freeSites.iterator(); Site bestSite = new Site(); double gain = Double.NEGATIVE_INFINITY; double newGain; if (i.hasNext()) { bestSite = i.next(); gain = bestSite.getFood() - moveCost*pythagoras(this.xPosition, bestSite.getXPosition(), this.yPosition, bestSite.getYPosition()); } while (i.hasNext()) { Site freeSite = i.next(); newGain = freeSite.getFood()-moveCost*pythagoras(this.xPosition, freeSite.getXPosition(), this.yPosition, freeSite.getYPosition()); if (newGain > gain) { bestSite = freeSite; gain = newGain; } } // Then return the best Site. return bestSite; }
e2a1f03f-6cc5-4e26-bdc7-77bc57e00fda
public void move(Site newSite) { sim.grid[this.xPosition][this.yPosition].setAgent(null); energy -= moveCost*pythagoras(this.xPosition, newSite.getXPosition(), this.yPosition, newSite.getYPosition()); this.xPosition = newSite.getXPosition(); this.yPosition = newSite.getYPosition(); newSite.setAgent(this); }
40b08245-58ca-4732-8cc9-02e1e982a08c
public void reap(Site s) { this.energy += s.getFood(); s.setFood(0.0); }
79e85db8-159c-4a6a-9041-ea45043fff38
public void procreate(Vector<Site> babySites) { energy -= procreateCost; Agent baby = new Agent(sim); sim.agents.add(baby); Site babySite = (Site) babySites.elementAt(0); baby.setPosition(babySite.getXPosition(), babySite.getYPosition()); babySite.setAgent(baby); }
6e64db56-75b3-46e1-b984-a53ff8180667
public void remove() { sim.agents.remove(this); sim.grid[xPosition][yPosition].setAgent(null); }
490abd69-4d84-49ca-a3a6-c60d115fc47c
public Vector<Site> findFreeSites() { Vector<Site> freeSites = new Vector<Site>(); for (int m = -vision; m <= vision; m++) { for (int n = -vision; n <= vision; n++) { Site site; int x = xPosition + m; int y = yPosition + n; if (x >= 0 && x < sim.xSize && y >= 0 && y < sim.ySize) { site = sim.grid[x][y]; Agent occ = site.getAgent(); if (occ == null || this.equals(occ)) { freeSites.addElement(site); } } } } Collections.shuffle(freeSites); return freeSites; }
7dd0e9b6-a132-472f-b4be-48c3f27c468a
public Vector<Site> findBabySites() { Vector<Site> babySites = new Vector<Site>(); for (int m = -1; m <= 1; m++) { for (int n = -1; n <= 1; n++) { Site site; int x = xPosition + m; int y = yPosition + n; if (x >= 0 && x < sim.xSize && y >= 0 && y < sim.ySize) { site = sim.grid[x][y]; Agent occ = site.getAgent(); if (occ == null) { babySites.addElement(site); } } } } Collections.shuffle(babySites); return babySites; }
65a7c65e-d6cf-4019-990a-71ba55c8ba27
public double calculateDistance(int x, int y) { return Math.sqrt(Math.pow((x - xPosition), 2) + Math.pow((y - yPosition), 2)); }
4db16093-0b8b-4d34-ad23-31909eb9d90a
public void setPosition(int x, int y) { xPosition = x; yPosition = y; }
59ab0c48-fa7b-4759-9eb8-b3d62964c1d4
public int getXPosition() { return xPosition; }
3f47ab58-5853-47a9-bb41-32b4ae69cd5e
public int getYPosition() { return yPosition; }
ce1428da-6a10-48cc-a5ef-4718f4797137
public double getEnergy() { return energy; }
3bf5458c-3a75-4d5a-8765-445fa9ea2606
public int getAge() { return age; }
86b983f3-875e-4966-a038-a17a848ab5ef
private double pythagoras(int x1, int x2, int y1, int y2){ return Math.sqrt(Math.pow(Math.abs(x1-x2), 2) + Math.pow(Math.abs(y1-y2), 2)); }
ea262067-fc60-4979-8015-13a81be7a975
public static void main(String args[]) { Simulation sim = new Simulation(); sim.run(); }
271510ee-de8b-470c-a420-f6bc4cd2313f
public Simulation() { epochs = 0; initGrid(); initAgents(); }
eb40d821-faf4-4656-85f9-515e0fd2b453
public void run() { createAndShowGUI(); }
b79d4c0f-a2d9-4b88-9657-47b2c303ae8a
private void createAndShowGUI() { //Create and set up the window. frame = new JFrame("Scape"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setResizable(false); //Set up the content pane. buildUI(frame.getContentPane()); //Display the window. frame.pack(); frame.setLocationRelativeTo(null); frame.setVisible(true); buttonPanel.forwardEpochs.grabFocus(); }
05237203-0d17-4290-a98d-690fdd4af3cd
private void buildUI(Container pane) { pane.setLayout(new FlowLayout()); mainPanel = new MainPanel(this); pane.add(mainPanel); buttonPanel = new ButtonPanel(this); pane.add(buttonPanel); }
1229c55c-5609-4bb4-b21e-08587774b983
private void initGrid() { grid = new Site[xSize][ySize]; for(int x = 0; x < xSize; x++) { for(int y = 0; y < ySize; y++) { double distance = Math.sqrt(Math.pow((center1 - x), 2) + Math.pow((center1 - y), 2)); double distance2 = Math.sqrt(Math.pow((center2 - x), 2) + Math.pow((center2 - y), 2)); double cap = minFood; if(distance <= distance2 && distance >= 0) { cap = maxFood * (1 - distance / spread); } if(distance > distance2 && distance2 >= 0) { cap = maxFood * (1 - distance2 / spread); } if(cap < minFood) { cap = minFood; } grid[x][y] = new Site(cap, x, y); totalFoodCapacity = totalFoodCapacity + cap; } } }
52c35e54-6162-4a2b-aa1d-b034f4a5a5da
private void initAgents() { agents = new Vector<Agent>(); for(int a = 0; a < numAgents; a++) { agents.add(new Agent(this)); } for(int a = 0; a < agents.size(); a++) { int x = 0; int y = 0; boolean free = false; while (!free) { x = gen.nextInt(xSize); y = gen.nextInt(ySize); free = (grid[x][y].getAgent() == null); } Agent agent = agents.elementAt(a); agent.setPosition(x,y); grid[x][y].setAgent(agent); } }
e0575b8c-a91b-42d3-a41a-e82d55a44800
public void step() { for(int x = 0; x < xSize; x++) { for(int y = 0; y < ySize; y++) { grid[x][y].grow(); // YOU WILL NEED TO IMPLEMENT GROW() YOURSELF. } } Collections.shuffle(agents); for(int a = agents.size()-1; a >= 0; a--) { Agent agent = agents.elementAt(a); agent.act(); // YOU WILL NEED TO COMPLETE ACT() YOURSELF. } }
5f439efb-95a6-4148-ba2d-737024c2e264
public ButtonPanel(Simulation controller) { scape = controller; setLayout(new BorderLayout()); setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); info = new JTextPane(); info.setPreferredSize(new Dimension(270, 300)); info.setMaximumSize(new Dimension(270, 300)); info.setEditable(false); info.setOpaque(false); info.setBorder( BorderFactory.createCompoundBorder( BorderFactory.createEmptyBorder(0, 0, 20, 0), BorderFactory.createCompoundBorder( BorderFactory.createEtchedBorder(EtchedBorder.RAISED), BorderFactory.createEmptyBorder(5, 5, 5, 5)))); StyledDocument doc = info.getStyledDocument(); addStylesToDocument(doc); updateInfo(); epochsLabel = new JLabel("", SwingConstants.CENTER); String ep = "Epochs: " + scape.epochs; epochsLabel.setText(ep); buttons1 = new JPanel(); buttons1.setLayout(new FlowLayout()); buttons1.setBorder(BorderFactory.createEmptyBorder(10, 0, 10, 0)); next = new JButton("Next"); next.setActionCommand("next"); next.addActionListener(this); buttons1.add(next); forwardLabel = new JLabel("Enter the number of epochs to forward.", SwingConstants.LEFT); forwardLabel.setVerticalAlignment(SwingConstants.BOTTOM); buttons2 = new JPanel(); buttons2.setLayout(new BoxLayout(buttons2, BoxLayout.LINE_AXIS)); forwardEpochs = new JTextField("100"); forwardEpochs.setMaximumSize(new Dimension(100, 25)); forward = new JButton("Forward"); forward.setActionCommand("forward"); forward.addActionListener(this); buttons2.add(forwardEpochs); buttons2.add(Box.createRigidArea(new Dimension(5, 0))); buttons2.add(forward); buttons3 = new JPanel(); buttons3.setLayout(new BoxLayout(buttons3, BoxLayout.LINE_AXIS)); buttons3.setBorder(BorderFactory.createEmptyBorder(0, 0, 10, 0)); restart = new JButton("Restart"); restart.setActionCommand("restart"); restart.addActionListener(this); exit = new JButton("Exit"); exit.setActionCommand("exit"); exit.addActionListener(this); buttons3.add(Box.createHorizontalGlue()); buttons3.add(restart); buttons3.add(Box.createRigidArea(new Dimension(5, 0))); buttons3.add(exit); body = new JPanel(); body.setLayout(new GridLayout(0, 1)); body.add(epochsLabel); body.add(buttons1); body.add(forwardLabel); body.add(buttons2); this.add(info, BorderLayout.NORTH); this.add(body, BorderLayout.CENTER); this.add(buttons3, BorderLayout.SOUTH); }
9db498a2-373e-4d7a-9893-091fa57162bd
public Dimension getPreferredSize() { return preferredSize; }
56286f19-46b7-4d97-b3f1-9348028b00b7
public void actionPerformed(ActionEvent e) { if ("next".equals(e.getActionCommand())) { update(1); } if ("forward".equals(e.getActionCommand())) { Integer num = new Integer(forwardEpochs.getText()); update(num.intValue()); } if ("restart".equals(e.getActionCommand())) { scape.frame.dispose(); new Simulation().run(); } if ("exit".equals(e.getActionCommand())) { scape.frame.dispose(); } }
23d8a090-ff37-4fe8-a780-28c3a4dc8f85
private void update(int cycles) { if (cycles < 0) { while (true) { scape.step(); addInfo(scape.grid[scape.mainPanel.xSelected][scape.mainPanel.ySelected]); scape.epochs++; String ep = "Epochs: " + scape.epochs; epochsLabel.setText(ep); } } else { for (int c = 0; c < cycles; c++) { scape.step(); addInfo(scape.grid[scape.mainPanel.xSelected][scape.mainPanel.ySelected]); scape.epochs++; String ep = "Epochs: " + scape.epochs; epochsLabel.setText(ep); scape.mainPanel.update(); } } }
d988dce9-2292-4ef0-8bf1-2d9b08d26d89
private void addStylesToDocument(StyledDocument doc) { // Initialize some styles. Style def = StyleContext.getDefaultStyleContext().getStyle(StyleContext.DEFAULT_STYLE); Style regular = doc.addStyle("regular", def); StyleConstants.setFontFamily(def, "SansSerif"); StyleConstants.setFontSize(regular, 14); Style s = doc.addStyle("italic", regular); StyleConstants.setItalic(s, true); s = doc.addStyle("bold", regular); StyleConstants.setBold(s, true); }
7aebe142-7481-4ee0-9f4c-3d2cdbe6cb3a
public void addInfo(Site s) { content[0] = "Scape"; content[1] = "Agents: " + scape.agents.size(); content[2] = newline + "Site"; content[3] = "Coordinates: (" + s.getXPosition() + ", " + s.getYPosition() + ")"; content[4] = "Site food: " + round(s.getFood()); content[5] = newline + "Agent on Site"; Agent a = s.getAgent(); if (a != null) { content[6] = "Agent ID: " + a; content[7] = "Age: " + a.getAge(); content[8] = "Agent Energy: " + round(a.getEnergy()); } else { content[6] = "ID: "; content[7] = "Age: "; content[8] = "Agent Energy: "; } updateInfo(); }
5e94f802-4a01-40f0-a802-8276b824209f
private void updateInfo() { StyledDocument doc = info.getStyledDocument(); try { doc.remove(0, doc.getLength()); for (int i = 0; i < content.length; i++) { doc.insertString(doc.getLength(), content[i] + newline, doc.getStyle(style[i])); } } catch (BadLocationException ble) { System.err.println("Couldn't insert text into text pane."); } }
f797274e-00ff-4ef1-86cd-3c2284e51ce0
public String round(double value) { DecimalFormat df = new DecimalFormat("0.00"); String stringValue = df.format(value); return stringValue; }
02fb4113-7cb0-4b77-a2d7-b2bc2ea94aad
public Site () { food = 0; }
7f4d8986-8486-4b12-b37b-42ba4f41d712
public Site(double cap, int x, int y) { food = foodMax = cap; xPosition = x; yPosition = y; }
87209eb9-930c-4eca-a58b-e90d3ed0a742
public void grow() { double growthFactor = 0.15; food += (foodMax-food)*growthFactor; }
6eb838e5-499a-4694-bd09-8f9e303c4128
public double getFood() { return food; }
993f7b90-62b5-4533-b07d-34f8dbe8dc89
public void setFood(double f) { food = f; }
fe12c51c-120c-41ad-bb46-a05330662e73
public Agent getAgent() { return agent; }
ca1cba26-1317-4e49-ad5d-9856121aa0ef
public void setAgent(Agent a) { agent = a; }
0e93a461-4ac1-4a91-91c7-750e3e2f2b22
public int getXPosition() { return xPosition; }
b9798b62-499d-43fa-99d8-3853f04fb1a4
public int getYPosition() { return yPosition; }
33e084db-0363-4a46-87ea-546423839232
public MainPanel(Simulation controller) { this.scape = controller; xSize = scape.xSize; ySize = scape.ySize; setLayout(new GridLayout(xSize, ySize)); addMouseListener(this); labels = new JLabel[xSize][ySize]; for (int y = 0; y < ySize; y++) { for (int x = 0; x < xSize; x++) { labels[x][y] = new JLabel(""); labels[x][y].setOpaque(true); labels[x][y].setBorder(BorderFactory.createLineBorder(Color.black)); labels[x][y].setHorizontalAlignment(SwingConstants.CENTER); labels[x][y].setVerticalAlignment(SwingConstants.CENTER); add(labels[x][y]); } } update(); }
774ae406-8901-4b8e-9ed9-e7278174858e
public void update() { for (int y = 0; y < ySize; y++) { for (int x = 0; x < ySize; x++) { Site site = scape.grid[x][y]; JLabel label = labels[x][y]; double energy = site.getFood(); double div = (255 / scape.maxFood) * energy; int gradient = (int) (255 - div); Color background; background = (gradient > 235) ? new Color(255, 250, 205) : new Color(gradient, 255, gradient); label.setBackground(background); if (site.getAgent() != null) { label.setText("o"); label.setForeground(Color.red); } else { label.setText(""); } } } }
0e96b58d-61f4-4054-9c82-516cdb0d0394
public Dimension getPreferredSize() { return preferredSize; }
dfadb17b-ab0d-4d59-9e42-8ff301e60324
public void mouseClicked(MouseEvent e) { labels[xSelected][ySelected].setBorder(BorderFactory.createLineBorder(Color.black)); xSelected = e.getX() / (650 / xSize); ySelected = e.getY() / (650 / ySize); labels[xSelected][ySelected].setBorder(BorderFactory.createLineBorder(Color.red)); scape.buttonPanel.addInfo(scape.grid[xSelected][ySelected]); }
c65951d6-bd2d-4bd2-b55c-c1ca9ed3be0b
public void mouseMoved(MouseEvent e) { }
67d64c8d-9bd3-4824-8291-50ec84d3cbce
public void mouseExited(MouseEvent e) { }
e682b102-ca00-40a8-926b-5401d9426f75
public void mouseReleased(MouseEvent e) { }
2c3ae05e-55c7-47ad-82de-1a2bfbad9230
public void mouseEntered(MouseEvent e) { }
051eac88-b658-496a-b501-c3027d33a754
public void mousePressed(MouseEvent e) { }
703b653b-430f-47d3-839f-cef25ef88507
public void mouseDragged(MouseEvent e) { }
e7bb6031-0d2b-4a2b-a0f0-a38cc901e2e7
@Override public void start(Stage primaryStage) throws Exception{ PresenterImpl mainPresenter = new PresenterImpl(primaryStage); mainPresenter.show(); }
572d4fd2-aecc-4521-b645-8c2f46b9f2cf
public static void main(String[] args) { // System.out.println("os.name="+System.getProperty("os.name")); launch(args); }
69dd0347-c1ec-4426-9a38-5d86be996a0e
@Override public int check(int attempt) { this.lastAttempt = attempt; this.noAttepts++; if (attempt > this.number) return 1; if (attempt < this.number) return -1; return 0; }
8d52d835-4ae4-4eff-8afa-f2827a5bf9b3
@Override public void generateRandomNumber(int maxNumber) { this.lastAttempt = 0; this.noAttepts=0; Random r = new Random(); this.number = r.nextInt(maxNumber); System.out.println("generated number: "+this.number); }
d88fd023-5cf4-4f34-871c-bf8df9acf0e0
@Override public int getLastTry() { return this.lastAttempt; }
107502f0-5445-48e3-b70e-857f21132306
@Override public int getNoAttepts() { return this.noAttepts; }
11f9ced1-8ff2-47c4-81f9-c0abd24994f6
public int check(int number);
f8b8c6c8-1d68-4ec0-a66d-53aed0ad3484
public void generateRandomNumber(int maxNumber);
1c5f1f6b-3b39-46ab-bea1-aa2b9adec9f3
public int getLastTry();
062e1670-c954-440b-bdc5-39e0aa62faab
public int getNoAttepts();
6760faee-0b8b-44af-81af-763e7caaf8b7
public PresenterImpl(Stage stage) { this.stage = stage; this.model = getModel(); }
0b9b14e0-6043-4897-ad0b-ef436184fc9b
public void show() throws Exception { gamePresenter = getGamePresenter(); newGame(); Scene scene = new Scene(gamePresenter.getViewRoot()); stage.setScene(scene); stage.setTitle("FindNumber FXML"); // setScreenSize(); // stage.setMaximised(true);// available in JavaFX 8 // reakcja na wcisniecie krzyzyka stage.setOnCloseRequest(new EventHandler<WindowEvent>() { public void handle(final WindowEvent e) { e.consume(); // Consuming the event by default. Wymagane zeby klikniecie w krzyzyk otwarlo popup zamiast zamknac aplikacji // new CloseAppDialog(stage, "Question"); applicationExitShowConfirmDialog(); } }); // stage.setFullScreen(true); setWindowStyle(); stage.show(); stage.centerOnScreen(); }
74f50e41-2ece-4f52-8680-21a957fce6b9
public void handle(final WindowEvent e) { e.consume(); // Consuming the event by default. Wymagane zeby klikniecie w krzyzyk otwarlo popup zamiast zamknac aplikacji // new CloseAppDialog(stage, "Question"); applicationExitShowConfirmDialog(); }
ead8a7ff-4c51-4677-95b8-dbe8eb995f85
private void setScreenSize() { Rectangle2D screenBounds = Screen.getPrimary().getVisualBounds(); stage.setX(0); stage.setY(0); stage.setWidth(screenBounds.getWidth()); stage.setHeight(screenBounds.getHeight()); }
88c5e36e-d76b-4a79-a089-52a552fc5bc1
private void setWindowStyle() { stage.initStyle(StageStyle.DECORATED); // stage.initStyle(StageStyle.UNDECORATED); }
cc60dd80-a42b-46c9-8530-4e5ee3493cac
public GamePresenter getGamePresenter() { if (gamePresenter == null) { try { FXMLLoader loader = new FXMLLoader(getClass().getResource("../view/game/game.fxml")); loader.load(); gamePresenter = loader.getController(); if (gamePresenter == null) System.out.println("gamePresenter null"); gamePresenter.setPresenterImpl(this); } catch (IOException e) { throw new RuntimeException("Unable to load game.fxml", e); } } return gamePresenter; }
e2196115-b13a-4833-b8e4-859400c5a729
public ModelInterface getModel() { if (model == null) { model = new Model(); // initMock(); } return model; }
6674b84b-c1c3-43eb-8ce0-7fb3d8a53170
private void initMock() { model = Mockito.mock(Model.class); Mockito.when(model.check(Mockito.anyInt())).thenReturn(100); Mockito.when(model.check(501)).thenReturn(0); Mockito.when(model.check(400)).thenReturn(-1); Mockito.when(model.check(600)).thenReturn(1); }
8e58f173-d7ba-45f5-8fd6-4ce642290f30
@Override public void applicationExitShowConfirmDialog() { System.out.println("application exit"); closeAppDialog = new CloseAppDialog(stage, "Question"); closeAppDialog.setPresenterImpl(this); }
b9d11940-9b9f-4708-9585-40bb9d53939a
@Override public void applicationExit() { if (closeAppDialog == null) return; if (!closeAppDialog.isButtonOkPressed()) return; stage.close(); }
54d5679c-33c3-40ff-8f80-e81d494ccf00
@Override public void showInfoVictory() { String m = "victory: correct number"; System.out.println(m); gamePresenter.addTryHistory(getMessageForAttemptsHistory(m)); gamePresenter.showInfo(m); }
dd8444a0-fb3c-4296-8c98-ecb1ba9f20e0
@Override public void showInfoNumberToLow() { String m = "number to low"; System.out.println(m); gamePresenter.addTryHistory(getMessageForAttemptsHistory(m)); gamePresenter.showInfo(m); }
e44b8a19-588f-406d-96dc-288ebf63ec70
private String getMessageForAttemptsHistory(String m) { return model.getNoAttepts() + ": " + model.getLastTry() + " " + m; }
6f6a26d0-9b14-460d-b28c-9903857afe93
@Override public void showInfoNumberToBig() { String m = "number to big"; System.out.println(m); gamePresenter.addTryHistory(getMessageForAttemptsHistory(m)); gamePresenter.showInfo(m); }
9f23d7a4-ebfe-4b80-9b38-a47a054ec22f
@Override public void setFieldsActive(boolean active) { gamePresenter.setFieldsActive(active); }
64779685-5f93-4c89-a8d1-6068e9487f5b
@Override public void newGame() { model.generateRandomNumber(1000); gamePresenter.setFieldsActive(true); gamePresenter.clearAtteptsHistory(); }
cb5f4158-cbfc-403b-a978-123138c30943
@Override public void processTry(int number) { int wynik = model.check(number); System.out.println("wynik=" + wynik); if (wynik == 0) showInfoVictory(); else if (wynik < 0) showInfoNumberToLow(); else if (wynik > 0) showInfoNumberToBig(); if (wynik == 0) setFieldsActive(false); else setFieldsActive(true); }
f9739791-ef2b-4b2c-9cef-646b236a9dd9
public void applicationExit();
a5ac9bcc-722e-4123-b0b6-1f63f9766396
public void applicationExitShowConfirmDialog();
37abc20e-cc80-4819-8808-64e241e4a450
public void showInfoVictory();
d04ffcd9-b888-406a-a279-00badc95534e
public void showInfoNumberToLow();
2e0c1f6b-4b13-4117-8f22-05100f1f7d9c
public void showInfoNumberToBig();
d168d4cd-1711-437e-9a39-5d2acce2607a
public void setFieldsActive(boolean active);
d0ba21d6-cbc5-4e39-849e-9335e3cde9b7
public void newGame();