1 package jspecview.js2d; 2 3 import org.jmol.awtjs.swing.Dimension; 4 import org.jmol.awtjs.swing.JComponent; 5 import org.jmol.awtjs.swing.JEditorPane; 6 import org.jmol.awtjs.swing.JDialog; 7 import org.jmol.awtjs.swing.JLabel; 8 import org.jmol.awtjs.swing.JScrollPane; 9 import org.jmol.awtjs.swing.JTable; 10 import javajs.util.PT; 11 12 import jspecview.api.JSVPanel; 13 import jspecview.api.PlatformDialog; 14 import jspecview.common.Spectrum; 15 import jspecview.dialog.JSVDialog; 16 import jspecview.dialog.DialogManager; 17 18 /** 19 * A DialogManager for JavaScript. 20 * 21 * @author hansonr 22 * 23 */ 24 public class JsDialogManager extends DialogManager { 25 JsDialogManager()26 public JsDialogManager() { 27 // for reflection 28 } 29 30 @Override getDialog(JSVDialog jsvDialog)31 public PlatformDialog getDialog(JSVDialog jsvDialog) { 32 return new JsDialog(this, jsvDialog, registerDialog(jsvDialog)); 33 } 34 35 @Override getDialogInput(Object parentComponent, String phrase, String title, int msgType, Object icon, Object[] objects, String defaultStr)36 public String getDialogInput(Object parentComponent, String phrase, 37 String title, int msgType, Object icon, Object[] objects, 38 String defaultStr) { 39 /** 40 * @j2sNative 41 * 42 * return prompt(phrase, defaultStr); 43 */ 44 { 45 return null; 46 } 47 } 48 49 @Override showMessageDialog(Object parentComponent, String msg, String title, int msgType)50 public void showMessageDialog(Object parentComponent, String msg, 51 String title, int msgType) { 52 /** 53 * @j2sNative 54 * 55 * alert(msg); 56 */ 57 { 58 59 } 60 } 61 62 @Override getLocationOnScreen(Object component)63 public int[] getLocationOnScreen(Object component) { 64 // TODO Auto-generated method stub 65 return new int[2]; 66 } 67 68 @Override getOptionFromDialog(Object frame, String[] items, JSVPanel jsvp, String dialogName, String labelName)69 public int getOptionFromDialog(Object frame, String[] items, JSVPanel jsvp, 70 String dialogName, String labelName) { 71 // for export and others 72 return vwr.html5Applet.getOption(items, dialogName, labelName); 73 } 74 75 /** 76 * Looks a lot like Swing, right? :) 77 * 78 */ 79 @Override showProperties(Object frame, Spectrum spectrum)80 public void showProperties(Object frame, Spectrum spectrum) { 81 JDialog dialog = new JDialog();// no manager needed here 82 dialog.setTitle("Header Information"); 83 Object[][] rowData = spectrum.getHeaderRowDataAsArray(); 84 String[] columnNames = { "Label", "Description" }; 85 DialogTableModel tableModel = new DialogTableModel(columnNames, rowData, 86 false, true); 87 JTable table = new JTable(tableModel); 88 table.setPreferredScrollableViewportSize(new Dimension(400, 195)); 89 JScrollPane scrollPane = new JScrollPane(table); 90 dialog.getContentPane().add(scrollPane); 91 dialog.pack(); 92 dialog.setVisible(true); 93 dialog.toFront(); 94 } 95 96 @Override showMessage(Object frame, String text, String title)97 public void showMessage(Object frame, String text, String title) { 98 JDialog dialog = new JDialog(); 99 /** 100 * @j2sNative 101 * 102 * dialog.manager = this; 103 */ 104 {} 105 dialog.setTitle(title); 106 JComponent pane; 107 if (text.indexOf("</div>") >= 0) { 108 pane = new JLabel(text); 109 } else { 110 // JEditorPane sourcePane = new JEditorPane(); 111 // sourcePane.setText(text); 112 // sourcePane.setEditable(false); 113 // sourcePane.setFont(new Font(null, Font.BOLD, 12)); 114 // JScrollPane scrollPane = new JScrollPane(sourcePane); 115 // scrollPane.setPreferredSize(new Dimension(500, 400)); 116 // scrollPane.setMinimumSize(new Dimension(500, 400)); 117 // JPanel contentPanel = new JPanel(new BorderLayout()); 118 // contentPanel.add(scrollPane, BorderLayout.CENTER); 119 // dialog.getContentPane().add(contentPanel); 120 121 pane = new JEditorPane(); 122 pane.setText(text); 123 } 124 dialog.getContentPane().add(pane); 125 dialog.pack(); 126 dialog.setVisible(true); 127 dialog.toFront(); 128 } 129 130 /** 131 * Jmol.Swing.click() callback (via SwingController) 132 * @param eventId 133 */ actionPerformed(String eventId)134 public void actionPerformed(String eventId) { 135 int pt = eventId.indexOf("/JT"); 136 if (pt >= 0) { 137 int pt2 = eventId.lastIndexOf ("_"); 138 int pt1 = eventId.lastIndexOf ("_", pt2 - 1); 139 int irow = PT.parseInt(eventId.substring(pt1 + 1, pt2)); 140 int icol = PT.parseInt(eventId.substring(pt2 + 1)); 141 processTableEvent(eventId.substring(0, pt) + "/ROWCOL", irow, icol, false); 142 return; 143 } 144 processClick(eventId); 145 } 146 147 } 148