private void loadList(JList list) { list.removeAll(); profiles = parentGenerator.getProfiles(); DefaultListModel model = new DefaultListModel(); int i = 0; int foundLastProfile = -1; for (Profile p : profiles) { // Check that this profile says it's for this machine if (ProfileUtils.shouldDisplay(p) || filterBox.isSelected()) model.addElement(p.toString()); if (p.toString().equals(Base.preferences.get("lastGeneratorProfileSelected", "---"))) { Base.logger.fine("Selecting last used element: " + p); foundLastProfile = i; } i++; } list.setModel(model); list.clearSelection(); if (foundLastProfile != -1) { list.setSelectedIndex(foundLastProfile); doneButton.setEnabled(true); doneButton.requestFocusInWindow(); doneButton.setFocusPainted(true); } }
/** Does pre-miraclegrue generation tasks */ protected boolean configureGenerator() { if (!parentGenerator.runSanityChecks()) { return false; } int idx = prefPulldown.getSelectedIndex(); if (idx == -1) { return false; } MgProfile p = ProfileUtils.getListedProfile(prefPulldown.getModel(), profiles, idx); Base.preferences.put("lastGeneratorProfileSelected", p.toString()); parentGenerator.profile = p.getFullPath(); MiracleGrueGenerator.setSelectedProfile(p.toString()); return true; }
/** * Fills a combo box with a list of miraclegrue profiles * * @param comboBox to fill with list of miraclegrue profiles */ private void loadList(JComboBox comboBox) { comboBox.removeAllItems(); profiles = parentGenerator.getProfiles(); DefaultComboBoxModel model = new DefaultComboBoxModel(); int i = 0; int foundLastProfile = -1; for (MgProfile p : profiles) { // Check that this profile says it's for this machine if (ProfileUtils.shouldDisplay(p)) { model.addElement(p.toString()); if (p.toString().equals(Base.preferences.get("lastGeneratorProfileSelected", "---"))) { Base.logger.fine("Selecting last used element: " + p); foundLastProfile = i; } i++; } } comboBox.setModel(model); if (foundLastProfile != -1) { comboBox.setSelectedIndex(foundLastProfile); } }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_chat); mContext = this; mMe = ProfileUtils.getUser(mContext); mProgressDialog = new ProgressDialog(this); mProgressDialog.setTitle(getString(R.string.please_wait)); mProgressDialog.setMessage(getString(R.string.please_wait_more)); mTalkee = (User) getIntent().getSerializableExtra("user"); mMessageInput = (EditText) findViewById(R.id.chat_text); mListView = (ListView) findViewById(R.id.listview); mMessages = new ArrayList<>(); mAdapter = new ChatAdapter(this, mMessages); mListView.setAdapter(mAdapter); mListView.setDivider(null); mSendOrAttachButton = (ImageButton) findViewById(R.id.send_button); mMessageInput.addTextChangedListener( new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) {} @Override public void onTextChanged(CharSequence s, int start, int before, int count) {} @Override public void afterTextChanged(Editable s) { if (TextUtils.isEmpty(s.toString())) { mSendOrAttachButton.setImageResource(R.drawable.ic_action_attach); } else { mSendOrAttachButton.setImageResource(R.drawable.send_icon); } } }); mSendOrAttachButton.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { if (!TextUtils.isEmpty(mMessageInput.getText().toString())) { Message message = new Message(); message.setText(mMessageInput.getText().toString()); message.setRoomId(mTalkee.getRoomId()); message.setSender(mMe); message.setStatus(Message.MessageStatus.SENT); message.setDate(String.valueOf(System.currentTimeMillis())); message.setId("not-set"); try { sendMessage(message); } catch (JSONException e) { e.printStackTrace(); } } else { attachFile(); } } }); loadMessages(); }