From e3f025473671598ee8c8e951bfd98e91687f1513 Mon Sep 17 00:00:00 2001 From: huangyuhui Date: Tue, 29 Dec 2015 13:57:15 +0800 Subject: [PATCH] fix some ui problems --- .gitignore~ | 26 ----- .../hellominecraft/launcher/Main.java | 1 - .../launcher/settings/Config.java | 13 ++- .../launcher/views/DraggableFrame.java | 9 +- .../launcher/views/LauncherSettingsPanel.form | 27 ++++- .../launcher/views/LauncherSettingsPanel.java | 30 ++++- .../launcher/views/MainFrame.java | 110 +++++++++++++----- .../hellominecraft/launcher/I18N.properties | 3 +- 8 files changed, 145 insertions(+), 74 deletions(-) delete mode 100755 .gitignore~ diff --git a/.gitignore~ b/.gitignore~ deleted file mode 100755 index 214fff1dc..000000000 --- a/.gitignore~ +++ /dev/null @@ -1,26 +0,0 @@ -*.class - -# Mobile Tools for Java (J2ME) -.mtj.tmp/ - -# Package Files # -*.jar -*.war -*.ear - -# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml -hs_err_pid* - -.gradle -.nb-gradle - -*.bat -*.log -.mine* -*.json -*.hmd - -HMCLAPI/build/ -HMCL/build/ -HMCSM/build/ -MetroLookAndFeel/build/ diff --git a/HMCL/src/main/java/org/jackhuang/hellominecraft/launcher/Main.java b/HMCL/src/main/java/org/jackhuang/hellominecraft/launcher/Main.java index 1e29a8b0f..3fa7a31d2 100755 --- a/HMCL/src/main/java/org/jackhuang/hellominecraft/launcher/Main.java +++ b/HMCL/src/main/java/org/jackhuang/hellominecraft/launcher/Main.java @@ -121,7 +121,6 @@ public final class Main implements Runnable { return; System.setProperty("sun.java2d.noddraw", "true"); - Thread.setDefaultUncaughtExceptionHandler(new CrashReporter(true)); try { diff --git a/HMCL/src/main/java/org/jackhuang/hellominecraft/launcher/settings/Config.java b/HMCL/src/main/java/org/jackhuang/hellominecraft/launcher/settings/Config.java index e61fdf398..76c1ff26f 100755 --- a/HMCL/src/main/java/org/jackhuang/hellominecraft/launcher/settings/Config.java +++ b/HMCL/src/main/java/org/jackhuang/hellominecraft/launcher/settings/Config.java @@ -28,6 +28,7 @@ import org.jackhuang.hellominecraft.launcher.utils.auth.IAuthenticator; import org.jackhuang.hellominecraft.lookandfeel.Theme; import org.jackhuang.hellominecraft.utils.EventHandler; import org.jackhuang.hellominecraft.utils.system.JdkVersion; +import org.jackhuang.hellominecraft.utils.system.OS; /** * @@ -46,7 +47,8 @@ public final class Config { private String proxyHost, proxyPort, proxyUserName, proxyPassword; @SerializedName("enableShadow") private boolean enableShadow; - + @SerializedName("decorated") + private boolean decorated; @SerializedName("enableAnimation") private boolean enableAnimation; @SerializedName("theme") @@ -70,6 +72,14 @@ public final class Config { Settings.save(); } + public boolean isDecorated() { + return decorated; + } + + public void setDecorated(boolean decorated) { + this.decorated = decorated; + } + public boolean isEnableShadow() { return enableShadow; } @@ -178,6 +188,7 @@ public final class Config { enableShadow = false; enableAnimation = true; theme = 4; + decorated = OS.os() == OS.LINUX; } public DownloadType getDownloadSource() { diff --git a/HMCL/src/main/java/org/jackhuang/hellominecraft/launcher/views/DraggableFrame.java b/HMCL/src/main/java/org/jackhuang/hellominecraft/launcher/views/DraggableFrame.java index 4cbc0670d..9dc90661b 100755 --- a/HMCL/src/main/java/org/jackhuang/hellominecraft/launcher/views/DraggableFrame.java +++ b/HMCL/src/main/java/org/jackhuang/hellominecraft/launcher/views/DraggableFrame.java @@ -1,7 +1,7 @@ /* * Hello Minecraft! Launcher. * Copyright (C) 2013 huangyuhui - * + * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or @@ -27,14 +27,13 @@ import javax.swing.JFrame; * @author huangyuhui */ public class DraggableFrame extends JFrame -implements MouseListener, MouseMotionListener { + implements MouseListener, MouseMotionListener { private int dragGripX; private int dragGripY; @SuppressWarnings("LeakingThisInConstructor") public DraggableFrame() { - setUndecorated(true); addMouseListener(this); addMouseMotionListener(this); } @@ -45,7 +44,7 @@ implements MouseListener, MouseMotionListener { @Override public void mousePressed(MouseEvent e) { - if (e.getButton() == 1) { + if (e.getButton() == 1 && isUndecorated()) { this.dragGripX = e.getX(); this.dragGripY = e.getY(); } @@ -65,7 +64,7 @@ implements MouseListener, MouseMotionListener { @Override public void mouseDragged(MouseEvent e) { - if ((e.getModifiersEx() & 0x400) != 0) + if ((e.getModifiersEx() & 0x400) != 0 && isUndecorated()) setLocation(e.getXOnScreen() - this.dragGripX, e.getYOnScreen() - this.dragGripY); } diff --git a/HMCL/src/main/java/org/jackhuang/hellominecraft/launcher/views/LauncherSettingsPanel.form b/HMCL/src/main/java/org/jackhuang/hellominecraft/launcher/views/LauncherSettingsPanel.form index edbd88b87..370c29bf8 100755 --- a/HMCL/src/main/java/org/jackhuang/hellominecraft/launcher/views/LauncherSettingsPanel.form +++ b/HMCL/src/main/java/org/jackhuang/hellominecraft/launcher/views/LauncherSettingsPanel.form @@ -60,12 +60,16 @@ - - + + - + + + + + + - @@ -109,7 +113,10 @@ - + + + + @@ -270,5 +277,15 @@ + + + + + + + + + + diff --git a/HMCL/src/main/java/org/jackhuang/hellominecraft/launcher/views/LauncherSettingsPanel.java b/HMCL/src/main/java/org/jackhuang/hellominecraft/launcher/views/LauncherSettingsPanel.java index b06a4250e..cd3ed499e 100755 --- a/HMCL/src/main/java/org/jackhuang/hellominecraft/launcher/views/LauncherSettingsPanel.java +++ b/HMCL/src/main/java/org/jackhuang/hellominecraft/launcher/views/LauncherSettingsPanel.java @@ -54,6 +54,7 @@ public class LauncherSettingsPanel extends AnimatedPanel { cboTheme.setSelectedIndex(Settings.getInstance().getTheme().ordinal()); chkEnableShadow.setSelected(Settings.getInstance().isEnableShadow()); chkEnableAnimation.setSelected(Settings.getInstance().isEnableAnimation()); + chkDecorated.setSelected(Settings.getInstance().isDecorated()); setBackground(Color.white); setOpaque(true); @@ -88,6 +89,7 @@ public class LauncherSettingsPanel extends AnimatedPanel { txtProxyPassword = new javax.swing.JTextField(); jLabel8 = new javax.swing.JLabel(); chkEnableAnimation = new javax.swing.JCheckBox(); + chkDecorated = new javax.swing.JCheckBox(); cboDownloadSource.addItemListener(new java.awt.event.ItemListener() { public void itemStateChanged(java.awt.event.ItemEvent evt) { @@ -180,6 +182,14 @@ public class LauncherSettingsPanel extends AnimatedPanel { } }); + java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle("org/jackhuang/hellominecraft/launcher/I18N"); // NOI18N + chkDecorated.setText(bundle.getString("launcher.decorated")); // NOI18N + chkDecorated.addFocusListener(new java.awt.event.FocusAdapter() { + public void focusLost(java.awt.event.FocusEvent evt) { + chkDecoratedFocusLost(evt); + } + }); + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); this.setLayout(layout); layout.setHorizontalGroup( @@ -222,11 +232,14 @@ public class LauncherSettingsPanel extends AnimatedPanel { .addComponent(chkEnableShadow) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(chkEnableAnimation)) - .addGroup(layout.createSequentialGroup() - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(btnCheckUpdate)) - .addGap(0, 0, Short.MAX_VALUE))) + .addGap(0, 0, Short.MAX_VALUE)) + .addGroup(layout.createSequentialGroup() + .addComponent(btnCheckUpdate) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(chkDecorated)))) .addContainerGap()) ); layout.setVerticalGroup( @@ -261,7 +274,9 @@ public class LauncherSettingsPanel extends AnimatedPanel { .addComponent(chkEnableShadow) .addComponent(chkEnableAnimation)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(btnCheckUpdate, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(btnCheckUpdate, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(chkDecorated)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 71, Short.MAX_VALUE) .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addContainerGap()) @@ -331,11 +346,16 @@ public class LauncherSettingsPanel extends AnimatedPanel { Settings.getInstance().setEnableAnimation(chkEnableAnimation.isSelected()); }//GEN-LAST:event_chkEnableAnimationFocusLost + private void chkDecoratedFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_chkDecoratedFocusLost + Settings.getInstance().setDecorated(chkDecorated.isSelected()); + }//GEN-LAST:event_chkDecoratedFocusLost + // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton btnCheckUpdate; private javax.swing.JButton btnSelBackgroundPath; private javax.swing.JComboBox cboDownloadSource; private javax.swing.JComboBox cboTheme; + private javax.swing.JCheckBox chkDecorated; private javax.swing.JCheckBox chkEnableAnimation; private javax.swing.JCheckBox chkEnableShadow; private javax.swing.JLabel jLabel1; diff --git a/HMCL/src/main/java/org/jackhuang/hellominecraft/launcher/views/MainFrame.java b/HMCL/src/main/java/org/jackhuang/hellominecraft/launcher/views/MainFrame.java index a55474b57..f37c3560b 100755 --- a/HMCL/src/main/java/org/jackhuang/hellominecraft/launcher/views/MainFrame.java +++ b/HMCL/src/main/java/org/jackhuang/hellominecraft/launcher/views/MainFrame.java @@ -29,6 +29,8 @@ import java.awt.Transparency; import java.awt.event.ActionListener; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; +import java.awt.event.WindowEvent; +import java.awt.event.WindowListener; import java.awt.image.BufferedImage; import javax.swing.BorderFactory; import javax.swing.Box; @@ -73,13 +75,22 @@ public final class MainFrame extends DraggableFrame { boolean enableShadow; String defaultTitle; + private int tempW, tempH; + + void setContentSize(int w, int h) { + setSize(w, h); + tempW = w; + tempH = h; + } + MainFrame() { - defaultTitle = Main.makeTitle(); - enableShadow = Settings.getInstance().isEnableShadow(); + setUndecorated(!Settings.getInstance().isDecorated()); + defaultTitle = isUndecorated() ? Main.makeTitle() : ""; + enableShadow = Settings.getInstance().isEnableShadow() && isUndecorated(); if (enableShadow) - setSize(834, 542); + setContentSize(834, 542); else - setSize(802, 511); + setContentSize(802, 511); setDefaultCloseOperation(3); setTitle(Main.makeTitle()); initComponents(); @@ -87,10 +98,48 @@ public final class MainFrame extends DraggableFrame { loadBackground(); setLocationRelativeTo(null); + if (MainFrame.this.isUndecorated()) + setResizable(false); + + this.addWindowListener(new WindowListener() { + @Override + public void windowOpened(WindowEvent e) { + } + + @Override + public void windowClosing(WindowEvent e) { + } + + @Override + public void windowClosed(WindowEvent e) { + } + + @Override + public void windowIconified(WindowEvent e) { + } + + @Override + public void windowDeiconified(WindowEvent e) { + } + + @Override + public void windowActivated(WindowEvent e) { + if (!MainFrame.this.isUndecorated()) { + int w = tempW + getWidth() - getContentPane().getWidth(), h = tempH + getHeight() - getContentPane().getHeight(); + setSize(w, h); + setResizable(false); + setLocationRelativeTo(null); + } + } + + @Override + public void windowDeactivated(WindowEvent e) { + } + }); if (enableShadow) try { - setBackground(new Color(0, 0, 0, 0)); + //setBackground(new Color(0, 0, 0, 0)); getRootPane().setBorder(border = new DropShadowBorder(borderColor, 4)); } catch (Throwable ex) { HMCLog.err("Failed to set window transparent.", ex); @@ -167,24 +216,25 @@ public final class MainFrame extends DraggableFrame { windowGadgetPanel.setLayout(new BoxLayout(windowGadgetPanel, BoxLayout.LINE_AXIS)); windowGadgetPanel.setAlignmentX(1.0F); - ImageIcon minimizeIcon = Main.getIcon("minimize.png"); - JButton minimizeButton = new JButton(minimizeIcon); - minimizeButton.setBorder(BorderFactory.createEmptyBorder()); - minimizeButton.setContentAreaFilled(false); - minimizeButton.setCursor(new Cursor(12)); - minimizeButton.setFocusable(false); - minimizeButton.addActionListener((e) -> MainFrame.this.minimizeWindow()); - windowGadgetPanel.add(minimizeButton); - - ImageIcon closeIcon = Main.getIcon("close.png"); - JButton closeButton = new JButton(closeIcon); - closeButton.setBorder(BorderFactory.createEmptyBorder()); - closeButton.setContentAreaFilled(false); - closeButton.addActionListener((e) -> MainFrame.this.closeWindow()); - closeButton.setCursor(new Cursor(12)); - closeButton.setFocusable(false); - windowGadgetPanel.add(closeButton); + if (!Settings.getInstance().isDecorated()) { + ImageIcon minimizeIcon = Main.getIcon("minimize.png"); + JButton minimizeButton = new JButton(minimizeIcon); + minimizeButton.setBorder(BorderFactory.createEmptyBorder()); + minimizeButton.setContentAreaFilled(false); + minimizeButton.setCursor(new Cursor(12)); + minimizeButton.setFocusable(false); + minimizeButton.addActionListener((e) -> MainFrame.this.minimizeWindow()); + windowGadgetPanel.add(minimizeButton); + ImageIcon closeIcon = Main.getIcon("close.png"); + JButton closeButton = new JButton(closeIcon); + closeButton.setBorder(BorderFactory.createEmptyBorder()); + closeButton.setContentAreaFilled(false); + closeButton.addActionListener((e) -> MainFrame.this.closeWindow()); + closeButton.setCursor(new Cursor(12)); + closeButton.setFocusable(false); + windowGadgetPanel.add(closeButton); + } rightHeaderPanel.add(windowGadgetPanel); windowTitle = new JLabel(defaultTitle); @@ -297,14 +347,14 @@ public final class MainFrame extends DraggableFrame { public void loadBackground() { background = Utils.searchBackgroundImage(Main.getIcon("background.jpg"), Settings.getInstance().getBgpath(), 800, 480); - if (background != null) { + if (background != null) if (backgroundLabel == null) { backgroundLabel = new JLabel(background); backgroundLabel.setBounds(0, 0, 800, 480); + centralPanel.add(backgroundLabel, -1); } else backgroundLabel.setIcon(background); - centralPanel.add(backgroundLabel, -1); - } else + else HMCLog.warn("No Background Image, the background will be empty!"); } @@ -344,7 +394,7 @@ public final class MainFrame extends DraggableFrame { IAuthenticator l = Settings.getInstance().getAuthenticator(); if (l.hasPassword() && !l.isLoggedIn()) SwingUtilities.invokeLater(() -> MainFrame.INSTANCE.showMessage(C.i18n("ui.message.enter_password"))); - INSTANCE.show(); + INSTANCE.setVisible(true); } Color borderColor; @@ -367,14 +417,14 @@ public final class MainFrame extends DraggableFrame { } private void paintImpl(Graphics g) { - int off = enableShadow ? 16 : 0; + int off = enableShadow ? 16 : 0, yoff = getInsets().top + off, xoff = getInsets().left + off; int width = 800; int height = header.getHeight() + 480 - 1; super.paint(g); g.setColor(borderColor); - g.drawLine(off, off, off, height + off + 1); - g.drawLine(off + width + 1, off, off + width + 1, height + off + 1); - g.drawLine(off, height + off + 1, off + width + 1, height + off + 1); + g.drawLine(xoff, yoff, xoff, height + yoff + 1); + g.drawLine(xoff + width + 1, yoff, xoff + width + 1, height + yoff + 1); + g.drawLine(xoff, height + yoff + 1, xoff + width + 1, height + yoff + 1); } @Override diff --git a/HMCLAPI/src/main/resources/org/jackhuang/hellominecraft/launcher/I18N.properties b/HMCLAPI/src/main/resources/org/jackhuang/hellominecraft/launcher/I18N.properties index c9f260e80..e875bec4b 100755 --- a/HMCLAPI/src/main/resources/org/jackhuang/hellominecraft/launcher/I18N.properties +++ b/HMCLAPI/src/main/resources/org/jackhuang/hellominecraft/launcher/I18N.properties @@ -254,6 +254,7 @@ launcher.update_launcher=\u68c0\u67e5\u66f4\u65b0 launcher.enable_shadow=\u542f\u7528\u7a97\u53e3\u9634\u5f71(\u91cd\u542f\u542f\u52a8\u5668\u751f\u6548,\u53ef\u52a0\u5feb\u6e32\u67d3\u901f\u5ea6) launcher.theme=\u4e3b\u9898 launcher.proxy=\u4ee3\u7406 +launcher.decorated=\u542f\u7528\u7a97\u53e3\u8fb9\u6846(Linux\u4e0b\u53ef\u89e3\u51b3\u7a0b\u5e8f\u754c\u9762\u5168\u7070\u95ee\u9898) launcher.title.game=\u6e38\u620f\u8bbe\u7f6e launcher.title.main=\u4e3b\u9875 @@ -331,4 +332,4 @@ color.blue=\u84dd\u8272 color.green=\u7eff\u8272 color.orange=\u6a59\u8272 color.dark_blue=\u6df1\u84dd\u8272 -color.purple=\u7d2b\u8272 \ No newline at end of file +color.purple=\u7d2b\u8272