public HeaderPanel(String heading) { super(); this.setLayout(new BoxLayout(this, BoxLayout.X_AXIS)); this.setBackground(background); JLabel panelLabel = new JLabel(" " + heading, SwingConstants.LEFT); Font labelFont = new Font("Dialog", Font.BOLD, 18); panelLabel.setFont(labelFont); this.add(panelLabel); this.add(Box.createHorizontalGlue()); refresh = new JButton("Refresh"); refresh.addActionListener(this); this.add(refresh); this.add(Box.createHorizontalStrut(5)); root = new JComboBox(); Dimension d = root.getPreferredSize(); d.width = 90; root.setPreferredSize(d); root.setMaximumSize(d); File[] roots = directoryPane.getRoots(); for (int i = 0; i < roots.length; i++) root.addItem(roots[i].getAbsolutePath()); this.add(root); root.setSelectedIndex(directoryPane.getCurrentRootIndex()); root.addActionListener(this); this.add(Box.createHorizontalStrut(17)); }
private void createComponents(JPanel p) { String tt = "Any of these: 45.5 -120.2 or 45 30 0 n 120 12 0 w or Seattle"; JComboBox field = new JComboBox(); field.setOpaque(false); field.setEditable(true); field.setLightWeightPopupEnabled(false); field.setPreferredSize(new Dimension(200, field.getPreferredSize().height)); field.setToolTipText(tt); JLabel label = new JLabel(ImageLibrary.getIcon("gov/nasa/worldwindow/images/safari-24x24.png")); // new // ImageIcon(getClass().getResource("gov/nasa/worldwindow/images/safari-24x24.png"))); label.setOpaque(false); label.setToolTipText(tt); p.add(label, BorderLayout.WEST); p.add(field, BorderLayout.CENTER); field.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { performGazeteerAction(actionEvent); } }); }
@Override public int getBaseline() { FontMetrics fm = b.getFontMetrics(b.getFont()); int border = (b.getPreferredSize().height - fm.getHeight()) / 2; int bestGuess = border + fm.getAscent(); if (PlatformUtils.isMac()) bestGuess -= 1; return bestGuess; }
private void relayout() { int preferredHeight = b.getPreferredSize().height; b.setBounds(0, topOffset, getWidth(), preferredHeight); }
/** * Make the UI for this widget. * * @param floatToolBar true if the toolbar should be floatable * @return UI as a Component */ private JComponent doMakeContents(boolean floatToolBar) { String imgp = "/auxdata/ui/icons/"; KeyListener listener = new KeyAdapter() { public void keyPressed(KeyEvent e) { if ((e.getSource() instanceof JComboBox)) { return; } int code = e.getKeyCode(); char c = e.getKeyChar(); if ((code == KeyEvent.VK_RIGHT) || (code == KeyEvent.VK_KP_RIGHT)) { if (e.isShiftDown()) { gotoIndex(anime.getNumSteps() - 1); } else { actionPerformed(CMD_FORWARD); } } else if ((code == KeyEvent.VK_LEFT) || (code == KeyEvent.VK_KP_LEFT)) { if (e.isShiftDown()) { gotoIndex(0); } else { actionPerformed(CMD_BACKWARD); } } else if (code == KeyEvent.VK_ENTER) { actionPerformed(CMD_STARTSTOP); } else if ((code == KeyEvent.VK_P) && e.isControlDown()) { actionPerformed(CMD_PROPS); } else if (Character.isDigit(c)) { int step = new Integer("" + c).intValue() - 1; if (step < 0) { step = 0; } if (step >= anime.getNumSteps()) { step = anime.getNumSteps() - 1; } gotoIndex(step); } } }; List buttonList = new ArrayList(); buttonList.add(timesCbx); // Update the list of times setTimesInTimesBox(); Dimension preferredSize = timesCbx.getPreferredSize(); if (preferredSize != null) { int height = preferredSize.height; if (height < 50) { JComponent filler = GuiUtils.filler(3, height); buttonList.add(filler); } } String[][] buttonInfo = { {"Go to first frame", CMD_BEGINNING, getIcon("Rewind")}, {"One frame back", CMD_BACKWARD, getIcon("StepBack")}, {"Run/Stop", CMD_STARTSTOP, getIcon("Play")}, {"One frame forward", CMD_FORWARD, getIcon("StepForward")}, {"Go to last frame", CMD_END, getIcon("FastForward")}, {"Properties", CMD_PROPS, getIcon("Information")} }; for (int i = 0; i < buttonInfo.length; i++) { JButton btn = GuiUtils.getScaledImageButton(buttonInfo[i][2], getClass(), 2, 2); btn.setToolTipText(buttonInfo[i][0]); btn.setActionCommand(buttonInfo[i][1]); btn.addActionListener(this); btn.addKeyListener(listener); // JComponent wrapper = GuiUtils.center(btn); // wrapper.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED)); btn.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED)); buttonList.add(btn); // buttonList.add(wrapper); if (i == 2) { startStopBtn = btn; } } JComponent contents = GuiUtils.hflow(buttonList, 1, 0); if (boxPanel == null) { boxPanel = new AnimationBoxPanel(this); if (timesArray != null) { updateBoxPanel(timesArray); } } boxPanel.addKeyListener(listener); if (!getBoxPanelVisible()) { boxPanel.setVisible(false); } contents = GuiUtils.doLayout(new Component[] {boxPanel, contents}, 1, GuiUtils.WT_Y, GuiUtils.WT_N); // GuiUtils.addKeyListenerRecurse(listener,contents); if (floatToolBar) { JToolBar toolbar = new JToolBar(JToolBar.HORIZONTAL); toolbar.setFloatable(true); contents = GuiUtils.left(contents); toolbar.add(contents); contents = toolbar; } updateRunButton(); madeContents = true; return contents; }
@Override public Dimension getPreferredSize() { return myThemedCombo.getPreferredSize(); }
public SceneLayoutApp() { super(); new Pair(); final JFrame frame = new JFrame("Scene Layout"); final JPanel panel = new JPanel(new BorderLayout()); frame.setContentPane(panel); final Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); frame.setMaximumSize(screenSize); frame.setSize(screenSize); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); final JMenuBar mb = new JMenuBar(); frame.setJMenuBar(mb); final JMenu jMenu = new JMenu("File"); mb.add(jMenu); mb.add(new JMenu("Edit")); mb.add(new JMenu("Help")); JMenu menu = new JMenu("Look and Feel"); // // Get all the available look and feel that we are going to use for // creating the JMenuItem and assign the action listener to handle // the selection of menu item to change the look and feel. // UIManager.LookAndFeelInfo[] lookAndFeelInfos = UIManager.getInstalledLookAndFeels(); for (int i = 0; i < lookAndFeelInfos.length; i++) { final UIManager.LookAndFeelInfo lookAndFeelInfo = lookAndFeelInfos[i]; JMenuItem item = new JMenuItem(lookAndFeelInfo.getName()); item.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { try { // // Set the look and feel for the frame and update the UI // to use a new selected look and feel. // UIManager.setLookAndFeel(lookAndFeelInfo.getClassName()); SwingUtilities.updateComponentTreeUI(frame); } catch (ClassNotFoundException e1) { e1.printStackTrace(); } catch (InstantiationException e1) { e1.printStackTrace(); } catch (IllegalAccessException e1) { e1.printStackTrace(); } catch (UnsupportedLookAndFeelException e1) { e1.printStackTrace(); } } }); menu.add(item); } mb.add(menu); jMenu.add(new JMenuItem(new scene.action.QuitAction())); panel.add(new JScrollPane(desktopPane), BorderLayout.CENTER); final JToolBar bar = new JToolBar(); panel.add(bar, BorderLayout.NORTH); final JComboBox comboNewWindow = new JComboBox( new String[] {"320:180", "320:240", "640:360", "640:480", "1280:720", "1920:1080"}); comboNewWindow.addActionListener(new CreateSceneWindowAction()); comboNewWindow.setBorder(BorderFactory.createTitledBorder("Create New Window")); bar.add(comboNewWindow); bar.add( new AbstractAction("Progress Bars") { /** Invoked when an action occurs. */ @Override public void actionPerformed(ActionEvent e) { new ProgressBarAnimator(); } }); bar.add( new AbstractAction("Sliders") { /** Invoked when an action occurs. */ @Override public void actionPerformed(ActionEvent e) { new SliderBarAnimator(); } }); final JCheckBox permaViz = new JCheckBox(); permaViz.setText("Show the dump window"); permaViz.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED)); dumpWindow = new JInternalFrame("perma dump window"); dumpWindow.setContentPane(new JScrollPane(permText)); permaViz.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { dumpWindow.setVisible(permaViz.isSelected()); } }); comboNewWindow.setMaximumSize(comboNewWindow.getPreferredSize()); permaViz.setSelected(false); bar.add(new CreateWebViewV1Action()); bar.add(new CreateWebViewV2Action()); bar.add(permaViz); desktopPane.add(dumpWindow); dumpWindow.setSize(400, 400); dumpWindow.setResizable(true); dumpWindow.setClosable(false); dumpWindow.setIconifiable(false); final JMenuBar m = new JMenuBar(); final JMenu cmenu = new JMenu("Create"); m.add(cmenu); final JMenuItem menuItem = new JMenuItem( new AbstractAction("new") { @Override public void actionPerformed(ActionEvent e) { Runnable runnable = new Runnable() { public void run() { Object[] in = (Object[]) XSTREAM.fromXML(permText.getText()); final JInternalFrame ff = new JInternalFrame(); final ScenePanel c = new ScenePanel(); ff.setContentPane(c); desktopPane.add(ff); final Dimension d = (Dimension) in[0]; c.setMaximumSize(d); c.setPreferredSize(d); ff.setSize(d.width + 50, d.height + 50); ScenePanel.panes.put(c, (List<Pair<Point, ArrayList<URL>>>) in[1]); c.invalidate(); c.repaint(); ff.pack(); ff.setClosable(true); ff.setMaximizable(false); ff.setIconifiable(false); ff.setResizable(false); ff.show(); } }; SwingUtilities.invokeLater(runnable); } }); cmenu.add(menuItem); // JMenuBar menuBar = new JMenuBar(); // getContentPane().add(menuBar); dumpWindow.setJMenuBar(m); frame.setVisible(true); }