files);
+
+ @Override
+ public void dragEnter(DropTargetDragEvent arg0) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void dragExit(DropTargetEvent arg0) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void dragOver(DropTargetDragEvent arg0) {
+ // TODO Auto-generated method stub
+
+ }
+
+
+
+ @Override
+ public void dropActionChanged(DropTargetDragEvent arg0) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void dragGestureRecognized(DragGestureEvent arg0) {
+ // TODO Auto-generated method stub
+
+ }
+
+}
diff --git a/src/main/java/com/github/oxygenPlugins/common/gui/swing/SwingUtil.java b/src/main/java/com/github/oxygenPlugins/common/gui/swing/SwingUtil.java
new file mode 100644
index 0000000..da7f6d3
--- /dev/null
+++ b/src/main/java/com/github/oxygenPlugins/common/gui/swing/SwingUtil.java
@@ -0,0 +1,68 @@
+package com.github.oxygenPlugins.common.gui.swing;
+
+import java.awt.Component;
+import java.awt.Container;
+import java.awt.Dimension;
+import java.awt.GridBagConstraints;
+import java.awt.GridBagLayout;
+import java.awt.Insets;
+import java.awt.Point;
+import java.awt.Rectangle;
+import java.awt.Toolkit;
+import java.awt.Window;
+
+
+public class SwingUtil {
+
+ public static void addComponent(final Container cont, final GridBagLayout gbl, final Component c, final int x, final int y,
+ final int width, final int height, final double weightx, final double weighty) {
+ addComponent(cont, gbl, c, x, y, width, height, weightx, weighty, GridBagConstraints.NORTH, GridBagConstraints.BOTH);
+ }
+
+ public static void addComponent(final Container cont, final GridBagLayout gbl, final Component c, final int x, final int y,
+ final int width, final int height, final double weightx, final double weighty, final int anchor, final int fill) {
+ addComponent(cont, gbl, c, x, y, width, height, weightx, weighty, anchor, fill, new Insets(0, 0, 0, 0));
+ }
+
+ public static void addComponent(final Container container, final GridBagLayout gbl, final Component c, final int x, final int y,
+ final int width, final int height, final double weightx, final double weighty, final int anchor, final int fill,
+ final Insets insets) {
+ final GridBagConstraints gbc = new GridBagConstraints();
+ gbc.fill = fill;
+ gbc.gridx = x;
+ gbc.gridy = y;
+ gbc.gridwidth = width;
+ gbc.gridheight = height;
+ gbc.weightx = weightx;
+ gbc.weighty = weighty;
+ gbc.anchor = anchor;
+ gbc.insets = insets;
+ gbl.setConstraints(c, gbc);
+ container.add(c);
+ }
+ public static void centerFrame(final Window frame) {
+ final Rectangle bounds = frame.getBounds();
+ final Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
+ bounds.x = (screen.width / 2) - (bounds.width / 2);
+ bounds.y = (screen.height / 2) - (bounds.height / 2);
+ frame.setBounds(bounds);
+ }
+
+// public static void centerFrame(final Window frame, final Window parentFrame) {
+// final Rectangle bounds = frame.getBounds();
+// final Rectangle parentBounds = parentFrame.getBounds();
+// bounds.x = (parentBounds.width / 2) - (bounds.width / 2) + parentBounds.x;
+// bounds.y = (parentBounds.height / 2) - (bounds.height / 2) + parentBounds.y;
+// frame.setBounds(bounds);
+// }
+//
+ public static void centerFrame(final Window frame, Window owner){
+ if(owner != null){
+ Point ownerLoc = owner.getLocation();
+ frame.setLocation(ownerLoc.x + (owner.getWidth() / 2) - (frame.getWidth() / 2),
+ ownerLoc.y + (owner.getHeight() / 2) - (frame.getHeight() / 2));
+ } else {
+ centerFrame(frame);
+ }
+ }
+}
diff --git a/src/main/java/com/github/oxygenPlugins/common/gui/swing/WrapLayout.java b/src/main/java/com/github/oxygenPlugins/common/gui/swing/WrapLayout.java
new file mode 100644
index 0000000..d51a471
--- /dev/null
+++ b/src/main/java/com/github/oxygenPlugins/common/gui/swing/WrapLayout.java
@@ -0,0 +1,198 @@
+package com.github.oxygenPlugins.common.gui.swing;
+import java.awt.Component;
+import java.awt.Container;
+import java.awt.Dimension;
+import java.awt.FlowLayout;
+import java.awt.Insets;
+
+import javax.swing.JScrollPane;
+import javax.swing.SwingUtilities;
+
+/**
+ * FlowLayout subclass that fully supports wrapping of components.
+ */
+public class WrapLayout extends FlowLayout
+{
+ private static final long serialVersionUID = 2439203958402278119L;
+// private Dimension preferredLayoutSize;
+
+ /**
+ * Constructs a new WrapLayout
with a left
+ * alignment and a default 5-unit horizontal and vertical gap.
+ */
+ public WrapLayout()
+ {
+ super();
+ }
+
+ /**
+ * Constructs a new FlowLayout
with the specified
+ * alignment and a default 5-unit horizontal and vertical gap.
+ * The value of the alignment argument must be one of
+ * WrapLayout
, WrapLayout
,
+ * or WrapLayout
.
+ * @param align the alignment value
+ */
+ public WrapLayout(int align)
+ {
+ super(align);
+ }
+
+ /**
+ * Creates a new flow layout manager with the indicated alignment
+ * and the indicated horizontal and vertical gaps.
+ *
+ * The value of the alignment argument must be one of
+ * WrapLayout
, WrapLayout
,
+ * or WrapLayout
.
+ * @param align the alignment value
+ * @param hgap the horizontal gap between components
+ * @param vgap the vertical gap between components
+ */
+ public WrapLayout(int align, int hgap, int vgap)
+ {
+ super(align, hgap, vgap);
+ }
+
+ /**
+ * Returns the preferred dimensions for this layout given the
+ * visible components in the specified target container.
+ * @param target the component which needs to be laid out
+ * @return the preferred dimensions to lay out the
+ * subcomponents of the specified container
+ */
+ @Override
+ public Dimension preferredLayoutSize(Container target)
+ {
+ return layoutSize(target, true);
+ }
+
+ /**
+ * Returns the minimum dimensions needed to layout the visible
+ * components contained in the specified target container.
+ * @param target the component which needs to be laid out
+ * @return the minimum dimensions to lay out the
+ * subcomponents of the specified container
+ */
+ @Override
+ public Dimension minimumLayoutSize(Container target)
+ {
+ Dimension minimum = layoutSize(target, false);
+ minimum.width -= (getHgap() + 1);
+ return minimum;
+ }
+
+ /**
+ * Returns the minimum or preferred dimension needed to layout the target
+ * container.
+ *
+ * @param target target to get layout size for
+ * @param preferred should preferred size be calculated
+ * @return the dimension to layout the target container
+ */
+ private Dimension layoutSize(Container target, boolean preferred)
+ {
+ synchronized (target.getTreeLock())
+ {
+ // Each row must fit with the width allocated to the containter.
+ // When the container width = 0, the preferred width of the container
+ // has not yet been calculated so lets ask for the maximum.
+
+ int targetWidth = target.getSize().width;
+ Container container = target;
+
+ while (container.getSize().width == 0 && container.getParent() != null)
+ {
+ container = container.getParent();
+ }
+
+ targetWidth = container.getSize().width;
+
+ if (targetWidth == 0)
+ targetWidth = Integer.MAX_VALUE;
+
+ int hgap = getHgap();
+ int vgap = getVgap();
+ Insets insets = target.getInsets();
+ int horizontalInsetsAndGap = insets.left + insets.right + (hgap * 2);
+ int maxWidth = targetWidth - horizontalInsetsAndGap;
+
+ // Fit components into the allowed width
+
+ Dimension dim = new Dimension(0, 0);
+ int rowWidth = 0;
+ int rowHeight = 0;
+
+ int nmembers = target.getComponentCount();
+
+ for (int i = 0; i < nmembers; i++)
+ {
+ Component m = target.getComponent(i);
+
+ if (m.isVisible())
+ {
+ Dimension d = preferred ? m.getPreferredSize() : m.getMinimumSize();
+
+ // Can't add the component to current row. Start a new row.
+
+ if (rowWidth + d.width > maxWidth)
+ {
+ addRow(dim, rowWidth, rowHeight);
+ rowWidth = 0;
+ rowHeight = 0;
+ }
+
+ // Add a horizontal gap for all components after the first
+
+ if (rowWidth != 0)
+ {
+ rowWidth += hgap;
+ }
+
+ rowWidth += d.width;
+ rowHeight = Math.max(rowHeight, d.height);
+ }
+ }
+
+ addRow(dim, rowWidth, rowHeight);
+
+ dim.width += horizontalInsetsAndGap;
+ dim.height += insets.top + insets.bottom + vgap * 2;
+
+ // When using a scroll pane or the DecoratedLookAndFeel we need to
+ // make sure the preferred size is less than the size of the
+ // target containter so shrinking the container size works
+ // correctly. Removing the horizontal gap is an easy way to do this.
+
+ Container scrollPane = SwingUtilities.getAncestorOfClass(JScrollPane.class, target);
+
+ if (scrollPane != null && target.isValid())
+ {
+ dim.width -= (hgap + 1);
+ }
+
+ return dim;
+ }
+ }
+
+ /*
+ * A new row has been completed. Use the dimensions of this row
+ * to update the preferred size for the container.
+ *
+ * @param dim update the width and height when appropriate
+ * @param rowWidth the width of the row to add
+ * @param rowHeight the height of the row to add
+ */
+ private void addRow(Dimension dim, int rowWidth, int rowHeight)
+ {
+ dim.width = Math.max(dim.width, rowWidth);
+
+ if (dim.height > 0)
+ {
+ dim.height += getVgap();
+ }
+
+ dim.height += rowHeight;
+ }
+}
+
diff --git a/src/main/java/com/github/oxygenPlugins/common/gui/types/BooleanVerifier.java b/src/main/java/com/github/oxygenPlugins/common/gui/types/BooleanVerifier.java
new file mode 100644
index 0000000..041d603
--- /dev/null
+++ b/src/main/java/com/github/oxygenPlugins/common/gui/types/BooleanVerifier.java
@@ -0,0 +1,35 @@
+package com.github.oxygenPlugins.common.gui.types;
+
+import java.awt.Container;
+
+import javax.swing.JFormattedTextField;
+
+import com.github.oxygenPlugins.common.gui.types.panels.BooleanPanel;
+import com.github.oxygenPlugins.common.gui.types.panels.BooleanPanel2;
+import com.github.oxygenPlugins.common.gui.types.panels.StringPanel;
+
+public class BooleanVerifier extends ValidCharVerifier {
+ public BooleanVerifier() {
+ this("");
+ }
+ public BooleanVerifier(String invalidStrings){
+ this(invalidStrings, "");
+ }
+ public BooleanVerifier(String invalidStrings, String invalidStarts){
+ super(invalidStrings, invalidStarts, false);
+ }
+
+ @Override
+ public void setVerifier(JFormattedTextField field, Container owner) {
+ BooleanPanel2 sp = new BooleanPanel2(field, owner);
+// field.removeFocusListener(sp);
+ field.addMouseListener(sp);
+// field.removeFocusListener(sp);
+// field.addFocusListener(sp);
+ super.setVerifier(field, owner);
+ }
+ @Override
+ public _Verifier getNewInstance() {
+ return new BooleanVerifier();
+ }
+}
diff --git a/src/main/java/com/github/oxygenPlugins/common/gui/types/CalendarTimeVerifier.java b/src/main/java/com/github/oxygenPlugins/common/gui/types/CalendarTimeVerifier.java
new file mode 100644
index 0000000..e0fbdb8
--- /dev/null
+++ b/src/main/java/com/github/oxygenPlugins/common/gui/types/CalendarTimeVerifier.java
@@ -0,0 +1,28 @@
+package com.github.oxygenPlugins.common.gui.types;
+
+import java.awt.Container;
+
+import javax.swing.JFormattedTextField;
+
+import com.github.oxygenPlugins.common.gui.types.panels.CalendarTimePanel2;
+
+public class CalendarTimeVerifier implements _Verifier {
+
+
+ @Override
+ public void setVerifier(JFormattedTextField field, Container owner) {
+ field.addMouseListener(new CalendarTimePanel2(field, 11, owner, true));
+ }
+
+ @Override
+ public _Verifier getNewInstance() {
+ // TODO Auto-generated method stub
+ return new CalendarTimeVerifier();
+ }
+
+ @Override
+ public void setVerifier(JFormattedTextField field, Container owner, boolean entryHelp) {
+ setVerifier(field, owner);
+ }
+
+}
diff --git a/src/main/java/com/github/oxygenPlugins/common/gui/types/CalendarVerifier.java b/src/main/java/com/github/oxygenPlugins/common/gui/types/CalendarVerifier.java
new file mode 100644
index 0000000..dedacc8
--- /dev/null
+++ b/src/main/java/com/github/oxygenPlugins/common/gui/types/CalendarVerifier.java
@@ -0,0 +1,28 @@
+package com.github.oxygenPlugins.common.gui.types;
+
+import java.awt.Container;
+
+import javax.swing.JFormattedTextField;
+
+import com.github.oxygenPlugins.common.gui.types.panels.CalendarPanel2;
+
+public class CalendarVerifier implements _Verifier {
+
+
+ @Override
+ public void setVerifier(JFormattedTextField field, Container owner) {
+ field.addMouseListener(new CalendarPanel2(field, 11, owner));
+ }
+
+ @Override
+ public _Verifier getNewInstance() {
+ // TODO Auto-generated method stub
+ return new CalendarVerifier();
+ }
+
+ @Override
+ public void setVerifier(JFormattedTextField field, Container owner, boolean entryHelp) {
+ setVerifier(field, owner);
+ }
+
+}
diff --git a/src/main/java/com/github/oxygenPlugins/common/gui/types/ColorVerifier.java b/src/main/java/com/github/oxygenPlugins/common/gui/types/ColorVerifier.java
new file mode 100644
index 0000000..c7f78ab
--- /dev/null
+++ b/src/main/java/com/github/oxygenPlugins/common/gui/types/ColorVerifier.java
@@ -0,0 +1,45 @@
+package com.github.oxygenPlugins.common.gui.types;
+
+
+import java.awt.Color;
+import java.awt.Container;
+import java.awt.event.KeyEvent;
+
+import javax.swing.JFormattedTextField;
+
+import com.github.oxygenPlugins.common.gui.types.panels.ColorPanel;
+
+public class ColorVerifier extends ValidCharVerifier {
+
+ public ColorVerifier() {
+ super("0123456789abcdefABCDEF", "");
+ }
+ @Override
+ public void setVerifier(JFormattedTextField field, Container owner) {
+ field.addMouseListener(new ColorPanel(field, owner));
+ super.setVerifier(field, owner);
+ }
+
+
+
+ public void keyReleased(KeyEvent keyEvent) {
+ super.keyTyped(keyEvent);
+ JFormattedTextField field = this.getField();
+ String code = field.getText();
+ Color c = field.getBackground();
+ if (code.replaceAll("[\\dabcdefABCDEF]", "").equals("")
+ && code.length() == 6) {
+ c = Color.decode("#" + code);
+ }
+ field.setBackground(c);
+ if(c.getRed()+ c.getGreen() * 1.5 < 334)
+ field.setForeground(Color.WHITE);
+ else
+ field.setForeground(Color.BLACK);
+ field.repaint();
+ }
+ @Override
+ public _Verifier getNewInstance() {
+ return new ColorVerifier();
+ }
+}
diff --git a/src/main/java/com/github/oxygenPlugins/common/gui/types/IntegerAreaVerifier.java b/src/main/java/com/github/oxygenPlugins/common/gui/types/IntegerAreaVerifier.java
new file mode 100644
index 0000000..d6d6699
--- /dev/null
+++ b/src/main/java/com/github/oxygenPlugins/common/gui/types/IntegerAreaVerifier.java
@@ -0,0 +1,90 @@
+package com.github.oxygenPlugins.common.gui.types;
+
+
+import java.awt.Container;
+import java.awt.event.KeyEvent;
+import java.awt.event.KeyListener;
+
+import javax.swing.JFormattedTextField;
+
+import com.github.oxygenPlugins.common.gui.types.panels.StringPanel;
+
+public class IntegerAreaVerifier implements _Verifier, KeyListener {
+
+ protected final char[] validChars = "0123456789".toCharArray();
+ private final int start;
+ private final int end;
+
+ protected JFormattedTextField field = new JFormattedTextField();
+ public IntegerAreaVerifier(int end) {
+ this(0, end);
+ }
+ public IntegerAreaVerifier(int start, int end) {
+ this.start = start;
+ this.end = end;
+
+ }
+
+
+
+ @Override
+ public void setVerifier(JFormattedTextField field, Container owner) {
+ this.field = field;
+ field.addKeyListener(this);
+ }
+ protected JFormattedTextField getField(){
+ return this.field;
+ }
+
+ public void keyReleased(KeyEvent ke) {}
+ public void keyTyped(KeyEvent keyEvent) {
+ // TODO Auto-generated method stub
+// int pos = field.getCaret().getMark();
+ int selStart = field.getSelectionStart();
+ int selEnd = field.getSelectionEnd();
+ char insert = keyEvent.getKeyChar();
+
+ boolean consume = true;
+ String newValue = field.getText();
+ newValue = newValue.substring(0, selStart) + keyEvent.getKeyChar() + newValue.substring(selEnd);
+
+ for (char valChar : this.validChars) {
+ if(valChar == insert){
+ consume = false;
+ break;
+ }
+ }
+ if(consume){
+ keyEvent.consume();
+ } else {
+ int newValInt = Integer.parseInt(newValue);
+ if(newValInt > end || newValInt < start){
+ keyEvent.consume();
+ }
+ }
+
+
+ System.out.println(newValue);
+// System.out.println("pos: " + pos);
+// System.out.println("selStart: " + selStart);
+// System.out.println("selEnd: " + selEnd);
+
+ }
+ @Override
+ public void keyPressed(KeyEvent arg0) {}
+
+ @Override
+ public _Verifier getNewInstance() {
+// if(this instanceof IntegerVerifier)
+// return new IntegerVerifier(String.copyValueOf(validChars), String.copyValueOf(startChars));
+ return new IntegerAreaVerifier(start, end);
+ }
+
+ @Override
+ public void setVerifier(JFormattedTextField field, Container owner, boolean entryHelp) {
+ if(entryHelp)
+ field.addMouseListener(new StringPanel(field, this, owner));
+ setVerifier(field, owner);
+ }
+
+}
diff --git a/src/main/java/com/github/oxygenPlugins/common/gui/types/IntegerVerifier.java b/src/main/java/com/github/oxygenPlugins/common/gui/types/IntegerVerifier.java
new file mode 100644
index 0000000..84ee439
--- /dev/null
+++ b/src/main/java/com/github/oxygenPlugins/common/gui/types/IntegerVerifier.java
@@ -0,0 +1,39 @@
+package com.github.oxygenPlugins.common.gui.types;
+
+
+import java.awt.Container;
+
+import javax.swing.JFormattedTextField;
+
+import com.github.oxygenPlugins.common.gui.types.panels.StringPanel;
+
+public class IntegerVerifier extends ValidCharVerifier {
+ private final static String digits = "0123456789";
+ public IntegerVerifier() {
+ this("");
+ }
+ public IntegerVerifier(String vddValidStrings){
+ this(digits + vddValidStrings, "");
+ }
+ public IntegerVerifier(String vddValidStrings, String startChars){
+ super(digits + vddValidStrings, startChars);
+ }
+
+ @Override
+ public void setVerifier(JFormattedTextField field, Container owner) {
+ setVerifier(field, owner, true);
+ }
+
+ @Override
+ public void setVerifier(JFormattedTextField field, Container owner, boolean entryHelp) {
+ if(entryHelp){
+ field.addMouseListener(new StringPanel(field, this, owner));
+ }
+ super.setVerifier(field, owner);
+ }
+
+ @Override
+ public _Verifier getNewInstance() {
+ return new IntegerVerifier(String.copyValueOf(validChars), String.copyValueOf(startChars));
+ }
+}
diff --git a/src/main/java/com/github/oxygenPlugins/common/gui/types/MultiChoiceVerifier.java b/src/main/java/com/github/oxygenPlugins/common/gui/types/MultiChoiceVerifier.java
new file mode 100644
index 0000000..1d2cb8c
--- /dev/null
+++ b/src/main/java/com/github/oxygenPlugins/common/gui/types/MultiChoiceVerifier.java
@@ -0,0 +1,31 @@
+package com.github.oxygenPlugins.common.gui.types;
+
+import java.awt.Container;
+
+import javax.swing.JFormattedTextField;
+
+import com.github.oxygenPlugins.common.gui.types.panels.BooleanPanel;
+import com.github.oxygenPlugins.common.gui.types.panels.BooleanPanel2;
+import com.github.oxygenPlugins.common.gui.types.panels.MultiChoicePanel;
+import com.github.oxygenPlugins.common.gui.types.panels.StringPanel;
+
+public class MultiChoiceVerifier extends ValidCharVerifier {
+ private final String[] values;
+ private final boolean isNullSelectable;
+ public MultiChoiceVerifier(String[] values, boolean isNullSelectable){
+ super("", "", false);
+ this.values = values;
+ this.isNullSelectable = isNullSelectable;
+ }
+
+ @Override
+ public void setVerifier(JFormattedTextField field, Container owner) {
+ MultiChoicePanel sp = new MultiChoicePanel(field, owner, this.values, this.isNullSelectable);
+ field.addMouseListener(sp);
+ super.setVerifier(field, owner);
+ }
+ @Override
+ public _Verifier getNewInstance() {
+ return new MultiChoiceVerifier(this.values, this.isNullSelectable);
+ }
+}
diff --git a/src/main/java/com/github/oxygenPlugins/common/gui/types/PassVerifier.java b/src/main/java/com/github/oxygenPlugins/common/gui/types/PassVerifier.java
new file mode 100644
index 0000000..c3b0f6c
--- /dev/null
+++ b/src/main/java/com/github/oxygenPlugins/common/gui/types/PassVerifier.java
@@ -0,0 +1,56 @@
+package com.github.oxygenPlugins.common.gui.types;
+
+import java.awt.Color;
+import java.awt.GridBagConstraints;
+import java.awt.GridBagLayout;
+import java.text.ParseException;
+import java.util.regex.Pattern;
+
+import javax.swing.InputVerifier;
+import javax.swing.JComponent;
+import javax.swing.JFormattedTextField;
+import javax.swing.JFrame;
+import javax.swing.JTextField;
+import javax.swing.UIManager;
+import javax.swing.UnsupportedLookAndFeelException;
+
+import com.github.oxygenPlugins.common.gui.swing.SwingUtil;
+import com.github.oxygenPlugins.common.gui.types.converter.TypeConverter;
+
+
+
+class PassVerifier extends InputVerifier {
+ public boolean verify(JComponent input) {
+ JTextField tf = (JTextField) input;
+ return Pattern.matches("\\d*", tf.getText());
+ }
+
+ public static void main(String[] args) throws ClassNotFoundException,
+ InstantiationException, IllegalAccessException,
+ UnsupportedLookAndFeelException, ParseException {
+ UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
+ JFrame frame = new JFrame("number");
+ JFormattedTextField stringField = new JFormattedTextField();
+ JFormattedTextField intField = new JFormattedTextField();
+ JFormattedTextField dateField = new JFormattedTextField();
+ VerifierFactory.addVerifier(new TypeConverter("abc"), stringField, frame);
+ VerifierFactory.addVerifier(new TypeConverter("int"), intField, frame);
+ VerifierFactory.addVerifier(new TypeConverter("date"), dateField, frame);
+
+
+
+ GridBagLayout gbl = new GridBagLayout();
+ frame.setLayout(gbl);
+ SwingUtil.addComponent(frame, gbl, stringField, 0, 0, 1, 1, 1.0, 1.0,
+ GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL);
+ SwingUtil.addComponent(frame, gbl, intField, 0, 1, 1, 1, 1.0, 1.0,
+ GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL);
+ SwingUtil.addComponent(frame, gbl, dateField, 0, 2, 1, 1, 1.0, 1.0,
+ GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL);
+ intField.getParent().setBackground(Color.WHITE);
+ intField.setInputVerifier(new PassVerifier());
+ frame.setSize(300, 400);
+ frame.setVisible(true);
+ frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+ }
+}
diff --git a/src/main/java/com/github/oxygenPlugins/common/gui/types/StringVerifier.java b/src/main/java/com/github/oxygenPlugins/common/gui/types/StringVerifier.java
new file mode 100644
index 0000000..68f7d4f
--- /dev/null
+++ b/src/main/java/com/github/oxygenPlugins/common/gui/types/StringVerifier.java
@@ -0,0 +1,33 @@
+package com.github.oxygenPlugins.common.gui.types;
+
+import java.awt.Container;
+
+import javax.swing.JFormattedTextField;
+
+import com.github.oxygenPlugins.common.gui.types.panels.StringPanel;
+
+public class StringVerifier extends ValidCharVerifier {
+ public StringVerifier() {
+ this("");
+ }
+ public StringVerifier(String invalidStrings){
+ this(invalidStrings, "");
+ }
+ public StringVerifier(String invalidStrings, String invalidStarts){
+ super(invalidStrings, invalidStarts, false);
+ }
+
+ @Override
+ public void setVerifier(JFormattedTextField field, Container owner) {
+ StringPanel sp = new StringPanel(field, owner);
+// field.removeFocusListener(sp);
+ field.addMouseListener(sp);
+// field.removeFocusListener(sp);
+// field.addFocusListener(sp);
+ super.setVerifier(field, owner);
+ }
+ @Override
+ public _Verifier getNewInstance() {
+ return new StringVerifier();
+ }
+}
diff --git a/src/main/java/com/github/oxygenPlugins/common/gui/types/TimeVerifier.java b/src/main/java/com/github/oxygenPlugins/common/gui/types/TimeVerifier.java
new file mode 100644
index 0000000..4d9e04d
--- /dev/null
+++ b/src/main/java/com/github/oxygenPlugins/common/gui/types/TimeVerifier.java
@@ -0,0 +1,28 @@
+package com.github.oxygenPlugins.common.gui.types;
+
+import java.awt.Container;
+
+import javax.swing.JFormattedTextField;
+
+import com.github.oxygenPlugins.common.gui.types.panels.TimePanel;
+
+public class TimeVerifier implements _Verifier {
+
+
+ @Override
+ public void setVerifier(JFormattedTextField field, Container owner) {
+ field.addMouseListener(new TimePanel(field, 11, owner));
+ }
+
+ @Override
+ public _Verifier getNewInstance() {
+ // TODO Auto-generated method stub
+ return new TimeVerifier();
+ }
+
+ @Override
+ public void setVerifier(JFormattedTextField field, Container owner, boolean entryHelp) {
+ setVerifier(field, owner);
+ }
+
+}
diff --git a/src/main/java/com/github/oxygenPlugins/common/gui/types/ValidCharVerifier.java b/src/main/java/com/github/oxygenPlugins/common/gui/types/ValidCharVerifier.java
new file mode 100644
index 0000000..401bd7f
--- /dev/null
+++ b/src/main/java/com/github/oxygenPlugins/common/gui/types/ValidCharVerifier.java
@@ -0,0 +1,88 @@
+package com.github.oxygenPlugins.common.gui.types;
+
+
+import java.awt.Container;
+import java.awt.event.KeyEvent;
+import java.awt.event.KeyListener;
+
+import javax.swing.JFormattedTextField;
+
+import com.github.oxygenPlugins.common.gui.types.panels.StringPanel;
+
+public class ValidCharVerifier implements _Verifier, KeyListener {
+ protected final char[] validChars;
+ protected final char[] startChars;
+ protected JFormattedTextField field = new JFormattedTextField();
+ private final boolean charsAreValid;
+ public ValidCharVerifier(String validStrings, String validStart) {
+ this(validStrings, validStart, true);
+ }
+ public ValidCharVerifier(String validStrings, String validStart, boolean charsAreValid) {
+ validChars = (validStrings + validStart).toCharArray();
+ this.startChars = validStart.toCharArray();
+ this.charsAreValid = charsAreValid;
+ }
+
+
+
+ @Override
+ public void setVerifier(JFormattedTextField field, Container owner) {
+ this.field = field;
+ field.addKeyListener(this);
+ }
+ protected JFormattedTextField getField(){
+ return this.field;
+ }
+ public void keyReleased(KeyEvent ke) {}
+ public void keyTyped(KeyEvent keyEvent) {
+ // TODO Auto-generated method stub
+ int pos = field.getCaret().getMark();
+ int selStart = field.getSelectionStart();
+ int selEnd = field.getSelectionEnd();
+ boolean consume = charsAreValid;
+ for (int i = 0; i < validChars.length; i++) {
+ if (validChars[i] == keyEvent.getKeyChar()) {
+ consume = !charsAreValid;
+ break;
+ }
+ }
+ if (pos != 0 && selStart != 0) {
+ for (int i = 0; i < startChars.length; i++) {
+ if (startChars[i] == keyEvent.getKeyChar()) {
+ consume = charsAreValid;
+ break;
+ }
+ }
+ }
+ if (pos == 0 && selEnd ==0){
+ char[] chars = field.getText().toCharArray();
+ for (int i = 0; i < startChars.length; i++) {
+
+ if (chars.length >0 && startChars[i] == chars[0]) {
+ consume = charsAreValid;
+ break;
+ }
+ }
+ }
+ if (consume)
+ keyEvent.consume();
+ }
+ @Override
+ public void keyPressed(KeyEvent arg0) {}
+
+ @Override
+ public _Verifier getNewInstance() {
+// if(this instanceof IntegerVerifier)
+// return new IntegerVerifier(String.copyValueOf(validChars), String.copyValueOf(startChars));
+ return new ValidCharVerifier(String.copyValueOf(validChars),
+ String.copyValueOf(startChars), charsAreValid);
+ }
+
+ @Override
+ public void setVerifier(JFormattedTextField field, Container owner, boolean entryHelp) {
+ if(entryHelp)
+ field.addMouseListener(new StringPanel(field, this, owner));
+ setVerifier(field, owner);
+ }
+
+}
diff --git a/src/main/java/com/github/oxygenPlugins/common/gui/types/VerifierFactory.java b/src/main/java/com/github/oxygenPlugins/common/gui/types/VerifierFactory.java
new file mode 100644
index 0000000..7e1cf7f
--- /dev/null
+++ b/src/main/java/com/github/oxygenPlugins/common/gui/types/VerifierFactory.java
@@ -0,0 +1,68 @@
+package com.github.oxygenPlugins.common.gui.types;
+
+import java.awt.Container;
+import java.util.HashMap;
+
+import javax.swing.JFormattedTextField;
+
+import com.github.oxygenPlugins.common.gui.types.converter.EnumTypeConverter;
+import com.github.oxygenPlugins.common.gui.types.converter.TypeConverter;
+
+
+public class VerifierFactory {
+ private static final String DEFAULT_TYPE = "xs:string";
+
+ public static _Verifier addVerifier(TypeConverter typeConverter, JFormattedTextField field, Container owner) {
+ return addVerifier(typeConverter, field, owner, true);
+ }
+
+ public static _Verifier addVerifier(EnumTypeConverter typeConv, JFormattedTextField field, Container owner, boolean entryHelp) {
+ MultiChoiceVerifier mcVerifier = new MultiChoiceVerifier(typeConv.getEnumValuesAsString(), false);
+ mcVerifier.setVerifier(field, owner, entryHelp);
+ return mcVerifier;
+ }
+ public static _Verifier addVerifier(TypeConverter typeConv, JFormattedTextField field, Container owner, boolean entryHelp) {
+ if(typeConv instanceof EnumTypeConverter){
+ return addVerifier((EnumTypeConverter) typeConv, field, owner, entryHelp);
+ }
+
+ String type = typeConv.getType();
+ type = type.replaceFirst("[\\?\\*\\+]$", "");
+ type = typeVerifierMap.containsKey(type) ? type : DEFAULT_TYPE;
+ if(typeVerifierMap.containsKey(type)){
+// field.setEditable(false);
+ _Verifier verifier = typeVerifierMap.get(type).getNewInstance();
+ verifier.setVerifier(field, owner, entryHelp);
+ return verifier;
+ }
+ return null;
+ }
+
+ @SuppressWarnings("unused")
+ private static String[] types = new String[] { "float", "double",
+ "boolean", "byte", "QName", "dateTime", "hexBinary",
+ "base64Binary", "hexBinary",
+ "unsignedByte", "time", "g", "anySimpleType", "duration",
+ "NOTATION" };
+ private static HashMap typeVerifierMap = new HashMap();
+ static {
+ typeVerifierMap.put(null, new StringVerifier());
+ typeVerifierMap.put("xs:string", new StringVerifier());
+ typeVerifierMap.put("xs:boolean", new BooleanVerifier());
+ typeVerifierMap.put("xs:int", new IntegerVerifier("","+-"));
+ typeVerifierMap.put("xs:integer", new IntegerVerifier("","+-"));
+ typeVerifierMap.put("xs:short", new IntegerVerifier("","+-"));
+ typeVerifierMap.put("xs:long", new IntegerVerifier("","+-"));
+ typeVerifierMap.put("xs:decimal", new IntegerVerifier(".","+-"));
+ typeVerifierMap.put("xs:unsignedInt", new IntegerVerifier("","+"));
+ typeVerifierMap.put("xs:unsignedShort", new IntegerVerifier("","+"));
+ typeVerifierMap.put("sqf:color", new ColorVerifier());
+ typeVerifierMap.put("xs:date", new CalendarVerifier());
+ typeVerifierMap.put("xs:dateTime", new CalendarTimeVerifier());
+ typeVerifierMap.put("xs:time", new TimeVerifier());
+ }
+
+ public static void installVerifier(String type, _Verifier verifier){
+ typeVerifierMap.put(type, verifier);
+ }
+}
diff --git a/src/main/java/com/github/oxygenPlugins/common/gui/types/_Verifier.java b/src/main/java/com/github/oxygenPlugins/common/gui/types/_Verifier.java
new file mode 100644
index 0000000..c8f6aee
--- /dev/null
+++ b/src/main/java/com/github/oxygenPlugins/common/gui/types/_Verifier.java
@@ -0,0 +1,11 @@
+package com.github.oxygenPlugins.common.gui.types;
+
+import java.awt.Container;
+
+import javax.swing.JFormattedTextField;
+
+public interface _Verifier {
+ public void setVerifier(JFormattedTextField field, Container owner);
+ public _Verifier getNewInstance();
+ void setVerifier(JFormattedTextField field, Container owner, boolean entryHelp);
+}
diff --git a/src/main/java/com/github/oxygenPlugins/common/gui/types/converter/EnumTypeConverter.java b/src/main/java/com/github/oxygenPlugins/common/gui/types/converter/EnumTypeConverter.java
new file mode 100644
index 0000000..dbf31d4
--- /dev/null
+++ b/src/main/java/com/github/oxygenPlugins/common/gui/types/converter/EnumTypeConverter.java
@@ -0,0 +1,42 @@
+package com.github.oxygenPlugins.common.gui.types.converter;
+
+import javax.xml.xpath.XPathExpressionException;
+
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+import com.nkutsche.common.xml.xpath.XPathReader;
+
+public class EnumTypeConverter extends TypeConverter {
+
+ private final Object[] enumValues;
+
+ public EnumTypeConverter(String type, NodeList values) {
+ super(type);
+ XPathReader xpathreader = new XPathReader();
+ // E N U M E R A T I O N
+ enumValues = new Object[values.getLength()];
+ for (int i = 0; i < values.getLength(); i++) {
+ Node enumVal = values.item(i);
+ try {
+ enumValues[i] = this.convertValue(xpathreader.getString(".", enumVal));
+ } catch (XPathExpressionException e) {
+ enumValues[i] = null;
+ }
+ }
+
+ }
+
+ public Object[] getEnumValues() {
+ return enumValues;
+ }
+
+ public String[] getEnumValuesAsString(){
+ String[] values = new String[enumValues.length];
+ int i = 0;
+ for (Object val : enumValues) {
+ values[i++] = this.convertToString(val);
+ }
+ return values;
+ }
+}
diff --git a/src/main/java/com/github/oxygenPlugins/common/gui/types/converter/TypeConverter.java b/src/main/java/com/github/oxygenPlugins/common/gui/types/converter/TypeConverter.java
new file mode 100644
index 0000000..e0f2d4a
--- /dev/null
+++ b/src/main/java/com/github/oxygenPlugins/common/gui/types/converter/TypeConverter.java
@@ -0,0 +1,112 @@
+package com.github.oxygenPlugins.common.gui.types.converter;
+
+import java.util.HashMap;
+
+import net.sf.saxon.trans.XPathException;
+import net.sf.saxon.type.ValidationException;
+import net.sf.saxon.value.DateTimeValue;
+import net.sf.saxon.value.DateValue;
+import net.sf.saxon.value.TimeValue;
+
+@SuppressWarnings("rawtypes")
+public class TypeConverter {
+ private String type;
+ public TypeConverter(String type) {
+ this.type = type;
+
+ }
+
+ public Object convertValue(String value){
+ Object result;
+ try{
+ if(value == null){
+ result = null;
+ } else if (type.equals("xs:dateTime")) {
+ result = getClass(type).cast(getDate(value));
+ } else if (type.equals("xs:time")) {
+ result = getClass(type).cast(getTime(value));
+ } else if (type.equals("xs:date")) {
+ result = getClass(type).cast(getDate(value));
+ } else if (type.equals("xs:dateTime")) {
+ result = getClass(type).cast(getDateTime(value));
+ } else if (type.equals("xs:integer")) {
+ int valInt = value.equals("") ? 0 : Integer.valueOf(value);
+ result = getClass(type).cast(valInt);
+ } else {
+ result = getClass(type).cast(value);
+ }
+ return result;
+ } catch(ClassCastException e){
+ return null;
+ }
+
+ }
+
+
+ private Class getClass(String type){
+ if(typeVerifierMap.containsKey(type)){
+ return typeVerifierMap.get(type);
+ } else {
+ return String.class;
+ }
+ }
+
+ private static Object getTime(String value){
+ return TimeValue.makeTimeValue(value);
+ }
+ private static DateTimeValue getDateTime(String value){
+ if(value.contains("T")){
+ String[] split = value.split("T");
+ try {
+ return DateTimeValue.makeDateTimeValue(getDate(split[0]), (TimeValue) getTime(split[1]));
+ } catch (XPathException e) {
+ }
+ }
+ return null;
+ }
+
+ private static DateValue getDate(String value){
+ try {
+ return new DateValue(value);
+ } catch (ValidationException e) {
+ return null;
+ }
+ }
+
+ private static HashMap typeVerifierMap = new HashMap();
+ static {
+ typeVerifierMap.put(null, String.class);
+ typeVerifierMap.put("xs:string", String.class);
+ typeVerifierMap.put("xs:int", Integer.class);
+ typeVerifierMap.put("xs:integer", Integer.class);
+ typeVerifierMap.put("xs:short", Double.class);
+ typeVerifierMap.put("xs:long", Double.class);
+ typeVerifierMap.put("xs:decimal", Double.class);
+ typeVerifierMap.put("xs:unsignedInt", Double.class);
+ typeVerifierMap.put("xs:unsignedShort", Double.class);
+ typeVerifierMap.put("sqf:color", String.class);
+ typeVerifierMap.put("xs:date", DateValue.class);
+ typeVerifierMap.put("xs:time", TimeValue.class);
+ typeVerifierMap.put("xs:dateTime", DateTimeValue.class);
+ }
+ public String convertToString(Object value) {
+ if (value instanceof DateValue) {
+ DateValue dv = (DateValue) value;
+ return dv.getPrimitiveStringValue().toString();
+ }
+ if (value instanceof TimeValue) {
+ TimeValue time = (TimeValue) value;
+ return time.getPrimitiveStringValue().toString();
+ }
+ if (value instanceof DateTimeValue) {
+ DateTimeValue dateTime = (DateTimeValue) value;
+ return dateTime.getPrimitiveStringValue().toString();
+ }
+ return value.toString();
+ }
+
+ public String getType(){
+ return this.type;
+ }
+
+}
diff --git a/src/main/java/com/github/oxygenPlugins/common/gui/types/panels/BooleanPanel.java b/src/main/java/com/github/oxygenPlugins/common/gui/types/panels/BooleanPanel.java
new file mode 100644
index 0000000..dafef85
--- /dev/null
+++ b/src/main/java/com/github/oxygenPlugins/common/gui/types/panels/BooleanPanel.java
@@ -0,0 +1,388 @@
+package com.github.oxygenPlugins.common.gui.types.panels;
+
+
+import java.awt.Color;
+import java.awt.Container;
+import java.awt.Dialog;
+import java.awt.Dimension;
+import java.awt.Frame;
+import java.awt.GridBagConstraints;
+import java.awt.GridBagLayout;
+import java.awt.Insets;
+import java.awt.Point;
+import java.awt.Window;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.FocusEvent;
+import java.awt.event.FocusListener;
+import java.awt.event.ItemEvent;
+import java.awt.event.ItemListener;
+import java.awt.event.KeyEvent;
+import java.awt.event.KeyListener;
+import java.awt.event.MouseEvent;
+import java.awt.event.MouseListener;
+import java.awt.event.WindowEvent;
+import java.awt.event.WindowFocusListener;
+import java.io.IOException;
+
+import javax.swing.BorderFactory;
+import javax.swing.Icon;
+import javax.swing.JButton;
+import javax.swing.JComboBox;
+import javax.swing.JDialog;
+import javax.swing.JFormattedTextField;
+import javax.swing.JFrame;
+import javax.swing.JPanel;
+import javax.swing.JTextField;
+import javax.swing.border.BevelBorder;
+import javax.swing.border.Border;
+
+import com.github.oxygenPlugins.common.gui.images.IconMap;
+import com.github.oxygenPlugins.common.gui.swing.SwingUtil;
+
+
+//
+public class BooleanPanel extends JPanel implements MouseListener, FocusListener {
+ private static final long serialVersionUID = 2661956887580911488L;
+ private final GridBagLayout gbl;
+
+ private final int minWidth = 100;
+ private final int minHeight = 0;
+
+ private final int maxHeight = 30;
+ private final int maxWidth = 0;
+
+ private JDialog dialog;
+// private final Border defaultBorder = BorderFactory.createBevelBorder(
+// BevelBorder.RAISED, new Color(240, 240, 240), new Color(150, 150,
+// 150));
+ private final Border outlineBorder = BorderFactory.createBevelBorder(
+ BevelBorder.LOWERED, new Color(110, 110, 110), new Color(200, 200,
+ 200));
+// private final Border selectBorder = BorderFactory.createBevelBorder(
+// BevelBorder.RAISED, new Color(30, 20, 120),
+// new Color(110, 100, 200));
+ private JFormattedTextField textField;
+
+ private static String[] VALUE_LABELS = new String[]{"", "true", "false"};
+ private static String[] VALUE_LABELS_WON = new String[]{"true", "false"};
+ private static int VALUE_NULL = 0;
+ private static int VALUE_TRUE = 1;
+ private static int VALUE_FALSE = 2;
+
+ private int value;
+ private final int initialValue;
+
+ private JComboBox entryBox;
+ private final Container owner;
+
+ private final JPanel buttonPanel = new JPanel();
+ private final JButton okBtn;
+ @SuppressWarnings("unused")
+ private final JButton cancelBtn;
+ private final JButton clearBtn;
+
+ private class PanelButton extends JButton{
+ private static final long serialVersionUID = 1699184718806511284L;
+ public PanelButton(Icon i){
+ this.setIcon(i);
+ Dimension dim = new Dimension(i.getIconWidth() + 1, i.getIconHeight() + 1);
+ this.setMinimumSize(dim);
+ this.setSize(dim);
+ }
+ public PanelButton(String text){
+ super(text);
+ }
+ }
+
+ public BooleanPanel(final JFormattedTextField field, Container owner) {
+ this.owner = owner;
+ this.textField = field;
+ textField.setHorizontalAlignment(JTextField.CENTER);
+ if(field.isEnabled()){
+ initialValue = field.getText().equals("true") ? VALUE_TRUE : VALUE_FALSE;
+ value = initialValue;
+ } else {
+ initialValue = VALUE_NULL;
+ value = VALUE_NULL;
+ }
+ setBorder(outlineBorder);
+ setBackground(Color.WHITE);
+ gbl = new GridBagLayout();
+ this.setLayout(gbl);
+
+ GridBagLayout buttonGbl = new GridBagLayout();
+ buttonPanel.setLayout(buttonGbl);
+ buttonPanel.setVisible(false);
+
+ if(IconMap.ICONS == null){
+ try {
+ IconMap.ICONS = new IconMap();
+ } catch (IOException e) {
+ }
+ }
+
+ if(IconMap.ICONS != null){
+ IconMap icons = IconMap.ICONS;
+ this.okBtn = new PanelButton(icons.getIcon(2, 10));
+ this.clearBtn = new PanelButton(icons.getIcon(10, 11));
+ this.cancelBtn = new PanelButton(icons.getIcon(0, 10));
+ } else {
+ this.okBtn = new PanelButton("ok");
+ this.clearBtn = new PanelButton("x");
+ this.cancelBtn = new PanelButton("c");
+ }
+
+ this.okBtn.addActionListener(new ActionListener() {
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ dispose();
+ }
+ });
+
+ this.clearBtn.addActionListener(new ActionListener() {
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ dispose(true);
+ }
+ });
+
+// this.okBtn.setVisible(false);
+// this.clearBtn.setVisible(false);
+// this.cancelBtn.setVisible(false);
+
+
+ entryBox = new JComboBox(value == VALUE_NULL ? VALUE_LABELS : VALUE_LABELS_WON);
+ entryBox.setSelectedIndex(value);
+ KeyListener[] kls = textField.getKeyListeners();
+ entryBox.addItemListener(new ItemListener() {
+
+ @Override
+ public void itemStateChanged(ItemEvent ie) {
+ if(dialog == null)
+ return;
+ if(dialog.isVisible()){
+ dispose();
+ }
+ }
+ });
+
+ entryBox.addKeyListener(new KeyListener() {
+ @Override
+ public void keyTyped(KeyEvent e) {}
+ @Override
+ public void keyReleased(KeyEvent e) {
+ if(e.getKeyChar()=='\n'){
+ dispose();
+ if (textField instanceof FocusTraversalField) {
+ FocusTraversalField focusField = (FocusTraversalField) textField;
+ focusField.nextFocus();
+ }
+ } else if(e.getKeyChar() == KeyEvent.VK_ESCAPE){
+ dispose(true);
+ if (textField instanceof FocusTraversalField) {
+ FocusTraversalField focusField = (FocusTraversalField) textField;
+ focusField.parentFocus();
+ }
+ } else if(e.getKeyChar() == KeyEvent.VK_TAB){
+ if(textField instanceof FocusTraversalField){
+ FocusTraversalField focusField = (FocusTraversalField) textField;
+
+ dispose();
+
+ if(e.isShiftDown()){
+ focusField.prevFocus();
+ } else {
+ focusField.nextFocus();
+ }
+ }
+ }
+ }
+ @Override
+ public void keyPressed(KeyEvent e) {}
+ });
+
+ if(textField instanceof FocusTraversalField){
+ textField.setFocusable(true);
+ entryBox.setFocusTraversalKeysEnabled(false);
+ ((FocusTraversalField) textField).removeAllFocusListener();
+ textField.addFocusListener(this);
+ }
+
+ SwingUtil.addComponent(this, gbl, entryBox,
+ 0, 0, 1, 1, 1.0, 1.0,
+ GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(3, 3, 3, 0));
+
+
+// SwingUtil.addComponent(this, gbl, okBtn,
+// 1, 0, 1, 1, 0.0, 1.0,
+// GridBagConstraints.NORTHEAST, GridBagConstraints.VERTICAL, new Insets(3, 0, 0, 3));
+
+
+// SwingUtil.addComponent(this, gbl, cancelBtn,
+// 1, 1, 1, 1, 0.0, 1.0,
+// GridBagConstraints.EAST, GridBagConstraints.VERTICAL, new Insets(0, 0, 0, 3));
+
+ SwingUtil.addComponent(this, gbl, clearBtn,
+ 1, 0, 1, 1, 0.0, 1.0,
+ GridBagConstraints.SOUTHEAST, GridBagConstraints.VERTICAL, new Insets(0, 0, 3, 3));
+
+
+ MouseListener ml = new MouseListener() {
+ @Override
+ public void mouseReleased(MouseEvent arg0) {}
+ @Override
+ public void mousePressed(MouseEvent arg0) {}
+ @Override
+ public void mouseExited(MouseEvent arg0) {
+
+// switchToField();
+ }
+ @Override
+ public void mouseEntered(MouseEvent arg0) {
+
+// switchToButtons();
+ }
+ @Override
+ public void mouseClicked(MouseEvent arg0) {
+ dispose();
+ }
+ };
+
+ addMouseListener(ml);
+ }
+
+
+
+ protected void setText() {
+ this.textField.setEnabled(true);
+ this.textField.setText(convert(this.entryBox.getSelectedIndex()));
+ textField.repaint();
+ }
+ private void getText() {
+ if(textField.isEnabled()){
+ value = convert(textField.getText());
+ } else {
+ value = VALUE_NULL;
+ }
+ entryBox.setSelectedItem(textField.getText());
+ }
+
+ private String convert(int value){
+ return VALUE_LABELS[value];
+ }
+ private int convert(String valueString){
+ int i = 0;
+ for (String label : VALUE_LABELS) {
+ if(valueString.equals(label))
+ return i;
+ i++;
+ }
+ return VALUE_NULL;
+ }
+
+ @Override
+ public void mouseClicked(MouseEvent e) {
+ // TODO Auto-generated method stub
+
+ }
+ @Override
+ public void mouseEntered(MouseEvent e) {
+
+ }
+ @Override
+ public void mouseExited(MouseEvent e) {
+ // TODO Auto-generated method stub
+
+ }
+ @Override
+ public void mousePressed(MouseEvent e) {
+ activate();
+ }
+ @Override
+ public void mouseReleased(MouseEvent e) {
+ // TODO Auto-generated method stub
+
+ }
+ private void activate(){
+// if (textField.isEnabled()) {
+// if (dialog != null) {
+// dispose();
+// }
+ this.getText();
+
+ if(dialog == null){
+ if(owner instanceof Dialog){
+ dialog = new JDialog((Dialog) owner);
+ } else if(owner instanceof Frame) {
+ dialog = new JDialog((Frame) owner);
+ } else if(owner instanceof Window) {
+ dialog = new JDialog((Window) owner);
+ } else {
+ dialog = new JDialog(new JFrame());
+ }
+ }
+ dialog.addWindowFocusListener(new WindowFocusListener() {
+
+ @Override
+ public void windowLostFocus(WindowEvent arg0) {
+ if(dialog != null)
+ dispose();
+ }
+
+ @Override
+ public void windowGainedFocus(WindowEvent arg0) {
+ }
+ });
+ dialog.setUndecorated(true);
+ dialog.setMinimumSize(new Dimension(minWidth, minHeight));
+ Point tfLoc = textField.getLocationOnScreen();
+ int finalWidth = textField.getWidth() * 2;
+ int finalHeight = textField.getHeight() * 2;
+
+ finalHeight = this.maxHeight > 0 && this.maxHeight < finalHeight ? this.maxHeight : finalHeight;
+ finalWidth = this.maxWidth > 0 && this.maxWidth < finalWidth ? this.maxWidth : finalWidth;
+
+ dialog.setMaximumSize(new Dimension(finalWidth, finalHeight));
+
+ dialog.setSize(finalWidth, finalHeight);
+ dialog.setLocation(new Point((int) (tfLoc.x - finalWidth * 0.25),
+ (int) (tfLoc.y - finalHeight * 0.25)));
+ dialog.add(this);
+ dialog.setModal(false);
+ dialog.setVisible(true);
+// }
+ }
+
+ private void dispose(){
+ dispose(false);
+ }
+ private void dispose(boolean unsetText){
+ if(unsetText){
+ if(initialValue != VALUE_NULL){
+ this.textField.setEnabled(true);
+ } else {
+ this.textField.setEnabled(false);
+ }
+ this.textField.setText(convert(initialValue));
+ this.textField.repaint();
+ } else {
+ this.setText();
+ }
+ if(dialog != null){
+ this.dialog.dispose();
+ this.dialog = null;
+ }
+ }
+
+ @Override
+ public void focusGained(FocusEvent arg0) {
+ if(dialog == null){
+// activate();
+ }
+ }
+ @Override
+ public void focusLost(FocusEvent arg0) {
+// dispose();
+ }
+}
diff --git a/src/main/java/com/github/oxygenPlugins/common/gui/types/panels/BooleanPanel2.java b/src/main/java/com/github/oxygenPlugins/common/gui/types/panels/BooleanPanel2.java
new file mode 100644
index 0000000..5f29b83
--- /dev/null
+++ b/src/main/java/com/github/oxygenPlugins/common/gui/types/panels/BooleanPanel2.java
@@ -0,0 +1,14 @@
+package com.github.oxygenPlugins.common.gui.types.panels;
+
+import java.awt.Container;
+
+import javax.swing.JFormattedTextField;
+
+public class BooleanPanel2 extends MultiChoicePanel {
+
+ public BooleanPanel2(JFormattedTextField field, Container owner) {
+ super(field, owner, new String[]{"true", "false"});
+ // TODO Auto-generated constructor stub
+ }
+
+}
diff --git a/src/main/java/com/github/oxygenPlugins/common/gui/types/panels/CalendarPanel2.java b/src/main/java/com/github/oxygenPlugins/common/gui/types/panels/CalendarPanel2.java
new file mode 100644
index 0000000..a0478a3
--- /dev/null
+++ b/src/main/java/com/github/oxygenPlugins/common/gui/types/panels/CalendarPanel2.java
@@ -0,0 +1,489 @@
+package com.github.oxygenPlugins.common.gui.types.panels;
+
+
+import java.awt.Color;
+import java.awt.Container;
+import java.awt.Dialog;
+import java.awt.Dimension;
+import java.awt.Font;
+import java.awt.Frame;
+import java.awt.GridBagConstraints;
+import java.awt.GridBagLayout;
+import java.awt.Insets;
+import java.awt.Point;
+import java.awt.Window;
+import java.awt.event.FocusEvent;
+import java.awt.event.FocusListener;
+import java.awt.event.MouseEvent;
+import java.awt.event.MouseListener;
+import java.awt.event.WindowEvent;
+import java.awt.event.WindowFocusListener;
+import java.io.IOException;
+import java.util.Locale;
+
+import javax.swing.BorderFactory;
+import javax.swing.Icon;
+import javax.swing.JDialog;
+import javax.swing.JFormattedTextField;
+import javax.swing.JFrame;
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+import javax.swing.JTextField;
+import javax.swing.border.BevelBorder;
+import javax.swing.border.Border;
+
+import org.joda.time.DateTime;
+import org.joda.time.format.DateTimeFormat;
+import org.joda.time.format.DateTimeFormatter;
+
+import com.github.oxygenPlugins.common.gui.images.IconMap;
+import com.github.oxygenPlugins.common.gui.swing.SwingUtil;
+
+
+public class CalendarPanel2 extends JPanel implements MouseListener {
+ private static final long serialVersionUID = -4261661006435142610L;
+ private final JDialog dialog;
+ private final JTextField textField;
+
+ private final Font defFont;
+
+ private final int padding;
+ private final GridBagLayout gbl = new GridBagLayout();
+
+ private final int minWidth;
+ private final int minHeight;
+ private JPanel contentPanel = new JPanel();
+
+ private final Border defaultBorder = BorderFactory.createBevelBorder(
+ BevelBorder.RAISED, new Color(240, 240, 240), new Color(150, 150,
+ 150));
+ private final Border greenBorder = BorderFactory.createBevelBorder(
+ BevelBorder.LOWERED, new Color(0, 110, 0), new Color(0, 200,
+ 0));
+ private final Border selectBorder = BorderFactory.createBevelBorder(
+ BevelBorder.RAISED, new Color(30, 20, 120),
+ new Color(110, 100, 200));
+
+ public CalendarPanel2(JFormattedTextField field, int fontSize, Container owner) {
+
+ if(owner instanceof Dialog){
+ dialog = new JDialog((Dialog) owner);
+ } else if(owner instanceof Frame) {
+ dialog = new JDialog((Frame) owner);
+ } else if(owner instanceof Window) {
+ dialog = new JDialog((Window) owner);
+ } else {
+ dialog = new JDialog(new JFrame());
+ }
+
+ this.textField = field;
+ Font defFont = new JLabel().getFont();
+ this.defFont = new Font(defFont.getName(), defFont.getStyle(), fontSize);
+
+ this.minWidth = 25 * fontSize;
+ this.minHeight = this.minWidth;
+ this.padding = (int) Math.round(fontSize * 0.75);
+ this.setLayout(gbl);
+
+ String text = this.textField.getText();
+ DateTime actuellDat = convert(text);
+ buildCalendar(actuellDat, actuellDat);
+
+ this.textField.setFocusable(true);
+ this.textField.addFocusListener(new FocusListener() {
+
+ @Override
+ public void focusLost(FocusEvent arg0) {
+// textField.setEnabled(false);
+ }
+
+ @Override
+ public void focusGained(FocusEvent arg0) {
+// textField.setEnabled(true);
+
+ System.out.println("hello calendar field!");
+ }
+ });
+ // this.setBackground(Color.RED);
+
+ dialog.addWindowFocusListener(new WindowFocusListener() {
+ @Override
+ public void windowLostFocus(WindowEvent arg0) {
+ dispose();
+ }
+
+ @Override
+ public void windowGainedFocus(WindowEvent arg0) {
+ }
+ });
+ dialog.addMouseListener(new MouseListener() {
+ @Override
+ public void mouseReleased(MouseEvent arg0) {
+ }
+
+ @Override
+ public void mousePressed(MouseEvent arg0) {
+ }
+
+ @Override
+ public void mouseExited(MouseEvent arg0) {
+ }
+
+ @Override
+ public void mouseEntered(MouseEvent arg0) {
+ }
+
+ @Override
+ public void mouseClicked(MouseEvent arg0) {
+ dispose();
+ }
+ });
+ dialog.setMinimumSize(new Dimension(minWidth, minHeight));
+ dialog.setUndecorated(true);
+ dialog.add(this);
+ }
+
+ private void dispose() {
+ this.dialog.dispose();
+ this.textField.setEnabled(true);
+ }
+
+ @Override
+ public void mouseClicked(MouseEvent e) {
+ if (this.dialog.isVisible()) {
+ dispose();
+ } else {
+ activate();
+ }
+ }
+
+
+
+ private void activate() {
+ String text = this.textField.getText();
+ DateTime actuellDat = convert(text);
+ buildCalendar(actuellDat, actuellDat);
+
+// dialog.setSize(textField.getWidth(), textField.getWidth());
+ dialog.setLocation(getDialogBounds());
+ // System.out.println(tfLoc.y);
+ dialog.setModal(false);
+ dialog.setVisible(true);
+// dialog.pack();
+ textField.setEnabled(false);
+ }
+
+ private Point getDialogBounds(){
+
+ Point tfLoc = textField.getLocationOnScreen();
+ Dimension screen = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
+
+ int x = tfLoc.x + textField.getWidth() - dialog.getWidth();
+ x = x < 0 ? 0 : x;
+
+ int y = tfLoc.y + textField.getHeight();
+ y = y < 0 ? 0 : y;
+
+ if((x + dialog.getWidth() ) > screen.width){
+ x = screen.width - dialog.getWidth();
+ }
+ if((y + dialog.getHeight()) > screen.height){
+ y = tfLoc.y - dialog.getHeight();
+ }
+
+ return new Point(x, y);
+ }
+
+
+ @Override
+ public void mouseEntered(MouseEvent e) {
+ }
+
+ @Override
+ public void mouseExited(MouseEvent e) {
+ }
+
+ @Override
+ public void mousePressed(MouseEvent e) {
+ }
+
+ @Override
+ public void mouseReleased(MouseEvent e) {
+ }
+
+ private void clear() {
+ this.remove(contentPanel);
+ }
+
+ private void buildCalendar(final DateTime actuell,
+ final DateTime selectedDate) {
+ clear();
+ this.setBorder(defaultBorder);
+ contentPanel = new JPanel();
+ contentPanel.setLayout(gbl);
+ contentPanel.setBackground(Color.WHITE);
+ contentPanel.setOpaque(true);
+ GridBagLayout gblRoot = new GridBagLayout();
+ this.setLayout(gblRoot);
+ SwingUtil.addComponent(this, gblRoot, contentPanel, 0, 0, 1, 1, 1.0, 1.0, GridBagConstraints.NORTHEAST, GridBagConstraints.BOTH);
+
+ JPanel head = buildHeader(actuell, selectedDate);
+ SwingUtil.addComponent(contentPanel, gbl, head, 0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.NORTHEAST, GridBagConstraints.BOTH);
+
+
+ JPanel body = new JPanel();
+ GridBagLayout gblBody = new GridBagLayout();
+ body.setLayout(gblBody);
+ body.setOpaque(false);
+ SwingUtil.addComponent(contentPanel, gbl, body, 0, 1, 1, 1, 1.0, 1.0, GridBagConstraints.NORTHEAST, GridBagConstraints.BOTH);
+
+ final int month = actuell.getMonthOfYear();
+ DateTime monthStart = actuell.minusDays(actuell.getDayOfMonth() - 1);
+ DateTime nextMonth = actuell.plusMonths(1);
+ DateTime monthEnd = nextMonth.minusDays(nextMonth.getDayOfMonth());
+
+ int weeks = monthEnd.getWeekOfWeekyear() - monthStart.getWeekOfWeekyear() + 1;
+
+ DateTime start = monthStart.minusDays(monthStart.getDayOfWeek() - 1);
+ DateTime end = monthEnd.plusDays(7 - monthEnd.getDayOfWeek());
+
+ weeks = weeks < 0 ? monthEnd.minusDays(monthEnd.getDayOfWeek()).getWeekOfWeekyear() - monthStart.getWeekOfWeekyear() + 2 : weeks;
+ if (weeks < 0) {
+ } else if (weeks < 5){
+ end = end.plusWeeks(1);
+ start = start.minusWeeks(1);
+ } else if(weeks < 6) {
+ if (monthStart.getDayOfWeek() - 1 > 7 - monthEnd.getDayOfWeek()){
+ end = end.plusWeeks(1);
+ } else {
+ start = start.minusWeeks(1);
+ }
+ }
+
+
+ for (int i = 0; i < 7; i++) {
+ String labelString = start.plusDays(i).toString(
+ DateTimeFormat.forPattern("E").withLocale(Locale.ENGLISH));
+ JLabel weekLabel = new JLabel(labelString.substring(0, 1));
+ weekLabel.setFont(defFont);
+ SwingUtil.addComponent(body, gblBody, weekLabel, i, 0, 1, 1,
+ 0.0, 0.0, GridBagConstraints.CENTER,
+ GridBagConstraints.NONE, new Insets(padding, padding, padding, padding));
+ }
+
+ int y = 1;
+ for (DateTime date = start; date.isBefore(end.plusDays(1)); date = date
+ .plusDays(1)) {
+ final DateTime finalDate = date;
+ final DateView label = new DateView(date, selectedDate, month){
+ private static final long serialVersionUID = 1L;
+ @Override
+ public void performAction() {
+ confirmDate(finalDate);
+ }
+ };
+
+ SwingUtil.addComponent(body, gblBody, label,
+ (date.getDayOfWeek() - 1), y, 1, 1, 1.0, 1.0,
+ GridBagConstraints.CENTER, GridBagConstraints.BOTH);
+ if (date.dayOfWeek().get() == 7)
+ y++;
+ }
+ this.contentPanel.repaint();
+ this.repaint();
+ this.updateUI();
+ }
+
+//
+// H E A D E R
+//
+ private JPanel buildHeader(final DateTime actuell, final DateTime selectedDate){
+ JPanel head = new JPanel();
+ GridBagLayout gblHead = new GridBagLayout();
+ head.setLayout(gblHead);
+ head.setOpaque(false);
+
+ IconMap icons = null;;
+ try {
+ icons = new IconMap();
+ } catch (IOException e) {
+ }
+
+ DateView yearMinus = new DateView(icons.getIcon(10, 13, true)) {
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public void performAction() {
+ buildCalendar(actuell.minusYears(1), selectedDate);
+ }
+ };
+ SwingUtil.addComponent(head, gblHead, yearMinus, 0, 0, 1, 1, 0.0,
+ 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE);
+
+ DateView yearPlus = new DateView(icons.getIcon(8, 13, true)) {
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public void performAction() {
+ buildCalendar(actuell.plusYears(1), selectedDate);
+ }
+ };
+ SwingUtil.addComponent(head, gblHead, yearPlus, 2, 0, 1, 1, 0.0,
+ 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE);
+
+ JLabel yearLabel = new JLabel(actuell.toString(DateTimeFormat
+ .forPattern("yyyy")));
+ yearLabel.setFont(defFont);
+ yearLabel.setHorizontalAlignment(JLabel.CENTER);
+ SwingUtil.addComponent(head, gblHead, yearLabel, 1, 0, 1, 1, 1.0,
+ 1.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL);
+
+
+
+ DateView monthMinus = new DateView(icons.getIcon(2, 13, true)) {
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public void performAction() {
+ buildCalendar(actuell.minusMonths(1), selectedDate);
+ }
+ };
+ SwingUtil.addComponent(head, gblHead, monthMinus, 0, 1, 1, 1, 0.0,
+ 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE);
+
+ DateView monthPlus = new DateView(icons.getIcon(0, 13, true)) {
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public void performAction() {
+ buildCalendar(actuell.plusMonths(1), selectedDate);
+ }
+ };
+ SwingUtil.addComponent(head, gblHead, monthPlus, 2, 1, 1, 1, 0.0,
+ 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE);
+
+ JLabel monthLabel = new JLabel(actuell.toString(DateTimeFormat
+ .forPattern("MMMM").withLocale(Locale.ENGLISH)));
+ monthLabel.setFont(defFont);
+ monthLabel.setHorizontalAlignment(JLabel.CENTER);
+ monthLabel.setBackground(Color.WHITE);
+ monthLabel.setOpaque(true);
+ SwingUtil.addComponent(head, gblHead, monthLabel, 1, 1, 1, 1, 1.0,
+ 1.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL);
+
+
+
+ return head;
+ }
+
+ private abstract class DateView extends JPanel {
+ private static final long serialVersionUID = 1L;
+ private final JLabel label;
+ private Color foreground;
+ private Color background = Color.WHITE;
+ private Border defaultBorder = CalendarPanel2.this.defaultBorder;
+
+ private DateView(int padding){
+ this.label = new JLabel();
+ this.foreground = Color.BLACK;
+ this.label.setAlignmentX(JLabel.CENTER_ALIGNMENT);
+ this.label.setAlignmentY(JLabel.CENTER_ALIGNMENT);
+
+ DateView.this.setSelect(false);
+
+ this.label.setFont(defFont);
+ Insets insets = new Insets(padding, padding, padding, padding);
+ JPanel labelPanel = new JPanel();
+ labelPanel.add(label);
+ SwingUtil.addComponent(this, gbl, label, 0, 0, 1, 1, 1.0, 1.0,
+ GridBagConstraints.CENTER, GridBagConstraints.NONE,
+ insets);
+ addMouseListener(new MouseListener() {
+ @Override
+ public void mouseReleased(MouseEvent arg0) {}
+ @Override
+ public void mousePressed(MouseEvent arg0) {}
+ @Override
+ public void mouseExited(MouseEvent arg0) {
+ DateView.this.setSelect(false);
+ }
+ @Override
+ public void mouseEntered(MouseEvent arg0) {
+ DateView.this.setSelect(true);
+ }
+ @Override
+ public void mouseClicked(MouseEvent arg0) {
+ DateView.this.setSelect(false);
+ performAction();
+ }
+ });
+
+ }
+
+ private DateView(String labelString){
+ this(100);
+ this.label.setText(labelString);
+ }
+
+ private DateView(Icon icon){
+ this(0);
+ this.label.setIcon(icon);
+// this.label.setBackground(Color.YELLOW);
+// this.label.setOpaque(true);
+ }
+
+ private DateView(DateTime date,
+ DateTime selectedDate, int month) {
+ this("" + date.getDayOfMonth());
+ this.foreground = date.getMonthOfYear() == month ? foreground
+ : Color.GRAY;
+
+ GridBagLayout gbl = new GridBagLayout();
+ this.setLayout(gbl);
+
+ this.label.setFont(defFont);
+
+ if(date.isEqual(selectedDate)){
+ this.defaultBorder = CalendarPanel2.this.greenBorder;
+ }
+
+ setSelect(false);
+
+ }
+
+ public abstract void performAction();
+
+ private void setSelect(boolean isSelect) {
+ if (isSelect) {
+ this.setBorder(selectBorder);
+ setBackground(new Color(205, 225, 225));
+// this.label.setForeground(Color.WHITE);
+ } else {
+ this.setBorder(this.defaultBorder);
+ setBackground(this.background);
+ this.label.setForeground(this.foreground);
+ }
+ this.setOpaque(true);
+ }
+ }
+
+ private void confirmDate(DateTime date) {
+ this.textField.setText(convert(date));
+ dispose();
+ }
+
+ static DateTimeFormatter FMT = DateTimeFormat.forPattern("yyyy-MM-dd");
+
+ private static String convert(DateTime date) {
+ return date.toString(FMT);
+ }
+
+ private static DateTime convert(String string) {
+ try {
+ return DateTime.parse(string, FMT);
+ } catch (IllegalArgumentException e) {
+ return new DateTime();
+ }
+ }
+
+}
diff --git a/src/main/java/com/github/oxygenPlugins/common/gui/types/panels/CalendarTimePanel2.java b/src/main/java/com/github/oxygenPlugins/common/gui/types/panels/CalendarTimePanel2.java
new file mode 100644
index 0000000..8a17c94
--- /dev/null
+++ b/src/main/java/com/github/oxygenPlugins/common/gui/types/panels/CalendarTimePanel2.java
@@ -0,0 +1,471 @@
+package com.github.oxygenPlugins.common.gui.types.panels;
+
+
+import java.awt.Color;
+import java.awt.Container;
+import java.awt.Dialog;
+import java.awt.Dimension;
+import java.awt.Font;
+import java.awt.Frame;
+import java.awt.GridBagConstraints;
+import java.awt.GridBagLayout;
+import java.awt.Insets;
+import java.awt.Point;
+import java.awt.Window;
+import java.awt.event.MouseEvent;
+import java.awt.event.MouseListener;
+import java.awt.event.WindowEvent;
+import java.awt.event.WindowFocusListener;
+import java.io.IOException;
+import java.util.Locale;
+
+import javax.swing.BorderFactory;
+import javax.swing.Icon;
+import javax.swing.JDialog;
+import javax.swing.JFormattedTextField;
+import javax.swing.JFrame;
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+import javax.swing.JTextField;
+import javax.swing.border.BevelBorder;
+import javax.swing.border.Border;
+
+import org.joda.time.DateTime;
+import org.joda.time.format.DateTimeFormat;
+import org.joda.time.format.DateTimeFormatter;
+
+import com.github.oxygenPlugins.common.gui.images.IconMap;
+import com.github.oxygenPlugins.common.gui.swing.SwingUtil;
+
+
+
+public class CalendarTimePanel2 extends JPanel implements MouseListener {
+ private static final long serialVersionUID = -4261661006435142610L;
+ private final JDialog dialog;
+ private final JTextField textField;
+
+ private final Font defFont;
+
+ private final int padding;
+ private final GridBagLayout gbl = new GridBagLayout();
+
+ private final int minWidth;
+ private final int minHeight;
+ private JPanel contentPanel = new JPanel();
+
+ private final Border defaultBorder = BorderFactory.createBevelBorder(
+ BevelBorder.RAISED, new Color(240, 240, 240), new Color(150, 150,
+ 150));
+ private final Border greenBorder = BorderFactory.createBevelBorder(
+ BevelBorder.LOWERED, new Color(0, 110, 0), new Color(0, 200,
+ 0));
+ private final Border selectBorder = BorderFactory.createBevelBorder(
+ BevelBorder.RAISED, new Color(30, 20, 120),
+ new Color(110, 100, 200));
+
+ public CalendarTimePanel2(JFormattedTextField field, int fontSize, Container owner) {
+ this(field, fontSize, owner, false);
+ }
+ public CalendarTimePanel2(JFormattedTextField field, int fontSize, Container owner, boolean hasTime) {
+
+ if(owner instanceof Dialog){
+ dialog = new JDialog((Dialog) owner);
+ } else if(owner instanceof Frame) {
+ dialog = new JDialog((Frame) owner);
+ } else if(owner instanceof Window) {
+ dialog = new JDialog((Window) owner);
+ } else {
+ dialog = new JDialog(new JFrame());
+ }
+
+ this.textField = field;
+ Font defFont = new JLabel().getFont();
+ this.defFont = new Font(defFont.getName(), defFont.getStyle(), fontSize);
+
+ this.minWidth = 25 * fontSize;
+ this.minHeight = this.minWidth + (2 * fontSize);
+ this.padding = (int) Math.round(fontSize * 0.75);
+ this.setLayout(gbl);
+
+ String text = this.textField.getText();
+ DateTime actuellDat = convert(text);
+ buildCalendar(actuellDat, actuellDat);
+
+ // this.setBackground(Color.RED);
+
+ dialog.addWindowFocusListener(new WindowFocusListener() {
+ @Override
+ public void windowLostFocus(WindowEvent arg0) {
+ dispose();
+ }
+
+ @Override
+ public void windowGainedFocus(WindowEvent arg0) {
+ }
+ });
+ dialog.addMouseListener(new MouseListener() {
+ @Override
+ public void mouseReleased(MouseEvent arg0) {
+ }
+
+ @Override
+ public void mousePressed(MouseEvent arg0) {
+ }
+
+ @Override
+ public void mouseExited(MouseEvent arg0) {
+ }
+
+ @Override
+ public void mouseEntered(MouseEvent arg0) {
+ }
+
+ @Override
+ public void mouseClicked(MouseEvent arg0) {
+ dispose();
+ }
+ });
+ dialog.setMinimumSize(new Dimension(minWidth, minHeight));
+ dialog.setUndecorated(true);
+ dialog.add(this);
+ }
+
+ private void dispose() {
+ this.dialog.dispose();
+ this.textField.setEnabled(true);
+ }
+
+ @Override
+ public void mouseClicked(MouseEvent e) {
+ if (textField.isEnabled()) {
+
+ String text = this.textField.getText();
+ DateTime actuellDat = convert(text);
+ buildCalendar(actuellDat, actuellDat);
+
+// dialog.setSize(textField.getWidth(), textField.getWidth());
+ dialog.setLocation(getDialogBounds());
+ // System.out.println(tfLoc.y);
+ dialog.setModal(false);
+ dialog.setVisible(true);
+// dialog.pack();
+ textField.setEnabled(false);
+ } else {
+ dispose();
+ }
+ }
+
+ private Point getDialogBounds(){
+
+ Point tfLoc = textField.getLocationOnScreen();
+ Dimension screen = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
+
+ int x = tfLoc.x + textField.getWidth() - dialog.getWidth();
+ x = x < 0 ? 0 : x;
+
+ int y = tfLoc.y + textField.getHeight();
+ y = y < 0 ? 0 : y;
+
+ if((x + dialog.getWidth() ) > screen.width){
+ x = screen.width - dialog.getWidth();
+ }
+ if((y + dialog.getHeight()) > screen.height){
+ y = tfLoc.y - dialog.getHeight();
+ }
+
+ return new Point(x, y);
+ }
+
+
+ @Override
+ public void mouseEntered(MouseEvent e) {
+ }
+
+ @Override
+ public void mouseExited(MouseEvent e) {
+ }
+
+ @Override
+ public void mousePressed(MouseEvent e) {
+ }
+
+ @Override
+ public void mouseReleased(MouseEvent e) {
+ }
+
+ private void clear() {
+ this.remove(contentPanel);
+ }
+
+ private void buildCalendar(final DateTime actuell,
+ final DateTime selectedDate) {
+ clear();
+ this.setBorder(defaultBorder);
+ contentPanel = new JPanel();
+ contentPanel.setLayout(gbl);
+ contentPanel.setBackground(Color.WHITE);
+ contentPanel.setOpaque(true);
+ GridBagLayout gblRoot = new GridBagLayout();
+ this.setLayout(gblRoot);
+ SwingUtil.addComponent(this, gblRoot, contentPanel, 0, 0, 1, 1, 1.0, 1.0, GridBagConstraints.NORTHEAST, GridBagConstraints.BOTH);
+
+ JPanel head = buildHeader(actuell, selectedDate);
+ SwingUtil.addComponent(contentPanel, gbl, head, 0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.NORTHEAST, GridBagConstraints.BOTH);
+
+
+ JPanel body = new JPanel();
+ GridBagLayout gblBody = new GridBagLayout();
+ body.setLayout(gblBody);
+ body.setOpaque(false);
+ SwingUtil.addComponent(contentPanel, gbl, body, 0, 1, 1, 1, 1.0, 1.0, GridBagConstraints.NORTHEAST, GridBagConstraints.BOTH);
+
+ final int month = actuell.getMonthOfYear();
+ DateTime monthStart = actuell.minusDays(actuell.getDayOfMonth() - 1);
+ DateTime nextMonth = actuell.plusMonths(1);
+ DateTime monthEnd = nextMonth.minusDays(nextMonth.getDayOfMonth());
+
+ int weeks = monthEnd.getWeekOfWeekyear() - monthStart.getWeekOfWeekyear() + 1;
+
+ DateTime start = monthStart.minusDays(monthStart.getDayOfWeek() - 1);
+ DateTime end = monthEnd.plusDays(7 - monthEnd.getDayOfWeek());
+
+ weeks = weeks < 0 ? monthEnd.minusDays(monthEnd.getDayOfWeek()).getWeekOfWeekyear() - monthStart.getWeekOfWeekyear() + 2 : weeks;
+ if (weeks < 0) {
+ } else if (weeks < 5){
+ end = end.plusWeeks(1);
+ start = start.minusWeeks(1);
+ } else if(weeks < 6) {
+ if (monthStart.getDayOfWeek() - 1 > 7 - monthEnd.getDayOfWeek()){
+ end = end.plusWeeks(1);
+ } else {
+ start = start.minusWeeks(1);
+ }
+ }
+
+
+ for (int i = 0; i < 7; i++) {
+ String labelString = start.plusDays(i).toString(
+ DateTimeFormat.forPattern("E").withLocale(Locale.ENGLISH));
+ JLabel weekLabel = new JLabel(labelString.substring(0, 1));
+ weekLabel.setFont(defFont);
+ SwingUtil.addComponent(body, gblBody, weekLabel, i, 0, 1, 1,
+ 0.0, 0.0, GridBagConstraints.CENTER,
+ GridBagConstraints.NONE, new Insets(padding, padding, padding, padding));
+ }
+
+ int y = 1;
+ for (DateTime date = start; date.isBefore(end.plusDays(1)); date = date
+ .plusDays(1)) {
+ final DateTime finalDate = date;
+ final DateView label = new DateView(date, selectedDate, month){
+ private static final long serialVersionUID = 1L;
+ @Override
+ public void performAction() {
+ confirmDate(finalDate);
+ }
+ };
+
+ SwingUtil.addComponent(body, gblBody, label,
+ (date.getDayOfWeek() - 1), y, 1, 1, 1.0, 1.0,
+ GridBagConstraints.CENTER, GridBagConstraints.BOTH);
+ if (date.dayOfWeek().get() == 7)
+ y++;
+ }
+ this.contentPanel.repaint();
+ this.repaint();
+ this.updateUI();
+ }
+
+//
+// H E A D E R
+//
+ private JPanel buildHeader(final DateTime actuell, final DateTime selectedDate){
+ JPanel head = new JPanel();
+ GridBagLayout gblHead = new GridBagLayout();
+ head.setLayout(gblHead);
+ head.setOpaque(false);
+
+ IconMap icons = null;;
+ try {
+ icons = new IconMap();
+ } catch (IOException e) {
+ }
+
+ DateView yearMinus = new DateView(icons.getIcon(10, 13, true)) {
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public void performAction() {
+ buildCalendar(actuell.minusYears(1), selectedDate);
+ }
+ };
+ SwingUtil.addComponent(head, gblHead, yearMinus, 0, 0, 1, 1, 0.0,
+ 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE);
+
+ DateView yearPlus = new DateView(icons.getIcon(8, 13, true)) {
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public void performAction() {
+ buildCalendar(actuell.plusYears(1), selectedDate);
+ }
+ };
+ SwingUtil.addComponent(head, gblHead, yearPlus, 2, 0, 1, 1, 0.0,
+ 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE);
+
+ JLabel yearLabel = new JLabel(actuell.toString(DateTimeFormat
+ .forPattern("yyyy")));
+ yearLabel.setFont(defFont);
+ yearLabel.setHorizontalAlignment(JLabel.CENTER);
+ SwingUtil.addComponent(head, gblHead, yearLabel, 1, 0, 1, 1, 1.0,
+ 1.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL);
+
+
+
+ DateView monthMinus = new DateView(icons.getIcon(2, 13, true)) {
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public void performAction() {
+ buildCalendar(actuell.minusMonths(1), selectedDate);
+ }
+ };
+ SwingUtil.addComponent(head, gblHead, monthMinus, 0, 1, 1, 1, 0.0,
+ 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE);
+
+ DateView monthPlus = new DateView(icons.getIcon(0, 13, true)) {
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public void performAction() {
+ buildCalendar(actuell.plusMonths(1), selectedDate);
+ }
+ };
+ SwingUtil.addComponent(head, gblHead, monthPlus, 2, 1, 1, 1, 0.0,
+ 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE);
+
+ JLabel monthLabel = new JLabel(actuell.toString(DateTimeFormat
+ .forPattern("MMMM").withLocale(Locale.ENGLISH)));
+ monthLabel.setFont(defFont);
+ monthLabel.setHorizontalAlignment(JLabel.CENTER);
+ monthLabel.setBackground(Color.WHITE);
+ monthLabel.setOpaque(true);
+ SwingUtil.addComponent(head, gblHead, monthLabel, 1, 1, 1, 1, 1.0,
+ 1.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL);
+
+
+
+ return head;
+ }
+
+ private abstract class DateView extends JPanel {
+ private static final long serialVersionUID = 1L;
+ private final JLabel label;
+ private Color foreground;
+ private Color background = Color.WHITE;
+ private Border defaultBorder = CalendarTimePanel2.this.defaultBorder;
+
+ private DateView(int padding){
+ this.label = new JLabel();
+ this.foreground = Color.BLACK;
+ this.label.setAlignmentX(JLabel.CENTER_ALIGNMENT);
+ this.label.setAlignmentY(JLabel.CENTER_ALIGNMENT);
+
+ DateView.this.setSelect(false);
+
+ this.label.setFont(defFont);
+ Insets insets = new Insets(padding, padding, padding, padding);
+ JPanel labelPanel = new JPanel();
+ labelPanel.add(label);
+ SwingUtil.addComponent(this, gbl, label, 0, 0, 1, 1, 1.0, 1.0,
+ GridBagConstraints.CENTER, GridBagConstraints.NONE,
+ insets);
+ addMouseListener(new MouseListener() {
+ @Override
+ public void mouseReleased(MouseEvent arg0) {}
+ @Override
+ public void mousePressed(MouseEvent arg0) {}
+ @Override
+ public void mouseExited(MouseEvent arg0) {
+ DateView.this.setSelect(false);
+ }
+ @Override
+ public void mouseEntered(MouseEvent arg0) {
+ DateView.this.setSelect(true);
+ }
+ @Override
+ public void mouseClicked(MouseEvent arg0) {
+ DateView.this.setSelect(false);
+ performAction();
+ }
+ });
+
+ }
+
+ private DateView(String labelString){
+ this(100);
+ this.label.setText(labelString);
+ }
+
+ private DateView(Icon icon){
+ this(0);
+ this.label.setIcon(icon);
+// this.label.setBackground(Color.YELLOW);
+// this.label.setOpaque(true);
+ }
+
+ private DateView(DateTime date,
+ DateTime selectedDate, int month) {
+ this("" + date.getDayOfMonth());
+ this.foreground = date.getMonthOfYear() == month ? foreground
+ : Color.GRAY;
+
+ GridBagLayout gbl = new GridBagLayout();
+ this.setLayout(gbl);
+
+ this.label.setFont(defFont);
+
+ if(date.isEqual(selectedDate)){
+ this.defaultBorder = CalendarTimePanel2.this.greenBorder;
+ }
+
+ setSelect(false);
+
+ }
+
+ public abstract void performAction();
+
+ private void setSelect(boolean isSelect) {
+ if (isSelect) {
+ this.setBorder(selectBorder);
+ setBackground(new Color(205, 225, 225));
+// this.label.setForeground(Color.WHITE);
+ } else {
+ this.setBorder(this.defaultBorder);
+ setBackground(this.background);
+ this.label.setForeground(this.foreground);
+ }
+ this.setOpaque(true);
+ }
+ }
+
+ private void confirmDate(DateTime date) {
+ this.textField.setText(convert(date));
+ dispose();
+ }
+
+ static DateTimeFormatter FMT = DateTimeFormat.forPattern("yyyy-MM-dd");
+
+ private static String convert(DateTime date) {
+ return date.toString(FMT);
+ }
+
+ private static DateTime convert(String string) {
+ try {
+ return DateTime.parse(string, FMT);
+ } catch (IllegalArgumentException e) {
+ return new DateTime();
+ }
+ }
+
+}
diff --git a/src/main/java/com/github/oxygenPlugins/common/gui/types/panels/ColorPanel.java b/src/main/java/com/github/oxygenPlugins/common/gui/types/panels/ColorPanel.java
new file mode 100644
index 0000000..b0cb5e9
--- /dev/null
+++ b/src/main/java/com/github/oxygenPlugins/common/gui/types/panels/ColorPanel.java
@@ -0,0 +1,207 @@
+package com.github.oxygenPlugins.common.gui.types.panels;
+
+import java.awt.Color;
+import java.awt.Container;
+import java.awt.Dialog;
+import java.awt.Dimension;
+import java.awt.Frame;
+import java.awt.GridBagConstraints;
+import java.awt.GridBagLayout;
+import java.awt.Insets;
+import java.awt.Point;
+import java.awt.Window;
+import java.awt.event.MouseEvent;
+import java.awt.event.MouseListener;
+import java.awt.event.WindowEvent;
+import java.awt.event.WindowFocusListener;
+
+import javax.swing.BorderFactory;
+import javax.swing.JDialog;
+import javax.swing.JFormattedTextField;
+import javax.swing.JFrame;
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+import javax.swing.JSlider;
+import javax.swing.JTextField;
+import javax.swing.border.BevelBorder;
+import javax.swing.border.Border;
+import javax.swing.event.ChangeEvent;
+import javax.swing.event.ChangeListener;
+
+import com.github.oxygenPlugins.common.gui.swing.SwingUtil;
+
+
+
+public class ColorPanel extends JPanel implements MouseListener{
+ private static final long serialVersionUID = 2661956887580911488L;
+ private final GridBagLayout gbl;
+ private final int minWidth = 150;
+ private final int minHeight = 100;
+ private JDialog dialog;
+ private final Border outlineBorder = BorderFactory.createBevelBorder(
+ BevelBorder.LOWERED, new Color(110, 110, 110), new Color(200, 200,
+ 200));
+ private JFormattedTextField textField;
+ private JLabel rgbCode = new JLabel();
+ private JSlider[] sliders = new JSlider[3];
+ private Color color;
+ private final Container owner;
+ public ColorPanel(JFormattedTextField field, Container owner){
+ this(field, field.getBackground(), owner);
+ }
+ public ColorPanel(final JFormattedTextField field, Color c, Container owner) {
+ this.textField = field;
+ this.owner = owner;
+ textField.setHorizontalAlignment(JTextField.CENTER);
+ color = c;
+ setBorder(outlineBorder);
+ setBackground(Color.WHITE);
+ gbl = new GridBagLayout();
+ this.setLayout(gbl);
+
+ for (int i = 0; i < sliders.length; i++) {
+ JPanel colorBar = getColorBar(i);
+ colorBar.setBackground(Color.WHITE);
+ SwingUtil.addComponent(this, gbl, colorBar,
+ 0, i, 1, 1, 1.0, 1.0,
+ GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(3, 3, 3, 3));
+ }
+ MouseListener ml = new MouseListener() {
+ @Override
+ public void mouseReleased(MouseEvent arg0) {}
+ @Override
+ public void mousePressed(MouseEvent arg0) {}
+ @Override
+ public void mouseExited(MouseEvent arg0) {}
+ @Override
+ public void mouseEntered(MouseEvent arg0) {}
+ @Override
+ public void mouseClicked(MouseEvent arg0) {
+ dialog.dispose();
+ }
+ };
+ addMouseListener(ml);
+// SwingUtil.addComponent(this, gbl, rgbCode,
+// 3, 1, 1, 1, 1.0, 0.0,
+// GridBagConstraints.NORTH, GridBagConstraints.BOTH, new Insets(3, 5, 5, 5));
+ rgbCode.setSize(rgbCode.getWidth(), textField.getWidth() / 3);
+ setColor();
+ }
+ private JPanel getColorBar(int i) {
+ JPanel jp = new JPanel();
+ GridBagLayout gbl = new GridBagLayout();
+ jp.setLayout(gbl);
+
+ JLabel label = new JLabel(i==0 ? "R" : i==1 ? "G" : "B");
+ JLabel maxVal = new JLabel("255");
+ JLabel minVal = new JLabel("0");
+ sliders[i] = new JSlider(JSlider.HORIZONTAL);
+ sliders[i].setMinimum(0);
+ sliders[i].setMaximum(255);
+ sliders[i].setBackground(i==0 ? Color.RED : i==1 ? Color.GREEN : Color.BLUE);
+ sliders[i].setPaintTicks(true);
+ sliders[i].setPaintTrack(true);
+ sliders[i].setOpaque(false);
+ sliders[i].setValue(i==0 ? color.getRed() : i==1 ? color.getGreen() : color.getBlue());
+ sliders[i].addChangeListener(new ChangeListener() {
+ @Override
+ public void stateChanged(ChangeEvent arg0) {
+ setColor();
+ }
+ });
+ SwingUtil.addComponent(jp, gbl, label,
+ 0, 0, 1, 1, 0.0, 0.0,
+ GridBagConstraints.WEST, GridBagConstraints.VERTICAL, new Insets(5, 5, 5, 5));
+ SwingUtil.addComponent(jp, gbl, minVal,
+ 1, 0, 1, 1, 0.0, 0.0,
+ GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5));
+ SwingUtil.addComponent(jp, gbl, sliders[i],
+ 2, 0, 1, 1, 1.0, 0.0,
+ GridBagConstraints.NORTH, GridBagConstraints.BOTH, new Insets(5, 5, 5, 5));
+ SwingUtil.addComponent(jp, gbl, maxVal,
+ 3, 0, 1, 1, 0.0, 0.0,
+ GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5));
+ return jp;
+ }
+ protected void setColor() {
+ int r = sliders[0].getValue();
+ int g = sliders[1].getValue();
+ int b = sliders[2].getValue();
+ color = new Color(r,g,b);
+
+ textField.setBackground(color);
+ if(color.getRed()+ color.getGreen() * 1.5 < 334)
+ textField.setForeground(Color.WHITE);
+ else
+ textField.setForeground(Color.BLACK);
+ textField.setText(Integer.toHexString(color.getRGB()).substring(2));
+ }
+ private void getColor() {
+ color = textField.getBackground();
+ sliders[0].setValue(color.getRed());
+ sliders[1].setValue(color.getGreen());
+ sliders[2].setValue(color.getBlue());
+ }
+ @Override
+ public void mouseClicked(MouseEvent e) {
+ // TODO Auto-generated method stub
+
+ }
+ @Override
+ public void mouseEntered(MouseEvent e) {
+ // TODO Auto-generated method stub
+
+ }
+ @Override
+ public void mouseExited(MouseEvent e) {
+ // TODO Auto-generated method stub
+
+ }
+ @Override
+ public void mousePressed(MouseEvent e) {
+ if (textField.isEnabled()) {
+ this.getColor();
+ if (dialog != null)
+ dialog.dispose();
+ if(owner instanceof Dialog){
+ dialog = new JDialog((Dialog) owner);
+ } else if(owner instanceof Frame) {
+ dialog = new JDialog((Frame) owner);
+ } else if(owner instanceof Window) {
+ dialog = new JDialog((Window) owner);
+ } else {
+ dialog = new JDialog(new JFrame());
+ }
+ dialog.addWindowFocusListener(new WindowFocusListener() {
+
+ @Override
+ public void windowLostFocus(WindowEvent arg0) {
+ dialog.dispose();
+ }
+
+ @Override
+ public void windowGainedFocus(WindowEvent arg0) {
+ }
+ });
+ dialog.setUndecorated(true);
+ dialog.setMinimumSize(new Dimension(minWidth, minHeight));
+ Point tfLoc = textField.getLocationOnScreen();
+ dialog.setSize(textField.getWidth(), textField.getWidth());
+ dialog.setLocation(new Point(tfLoc.x + textField.getWidth()
+ - dialog.getWidth(), tfLoc.y + textField.getHeight()));
+ dialog.add(this);
+ dialog.setModal(false);
+ dialog.setVisible(true);
+ }
+ }
+// private Frame getFrame(Component c) {
+// if (c instanceof Frame)
+// return (Frame) c;
+// return getFrame(c.getParent());
+// }
+ @Override
+ public void mouseReleased(MouseEvent e) {
+ // TODO Auto-generated method stub
+
+ }
+}
diff --git a/src/main/java/com/github/oxygenPlugins/common/gui/types/panels/FocusTraversalField.java b/src/main/java/com/github/oxygenPlugins/common/gui/types/panels/FocusTraversalField.java
new file mode 100644
index 0000000..26656cd
--- /dev/null
+++ b/src/main/java/com/github/oxygenPlugins/common/gui/types/panels/FocusTraversalField.java
@@ -0,0 +1,64 @@
+package com.github.oxygenPlugins.common.gui.types.panels;
+
+import java.awt.event.FocusListener;
+
+import javax.swing.JComponent;
+import javax.swing.JFormattedTextField;
+
+public class FocusTraversalField extends JFormattedTextField {
+
+ private static final long serialVersionUID = 1L;
+ private JComponent nextComponent = null;
+ private JComponent prevComponent = null;
+ private JComponent parentComponent;
+
+ public FocusTraversalField(){}
+
+ public FocusTraversalField(JComponent prevComponent, JComponent nextComponent){
+ this.prevComponent = prevComponent;
+ this.nextComponent = nextComponent;
+
+
+ }
+
+ public void nextFocus(){
+ if(nextComponent != null){
+ nextComponent.setEnabled(true);
+ nextComponent.requestFocus();
+ }
+ }
+
+ public void setNextComponent(JComponent nextComp) {
+ this.nextComponent = nextComp;
+ }
+
+ public void prevFocus(){
+ if(prevComponent != null){
+ prevComponent.setEnabled(true);
+ prevComponent.requestFocus();
+ }
+ }
+
+ public void setPrevComponent(JComponent prevComp) {
+ this.prevComponent = prevComp;
+ }
+
+ public void parentFocus(){
+ if(parentComponent != null){
+ parentComponent.setEnabled(true);
+ parentComponent.requestFocus();
+ }
+ }
+
+ public void setParentComponent(JComponent parentComp) {
+ this.parentComponent = parentComp;
+ }
+
+ public void removeAllFocusListener(){
+
+ FocusListener[] listeners = this.getFocusListeners();
+ for (FocusListener listener : listeners) {
+ this.removeFocusListener(listener);
+ }
+ }
+}
diff --git a/src/main/java/com/github/oxygenPlugins/common/gui/types/panels/MultiChoicePanel.java b/src/main/java/com/github/oxygenPlugins/common/gui/types/panels/MultiChoicePanel.java
new file mode 100644
index 0000000..a130825
--- /dev/null
+++ b/src/main/java/com/github/oxygenPlugins/common/gui/types/panels/MultiChoicePanel.java
@@ -0,0 +1,419 @@
+package com.github.oxygenPlugins.common.gui.types.panels;
+
+
+import java.awt.Color;
+import java.awt.Container;
+import java.awt.Dialog;
+import java.awt.Dimension;
+import java.awt.Frame;
+import java.awt.GridBagConstraints;
+import java.awt.GridBagLayout;
+import java.awt.Insets;
+import java.awt.Point;
+import java.awt.Window;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.FocusEvent;
+import java.awt.event.FocusListener;
+import java.awt.event.ItemEvent;
+import java.awt.event.ItemListener;
+import java.awt.event.KeyEvent;
+import java.awt.event.KeyListener;
+import java.awt.event.MouseEvent;
+import java.awt.event.MouseListener;
+import java.awt.event.WindowEvent;
+import java.awt.event.WindowFocusListener;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collections;
+
+import javax.swing.BorderFactory;
+import javax.swing.Icon;
+import javax.swing.JButton;
+import javax.swing.JComboBox;
+import javax.swing.JDialog;
+import javax.swing.JFormattedTextField;
+import javax.swing.JFrame;
+import javax.swing.JPanel;
+import javax.swing.JTextField;
+import javax.swing.border.BevelBorder;
+import javax.swing.border.Border;
+
+import com.github.oxygenPlugins.common.gui.images.IconMap;
+import com.github.oxygenPlugins.common.gui.swing.SwingUtil;
+
+//
+public class MultiChoicePanel extends JPanel implements MouseListener, FocusListener {
+ private static final long serialVersionUID = 2661956887580911488L;
+ private final GridBagLayout gbl;
+
+ private final int minWidth = 100;
+ private final int minHeight = 0;
+
+ private final int maxHeight = 30;
+ private final int maxWidth = 0;
+
+ private JDialog dialog;
+// private final Border defaultBorder = BorderFactory.createBevelBorder(
+// BevelBorder.RAISED, new Color(240, 240, 240), new Color(150, 150,
+// 150));
+ private final Border outlineBorder = BorderFactory.createBevelBorder(
+ BevelBorder.LOWERED, new Color(110, 110, 110), new Color(200, 200,
+ 200));
+// private final Border selectBorder = BorderFactory.createBevelBorder(
+// BevelBorder.RAISED, new Color(30, 20, 120),
+// new Color(110, 100, 200));
+ private JFormattedTextField textField;
+
+ private final ArrayList valueList;
+
+ private int value;
+ private final int initialValue;
+
+ private JComboBox entryBox;
+ private final Container owner;
+
+ private final JPanel buttonPanel = new JPanel();
+ private final JButton okBtn;
+ @SuppressWarnings("unused")
+ private final JButton cancelBtn;
+ private final JButton clearBtn;
+ private final boolean hasNull;
+
+ private final String fallbackText;
+ private final String nullText = "(no value)";
+
+ private class PanelButton extends JButton{
+ private static final long serialVersionUID = 1699184718806511284L;
+ public PanelButton(Icon i){
+ this.setIcon(i);
+ Dimension dim = new Dimension(i.getIconWidth() + 1, i.getIconHeight() + 1);
+ this.setMinimumSize(dim);
+ this.setSize(dim);
+ }
+ public PanelButton(String text){
+ super(text);
+ }
+ }
+ public MultiChoicePanel(final JFormattedTextField field, Container owner, String[] values) {
+ this(field, owner, values, false);
+ }
+ public MultiChoicePanel(final JFormattedTextField field, Container owner, String[] values, boolean isNullSelectable) {
+ this.owner = owner;
+ this.textField = field;
+ textField.setHorizontalAlignment(JTextField.CENTER);
+
+ this.valueList = new ArrayList();
+ this.hasNull = !field.isEnabled();
+
+ if(isNullSelectable && hasNull){
+ valueList.add(nullText);
+ }
+ Collections.addAll(this.valueList, values);
+
+ fallbackText = field.getText();
+ initialValue = this.valueList.indexOf(fallbackText);
+ value = initialValue;
+
+// if(field.isEnabled()){
+//
+// } else {
+// initialValue = VALUE_NULL;
+// value = VALUE_NULL;
+// }
+ setBorder(outlineBorder);
+ setBackground(Color.WHITE);
+ gbl = new GridBagLayout();
+ this.setLayout(gbl);
+
+ GridBagLayout buttonGbl = new GridBagLayout();
+ buttonPanel.setLayout(buttonGbl);
+ buttonPanel.setVisible(false);
+
+ if(IconMap.ICONS == null){
+ try {
+ IconMap.ICONS = new IconMap();
+ } catch (IOException e) {
+ }
+ }
+
+ if(IconMap.ICONS != null){
+ IconMap icons = IconMap.ICONS;
+ this.okBtn = new PanelButton(icons.getIcon(2, 10));
+ this.clearBtn = new PanelButton(icons.getIcon(10, 11));
+ this.cancelBtn = new PanelButton(icons.getIcon(0, 10));
+ } else {
+ this.okBtn = new PanelButton("ok");
+ this.clearBtn = new PanelButton("x");
+ this.cancelBtn = new PanelButton("c");
+ }
+
+ this.okBtn.addActionListener(new ActionListener() {
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ dispose();
+ }
+ });
+
+ this.clearBtn.addActionListener(new ActionListener() {
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ dispose(true);
+ }
+ });
+
+// this.okBtn.setVisible(false);
+// this.clearBtn.setVisible(false);
+// this.cancelBtn.setVisible(false);
+
+
+ entryBox = new JComboBox(this.valueList.toArray(new String[this.valueList.size()]));
+ entryBox.setSelectedIndex(value);
+ KeyListener[] kls = textField.getKeyListeners();
+ entryBox.addItemListener(new ItemListener() {
+
+ @Override
+ public void itemStateChanged(ItemEvent ie) {
+ if(dialog == null)
+ return;
+ if(dialog.isVisible()){
+ dispose();
+ }
+ }
+ });
+
+ entryBox.addKeyListener(new KeyListener() {
+ @Override
+ public void keyTyped(KeyEvent e) {}
+ @Override
+ public void keyReleased(KeyEvent e) {
+ if(e.getKeyChar()=='\n'){
+ dispose();
+ if (textField instanceof FocusTraversalField) {
+ FocusTraversalField focusField = (FocusTraversalField) textField;
+ focusField.nextFocus();
+ }
+ } else if(e.getKeyChar() == KeyEvent.VK_ESCAPE){
+ dispose(true);
+ if (textField instanceof FocusTraversalField) {
+ FocusTraversalField focusField = (FocusTraversalField) textField;
+ focusField.parentFocus();
+ }
+ } else if(e.getKeyChar() == KeyEvent.VK_TAB){
+ if(textField instanceof FocusTraversalField){
+ FocusTraversalField focusField = (FocusTraversalField) textField;
+
+ dispose();
+
+ if(e.isShiftDown()){
+ focusField.prevFocus();
+ } else {
+ focusField.nextFocus();
+ }
+ }
+ }
+ }
+ @Override
+ public void keyPressed(KeyEvent e) {}
+ });
+
+ if(textField instanceof FocusTraversalField){
+ textField.setFocusable(true);
+ entryBox.setFocusTraversalKeysEnabled(false);
+ ((FocusTraversalField) textField).removeAllFocusListener();
+ textField.addFocusListener(this);
+ }
+
+ SwingUtil.addComponent(this, gbl, entryBox,
+ 0, 0, 1, 1, 1.0, 1.0,
+ GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(3, 3, 3, 0));
+
+
+// SwingUtil.addComponent(this, gbl, okBtn,
+// 1, 0, 1, 1, 0.0, 1.0,
+// GridBagConstraints.NORTHEAST, GridBagConstraints.VERTICAL, new Insets(3, 0, 0, 3));
+
+
+// SwingUtil.addComponent(this, gbl, cancelBtn,
+// 1, 1, 1, 1, 0.0, 1.0,
+// GridBagConstraints.EAST, GridBagConstraints.VERTICAL, new Insets(0, 0, 0, 3));
+
+ SwingUtil.addComponent(this, gbl, clearBtn,
+ 1, 0, 1, 1, 0.0, 1.0,
+ GridBagConstraints.SOUTHEAST, GridBagConstraints.VERTICAL, new Insets(0, 0, 3, 3));
+
+
+ MouseListener ml = new MouseListener() {
+ @Override
+ public void mouseReleased(MouseEvent arg0) {}
+ @Override
+ public void mousePressed(MouseEvent arg0) {}
+ @Override
+ public void mouseExited(MouseEvent arg0) {
+
+// switchToField();
+ }
+ @Override
+ public void mouseEntered(MouseEvent arg0) {
+
+// switchToButtons();
+ }
+ @Override
+ public void mouseClicked(MouseEvent arg0) {
+ dispose();
+ }
+ };
+
+ addMouseListener(ml);
+ }
+
+
+
+ protected void setText() {
+ int value = this.entryBox.getSelectedIndex();
+ boolean isNull = isNull(value);
+ this.textField.setEnabled(!isNull);
+ this.textField.setText(convert(this.entryBox.getSelectedIndex()));
+ textField.repaint();
+ }
+ private void getText() {
+ String text = textField.getText();
+ if(textField.isEnabled()){
+ value = convert(text);
+ } else {
+ value = 0;
+ text = nullText;
+ }
+ entryBox.setSelectedItem(text);
+ }
+
+ private boolean isNull(int value){
+ if(value >= valueList.size())
+ return true;
+ if(entryBox.getItemAt(value) == this.nullText)
+ return true;
+ if(value < 0)
+ return true;
+ return false;
+ }
+
+ private String convert(int value){
+ if(isNull(value))
+ return fallbackText;
+ return valueList.get(value);
+ }
+ private int convert(String valueString){
+ int i = 0;
+ for (String label : valueList) {
+ if(valueString.equals(label))
+ return i;
+ i++;
+ }
+ return 0;
+ }
+
+ @Override
+ public void mouseClicked(MouseEvent e) {
+ // TODO Auto-generated method stub
+
+ }
+ @Override
+ public void mouseEntered(MouseEvent e) {
+
+ }
+ @Override
+ public void mouseExited(MouseEvent e) {
+ // TODO Auto-generated method stub
+
+ }
+ @Override
+ public void mousePressed(MouseEvent e) {
+ activate();
+ }
+ @Override
+ public void mouseReleased(MouseEvent e) {
+ // TODO Auto-generated method stub
+
+ }
+ private void activate(){
+// if (textField.isEnabled()) {
+// if (dialog != null) {
+// dispose();
+// }
+ this.getText();
+
+ if(dialog == null){
+ if(owner instanceof Dialog){
+ dialog = new JDialog((Dialog) owner);
+ } else if(owner instanceof Frame) {
+ dialog = new JDialog((Frame) owner);
+ } else if(owner instanceof Window) {
+ dialog = new JDialog((Window) owner);
+ } else {
+ dialog = new JDialog(new JFrame());
+ }
+ }
+ dialog.addWindowFocusListener(new WindowFocusListener() {
+
+ @Override
+ public void windowLostFocus(WindowEvent arg0) {
+ if(dialog != null)
+ dispose();
+ }
+
+ @Override
+ public void windowGainedFocus(WindowEvent arg0) {
+ }
+ });
+ dialog.setUndecorated(true);
+ dialog.setMinimumSize(new Dimension(minWidth, minHeight));
+ Point tfLoc = textField.getLocationOnScreen();
+ int finalWidth = textField.getWidth() * 2;
+ int finalHeight = textField.getHeight() * 2;
+
+ finalHeight = this.maxHeight > 0 && this.maxHeight < finalHeight ? this.maxHeight : finalHeight;
+ finalWidth = this.maxWidth > 0 && this.maxWidth < finalWidth ? this.maxWidth : finalWidth;
+
+ dialog.setMaximumSize(new Dimension(finalWidth, finalHeight));
+
+ dialog.setSize(finalWidth, finalHeight);
+ dialog.setLocation(new Point((int) (tfLoc.x - finalWidth * 0.25),
+ (int) (tfLoc.y - finalHeight * 0.25)));
+ dialog.add(this);
+ dialog.setModal(false);
+ dialog.setVisible(true);
+// }
+ }
+
+ private void dispose(){
+ dispose(false);
+ }
+ private void dispose(boolean unsetText){
+ if(unsetText){
+ if(hasNull){
+ this.textField.setEnabled(false);
+ } else {
+ this.textField.setEnabled(true);
+ }
+ this.textField.setText(convert(initialValue));
+ this.textField.repaint();
+ } else {
+ this.setText();
+ }
+ if(dialog != null){
+ this.dialog.dispose();
+ this.dialog = null;
+ }
+ }
+
+ @Override
+ public void focusGained(FocusEvent arg0) {
+ if(dialog == null){
+// activate();
+ }
+ }
+ @Override
+ public void focusLost(FocusEvent arg0) {
+// dispose();
+ }
+}
diff --git a/src/main/java/com/github/oxygenPlugins/common/gui/types/panels/StringPanel.java b/src/main/java/com/github/oxygenPlugins/common/gui/types/panels/StringPanel.java
new file mode 100644
index 0000000..583f336
--- /dev/null
+++ b/src/main/java/com/github/oxygenPlugins/common/gui/types/panels/StringPanel.java
@@ -0,0 +1,358 @@
+package com.github.oxygenPlugins.common.gui.types.panels;
+
+
+import java.awt.Color;
+import java.awt.Container;
+import java.awt.Dialog;
+import java.awt.Dimension;
+import java.awt.Frame;
+import java.awt.GridBagConstraints;
+import java.awt.GridBagLayout;
+import java.awt.Insets;
+import java.awt.Point;
+import java.awt.Window;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.FocusEvent;
+import java.awt.event.FocusListener;
+import java.awt.event.KeyEvent;
+import java.awt.event.KeyListener;
+import java.awt.event.MouseEvent;
+import java.awt.event.MouseListener;
+import java.awt.event.WindowEvent;
+import java.awt.event.WindowFocusListener;
+import java.io.IOException;
+
+import javax.swing.BorderFactory;
+import javax.swing.Icon;
+import javax.swing.JButton;
+import javax.swing.JDialog;
+import javax.swing.JFormattedTextField;
+import javax.swing.JFrame;
+import javax.swing.JPanel;
+import javax.swing.JTextField;
+import javax.swing.border.BevelBorder;
+import javax.swing.border.Border;
+
+import com.github.oxygenPlugins.common.gui.images.IconMap;
+import com.github.oxygenPlugins.common.gui.swing.SwingUtil;
+import com.github.oxygenPlugins.common.gui.types._Verifier;
+
+//
+public class StringPanel extends JPanel implements MouseListener, FocusListener {
+ private static final long serialVersionUID = 2661956887580911488L;
+ private final GridBagLayout gbl;
+ private final int minWidth = 75;
+ private final int minHeight = 0;
+ private JDialog dialog;
+// private final Border defaultBorder = BorderFactory.createBevelBorder(
+// BevelBorder.RAISED, new Color(240, 240, 240), new Color(150, 150,
+// 150));
+ private final Border outlineBorder = BorderFactory.createBevelBorder(
+ BevelBorder.LOWERED, new Color(110, 110, 110), new Color(200, 200,
+ 200));
+// private final Border selectBorder = BorderFactory.createBevelBorder(
+// BevelBorder.RAISED, new Color(30, 20, 120),
+// new Color(110, 100, 200));
+ private JFormattedTextField textField;
+
+ private String value;
+ private final String initialValue;
+
+ private JFormattedTextField entryField;
+ private final Container owner;
+
+ private final JPanel buttonPanel = new JPanel();
+ private final JButton okBtn;
+ @SuppressWarnings("unused")
+ private final JButton cancelBtn;
+ private final JButton clearBtn;
+
+ private class PanelButton extends JButton{
+ private static final long serialVersionUID = 1699184718806511284L;
+ public PanelButton(Icon i){
+ this.setIcon(i);
+ Dimension dim = new Dimension(i.getIconWidth() + 1, i.getIconHeight() + 1);
+ this.setMinimumSize(dim);
+ this.setSize(dim);
+ }
+ public PanelButton(String text){
+ super(text);
+ }
+ }
+
+ public StringPanel(final JFormattedTextField field, _Verifier verifier, Container owner){
+ this(field, owner);
+ verifier.setVerifier(entryField, owner, false);
+ }
+ public StringPanel(final JFormattedTextField field, Container owner) {
+ this.owner = owner;
+ this.textField = field;
+ textField.setHorizontalAlignment(JTextField.CENTER);
+ if(field.isEnabled()){
+ initialValue = field.getText();
+ value = initialValue;
+ } else {
+ initialValue = null;
+ value = null;
+ }
+ setBorder(outlineBorder);
+ setBackground(Color.WHITE);
+ gbl = new GridBagLayout();
+ this.setLayout(gbl);
+
+ GridBagLayout buttonGbl = new GridBagLayout();
+ buttonPanel.setLayout(buttonGbl);
+ buttonPanel.setVisible(false);
+
+ if(IconMap.ICONS == null){
+ try {
+ IconMap.ICONS = new IconMap();
+ } catch (IOException e) {
+ }
+ }
+
+ if(IconMap.ICONS != null){
+ IconMap icons = IconMap.ICONS;
+ this.okBtn = new PanelButton(icons.getIcon(2, 10));
+ this.clearBtn = new PanelButton(icons.getIcon(10, 11));
+ this.cancelBtn = new PanelButton(icons.getIcon(0, 10));
+ } else {
+ this.okBtn = new PanelButton("ok");
+ this.clearBtn = new PanelButton("x");
+ this.cancelBtn = new PanelButton("c");
+ }
+
+ this.okBtn.addActionListener(new ActionListener() {
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ dispose();
+ }
+ });
+
+ this.clearBtn.addActionListener(new ActionListener() {
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ dispose(true);
+ }
+ });
+
+// this.okBtn.setVisible(false);
+// this.clearBtn.setVisible(false);
+// this.cancelBtn.setVisible(false);
+
+
+ entryField = new JFormattedTextField();
+ if(value == null){
+ entryField.setText("");
+ } else {
+ entryField.setText(value);
+ }
+ KeyListener[] kls = textField.getKeyListeners();
+
+ for (int i = 0; i < kls.length; i++) {
+ entryField.addKeyListener(kls[i]);
+ }
+ entryField.addKeyListener(new KeyListener() {
+ @Override
+ public void keyTyped(KeyEvent e) {}
+ @Override
+ public void keyReleased(KeyEvent e) {
+ if(e.getKeyChar()=='\n'){
+ dispose();
+ if (textField instanceof FocusTraversalField) {
+ FocusTraversalField focusField = (FocusTraversalField) textField;
+ focusField.nextFocus();
+ }
+ } else if(e.getKeyChar() == KeyEvent.VK_ESCAPE){
+ dispose(true);
+ if (textField instanceof FocusTraversalField) {
+ FocusTraversalField focusField = (FocusTraversalField) textField;
+ focusField.parentFocus();
+ }
+ } else if(e.getKeyChar() == KeyEvent.VK_TAB){
+ if(textField instanceof FocusTraversalField){
+ FocusTraversalField focusField = (FocusTraversalField) textField;
+
+ dispose();
+
+ if(e.isShiftDown()){
+ focusField.prevFocus();
+ } else {
+ focusField.nextFocus();
+ }
+ }
+ }
+ }
+ @Override
+ public void keyPressed(KeyEvent e) {}
+ });
+
+ if(textField instanceof FocusTraversalField){
+ textField.setFocusable(true);
+ entryField.setFocusTraversalKeysEnabled(false);
+ ((FocusTraversalField) textField).removeAllFocusListener();
+ textField.addFocusListener(this);
+ }
+
+ SwingUtil.addComponent(this, gbl, entryField,
+ 0, 0, 1, 3, 1.0, 1.0,
+ GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(3, 3, 3, 0));
+
+
+ SwingUtil.addComponent(this, gbl, okBtn,
+ 1, 0, 1, 1, 0.0, 1.0,
+ GridBagConstraints.NORTHEAST, GridBagConstraints.VERTICAL, new Insets(3, 0, 0, 3));
+
+
+// SwingUtil.addComponent(this, gbl, cancelBtn,
+// 1, 1, 1, 1, 0.0, 1.0,
+// GridBagConstraints.EAST, GridBagConstraints.VERTICAL, new Insets(0, 0, 0, 3));
+
+ SwingUtil.addComponent(this, gbl, clearBtn,
+ 1, 1, 1, 1, 0.0, 1.0,
+ GridBagConstraints.SOUTHEAST, GridBagConstraints.VERTICAL, new Insets(0, 0, 3, 3));
+
+
+ MouseListener ml = new MouseListener() {
+ @Override
+ public void mouseReleased(MouseEvent arg0) {}
+ @Override
+ public void mousePressed(MouseEvent arg0) {}
+ @Override
+ public void mouseExited(MouseEvent arg0) {
+
+// switchToField();
+ }
+ @Override
+ public void mouseEntered(MouseEvent arg0) {
+
+// switchToButtons();
+ }
+ @Override
+ public void mouseClicked(MouseEvent arg0) {
+ dispose();
+ }
+ };
+
+ addMouseListener(ml);
+ }
+
+
+
+
+ protected void setText() {
+ this.textField.setEnabled(true);
+ this.textField.setText(this.entryField.getText());
+ textField.repaint();
+ }
+ private void getText() {
+ if(textField.isEnabled()){
+ value = textField.getText();
+ } else {
+ value = "";
+ }
+ entryField.setText(value);
+
+ if(!value.equals("")){
+ entryField.setSelectionStart(0);
+ entryField.setSelectionEnd(value.length());
+ }
+ }
+ @Override
+ public void mouseClicked(MouseEvent e) {
+ // TODO Auto-generated method stub
+
+ }
+ @Override
+ public void mouseEntered(MouseEvent e) {
+
+ }
+ @Override
+ public void mouseExited(MouseEvent e) {
+ // TODO Auto-generated method stub
+
+ }
+ @Override
+ public void mousePressed(MouseEvent e) {
+ activate();
+ }
+ @Override
+ public void mouseReleased(MouseEvent e) {
+ // TODO Auto-generated method stub
+
+ }
+ private void activate(){
+// if (textField.isEnabled()) {
+ this.getText();
+// if (dialog != null) {
+// dispose();
+// }
+ if(dialog == null){
+ if(owner instanceof Dialog){
+ dialog = new JDialog((Dialog) owner);
+ } else if(owner instanceof Frame) {
+ dialog = new JDialog((Frame) owner);
+ } else if(owner instanceof Window) {
+ dialog = new JDialog((Window) owner);
+ } else {
+ dialog = new JDialog(new JFrame());
+ }
+ }
+ dialog.addWindowFocusListener(new WindowFocusListener() {
+
+ @Override
+ public void windowLostFocus(WindowEvent arg0) {
+ if(dialog != null)
+ dispose();
+ }
+
+ @Override
+ public void windowGainedFocus(WindowEvent arg0) {
+ }
+ });
+ dialog.setUndecorated(true);
+ dialog.setMinimumSize(new Dimension(minWidth, minHeight));
+ Point tfLoc = textField.getLocationOnScreen();
+ int finalWidth = textField.getWidth() * 2;
+ int finalHeight = textField.getHeight() * 2;
+ dialog.setSize(finalWidth, finalHeight);
+ dialog.setLocation(new Point((int) (tfLoc.x - finalWidth * 0.25),
+ (int) (tfLoc.y - finalHeight * 0.25)));
+ dialog.add(this);
+ dialog.setModal(false);
+ dialog.setVisible(true);
+// }
+ }
+ protected void dispose() {
+ this.dispose(false);
+ }
+ private void dispose(boolean unsetText){
+ if(unsetText){
+ if(initialValue != null){
+ this.textField.setEnabled(true);
+ } else {
+ this.textField.setEnabled(false);
+ }
+ this.textField.setText(initialValue);
+ this.textField.repaint();
+ } else {
+ this.setText();
+ }
+ if(dialog != null){
+ this.dialog.dispose();
+ this.dialog = null;
+ }
+ }
+
+ @Override
+ public void focusGained(FocusEvent arg0) {
+ if(dialog == null){
+// activate();
+ }
+ }
+ @Override
+ public void focusLost(FocusEvent arg0) {
+// dispose();
+ }
+}
diff --git a/src/main/java/com/github/oxygenPlugins/common/gui/types/panels/TimePanel.java b/src/main/java/com/github/oxygenPlugins/common/gui/types/panels/TimePanel.java
new file mode 100644
index 0000000..f7f50d4
--- /dev/null
+++ b/src/main/java/com/github/oxygenPlugins/common/gui/types/panels/TimePanel.java
@@ -0,0 +1,557 @@
+package com.github.oxygenPlugins.common.gui.types.panels;
+
+import java.awt.Color;
+import java.awt.Container;
+import java.awt.Dialog;
+import java.awt.Dimension;
+import java.awt.Font;
+import java.awt.Frame;
+import java.awt.GridBagConstraints;
+import java.awt.GridBagLayout;
+import java.awt.Point;
+import java.awt.Window;
+import java.awt.event.MouseEvent;
+import java.awt.event.MouseListener;
+import java.awt.event.WindowEvent;
+import java.awt.event.WindowFocusListener;
+import java.io.IOException;
+
+import javax.swing.BorderFactory;
+import javax.swing.Icon;
+import javax.swing.JDialog;
+import javax.swing.JFormattedTextField;
+import javax.swing.JFrame;
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+import javax.swing.JTextField;
+import javax.swing.border.BevelBorder;
+import javax.swing.border.Border;
+
+import org.joda.time.DateTime;
+import org.joda.time.format.DateTimeFormat;
+import org.joda.time.format.DateTimeFormatter;
+
+import com.github.oxygenPlugins.common.gui.images.IconMap;
+import com.github.oxygenPlugins.common.gui.swing.SwingUtil;
+import com.github.oxygenPlugins.common.gui.types.IntegerAreaVerifier;
+
+
+
+public class TimePanel extends JPanel implements MouseListener {
+ private static final long serialVersionUID = -4261661006435142610L;
+ private final JDialog dialog;
+ private final JTextField textField;
+
+ private final Font defFont;
+
+ @SuppressWarnings("unused")
+ private final int padding;
+ private final GridBagLayout gbl = new GridBagLayout();
+
+ // private final int minWidth;
+ // private final int minHeight;
+ private JPanel contentPanel = new JPanel();
+
+ JFormattedTextField hour = new JFormattedTextField();
+ JFormattedTextField minutes = new JFormattedTextField();
+ JFormattedTextField sec = new JFormattedTextField();
+
+ private final Border defaultBorder = BorderFactory.createBevelBorder(
+ BevelBorder.RAISED, new Color(240, 240, 240), new Color(150, 150,
+ 150));
+ private final Border greenBorder = BorderFactory.createBevelBorder(
+ BevelBorder.LOWERED, new Color(0, 110, 0), new Color(0, 200, 0));
+ private final Border selectBorder = BorderFactory.createBevelBorder(
+ BevelBorder.RAISED, new Color(30, 20, 120),
+ new Color(110, 100, 200));
+ private String initialValue;
+
+ public TimePanel(JFormattedTextField field, int fontSize, Container owner) {
+
+ if(field.isEnabled()){
+ initialValue = field.getText();
+ setTime(convert(initialValue));
+ } else {
+ initialValue = null;
+ }
+
+ if (owner instanceof Dialog) {
+ dialog = new JDialog((Dialog) owner);
+ } else if (owner instanceof Frame) {
+ dialog = new JDialog((Frame) owner);
+ } else if (owner instanceof Window) {
+ dialog = new JDialog((Window) owner);
+ } else {
+ dialog = new JDialog(new JFrame());
+ }
+ this.setLayout(gbl);
+ this.textField = field;
+ Font defFont = new JLabel().getFont();
+ this.defFont = new Font(defFont.getName(), defFont.getStyle(), fontSize);
+
+ // this.minWidth = 25 * fontSize;
+ // this.minHeight = 25 * fontSize;
+ this.padding = (int) Math.round(fontSize * 0.1);
+ this.setLayout(gbl);
+
+ String text = this.textField.getText();
+ DateTime actuellDat = convert(text);
+ buildCalendar(actuellDat, actuellDat);
+ Dimension minDim = new Dimension(fontSize * 7 / 4, fontSize * 2);
+ hour.setMinimumSize(minDim);
+ hour.setPreferredSize(minDim);
+ minutes.setMinimumSize(minDim);
+ minutes.setPreferredSize(minDim);
+ sec.setMinimumSize(minDim);
+ sec.setPreferredSize(minDim);
+
+
+ dialog.addWindowFocusListener(new WindowFocusListener() {
+ @Override
+ public void windowLostFocus(WindowEvent arg0) {
+ dispose();
+ }
+
+ @Override
+ public void windowGainedFocus(WindowEvent arg0) {
+ }
+ });
+ dialog.addMouseListener(new MouseListener() {
+ @Override
+ public void mouseReleased(MouseEvent arg0) {
+ }
+
+ @Override
+ public void mousePressed(MouseEvent arg0) {
+ }
+
+ @Override
+ public void mouseExited(MouseEvent arg0) {
+ }
+
+ @Override
+ public void mouseEntered(MouseEvent arg0) {
+ }
+
+ @Override
+ public void mouseClicked(MouseEvent arg0) {
+ dispose();
+ }
+ });
+ // dialog.setMinimumSize(new Dimension(minWidth, minHeight));
+ dialog.setUndecorated(true);
+ dialog.add(this);
+ }
+
+ private void dispose() {
+ this.dialog.dispose();
+ this.textField.setEnabled(true);
+ }
+
+ @Override
+ public void mouseClicked(MouseEvent e) {
+ if (textField.isEnabled()) {
+
+ String text = this.textField.getText();
+ DateTime actuellDat = convert(text);
+ buildCalendar(actuellDat, actuellDat);
+
+ // dialog.setSize(textField.getWidth(), textField.getWidth());
+ int finalWidth = textField.getWidth() * 2;
+ int finalHeight = textField.getHeight() * 2;
+ dialog.setSize(finalWidth, finalHeight);
+
+ dialog.pack();
+
+ dialog.setLocation(getDialogBounds());
+ // System.out.println(tfLoc.y);
+ dialog.setModal(false);
+ dialog.setVisible(true);
+ textField.setEnabled(false);
+ } else {
+ dispose();
+ }
+ }
+
+ private Point getDialogBounds() {
+
+ Point tfLoc = textField.getLocationOnScreen();
+
+ return new Point((int) (tfLoc.x - dialog.getWidth() * 0.25),
+ (int) (tfLoc.y - dialog.getHeight() * 0.25));
+ }
+
+ @Override
+ public void mouseEntered(MouseEvent e) {
+ }
+
+ @Override
+ public void mouseExited(MouseEvent e) {
+ }
+
+ @Override
+ public void mousePressed(MouseEvent e) {
+ }
+
+ @Override
+ public void mouseReleased(MouseEvent e) {
+ }
+
+ private void clear() {
+ this.remove(contentPanel);
+ }
+
+ private void buildCalendar(final DateTime actuell,
+ final DateTime selectedDate) {
+ clear();
+
+ IconMap icons = null;
+ ;
+ try {
+ icons = new IconMap();
+ } catch (IOException e) {
+ }
+ GridBagLayout gblContent = new GridBagLayout();
+
+ this.setBorder(defaultBorder);
+ contentPanel = new JPanel();
+ contentPanel.setLayout(gblContent);
+ contentPanel.setBackground(Color.WHITE);
+ contentPanel.setOpaque(true);
+
+ SwingUtil.addComponent(this, gbl, contentPanel, 0, 0, 1, 1, 1.0, 1.0,
+ GridBagConstraints.NORTHEAST, GridBagConstraints.BOTH);
+
+ // JPanel head = buildHeader(actuell, selectedDate);
+ // SwingUtil.addComponent(contentPanel, gbl, head, 0, 0, 1, 1, 0.0, 0.0,
+ // GridBagConstraints.NORTHEAST, GridBagConstraints.BOTH);
+
+ IntegerAreaVerifier iavHour = new IntegerAreaVerifier(0, 23);
+ IntegerAreaVerifier iavMinutes = new IntegerAreaVerifier(0, 59);
+ IntegerAreaVerifier iavSec = new IntegerAreaVerifier(0, 59);
+
+ iavHour.setVerifier(hour, dialog, false);
+
+ iavMinutes.setVerifier(minutes, dialog, false);
+
+ iavSec.setVerifier(sec, dialog, false);
+
+ setTime(actuell);
+// int tinySize = 25;
+// JButton hourP = new PanelButton(icons.getIcon(6, 13));
+// hourP.addActionListener(new ActionListener() {
+// @Override
+// public void actionPerformed(ActionEvent arg0) {
+// setTime(getTime().plusHours(1));
+// }
+// });
+// JButton hourM = new PanelButton(icons.getIcon(4, 13));
+// hourM.addActionListener(new ActionListener() {
+// @Override
+// public void actionPerformed(ActionEvent arg0) {
+// setTime(getTime().minusHours(1));
+// }
+// });
+// JButton minP = new PanelButton(icons.getIcon(6, 13));
+// hourM.addActionListener(new ActionListener() {
+// @Override
+// public void actionPerformed(ActionEvent arg0) {
+// setTime(getTime().plusMinutes(1));
+// }
+// });
+// JButton minM = new PanelButton(icons.getIcon(4, 13));
+// hourM.addActionListener(new ActionListener() {
+// @Override
+// public void actionPerformed(ActionEvent arg0) {
+// setTime(getTime().minusMinutes(1));
+// }
+// });
+// JButton secP = new PanelButton(icons.getIcon(6, 13));
+// hourM.addActionListener(new ActionListener() {
+// @Override
+// public void actionPerformed(ActionEvent arg0) {
+// setTime(getTime().plusSeconds(1));
+// }
+// });
+// JButton secM = new PanelButton(icons.getIcon(4, 13));
+// hourM.addActionListener(new ActionListener() {
+// @Override
+// public void actionPerformed(ActionEvent arg0) {
+// setTime(getTime().minusSeconds(1));
+// }
+// });
+// JButton conformBtn = new PanelButton(icons.getIcon(2, 10));
+// hourM.addActionListener(new ActionListener() {
+// @Override
+// public void actionPerformed(ActionEvent arg0) {
+// confirmDate(getTime());
+// }
+// });
+
+
+ DateView hourP = new DateView(icons.getIcon(6, 13)) {
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public void performAction() {
+ setTime(getTime().plusHours(1));
+ }
+ };
+
+ DateView hourM = new DateView(icons.getIcon(4, 13)) {
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public void performAction() {
+ setTime(getTime().minusHours(1));
+ }
+ };
+ DateView minP = new DateView(icons.getIcon(6, 13)) {
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public void performAction() {
+ setTime(getTime().plusMinutes(1));
+ }
+ };
+ DateView minM = new DateView(icons.getIcon(4, 13)) {
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public void performAction() {
+ setTime(getTime().minusMinutes(1));
+ }
+ };
+ DateView secP = new DateView(icons.getIcon(6, 13)) {
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public void performAction() {
+ setTime(getTime().plusSeconds(1));
+ }
+ };
+ DateView secM = new DateView(icons.getIcon(4, 13)) {
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public void performAction() {
+ setTime(getTime().minusSeconds(1));
+ }
+ };
+ DateView conformBtn = new DateView(icons.getIcon(2, 10)) {
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public void performAction() {
+ confirmDate(getTime());
+ }
+ };
+ DateView clearBtn = new DateView(icons.getIcon(10, 11)) {
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public void performAction() {
+ unsetTextAndDispose();
+ }
+ };
+
+ SwingUtil.addComponent(contentPanel, gblContent, hour, 0, 0, 1, 2, 0.0,
+ 1.0, GridBagConstraints.NORTHWEST, GridBagConstraints.BOTH);
+ SwingUtil
+ .addComponent(contentPanel, gblContent, hourP, 1, 0, 1, 1, 0.0,
+ 0.0, GridBagConstraints.NORTHWEST,
+ GridBagConstraints.NONE);
+ SwingUtil
+ .addComponent(contentPanel, gblContent, hourM, 1, 1, 1, 1, 0.0,
+ 0.0, GridBagConstraints.SOUTHWEST,
+ GridBagConstraints.NONE);
+ SwingUtil.addComponent(contentPanel, gblContent, minutes, 2, 0, 1, 2,
+ 0.0, 1.0, GridBagConstraints.NORTH, GridBagConstraints.BOTH);
+ SwingUtil.addComponent(contentPanel, gblContent, minP, 3, 0, 1, 1, 0.0,
+ 0.0, GridBagConstraints.NORTH, GridBagConstraints.NONE);
+ SwingUtil.addComponent(contentPanel, gblContent, minM, 3, 1, 1, 1, 0.0,
+ 0.0, GridBagConstraints.SOUTH, GridBagConstraints.NONE);
+ SwingUtil.addComponent(contentPanel, gblContent, sec, 4, 0, 1, 2, 0.0,
+ 1.0, GridBagConstraints.NORTHEAST, GridBagConstraints.BOTH);
+ SwingUtil.addComponent(contentPanel, gblContent, secP, 5, 0, 1, 1, 0.0,
+ 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE);
+ SwingUtil.addComponent(contentPanel, gblContent, secM, 5, 1, 1, 1, 0.0,
+ 0.0, GridBagConstraints.SOUTHWEST, GridBagConstraints.NONE);
+
+ SwingUtil.addComponent(contentPanel, gblContent, conformBtn, 6, 0, 1,
+ 1, 0.0, 0.0, GridBagConstraints.SOUTHWEST,
+ GridBagConstraints.NONE);
+ SwingUtil.addComponent(contentPanel, gblContent, clearBtn, 6, 1, 1,
+ 1, 0.0, 0.0, GridBagConstraints.SOUTHWEST,
+ GridBagConstraints.NONE);
+
+ this.contentPanel.repaint();
+ this.repaint();
+ this.updateUI();
+ }
+
+ protected void unsetTextAndDispose() {
+ if(initialValue != null){
+ this.textField.setEnabled(true);
+ } else {
+ this.textField.setEnabled(false);
+ }
+ this.textField.setText(initialValue);
+ this.textField.repaint();
+
+ this.dialog.dispose();
+ }
+
+ private DateTime getTime() {
+ String timeString = "T" + hour.getText() + ":" + minutes.getText()
+ + ":" + sec.getText();
+ DateTime time = DateTime.parse(timeString);
+ return time;
+ }
+
+
+ private void setTime(DateTime time) {
+ setIntToField(hour, time.getHourOfDay());
+ setIntToField(minutes, time.getMinuteOfHour());
+ setIntToField(sec, time.getSecondOfMinute());
+ }
+
+ private void setIntToField(JFormattedTextField field, int value) {
+ String valueString = "" + value;
+ if (valueString.length() == 1) {
+ valueString = "0" + valueString;
+ }
+ field.setText(valueString);
+ }
+
+
+ private abstract class DateView extends JLabel {
+ private static final long serialVersionUID = 1L;
+ private final JLabel label;
+ private Color foreground;
+ private Color background = Color.WHITE;
+ private Border defaultBorder = TimePanel.this.defaultBorder;
+
+ private DateView(int padding) {
+ this.label = new JLabel();
+ this.foreground = Color.BLACK;
+// this.label.setAlignmentX(JLabel.CENTER_ALIGNMENT);
+// this.label.setAlignmentY(JLabel.CENTER_ALIGNMENT);
+
+ setSelect(false);
+// this.setBackground(Color.RED);
+// this.label.setBackground(Color.BLUE);
+// this.label.setOpaque(true);
+
+ this.setFont(defFont);
+// Insets insets = new Insets(padding, padding, padding, padding);
+// SwingUtil.addComponent(this, gbl, label, 0, 0, 1, 1, 1.0, 1.0,
+// GridBagConstraints.CENTER, GridBagConstraints.NONE, insets);
+ addMouseListener(new MouseListener() {
+ @Override
+ public void mouseReleased(MouseEvent arg0) {
+ }
+
+ @Override
+ public void mousePressed(MouseEvent arg0) {
+ }
+
+ @Override
+ public void mouseExited(MouseEvent arg0) {
+ DateView.this.setSelect(false);
+ }
+
+ @Override
+ public void mouseEntered(MouseEvent arg0) {
+ DateView.this.setSelect(true);
+ }
+
+ @Override
+ public void mouseClicked(MouseEvent arg0) {
+// DateView.this.setSelect(false);
+ performAction();
+ }
+ });
+
+ }
+
+ private DateView(String labelString) {
+ this(100);
+ this.label.setText(labelString);
+ }
+
+ private DateView(Icon icon) {
+ this(0);
+ this.setIcon(icon);
+ Dimension dim = new Dimension(icon.getIconWidth() + 1, icon.getIconHeight() + 1);
+ this.setMinimumSize(dim);
+ this.setSize(dim);
+ // this.label.setBackground(Color.YELLOW);
+ // this.label.setOpaque(true);
+ }
+
+ private DateView(Icon icon, int size) {
+ this(icon);
+ Dimension dim = new Dimension(size, size);
+ this.setMaximumSize(dim);
+ setSize(dim);
+ setPreferredSize(dim);
+ }
+
+ private DateView(DateTime date, DateTime selectedDate, int month) {
+ this("" + date.getDayOfMonth());
+ this.foreground = date.getMonthOfYear() == month ? foreground
+ : Color.GRAY;
+
+ GridBagLayout gbl = new GridBagLayout();
+ this.setLayout(gbl);
+
+ this.label.setFont(defFont);
+
+ if (date.isEqual(selectedDate)) {
+ this.defaultBorder = TimePanel.this.greenBorder;
+ }
+
+ setSelect(false);
+
+ }
+
+ public abstract void performAction();
+
+ private void setSelect(boolean isSelect) {
+ if (isSelect) {
+ this.setBorder(selectBorder);
+ setBackground(new Color(205, 225, 225));
+ // this.label.setForeground(Color.WHITE);
+ } else {
+ this.setBorder(this.defaultBorder);
+ setBackground(this.background);
+ this.label.setForeground(this.foreground);
+ }
+ this.setOpaque(true);
+ }
+ }
+
+ private void confirmDate(DateTime date) {
+ this.textField.setText(convert(date));
+ dispose();
+ }
+
+ static DateTimeFormatter FMT = DateTimeFormat.forPattern("HH:mm:ss");
+
+ private static String convert(DateTime date) {
+ return date.toString(FMT);
+ }
+
+ private static DateTime convert(String string) {
+ try {
+ return DateTime.parse(string, FMT);
+ } catch (IllegalArgumentException e) {
+ return new DateTime();
+ }
+ }
+
+}