Changeset 36183 in osm for applications
- Timestamp:
- 2023-10-26T22:28:32+02:00 (14 months ago)
- Location:
- applications/editors/josm/plugins/OpeningHoursEditor
- Files:
-
- 1 added
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/OpeningHoursEditor/build.xml
r35378 r36183 16 16 <import file="../build-common.xml"/> 17 17 18 18 <property name="parser.dir" location="${plugin.src.dir}/org/openstreetmap/josm/plugins/ohe/parser"/> 19 19 20 <target name="javacc" depends=" init" unless="javacc.notRequired">20 <target name="javacc" depends="resolve-tools" unless="javacc.notRequired"> 21 21 <ivy:cachepath file="${core.tools.ivy}" pathid="javacc.classpath" conf="javacc"/> 22 22 <java classname="javacc" fork="true" failonerror="true"> … … 30 30 </target> 31 31 32 <!-- 33 ********************************************************** 34 ** compile - compiles the source tree 35 ********************************************************** 36 --> 37 <target name="compile" depends="init, javacc"> 38 <echo message="compiling sources for ${plugin.jar} ... "/> 39 <javac srcdir="src" debug="true" destdir="${plugin.build.dir}" includeAntRuntime="false" encoding="UTF-8"> 40 <classpath> 41 <pathelement path="${plugin.build.dir}"/> 42 <pathelement location="${josm}"/> 43 </classpath> 44 <compilerarg value="-Xlint:deprecation"/> 45 <compilerarg value="-Xlint:unchecked"/> 46 </javac> 32 <target name="pre-compile" depends="javacc"> 33 <!-- ensure that we build the javacc classes --> 47 34 </target> 48 35 -
applications/editors/josm/plugins/OpeningHoursEditor/src/org/openstreetmap/josm/plugins/ohe/ClockSystem.java
r34535 r36183 29 29 try { 30 30 midnight = localeFormat.format(stdFormat.parse("12:00 AM")); 31 } catch (ParseException ignore) {32 Logging.trace( ignore);31 } catch (ParseException parseException) { 32 Logging.trace(parseException); 33 33 } 34 34 if (midnight.contains("12")) -
applications/editors/josm/plugins/OpeningHoursEditor/src/org/openstreetmap/josm/plugins/ohe/OhePlugin.java
r36078 r36183 7 7 import java.awt.Component; 8 8 import java.awt.Font; 9 import java.awt.GridBagConstraints; 9 10 import java.awt.GridBagLayout; 10 11 import java.awt.event.ActionEvent; … … 32 33 import javax.swing.JTable; 33 34 import javax.swing.ListSelectionModel; 35 import javax.swing.ScrollPaneConstants; 34 36 import javax.swing.table.DefaultTableCellRenderer; 35 37 import javax.swing.table.DefaultTableModel; … … 61 63 * {key, value, key-to-edit} key and value can contain regular expressions 62 64 */ 63 private final String[][] TAG_EDIT_STRINGS = new String[][] {65 private static final String[][] TAG_EDIT_STRINGS = new String[][] { 64 66 {"opening_hours", ".*", "opening_hours"}, 65 67 {"opening_hours:kitchen", ".*", "opening_hours:kitchen"}, … … 195 197 // showing the tags in a dialog 196 198 propertyTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); 197 JScrollPane sp = new JScrollPane( JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,198 JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);199 JScrollPane sp = new JScrollPane(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, 200 ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); 199 201 sp.setViewportView(propertyTable); 200 202 … … 269 271 270 272 JPanel dlgPanel = new JPanel(new GridBagLayout()); 271 dlgPanel.add(editButton, GBC.std().anchor(G BC.WEST));272 dlgPanel.add(sp, GBC.eol().fill(G BC.BOTH));273 dlgPanel.add(newButton, GBC.std().anchor(G BC.WEST));274 dlgPanel.add(newTagField, GBC.eol().fill(G BC.HORIZONTAL));275 dlgPanel.add(useTwelveHourClock, GBC.eol().fill(G BC.HORIZONTAL).insets(0, 5, 0, 5));273 dlgPanel.add(editButton, GBC.std().anchor(GridBagConstraints.WEST)); 274 dlgPanel.add(sp, GBC.eol().fill(GridBagConstraints.BOTH)); 275 dlgPanel.add(newButton, GBC.std().anchor(GridBagConstraints.WEST)); 276 dlgPanel.add(newTagField, GBC.eol().fill(GridBagConstraints.HORIZONTAL)); 277 dlgPanel.add(useTwelveHourClock, GBC.eol().fill(GridBagConstraints.HORIZONTAL).insets(0, 5, 0, 5)); 276 278 277 279 JOptionPane optionPane = new JOptionPane(dlgPanel, JOptionPane.QUESTION_MESSAGE, … … 286 288 Object valuesToEdit = ""; 287 289 if (answer != null && answer != JOptionPane.UNINITIALIZED_VALUE 288 && (answer instanceof Integer && (Integer) answer == JOptionPane.OK_OPTION)) 290 && (answer instanceof Integer && (Integer) answer == JOptionPane.OK_OPTION)) { 289 291 if (editButton.isSelected() && propertyTable.getSelectedRow() != -1) { 290 292 keyToEdit = (String) propertyData.getValueAt(propertyTable.getSelectedRow(), 0); … … 293 295 keyToEdit = newTagField.getSelectedItem().toString(); 294 296 } 297 } 295 298 if (keyToEdit == null) 296 299 return; … … 300 303 : ClockSystem.TWENTYFOUR_HOURS).toString()); 301 304 302 OheDialogPanel panel = new OheDialogPanel( OhePlugin.this,keyToEdit, valuesToEdit,305 OheDialogPanel panel = new OheDialogPanel(keyToEdit, valuesToEdit, 303 306 useTwelveHourClock.isSelected() ? ClockSystem.TWELVE_HOURS : ClockSystem.TWENTYFOUR_HOURS); 304 307 … … 320 323 String value = changedKeyValuePair[2].trim(); 321 324 322 if ( value.equals("")) {325 if ("".equals(value)) { 323 326 value = null; // delete the key 324 327 } 325 if ( newkey.equals("")) {328 if ("".equals(newkey)) { 326 329 newkey = key; 327 330 value = null; // delete the key instead -
applications/editors/josm/plugins/OpeningHoursEditor/src/org/openstreetmap/josm/plugins/ohe/OpeningTimeUtils.java
r32583 r36183 3 3 4 4 import java.util.ArrayList; 5 import java.util.List; 5 6 6 7 import org.openstreetmap.josm.plugins.ohe.gui.TimeRect; … … 19 20 * Implements the subtraction of daytimes in spans of days when a day in the list occurs direct afterwards 20 21 */ 21 public static ArrayList<int[]> convert(ArrayList<DateTime> dateTimes) {22 public static List<int[]> convert(List<DateTime> dateTimes) { 22 23 ArrayList<int[]> ret = new ArrayList<>(); // the list which is 23 24 // returned … … 29 30 if (dateTime.daySpans.size() == 1 && dateTime.daySpans.get(0).isSpan()) { 30 31 ArrayList<DaySpan> partDaySpans = new ArrayList<>(); 31 int start _day = dateTime.daySpans.get(0).startDay;32 int startDay = dateTime.daySpans.get(0).startDay; 32 33 33 34 // look in every entry behind 34 35 while (i + 1 < dateTimes.size()) { 35 ArrayList<DaySpan> following = dateTimes.get(i + 1).daySpans;36 List<DaySpan> following = dateTimes.get(i + 1).daySpans; 36 37 if (following.size() == 1 && following.get(0).startDay > dateTime.daySpans.get(0).startDay 37 38 && following.get(0).endDay < dateTime.daySpans.get(0).endDay) { 38 partDaySpans.add(new DaySpan(start _day, following.get(0).startDay - 1));39 start _day = following.get(0).endDay + 1;39 partDaySpans.add(new DaySpan(startDay, following.get(0).startDay - 1)); 40 startDay = following.get(0).endDay + 1; 40 41 newDateTimes.add(dateTimes.get(i + 1)); 41 42 i++; … … 45 46 } 46 47 47 partDaySpans.add(new DaySpan(start _day, dateTime.daySpans.get(0).endDay));48 partDaySpans.add(new DaySpan(startDay, dateTime.daySpans.get(0).endDay)); 48 49 newDateTimes.add(new DateTime(partDaySpans, dateTime.daytimeSpans)); 49 50 } … … 53 54 54 55 // create the int-array 55 for (int j = 0; j < newDateTimes.size(); ++j) { 56 DateTime dateTime2 = newDateTimes.get(j); 56 for (DateTime dateTime2 : newDateTimes) { 57 57 for (DaySpan dayspan : dateTime2.daySpans) { 58 58 for (DaytimeSpan timespan : dateTime2.daytimeSpans) { 59 59 if (!timespan.isOff()) { 60 ret.add(new int[] 61 timespan.endMinute 60 ret.add(new int[]{dayspan.startDay, dayspan.endDay, timespan.startMinute, 61 timespan.endMinute}); 62 62 } 63 63 } … … 68 68 } 69 69 70 /** 71 * The span of days 72 */ 70 73 public static class DaySpan { 71 public int startDay; 72 public int endDay; 73 74 /** The start day */ 75 public final int startDay; 76 /** The end day */ 77 public final int endDay; 78 79 /** 80 * Create a new day span 81 * @param startDay The weekday start 82 * @param endDay The weekday end 83 */ 74 84 public DaySpan(int startDay, int endDay) { 75 85 this.startDay = startDay; … … 86 96 } 87 97 98 /** 99 * A span of time within a day 100 */ 88 101 public static class DaytimeSpan { 89 public int startMinute; 90 public int endMinute; 91 102 /** The start minute of the time span */ 103 public final int startMinute; 104 /** The end minute of the time span */ 105 public final int endMinute; 106 107 /** 108 * Create a new time span 109 * @param startMinute The start minute 110 * @param endMinute The end minute 111 */ 92 112 public DaytimeSpan(int startMinute, int endMinute) { 93 113 this.startMinute = startMinute; … … 104 124 } 105 125 126 /** 127 * A collection of days and time spans 128 */ 106 129 public static class DateTime { 107 public ArrayList<DaySpan> daySpans; 108 public ArrayList<DaytimeSpan> daytimeSpans; 109 110 public DateTime(ArrayList<DaySpan> daySpans, ArrayList<DaytimeSpan> daytimeSpans) { 130 /** The weekday spans */ 131 public final List<DaySpan> daySpans; 132 /** The time spans */ 133 public final List<DaytimeSpan> daytimeSpans; 134 135 /** 136 * Create a new collection of time spans 137 * @param daySpans The weekday spans 138 * @param daytimeSpans The times for the weekday spans 139 */ 140 public DateTime(List<DaySpan> daySpans, List<DaytimeSpan> daytimeSpans) { 111 141 this.daySpans = daySpans; 112 142 this.daytimeSpans = daytimeSpans; … … 117 147 * Returns a String (e.g "Mo-Sa 10:00-20:00; Tu off") representing the TimeRects 118 148 */ 119 public static String makeStringFromRects( ArrayList<TimeRect> givenTimeRects) {149 public static String makeStringFromRects(List<TimeRect> givenTimeRects) { 120 150 // create an array of booleans representing every minute on all the days in a week 121 151 boolean[][] minuteArray = new boolean[7][24 * 60 + 2]; … … 133 163 } 134 164 135 String ret = "";165 StringBuilder ret = new StringBuilder(); 136 166 int[] days = new int[7]; // an array representing the status of the days 137 167 // 0 means nothing done with this day yet … … 179 209 180 210 if (!add.isEmpty()) { 181 if ( !ret.isEmpty()) {182 ret += "; ";183 } 184 ret += add;185 } 186 } 187 return ret ;211 if (ret.length() != 0) { 212 ret.append("; "); 213 } 214 ret.append(add); 215 } 216 } 217 return ret.toString(); 188 218 } 189 219 … … 192 222 */ 193 223 private static String makeStringFromMinuteArray(boolean[] minutes) { 194 String ret = "";224 StringBuilder ret = new StringBuilder(); 195 225 for (int i = 0; i < minutes.length; ++i) { 196 226 if (minutes[i]) { … … 205 235 addString += "-" + timeString(i - 1); 206 236 } 207 if (!ret.isEmpty()) { 208 ret += ","; 209 } 210 ret += addString; 211 } 212 } 213 return ret; 214 } 215 237 if (ret.length() != 0) { 238 ret.append(','); 239 } 240 ret.append(addString); 241 } 242 } 243 return ret.toString(); 244 } 245 246 /** 247 * Convert minutes to a string 248 * @param minutes integer in range from 0 and 24*60 inclusive 249 * @return a formatted string of the time (for example "01:45 PM" or "13:45") 250 */ 216 251 public static String timeString(int minutes) { 217 252 return timeString(minutes, ClockSystem.TWENTYFOUR_HOURS); 218 253 } 219 254 255 /** 256 * Convert minutes to a string 257 * @param minutes integer in range from 0 and 24*60 inclusive 258 * @param hourMode 12 or 24 hour clock 259 * @return a formatted string of the time (for example "01:45 PM" or "13:45") 260 */ 220 261 public static String timeString(int minutes, ClockSystem hourMode) { 221 262 return timeString(minutes, hourMode, false); … … 223 264 224 265 /** 225 * 266 * Convert minutes to a string 226 267 * @param minutes integer in range from 0 and 24*60 inclusive 227 268 * @param hourMode 12 or 24 hour clock … … 250 291 251 292 private static boolean isArrayEmpty(boolean[] bs) { 252 for ( int i = 0; i < bs.length; i++) {253 if (b s[i])293 for (boolean b : bs) { 294 if (b) 254 295 return false; 255 296 } -
applications/editors/josm/plugins/OpeningHoursEditor/src/org/openstreetmap/josm/plugins/ohe/gui/OheDialogPanel.java
r34535 r36183 5 5 6 6 import java.awt.Dimension; 7 import java.awt.GridBagConstraints; 7 8 import java.awt.GridBagLayout; 8 import java.awt.event.ActionEvent; 9 import java.awt.event.ActionListener; 10 import java.util.ArrayList; 9 import java.util.List; 11 10 import java.util.Map; 12 11 … … 19 18 20 19 import org.openstreetmap.josm.plugins.ohe.ClockSystem; 21 import org.openstreetmap.josm.plugins.ohe.OhePlugin;22 20 import org.openstreetmap.josm.plugins.ohe.OpeningTimeUtils; 23 21 import org.openstreetmap.josm.plugins.ohe.parser.OpeningTimeCompiler; … … 28 26 import org.openstreetmap.josm.tools.Logging; 29 27 28 /** The dialog panel for editing opening hourse */ 30 29 public class OheDialogPanel extends JPanel { 31 30 31 /** The key we are modifying */ 32 32 private final JTextField keyField; 33 33 34 / / The Component for showing the Time as a Text34 /** The Component for showing the Time as a Text */ 35 35 private final JTextField valueField; 36 36 37 private final JButton twentyfourSevenButton;38 private final JLabel actualPos tionLabel;39 40 / / The important Panel for showing/editing the Time graphical37 /** The position of the mouse pointer*/ 38 private final JLabel actualPositionLabel; 39 40 /** The important Panel for showing/editing the Time graphical */ 41 41 private final OheEditor editorPanel; 42 42 43 private final String oldkey; 44 45 private ClockSystem clockSystem; 43 /** The original key for the initial timespan */ 44 private final String oldKey; 45 46 /** The ClockSystem that the user wants us to use */ 47 private final ClockSystem clockSystem; 46 48 47 49 /** 48 50 * The Panel for editing the time-values. 49 * 51 * 52 * @param key The key to edit 50 53 * @param valuesToEdit 51 54 * can be a String or a Map<String, Integer> which contains 52 55 * multiple values and their number of occurences 53 */ 54 public OheDialogPanel(OhePlugin plugin, String key, Object valuesToEdit, ClockSystem clockSystem) { 56 * @param clockSystem The clocksystem to use 57 */ 58 public OheDialogPanel(String key, Object valuesToEdit, ClockSystem clockSystem) { 55 59 this.clockSystem = clockSystem; 56 60 57 old key = key;61 oldKey = key; 58 62 keyField = new JTextField(key); 59 63 … … 69 73 // TODO let the user choose which value he wants to edit (e.g. with a combobox) 70 74 int mostOccurences = 0; 71 for ( String v : valuesMap.keySet()) {72 if ( valuesMap.get(v) > mostOccurences) {73 value = v;74 mostOccurences = valuesMap.get(v);75 for (Map.Entry<String, Integer> entry : valuesMap.entrySet()) { 76 if (entry.getValue() > mostOccurences) { 77 value = entry.getKey(); 78 mostOccurences = entry.getValue(); 75 79 } 76 80 } … … 78 82 } 79 83 valueField = new JTextField(value); 80 valueField.addActionListener(new ActionListener() { 81 @Override 82 public void actionPerformed(ActionEvent evt) { 83 // on every action in the textfield the timeRects are reloaded 84 editorPanel.initTimeRects(); 85 } 86 }); 87 88 twentyfourSevenButton = new JButton(tr("apply {0}", "24/7")); 89 twentyfourSevenButton.addActionListener(new ActionListener() { 90 @Override 91 public void actionPerformed(ActionEvent arg0) { 92 valueField.setText("24/7"); 93 editorPanel.initTimeRects(); 94 } 95 }); 96 97 actualPostionLabel = new JLabel("-"); 84 85 JButton twentyfourSevenButton = new JButton(tr("apply {0}", "24/7")); 86 87 actualPositionLabel = new JLabel("-"); 98 88 JPanel toolsPanel = new JPanel(new GridBagLayout()); 99 89 toolsPanel.add(twentyfourSevenButton, GBC.std()); 100 toolsPanel.add(Box.createGlue(), GBC.std().fill(G BC.HORIZONTAL));101 toolsPanel.add(actualPos tionLabel, GBC.eop());90 toolsPanel.add(Box.createGlue(), GBC.std().fill(GridBagConstraints.HORIZONTAL)); 91 toolsPanel.add(actualPositionLabel, GBC.eop()); 102 92 103 93 editorPanel = new OheEditor(this); 94 95 // on every action in the textfield the timeRects are reloaded 96 valueField.addActionListener(evt -> editorPanel.initTimeRects()); 97 98 twentyfourSevenButton.addActionListener(arg0 -> { 99 valueField.setText("24/7"); 100 editorPanel.initTimeRects(); 101 }); 104 102 105 103 // adding all Components in a Gridbaglayout … … 107 105 add(new JLabel(tr("Key")), GBC.std()); 108 106 add(Box.createHorizontalStrut(10), GBC.std()); 109 add(keyField, GBC.eol().fill(G BC.HORIZONTAL));107 add(keyField, GBC.eol().fill(GridBagConstraints.HORIZONTAL)); 110 108 add(new JLabel(tr("Value")), GBC.std()); 111 109 add(Box.createHorizontalStrut(10), GBC.std()); 112 add(valueField, GBC.eop().fill(G BC.HORIZONTAL));113 add(toolsPanel, GBC.eol().fill(G BC.HORIZONTAL));110 add(valueField, GBC.eop().fill(GridBagConstraints.HORIZONTAL)); 111 add(toolsPanel, GBC.eol().fill(GridBagConstraints.HORIZONTAL)); 114 112 add(editorPanel, GBC.eol().fill()); 115 113 … … 118 116 119 117 public String[] getChangedKeyValuePair() { 120 return new String[] {old key, keyField.getText(), valueField.getText()};118 return new String[] {oldKey, keyField.getText(), valueField.getText()}; 121 119 } 122 120 … … 124 122 * Returns the compiled Time from the valueField. 125 123 * @return the compiled Time from the valueField 126 */ 127 public ArrayList<int[]> getTime() throws Exception { 124 * @throws OheException if the time value could not be parsed 125 */ 126 public List<int[]> getTime() throws OheException { 128 127 String value = valueField.getText(); 129 ArrayList<int[]> time = null;128 List<int[]> time = null; 130 129 if (value.length() > 0) { 131 130 OpeningTimeCompiler compiler = new OpeningTimeCompiler(value); 132 131 try { 133 132 time = OpeningTimeUtils.convert(compiler.startCompile()); 134 } catch ( Exception | TokenMgrError t) {133 } catch (ParseException | SyntaxException | TokenMgrError t) { 135 134 Logging.warn(t); 136 135 … … 152 151 tColumns = new int[] {col - 1, col + 1}; 153 152 } 154 } catch (IndexOutOfBoundsException e) { 155 Logging.warn(e); 156 } catch (NumberFormatException e) { 153 } catch (IndexOutOfBoundsException | NumberFormatException e) { 157 154 Logging.warn(e); 158 155 } … … 183 180 } 184 181 185 throw new Exception("Error in the TimeValue", t);182 throw new OheException("Error in the TimeValue", t); 186 183 } 187 184 } … … 191 188 192 189 /** 193 * Updates the valueField with the given timeRects. 194 */ 195 public void updateValueField(ArrayList<TimeRect> timeRects) { 190 * Updates the valueField with the given {@link TimeRect}s. 191 * @param timeRects The time rectangles to set the value from 192 */ 193 void updateValueField(List<TimeRect> timeRects) { 196 194 if (valueField != null && timeRects != null) 197 195 valueField.setText(OpeningTimeUtils.makeStringFromRects(timeRects)); 198 196 } 199 197 200 public void setMousePositionText(String positionText) { 201 actualPostionLabel.setText(positionText); 198 /** 199 * Set the position text for the mouse 200 * @param positionText The text to use 201 */ 202 void setMousePositionText(String positionText) { 203 actualPositionLabel.setText(positionText); 202 204 } 203 205 -
applications/editors/josm/plugins/OpeningHoursEditor/src/org/openstreetmap/josm/plugins/ohe/gui/OheEditor.java
r34535 r36183 12 12 import java.awt.event.MouseMotionListener; 13 13 import java.util.ArrayList; 14 import java.util.List; 14 15 15 16 import javax.swing.JPanel; 16 17 import javax.swing.JScrollPane; 18 import javax.swing.ScrollPaneConstants; 17 19 18 20 import org.openstreetmap.josm.plugins.ohe.ClockSystem; … … 21 23 import org.openstreetmap.josm.tools.Logging; 22 24 25 /** 26 * The editor for opening hours 27 */ 23 28 public class OheEditor extends JPanel implements MouseListener, MouseMotionListener { 29 /** A panel for the {@link TimeRect}s */ 24 30 private final class OhePanel extends JPanel { 25 31 @Override … … 64 70 int minute2 = Math.min(minute0, minute1); 65 71 int minute3 = Math.max(minute0, minute1); 66 Rectangle bounds = getPanelBoundsForTime interval(day2, day3 + 1, minute2, minute3);72 Rectangle bounds = getPanelBoundsForTimeInterval(day2, day3 + 1, minute2, minute3); 67 73 TimeRect.drawTimeRect(g2D, bounds, minute2 == minute3, false); 68 74 } … … 76 82 final OheDialogPanel dialog; 77 83 78 private final JScrollPane scrollPane;79 84 final JPanel contentPanel; 80 85 81 ArrayList<TimeRect> timeRects; 82 83 private final int dayAxisHeight = 20; 84 private final int timeAxisWidth = 45; 85 86 /** The time rectangles for this dialog */ 87 List<TimeRect> timeRects; 88 89 /** The height for the cells */ 90 private static final int DAY_AXIS_HEIGHT = 20; 91 /** The width for the cells */ 92 private static final int TIME_AXIS_WIDTH = 45; 93 94 /** 95 * Create a new editor component 96 * @param oheDialogPanel The dialog with settings for this editor 97 */ 86 98 public OheEditor(OheDialogPanel oheDialogPanel) { 87 99 dialog = oheDialogPanel; … … 96 108 initTimeRects(); 97 109 98 scrollPane = new JScrollPane(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,99 JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);110 JScrollPane scrollPane = new JScrollPane(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, 111 ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); 100 112 scrollPane.setViewportView(contentPanel); 101 113 … … 104 116 @Override 105 117 public Dimension getPreferredSize() { 106 return new Dimension(contentPanel.getWidth(), dayAxisHeight);118 return new Dimension(contentPanel.getWidth(), DAY_AXIS_HEIGHT); 107 119 } 108 120 … … 120 132 String text = OpeningTimeCompiler.WEEKDAYS[i]; 121 133 g.drawString(text, (int) (getDayPosition(i + 0.5) - g.getFontMetrics().stringWidth(text) * 0.5), 122 (int) ( dayAxisHeight* 0.5 + g.getFontMetrics().getHeight() * 0.35));134 (int) (DAY_AXIS_HEIGHT * 0.5 + g.getFontMetrics().getHeight() * 0.35)); 123 135 } 124 136 } … … 129 141 @Override 130 142 public Dimension getPreferredSize() { 131 return new Dimension( timeAxisWidth, contentPanel.getHeight());143 return new Dimension(TIME_AXIS_WIDTH, contentPanel.getHeight()); 132 144 } 133 145 … … 148 160 if (i % 24 != 0) { 149 161 String text = OpeningTimeUtils.timeString(i * 60, dialog.getHourMode(), false); 150 g.drawString(text, ( timeAxisWidth- g.getFontMetrics().stringWidth(text)) / 2,162 g.drawString(text, (TIME_AXIS_WIDTH - g.getFontMetrics().stringWidth(text)) / 2, 151 163 getMinutePosition(i * 60) + (int) (g.getFontMetrics().getHeight() * 0.35)); 152 164 } … … 160 172 g.setColor(Color.BLACK); 161 173 String text = OpeningTimeUtils.timeString(0, dialog.getHourMode(), false); 162 g.drawString(text, ( timeAxisWidth- g.getFontMetrics().stringWidth(text)) / 2, getMinutePosition(0)174 g.drawString(text, (TIME_AXIS_WIDTH - g.getFontMetrics().stringWidth(text)) / 2, getMinutePosition(0) 163 175 + (int) (g.getFontMetrics().getHeight() * 1.0)); 164 176 if (dialog.getHourMode() == ClockSystem.TWELVE_HOURS) { 165 177 text = "AM"; 166 g.drawString(text, ( timeAxisWidth- g.getFontMetrics().stringWidth(text)) / 2, getMinutePosition(0)178 g.drawString(text, (TIME_AXIS_WIDTH - g.getFontMetrics().stringWidth(text)) / 2, getMinutePosition(0) 167 179 + (int) (g.getFontMetrics().getHeight() * 1.85)); 168 180 text = "PM"; 169 g.drawString(text, ( timeAxisWidth- g.getFontMetrics().stringWidth(text)) / 2,181 g.drawString(text, (TIME_AXIS_WIDTH - g.getFontMetrics().stringWidth(text)) / 2, 170 182 getMinutePosition(12 * 60) + (int) (g.getFontMetrics().getHeight() * 1.2)); 171 183 } … … 183 195 contentPanel.removeAll(); 184 196 185 ArrayList<int[]> time;197 List<int[]> time; 186 198 try { 187 199 time = dialog.getTime(); … … 196 208 if (time != null) { 197 209 for (int[] timeRectValues : time) { 198 int day0 = timeRectValues[0];199 int day1 = timeRectValues[1];200 int minute0 = timeRectValues[2];201 int minute1 = timeRectValues[3];202 TimeRect timeRect = new TimeRect(OheEditor.this, day0, day1, minute0, minute1);210 int tDay0 = timeRectValues[0]; 211 int tDay1 = timeRectValues[1]; 212 int tMinute0 = timeRectValues[2]; 213 int tMinute1 = timeRectValues[3]; 214 TimeRect timeRect = new TimeRect(OheEditor.this, tDay0, tDay1, tMinute0, tMinute1); 203 215 timeRects.add(timeRect); 204 216 contentPanel.add(timeRect); … … 218 230 } 219 231 220 // returns the physical Borders of the TimeRect on the mainPanel 221 public Rectangle getPanelBoundsForTimeinterval(int dayStart, int dayEnd, int minutesStart, int minutesEnd) { 232 /** 233 * returns the physical Borders of the TimeRect on the mainPanel 234 * 235 * @param dayStart The starting weekday for the opening hours 236 * @param dayEnd The ending weekday for the opening hours 237 * @param minutesStart The starting time for the opening hours 238 * @param minutesEnd The ending time for the opening hours 239 * @return The borders for the time rectangle 240 */ 241 public Rectangle getPanelBoundsForTimeInterval(int dayStart, int dayEnd, int minutesStart, int minutesEnd) { 222 242 int x = getDayPosition(dayStart); 223 243 int y = getMinutePosition(minutesStart); … … 226 246 227 247 if (minutesStart == minutesEnd) 228 return new Rectangle(x, y - 2 - TimeRect. verticalNonDrawedPixels, width, height + 5 + 2229 * TimeRect. verticalNonDrawedPixels);248 return new Rectangle(x, y - 2 - TimeRect.VERTICAL_NON_DRAWN_PIXELS, width, height + 5 + 2 249 * TimeRect.VERTICAL_NON_DRAWN_PIXELS); 230 250 231 251 return new Rectangle(x, y, width, height + 1); 232 252 } 233 253 234 public double getDayWidth() { 254 /** 255 * Get the width for a time cell 256 * @return The width in pixels 257 */ 258 double getDayWidth() { 235 259 return (contentPanel.getWidth() - 1) / 7.0; 236 260 } 237 261 238 public int getDayPosition(double d) { 262 /** 263 * Get the position for a day 264 * @param d The weekday 265 * @return The starting pixel position for the day 266 */ 267 int getDayPosition(double d) { 239 268 return (int) (d * getDayWidth()); 240 269 } 241 270 242 public double getMinuteHeight() { 271 /** 272 * Get the height for a hour 273 * @return The height of an hour in pixels 274 */ 275 double getMinuteHeight() { 243 276 return (contentPanel.getHeight() - 1) / (24.0 * 60); 244 277 } 245 278 246 public int getMinutePosition(int minute) { 279 /** 280 * Get the position for a minute in pixels 281 * @param minute The minute to get the position for 282 * @return The pixel location for the minute 283 */ 284 int getMinutePosition(int minute) { 247 285 return (int) (minute * getMinuteHeight()); 248 286 } 249 287 250 288 /** 251 * Removes the given timerect from the panel and from the arraylist 252 */ 253 public void removeTimeRect(TimeRect timeRectToRemove) { 289 * Removes the given {@link TimeRect} from the panel and from the arraylist 290 * @param timeRectToRemove The rectangle to remove 291 */ 292 void removeTimeRect(TimeRect timeRectToRemove) { 254 293 timeRects.remove(timeRectToRemove); 255 294 contentPanel.remove(timeRectToRemove); … … 259 298 260 299 // drawing a new Rect 300 /** The first day of the time slot. -1 is for new rectangles. */ 261 301 private int day0 = -1; 302 /** THe first minute of the time slot */ 262 303 private int minute0; 304 /** The last day of the time slot */ 263 305 private int day1; 306 /** The last minute of the time slot */ 264 307 private int minute1; 308 /** The x location of the mouse click */ 265 309 private int xDragStart; 310 /** The y location of the mouse click */ 266 311 private int yDragStart; 267 312 268 313 @Override 269 314 public void mouseClicked(MouseEvent evt) { 315 // Do nothing 270 316 } 271 317 … … 292 338 } 293 339 day0 = (int) Math.floor(evt.getX() / getDayWidth()); 294 minute0 = (int) Math.floor(evt.getY() / (getMinuteHeight() * TimeRect. minuteResterize))295 * TimeRect. minuteResterize;340 minute0 = (int) Math.floor(evt.getY() / (getMinuteHeight() * TimeRect.MINUTE_RASTERIZE)) 341 * TimeRect.MINUTE_RASTERIZE; 296 342 day1 = day0; 297 343 minute1 = minute0; … … 332 378 xDragStart = -1; 333 379 day1 = (int) Math.floor(evt.getX() / getDayWidth()); 334 minute1 = (int) Math.floor(evt.getY() / (getMinuteHeight() * TimeRect. minuteResterize))335 * TimeRect. minuteResterize;380 minute1 = (int) Math.floor(evt.getY() / (getMinuteHeight() * TimeRect.MINUTE_RASTERIZE)) 381 * TimeRect.MINUTE_RASTERIZE; 336 382 337 383 // ensure that the new time is in a valid range … … 354 400 } 355 401 356 public void mousePositionChanged(int x, int y, boolean mouseInside) { 402 /** 403 * Called when the mouse position moves 404 * @param x The mouse x position 405 * @param y The mouse y position 406 * @param mouseInside {@code true} if the mouse is inside the component for time cells 407 */ 408 void mousePositionChanged(int x, int y, boolean mouseInside) { 357 409 if (mouseInside) { 358 410 int actualDay = (int) Math.floor(x / getDayWidth()); 359 int minutes = (int) Math.floor(y / (getMinuteHeight() * TimeRect. minuteResterize))360 * TimeRect. minuteResterize;411 int minutes = (int) Math.floor(y / (getMinuteHeight() * TimeRect.MINUTE_RASTERIZE)) 412 * TimeRect.MINUTE_RASTERIZE; 361 413 actualDay = Math.max(0, Math.min(6, actualDay)); 362 414 minutes = Math.max(0, Math.min(24 * 60, minutes)); -
applications/editors/josm/plugins/OpeningHoursEditor/src/org/openstreetmap/josm/plugins/ohe/gui/TimeRect.java
r32583 r36183 10 10 import java.awt.Graphics2D; 11 11 import java.awt.Rectangle; 12 import java.awt.event.ActionEvent;13 import java.awt.event.ActionListener;14 12 import java.awt.event.MouseEvent; 15 13 import java.awt.event.MouseListener; … … 22 20 import org.openstreetmap.josm.plugins.ohe.OpeningTimeUtils; 23 21 22 /** 23 * Rectangles for a time block 24 */ 24 25 public class TimeRect extends JPanel implements MouseListener, MouseMotionListener { 25 26 26 publicstatic final int[] transformCursorTypes = new int[] {27 static final int[] transformCursorTypes = new int[] { 27 28 Cursor.MOVE_CURSOR, Cursor.N_RESIZE_CURSOR, 28 29 Cursor.NE_RESIZE_CURSOR, Cursor.E_RESIZE_CURSOR, … … 31 32 Cursor.NW_RESIZE_CURSOR }; 32 33 33 public static final int minuteResterize= 15;34 public static final int verticalNonDrawedPixels= 5;35 36 publicstatic final boolean[][] transformDirections = new boolean[][] {34 static final int MINUTE_RASTERIZE = 15; 35 static final int VERTICAL_NON_DRAWN_PIXELS = 5; 36 37 static final boolean[][] transformDirections = new boolean[][] { 37 38 {true, true, true, true}, // Drag 38 39 {true, false, false, false}, // N … … 46 47 }; 47 48 48 publicstatic final int roundCornerSize = 8;49 static final int roundCornerSize = 8; 49 50 private final int clickAreaSize = 16; 50 51 … … 101 102 102 103 public void reposition() { 103 setBounds(editor.getPanelBoundsForTime interval(dayStart, dayEnd + 1, minuteStart, minuteEnd));104 setBounds(editor.getPanelBoundsForTimeInterval(dayStart, dayEnd + 1, minuteStart, minuteEnd)); 104 105 editor.contentPanel.repaint(); 105 106 } … … 145 146 innerColor = new Color(135, 234, 135); 146 147 tmpRoundCornerSize = 0; 147 verticalNonFilledBorder = verticalNonDrawedPixels;148 verticalNonFilledBorder = VERTICAL_NON_DRAWN_PIXELS; 148 149 } 149 150 … … 205 206 final JCheckBoxMenuItem cbMenuItem = new JCheckBoxMenuItem(tr("open end"), isOpenEndInterval()); 206 207 menu.add(cbMenuItem); 207 cbMenuItem.addActionListener(new ActionListener() { 208 @Override 209 public void actionPerformed(ActionEvent e) { 210 if (cbMenuItem.isSelected()) 211 updateTimeInterval(dayStart, dayEnd, minuteStart, 24 * 60 + 1); 212 else 213 updateTimeInterval(dayStart, dayEnd, minuteStart, 24 * 60); 214 } 208 cbMenuItem.addActionListener(e -> { 209 if (cbMenuItem.isSelected()) 210 updateTimeInterval(dayStart, dayEnd, minuteStart, 24 * 60 + 1); 211 else 212 updateTimeInterval(dayStart, dayEnd, minuteStart, 24 * 60); 215 213 }); 216 214 menu.show(this, evt.getX(), evt.getY()); … … 219 217 @Override 220 218 public void mouseClicked(MouseEvent evt) { 219 // Do nothing 221 220 } 222 221 223 222 @Override 224 223 public void mouseEntered(MouseEvent evt) { 224 // Do nothing 225 225 } 226 226 … … 263 263 - actualDayDrag; 264 264 yDiff = (int) Math.round(yDiff 265 / (editor.getMinuteHeight() * minuteResterize))266 * minuteResterize- actualMinuteDrag;265 / (editor.getMinuteHeight() * MINUTE_RASTERIZE)) 266 * MINUTE_RASTERIZE - actualMinuteDrag; 267 267 268 268 if (xDiff != 0) {
Note:
See TracChangeset
for help on using the changeset viewer.