List of usage examples for javax.swing.text AbstractDocument addDocumentListener
public void addDocumentListener(DocumentListener listener)
From source file:se.llbit.chunky.renderer.ui.RenderControls.java
private void buildUI() { setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE); setModalityType(ModalityType.MODELESS); if (!ShutdownAlert.canShutdown()) { // disable the computer shutdown checkbox if we can't shutdown shutdownWhenDoneCB.setEnabled(false); }// w w w . j a v a2s . c o m addWindowListener(new WindowListener() { @Override public void windowOpened(WindowEvent e) { } @Override public void windowIconified(WindowEvent e) { } @Override public void windowDeiconified(WindowEvent e) { } @Override public void windowDeactivated(WindowEvent e) { } @Override public void windowClosing(WindowEvent e) { sceneMan.interrupt(); RenderControls.this.dispose(); } @Override public void windowClosed(WindowEvent e) { // halt rendering renderMan.interrupt(); // dispose of the 3D view view.setVisible(false); view.dispose(); } @Override public void windowActivated(WindowEvent e) { } }); updateTitle(); addTab("General", Icon.wrench, buildGeneralPane()); addTab("Lighting", Icon.light, buildLightingPane()); addTab("Sky", Icon.sky, buildSkyPane()); addTab("Water", Icon.water, buildWaterPane()); addTab("Camera", Icon.camera, buildCameraPane()); addTab("Post-processing", Icon.gear, buildPostProcessingPane()); addTab("Advanced", Icon.advanced, buildAdvancedPane()); addTab("Help", Icon.question, buildHelpPane()); JLabel sppTargetLbl = new JLabel("SPP Target: "); sppTargetLbl.setToolTipText("The render will be paused at this SPP count"); JButton setDefaultBtn = new JButton("Make Default"); setDefaultBtn.setToolTipText("Make the current SPP target the default"); setDefaultBtn.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { PersistentSettings.setSppTargetDefault(renderMan.scene().getTargetSPP()); } }); targetSPP.update(); JLabel renderLbl = new JLabel("Render: "); setViewVisible(false); showPreviewBtn.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (view.isViewVisible()) { view.hideView(); } else { showPreviewWindow(); } } }); startRenderBtn.setText("START"); startRenderBtn.setIcon(Icon.play.imageIcon()); startRenderBtn.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { switch (renderMan.scene().getRenderState()) { case PAUSED: renderMan.scene().resumeRender(); break; case PREVIEW: renderMan.scene().startRender(); break; case RENDERING: renderMan.scene().pauseRender(); break; } stopRenderBtn.setEnabled(true); } }); stopRenderBtn.setText("RESET"); stopRenderBtn.setIcon(Icon.stop.imageIcon()); stopRenderBtn.setToolTipText("<html>Warning: this will discard the " + "current rendered image!<br>Make sure to save your image " + "before stopping the renderer!"); stopRenderBtn.setEnabled(false); stopRenderBtn.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { renderMan.scene().haltRender(); } }); saveFrameBtn.setText("Save Current Frame"); saveFrameBtn.addActionListener(saveFrameListener); sppLbl.setToolTipText("SPP = Samples Per Pixel, SPS = Samples Per Second"); setRenderTime(0); setSamplesPerSecond(0); setSPP(0); setProgress("Progress:", 0, 0, 1); progressLbl.setText("Progress:"); etaLbl.setText("ETA:"); sceneNameLbl.setText("Scene name: "); sceneNameField.setColumns(15); AbstractDocument document = (AbstractDocument) sceneNameField.getDocument(); document.setDocumentFilter(new SceneNameFilter()); document.addDocumentListener(sceneNameListener); sceneNameField.addActionListener(sceneNameActionListener); updateSceneNameField(); saveSceneBtn.setText("Save"); saveSceneBtn.setIcon(Icon.disk.imageIcon()); saveSceneBtn.addActionListener(saveSceneListener); JPanel panel = new JPanel(); GroupLayout layout = new GroupLayout(panel); panel.setLayout(layout); layout.setHorizontalGroup(layout.createSequentialGroup().addContainerGap().addGroup(layout .createParallelGroup() .addGroup(layout.createSequentialGroup().addComponent(sceneNameLbl).addComponent(sceneNameField) .addPreferredGap(ComponentPlacement.RELATED).addComponent(saveSceneBtn)) .addComponent(tabbedPane) .addGroup(layout.createSequentialGroup().addGroup(targetSPP.horizontalGroup(layout)) .addPreferredGap(ComponentPlacement.RELATED).addComponent(setDefaultBtn)) .addGroup(layout.createSequentialGroup().addComponent(renderLbl) .addPreferredGap(ComponentPlacement.UNRELATED).addComponent(startRenderBtn) .addPreferredGap(ComponentPlacement.UNRELATED).addComponent(stopRenderBtn)) .addGroup( layout.createSequentialGroup().addComponent(saveFrameBtn) .addPreferredGap(ComponentPlacement.UNRELATED, GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE) .addComponent(showPreviewBtn)) .addGroup( layout.createSequentialGroup().addComponent(renderTimeLbl) .addPreferredGap(ComponentPlacement.UNRELATED, GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE) .addComponent(sppLbl)) .addGroup( layout.createSequentialGroup().addComponent(progressLbl) .addPreferredGap(ComponentPlacement.UNRELATED, GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE) .addComponent(etaLbl)) .addComponent(progressBar)).addContainerGap()); layout.setVerticalGroup( layout.createSequentialGroup().addContainerGap() .addGroup(layout.createParallelGroup(Alignment.BASELINE).addComponent(sceneNameLbl) .addComponent(sceneNameField).addComponent(saveSceneBtn)) .addPreferredGap(ComponentPlacement.UNRELATED).addComponent(tabbedPane) .addPreferredGap(ComponentPlacement.UNRELATED) .addGroup(layout.createParallelGroup(Alignment.BASELINE) .addGroup(targetSPP.verticalGroup(layout)).addComponent(setDefaultBtn)) .addPreferredGap(ComponentPlacement.UNRELATED) .addGroup(layout.createParallelGroup(Alignment.BASELINE).addComponent(renderLbl) .addComponent(startRenderBtn).addComponent(stopRenderBtn)) .addPreferredGap(ComponentPlacement.UNRELATED) .addGroup(layout.createParallelGroup().addComponent(saveFrameBtn) .addComponent(showPreviewBtn)) .addPreferredGap(ComponentPlacement.UNRELATED) .addGroup(layout.createParallelGroup().addComponent(renderTimeLbl).addComponent(sppLbl)) .addPreferredGap(ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup().addComponent(progressLbl).addComponent(etaLbl)) .addComponent(progressBar).addContainerGap()); final JScrollPane scrollPane = new JScrollPane(panel, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); setContentPane(scrollPane); scrollPane.getViewport().addChangeListener(new ChangeListener() { private boolean resized = false; @Override public void stateChanged(ChangeEvent e) { if (!resized && scrollPane.getVerticalScrollBar().isVisible()) { Dimension vsbPrefSize = new JScrollPane().getVerticalScrollBar().getPreferredSize(); Dimension size = getSize(); setSize(size.width + vsbPrefSize.width, size.height); resized = true; } } }); pack(); setLocationRelativeTo(chunky.getFrame()); setVisible(true); }