/** @inheritDoc */ public void drawTextField(Graphics g, TextField ta) { if (ta instanceof DateField) { drawDateField(g, (DateField) ta); return; } setFG(g, ta); // display ******** if it is a password field String displayText = getTextFieldString(ta); Style style = ta.getStyle(); int x = 0; int cursorCharPosition = ta.getCursorPosition(); Font f = ta.getStyle().getFont(); int cursorX = 0; int xPos = 0; if (cursorCharPosition > 0) { xPos = f.stringWidth(displayText.substring(0, cursorCharPosition)); cursorX = ta.getX() + style.getPadding(Component.LEFT) + xPos; if (ta.getWidth() > (f.getHeight() * 2) && cursorX >= ta.getWidth() - style.getPadding(Component.LEFT)) { while (x + xPos >= ta.getWidth() - style.getPadding(Component.LEFT) * 2) { x--; } } } g.drawString( displayText, ta.getX() + x + style.getPadding(Component.LEFT), ta.getY() + style.getPadding(Component.TOP)); // show always if (ta.getInputModeOrder() != null && ta.getInputModeOrder().length > 0) { String inputMode = ta.getInputMode(); int inputModeWidth = f.stringWidth(inputMode); if (ta.handlesInput() && ta.getWidth() / 2 > inputModeWidth) { int drawXPos = ta.getX() + style.getPadding(Component.LEFT) - 1; if (xPos < ta.getWidth() / 2) { // draw on the right side drawXPos = drawXPos + ta.getWidth() - inputModeWidth - style.getPadding(Component.RIGHT) - style.getPadding(Component.LEFT); } g.setColor(style.getFgSelectionColor()); // unfurtanally g.fillroundrect does not suppport alpha // g.fillRoundRect(drawXPos, ta.getY() + style.getPadding(Component.TOP)-1, inputModeWidth, // ta.getHeight()-4, 4, 4); // so a work around is required byte alphaLevel = (byte) 140; g.fillRect( drawXPos, ta.getY() + style.getPadding(Component.TOP) - 1, inputModeWidth + 2, ta.getHeight() - 4, alphaLevel); // g.setColor(0xFF0000); g.setColor(style.getBgSelectionColor()); g.fillRect(drawXPos, ta.getY() + style.getPadding(Component.TOP) - 1, 1, 1, alphaLevel); g.fillRect( drawXPos + inputModeWidth + 1, ta.getY() + style.getPadding(Component.TOP) - 1, 1, 1, alphaLevel); g.fillRect( drawXPos + inputModeWidth + 1, ta.getY() + style.getPadding(Component.TOP) - 1 + ta.getHeight() - 4 - 1, 1, 1, alphaLevel); g.fillRect( drawXPos, ta.getY() + style.getPadding(Component.TOP) - 1 + ta.getHeight() - 4 - 1, 1, 1, alphaLevel); g.drawString(inputMode, drawXPos + 1, ta.getY() + style.getPadding(Component.TOP)); } } }
public Form getForm() { if (loginForm != null) { titleLbl.setText("Login:"******"NoiseTube Account"); loginPanel = new Container(); loginPanel.setLayout(new BoxLayout(BoxLayout.Y_AXIS)); titleLbl = new Label(" "); usernameLbl = new Label(); usernameTxt = new TextField(); usernameLbl.setText("Username:"******"Password:"******"Skip"); loginCmd = new Command("Login"); // buttonPanel = new Container(); // buttonPanel.addComponent(loginBtn); // buttonPanel.getStyle().setMargin(2, 2, 2, 2); titleLbl.setText("Login:"******"Connexion error"); titleLbl.setText("Connexion error"); } catch (RecordStoreException e1) { titleLbl.setText("Error saving APIkey"); log.error(e1, "Error saving APIkey"); } } else if (skipCmd.equals(arg0.getCommand())) { MainMidlet.getInstance() .getPreferences() .setSavingMode( Device.supportsSavingToFile() ? Preferences.SAVE_FILE : Preferences.SAVE_NO); midlet.showMeasureForm(); } else midlet.notifyDestroyed(); } }); return loginForm; }
protected void executeView(final Container f) { reportId = ""; f.setLayout(new BoxLayout(BoxLayout.Y_AXIS)); Image helpIcon = HILMain.getInstance().res.getImage("GeneralReportData_sel.png"); final Label title = new Label(getName()); title.getStyle().setFont(HILMain.getInstance().theme.getFont("titleFont")); title.setIcon(helpIcon); title.setAlignment(Label.LEFT); title.setHeight(14); title.setWidth(240); title.getStyle().setBgColor(0x7799bb); title.getStyle().setFgColor(0xFFFFFF); title.getStyle().setPadding(5, 5, 15, 0); title.getStyle().setBgTransparency(250); setTitle(title, f); f.setScrollable(true); FocusListener textFocus = new FocusListener() { public void focusGained(Component arg0) { arg0.getStyle().setFont(HILMain.getInstance().theme.getFont("defaultFont")); arg0.getStyle().setBorder(Border.createEmpty()); } public void focusLost(Component arg0) {} }; TextArea shortHelpLabel = new TextArea(2, 10); shortHelpLabel.getStyle().setFont(HILMain.getInstance().theme.getFont("defaultFont")); shortHelpLabel.getStyle().setBorder(Border.createEmpty(), true); shortHelpLabel.getStyle().setBgTransparency(0); shortHelpLabel.getStyle().setFgColor(0x000000); shortHelpLabel.setFocus(false); shortHelpLabel.setFocusable(false); shortHelpLabel.setText( (String) HILMain.getInstance().locale.get("short_help_general_report_data")); f.addComponent(shortHelpLabel); date = new Date(); final Button dateLabel = new Button(); dateLabel.getStyle().setFont(HILMain.getInstance().theme.getFont("defaultFont")); dateLabel.getStyle().setBorder(Border.createEmpty()); dateLabel.getStyle().setBgColor(0xCECECE); dateLabel.getStyle().setFgColor(0x81746B); dateLabel.setTextPosition(Label.LEFT); dateLabel.setText(""); dateLabel.getSelectedStyle().setFont(HILMain.getInstance().theme.getFont("defaultFont")); dateLabel.getSelectedStyle().setBorder(Border.createEmpty()); dateLabel.getSelectedStyle().setBgColor(0xCECECE); dateLabel.getSelectedStyle().setFgColor(0x81746B); dateLabel.getSelectedStyle().setBgTransparency(100); dateLabel.getPressedStyle().setBorder(Border.createEmpty()); dateLabel.getPressedStyle().setBgColor(0xCECECE); dateLabel.getPressedStyle().setFgColor(0x81746B); dateLabel.getPressedStyle().setBgTransparency(100); dateLabel.setText(DateUtil.getMonthYear(date, "/")); f.addComponent(createPair((String) HILMain.getInstance().locale.get("time"), dateLabel, 54)); Container buttonContainer = new Container(new BoxLayout(BoxLayout.X_AXIS)); buttonContainer.setWidth(Display.getInstance().getDisplayWidth()); Button submit = new Button(); submit.setText((String) HILMain.getInstance().locale.get("get_data")); submit.getStyle().setBgTransparency(255); submit.getStyle().setFont(HILMain.getInstance().theme.getFont("defaultFont")); submit.getStyle().setBorder(Border.createRoundBorder(0, 0, 0xcadaf1)); submit.getStyle().setBgColor(0xFAAC58, true); submit.getStyle().setAlignment(Label.CENTER); submit.getStyle().setFgColor(0xFFFFFF); submit.getSelectedStyle().setBgTransparency(255); submit.getSelectedStyle().setFont(HILMain.getInstance().theme.getFont("defaultFont")); submit.getSelectedStyle().setBorder(Border.createRoundBorder(0, 0, 0xcadaf1)); submit.getSelectedStyle().setBgColor(0xFAAC58); submit.getSelectedStyle().setAlignment(Label.CENTER); submit.getSelectedStyle().setFgColor(0x000000); submit.getPressedStyle().setBgTransparency(255); submit.getPressedStyle().setFont(HILMain.getInstance().theme.getFont("defaultFont")); submit.getPressedStyle().setBorder(Border.createRoundBorder(0, 0, 0xcadaf1)); submit.getPressedStyle().setBgColor(0xFAAC58); submit.getPressedStyle().setAlignment(Label.CENTER); submit.getPressedStyle().setFgColor(0x000000); final Button buttonEdit = new Button(); buttonEdit.setText((String) HILMain.getInstance().locale.get("edit")); buttonEdit.getStyle().setBgTransparency(255); buttonEdit.getStyle().setFont(HILMain.getInstance().theme.getFont("defaultFont")); buttonEdit.getStyle().setBorder(Border.createRoundBorder(0, 0, 0xcadaf1)); buttonEdit.getStyle().setBgColor(0xFAAC58, true); buttonEdit.getStyle().setAlignment(Label.CENTER); buttonEdit.getStyle().setFgColor(0xFFFFFF); buttonEdit.getDisabledStyle().setBgTransparency(255); buttonEdit.getDisabledStyle().setFont(HILMain.getInstance().theme.getFont("defaultFont")); buttonEdit.getDisabledStyle().setBorder(Border.createRoundBorder(0, 0, 0xcadaf1)); buttonEdit.getDisabledStyle().setBgColor(0xBDBDBD); buttonEdit.getDisabledStyle().setAlignment(Label.CENTER); buttonEdit.getDisabledStyle().setFgColor(0xFFFFFF); buttonEdit.getSelectedStyle().setBgTransparency(255); buttonEdit.getSelectedStyle().setFont(HILMain.getInstance().theme.getFont("defaultFont")); buttonEdit.getSelectedStyle().setBorder(Border.createRoundBorder(0, 0, 0xcadaf1)); buttonEdit.getSelectedStyle().setBgColor(0xFAAC58); buttonEdit.getSelectedStyle().setAlignment(Label.CENTER); buttonEdit.getSelectedStyle().setFgColor(0x000000); buttonEdit.getPressedStyle().setBgTransparency(255); buttonEdit.getPressedStyle().setFont(HILMain.getInstance().theme.getFont("defaultFont")); buttonEdit.getPressedStyle().setBorder(Border.createRoundBorder(0, 0, 0xcadaf1)); buttonEdit.getPressedStyle().setBgColor(0xFAAC58); buttonEdit.getPressedStyle().setAlignment(Label.CENTER); buttonEdit.getPressedStyle().setFgColor(0x000000); buttonEdit.setEnabled(false); buttonContainer.addComponent(submit); buttonContainer.addComponent(buttonEdit); f.addComponent(buttonContainer); Label normalLabel = new Label((String) HILMain.getInstance().locale.get("normal_reaction")); normalLabel.getStyle().setBgTransparency(250); normalLabel.setWidth(240); normalLabel.getStyle().setBgColor(0xBFD6FF); f.addComponent(normalLabel); final TextField normalReaction = new TextField(10); normalReaction.getStyle().setFont(HILMain.getInstance().theme.getFont("defaultFont")); normalReaction.setText(""); normalReaction.getStyle().setBorder(Border.createEmpty(), true); normalReaction.addFocusListener(textFocus); normalReaction.getStyle().setBgColor(0xCECECE); normalReaction.getStyle().setBgTransparency(150); normalReaction.getStyle().setFgColor(0x81746B); normalReaction.getSelectedStyle().setBgColor(0xCECECE); normalReaction.getSelectedStyle().setBgTransparency(100); normalReaction.getSelectedStyle().setFgColor(0x81746B); normalReaction.setConstraint(TextField.NUMERIC); normalReaction.setInputModeOrder(new String[] {"123"}); normalReaction.setEditable(false); f.addComponent(normalReaction); Label seriousLabel = new Label((String) HILMain.getInstance().locale.get("serious_reaction")); seriousLabel.getStyle().setBgTransparency(250); seriousLabel.setWidth(240); seriousLabel.getStyle().setBgColor(0xBFD6FF); f.addComponent(seriousLabel); final TextField seriousReaction = new TextField(10); seriousReaction.getStyle().setFont(HILMain.getInstance().theme.getFont("defaultFont")); seriousReaction.setText(""); seriousReaction.getStyle().setBorder(Border.createEmpty(), true); seriousReaction.addFocusListener(textFocus); seriousReaction.getStyle().setBgColor(0xCECECE); seriousReaction.getStyle().setBgTransparency(150); seriousReaction.getStyle().setFgColor(0x81746B); seriousReaction.getSelectedStyle().setBgColor(0xCECECE); seriousReaction.getSelectedStyle().setBgTransparency(100); seriousReaction.getSelectedStyle().setFgColor(0x81746B); seriousReaction.setConstraint(TextField.NUMERIC); seriousReaction.setInputModeOrder(new String[] {"123"}); seriousReaction.setEditable(false); f.addComponent(seriousReaction); Label tetanusLabel = new Label((String) HILMain.getInstance().locale.get("tetanus_protection")); tetanusLabel.getStyle().setBgTransparency(250); tetanusLabel.setWidth(240); tetanusLabel.getStyle().setBgColor(0xBFD6FF); f.addComponent(tetanusLabel); final TextField tetanus = new TextField(10); tetanus.getStyle().setFont(HILMain.getInstance().theme.getFont("defaultFont")); tetanus.setText(""); tetanus.getStyle().setBorder(Border.createEmpty(), true); tetanus.addFocusListener(textFocus); tetanus.getStyle().setBgColor(0xCECECE); tetanus.getStyle().setBgTransparency(150); tetanus.getStyle().setFgColor(0x81746B); tetanus.getSelectedStyle().setBgColor(0xCECECE); tetanus.getSelectedStyle().setBgTransparency(100); tetanus.getSelectedStyle().setFgColor(0x81746B); tetanus.setConstraint(TextField.NUMERIC); tetanus.setInputModeOrder(new String[] {"123"}); tetanus.setEditable(false); f.addComponent(tetanus); final Button buttonSave = new Button(); buttonSave.setText((String) HILMain.getInstance().locale.get("save")); buttonSave.getStyle().setBgTransparency(255); buttonSave.getStyle().setFont(HILMain.getInstance().theme.getFont("defaultFont")); buttonSave.getStyle().setBorder(Border.createRoundBorder(0, 0, 0xcadaf1)); buttonSave.getStyle().setBgColor(0xFAAC58, true); buttonSave.getStyle().setAlignment(Label.CENTER); buttonSave.getStyle().setFgColor(0xFFFFFF); buttonSave.setWidth(100); buttonSave.getDisabledStyle().setBgTransparency(255); buttonSave.getDisabledStyle().setFont(HILMain.getInstance().theme.getFont("defaultFont")); buttonSave.getDisabledStyle().setBorder(Border.createRoundBorder(0, 0, 0xcadaf1)); buttonSave.getDisabledStyle().setBgColor(0xBDBDBD); buttonSave.getDisabledStyle().setAlignment(Label.CENTER); buttonSave.getDisabledStyle().setFgColor(0xFFFFFF); buttonSave.getSelectedStyle().setBgTransparency(255); buttonSave.getSelectedStyle().setFont(HILMain.getInstance().theme.getFont("defaultFont")); buttonSave.getSelectedStyle().setBorder(Border.createRoundBorder(0, 0, 0xcadaf1)); buttonSave.getSelectedStyle().setBgColor(0xFAAC58); buttonSave.getSelectedStyle().setAlignment(Label.CENTER); buttonSave.getSelectedStyle().setFgColor(0x000000); buttonSave.getPressedStyle().setBgTransparency(255); buttonSave.getPressedStyle().setFont(HILMain.getInstance().theme.getFont("defaultFont")); buttonSave.getPressedStyle().setBorder(Border.createRoundBorder(0, 0, 0xcadaf1)); buttonSave.getPressedStyle().setBgColor(0xFAAC58); buttonSave.getPressedStyle().setAlignment(Label.CENTER); buttonSave.getPressedStyle().setFgColor(0x000000); buttonSave.setEnabled(false); f.addComponent(buttonSave); buttonEdit.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent ae) { normalReaction.setEditable(true); seriousReaction.setEditable(true); tetanus.setEditable(true); buttonSave.setEnabled(true); } }); buttonSave.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent ev) { if (normalReaction.getText().trim().length() == 0 && seriousReaction.getText().trim().length() == 0 && tetanus.getText().trim().length() == 0) return; ConnectionRequest req = new ConnectionRequest() { protected void readResponse(InputStream input) throws IOException { JSONParser p = new JSONParser(); Hashtable result = p.parse(new InputStreamReader(input, "UTF-8")); result = (Hashtable) result.get("ResultSet"); int total = ((Double) result.get("totalResultsReturned")).intValue(); if (total == 0) { Dialog.show( (String) HILMain.getInstance().locale.get("notice"), (String) HILMain.getInstance().locale.get("upload_unsuccessful"), (String) HILMain.getInstance().locale.get("ok"), null); } else { Vector entries = (Vector) result.get("Result"); for (int iter = 0; iter < entries.size(); iter++) { result = (Hashtable) entries.elementAt(iter); reportId = (String) result.get("reportId"); normalReaction.setText((String) result.get("normal")); seriousReaction.setText((String) result.get("serious")); tetanus.setText((String) result.get("tetanus")); normalReaction.setEditable(false); seriousReaction.setEditable(false); tetanus.setEditable(false); buttonSave.setEnabled(false); } if (Dialog.show( (String) HILMain.getInstance().locale.get("notice"), (String) HILMain.getInstance().locale.get("upload_successful"), (String) HILMain.getInstance().locale.get("ok"), null)) { buttonSave.setEnabled(false); HILMain.getInstance().showMainMenu(); } } } }; req.setPost(true); req.setUrl(HILMain.getInstance().SERVER_ADDRESS + "saveGeneralReportData"); req.setContentType("text/plain"); req.addArgumentNoEncoding( "sessionAuth", HILMain.getInstance().currentUser.getSessionAuth()); req.addArgumentNoEncoding( "username", HILMain.getInstance().currentUser.getAccountName()); req.addArgumentNoEncoding("password", HILMain.getInstance().currentUser.getPassword()); req.addArgumentNoEncoding("reportId", reportId); req.addArgumentNoEncoding("cId", HILMain.getInstance().currentUser.getcId()); req.addArgumentNoEncoding("timeData", DateUtil.getMonthYear(date, "/")); req.addArgumentNoEncoding("normal", normalReaction.getText().trim()); req.addArgumentNoEncoding("serious", seriousReaction.getText().trim()); req.addArgumentNoEncoding("tatanus", tetanus.getText().trim()); NetworkManager.getInstance().addToQueue(req); } }); dateLabel.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent evt) { TextArea noteLabel = new TextArea(2, 10); noteLabel.getStyle().setFont(HILMain.getInstance().theme.getFont("defaultFont")); noteLabel.getStyle().setBorder(Border.createEmpty(), true); noteLabel.getStyle().setBgTransparency(0); noteLabel.getStyle().setFgColor(0x000000); noteLabel.setFocus(false); noteLabel.setFocusable(false); noteLabel.setText((String) HILMain.getInstance().locale.get("help_select_date")); Form calendarForm = new Form(); calendarForm.setLayout(new BoxLayout(BoxLayout.Y_AXIS)); final Calendar aCalendar = new Calendar(); Command okCommand = new Command((String) HILMain.getInstance().locale.get("ok")) { public void actionPerformed(ActionEvent evt) { showForm(f); } }; aCalendar.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent evt) { date = aCalendar.getDate(); if (!DateUtil.getMonthYear(date, "/").equalsIgnoreCase(dateLabel.getText())) { dateLabel.setText(DateUtil.getMonthYear(date, "/")); reportId = ""; normalReaction.setText(""); seriousReaction.setText(""); tetanus.setText(""); normalReaction.setEditable(true); seriousReaction.setEditable(true); tetanus.setEditable(true); buttonEdit.setEnabled(false); buttonSave.setEnabled(false); } } }); calendarForm.addComponent(noteLabel); Container tContainer = new Container(); tContainer.setLayout(new BorderLayout()); tContainer.addComponent(BorderLayout.CENTER, aCalendar); calendarForm.addComponent(tContainer); calendarForm.addCommand(okCommand); calendarForm.show(); } }); submit.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent ae) { ConnectionRequest req = new ConnectionRequest() { protected void readResponse(InputStream input) throws IOException { JSONParser p = new JSONParser(); Hashtable result = p.parse(new InputStreamReader(input, "UTF-8")); result = (Hashtable) result.get("ResultSet"); int total = ((Double) result.get("totalResultsReturned")).intValue(); if (total == 0) { Dialog.show( (String) HILMain.getInstance().locale.get("notice"), (String) HILMain.getInstance().locale.get("there_is_no_data"), (String) HILMain.getInstance().locale.get("ok"), null); reportId = ""; normalReaction.setText(""); normalReaction.setEditable(true); seriousReaction.setText(""); seriousReaction.setEditable(true); tetanus.setText(""); tetanus.setEditable(true); normalReaction.setEditable(true); seriousReaction.setEditable(true); tetanus.setEditable(true); buttonEdit.setEnabled(false); buttonSave.setEnabled(true); } else { Vector entries = (Vector) result.get("Result"); for (int iter = 0; iter < entries.size(); iter++) { result = (Hashtable) entries.elementAt(iter); reportId = (String) result.get("reportId"); normalReaction.setText((String) result.get("normal")); normalReaction.setEditable(false); seriousReaction.setText((String) result.get("serious")); seriousReaction.setEditable(false); tetanus.setText((String) result.get("tetanus")); tetanus.setEditable(false); normalReaction.setEditable(false); seriousReaction.setEditable(false); tetanus.setEditable(false); buttonEdit.setEnabled(true); buttonSave.setEnabled(false); } if (normalReaction.getText().length() == 0 && seriousReaction.getText().length() == 0 && tetanus.getText().length() == 0) { Dialog.show( (String) HILMain.getInstance().locale.get("notice"), (String) HILMain.getInstance().locale.get("there_is_no_data"), (String) HILMain.getInstance().locale.get("ok"), null); normalReaction.setEditable(true); seriousReaction.setEditable(true); tetanus.setEditable(true); buttonEdit.setEnabled(false); buttonSave.setEnabled(true); } } } }; req.setPost(true); req.setUrl(HILMain.getInstance().SERVER_ADDRESS + "generalReportData"); req.setContentType("text/plain"); req.addArgumentNoEncoding( "sessionAuth", HILMain.getInstance().currentUser.getSessionAuth()); req.addArgumentNoEncoding( "username", HILMain.getInstance().currentUser.getAccountName()); req.addArgumentNoEncoding("password", HILMain.getInstance().currentUser.getPassword()); req.addArgumentNoEncoding("cId", HILMain.getInstance().currentUser.getcId()); req.addArgumentNoEncoding("timeData", DateUtil.getMonthYear(date, "/")); NetworkManager.getInstance().addToQueue(req); } }); }