public Object showWindow(final MkWindow macWindow, String title, boolean isModal) { listMkWindow.add(macWindow); if (isModal) { JDialog modalFrame = new JDialog(this, title, true); // macWindow.setJanela(modalFrame); final MkRun onCloseWindow = macWindow.onCloseWindow; modalFrame.setDefaultCloseOperation(JInternalFrame.DO_NOTHING_ON_CLOSE); modalFrame.addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent e) { if (onCloseWindow != null) { onCloseWindow.execute(); } disposeWindow(macWindow); } }); modalFrame.setLayout(new BorderLayout()); modalFrame.add(macWindow, BorderLayout.CENTER); modalFrame.pack(); Dimension desktopSize = desktopPane.getSize(); int x = (desktopSize.width - modalFrame.getWidth()) / 2; int y = (desktopSize.height - modalFrame.getHeight()) / 2; modalFrame.setLocation((x < 0 ? 0 : x), (y < 0 ? 0 : y)); if (macWindow.panelButton != null) { modalFrame.getRootPane().setDefaultButton((JButton) macWindow.panelButton.getComponent(0)); } modalFrame.setVisible(true); return modalFrame; } else { JInternalFrame internalFrame = new JInternalFrame(title, true, true, true, true); internalFrame.setContentPane(macWindow); internalFrame.pack(); // internalFrame.setBounds(internalFrame.getBounds()); //pq? desktopPane.add(internalFrame); internalFrame.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); final MkRun onCloseWindow = macWindow.onCloseWindow; if (onCloseWindow != null) { internalFrame.setDefaultCloseOperation(JInternalFrame.DO_NOTHING_ON_CLOSE); internalFrame.addInternalFrameListener( new InternalFrameAdapter() { public void internalFrameClosing(InternalFrameEvent e) { onCloseWindow.execute(); } }); } Dimension desktopSize = desktopPane.getSize(); int x = (desktopSize.width - internalFrame.getWidth()) / 2; int y = (desktopSize.height - internalFrame.getHeight()) / 2; internalFrame.setLocation((x < 0 ? 0 : x), (y < 0 ? 0 : y)); internalFrame.setVisible(true); return internalFrame; } }
private synchronized void display(ExtSed sed) { manageAssociatedManagerWindows(sed); try { SpectrumContainer container = (SpectrumContainer) sed.getAttachment(IrisDisplayManager.FIT_MODEL); // There is no Sed attachment, so build a model manager and attach it. if (container == null) { if (buildAttachment(sed)) { return; } } // VAOPD-879: spectrum name must be identical with Sed name. if (container != null) { container.getSpectrum().setName(sed.getId()); } // Now display the Sed. idm.display(sed, sed.getId()); // and add its frame to the workspace. JInternalFrame frame = idm.getInternalFrame(); // VAOPD-863 frame.setTitle(sed.getId()); if (container != null) { JFrame modelManagerFrame = container.getModelManager().getFrame(); if (modelManagerFrame != null) { modelManagerFrame.setTitle(sed.getId()); } } if (frame != currentFrame) { lastLocation = null; disposeCurrentFrame(); currentFrame = frame; currentFrame.setDefaultCloseOperation(JInternalFrame.HIDE_ON_CLOSE); if (lastLocation != null) { currentFrame.setLocation(lastLocation); } frame.setTitle("Iris Visualizer"); ws.addFrame(frame); } } catch (Exception ex) { LogEvent.getInstance().fire(this, new LogEntry("Error: " + ex.getMessage(), sed)); Logger.getLogger("IrisVisualizer").log(Level.SEVERE, null, ex); } }
private void initAboutFrames() { System.out.println("Initializing the about frames..."); authorFrame = new JInternalFrame("Authors", true, true, true, true); problemFrame = new JInternalFrame("Problem Description", true, true, true, true); final String AUTHOR_TEXT = "Authors:\n Ethan Wells and San Yeung\n"; JTextArea authorFrameTextArea = new JTextArea(AUTHOR_TEXT); authorFrameTextArea.setEditable(false); authorFrameTextArea.setLineWrap(true); authorFrameTextArea.setColumns(60); authorFrame.add(authorFrameTextArea); authorFrame.pack(); final String PROBLEM_TEXT = "Two towns A and B are connected with a bridge. Suppose there are four\n" + "people and their moving directions are indicated by the arrows. The bridge is narrow, and at any\n" + "time, multiple people cannot pass in the opposite directions.\n" + "1. Based on the Ricart & Agrawalas mutual exclusion algorithm, design a decentralized protocol\n" + "so that at most one person can be on the bridge at any given time, and no person is indefinitely\n" + "prevented from crossing the bridge. Treat each person to be a process, and assume that their\n" + "clocks are synchronized.\n" + "2. Design another protocol so that multiple people can be on the bridge as long as they are\n" + "moving in the same direction, but no person is indefinitely prevented from crossing the bridge.\n" + "Design a graphical user interface to display the movement of the people, so that the instructor can\n" + "control the walking speed of the people and verify the protocol. Note that to receive full credits,\n" + "you should provide instructions on how to compile and run your program, and your program should\n" + "be well-documented."; JTextArea problemFrameTextArea = new JTextArea(PROBLEM_TEXT); problemFrameTextArea.setEditable(false); problemFrameTextArea.setLineWrap(true); problemFrameTextArea.setColumns(70); problemFrame.add(problemFrameTextArea); problemFrame.pack(); authorFrame.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE); problemFrame.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE); virtualDesktop.add(authorFrame); virtualDesktop.add(problemFrame); }
public void setDefaultCloseOperation(int mode) { if (ggTitle != null) { ggTitle.setDefaultCloseOperation(mode); } else if (jf != null) { jf.setDefaultCloseOperation(mode); } else if (jd != null) { jd.setDefaultCloseOperation(mode); } else if (jif != null) { jif.setDefaultCloseOperation(mode); } else { throw new IllegalStateException("setDefaultCloseOperation wrapper not yet implemented"); } }
private void setClosingBehaviour(final LayerManagerProxy internalFrame) { final JInternalFrame i = (JInternalFrame) internalFrame; i.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); i.addInternalFrameListener( new InternalFrameAdapter() { public void internalFrameClosing(InternalFrameEvent e) { if (1 == getInternalFramesAssociatedWith((LayerManager) internalFrame.getLayerManager()) .size()) { if (confirmClose( "Close Task", internalFrame.getLayerManager().getLayersWithModifiedFeatureCollections())) { GUIUtil.dispose(i, desktopPane); internalFrame.getLayerManager().dispose(); } } else { GUIUtil.dispose(i, desktopPane); } } }); }
private void initializeContainer(Container c) { System.out.println("Initializing the Container..."); c.setPreferredSize(MASTER_WINDOW_SIZE); virtualDesktop = new JDesktopPane(); virtualDesktop.setPreferredSize(MASTER_WINDOW_SIZE); algorithmFrame = new JInternalFrame("Algorithm Visualization", true, true, true, true); algorithmFrame.setResizable(false); algorithmFrame.setDefaultCloseOperation(JInternalFrame.DO_NOTHING_ON_CLOSE); vizPanel = new VisualizationPanel(); algorithmFrame.setContentPane(vizPanel); vizPanel.setDisplayedThreads(); algorithmFrame.pack(); virtualDesktop.add(algorithmFrame); initAboutFrames(); c.add(virtualDesktop); algorithmFrame.setVisible(true); }
public JInternalFrame employeeFrame() { JInternalFrame f = new JInternalFrame(); f = new JInternalFrame( "Employee Database", false, // Resizable true, // Closable true, // Maximizable true); // Iconifiable f.setLayout(new BorderLayout()); JScrollPane sp = new JScrollPane(employeeTable()); sp.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED); sp.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); sp.setBorder(BorderFactory.createTitledBorder("Employees")); f.add(buttonPanel(false), BorderLayout.NORTH); f.add(sp); // f.setLocation(loc); f.setDefaultCloseOperation(JInternalFrame.DISPOSE_ON_CLOSE); f.setFrameIcon(images.loadImage("Images/menubar/database_icon.png")); f.addInternalFrameListener(this); if (osp.isLowResolution()) f.setSize(550, 282); else if (osp.isMidResolution()) f.setSize(550, 282); else f.setSize(850, 500); // Width, Height f.setVisible(true); try { f.setSelected(true); } catch (PropertyVetoException e1) { e1.printStackTrace(); } return f; }
public static void init( JInternalFrame comp, Thing thing, Container parent, ActionContext actionContext) { JComponentCreator.init(comp, thing, parent, actionContext); String title = JavaCreator.createText(thing, "title", actionContext); if (title != null) { comp.setTitle(title); } Boolean closable = JavaCreator.createBoolean(thing, "closable"); if (closable != null) { comp.setClosable(closable); } Boolean closed = JavaCreator.createBoolean(thing, "closed"); if (closed != null) { try { comp.setClosed(closed); } catch (PropertyVetoException e) { e.printStackTrace(); } } Cursor cursor = AwtCreator.createCursor(thing, "cursor", actionContext); if (cursor != null) { comp.setCursor(cursor); } Integer defaultCloseOperation = null; String d = thing.getString("defaultCloseOperation"); if ("DO_NOTHING_ON_CLOSE".equals(d)) { defaultCloseOperation = JInternalFrame.DO_NOTHING_ON_CLOSE; } else if ("HIDE_ON_CLOSE".equals(d)) { defaultCloseOperation = JInternalFrame.HIDE_ON_CLOSE; } else if ("DISPOSE_ON_CLOSE".equals(d)) { defaultCloseOperation = JInternalFrame.DISPOSE_ON_CLOSE; } if (defaultCloseOperation != null) { comp.setDefaultCloseOperation(defaultCloseOperation); } Boolean focusCycleRoot = JavaCreator.createBoolean(thing, "focusCycleRoot"); if (focusCycleRoot != null) { comp.setFocusCycleRoot(focusCycleRoot); } Icon frameIcon = SwingCreator.createIcon(thing, "frameIcon", actionContext); if (frameIcon != null) { comp.setFrameIcon(frameIcon); } Boolean setIcon = JavaCreator.createBoolean(thing, "setIcon"); if (setIcon != null) { try { comp.setIcon(setIcon); } catch (PropertyVetoException e) { e.printStackTrace(); } } Boolean iconifiable = JavaCreator.createBoolean(thing, "iconifiable"); if (iconifiable != null) { comp.setIconifiable(iconifiable); } Integer layer = JavaCreator.createInteger(thing, "layer"); if (layer != null) { comp.setLayer(layer); } Boolean maximizable = JavaCreator.createBoolean(thing, "maximizable"); if (maximizable != null) { comp.setMaximizable(maximizable); } Boolean maximum = JavaCreator.createBoolean(thing, "maximum"); if (maximum != null) { try { comp.setMaximum(maximum); } catch (PropertyVetoException e) { e.printStackTrace(); } } Boolean resizable = JavaCreator.createBoolean(thing, "resizable"); if (resizable != null) { comp.setResizable(resizable); } Boolean selected = JavaCreator.createBoolean(thing, "selected"); if (selected != null) { try { comp.setSelected(selected); } catch (PropertyVetoException e) { e.printStackTrace(); } } }
/** * Constructor: The one we're working on right now. * * @param id * @param label * @param desktop */ public kCodeWindow(String id, String label, JDesktopPane desktop) { this.id = id; this.desktop = desktop; // make the editor portions TextAreaDefaults editareaSettings = new PdeTextAreaDefaults(); editareaSettings.rows = TEXTAREA_DEFAULT_ROWS; editareaSettings.cols = TEXTAREA_DEFAULT_COLS; textarea = new JEditTextArea(editareaSettings); textarea.getDocument().setTokenMarker(Editor.pdeTokenMarker); textarea.setEventsEnabled( false); // suppress JEditTextArea events (not that anyone is listening to it) textarea.setEditable(true); textarea.setHorizontalOffset(TEXTAREA_HORIZ_OFFSET); textarea.getPainter().setLineHighlightEnabled(false); // else looks funny textarea.getPainter().setBackground(kConstants.CODE_WINDOW_COLOR); setShortcutKeystrokes(); JScrollPane scrollPane = new JScrollPane(textarea); scrollPane.setBorder(null); // scrollPane.setOpaque(true); editFrame = new JInternalFrame(label, true, false, false, false); editFrame.setContentPane(textarea); editFrame.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE); editFrame.setSize(editFrame_DEFAULT_WIDTH, editFrame_DEFAULT_HEIGHT); editFrame.setBorder(null); editFrame.setOpaque(true); // make the triangle triangleFrame = new JInternalFrame("", false, false, false, false); triangleFrame.setOpaque(false); triangleFrame .getRootPane() .setBackground(new Color(0, 0, 0, 0)); // needs this to actually do the trick triangleFrame.setContentPane( new Triangle("SE", 0, TRIANGLE_BASE, TRIANGLE_DEFAULT_HEIGHT, TRIANGLE_BASE)); triangleFrame.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE); triangleFrame.setSize(TRIANGLE_BASE, TRIANGLE_DEFAULT_HEIGHT); triangleFrame.setBorder(null); // remove the ability to move the triangle iframe MouseMotionListener[] actions = (MouseMotionListener[]) triangleFrame.getListeners(MouseMotionListener.class); for (int i = 0; i < actions.length; i++) triangleFrame.removeMouseMotionListener(actions[i]); // make the buttons moveButton = new JButton(Base.getImageIcon("codewindow-activ-move.gif", desktop)); moveButton.setDisabledIcon(Base.getImageIcon("codewindow-inact-move.gif", desktop)); moveButton.setVisible(true); moveButton.setBorder(null); moveButton.setOpaque(false); moveButton.setCursor(new Cursor(Cursor.HAND_CURSOR)); closeButton = new JButton(Base.getImageIcon("codewindow-activ-close.gif", desktop)); closeButton.setDisabledIcon(Base.getImageIcon("codewindow-inact-close.gif", desktop)); closeButton.setVisible(true); closeButton.setBorder(null); closeButton.setOpaque(false); closeButton.setCursor(new Cursor(Cursor.HAND_CURSOR)); JPanel buttonPanel = new JPanel(); buttonPanel.setLayout(new FlowLayout(FlowLayout.LEFT, 1, 0)); buttonPanel.setBorder(null); buttonPanel.setOpaque(false); buttonPanel.add(moveButton); buttonPanel.add(closeButton); buttonFrame = new JInternalFrame("", false, false, false, false); buttonFrame.setContentPane(buttonPanel); buttonFrame.setOpaque(false); buttonFrame.getRootPane().setBackground(new Color(0, 0, 0, 0)); buttonFrame.setSize(BUTTON_ICON_WIDTH * 2 + BUTTON_GAP, BUTTON_ICON_HEIGHT); buttonFrame.setBorder(null); // myriad event handling installFocusHandlers(buttonPanel); // hide code window when escape key is hit textarea.addKeyListener( new KeyAdapter() { public void keyPressed(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_ESCAPE) setVisible(false); } }); // add dragging function of the move button, // reset the triangle after mouse release, and shift the editFrame // along with the mouse when the user is moving the window mxMouseControl moveListener = createMoveListener(); moveButton.addMouseListener(moveListener); moveButton.addMouseMotionListener(moveListener); closeButton.addMouseListener(createCloseListener()); // listens to resizing of editFrame and adjusts the position of the // buttons and the shape of the triangle accordingly editFrame.addComponentListener(createResizeListener()); // when code windows are on top of each other, layers them correctly // such that when the user clicks on any part of a code window // all three component internal frames are brought to the top // so they appear "focused" also InternalFrameListener iframeListener = new InternalFrameAdapter() { public void internalFrameActivated(InternalFrameEvent e) { moveToFrontLayer(); } public void internalFrameDeactivated(InternalFrameEvent e) { moveToBackLayer(); } }; editFrame.addInternalFrameListener(iframeListener); buttonFrame.addInternalFrameListener(iframeListener); triangleFrame.addInternalFrameListener(iframeListener); // add everything to desktop desktop.add(editFrame); desktop.add(buttonFrame); desktop.add(triangleFrame); moveToBackLayer(); }
/** Run the task. */ public void run() { final BoundedRangeModel model = progressBar.getModel(); switch (task) { case -LABEL: { value = description.getText(); return; } case +LABEL: { description.setText((String) value); return; } case PROGRESS: { model.setValue(((Integer) value).intValue()); progressBar.setIndeterminate(false); return; } case STARTED: { model.setRangeProperties(0, 1, 0, 100, false); window.setVisible(true); break; // Need further action below. } case COMPLETE: { model.setRangeProperties(100, 1, 0, 100, false); window.setVisible(warningArea != null); cancel.setEnabled(false); break; // Need further action below. } } /* * Some of the tasks above requires an action on the window, which may be a JDialog or * a JInternalFrame. We need to determine the window type before to apply the action. */ synchronized (ProgressWindow.this) { if (window instanceof JDialog) { final JDialog window = (JDialog) ProgressWindow.this.window; switch (task) { case -TITLE: { value = window.getTitle(); return; } case +TITLE: { window.setTitle((String) value); return; } case STARTED: { window.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE); return; } case COMPLETE: { window.setDefaultCloseOperation(JDialog.HIDE_ON_CLOSE); return; } case DISPOSE: { window.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); if (warningArea == null || !window.isVisible()) { window.dispose(); } return; } } } else { final JInternalFrame window = (JInternalFrame) ProgressWindow.this.window; switch (task) { case -TITLE: { value = window.getTitle(); return; } case +TITLE: { window.setTitle((String) value); return; } case STARTED: { window.setClosable(false); return; } case COMPLETE: { window.setClosable(true); return; } case DISPOSE: { window.setDefaultCloseOperation(JInternalFrame.DISPOSE_ON_CLOSE); if (warningArea == null || !window.isVisible()) { window.dispose(); } return; } } } /* * Si la tâche spécifiée n'est aucune des tâches énumérées ci-haut, * on supposera que l'on voulait afficher un message d'avertissement. */ if (warningArea == null) { final JTextArea warningArea = new JTextArea(); final JScrollPane scroll = new JScrollPane(warningArea); final JPanel namedArea = new JPanel(new BorderLayout()); ProgressWindow.this.warningArea = warningArea; warningArea.setFont(Font.getFont("Monospaced")); warningArea.setEditable(false); namedArea.setBorder(BorderFactory.createEmptyBorder(0, HMARGIN, VMARGIN, HMARGIN)); namedArea.add(new JLabel(getString(VocabularyKeys.WARNING)), BorderLayout.NORTH); namedArea.add(scroll, BorderLayout.CENTER); content.add(namedArea, BorderLayout.CENTER); if (window instanceof JDialog) { final JDialog window = (JDialog) ProgressWindow.this.window; window.setResizable(true); } else { final JInternalFrame window = (JInternalFrame) ProgressWindow.this.window; window.setResizable(true); } window.setSize(WIDTH, HEIGHT + WARNING_HEIGHT); window.setVisible(true); // Seems required in order to force relayout. } final JTextArea warningArea = (JTextArea) ProgressWindow.this.warningArea; warningArea.append((String) value); } }
/** * Creates a window for reporting progress. The window will not appears immediately. It will * appears only when the {@link #started} method will be invoked. * * @param parent The parent component, or {@code null} if none. */ public ProgressWindow(final Component parent) { /* * Creates the window containing the components. */ Dimension parentSize; final Vocabulary resources = Vocabulary.getResources(parent != null ? parent.getLocale() : null); final String title = resources.getString(VocabularyKeys.PROGRESSION); final JDesktopPane desktop = JOptionPane.getDesktopPaneForComponent(parent); if (desktop != null) { final JInternalFrame frame; frame = new JInternalFrame(title); window = frame; content = new JPanel(); // Pour avoir un fond opaque parentSize = desktop.getSize(); frame.setContentPane(content); frame.setDefaultCloseOperation(JInternalFrame.HIDE_ON_CLOSE); desktop.add(frame, JLayeredPane.PALETTE_LAYER); } else { final JDialog dialog; dialog = new JDialog((Frame) null, title); window = dialog; content = (JComponent) dialog.getContentPane(); parentSize = Toolkit.getDefaultToolkit().getScreenSize(); dialog.setDefaultCloseOperation(JDialog.HIDE_ON_CLOSE); dialog.setResizable(false); } window.setBounds( (parentSize.width - WIDTH) / 2, (parentSize.height - HEIGHT) / 2, WIDTH, HEIGHT); /* * Creates the label that is going to display the undergoing operation. * This label is initially empty. */ description = new JLabel(); description.setHorizontalAlignment(JLabel.CENTER); /* * Creates the progress bar. */ progressBar = new JProgressBar(); progressBar.setIndeterminate(true); progressBar.setBorder( BorderFactory.createCompoundBorder( BorderFactory.createEmptyBorder(6, 9, 6, 9), progressBar.getBorder())); /* * Creates the cancel button. */ cancel = new JButton(resources.getString(VocabularyKeys.CANCEL)); cancel.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { setCanceled(true); } }); final Box cancelBox = Box.createHorizontalBox(); cancelBox.add(Box.createGlue()); cancelBox.add(cancel); cancelBox.add(Box.createGlue()); cancelBox.setBorder(BorderFactory.createEmptyBorder(0, 0, 6, 0)); /* * Layout the elements inside the window. An empty border is created in * order to put some space between the window content and the window border. */ final JPanel panel = new JPanel(new GridLayout(2, 1)); panel.setBorder( BorderFactory.createCompoundBorder( BorderFactory.createEmptyBorder(VMARGIN, HMARGIN, VMARGIN, HMARGIN), BorderFactory.createEtchedBorder())); panel.add(description); panel.add(progressBar); content.setLayout(new BorderLayout()); content.add(panel, BorderLayout.NORTH); content.add(cancelBox, BorderLayout.SOUTH); }