/** * ************************************************************ constructor * ************************************************************* */ public WorldPathDetailEditor( final WorldPath _myPath, final PlainChart theChart, final PropertiesPanel thePanel, final ToolParent theParent, final String myType) { _myType = myType; setObject(_myPath, theChart, null, thePanel); this._theParent = theParent; _editor.setChart(theChart); }
/** an item has been selected, edit it */ void editThis(final Object val) { _editor.setValue(val); }
/** create the form */ private void createForm() { // create the panel setName(getMyType() + " editor"); // create the information message String msg = "1. Use the buttons to the right to add/remove and re-order the points in the " + getMyType() + ".\r\n"; msg += " 2. Use the Drag button to switch on and off dragging of " + getMyType() + " points.\r\n"; msg += " 3. Select a point from the list below to edit it in Point Editor (below).\r\n"; msg += " 4. Use Reset to return to the original " + getMyType() + ".\r\n"; msg += " 5. Finally use Apply then Close to update the shape.\r\n"; // create the information panel final JTextArea info = new JTextArea(); info.setBackground(this.getBackground()); info.setLineWrap(true); info.setWrapStyleWord(true); info.setText(msg); // make the text a little smaller final Font infoFont = info.getFont(); info.setFont(infoFont.deriveFont((float) 10.0)); // create the top panel (with the new, up, down button) final JPanel infoPanel = new JPanel(); infoPanel.setLayout(new BorderLayout()); final JPanel btnBar = new JPanel(); btnBar.setLayout(new GridLayout(2, 0)); infoPanel.add("East", btnBar); infoPanel.add("Center", info); // and the new, up, down buttons final JButton upBtn = createButton("Move current point up", "images/Up.gif", "Up"); upBtn.addActionListener( new ActionListener() { public void actionPerformed(final ActionEvent e) { doUpDown(true); } }); final JButton downBtn = createButton("Move current point down", "images/Down.gif", "Down"); downBtn.addActionListener( new ActionListener() { public void actionPerformed(final ActionEvent e) { doUpDown(false); } }); final JButton newBtn = createButton("Add new point", "images/NewPin.gif", "New"); newBtn.addActionListener( new ActionListener() { public void actionPerformed(final ActionEvent e) { addNew(); } }); final JButton deleteBtn = createButton("Delete current point", "images/DeletePin.gif", "Delete"); deleteBtn.addActionListener( new ActionListener() { public void actionPerformed(final ActionEvent e) { deleteCurrent(); } }); btnBar.add(upBtn); btnBar.add(downBtn); btnBar.add(newBtn); btnBar.add(deleteBtn); // create the list _myList = new JList(); _myList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); _myList.setBorder(new javax.swing.border.EtchedBorder()); _myList.addListSelectionListener( new ListSelectionListener() { public void valueChanged(final ListSelectionEvent e) { if (!e.getValueIsAdjusting()) { if (!_myList.isSelectionEmpty()) { final WorldLocation loc = (WorldLocation) _myList.getSelectedValue(); if (loc != null) editThis(_myList.getSelectedValue()); } } } }); // show the list final JPanel listHolder = new JPanel(); listHolder.setLayout(new BorderLayout()); _dragger = new DragButton(getChart(), _theParent); listHolder.add("North", _dragger); listHolder.add("Center", _myList); // create the sub-form _subPanel = new JPanel(); _subPanel.setBorder(javax.swing.BorderFactory.createTitledBorder("Point Editor")); _subPanel.setName("Point editor"); _subPanel.setLayout(new BorderLayout()); _subPanel.add("Center", _editor.getCustomEditor()); final JButton subApply = new JButton("Apply"); subApply.setToolTipText("Apply the changes to our " + getMyType()); subApply.addActionListener( new ActionListener() { public void actionPerformed(final ActionEvent e) { final WorldLocation curLoc = (WorldLocation) _myList.getSelectedValue(); if (curLoc != null) { curLoc.copy((WorldLocation) _editor.getValue()); _myList.repaint(); // also update the point in the path final int index = _myList.getSelectedIndex(); getPath().getLocationAt(index).copy(curLoc); // update the plot getChart().getLayers().fireReformatted(null); } } }); // create the bottom toolbar final JButton closeBtn = new JButton("Close"); closeBtn.setToolTipText("Close this panel"); closeBtn.addActionListener( new ActionListener() { public void actionPerformed(final ActionEvent e) { doClose(); } }); // now the reset button final JButton resetBtn = new JButton("Reset"); resetBtn.setToolTipText("Reset the data"); resetBtn.addActionListener( new ActionListener() { public void actionPerformed(final ActionEvent e) { doReset(); } }); final JPanel buttonHolder = new JPanel(); buttonHolder.setLayout(new GridLayout(1, 0)); buttonHolder.add(closeBtn); buttonHolder.add(subApply); buttonHolder.add(resetBtn); final JPanel bottomHolder = new JPanel(); bottomHolder.setLayout(new BorderLayout()); bottomHolder.add("Center", _subPanel); bottomHolder.add("South", buttonHolder); // put them into the form setLayout(new BorderLayout()); add("North", infoPanel); add("Center", listHolder); add("South", bottomHolder); }