diff --git a/sources/net.sf.j2s.core/dist/swingjs/SwingJS-site.zip b/sources/net.sf.j2s.core/dist/swingjs/SwingJS-site.zip index e46407ecb..a8f5c839b 100644 Binary files a/sources/net.sf.j2s.core/dist/swingjs/SwingJS-site.zip and b/sources/net.sf.j2s.core/dist/swingjs/SwingJS-site.zip differ diff --git a/sources/net.sf.j2s.core/dist/swingjs/timestamp b/sources/net.sf.j2s.core/dist/swingjs/timestamp index af3b20978..f7ba85533 100644 --- a/sources/net.sf.j2s.core/dist/swingjs/timestamp +++ b/sources/net.sf.j2s.core/dist/swingjs/timestamp @@ -1 +1 @@ -20190316185356 +20190319211418 diff --git a/sources/net.sf.j2s.core/dist/swingjs/ver/3.2.4/SwingJS-site.zip b/sources/net.sf.j2s.core/dist/swingjs/ver/3.2.4/SwingJS-site.zip index e46407ecb..a8f5c839b 100644 Binary files a/sources/net.sf.j2s.core/dist/swingjs/ver/3.2.4/SwingJS-site.zip and b/sources/net.sf.j2s.core/dist/swingjs/ver/3.2.4/SwingJS-site.zip differ diff --git a/sources/net.sf.j2s.core/dist/swingjs/ver/3.2.4/timestamp b/sources/net.sf.j2s.core/dist/swingjs/ver/3.2.4/timestamp index af3b20978..f7ba85533 100644 --- a/sources/net.sf.j2s.core/dist/swingjs/ver/3.2.4/timestamp +++ b/sources/net.sf.j2s.core/dist/swingjs/ver/3.2.4/timestamp @@ -1 +1 @@ -20190316185356 +20190319211418 diff --git a/sources/net.sf.j2s.java.core/dist/SwingJS-site.zip b/sources/net.sf.j2s.java.core/dist/SwingJS-site.zip index e46407ecb..a8f5c839b 100644 Binary files a/sources/net.sf.j2s.java.core/dist/SwingJS-site.zip and b/sources/net.sf.j2s.java.core/dist/SwingJS-site.zip differ diff --git a/sources/net.sf.j2s.java.core/src/java/awt/Component.java b/sources/net.sf.j2s.java.core/src/java/awt/Component.java index 3b050992c..de73e3fa0 100644 --- a/sources/net.sf.j2s.java.core/src/java/awt/Component.java +++ b/sources/net.sf.j2s.java.core/src/java/awt/Component.java @@ -2385,17 +2385,15 @@ protected Dimension prefSizeComp() { Dimension dim = prefSize; if (dim == null || !(isPreferredSizeSet() || isValid())) { // synchronized (getTreeLock()) { - - // SwingJS TODO: it is not clear that we should deliver getMinimumSize here. - // - prefSize = // ( + dim = (width != 0 || height != 0 ? null + : isDisplayable() ? // // peer != null) ? - // peer.preferredSize() : - (width == 0 && height == 0 ? getMinimumSize() : new Dimension(width, height)); - dim = prefSize; + peer.getPreferredSize() : + getMinimumSize()); + prefSize = dim; } // } - return new Dimension(dim); + return (dim == null ? new Dimension(width, height) : new Dimension(dim)); } /** diff --git a/sources/net.sf.j2s.java.core/src/java/awt/peer/ComponentPeer.java b/sources/net.sf.j2s.java.core/src/java/awt/peer/ComponentPeer.java index c8e5bf3eb..74c0e49f4 100644 --- a/sources/net.sf.j2s.java.core/src/java/awt/peer/ComponentPeer.java +++ b/sources/net.sf.j2s.java.core/src/java/awt/peer/ComponentPeer.java @@ -90,9 +90,8 @@ public interface ComponentPeer { Point getLocationOnScreen(); -// SwingJS -- never called by Java Dimension getPreferredSize(); -// + Dimension getMinimumSize(); ColorModel getColorModel(); diff --git a/sources/net.sf.j2s.java.core/src/javax/swing/JTextArea.java b/sources/net.sf.j2s.java.core/src/javax/swing/JTextArea.java index f870ef2de..78259815c 100644 --- a/sources/net.sf.j2s.java.core/src/javax/swing/JTextArea.java +++ b/sources/net.sf.j2s.java.core/src/javax/swing/JTextArea.java @@ -39,7 +39,6 @@ import javax.swing.text.Element; import javax.swing.text.JTextComponent; import javax.swing.text.PlainDocument; - import swingjs.api.JSMinimalAbstractDocument; /** @@ -240,8 +239,6 @@ public String getUIClassID() { * @return the default document model */ protected Document createDefaultModel() { - // SwingJS -// return JSToolkit.getPlainDocument(this); return new PlainDocument(); } diff --git a/sources/net.sf.j2s.java.core/src/swingjs/plaf/JSComponentUI.java b/sources/net.sf.j2s.java.core/src/swingjs/plaf/JSComponentUI.java index a9da0c6b6..1a90765fa 100644 --- a/sources/net.sf.j2s.java.core/src/swingjs/plaf/JSComponentUI.java +++ b/sources/net.sf.j2s.java.core/src/swingjs/plaf/JSComponentUI.java @@ -2958,7 +2958,7 @@ public Insets getInsets() { @Override public void beginValidate() { - System.out.println("JSCUI beginValidate " + id); + //System.out.println("JSCUI beginValidate " + id); } @Override diff --git a/sources/net.sf.j2s.java.core/src/swingjs/plaf/JSFrameUI.java b/sources/net.sf.j2s.java.core/src/swingjs/plaf/JSFrameUI.java index 051b98a84..75aadcedc 100644 --- a/sources/net.sf.j2s.java.core/src/swingjs/plaf/JSFrameUI.java +++ b/sources/net.sf.j2s.java.core/src/swingjs/plaf/JSFrameUI.java @@ -59,10 +59,6 @@ public JSFrameUI() { } - protected void selected() { - ((JFrame) jc).toFront(); - } - // public void notifyFrameMoved() { // Toolkit.getEventQueue().postEvent(new ComponentEvent(frame, // ComponentEvent.COMPONENT_MOVED)); @@ -119,36 +115,7 @@ public DOMNode updateDOMNode() { DOMNode.setTopLeftAbsolute(modalNode, 0, 0); DOMNode.setSize(modalNode, screen.width, screen.height); } - // we have to wait until the frame is wrapped. - @SuppressWarnings("unused") - DOMNode fnode = frameNode; - - JSFunction fGetFrameParent = null; - /** - * @j2sNative var me = this; - * fGetFrameParent = function(mode, x, y) { - * switch(arguments.length) { - * case 1: - * if (mode == 501) - * me.selected$(); - * me.hideMenu$(); - * return $(fnode).parent(); - * case 3: - * if (mode == 506) { - * me.moveFrame$I$I(x, y); - * return null; - * } - * } - * - * return null; - * } - */ - { - hideMenu(); - } - - - J2S.setDraggable(titleBarNode, fGetFrameParent); + setDraggableEvents(); titleBarNode.appendChild(titleNode); titleBarNode.appendChild(closerWrap); closerWrap.appendChild(closerNode); @@ -173,7 +140,51 @@ public DOMNode updateDOMNode() { return domNode; } + @Override + protected void setDraggableEvents() { + @SuppressWarnings("unused") + DOMNode fnode = frameNode; + JSFunction fGetFrameParent = null; + /** + * @j2sNative var me = this; + * fGetFrameParent = function(mode, x, y) { + * switch(arguments.length) { + * case 1: + * if (mode == 501) + * me.selected$(); + * me.hideMenu$(); + * return $(fnode).parent(); + * case 3: + * if (mode == 506) { + * me.moveFrame$I$I(x, y); + * return null; + * } + * } + * + * return null; + * } + */ + { + selected(); + moveFrame(0,0); + hideMenu(); + } + + J2S.setDraggable(titleBarNode, fGetFrameParent); + } + + /** + * Do not change this method name + * referenced by j2sNative, above + */ + protected void selected() { + // subclassed by JSInternalFrameUI + ((JFrame) jc).toFront(); + } + + /** + * Do not change this method name * referenced by j2sNative, above */ /*not private*/ void hideMenu() { @@ -182,7 +193,13 @@ public DOMNode updateDOMNode() { - void moveFrame(int x, int y) { + /** + * Do not change this method name + * referenced by j2sNative, above + * @param x + * @param y + */ + /*not private*/ void moveFrame(int x, int y) { if (!isInternalFrame) { x = Math.max(30 - frame.getWidth(), x); y = Math.max(0, y); diff --git a/sources/net.sf.j2s.java.core/src/swingjs/plaf/JSTextAreaUI.java b/sources/net.sf.j2s.java.core/src/swingjs/plaf/JSTextAreaUI.java index 9bedd72c3..9587cecb1 100644 --- a/sources/net.sf.j2s.java.core/src/swingjs/plaf/JSTextAreaUI.java +++ b/sources/net.sf.j2s.java.core/src/swingjs/plaf/JSTextAreaUI.java @@ -5,6 +5,12 @@ import java.beans.PropertyChangeEvent; import javax.swing.JTextArea; +import javax.swing.text.Document; +import javax.swing.text.Element; +import javax.swing.text.JTextComponent; +import javax.swing.text.PlainView; +import javax.swing.text.View; +import javax.swing.text.WrappedPlainView; import swingjs.JSToolkit; import swingjs.api.js.DOMNode; @@ -45,12 +51,20 @@ public DOMNode updateDOMNode() { @Override public void propertyChange(PropertyChangeEvent e) { String prop = e.getPropertyName(); - if (prop == "ancestor") { +// Object newValue = e.getNewValue(); +// Object oldValue = e.getOldValue(); + switch(prop) { + case "ancestor": setJ2sMouseHandler(); - } + break; + } super.propertyChange(e); } - + + protected void updateRootView() { + useRootView = true; + rootView.setView(create(editor.getDocument().getDefaultRootElement()));// does not take into account nested documents like HTML (I guess) + } /** * Get the real height and width of the text in a JavaScript textarea * Used by JSScrollPaneUI @@ -109,4 +123,22 @@ protected DOMNode setHTMLElement() { "position", "absolute"); } + /** + * Creates the view for an element. Returns a WrappedPlainView or PlainView. + * + * @param elem the element + * @return the view + */ + @Override + public View create(Element elem) { + JTextArea area = (JTextArea) c; + View v; + if (area.getLineWrap()) { + v = new WrappedPlainView(elem, area.getWrapStyleWord()); + } else { + v = new PlainView(elem); + } + return v; + } + } diff --git a/sources/net.sf.j2s.java.core/src/swingjs/plaf/JSTextUI.java b/sources/net.sf.j2s.java.core/src/swingjs/plaf/JSTextUI.java index 550fb3e13..fd9a764d9 100644 --- a/sources/net.sf.j2s.java.core/src/swingjs/plaf/JSTextUI.java +++ b/sources/net.sf.j2s.java.core/src/swingjs/plaf/JSTextUI.java @@ -29,6 +29,7 @@ import java.awt.Color; import java.awt.Component; +import java.awt.Container; import java.awt.Dimension; import java.awt.Font; import java.awt.Graphics; @@ -36,6 +37,8 @@ import java.awt.KeyboardFocusManager; import java.awt.LayoutManager; import java.awt.Point; +import java.awt.Rectangle; +import java.awt.Shape; import java.awt.event.ActionEvent; import java.awt.event.KeyEvent; @@ -44,6 +47,7 @@ import javax.swing.ActionMap; import javax.swing.InputMap; import javax.swing.JComponent; +import javax.swing.JTextArea; import javax.swing.SwingUtilities; import javax.swing.UIManager; import javax.swing.event.CaretEvent; @@ -52,13 +56,20 @@ import javax.swing.plaf.InputMapUIResource; import javax.swing.plaf.TextUI; import javax.swing.plaf.UIResource; +import javax.swing.text.AbstractDocument; +import javax.swing.text.AttributeSet; +import javax.swing.text.BadLocationException; import javax.swing.text.Caret; import javax.swing.text.DefaultCaret; import javax.swing.text.DefaultEditorKit; +import javax.swing.text.Document; import javax.swing.text.EditorKit; +import javax.swing.text.Element; import javax.swing.text.JTextComponent; import javax.swing.text.Position; +import javax.swing.text.Position.Bias; import javax.swing.text.TextAction; +import javax.swing.text.View; import javax.swing.text.html.HTMLDocument; import swingjs.JSKeyEvent; @@ -125,7 +136,14 @@ public abstract class JSTextUI extends JSLightweightUI {// implements {ViewFacto transient JTextComponent editor; protected boolean editable = true; + protected RootView rootView = new RootView(); + TextListener textListener; // referred to in j2sApplet.js + + protected boolean useRootView = false; // TextArea only? + + + @Override public DOMNode updateDOMNode() { if (editor.isOpaque() && editor.isEnabled()) @@ -145,7 +163,7 @@ public DOMNode updateDOMNode() { @Override public boolean handleJSEvent(Object target, int eventType, Object jQueryEvent) { String type = /** @j2sNative jQueryEvent.type || */null; - System.out.println("JSTextUI handlejs "+type + " " + eventType); + //System.out.println("JSTextUI handlejs "+type + " " + eventType); if (JSToolkit.isMouseEvent(eventType)) { return NOT_HANDLED; } @@ -491,8 +509,6 @@ protected final JTextComponent getComponent() { // --- ComponentUI methods -------------------------------------------- - TextListener textListener; // referred to in j2sApplet.js - /** * Installs the UI for a component. This does the following things. *
+ * This can be called on a different thread from the + * event dispatching thread and is basically unsafe to + * propagate into the component. To make this safe, + * the operation is transferred over to the event dispatching + * thread for completion. It is a design goal that all view + * methods be safe to call without concern for concurrency, + * and this behavior helps make that true. + * + * @param child the child view + * @param width true if the width preference has changed + * @param height true if the height preference has changed + */ + public void preferenceChanged(View child, boolean width, boolean height) { + editor.revalidate(); + } + + /** + * Determines the desired alignment for this view along an axis. + * + * @param axis may be either X_AXIS or Y_AXIS + * @return the desired alignment, where 0.0 indicates the origin + * and 1.0 the full span away from the origin + */ + public float getAlignment(int axis) { + if (view != null) { + return view.getAlignment(axis); + } + return 0; + } + + /** + * Renders the view. + * + * @param g the graphics context + * @param allocation the region to render into + */ + public void paint(Graphics g, Shape allocation) { + if (view != null) { + Rectangle alloc = (allocation instanceof Rectangle) ? + (Rectangle)allocation : allocation.getBounds(); + setSize(alloc.width, alloc.height); + view.paint(g, allocation); + } + } + + /** + * Sets the view parent. + * + * @param parent the parent view + */ + public void setParent(View parent) { + throw new Error("Can't set parent on root view"); + } + + /** + * Returns the number of views in this view. Since + * this view simply wraps the root of the view hierarchy + * it has exactly one child. + * + * @return the number of views + * @see #getView + */ + public int getViewCount() { + return 1; + } + + /** + * Gets the n-th view in this container. + * + * @param n the number of the view to get + * @return the view + */ + public View getView(int n) { + return view; + } + + /** + * Returns the child view index representing the given position in + * the model. This is implemented to return the index of the only + * child. + * + * @param pos the position >= 0 + * @return index of the view representing the given position, or + * -1 if no view represents that position + * @since 1.3 + */ + public int getViewIndex(int pos, Position.Bias b) { + return 0; + } + + /** + * Fetches the allocation for the given child view. + * This enables finding out where various views + * are located, without assuming the views store + * their location. This returns the given allocation + * since this view simply acts as a gateway between + * the view hierarchy and the associated component. + * + * @param index the index of the child + * @param a the allocation to this view. + * @return the allocation to the child + */ + public Shape getChildAllocation(int index, Shape a) { + return a; + } + + @Override + public Shape modelToView(int pos, Shape a, Bias b) throws BadLocationException { + // TODO Auto-generated method stub + return null; + } + + @Override + public int viewToModel(float x, float y, Shape a, Bias[] biasReturn) { + // TODO Auto-generated method stub + return 0; + } + } + /** * Fetches the EditorKit for the UI. * diff --git a/sources/net.sf.j2s.java.core/src/swingjs/plaf/JSWindowUI.java b/sources/net.sf.j2s.java.core/src/swingjs/plaf/JSWindowUI.java index 4a013d541..73885eacd 100644 --- a/sources/net.sf.j2s.java.core/src/swingjs/plaf/JSWindowUI.java +++ b/sources/net.sf.j2s.java.core/src/swingjs/plaf/JSWindowUI.java @@ -229,9 +229,16 @@ public void endValidate() { protected void bindWindowEvents() { setJ2sMouseHandler(); + setDraggableEvents(); if (closerNode != null) bindJQueryEvents(closerNode, "click mouseenter mouseout", SOME_MOUSE_EVENT); } + + protected void setDraggableEvents() { + // Frame and Dialog only + } + + private static void setChildVisibilities(JComponent jc) { for (int i = jc.getComponentCount(); --i >= 0;) { diff --git a/sources/net.sf.j2s.java.core/src/swingjs/plaf/TextListener.java b/sources/net.sf.j2s.java.core/src/swingjs/plaf/TextListener.java index ffbe4656f..e03e4ea6f 100644 --- a/sources/net.sf.j2s.java.core/src/swingjs/plaf/TextListener.java +++ b/sources/net.sf.j2s.java.core/src/swingjs/plaf/TextListener.java @@ -70,12 +70,22 @@ void checkDocument() { public void propertyChange(PropertyChangeEvent e) { String prop = e.getPropertyName(); // System.out.println("JSTextListener property change: " + prop + " " + e.getSource()); - if ("font" == prop || "foreground" == prop || "preferredSize" == prop) { + switch (prop) { + case "font": + case "foreground": + case "preferredSize": JTextComponent txtComp = (JTextComponent) e.getSource(); ((JSComponentUI) txtComp.getUI()).propertyChangedFromListener(e, prop); - } - if ("editable" == prop) + break; + case "editable": ui.setEditable(((Boolean) e.getNewValue()).booleanValue()); + break; + case "document": + if (e.getNewValue() != null) + ui.updateRootView(); + break; + } + } @Override diff --git a/sources/net.sf.j2s.java.core/src/test/TApp2.java b/sources/net.sf.j2s.java.core/src/test/TApp2.java index 5eca0e2cf..0c92d315f 100644 --- a/sources/net.sf.j2s.java.core/src/test/TApp2.java +++ b/sources/net.sf.j2s.java.core/src/test/TApp2.java @@ -3,24 +3,36 @@ import java.applet.Applet; import java.awt.AlphaComposite; import java.awt.BasicStroke; +import java.awt.BorderLayout; import java.awt.Button; import java.awt.Color; import java.awt.Component; +import java.awt.Dialog; +import java.awt.Dimension; +import java.awt.Event; +import java.awt.FlowLayout; import java.awt.Font; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.GridLayout; import java.awt.Image; import java.awt.Label; +import java.awt.Panel; import java.awt.Scrollbar; import java.awt.TextArea; import java.awt.TextField; +import java.awt.datatransfer.Clipboard; +import java.awt.datatransfer.DataFlavor; +import java.awt.datatransfer.StringSelection; +import java.awt.datatransfer.Transferable; import java.awt.event.AdjustmentEvent; import java.awt.event.AdjustmentListener; import java.awt.event.FocusEvent; import java.awt.event.FocusListener; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; +import java.awt.event.WindowAdapter; +import java.awt.event.WindowEvent; import javax.swing.JButton; import javax.swing.JLabel; @@ -279,4 +291,5 @@ public void mouseReleased(MouseEvent e) { }); } -} \ No newline at end of file +} + diff --git a/sources/net.sf.j2s.java.core/src/test/Test_Dialog.java b/sources/net.sf.j2s.java.core/src/test/Test_Dialog.java index 29b23e5ab..fb85bedfc 100644 --- a/sources/net.sf.j2s.java.core/src/test/Test_Dialog.java +++ b/sources/net.sf.j2s.java.core/src/test/Test_Dialog.java @@ -1,10 +1,27 @@ package test; import java.awt.BorderLayout; +import java.awt.Button; import java.awt.Color; +import java.awt.Component; +import java.awt.Dialog; +import java.awt.Dimension; +import java.awt.Event; +import java.awt.FlowLayout; +import java.awt.Font; +import java.awt.Frame; import java.awt.GridLayout; +import java.awt.Label; +import java.awt.Panel; +import java.awt.TextArea; +import java.awt.datatransfer.Clipboard; +import java.awt.datatransfer.DataFlavor; +import java.awt.datatransfer.StringSelection; +import java.awt.datatransfer.Transferable; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import java.awt.event.WindowAdapter; +import java.awt.event.WindowEvent; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import java.io.File; @@ -12,11 +29,13 @@ import javax.swing.BoxLayout; import javax.swing.JButton; import javax.swing.JColorChooser; +import javax.swing.JDialog; import javax.swing.JFileChooser; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JOptionPane; import javax.swing.JPanel; +import javax.swing.JTextArea; import javax.swing.plaf.UIResource; public class Test_Dialog extends JFrame implements PropertyChangeListener { @@ -168,6 +187,38 @@ public void actionPerformed(ActionEvent e) { }); p.add(b); + b = new JButton("ExportDialog"); + b.addActionListener(new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + + Dialog d = new ImportExportDialog(null, "Export Dialog"); + d.setVisible(true); +// Test_Dialog.this +// .onDialogReturn(JColorChooser.showDialog(Test_Dialog.this, "Testing JColorChooser", Color.RED)); +// + } + + }); + p.add(b); + + b = new JButton("ExportJDialog"); + b.addActionListener(new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + + JDialog d = new ImportExportJDialog(null, "Export Dialog"); + d.setVisible(true); +// Test_Dialog.this +// .onDialogReturn(JColorChooser.showDialog(Test_Dialog.this, "Testing JColorChooser", Color.RED)); +// + } + + }); + p.add(b); + pack(); setVisible(true); @@ -183,3 +234,204 @@ public static void main(String[] args) { } } + +class ImportExportDialog extends Dialog +{ + protected Button closeButton, copyPasteButton, importButton; + protected Label label; + public TextArea textArea; + + public ImportExportDialog(Frame parent, String title) { + + super(parent, title, true); + + this.setLayout(new BorderLayout(15, 0)); + + if (title.equals("Import Dialog")) + add("North", new Label("Import using CTRL + V")); + else + add("North", new Label("Export using CTRL + C")); + + textArea = new TextArea() { + public Dimension getPreferredSize() { + Dimension d = super.getPreferredSize(); + System.out.println(this.getRows() + " " + this.getColumns()); + System.out.println("export dialog textarea pref d = " + d); + return d; + } + public Dimension preferredSize() { + Dimension d = super.preferredSize(); + System.out.println("export dialog pref textarea pref d = " + d); + return d; + } + + public Dimension minimumSize() { + Dimension d = super.minimumSize(); + System.out.println("export dialog min textarea min d = " + d); + return d; + } + + public Dimension getMinimumSize() { + Dimension d = super.getMinimumSize(); + System.out.println("export dialog textarea min d = " + d); + return d; + } + + }; + textArea.setText( + "this is a test of the system and this is a test of the system\n" + + + "this is a test of the system and this is a test of the system\n" + + + "this is a test of the system and this is a test of the system\n" + + + "this is a test of the system and this is a test of the system\n" + + + "this is a test of the system and this is a test of the system\n" + + + "this is a test of the system and this is a test of the system\n" + + + "this is a test of the system and this is a test of the system\n" + + + "this is a test of the system and this is a test of the system\n" + + + "this is a test of the system and this is a test of the system\n" + + + "this is a test of the system and this is a test of the system\n" + + + "this is a test of the system and this is a test of the system\n" + + + "this is a test of the system and this is a test of the system\n" + + + "this is a test of the system and this is a test of the system\n" + + + "this is a test of the system and this is a test of the system\n" + + + "this is a test of the system and this is a test of the system\n" + + + "this is a test of the system and this is a test of the system\n" + + + "this is a test of the system and this is a test of the system\n" + + + "this is a test of the system\nthis is a test of the system\nthis is a test of the system\nthis is a test of the system\n"); + textArea.setFont(new Font(Font.DIALOG, Font.PLAIN, 18)); + this.add("Center", textArea); + + copyPasteButton = new Button("Copy"); + if (title.equals("Import Dialog")) + copyPasteButton.setLabel("Paste"); + + importButton = new Button("Import"); + + closeButton = new Button("Close"); + if (title.equals("Import Dialog")) + closeButton.setLabel("Close"); + closeButton.addActionListener(new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + hide(); + dispose(); + } + + }); + + Panel p = new Panel(); + p.setLayout(new FlowLayout(FlowLayout.CENTER, 15, 10)); +// p.add(copyPasteButton); + if (title.equals("Import Dialog")) + p.add(importButton); + p.add(closeButton); + this.add("South", p); + setLocation(430,0); + this.pack(); + System.out.println(textArea.getPreferredSize()); + setResizable(false); + validate(); + repaint(); + } + +} // end class +class ImportExportJDialog extends JDialog +{ + protected Button closeButton, copyPasteButton, importButton; + protected Label label; + public TextArea textArea; + + public ImportExportJDialog(JFrame parent, String title) { + + super(parent, title, true); + + this.setLayout(new BorderLayout(15, 0)); + + if (title.equals("Import Dialog")) + add("North", new Label("Import using CTRL + V")); + else + add("North", new Label("Export using CTRL + C")); + + textArea = new TextArea() { + public Dimension getPreferredSize() { + Dimension d = super.getPreferredSize(); + System.out.println(this.getRows() + " " + this.getColumns()); + System.out.println("export dialog textarea pref d = " + d); + return d; + } + public Dimension preferredSize() { + Dimension d = super.preferredSize(); + System.out.println("export dialog pref textarea pref d = " + d); + return d; + } + + public Dimension minimumSize() { + Dimension d = super.minimumSize(); + System.out.println("export dialog min textarea min d = " + d); + return d; + } + + public Dimension getMinimumSize() { + Dimension d = super.getMinimumSize(); + System.out.println("export dialog textarea min d = " + d); + return d; + } + + }; + textArea.setText("this is a test of the system and this is a test of the system\nthis is a test of the system\nthis is a test of the system\nthis is a test of the system\nthis is a test of the system\n"); + textArea.setFont(new Font(Font.DIALOG, Font.PLAIN, 18)); + this.add("Center", textArea); + + copyPasteButton = new Button("Copy"); + if (title.equals("Import Dialog")) + copyPasteButton.setLabel("Paste"); + + importButton = new Button("Import"); + + closeButton = new Button("Close"); + if (title.equals("Import Dialog")) + closeButton.setLabel("Close"); + closeButton.addActionListener(new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + hide(); + dispose(); + } + + }); + + + Panel p = new Panel(); + p.setLayout(new FlowLayout(FlowLayout.CENTER, 15, 10)); +// p.add(copyPasteButton); + if (title.equals("Import Dialog")) + p.add(importButton); + p.add(closeButton); + this.add("South", p); + setLocation(430,0); + this.pack(); + System.out.println(textArea.getPreferredSize()); + setResizable(false); + validate(); + repaint(); + } + +} \ No newline at end of file