List of usage examples for java.awt.event KeyAdapter KeyAdapter
KeyAdapter
From source file:org.openconcerto.erp.core.sales.pos.element.SaisieVenteComptoirSQLElement.java
public SQLComponent createComponent() { return new BaseSQLComponent(this) { private final JCheckBox checkService = new JCheckBox("dont "); private SQLSearchableTextCombo textNom; private DeviseField textMontantTTC; private DeviseField textMontantService; private ElementComboBox comboFournisseur; private JTextField textEcheance; private ElementComboBox comboTaxe; private DeviseField textMontantHT; private JCheckBox checkCommande; private JDate dateSaisie; private ElementComboBox nomArticle; private Date dateEch; private JLabel labelEcheancejours = new JLabel("jours"); private ElementComboBox comboAvoir; private ElementComboBox comboClient; private final JLabel labelWarning = new JLabelWarning( "le montant du service ne peut pas dpasser le total HT!"); private ValidState validState = ValidState.getTrueInstance(); // FIXME: use w private Where w; private DocumentListener docTTCListen; private PropertyChangeListener propertyChangeListener = new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent evt) { if ((nomArticle.getValidState().isValid()) && (!nomArticle.isEmpty()) && !isFilling()) { int idArticle = nomArticle.getValue().intValue(); SQLTable tableArticle = ((ComptaPropsConfiguration) Configuration.getInstance()) .getRootSociete().getTable("ARTICLE"); SQLRow rowArticle = tableArticle.getRow(idArticle); if (rowArticle != null) { comboTaxe.setValue(rowArticle.getInt("ID_TAXE")); textMontantTTC.setText(((BigDecimal) rowArticle.getObject("PV_TTC")).toString()); }/*w ww . j a v a 2s . co m*/ System.out.println("value article Changed"); } } }; public void addViews() { this.setLayout(new GridBagLayout()); final GridBagConstraints c = new DefaultGridBagConstraints(); this.docTTCListen = new DocumentListener() { public void changedUpdate(DocumentEvent e) { calculMontant(); } public void removeUpdate(DocumentEvent e) { calculMontant(); } public void insertUpdate(DocumentEvent e) { calculMontant(); } }; /*********************************************************************************** * * RENSEIGNEMENTS **********************************************************************************/ c.gridwidth = GridBagConstraints.REMAINDER; c.gridheight = 1; TitledSeparator sep = new TitledSeparator("Renseignements"); this.add(sep, c); c.insets = new Insets(2, 2, 1, 2); c.gridwidth = 1; // Libell vente JLabel labelNom = new JLabel(getLabelFor("NOM")); labelNom.setHorizontalAlignment(SwingConstants.RIGHT); c.gridy++; c.gridx = 0; c.weightx = 0; this.add(labelNom, c); this.textNom = new SQLSearchableTextCombo(); c.gridx++; c.weightx = 1; c.gridwidth = 2; this.add(this.textNom, c); // Date JLabel labelDate = new JLabel(getLabelFor("DATE")); this.dateSaisie = new JDate(true); c.gridwidth = 1; // c.gridx += 2; c.gridx = 0; c.gridy++; c.weightx = 0; labelDate.setHorizontalAlignment(SwingConstants.RIGHT); this.add(labelDate, c); c.gridx++; c.weightx = 1; this.add(this.dateSaisie, c); // article c.gridy++; c.gridx = 0; this.nomArticle = new ElementComboBox(); JLabel labelNomArticle = new JLabel(getLabelFor("ID_ARTICLE")); c.weightx = 0; labelNomArticle.setHorizontalAlignment(SwingConstants.RIGHT); // this.add(labelNomArticle, c); c.gridx++; c.weightx = 0; c.gridwidth = GridBagConstraints.REMAINDER; // this.add(this.nomArticle, c); this.nomArticle.addValueListener(this.propertyChangeListener); // client this.comboClient = new ElementComboBox(); this.comboClient.addValueListener(new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent evt) { if (comboClient.isEmpty()) { w = new Where(getTable().getBase().getTable("AVOIR_CLIENT").getField("ID_CLIENT"), "=", -1); } else { w = new Where(getTable().getBase().getTable("AVOIR_CLIENT").getField("ID_CLIENT"), "=", comboClient.getSelectedId()); } } }); JLabel labelNomClient = new JLabel(getLabelFor("ID_CLIENT")); c.gridy++; c.gridx = 0; c.gridwidth = 1; c.weightx = 0; labelNomClient.setHorizontalAlignment(SwingConstants.RIGHT); this.add(labelNomClient, c); c.gridx++; c.gridwidth = GridBagConstraints.REMAINDER; c.weightx = 0; this.add(this.comboClient, c); // Selection d'un avoir si le client en possede this.comboAvoir = new ElementComboBox(); JLabel labelAvoirClient = new JLabel(getLabelFor("ID_AVOIR_CLIENT")); c.gridy++; c.gridx = 0; c.gridwidth = 1; c.weightx = 0; labelAvoirClient.setHorizontalAlignment(SwingConstants.RIGHT); // this.add(labelAvoirClient, c); c.gridx++; c.gridwidth = GridBagConstraints.REMAINDER; c.weightx = 0; // this.add(this.comboAvoir, c); /*********************************************************************************** * * MONTANT **********************************************************************************/ c.gridwidth = GridBagConstraints.REMAINDER; c.gridx = 0; c.gridy++; c.weightx = 1; sep = new TitledSeparator("Montant en Euros"); c.insets = new Insets(10, 2, 1, 2); this.add(sep, c); c.insets = new Insets(2, 2, 1, 2); c.gridwidth = 1; final JLabel labelMontantHT = new JLabel(getLabelFor("MONTANT_HT")); labelMontantHT.setHorizontalAlignment(SwingConstants.RIGHT); this.textMontantHT = new DeviseField(); this.textMontantHT.setEditable(false); this.textMontantHT.setEnabled(false); this.textMontantHT.setFocusable(false); final JLabel labelMontantTTC = new JLabel(getLabelFor("MONTANT_TTC")); labelMontantTTC.setHorizontalAlignment(SwingConstants.RIGHT); this.textMontantTTC = new DeviseField(); this.textMontantTTC.getDocument().addDocumentListener(this.docTTCListen); // Montant HT c.fill = GridBagConstraints.HORIZONTAL; c.weightx = 0; c.gridy++; c.gridx = 0; c.gridwidth = 1; this.add(labelMontantHT, c); c.gridx++; c.weightx = 1; this.add(this.textMontantHT, c); // Montant Service c.gridx++; c.weightx = 0; this.add(checkService, c); checkService.addActionListener(new ActionListener() { public void actionPerformed(java.awt.event.ActionEvent e) { if (isFilling()) return; boolean b = checkService.isSelected(); textMontantService.setEditable(b); textMontantService.setEnabled(b); textMontantService.setFocusable(b); if (!b) { textMontantService.setText(""); // montantServiceValide = true; } else { textMontantService.setText(textMontantHT.getText()); } }; }); this.textMontantService = new DeviseField(); c.gridx++; c.weightx = 1; this.add(this.textMontantService, c); JLabel labelMontantService = new JLabel("de service HT"); c.weightx = 0; c.gridx++; this.add(labelMontantService, c); c.gridx++; c.gridwidth = GridBagConstraints.REMAINDER; this.add(this.labelWarning, c); this.labelWarning.setVisible(false); // Choix TVA c.gridy++; c.gridx = 0; c.weightx = 0; c.gridwidth = 1; final JLabel labelTaxe = new JLabel(getLabelFor("ID_TAXE")); labelTaxe.setHorizontalAlignment(SwingUtilities.RIGHT); this.add(labelTaxe, c); c.gridx++; this.comboTaxe = new ElementComboBox(false); c.fill = GridBagConstraints.NONE; this.add(this.comboTaxe, c); c.fill = GridBagConstraints.HORIZONTAL; // Montant TTC c.gridy++; c.gridx = 0; c.weightx = 0; this.add(labelMontantTTC, c); c.gridx++; c.weightx = 0; this.add(this.textMontantTTC, c); /*********************************************************************************** * * MODE DE REGLEMENT **********************************************************************************/ c.gridwidth = GridBagConstraints.REMAINDER; c.gridx = 0; c.gridy++; sep = new TitledSeparator("Mode de rglement"); c.insets = new Insets(10, 2, 1, 2); this.add(sep, c); c.insets = new Insets(2, 2, 1, 2); c.gridx = 0; c.gridy++; c.gridwidth = GridBagConstraints.REMAINDER; this.addView("ID_MODE_REGLEMENT", REQ + ";" + DEC + ";" + SEP); ElementSQLObject eltModeRegl = (ElementSQLObject) this.getView("ID_MODE_REGLEMENT"); this.add(eltModeRegl, c); /*********************************************************************************** * * COMMANDE **********************************************************************************/ c.gridwidth = GridBagConstraints.REMAINDER; c.gridx = 0; c.gridy++; sep = new TitledSeparator("Commande"); c.insets = new Insets(10, 2, 1, 2); this.add(sep, c); c.insets = new Insets(2, 2, 1, 2); this.checkCommande = new JCheckBox("Produit commander"); c.gridx = 0; c.gridy++; c.weightx = 0; c.gridwidth = 2; // this.add(this.checkCommande, c); this.checkCommande.addActionListener(new ActionListener() { public void actionPerformed(java.awt.event.ActionEvent e) { boolean b = checkCommande.isSelected(); comboFournisseur.setEnabled(b); comboFournisseur.setEditable(b); textEcheance.setEditable(b); textEcheance.setEnabled(b); updateValidState(); }; }); // Fournisseurs JLabel labelFournisseur = new JLabel(getLabelFor("ID_FOURNISSEUR")); c.gridx = 0; c.gridy++; c.weightx = 0; c.gridwidth = 1; labelFournisseur.setHorizontalAlignment(SwingConstants.RIGHT); // this.add(labelFournisseur, c); this.comboFournisseur = new ElementComboBox(); c.gridx++; c.weightx = 1; c.gridwidth = 4; // this.add(this.comboFournisseur, c); // Echeance JLabel labelEcheance = new JLabel("Echeance"); c.gridx = 0; c.gridy++; c.weightx = 0; c.gridwidth = 1; labelEcheance.setHorizontalAlignment(SwingConstants.RIGHT); // this.add(labelEcheance, c); c.gridx++; c.weightx = 1; this.textEcheance = new JTextField(); // this.add(this.textEcheance, c); this.textEcheance.addKeyListener(new KeyAdapter() { public void keyReleased(KeyEvent e) { calculDate(); } }); c.gridx++; c.weightx = 0; // this.add(this.labelEcheancejours, c); /*********************************************************************************** * * INFORMATIONS COMPLEMENTAIRES **********************************************************************************/ c.gridwidth = GridBagConstraints.REMAINDER; c.gridx = 0; c.gridy++; sep = new TitledSeparator("Informations complmentaires"); c.insets = new Insets(10, 2, 1, 2); // this.add(sep, c); c.insets = new Insets(2, 2, 1, 2); ITextArea textInfos = new ITextArea(); c.gridx = 0; c.gridy++; c.gridheight = GridBagConstraints.REMAINDER; c.gridwidth = GridBagConstraints.REMAINDER; c.weightx = 1; c.weighty = 1; c.fill = GridBagConstraints.BOTH; // this.add(textInfos, c); this.addSQLObject(this.textNom, "NOM"); this.addRequiredSQLObject(this.comboClient, "ID_CLIENT"); this.addSQLObject(this.nomArticle, "ID_ARTICLE"); this.addRequiredSQLObject(this.textMontantTTC, "MONTANT_TTC"); this.addRequiredSQLObject(this.textMontantHT, "MONTANT_HT"); this.addSQLObject(this.textMontantService, "MONTANT_SERVICE"); this.addRequiredSQLObject(this.dateSaisie, "DATE"); this.addSQLObject(textInfos, "INFOS"); this.addSQLObject(this.comboFournisseur, "ID_FOURNISSEUR"); this.addSQLObject(this.textEcheance, "ECHEANCE"); this.addRequiredSQLObject(this.comboTaxe, "ID_TAXE"); this.addSQLObject(this.comboAvoir, "ID_AVOIR_CLIENT"); this.comboTaxe.setButtonsVisible(false); this.comboTaxe.setValue(2); checkService.setSelected(false); this.textMontantService.setEditable(false); this.textMontantService.setEnabled(false); this.checkCommande.setSelected(false); this.comboFournisseur.setEditable(false); this.comboFournisseur.setEnabled(false); this.textEcheance.setEditable(false); this.textEcheance.setEnabled(false); this.comboTaxe.addValueListener(new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent evt) { calculMontant(); } }); final SimpleDocumentListener docL = new SimpleDocumentListener() { @Override public void update(DocumentEvent e) { updateValidState(); } }; this.textMontantService.getDocument().addDocumentListener(docL); this.textMontantHT.getDocument().addDocumentListener(docL); this.comboFournisseur.addEmptyListener(new EmptyListener() { @Override public void emptyChange(EmptyObj src, boolean newValue) { updateValidState(); } }); /* * this.nomClient.addValueListener(new PropertyChangeListener() { * * public void propertyChange(PropertyChangeEvent evt) { if (nomClient.isValid()) { * System.err.println("Changed Combo Avoir"); comboAvoir = new ElementComboBox(new * AvoirClientSQLElement(new Where(new * AvoirClientSQLElement().getTable().getField("ID_CLIENT"), "=", * nomClient.getValue()))); if (comboAvoir != null) { comboAvoir.setEnabled(true); } * } else { comboAvoir.setEnabled(false); } } }); */ } @Override public Set<String> getPartialResetNames() { Set<String> s = new HashSet<String>(); s.addAll(super.getPartialResetNames()); s.add("MONTANT_TTC"); s.add("MONTANT_SERVICE"); s.add("MONTANT_HT"); s.add("NOM"); s.add("ID_AVOIR_CLIENT"); s.add("ID_ARTICLE"); s.add("INFOS"); return s; } private void calculMontant() { if (!isFilling()) { float taux; // PrixHT pHT; PrixTTC pTTC; // taux de la TVA selectionnee int idTaxe = this.comboTaxe.getSelectedId(); if (idTaxe > 1) { SQLRow ligneTaxe = getTable().getBase().getTable("TAXE").getRow(idTaxe); if (ligneTaxe != null) { taux = (ligneTaxe.getFloat("TAUX")) / 100.0F; // calcul des montants HT ou TTC if (this.textMontantTTC.getText().trim().length() > 0) { if (this.textMontantTTC.getText().trim().equals("-")) { pTTC = new PrixTTC(0); } else { pTTC = new PrixTTC( GestionDevise.parseLongCurrency(this.textMontantTTC.getText())); } // affichage updateTextHT(GestionDevise.currencyToString(pTTC.calculLongHT(taux))); } else { updateTextHT(""); } } } } } private boolean isMontantServiceValid() { String montant = this.textMontantService.getText().trim(); String montantHT = this.textMontantHT.getText().trim(); boolean b; if (montant.length() == 0) { b = true; } else { if (montantHT.length() == 0) { b = false; } else { b = (GestionDevise.parseLongCurrency(montantHT) >= GestionDevise .parseLongCurrency(montant)); } } this.labelWarning.setVisible(!b); System.err.println("Montant service is valid ? " + b + " --> HT val " + montantHT + " --> service val " + montant); return b; } /* * private void calculMontantHT() { * * float taux; PrixHT pHT; * * if (!this.comboTaxe.isEmpty()) { // taux de la TVA selectionnee SQLRow ligneTaxe = * Configuration.getInstance().getBase().getTable("TAXE").getRow(((Integer) * this.comboTaxe.getValue()).intValue()); taux = (ligneTaxe.getFloat("TAUX")) / 100; // * calcul des montants HT ou TTC if (this.textMontantHT.getText().trim().length() > 0) { * * if (this.textMontantHT.getText().trim().equals("-")) { pHT = new PrixHT(0); } else { * pHT = new PrixHT(Float.parseFloat(this.textMontantHT.getText())); } // affichage * updateTextTTC(String.valueOf(pHT.CalculTTC(taux))); } else updateTextTTC(""); } } */ private void updateTextHT(final String prixHT) { SwingUtilities.invokeLater(new Runnable() { public void run() { textMontantHT.setText(prixHT); } }); } @Override protected SQLRowValues createDefaults() { SQLRowValues vals = new SQLRowValues(this.getTable()); SQLRowAccessor r; try { r = ModeReglementDefautPrefPanel.getDefaultRow(true); SQLElement eltModeReglement = Configuration.getInstance().getDirectory() .getElement("MODE_REGLEMENT"); if (r.getID() > 1) { SQLRowValues rowVals = eltModeReglement.createCopy(r.getID()); System.err.println(rowVals.getInt("ID_TYPE_REGLEMENT")); vals.put("ID_MODE_REGLEMENT", rowVals); } } catch (SQLException e) { System.err.println("Impossible de slectionner le mode de rglement par dfaut du client."); e.printStackTrace(); } return vals; } // private void updateTextTTC(final String prixTTC) { // SwingUtilities.invokeLater(new Runnable() { // // public void run() { // // if (docTTCListen != null) { // // textMontantTTC.getDocument().removeDocumentListener(docTTCListen); // } // // textMontantTTC.setText(prixTTC); // // // textTaxe.setText(prixTVA); // textMontantTTC.getDocument().addDocumentListener(docTTCListen); // } // }); // } private void calculDate() { int aJ = 0; // on rcupre les valeurs saisies if (this.textEcheance.getText().trim().length() != 0) { try { aJ = Integer.parseInt(this.textEcheance.getText()); } catch (Exception e) { System.out.println("Erreur de format sur TextField Ajour " + this.textEcheance.getText()); } } Calendar cal = Calendar.getInstance(); // on fixe le temps sur ToDay + Ajour cal.setTime(new Date()); long tempsMil = aJ * 86400000; cal.setTimeInMillis(cal.getTimeInMillis() + tempsMil); DateFormat dateFormat = new SimpleDateFormat("dd/MM/yy"); this.dateEch = cal.getTime(); this.labelEcheancejours.setText("jours, soit le " + dateFormat.format(this.dateEch)); } private void updateValidState() { this.setValidState(this.computeValidState()); } private ValidState computeValidState() { ValidState res = ValidState.getTrueInstance(); if (!this.isMontantServiceValid()) res = res.and(ValidState.createCached(false, this.labelWarning.getText())); if (this.checkCommande.isSelected()) res = res.and(ValidState.createCached(!this.comboFournisseur.isEmpty(), "Fournisseur non renseign")); return res; } private final void setValidState(ValidState validState) { if (!validState.equals(this.validState)) { this.validState = validState; this.fireValidChange(); } } @Override public synchronized ValidState getValidState() { return super.getValidState().and(this.validState); } public int insert(SQLRow order) { // On teste si l'article n'existe pas, on le cre if (this.nomArticle.isEmpty()) { createArticle(); } if (this.textNom.getValue() == null || this.textNom.getValue().trim().length() <= 0) { this.textNom.setValue(this.nomArticle.getTextComp().getText()); } final int id = super.insert(order); // on verifie si le produit est commander if (this.checkCommande.isSelected()) { createCommande(id); } SQLRow rowArt = getTable().getRow(id).getForeignRow("ID_ARTICLE"); if (rowArt != null && !rowArt.isUndefined() && rowArt.getBoolean("GESTION_STOCK")) { Configuration.getInstance().getNonInteractiveSQLExecutor().execute(new Runnable() { @Override public void run() { final SQLRow rowVC = getTable().getRow(id); // Mise jour des stocks final SQLElement eltMvtStock = Configuration.getInstance().getDirectory() .getElement("MOUVEMENT_STOCK"); final SQLRowValues rowVals = new SQLRowValues(eltMvtStock.getTable()); rowVals.put("QTE", -1); rowVals.put("NOM", "Saisie vente comptoir"); rowVals.put("IDSOURCE", id); rowVals.put("SOURCE", getTable().getName()); rowVals.put("ID_ARTICLE", rowVC.getInt("ID_ARTICLE")); rowVals.put("DATE", rowVC.getObject("DATE")); try { final SQLRow row = rowVals.insert(); final ListMap<SQLRow, SQLRowValues> map = ((MouvementStockSQLElement) Configuration .getInstance().getDirectory().getElement("MOUVEMENT_STOCK")) .updateStock(Arrays.asList(row), false); MouvementStockSQLElement.createCommandeF(map, null); } catch (SQLException e) { ExceptionHandler.handle("Erreur lors de la cration des mouvements de stock", e); } } }); } new GenerationMvtSaisieVenteComptoir(id); return id; } private void createCommande(final int id) { System.out.println("Ajout d'une commande"); SQLRow rowSaisie = SaisieVenteComptoirSQLElement.this.getTable().getRow(id); Map<String, Object> m = new HashMap<String, Object>(); // NOM, DATE, ECHEANCE, IDSOURCE, SOURCE, ID_CLI, ID_FOURN, ID_ARTICLE m.put("NOM", rowSaisie.getObject("NOM")); m.put("DATE", rowSaisie.getObject("DATE")); m.put("DATE_ECHEANCE", new java.sql.Date(this.dateEch.getTime())); m.put("IDSOURCE", new Integer(id)); m.put("SOURCE", "SAISIE_VENTE_COMPTOIR"); m.put("ID_CLIENT", rowSaisie.getObject("ID_CLIENT")); m.put("ID_FOURNISSEUR", rowSaisie.getObject("ID_FOURNISSEUR")); m.put("ID_ARTICLE", rowSaisie.getObject("ID_ARTICLE")); SQLTable tableCmd = getTable().getBase().getTable("COMMANDE_CLIENT"); SQLRowValues valCmd = new SQLRowValues(tableCmd, m); try { if (valCmd.getInvalid() == null) { // ajout de l'ecriture valCmd.insert(); } } catch (Exception e) { System.err.println("Erreur l'insertion dans la table " + valCmd.getTable().getName()); e.printStackTrace(); } } private void createArticle() { System.out.println("Cration de l'article"); String tNomArticle = this.nomArticle.getTextComp().getText(); String codeArticle = "";// this.nomArticle.getTextOpt(); if (tNomArticle.trim().length() == 0 && codeArticle.trim().length() == 0) { return; } SQLTable articleTable = getTable().getBase().getTable("ARTICLE"); int idTaxe = this.comboTaxe.getSelectedId(); final BigDecimal prix = StringUtils.getBigDecimalFromUserText(this.textMontantHT.getText()); final BigDecimal prixTTC = StringUtils.getBigDecimalFromUserText(this.textMontantTTC.getText()); if (tNomArticle.trim().length() == 0) { tNomArticle = "Nom Indefini"; } if (codeArticle.trim().length() == 0) { codeArticle = "Indefini"; } SQLRowValues vals = new SQLRowValues(articleTable); vals.put("NOM", tNomArticle); vals.put("CODE", codeArticle); vals.put("PA_HT", prix); vals.put("PV_HT", prix); vals.put("PRIX_METRIQUE_VT_1", prix); vals.put("PRIX_METRIQUE_HA_1", prix); vals.put("PV_TTC", prixTTC); vals.put("ID_UNITE_VENTE", UniteVenteArticleSQLElement.A_LA_PIECE); vals.put("ID_TAXE", new Integer(idTaxe)); vals.put("CREATION_AUTO", Boolean.TRUE); vals.put("GESTION_STOCK", Boolean.FALSE); try { SQLRow row = vals.insert(); this.nomArticle.setValue(row); } catch (SQLException e) { e.printStackTrace(); } } public void update() { if (JOptionPane.showConfirmDialog(this, "Attention en modifiant cette vente comptoir, vous supprimerez les chques et les chances associs. Continuer?", "Modification de vente comptoir", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) { // on efface les mouvements de stocks associs SQLRow row = getTable().getRow(this.getSelectedID()); SQLElement eltMvtStock = Configuration.getInstance().getDirectory() .getElement("MOUVEMENT_STOCK"); SQLSelect sel = new SQLSelect(); sel.addSelect(eltMvtStock.getTable().getField("ID")); Where w = new Where(eltMvtStock.getTable().getField("IDSOURCE"), "=", row.getID()); Where w2 = new Where(eltMvtStock.getTable().getField("SOURCE"), "=", getTable().getName()); sel.setWhere(w.and(w2)); List l = (List) eltMvtStock.getTable().getBase().getDataSource().execute(sel.asString(), new ArrayListHandler()); if (l != null) { for (int i = 0; i < l.size(); i++) { Object[] tmp = (Object[]) l.get(i); try { eltMvtStock.archive(((Number) tmp[0]).intValue()); } catch (SQLException e) { e.printStackTrace(); } } } if (this.textNom.getValue() != null && this.textNom.getValue().trim().length() <= 0) { this.textNom.setValue(this.nomArticle.getTextComp().getText()); } // On teste si l'article n'existe pas, on le cre if (this.nomArticle.getValue() == null || Integer.parseInt(this.nomArticle.getValue().toString()) == -1) { createArticle(); } // TODO check echeance, ---> creation article, commande?? super.update(); row = getTable().getRow(this.getSelectedID()); int idMvt = row.getInt("ID_MOUVEMENT"); System.out.println(row.getID() + "__________***************** UPDATE " + idMvt); // on supprime tout ce qui est li la facture EcritureSQLElement eltEcr = (EcritureSQLElement) Configuration.getInstance().getDirectory() .getElement("ECRITURE"); eltEcr.archiveMouvementProfondeur(idMvt, false); SQLRow rowArt = row.getForeignRow("ID_ARTICLE"); if (rowArt != null && !rowArt.isUndefined() && rowArt.getBoolean("GESTION_STOCK")) { // Mise jour des stocks SQLRowValues rowVals = new SQLRowValues(eltMvtStock.getTable()); rowVals.put("QTE", -1); rowVals.put("NOM", "Saisie vente comptoir"); rowVals.put("IDSOURCE", getSelectedID()); rowVals.put("SOURCE", getTable().getName()); rowVals.put("ID_ARTICLE", row.getInt("ID_ARTICLE")); rowVals.put("DATE", row.getObject("DATE")); try { SQLRow rowNew = rowVals.insert(); final ListMap<SQLRow, SQLRowValues> map = ((MouvementStockSQLElement) Configuration .getInstance().getDirectory().getElement("MOUVEMENT_STOCK")) .updateStock(Arrays.asList(rowNew), false); ComptaPropsConfiguration.getInstanceCompta().getNonInteractiveSQLExecutor() .execute(new Runnable() { @Override public void run() { MouvementStockSQLElement.createCommandeF(map, null); } }); } catch (SQLException e) { e.printStackTrace(); } } if (idMvt > 1) { new GenerationMvtSaisieVenteComptoir(this.getSelectedID(), idMvt); } else { new GenerationMvtSaisieVenteComptoir(this.getSelectedID()); } } } @Override public void select(SQLRowAccessor r) { this.textMontantTTC.getDocument().removeDocumentListener(this.docTTCListen); this.nomArticle.rmValueListener(this.propertyChangeListener); super.select(r); checkService.setSelected( r != null && r.getObject("MONTANT_SERVICE") != null && r.getLong("MONTANT_SERVICE") > 0); this.textMontantTTC.getDocument().addDocumentListener(this.docTTCListen); this.nomArticle.addValueListener(this.propertyChangeListener); } @Override public void select(SQLRowAccessor r, Set<String> views) { super.select(r, views); checkService.setSelected( r != null && r.getObject("MONTANT_SERVICE") != null && r.getLong("MONTANT_SERVICE") > 0); } }; }
From source file:org.freeplane.view.swing.features.time.mindmapmode.NodeList.java
public NodeList(final boolean modal, final boolean showAllNodes, final boolean searchInAllMaps) { // this.modeController = modeController; // controller = modeController.getController(); this.modal = modal; this.showAllNodes = showAllNodes; this.searchInAllMaps = searchInAllMaps; mFilterTextSearchField = new JComboBox(); mFilterTextSearchField.setEditable(true); final FilterTextDocumentListener listener = new FilterTextDocumentListener(); mFilterTextSearchField.addActionListener(listener); final JTextComponent editorComponent = (JTextComponent) mFilterTextSearchField.getEditor() .getEditorComponent();/*from www . j a v a 2s . c om*/ editorComponent.getDocument().addDocumentListener(listener); mFilterTextSearchField.addKeyListener(new KeyAdapter() { @Override public void keyPressed(final KeyEvent pEvent) { if (pEvent.getKeyCode() == KeyEvent.VK_DOWN) { mFilterTextReplaceField.requestFocusInWindow(); } } }); mFilterTextReplaceField = new JComboBox(); mFilterTextReplaceField.setEditable(true); mFilterTextReplaceField.addKeyListener(new KeyAdapter() { @Override public void keyPressed(final KeyEvent pEvent) { if (pEvent.getKeyCode() == KeyEvent.VK_DOWN) { timeTable.requestFocusInWindow(); } else if (pEvent.getKeyCode() == KeyEvent.VK_UP) { mFilterTextSearchField.requestFocusInWindow(); } } }); useRegexInReplace = new JCheckBox(); useRegexInFind = new JCheckBox(); useRegexInFind.addChangeListener(listener); matchCase = new JCheckBox(); matchCase.addChangeListener(listener); final MapChangeListener mapChangeListener = new MapChangeListener(); final ModeController modeController = Controller.getCurrentModeController(); final MapController mapController = modeController.getMapController(); mapController.addMapChangeListener(mapChangeListener); mapController.addNodeChangeListener(mapChangeListener); Controller.getCurrentController().getMapViewManager().addMapSelectionListener(mapChangeListener); }
From source file:op.care.prescription.DlgRegular.java
/** * This method is called from within the constructor to * initialize the form./*from w w w .java 2 s . c om*/ * WARNING: Do NOT modify this code. The content of this method is * always regenerated by the PrinterForm Editor. */ // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents private void initComponents() { jPanel1 = new JPanel(); txtMed = new JXSearchField(); cmbMed = new JComboBox<>(); panel4 = new JPanel(); btnMed = new JButton(); cmbIntervention = new JComboBox<>(); txtIntervention = new JXSearchField(); jPanel8 = new JPanel(); jspDosis = new JScrollPane(); tblDosis = new JTable(); panel2 = new JPanel(); btnAddDosis = new JButton(); jPanel3 = new JPanel(); pnlOFF = new JPanel(); rbActive = new JRadioButton(); rbDate = new JRadioButton(); txtTo = new JTextField(); rbEndOfPackage = new JRadioButton(); jScrollPane3 = new JScrollPane(); txtBemerkung = new JTextPane(); lblText = new JLabel(); pnlON = new JPanel(); cmbDocON = new JComboBox<>(); btnAddGP = new JButton(); cmbHospitalON = new JComboBox<>(); btnAddHospital = new JButton(); panel1 = new JPanel(); btnClose = new JButton(); btnSave = new JButton(); lblTX = new JLabel(); //======== this ======== setModalityType(Dialog.ModalityType.APPLICATION_MODAL); setResizable(false); setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); Container contentPane = getContentPane(); contentPane.setLayout(new FormLayout("$rgap, $lcgap, default, $lcgap, pref, $lcgap, $rgap", "$rgap, $lgap, fill:default:grow, $lgap, fill:default, $lgap, $rgap")); //======== jPanel1 ======== { jPanel1.setBorder(null); jPanel1.setLayout(new FormLayout("68dlu, $lcgap, 284dlu, $lcgap, pref", "2*(16dlu, $lgap), default, $lgap, fill:default:grow")); //---- txtMed ---- txtMed.setFont(new Font("Arial", Font.PLAIN, 14)); txtMed.setPrompt("Medikamente"); txtMed.setFocusBehavior(PromptSupport.FocusBehavior.HIGHLIGHT_PROMPT); txtMed.addActionListener(e -> txtMedActionPerformed(e)); txtMed.addFocusListener(new FocusAdapter() { @Override public void focusGained(FocusEvent e) { txtMedFocusGained(e); } }); jPanel1.add(txtMed, CC.xy(1, 1)); //---- cmbMed ---- cmbMed.setModel(new DefaultComboBoxModel<>(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" })); cmbMed.setFont(new Font("Arial", Font.PLAIN, 14)); cmbMed.addItemListener(e -> cmbMedItemStateChanged(e)); jPanel1.add(cmbMed, CC.xy(3, 1)); //======== panel4 ======== { panel4.setLayout(new BoxLayout(panel4, BoxLayout.LINE_AXIS)); //---- btnMed ---- btnMed.setIcon(new ImageIcon(getClass().getResource("/artwork/22x22/bw/add.png"))); btnMed.setBorderPainted(false); btnMed.setBorder(null); btnMed.setContentAreaFilled(false); btnMed.setToolTipText("Neues Medikament eintragen"); btnMed.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); btnMed.setSelectedIcon(new ImageIcon(getClass().getResource("/artwork/22x22/bw/add-pressed.png"))); btnMed.addActionListener(e -> btnMedActionPerformed(e)); panel4.add(btnMed); } jPanel1.add(panel4, CC.xy(5, 1)); //---- cmbIntervention ---- cmbIntervention .setModel(new DefaultComboBoxModel<>(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" })); cmbIntervention.setFont(new Font("Arial", Font.PLAIN, 14)); jPanel1.add(cmbIntervention, CC.xywh(3, 3, 3, 1)); //---- txtIntervention ---- txtIntervention.setFont(new Font("Arial", Font.PLAIN, 14)); txtIntervention.setPrompt("Massnahmen"); txtIntervention.addActionListener(e -> txtMassActionPerformed(e)); jPanel1.add(txtIntervention, CC.xy(1, 3)); //======== jPanel8 ======== { jPanel8.setBorder(new TitledBorder(null, "Dosis / H\u00e4ufigkeit", TitledBorder.LEADING, TitledBorder.DEFAULT_POSITION, new Font("Arial", Font.PLAIN, 14))); jPanel8.setFont(new Font("Arial", Font.PLAIN, 14)); jPanel8.setLayout(new FormLayout("370dlu", "fill:default:grow, $lgap, pref")); //======== jspDosis ======== { jspDosis.setToolTipText(null); //---- tblDosis ---- tblDosis.setModel(new DefaultTableModel( new Object[][] { { null, null, null, null }, { null, null, null, null }, { null, null, null, null }, { null, null, null, null }, }, new String[] { "Title 1", "Title 2", "Title 3", "Title 4" })); tblDosis.setSurrendersFocusOnKeystroke(true); tblDosis.setToolTipText(null); tblDosis.addMouseListener(new MouseAdapter() { @Override public void mousePressed(MouseEvent e) { tblDosisMousePressed(e); } }); jspDosis.setViewportView(tblDosis); } jPanel8.add(jspDosis, CC.xy(1, 1)); //======== panel2 ======== { panel2.setLayout(new BoxLayout(panel2, BoxLayout.LINE_AXIS)); //---- btnAddDosis ---- btnAddDosis.setIcon(new ImageIcon(getClass().getResource("/artwork/22x22/bw/add.png"))); btnAddDosis.setBorderPainted(false); btnAddDosis.setBorder(null); btnAddDosis.setContentAreaFilled(false); btnAddDosis.setToolTipText("Neue Dosierung eintragen"); btnAddDosis.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); btnAddDosis.setSelectedIcon( new ImageIcon(getClass().getResource("/artwork/22x22/bw/add-pressed.png"))); btnAddDosis.addActionListener(e -> btnAddDosisActionPerformed(e)); panel2.add(btnAddDosis); } jPanel8.add(panel2, CC.xy(1, 3, CC.LEFT, CC.DEFAULT)); } jPanel1.add(jPanel8, CC.xywh(1, 7, 5, 1)); } contentPane.add(jPanel1, CC.xy(5, 3)); //======== jPanel3 ======== { jPanel3.setBorder(null); jPanel3.setLayout(new FormLayout("149dlu", "3*(fill:default, $lgap), fill:108dlu:grow, $lgap, 60dlu")); //======== pnlOFF ======== { pnlOFF.setBorder(new TitledBorder("Absetzung")); pnlOFF.setLayout(new FormLayout("pref, 86dlu:grow", "2*(fill:17dlu, $lgap), fill:17dlu")); //---- rbActive ---- rbActive.setText("text"); rbActive.setSelected(true); rbActive.addItemListener(e -> rbActiveItemStateChanged(e)); pnlOFF.add(rbActive, CC.xywh(1, 1, 2, 1)); //---- rbDate ---- rbDate.setText(null); rbDate.addItemListener(e -> rbDateItemStateChanged(e)); pnlOFF.add(rbDate, CC.xy(1, 3)); //---- txtTo ---- txtTo.addFocusListener(new FocusAdapter() { @Override public void focusLost(FocusEvent e) { txtToFocusLost(e); } }); pnlOFF.add(txtTo, CC.xy(2, 3)); //---- rbEndOfPackage ---- rbEndOfPackage.setText("text"); rbEndOfPackage.addItemListener(e -> rbEndOfPackageItemStateChanged(e)); pnlOFF.add(rbEndOfPackage, CC.xywh(1, 5, 2, 1)); } jPanel3.add(pnlOFF, CC.xy(1, 3)); //======== jScrollPane3 ======== { //---- txtBemerkung ---- txtBemerkung.addCaretListener(e -> txtBemerkungCaretUpdate(e)); jScrollPane3.setViewportView(txtBemerkung); } jPanel3.add(jScrollPane3, CC.xy(1, 7)); //---- lblText ---- lblText.setText("Bemerkung:"); jPanel3.add(lblText, CC.xy(1, 5)); //======== pnlON ======== { pnlON.setBorder(new TitledBorder("Ansetzung")); pnlON.setLayout(new FormLayout("119dlu:grow, $lcgap, default", "default, $lgap, default")); //---- cmbDocON ---- cmbDocON.setModel( new DefaultComboBoxModel<>(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" })); cmbDocON.addKeyListener(new KeyAdapter() { @Override public void keyPressed(KeyEvent e) { cmbDocONKeyPressed(e); } }); pnlON.add(cmbDocON, CC.xy(1, 1)); //---- btnAddGP ---- btnAddGP.setIcon(new ImageIcon(getClass().getResource("/artwork/22x22/bw/add.png"))); btnAddGP.setBorderPainted(false); btnAddGP.setBorder(null); btnAddGP.setContentAreaFilled(false); btnAddGP.setToolTipText("Neues Medikament eintragen"); btnAddGP.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); btnAddGP.setSelectedIcon( new ImageIcon(getClass().getResource("/artwork/22x22/bw/add-pressed.png"))); btnAddGP.addActionListener(e -> btnAddGPActionPerformed(e)); pnlON.add(btnAddGP, CC.xy(3, 1)); //---- cmbHospitalON ---- cmbHospitalON.setModel( new DefaultComboBoxModel<>(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" })); pnlON.add(cmbHospitalON, CC.xy(1, 3)); //---- btnAddHospital ---- btnAddHospital.setIcon(new ImageIcon(getClass().getResource("/artwork/22x22/bw/add.png"))); btnAddHospital.setBorderPainted(false); btnAddHospital.setBorder(null); btnAddHospital.setContentAreaFilled(false); btnAddHospital.setToolTipText("Neues Medikament eintragen"); btnAddHospital.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); btnAddHospital.setSelectedIcon( new ImageIcon(getClass().getResource("/artwork/22x22/bw/add-pressed.png"))); btnAddHospital.addActionListener(e -> btnAddHospitalActionPerformed(e)); pnlON.add(btnAddHospital, CC.xy(3, 3)); } jPanel3.add(pnlON, CC.xy(1, 1)); } contentPane.add(jPanel3, CC.xy(3, 3)); //======== panel1 ======== { panel1.setLayout(new BoxLayout(panel1, BoxLayout.LINE_AXIS)); //---- btnClose ---- btnClose.setIcon(new ImageIcon(getClass().getResource("/artwork/22x22/cancel.png"))); btnClose.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); btnClose.addActionListener(e -> btnCloseActionPerformed(e)); panel1.add(btnClose); //---- btnSave ---- btnSave.setIcon(new ImageIcon(getClass().getResource("/artwork/22x22/apply.png"))); btnSave.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); btnSave.addActionListener(e -> btnSaveActionPerformed(e)); panel1.add(btnSave); } contentPane.add(panel1, CC.xy(5, 5, CC.RIGHT, CC.DEFAULT)); //---- lblTX ---- lblTX.setText(null); lblTX.setIcon(new ImageIcon(getClass().getResource("/artwork/22x22/ambulance2.png"))); contentPane.add(lblTX, CC.xy(3, 5)); setSize(1015, 640); setLocationRelativeTo(getOwner()); //---- bgMedikament ---- ButtonGroup bgMedikament = new ButtonGroup(); bgMedikament.add(rbActive); bgMedikament.add(rbDate); bgMedikament.add(rbEndOfPackage); }
From source file:com.rapidminer.gui.new_plotter.gui.dialog.ManageZoomDialog.java
/** * Setup the GUI.// w w w. ja va2s. c o m */ private void setupGUI() { JPanel mainPanel = new JPanel(); this.setContentPane(mainPanel); // start layout mainPanel.setLayout(new GridBagLayout()); GridBagConstraints gbc = new GridBagConstraints(); gbc.gridx = 0; gbc.gridy = 0; gbc.fill = GridBagConstraints.HORIZONTAL; gbc.weightx = 0; gbc.anchor = GridBagConstraints.WEST; gbc.insets = new Insets(5, 5, 2, 5); JPanel radioPanel = new JPanel(); radioPanel.setLayout(new BorderLayout()); zoomRadiobutton = new JRadioButton( I18N.getMessage(I18N.getGUIBundle(), "gui.action.manage_zoom.zoom.label")); zoomRadiobutton.setToolTipText(I18N.getMessage(I18N.getGUIBundle(), "gui.action.manage_zoom.zoom.tip")); zoomRadiobutton.setSelected(true); radioPanel.add(zoomRadiobutton, BorderLayout.LINE_START); gbc.gridx = 1; gbc.gridy = 0; gbc.weightx = 1; selectionRadiobutton = new JRadioButton( I18N.getMessage(I18N.getGUIBundle(), "gui.action.manage_zoom.selection.label")); selectionRadiobutton .setToolTipText(I18N.getMessage(I18N.getGUIBundle(), "gui.action.manage_zoom.selection.tip")); selectionRadiobutton.setHorizontalAlignment(SwingConstants.CENTER); radioPanel.add(selectionRadiobutton, BorderLayout.LINE_END); gbc.gridx = 0; gbc.gridy = 0; gbc.gridwidth = 3; this.add(radioPanel, gbc); ButtonGroup group = new ButtonGroup(); group.add(zoomRadiobutton); group.add(selectionRadiobutton); gbc.gridx = 0; gbc.gridy = 1; gbc.fill = GridBagConstraints.BOTH; gbc.weightx = 1; gbc.gridwidth = 3; gbc.anchor = GridBagConstraints.CENTER; rangeAxisSelectionCombobox = new JComboBox(); rangeAxisSelectionCombobox.setToolTipText( I18N.getMessage(I18N.getGUIBundle(), "gui.action.manage_zoom.range_axis_combobox.tip")); rangeAxisSelectionCombobox.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { updateValueRange(); } }); this.add(rangeAxisSelectionCombobox, gbc); gbc.gridx = 0; gbc.gridy = 2; gbc.fill = GridBagConstraints.NONE; gbc.weightx = 1; gbc.gridwidth = 3; gbc.anchor = GridBagConstraints.WEST; gbc.insets = new Insets(5, 5, 2, 5); JLabel domainRangeLowerBoundLabel = new JLabel( I18N.getMessage(I18N.getGUIBundle(), "gui.action.manage_zoom.domain_lower_bound.label")); this.add(domainRangeLowerBoundLabel, gbc); gbc.gridx = 1; gbc.gridy = 2; gbc.insets = new Insets(2, 5, 2, 5); gbc.fill = GridBagConstraints.HORIZONTAL; domainRangeLowerBoundField = new JTextField(); domainRangeLowerBoundField.setText(String.valueOf(domainRangeLowerBound)); domainRangeLowerBoundField.setInputVerifier(new InputVerifier() { @Override public boolean verify(JComponent input) { return verifyDomainRangeLowerBoundInput(input); } }); domainRangeLowerBoundField.setToolTipText( I18N.getMessage(I18N.getGUIBundle(), "gui.action.manage_zoom.domain_lower_bound.tip")); this.add(domainRangeLowerBoundField, gbc); gbc.gridx = 0; gbc.gridy = 3; gbc.fill = GridBagConstraints.NONE; JLabel domainRangeUpperBoundLabel = new JLabel( I18N.getMessage(I18N.getGUIBundle(), "gui.action.manage_zoom.domain_upper_bound.label")); this.add(domainRangeUpperBoundLabel, gbc); gbc.gridx = 1; gbc.gridy = 3; gbc.fill = GridBagConstraints.HORIZONTAL; domainRangeUpperBoundField = new JTextField(); domainRangeUpperBoundField.setToolTipText( I18N.getMessage(I18N.getGUIBundle(), "gui.action.manage_zoom.domain_upper_bound.tip")); domainRangeUpperBoundField.setText(String.valueOf(domainRangeUpperBound)); domainRangeUpperBoundField.setInputVerifier(new InputVerifier() { @Override public boolean verify(JComponent input) { return verifyDomainRangeUpperBoundInput(input); } }); this.add(domainRangeUpperBoundField, gbc); gbc.gridx = 0; gbc.gridy = 4; gbc.fill = GridBagConstraints.NONE; JLabel valueRangeLowerBoundLabel = new JLabel( I18N.getMessage(I18N.getGUIBundle(), "gui.action.manage_zoom.value_lower_bound.label")); this.add(valueRangeLowerBoundLabel, gbc); gbc.gridx = 1; gbc.gridy = 4; gbc.fill = GridBagConstraints.HORIZONTAL; valueRangeLowerBoundField = new JTextField(); valueRangeLowerBoundField.setToolTipText( I18N.getMessage(I18N.getGUIBundle(), "gui.action.manage_zoom.value_lower_bound.tip")); valueRangeLowerBoundField.setText(String.valueOf(valueRangeLowerBound)); valueRangeLowerBoundField.setInputVerifier(new InputVerifier() { @Override public boolean verify(JComponent input) { return verifyValueRangeLowerBoundInput(input); } }); this.add(valueRangeLowerBoundField, gbc); gbc.gridx = 0; gbc.gridy = 5; gbc.fill = GridBagConstraints.NONE; JLabel valueRangeUpperBoundLabel = new JLabel( I18N.getMessage(I18N.getGUIBundle(), "gui.action.manage_zoom.value_upper_bound.label")); this.add(valueRangeUpperBoundLabel, gbc); gbc.gridx = 1; gbc.gridy = 5; gbc.fill = GridBagConstraints.HORIZONTAL; valueRangeUpperBoundField = new JTextField(); valueRangeUpperBoundField.setToolTipText( I18N.getMessage(I18N.getGUIBundle(), "gui.action.manage_zoom.value_upper_bound.tip")); valueRangeUpperBoundField.setText(String.valueOf(valueRangeUpperBound)); valueRangeUpperBoundField.setInputVerifier(new InputVerifier() { @Override public boolean verify(JComponent input) { return verifyValueRangeUpperBoundInput(input); } }); this.add(valueRangeUpperBoundField, gbc); gbc.gridx = 0; gbc.gridy = 6; gbc.gridwidth = 3; gbc.fill = GridBagConstraints.HORIZONTAL; gbc.anchor = GridBagConstraints.CENTER; this.add(new JSeparator(), gbc); gbc.gridx = 0; gbc.gridy = 7; gbc.fill = GridBagConstraints.NONE; gbc.anchor = GridBagConstraints.WEST; JLabel colorMinValueLabel = new JLabel( I18N.getMessage(I18N.getGUIBundle(), "gui.action.manage_zoom.color_min_value.label")); this.add(colorMinValueLabel, gbc); gbc.gridx = 1; gbc.gridy = 7; gbc.fill = GridBagConstraints.HORIZONTAL; colorMinValueField = new JTextField(); colorMinValueField .setToolTipText(I18N.getMessage(I18N.getGUIBundle(), "gui.action.manage_zoom.color_min_value.tip")); colorMinValueField.setText(String.valueOf(colorMinValue)); colorMinValueField.setInputVerifier(new InputVerifier() { @Override public boolean verify(JComponent input) { return verifyColorInput(input); } }); colorMinValueField.setEnabled(false); this.add(colorMinValueField, gbc); gbc.gridx = 0; gbc.gridy = 8; gbc.fill = GridBagConstraints.NONE; JLabel colorMaxValueLabel = new JLabel( I18N.getMessage(I18N.getGUIBundle(), "gui.action.manage_zoom.color_max_value.label")); this.add(colorMaxValueLabel, gbc); gbc.gridx = 1; gbc.gridy = 8; gbc.fill = GridBagConstraints.HORIZONTAL; colorMaxValueField = new JTextField(); colorMaxValueField .setToolTipText(I18N.getMessage(I18N.getGUIBundle(), "gui.action.manage_zoom.color_max_value.tip")); colorMaxValueField.setText(String.valueOf(colorMaxValue)); colorMaxValueField.setInputVerifier(new InputVerifier() { @Override public boolean verify(JComponent input) { return verifyColorInput(input); } }); colorMaxValueField.setEnabled(false); this.add(colorMaxValueField, gbc); gbc.gridx = 1; gbc.gridy = 9; gbc.fill = GridBagConstraints.NONE; restoreColorButton = new JButton( I18N.getMessage(I18N.getGUIBundle(), "gui.action.manage_zoom.restore_color.label")); restoreColorButton .setToolTipText(I18N.getMessage(I18N.getGUIBundle(), "gui.action.manage_zoom.restore_color.tip")); restoreColorButton.setIcon(SwingTools.createIcon( "16/" + I18N.getMessage(I18N.getGUIBundle(), "gui.action.manage_zoom.restore_color.icon"))); restoreColorButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { LinkAndBrushSelection linkAndBrushSelection = new LinkAndBrushSelection(SelectionType.RESTORE_COLOR, new LinkedList<Pair<Integer, Range>>(), new LinkedList<Pair<Integer, Range>>(), null, null, engine.getPlotInstance()); engine.getChartPanel().informLinkAndBrushSelectionListeners(linkAndBrushSelection); updateColorValues(); } }); restoreColorButton.setEnabled(false); this.add(restoreColorButton, gbc); gbc.gridx = 0; gbc.gridy = 10; gbc.gridwidth = 3; gbc.fill = GridBagConstraints.HORIZONTAL; gbc.anchor = GridBagConstraints.CENTER; gbc.insets = new Insets(2, 5, 5, 5); this.add(new JSeparator(), gbc); gbc.gridx = 0; gbc.gridy = 11; gbc.gridwidth = 1; gbc.fill = GridBagConstraints.NONE; gbc.anchor = GridBagConstraints.WEST; gbc.insets = new Insets(5, 5, 5, 5); okButton = new JButton(I18N.getMessage(I18N.getGUIBundle(), "gui.action.manage_zoom.ok.label")); okButton.setToolTipText(I18N.getMessage(I18N.getGUIBundle(), "gui.action.manage_zoom.ok.tip")); okButton.setIcon(SwingTools .createIcon("24/" + I18N.getMessage(I18N.getGUIBundle(), "gui.action.manage_zoom.ok.icon"))); okButton.setMnemonic( I18N.getMessage(I18N.getGUIBundle(), "gui.action.manage_zoom.ok.mne").toCharArray()[0]); okButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { // make sure fields have correct values boolean fieldsPassedChecks = checkFields(); if (!fieldsPassedChecks) { return; } Object selectedItem = rangeAxisSelectionCombobox.getSelectedItem(); if (selectedItem != null && selectedItem instanceof RangeAxisConfig) { RangeAxisConfig config = (RangeAxisConfig) selectedItem; boolean zoomOnLinkAndBrushSelection = engine.getChartPanel().getZoomOnLinkAndBrushSelection(); Range domainRange = new Range(Double.parseDouble(domainRangeLowerBoundField.getText()), Double.parseDouble(domainRangeUpperBoundField.getText())); Range valueRange = new Range(Double.parseDouble(valueRangeLowerBoundField.getText()), Double.parseDouble(valueRangeUpperBoundField.getText())); LinkedList<Pair<Integer, Range>> domainRangeList = new LinkedList<Pair<Integer, Range>>(); // only add domain zoom if != 0 if (domainRange.getUpperBound() != 0) { domainRangeList.add(new Pair<Integer, Range>(0, domainRange)); } LinkedList<Pair<Integer, Range>> valueRangeList = new LinkedList<Pair<Integer, Range>>(); // only add range zoom if at least one RangeAxisConfig exists if (engine.getPlotInstance().getMasterPlotConfiguration().getRangeAxisConfigs().size() > 0) { if (valueRange.getUpperBound() != 0) { // only add value zoom if != 0 valueRangeList.add( new Pair<Integer, Range>(engine.getPlotInstance().getMasterPlotConfiguration() .getIndexOfRangeAxisConfigById(config.getId()), valueRange)); } } // zoom or select or color LinkAndBrushSelection linkAndBrushSelection = null; if (zoomRadiobutton.isSelected()) { linkAndBrushSelection = new LinkAndBrushSelection(SelectionType.ZOOM_IN, domainRangeList, valueRangeList); if (isColorChanged(Double.parseDouble(colorMinValueField.getText()), Double.parseDouble(colorMaxValueField.getText()))) { linkAndBrushSelection = new LinkAndBrushSelection(SelectionType.COLOR_ZOOM, domainRangeList, valueRangeList, Double.parseDouble(colorMinValueField.getText()), Double.parseDouble(colorMaxValueField.getText()), engine.getPlotInstance()); } } else if (selectionRadiobutton.isSelected()) { linkAndBrushSelection = new LinkAndBrushSelection(SelectionType.SELECTION, domainRangeList, valueRangeList); if (isColorChanged(Double.parseDouble(colorMinValueField.getText()), Double.parseDouble(colorMaxValueField.getText()))) { linkAndBrushSelection = new LinkAndBrushSelection(SelectionType.COLOR_SELECTION, domainRangeList, valueRangeList, Double.parseDouble(colorMinValueField.getText()), Double.parseDouble(colorMaxValueField.getText()), engine.getPlotInstance()); } } engine.getChartPanel().informLinkAndBrushSelectionListeners(linkAndBrushSelection); engine.getChartPanel().setZoomOnLinkAndBrushSelection(zoomOnLinkAndBrushSelection); } else { return; } ManageZoomDialog.this.dispose(); } }); okButton.addKeyListener(new KeyAdapter() { @Override public void keyPressed(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_ENTER) { okButton.doClick(); } } }); this.add(okButton, gbc); gbc.gridx = 2; gbc.gridy = 11; gbc.fill = GridBagConstraints.NONE; gbc.anchor = GridBagConstraints.EAST; cancelButton = new JButton(I18N.getMessage(I18N.getGUIBundle(), "gui.action.manage_zoom.cancel.label")); cancelButton.setToolTipText(I18N.getMessage(I18N.getGUIBundle(), "gui.action.manage_zoom.cancel.tip")); cancelButton.setIcon(SwingTools .createIcon("24/" + I18N.getMessage(I18N.getGUIBundle(), "gui.action.manage_zoom.cancel.icon"))); cancelButton.setMnemonic( I18N.getMessage(I18N.getGUIBundle(), "gui.action.manage_zoom.cancel.mne").toCharArray()[0]); cancelButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { // cancel requested, close dialog ManageZoomDialog.this.dispose(); } }); this.add(cancelButton, gbc); // misc settings this.setMinimumSize(new Dimension(375, 360)); // center dialog this.setLocationRelativeTo(null); this.setTitle(I18N.getMessage(I18N.getGUIBundle(), "gui.action.manage_zoom.title.label")); this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); this.setModal(true); this.addWindowListener(new WindowAdapter() { @Override public void windowActivated(WindowEvent e) { okButton.requestFocusInWindow(); } }); }
From source file:com.projity.pm.graphic.spreadsheet.SpreadSheet.java
protected void initListeners() { addKeyListener(new KeyAdapter() { // TODO need to fix focus problems elsewhere for this to always work public void keyPressed(KeyEvent e) { int row = getSelectedRow(); if (row < 0) return; CommonSpreadSheetModel model = (CommonSpreadSheetModel) getModel(); if (e.getKeyCode() == KeyEvent.VK_INSERT) executeAction(MenuActionConstants.ACTION_NEW); else if (e.getKeyCode() == KeyEvent.VK_DELETE) executeAction(MenuActionConstants.ACTION_DELETE); else if (e.getKeyCode() == KeyEvent.VK_F3) GraphicManager.getInstance().doFind(SpreadSheet.this, null); else if (e.getKeyCode() == KeyEvent.VK_F && e.getModifiers() == KeyEvent.CTRL_MASK) GraphicManager.getInstance().doFind(SpreadSheet.this, null); }/*from ww w. j ava 2 s. c om*/ }); }
From source file:AppSpringLayout.java
/** * Initialize the contents of the frame. */// w ww.j av a 2 s. co m private void initialize() { frame = new JFrame(); frame.setBounds(0, 0, 850, 750); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); springLayout = new SpringLayout(); frame.getContentPane().setLayout(springLayout); frame.setLocationRelativeTo(null); FileNameExtensionFilter filter = new FileNameExtensionFilter("Image files", "jpg", "jpeg", "png"); fc = new JFileChooser(); fc.setFileFilter(filter); // frame.getContentPane().add(fc); btnTurnCameraOn = new JButton("Turn camera on"); springLayout.putConstraint(SpringLayout.WEST, btnTurnCameraOn, 51, SpringLayout.WEST, frame.getContentPane()); springLayout.putConstraint(SpringLayout.EAST, btnTurnCameraOn, -581, SpringLayout.EAST, frame.getContentPane()); frame.getContentPane().add(btnTurnCameraOn); urlTextField = new JTextField(); springLayout.putConstraint(SpringLayout.SOUTH, btnTurnCameraOn, -6, SpringLayout.NORTH, urlTextField); springLayout.putConstraint(SpringLayout.WEST, urlTextField, 0, SpringLayout.WEST, btnTurnCameraOn); springLayout.putConstraint(SpringLayout.EAST, urlTextField, 274, SpringLayout.WEST, frame.getContentPane()); frame.getContentPane().add(urlTextField); urlTextField.setColumns(10); originalImageLabel = new JLabel(""); springLayout.putConstraint(SpringLayout.NORTH, originalImageLabel, 102, SpringLayout.NORTH, frame.getContentPane()); springLayout.putConstraint(SpringLayout.WEST, originalImageLabel, 34, SpringLayout.WEST, frame.getContentPane()); springLayout.putConstraint(SpringLayout.SOUTH, originalImageLabel, -326, SpringLayout.SOUTH, frame.getContentPane()); springLayout.putConstraint(SpringLayout.EAST, originalImageLabel, -566, SpringLayout.EAST, frame.getContentPane()); springLayout.putConstraint(SpringLayout.SOUTH, urlTextField, -6, SpringLayout.NORTH, originalImageLabel); frame.getContentPane().add(originalImageLabel); btnAnalyseImage = new JButton("Analyse image"); springLayout.putConstraint(SpringLayout.NORTH, btnAnalyseImage, 6, SpringLayout.SOUTH, originalImageLabel); springLayout.putConstraint(SpringLayout.WEST, btnAnalyseImage, 58, SpringLayout.WEST, frame.getContentPane()); springLayout.putConstraint(SpringLayout.EAST, btnAnalyseImage, 252, SpringLayout.WEST, frame.getContentPane()); frame.getContentPane().add(btnAnalyseImage); lblTags = new JLabel("Tags:"); frame.getContentPane().add(lblTags); lblDescription = new JLabel("Description:"); springLayout.putConstraint(SpringLayout.WEST, lblDescription, 84, SpringLayout.EAST, lblTags); springLayout.putConstraint(SpringLayout.NORTH, lblTags, 0, SpringLayout.NORTH, lblDescription); springLayout.putConstraint(SpringLayout.NORTH, lblDescription, 6, SpringLayout.SOUTH, btnAnalyseImage); springLayout.putConstraint(SpringLayout.SOUTH, lblDescription, -269, SpringLayout.SOUTH, frame.getContentPane()); frame.getContentPane().add(lblDescription); tagsTextArea = new JTextArea(); springLayout.putConstraint(SpringLayout.NORTH, tagsTextArea, 459, SpringLayout.NORTH, frame.getContentPane()); springLayout.putConstraint(SpringLayout.WEST, tagsTextArea, 10, SpringLayout.WEST, frame.getContentPane()); springLayout.putConstraint(SpringLayout.EAST, tagsTextArea, -727, SpringLayout.EAST, frame.getContentPane()); frame.getContentPane().add(tagsTextArea); descriptionTextArea = new JTextArea(); springLayout.putConstraint(SpringLayout.NORTH, descriptionTextArea, 0, SpringLayout.SOUTH, lblDescription); springLayout.putConstraint(SpringLayout.WEST, descriptionTextArea, 18, SpringLayout.EAST, tagsTextArea); descriptionTextArea.setLineWrap(true); descriptionTextArea.setWrapStyleWord(true); frame.getContentPane().add(descriptionTextArea); lblImageType = new JLabel("Image type"); springLayout.putConstraint(SpringLayout.WEST, lblTags, 0, SpringLayout.WEST, lblImageType); springLayout.putConstraint(SpringLayout.NORTH, lblImageType, 10, SpringLayout.SOUTH, tagsTextArea); springLayout.putConstraint(SpringLayout.WEST, lblImageType, 20, SpringLayout.WEST, frame.getContentPane()); frame.getContentPane().add(lblImageType); lblSize = new JLabel("Size"); springLayout.putConstraint(SpringLayout.NORTH, lblSize, 21, SpringLayout.SOUTH, lblImageType); springLayout.putConstraint(SpringLayout.WEST, lblSize, 20, SpringLayout.WEST, frame.getContentPane()); frame.getContentPane().add(lblSize); lblLicense = new JLabel("License"); springLayout.putConstraint(SpringLayout.WEST, lblLicense, 20, SpringLayout.WEST, frame.getContentPane()); frame.getContentPane().add(lblLicense); lblSafeSearch = new JLabel("Safe search"); springLayout.putConstraint(SpringLayout.WEST, lblSafeSearch, 10, SpringLayout.WEST, frame.getContentPane()); springLayout.putConstraint(SpringLayout.SOUTH, lblSafeSearch, 139, SpringLayout.SOUTH, frame.getContentPane()); frame.getContentPane().add(lblSafeSearch); String[] licenseTypes = { "unspecified", "Public", "Share", "ShareCommercially", "Modify" }; licenseBox = new JComboBox(licenseTypes); springLayout.putConstraint(SpringLayout.WEST, licenseBox, 28, SpringLayout.EAST, lblLicense); frame.getContentPane().add(licenseBox); String[] sizeTypes = { "unspecified", "Small", "Medium", "Large", "Wallpaper" }; sizeBox = new JComboBox(sizeTypes); springLayout.putConstraint(SpringLayout.WEST, sizeBox, 50, SpringLayout.EAST, lblSize); springLayout.putConstraint(SpringLayout.EAST, sizeBox, -556, SpringLayout.EAST, frame.getContentPane()); springLayout.putConstraint(SpringLayout.EAST, licenseBox, 0, SpringLayout.EAST, sizeBox); frame.getContentPane().add(sizeBox); String[] imageTypes = { "unspecified", "AnimategGif", "Clipart", "Line", "Photo" }; imageTypeBox = new JComboBox(imageTypes); springLayout.putConstraint(SpringLayout.SOUTH, descriptionTextArea, -6, SpringLayout.NORTH, imageTypeBox); springLayout.putConstraint(SpringLayout.NORTH, imageTypeBox, 547, SpringLayout.NORTH, frame.getContentPane()); springLayout.putConstraint(SpringLayout.SOUTH, tagsTextArea, -6, SpringLayout.NORTH, imageTypeBox); springLayout.putConstraint(SpringLayout.WEST, imageTypeBox, 6, SpringLayout.EAST, lblImageType); springLayout.putConstraint(SpringLayout.EAST, imageTypeBox, -556, SpringLayout.EAST, frame.getContentPane()); springLayout.putConstraint(SpringLayout.NORTH, sizeBox, 10, SpringLayout.SOUTH, imageTypeBox); frame.getContentPane().add(imageTypeBox); btnBrowse = new JButton("Browse"); springLayout.putConstraint(SpringLayout.WEST, btnBrowse, 0, SpringLayout.WEST, btnTurnCameraOn); springLayout.putConstraint(SpringLayout.EAST, btnBrowse, -583, SpringLayout.EAST, frame.getContentPane()); frame.getContentPane().add(btnBrowse); lblSafeSearch_1 = new JLabel("Safe search"); springLayout.putConstraint(SpringLayout.WEST, lblSafeSearch_1, 20, SpringLayout.WEST, frame.getContentPane()); springLayout.putConstraint(SpringLayout.SOUTH, lblLicense, -17, SpringLayout.NORTH, lblSafeSearch_1); frame.getContentPane().add(lblSafeSearch_1); String[] safeSearchTypes = { "Strict", "Moderate", "Off" }; safeSearchBox = new JComboBox(safeSearchTypes); springLayout.putConstraint(SpringLayout.SOUTH, licenseBox, -6, SpringLayout.NORTH, safeSearchBox); springLayout.putConstraint(SpringLayout.WEST, safeSearchBox, 4, SpringLayout.EAST, lblSafeSearch_1); springLayout.putConstraint(SpringLayout.EAST, safeSearchBox, 0, SpringLayout.EAST, licenseBox); frame.getContentPane().add(safeSearchBox); btnSearchForSimilar = new JButton("Search for similar images"); springLayout.putConstraint(SpringLayout.SOUTH, lblSafeSearch_1, -13, SpringLayout.NORTH, btnSearchForSimilar); springLayout.putConstraint(SpringLayout.SOUTH, safeSearchBox, -6, SpringLayout.NORTH, btnSearchForSimilar); springLayout.putConstraint(SpringLayout.NORTH, btnSearchForSimilar, 689, SpringLayout.NORTH, frame.getContentPane()); springLayout.putConstraint(SpringLayout.WEST, btnSearchForSimilar, 36, SpringLayout.WEST, frame.getContentPane()); frame.getContentPane().add(btnSearchForSimilar); btnCancel = new JButton("Cancel"); springLayout.putConstraint(SpringLayout.NORTH, btnCancel, 0, SpringLayout.NORTH, btnBrowse); btnCancel.setVisible(false); frame.getContentPane().add(btnCancel); btnSave = new JButton("Save"); springLayout.putConstraint(SpringLayout.WEST, btnCancel, 6, SpringLayout.EAST, btnSave); springLayout.putConstraint(SpringLayout.NORTH, btnSave, 0, SpringLayout.NORTH, btnBrowse); btnSave.setVisible(false); frame.getContentPane().add(btnSave); btnTakeAPicture = new JButton("Take a picture"); springLayout.putConstraint(SpringLayout.WEST, btnTakeAPicture, 114, SpringLayout.EAST, btnBrowse); springLayout.putConstraint(SpringLayout.WEST, btnSave, 6, SpringLayout.EAST, btnTakeAPicture); springLayout.putConstraint(SpringLayout.NORTH, btnTakeAPicture, 0, SpringLayout.NORTH, btnBrowse); btnTakeAPicture.setVisible(false); frame.getContentPane().add(btnTakeAPicture); //// JScrollPane scroll = new JScrollPane(list); // Constraints c = springLayout.getConstraints(list); // frame.getContentPane().add(scroll, c); list = new JList(); JScrollPane scroll = new JScrollPane(list); springLayout.putConstraint(SpringLayout.EAST, descriptionTextArea, -89, SpringLayout.WEST, list); springLayout.putConstraint(SpringLayout.EAST, list, -128, SpringLayout.EAST, frame.getContentPane()); springLayout.putConstraint(SpringLayout.WEST, list, 64, SpringLayout.EAST, licenseBox); springLayout.putConstraint(SpringLayout.NORTH, list, 0, SpringLayout.NORTH, btnTurnCameraOn); springLayout.putConstraint(SpringLayout.SOUTH, list, -35, SpringLayout.SOUTH, lblSafeSearch_1); Constraints c = springLayout.getConstraints(list); frame.getContentPane().add(scroll, c); // frame.getContentPane().add(list); progressBar = new JProgressBar(); springLayout.putConstraint(SpringLayout.NORTH, progressBar, 15, SpringLayout.SOUTH, list); springLayout.putConstraint(SpringLayout.WEST, progressBar, 24, SpringLayout.EAST, safeSearchBox); springLayout.putConstraint(SpringLayout.EAST, progressBar, 389, SpringLayout.WEST, btnTakeAPicture); progressBar.setIndeterminate(true); progressBar.setStringPainted(true); progressBar.setVisible(false); Border border = BorderFactory .createTitledBorder("We are checking every image, pixel by pixel, it may take a while..."); progressBar.setBorder(border); frame.getContentPane().add(progressBar); labelTryLinks = new JLabel(); labelTryLinks.setVisible(false); springLayout.putConstraint(SpringLayout.NORTH, labelTryLinks, -16, SpringLayout.SOUTH, btnSearchForSimilar); springLayout.putConstraint(SpringLayout.WEST, labelTryLinks, -61, SpringLayout.EAST, licenseBox); springLayout.putConstraint(SpringLayout.SOUTH, labelTryLinks, 0, SpringLayout.SOUTH, btnSearchForSimilar); springLayout.putConstraint(SpringLayout.EAST, labelTryLinks, 0, SpringLayout.EAST, licenseBox); frame.getContentPane().add(labelTryLinks); lblFoundLinks = new JLabel(""); springLayout.putConstraint(SpringLayout.NORTH, lblFoundLinks, -29, SpringLayout.NORTH, progressBar); springLayout.putConstraint(SpringLayout.WEST, lblFoundLinks, 6, SpringLayout.EAST, scroll); springLayout.putConstraint(SpringLayout.SOUTH, lblFoundLinks, -13, SpringLayout.NORTH, progressBar); springLayout.putConstraint(SpringLayout.EAST, lblFoundLinks, -10, SpringLayout.EAST, frame.getContentPane()); frame.getContentPane().add(lblFoundLinks); numberOfImagesToSearchFor = new JTextField(); springLayout.putConstraint(SpringLayout.NORTH, numberOfImagesToSearchFor, 0, SpringLayout.NORTH, tagsTextArea); springLayout.putConstraint(SpringLayout.WEST, numberOfImagesToSearchFor, 6, SpringLayout.EAST, descriptionTextArea); springLayout.putConstraint(SpringLayout.EAST, numberOfImagesToSearchFor, -36, SpringLayout.WEST, scroll); frame.getContentPane().add(numberOfImagesToSearchFor); numberOfImagesToSearchFor.setColumns(10); JLabel lblNumberOfImages = new JLabel("Number"); springLayout.putConstraint(SpringLayout.NORTH, lblNumberOfImages, 0, SpringLayout.NORTH, lblTags); springLayout.putConstraint(SpringLayout.WEST, lblNumberOfImages, 31, SpringLayout.EAST, btnAnalyseImage); springLayout.putConstraint(SpringLayout.EAST, lblNumberOfImages, -6, SpringLayout.WEST, scroll); frame.getContentPane().add(lblNumberOfImages); // label to get coordinates for web camera panel // lblNewLabel_1 = new JLabel("New label"); // springLayout.putConstraint(SpringLayout.NORTH, lblNewLabel_1, 0, // SpringLayout.NORTH, btnTurnCameraOn); // springLayout.putConstraint(SpringLayout.WEST, lblNewLabel_1, 98, // SpringLayout.EAST, originalImagesLabel); // springLayout.putConstraint(SpringLayout.SOUTH, lblNewLabel_1, -430, // SpringLayout.SOUTH, lblSafeSearch_1); // springLayout.putConstraint(SpringLayout.EAST, lblNewLabel_1, 0, // SpringLayout.EAST, btnCancel); // frame.getContentPane().add(lblNewLabel_1); btnBrowse.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (fc.showOpenDialog(frame) == JFileChooser.APPROVE_OPTION) { openFilechooser(); } } }); btnTurnCameraOn.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { System.out.println("turn camera on"); turnCameraOn(); btnCancel.setVisible(true); btnTakeAPicture.setVisible(true); } }); btnTakeAPicture.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { btnSave.setVisible(true); imageWebcam = webcam.getImage(); originalImage = imageWebcam; // to mirror the image we create a temporary file, flip it // horizontally and then delete // get user's name to store file in the user directory String user = System.getProperty("user.home"); String fileName = user + "/webCamPhoto.jpg"; File newFile = new File(fileName); try { ImageIO.write(originalImage, "jpg", newFile); } catch (IOException e1) { e1.printStackTrace(); } try { originalImage = (BufferedImage) ImageIO.read(newFile); } catch (IOException e1) { e1.printStackTrace(); } newFile.delete(); originalImage = mirrorImage(originalImage); icon = scaleBufferedImage(originalImage, originalImageLabel); originalImageLabel.setIcon(icon); } }); btnSave.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (fc.showSaveDialog(frame) == JFileChooser.APPROVE_OPTION) { try { file = fc.getSelectedFile(); File output = new File(file.toString()); // check if image already exists if (output.exists()) { int response = JOptionPane.showConfirmDialog(null, // "Do you want to replace the existing file?", // "Confirm", JOptionPane.YES_NO_OPTION, // JOptionPane.QUESTION_MESSAGE); if (response != JOptionPane.YES_OPTION) { return; } } ImageIO.write(toBufferedImage(originalImage), "jpg", output); System.out.println("Your image has been saved in the folder " + file.getPath()); } catch (IOException e1) { e1.printStackTrace(); } } } }); btnCancel.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { btnTakeAPicture.setVisible(false); btnCancel.setVisible(false); btnSave.setVisible(false); webcam.close(); panel.setVisible(false); } }); urlTextField.addKeyListener(new KeyAdapter() { @Override public void keyReleased(KeyEvent e) { if (urlTextField.getText().length() > 0) { String linkNew = urlTextField.getText(); displayImage(linkNew, originalImageLabel); originalImage = imageResponses; } } }); btnAnalyseImage.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { Token computerVisionToken = new Token(); String computerVisionTokenFileName = "APIToken.txt"; try { computerVisionImageToken = computerVisionToken.getApiToken(computerVisionTokenFileName); try { analyse(); } catch (NullPointerException e1) { // if user clicks on "analyze" button without uploading // image or posts a broken link JOptionPane.showMessageDialog(null, "Please choose an image"); e1.printStackTrace(); } } catch (NullPointerException e1) { e1.printStackTrace(); } } }); btnSearchForSimilar.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { listModel.clear(); Token bingImageToken = new Token(); String bingImageTokenFileName = "SearchApiToken.txt"; bingToken = bingImageToken.getApiToken(bingImageTokenFileName); // in case user edited description or tags, update it and // replace new line character, spaces and breaks with %20 text = descriptionTextArea.getText().replace(" ", "%20").replace("\r", "%20").replace("\n", "%20"); String tagsString = tagsTextArea.getText().replace(" ", "%20").replace("\r", "%20").replace("\n", "%20"); String numberOfImages = numberOfImagesToSearchFor.getText(); try { int numberOfImagesTry = Integer.parseInt(numberOfImages); System.out.println(numberOfImagesTry); imageTypeString = imageTypeBox.getSelectedItem().toString(); sizeTypeString = sizeBox.getSelectedItem().toString(); licenseTypeString = licenseBox.getSelectedItem().toString(); safeSearchTypeString = safeSearchBox.getSelectedItem().toString(); searchParameters = tagsString + text; System.out.println("search parameters: " + searchParameters); if (searchParameters.length() != 0) { // add new thread for searching, so that progress bar // and searching could run simultaneously Thread t1 = new Thread(new Runnable() { @Override public void run() { progressBar.setVisible(true); workingUrls = searchToDisplayOnJList(searchParameters, imageTypeString, sizeTypeString, licenseTypeString, safeSearchTypeString, numberOfImages); } }); // start searching in a separate thread t1.start(); } else { JOptionPane.showMessageDialog(null, "Please choose first an image to analyse or insert search parameters"); } } catch (NumberFormatException e1) { JOptionPane.showMessageDialog(null, "Please insert a valid number of images to search for"); e1.printStackTrace(); } } }); list.addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { int i = list.getSelectedIndex(); if (fc.showSaveDialog(frame) == JFileChooser.APPROVE_OPTION) { try { file = fc.getSelectedFile(); File output = new File(file.toString()); // check if file already exists, ask user if they // wish to overwrite it if (output.exists()) { int response = JOptionPane.showConfirmDialog(null, // "Do you want to replace the existing file?", // "Confirm", JOptionPane.YES_NO_OPTION, // JOptionPane.QUESTION_MESSAGE); if (response != JOptionPane.YES_OPTION) { return; } } try { URL fileNameAsUrl = new URL(linksResponse[i]); originalImage = ImageIO.read(fileNameAsUrl); ImageIO.write(toBufferedImage(originalImage), "jpeg", output); System.out.println("image saved, in the folder: " + output.getAbsolutePath()); } catch (MalformedURLException e1) { e1.printStackTrace(); } catch (IOException e1) { e1.printStackTrace(); } } catch (NullPointerException e2) { e2.getMessage(); } } } }); }
From source file:edu.ku.brc.specify.tools.StrLocalizerApp.java
/** * //from w ww . j a va 2s . c om */ private void createUI() { IconManager.setApplicationClass(Specify.class); IconManager.loadIcons(XMLHelper.getConfigDir("icons_datamodel.xml")); //$NON-NLS-1$ IconManager.loadIcons(XMLHelper.getConfigDir("icons_plugins.xml")); //$NON-NLS-1$ IconManager.loadIcons(XMLHelper.getConfigDir("icons_disciplines.xml")); //$NON-NLS-1$ System.setProperty("edu.ku.brc.ui.db.PickListDBAdapterFactory", //$NON-NLS-1$ "edu.ku.brc.specify.tools.StrLocPickListFactory"); // Needed By the Auto Cosmplete UI //$NON-NLS-1$ CellConstraints cc = new CellConstraints(); PanelBuilder pb = new PanelBuilder(new FormLayout("f:p:g,10px,f:p:g", "p,4px,f:p:g,4px,p"), this); pb.addSeparator("Localize", cc.xyw(1, 1, 3)); termList = new JList(new ItemModel(srcFile)); newTermList = new JList(newKeyList); srcLbl = UIHelper.createTextArea(3, 40); srcLbl.setBorder(new LineBorder(srcLbl.getForeground())); textField = UIHelper.createTextField(40); textField.getDocument().addDocumentListener(new DocumentAdaptor() { @Override protected void changed(DocumentEvent e) { hasChanged = true; } }); statusBar = new JStatusBar(); statusBar.setSectionText(1, " "); //$NON-NLS-1$ //$NON-NLS-2$ UIRegistry.setStatusBar(statusBar); srcLbl.setEditable(false); rsController = new ResultSetController(null, false, false, false, "", 1, true); //transBtn = UIHelper.createButton(getResourceString("StrLocalizerApp.Translate")); PanelBuilder pbr = new PanelBuilder( new FormLayout("r:p,2px,f:p:g", "p, 4px, c:p,4px,p,4px,p,4px,p,4px,p,10px,p,2px,f:p:g")); pbr.add(UIHelper.createLabel(getResourceString("StrLocalizerApp.FileLbl")), cc.xy(1, 1)); fileLbl = UIHelper.createLabel(" "); pbr.add(fileLbl, cc.xy(3, 1)); pbr.add(UIHelper.createLabel("English:"), cc.xy(1, 3)); pbr.add(srcLbl, cc.xy(3, 3)); destLbl = UIHelper.createFormLabel(destLanguage.getEnglishName()); pbr.add(destLbl, cc.xy(1, 5)); pbr.add(textField, cc.xy(3, 5)); pbr.add(rsController.getPanel(), cc.xyw(1, 7, 3)); //pbr.add(transBtn, cc.xy(1, 9)); pbr.addSeparator("Searching", cc.xyw(1, 11, 3)); searchBtn = createButton(getResourceString("SEARCH")); searchBtn.setToolTipText(getResourceString("ExpressSearchTT")); searchText = new JAutoCompTextField(15, PickListDBAdapterFactory.getInstance().create("ExpressSearch", true)); searchText.setAskBeforeSave(false); searchBox = new SearchBox(searchText, null, true); searchText.addKeyListener(new KeyAdapter() { @Override public void keyReleased(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_ENTER) { fndKeyHash.clear(); results.clear(); String txt = searchText.getText(); if (!txt.isEmpty()) { doSearch(txt, "key"); doSearch(txt, "src"); doSearch(txt, "dst"); } model.fireChanges(); } } }); pbr.add(searchBox, cc.xyw(1, 13, 3)); model = new SearchResultsModel(); searchResultsTbl = new JTable(model); pbr.add(UIHelper.createScrollPane(searchResultsTbl), cc.xyw(1, 15, 3)); searchResultsTbl.getSelectionModel().addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { //tableRowSelected(); if (results != null && results.size() > 0 && searchResultsTbl.getSelectedRow() > -1) { StrLocaleEntry entry = (StrLocaleEntry) results.get(searchResultsTbl.getSelectedRow()); if (entry != null) { int listIndex = srcFile.getInxForKey(entry.getKey()); termList.setSelectedIndex(listIndex); termList.ensureIndexIsVisible(listIndex); } } } }); PanelBuilder pbl = new PanelBuilder(new FormLayout("f:p:g", "f:p:g,10px,p,4px,f:p:g")); JScrollPane sp = UIHelper.createScrollPane(termList); JScrollPane nsp = UIHelper.createScrollPane(newTermList); pbl.add(sp, cc.xy(1, 1)); pbl.addSeparator("New Items", cc.xy(1, 3)); pbl.add(nsp, cc.xy(1, 5)); pb.add(pbl.getPanel(), cc.xy(1, 3)); pb.add(pbr.getPanel(), cc.xy(3, 3)); pb.add(statusBar, cc.xyw(1, 5, 3)); ResultSetController.setBackStopRS(rsController); pb.setDefaultDialogBorder(); mainPane = pb.getPanel(); termList.addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { listSelected(); } }); newTermList.addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { newListSelected(); } }); transBtn.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { String txt = srcLbl.getText(); String newText = translate(txt); if (StringUtils.isNotEmpty(newText)) { newText = newText.replace("'", "'"); textField.setText(newText); StrLocaleEntry entry = srcFile.getKey(termList.getSelectedIndex()); entry.setDstStr(textField.getText()); } } }); rscListener = new ResultSetControllerListener() { @Override public void newRecordAdded() { } @Override public void indexChanged(int newIndex) { termList.setSelectedIndex(newIndex); } @Override public boolean indexAboutToChange(int oldIndex, int newIndex) { return true; } }; rsController.addListener(rscListener); frame.pack(); }
From source file:edu.ku.brc.specify.plugins.ipadexporter.iPadDBExporterPlugin.java
/** * @return// ww w . ja va 2s .c om */ private Pair<String, String> getExportLoginCreds(final String userName, final boolean wasInError) { loginBtn.setEnabled(false); loadAndPushResourceBundle(RESOURCE_NAME); try { final JTextField userNameTF = createTextField(15); final JPasswordField passwordTF = createPasswordField(); final JLabel statusLbl = createLabel(" "); if (wasInError) { setErrorMsg(statusLbl, "Your username or password was not correct."); } ImageIcon imgIcon = IconManager.getImage("SpecifySmalliPad128x128", IconManager.STD_ICON_SIZE.NonStd); JPanel loginPanel = DatabaseLoginPanel.createLoginPanel("Username", userNameTF, "USRNM_EMAIL_HINT", "Password", passwordTF, statusLbl, imgIcon); if (!iPadDBExporter.IS_TESTING) // ZZZ { while (true) { userNameTF.setText(userName); final CustomDialog dlg = new CustomDialog((Frame) getMostRecentWindow(), getResourceString("iPad Cloud Login"), true, CustomDialog.OKCANCELAPPLY, loginPanel) { @Override protected void applyButtonPressed() { String uName = userNameTF.getText(); if (iPadCloud.isUserNameOK(uName)) { setErrorMsg(statusLbl, getFormattedResStr("USRNM_IS_TAKEN", uName)); } else { super.applyButtonPressed(); } } }; KeyAdapter ka = new KeyAdapter() { @Override public void keyReleased(KeyEvent e) { super.keyReleased(e); boolean isOK = UIHelper.isValidEmailAddress(userNameTF.getText()) && StringUtils.isNotEmpty(new String(passwordTF.getPassword())); dlg.getOkBtn().setEnabled(isOK); dlg.getApplyBtn().setEnabled(isOK); } }; userNameTF.addKeyListener(ka); passwordTF.addKeyListener(ka); dlg.setCloseOnApplyClk(true); dlg.setApplyLabel(getResourceString("NEW_USER")); dlg.setOkLabel(getResourceString("LOGIN")); dlg.createUI(); boolean enableBtns = StringUtils.isNotEmpty(userName); dlg.getOkBtn().setEnabled(enableBtns); dlg.getApplyBtn().setEnabled(enableBtns); centerAndShow(dlg); if (!dlg.isCancelled()) { boolean isOK = true; String uName = userNameTF.getText(); String pwd = new String(passwordTF.getPassword()); if (dlg.getBtnPressed() == CustomDialog.APPLY_BTN) { Institution inst = iPadDBExporter.getCurrentInstitution(); if (!iPadCloud.addNewUser(uName, pwd, inst.getGuid())) { setErrorMsg(statusLbl, kErrorCreatingAcctMsg); isOK = false; } } if (isOK) { return new Pair<String, String>(uName, pwd); } } else { return null; } } } return null;//new Pair<String, String>("testuser@ku.edu", "testuser@ku.edu"); } catch (Exception ex) { ex.printStackTrace(); } finally { popResourceBundle(); loginBtn.setEnabled(true); } return null; }
From source file:md.mclama.com.ModManager.java
/** * Create the frame.//from w w w . j a v a 2s . c o m */ @SuppressWarnings("serial") public ModManager() throws MalformedURLException { setResizable(false); setTitle("McLauncher " + McVersion); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setBounds(100, 100, 700, 400); contentPane = new JPanel(); contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); setContentPane(contentPane); contentPane.setLayout(null); JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.TOP); tabbedPane.setBounds(0, 0, 694, 372); contentPane.add(tabbedPane); profileListMdl = new DefaultListModel<String>(); ModListModel = new DefaultListModel<String>(); listModel = new DefaultListModel<String>(); getCurrentMods(); panelLauncher = new JPanel(); tabbedPane.addTab("Launcher", null, panelLauncher, null); panelLauncher.setLayout(null); JScrollPane scrollPane = new JScrollPane(); scrollPane.setBounds(556, 36, 132, 248); panelLauncher.add(scrollPane); profileList = new JList<String>(profileListMdl); profileList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); scrollPane.setViewportView(profileList); btnNewProfile = new JButton("New"); btnNewProfile.setFont(new Font("SansSerif", Font.PLAIN, 12)); btnNewProfile.setBounds(479, 4, 76, 20); panelLauncher.add(btnNewProfile); btnNewProfile.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { newProfile(txtProfile.getText()); } }); btnNewProfile.setToolTipText("Click to create a new profile."); JButton btnRenameProfile = new JButton("Rename"); btnRenameProfile.setBounds(479, 25, 76, 20); panelLauncher.add(btnRenameProfile); btnRenameProfile.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { renameProfile(); } }); btnRenameProfile.setToolTipText("Click to rename the selected profile"); JButton btnDelProfile = new JButton("Delete"); btnDelProfile.setBounds(479, 50, 76, 20); panelLauncher.add(btnDelProfile); btnDelProfile.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { deleteProfile(); } }); btnDelProfile.setToolTipText("Click to delete the selected profile."); JButton btnLaunch = new JButton("Launch"); btnLaunch.setBounds(605, 319, 89, 23); panelLauncher.add(btnLaunch); btnLaunch.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (selProfile != null) { LaunchFactorioWithSelectedMods(false); //dont ignore } } }); btnLaunch.setToolTipText("Click to launch factorio with the selected mod profile."); lblAvailableMods = new JLabel("Available Mods"); lblAvailableMods.setBounds(4, 155, 144, 14); panelLauncher.add(lblAvailableMods); lblAvailableMods.setFont(new Font("SansSerif", Font.PLAIN, 10)); lblAvailableMods.setText("Available Mods: " + -1); txtGamePath = new JTextField(); txtGamePath.setBounds(4, 5, 211, 23); panelLauncher.add(txtGamePath); txtGamePath.setToolTipText("Select tha path to your game!"); txtGamePath.setFont(new Font("Tahoma", Font.PLAIN, 8)); txtGamePath.setText("Game Path"); txtGamePath.setColumns(10); JButton btnFind = new JButton("find"); btnFind.setBounds(227, 3, 32, 23); panelLauncher.add(btnFind); txtProfile = new JTextField(); txtProfile.setBounds(556, 2, 132, 22); panelLauncher.add(txtProfile); txtProfile.setToolTipText("The name of NEW or RENAME profiles"); txtProfile.setText("Profile1"); txtProfile.setColumns(10); lblModsEnabled = new JLabel("Mods Enabled: -1"); lblModsEnabled.setBounds(335, 155, 95, 16); panelLauncher.add(lblModsEnabled); lblModsEnabled.setFont(new Font("SansSerif", Font.PLAIN, 10)); JScrollPane scrollPane_1 = new JScrollPane(); scrollPane_1.setBounds(0, 167, 211, 165); panelLauncher.add(scrollPane_1); modsList = new JList<String>(listModel); modsList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); modsList.addMouseListener(new MouseAdapter() { @Override public void mouseReleased(MouseEvent e) { String modName = util.getModVersion(modsList.getSelectedValue()); lblModVersion.setText("Mod Version: " + modName); checkDependency(modsList); if (modName.contains(".zip")) { new File(System.getProperty("java.io.tmpdir") + modName.replace(".zip", "")).delete(); } if (System.currentTimeMillis() - lastClickTime <= 300) { //Double click addMod(); } lastClickTime = System.currentTimeMillis(); } }); scrollPane_1.setViewportView(modsList); modsList.setFont(new Font("Tahoma", Font.PLAIN, 9)); JScrollPane scrollPane_2 = new JScrollPane(); scrollPane_2.setBounds(333, 167, 211, 165); panelLauncher.add(scrollPane_2); enabledModsList = new JList<String>(ModListModel); enabledModsList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); enabledModsList.addMouseListener(new MouseAdapter() { @Override public void mouseReleased(MouseEvent e) { lblModVersion.setText("Mod Version: " + util.getModVersion(enabledModsList.getSelectedValue())); checkDependency(enabledModsList); if (System.currentTimeMillis() - lastClickTime <= 300) { //Double click removeMod(); } lastClickTime = System.currentTimeMillis(); } }); enabledModsList.setFont(new Font("SansSerif", Font.PLAIN, 10)); scrollPane_2.setViewportView(enabledModsList); JButton btnEnable = new JButton("Enable"); btnEnable.setBounds(223, 200, 90, 28); panelLauncher.add(btnEnable); btnEnable.setToolTipText("Add mod -->"); JButton btnDisable = new JButton("Disable"); btnDisable.setBounds(223, 240, 90, 28); panelLauncher.add(btnDisable); btnDisable.setToolTipText("Disable mod "); JLabel lblModsAvailable = new JLabel("Mods available"); lblModsAvailable.setBounds(4, 329, 89, 14); panelLauncher.add(lblModsAvailable); lblModsAvailable.setFont(new Font("SansSerif", Font.PLAIN, 10)); JLabel lblEnabledMods = new JLabel("Enabled Mods"); lblEnabledMods.setBounds(337, 329, 89, 16); panelLauncher.add(lblEnabledMods); lblEnabledMods.setFont(new Font("SansSerif", Font.PLAIN, 10)); lblModVersion = new JLabel("Mod Version: (select a mod first)"); lblModVersion.setBounds(4, 117, 183, 14); panelLauncher.add(lblModVersion); lblModVersion.setFont(new Font("SansSerif", Font.PLAIN, 10)); lblRequiredMods = new JLabel("Required Mods: " + reqModsStr); lblRequiredMods.setBounds(6, 143, 538, 14); panelLauncher.add(lblRequiredMods); lblRequiredMods.setHorizontalAlignment(SwingConstants.RIGHT); lblRequiredMods.setFont(new Font("SansSerif", Font.PLAIN, 10)); JButton btnNewButton = new JButton("TEST"); btnNewButton.setVisible(testBtnEnabled); btnNewButton.setEnabled(testBtnEnabled); btnNewButton.setBounds(338, 61, 90, 28); panelLauncher.add(btnNewButton); btnUpdate.setBounds(218, 322, 103, 20); panelLauncher.add(btnUpdate); btnUpdate.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { util.updateLauncher(); } }); btnUpdate.setVisible(false); btnUpdate.setFont(new Font("SansSerif", Font.PLAIN, 9)); lblModRequires = new JLabel("Mod Requires: (Select a mod first)"); lblModRequires.setBounds(4, 127, 317, 16); panelLauncher.add(lblModRequires); btnLaunchIgnore = new JButton("Launch + ignore"); btnLaunchIgnore.setToolTipText("Ignore any errors that McLauncher may not correctly account for."); btnLaunchIgnore.setFont(new Font("SansSerif", Font.PLAIN, 11)); btnLaunchIgnore.setBounds(556, 284, 133, 23); panelLauncher.add(btnLaunchIgnore); JButton btnConsole = new JButton("Console"); btnConsole.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { boolean changeto = !con.isVisible(); con.setVisible(changeto); con.updateConsole(); } }); btnConsole.setBounds(335, 0, 90, 28); panelLauncher.add(btnConsole); JPanel panelDownloadMods = new JPanel(); tabbedPane.addTab("Download Mods", null, panelDownloadMods, null); panelDownloadMods.setLayout(null); scrollPane_3 = new JScrollPane(); scrollPane_3.setBounds(0, 0, 397, 303); panelDownloadMods.add(scrollPane_3); dlModel = new DefaultTableModel(new Object[][] {}, new String[] { "Mod Name", "Author", "Version", "Tags" }) { Class[] columnTypes = new Class[] { String.class, String.class, String.class, Object.class }; public Class getColumnClass(int columnIndex) { return columnTypes[columnIndex]; } boolean[] columnEditables = new boolean[] { false, false, false, false }; public boolean isCellEditable(int row, int column) { return columnEditables[column]; }; }; tSorter = new TableRowSorter<DefaultTableModel>(dlModel); tableDownloads = new JTable(); tableDownloads.setRowSorter(tSorter); tableDownloads.addMouseListener(new MouseAdapter() { @Override public void mouseReleased(MouseEvent e) { trow = tableDownloads.getSelectedRow(); trow = tableDownloads.getRowSorter().convertRowIndexToModel(trow); getDlModData(); canDownloadMod = true; } }); tableDownloads.addKeyListener(new KeyAdapter() { @Override public void keyReleased(KeyEvent e) { trow = tableDownloads.getSelectedRow(); trow = tableDownloads.getRowSorter().convertRowIndexToModel(trow); getDlModData(); canDownloadMod = true; } }); tableDownloads.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION); tableDownloads.setShowVerticalLines(true); tableDownloads.setShowHorizontalLines(true); tableDownloads.setModel(dlModel); tableDownloads.getColumnModel().getColumn(0).setPreferredWidth(218); tableDownloads.getColumnModel().getColumn(1).setPreferredWidth(97); tableDownloads.getColumnModel().getColumn(2).setPreferredWidth(77); scrollPane_3.setViewportView(tableDownloads); btnDownload = new JButton("Download"); btnDownload.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (canDownloadMod && !CurrentlyDownloading) { String dlUrl = getModDownloadUrl(); try { if (dlUrl.equals("") || dlUrl.equals(" ") || dlUrl == null) { con.log("Log", "No download link for mod, got... '" + dlUrl + "'"); } else { CurrentlyDownloading = true; CurrentDownload = new Download(new URL(dlUrl), McLauncher); } } catch (MalformedURLException e1) { con.log("Log", "Failed to download mod... No download URL?"); } } } }); btnDownload.setBounds(307, 308, 90, 28); panelDownloadMods.add(btnDownload); btnGotoMod = new JButton("Mod Page"); btnGotoMod.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { util.openWebpage(modPageUrl); } }); btnGotoMod.setEnabled(false); btnGotoMod.setBounds(134, 308, 90, 28); panelDownloadMods.add(btnGotoMod); pBarDownloadMod = new JProgressBar(); pBarDownloadMod.setBounds(538, 308, 150, 10); panelDownloadMods.add(pBarDownloadMod); pBarExtractMod = new JProgressBar(); pBarExtractMod.setBounds(538, 314, 150, 10); panelDownloadMods.add(pBarExtractMod); lblDownloadModInfo = new JLabel("Download progress"); lblDownloadModInfo.setBounds(489, 326, 199, 16); panelDownloadMods.add(lblDownloadModInfo); lblDownloadModInfo.setHorizontalAlignment(SwingConstants.TRAILING); panelModImg = new JPanel(); panelModImg.setBounds(566, 0, 128, 128); panelDownloadMods.add(panelModImg); txtFilterText = new JTextField(); txtFilterText.addFocusListener(new FocusAdapter() { @Override public void focusGained(FocusEvent e) { if (txtFilterText.getText().equals("Filter Text")) { txtFilterText.setText(""); newFilter(); } } }); txtFilterText.addKeyListener(new KeyAdapter() { @Override public void keyReleased(KeyEvent e) { if (!txtFilterText.getText().equals("Filter Text")) { newFilter(); } } }); txtFilterText.setText("Filter Text"); txtFilterText.setBounds(0, 308, 122, 28); panelDownloadMods.add(txtFilterText); txtFilterText.setColumns(10); comboBox = new JComboBox(); comboBox.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { newFilter(); } }); comboBox.setModel(new DefaultComboBoxModel(new String[] { "No tag filter", "Vanilla", "Machine", "Mechanic", "New Ore", "Module", "Big Mod", "Power", "GUI", "Map-Gen", "Must-Have", "Equipment" })); comboBox.setBounds(403, 44, 150, 26); panelDownloadMods.add(comboBox); lblModDlCounter = new JLabel("Mod database: "); lblModDlCounter.setFont(new Font("SansSerif", Font.PLAIN, 10)); lblModDlCounter.setBounds(403, 5, 162, 16); panelDownloadMods.add(lblModDlCounter); txtrDMModDescription = new JTextArea(); txtrDMModDescription.setBackground(Color.LIGHT_GRAY); txtrDMModDescription.setBorder(new LineBorder(new Color(0, 0, 0))); txtrDMModDescription.setFocusable(false); txtrDMModDescription.setEditable(false); txtrDMModDescription.setLineWrap(true); txtrDMModDescription.setWrapStyleWord(true); txtrDMModDescription.setText("Mod Description: "); txtrDMModDescription.setBounds(403, 132, 285, 75); panelDownloadMods.add(txtrDMModDescription); lblDMModTags = new JTextArea(); lblDMModTags.setFocusable(false); lblDMModTags.setEditable(false); lblDMModTags.setBorder(new LineBorder(new Color(0, 0, 0))); lblDMModTags.setWrapStyleWord(true); lblDMModTags.setLineWrap(true); lblDMModTags.setBackground(Color.LIGHT_GRAY); lblDMModTags.setText("Mod Tags: "); lblDMModTags.setBounds(403, 71, 160, 60); panelDownloadMods.add(lblDMModTags); lblDMRequiredMods = new JTextArea(); lblDMRequiredMods.setFocusable(false); lblDMRequiredMods.setEditable(false); lblDMRequiredMods.setText("Required Mods: "); lblDMRequiredMods.setWrapStyleWord(true); lblDMRequiredMods.setLineWrap(true); lblDMRequiredMods.setBorder(new LineBorder(new Color(0, 0, 0))); lblDMRequiredMods.setBackground(Color.LIGHT_GRAY); lblDMRequiredMods.setBounds(403, 208, 285, 57); panelDownloadMods.add(lblDMRequiredMods); lblDLModLicense = new JLabel(""); lblDLModLicense.setHorizontalAlignment(SwingConstants.RIGHT); lblDLModLicense.setBounds(403, 294, 285, 16); panelDownloadMods.add(lblDLModLicense); lblWipmod = new JLabel(""); lblWipmod.setBounds(395, 314, 64, 16); panelDownloadMods.add(lblWipmod); JButton btnCancel = new JButton("Cancel"); btnCancel.setToolTipText("Stop downloading"); btnCancel.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { CurrentDownload.cancel(); } }); btnCancel.setBounds(230, 308, 72, 28); panelDownloadMods.add(btnCancel); panelOptions = new JPanel(); tabbedPane.addTab("Options", null, panelOptions, null); panelOptions.setLayout(null); scrollPane_4.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); scrollPane_4.setBounds(0, 0, 694, 342); panelOptions.add(scrollPane_4); panel = new JPanel(); scrollPane_4.setViewportView(panel); panel.setLayout(null); lblCloseMclauncherAfter = new JLabel("Close McLauncher after launching Factorio?"); lblCloseMclauncherAfter.setBounds(6, 6, 274, 16); panel.add(lblCloseMclauncherAfter); lblCloseMclauncherAfter_1 = new JLabel("Close McLauncher after updating?"); lblCloseMclauncherAfter_1.setBounds(6, 34, 274, 16); panel.add(lblCloseMclauncherAfter_1); lblSortNewestDownloadable = new JLabel("Sort newest downloadable mods first?"); lblSortNewestDownloadable.setBounds(6, 62, 274, 16); panel.add(lblSortNewestDownloadable); tglbtnNewModsFirst = new JToggleButton("Toggle"); tglbtnNewModsFirst.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { lblNeedrestart.setText("McLauncher needs to restart for that to work"); writeData(); } }); tglbtnNewModsFirst.setSelected(true); tglbtnNewModsFirst.setBounds(281, 56, 66, 28); panel.add(tglbtnNewModsFirst); tglbtnCloseAfterUpdate = new JToggleButton("Toggle"); tglbtnCloseAfterUpdate.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { writeData(); } }); tglbtnCloseAfterUpdate.setBounds(281, 28, 66, 28); panel.add(tglbtnCloseAfterUpdate); tglbtnCloseAfterLaunch = new JToggleButton("Toggle"); tglbtnCloseAfterLaunch.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { writeData(); } }); tglbtnCloseAfterLaunch.setBounds(281, 0, 66, 28); panel.add(tglbtnCloseAfterLaunch); tglbtnDisplayon = new JToggleButton("On"); tglbtnDisplayon.setFont(new Font("SansSerif", Font.PLAIN, 10)); tglbtnDisplayon.setSelected(true); tglbtnDisplayon.setBounds(588, 308, 44, 28); panel.add(tglbtnDisplayon); tglbtnDisplayoff = new JToggleButton("Off"); tglbtnDisplayoff.setFont(new Font("SansSerif", Font.PLAIN, 10)); tglbtnDisplayoff.setBounds(644, 308, 44, 28); panel.add(tglbtnDisplayoff); lblInfo = new JLabel("What enabled and disabled look like"); lblInfo.setFont(new Font("SansSerif", Font.PLAIN, 10)); lblInfo.setHorizontalAlignment(SwingConstants.TRAILING); lblInfo.setBounds(359, 314, 231, 16); panel.add(lblInfo); JSeparator separator = new JSeparator(); separator.setBounds(6, 55, 676, 24); panel.add(separator); JSeparator separator_1 = new JSeparator(); separator_1.setBounds(6, 27, 676, 18); panel.add(separator_1); JSeparator separator_2 = new JSeparator(); separator_2.setBounds(6, 84, 676, 24); panel.add(separator_2); JSeparator separator_3 = new JSeparator(); separator_3.setOrientation(SwingConstants.VERTICAL); separator_3.setBounds(346, 0, 16, 336); panel.add(separator_3); lblNeedrestart = new JLabel(""); lblNeedrestart.setBounds(6, 314, 341, 16); panel.add(lblNeedrestart); tglbtnSendAnonData = new JToggleButton("Toggle"); tglbtnSendAnonData.setToolTipText("Information regarding the activity of McLauncher."); tglbtnSendAnonData.setSelected(true); //set enabled by default. tglbtnSendAnonData.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { writeData(); } }); tglbtnSendAnonData.setBounds(622, 0, 66, 28); panel.add(tglbtnSendAnonData); lblSendAnonymousUse = new JLabel("Send anonymous use data?"); lblSendAnonymousUse.setBounds(359, 6, 251, 16); panel.add(lblSendAnonymousUse); lblDeleteOldMod = new JLabel("Delete old mod before updating?"); lblDeleteOldMod.setBounds(359, 34, 251, 16); panel.add(lblDeleteOldMod); tglbtnDeleteBeforeUpdate = new JToggleButton("Toggle"); tglbtnDeleteBeforeUpdate.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { writeData(); } }); tglbtnDeleteBeforeUpdate.setBounds(622, 28, 66, 28); panel.add(tglbtnDeleteBeforeUpdate); tglbtnAlertOnModUpdateAvailable = new JToggleButton("Toggle"); tglbtnAlertOnModUpdateAvailable.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { writeData(); } }); tglbtnAlertOnModUpdateAvailable.setSelected(true); tglbtnAlertOnModUpdateAvailable.setBounds(281, 86, 66, 28); panel.add(tglbtnAlertOnModUpdateAvailable); separator_4 = new JSeparator(); separator_4.setBounds(0, 112, 676, 24); panel.add(separator_4); JLabel lblAlertModHas = new JLabel("Alert mod has update on launch?"); lblAlertModHas.setBounds(6, 92, 231, 16); panel.add(lblAlertModHas); panelChangelog = new JPanel(); tabbedPane.addTab("Changelog", null, panelChangelog, null); panelChangelog.setLayout(new BoxLayout(panelChangelog, BoxLayout.X_AXIS)); scrollPane_6 = new JScrollPane(); panelChangelog.add(scrollPane_6); textChangelog = new JTextArea(); scrollPane_6.setViewportView(textChangelog); textChangelog.setEditable(false); textChangelog.setText( "v0.4.6\r\n\r\n+Fix problem where config file would not save in the correct location. (Thanks Arano-kai)\r\n+McLauncher will now save when you select a path, or profile. (Thanks Arano-kai)\r\n+Fixed an issue where McLauncher could not get the version from a .zip mod. (Thanks Arano-kai)\r\n+Added a Cancel button to stop downloading the current mod. (Suggested by Arano-kai)\r\n\r\n\r\n\r\nv0.4.5\r\n\r\n+McLauncher should now correctly warn you on failed write/read access.\r\n+McLauncher should now work when a user has both zip and installer versions of factorio. (Thanks Jeroon)\r\n+Attempt to fix an error with dependency and .zip files, With versions. (Thanks Arano-kai)\r\n+Fix only allow single selection of mods. (Thanks Arano-kai)\r\n+Fix for the Launch+Ignore button problem on linux being cut off. (Thanks Arano-kai)\r\n+Display download progress.\r\n+Fixed an error that was thrown when clicking on some mods that had a single dependency mod.\r\n+Double clicking on a mod will now enable or disable the mod. (Thanks Arano-kai)"); btnLaunchIgnore.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (selProfile != null) { LaunchFactorioWithSelectedMods(true); //ignore errors, launch. } } }); btnLaunchIgnore.setVisible(false); //This is my test button. I use this to test things then implement them into the swing. btnNewButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { testButtonCode(e); } }); //Disable mods button. (from profile) btnDisable.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { removeMod(); } }); //Enable mods button. (to profile) btnEnable.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { addMod(); } }); //Game path button btnFind.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { findPath(); } }); //mouseClick event lister for when you click on a new profile profileList.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { selectedProfile(); } }); readData(); //Load settings init(); //some extra init getMods(); //Get the mods the user has installed }