@Test public void shouldOpenFileAndShowItsContent() { String PATH = "something.txt"; frame.setProvider(ip); collector.decorate = false; frame.setModelProcessor( new ModelProcessor() { @Override public String asUrlString(Model model) { return "" + model.ocurrencesOf(111) + ";" + model.ocurrencesOf(222); } }); window.menuItemWithPath("File", "Open").click().robot.waitForIdle(); robot().waitForIdle(); JFileChooserFixture fc = window.fileChooser("open"); fc.selectFile(new File(PATH)); fc.approve(); robot().waitForIdle(); assertEquals("2.0;1.0", frame.output.getResult()); }
/*----------------------------------------------------------------------- * testshowFinishMsg1() * * 1. 預期螢幕顯示 : * [結束了] * 2. 呼叫 UI.showFinishMsg() 印出結束訊息 * 3. assert equal of the two results * *-----------------------------------------------------------------------*/ public void testshowFinishMsg1() { String expected = "結束了\r\n"; UI aUI = new UI(true); aUI.showFinishMsg(); assertEquals(expected, outContent.toString()); }
// initialize objects for game class private void initGame() { Game.setBank(new Bank()); Game.setBoard(new Board()); CardsChance chance = new CardsChance(); chance.fillValues(); chance.shuffleCards(); Game.setCardsChance(chance); CardsCommunity community = new CardsCommunity(); community.fillValues(); community.shuffleCards(); Game.setCardsCommunity(community); // ask for players and fill them up int choice; do { choice = UI.askNgetInt("How many players (2-4)?"); } while (choice > 4 || choice < 2); Game.setNumPlayers(choice); for (int i = 0; i < Game.getNumPlayers(); i++) { Game.addPlayer(UI.askNgetString("Enter name for player #" + (i + 1))); } // display all players UI.displayChoiceItems( "Players playing", UI.playersToItems(Game.getAllPlayingPlayers()), false, false); }
public void create() { Thread.setDefaultUncaughtExceptionHandler( new UncaughtExceptionHandler() { public void uncaughtException(Thread thread, Throwable ex) { ex.printStackTrace(); Runtime.getRuntime().halt(0); // Prevent Swing from keeping JVM alive. } }); prefs = Gdx.app.getPreferences("spine-skeletonviewer"); ui = new UI(); batch = new PolygonSpriteBatch(); renderer = new SkeletonMeshRenderer(); debugRenderer = new SkeletonRendererDebug(); skeletonX = (int) (ui.window.getWidth() + (Gdx.graphics.getWidth() - ui.window.getWidth()) / 2); skeletonY = Gdx.graphics.getHeight() / 4; ui.loadPrefs(); loadSkeleton( Gdx.files.internal( Gdx.app .getPreferences("spine-skeletonviewer") .getString("lastFile", "spineboy/spineboy.json"))); ui.loadPrefs(); }
public void run() { try { for (Slice.FileData data = slice.readNextFile(); data != null; data = slice.readNextFile()) { FileList.FileLocation file = data.file; ByteArrayInputStream in = new ByteArrayInputStream(data.data); decoder.SetDecoderProperties(data.props); String fileName = destpath + "/" + file.fileName; File f = new File(fileName); f.getParentFile().mkdirs(); // check if we need to undo the tranformation on x86 executables if ((file.fileName.contains(".exe") || file.fileName.contains(".dll"))) { // TODO there is an attribute for this ByteArrayOutputStream out = new ByteArrayOutputStream(); decoder.Code(in, out, file.originalSize); byte[] decompressedData = out.toByteArray(); Util.transformCallInstructions(decompressedData); BufferedOutputStream outfile = new BufferedOutputStream(new FileOutputStream(f)); outfile.write(decompressedData); outfile.close(); } else { BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(f)); decoder.Code(in, out, file.originalSize); out.close(); } f.setLastModified(file.mtime.getTime()); ui.increaseProgress(); } } catch (Exception e) { ui.showError(e.getLocalizedMessage()); e.printStackTrace(); } }
// when game is initialized the game can start playing, this is main loop in // which will the game stay will somebody wins private void startGame() { // while there is still anybody playing loop this while (Game.anyPlayerPlaying()) { if (Game.getCurrentPlayer().isPlaying()) { if (Game.getCurrentPlayer().didYouWon()) { // somebody won, change him to "non-playing" state as well so the loop // will exit properly UI.anounceWinner(Game.getCurrentPlayer()); Game.getCurrentPlayer().giveUp(); } else { // in all other cases display board and his options depending on jail // status UI.displayBoard(); if (Game.getCurrentPlayer().getJailTime() > 0) { jailOptions(); } else { playerOptions(); } } } Game.nextPlayer(); } }
/** thread's run() method that does all the work in the right order */ public void run() { try { if (log != null) log.println( "-------------------\ncartridge " + gwcfile.name + " started (openWIG r" + VERSION + ")\n-------------------"); prepareState(); if (doRestore) restoreGame(); else newGame(); loglevel = LOG_PROP; ui.debugMsg("Starting game...\n"); ui.start(); player.refreshLocation(); cartridge.callEvent(doRestore ? "OnRestore" : "OnStart", null); ui.refresh(); eventRunner.unpause(); mainloop(); } catch (IOException e) { ui.showError("Could not load cartridge: " + e.getMessage()); } catch (Throwable t) { stacktrace(t); } finally { ui.end(); } }
@Override public boolean hit(IPointerEvent e) { int x = e.getX(); int y = e.getY(); UI ui = getUI(); float bx = ui.getX() + getX() * (BUTTON_GAP + BUTTON_WIDTH); float by = ui.getY() + getY() * (BUTTON_GAP + BUTTON_HEIGHT); return x >= bx && x <= bx + BUTTON_WIDTH && y >= by && y <= by + BUTTON_HEIGHT; }
public void run() { // perform the actual sync try { ui.blockForSaving(); savegame.store(state.getEnvironment()); } catch (IOException e) { log("STOR: save failed: " + e.toString(), LOG_WARN); ui.showError("Sync failed.\n" + e.getMessage()); } finally { ui.unblock(); } }
/** Draw the number in the square at x,y, using white circles */ public void drawNumber(int num, double x, double y) { double xOff = x - DIAM / 2; // offset by radius of spots double yOff = y - DIAM / 2; // offset by radius of spots double left = xOff + WIDTH * 0.25; double centr = xOff + WIDTH * 0.5; double right = xOff + WIDTH * 0.75; double top = yOff + WIDTH * 0.25; double mid = yOff + WIDTH * 0.5; double bot = yOff + WIDTH * 0.75; UI.setColor(Color.white); if (num % 2 == 1) { // 1, 3, 5 UI.fillOval(centr, mid, DIAM, DIAM); } if (num > 1) { // 2, 3, 4, 5, 6 UI.fillOval(left, top, DIAM, DIAM); UI.fillOval(right, bot, DIAM, DIAM); } if (num > 3) { // 4, 5, 6 UI.fillOval(left, bot, DIAM, DIAM); UI.fillOval(right, top, DIAM, DIAM); } if (num == 6) { UI.fillOval(left, mid, DIAM, DIAM); UI.fillOval(right, mid, DIAM, DIAM); } }
/** * Method for testing the dominos Creates 49 dominos, and draws them in a table, and the flipped * versions in a table beside it */ public static void main(String[] arguments) { UI.setImmediateRepaint(false); double flippedLeft = 8 * (WIDTH + 5); for (int row = 0; row <= 6; row++) { for (int col = 0; col <= 6; col++) { Domino dom = new Domino(); double x = col * (WIDTH + 5); double y = row * (HEIGHT + 5); dom.draw(x, y); dom.flip(); dom.draw(flippedLeft + x, y); } } UI.repaintGraphics(); }
/** Destructor. */ protected void finalize() throws Throwable { if (getbDoFinalize()) { __finalize(this.getNativeRef()); dontFinalize(); // finalize once. } super.finalize(); }
/** main loop - periodically copy location data into Lua and evaluate zone positions */ private void mainloop() { try { while (!end) { try { if (gps.getLatitude() != player.position.latitude || gps.getLongitude() != player.position.longitude || gps.getAltitude() != player.position.altitude) { player.refreshLocation(); } cartridge.tick(); } catch (Exception e) { stacktrace(e); } try { Thread.sleep(1000); } catch (InterruptedException e) { } } if (log != null) log.close(); } catch (Throwable t) { ui.end(); stacktrace(t); } finally { instance = null; state = null; if (eventRunner != null) eventRunner.kill(); eventRunner = null; } }
protected List<SButton> getAllOrderButtons(List<? extends Humanoid> selectedHumanoids) { Game kc = Rpg.getGame(); allOrderButtons.clear(); orders.clear(); orderTypes.clear(); if (selectedHumanoids == null) return allOrderButtons; for (LivingThing lt : selectedHumanoids) if (lt.getPossibleOrders() != null) orders.addAll(lt.getPossibleOrders()); List<? extends Humanoid> unitsOrdering = selectedHumanoids; OrderButton abButton; for (Order o : orders) { if (orderTypes.contains(o.getOrderType())) continue; abButton = OrderButton.getInstance(kc.getActivity(), o, null, unitsOrdering, ui.getSoldierOrders()); allOrderButtons.add(abButton); orderTypes.add(o.getOrderType()); } return allOrderButtons; }
protected List<SButton> getAllOrderButtons(Humanoid selectedHumanoid) { Game kc = Rpg.getGame(); allOrderButtons.clear(); orders.clear(); orderTypes.clear(); if (selectedHumanoid != null) if (selectedHumanoid.getPossibleOrders() != null) orders.addAll(selectedHumanoid.getPossibleOrders()); ArrayList<Humanoid> unitsOrdering = null; for (Order o : orders) { if (orderTypes.contains(o.getOrderType())) continue; OrderButton abButton = OrderButton.getInstance( kc.getActivity(), o, selectedHumanoid, unitsOrdering, ui.getSoldierOrders()); allOrderButtons.add(abButton); orderTypes.add(o.getOrderType()); } return allOrderButtons; }
private int displayPlayerMenu() { ArrayList<String> items = new ArrayList<String>( Arrays.asList( "Roll dice", "Show my properties", "Show players stats", "Sell to other player", "Downgrade properties", "Mortages", "Give up", "Suspend game (save & exit)", "Stop on request (just exit)")); if (debug) { items.add("Debug options"); } return UI.displayMenuNGetChoice( Game.getCurrentPlayer() + "'s options (" + Bank.moneyEuro(Game.getCurrentPlayer().getCash()) + " cash)", items, false, false); }
/** * Adds the card to the view * * @param sharedPreferences the shared preferences * @param key the key */ private void addCard(SharedPreferences sharedPreferences, String key) { String json = sharedPreferences.getString(key, null); if (json != null) { try { JSONObject jsonData = new JSONObject(json); if (jsonData.has(IMAGE_KEY)) { String image = jsonData.getString(IMAGE_KEY); List<ITopic> cards = getSourceTopicModel(); if (key.equals(POOL_KEY)) { cards.add(0, Cards.pool(image, getActivity())); removeDuplicates(POOL_KEY, cards); } else if (key.equals(FOOD_KEY)) { cards.add(0, Cards.food(image, getActivity())); removeDuplicates(FOOD_KEY, cards); } } else if (jsonData.has(MESSAGE_KEY)) { String message = jsonData.getString(MESSAGE_KEY); List<ITopic> cards = getSourceTopicModel(); cards.add(0, Cards.test(message, getActivity())); } UI.execute(this::filterModel); } catch (JSONException e) { e.printStackTrace(); } } }
private void sendPrepare() { String postT = parentObj.getString("Subject", ""); String postC = postContent.getText().toString(); if (postC.length() == 0) { postContent.requestFocus(); UI.toast("内容不能为空"); return; } File upload = null; /*if (frame.getVisibility() == View.VISIBLE) { Bitmap bitmap = null; try { if (contentUri != null) { bitmap = resizeBitmap(getContentResolver(), contentUri, 400, 300); } else if (outputFileUri != null) { bitmap = resizeBitmap(outputFileUri, 400, 300); } } catch (FileNotFoundException e) {} if (bitmap == null) { UI.toast("图片已经不存在,请重新选择"); return; } upload = new File(MainApp.getOutCacheDir(), TEMP_IMAGE); try { FileOutputStream out = new FileOutputStream(upload); bitmap.compress(Bitmap.CompressFormat.JPEG, 90, out); } catch (Exception e) { e.printStackTrace(); } }*/ sendNow(postT, postC, upload); }
private void initAllData(Intent intent) { String obj = intent.getStringExtra(EXTRA_OBJ); try { JSONObject json = new JSONObject(obj); parentObj = new JSONObjectExt(json); String subject = parentObj.getString("Subject", ""); mChildCount = parentObj.getInt("ChildCount", 0); mChildCount = intent.getIntExtra(EXTRA_CNT, mChildCount); title.setText(subject); } catch (JSONException e) { finish(); UI.toast("无法加载内容"); e.printStackTrace(); return; } mPID = intent.getLongExtra(EXTRA_PID, 0l); mCount = 12; mReachEnd = false; cachedData = new DataArray(null); adapter.notifyDataSetChanged(); onLoadMore(false); }
private void showBitmapForView(ImageView v, final Bitmap bitmap) { v.setImageBitmap(bitmap); Animation a = AnimUtils.FadeIn.loadAnimation(UI.getActivity(), 500); a.setStartOffset(500); v.startAnimation(a); topicView .findViewById(R.id.forum_image_btn) .setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { File f; try { f = Utils.saveTmpBitmap(bitmap); Intent intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType(Uri.fromFile(f), "image/*"); startActivity(intent); } catch (IOException e) { e.printStackTrace(); UI.toast("图片保存出错"); } catch (ActivityNotFoundException e) { UI.toast("无法查看图片,无图库程序"); } } }); }
@Override public void activate(Game g) { // TODO complete consiliarius // Player can pick up all his character cards and lay them again. // Dump board to an array... // Better idea. Create an array of 6 ints, this will hold the new // positions of each card. i.e. array[0] = 4 means that the card at // index 0 will be moved to index 4. // That seems to cause problems, dump board to an array,read off titles // of all those who aren't null (or no card). "Please enter new // location for x", stores new index at current index in array. Gives // this to player.board. super.setUI(g.getUI()); Player current = g.getCurrentPlayer(); String[] cardArray = current.dumpBoard(); int[] newCardLocations = new int[cardArray.length]; for (int i = 0; i < cardArray.length; i++) { if (cardArray[i] == null || super.isBuilding(cardArray[i])) { newCardLocations[i] = -1; } else { System.out.println("Please enter a new location for card " + cardArray[i]); newCardLocations[i] = UI.getInt(0, 6); } } current.reshuffleBoard(newCardLocations); }
private int displayDebugMenu() { ArrayList<String> items = new ArrayList<String>( Arrays.asList( "Exit debugging", ((Game.getDebugDice()) ? "Disable" : "Enable") + " dice debugging", "Jump to tile #", "Execute current tile action", "Set your cash", "Set jail time", "Pick community card", "Pick chance card", "Show deck sizes", "Switch to other player", "Display board", "Access available upgrades")); StdOut.println( "\nWARNING !!! Be careful, you could break the game.\n Some of these functions do not do any sanity checks!!!"); StdOut.println( "And really if some of these functions is used in some situations, it will make the game misbehave."); return UI.displayMenuNGetChoice( "Debug options (" + Bank.moneyEuro(Game.getCurrentPlayer().getCash()) + " cash)", items, true, true); }
public void run(UI ui) throws InterruptedException { this.ui = ui; ui.setreceiver(this); while (sess.alive()) { Message msg; while ((msg = sess.getuimsg()) != null) { if (msg.type == Message.RMSG_NEWWDG) { int id = msg.uint16(); String type = msg.string(); Coord c = msg.coord(); int parent = msg.uint16(); Object[] args = msg.list(); if (type.equals("cnt")) { args[0] = MainFrame.getInnerSize(); } else if (type.equals("img") && args.length >= 1) { if (((String) args[0]).equals("gfx/ccscr")) c = MainFrame.getCenterPoint().add(-400, -300); if (((String) args[0]).equals("gfx/logo2")) c = MainFrame.getCenterPoint().add(-415, -300); if (((String) args[0]).indexOf("gfx/hud/prog/") >= 0) // new addons.HavenUtil.HourglassID = id; // new } else if (type.equals("charlist") && args.length >= 1) { c = MainFrame.getCenterPoint().add(-380, -50); } else if (type.equals("ibtn") && args.length >= 2) { if (((String) args[0]).equals("gfx/hud/buttons/ncu") && ((String) args[1]).equals("gfx/hud/buttons/ncd")) { c = MainFrame.getCenterPoint().add(86, 214); } } else if (type.equals("wnd") && c.x == 400 && c.y == 200) { c = MainFrame.getCenterPoint().add(0, -100); } ui.newwidget(id, type, c, parent, args); } else if (msg.type == Message.RMSG_WDGMSG) { int id = msg.uint16(); String name = msg.string(); ui.uimsg(id, name, msg.list()); } else if (msg.type == Message.RMSG_DSTWDG) { int id = msg.uint16(); ui.destroy(id); if (id == addons.HavenUtil.HourglassID) addons.HavenUtil.HourglassID = -1; // new } } synchronized (sess) { sess.wait(); } } }
private int displayMainMenu() { ArrayList<String> items = new ArrayList<String>(Arrays.asList("Exit monopoly", "Start playing", "Load saved game")); if (UI.enhancedGraphics) { items.add("Switch to " + (UI.dice3D ? "2D dices" : "3D dices")); } return UI.displayMenuNGetChoice("Main Menu", items, true, true); }
/** creates a new global Engine instance */ public static Engine newInstance( CartridgeFile cf, OutputStream log, UI ui, LocationService service) throws IOException { ui.debugMsg("Creating engine...\n"); Engine.ui = ui; Engine.gps = service; instance = new Engine(cf, log); return instance; }
public static FvContext connectFv(TextEdit file, View vi) throws InputException { if (null != tfc && vi == tfc.vi) throw new InputException("can't change command window to display other data"); UI.setTitle(file.toString()); FvContext fvc = FvContext.getcontext(vi, file); fvc.setCurrView(); return fvc; }
@Override public void componentResized(ComponentEvent arg0) { ui.attributesPanel.machineAP.setPreferredSize( new Dimension( ui.getWidth() - ui.drawingPanel.getWidth() - 100, ui.attributesPanel.getHeight() - 100)); ui.attributesPanel.machineAP.revalidate(); repaint(); }
/** * Handle the event * * @param event the event to handle */ public void doHandle(Object event) { SigningStatusRefreshed e = (SigningStatusRefreshed) event; if (!UIState.isReadyToSign()) { // this can happen if for example the user pulled the smart card out after the signature but // before the callback UI.updateUiStatus(MessageLevel.INFO, MessagesEnum.dss_applet_operation_cancelled, null); return; } if (!e.getStatus().isException()) { Event.getInstance().fire(new PdfSignedOk()); } if (e.getStatus().isClean()) { UIState.transitionSigned(); } else if (e.getStatus().isWarning()) { MessagesEnum[] arrayStatusCode = new MessagesEnum[e.getStatus().getWarningStatusCodes().size()]; UI.updateUiStatus( MessageLevel.WARNING, MessagesEnum.dss_applet_message_signature_status_warning, e.getStatus().getWarningStatusCodes().toArray(arrayStatusCode)); UIState.transitionSigned(); } else if (e.getStatus().isException()) { SignatureInformationHome.getInstance().getSignatureEvent().setNeedsUserInput(false); SignatureInformationHome.getInstance().getSignatureEvent().setSigned(false); SignatureInformationHome.getInstance() .getSignatureEvent() .setErrorDescription(e.getStatus().getExceptionStatusCodesAsString()); MessagesEnum[] arrayStatusCode = new MessagesEnum[e.getStatus().getExceptionStatusCodes().size()]; UI.updateUiStatus( MessageLevel.ERROR, MessagesEnum.dss_applet_message_signature_status_error, e.getStatus().getExceptionStatusCodes().toArray(arrayStatusCode)); AsynchronousCallerHome.getInstance() .getCaller() .fire( new ServerCall( AsynchronousServerCall.callServer, ServerCallId.logStatistics, SignatureInformationHome.getInstance().getSignatureEvent())); SignatureInformationHome.getInstance().reset(); } UI.updateUI(); }
public void chat(JPanel panel) { this.panel = panel; userInterface = new UI(player); userInterface.chat(panel); AddKeyListener keyListener = new AddKeyListener(); keyListener.setPlayer(player); keyListenerLayer = new JLayeredPane(); keyListenerLayer.add(keyListener, 10); panel.add(BorderLayout.CENTER, keyListenerLayer); keyListener.setFocusable(true); keyListener.requestFocusInWindow(); panel.add(BorderLayout.CENTER, layeredPane); panel.add(BorderLayout.SOUTH, userInterface.getChatPanel()); panel.validate(); panel.repaint(); // initialize networkStartup.InGameChatInitialize(userInterface.getOutgoing(), userInterface.getIncoming()); panel.addMouseListener( new MouseAdapter() { public void mousePressed(MouseEvent e) { keyListener.setFocusable(true); keyListener.requestFocusInWindow(); } }); userInterface .getOutgoing() .addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { networkStartup.InGameChatSendButtonListener( userInterface.getOutgoing(), userInterface.getIncoming()); } }); // startDrawingPanelThread(); }
public void songManager() { UI ui = new UI(); int choice = ui.getChoice(); Play p = new Play(this); while (choice != 5) { switch (choice) { case 1: sortByArtist(); print(); break; case 2: sortByTitle(); print(); break; case 3: Scanner sc = new Scanner(new InputStreamReader(System.in)); int songChoice = 0; while (songChoice < 1 || songChoice > size()) { System.out.println("Enter Song Choice: "); sortByArtist(); print(); songChoice = sc.nextInt(); } try { p.playSong(songChoice, this); } catch (JavaLayerException e) { // TODO Auto-generated catch block e.printStackTrace(); } break; case 4: if (player != null) { player.close(); } break; default: break; } choice = ui.getChoice(); if (choice == 5) break; } }