Search in sources :

Example 1 with DatePickerSettings

use of com.github.lgooddatepicker.components.DatePickerSettings in project DevKits by qmjy.

the class AppStarter method createCalendarPane.

private Container createCalendarPane() {
    DatePickerSettings datePickerSettings = new DatePickerSettings();
    datePickerSettings.setWeekNumbersDisplayed(true, true);
    // int newHeight = (int) (datePickerSettings.getSizeDatePanelMinimumHeight() * 1.6);
    // int newWidth = (int) (datePickerSettings.getSizeDatePanelMinimumWidth() * 1.6);
    // datePickerSettings.setSizeDatePanelMinimumHeight(newHeight);
    // datePickerSettings.setSizeDatePanelMinimumWidth(newWidth);
    CalendarPanel calendarPanel = new CalendarPanel(datePickerSettings);
    calendarPanel.setSelectedDate(LocalDate.now());
    calendarPanel.setBorder(new LineBorder(Color.lightGray));
    return calendarPanel;
}
Also used : CalendarPanel(com.github.lgooddatepicker.components.CalendarPanel) DatePickerSettings(com.github.lgooddatepicker.components.DatePickerSettings) LineBorder(javax.swing.border.LineBorder)

Example 2 with DatePickerSettings

use of com.github.lgooddatepicker.components.DatePickerSettings in project sldeditor by robward-scisys.

the class DateTimePanel method createUI.

/**
 * Creates the UI.
 *
 * @param xPos the x pos
 * @param indentWidth the indent width
 * @param yOffset the y offset
 * @param fieldPanel the field panel
 */
public void createUI(int xPos, int indentWidth, int yOffset, JPanel fieldPanel) {
    if (dateTimePicker == null) {
        DatePickerSettings dateModel = new DatePickerSettings();
        dateModel.setAllowEmptyDates(false);
        dateModel.setFormatForDatesCommonEra(DateTimeFormatter.ofPattern("dd MMM yyyy"));
        TimePickerSettings timeModel = new TimePickerSettings();
        timeModel.setAllowEmptyTimes(false);
        timeModel.setDisplaySpinnerButtons(true);
        timeModel.setDisplayToggleTimeMenuButton(false);
        timeModel.setFormatForDisplayTime(PickerUtilities.createFormatterFromPatternString("HH:mm:ss.SSS", timeModel.getLocale()));
        dateTimePicker = new DateTimePicker(dateModel, timeModel);
        int x = xPos + indentWidth;
        dateTimePicker.setBounds(x, yOffset, DATEPICKER_WIDTH, BasePanel.WIDGET_HEIGHT);
        fieldPanel.add(dateTimePicker);
        offsetSign = new JComboBox<>(offsetStrings);
        int y = BasePanel.WIDGET_HEIGHT + yOffset;
        offsetSign.setBounds(x, y, OFFSET_SIGN_WIDTH, BasePanel.WIDGET_HEIGHT);
        offsetSign.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                if (callback != null) {
                    callback.dateTimeValueUpdated();
                }
            }
        });
        fieldPanel.add(offsetSign);
        SpinnerNumberModel hourModel = new SpinnerNumberModel();
        hourModel.setStepSize(1);
        hourModel.setMinimum(0);
        hourModel.setMaximum(23);
        hourSpinner = new JSpinner(hourModel);
        hourSpinner.addChangeListener(new ChangeListener() {

            @Override
            public void stateChanged(ChangeEvent e) {
                if (callback != null) {
                    callback.dateTimeValueUpdated();
                }
            }
        });
        fieldPanel.add(hourSpinner);
        x += OFFSET_SIGN_WIDTH + 2;
        hourSpinner.setBounds(x, y, OFFSET_HOURS_WIDTH, BasePanel.WIDGET_HEIGHT);
        SpinnerNumberModel secondModel = new SpinnerNumberModel();
        secondModel.setStepSize(1);
        secondModel.setMinimum(0);
        secondModel.setMaximum(59);
        minuteSpinner = new JSpinner(secondModel);
        fieldPanel.add(minuteSpinner);
        minuteSpinner.addChangeListener(new ChangeListener() {

            @Override
            public void stateChanged(ChangeEvent e) {
                if (callback != null) {
                    callback.dateTimeValueUpdated();
                }
            }
        });
        x += OFFSET_HOURS_WIDTH + 2;
        minuteSpinner.setBounds(x, y, OFFSET_MINUTES_WIDTH, BasePanel.WIDGET_HEIGHT);
        dateTimePicker.addDateTimeChangeListener(new DateTimeChangeListener() {

            @Override
            public void dateOrTimeChanged(DateTimeChangeEvent event) {
                if (callback != null) {
                    callback.dateTimeValueUpdated();
                }
            }
        });
    }
}
Also used : DateTimeChangeListener(com.github.lgooddatepicker.optionalusertools.DateTimeChangeListener) TimePickerSettings(com.github.lgooddatepicker.components.TimePickerSettings) ActionEvent(java.awt.event.ActionEvent) DateTimePicker(com.github.lgooddatepicker.components.DateTimePicker) DateTimeChangeEvent(com.github.lgooddatepicker.zinternaltools.DateTimeChangeEvent) SpinnerNumberModel(javax.swing.SpinnerNumberModel) DatePickerSettings(com.github.lgooddatepicker.components.DatePickerSettings) ActionListener(java.awt.event.ActionListener) ChangeEvent(javax.swing.event.ChangeEvent) DateTimeChangeEvent(com.github.lgooddatepicker.zinternaltools.DateTimeChangeEvent) JSpinner(javax.swing.JSpinner) DateTimeChangeListener(com.github.lgooddatepicker.optionalusertools.DateTimeChangeListener) ChangeListener(javax.swing.event.ChangeListener)

Example 3 with DatePickerSettings

use of com.github.lgooddatepicker.components.DatePickerSettings in project dna by leifeld.

the class DocumentEditor method createGui.

private void createGui(int numDocuments) {
    String toolTipText = "<html><p width=\"500\">Overwrite the document contents and meta-data " + "by editing the fields shown in this editor dialog.</p>" + "<p width=\"500\">Note that the document text field is only editable if there are " + "no statements contained in the document.</p>" + "<p width=\"500\">In the title, author, source, section, type, notes, and text " + "fields, the following wildcards can be used (across the different fields) to " + "represent the contents of the respective field that are currently saved " + "in the database:</p>" + "<dl>" + "<dt><b>%title</b></dt><dd>Represents the current contents of the title field.</dd>" + "<dt><b>%author</b></dt><dd>Represents the current contents of the author field.</dd>" + "<dt><b>%source</b></dt><dd>Represents the current contents of the source field.</dd>" + "<dt><b>%section</b></dt><dd>Represents the current contents of the section field.</dd>" + "<dt><b>%type</b></dt><dd>Represents the current contents of the type field.</dd>" + "<dt><b>%notes</b></dt><dd>Represents the current contents of the notes field.</dd>" + "<dt><b>%text</b></dt><dd>Represents the current contents of the text field.</dd>" + "<dt><b>%day</b></dt><dd>Represents the current day (1-31) of the document.</dd>" + "<dt><b>%month</b></dt><dd>Represents the current month (1-12) of the document.</dd>" + "<dt><b>%year</b></dt><dd>Represents the current year (e.g., 2007) of the document.</dd>" + "<dt><b>%hour</b></dt><dd>Represents the current hour (0-23) of the document.</dd>" + "<dt><b>%minute</b></dt><dd>Represents the current minute (0-59) of the document.</dd>" + "</dl>" + "<p width=\"500\">For example, you can combine title and date like this: " + "%title (%day.%month.%year).</p>" + "<p width=\"500\">Note that the date or time fields may show as empty when multiple " + "documents are edited simultaneously. This just means the original date or time will be " + "kept when saving unless edited. It is possible to edit only the date or only the time " + "if necessary while keeping the other field empty.</p></html>";
    this.setModal(true);
    if (numDocuments == 0) {
        this.setTitle("Add new document...");
    } else {
        String s = " document...";
        if (numDocuments > 1) {
            s = " documents...";
        }
        this.setTitle("Edit " + numDocuments + s);
    }
    this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    ImageIcon tableAddIcon = new ImageIcon(getClass().getResource("/icons/tabler-icon-file-plus.png"));
    this.setIconImage(tableAddIcon.getImage());
    this.setLayout(new FlowLayout(FlowLayout.LEFT));
    textArea = new JXTextArea("paste the contents of the document here using Ctrl-V...");
    textArea.setLineWrap(true);
    textArea.setWrapStyleWord(true);
    textScroller = new JScrollPane(textArea);
    textScroller.setPreferredSize(new Dimension(700, 360));
    textScroller.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
    textScroller.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
    if (numDocuments > 0) {
        textScroller.setToolTipText(toolTipText);
    }
    JPanel fieldsPanel = new JPanel(new GridBagLayout());
    GridBagConstraints gbc = new GridBagConstraints();
    gbc.fill = GridBagConstraints.HORIZONTAL;
    // first column: labels
    gbc.insets = new Insets(3, 0, 3, 7);
    gbc.gridy = 0;
    gbc.gridx = 0;
    JLabel titleLabel = new JLabel("title", JLabel.RIGHT);
    if (numDocuments > 0) {
        titleLabel.setToolTipText(toolTipText);
    }
    fieldsPanel.add(titleLabel, gbc);
    gbc.gridy = 1;
    gbc.gridx = 0;
    JLabel dateLabel = new JLabel("date", JLabel.RIGHT);
    if (numDocuments > 0) {
        dateLabel.setToolTipText(toolTipText);
    }
    fieldsPanel.add(dateLabel, gbc);
    gbc.gridy = 2;
    gbc.gridx = 0;
    JLabel coderLabel = new JLabel("coder", JLabel.RIGHT);
    fieldsPanel.add(coderLabel, gbc);
    gbc.gridy = 3;
    gbc.gridx = 0;
    JLabel authorLabel = new JLabel("author", JLabel.RIGHT);
    if (numDocuments > 0) {
        authorLabel.setToolTipText(toolTipText);
    }
    fieldsPanel.add(authorLabel, gbc);
    gbc.gridy = 4;
    gbc.gridx = 0;
    JLabel sourceLabel = new JLabel("source", JLabel.RIGHT);
    if (numDocuments > 0) {
        sourceLabel.setToolTipText(toolTipText);
    }
    fieldsPanel.add(sourceLabel, gbc);
    gbc.gridy = 5;
    gbc.gridx = 0;
    JLabel sectionLabel = new JLabel("section", JLabel.RIGHT);
    if (numDocuments > 0) {
        sectionLabel.setToolTipText(toolTipText);
    }
    fieldsPanel.add(sectionLabel, gbc);
    gbc.gridy = 6;
    gbc.gridx = 0;
    JLabel typeLabel = new JLabel("type", JLabel.RIGHT);
    if (numDocuments > 0) {
        typeLabel.setToolTipText(toolTipText);
    }
    fieldsPanel.add(typeLabel, gbc);
    gbc.gridy = 7;
    gbc.gridx = 0;
    gbc.anchor = GridBagConstraints.NORTH;
    JLabel notesLabel = new JLabel("notes", JLabel.RIGHT);
    if (numDocuments > 0) {
        notesLabel.setToolTipText(toolTipText);
    }
    fieldsPanel.add(notesLabel, gbc);
    gbc.gridy = 8;
    gbc.gridx = 0;
    JLabel textLabel = new JLabel("text", JLabel.RIGHT);
    if (numDocuments > 0) {
        textLabel.setToolTipText(toolTipText);
    }
    fieldsPanel.add(textLabel, gbc);
    // second column: fields
    gbc.insets = new Insets(3, 0, 3, 0);
    gbc.gridy = 0;
    gbc.gridx = 1;
    gbc.gridwidth = 3;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    gbc.weightx = 1.0;
    titleField = new JXTextField("paste the title of the document here using Ctrl-V...");
    titleField.setColumns(60);
    if (numDocuments > 0) {
        titleField.setToolTipText(toolTipText);
    }
    fieldsPanel.add(titleField, gbc);
    if (numDocuments < 2) {
        titleField.getDocument().addDocumentListener(new DocumentListener() {

            @Override
            public void changedUpdate(DocumentEvent e) {
                checkButton();
            }

            @Override
            public void insertUpdate(DocumentEvent e) {
                checkButton();
            }

            @Override
            public void removeUpdate(DocumentEvent e) {
                checkButton();
            }

            public void checkButton() {
                boolean problem = false;
                if (titleField.getText().equals("")) {
                    problem = true;
                }
                if (problem == true) {
                    okButton.setEnabled(false);
                } else {
                    okButton.setEnabled(true);
                }
            }
        });
    }
    gbc.gridy = 1;
    gbc.gridx = 1;
    gbc.fill = GridBagConstraints.NONE;
    gbc.anchor = GridBagConstraints.WEST;
    DatePickerSettings dateSettings = new DatePickerSettings();
    dateSettings.setFormatForDatesCommonEra("dd MM yyyy");
    dateSettings.setFormatForDatesBeforeCommonEra("dd MM uuuu");
    TimePickerSettings timeSettings = new TimePickerSettings();
    timeSettings.setFormatForDisplayTime("HH:mm:ss");
    timeSettings.setFormatForMenuTimes("HH:mm:ss");
    dateTimePicker = new DateTimePicker(dateSettings, timeSettings);
    dateTimePicker.getDatePicker().setDateToToday();
    dateTimePicker.getTimePicker().setTime(LocalTime.MIDNIGHT);
    ImageIcon dateIcon = new ImageIcon(new ImageIcon(getClass().getResource("/icons/tabler-icon-calendar-event.png")).getImage().getScaledInstance(16, 16, Image.SCALE_SMOOTH));
    JButton dateButton = dateTimePicker.getDatePicker().getComponentToggleCalendarButton();
    dateButton.setText("");
    dateButton.setIcon(dateIcon);
    ImageIcon timeIcon = new ImageIcon(new ImageIcon(getClass().getResource("/icons/tabler-icon-clock.png")).getImage().getScaledInstance(16, 16, Image.SCALE_SMOOTH));
    JButton timeButton = dateTimePicker.getTimePicker().getComponentToggleTimeMenuButton();
    timeButton.setText("");
    timeButton.setIcon(timeIcon);
    if (numDocuments > 0) {
        dateTimePicker.setToolTipText(toolTipText);
        dateButton.setToolTipText(toolTipText);
        timeButton.setToolTipText(toolTipText);
    }
    fieldsPanel.add(dateTimePicker, gbc);
    gbc.gridy = 2;
    gbc.gridx = 1;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    if (Dna.sql.getActiveCoder().isPermissionEditOthersDocuments()) {
        // create list of eligible coders
        List<Coder> eligibleCoders = Dna.sql.getCoders().stream().filter(e -> e.getId() == Dna.sql.getActiveCoder().getId() || (e.getId() != Dna.sql.getActiveCoder().getId() && Dna.sql.getActiveCoder().isPermissionEditOthersDocuments(e.getId()))).sorted().collect(Collectors.toList());
        if (eligibleCoders.size() == 1) {
            // only one eligible coder (must be the active coder); create coder badge panel instead of combo box
            this.cbp = new CoderBadgePanel(eligibleCoders.get(0));
            fieldsPanel.add(this.cbp, gbc);
        } else {
            // check if there is only a single coder across the documents and add a fake coder for multiple coders coder varies across documents
            boolean oneCoder = (numDocuments == 0 || documents.stream().mapToInt(Document::getCoder).distinct().limit(2).count() <= 1);
            if (!oneCoder) {
                eligibleCoders.add(0, new Coder(-1, "(keep multiple coders)", Color.BLACK));
            }
            // create and populate combo box with coders
            ArrayList<Coder> coderArrayList = new ArrayList<Coder>(eligibleCoders);
            this.coderComboBox = new JComboBox<Coder>();
            CoderComboBoxModel comboBoxModel = new CoderComboBoxModel(coderArrayList);
            this.coderComboBox.setModel(comboBoxModel);
            this.coderComboBox.setRenderer(new CoderComboBoxRenderer(18, 0, 97));
            // select the right coder and add combo box to panel
            if (numDocuments == 0) {
                this.coderComboBox.setSelectedIndex(IntStream.range(0, eligibleCoders.size()).filter(i -> Dna.sql.getActiveCoder().getId() == eligibleCoders.get(i).getId()).findFirst().getAsInt());
            } else if (oneCoder) {
                this.coderComboBox.setSelectedIndex(IntStream.range(0, eligibleCoders.size()).filter(i -> documents.get(0).getCoder() == eligibleCoders.get(i).getId()).findFirst().getAsInt());
            } else {
                this.coderComboBox.setSelectedIndex(0);
            }
            fieldsPanel.add(this.coderComboBox, gbc);
        }
    } else {
        // no permission to add other coders' documents; create coder badge panel
        this.cbp = new CoderBadgePanel(Dna.sql.getActiveCoder());
        fieldsPanel.add(this.cbp, gbc);
    }
    gbc.gridy = 3;
    gbc.gridx = 1;
    authorBox = new JXComboBox();
    authorBox.setEditable(true);
    AutoCompleteDecorator.decorate(authorBox);
    if (numDocuments > 0) {
        authorBox.setToolTipText(toolTipText);
    }
    authorBox.setRenderer(new ComboBoxRenderer());
    fieldsPanel.add(authorBox, gbc);
    gbc.gridy = 4;
    gbc.gridx = 1;
    sourceBox = new JXComboBox();
    sourceBox.setEditable(true);
    sourceBox.setSelectedItem("");
    AutoCompleteDecorator.decorate(sourceBox);
    if (numDocuments > 0) {
        sourceBox.setToolTipText(toolTipText);
    }
    sourceBox.setRenderer(new ComboBoxRenderer());
    fieldsPanel.add(sourceBox, gbc);
    gbc.gridy = 5;
    gbc.gridx = 1;
    sectionBox = new JXComboBox();
    sectionBox.setEditable(true);
    sectionBox.setSelectedItem("");
    AutoCompleteDecorator.decorate(sectionBox);
    if (numDocuments > 0) {
        sectionBox.setToolTipText(toolTipText);
    }
    sectionBox.setRenderer(new ComboBoxRenderer());
    fieldsPanel.add(sectionBox, gbc);
    gbc.gridy = 6;
    gbc.gridx = 1;
    typeBox = new JXComboBox();
    typeBox.setEditable(true);
    typeBox.setSelectedItem("");
    AutoCompleteDecorator.decorate(typeBox);
    if (numDocuments > 0) {
        typeBox.setToolTipText(toolTipText);
    }
    typeBox.setRenderer(new ComboBoxRenderer());
    JDBCWorker worker = new JDBCWorker(numDocuments == 0);
    worker.execute();
    fieldsPanel.add(typeBox, gbc);
    gbc.gridy = 7;
    gbc.gridx = 1;
    notesArea = new JXTextArea("notes...");
    notesArea.setLineWrap(true);
    notesArea.setWrapStyleWord(true);
    notesArea.setRows(4);
    JScrollPane notesScroller = new JScrollPane(notesArea);
    notesScroller.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
    if (numDocuments > 0) {
        notesScroller.setToolTipText(toolTipText);
    }
    fieldsPanel.add(notesScroller, gbc);
    gbc.gridy = 8;
    gbc.gridx = 1;
    fieldsPanel.add(textScroller, gbc);
    newArticlePanel = new JPanel(new BorderLayout());
    newArticlePanel.add(fieldsPanel, BorderLayout.CENTER);
    FlowLayout fl = new FlowLayout(FlowLayout.RIGHT);
    JPanel buttons = new JPanel(fl);
    ImageIcon cancelIcon = new ImageIcon(new ImageIcon(getClass().getResource("/icons/tabler-icon-x.png")).getImage().getScaledInstance(18, 18, Image.SCALE_SMOOTH));
    JButton cancelButton = new JButton("Cancel", cancelIcon);
    cancelButton.setToolTipText("close this window without making any changes");
    cancelButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            dispose();
        }
    });
    buttons.add(cancelButton);
    ImageIcon okIcon = new ImageIcon(new ImageIcon(getClass().getResource("/icons/tabler-icon-check.png")).getImage().getScaledInstance(18, 18, Image.SCALE_SMOOTH));
    String okString = "Add";
    if (numDocuments > 0) {
        okString = "Update";
    }
    okButton = new JButton(okString, okIcon);
    if (numDocuments == 0) {
        okButton.setToolTipText("insert a new article based on the information you entered in this window");
        okButton.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                int coder = 1;
                if (DocumentEditor.this.cbp != null) {
                    coder = cbp.getCoder().getId();
                } else {
                    coder = ((Coder) coderComboBox.getSelectedItem()).getId();
                }
                String text = textArea.getText();
                String title = titleField.getText().substring(0, Math.min(190, titleField.getText().length()));
                LocalDateTime dateTime = dateTimePicker.getDateTimeStrict();
                String author = ((String) authorBox.getModel().getSelectedItem()).substring(0, Math.min(190, ((String) authorBox.getModel().getSelectedItem()).length()));
                String source = ((String) sourceBox.getModel().getSelectedItem()).substring(0, Math.min(190, ((String) sourceBox.getModel().getSelectedItem()).length()));
                String section = ((String) sectionBox.getModel().getSelectedItem()).substring(0, Math.min(190, ((String) sectionBox.getModel().getSelectedItem()).length()));
                String notes = notesArea.getText();
                String type = ((String) typeBox.getModel().getSelectedItem()).substring(0, Math.min(190, ((String) typeBox.getModel().getSelectedItem()).length()));
                ArrayList<Document> al = new ArrayList<Document>();
                Document d = new Document(-1, coder, title, text, author, source, section, type, notes, dateTime, new ArrayList<Statement>());
                al.add(d);
                documents = al;
                documentIds = Dna.sql.addDocuments(documents);
                changesApplied = true;
                LogEvent l = new LogEvent(Logger.MESSAGE, "[GUI] A new document was added to the database.", "A new document was manually added to the database by clicking on the Add button in a New Document dialog window.");
                Dna.logger.log(l);
                dispose();
            }
        });
        okButton.setEnabled(false);
    } else {
        okButton.setToolTipText("save updated document data into the database");
        okButton.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                int coder = 1;
                if (DocumentEditor.this.cbp != null) {
                    coder = cbp.getCoder().getId();
                } else {
                    // can be -1 for keeping existing coders; needs to be taken care of in the Sql.updateDocuments method
                    coder = ((Coder) coderComboBox.getSelectedItem()).getId();
                }
                String message = "Are you sure you want to recode " + documentIds.length + " documents and save the changes to the database?";
                int dialog = JOptionPane.showConfirmDialog(DocumentEditor.this, message, "Confirmation required", JOptionPane.YES_NO_OPTION);
                if (dialog == 0) {
                    LocalDate ld = dateTimePicker.getDatePicker().getDate();
                    LocalTime lt = dateTimePicker.getTimePicker().getTime();
                    Dna.sql.updateDocuments(documentIds, coder, titleField.getText(), textArea.getText(), (String) authorBox.getSelectedItem(), (String) sourceBox.getSelectedItem(), (String) sectionBox.getSelectedItem(), (String) typeBox.getSelectedItem(), notesArea.getText(), ld, lt);
                    changesApplied = true;
                    LogEvent l = new LogEvent(Logger.MESSAGE, "[GUI] " + documentIds.length + " documents were updated in the database.", "Using a Document Editor dialog window, the meta-data of " + documentIds.length + " documents were updated in the database.");
                    Dna.logger.log(l);
                }
                dispose();
            }
        });
    }
    buttons.add(okButton);
    newArticlePanel.add(buttons, BorderLayout.SOUTH);
    // add contents for editing if this is not a new document
    if (numDocuments > 0) {
        String contentTitle = documents.get(0).getTitle();
        titleField.setText(contentTitle);
        if (numDocuments > 1) {
            for (int i = 0; i < documents.size(); i++) {
                if (!documents.get(i).getTitle().equals(contentTitle)) {
                    titleField.setText("%title");
                    titleField.setPrompt("(Overwrite all titles at once by replacing this text.)");
                    break;
                }
            }
        }
        String contentText = documents.get(0).getText();
        if (Dna.sql.documentsContainStatements(documentIds) == true) {
            textArea.setEditable(false);
        }
        if (numDocuments > 1) {
            for (int i = 0; i < documents.size(); i++) {
                if (!documents.get(i).getText().equals(contentText)) {
                    textArea.setText("%text");
                    textArea.setPrompt("(Overwrite all texts at once by replacing this text.)");
                    break;
                }
            }
        }
        if (textArea.getText().equals("")) {
            textArea.setText(contentText);
        }
        String contentNotes = documents.get(0).getNotes();
        notesArea.setText(contentNotes);
        if (numDocuments > 1) {
            for (int i = 0; i < documents.size(); i++) {
                if (!documents.get(i).getNotes().equals(contentNotes)) {
                    notesArea.setText("%notes");
                    notesArea.setPrompt("(Overwrite all notes at once by replacing this text.)");
                    break;
                }
            }
        }
        String contentAuthor = documents.get(0).getAuthor();
        authorBox.setSelectedItem(contentAuthor);
        if (numDocuments > 1) {
            for (int i = 0; i < documents.size(); i++) {
                if (!documents.get(i).getAuthor().equals(contentAuthor)) {
                    authorBox.setSelectedItem("%author");
                    break;
                }
            }
        }
        String contentSource = documents.get(0).getSource();
        sourceBox.setSelectedItem(contentSource);
        if (numDocuments > 1) {
            for (int i = 0; i < documents.size(); i++) {
                if (!documents.get(i).getSource().equals(contentSource)) {
                    sourceBox.setSelectedItem("%source");
                    break;
                }
            }
        }
        String contentSection = documents.get(0).getSection();
        sectionBox.setSelectedItem(contentSection);
        if (numDocuments > 1) {
            for (int i = 0; i < documents.size(); i++) {
                if (!documents.get(i).getSection().equals(contentSection)) {
                    sectionBox.setSelectedItem("%section");
                    break;
                }
            }
        }
        String contentType = documents.get(0).getType();
        typeBox.setSelectedItem(contentType);
        if (numDocuments > 1) {
            for (int i = 0; i < documents.size(); i++) {
                if (!documents.get(i).getType().equals(contentType)) {
                    typeBox.setSelectedItem("%type");
                    break;
                }
            }
        }
        LocalDateTime contentDateTime = documents.get(0).getDateTime();
        dateTimePicker.setDateTimeStrict(contentDateTime);
        if (numDocuments > 1) {
            for (int i = 0; i < documents.size(); i++) {
                if (!documents.get(i).getDateTime().equals(contentDateTime)) {
                    dateTimePicker.clear();
                    break;
                }
            }
        }
    }
    this.add(newArticlePanel);
    this.pack();
    this.setLocationRelativeTo(null);
    this.setVisible(true);
}
Also used : Color(java.awt.Color) UIManager(javax.swing.UIManager) Connection(java.sql.Connection) DocumentListener(javax.swing.event.DocumentListener) JDialog(javax.swing.JDialog) ResultSet(java.sql.ResultSet) LocalTime(java.time.LocalTime) SwingWorker(javax.swing.SwingWorker) BorderLayout(java.awt.BorderLayout) JComboBox(javax.swing.JComboBox) JFrame(javax.swing.JFrame) DateTimePicker(com.github.lgooddatepicker.components.DateTimePicker) Image(java.awt.Image) GridBagConstraints(java.awt.GridBagConstraints) PreparedStatement(java.sql.PreparedStatement) Component(java.awt.Component) Collectors(java.util.stream.Collectors) Dna(dna.Dna) Logger(logger.Logger) Dimension(java.awt.Dimension) List(java.util.List) LocalDate(java.time.LocalDate) GridBagLayout(java.awt.GridBagLayout) Document(model.Document) JPanel(javax.swing.JPanel) DatePickerSettings(com.github.lgooddatepicker.components.DatePickerSettings) IntStream(java.util.stream.IntStream) Insets(java.awt.Insets) AutoCompleteDecorator(org.jdesktop.swingx.autocomplete.AutoCompleteDecorator) ActionListener(java.awt.event.ActionListener) LocalDateTime(java.time.LocalDateTime) Coder(model.Coder) ArrayList(java.util.ArrayList) JXTextField(org.jdesktop.swingx.JXTextField) SQLException(java.sql.SQLException) ImageIcon(javax.swing.ImageIcon) JXComboBox(org.jdesktop.swingx.JXComboBox) DocumentEvent(javax.swing.event.DocumentEvent) FlowLayout(java.awt.FlowLayout) JButton(javax.swing.JButton) JList(javax.swing.JList) JOptionPane(javax.swing.JOptionPane) ActionEvent(java.awt.event.ActionEvent) LogEvent(logger.LogEvent) JScrollPane(javax.swing.JScrollPane) TimePickerSettings(com.github.lgooddatepicker.components.TimePickerSettings) ListCellRenderer(javax.swing.ListCellRenderer) JLabel(javax.swing.JLabel) JXTextArea(org.jdesktop.swingx.JXTextArea) Statement(model.Statement) LocalDateTime(java.time.LocalDateTime) ImageIcon(javax.swing.ImageIcon) JPanel(javax.swing.JPanel) DocumentListener(javax.swing.event.DocumentListener) GridBagConstraints(java.awt.GridBagConstraints) FlowLayout(java.awt.FlowLayout) Insets(java.awt.Insets) TimePickerSettings(com.github.lgooddatepicker.components.TimePickerSettings) GridBagLayout(java.awt.GridBagLayout) ActionEvent(java.awt.event.ActionEvent) JXTextArea(org.jdesktop.swingx.JXTextArea) JButton(javax.swing.JButton) ArrayList(java.util.ArrayList) DateTimePicker(com.github.lgooddatepicker.components.DateTimePicker) Document(model.Document) LocalDate(java.time.LocalDate) JXTextField(org.jdesktop.swingx.JXTextField) DatePickerSettings(com.github.lgooddatepicker.components.DatePickerSettings) BorderLayout(java.awt.BorderLayout) JXComboBox(org.jdesktop.swingx.JXComboBox) JScrollPane(javax.swing.JScrollPane) Coder(model.Coder) LocalTime(java.time.LocalTime) LogEvent(logger.LogEvent) JLabel(javax.swing.JLabel) Dimension(java.awt.Dimension) DocumentEvent(javax.swing.event.DocumentEvent) ActionListener(java.awt.event.ActionListener)

Example 4 with DatePickerSettings

use of com.github.lgooddatepicker.components.DatePickerSettings in project Kernbeisser-Gradle by julikiller98.

the class AccountingReportsView method createUIComponents.

private void createUIComponents() {
    user = new AdvancedComboBox<>(User::getFullName);
    tillRollStartDate = new DatePicker(new DatePickerSettings(Locale.GERMANY));
    tillRollEndDate = new DatePicker(new DatePickerSettings(Locale.GERMANY));
}
Also used : DatePickerSettings(com.github.lgooddatepicker.components.DatePickerSettings) DatePicker(com.github.lgooddatepicker.components.DatePicker)

Example 5 with DatePickerSettings

use of com.github.lgooddatepicker.components.DatePickerSettings in project EmailDatasetBrowser by ArchitecturalKnowledgeAnalysis.

the class DownloadEmailsAction method actionPerformed.

@Override
public void actionPerformed(ActionEvent e) {
    JDialog dialog = new JDialog(owner, "Download ", Dialog.ModalityType.APPLICATION_MODAL);
    JPanel p = new JPanel(new BorderLayout());
    JTextField domainField = new JTextField(0);
    JTextField listField = new JTextField(0);
    var timeSettings = new TimePickerSettings();
    timeSettings.setAllowEmptyTimes(false);
    timeSettings.setInitialTimeToNow();
    var dateSettings = new DatePickerSettings();
    dateSettings.setAllowEmptyDates(false);
    DateTimePicker startPicker = new DateTimePicker(dateSettings.copySettings(), timeSettings);
    startPicker.setDateTimeStrict(LocalDateTime.now().minusYears(10));
    DateTimePicker endPicker = new DateTimePicker(dateSettings.copySettings(), timeSettings);
    endPicker.setDateTimeStrict(LocalDateTime.now());
    PathSelectField dirField = PathSelectField.directorySelectField();
    JPanel inputPanel = new JPanel();
    inputPanel.setLayout(new BoxLayout(inputPanel, BoxLayout.PAGE_AXIS));
    inputPanel.add(new LabelledField("Domain", domainField));
    inputPanel.add(new LabelledField("List", listField));
    inputPanel.add(new LabelledField("Start", startPicker));
    inputPanel.add(new LabelledField("End", endPicker));
    inputPanel.add(dirField);
    p.add(inputPanel, BorderLayout.CENTER);
    JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
    JButton cancelButton = new JButton("Cancel");
    cancelButton.addActionListener(event -> dialog.dispose());
    JButton downloadButton = new JButton("Download");
    downloadButton.addActionListener(event -> {
        ApacheMailingListFetcher fetcher = new ApacheMailingListFetcher();
        Path outputDir = dirField.getSelectedPath();
        dialog.dispose();
        ProgressDialog progressDialog = new ProgressDialog(owner, "Downloading...", "Downloading emails");
        progressDialog.activate();
        fetcher.download(outputDir, domainField.getText(), listField.getText(), startPicker.getDateTimeStrict().atZone(ZoneId.systemDefault()), endPicker.getDateTimeStrict().atZone(ZoneId.systemDefault()), progressDialog).handle((paths, throwable) -> {
            progressDialog.done();
            if (throwable == null) {
                JOptionPane.showMessageDialog(progressDialog, "MBox files downloaded successfully.", "Done", JOptionPane.INFORMATION_MESSAGE);
            } else {
                throwable.printStackTrace();
            }
            return null;
        });
    });
    buttonPanel.add(downloadButton);
    buttonPanel.add(cancelButton);
    p.add(buttonPanel, BorderLayout.SOUTH);
    dialog.setContentPane(p);
    dialog.pack();
    dialog.setLocationRelativeTo(owner);
    dialog.setVisible(true);
}
Also used : Path(java.nio.file.Path) ApacheMailingListFetcher(nl.andrewl.emaildownloader.ApacheMailingListFetcher) TimePickerSettings(com.github.lgooddatepicker.components.TimePickerSettings) DateTimePicker(com.github.lgooddatepicker.components.DateTimePicker) ProgressDialog(nl.andrewl.emaildatasetbrowser.view.ProgressDialog) DatePickerSettings(com.github.lgooddatepicker.components.DatePickerSettings) PathSelectField(nl.andrewl.emaildatasetbrowser.view.PathSelectField) LabelledField(nl.andrewl.emaildatasetbrowser.view.LabelledField)

Aggregations

DatePickerSettings (com.github.lgooddatepicker.components.DatePickerSettings)5 DateTimePicker (com.github.lgooddatepicker.components.DateTimePicker)3 TimePickerSettings (com.github.lgooddatepicker.components.TimePickerSettings)3 ActionEvent (java.awt.event.ActionEvent)2 ActionListener (java.awt.event.ActionListener)2 CalendarPanel (com.github.lgooddatepicker.components.CalendarPanel)1 DatePicker (com.github.lgooddatepicker.components.DatePicker)1 DateTimeChangeListener (com.github.lgooddatepicker.optionalusertools.DateTimeChangeListener)1 DateTimeChangeEvent (com.github.lgooddatepicker.zinternaltools.DateTimeChangeEvent)1 Dna (dna.Dna)1 BorderLayout (java.awt.BorderLayout)1 Color (java.awt.Color)1 Component (java.awt.Component)1 Dimension (java.awt.Dimension)1 FlowLayout (java.awt.FlowLayout)1 GridBagConstraints (java.awt.GridBagConstraints)1 GridBagLayout (java.awt.GridBagLayout)1 Image (java.awt.Image)1 Insets (java.awt.Insets)1 Path (java.nio.file.Path)1