Java Code Examples for javax.swing.JInternalFrame

The following examples show how to use javax.swing.JInternalFrame. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
/**
 * {@inheritDoc}
 */
public boolean isInState(JComponent c) {
    Component parent = c;

    while (parent.getParent() != null) {

        if (parent instanceof JInternalFrame) {
            break;
        }

        parent = parent.getParent();
    }

    if (parent instanceof JInternalFrame) {
        return !(((JInternalFrame) parent).isSelected());
    }

    return false;
}
 
Example 2
Source Project: visualvm   Source File: WindowBuilders.java    License: GNU General Public License v2.0 6 votes vote down vote up
protected JInternalFrame createInstanceImpl() {
    JInternalFrame frame = new JInternalFrame(title, resizable, closable, maximizable, iconable) {
        protected JRootPane createRootPane() {
            return _rootPane == null ? null : _rootPane.createInstance();
        }
        public void addNotify() {
            try {
                // Doesn't seem to work correctly
                setClosed(_isClosed);
                setMaximum(_isMaximum);
                setIcon(_isIcon);
                setSelected(_isSelected);
            } catch (PropertyVetoException ex) {}
        }
    };
    return frame;
}
 
Example 3
Source Project: dragonwell8_jdk   Source File: Test6505027.java    License: GNU General Public License v2.0 6 votes vote down vote up
public Test6505027(JFrame main) {
    Container container = main;
    if (INTERNAL) {
        JInternalFrame frame = new JInternalFrame();
        frame.setBounds(OFFSET, OFFSET, WIDTH, HEIGHT);
        frame.setVisible(true);

        JDesktopPane desktop = new JDesktopPane();
        desktop.add(frame, new Integer(1));

        container.add(desktop);
        container = frame;
    }
    if (TERMINATE) {
        this.table.putClientProperty(KEY, Boolean.TRUE);
    }
    TableColumn column = this.table.getColumn(COLUMNS[1]);
    column.setCellEditor(new DefaultCellEditor(new JComboBox(ITEMS)));

    container.add(BorderLayout.NORTH, new JTextField());
    container.add(BorderLayout.CENTER, new JScrollPane(this.table));
}
 
Example 4
Source Project: mars-sim   Source File: MainDesktopPane.java    License: GNU General Public License v3.0 6 votes vote down vote up
@Override
	public void componentShown(ComponentEvent e) {
//		logger.config("componentShown()");
		SwingUtilities.invokeLater(() -> {
			JInternalFrame[] frames = (JInternalFrame[]) this.getAllFrames();
			for (JInternalFrame f : frames) {
				ToolWindow w = (ToolWindow) f;
				if (this.isVisible() || this.isShowing()) {
					w.update();
//					f.updateUI();
//					 SwingUtilities.updateComponentTreeUI(f);
//					f.validate();
//					f.repaint();
				}
				
				else if (!this.isShowing() && w.getToolName().equals(NavigatorWindow.NAME))
					closeToolWindow(NavigatorWindow.NAME);
			}
		});
	}
 
Example 5
Source Project: seaglass   Source File: SeaGlassDesktopIconUI.java    License: Apache License 2.0 6 votes vote down vote up
public void propertyChange(PropertyChangeEvent evt) {
    if (evt.getSource() instanceof JInternalFrame.JDesktopIcon) {
        if (SeaGlassLookAndFeel.shouldUpdateStyle(evt)) {
            updateStyle((JInternalFrame.JDesktopIcon) evt.getSource());
        }
    } else if (evt.getSource() instanceof JInternalFrame) {
        JInternalFrame frame = (JInternalFrame) evt.getSource();
        if (iconPane instanceof JToggleButton) {
            JToggleButton button = (JToggleButton) iconPane;
            String prop = evt.getPropertyName();
            if (prop == "title") {
                button.setText((String) evt.getNewValue());
            } else if (prop == "frameIcon") {
                button.setIcon((Icon) evt.getNewValue());
            } else if (prop == JInternalFrame.IS_ICON_PROPERTY || prop == JInternalFrame.IS_SELECTED_PROPERTY) {
                button.setSelected(!frame.isIcon() && frame.isSelected());
            }
        }
    }
}
 
Example 6
Source Project: JByteMod-Beta   Source File: InfoPanel.java    License: GNU General Public License v2.0 6 votes vote down vote up
@Override
public void setBoundsForFrame(JComponent f, int newX, int newY, int newWidth, int newHeight) {
  if (!(f instanceof JInternalFrame)) {
    return;
  }
  boolean didResize = (f.getWidth() != newWidth || f.getHeight() != newHeight);
  if (!inBounds((JInternalFrame) f, newX, newY, newWidth, newHeight)) {
    Container parent = f.getParent();
    Dimension parentSize = parent.getSize();
    int boundedX = (int) Math.min(Math.max(0, newX), parentSize.getWidth() - newWidth);
    int boundedY = (int) Math.min(Math.max(0, newY), parentSize.getHeight() - newHeight);
    f.setBounds(boundedX, boundedY, newWidth, newHeight);
  } else {
    f.setBounds(newX, newY, newWidth, newHeight);
  }
  if (didResize) {
    f.validate();
  }
}
 
Example 7
Source Project: snap-desktop   Source File: UIUtils.java    License: GNU General Public License v3.0 6 votes vote down vote up
public static String getUniqueFrameTitle(final JInternalFrame[] frames, final String titleBase) {
    if (frames.length == 0) {
        return titleBase;
    }
    String[] titles = new String[frames.length];
    for (int i = 0; i < frames.length; i++) {
        JInternalFrame frame = frames[i];
        titles[i] = frame.getTitle();
    }
    if (!ArrayUtils.isMemberOf(titleBase, titles)) {
        return titleBase;
    }
    for (int i = 0; i < frames.length; i++) {
        final String title = titleBase + " (" + (i + 2) + ")";
        if (!ArrayUtils.isMemberOf(title, titles)) {
            return title;
        }
    }
    return titleBase + " (" + (frames.length + 1) + ")";
}
 
Example 8
Source Project: visualvm   Source File: WindowBuilders.java    License: GNU General Public License v2.0 6 votes vote down vote up
static ComponentBuilder getBuilder(Instance instance, Heap heap) {
    if (DetailsUtils.isSubclassOf(instance, JRootPane.class.getName())) {
        return new JRootPaneBuilder(instance, heap);
    } else if (DetailsUtils.isSubclassOf(instance, JDesktopPane.class.getName())) {
        return new JDesktopPaneBuilder(instance, heap);
    } else if (DetailsUtils.isSubclassOf(instance, JLayeredPane.class.getName())) {
        return new JLayeredPaneBuilder(instance, heap);
    } else if (DetailsUtils.isSubclassOf(instance, Frame.class.getName())) {
        return new FrameBuilder(instance, heap);
    } else if (DetailsUtils.isSubclassOf(instance, Dialog.class.getName())) {
        return new DialogBuilder(instance, heap);
    } else if (DetailsUtils.isSubclassOf(instance, JInternalFrame.class.getName())) {
        return new JInternalFrameBuilder(instance, heap);
    }
    return null;
}
 
Example 9
Source Project: drmips   Source File: FrmSimulator.java    License: GNU General Public License v3.0 6 votes vote down vote up
/**
 * Restores the specified frame's bounds from the preferences.
 * @param prefPrefix The prefix of the preference.
 * @param frame The frame.
 */
private void restoreFrameBounds(String prefPrefix, JInternalFrame frame) {
	frame.setLocation(DrMIPS.prefs.getInt(prefPrefix + "_x", 0), DrMIPS.prefs.getInt(prefPrefix + "_y", 0));
	int w = DrMIPS.prefs.getInt(prefPrefix + "_w", -1);
	int h = DrMIPS.prefs.getInt(prefPrefix + "_h", -1);
	if(w > 0 && h > 0)
		frame.setSize(w, h);
	else
		frame.pack();
	try {
		if(DrMIPS.prefs.getBoolean(prefPrefix + "_max", false))
			frame.setMaximum(true);
		if(DrMIPS.prefs.getBoolean(prefPrefix + "_min", false))
			frame.setIcon(true);
	}
	catch(PropertyVetoException ex) {
		LOG.log(Level.WARNING, "failed to maximize/minimize an internal frame");
	}
}
 
Example 10
Source Project: seaglass   Source File: ToolBarWindowIsActiveState.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
public boolean isInState(JComponent c) {
    Component parent = c;

    while (parent.getParent() != null) {

        if (parent instanceof JInternalFrame || parent instanceof Window) {
            break;
        }

        parent = parent.getParent();
    }

    if (parent instanceof JInternalFrame) {
        return ((JInternalFrame) parent).isSelected();
    } else if (parent instanceof Window) {
        return ((Window) parent).isActive();
    }

    // Default to true.
    return true;
}
 
Example 11
/**
 * Searches JInternalframe in container.
 *
 * @param cont Container to search component in.
 * @param chooser a component chooser specifying searching criteria.
 * @param index Ordinal component index.
 * @return JInternalframe instance or null if component was not found.
 */
public static JInternalFrame findJInternalFrame(Container cont, ComponentChooser chooser, int index) {
    Component res = findComponent(cont, new JInternalFrameFinder(chooser), index);
    if (res instanceof JInternalFrame) {
        return (JInternalFrame) res;
    } else if (res instanceof JInternalFrame.JDesktopIcon) {
        return ((JInternalFrame.JDesktopIcon) res).getInternalFrame();
    } else {
        return null;
    }
}
 
Example 12
/**
 * Maps {@code JInternalFrame.getTitle()} through queue
 */
public String getTitle() {
    return (runMapping(new MapAction<String>("getTitle") {
        @Override
        public String map() {
            return ((JInternalFrame) getSource()).getTitle();
        }
    }));
}
 
Example 13
private static JInternalFrame create(int index) {
    String text = "test" + index; // NON-NLS: frame identification
    index = index * 3 + 1;

    JInternalFrame internal = new JInternalFrame(text, true, true, true, true);
    internal.getContentPane().add(new JTextArea(text));
    internal.setBounds(10 * index, 10 * index, WIDTH, HEIGHT);
    internal.setVisible(true);
    return internal;
}
 
Example 14
public void deiconifyFrame(JInternalFrame f) {
  JInternalFrame.JDesktopIcon desktopIcon = f.getDesktopIcon();
  Container c = desktopIcon.getParent();
  if (c != null) {
    f.setBounds(oldBounds.remove(f)); //XXX
    //c.add(f); //XXX

    // If the frame is to be restored to a maximized state make
    // sure it still fills the whole desktop.
    if (f.isMaximum()) {
      Rectangle desktopBounds = c.getBounds();
      if (f.getWidth() != desktopBounds.width || f.getHeight() != desktopBounds.height) {
        setBoundsForFrame(f, 0, 0, desktopBounds.width, desktopBounds.height);
      }
    }
    removeIconFor(f);
    if (f.isSelected()) {
      f.moveToFront();
    }
    else {
      try {
        f.setSelected(true);
      }
      catch (PropertyVetoException e2) {
      }
    }
  }
}
 
Example 15
/**
 * Maps {@code JInternalFrame.setFrameIcon(Icon)} through queue
 */
public void setFrameIcon(final Icon icon) {
    runMapping(new MapVoidAction("setFrameIcon") {
        @Override
        public void map() {
            ((JInternalFrame) getSource()).setFrameIcon(icon);
        }
    });
}
 
Example 16
/**
 * Maps {@code JInternalFrame.setClosable(boolean)} through queue
 */
public void setClosable(final boolean b) {
    runMapping(new MapVoidAction("setClosable") {
        @Override
        public void map() {
            ((JInternalFrame) getSource()).setClosable(b);
        }
    });
}
 
Example 17
Source Project: jdk8u_jdk   Source File: MetalworksFrame.java    License: GNU General Public License v2.0 5 votes vote down vote up
public void openInBox() {
    JInternalFrame doc = new MetalworksInBox();
    desktop.add(doc, DOCLAYER);
    try {
        doc.setVisible(true);
        doc.setSelected(true);
    } catch (java.beans.PropertyVetoException e2) {
    }
}
 
Example 18
Source Project: drmips   Source File: FrmSimulator.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * Saves the specified frame's bounds to the preferences.
 * @param prefPrefix The prefix of the preference.
 * @param frame The frame.
 */
private void saveFrameBounds(String prefPrefix, JInternalFrame frame) {
	DrMIPS.prefs.putInt(prefPrefix + "_x", frame.getNormalBounds().x);
	DrMIPS.prefs.putInt(prefPrefix + "_y", frame.getNormalBounds().y);
	DrMIPS.prefs.putInt(prefPrefix + "_w", frame.getNormalBounds().width);
	DrMIPS.prefs.putInt(prefPrefix + "_h", frame.getNormalBounds().height);
	DrMIPS.prefs.putBoolean(prefPrefix + "_max", frame.isMaximum());
	DrMIPS.prefs.putBoolean(prefPrefix + "_min", frame.isIcon());
}
 
Example 19
Source Project: littleluck   Source File: InternalFrameDemo.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * InternalFrameDemo Constructor
 */
public InternalFrameDemo() {
    setLayout(new BorderLayout());

    // preload all the icons we need for this demo
    icon1 = resourceManager.createImageIcon("bananas.png",
            resourceManager.getString("InternalFrameDemo.bananas"));
    icon2 = resourceManager.createImageIcon("globe.png",
            resourceManager.getString("InternalFrameDemo.globe"));
    icon3 = resourceManager.createImageIcon("package.png",
            resourceManager.getString("InternalFrameDemo.package"));
    icon4 = resourceManager.createImageIcon("soccer_ball.png",
            resourceManager.getString("InternalFrameDemo.soccerball"));

    smIcon1 = resourceManager.createImageIcon("bananas_small.png",
            resourceManager.getString("InternalFrameDemo.bananas"));
    smIcon2 = resourceManager.createImageIcon("globe_small.png",
            resourceManager.getString("InternalFrameDemo.globe"));
    smIcon3 = resourceManager.createImageIcon("package_small.png",
            resourceManager.getString("InternalFrameDemo.package"));
    smIcon4 = resourceManager.createImageIcon("soccer_ball_small.png",
            resourceManager.getString("InternalFrameDemo.soccerball"));

    //<snip>Create desktop pane
    // The desktop pane will contain all the internal frames
    desktop = new JDesktopPane();
    add(desktop, BorderLayout.CENTER);
    //</snip>

    // Create the "frame maker" palette
    createInternalFramePalette();

    // Create an initial internal frame to show
    JInternalFrame frame1 = createInternalFrame(icon2, DEMO_FRAME_LAYER, 1, 1);
    frame1.setBounds(FRAME0_X, FRAME0_Y, FRAME0_WIDTH, FRAME0_HEIGHT);

}
 
Example 20
Source Project: dragonwell8_jdk   Source File: Test6802868.java    License: GNU General Public License v2.0 5 votes vote down vote up
public Test6802868(JFrame frame) {
    JDesktopPane desktop = new JDesktopPane();

    this.frame = frame;
    this.frame.add(desktop);

    this.internal = new JInternalFrame(getClass().getName(), true, true, true, true);
    this.internal.setVisible(true);

    desktop.add(this.internal);
}
 
Example 21
public void activateFrame(JInternalFrame f) {
    JInternalFrame currentFrame = currentFrameRef != null ?
        currentFrameRef.get() : null;
    try {
        super.activateFrame(f);
        if (currentFrame != null && f != currentFrame) {
            // If the current frame is maximized, transfer that
            // attribute to the frame being activated.
            if (currentFrame.isMaximum() &&
                (f.getClientProperty("JInternalFrame.frameType") !=
                "optionDialog") ) {
                //Special case.  If key binding was used to select next
                //frame instead of minimizing the icon via the minimize
                //icon.
                if (!currentFrame.isIcon()) {
                    currentFrame.setMaximum(false);
                    if (f.isMaximizable()) {
                        if (!f.isMaximum()) {
                            f.setMaximum(true);
                        } else if (f.isMaximum() && f.isIcon()) {
                            f.setIcon(false);
                        } else {
                            f.setMaximum(false);
                        }
                    }
                }
            }
            if (currentFrame.isSelected()) {
                currentFrame.setSelected(false);
            }
        }

        if (!f.isSelected()) {
            f.setSelected(true);
        }
    } catch (PropertyVetoException e) {}
    if (f != currentFrame) {
        currentFrameRef = new WeakReference<JInternalFrame>(f);
    }
}
 
Example 22
Source Project: dragonwell8_jdk   Source File: Test6657026.java    License: GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    UIManager.setLookAndFeel(new MetalLookAndFeel());

    ThreadGroup group = new ThreadGroup("$$$");
    Thread thread = new Thread(group, new Test6657026());
    thread.start();
    thread.join();

    new JInternalFrame().setContentPane(new JPanel());
}
 
Example 23
/**
 * Maps {@code JInternalFrame.getLayer()} through queue
 */
public int getLayer() {
    return (runMapping(new MapIntegerAction("getLayer") {
        @Override
        public int map() {
            return ((JInternalFrame) getSource()).getLayer();
        }
    }));
}
 
Example 24
/**
 * Maps {@code JInternalFrame.setContentPane(Container)} through queue
 */
public void setContentPane(final Container container) {
    runMapping(new MapVoidAction("setContentPane") {
        @Override
        public void map() {
            ((JInternalFrame) getSource()).setContentPane(container);
        }
    });
}
 
Example 25
/**
 * Maps {@code JInternalFrame.isClosed()} through queue
 */
public boolean isClosed() {
    return (runMapping(new MapBooleanAction("isClosed") {
        @Override
        public boolean map() {
            return ((JInternalFrame) getSource()).isClosed();
        }
    }));
}
 
Example 26
/**
 * Maps {@code JInternalFrame.moveToBack()} through queue
 */
public void moveToBack() {
    runMapping(new MapVoidAction("moveToBack") {
        @Override
        public void map() {
            ((JInternalFrame) getSource()).moveToBack();
        }
    });
}
 
Example 27
/**
 * Maps {@code JInternalFrame.getUI()} through queue
 */
public InternalFrameUI getUI() {
    return (runMapping(new MapAction<InternalFrameUI>("getUI") {
        @Override
        public InternalFrameUI map() {
            return ((JInternalFrame) getSource()).getUI();
        }
    }));
}
 
Example 28
/**
 * Looks for a first window-like container.
 *
 * @return either WindowOperator of JInternalFrameOperator
 */
public ContainerOperator<?> getWindowContainerOperator() {
    Component resultComp;
    if (getSource() instanceof Window) {
        resultComp = getSource();
    } else {
        resultComp = getContainer(new ComponentChooser() {
            @Override
            public boolean checkComponent(Component comp) {
                return (comp instanceof Window
                        || comp instanceof JInternalFrame);
            }

            @Override
            public String getDescription() {
                return "";
            }
        });
    }
    ContainerOperator<?> result;
    if (resultComp instanceof Window) {
        result = new WindowOperator((Window) resultComp);
    } else {
        result = new ContainerOperator<>((Container) resultComp);
    }
    result.copyEnvironment(this);
    return result;
}
 
Example 29
Source Project: littleluck   Source File: LuckInternalFrameUI.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected JComponent createNorthPane(JInternalFrame w)
{
    titlePane = new LuckInternalFrameTitlePane(w);

    return titlePane;
}
 
Example 30
private void initActions() {
	mntmSaveDisplay.addActionListener(ae -> {
		int i = 0;

		try {
			FileUtils.cleanDirectory(AbstractJDashlet.confdir);
		} catch (IOException e1) {
			logger.error(e1);
		}

		
		for (JInternalFrame jif : desktop.getAllFrames()) {
			i++;
			AbstractJDashlet dash = (AbstractJDashlet) jif;
			dash.setProperty("x", String.valueOf(dash.getBounds().getX()));
			dash.setProperty("y", String.valueOf(dash.getBounds().getY()));
			dash.setProperty("w", String.valueOf(dash.getBounds().getWidth()));
			dash.setProperty("h", String.valueOf(dash.getBounds().getHeight()));
			dash.setProperty("class", dash.getClass().getName());
			dash.setProperty("id", String.valueOf(i));
			File f = new File(AbstractJDashlet.confdir, i + ".conf");

			try (FileOutputStream fos = new FileOutputStream(f)) {
				dash.getProperties().store(fos, "");
				logger.trace("saving " + f + " :" + dash.getProperties());
				
			} catch (IOException e) {
				logger.error(e);
			}
		}	
		
	
		
	});
	
}