public void showDialog(JComponent dialog) { closeDialog(); JRootPane rootPane = SwingUtilities.getRootPane(mainPanel); if (rootPane == null) { log.severe("could not find root pane for viewer to show dialog " + dialog); } else { JLayeredPane layeredPane = rootPane.getLayeredPane(); Dimension d = dialog.getPreferredSize(); if (dialogPanel == null) { dialogPanel = new DialogPanel(this, new BorderLayout()); } Insets insets = dialogPanel.getInsets(); int width = viewerPanel.getWidth() - insets.left - insets.right; int height = viewerPanel.getHeight() - insets.top - insets.bottom; if (d.width > width) { d.width = width; } if (d.height > height) { d.height = height; } dialogPanel.add(dialog, BorderLayout.CENTER); dialogPanel.setBounds( ((width - d.width) >> 1) + insets.left, ((height - d.height) >> 1) + insets.top, d.width + insets.left + insets.right, d.height + insets.top + insets.bottom); dialog.setVisible(true); layeredPane.add(dialogPanel, DIALOG_LAYER); currentDialog = dialog; mainPanel.repaint(); } }
public boolean closeDialog(DialogTab dialogTab) { for (int i = 0; i < dialogTabArrayList.size(); i++) { if (dialogTabArrayList.get(i).equals(dialogTab)) { dialogPanelArrayList.remove(i); dialogTabArrayList.remove(i); if (!(currentDialogPanel == null)) currentDialogPanel.setVisible(false); if (dialogTabArrayList.size() == 0) { dialogTabsPanel.setVisible(false); currentDialogTab = null; currentDialogPanel = null; repaint(); revalidate(); return true; } if ((dialogTab.equals(currentDialogTab))) { if (i > 0) { currentDialogPanel = dialogPanelArrayList.get(i - 1); currentDialogTab = dialogTabArrayList.get(i - 1); } else { currentDialogPanel = dialogPanelArrayList.get(i); currentDialogTab = dialogTabArrayList.get(i); } } if (!(currentDialogPanel == null)) { currentDialogTab.setBorder(new LineBorder(Color.RED)); currentDialogPanel.setBounds(0, 84, 960, 1000); bigPanel.add(currentDialogPanel); currentDialogPanel.setVisible(true); } dialogTabsPanel.setVisible(false); if (dialogTabArrayList.size() > 0) repaintDialogTabsPanel(); bigPanel.repaint(); bigPanel.revalidate(); break; } } return false; }
public void vetoableChange(PropertyChangeEvent evt) throws PropertyVetoException { Object source = evt.getSource(); if (source instanceof JEWTDialog) { JEWTDialog dialog = (JEWTDialog) source; if (JEWTDialog.isDialogClosingEvent(evt)) { DialogPanel dp = (DialogPanel) dialog.getContent(); if (dp.getRoot().trim().length() == 0) { // Display Alert and request focus JOptionPane.showMessageDialog( dialog, "Root cannot be blank", "DTD to Schema", JOptionPane.ERROR_MESSAGE); dp.getRootCombo().requestFocus(); throw new PropertyVetoException("Root cannot be blank", evt); } if (dp.getSchemaName().trim().length() == 0) { // Display Alert and request focus JOptionPane.showMessageDialog( dialog, "Schema name cannot be blank", "DTD to Schema", JOptionPane.ERROR_MESSAGE); dp.getSchemaNameFld().requestFocus(); throw new PropertyVetoException("Schema name cannot be blank", evt); } } } else System.out.println("No action taken"); // NOTRANS }
public boolean handleEvent(IdeAction action, Context context) { int cmdId = action.getCommandId(); String msg = ""; boolean ret = false; if (cmdId == DTD_TO_SCHEMA_CMD_ID) { TextNode element = null; if (context.getElement() != null && context.getElement() instanceof TextNode && context.getElement().getShortLabel().toUpperCase().endsWith(".DTD")) element = (TextNode) context.getElement(); if (element == null) // Check Editor { Editor editor = EditorManager.getEditorManager().getCurrentEditor(); if (editor != null) { if (editor.getContext().getNode() instanceof TextNode && editor.getContext().getNode().getShortLabel().toUpperCase().endsWith(".DTD")) { element = (TextNode) editor.getContext().getNode(); } } } if (element != null) { try { final TextNode dtdNode = (TextNode) element; // We need: // The root name // The path to the schema to generate final Project currentPrj = Ide.getActiveProject(); final String srcPath = JProjectUtil.getProjectBasePath(currentPrj).getFile().toString(); if (dp == null) dp = new DialogPanel(); dp.setDefaultLocation(srcPath); // Set the DTD root list URL dtdURL = dtdNode.getURL(); // get the DTD object dp.getRootCombo().removeAllItems(); DTD dtdNoRoot = getDTD(dtdURL, null); NamedNodeMap map = dtdNoRoot.getElementDecls(); for (int i = 0; i < map.getLength(); i++) { Node node = map.item(i); dp.getRootCombo().addItem(node.getNodeName()); } // Suggest a default name for the schema String dtdFullName = dtdNode.getLongLabel(); String xsdFullName = dtdFullName.substring(0, dtdFullName.lastIndexOf(".dtd")) + ".xsd"; dp.getSchemaNameFld().setText(xsdFullName); JEWTDialog dlg = OnePageWizardDialogFactory.createJEWTDialog(dp, null, "DTD to Schema"); dlg.addVetoableChangeListener(new LocalVetoableChangeListener()); dlg.setDefaultButton(JEWTDialog.BUTTON_OK); dlg.setOKButtonEnabled(true); String topic = "dtd_to_schema_html"; HelpSystem.getHelpSystem().registerTopic((JComponent) dlg.getContent(), topic); boolean go = WizardLauncher.runDialog(dlg); if (go) { final String root = dp.getRoot(); final String fName = dp.getSchemaName(); class SchemaGenerationRunnable implements Runnable { XmlSchemaNode xsn = null; boolean ok = true; public void run() { try { URL dtdURL = dtdNode.getURL(); // get the DTD object DTD dtd = getDTD(dtdURL, root); // convert DTD to Schema DOM tree XMLDocument dtddoc = dtd.convertDTD2Schema(); URL classURL = URLFactory.newURL(fName); if (classURL == null) { JOptionPane.showMessageDialog( null, "Cannot create URL for " + fName, "Ooops", JOptionPane.ERROR_MESSAGE); // ok2go.setValue(false); ok = false; } else { // Let's go on xsn = (XmlSchemaNode) NodeFactory.findOrCreate(XmlSchemaNode.class, classURL); currentPrj.add(xsn, true); xsn.open(); // Now the Node is created, let's create its content TextBuffer tb = xsn.acquireTextBuffer(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); PrintWriter pw = new PrintWriter(baos); dtddoc.print(pw); String content = baos.toString(); tb.beginEdit(); tb.append(content.toCharArray()); tb.endEdit(); ok = true; } } catch (Exception e) { e.printStackTrace(); } } public boolean isOk() { return ok; } public XmlSchemaNode getXmlSchemaNode() { return xsn; } } SchemaGenerationRunnable schemaGeneration = new SchemaGenerationRunnable(); SchemaGenerationProgress generationProgress = new SchemaGenerationProgress(schemaGeneration); final String LABEL = "Converting..."; ProgressBar progress = new ProgressBar(Ide.getMainWindow(), LABEL, generationProgress, true); generationProgress.setProgressBar(progress); progress.start("Please wait", ""); // reset generationProgress = null; progress = null; if (schemaGeneration.isOk()) { // Open the created node EditorManager.getEditorManager() .openDefaultEditorInFrame(schemaGeneration.getXmlSchemaNode().getURL()); // Add the compilation date SimpleDateFormat sdf = new SimpleDateFormat("hh:mm:dd a"); // NOTRANS msg += ("Schema generation [" + sdf.format(new Date()) + "] " + " successful."); // Display message in log window. logMessage(msg); msg = ""; // reset } } ret = true; } catch (Exception ex) { logMessage("Error:" + ex.toString()); ex.printStackTrace(); } } else logMessage("element is null"); } if (msg != null && msg.trim().length() > 0) { logMessage(msg); // Ide.getStatusBar().setText(msg); ret = true; } return ret; }
public void changeMode(Mode mode) { if (mode == Mode.DIALOG) { boolean newMessages = false; for (int i = 0; i < dialogTabArrayList.size(); i++) { if (dialogTabArrayList.get(i).getNewMessageLabel().isVisible()) { newMessages = true; } } if (newMessages) { homeButton.setIcon(newDialogButIcon); } else { homeButton.setIcon(dialogButIcon); } final boolean finalNewMessages = newMessages; homeButton.addMouseListener( new MouseAdapter() { @Override public void mouseEntered(MouseEvent e) { if (finalNewMessages) { homeButton.setIcon(newDialogButIconEntered); } else { homeButton.setIcon(dialogButIconEntered); } } @Override public void mouseExited(MouseEvent e) { if (finalNewMessages) { homeButton.setIcon(newDialogButIcon); } else { homeButton.setIcon(dialogButIcon); } } }); if (!(currentDialogTab == null)) currentDialogPanel.setVisible(false); homePanel.setVisible(true); friendPanelButton.setVisible(false); dialogTabsPanel.setVisible(false); isFriendPanelOpened = false; noConversationsPanel.setVisible(false); friendPanelMode(); } else if (mode == Mode.HOME_PANEL) { homeButton.setIcon(homeButIcon); homeButton.addMouseListener( new MouseAdapter() { @Override public void mouseEntered(MouseEvent e) { homeButton.setIcon(homeButIconEntered); } @Override public void mouseExited(MouseEvent e) { homeButton.setIcon(homeButIcon); } }); friendPanelButton.setVisible(true); homePanel.setVisible(false); if (dialogTabArrayList.size() > 0) { dialogTabsPanel.setVisible(true); } else { noConversationsPanel.setVisible(true); } if (!(currentDialogPanel == null)) { currentDialogPanel.setVisible(true); } friendPanelButton.setVisible(true); repaint(); } }
public DialogPanel receiveIncomingMessage( Message message, BufferedImage myPhoto, BufferedImage friendPhoto, Mode mode) { if (mode == Mode.HOME_PANEL) { homeButton.setIcon(newDialogButIcon); PopUpMenu.displayMessage("You have new message from " + message.getNickname_From()); homeButton.addMouseListener( new MouseAdapter() { @Override public void mouseEntered(MouseEvent e) { homeButton.setIcon(newDialogButIconEntered); } @Override public void mouseExited(MouseEvent e) { homeButton.setIcon(newDialogButIcon); } }); } for (int i = 0; i < dialogTabArrayList.size(); i++) { if (message.getNickname_From().equals(dialogTabArrayList.get(i).getNickButton().getText())) { if (dialogTabArrayList.get(i).equals(currentDialogTab)) { dialogPanelArrayList.get(i).showIncomingMessage(message); } else { dialogPanelArrayList.get(i).showIncomingMessage(message); dialogTabArrayList.get(i).getNewMessageLabel().setVisible(true); } return null; } } final DialogTab dialogTab = new DialogTab(message.getNickname_From()); dialogTab.setBorder(new LineBorder(Color.WHITE)); dialogTabArrayList.add(dialogTab); dialogTab.getNewMessageLabel().setVisible(true); final DialogPanel dialogPanel = new DialogPanel(); try { dialogPanel.updateInfo(myPhoto, friendPhoto); } catch (IOException e) { e.printStackTrace(); } dialogPanelArrayList.add(dialogPanel); repaintDialogTabsPanel(); repaint(); revalidate(); dialogTab .getNickButton() .addActionListener( new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { for (int i = 0; i < dialogTabArrayList.size(); i++) { dialogTabArrayList.get(i).setBorder(new LineBorder(Color.WHITE)); } dialogTab.setBorder(new LineBorder(Color.RED)); dialogTab.getNewMessageLabel().setVisible(false); currentDialogTab = dialogTab; if (!(currentDialogPanel == null)) currentDialogPanel.setVisible(false); currentDialogPanel = dialogPanel; currentDialogPanel.setBounds(0, 84, 960, 1000); bigPanel.add(currentDialogPanel); currentDialogPanel.setVisible(true); repaintDialogTabsPanel(); repaint(); revalidate(); } }); dialogPanel.showIncomingMessage(message); noConversationsPanel.setVisible(false); return dialogPanel; }
public boolean startNewDialog( BufferedImage myPhoto, BufferedImage friendPhoto, String friendNick) { for (int i = 0; i < dialogTabArrayList.size(); i++) { if (dialogTabArrayList.get(i).getNickButton().getText().equals(friendNick)) { if (!(currentDialogPanel == null)) { currentDialogPanel.setVisible(false); currentDialogTab.setBorder(new LineBorder(Color.WHITE)); } currentDialogPanel = dialogPanelArrayList.get(i); currentDialogTab = dialogTabArrayList.get(i); currentDialogTab.setBorder(new LineBorder(Color.RED)); currentDialogTab.getNewMessageLabel().setVisible(false); currentDialogPanel.setBounds(0, 84, 960, 1000); bigPanel.add(currentDialogPanel); currentDialogPanel.setVisible(true); repaint(); revalidate(); return false; } } final DialogTab dialogTab = new DialogTab(friendNick); currentDialogTab = dialogTab; dialogTab.setBorder(new LineBorder(Color.RED)); dialogTabArrayList.add(dialogTab); final DialogPanel dialogPanel = new DialogPanel(); try { dialogPanel.updateInfo(myPhoto, friendPhoto); } catch (IOException e) { e.printStackTrace(); } dialogPanelArrayList.add(dialogPanel); for (int i = 0; i < dialogTabArrayList.size() - 1; i++) { dialogTabArrayList.get(i).setBorder(new LineBorder(Color.WHITE)); } if (!(currentDialogPanel == null)) currentDialogPanel.setVisible(false); currentDialogPanel = dialogPanel; currentDialogPanel.setBounds(0, 84, 960, 1000); bigPanel.add(currentDialogPanel); repaintDialogTabsPanel(); repaint(); revalidate(); dialogTab .getNickButton() .addActionListener( new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { for (int i = 0; i < dialogTabArrayList.size(); i++) { dialogTabArrayList.get(i).setBorder(new LineBorder(Color.WHITE)); } dialogTab.setBorder(new LineBorder(Color.RED)); dialogTab.getNewMessageLabel().setVisible(false); currentDialogTab = dialogTab; currentDialogPanel.setVisible(false); currentDialogPanel = dialogPanel; currentDialogPanel.setBounds(0, 84, 960, 1000); bigPanel.add(currentDialogPanel); currentDialogPanel.setVisible(true); repaintDialogTabsPanel(); repaint(); revalidate(); } }); noConversationsPanel.setVisible(false); return true; }