/** * Retrieves list of Direction stops from Model and passes over to the View updateStops method * * @throws ServiceUnavailableException */ private void updateDirectionStopsTable(Direction direction) throws ServiceUnavailableException { String[][] stopList = mainModel.getRouteStopsArray( FindStopsHelper.identifyStopsForDirection(direction, mainModel.getAllStopsList())); mainView.enableRefresh(stopsExist(stopList.length)); mainView.updateStopsTable(stopList); }
/** * Retrieves a list of all the RouteConfigs for specified Agency and stores the result in a * MainModel variable */ public void processAllRouteConfigs() { mainView.updateStatus("Address search disabled until Route Configs loaded..."); try { long current = System.currentTimeMillis(); RouteList routeList = mainModel.getRouteList(); Map<String, RouteConfig> allRouteConfigs = new HashMap<String, RouteConfig>(routeList.getRoutes().size()); mainView.setupProgressBar(routeList.getRoutes().size()); int progressLength = 1; for (Route route : routeList.getRoutes()) { RouteConfig routeConfig = mainModel.getRouteConfig(route); allRouteConfigs.put(route.getTag(), routeConfig); mainView.updateProgressBar(progressLength++); Thread.sleep(1); } mainModel.setAllRouteConfigs(allRouteConfigs); mainView.updateStatus( "It took " + (System.currentTimeMillis() - current) + " ms to get all routeConfigs."); Thread.sleep(5000); mainView.updateStatus(MainView.DEFAULT_STATUS); } catch (InterruptedException | ServiceUnavailableException e) { e.printStackTrace(); } }
/** * Performs actions after specific Route is selected. * * @param ae - Route Object Tag value (String) */ public void selectRouteAction(ItemEvent ae) { Item item = (Item) ((JComboBox) ae.getSource()).getSelectedItem(); String routeTag = item.getId(); Vector<Item> busDirectionItems = null; mainView.enableRefresh(false); try { busDirectionItems = mainModel.getBusDirectionItems(routeTag); if (busDirectionItems.size() > 0) { // Clear Out Bus Stops Table mainView.clearStops(); // Populate Directions Combobox updateMapDirections(busDirectionItems); // Populate Directions Hash Map mainModel.setDirectionsMap(routeTag); // Draw Route on map drawMapRoute(routeTag); } else { mainView.enableRouteDirections(false); } } catch (ServiceUnavailableException e) { mainView.notifyAndExit(MainView.NEXTBUS_SERVICE_UNAVAILABLE); } catch (NullPointerException npe) { resetAll(); // npe.printStackTrace(); } }
/** * Action performed when refresh button in MainView is pressed * * @throws ServiceUnavailableException */ public void refreshPressedAction() throws ServiceUnavailableException { if (mainView.getRadioByRoute().isSelected()) { selectDirectionAction(this.lastItemEvent); } else if (mainView.getRadioByAddress().isSelected()) { searchPressedAction(this.lastAddress); } }
@Override public void firstFetchItems() { checkAttached(); mMainModel.setCurrSort(mMainView.getCurrSort()); mMainModel.setCurrList(mMainView.getCurrList()); mMainModel.setCurrTimeFrame(mMainView.getCurrTimeFrame()); super.firstFetchItems(); }
public void revertUndoState() { aGrid.cancelAnimations(); grid.revertTiles(); score = undoScore; won = false; lose = false; mView.refreshLastTime = true; mView.invalidate(); }
/** * Accepts Item Vector List of all the Bus Directions. Populates Bus Directions ComboBox with * provided Bus Directions List. * * @param busDirectionItems Item Vector List */ private void updateMapDirections(Vector<Item> busDirectionItems) { mainView.clearDirections(); mainView.enableRouteDirections(true); mainView.enableRefresh(true); Iterator<Item> itr = busDirectionItems.iterator(); while (itr.hasNext()) { mainView.addRouteDirectionItem((Item) itr.next()); } }
/** * Accepts {@link Stop} List to draw stops on map for specific set of Stop objects. * * @param stopList - List of Stop objects */ private void drawClosestMapStops(List<Stop> stopList, String address) { try { mapControl = mainView.getMapControl(); mapControl.setCenterPosition(mainModel.getSearchGeoPosition(address)); mapControl.setZoom(2); mapControl.addWaypoint(getWayPoints(stopList), stopList); mapControl.addHomeWaypoint(mainModel.getSearchWayPoint(address)); mapControl.getStopsNearHome(); } catch (ServiceUnavailableException e) { mainView.notifyAndExit(MainView.NEXTBUS_SERVICE_UNAVAILABLE); } catch (InvalidAddressException e) { mainView.updateStatus(MainView.INVALID_ADDRESS); } }
/** * Accepts Route Tag value to retrieve Route object. Gets list of GeoPosition points using Route * object. Draws route on map based on retrieved GeoPosition points. * * @param routeTag - Route Object Tag value (String) */ private void drawMapRoute(String routeTag) { try { Route route = mainModel.getRoute(routeTag); RouteConfig routeConfig = mainModel.getRouteConfig(route); ArrayList<Path> ttfPaths = mainModel.getPathList(route); mapControl = mainView.getMapControl(); mapControl.drawRoute(routeConfig, ttfPaths); mapControl.getAllOverlays(); mainView.updateMapViewer(); } catch (ServiceUnavailableException e) { mainView.notifyAndExit(MainView.NEXTBUS_SERVICE_UNAVAILABLE); } }
public void newGame() { grid = new Grid(numSquaresX, numSquaresY); aGrid = new AnimationGrid(numSquaresX, numSquaresY); highScore = getHighScore(); if (score >= highScore) { highScore = score; recordHighScore(); } score = 0; won = false; lose = false; addStartTiles(); mView.refreshLastTime = true; mView.resyncTime(); mView.postInvalidate(); }
private void init(MainView v, Object params) { Context ctx = RhodesActivity.getContext(); view = new MyView(ctx); view.setOrientation(LinearLayout.VERTICAL); view.setGravity(Gravity.BOTTOM); view.setLayoutParams(new LinearLayout.LayoutParams(FILL_PARENT, FILL_PARENT)); webView = null; if (v != null) webView = v.detachWebView(); if (webView == null) webView = RhodesActivity.safeGetInstance().createWebView(); view.addView(webView, new LinearLayout.LayoutParams(FILL_PARENT, 0, 1)); LinearLayout bottom = new LinearLayout(ctx); bottom.setOrientation(LinearLayout.HORIZONTAL); bottom.setBackgroundColor(Color.GRAY); bottom.setLayoutParams(new LinearLayout.LayoutParams(FILL_PARENT, WRAP_CONTENT, 0)); view.addView(bottom); toolBar = bottom; setupToolbar(toolBar, params); webView.requestFocus(); }
private void onOK() { try { Map<String, String> data = new HashMap<String, String>(); data.put("login", loginField.getText()); data.put("password", passwordField.getText()); String errorMsg = SocketManager.doAction(Constants.LOGIN_ACTION, data); if (errorMsg.equals("0")) { MainView mainView = new MainView(); mainView.setVisible(true); dispose(); } else { JOptionPane.showMessageDialog(this, errorMsg, "Error!", JOptionPane.ERROR_MESSAGE); } } catch (IOException e) { JOptionPane.showMessageDialog(this, e.getMessage(), "Error!", JOptionPane.ERROR_MESSAGE); } }
/** * Performs actions after specific Direction is selected. * * @param ae - Direction Object Tag value (String) * @throws ServiceUnavailableException */ public void selectDirectionAction(ItemEvent ae) throws ServiceUnavailableException { Item item = (Item) ((JComboBox) ae.getSource()).getSelectedItem(); String directionTag = item.getId(); Direction direction = null; mainView.enableRefresh(false); this.lastItemEvent = ae; try { direction = mainModel.getDirection(directionTag); // Show Stops for Direction on Table updateDirectionStopsTable(direction); // Draw Stops on map drawMapStops(direction); } catch (NullPointerException npe) { mainView.clearStops(); } }
/** * Return the RouteList of bus routes that an Agency services. * * @param agency the {@link Agency} to which the RouteList applies * @return the list of Routes */ public Vector<Item> getRouteListItems() { Vector<Item> routeListItems = new Vector<Item>(); try { routeListItems = mainModel.getRouteListItems(); } catch (ServiceUnavailableException e) { mainView.notifyAndExit(MainView.NEXTBUS_SERVICE_UNAVAILABLE); } return routeListItems; }
@Override public void paintComponent(final Graphics graphics) { final Graphics2D g = (Graphics2D) graphics; final NodeView nodeView = getNodeView(); if (nodeView.getModel() == null) { return; } paintBackgound(g); paintDragOver(g); super.paintComponent(g); }
/** * Method called when the user inputs an address on the user interface and they want to see the * closes bus stops. * * @param address the user entered address */ public void searchPressedAction(String address) { mainView.enableRefresh(false); this.lastAddress = address; try { if (address != null && address.length() > 0) { // Get closest stops to address ArrayList<RouteStopGeoPositionDTO> closestStops = mainModel.getStopsForDisplay(address); // Get stops with next bus times added ArrayList<Stop> stopsList = mainModel.addNextBusTimes(closestStops); // Clear out Route and Stop Information resetAll(); // Update Stops Table with Closest Stops String[][] closestStopsArray = StopsToArray.convert(closestStops); mainView.enableRefresh(stopsExist(closestStopsArray.length)); mainView.updateStopsTable(closestStopsArray); // Draw Closest Stops on Map drawClosestMapStops(stopsList, address); // Update Status mainView.updateStatus(MainView.DEFAULT_STATUS); } } catch (ServiceUnavailableException e) { mainView.notifyAndExit(MainView.NEXTBUS_SERVICE_UNAVAILABLE); } catch (InvalidAddressException e) { mainView.updateStatus(MainView.INVALID_ADDRESS); } }
@Override void paintDecoration(final NodeView nodeView, final Graphics2D g) { final Stroke oldStroke = g.getStroke(); float edgeWidth = getEdgeWidth(); g.setStroke(new BasicStroke(edgeWidth, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER)); final Color oldColor = g.getColor(); g.setColor(nodeView.getEdgeColor()); Point leftLinePoint = getLeftPoint(); g.drawLine(leftLinePoint.x, leftLinePoint.y, leftLinePoint.x + getWidth(), leftLinePoint.y); g.setColor(oldColor); g.setStroke(oldStroke); super.paintDecoration(nodeView, g); }
/** Action performed when Search By Address Radio Button is selected */ public void rdBusRouteAction() { resetAll(); mainView.enableAddressSearch(false); mainView.enableRouteDirections(false); mainView.enableRoute(true); mainView.enableRefresh(false); mainView.updateStatus(MainView.DEFAULT_STATUS); String[] tableColumns = BUS_ROUTE_COLUMNS; mainView.setTableColumns(tableColumns); }
/** Action performed when Search By Address Radio Button is selected */ public void rdSearchAddressAction() { resetAll(); mainView.enableRoute(false); mainView.enableRouteDirections(false); mainView.enableAddressSearch(true); mainView.enableRefresh(false); mainView.updateStatus(MainView.DEFAULT_STATUS); String[] tableColumns = SEARCH_ADDRESS_COLUMNS; mainView.setTableColumns(tableColumns); }
@Override public void onResume() { // TODO Auto-generated method stub view.showProgress(); }
public void move(int direction) { saveUndoState(); aGrid.cancelAnimations(); // 0: up, 1: right, 2: down, 3: left if (lose || won) { return; } Cell vector = getVector(direction); List<Integer> traversalsX = buildTraversalsX(vector); List<Integer> traversalsY = buildTraversalsY(vector); boolean moved = false; prepareTiles(); for (int xx : traversalsX) { for (int yy : traversalsY) { Cell cell = new Cell(xx, yy); Tile tile = grid.getCellContent(cell); if (tile != null) { Cell[] positions = findFarthestPosition(cell, vector); Tile next = grid.getCellContent(positions[1]); if (next != null && next.getValue() == tile.getValue() && next.getMergedFrom() == null) { Tile merged = new Tile(positions[1], tile.getValue() * 2); Tile[] temp = {tile, next}; merged.setMergedFrom(temp); grid.insertTile(merged); grid.removeTile(tile); // Converge the two tiles' positions tile.updatePosition(positions[1]); int[] extras = {xx, yy}; aGrid.startAnimation( merged.getX(), merged.getY(), MOVE_ANIMATION, MOVE_ANIMATION_TIME, 0, extras); // Direction: 0 = MOVING MERGED aGrid.startAnimation( merged.getX(), merged.getY(), MERGE_ANIMATION, SPAWN_ANIMATION_TIME, MOVE_ANIMATION_TIME, null); // Update the score score = score + merged.getValue(); highScore = Math.max(score, highScore); // The mighty 2048 tile if (merged.getValue() == 2048) { won = true; endGame(); } } else { moveTile(tile, positions[0]); int[] extras = {xx, yy, 0}; aGrid.startAnimation( positions[0].getX(), positions[0].getY(), MOVE_ANIMATION, MOVE_ANIMATION_TIME, 0, extras); // Direction: 1 = MOVING NO MERGE } if (!positionsEqual(cell, tile)) { moved = true; } } } } if (moved) { addRandomTile(); checkLose(); } mView.resyncTime(); mView.postInvalidate(); }
@SuppressWarnings("unchecked") public TabbedMainView(Object params) { Context ctx = RhodesActivity.getContext(); mBackgroundColorEnable = false; Vector<Object> tabs = null; boolean place_tabs_bottom = false; if (params instanceof Vector<?>) tabs = (Vector<Object>) params; else if (params instanceof Map<?, ?>) { Map<Object, Object> settings = (Map<Object, Object>) params; Object bkgObj = settings.get("background_color"); if ((bkgObj != null) && (bkgObj instanceof String)) { int color = Integer.parseInt((String) bkgObj) | 0xFF000000; mBackgroundColor = color; mBackgroundColorEnable = true; } Object callbackObj = settings.get("on_change_tab_callback"); if ((callbackObj != null) && (callbackObj instanceof String)) { mChangeTabCallback = new String(((String) callbackObj)); } Object placeBottomObj = settings.get("place_tabs_bottom"); if ((placeBottomObj != null) && (placeBottomObj instanceof String)) { place_tabs_bottom = ((String) placeBottomObj).equalsIgnoreCase("true"); } Object tabsObj = settings.get("tabs"); if (tabsObj != null && (tabsObj instanceof Vector<?>)) tabs = (Vector<Object>) tabsObj; } if (tabs == null) throw new IllegalArgumentException("No tabs specified"); int size = tabs.size(); host = new TabHost(ctx, null); tabData = new Vector<TabData>(size); tabIndex = 0; TabWidget tabWidget = new TabWidget(ctx); tabWidget.setId(android.R.id.tabs); FrameLayout frame = new FrameLayout(ctx); FrameLayout.LayoutParams lpf = null; TabHost.LayoutParams lpt = null; if (place_tabs_bottom) { frame.setId(android.R.id.tabcontent); lpf = new FrameLayout.LayoutParams( LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT, Gravity.TOP); host.addView(frame, lpf); lpt = new TabHost.LayoutParams( LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT, Gravity.BOTTOM); host.addView(tabWidget, lpt); } else { lpt = new TabHost.LayoutParams( LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT, Gravity.TOP); host.addView(tabWidget, lpt); frame = new FrameLayout(ctx); frame.setId(android.R.id.tabcontent); lpf = new FrameLayout.LayoutParams( LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT, Gravity.BOTTOM); host.addView(frame, lpf); } host.setup(); TabHost.TabSpec spec; DisplayMetrics metrics = new DisplayMetrics(); WindowManager wm = (WindowManager) ctx.getSystemService(Context.WINDOW_SERVICE); wm.getDefaultDisplay().getMetrics(metrics); int selected_color = 0; boolean selected_color_enable = false; for (int i = 0; i < size; ++i) { Object param = tabs.elementAt(i); if (!(param instanceof Map<?, ?>)) throw new IllegalArgumentException("Hash expected"); Map<Object, Object> hash = (Map<Object, Object>) param; Object labelObj = hash.get("label"); if (labelObj == null || !(labelObj instanceof String)) throw new IllegalArgumentException("'label' should be String"); Object actionObj = hash.get("action"); boolean use_current_view_for_tab = false; Object use_current_view_for_tab_Obj = hash.get("use_current_view_for_tab"); if (use_current_view_for_tab_Obj != null) { use_current_view_for_tab = ((String) use_current_view_for_tab_Obj).equalsIgnoreCase("true"); } if (use_current_view_for_tab) { actionObj = new String("none"); } if (actionObj == null || !(actionObj instanceof String)) throw new IllegalArgumentException("'action' should be String"); String label = (String) labelObj; String action = (String) actionObj; String icon = null; boolean reload = false; boolean disabled = false; int web_bkg_color = 0xFFFFFFFF; Object iconObj = hash.get("icon"); if (iconObj != null && (iconObj instanceof String)) icon = "apps/" + (String) iconObj; Object reloadObj = hash.get("reload"); if (reloadObj != null && (reloadObj instanceof String)) reload = ((String) reloadObj).equalsIgnoreCase("true"); Object selected_color_Obj = hash.get("selected_color"); if ((selected_color_Obj != null) && (selected_color_Obj instanceof String)) { selected_color_enable = true; selected_color = Integer.parseInt((String) selected_color_Obj) | 0xFF000000; } Object disabled_Obj = hash.get("disabled"); if (disabled_Obj != null && (disabled_Obj instanceof String)) disabled = ((String) disabled_Obj).equalsIgnoreCase("true"); Object web_bkg_color_Obj = hash.get("web_bkg_color"); if (web_bkg_color_Obj != null && (web_bkg_color_Obj instanceof String)) { web_bkg_color = Integer.parseInt((String) web_bkg_color_Obj) | 0xFF000000; } spec = host.newTabSpec(Integer.toString(i)); // Set label and icon BitmapDrawable drawable = null; if (icon != null) { String iconPath = RhoFileApi.normalizePath(icon); Bitmap bitmap = BitmapFactory.decodeStream(RhoFileApi.open(iconPath)); if (disabled && (bitmap != null)) { // replace Bitmap to gray bitmap = bitmap.copy(Bitmap.Config.ARGB_8888, true); // prepare mutable bitmap int x; int y; int bw = bitmap.getWidth(); int bh = bitmap.getHeight(); int nc = DISABLED_IMG_COLOR & 0xFFFFFF; int c; for (y = 0; y < bh; y++) { for (x = 0; x < bw; x++) { c = bitmap.getPixel(x, y); c = nc | (c & 0xFF000000); bitmap.setPixel(x, y, c); } } } if (bitmap != null) bitmap.setDensity(DisplayMetrics.DENSITY_MEDIUM); // Bitmap.DENSITY_NONE); drawable = new BitmapDrawable(bitmap); drawable.setTargetDensity(metrics); } if (drawable == null) spec.setIndicator(label); else spec.setIndicator(label, drawable); SimpleMainView view = null; if (use_current_view_for_tab) { RhodesService r = RhodesService.getInstance(); MainView mainView = r.getMainView(); action = mainView.currentLocation(-1); view = new SimpleMainView(mainView); } else { view = new SimpleMainView(); } // Set view factory if (web_bkg_color_Obj != null) { if (!use_current_view_for_tab) { view.setWebBackgroundColor(web_bkg_color); } host.setBackgroundColor(web_bkg_color); } TabData data = new TabData(); data.view = view; data.url = action; data.reload = reload; if (use_current_view_for_tab) { data.loaded = true; tabIndex = i; } data.selected_color = selected_color; data.selected_color_enabled = selected_color_enable; data.disabled = disabled; TabViewFactory factory = new TabViewFactory(data); spec.setContent(factory); tabData.addElement(data); host.addTab(spec); } tabWidget.measure(host.getWidth(), host.getHeight()); int hh = tabWidget.getMeasuredHeight(); // if (hh < 64) { // hh = 64; // } if (place_tabs_bottom) { lpf.setMargins(0, 0, 0, hh); } else { lpf.setMargins(0, hh, 0, 0); } host.updateViewLayout(frame, lpf); }
private void updateModelClicked() { convertAndUpdateModel(); callBack.configurationUpdated(model); }
@Override public void onFetchUserInfoError() { mMainView.onFetchUserInfoError(); }
@Override public void onFetchUserInfoFinished(User userInfo) { mMainView.onFetchUserInfoFinished(userInfo); }
/** * Accepts {@link Stop} List to draw stops on map for specific set of Stop objects. * * @param stopList - List of Stop objects */ private void drawMapStops(List<Stop> stopList) { mapControl = mainView.getMapControl(); mapControl.addWaypoint(getWayPoints(stopList), stopList); mapControl.getAllOverlays(); }
@Override public void getChooseResult(OptionView ov_content) { String message = ov_content.getWhichRadioButtonChecked(); view.showMessage(String.format("Ñ¡ÔñÁË%sÑ¡Ïî", message)); }
/** Clears Bus Route and Stop information from Map and Table */ private void resetAll() { mainView.clearStops(); mainView.clearDirections(); mainView.enableRouteDirections(false); mainView.resetMapViewer(); }
/** * Retrieves list of Route stops from Model and passes over to the View updateStops method * * @throws ServiceUnavailableException */ private void updateRouteStopsTable(ArrayList<Stop> stopList) throws ServiceUnavailableException { mainView.updateStopsTable(mainModel.getRouteStopsArray(stopList)); }
CatenaSetting() { super(PeaFactory.getFrame()); setting = this; // setting.setUndecorated(true); setting.setAlwaysOnTop(true); this.setIconImage(MainView.getImage()); JPanel scryptPane = (JPanel) setting.getContentPane(); // new JPanel(); scryptPane.setBorder(new LineBorder(Color.GRAY, 2)); scryptPane.setLayout(new BoxLayout(scryptPane, BoxLayout.Y_AXIS)); JLabel scryptLabel = new JLabel("Settings for CATENA:"); scryptLabel.setPreferredSize(new Dimension(250, 30)); JLabel tipLabel1 = new JLabel("Settings for this session only"); tipLabel1.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 11)); tipLabel1.setPreferredSize(new Dimension(250, 20)); scryptPane.add(scryptLabel); scryptPane.add(tipLabel1); JLabel instanceLabel = new JLabel("Select an instance of Catena:"); instanceLabel.setPreferredSize(new Dimension(250, 40)); scryptPane.add(instanceLabel); JLabel instanceRecommendedLabel = new JLabel("recommended: Dragonfly-Full"); instanceRecommendedLabel.setPreferredSize(new Dimension(250, 20)); instanceRecommendedLabel.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 11)); scryptPane.add(instanceRecommendedLabel); JRadioButton dragonflyFullButton = new JRadioButton("Dragonfly-Full"); dragonflyFullButton.setMnemonic(KeyEvent.VK_U); dragonflyFullButton.addActionListener(this); dragonflyFullButton.setActionCommand("Dragonfly-Full"); scryptPane.add(dragonflyFullButton); JRadioButton butterflyFullButton = new JRadioButton("Butterfly-Full"); butterflyFullButton.setMnemonic(KeyEvent.VK_U); butterflyFullButton.addActionListener(this); butterflyFullButton.setActionCommand("Butterfly-Full"); scryptPane.add(butterflyFullButton); JRadioButton dragonflyButton = new JRadioButton("Dragonfly"); dragonflyButton.setMnemonic(KeyEvent.VK_B); dragonflyButton.addActionListener(this); dragonflyButton.setActionCommand("Dragonfly"); scryptPane.add(dragonflyButton); JRadioButton butterflyButton = new JRadioButton("Butterfly"); butterflyButton.setMnemonic(KeyEvent.VK_B); butterflyButton.addActionListener(this); butterflyButton.setActionCommand("Butterfly"); scryptPane.add(butterflyButton); // Group the radio buttons. ButtonGroup group = new ButtonGroup(); group.add(dragonflyButton); group.add(dragonflyFullButton); group.add(butterflyButton); group.add(butterflyFullButton); group.setSelected(dragonflyFullButton.getModel(), true); scryptPane.add(Box.createVerticalStrut(20)); JLabel memoryLabel = new JLabel("Memory cost parameter GARLIC: "); memoryLabel.setPreferredSize(new Dimension(220, 40)); scryptPane.add(memoryLabel); memoryField = new JTextField() { private static final long serialVersionUID = 1L; public void processKeyEvent(KeyEvent ev) { char c = ev.getKeyChar(); try { // printable characters if (c > 31 && c < 65535 && c != 127) { Integer.parseInt(c + ""); // parse } super.processKeyEvent(ev); } catch (NumberFormatException nfe) { // if not a number: ignore } } }; memoryField.setText("18"); memoryField.setColumns(2); memoryField.setDragEnabled(true); memoryField .getDocument() .addDocumentListener( new DocumentListener() { public void changedUpdate(DocumentEvent e) { warn(); } public void removeUpdate(DocumentEvent e) { warn(); } public void insertUpdate(DocumentEvent e) { warn(); } public void warn() { int garlic = 0; try { garlic = Integer.parseInt(memoryField.getText()); } catch (Exception nfe) { errorLabel.setText("Invalid input"); return; } if (garlic == 0) { errorLabel.setText("Invalid value"); } else if (garlic < 14) { errorLabel.setText("Warning: Weak parameter"); } else if (garlic > 22 && garlic < 64) { errorLabel.setText("Warning: Long execution time"); } else if (garlic > 63) { errorLabel.setText("Invalid value: must be < 64"); } else { errorLabel.setText(""); } } }); memoryRecommendedLabel = new JLabel("recommended >= 18"); memoryRecommendedLabel.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 11)); JPanel memoryPanel = new JPanel(); memoryPanel.add(memoryField); memoryPanel.add(memoryRecommendedLabel); scryptPane.add(memoryPanel); scryptPane.add(Box.createVerticalStrut(10)); JLabel timeLabel = new JLabel("Time cost parameter LAMBDA: "); timeLabel.setPreferredSize(new Dimension(220, 40)); scryptPane.add(timeLabel); timeField = new JTextField() { private static final long serialVersionUID = 1L; public void processKeyEvent(KeyEvent ev) { char c = ev.getKeyChar(); try { // printable characters if (c > 31 && c < 65535 && c != 127) { Integer.parseInt(c + ""); // parse } super.processKeyEvent(ev); } catch (NumberFormatException nfe) { // if not a number: ignore } } }; timeField.setText("2"); timeField.setColumns(3); timeField.setDragEnabled(true); timeField .getDocument() .addDocumentListener( new DocumentListener() { public void changedUpdate(DocumentEvent e) { warn(); } public void removeUpdate(DocumentEvent e) { warn(); } public void insertUpdate(DocumentEvent e) { warn(); } public void warn() { int lambda = 0; try { lambda = Integer.parseInt(timeField.getText()); } catch (Exception nfe) { errorLabel.setText("Invalid input"); return; } if (lambda == 0) { errorLabel.setText("Invalid value"); } else if (lambda == 1) { errorLabel.setText("Warning: Weak parameter"); } else if (lambda > 4) { errorLabel.setText("Warning: Long execution time"); } else { errorLabel.setText(""); } } }); timeRecommendedLabel = new JLabel("recommended 2"); timeRecommendedLabel.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 11)); JPanel timePanel = new JPanel(); timePanel.add(timeField); timePanel.add(timeRecommendedLabel); scryptPane.add(timePanel); scryptPane.add(Box.createVerticalStrut(10)); errorLabel = new JLabel(""); errorLabel.setForeground(Color.RED); scryptPane.add(errorLabel); JButton scryptOkButton = new JButton("ok"); scryptOkButton.setActionCommand("newSetting"); scryptOkButton.addActionListener(this); scryptPane.add(scryptOkButton); setting.pack(); setting.setLocation(100, 100); setting.setVisible(true); }