List of usage examples for javax.swing DefaultComboBoxModel DefaultComboBoxModel
public DefaultComboBoxModel(Vector<E> v)
From source file:jeplus.gui.JPanel_EPlusProjectFiles.java
/** * Creates new form JPanel_EPlusProjectFiles with parameters *///from w w w . j av a2 s. co m public JPanel_EPlusProjectFiles(JEPlusFrameMain frame, JEPlusProject project) { initComponents(); MainGUI = frame; Project = project; this.txtGroupID.setText(Project.getProjectID()); this.txtGroupNotes.setText(Project.getProjectNotes()); txtIdfDir.setText(Project.getIDFDir()); if (Project.getIDFTemplate() != null) { cboTemplateFile.setModel(new DefaultComboBoxModel(Project.getIDFTemplate().split("\\s*;\\s*"))); } else { cboTemplateFile.setModel(new DefaultComboBoxModel(new String[] { "Select files..." })); } txtWthrDir.setText(Project.getWeatherDir()); if (Project.getWeatherFile() != null) { cboWeatherFile.setModel(new DefaultComboBoxModel(Project.getWeatherFile().split("\\s*;\\s*"))); } else { cboWeatherFile.setModel(new DefaultComboBoxModel(new String[] { "Select files..." })); } chkReadVar.setSelected(Project.isUseReadVars()); txtRviDir.setText(Project.getRVIDir()); if (Project.getRVIFile() != null) { cboRviFile.setModel(new DefaultComboBoxModel(new String[] { Project.getRVIFile() })); } else { cboRviFile.setModel(new DefaultComboBoxModel(new String[] { "Select a file..." })); } this.chkReadVarActionPerformed(null); // Set listeners to text fields DL = new DocumentListener() { Document DocProjID = txtGroupID.getDocument(); Document DocProjNotes = txtGroupNotes.getDocument(); Document DocIdfDir = txtIdfDir.getDocument(); Document DocWthrDir = txtWthrDir.getDocument(); Document DocRviDir = txtRviDir.getDocument(); @Override public void insertUpdate(DocumentEvent e) { Document src = e.getDocument(); if (src == DocProjID) { Project.setProjectID(txtGroupID.getText()); } else if (src == DocProjNotes) { Project.setProjectNotes(txtGroupNotes.getText()); } else if (src == DocIdfDir) { Project.setIDFDir(txtIdfDir.getText()); } else if (src == DocWthrDir) { Project.setWeatherDir(txtWthrDir.getText()); } else if (src == DocRviDir) { Project.setRVIDir(txtRviDir.getText()); } } @Override public void removeUpdate(DocumentEvent e) { insertUpdate(e); } @Override public void changedUpdate(DocumentEvent e) { // not applicable } }; txtGroupID.getDocument().addDocumentListener(DL); txtGroupNotes.getDocument().addDocumentListener(DL); txtIdfDir.getDocument().addDocumentListener(DL); txtWthrDir.getDocument().addDocumentListener(DL); txtRviDir.getDocument().addDocumentListener(DL); }
From source file:ch.epfl.lis.gnwgui.Simulation.java
/** * Constructor//from w w w.j ava2s . co m */ public Simulation(Frame aFrame, NetworkElement item) { super(aFrame); item_ = item; GnwSettings settings = GnwSettings.getInstance(); // Model model_.setModel(new DefaultComboBoxModel( new String[] { "Deterministic (ODEs)", "Stochastic (SDEs)", "Run both (ODEs and SDEs)" })); if (settings.getSimulateODE() && !settings.getSimulateSDE()) model_.setSelectedIndex(0); else if (!settings.getSimulateODE() && settings.getSimulateSDE()) model_.setSelectedIndex(1); else if (settings.getSimulateODE() && settings.getSimulateSDE()) model_.setSelectedIndex(2); // Experiments wtSS_.setSelected(true); wtSS_.setEnabled(false); knockoutSS_.setSelected(settings.generateSsKnockouts()); knockdownSS_.setSelected(settings.generateSsKnockdowns()); multifactorialSS_.setSelected(settings.generateSsMultifactorial()); dualKnockoutSS_.setSelected(settings.generateSsDualKnockouts()); knockoutTS_.setSelected(settings.generateTsKnockouts()); knockdownTS_.setSelected(settings.generateTsKnockdowns()); multifactorialTS_.setSelected(settings.generateTsMultifactorial()); dualKnockoutTS_.setSelected(settings.generateTsDualKnockouts()); timeSeriesAsDream4_.setSelected(settings.generateTsDREAM4TimeSeries()); // Set model of "number of time series" spinner SpinnerNumberModel model = new SpinnerNumberModel(); model.setMinimum(1); model.setMaximum(10000); model.setStepSize(1); model.setValue(settings.getNumTimeSeries()); numTimeSeries_.setModel(model); // Set model of "duration" spinner model = new SpinnerNumberModel(); model.setMinimum(1); model.setMaximum(100000); model.setStepSize(10); model.setValue((int) settings.getMaxtTimeSeries()); tmax_.setModel(model); // Set model of "number of points per time series" spinner model = new SpinnerNumberModel(); model.setMinimum(3); model.setMaximum(100000); model.setStepSize(10); double dt = settings.getDt(); double maxt = settings.getMaxtTimeSeries(); int numMeasuredPoints = (int) Math.round(maxt / dt) + 1; if (dt * (numMeasuredPoints - 1) != maxt) throw new RuntimeException( "Duration of time series (GnwSettings.maxtTimeSeries_) must be a multiple of the time step (GnwSettings.dt_)"); model.setValue(numMeasuredPoints); numPointsPerTimeSeries_.setModel(model); perturbationNew_.setSelected(!settings.getLoadPerturbations()); perturbationLoad_.setSelected(settings.getLoadPerturbations()); // Noise // Diffusion multiplier (SDE only) model = new SpinnerNumberModel(); model.setMinimum(0.0); model.setMaximum(10.); model.setStepSize(0.01); model.setValue(settings.getNoiseCoefficientSDE()); sdeDiffusionCoeff_.setModel(model); noNoise_.setSelected(!settings.getAddMicroarrayNoise() && !settings.getAddNormalNoise() && !settings.getAddLognormalNoise()); useMicroarrayNoise_.setSelected(settings.getAddMicroarrayNoise()); useLogNormalNoise_.setSelected(settings.getAddNormalNoise() || settings.getAddLognormalNoise()); addGaussianNoise_.setSelected(settings.getAddNormalNoise()); addLogNormalNoise_.setSelected(settings.getAddLognormalNoise()); // Set model of "Gaussian noise std" spinner model = new SpinnerNumberModel(); model.setMinimum(0.000001); model.setMaximum(10.); model.setStepSize(0.01); model.setValue(settings.getNormalStdev()); gaussianNoise_.setModel(model); // Set model of "log-normal noise std" spinner model = new SpinnerNumberModel(); model.setMinimum(0.000001); model.setMaximum(10.); model.setStepSize(0.01); model.setValue(settings.getLognormalStdev()); logNormalNoise_.setModel(model); normalizeNoise_.setSelected(settings.getNormalizeAfterAddingNoise()); // Set the text field with the user path userPath_.setText(GnwSettings.getInstance().getOutputDirectory()); setModelAction(); setExperimentAction(); setNoiseAction(); String title1, title2; title1 = title2 = ""; if (item_ instanceof StructureElement) { ImodNetwork network = ((StructureElement) item_).getNetwork(); title1 = item_.getLabel(); title2 = network.getSize() + " nodes, " + network.getNumEdges() + " edges"; } else if (item_ instanceof DynamicalModelElement) { GeneNetwork geneNetwork = ((DynamicalModelElement) item_).getGeneNetwork(); title1 = item_.getLabel(); title2 = geneNetwork.getSize() + " genes, " + geneNetwork.getNumEdges() + " interactions"; } setHeaderInfo(title1 + " (" + title2 + ")"); // Set tool tips for all elements of the window addTooltips(); /** * ACTIONS */ model_.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { setModelAction(); } }); dream4Settings_.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { setDream4Settings(); } }); browse_.addActionListener(new ActionListener() { public void actionPerformed(final ActionEvent arg0) { IODialog dialog = new IODialog(new Frame(""), "Select Target Folder", GnwSettings.getInstance().getOutputDirectory(), IODialog.LOAD); dialog.selectOnlyFolder(true); dialog.display(); if (dialog.getSelection() != null) userPath_.setText(dialog.getSelection()); } }); runButton_.addActionListener(new ActionListener() { public void actionPerformed(final ActionEvent arg0) { enterAction(); } }); cancelButton_.addActionListener(new ActionListener() { public void actionPerformed(final ActionEvent arg0) { GnwSettings.getInstance().stopBenchmarkGeneration(true); escapeAction(); } }); knockoutSS_.addActionListener(new ActionListener() { public void actionPerformed(final ActionEvent arg0) { setExperimentAction(); } }); knockdownSS_.addActionListener(new ActionListener() { public void actionPerformed(final ActionEvent arg0) { setExperimentAction(); } }); multifactorialSS_.addActionListener(new ActionListener() { public void actionPerformed(final ActionEvent arg0) { setExperimentAction(); } }); dualKnockoutSS_.addActionListener(new ActionListener() { public void actionPerformed(final ActionEvent arg0) { setExperimentAction(); } }); knockoutTS_.addActionListener(new ActionListener() { public void actionPerformed(final ActionEvent arg0) { setExperimentAction(); } }); knockdownTS_.addActionListener(new ActionListener() { public void actionPerformed(final ActionEvent arg0) { setExperimentAction(); } }); multifactorialTS_.addActionListener(new ActionListener() { public void actionPerformed(final ActionEvent arg0) { setExperimentAction(); } }); dualKnockoutTS_.addActionListener(new ActionListener() { public void actionPerformed(final ActionEvent arg0) { setExperimentAction(); } }); timeSeriesAsDream4_.addActionListener(new ActionListener() { public void actionPerformed(final ActionEvent arg0) { setExperimentAction(); } }); noNoise_.addActionListener(new ActionListener() { public void actionPerformed(final ActionEvent arg0) { setNoiseAction(); } }); useMicroarrayNoise_.addActionListener(new ActionListener() { public void actionPerformed(final ActionEvent arg0) { setNoiseAction(); } }); useLogNormalNoise_.addActionListener(new ActionListener() { public void actionPerformed(final ActionEvent arg0) { setNoiseAction(); } }); addGaussianNoise_.addActionListener(new ActionListener() { public void actionPerformed(final ActionEvent arg0) { setNoiseAction(); } }); addLogNormalNoise_.addActionListener(new ActionListener() { public void actionPerformed(final ActionEvent arg0) { setNoiseAction(); } }); }
From source file:edu.ku.brc.specify.config.ResImpExpMetaInfoDlg.java
@Override public void createUI() { super.createUI(); //HelpMgr.registerComponent(helpBtn, "ResImpExpMetaInfoDlg"); DefaultComboBoxModel mimeModel = new DefaultComboBoxModel( new String[] { "XML", "Label", "Report", "Subreport" }); // I18N DefaultComboBoxModel typeModel = new DefaultComboBoxModel( new String[] { "Report", "Invoice", "WorkBench", "CollectionObject" }); // I18N DefaultComboBoxModel tblModel = new DefaultComboBoxModel( DBTableIdMgr.getInstance().getTablesForUserDisplay()); mimeTypeCBX = createComboBox(mimeModel); nameTxt = createTextField();/*from w ww . j a v a2 s . co m*/ descTxt = createTextField(); CellConstraints cc = new CellConstraints(); // Meta Info tableIdCBX = createComboBox(tblModel); reqsRecSetChk = createCheckBox("Is Record Set Required?"); rptTypeCBX = createComboBox(typeModel); subReportsTxt = createTextField(); actionsTxt = createTextField(); PanelBuilder pb = new PanelBuilder( new FormLayout("p,2px,p,f:p:g", "p,4px,p,4px,p,4px,p,4px,p,4px,p,4px,p,4px,p,4px")); //$NON-NLS-1$ //$NON-NLS-2$ int y = 1; JLabel lbl = createI18NFormLabel("Mime Type"); // I18N pb.add(lbl, cc.xy(1, y)); pb.add(mimeTypeCBX, cc.xy(3, y)); y += 2; lbl = createI18NFormLabel("Name"); // I18N pb.add(lbl, cc.xy(1, y)); pb.add(nameTxt, cc.xy(3, y)); y += 2; lbl = createI18NFormLabel("Description"); // I18N pb.add(lbl, cc.xy(1, y)); pb.add(descTxt, cc.xyw(3, y, 2)); y += 2; lbl = createI18NFormLabel("Table"); // I18N labels.add(lbl); pb.add(lbl, cc.xy(1, y)); pb.add(tableIdCBX, cc.xy(3, y)); y += 2; pb.add(reqsRecSetChk, cc.xy(3, y)); y += 2; lbl = createI18NFormLabel("Report Type"); // I18N labels.add(lbl); pb.add(lbl, cc.xy(1, y)); pb.add(rptTypeCBX, cc.xy(3, y)); y += 2; lbl = createI18NFormLabel("Sub-Reports"); // I18N labels.add(lbl); pb.add(lbl, cc.xy(1, y)); pb.add(subReportsTxt, cc.xyw(3, y, 2)); y += 2; lbl = createI18NFormLabel("Action"); // I18N labels.add(lbl); pb.add(lbl, cc.xy(1, y)); pb.add(actionsTxt, cc.xyw(3, y, 2)); y += 2; pb.setDefaultDialogBorder(); nameTxt.setText(FilenameUtils.getBaseName(fileName)); contentPanel = pb.getPanel(); mainPanel.add(contentPanel, BorderLayout.CENTER); pack(); updateUI(); mimeTypeCBX.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { updateUI(); } }); }
From source file:DatabaseBrowser.java
protected void populateCatalogBox() { try {//from w ww .j ava2s. co m DatabaseMetaData dmd = connection.getMetaData(); ResultSet rset = dmd.getCatalogs(); Vector values = new Vector(); while (rset.next()) { values.addElement(rset.getString(1)); } rset.close(); catalogBox.setModel(new DefaultComboBoxModel(values)); catalogBox.setSelectedItem(connection.getCatalog()); catalogBox.setEnabled(values.size() > 0); } catch (Exception e) { catalogBox.setEnabled(false); } }
From source file:com.floreantpos.config.ui.AddPrinterDialog.java
@Override public void initUI() { setLayout(new BorderLayout(5, 5)); JPanel centerPanel = new JPanel(); centerPanel.setLayout(new MigLayout("", "[][grow][]", "[][][][][grow]")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ titlePanel = new TitlePanel(); titlePanel.setTitle("Printer Type:");//$NON-NLS-1$ add(titlePanel, BorderLayout.NORTH); JLabel lblName = new JLabel("Virtual Printer Name : "); //$NON-NLS-1$ centerPanel.add(lblName, "cell 0 0,alignx trailing"); //$NON-NLS-1$ tfName = new FixedLengthTextField(20); cbVirtualPrinter = new JComboBox(); List<VirtualPrinter> virtualPrinters = VirtualPrinterDAO.getInstance().findAll(); cbVirtualPrinter/*from ww w .j a v a2 s. c om*/ .setModel(new DefaultComboBoxModel<VirtualPrinter>(virtualPrinters.toArray(new VirtualPrinter[0]))); //centerPanel.add(cbVirtualPrinter, "cell 1 0,growx"); //$NON-NLS-1$ centerPanel.add(tfName, "cell 1 0,growx"); //$NON-NLS-1$ JButton btnNew = new JButton(Messages.getString("AddPrinterDialog.7")); //$NON-NLS-1$ btnNew.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { doAddNewVirtualPrinter(); } }); //centerPanel.add(btnNew, "cell 2 0"); //$NON-NLS-1$ JLabel lblDevice = new JLabel(Messages.getString("AddPrinterDialog.9")); //$NON-NLS-1$ centerPanel.add(lblDevice, "cell 0 1,alignx trailing"); //$NON-NLS-1$ cbDevice = new JComboBox(); List printerServices = new ArrayList<>(); printerServices.add(DO_NOT_PRINT); PrintService[] lookupPrintServices = PrintServiceLookup.lookupPrintServices(null, null); //cbDevice.setModel(new DefaultComboBoxModel(PrintServiceLookup.lookupPrintServices(null, null))); cbDevice.addItem(null); for (int i = 0; i < lookupPrintServices.length; i++) { printerServices.add(lookupPrintServices[i]); } cbDevice.setModel(new ComboBoxModel(printerServices)); cbDevice.setRenderer(new PrintServiceComboRenderer()); centerPanel.add(cbDevice, "cell 1 1,growx"); //$NON-NLS-1$ chckbxDefault = new JCheckBox(Messages.getString("AddPrinterDialog.12")); //$NON-NLS-1$ centerPanel.add(chckbxDefault, "cell 1 2"); //$NON-NLS-1$ JSeparator separator = new JSeparator(); centerPanel.add(separator, "cell 0 3 3 1,growx,gapy 50px"); //$NON-NLS-1$ add(centerPanel, BorderLayout.CENTER); JPanel panel = new JPanel(); JButton btnOk = new JButton(Messages.getString("AddPrinterDialog.16")); //$NON-NLS-1$ btnOk.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { doAddPrinter(); } }); panel.add(btnOk); JButton btnCancel = new JButton(Messages.getString("AddPrinterDialog.17")); //$NON-NLS-1$ btnCancel.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { setCanceled(true); dispose(); } }); panel.add(btnCancel); add(panel, BorderLayout.SOUTH); //$NON-NLS-1$ }
From source file:com.mirth.connect.connectors.file.FileReader.java
public FileReader() { this.parent = PlatformUI.MIRTH_FRAME; setBackground(UIConstants.BACKGROUND_COLOR); setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1)); setLayout(new MigLayout("novisualpadding, hidemode 3, insets 0")); initComponents();// w w w .jav a 2 s .c o m initLayout(); afterProcessingActionComboBox.setModel( new DefaultComboBoxModel(new FileAction[] { FileAction.NONE, FileAction.MOVE, FileAction.DELETE })); errorReadingActionComboBox.setModel( new DefaultComboBoxModel(new FileAction[] { FileAction.NONE, FileAction.MOVE, FileAction.DELETE })); errorResponseActionComboBox.setModel(new DefaultComboBoxModel( new FileAction[] { FileAction.AFTER_PROCESSING, FileAction.MOVE, FileAction.DELETE })); fileAgeField.setDocument(new MirthFieldConstraints(0, false, false, true)); fileSizeMinimumField.setDocument(new MirthFieldConstraints(0, false, false, true)); fileSizeMaximumField.setDocument(new MirthFieldConstraints(0, false, false, true)); parent.setupCharsetEncodingForConnector(charsetEncodingComboBox); }
From source file:com.actian.services.knime.core.operators.DeriveGroupNodeDialogPane.java
private void initComponents() { this.expression = new JTextArea(10, 20); expression.setWrapStyleWord(true);//from w w w. ja v a2s . c o m expression.setFont(new Font("Monospaced", Font.PLAIN, 11)); this.expressionPanel = new JScrollPane(expression); this.expressionPanel.setBorder(BorderFactory.createTitledBorder("Group Expressions")); functionPanel = new JPanel(); functionPanel.setLayout(new GridLayout(0, 1, 0, 0)); functionPanel.setBorder(BorderFactory.createTitledBorder("Available Aggregate Functions")); fcomboBox = new JComboBox(); fcomboBox.setMaximumRowCount(10); fcomboBox.setModel(new DefaultComboBoxModel(new String[] { "Function - Description" })); fcomboBox.setFont(new Font("Monospaced", Font.PLAIN, 10)); functionPanel.add(fcomboBox); GroupLayout groupLayout = new GroupLayout(this); groupLayout.setHorizontalGroup(groupLayout.createParallelGroup(Alignment.TRAILING).addGroup(groupLayout .createSequentialGroup() .addGroup(groupLayout.createParallelGroup(Alignment.TRAILING) .addGroup(Alignment.LEADING, groupLayout.createSequentialGroup().addContainerGap().addComponent(columnSelect, GroupLayout.DEFAULT_SIZE, 433, Short.MAX_VALUE)) .addGroup(Alignment.LEADING, groupLayout.createSequentialGroup().addGap(7).addComponent(expressionPanel, GroupLayout.DEFAULT_SIZE, 436, Short.MAX_VALUE)) .addGroup(Alignment.LEADING, groupLayout.createSequentialGroup().addContainerGap() .addComponent(functionPanel, GroupLayout.DEFAULT_SIZE, 433, Short.MAX_VALUE))) .addGap(7))); groupLayout.setVerticalGroup(groupLayout.createParallelGroup(Alignment.LEADING) .addGroup(groupLayout.createSequentialGroup().addGap(5) .addComponent(expressionPanel, GroupLayout.DEFAULT_SIZE, 203, Short.MAX_VALUE) .addPreferredGap(ComponentPlacement.RELATED) .addComponent(functionPanel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) .addPreferredGap(ComponentPlacement.RELATED) .addComponent(columnSelect, GroupLayout.PREFERRED_SIZE, 248, GroupLayout.PREFERRED_SIZE) .addContainerGap())); setLayout(groupLayout); }
From source file:edu.ku.brc.af.ui.db.JEditComboBox.java
/** * An initializer so a PickListAdaptor can be set after the control is created, and automatically makes it editable * @param dbAdapterArg the PickListAdaptor * @param makeEditable indicates whether it is editable */// ww w. ja va2 s . com public void init(final PickListDBAdapterIFace dbAdapterArg, final boolean makeEditable) { setModel(new DefaultComboBoxModel(dbAdapterArg.getList())); this.dbAdapter = dbAdapterArg; init(makeEditable); }
From source file:de.erdesignerng.visual.editor.openxavaexport.ConvertPropertyAdapter.java
@Override public void model2view(Object aModel, String aPropertyName) { OpenXavaOptions theOptions = (OpenXavaOptions) aModel; String theCurrentTypeName = helper.getText(ERDesignerBundle.CURRENTDATATYPE); String theTargetTypeName = helper.getText(ERDesignerBundle.TARGETDATATYPE); String theStereoTypeName = helper.getText(ERDesignerBundle.STEREOTYPE); String[] theTargetTypes = new String[theOptions.getTypeMapping().keySet().size()]; String[] theStereoTypes = new String[theOptions.getTypeMapping().keySet().size()]; List<DataType> theCurrentTypes = new ArrayList<>(); theCurrentTypes.addAll(theOptions.getTypeMapping().keySet()); Collections.sort(theCurrentTypes, new BeanComparator("name")); int theRow = 0; for (DataType theType : theCurrentTypes) { OpenXavaTypeMap theMap = theOptions.getTypeMapping().get(theType); theTargetTypes[theRow] = theMap.getJavaType(); theStereoTypes[theRow] = theMap.getStereoType(); theRow++;//from www .j av a2s . c om } DefaultTable theTable = (DefaultTable) getComponent()[0]; OpenXavaExportTableModel theModel = new OpenXavaExportTableModel(theCurrentTypeName, theTargetTypeName, theStereoTypeName, theCurrentTypes, theTargetTypes, theStereoTypes); theTable.setModel(theModel); theTable.getColumnModel().getColumn(0).setCellRenderer(ModelItemDefaultCellRenderer.getInstance()); theTable.getColumnModel().getColumn(1).setCellRenderer(ModelItemDefaultCellRenderer.getInstance()); theTable.getColumnModel().getColumn(2).setCellRenderer(ModelItemDefaultCellRenderer.getInstance()); DefaultComboBox theTargetTypesEditor = new DefaultComboBox(); theTargetTypesEditor.setBorder(BorderFactory.createEmptyBorder()); theTargetTypesEditor.setModel(new DefaultComboBoxModel(OpenXavaOptions.SUPPORTED_STEREOTYPES)); theTable.getColumnModel().getColumn(2).setCellEditor(new DefaultCellEditor(theTargetTypesEditor)); theTable.setRowHeight((int) theTargetTypesEditor.getPreferredSize().getHeight()); }
From source file:utybo.easypastebin.windows.MainWindow.java
/** * Creates the window/* ww w. j a va2 s.c om*/ */ @SuppressWarnings({ "rawtypes", "unchecked" }) public MainWindow() { EasyPastebin.LOGGER.log("Initializing the window", SinkJLevel.INFO); setTitle("EasyPastebin"); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setBounds(100, 100, 664, 431); contentPane = new JPanel(); contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); contentPane.setLayout(new BorderLayout(0, 0)); setContentPane(contentPane); JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.TOP); contentPane.add(tabbedPane, BorderLayout.CENTER); JPanel main = new JPanel(); tabbedPane.addTab("EasyPastebin", null, main, null); main.setLayout(null); JScrollPane scrollPane = new JScrollPane(); scrollPane.setBounds(62, 39, 312, 132); main.add(scrollPane); pasteContent = new JTextArea(); pasteContent.setFont(new Font("Monospaced", Font.PLAIN, 11)); pasteContent.setWrapStyleWord(true); pasteContent.setLineWrap(true); pasteContent.setToolTipText("Put your paste here!"); scrollPane.setViewportView(pasteContent); JLabel titleLabel = new JLabel("Title :"); titleLabel.setFont(new Font("Tahoma", Font.PLAIN, 12)); titleLabel.setBounds(10, 11, 42, 21); main.add(titleLabel); pasteTitle = new JTextField(); pasteTitle.setBounds(62, 12, 312, 20); main.add(pasteTitle); pasteTitle.setColumns(10); JLabel lblPaste = new JLabel("Paste :"); lblPaste.setForeground(Color.RED); lblPaste.setFont(new Font("Tahoma", Font.PLAIN, 12)); lblPaste.setBounds(10, 85, 53, 21); main.add(lblPaste); pasteExpireDate = new JComboBox(); pasteExpireDate.setFont(new Font("Tahoma", Font.PLAIN, 12)); pasteExpireDate.setModel(new DefaultComboBoxModel(EnumExpireDate.values())); pasteExpireDate.setBounds(468, 12, 155, 21); main.add(pasteExpireDate); JLabel lblExpireDate = new JLabel("Expire Date :"); lblExpireDate.setFont(new Font("Tahoma", Font.PLAIN, 12)); lblExpireDate.setBounds(384, 14, 81, 14); main.add(lblExpireDate); JLabel lblfieldsInRed = new JLabel("(Fields in red are required)"); lblfieldsInRed.setBounds(72, 182, 302, 14); main.add(lblfieldsInRed); btnSubmit = new JButton("Submit!"); btnSubmit.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { EasyPastebin.LOGGER.log("Starting Submit script", SinkJLevel.INFO); btnSubmit.setEnabled(false); btnSubmit.setText("Please wait..."); boolean success = true; String paste = pasteContent.getText(); String title = pasteTitle.getText(); EnumExpireDate expireDate = (EnumExpireDate) pasteExpireDate.getSelectedItem(); if (paste.equals("") || paste.equals(" ") || paste.equals(null)) { pastebinUrl.setText("ERROR"); JOptionPane.showMessageDialog(null, "You cannot send empty pastes!", "Error while processing paste", JOptionPane.ERROR_MESSAGE); } else { try { EasyPastebin.LOGGER.log("Setting options", SinkJLevel.INFO); Map map = new HashMap<String, String>(); map.put("api_dev_key", HttpHelper.API_KEY); map.put("api_option", "paste"); map.put("api_paste_code", paste); if (!(expireDate.equals(null) || expireDate.equals(EnumExpireDate.NEVER))) map.put("api_paste_expire_date", expireDate.getRawName()); if (!(title.equals("") || title.equals(" ") || title.equals(null))) map.put("api_paste_name", title); EasyPastebin.LOGGER.log("Sending paste", SinkJLevel.INFO); String actionResult = HttpHelper.sendPost("http://pastebin.com/api/api_post.php", map) .asString(); EasyPastebin.LOGGER.log("Paste sent, checking output", SinkJLevel.INFO); // Exception handlers if (actionResult.equals("Bad API request, invalid api_option")) { success = false; EasyPastebin.LOGGER.log( "The output is an error message : " + actionResult + ". Submit script failed!", SinkJLevel.ERROR); JOptionPane.showMessageDialog(null, "Error while processing paste. Incorrect Pastebin option!", "Error", JOptionPane.ERROR_MESSAGE); } if (actionResult.equals("Bad API request, invalid api_dev_key")) { success = false; EasyPastebin.LOGGER.log( "The output is an error message : " + actionResult + ". Submit script failed!", SinkJLevel.ERROR); JOptionPane.showMessageDialog(null, "Error while processing paste. Incorrect dev key! Try again with a more recent version!", "Error", JOptionPane.ERROR_MESSAGE); } if (actionResult.equals("Bad API request, IP blocked")) { success = false; EasyPastebin.LOGGER.log( "The output is an error message : " + actionResult + ". Submit script failed!", SinkJLevel.ERROR); JOptionPane.showMessageDialog(null, "Error while processing paste. Your IP is blocked!", "Error", JOptionPane.ERROR_MESSAGE); } if (actionResult.equals( "Bad API request, maximum number of 25 unlisted pastes for your free account")) { success = false; EasyPastebin.LOGGER.log( "The output is an error message : " + actionResult + ". Submit script failed!", SinkJLevel.ERROR); } if (actionResult.equals( "Bad API request, maximum number of 10 private pastes for your free account")) { success = false; EasyPastebin.LOGGER.log( "The output is an error message : " + actionResult + ". Submit script failed!", SinkJLevel.ERROR); } if (actionResult.equals("Bad API request, api_paste_code was empty")) { success = false; EasyPastebin.LOGGER.log( "The output is an error message : " + actionResult + ". Submit script failed!", SinkJLevel.ERROR); } if (actionResult.equals("Bad API request, maximum paste file size exceeded")) { success = false; EasyPastebin.LOGGER.log( "The output is an error message : " + actionResult + ". Submit script failed!", SinkJLevel.ERROR); JOptionPane.showMessageDialog(null, "Error while processing paste. Your paste is too big!", "Error", JOptionPane.ERROR_MESSAGE); } if (actionResult.equals("Bad API request, invalid api_expire_date")) { success = false; EasyPastebin.LOGGER.log( "The output is an error message : " + actionResult + ". Submit script failed!", SinkJLevel.ERROR); JOptionPane.showMessageDialog(null, "Error while processing paste. Invalid expire date!", "Error", JOptionPane.ERROR_MESSAGE); } if (actionResult.equals("Bad API request, invalid api_paste_private")) { success = false; EasyPastebin.LOGGER.log( "The output is an error message : " + actionResult + ". Submit script failed!", SinkJLevel.ERROR); JOptionPane.showMessageDialog(null, "Error while processing paste. Invalid privacy value!", "Error", JOptionPane.ERROR_MESSAGE); } if (actionResult.equals("Bad API request, invalid api_paste_format")) { success = false; EasyPastebin.LOGGER.log( "The output is an error message : " + actionResult + ". Submit script failed!", SinkJLevel.ERROR); JOptionPane.showMessageDialog(null, "Error while processing paste. Invalid format!", "Error", JOptionPane.ERROR_MESSAGE); } // END // Starting display stuff if (success == false) { EasyPastebin.LOGGER.log("Submit script failed : success == false", SinkJLevel.ERROR); pastebinUrl.setText("ERROR"); } if (success == true) { EasyPastebin.LOGGER.log("Paste sent! Starting display script!", SinkJLevel.INFO); pastebinUrl.setText(actionResult); JOptionPane.showMessageDialog(null, "Paste successfully sent!", "Done!", JOptionPane.INFORMATION_MESSAGE); EasyPastebin.LOGGER.log("Display script finished! Paste URL is : " + actionResult, SinkJLevel.INFO); } } catch (ClientProtocolException e) { EasyPastebin.LOGGER.log("Unexpected error! " + e, SinkJLevel.ERROR); JOptionPane.showMessageDialog(null, "Error while processing paste : " + e, "Error", JOptionPane.ERROR_MESSAGE); e.printStackTrace(); } catch (IOException e) { EasyPastebin.LOGGER.log("Unexpected error! " + e, SinkJLevel.ERROR); JOptionPane.showMessageDialog(null, "Error while processing paste : " + e, "Error", JOptionPane.ERROR_MESSAGE); e.printStackTrace(); } catch (MissingParamException e) { EasyPastebin.LOGGER.log("Unexpected error! " + e, SinkJLevel.ERROR); JOptionPane.showMessageDialog(null, "Error while processing paste : " + e + "! This is a severe programming error! Try again with a more recent version!", "Error", JOptionPane.ERROR_MESSAGE); e.printStackTrace(); } } EasyPastebin.LOGGER.log("Re-enabling the Submit button ", SinkJLevel.INFO); btnSubmit.setEnabled(true); btnSubmit.setText("Submit another paste!"); EasyPastebin.LOGGER.log("Finished submit script! Success : " + success, SinkJLevel.INFO); } }); btnSubmit.setBounds(386, 45, 237, 44); main.add(btnSubmit); pastebinUrl = new JTextField(); pastebinUrl.setText("The paste's URL will be shown here!"); pastebinUrl.setEditable(false); pastebinUrl.setBounds(384, 198, 239, 32); main.add(pastebinUrl); pastebinUrl.setColumns(10); JPanel about = new JPanel(); tabbedPane.addTab("About", null, about, null); JLabel label = new JLabel("EasyPastebin"); label.setBounds(12, 12, 623, 39); label.setHorizontalAlignment(SwingConstants.CENTER); label.setFont(new Font("Dialog", Font.PLAIN, 25)); JLabel lblTheEasiestWay = new JLabel("The easiest way to use Pastebin.com"); lblTheEasiestWay.setBounds(12, 63, 623, 32); lblTheEasiestWay.setFont(new Font("Dialog", Font.PLAIN, 16)); lblTheEasiestWay.setHorizontalAlignment(SwingConstants.CENTER); about.setLayout(null); about.add(label); about.add(lblTheEasiestWay); JButton btnForkM = new JButton("Fork me on Github!"); btnForkM.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { goToUrl("https://github.com/utybo/EasyPastebin"); } }); btnForkM.setBounds(12, 117, 623, 25); about.add(btnForkM); JButton btnCheckOutUtybos = new JButton("Check out utybo's projects!"); btnCheckOutUtybos.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { goToUrl("http://utybo.github.io/"); } }); btnCheckOutUtybos.setBounds(12, 154, 623, 25); about.add(btnCheckOutUtybos); JButton btnGoToPastebincom = new JButton("Go to Pastebin.com!"); btnGoToPastebincom.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { goToUrl("http://www.pastebin.com"); } }); btnGoToPastebincom.setBounds(12, 191, 623, 25); about.add(btnGoToPastebincom); JLabel lblcUtybo = new JLabel( "This soft was made by utybo. It uses Apache's libraries for the interaction with Pastebin's API"); lblcUtybo.setFont(new Font("Dialog", Font.PLAIN, 10)); lblcUtybo.setHorizontalAlignment(SwingConstants.CENTER); lblcUtybo.setBounds(12, 324, 623, 15); about.add(lblcUtybo); JLabel lblClickMeTo = new JLabel("Click me to go to Apache's licence official website"); lblClickMeTo.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { goToUrl("http://www.apache.org/licenses/LICENSE-2.0"); } }); lblClickMeTo.setHorizontalAlignment(SwingConstants.CENTER); lblClickMeTo.setFont(new Font("Dialog", Font.PLAIN, 10)); lblClickMeTo.setBounds(12, 342, 623, 15); about.add(lblClickMeTo); setVisible(true); EasyPastebin.LOGGER.log("Done!", SinkJLevel.INFO); }