Added date picker to InviteWindow

This commit is contained in:
Nikolay Borodin 2024-06-13 16:25:23 +00:00
parent a7a2e73944
commit fa526ad329
5 changed files with 168 additions and 39 deletions

View file

@ -26,7 +26,7 @@
<property name="clib" value="clib"/>
<property name="lib" value="lib"/>
<property name="resources" value="resources"/>
<property name="classpath" value="${lib}/commons-jxpath-1.1.jar;${lib}/commons-logging-1.2.jar;${lib}/bcprov-jdk15on-1.70.jar;${lib}/junit-4.5.jar;${lib}/commons-codec-1.3.jar;${lib}/swing-layout-1.0.3.jar;${lib}/WaifUPnP.jar;${lib}/flatlaf-3.1.1.jar"/>
<property name="classpath" value="${lib}/commons-jxpath-1.1.jar;${lib}/commons-logging-1.2.jar;${lib}/bcprov-jdk15on-1.70.jar;${lib}/junit-4.5.jar;${lib}/commons-codec-1.3.jar;${lib}/swing-layout-1.0.3.jar;${lib}/WaifUPnP.jar;${lib}/flatlaf-3.1.1.jar;${lib}/LGoodDatePicker-11.2.1.jar"/>
<property name="ivy.install.version" value="2.5.2"/>
<condition property="ivy.home" value="${env.IVY_HOME}">
<isset property="env.IVY_HOME"/>
@ -110,7 +110,7 @@
<zipfileset dir="${resources}" prefix="resources"/>
<manifest>
<attribute name="Main-Class" value="org.p2pvpn.Main"/>
<attribute name="Class-Path" value="${lib}/commons-jxpath-1.1.jar ${lib}/commons-logging-1.2.jar ${lib}/bcprov-jdk15on-1.70.jar ${lib}/commons-codec-1.3.jar ${lib}/swing-layout-1.0.3.jar ${lib}/WaifUPnP.jar ${lib}/flatlaf-3.1.1.jar"/>
<attribute name="Class-Path" value="${lib}/commons-jxpath-1.1.jar ${lib}/commons-logging-1.2.jar ${lib}/bcprov-jdk15on-1.70.jar ${lib}/commons-codec-1.3.jar ${lib}/swing-layout-1.0.3.jar ${lib}/WaifUPnP.jar ${lib}/flatlaf-3.1.1.jar ${lib}/LGoodDatePicker-11.2.1.jar"/>
</manifest>
</jar>
</target>

View file

@ -14,5 +14,6 @@
<dependency org="com.formdev" name="flatlaf" rev="3.1.1"/>
<dependency org="org.swinglabs" name="swing-layout" rev="1.0.3"/>
<dependency org="junit" name="junit" rev="4.5"/>
<dependency org="com.github.lgooddatepicker" name="LGoodDatePicker" rev="11.2.1"/>
</dependencies>
</ivy-module>

View file

@ -0,0 +1,86 @@
/*
Copyright 2023-2024 Nikolay Borodin <Monsterovich>
This file is part of Lanemu.
Lanemu is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Lanemu is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with Lanemu. If not, see <http://www.gnu.org/licenses/>.
*/
package org.p2pvpn.gui;
import com.github.lgooddatepicker.components.CalendarPanel;
import com.github.lgooddatepicker.zinternaltools.CustomPopup;
import com.github.lgooddatepicker.zinternaltools.CalendarSelectionEvent;
import com.github.lgooddatepicker.zinternaltools.YearMonthChangeEvent;
import com.github.lgooddatepicker.optionalusertools.CalendarListener;
import java.awt.Component;
import java.awt.Point;
import java.time.LocalDate;
import java.time.ZoneId;
import java.util.Date;
import javax.swing.JSpinner;
import javax.swing.SwingUtilities;
/**
* Calendar widget for the date entry field in InviteWindow.
* Uses internal library methods.
* @author monsterovich
*/
public class Calendar implements CalendarListener {
private final CalendarPanel calendarPanel;
private CustomPopup calendarPopup;
private final Component parentComponent;
private final JSpinner inputField;
public Calendar(Component component, JSpinner field) {
parentComponent = component;
inputField = field;
calendarPanel = new CalendarPanel();
calendarPanel.addCalendarListener(this);
}
void show() {
Date originalDate = (Date) inputField.getModel().getValue();
calendarPanel.setSelectedDate(originalDate.toInstant().atZone(ZoneId.systemDefault()).toLocalDate());
calendarPopup =
new CustomPopup(
calendarPanel,
SwingUtilities.getWindowAncestor(parentComponent),
null,
null);
Point pointOnScreen = new Point();
SwingUtilities.convertPointToScreen(pointOnScreen, parentComponent);
calendarPopup.setLocation(pointOnScreen.x, pointOnScreen.y + parentComponent.getHeight() + 1);
calendarPopup.show();
calendarPanel.requestFocus();
}
public void selectedDateChanged(CalendarSelectionEvent event) {
LocalDate calendarDate = event.getSource().getSelectedDate();
if (calendarDate != null && event.isDuplicate()) {
Date originalDate = (Date) inputField.getModel().getValue();
Date date = Date.from(calendarDate.atStartOfDay(ZoneId.systemDefault()).toInstant());
date.setHours(originalDate.getHours());
date.setMinutes(originalDate.getMinutes());
inputField.getModel().setValue(date);
calendarPopup.hide();
}
}
public void yearMonthChanged(YearMonthChangeEvent event) {
}
}

View file

@ -31,29 +31,35 @@
<Group type="102" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="1" attributes="0">
<EmptySpace min="0" pref="338" max="32767" attributes="0"/>
<Component id="btnClose" min="-2" max="-2" attributes="0"/>
</Group>
<Group type="102" alignment="0" attributes="0">
<Component id="lblDate" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<Component id="radDate" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="spnExpiryDate" pref="251" max="32767" attributes="0"/>
</Group>
<Component id="radNever" alignment="0" min="-2" max="-2" attributes="0"/>
</Group>
</Group>
<Group type="102" attributes="0">
<Group type="103" groupAlignment="0" attributes="0">
<Component id="chkNetwork" min="-2" max="-2" attributes="0"/>
<Component id="lblNote" alignment="0" min="-2" max="-2" attributes="0"/>
<Component id="btnGenerate" alignment="0" min="-2" max="-2" attributes="0"/>
<Group type="102" alignment="0" attributes="0">
<Component id="lblDate" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<Component id="radDate" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="spnExpiryDate" pref="262" max="32767" attributes="0"/>
</Group>
<Component id="radNever" alignment="0" min="-2" max="-2" attributes="0"/>
</Group>
</Group>
<Group type="102" attributes="0">
<Group type="103" groupAlignment="0" attributes="0">
<Component id="chkNetwork" min="-2" max="-2" attributes="0"/>
<Component id="lblNote" alignment="0" min="-2" max="-2" attributes="0"/>
<Component id="btnGenerate" alignment="0" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace min="0" pref="0" max="32767" attributes="0"/>
</Group>
</Group>
<EmptySpace max="-2" attributes="0"/>
<Component id="btnCalendar" min="-2" max="-2" attributes="0"/>
</Group>
<Group type="102" alignment="1" attributes="0">
<EmptySpace min="0" pref="0" max="32767" attributes="0"/>
<Component id="btnClose" min="-2" max="-2" attributes="0"/>
</Group>
</Group>
<EmptySpace max="-2" attributes="0"/>
@ -73,7 +79,10 @@
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="1" attributes="0">
<Component id="radDate" min="-2" max="-2" attributes="0"/>
<Component id="spnExpiryDate" min="-2" max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="spnExpiryDate" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="btnCalendar" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
</Group>
<EmptySpace max="-2" attributes="0"/>
<Component id="lblNote" min="-2" max="-2" attributes="0"/>
@ -204,5 +213,14 @@
</Property>
</Properties>
</Component>
<Component class="javax.swing.JButton" name="btnCalendar">
<Properties>
<Property name="text" type="java.lang.String" value="..."/>
<Property name="toolTipText" type="java.lang.String" value="Open calendar"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btnCalendarActionPerformed"/>
</Events>
</Component>
</SubComponents>
</Form>

View file

@ -1,6 +1,6 @@
/*
Copyright 2008, 2009 Wolfgang Ginolas
Copyright 2023 Nikolay Borodin <Monsterovich>
Copyright 2023-2024 Nikolay Borodin <Monsterovich>
This file is part of Lanemu.
@ -16,7 +16,7 @@
You should have received a copy of the GNU Lesser General Public License
along with Lanemu. If not, see <http://www.gnu.org/licenses/>.
*/
*/
package org.p2pvpn.gui;
import java.awt.Toolkit;
@ -39,6 +39,7 @@ import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPopupMenu;
import org.p2pvpn.tools.AdvProperties;
import org.p2pvpn.gui.Calendar;
/**
* This window is shown, when the user wants to invite another persion.
@ -49,6 +50,8 @@ public class InviteWindow extends javax.swing.JDialog implements ClipboardOwner
MainControl mainControl;
JFileChooser fileChooser;
Calendar calendar;
/**
* Creates new form InviteWindow
@ -77,6 +80,7 @@ public class InviteWindow extends javax.swing.JDialog implements ClipboardOwner
});
menu.add(mitem);
txtInvitation.setComponentPopupMenu(menu);
calendar = new Calendar(btnCalendar, spnExpiryDate);
}
/**
@ -110,6 +114,7 @@ public class InviteWindow extends javax.swing.JDialog implements ClipboardOwner
lblNote = new javax.swing.JLabel();
radNever = new javax.swing.JRadioButton();
radDate = new javax.swing.JRadioButton();
btnCalendar = new javax.swing.JButton();
setTitle("Generate Invitation");
@ -177,6 +182,14 @@ public class InviteWindow extends javax.swing.JDialog implements ClipboardOwner
grpDate.add(radDate);
btnCalendar.setText("...");
btnCalendar.setToolTipText("Open calendar");
btnCalendar.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnCalendarActionPerformed(evt);
}
});
org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
@ -185,24 +198,28 @@ public class InviteWindow extends javax.swing.JDialog implements ClipboardOwner
.add(layout.createSequentialGroup()
.addContainerGap()
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
.add(0, 338, Short.MAX_VALUE)
.add(btnClose))
.add(layout.createSequentialGroup()
.add(lblDate)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.add(radDate)
.add(lblDate)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(spnExpiryDate, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 251, Short.MAX_VALUE))
.add(radNever)))
.add(layout.createSequentialGroup()
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(chkNetwork)
.add(lblNote)
.add(btnGenerate))
.add(0, 0, Short.MAX_VALUE)))
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.add(radDate)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(spnExpiryDate, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 262, Short.MAX_VALUE))
.add(radNever)))
.add(layout.createSequentialGroup()
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(chkNetwork)
.add(lblNote)
.add(btnGenerate))
.add(0, 0, Short.MAX_VALUE)))
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(btnCalendar))
.add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
.add(0, 0, Short.MAX_VALUE)
.add(btnClose)))
.addContainerGap())
);
layout.setVerticalGroup(
@ -217,7 +234,9 @@ public class InviteWindow extends javax.swing.JDialog implements ClipboardOwner
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
.add(radDate)
.add(spnExpiryDate, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(spnExpiryDate, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(btnCalendar)))
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(lblNote)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
@ -232,6 +251,10 @@ public class InviteWindow extends javax.swing.JDialog implements ClipboardOwner
pack();
}// </editor-fold>//GEN-END:initComponents
private void btnCalendarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCalendarActionPerformed
calendar.show();
}//GEN-LAST:event_btnCalendarActionPerformed
private void btnCloseActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_btnCloseActionPerformed
setVisible(false);
}// GEN-LAST:event_btnCloseActionPerformed
@ -293,6 +316,7 @@ public class InviteWindow extends javax.swing.JDialog implements ClipboardOwner
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton btnCalendar;
private javax.swing.JButton btnClose;
private javax.swing.JButton btnGenerate;
private javax.swing.JButton btnSave;