@Override public String getMachineCode() { return getOpcode() + Utilities.getBinaryNumber(getRegANum(), 3) + Utilities.getBinaryNumber(getRegBNum(), 3) + "0000" + Utilities.getBinaryNumber(getRegCNum(), 3); }
private BindCardWithSidWindow() { int width = 230; int height = 190; setLayout(null); setBounds( (Utilities.getScreenWidth() - width) / 2, (Utilities.getScreenHeight() - height) / 2, width, height); setAlwaysOnTop(true); setResizable(false); setDefaultCloseOperation(DISPOSE_ON_CLOSE); JLabel cardPromptLbl = new JLabel("卡号:"); cardPromptLbl.setFont(new Font("Courier New", 0, 15)); cardPromptLbl.setBounds(30, 20, 50, 30); add(cardPromptLbl); JLabel sidPromptLbl = new JLabel("学号:"); sidPromptLbl.setFont(new Font("Courier New", 0, 15)); sidPromptLbl.setBounds(30, 50, 50, 30); add(sidPromptLbl); cardLbl = new JLabel(""); cardLbl.setBackground(Color.blue); cardLbl.setFont(new Font("黑体", 0, 15)); cardLbl.setHorizontalAlignment(JLabel.CENTER); cardLbl.setBounds(80, 20, 120, 30); add(cardLbl); sidField = new JTextField(""); sidField.setHorizontalAlignment(JTextField.CENTER); sidField.setFont(new Font("黑体", 0, 15)); sidField.setBounds(80, 50, 120, 30); add(sidField); confirmBtn = new JButton("确定"); confirmBtn.setBounds(75, 100, 80, 40); confirmBtn.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { String text = sidField.getText(); setVisible(false); if (text.length() != 0) { CardDatabase.bindCardWithStudent(cardLbl.getText(), text); } } }); add(confirmBtn); }
public static void main(String[] args) { long start = System.currentTimeMillis(); long result = 0; // find all remainders Set<Integer> set = new HashSet<Integer>(); for (int i = 1; i <= 1000; i++) { set.add(utilities.Utilities.pow(i, i, 250)); } // store remainders in an array int[] remainders = new int[set.size()]; int[] amount = new int[set.size()]; int h = 0; for (int e : set) { remainders[h++] = e; } // find amounts for (int i = 1; i <= 1000; i++) { // for first 1000 int r = utilities.Utilities.pow(i, i, 250); for (int j = 0; j < remainders.length; j++) { if (remainders[j] == r) { amount[j]++; } } } for (int i = 0; i < amount.length; i++) { // for first 250000 amount[i] *= 250; } for (int i = 1; i <= 250; i++) { // for 250,001 - 250,250 int r = utilities.Utilities.pow(i, i, 250); for (int j = 0; j < remainders.length; j++) { if (remainders[j] == r) { amount[j]++; } } } System.out.print(" "); for (int i = 0; i < remainders.length; i++) { System.out.print(remainders[i] + " "); } System.out.println(); for (int i = 0; i < amount.length; i++) { System.out.print(amount[i] + " "); } System.out.println(); System.out.println(result); System.out.println("done in " + (System.currentTimeMillis() - start) + "ms"); }
/** Refreshes preview image. */ private void refreshPreviewImage() { if (originalBackgroundImage != null) { this.scalingRatioToFitContainer = Utilities.getScalingRatioToFitContainer( this.originalBackgroundImage, PANEL_WIDTH, PANEL_HEIGHT); this.backgroundImage = Utilities.scaleImageToFitContainer(this.backgroundImage, PANEL_WIDTH, PANEL_HEIGHT); this.repaint(); } }
/** * Instantiates a new <code>MapPreviewPanel</code>. This constructor is used when we open <code> * AddMapDialog</code> in <code>AddMapDialogMode.EDIT</code> mode. * * @param map <code>RoomMap</code> object * @param parent <code>AddMapDialog</code> parent object * @see AddMapDialog * @see gui.enumeration.AddMapDialogMode */ public MapPreviewPanel(RoomMap map, AddMapDialog parent) { receiverViews = new ArrayList<ReceiverView>(); scalingRatioToFitContainer = 1.0; this.map = map; // TODO: added code Application.getApplication().setRoomMap(this.map); this.originalBackgroundImage = Utilities.deepCopy((BufferedImage) map.getImage()); this.backgroundImage = Utilities.deepCopy((BufferedImage) map.getImage()); this.parent = parent; initializeGui(); }
@Override protected void onPostExecute(Map<String, List<String>> aVoid) { super.onPostExecute(aVoid); Utilities.dismissLoadingDialog(); Utilities.DrawFormFieldsOnLayout( getActivity(), getActivity().getApplicationContext(), linearAddForms, formFields, _currentVisa, visaJson, parameters, NocMainFragment._noc); }
/** * Changes the panel image. When changed, any <code>ReceiverView</code>s placed on the map will be * removed and <code>CoordinateZeroMarkerView</code>'s will be set to (0,0) position. * * @param file <code>File</code> Image file * @see <code>ReceiverView</code> */ public void setPreviewImage(File file) { try { this.backgroundImage = ImageIO.read(file); this.originalBackgroundImage = ImageIO.read(file); this.scalingRatioToFitContainer = Utilities.getScalingRatioToFitContainer( this.originalBackgroundImage, PANEL_WIDTH, PANEL_HEIGHT); this.backgroundImage = Utilities.scaleImageToFitContainer(this.backgroundImage, PANEL_WIDTH, PANEL_HEIGHT); this.map.setImage(originalBackgroundImage); this.map.setPath(file.getAbsolutePath()); } catch (IOException e) { logger.severe("Reading of the image failed.\n" + e.getMessage()); } }
@Nullable @Override public View onCreateView( LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { View view = inflater.inflate(R.layout.noc_second_page, container, false); InitializeViews(view); parameters.put("auth", new StoreData(getActivity()).getNOCAuthorityType()); parameters.put("lang", new StoreData(getActivity().getApplicationContext()).getNOCLanguage()); eServiceAdministration = Utilities.geteServiceAdministration(); soql = SoqlStatements.getInstance() .constructWebFormQuery(eServiceAdministration.getNew_Edit_VF_Generator__c()); perFormFormFieldsRequest(soql); return view; }
/** * Initializes graphical user interface. Layout of this panel is set to <code>null</code> (no * <code>LayoutManager</code>) so that <code>ReceiverView</code> items can be positioned * absolutely. * * @see ReceiverView * @see LayoutManager */ private void initializeGui() { logger = Utilities.initializeLogger(this.getClass().getName()); setSize(new Dimension(PANEL_WIDTH, PANEL_HEIGHT)); setPreferredSize(new Dimension(PANEL_WIDTH, PANEL_HEIGHT)); setBackground(new Color(GRAY_COLOUR, GRAY_COLOUR, GRAY_COLOUR)); setLayout(null); // in order to position ReceiverViews absolutely refreshPreviewImage(); // register all receiver views to the ComponentMover componentMover = new ComponentMover(); // add zero coordinate marker views addCoordinateZeroMarkerViewsToMap(); for (Receiver receiver : map.getReceivers()) { ReceiverView receiverView = new ReceiverView(receiver, this); receiverViews.add(receiverView); this.add(receiverView); // TODO: location should be calculated with offsets for scaling // the image and pixel/meter scaling double receiverPositionInMetersX = receiver.getXPos(); double receiverPositionInMetersY = receiver.getYPos(); double mapRatioWidth = map.getRatioWidth(); double mapRatioHeight = map.getRatioHeight(); int lowerLeftMarkerOffsetXInPixels = map.getLowerLeftMarkerOffsetXInPixels(); int lowerLeftMarkerOffsetYInPixels = map.getLowerLeftMarkerOffsetYInPixels(); int receiverPositionInPixelsX = calculateReceiverPositionInPixelsX( receiverPositionInMetersX, lowerLeftMarkerOffsetXInPixels, mapRatioWidth); int receiverPositionInPixelsY = calculateReceiverPositionInPixelsY( receiverPositionInMetersY, lowerLeftMarkerOffsetYInPixels, mapRatioHeight); receiverView.setLocation(receiverPositionInPixelsX, receiverPositionInPixelsY); componentMover.registerComponent(receiverView); } }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.show_details_view_statement); imageShowDetails = (ImageView) findViewById(R.id.imageShowDetails); imageBack = (ImageView) findViewById(R.id.imageBack); tvEmployeeName = (TextView) findViewById(R.id.tvEmployeeName); tvAmount = (TextView) findViewById(R.id.tvAmount); tvBalance = (TextView) findViewById(R.id.tvBalance); tvDate = (TextView) findViewById(R.id.tvDate); tvStatus = (TextView) findViewById(R.id.tvStatus); Gson gson = new Gson(); FreeZonePayment freeZonePayment = gson.fromJson(getIntent().getExtras().getString("str"), FreeZonePayment.class); if (freeZonePayment.getEffectOnAccount().equals("Debit")) { imageShowDetails.setImageResource(R.drawable.payment_debit); tvAmount.setText(Utilities.stringNotNull(freeZonePayment.getDebitAmount()) + " AED."); tvBalance.setText(""); } else { imageShowDetails.setImageResource(R.drawable.payment_credit); tvAmount.setText(Utilities.stringNotNull(freeZonePayment.getCreditAmount()) + " AED."); tvBalance.setText(Utilities.stringNotNull(freeZonePayment.getClosingBalance())); } imageBack.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { finish(); } }); tvEmployeeName.setText(Utilities.stringNotNull(freeZonePayment.getEmployeeName())); tvDate.setText( !Utilities.stringNotNull(freeZonePayment.getCreatedDate()).equals("") ? Utilities.stringNotNull(freeZonePayment.getCreatedDate()).substring(0, 10) : ""); tvStatus.setText(Utilities.stringNotNull(freeZonePayment.getStatus())); }
private void InitializeViews(View view) { servicePrice = (EditText) view.findViewById(R.id.servicePrice); Utilities.showloadingDialog(activity); new ClientManager( getActivity(), SalesforceSDKManager.getInstance().getAccountType(), SalesforceSDKManager.getInstance().getLoginOptions(), SalesforceSDKManager.getInstance().shouldLogoutWhenTokenRevoked()) .getRestClient( getActivity(), new ClientManager.RestClientCallback() { @Override public void authenticatedRestClient(final RestClient client) { if (client == null) { System.exit(0); } else { String Value = ""; if (activity .getUser() .get_contact() .get_account() .getLegalForm() .equals("DWC-LLC")) { Value = "Branch"; } else if (activity .getUser() .get_contact() .get_account() .getLegalForm() .equals("DWC-Branch")) { Value = "LLC"; } String SoqlEServiceQuery = String.format(eServiceAdmin, Value); try { // Getting E-Service Administration restRequest = RestRequest.getRequestForQuery( getActivity().getString(R.string.api_version), SoqlEServiceQuery); client.sendAsync( restRequest, new RestClient.AsyncRequestCallback() { @Override public void onSuccess(RestRequest request, RestResponse result) { activity.seteServiceAdministration( SFResponseManager.parseReceiptObjectResponse(result.toString()) .get(0)); servicePrice.setText( activity.geteServiceAdministration().getTotal_Amount__c() + "AED"); getRecordType(); } @Override public void onError(Exception exception) { VolleyError volleyError = (VolleyError) exception; NetworkResponse response = volleyError.networkResponse; String json = new String(response.data); Log.d("", json); Utilities.dismissLoadingDialog(); getActivity().finish(); } }); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } } } }); }
/** Created by dyeung on 2/4/16. */ public class LoadGameView extends View { // ----------View Design stuff -------- private final int BUTTON_WIDTH = 200; private final int BUTTON_HEIGHT = 50; private final int START_POSITION = 100; // --------File Path stuff ------- private String saveFilePath = Utilities.getFileSystemDependentPath("src/res/save_files/"); private File[] listOfSaveFiles; public LoadGameView() { this.viewController = new LoadGameController(this); // File folder = new File(saveFilePath); listOfSaveFiles = ((LoadGameController) viewController).getFileNames(); // getNewFiles(); } public void getNewFiles() { // Function is used to update the list of save files in the folder listOfSaveFiles = ((LoadGameController) this.viewController).loadNewFolder(); System.out.println("LGV: " + listOfSaveFiles.length); } public void render(Graphics g) { renderFileButtons(g); } private void renderFileButtons(Graphics g) { g.setFont(VIEW_FONT); FontMetrics fm = g.getFontMetrics(VIEW_FONT); Graphics2D g2d = (Graphics2D) g; g2d.setColor(Color.white); g2d.setFont(new Font("Courier New", Font.PLAIN, 13)); // no saved games to list in for loop below if (listOfSaveFiles.length == 0) { String message = "No Saved Games"; Rectangle2D rectangle = fm.getStringBounds(message, g); int boxX = View.B_WIDTH / 2 - BUTTON_WIDTH / 2; int boxY = BUTTON_HEIGHT + START_POSITION; int boxDX = BUTTON_WIDTH; int boxDY = BUTTON_HEIGHT; int stringX = View.B_WIDTH / 2 - (int) (rectangle.getWidth() / 2); int stringY = BUTTON_HEIGHT + (int) (rectangle.getHeight() / 2) + fm.getAscent() + START_POSITION; Color primaryColor; Color secondaryColor; primaryColor = Color.WHITE; secondaryColor = Color.BLACK; g.setColor(primaryColor); g.fillRect(boxX, boxY, boxDX, boxDY); g.setColor(secondaryColor); g.drawString(message, stringX, stringY); } else { // Draw title Font titleFont = new Font("Courier New", Font.PLAIN, 28); g.setFont(titleFont); fm = g.getFontMetrics(titleFont); String titleString = "Pick the save file you want to load"; Rectangle2D rec = fm.getStringBounds(titleString, g); int xTitle = (View.B_WIDTH / 2 - (int) (rec.getWidth() / 2)); int yTitle = View.B_HEIGHT / 6 + (int) (rec.getHeight() / 2) + fm.getAscent(); g.drawString(titleString, xTitle, yTitle); int START_FILES = yTitle + (int) (rec.getHeight() / 2) + fm.getAscent(); fm = g.getFontMetrics(VIEW_FONT); g.setFont(VIEW_FONT); // display list of files for (int i = 0; i < listOfSaveFiles.length; i++) { File file = listOfSaveFiles[i]; // Exclude .DS_Store file lol. if (file.isFile() && !file.getName().equals(".DS_Store")) { String fileName = file.getName(); Rectangle2D rectangle = fm.getStringBounds(fileName, g); int boxX = View.B_WIDTH / 2 - BUTTON_WIDTH / 2; int boxY = BUTTON_HEIGHT * i + START_FILES; int boxDX = BUTTON_WIDTH; int boxDY = BUTTON_HEIGHT; int stringX = View.B_WIDTH / 2 - (int) (rectangle.getWidth() / 2); int stringY = i * BUTTON_HEIGHT + (int) (rectangle.getHeight() / 2) + fm.getAscent() + START_FILES; Color primaryColor; Color secondaryColor; if (i == (((LoadGameController) this.viewController).getActiveOptions())) { primaryColor = Color.WHITE; secondaryColor = Color.BLACK; } else { primaryColor = Color.BLACK; secondaryColor = Color.WHITE; } g.setColor(primaryColor); g.fillRect(boxX, boxY, boxDX, boxDY); g.setColor(secondaryColor); g.drawString(fileName, stringX, stringY); } } } } }
@Override protected void onPreExecute() { super.onPreExecute(); Utilities.showloadingDialog(getActivity()); }
private void InitializeViews(View view) { tvCardOwnerName = (TextView) view.findViewById(R.id.tvCardOwnerName); image = (DWCRoundedImageView) view.findViewById(R.id.view); linearAddForms = (LinearLayout) view.findViewById(R.id.linearAddForms); if (managementMember != null) { // General Managers tvCardOwnerName.setText( managementMember.get_manager().getName() == null ? "" : managementMember.get_manager().getName()); Utilities.setUserPhoto( getActivity(), Utilities.stringNotNull(managementMember.get_manager().getPersonal_Photo()), image); _views = new ArrayList<>(); _views.add(new DWCView("Personal Information", ItemType.HEADER)); _views.add(new DWCView("Name", ItemType.LABEL)); _views.add( new DWCView( Utilities.stringNotNull(managementMember.get_manager().getName()), ItemType.VALUE)); _views.add(new DWCView("", ItemType.LINE)); _views.add(new DWCView("Nationality", ItemType.LABEL)); _views.add( new DWCView( Utilities.stringNotNull(managementMember.get_manager().getNationality()), ItemType.VALUE)); _views.add(new DWCView("", ItemType.LINE)); _views.add(new DWCView("Passport Number", ItemType.LABEL)); _views.add( new DWCView( managementMember.get_manager() == null ? "" : managementMember.get_manager().getCurrentPassport().getName(), ItemType.VALUE)); _views.add(new DWCView("", ItemType.LINE)); _views.add(new DWCView("Passport Expiry", ItemType.LABEL)); _views.add( new DWCView( managementMember.get_manager() == null ? "" : Utilities.formatVisitVisaDate( Utilities.stringNotNull( managementMember .get_manager() .getCurrentPassport() .getPassport_Expiry_Date__c())), ItemType.VALUE)); _views.add(new DWCView("", ItemType.LINE)); _views.add(new DWCView("Manager Information", ItemType.HEADER)); _views.add(new DWCView("Role", ItemType.LABEL)); _views.add( new DWCView( managementMember.get_manager() == null ? "" : Utilities.stringNotNull(managementMember.getRole()), ItemType.VALUE)); _views.add(new DWCView("", ItemType.LINE)); _views.add(new DWCView("Start Date", ItemType.LABEL)); _views.add( new DWCView( managementMember.get_manager() == null ? "" : Utilities.formatVisitVisaDate( Utilities.stringNotNull(managementMember.getManager_Start_Date())), ItemType.VALUE)); _views.add(new DWCView("", ItemType.LINE)); _views.add(new DWCView("End Date", ItemType.LABEL)); _views.add( new DWCView( managementMember.get_manager() == null ? "" : Utilities.formatVisitVisaDate( Utilities.stringNotNull(managementMember.getManager_End_Date())), ItemType.VALUE)); viewItems = Utilities.drawViewsOnLayout( getActivity(), managementMember, getActivity().getApplicationContext(), _views); } else if (legalRepresentative != null) { // Legal Representatives tvCardOwnerName.setText( legalRepresentative.getLegalRepresentativeLookup().getName() == null ? "" : legalRepresentative.getLegalRepresentativeLookup().getName()); Utilities.setUserPhoto( getActivity(), Utilities.stringNotNull( legalRepresentative.getLegalRepresentativeLookup().getPersonal_Photo()), image); _views = new ArrayList<>(); _views.add(new DWCView("Personal Information", ItemType.HEADER)); _views.add(new DWCView("Name", ItemType.LABEL)); _views.add( new DWCView( Utilities.stringNotNull(legalRepresentative.getLegalRepresentativeLookup().getName()), ItemType.VALUE)); _views.add(new DWCView("", ItemType.LINE)); _views.add(new DWCView("Nationality", ItemType.LABEL)); _views.add( new DWCView( Utilities.stringNotNull( legalRepresentative.getLegalRepresentativeLookup().getNationality()), ItemType.VALUE)); _views.add(new DWCView("", ItemType.LINE)); _views.add(new DWCView("Passport Number", ItemType.LABEL)); _views.add( new DWCView( legalRepresentative.getLegalRepresentativeLookup() == null ? "" : legalRepresentative .getLegalRepresentativeLookup() .getCurrentPassport() .getName(), ItemType.VALUE)); _views.add(new DWCView("", ItemType.LINE)); _views.add(new DWCView("Passport Expiry", ItemType.LABEL)); _views.add( new DWCView( legalRepresentative.getLegalRepresentativeLookup() == null ? "" : Utilities.formatVisitVisaDate( Utilities.stringNotNull( legalRepresentative .getLegalRepresentativeLookup() .getCurrentPassport() .getPassport_Expiry_Date__c())), ItemType.VALUE)); _views.add(new DWCView("", ItemType.LINE)); _views.add(new DWCView("Legal Representatives Information", ItemType.HEADER)); _views.add(new DWCView("Role", ItemType.LABEL)); _views.add( new DWCView( legalRepresentative.getLegalRepresentativeLookup() == null ? "" : Utilities.stringNotNull(legalRepresentative.getRole()), ItemType.VALUE)); _views.add(new DWCView("", ItemType.LINE)); _views.add(new DWCView("Start Date", ItemType.LABEL)); _views.add( new DWCView( legalRepresentative.getLegalRepresentativeLookup() == null ? "" : Utilities.formatVisitVisaDate( Utilities.stringNotNull( legalRepresentative.getLegal_Representative_Start_Date())), ItemType.VALUE)); _views.add(new DWCView("", ItemType.LINE)); _views.add(new DWCView("End Date", ItemType.LABEL)); _views.add( new DWCView( legalRepresentative.getLegalRepresentativeLookup() == null ? "" : Utilities.formatVisitVisaDate( Utilities.stringNotNull( legalRepresentative.getLegal_Representative_End_Date())), ItemType.VALUE)); viewItems = Utilities.drawViewsOnLayout( getActivity(), legalRepresentative, getActivity().getApplicationContext(), _views); } else { // Shareholders tvCardOwnerName.setText( _ShareHolder.get_shareholder().getName() == null ? "" : _ShareHolder.get_shareholder().getName()); Utilities.setUserPhoto( getActivity(), Utilities.stringNotNull(_ShareHolder.get_shareholder().getPersonalPhoto()), image); _views = new ArrayList<>(); _views.add(new DWCView("Personal Information", ItemType.HEADER)); _views.add(new DWCView("Name", ItemType.LABEL)); _views.add( new DWCView( Utilities.stringNotNull(_ShareHolder.get_shareholder().getName()), ItemType.VALUE)); _views.add(new DWCView("", ItemType.LINE)); _views.add(new DWCView("Nationality", ItemType.LABEL)); _views.add( new DWCView( Utilities.stringNotNull(_ShareHolder.get_shareholder().getNationality()), ItemType.VALUE)); _views.add(new DWCView("", ItemType.LINE)); _views.add(new DWCView("Passport Number", ItemType.LABEL)); _views.add( new DWCView( _ShareHolder.get_shareholder() == null ? "" : _ShareHolder.get_shareholder().get_currentPassport().getName(), ItemType.VALUE)); _views.add(new DWCView("", ItemType.LINE)); _views.add(new DWCView("Passport Expiry", ItemType.LABEL)); _views.add( new DWCView( _ShareHolder.get_shareholder() == null ? "" : Utilities.formatVisitVisaDate( Utilities.stringNotNull( _ShareHolder.get_shareholder() .get_currentPassport() .getPassport_Expiry_Date__c())), ItemType.VALUE)); _views.add(new DWCView("", ItemType.LINE)); _views.add(new DWCView("Shareholder Information", ItemType.HEADER)); _views.add(new DWCView("Ownership (%)", ItemType.LABEL)); _views.add( new DWCView( _ShareHolder.get_shareholder() == null ? "" : Utilities.stringNotNull(_ShareHolder.getOwnership_of_Share__c()), ItemType.VALUE)); _views.add(new DWCView("", ItemType.LINE)); _views.add(new DWCView("No.of Share", ItemType.LABEL)); _views.add( new DWCView( _ShareHolder.get_shareholder() == null ? "" : Utilities.stringNotNull( Utilities.processAmount(_ShareHolder.getNo_of_Shares__c())), ItemType.VALUE)); _views.add(new DWCView("", ItemType.LINE)); _views.add(new DWCView("Start Date", ItemType.LABEL)); _views.add( new DWCView( _ShareHolder.get_shareholder() == null ? "" : Utilities.formatVisitVisaDate( Utilities.stringNotNull(_ShareHolder.getOwnership_Start_Date__c())), ItemType.VALUE)); _views.add(new DWCView("", ItemType.LINE)); // _views.add(new DWCView("End Date", ItemType.LABEL)); // _views.add(new DWCView(_ShareHolder.get_shareholder() == null ? "" : // Utilities.stringNotNull(_ShareHolder.getOwnership_End_Date__c()), ItemType.VALUE)); viewItems = Utilities.drawViewsOnLayout( getActivity(), _ShareHolder, getActivity().getApplicationContext(), _views); } linearAddForms.removeAllViews(); linearAddForms.addView(viewItems); }
/** Created by Bradley on 2/1/16. */ public class Map extends Observable { public Tile[][] tiles; private int mapWidth; private int mapHeight; private static final String defaultMap = Utilities.getFileSystemDependentPath("./src/res/maps/default_map.xml"); private int changedX; private int changedY; public Map() { Load_Save.getInstance() .loadMap(this, defaultMap); // whenever it is initialized, the default map will be loaded } public void initMap() { // Load_Save.getInstance().loadMap(defaultMap); } public void setMapInfo(int width, int height, Tile[][] tileArray) { mapHeight = height; mapWidth = width; tiles = tileArray; } public Tile[][] getTiles() { return tiles; } public Terrain getTerrainAtLocation(int x, int y) { if (y < 0 || y >= tiles.length || x < 0 || x >= tiles[0].length) return null; return tiles[y][x].getTerrain(); } public AreaEffect getAreaEffectAtLocation(int x, int y) { return tiles[y][x].getAreaEffect(); } public Decal getDecalAtLocation(int x, int y) { return tiles[y][x].getDecal(); } public Item getItemAtLocation(int x, int y) { return tiles[y][x].getItem(); } public Entity getEntityAtLocation(int x, int y) { return tiles[y][x].getEntity(); } // Mutator functions to tiles notify views.AreaViewport public void insertItemAtLocation(int x, int y, Item item) { tiles[y][x].addItem(item); this.setChanged(); this.changedX = x; this.changedY = y; this.notifyObservers(); } public void insertEntityAtLocation(int x, int y, Entity entity) { tiles[y][x].addEntity(entity); this.setChanged(); this.changedX = x; this.changedY = y; this.notifyObservers(); } public void removeItemFromLocation(int x, int y) { tiles[y][x].removeItem(); this.setChanged(); this.changedX = x; this.changedY = y; this.notifyObservers(); } public void removeEntityFromLocation(int x, int y) { tiles[y][x].removeEntity(); this.setChanged(); this.changedX = x; this.changedY = y; this.notifyObservers(); } public int getMapWidth() { return mapWidth; } public int getMapHeight() { return mapHeight; } }
/* * (non-Javadoc) * * @see dao.MapDAO#getAllMaps() */ @Override public List<RoomMap> getAllMaps() { if (allMaps != null) { return allMaps; } else { allMaps = new ArrayList<RoomMap>(); } // sample maps initialization values RoomMap map = null; BufferedImage image = null; double roomWidth = 0.0; double roomHeight = 0.0; String title = ""; ArrayList<Receiver> receivers = null; // add sample map, id 0 String path1 = "images/room_4m_6m.png"; image = (BufferedImage) Utilities.loadImage(path1); title = "Test Room"; roomWidth = 4.0; roomHeight = 6.0; receivers = new ArrayList<Receiver>(); receivers.add(new Receiver(0, 0.0, 0.0, 45.0, true)); receivers.add(new Receiver(1, 4.0, 0.0, 135.0, true)); receivers.add(new Receiver(2, 4.0, 6.0, 225.0, true)); receivers.add(new Receiver(3, 0.0, 6.0, 315.0, true)); map = new RoomMap(image, title, receivers); map.setId(0); map.setWidthInMeters(roomWidth); map.setHeightInMeters(roomHeight); map.setLowerLeftMarkerOffsetXInPixels(0); map.setLowerLeftMarkerOffsetYInPixels(460); map.setUpperRightMarkerOffsetXInPixels(309); map.setUpperRightMarkerOffsetYInPixels(0); map.setRatioWidth(75.5); map.setRatioHeight(75.5); map.setPath(path1); allMaps.add(map); // add sample map, id 1 String path2 = "images/test_room_fifth_floor.png"; image = (BufferedImage) Utilities.loadImage(path2); title = "Room 501"; roomWidth = 6.0; roomHeight = 6.0; receivers = new ArrayList<Receiver>(); receivers.add(new Receiver(0, 0.0, 6.0, 315.0, true)); receivers.add(new Receiver(1, 2.0, 6.0, 270.0, true)); receivers.add(new Receiver(2, 6.0, 6.0, 225.0, true)); receivers.add(new Receiver(3, 0.0, 2.45, 0.0, true)); receivers.add(new Receiver(4, 6.0, 2.45, 180.0, true)); receivers.add(new Receiver(6, 6.0, 0.0, 135.0, true)); receivers.add(new Receiver(9, 3.60, 2.0, 270.0, true)); map = new RoomMap(image, title, receivers); map.setId(1); map.setWidthInMeters(roomWidth); map.setHeightInMeters(roomHeight); map.setLowerLeftMarkerOffsetXInPixels(0); map.setLowerLeftMarkerOffsetYInPixels(538); map.setUpperRightMarkerOffsetXInPixels(538); map.setUpperRightMarkerOffsetYInPixels(0); map.setRatioWidth(89.67); map.setRatioHeight(89.67); map.setPath(path2); allMaps.add(map); // add sample map, id 2 String path3 = "images/room_4m_6m.png"; image = (BufferedImage) Utilities.loadImage(path3); title = "Room 481"; roomWidth = 5.0; roomHeight = 8.30; receivers = new ArrayList<Receiver>(); receivers.add(new Receiver(6, 0.7, 0.0, 90.0, true)); receivers.add(new Receiver(1, 5.0, 0.65, 135.0, true)); receivers.add(new Receiver(2, 5.0, 4.5, 180.0, true)); receivers.add(new Receiver(3, 0.0, 2.0, 0.0, true)); receivers.add(new Receiver(4, 0.0, 7.8, 315.0, true)); receivers.add(new Receiver(0, 2.5, 8.3, 270.0, true)); receivers.add(new Receiver(9, 4.80, 8.3, 225.0, true)); map = new RoomMap(image, title, receivers); map.setId(2); map.setWidthInMeters(roomWidth); map.setHeightInMeters(roomHeight); map.setLowerLeftMarkerOffsetXInPixels(0); map.setLowerLeftMarkerOffsetYInPixels(460); map.setUpperRightMarkerOffsetXInPixels(309); map.setUpperRightMarkerOffsetYInPixels(0); map.setRatioWidth(61.80); map.setRatioHeight(55.42); map.setPath(path3); allMaps.add(map); return allMaps; }
/** * Instantiates a new <code>HardcodedMapDAO</code> object. Although it is not implemented as a * singleton (and therefore multiple instances can be created), only one instance should be used, * since multiple instances will read/write from/to the same data source. */ public HardcodedMapDAO() { logger = Utilities.initializeLogger(this.getClass().getName()); }
private void uploadMapToServer(RoomMap newMap) { Mongo mongo = null; DB database; DBCollection sampleData; String databaseAddress = DEFAULT_DATABASE_ADDRESS; try { // read parameters from the configuration file databaseAddress = Utilities.getConfigurationValue(DATABASE_ADDRESS); } catch (NumberFormatException exception) { // reading has failed, use default values logger.info( "Reading parameters from configuration file failed. " + "Using default values for database_address instead."); } try { mongo = new Mongo(databaseAddress); } catch (UnknownHostException e1) { e1.printStackTrace(); } database = mongo.getDB("rssiSystem"); sampleData = database.getCollection("map_records"); // remove all maps sampleData.drop(); SimpleDateFormat simpledateformat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss"); String strDate = simpledateformat.format(new Date()); // ------------------- // Load our image byte[] imageBytes = null; try { imageBytes = Utilities.LoadImageAsBytes(newMap.getPath()); } catch (Exception e1) { e1.printStackTrace(); } // --------------------- // Create GridFS object GridFS fs = new GridFS(database); // Save image into database GridFSInputFile in = fs.createFile(imageBytes); in.save(); Object mapIdObject = in.getId(); // System.out.println(mapIdObject); try { DBObject documentDetail = new BasicDBObject(); documentDetail.put("_cls", "mapRecords"); // for mongoEngine ORM users documentDetail.put("image", mapIdObject); documentDetail.put("mapId", newMap.getId()); documentDetail.put("width", newMap.getWidthInMeters()); documentDetail.put("height", newMap.getHeightInMeters()); documentDetail.put("offsetX", newMap.getLowerLeftMarkerOffsetXInPixels()); documentDetail.put("offsetY", newMap.getLowerLeftMarkerOffsetYInPixels()); documentDetail.put("offset2X", newMap.getUpperRightMarkerOffsetXInPixels()); documentDetail.put("offset2Y", newMap.getUpperRightMarkerOffsetYInPixels()); documentDetail.put("scalingX", newMap.getRatioWidth()); documentDetail.put("scalingY", newMap.getRatioHeight()); documentDetail.put("title", newMap.getTitle()); documentDetail.put("updateTime", strDate); sampleData.insert(documentDetail); } catch (Exception e) { e.printStackTrace(); } }
public MessageHave(int pieceIndex) throws IOException, InterruptedException { super(MessageType.have, Utilities.getBytes(pieceIndex)); }