/** * Full constructor. * * @param owner the dialog owner * @param world the current world */ public EditWorldDialog(Window owner, World world) { super(owner, Messages.getString("dialog.world.edit.title"), ModalityType.APPLICATION_MODAL); this.setIconImage(Icons.EDIT_WORLD.getImage()); this.pnlWorld = new WorldPanel(world); this.pnlWorld.setBorder(BorderFactory.createEmptyBorder(5, 5, 10, 5)); JButton btnCancel = new JButton(Messages.getString("button.cancel")); JButton btnApply = new JButton(Messages.getString("button.apply")); btnCancel.setActionCommand("cancel"); btnApply.setActionCommand("apply"); btnCancel.addActionListener(this); btnApply.addActionListener(this); JPanel pnlButtons = new BottomButtonPanel(); pnlButtons.setLayout(new FlowLayout(FlowLayout.LEFT)); pnlButtons.add(btnCancel); pnlButtons.add(btnApply); Container container = this.getContentPane(); container.setLayout(new BorderLayout()); container.add(this.pnlWorld, BorderLayout.CENTER); container.add(pnlButtons, BorderLayout.PAGE_END); this.pack(); }
/** * Returns a new Color object given the color components in the given array. * * @param color the color components in RGB or RGBA * @return Color */ public static final Color convertColor(float[] color) { if (color.length == 3) { return new Color(color[0], color[1], color[2]); } else if (color.length == 4) { return new Color(color[0], color[1], color[2], color[3]); } else { throw new IllegalArgumentException(Messages.getString("exception.color.notEnoughComponents")); } }
/** * Panel used to create a fixture from a point cloud. * * @author William Bittle * @version 1.0.1 * @since 1.0.0 */ public class ConvexHullPolygonPanel extends ConvexHullShapePanel implements InputPanel { /** The version id */ private static final long serialVersionUID = -9180521501510030534L; /** The gift wrap algorithm item */ private static final ComboItem GIFT_WRAP = new ComboItem(Messages.getString("panel.hull.algorithm.giftWrap"), new GiftWrap()); /** The graham scan algorithm item */ private static final ComboItem GRAHAM_SCAN = new ComboItem(Messages.getString("panel.hull.algorithm.grahamScan"), new GrahamScan()); /** The monotone chain algorithm item */ private static final ComboItem MONOTONE_CHAIN = new ComboItem(Messages.getString("panel.hull.algorithm.monotoneChain"), new MonotoneChain()); /** The divide and conquer algorithm item */ private static final ComboItem DIVIDE_AND_CONQUER = new ComboItem( Messages.getString("panel.hull.algorithm.divideAndConquer"), new DivideAndConquer()); /** The array of algorithms */ private static final ComboItem[] ITEMS = new ComboItem[] {DIVIDE_AND_CONQUER, GIFT_WRAP, GRAHAM_SCAN, MONOTONE_CHAIN}; /** The default convex hull algorithm */ private static final ComboItem DEFAULT_ALGORITHM = GIFT_WRAP; // polygon panels /** The arbitrary polygon panel */ private ArbitraryConvexHullPolygonPanel pnlArbitraryPolygon; /** The from file polygon panel */ private FromFileConvexHullPolygonPanel pnlFromFilePolygon; // polygon radio buttons /** The arbitrary polygon radio button */ private JRadioButton rdoArbitrary; /** The from file polygon radio button */ private JRadioButton rdoFromFile; // decomposition algorithms /** The algorithm combo box */ private JComboBox cmbAlgorithms; /** The panel to show/hide sources */ private JPanel pnlSource; /** Default constructor. */ public ConvexHullPolygonPanel() { JLabel lblAlgorithm = new JLabel(Messages.getString("panel.hull.algorithm"), Icons.INFO, JLabel.LEFT); lblAlgorithm.setToolTipText(Messages.getString("panel.hull.algorithm.tooltip")); JLabel lblSource = new JLabel(Messages.getString("panel.hull.source"), Icons.INFO, JLabel.LEFT); lblSource.setToolTipText(Messages.getString("panel.hull.source.tooltip")); this.cmbAlgorithms = new JComboBox(ITEMS); this.cmbAlgorithms.setSelectedItem(DEFAULT_ALGORITHM); this.cmbAlgorithms.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent event) { ComboItem item = (ComboItem) cmbAlgorithms.getSelectedItem(); HullGenerator hullGenerator = (HullGenerator) item.getValue(); pnlArbitraryPolygon.setHullGenerator(hullGenerator); pnlFromFilePolygon.setHullGenerator(hullGenerator); } }); HullGenerator hullGenerator = (HullGenerator) DEFAULT_ALGORITHM.getValue(); this.pnlArbitraryPolygon = new ArbitraryConvexHullPolygonPanel(hullGenerator); this.pnlFromFilePolygon = new FromFileConvexHullPolygonPanel(hullGenerator); this.rdoArbitrary = new JRadioButton(Messages.getString("panel.hull.source.cloud")); this.rdoFromFile = new JRadioButton(Messages.getString("panel.hull.source.file")); // set arbitrary as the current one this.rdoArbitrary.setSelected(true); this.rdoArbitrary.addChangeListener( new ChangeListener() { @Override public void stateChanged(ChangeEvent event) { JRadioButton radio = (JRadioButton) event.getSource(); CardLayout cl = (CardLayout) pnlSource.getLayout(); if (radio.isSelected()) { cl.show(pnlSource, "arbitrary"); } else { cl.show(pnlSource, "fromFile"); } } }); ButtonGroup bg = new ButtonGroup(); bg.add(this.rdoFromFile); bg.add(this.rdoArbitrary); this.pnlSource = new JPanel(); this.pnlSource.setLayout(new CardLayout()); this.pnlSource.add(this.pnlArbitraryPolygon, "arbitrary"); this.pnlSource.add(this.pnlFromFilePolygon, "fromFile"); GroupLayout layout = new GroupLayout(this); this.setLayout(layout); layout.setAutoCreateContainerGaps(true); layout.setAutoCreateGaps(true); layout.setHonorsVisibility(true); layout.setHorizontalGroup( layout .createParallelGroup() .addGroup( layout .createSequentialGroup() .addGroup( layout .createParallelGroup() .addComponent(lblAlgorithm) .addComponent(lblSource)) .addGroup( layout .createParallelGroup() .addComponent(this.cmbAlgorithms) .addGroup( layout .createSequentialGroup() .addComponent(this.rdoFromFile) .addComponent(this.rdoArbitrary)))) .addComponent(this.pnlSource)); layout.setVerticalGroup( layout .createSequentialGroup() .addGroup( layout .createParallelGroup(GroupLayout.Alignment.CENTER) .addComponent(lblAlgorithm) .addComponent( this.cmbAlgorithms, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)) .addGroup( layout .createParallelGroup(GroupLayout.Alignment.CENTER) .addComponent(lblSource) .addComponent( this.rdoFromFile, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) .addComponent( this.rdoArbitrary, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)) .addComponent(this.pnlSource)); } /* (non-Javadoc) * @see org.dyn4j.sandbox.panels.ConvexShapePanel#getShape() */ @Override public Convex getShape() { // return the polygon for the selected radio button if (this.rdoArbitrary.isSelected()) { return this.pnlArbitraryPolygon.getShape(); } else if (this.rdoFromFile.isSelected()) { return this.pnlFromFilePolygon.getShape(); } return null; } /* (non-Javadoc) * @see org.dyn4j.sandbox.panels.InputPanel#isValidInput() */ @Override public boolean isValidInput() { // return the polygon for the selected radio button if (this.rdoArbitrary.isSelected()) { return this.pnlArbitraryPolygon.isValidInput(); } else if (this.rdoFromFile.isSelected()) { return this.pnlFromFilePolygon.isValidInput(); } return false; } /* (non-Javadoc) * @see org.dyn4j.sandbox.panels.InputPanel#showInvalidInputMessage(java.awt.Window) */ @Override public void showInvalidInputMessage(Window owner) { // return the polygon for the selected radio button if (this.rdoArbitrary.isSelected()) { this.pnlArbitraryPolygon.showInvalidInputMessage(owner); } else if (this.rdoFromFile.isSelected()) { this.pnlFromFilePolygon.showInvalidInputMessage(owner); } } }
/** Default constructor. */ public ConvexHullPolygonPanel() { JLabel lblAlgorithm = new JLabel(Messages.getString("panel.hull.algorithm"), Icons.INFO, JLabel.LEFT); lblAlgorithm.setToolTipText(Messages.getString("panel.hull.algorithm.tooltip")); JLabel lblSource = new JLabel(Messages.getString("panel.hull.source"), Icons.INFO, JLabel.LEFT); lblSource.setToolTipText(Messages.getString("panel.hull.source.tooltip")); this.cmbAlgorithms = new JComboBox(ITEMS); this.cmbAlgorithms.setSelectedItem(DEFAULT_ALGORITHM); this.cmbAlgorithms.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent event) { ComboItem item = (ComboItem) cmbAlgorithms.getSelectedItem(); HullGenerator hullGenerator = (HullGenerator) item.getValue(); pnlArbitraryPolygon.setHullGenerator(hullGenerator); pnlFromFilePolygon.setHullGenerator(hullGenerator); } }); HullGenerator hullGenerator = (HullGenerator) DEFAULT_ALGORITHM.getValue(); this.pnlArbitraryPolygon = new ArbitraryConvexHullPolygonPanel(hullGenerator); this.pnlFromFilePolygon = new FromFileConvexHullPolygonPanel(hullGenerator); this.rdoArbitrary = new JRadioButton(Messages.getString("panel.hull.source.cloud")); this.rdoFromFile = new JRadioButton(Messages.getString("panel.hull.source.file")); // set arbitrary as the current one this.rdoArbitrary.setSelected(true); this.rdoArbitrary.addChangeListener( new ChangeListener() { @Override public void stateChanged(ChangeEvent event) { JRadioButton radio = (JRadioButton) event.getSource(); CardLayout cl = (CardLayout) pnlSource.getLayout(); if (radio.isSelected()) { cl.show(pnlSource, "arbitrary"); } else { cl.show(pnlSource, "fromFile"); } } }); ButtonGroup bg = new ButtonGroup(); bg.add(this.rdoFromFile); bg.add(this.rdoArbitrary); this.pnlSource = new JPanel(); this.pnlSource.setLayout(new CardLayout()); this.pnlSource.add(this.pnlArbitraryPolygon, "arbitrary"); this.pnlSource.add(this.pnlFromFilePolygon, "fromFile"); GroupLayout layout = new GroupLayout(this); this.setLayout(layout); layout.setAutoCreateContainerGaps(true); layout.setAutoCreateGaps(true); layout.setHonorsVisibility(true); layout.setHorizontalGroup( layout .createParallelGroup() .addGroup( layout .createSequentialGroup() .addGroup( layout .createParallelGroup() .addComponent(lblAlgorithm) .addComponent(lblSource)) .addGroup( layout .createParallelGroup() .addComponent(this.cmbAlgorithms) .addGroup( layout .createSequentialGroup() .addComponent(this.rdoFromFile) .addComponent(this.rdoArbitrary)))) .addComponent(this.pnlSource)); layout.setVerticalGroup( layout .createSequentialGroup() .addGroup( layout .createParallelGroup(GroupLayout.Alignment.CENTER) .addComponent(lblAlgorithm) .addComponent( this.cmbAlgorithms, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)) .addGroup( layout .createParallelGroup(GroupLayout.Alignment.CENTER) .addComponent(lblSource) .addComponent( this.rdoFromFile, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) .addComponent( this.rdoArbitrary, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)) .addComponent(this.pnlSource)); }