2 * bnac : virtual museum environment creation/manipulation project
3 * Copyright (C) 2010 Felipe CaƱas Sabat
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 package cl
.uchile
.dcc
.bnac
.editor
;
21 import cl
.uchile
.dcc
.bnac
.Attribute
;
22 import cl
.uchile
.dcc
.bnac
.Capture
;
23 import cl
.uchile
.dcc
.bnac
.PlacedCapture
;
24 import cl
.uchile
.dcc
.bnac
.editor
.event
.WallListener
;
25 import cl
.uchile
.dcc
.bnac
.editor
.event
.WallEvent
;
27 import java
.awt
.event
.ActionEvent
;
28 import java
.awt
.event
.ActionListener
;
29 import java
.awt
.event
.MouseMotionListener
;
30 import java
.awt
.event
.MouseEvent
;
31 import java
.awt
.Insets
;
32 import java
.awt
.GridBagLayout
;
33 import java
.awt
.GridBagConstraints
;
35 import javax
.swing
.JButton
;
36 import javax
.swing
.JLabel
;
37 import javax
.swing
.JPanel
;
38 import javax
.swing
.JTextField
;
40 import javax
.vecmath
.Point2f
;
41 import javax
.vecmath
.Vector2f
;
43 public class PlaceCaptureDialogue
extends ProjectDialogue
44 implements WallListener
, MouseMotionListener
46 protected Capture cap
;
47 protected HallGraph hg
;
48 protected WallPickerPlot wpp
;
49 protected JLabel crds
;
51 public PlaceCaptureDialogue (Project project
, Capture cap
, HallGraph hg
)
53 super(project
, BnacEditor
.gs("PLACE_CAPTURE"));
56 wpp
= new WallPickerPlot(hg
.getHall(), 220, 220, 20, 20);
57 crds
= new JLabel("x,x");
58 crds
.setPreferredSize(new java
.awt
.Dimension(100, 25));
60 wpp
.addWallListener(this);
61 wpp
.addMouseMotionListener(this);
63 final JButton cancel
= new JButton(Util
.gs("CANCEL"));
64 cancel
.addActionListener(new ActionListener() {
65 public void actionPerformed (ActionEvent e
) {
70 GridBagLayout lo
= new GridBagLayout();
71 JPanel pan
= new JPanel(lo
);
72 GridBagConstraints c
= new GridBagConstraints();
74 c
.insets
= new Insets(2, 5, 2, 5);
75 c
.gridx
= c
.gridy
= 0;
76 c
.fill
= GridBagConstraints
.HORIZONTAL
;
78 pan
.add(new JLabel(String
.format("%s, %s",
79 cap
.getReferencedObject().get(Attribute
.Title
),
80 cap
.getReferencedObject().get(Attribute
.Author
)),
97 c
.gridx
= GridBagConstraints
.RELATIVE
;
104 public void mouseMoved (MouseEvent e
)
106 Point2f p
= wpp
.pixToCoords(e
.getX(), e
.getY());
107 crds
.setText(String
.format("%.02f, %.02f", p
.x
, p
.y
));
110 public void mouseDragged (MouseEvent e
) { }
112 public void onWallSelected (WallEvent e
)
114 float d
= e
.getWall().origin2f().distance(e
.getCoords());
115 project
.pushCommand(new PlaceCaptureCommand(
116 project
, hg
, e
.getIndex(),
117 String
.format("%s_%09d", cap
.getId(),
118 System
.currentTimeMillis()),
119 cap
, new Point2f(d
, 1.70f
)));
120 jf
.setVisible(false);
123 public void onWallOver (WallEvent e
) { }
124 public void onWallOut (WallEvent e
) { }
126 public class PlaceCaptureCommand
extends ProjectCommand
128 protected HallGraph hg
;
130 protected PortraitGraph pg
;
132 public PlaceCaptureCommand (Project project
, HallGraph hg
,
133 int widx
, String pcapid
, Capture cap
)
135 this(project
, hg
, widx
, pcapid
, cap
, new Point2f(0.0f
, 1.50f
));
138 public PlaceCaptureCommand (Project project
, HallGraph hg
,
139 int widx
, String pcapid
, Capture cap
, Point2f pos
)
141 super(project
, "PLACE_CAPTURE");
145 new PlacedCapture(pcapid
, cap
, pos
, 0.0f
, 1.0f
);
146 pg
= new PortraitGraph(project
, pcap
);
149 public void execute ()
151 hg
.addPortraitGraph(widx
, pg
);
156 hg
.getWallGraph(widx
).removePortraitGraph(pg
.getId());