private void showJPopupMenu(MouseEvent e) { try { if (e.isPopupTrigger() && menu != null) { if (window == null) { if (isWindows) { window = new JDialog((Frame) null); ((JDialog) window).setUndecorated(true); } else { window = new JWindow((Frame) null); } window.setAlwaysOnTop(true); Dimension size = menu.getPreferredSize(); Point centerPoint = GraphicsEnvironment.getLocalGraphicsEnvironment().getCenterPoint(); if (e.getY() > centerPoint.getY()) window.setLocation(e.getX(), e.getY() - size.height); else window.setLocation(e.getX(), e.getY()); window.setVisible(true); menu.show(((RootPaneContainer) window).getContentPane(), 0, 0); // popup works only for focused windows window.toFront(); } } } catch (Exception ignored) { } }
private JDialog createDialog(String title) { JDialog dlg = null; Presenter currentPst = AWWindowsManager.instance().getCurrentPst(); // boolean thrower = (currentPst!=null && // currentPst.getClass().getSimpleName().equals("AbrirDocumentoPst")); // if (thrower){ // dlg = new JDialog(null, title, Dialog.ModalityType.MODELESS); // }else if (AWWindowsManager.instance().isInMainWindow() || (currentPst == null)) { dlg = new JDialog( AWWindowsManager.instance().getFrame(), title, Dialog.ModalityType.DOCUMENT_MODAL); } else { JDialog parent = (JDialog) ((View) currentPst.getView()).getParentContainer(); dlg = new JDialog(parent, title, Dialog.ModalityType.DOCUMENT_MODAL); } setupIcons(dlg); dlg.setUndecorated(true); dlg.getContentPane().setLayout(new BorderLayout()); installFestFixture(dlg); // installMouseAdapter(dlg); return dlg; }
public DialogPopupWrapper(Component owner, Component content, int x, int y) { if (!owner.isShowing()) { throw new IllegalArgumentException("Popup owner must be showing"); } final Window wnd = owner instanceof Window ? (Window) owner : SwingUtilities.getWindowAncestor(owner); if (wnd instanceof Frame) { myDialog = new JDialog((Frame) wnd, false); } else { myDialog = new JDialog((Dialog) wnd, false); } myDialog.getContentPane().setLayout(new BorderLayout()); myDialog.getContentPane().add(content, BorderLayout.CENTER); myDialog.setUndecorated(true); myDialog.pack(); myDialog.setLocation(x, y); }
public static void initComponents() { final Browser browser = new Browser(); JFrame parent = new JFrame(); final JDialog dialog = new JDialog(parent, "QUIZ", true); browser.loadURL("http://dtprojecten.ehb.be/~PR-Ready/StatMenuWindow.html?85519519551951951"); dialog.addWindowListener( new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { browser.dispose(); dialog.setVisible(false); dialog.dispose(); } }); browser.registerFunction( "createPieChart", new BrowserFunction() { public JSValue invoke(JSValue... jsValues) { browser.dispose(); dialog.setVisible(false); dialog.dispose(); PieChartData[] dataArr = new PieChartData[6]; dataArr[0] = new PieChartData("De grote quiz", 50); dataArr[1] = new PieChartData("Test uw IQ!", 1); dataArr[2] = new PieChartData("Gestolen rijexamens", 15); dataArr[3] = new PieChartData("Win een reis!", 4); dataArr[4] = new PieChartData("Test uw kennis!", 10); dataArr[5] = new PieChartData("Kan u de verschillen aanwijzen?", 20); new PieChartWindow(factory, dataArr, "Populariteit per quiz"); return JSValue.createUndefined(); } }); browser.registerFunction( "createLineChart", new BrowserFunction() { public JSValue invoke(JSValue... jsValues) { browser.dispose(); dialog.setVisible(false); dialog.dispose(); LineChartData[] lineData = new LineChartData[3]; String title = "User creation"; String subtitle = "By month"; String leftTitle = "Users"; String[] categories = new String[3]; categories[0] = "September"; categories[1] = "Oktober"; categories[2] = "November"; double[] data = new double[3]; data[0] = 10; data[1] = 2; data[2] = 50; lineData[0] = new LineChartData("September", data); lineData[1] = new LineChartData("Oktober", data); lineData[2] = new LineChartData("November", data); new LineChartWindow(factory, lineData, title, subtitle, leftTitle, categories); return JSValue.createUndefined(); } }); browser.registerFunction( "createColumnChart", new BrowserFunction() { public JSValue invoke(JSValue... jsValues) { browser.dispose(); dialog.setVisible(false); dialog.dispose(); ColumnData[] dataColumn = new ColumnData[1]; double[] data = new double[3]; data[0] = 33.6; data[1] = 88; data[2] = 66; String title = "Gemiddelde score per quiz"; String subtitle = ""; dataColumn[0] = new ColumnData("Gemiddelde Score", data); new ColumnChartWindow(factory, dataColumn, title, subtitle); return JSValue.createUndefined(); } }); browser.registerFunction( "onExit", new BrowserFunction() { public JSValue invoke(JSValue... jsValues) { browser.dispose(); dialog.setVisible(false); dialog.dispose(); System.out.println("exit"); try { AdminMenuWindow amw = new AdminMenuWindow(factory); } catch (UserNoPermissionException e) { e.printStackTrace(); } return JSValue.createUndefined(); } }); dialog.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); dialog.add(new BrowserView(browser), BorderLayout.CENTER); dialog.setResizable(false); dialog.setUndecorated(true); dialog.setBounds(GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds()); dialog.setLocationRelativeTo(parent); dialog.setVisible(true); }
public SheetMessage( final Window owner, final String title, final String message, final Icon icon, final String[] buttons, final DialogWrapper.DoNotAskOption doNotAskOption, final String defaultButton, final String focusedButton) { myWindow = new JDialog(owner, "This should not be shown", Dialog.ModalityType.APPLICATION_MODAL); myWindow.getRootPane().putClientProperty("apple.awt.draggableWindowBackground", Boolean.FALSE); myWindow.addWindowListener( new WindowAdapter() { @Override public void windowActivated(WindowEvent e) { super.windowActivated(e); } }); myParent = owner; myWindow.setUndecorated(true); myWindow.setBackground(Gray.TRANSPARENT); myController = new SheetController( this, title, message, icon, buttons, defaultButton, doNotAskOption, focusedButton); imageHeight = 0; registerMoveResizeHandler(); myWindow.setFocusable(true); myWindow.setFocusableWindowState(true); if (SystemInfo.isJavaVersionAtLeast("1.7")) { myWindow.setSize(myController.SHEET_NC_WIDTH, 0); setWindowOpacity(0.0f); myWindow.addComponentListener( new ComponentAdapter() { @Override public void componentShown(ComponentEvent e) { super.componentShown(e); setWindowOpacity(1.0f); myWindow.setSize(myController.SHEET_NC_WIDTH, myController.SHEET_NC_HEIGHT); } }); } else { myWindow.setModal(true); myWindow.setSize(myController.SHEET_NC_WIDTH, myController.SHEET_NC_HEIGHT); setPositionRelativeToParent(); } startAnimation(true); restoreFullscreenButton = couldBeInFullScreen(); if (restoreFullscreenButton) { FullScreenUtilities.setWindowCanFullScreen(myParent, false); } LaterInvocator.enterModal(myWindow); myWindow.setVisible(true); LaterInvocator.leaveModal(myWindow); }
public SheetMessage( final Window owner, final String title, final String message, final Icon icon, final String[] buttons, final DialogWrapper.DoNotAskOption doNotAskOption, final String defaultButton, final String focusedButton) { final Window activeWindow = KeyboardFocusManager.getCurrentKeyboardFocusManager().getActiveWindow(); final Component recentFocusOwner = activeWindow == null ? null : activeWindow.getMostRecentFocusOwner(); WeakReference<Component> beforeShowFocusOwner = new WeakReference<Component>(recentFocusOwner); maximizeIfNeeded(owner); myWindow = new JDialog(owner, "This should not be shown", Dialog.ModalityType.APPLICATION_MODAL); myWindow.getRootPane().putClientProperty("apple.awt.draggableWindowBackground", Boolean.FALSE); myWindow.addWindowListener( new WindowAdapter() { @Override public void windowActivated(@NotNull WindowEvent e) { super.windowActivated(e); } }); myParent = owner; myWindow.setUndecorated(true); myWindow.setBackground(Gray.TRANSPARENT); myController = new SheetController( this, title, message, icon, buttons, defaultButton, doNotAskOption, focusedButton); imageHeight = 0; registerMoveResizeHandler(); myWindow.setFocusable(true); myWindow.setFocusableWindowState(true); if (SystemInfo.isJavaVersionAtLeast("1.7")) { myWindow.setSize(myController.SHEET_NC_WIDTH, 0); setWindowOpacity(0.0f); myWindow.addComponentListener( new ComponentAdapter() { @Override public void componentShown(@NotNull ComponentEvent e) { super.componentShown(e); setWindowOpacity(1.0f); myWindow.setSize(myController.SHEET_NC_WIDTH, myController.SHEET_NC_HEIGHT); } }); } else { myWindow.setModal(true); myWindow.setSize(myController.SHEET_NC_WIDTH, myController.SHEET_NC_HEIGHT); setPositionRelativeToParent(); } startAnimation(true); restoreFullScreenButton = couldBeInFullScreen(); if (restoreFullScreenButton) { FullScreenUtilities.setWindowCanFullScreen(myParent, false); } LaterInvocator.enterModal(myWindow); myWindow.setVisible(true); LaterInvocator.leaveModal(myWindow); Component focusCandidate = beforeShowFocusOwner.get(); if (focusCandidate == null) { focusCandidate = IdeFocusManager.getGlobalInstance() .getLastFocusedFor(IdeFocusManager.getGlobalInstance().getLastFocusedFrame()); } // focusCandidate is null if a welcome screen is closed and ide frame is not opened. // this is ok. We set focus correctly on our frame activation. if (focusCandidate != null) { focusCandidate.requestFocus(); } }
public void initComponents() { final Browser browser = new Browser(); BrowserView browserView = new BrowserView(browser); JFrame parent = new JFrame(); final JDialog dialog = new JDialog(parent, "QUIZ", true); browser.addLoadListener( new LoadAdapter() { @Override public void onFinishLoadingFrame(FinishLoadingEvent event) { if (event.isMainFrame()) { String videoUrl = "https://www.youtube.com/embed/" + url + "?rel=0&controls=0&showinfo=0"; DOMDocument document = event.getBrowser().getDocument(); DOMNode root = document.findElement(By.id("video")); DOMElement iframe = document.createElement("iframe"); iframe.setAttribute("src", videoUrl); iframe.setAttribute("frameborder", "0"); root.appendChild(iframe); DOMNode root2 = document.findElement(By.id("text")); DOMElement p = document.createElement("p"); p.setAttribute("class", "text"); DOMNode n = document.createTextNode(question.getText()); root2.appendChild(p); p.appendChild(n); DOMNode answers = document.findElement(By.id("answers")); if (question.getAnswerType().equals(AnswerType.MULTIPLE_CHOICE)) { DOMNode form = document.createElement("form"); AnswerManager am = new AnswerManager(session); List<String> answerList = am.getAnswerByQuestionId(question.getId()); for (String answer : answerList) { DOMElement trueBox = document.createElement("input"); trueBox.setAttribute("type", "radio"); trueBox.setAttribute("name", "tf"); DOMNode dataTrue = document.createTextNode(answer); DOMElement labeltrue = document.createElement("label"); labeltrue.appendChild(dataTrue); form.appendChild(trueBox); form.appendChild(labeltrue); DOMElement br = document.createElement("br"); form.appendChild(br); } answers.appendChild(form); } if (question.getAnswerType().equals(AnswerType.TRUE_FALSE)) { DOMNode form = document.createElement("form"); DOMElement trueBox = document.createElement("input"); trueBox.setAttribute("type", "radio"); trueBox.setAttribute("name", "tf"); DOMNode dataTrue = document.createTextNode("true"); DOMElement labeltrue = document.createElement("label"); labeltrue.appendChild(dataTrue); DOMElement falseBox = document.createElement("input"); DOMNode dataFalse = document.createTextNode("false"); DOMElement labelFalse = document.createElement("label"); labelFalse.appendChild(dataFalse); falseBox.setAttribute("type", "radio"); falseBox.setAttribute("name", "tf"); form.appendChild(labeltrue); form.appendChild(trueBox); DOMElement br = document.createElement("br"); form.appendChild(br); form.appendChild(labelFalse); form.appendChild(falseBox); // answers.appendChild(form); } } } }); browser.loadURL("http://dtprojecten.ehb.be/~PR-Ready/question/videoFrame.html?853954951951959"); dialog.addWindowListener( new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { browser.dispose(); dialog.setVisible(false); dialog.dispose(); } }); browser.registerFunction( "nextQuestion", new BrowserFunction() { public JSValue invoke(JSValue... jsValues) { browser.dispose(); dialog.setVisible(false); dialog.dispose(); quizLauncher.setIncrement(quizLauncher.getIncrement() + 1); quizLauncher.windowChoice(); return JSValue.createUndefined(); } }); browser.registerFunction( "previousQuestion", new BrowserFunction() { public JSValue invoke(JSValue... jsValues) { browser.dispose(); dialog.setVisible(false); dialog.dispose(); quizLauncher.setIncrement(quizLauncher.getIncrement() - 1); quizLauncher.windowChoice(); return JSValue.createUndefined(); } }); dialog.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); dialog.add(new BrowserView(browser), BorderLayout.CENTER); dialog.setResizable(false); dialog.setUndecorated(true); dialog.setBounds(GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds()); dialog.setLocationRelativeTo(parent); dialog.setVisible(true); }
public void run() { while (connected) { try { Object obj = in.readObject(); if (obj.toString().equals("-101")) { connected = false; in.close(); out.close(); socket.close(); SwingUtilities.invokeLater( new Runnable() { public void run() { Cashier.closee = true; JOptionPane.showMessageDialog( null, "Disconnected from server. Please Restart", "Error:", JOptionPane.PLAIN_MESSAGE); try { m.stop(); } catch (Exception w) { } } }); } else if (obj.toString().split("::")[0].equals("broadcast")) { // System.out.println("braodcast received"); bc.run(obj.toString().substring(obj.toString().indexOf("::") + 2)); } else if (obj.toString().split("::")[0].equals("chat")) { // System.out.println("chat received: // "+obj.toString().substring(obj.toString().indexOf("::")+2)); cc.run(obj.toString().substring(obj.toString().indexOf("::") + 2)); } else if (obj.toString().split("::")[0].equals("rankings")) { String hhh = obj.toString().split("::")[1]; final JDialog jd = new JDialog(); jd.setUndecorated(false); JPanel pan = new JPanel(new BorderLayout()); JLabel ppp = new JLabel(); ppp.setFont(new Font("Arial", Font.BOLD, 20)); ppp.setText( "<html><pre>Thanks for playing !!!<br/>1st: " + hhh.split(":")[0] + "<br/>2nd: " + hhh.split(":")[1] + "<br/>3rd: " + hhh.split(":")[2] + "</pre></html>"); pan.add(ppp, BorderLayout.CENTER); JButton ok = new JButton("Ok"); ok.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { jd.setVisible(false); try { m.stop(); } catch (Exception w) { } } }); pan.add(ok, BorderLayout.SOUTH); jd.setContentPane(pan); jd.setModalityType(JDialog.ModalityType.APPLICATION_MODAL); jd.pack(); jd.setLocationRelativeTo(null); jd.setVisible(true); } else if (obj.toString().split("::")[0].equals("rank")) { rc.run(obj.toString().substring(obj.toString().indexOf("::") + 2)); } else { User hhh = null; try { hhh = (User) obj; /*if(usrD==1) { reply=obj; ccl.interrupt(); } else*/ { try { m.ur.changeData((User) obj); } catch (Exception w) { try { maain.ur.changeData((User) obj); } catch (Exception ppp) { ppp.printStackTrace(); } } } } catch (Exception p) { int iid = -1; try { iid = Integer.parseInt(obj.toString()); obj = in.readObject(); if (obj.toString().equals("-102")) { // ccl.interrupt(); SwingUtilities.invokeLater( new Runnable() { public void run() { Cashier.closee = true; JOptionPane.showMessageDialog( null, "Server Not Running.", "Error:", JOptionPane.PLAIN_MESSAGE); } }); } // Thread th = ((Thread)rev.remove(iid)); rev2.put(iid, obj); // System.out.println("Put: "+iid+" : "+obj.toString()+" : // "+Thread.currentThread()); // th.interrupt(); // ccl.interrupt(); } catch (Exception ppp) { /*ppp.printStackTrace();*/ System.out.println( "Shit: " + iid + " : " + obj.toString() + " : " + Thread.currentThread()); } } } try { Thread.sleep(500); } catch (Exception n) { } } catch (Exception m) { } } }