/** * Creates a new Victor speed controller. * * @param channel The Digital Sidecar channel it should be connected to. */ public Victor(int channel) { frame = new JFrame("Victor Emulator: " + channel); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // frame.setResizable(false); frame.setLocation(510, 0); frame.setLayout(new BorderLayout()); frame.setPreferredSize(new Dimension(300, 320)); // tells the current speed of the victor in % above the graph. victorSpeed = new JLabel("Current Speed: " + (speed * 100) + "%"); frame.add(victorSpeed, BorderLayout.NORTH); // allows user to stop the movement of the graph. button located under the graph. startStop = new JButton("Stop Graph"); startStop.addActionListener(this); frame.add(startStop, BorderLayout.SOUTH); // makes the actual graph. graph = new SpeedGrapher(300, 300); frame.add(graph, BorderLayout.CENTER); startTime = 0; isGraphRunning = true; frame.addComponentListener(this); frame.pack(); frame.setVisible(true); }
public void openInAFrame(boolean on) { if (on) { if (frame == null) { frame = new JFrame("GraphStream"); frame.setLayout(new BorderLayout()); frame.add(this, BorderLayout.CENTER); frame.setSize(800, 600); frame.setLocationRelativeTo(null); frame.setVisible(true); frame.addWindowListener(this); frame.addComponentListener(this); frame.addKeyListener(shortcuts); } else { frame.setVisible(true); } } else { if (frame != null) { frame.removeComponentListener(this); frame.removeWindowListener(this); frame.removeKeyListener(shortcuts); frame.remove(this); frame.setVisible(false); frame.dispose(); } } }
public TransparentBackground(JFrame frame) { this.frame = frame; updateBackground(); frame.addComponentListener(this); frame.addWindowFocusListener(this); new Thread(this).start(); }
public Wing(JFrame parent) { super(parent, false); component = parent; this.setUndecorated(true); this.init(); parent.addComponentListener(this); this.addComponentListener(this); }
protected JFrame getPopupWindow() { if (popupWindow == null) { popupWindow = new JFrame(STLConstants.K1063_TOP_OUTLINE.getValue()); Image[] images = new Image[] { UIImages.LOGO_24.getImage(), UIImages.LOGO_32.getImage(), UIImages.LOGO_64.getImage(), UIImages.LOGO_128.getImage() }; popupWindow.setIconImages(Arrays.asList(images)); popupWindow.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); popupWindow.addComponentListener( new ComponentAdapter() { /* * (non-Javadoc) * * @see * java.awt.event.ComponentAdapter#componentResized(java.awt * .event.ComponentEvent) */ @Override public void componentResized(ComponentEvent e) { popupBound = popupWindow.getBounds(); popupState = popupWindow.getExtendedState(); } /* * (non-Javadoc) * * @see * java.awt.event.ComponentAdapter#componentMoved(java.awt.event * .ComponentEvent) */ @Override public void componentMoved(ComponentEvent e) { popupBound = popupWindow.getBounds(); popupState = popupWindow.getExtendedState(); } }); JPanel content = (JPanel) popupWindow.getContentPane(); content.setLayout(new BorderLayout()); content.setBackground(UIConstants.INTEL_WHITE); content.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); popupOutline = new TopologyOutlinePanel(updateService, Fit.WINDOW); popupOutline.setBackground(UIConstants.INTEL_WHITE); popupOutline.setPreferredSize(new Dimension(800, 600)); popupOutline.setMinimumSize(new Dimension(400, 300)); popupOutline.setToolTipText(""); popupOutline.setGraph(graph); content.add(popupOutline, BorderLayout.CENTER); popupWindow.pack(); } return popupWindow; }
public static void lockInMinSize(final JFrame frame) { // Ensures user cannot resize frame to be smaller than frame is right now. final int origX = frame.getSize().width; final int origY = frame.getSize().height; // frame.setSize(new Dimension(origX, origY)); frame.addComponentListener( new java.awt.event.ComponentAdapter() { @Override public void componentResized(ComponentEvent event) { frame.setSize(Math.max(frame.getWidth(), origX), Math.max(frame.getHeight(), origY)); frame.repaint(); } }); }
public FramePrefsHandler(JFrame frame) { this.frame = frame; frame.pack(); // makes the frame displayable, so that maximizing works frame.setMinimumSize(frame.getSize()); frame.setMaximizedBounds( GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds()); frame.setBounds(Util.stringToRectangle(PREFS.get("WINDOW_BOUNDS", null), frame.getBounds())); int state = frame.getExtendedState() | (PREFS.getBoolean("WINDOW_MAXIMIZED", true) ? JFrame.MAXIMIZED_BOTH : 0); frame.setExtendedState(state); frame.addComponentListener(this); frame.addWindowStateListener(this); }
// constructor public ClassTableInstance(JFrame jframe) { super(new BorderLayout(0, 0)); this.frame = jframe; model = new MyTableModel(); table = new JTable(model); table.setPreferredScrollableViewportSize(new Dimension(500, 70)); // Create the scroll pane and add the table to it. scrollPane = new JScrollPane(table); // Enable tool tips. ToolTipManager.sharedInstance().registerComponent(table); // set up colour manager table.setDefaultRenderer(String.class, new ColorRenderer(true)); // Listen for when the selection changes. table.addMouseListener(this); // Custom cell weight table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); // frame resize listener frame.addComponentListener( new ComponentAdapter() { @Override public void componentResized(ComponentEvent e) { double a = e.getComponent().getSize().getWidth() - scrollPane.getVerticalScrollBar().getSize().getWidth(); setTableDimensions((a - 15) * 0.3); } }); // Add the scroll pane to this panel. add(scrollPane, BorderLayout.CENTER); }
/** * Creates the frame to display the game. * * @param players * @param world * @param game */ public WorldPreviewGameFrame(Set<WorldPreview> worlds) { this.worlds = worlds; this.setSize( new Dimension( (int) (res_width * scaleFactorWidth), (int) (res_height * scaleFactorHeight))); // Setup the window. frame = new JFrame("Super Mario War"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize((int) (res_width * scaleFactorWidth), (int) (res_height * scaleFactorHeight)); frame.setLocationRelativeTo(null); frame.setVisible(true); frame.setResizable(true); frame.add(this, BorderLayout.CENTER); frame.pack(); // If the window is closed perform any needed shutdown cleanup. frame.addWindowListener( new WindowAdapter() { @Override public void windowClosing(WindowEvent we) { WorldPreviewTest.shutdown(); System.exit(0); } }); frame.addComponentListener( new ComponentAdapter() { public void componentResized(ComponentEvent e) { resetScalingFactors(); } }); // Now that frame is setup, create buffer strategy. this.createBufferStrategy(3); bs = getBufferStrategy(); }
/** Initialize the contents of the frame. */ private void initialize() { frmPuzzledicePuzzleEditor = new JFrame(); frmPuzzledicePuzzleEditor.setTitle("Puzzledice Puzzle Map Editor"); frmPuzzledicePuzzleEditor.setBounds(100, 100, 743, 585); frmPuzzledicePuzzleEditor.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); frmPuzzledicePuzzleEditor.getContentPane().setLayout(new BorderLayout(0, 0)); frmPuzzledicePuzzleEditor.addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent winEvt) { if (onExit()) System.exit(0); } }); // Set up the program to catch OSX quit events try { OSXAdapter.setQuitHandler(this, this.getClass().getMethod("onExit", new Class[] {})); } catch (SecurityException e) { e.printStackTrace(); } catch (NoSuchMethodException e) { e.printStackTrace(); } JMenuBar menuBar = new JMenuBar(); frmPuzzledicePuzzleEditor.setJMenuBar(menuBar); JMenu mnFile = new JMenu("File"); menuBar.add(mnFile); JMenuItem mntmNew = new JMenuItem("New"); mntmNew.setAccelerator( KeyStroke.getKeyStroke( KeyEvent.VK_N, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); mntmNew.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent evt) { clear(); _openFile = null; } }); mnFile.add(mntmNew); JMenuItem mntmOpen = new JMenuItem("Open"); mntmOpen.setAccelerator( KeyStroke.getKeyStroke( KeyEvent.VK_O, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); mntmOpen.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent evt) { // Run the file dialogue later since it's blocking SwingUtilities.invokeLater( new Runnable() { public void run() { FileDialog chooser = new FileDialog(frmPuzzledicePuzzleEditor, "Open", FileDialog.LOAD); chooser.setVisible(true); if (chooser.getFile() != null) { clear(); File file = new File(chooser.getDirectory(), chooser.getFile()); if (Loader.LoadFromXML(file)) { areaEditPanel.justLoaded(); puzzleEditPanel.justLoaded(); _openFile = file; } else { JOptionPane.showMessageDialog( frmPuzzledicePuzzleEditor, "File failed to open!", "Error", JOptionPane.ERROR_MESSAGE); } } } }); } }); mnFile.add(mntmOpen); JMenuItem mntmSave = new JMenuItem("Save"); mntmSave.setAccelerator( KeyStroke.getKeyStroke( KeyEvent.VK_S, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); mntmSave.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent arg0) { // Invoke the save later since it's a blocking method SwingUtilities.invokeLater( new Runnable() { public void run() { save(); } }); } }); mnFile.add(mntmSave); JMenuItem mntmSaveAs = new JMenuItem("Save As"); mntmSaveAs.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent evt) { SwingUtilities.invokeLater( new Runnable() { public void run() { String xml = xmlDigest(); saveAs(xml); } }); } }); mnFile.add(mntmSaveAs); JMenuItem mntmExit = new JMenuItem("Exit"); mntmExit.setAccelerator( KeyStroke.getKeyStroke( KeyEvent.VK_Q, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); mntmExit.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent arg0) { if (onExit()) System.exit(0); } }); mnFile.add(mntmExit); JMenu mnHelp = new JMenu("Help"); menuBar.add(mnHelp); JPanel panel = new JPanel(); frmPuzzledicePuzzleEditor.getContentPane().add(panel); panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS)); JPanel editPanel = new JPanel(); panel.add(editPanel); editPanel.setLayout(new BoxLayout(editPanel, BoxLayout.X_AXIS)); JSeparator separator_2 = new JSeparator(); separator_2.setMinimumSize(new Dimension(5, 0)); separator_2.setMaximumSize(new Dimension(5, 0)); separator_2.setPreferredSize(new Dimension(5, 0)); editPanel.add(separator_2); areaEditPanel = new AreaEditPanel(); editPanel.add(areaEditPanel); JSeparator separator = new JSeparator(); separator.setMinimumSize(new Dimension(5, 0)); separator.setMaximumSize(new Dimension(5, 0)); separator.setPreferredSize(new Dimension(5, 0)); editPanel.add(separator); puzzleEditPanel = new PuzzleEditPanel(); editPanel.add(puzzleEditPanel); JSeparator separator_1 = new JSeparator(); separator_1.setMinimumSize(new Dimension(5, 0)); separator_1.setMaximumSize(new Dimension(5, 0)); separator_1.setPreferredSize(new Dimension(5, 0)); editPanel.add(separator_1); graphPanel = new JTabbedPane(JTabbedPane.TOP); graphPanel.setPreferredSize( new Dimension( frmPuzzledicePuzzleEditor.getBounds().width, frmPuzzledicePuzzleEditor.getBounds().height)); panel.add(graphPanel); graphPanel.setAlignmentY(Component.TOP_ALIGNMENT); areaGraph = new mxGraph(); areaGraph.setAutoSizeCells(true); areaGraphComponent = new mxGraphComponent(areaGraph); areaGraphComponent.addComponentListener( new ComponentAdapter() { @Override public void componentResized(ComponentEvent arg0) { areaGraphLayout = new mxOrganicLayout( areaGraph, new Rectangle( 0, 0, graphPanel.getBounds().width, graphPanel.getBounds().height)); areaGraphLayout.execute(areaGraph.getDefaultParent()); } }); areaGraphComponent.setEnabled(false); areaGraphLayout = new mxOrganicLayout( areaGraph, new Rectangle(0, 0, graphPanel.getBounds().width, graphPanel.getBounds().height)); areaGraph.setEnabled(false); graphPanel.addTab("Area Graph", null, areaGraphComponent, null); puzzleGraph = new mxGraph(); puzzleGraph.setAutoSizeCells(true); puzzleGraphComponent = new mxGraphComponent(puzzleGraph); puzzleGraphComponent.addComponentListener( new ComponentAdapter() { @Override public void componentResized(ComponentEvent arg0) {} }); puzzleGraphComponent.setEnabled(false); puzzleGraphOrganicLayout = new mxOrganicLayout( puzzleGraph, new Rectangle(0, 0, graphPanel.getBounds().width, graphPanel.getBounds().height)); puzzleGraphHierLayout = new mxHierarchicalLayout(puzzleGraph, SwingConstants.WEST); graphPanel.addTab("Puzzle Graph", null, puzzleGraphComponent, null); txtTextPanel = new JTextArea("Textual description"); panel.add(txtTextPanel); txtTextPanel.setLineWrap(true); txtTextPanel.setWrapStyleWord(true); txtTextPanel.setEditable(false); frmPuzzledicePuzzleEditor.addComponentListener( new ComponentAdapter() { @Override public void componentResized(ComponentEvent arg0) { graphPanel.setPreferredSize( new Dimension( frmPuzzledicePuzzleEditor.getBounds().width, frmPuzzledicePuzzleEditor.getBounds().height)); } }); _emptyXml = xmlDigest(); }
public static void main(String[] args) { polygons = new ArrayList<Polygon>(); rotateLine[0] = new Point3Df(-1.0f, -1.0f, -1.0f); rotateLine[1] = new Point3Df(1.0f, 1.0f, 1.0f); // Prepare all our OpenGL canvas GLProfile glp = GLProfile.getDefault(); GLCapabilities caps = new GLCapabilities(glp); canvas[0] = new GLCanvas(caps); canvas[1] = new GLCanvas(caps); canvas[2] = new GLCanvas(caps); // Prepare the main frame for the application JFrame frame = new JFrame(appTitle); // The file chooser for opening and saving files final JFileChooser fc = new JFileChooser(); // Since the app started, set the save file to null saveFile = null; // This is our scene, which contains our polygons and rendering functions scene[0] = new Scene(Scene.XZPlane); scene[1] = new Scene(Scene.YZPlane); scene[2] = new Scene(Scene.XYPlane); // This is our list model and JList that will allow us to select the // polygons we wish to transform listModel = new DefaultListModel(); JList listPolys = new JList(listModel); listPolys.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); listPolys.setLayoutOrientation(JList.VERTICAL); listPolys.setVisibleRowCount(-1); JScrollPane listScrollerPolys = new JScrollPane(listPolys); refreshPolygons(); // This listener waits for selections in the JList and updates the polygons // in the scene with "selected" markers listPolys .getSelectionModel() .addListSelectionListener( new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { if (e.getValueIsAdjusting() == false) { ListSelectionModel lsm = (ListSelectionModel) e.getSource(); int minIndex = lsm.getMinSelectionIndex(); int maxIndex = lsm.getMaxSelectionIndex(); for (Polygon p : polygons) { p.setSelected(false); } for (int i = minIndex; i <= maxIndex; i++) { if (lsm.isSelectedIndex(i)) { ((Polygon) listPolys.getModel().getElementAt(i)).setSelected(true); } } refreshCanvas(); } } }); JSplitPane oneTwo = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, canvas[0], canvas[1]); JSplitPane threeFour = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, canvas[2], listScrollerPolys); oneTwo.setDividerLocation(0.50); threeFour.setDividerLocation(0.50); JSplitPane canvases = new JSplitPane(JSplitPane.VERTICAL_SPLIT, oneTwo, threeFour); canvases.setDividerLocation(0.50); // Main menu for this application JMenuBar menu = new JMenuBar(); JMenu menuFile = new JMenu("File"); JMenuItem menuOpen = new JMenuItem( new AbstractAction("Open") { @Override public void actionPerformed(ActionEvent e) { int returnVal = fc.showOpenDialog(frame); if (returnVal == JFileChooser.APPROVE_OPTION) { saveFile = fc.getSelectedFile(); openPolygons(); refreshPolygons(); refreshCanvas(); frame.setTitle(appTitle + " - " + saveFile.getAbsolutePath()); } } }); JMenuItem menuImportPly = new JMenuItem( new AbstractAction("Import Ply") { @Override public void actionPerformed(ActionEvent e) { int returnVal = fc.showOpenDialog(frame); if (returnVal == JFileChooser.APPROVE_OPTION) { importPly(fc.getSelectedFile()); refreshPolygons(); refreshCanvas(); } } }); JMenuItem menuSave = new JMenuItem( new AbstractAction("Save") { @Override public void actionPerformed(ActionEvent e) { if (saveFile != null) { savePolygons(); } else { int returnVal = fc.showSaveDialog(frame); if (returnVal == JFileChooser.APPROVE_OPTION) { saveFile = fc.getSelectedFile(); savePolygons(); frame.setTitle(appTitle + " - " + saveFile.getAbsolutePath()); } } } }); JMenuItem menuSaveAs = new JMenuItem( new AbstractAction("Save As") { @Override public void actionPerformed(ActionEvent e) { int returnVal = fc.showSaveDialog(frame); if (returnVal == JFileChooser.APPROVE_OPTION) { saveFile = fc.getSelectedFile(); savePolygons(); frame.setTitle(appTitle + " - " + saveFile.getAbsolutePath()); } } }); JMenuItem menuExit = new JMenuItem( new AbstractAction("Exit") { @Override public void actionPerformed(ActionEvent e) { System.exit(0); } }); menuFile.add(menuOpen); menuFile.add(menuImportPly); menuFile.add(menuSave); menuFile.add(menuSaveAs); menuFile.add(menuExit); JMenu menuTransform = new JMenu("Transform"); JMenuItem menuTranslate = new JMenuItem( new AbstractAction("Translate") { @Override public void actionPerformed(ActionEvent e) { String vector = (String) JOptionPane.showInputDialog(frame, "Input Translation Vector: x,y,z"); String[] vectorParts = vector.split(",", 3); float x = Float.valueOf(vectorParts[0]); float y = Float.valueOf(vectorParts[1]); float z = Float.valueOf(vectorParts[2]); for (Polygon p : polygons) { if (p.getSelected()) { p.translate(new Point3Df(x, y, z)); rebound(); } } refreshCanvas(); } }); JMenuItem menuScale = new JMenuItem( new AbstractAction("Scale") { @Override public void actionPerformed(ActionEvent e) { String vector = (String) JOptionPane.showInputDialog(frame, "Input Scale Factor: x,y,z"); String[] vectorParts = vector.split(",", 3); float x = Float.valueOf(vectorParts[0]); float y = Float.valueOf(vectorParts[1]); float z = Float.valueOf(vectorParts[2]); for (Polygon p : polygons) { if (p.getSelected()) { p.scale(new Point3Df(x, y, z)); rebound(); } } refreshCanvas(); } }); JMenuItem menuRotateLine = new JMenuItem( new AbstractAction("Set Rotate Line") { @Override public void actionPerformed(ActionEvent e) { String vector = (String) JOptionPane.showInputDialog(frame, "Input Line Point 0: x0,y0,z0"); String[] vectorParts = vector.split(",", 3); float x0 = Float.valueOf(vectorParts[0]); float y0 = Float.valueOf(vectorParts[1]); float z0 = Float.valueOf(vectorParts[2]); vector = (String) JOptionPane.showInputDialog(frame, "Input Line Point 1: x1,y1,z1"); vectorParts = vector.split(",", 3); float x1 = Float.valueOf(vectorParts[0]); float y1 = Float.valueOf(vectorParts[1]); float z1 = Float.valueOf(vectorParts[2]); rotateLine[0] = new Point3Df(x0, y0, z0); rotateLine[1] = new Point3Df(x1, y1, z1); refreshCanvas(); } }); JMenuItem menuRotate = new JMenuItem( new AbstractAction("Rotate") { @Override public void actionPerformed(ActionEvent e) { String sangle = (String) JOptionPane.showInputDialog(frame, "Input Rotation Angle in Degrees:"); float angle = Float.valueOf(sangle); for (Polygon p : polygons) { if (p.getSelected()) { p.rotate(rotateLine[0], rotateLine[1], angle * (Math.PI / 180)); rebound(); } } refreshCanvas(); } }); menuTransform.add(menuTranslate); menuTransform.add(menuScale); menuTransform.add(menuRotateLine); menuTransform.add(menuRotate); JMenu menuAnimate = new JMenu("Animate"); JMenuItem menuAnimateStart = new JMenuItem( new AbstractAction("Start") { @Override public void actionPerformed(ActionEvent e) { for (int i = 0; i < 3; i++) { scene[i].setAnimation(true); animator[i].start(); } } }); JMenuItem menuAnimateStop = new JMenuItem( new AbstractAction("Stop") { @Override public void actionPerformed(ActionEvent e) { for (int i = 0; i < 3; i++) { scene[i].setAnimation(false); animator[i].stop(); } } }); JMenuItem menuAnimateReset = new JMenuItem( new AbstractAction("Reset") { @Override public void actionPerformed(ActionEvent e) { for (int i = 0; i < 3; i++) { scene[i].resetRotationAnimation(); } refreshCanvas(); } }); menuAnimate.add(menuAnimateStart); menuAnimate.add(menuAnimateStop); menuAnimate.add(menuAnimateReset); menu.add(menuFile); menu.add(menuTransform); menu.add(menuAnimate); // Set the menu for the frame frame.setJMenuBar(menu); // Maximize the frame on startup frame.setExtendedState(java.awt.Frame.MAXIMIZED_BOTH); // Add our splitpane to the frame frame.getContentPane().add(canvases); frame.setVisible(true); frame.addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); canvases.addComponentListener( new ComponentListener() { // We do this to keep the splitpane the same proportion public void componentResized(ComponentEvent e) { oneTwo.setDividerLocation(0.50); threeFour.setDividerLocation(0.50); canvases.setDividerLocation(0.50); } @Override public void componentMoved(ComponentEvent e) {} @Override public void componentShown(ComponentEvent e) {} @Override public void componentHidden(ComponentEvent e) {} }); frame.addComponentListener( new ComponentListener() { // We do this to keep the splitpane the same proportion public void componentResized(ComponentEvent e) { canvases.setDividerLocation(0.50); } @Override public void componentMoved(ComponentEvent e) {} @Override public void componentShown(ComponentEvent e) {} @Override public void componentHidden(ComponentEvent e) {} }); canvas[0].addGLEventListener(scene[0]); canvas[1].addGLEventListener(scene[1]); canvas[2].addGLEventListener(scene[2]); animator[0] = new Animator(canvas[0]); animator[1] = new Animator(canvas[1]); animator[2] = new Animator(canvas[2]); }
public static void main(String[] args) { f = new JFrame("Server"); f.setVisible(true); f.setSize(500, 360); f.setLocation(100, 100); f.setLayout(null); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setBackground(Color.black); f.setAlwaysOnTop(true); a = new JTextArea(); a.setVisible(true); a.setSize(f.getWidth(), f.getHeight() - 60); a.setLocation(0, 0); a.setEditable(false); a.setBackground(Color.black); a.setForeground(Color.white); DefaultCaret caret = (DefaultCaret) a.getCaret(); caret.setUpdatePolicy(DefaultCaret.ALWAYS_UPDATE); b = new JTextField(); b.setVisible(true); b.setSize(f.getWidth() - 110, 20); b.setLocation(5, f.getHeight() - 65); b.setBackground(Color.black); b.setForeground(Color.white); f.add(b); c = new JScrollPane(a); c.setVisible(true); c.setSize(f.getWidth() - 20, f.getHeight() - 70); c.setLocation(1, 1); c.setBackground(Color.black); c.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS); c.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); c.setAutoscrolls(true); f.add(c); d = new JButton("INVIA"); d.setVisible(true); d.setSize(90, 20); d.setLocation(f.getWidth() - 105, f.getHeight() - 65); f.add(d); f.repaint(); f.addComponentListener( new ComponentListener() { @Override public void componentShown(ComponentEvent arg0) {} @Override public void componentResized(ComponentEvent arg0) { a.setSize(f.getWidth(), f.getHeight() - 60); b.setSize(f.getWidth() - 110, 20); b.setLocation(5, f.getHeight() - 65); c.setSize(f.getWidth() - 20, f.getHeight() - 70); d.setLocation(f.getWidth() - 100, f.getHeight() - 65); } @Override public void componentMoved(ComponentEvent arg0) {} @Override public void componentHidden(ComponentEvent arg0) {} }); b.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { console(); } }); d.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { console(); } }); Thread t = new Thread(new restart()); t.start(); s = new Server(); s.start(6677); }
public HexagonViewerAdvance(String[] args) { FormPanel panel = new FormPanel("ise/ct/plugins/HexagonViewerForm.jfrm"); super.add(panel); // add references to configurable components on form worldMap = panel.getComponentByName("HexagonViewerImage"); statusTitle = panel.getComponentByName("StatusTitle"); fileTitle = panel.getLabel("FileTitle"); fileProgress = panel.getProgressBar("FileProgress"); iterationTitle = panel.getLabel("IterationTitle"); iterationProgress = panel.getProgressBar("IterationProgress"); cycleTitle = panel.getLabel("CycleTitle"); cycleProgress = panel.getProgressBar("CycleProgress"); currentTitle = panel.getComponentByName("CurrentTitle"); commentTitle = panel.getLabel("CommentTitle"); commentLabel = panel.getLabel("CommentLabel"); phaseTitle = panel.getLabel("PhaseTitle"); phaseLabel = panel.getLabel("PhaseLabel"); turnTitle = panel.getLabel("TurnTitle"); turnProgress = panel.getProgressBar("TurnProgress"); showPaths = panel.getCheckBox("ShowPaths"); showPaths.setActionCommand("showpaths"); showPaths.setSelected(true); doShowPaths = true; showPaths.addItemListener(this); playButton = panel.getButton("PlayButton"); stepButton = panel.getButton("StepButton"); endButton = panel.getButton("EndButton"); playButton.setActionCommand("play"); stepButton.setActionCommand("step"); endButton.setActionCommand("end"); playButton.addItemListener(this); stepButton.addItemListener(this); endButton.addItemListener(this); playButton.setEnabled(true); stepButton.setEnabled(true); endButton.setEnabled(true); playButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent ae) { JButton s = (JButton) ae.getSource(); if (s.getText().equalsIgnoreCase("Pause")) { s.setText("Play"); Simulator.controlPanel.paused = true; Simulator.controlPanel.step = false; } else { s.setText("Pause"); Simulator.controlPanel.paused = false; Simulator.controlPanel.step = false; } } }); stepButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent ae) { playButton.setText("Play"); Simulator.controlPanel.paused = true; Simulator.controlPanel.step = true; } }); endButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent ae) { Simulator.experimentLength = Simulator.cycle; Simulator.controlPanel.paused = false; } }); cycleTitle = panel.getLabel("CycleTitle"); phaseTitle = panel.getLabel("PhaseTitle"); inspectorTitle = panel.getLabel("InspectorTitle"); cycleProgress = panel.getProgressBar("CycleProgress"); seperator1 = panel.getComponentByName("Seperator1"); seperator2 = panel.getComponentByName("Seperator2"); seperator3 = panel.getComponentByName("Seperator3"); seperator4 = panel.getComponentByName("Seperator4"); // inspector JScrollPane and JTree inspectorScrollPane = panel.getComponentByName("InspectorScrollPane"); inspectorTree = new JTree(); inspectorTree.setRowHeight(iconSize); inspectorTree.setCellRenderer( new DefaultTreeCellRenderer() { private static final long serialVersionUID = 1L; public Icon getLeafIcon() { Icon icon; if (this.getText().equals(AUCTION_NAME)) { icon = new ImageIcon(createAuctionIcon(iconSize, iconSize)); } else { icon = new ImageIcon(createAgentIcon(this.getText(), iconSize, iconSize)); } return icon; } }); getRootPane().setDefaultButton((JButton) playButton); super.addComponentListener(this); // resize events etc. // set the parameters this frame setSize(600, 500); setLocation(200, 100); setTitle("Hexagon Viewer Advance"); setVisible(true); }
public static void main(final String[] args) { final JFrame frame = new JFrame(); frame.setTitle(Globals.getLocalizedString("programName")); frame.setBackground(VComponentGlobals.BACKGROUND_COLOR); try { frame.setIconImage( ICODecoder.read(ClassLoader.getSystemResourceAsStream("Art Assets/Icons/Frame_Icon.ico")) .get(0)); } catch (final IOException e) { Logger.writeLog( Globals.getLocalizedString("DC_error_UnableToLoadIcon"), Logger.LOG_TYPE_ERROR); } frame.addWindowListener( new WindowListener() { @Override public void windowOpened(WindowEvent e) {} @Override public void windowClosing(WindowEvent e) { System.exit(0); } @Override public void windowClosed(WindowEvent e) { System.exit(0); } @Override public void windowIconified(WindowEvent e) {} @Override public void windowDeiconified(WindowEvent e) {} @Override public void windowActivated(WindowEvent e) {} @Override public void windowDeactivated(WindowEvent e) {} }); frame.addComponentListener( new ComponentAdapter() { public void componentResized(ComponentEvent e) { final Dimension currentDimensions = frame.getSize(); final Dimension minimumDimensions = frame.getMinimumSize(); if (currentDimensions.width < minimumDimensions.width) { currentDimensions.width = minimumDimensions.width; } if (currentDimensions.height < minimumDimensions.height) { currentDimensions.height = minimumDimensions.height; } frame.setSize(currentDimensions); } }); frame.add(new ConnectionScreenController(frame).getView()); frame.setResizable(false); frame.pack(); frame.setLocationRelativeTo(null); frame.setVisible(true); }
/** * Initializer, handles layout and wiring. Called when set of images is created. * * @param hasChannels */ public void show(final boolean hasChannels) { if (null == _frame || !_frame.isShowing()) { // create the histogram and color bar display panels _histogramPanel = new HistogramPanel(WIDTH, INSET, HISTOGRAM_HEIGHT); _histogramPanel.setListener(new HistogramPanelListener()); _colorBarPanel = new ColorBarPanel(WIDTH, INSET, COLORBAR_HEIGHT); _colorBarPanel.setLUT(getLUT()); _uiPanel = new HistogramUIPanel(hasChannels); _uiPanel.setListener(new UIPanelListener()); _frame = new JFrame("Histogram"); // _frame.setResizable(false); _frame.setLayout(new BorderLayout()); final JPanel panel = new JPanel(); panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS)); panel.add(_colorBarPanel); panel.add(_uiPanel); _frame.getContentPane().add(_histogramPanel, BorderLayout.CENTER); _frame.getContentPane().add(panel, BorderLayout.SOUTH); _frame.pack(); _frame.setVisible(true); // IJ.log("initial size " + _frame.getSize()); _frame.addComponentListener( new ComponentListener() { @Override public void componentHidden(final ComponentEvent e) {} @Override public void componentMoved(final ComponentEvent e) {} @Override public void componentResized(final ComponentEvent e) { // constrain maximum size boolean resize = false; final Dimension size = _frame.getSize(); if (size.width != (SET_WIDTH)) { size.width = SET_WIDTH; resize = true; } if (size.height > MAX_HEIGHT) { size.height = MAX_HEIGHT; resize = true; } if (size.height < MIN_HEIGHT) { size.height = MIN_HEIGHT; resize = true; } if (resize) { _frame.setSize(size); } saveSizeInPreferences(size); } @Override public void componentShown(final ComponentEvent e) {} }); _frame.setSize(getSizeFromPreferences()); } }
protected GLJPanel newGLJPanel( final JFrame frame, final GLCapabilities caps, final FPSAnimator animator, final SnapshotGLEventListener snap) throws AWTException, InterruptedException, InvocationTargetException { final GLJPanel glJPanel = new GLJPanel(caps); Assert.assertNotNull(glJPanel); glJPanel.setSkipGLOrientationVerticalFlip(skipGLOrientationVerticalFlip); glJPanel.setMinimumSize(wsize); glJPanel.setPreferredSize(wsize); glJPanel.setSize(wsize); glJPanel.setSurfaceScale(reqSurfacePixelScale); { final GLEventListener demo = createDemo(caps); if (null != demo) { glJPanel.addGLEventListener(demo); } } if (null != snap) { glJPanel.addGLEventListener(snap); } glJPanel.addGLEventListener( new GLEventListener() { @Override public void init(final GLAutoDrawable drawable) {} @Override public void dispose(final GLAutoDrawable drawable) {} @Override public void display(final GLAutoDrawable drawable) {} @Override public void reshape( final GLAutoDrawable drawable, final int x, final int y, final int width, final int height) { setTitle(frame, glJPanel, caps); } }); setTitle(frame, glJPanel, caps); frame.addComponentListener( new ComponentListener() { @Override public void componentResized(final ComponentEvent e) { setTitle(frame, glJPanel, caps); } @Override public void componentMoved(final ComponentEvent e) { setTitle(frame, glJPanel, caps); } @Override public void componentShown(final ComponentEvent e) {} @Override public void componentHidden(final ComponentEvent e) {} }); if (SwingUtilities.isEventDispatchThread()) { frame.getContentPane().add(glJPanel, BorderLayout.CENTER); frame.getContentPane().validate(); frame.pack(); frame.setVisible(true); } else { SwingUtilities.invokeAndWait( new Runnable() { public void run() { frame.getContentPane().add(glJPanel, BorderLayout.CENTER); frame.getContentPane().validate(); frame.pack(); frame.setVisible(true); } }); Assert.assertEquals(true, AWTRobotUtil.waitForVisible(frame, true)); Assert.assertEquals(true, AWTRobotUtil.waitForRealized(glJPanel, true)); final float[] minSurfacePixelScale = glJPanel.getMinimumSurfaceScale(new float[2]); final float[] maxSurfacePixelScale = glJPanel.getMaximumSurfaceScale(new float[2]); final float[] valReqSurfacePixelScale = glJPanel.getRequestedSurfaceScale(new float[2]); final float[] hasSurfacePixelScale = glJPanel.getCurrentSurfaceScale(new float[2]); System.err.println( "HiDPI PixelScale: min " + minSurfacePixelScale[0] + "x" + minSurfacePixelScale[1] + ", max " + maxSurfacePixelScale[0] + "x" + maxSurfacePixelScale[1] + ", req " + reqSurfacePixelScale[0] + "x" + reqSurfacePixelScale[1] + " -> val " + valReqSurfacePixelScale[0] + "x" + valReqSurfacePixelScale[1] + " -> has " + hasSurfacePixelScale[0] + "x" + hasSurfacePixelScale[1]); setTitle(frame, glJPanel, caps); } if (null != animator) { animator.add(glJPanel); animator.setUpdateFPSFrames(60, System.err); } return glJPanel; }
// Constructor JavaTerm() { int ii; JMenu menu; JMenuBar menuBar; // Load in the port number from the last time we ran try { // try opening the file JavaTerm.pref DataInputStream prefs = new DataInputStream(new FileInputStream(m_PrefsFileName)); // Read in serial port index m_PortIndex = prefs.readInt(); m_IsNative = prefs.readBoolean(); // check to make sure the value we read is valid if (m_PortIndex < 0 || m_PortIndex >= m_PortMenuItem.length) { throw new IOException(m_PrefsFileName + " is corrupt"); } // init the serial port initSerialPort(); } // We'll get here if the file doesn't exist because it's the first time running this program, // it can't be found / opened, or the requested serial port can't be opened catch (IOException e) { System.out.println( "preferences file 'JavaTerm.pref' not found / didn't open or there was a problem opening serial port. Searching for serial port"); // Open the first available serial port. // This code can be adapted to provide a list of available serial ports. find_open_serial_port: for (ii = 0; ii < m_PortMenuItem.length; ii++) { try { m_PortIndex = ii + 1; // This is the serial port we want to open initSerialPort(); // Try opening this serial port. Throws exception if there's a problem System.out.println("Opening serial port Comm" + m_PortIndex); break find_open_serial_port; // If we haven't thrown an exception, we're done } catch (IOException ee) { // wind up here if initSerialPort() above has a problem if (ii == m_PortMenuItem.length - 1) { System.out.println("Couldn't open any serial ports"); System.exit(0); // can't open any serial ports. } } } } // new our window frame m_Frame = new JFrame("Javaterm"); // set frame parameters // add the menu. menuBar = new JMenuBar(); menu = new JMenu("Sitting"); file_elem.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { int choice = fileopener.showOpenDialog(null); if (choice == JFileChooser.APPROVE_OPTION) { File myfile = fileopener.getSelectedFile(); // File_out=new FileOutputStream(myFile); // Data_out=new DataOutputStream(File_out); try { // myfile.getCanonicalPath(myfile); // Bread=new BufferedReader(new FileReader(myfile)); FileInputStream File_in = new FileInputStream(myfile); DataInputStream Data_in = new DataInputStream(File_in); m_TextOutput.setText(" "); byte ch[] = new byte[50000]; int ii = 0; while (ii != -1) { ii = Data_in.read(ch); try { // if(str!=-1) for (int j = 0; j < ii; j++) { m_SerialPort.writeByte(ch[j]); Thread.sleep(18); } Thread.sleep(0); } catch (InterruptedException ex) { Data_in.close(); File_in.close(); m_TextOutput.append("\nFile Sent !"); ex.printStackTrace(); } } m_TextOutput.append("\nFile Sent !"); } catch (IOException ex) { m_TextOutput.append("\nFile Sent !"); // ex.printStackTrace(); } } } }); menu.add(file_elem); for (ii = 0; ii < m_PortMenuItem.length; ii++) { menu.add(m_PortMenuItem[ii] = new JCheckBoxMenuItem("Com " + (ii + 1), false)); m_PortMenuItem[ii].addItemListener(this); } m_PortMenuItem[m_PortIndex - 1].setState(true); menuBar.add(menu); menu = new JMenu("Clear"); menu.add(m_ClearMenuItem); m_ClearMenuItem.addActionListener(this); menuBar.add(menu); m_Frame.setJMenuBar(menuBar); cp = m_Frame.getContentPane(); cp.setLayout(new FlowLayout()); cp.add(OutputLabel); m_TextOutput = new JTextArea(10, 40); TextOutputSc = new JScrollPane( m_TextOutput, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); cp.add(TextOutputSc); // create where the text areas goes cp.add(inputLabel); m_TextInput = new JTextArea(10, 40); TextInputSc = new JScrollPane( m_TextInput, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); m_TextInput.setEditable(false); cp.add(TextInputSc); // position the text areas // updateWindowComponents(); // When a key is pressed, send that keystroke to the serial port m_TextOutput.addKeyListener( new KeyAdapter() { public void keyTyped(KeyEvent e) { // System.out.println("You Typed a character "); byte tempByte = (byte) e.getKeyChar(); m_SerialPort.writeByte(tempByte); // <-- Here's where the data gets written // DONT use writeChar(). It's a two byte char // and has screwey results. // HACKISH: Need to add newline to carriage returns for proper operation // You may not need this. if (tempByte == '\r') { m_SerialPort.writeByte((byte) '\n'); } } }); // Make sure the focus stays on the output window. If input pane gets focus, set focus back to // output pane m_TextInput.addFocusListener( new FocusAdapter() { public void focusGained(FocusEvent e) { m_TextOutput.requestFocus(); } }); // If user clicks close box, exit this program m_Frame.addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent e) { // Write the current serial port to disk writePrefs(); System.exit(0); } }); // If user resizes the window, need to reposition the text areas. m_Frame.addComponentListener( new ComponentAdapter() { public void componentResized(ComponentEvent e) { updateWindowComponents(); } }); savebutt.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { File myfile = new File(nameFiled.getText()); FileOutputStream File_out; try { File_out = new FileOutputStream(myfile); DataOutputStream Data_out = new DataOutputStream(File_out); BufferedWriter myWrit = new BufferedWriter(new FileWriter(myfile)); myWrit.write(inputString); myWrit.flush(); myWrit.close(); Data_out.close(); File_out.close(); } catch (IOException ex) { ex.printStackTrace(); } } }); nameFiled.setText("rec.txt"); cp.add(namelabel); cp.add(nameFiled); cp.add(savebutt); m_Frame.setSize(500, 600); m_Frame.setLocation(100, 100); m_Frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); m_Frame.setVisible(true); // Infinite loop. WindowListener above will break us out of loop with call to System.exit(0); for (; true; ) { // Get any pending characters from serial port. // Returns empty string if there's nothing to read. // This is in contrast to readByte() which patiently waits for data. if (m_SerialPort != null) { inputString += m_SerialPort.readString(); } try { Thread.sleep(10); } catch (InterruptedException e) { } } }
/** Adds various listeners to components of EditorWindow and to the Editor window */ protected void addListeners() { if (thisErrorWindow == null) System.out.println("ERW null"); thisErrorWindow.addComponentListener( new ComponentListener() { @Override public void componentShown(ComponentEvent e) {} @Override public void componentResized(ComponentEvent e) { Docker.tryDocking(); } @Override public void componentMoved(ComponentEvent e) { Docker.tryDocking(); } @Override public void componentHidden(ComponentEvent e) {} }); thisErrorWindow.addWindowListener( new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { thisEditor.problemWindowMenuCB.setSelected(false); } @Override public void windowDeiconified(WindowEvent e) { thisEditor.setExtendedState(Frame.NORMAL); } }); if (thisEditor == null) { System.out.println("Editor null"); return; } /*thisEditor.addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { } @Override public void windowClosed(WindowEvent e) { errorCheckerService.pauseThread(); errorCheckerService.stopThread(); // Bye bye thread. thisErrorWindow.dispose(); } @Override public void windowIconified(WindowEvent e) { thisErrorWindow.setExtendedState(Frame.ICONIFIED); } @Override public void windowDeiconified(WindowEvent e) { thisErrorWindow.setExtendedState(Frame.NORMAL); } });*/ thisEditor.addComponentListener( new ComponentListener() { @Override public void componentShown(ComponentEvent e) {} @Override public void componentResized(ComponentEvent e) { if (Docker.isDocked()) { Docker.dock(); } else { Docker.tryDocking(); } } @Override public void componentMoved(ComponentEvent e) { if (Docker.isDocked()) { Docker.dock(); } else { Docker.tryDocking(); } } @Override public void componentHidden(ComponentEvent e) { // System.out.println("ed hidden"); } }); }
////////////// methods to create the interactive visualizer //////////////////////// private void createMainFrame() { mainFrame = new JFrame(); mainFrame.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE); Container contentPane = mainFrame.getContentPane(); // contentPane.setLayout(new BorderLayout()); // creates the control panel controlPanel = new JPanel(null); controlPanel.setLayout(new FlowLayout()); makeSoundVis(); mainFrame.addComponentListener(new ResizeHandler()); // setting up the play sound button playBtn = new JButton("Play"); playBtn.setEnabled(true); playBtn.setToolTipText("Play the sound"); playBtn.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent event) { stopBtn.setEnabled(true); pauseBtn.setEnabled(true); playBtn.setEnabled(false); playSelectionBtn.setEnabled(false); zoomInBtn.setEnabled(false); zoomOutBtn.setEnabled(false); isPlaying = true; myHelper.play(); } }); controlPanel.add(playBtn); // setting up the play selection button playSelectionBtn = new JButton("Play Selection"); playSelectionBtn.setEnabled(false); playSelectionBtn.setToolTipText("Play sound between start and stop index"); playSelectionBtn.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent event) { playSelClicked++; stopBtn.setEnabled(true); pauseBtn.setEnabled(true); playSelectionBtn.setEnabled(false); playBtn.setEnabled(false); zoomInBtn.setEnabled(false); zoomOutBtn.setEnabled(false); isPlaying = false; if (playSelClicked == 1) { myHelper.playInRange( wavePanel.getSelectionStartSample(), wavePanel.getSelectionEndSample()); } else { myHelper.play(); } } }); controlPanel.add(playSelectionBtn); // setting up the stop button stopBtn = new JButton("Stop"); stopBtn.setEnabled(false); stopBtn.setToolTipText("Stop playing the sound"); stopBtn.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent event) { myHelper.stop(); stopBtn.setEnabled(false); pauseBtn.setEnabled(false); playBtn.setEnabled(true); if (wavePanel.moreZoomInScope()) { zoomInBtn.setEnabled(true); playSelectionBtn.setEnabled(true); } if (wavePanel.moreZoomOutScope()) { zoomOutBtn.setEnabled(true); } playSelClicked = 0; isPlaying = false; } }); controlPanel.add(stopBtn); // setting up the stop button pauseBtn = new JButton("Pause"); pauseBtn.setEnabled(false); pauseBtn.setToolTipText("Pause the sound"); pauseBtn.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent event) { myHelper.pause(); if (isPlaying) { playBtn.setEnabled(true); } else { playSelectionBtn.setEnabled(true); } } }); controlPanel.add(pauseBtn); // setting up the zoom button zoomInBtn = new JButton("Zoom In"); zoomInBtn.setEnabled(false); zoomInBtn.setToolTipText("Click to see the samples within your selection"); zoomInBtn.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent event) { handleZoomIn(); } }); controlPanel.add(zoomInBtn); // setting up the zoom button zoomOutBtn = new JButton("Zoom Out"); zoomOutBtn.setEnabled(false); zoomOutBtn.setToolTipText("Click to zoom out"); zoomOutBtn.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent event) { handleZoomOut(); } }); controlPanel.add(zoomOutBtn); controlPanel.setBounds(0, controlLocY, frameWidth, controlHeight); contentPane.add(controlPanel); contentPane.add(wavePanel); contentPane.add(overViewPanel); wavePanel.setBounds(0, waveLocY, frameWidth, waveHeight); // controlPanel.removeAll(); // controlPanel.setBackground(Color.CYAN); mainFrame.setSize(frameWidth, frameHeight); overViewPanel.init(); wavePanel.init(); // // mainFrame.pack(); // mainFrame.setResizable(false); // mainFrame.validate(); mainFrame.setVisible(true); overViewPanel.setBounds(0, 0, frameWidth, overViewHeight); // mainFrame.validate(); }
public static void main() { // Main frame = new JFrame("Java Playground"); frame.setSize(640, 480); // Make sure the divider is properly resized frame.addComponentListener( new ComponentAdapter() { public void componentResized(ComponentEvent c) { splitter.setDividerLocation(.8); } }); // Make sure the JVM is reset on close frame.addWindowListener( new WindowAdapter() { public void windowClosed(WindowEvent w) { new FrameAction().kill(); } }); // Setting up the keybinding // Ctrl+k or Cmd+k -> compile bind(KeyEvent.VK_K); // Ctrl+e or Cmd+e -> console bind(KeyEvent.VK_E); // Save, New file, Open file, Print. // Currently UNUSED until I figure out how normal java files and playground files will // interface. bind(KeyEvent.VK_S); bind(KeyEvent.VK_N); bind(KeyEvent.VK_O); bind(KeyEvent.VK_P); // Binds the keys to the action defined in the FrameAction class. frame.getRootPane().getActionMap().put("console", new FrameAction()); // The main panel for typing code in. text = new JTextPane(); textScroll = new JScrollPane(text); textScroll.setBorder(null); textScroll.setPreferredSize(new Dimension(640, 480)); // Document with syntax highlighting. Currently unfinished. doc = text.getStyledDocument(); doc.addDocumentListener( new DocumentListener() { public void changedUpdate(DocumentEvent d) {} public void insertUpdate(DocumentEvent d) {} public void removeUpdate(DocumentEvent d) {} }); ((AbstractDocument) doc).setDocumentFilter(new NewLineFilter()); // The output log; a combination compiler warning/error/runtime error/output log. outputText = new JTextPane(); outputScroll = new JScrollPane(outputText); outputScroll.setBorder(null); // "Constant" for the error font error = new SimpleAttributeSet(); error.addAttribute(StyleConstants.CharacterConstants.Italic, Boolean.TRUE); error.addAttribute(StyleConstants.Foreground, Color.RED); // "Constant" for the warning message font warning = new SimpleAttributeSet(); warning.addAttribute(StyleConstants.CharacterConstants.Italic, Boolean.TRUE); warning.addAttribute(StyleConstants.Foreground, Color.PINK); // "Constant" for the debugger error font progErr = new SimpleAttributeSet(); progErr.addAttribute(StyleConstants.Foreground, Color.BLUE); // Print streams to redirect System.out and System.err. out = new TextOutputStream(outputText, null); err = new TextOutputStream(outputText, error); System.setOut(new PrintStream(out)); System.setErr(new PrintStream(err)); // Sets up the output log outputText.setEditable(false); outputScroll.setVisible(true); // File input/output setup chooser = new JFileChooser(); // Setting up miscellaneous stuff compiler = ToolProvider.getSystemJavaCompiler(); JVMrunning = false; redirectErr = null; redirectOut = null; redirectIn = null; // Sets up the splitter pane and opens the program up splitter = new JSplitPane(JSplitPane.VERTICAL_SPLIT, textScroll, outputScroll); consoleDisplayed = false; splitter.remove(outputScroll); // Initially hides terminal until it is needed splitter.setOneTouchExpandable(true); frame.add(splitter); frame.setVisible(true); // Sets the divider to the proper one, for debugging // splitter.setDividerLocation(.8); }
@Override public void run() { // TODO spravit krajsie final JFrame frame = new JFrame("ViDA"); GUI.frame = frame; frame.setLayout(null); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); graphLoader = new JFileChooser("./"); graphSaver = new JFileChooser("./"); menu = new JMenuBar(); Menu.init(); for (int i = 0; i < Menu.menuItems.length; i++) { final JMenu item = new JMenu(Menu.menuItems[i]); menu.add(item); for (int j = 0; j < Menu.allMenuItems[i].length; ++j) { if (Menu.allMenuItems[i][j].equals("--")) { item.addSeparator(); } else { final JMenuItem meno = new JMenuItem(Menu.allMenuItems[i][j]); item.add(meno); final int fi = i; final int fj = j; meno.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { Menu.performAction(fi, fj); } }); } } } popupInformation = new PopupPanel(informationPanel.scrollPanel); gkl.addMouseListener(KeyEvent.VK_I, popupInformation); popupZoomWindow = new PopupPanel(zoomWindow.canvas); layeredPane = new JLayeredPane(); frame.add(layeredPane); // layeredPane.setLayout(null); layeredPane.add(menu); layeredPane.add(player.graph.canvas); layeredPane.add(informationPanel.scrollPanel); layeredPane.add(zoomWindow.canvas); layeredPane.add(popupInformation); layeredPane.add(popupZoomWindow); frame.add(controls.panel); layeredPane.setComponentZOrder(menu, 0); layeredPane.setComponentZOrder(player.graph.canvas, 1); layeredPane.setComponentZOrder(informationPanel.scrollPanel, 0); layeredPane.setComponentZOrder(zoomWindow.canvas, 0); layeredPane.setComponentZOrder(popupInformation, 0); layeredPane.setComponentZOrder(popupZoomWindow, 0); informationPanel.scrollPanel.setVisible(false); zoomWindow.canvas.setVisible(false); KeyboardFocusManager manager = KeyboardFocusManager.getCurrentKeyboardFocusManager(); manager.addKeyEventDispatcher(gkl); frame.addWindowListener( new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { saveApp(); } }); frame.addComponentListener( new ComponentAdapter() { public void componentResized(ComponentEvent e) { refreshLayout(); } }); frame.setSize(CONST.windowWidth, CONST.windowHeight); frame.setVisible(true); int dw = frame.getWidth() - frame.getContentPane().getWidth(); int dh = frame.getHeight() - frame.getContentPane().getHeight(); System.out.println("frame " + dw + " " + dh); frame.setMinimumSize(new Dimension(CONST.minWindowWidth + dw, CONST.minWindowHeight + dh)); gRepaint(); }
public UserInterface(JFrame frame) { frame.addComponentListener(this); frame.addWindowFocusListener(this); new Thread(this).start(); }